1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
|
$NetBSD: patch-af,v 1.6 2014/10/08 22:52:04 christos Exp $
*** old/commands.c Fri Sep 4 11:22:06 1998
--- commands.c Fri Sep 4 11:21:28 1998
***************
*** 493,499 ****
--- 493,503 ----
char **argv, *list;
{
register char *cmd = *argv;
+ #ifndef MSGS_DYNAMIC
char list1[MAXMSGS_BITS];
+ #else
+ char *list1 = (char *) alloca(MSGS_BITS(msg_cnt));
+ #endif
int cur_msg = current_msg, save_cnt = msg_cnt;
if (*++argv && !strcmp(*argv, "-?"))
***************
*** 502,508 ****
return -1;
/* make into our own list so ~: commands don't overwrite this list */
! bitput(list, list1, MAXMSGS, =);
/* back up one arg to replace "cmd" in the new argv[0] */
argv += (n-1);
--- 506,512 ----
return -1;
/* make into our own list so ~: commands don't overwrite this list */
! bitput(list, list1, msg_cnt, =);
/* back up one arg to replace "cmd" in the new argv[0] */
argv += (n-1);
***************
*** 533,539 ****
if (istool)
(void) do_hdrs(0, DUBL_NULL, NULL);
/* copy the specified list back into msg_list */
! bitput(list1, list, MAXMSGS, =);
return 0;
}
--- 537,543 ----
if (istool)
(void) do_hdrs(0, DUBL_NULL, NULL);
/* copy the specified list back into msg_list */
! bitput(list1, list, msg_cnt, =);
return 0;
}
*** old/doproc.c Fri Sep 4 11:22:05 1998
--- doproc.c Fri Sep 4 11:21:28 1998
***************
*** 859,865 ****
int value;
Event *event;
{
! char *argv[3], list[MAXMSGS_BITS];
char *p = (char *)panel_get_value(msg_num_item);
int n = 0;
--- 859,869 ----
int value;
Event *event;
{
! #ifndef MSGS_DYNAMIC
! char list[MAXMSGS_BITS];
! #else
! char *list = (char *) alloca(MSGS_BITS(msg_cnt));
! #endif
char *p = (char *)panel_get_value(msg_num_item);
int n = 0;
*** old/expr.c Thu May 3 15:40:10 1990
--- expr.c Fri Sep 4 11:21:28 1998
***************
*** 17,23 ****
--- 17,27 ----
{
register int num1 = -1, num2 = -1, except = 0;
register char *p2;
+ #ifndef MSGS_DYNAMIC
char list2[MAXMSGS_BITS];
+ #else
+ char *list2 = (char *) alloca(MSGS_BITS(msg_cnt));
+ #endif
if (!p)
return "";
*** old/folders.c Fri Sep 4 11:22:09 1998
--- folders.c Fri Sep 4 11:21:28 1998
***************
*** 138,145 ****
--- 138,153 ----
xfree(msg[msg_cnt].m_subject);
xfree(msg[msg_cnt].m_to);
xfree(msg[msg_cnt].m_from);
+ xfree(msg[msg_cnt].m_name);
+ xfree(msg[msg_cnt].m_addr);
msg[msg_cnt].m_subject = NULL;
msg[msg_cnt].m_to = msg[msg_cnt].m_from = NULL;
+ msg[msg_cnt].m_name = msg[msg_cnt].m_addr = NULL;
+ msg[msg_cnt].m_author = 0;
+ msg[msg_cnt].m_flags = 0;
+ msg[msg_cnt].m_size = 0;
+ msg[msg_cnt].m_offset = 0;
+ msg[msg_cnt].m_lines = 0;
}
msg_cnt = 0, msg[0].m_offset = 0L;
turnoff(glob_flags, CONT_PRNT);
***************
*** 268,274 ****
register char **argv;
{
register char *p;
! char buf[128], unused[MAXMSGS_BITS];
if (argv && argv[1] && !strcmp(argv[1], "-?"))
return help(0, "folders", cmd_help);
--- 276,287 ----
register char **argv;
{
register char *p;
! char buf[128];
! #ifndef MSGS_DYNAMIC
! char *unused[MAXMSGS_BITS];
! #else
! char *unused = (char *) alloca(MSGS_BITS(msg_cnt));
! #endif
if (argv && argv[1] && !strcmp(argv[1], "-?"))
return help(0, "folders", cmd_help);
***************
*** 418,424 ****
char *argv[], list[];
{
int r, articles = 0, merge = 0, appending = 0;
! char buf[MAXPATHLEN], cmdbuf[MAXPATHLEN], newlist[MAXMSGS_BITS], *dir;
char *art_sep = ARTICLE_SEP;
FILE *fp;
--- 431,442 ----
char *argv[], list[];
{
int r, articles = 0, merge = 0, appending = 0;
! char buf[MAXPATHLEN], cmdbuf[MAXPATHLEN], *dir;
! #ifndef MSGS_DYNAMIC
! char newlist[MAXMSGS_BITS];
! #else
! char *newlist = (char *) alloca(MSGS_BITS(msg_cnt));
! #endif
char *art_sep = ARTICLE_SEP;
FILE *fp;
*** old/loop.c Fri Sep 4 11:22:07 1998
--- loop.c Fri Sep 4 11:21:28 1998
***************
*** 251,257 ****
--- 251,261 ----
/* Return values from commands, see check_internal() */
static int last_status; /* Changes after every command */
+ #ifndef MSGS_DYNAMIC
static char last_output[MAXMSGS]; /* Changes after SUCCESSFUL command */
+ #else
+ char* last_output; /* Changes after SUCCESSFUL command */
+ #endif
/*
* do the command specified by the argument vector, argv.
***************
*** 1196,1203 ****
--- 1200,1211 ----
struct history *hist;
#ifndef REGCMP
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ regex_t rex;
+ # else
char *rex = NULL;
extern char *regcomp();
+ # endif
# else
extern char *re_comp();
# endif
***************
*** 1222,1228 ****
--- 1230,1240 ----
if (*str) {
#ifndef REGCMP
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ if (regcomp(&rex, str, REG_EXTENDED) != 0) /* Assign and test */
+ # else
if (!(rex = regcomp(str))) /* Assign and test */
+ # endif
# else
if (re_comp(str))
# endif
***************
*** 1256,1262 ****
--- 1268,1278 ----
found =
#ifndef REGCMP
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ regexec(&rex, buf, 0, NULL, 0) == 0
+ # else
!!regexec(rex, buf)
+ # endif
# else
re_exec(buf)
# endif
***************
*** 1273,1279 ****
--- 1289,1299 ----
free(rex);
#else
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ regfree(&rex);
+ # else
free(rex);
+ # endif
# endif
#endif
return (*p == '?' ? p + 1 : p);
***************
*** 1286,1292 ****
--- 1306,1316 ----
#else
# ifdef REGCOMP
/* XXX: regfree */
+ # ifdef REG_EXTENDED
+ regfree(&rex);
+ # else
free(rex);
+ # endif
# endif
#endif
return NULL;
--- old/mail.c 2014-10-08 18:47:38.000000000 -0400
+++ mail.c 2014-10-08 18:48:42.000000000 -0400
@@ -34,7 +34,12 @@
char firstchar = (argv)? **argv: 'm';
char *to = NULL, *cc = NULL, *addcc = NULL, *bcc = NULL, *subj = NULL;
char *route = NULL;
- char inc_list[MAXMSGS_BITS], buf[HDRSIZ];
+ char buf[HDRSIZ];
+#ifndef MSGS_DYNAMIC
+ char inc_list[MAXMSGS_BITS];
+#else
+ char *inc_list = (char *) alloca(MSGS_BITS(msg_cnt));
+#endif
u_long flgs = 0;
if (ison(glob_flags, IS_GETTING)) {
@@ -350,7 +355,11 @@
/* If forwarding w/o editing, start a new file for each. */
if (ison(flags, FORWARD) && ison(flags, SEND_NOW)) {
+#ifndef MSGS_DYNAMIC
char fwd[MAXMSGS_BITS];
+#else
+ char *fwd = (char *) alloca(MSGS_BITS(msg_cnt));
+#endif
register int i;
clear_msg_list(fwd);
for (i = 0; i < msg_cnt; i++)
@@ -694,7 +703,11 @@
putstring(p2, ed_fp);
}
when ':': {
+#ifndef MSGS_DYNAMIC
char new[MAXMSGS_BITS];
+#else
+ char *new = (char *) alloca(MSGS_BITS(msg_cnt));
+#endif
u_long save_flags = glob_flags;
turnon(glob_flags, IGN_SIGS);
@@ -706,7 +719,11 @@
when 'i': case 'f': case 'I': case 'm': {
int n;
u_long copy_flgs = 0;
+#ifndef MSGS_DYNAMIC
char list[MAXMSGS_BITS];
+#else
+ char *list = (char *) alloca(MSGS_BITS(msg_cnt));
+#endif
if (!msg_cnt) {
wprint("No messages.\n");
@@ -962,6 +979,7 @@
register char *p;
int c;
char buf[MAXPATHLEN];
+ static char gpat[] = "{,{,*[ \\,]}mail{,[ \\,]*}}";
/* forwarded mail has no additional personalized text */
if (ison(flags, FORWARD)) {
@@ -985,8 +1003,7 @@
p = NULL;
if (!strncmp(Cc, "~v", 2) ||
/* Flashy test for $verify either empty or set to "mail" */
- glob(p = do_set(set_options, "verify"),
- "{,{,*[ \\,]}mail{,[ \\,]*}}")) {
+ glob(p = do_set(set_options, "verify"), gpat)) {
if (!p) /* so we don't Cc to ~v! */
*Cc = 0;
for (;;) {
@@ -1679,6 +1696,7 @@
else if (!lcase_strncmp(p, "subject:", 8))
(print_hdr = FALSE), strdup(subj, p);
else if (!lcase_strncmp(p, "from:", 5)) {
+#if 0
char not_me[BUFSIZ];
(void) strcpy(not_me, buf + 5);
take_me_off(not_me);
@@ -1692,6 +1710,7 @@
(void) no_newln(buf);
}
}
+#endif
got_from = TRUE;
#ifdef PICKY_MAILER
/* don't send From: to mta -- fool "for loop" below
*** old/main.c Fri Sep 4 11:22:09 1998
--- main.c Fri Sep 4 11:21:28 1998
***************
*** 30,36 ****
char buf[MAXPATHLEN];
register char *p;
struct mush_flags Flags;
!
#ifndef INTERNAL_MALLOC
extern char *stackbottom; /* used by xfree() */
--- 30,36 ----
char buf[MAXPATHLEN];
register char *p;
struct mush_flags Flags;
! static char gpat[] = "{,{,*[ \\,]}startup{,[ \\,]*}}";
#ifndef INTERNAL_MALLOC
extern char *stackbottom; /* used by xfree() */
***************
*** 59,64 ****
--- 59,80 ----
malloc_debug(0);
#endif /* sun && debug */
+ #ifdef MSGS_DYNAMIC
+ {
+ extern char *last_output;
+ msg_max = MSGS_INCR;
+ msg = (struct msg *) malloc(sizeof(struct msg) * msg_max);
+ bzero(msg, sizeof(struct msg) * msg_max);
+ msg_list = (char *) malloc(MSGS_BITS(msg_max));
+ last_output = (char *) malloc(sizeof(char) * msg_max);
+ if (msg == (struct msg *) 0 || msg_list == NULL ||
+ last_output == NULL) {
+ (void) fprintf(stderr, "%s: Out of memory.\n", prog_name);
+ exit(1);
+ }
+ }
+ #endif
+
if (!isatty(0))
turnon(glob_flags, REDIRECT);
else
***************
*** 255,261 ****
(void) signal(SIGHUP, catch);
if (!hdrs_only && !istool && (!Flags.src_file || !Flags.src_n_exit) &&
! !glob(do_set(set_options, "quiet"), "{,{,*[ \\,]}startup{,[ \\,]*}}"))
(void) printf("%s: Type '?' for help.\n", check_internal("version"));
(void) sprintf(buf, "folder %s %s", Flags.f_flags, mailfile);
--- 271,277 ----
(void) signal(SIGHUP, catch);
if (!hdrs_only && !istool && (!Flags.src_file || !Flags.src_n_exit) &&
! !glob(do_set(set_options, "quiet"), gpat))
(void) printf("%s: Type '?' for help.\n", check_internal("version"));
(void) sprintf(buf, "folder %s %s", Flags.f_flags, mailfile);
*** old/misc.c Fri Sep 4 11:22:08 1998
--- misc.c Fri Sep 4 11:21:28 1998
***************
*** 201,207 ****
--- 201,211 ----
int argc, ret_val = -1;
u_long save_do_pipe = ison(glob_flags, DO_PIPE);
u_long save_is_pipe = ison(glob_flags, IS_PIPE);
+ #ifndef MSGS_DYNAMIC
char dummy_list[MAXMSGS_BITS];
+ #else
+ char *dummy_list = (char *) alloca(MSGS_BITS(msg_cnt));
+ #endif
turnoff(glob_flags, DO_PIPE);
turnoff(glob_flags, IS_PIPE);
*** old/msgs.c Fri Sep 4 11:22:08 1998
--- msgs.c Fri Sep 4 11:21:28 1998
***************
*** 843,848 ****
--- 843,849 ----
}
#endif /* MMDF */
buf[0] = 0;
+ date[0] = 0;
while (fgets(buf, sizeof (buf), fp)) {
#ifndef MSG_SEPARATOR
turnoff(glob_flags, WARNING);
***************
*** 875,880 ****
--- 876,882 ----
{
msg_found++;
had_error = 0;
+ #ifndef MSGS_DYNAMIC
if (append && cnt == MAXMSGS-append) {
wprint("WARNING: exceeded %d messages.\n", MAXMSGS-append);
wprint("Not all messages have been loaded.\n");
***************
*** 882,887 ****
--- 884,931 ----
had_error++;
break;
}
+ #else
+ if (append && cnt == msg_max-append) {
+ /*
+ * XXX: should really ignore signals here but instead
+ * are careful with the order we do things
+ * so if we get interrupted, we only lose memory
+ */
+ int nmsg_max = msg_max + MSGS_INCR;
+ struct msg* m;
+ char* b, *l;
+ extern char* last_output;
+
+ m = (struct msg *) realloc(msg, sizeof(struct msg) *
+ nmsg_max);
+ if (m == (struct msg *) 0) {
+ bad:
+ wprint("Out of memory for %d messages.\n", nmsg_max);
+ wprint("Not all messages have been loaded.\n");
+ msg_cnt--;
+ had_error++;
+ break;
+ }
+
+ b = (char *) realloc(msg_list, MSGS_BITS(nmsg_max));
+ if (b == NULL)
+ goto bad;
+
+ l = (char *) realloc(last_output, sizeof(char) * nmsg_max);
+ if (l == NULL)
+ goto bad;
+
+
+ msg = m;
+ msg_list = b;
+ last_output = l;
+
+ bzero(&msg[msg_max], sizeof(struct msg) * MSGS_INCR);
+
+ msg_max = nmsg_max;
+
+ }
+ #endif /* MSGS_DYNAMIC */
if (ison(glob_flags, READ_ONLY))
bytes = ftell(fp) - strlen(buf);
else {
***************
*** 1058,1064 ****
}
close_lock(file, fp);
if (isoff(glob_flags, READ_ONLY)) {
! if (had_error && msg_found && append == 1 && cnt == MAXMSGS-append) {
wprint("Using read-only mode.\n");
turnon(glob_flags, READ_ONLY);
had_error = 0; /* return successfully anyway */
--- 1102,1113 ----
}
close_lock(file, fp);
if (isoff(glob_flags, READ_ONLY)) {
! #ifndef MSGS_DYNAMIC
! if (had_error && msg_found && append == 1 && cnt == MAXMSGS-append)
! #else
! if (had_error && msg_found && append == 1 && cnt == msg_max-append)
! #endif
! {
wprint("Using read-only mode.\n");
turnon(glob_flags, READ_ONLY);
had_error = 0; /* return successfully anyway */
--- version.h.orig Mon Jan 3 15:49:04 2000
+++ version.h Mon Jan 3 15:50:42 2000
@@ -1,7 +1,11 @@
/* @(#)version.h (c) Copyright 1989, 1990, 1991 (Dan Heller) */
#define MUSHNAME "Mail User's Shell"
-#define RELEASE_DATE "beta(4) 03/19/98"
+#ifdef MSGS_DYNAMIC
+#define RELEASE_DATE "beta(4.pl1)+dynamic 20000103"
+#else
+#define RELEASE_DATE "beta(4.pl1) 20000103"
+#endif
#define RELEASE 7
#define REVISION "2"
#define PATCHLEVEL 6
*** old/pick.c Fri Sep 4 12:07:59 1998
--- pick.c Fri Sep 4 13:12:17 1998
***************
*** 11,19 ****
static int pick();
static void month_day_year();
! #ifdef REGCOMP
regerror(msg)
! char *msg;
{
printf("regcomp error: %s\n", msg);
}
--- 11,20 ----
static int pick();
static void month_day_year();
! #if defined(REGCOMP) && !defined(REG_EXTENDED)
! void
regerror(msg)
! const char *msg;
{
printf("regcomp error: %s\n", msg);
}
***************
*** 23,29 ****
--- 24,34 ----
register int n;
register char **argv, list[];
{
+ #ifndef MSGS_DYNAMIC
char ret_list[MAXMSGS_BITS];
+ #else
+ char *ret_list = (char *) alloca(MSGS_BITS(msg_cnt));
+ #endif
if (n > 1 && !strcmp(argv[1], "-?"))
return help(0, "pick", cmd_help);
***************
*** 72,78 ****
register char c;
int matches = 0;
char pattern[256];
! short head_first, head_cnt, tail_cnt, search = TRUE;
int n;
if (!msg_cnt) {
--- 77,83 ----
register char c;
int matches = 0;
char pattern[256];
! short head_first, head_cnt, tail_cnt, search = TRUE, dups = FALSE;
int n;
if (!msg_cnt) {
***************
*** 166,171 ****
--- 171,177 ----
turnon(match_priority, M_PRIORITY(c - 'A' + 1));
when 'x' : xflg = 1;
when 'i' : icase = 1;
+ when 'D' : dups = TRUE;
otherwise:
print("pick: unknown flag: %c\n", argv[0][1]);
clear_msg_list(ret_list);
***************
*** 175,181 ****
print("Can't specify -x and head/tail options together.\n");
return -1;
}
! if (!mdy[1]) {
(void) argv_to_string(pattern, argv);
if (pattern[0] == '\0' && match_priority == 0 &&
head_cnt + tail_cnt < 0) {
--- 181,187 ----
print("Can't specify -x and head/tail options together.\n");
return -1;
}
! if (!mdy[1] && !dups) {
(void) argv_to_string(pattern, argv);
if (pattern[0] == '\0' && match_priority == 0 &&
head_cnt + tail_cnt < 0) {
***************
*** 184,190 ****
return -1;
}
}
! search = (pattern[0] || mdy[1] || (match_priority != 0));
if (verbose) {
if (head_cnt + tail_cnt >= 0) {
print("Finding the ");
--- 190,196 ----
return -1;
}
}
! search = (pattern[0] || mdy[1] || (match_priority > 0));
if (verbose) {
if (head_cnt + tail_cnt >= 0) {
print("Finding the ");
***************
*** 209,216 ****
print_more(" of the last %d", tail_cnt);
} else
print_more("Searching for %smessages",
! match_priority != 0 ? "priority " : "");
! if (!search) {
if (tail_cnt > 0 && head_cnt > 0)
print_more(" messages");
if (ison(glob_flags, IS_PIPE))
--- 215,224 ----
print_more(" of the last %d", tail_cnt);
} else
print_more("Searching for %smessages",
! match_priority > 0 ? "priority " : "");
! if (dups) {
! print_more(" that are duplicates");
! } else if (!search) {
if (tail_cnt > 0 && head_cnt > 0)
print_more(" messages");
if (ison(glob_flags, IS_PIPE))
***************
*** 241,247 ****
}
if (mdy[1] > 0 && icase)
print("using date: -i flag ignored.\n");
! if (!search) {
for (n = 0; n < msg_cnt && (!head_first || matches < head_cnt); n++)
if (msg_bit(list, n))
++matches, set_msg_bit(ret_list, n);
--- 249,258 ----
}
if (mdy[1] > 0 && icase)
print("using date: -i flag ignored.\n");
! if (dups)
! matches = find_dups(head_first? head_cnt : msg_cnt,
! list, ret_list);
! else if (!search) {
for (n = 0; n < msg_cnt && (!head_first || matches < head_cnt); n++)
if (msg_bit(list, n))
++matches, set_msg_bit(ret_list, n);
***************
*** 284,289 ****
--- 295,424 ----
return matches;
}
+
+ static int
+ cmplines(m1, m2)
+ struct msg **m1;
+ struct msg **m2;
+ {
+ int z = (int) (*m2)->m_lines - (int) (*m1)->m_lines;
+ if (z > 0)
+ return 1;
+ else if (z < 0)
+ return -1;
+ else
+ return 0;
+ }
+
+
+ /*
+ * find_dups searches for messages with the same body as others
+ */
+ find_dups(cnt, check_list, ret_list)
+ int cnt;
+ char check_list[], ret_list[];
+ {
+ int i, j, n, lcur, mcur;
+ int matches = 0;
+ #ifndef MSGS_DYNAMIC
+ struct msg *mlist[MAXMSGS];
+ #else
+ struct msg **mlist = (struct msg **) alloca(msg_cnt *
+ sizeof(struct msg *));
+ #endif
+ char *omsg = NULL, *nmsg = NULL, *otext = NULL, *ntext = NULL;
+ size_t otsize = 0, ntsize = 0, omsize = 0, nmsize = 0, mid;
+
+ if (cnt == -1)
+ cnt = msg_cnt;
+
+ for (i = 0, n = 0; i < cnt && n < msg_cnt; n++)
+ if (msg_bit(check_list, n)) {
+ mlist[i] = &msg[n];
+ mlist[i]->m_spare = n;
+ i++;
+ }
+
+ cnt = i;
+ qsort((char *) mlist, cnt, sizeof(struct msg *), cmplines);
+
+ clear_msg_list(ret_list);
+
+ lcur = -1;
+
+ for (i = 0; i < cnt - 1; i++) {
+ lcur = mlist[i]->m_lines;
+ mcur = mlist[i]->m_spare;
+
+ if (mlist[i + 1]->m_lines != lcur)
+ /* Next message has not the same number of lines, skip */
+ continue;
+
+ (void) msg_get(mcur, NULL, 0);
+ if (otsize < mlist[i]->m_size) {
+ otsize = mlist[i]->m_size;
+ otext = otext ? (char *) malloc(otsize) :
+ (char *) realloc(otext, otsize);
+ if (otext == NULL) {
+ print("Out of memory in find_dups\n");
+ goto bad;
+ }
+ }
+ if (fread(otext, 1, mlist[i]->m_size, tmpf) != mlist[i]->m_size) {
+ print("fread old for %d failed %d\n", mcur, sys_errlist[errno]);
+ goto bad;
+ }
+ if ((omsg = (char *) strstr(otext, "\n\n")) == NULL) {
+ printf("could not find start of message %d\n", mcur);
+ continue;
+ }
+ omsize = mlist[i]->m_size - (omsg - otext);
+ for (j = i + 1; j < cnt; j++) {
+ if (mlist[j]->m_lines != lcur)
+ /* Next message has not the same number of lines, skip */
+ break;
+ mid = mlist[j]->m_spare;
+ (void) msg_get(mid, NULL, 0);
+ if (ntsize < mlist[j]->m_size) {
+ ntsize = mlist[j]->m_size;
+ ntext = ntext ? (char *) malloc(ntsize) :
+ (char *) realloc(ntext, ntsize);
+ if (ntext == NULL) {
+ print("Out of memory in find_dups\n");
+ goto bad;
+ }
+ }
+ if (fread(ntext, 1, mlist[j]->m_size, tmpf) != mlist[j]->m_size) {
+ print("fread new for %d failed %d\n", mid, sys_errlist[errno]);
+ goto bad;
+ }
+ if ((nmsg = (char *) strstr(ntext, "\n\n")) == NULL) {
+ printf("could not find start of message %d\n", mid);
+ continue;
+ }
+ nmsize = mlist[j]->m_size - (nmsg - ntext);
+ if (nmsize != omsize)
+ continue;
+ if (memcmp(nmsg, omsg, nmsize) == 0) {
+ ++matches;
+ set_msg_bit(ret_list, mid);
+ }
+ }
+ }
+ if (otext)
+ free(otext);
+ if (ntext)
+ free(ntext);
+ return matches;
+ bad:
+ clear_msg_list(ret_list);
+ if (otext)
+ free(otext);
+ if (ntext)
+ free(ntext);
+ return 0;
+ }
+
/*
* find_pattern will search thru all the messages set in the check_list
* until the list runs out or "cnt" has been exhasted. ret_list contains
***************
*** 307,313 ****
--- 442,452 ----
#endif
#else /* REGCMP */
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ regex_t rex;
+ # else
char *regcomp(), *regexec();
+ # endif
# else
char *re_comp();
# endif
***************
*** 328,334 ****
--- 467,478 ----
}
#else /* REGCMP */
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ if (regcomp(&rex, p, REG_EXTENDED) != 0)
+ # else
if ((err = regcomp(p)) == NULL) {
+ # endif
+ {
clear_msg_list(ret_list);
return -1;
}
***************
*** 348,354 ****
/* start searching: set bytes, and message number: n */
for (n = 0; cnt && n < msg_cnt; n++)
if (msg_bit(check_list, n)) {
! if (match_priority != 0) {
if (msg[n].m_flags & match_priority)
++matches, set_msg_bit(ret_list, n);
continue;
--- 492,498 ----
/* start searching: set bytes, and message number: n */
for (n = 0; cnt && n < msg_cnt; n++)
if (msg_bit(check_list, n)) {
! if (match_priority > 0) {
if (msg[n].m_flags & match_priority)
++matches, set_msg_bit(ret_list, n);
continue;
***************
*** 421,427 ****
--- 565,575 ----
val = !!regex(err, p, NULL); /* convert value to a boolean */
#else /* REGCMP */
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ val = regexec(&rex, p, 0, NULL, 0) == 0;
+ # else
val = !!regexec(err, p);
+ # endif
# else
val = re_exec(p);
# endif
***************
*** 448,455 ****
--- 596,607 ----
#else
# ifdef REGCOMP
if (err)
+ # ifdef REG_EXTENDED
+ regfree(&rex);
+ # else
/* XXX: regfree soon */
free(err);
+ # endif
# endif
#endif /* REGCMP */
return matches;
***************
*** 476,482 ****
--- 628,638 ----
#endif
#else /* REGCMP */
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ regex_t rex;
+ # else
char *regcomp(), *regexec();
+ # endif
# else
char *re_comp();
# endif
***************
*** 509,515 ****
}
#else /* REGCMP */
# ifdef REGCOMP
! if (*pattern && !(err = regcomp(pattern, NULL))) {
print("Error in regcomp in %s", pattern);
return 0;
}
--- 665,676 ----
}
#else /* REGCMP */
# ifdef REGCOMP
! # ifdef REG_EXTENDED
! if (*pattern && regcomp(&rex, pattern, REG_EXTENDED))
! # else
! if (*pattern && !(err = regcomp(pattern, NULL)))
! # endif
! {
print("Error in regcomp in %s", pattern);
return 0;
}
***************
*** 534,540 ****
--- 695,705 ----
val = !!regex(err, p, NULL); /* convert value to a boolean */
#else /* REGCMP */
# ifdef REGCOMP
+ # ifdef REG_EXTENDED
+ val = regexec(&rex, p, 0, NULL, 0) == 0;
+ # else
val = !!regexec(err, p);
+ # endif
# else
val = re_exec(p);
# endif
***************
*** 549,556 ****
--- 714,725 ----
#else
# ifdef REGCOMP
if (err)
+ # ifdef REG_EXTENDED
+ regfree(&rex);
+ # else
/* XXX: regfree soon */
free(err);
+ # endif
# endif
#endif /* REGCMP */
|