-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchew.c
More file actions
1630 lines (1444 loc) · 30.3 KB
/
chew.c
File metadata and controls
1630 lines (1444 loc) · 30.3 KB
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
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* chew
Copyright (C) 1990-2017 Free Software Foundation, Inc.
Contributed by steve chamberlain @cygnus
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* Yet another way of extracting documentation from source.
No, I haven't finished it yet, but I hope you people like it better
than the old way
sac
Basically, this is a sort of string forth, maybe we should call it
struth?
You define new words thus:
: <newword> <oldwords> ;
*/
/* Primitives provided by the program:
Two stacks are provided, a string stack and an integer stack.
Internal state variables:
internal_wanted - indicates whether `-i' was passed
internal_mode - user-settable
Commands:
push_text
! - pop top of integer stack for address, pop next for value; store
@ - treat value on integer stack as the address of an integer; push
that integer on the integer stack after popping the "address"
hello - print "hello\n" to stdout
stdout - put stdout marker on TOS
stderr - put stderr marker on TOS
print - print TOS-1 on TOS (eg: "hello\n" stdout print)
skip_past_newline
catstr - fn icatstr
copy_past_newline - append input, up to and including newline into TOS
dup - fn other_dup
drop - discard TOS
idrop - ditto
remchar - delete last character from TOS
get_stuff_in_command
do_fancy_stuff - translate <<foo>> to @code{foo} in TOS
bulletize - if "o" lines found, prepend @itemize @bullet to TOS
and @item to each "o" line; append @end itemize
courierize - put @example around . and | lines, translate {* *} { }
exit - fn chew_exit
swap
outputdots - strip out lines without leading dots
paramstuff - convert full declaration into "PARAMS" form if not already
maybecatstr - do catstr if internal_mode == internal_wanted, discard
value in any case
translatecomments - turn {* and *} into comment delimiters
kill_bogus_lines - get rid of extra newlines
indent
internalmode - pop from integer stack, set `internalmode' to that value
print_stack_level - print current stack depth to stderr
strip_trailing_newlines - go ahead, guess...
[quoted string] - push string onto string stack
[word starting with digit] - push atol(str) onto integer stack
A command must be all upper-case, and alone on a line.
Foo. */
#include "ansidecl.h"
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define DEF_SIZE 5000
#define STACK 50
int internal_wanted;
int internal_mode;
int warning;
/* Here is a string type ... */
typedef struct buffer
{
char *ptr;
unsigned long write_idx;
unsigned long size;
} string_type;
#ifdef __STDC__
static void init_string_with_size (string_type *, unsigned int);
static void init_string (string_type *);
static int find (string_type *, char *);
static void write_buffer (string_type *, FILE *);
static void delete_string (string_type *);
static char *addr (string_type *, unsigned int);
static char at (string_type *, unsigned int);
static void catchar (string_type *, int);
static void overwrite_string (string_type *, string_type *);
static void catbuf (string_type *, char *, unsigned int);
static void cattext (string_type *, char *);
static void catstr (string_type *, string_type *);
static void die (char *);
#endif
static void
init_string_with_size (buffer, size)
string_type *buffer;
unsigned int size;
{
buffer->write_idx = 0;
buffer->size = size;
buffer->ptr = (char *) malloc (size);
}
static void
init_string (buffer)
string_type *buffer;
{
init_string_with_size (buffer, DEF_SIZE);
}
static int
find (str, what)
string_type *str;
char *what;
{
unsigned int i;
char *p;
p = what;
for (i = 0; i < str->write_idx && *p; i++)
{
if (*p == str->ptr[i])
p++;
else
p = what;
}
return (*p == 0);
}
static void
write_buffer (buffer, f)
string_type *buffer;
FILE *f;
{
if (buffer->write_idx != 0
&& fwrite (buffer->ptr, buffer->write_idx, 1, f) != 1)
die ("cannot write output");
}
static void
delete_string (buffer)
string_type *buffer;
{
if (buffer->ptr)
free (buffer->ptr);
buffer->ptr = NULL;
}
static char *
addr (buffer, idx)
string_type *buffer;
unsigned int idx;
{
return buffer->ptr + idx;
}
static char
at (buffer, pos)
string_type *buffer;
unsigned int pos;
{
if (pos >= buffer->write_idx)
return 0;
return buffer->ptr[pos];
}
static void
catchar (buffer, ch)
string_type *buffer;
int ch;
{
if (buffer->write_idx == buffer->size)
{
buffer->size *= 2;
buffer->ptr = (char *) realloc (buffer->ptr, buffer->size);
}
buffer->ptr[buffer->write_idx++] = ch;
}
static void
overwrite_string (dst, src)
string_type *dst;
string_type *src;
{
free (dst->ptr);
dst->size = src->size;
dst->write_idx = src->write_idx;
dst->ptr = src->ptr;
}
static void
catbuf (buffer, buf, len)
string_type *buffer;
char *buf;
unsigned int len;
{
if (buffer->write_idx + len >= buffer->size)
{
while (buffer->write_idx + len >= buffer->size)
buffer->size *= 2;
buffer->ptr = (char *) realloc (buffer->ptr, buffer->size);
}
memcpy (buffer->ptr + buffer->write_idx, buf, len);
buffer->write_idx += len;
}
static void
cattext (buffer, string)
string_type *buffer;
char *string;
{
catbuf (buffer, string, (unsigned int) strlen (string));
}
static void
catstr (dst, src)
string_type *dst;
string_type *src;
{
catbuf (dst, src->ptr, src->write_idx);
}
static unsigned int
skip_white_and_stars (src, idx)
string_type *src;
unsigned int idx;
{
char c;
while ((c = at (src, idx)),
isspace ((unsigned char) c)
|| (c == '*'
/* Don't skip past end-of-comment or star as first
character on its line. */
&& at (src, idx +1) != '/'
&& at (src, idx -1) != '\n'))
idx++;
return idx;
}
static unsigned int
skip_past_newline_1 (ptr, idx)
string_type *ptr;
unsigned int idx;
{
while (at (ptr, idx)
&& at (ptr, idx) != '\n')
idx++;
if (at (ptr, idx) == '\n')
return idx + 1;
return idx;
}
/***********************************************************************/
string_type stack[STACK];
string_type *tos;
unsigned int idx = 0; /* Pos in input buffer */
string_type *ptr; /* and the buffer */
typedef void (*stinst_type)();
stinst_type *pc;
stinst_type sstack[STACK];
stinst_type *ssp = &sstack[0];
long istack[STACK];
long *isp = &istack[0];
typedef int *word_type;
struct dict_struct
{
char *word;
struct dict_struct *next;
stinst_type *code;
int code_length;
int code_end;
int var;
};
typedef struct dict_struct dict_type;
static void
die (msg)
char *msg;
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
static void
check_range ()
{
if (tos < stack)
die ("underflow in string stack");
if (tos >= stack + STACK)
die ("overflow in string stack");
}
static void
icheck_range ()
{
if (isp < istack)
die ("underflow in integer stack");
if (isp >= istack + STACK)
die ("overflow in integer stack");
}
#ifdef __STDC__
static void exec (dict_type *);
static void call (void);
static void remchar (void), strip_trailing_newlines (void), push_number (void);
static void push_text (void);
static void remove_noncomments (string_type *, string_type *);
static void print_stack_level (void);
static void paramstuff (void), translatecomments (void);
static void outputdots (void), courierize (void), bulletize (void);
static void do_fancy_stuff (void);
static int iscommand (string_type *, unsigned int);
static int copy_past_newline (string_type *, unsigned int, string_type *);
static void icopy_past_newline (void), kill_bogus_lines (void), indent (void);
static void get_stuff_in_command (void), swap (void), other_dup (void);
static void drop (void), idrop (void);
static void icatstr (void), skip_past_newline (void), internalmode (void);
static void maybecatstr (void);
static char *nextword (char *, char **);
dict_type *lookup_word (char *);
static void perform (void);
dict_type *newentry (char *);
unsigned int add_to_definition (dict_type *, stinst_type);
void add_intrinsic (char *, void (*)());
void add_var (char *);
void compile (char *);
static void bang (void);
static void atsign (void);
static void hello (void);
static void stdout_ (void);
static void stderr_ (void);
static void print (void);
static void read_in (string_type *, FILE *);
static void usage (void);
static void chew_exit (void);
#endif
static void
exec (word)
dict_type *word;
{
pc = word->code;
while (*pc)
(*pc) ();
}
static void
call ()
{
stinst_type *oldpc = pc;
dict_type *e;
e = (dict_type *) (pc[1]);
exec (e);
pc = oldpc + 2;
}
static void
remchar ()
{
if (tos->write_idx)
tos->write_idx--;
pc++;
}
static void
strip_trailing_newlines ()
{
while ((isspace ((unsigned char) at (tos, tos->write_idx - 1))
|| at (tos, tos->write_idx - 1) == '\n')
&& tos->write_idx > 0)
tos->write_idx--;
pc++;
}
static void
push_number ()
{
isp++;
icheck_range ();
pc++;
*isp = (long) (*pc);
pc++;
}
static void
push_text ()
{
tos++;
check_range ();
init_string (tos);
pc++;
cattext (tos, *((char **) pc));
pc++;
}
/* This function removes everything not inside comments starting on
the first char of the line from the string, also when copying
comments, removes blank space and leading *'s.
Blank lines are turned into one blank line. */
static void
remove_noncomments (src, dst)
string_type *src;
string_type *dst;
{
unsigned int idx = 0;
while (at (src, idx))
{
/* Now see if we have a comment at the start of the line. */
if (at (src, idx) == '\n'
&& at (src, idx + 1) == '/'
&& at (src, idx + 2) == '*')
{
idx += 3;
idx = skip_white_and_stars (src, idx);
/* Remove leading dot */
if (at (src, idx) == '.')
idx++;
/* Copy to the end of the line, or till the end of the
comment. */
while (at (src, idx))
{
if (at (src, idx) == '\n')
{
/* end of line, echo and scrape of leading blanks */
if (at (src, idx + 1) == '\n')
catchar (dst, '\n');
catchar (dst, '\n');
idx++;
idx = skip_white_and_stars (src, idx);
}
else if (at (src, idx) == '*' && at (src, idx + 1) == '/')
{
idx += 2;
cattext (dst, "\nENDDD\n");
break;
}
else
{
catchar (dst, at (src, idx));
idx++;
}
}
}
else
idx++;
}
}
static void
print_stack_level ()
{
fprintf (stderr, "current string stack depth = %ld, ",
(long) (tos - stack));
fprintf (stderr, "current integer stack depth = %ld\n",
(long) (isp - istack));
pc++;
}
/* turn:
foobar name(stuff);
into:
foobar
name PARAMS ((stuff));
and a blank line.
*/
static void
paramstuff ()
{
unsigned int openp;
unsigned int fname;
unsigned int idx;
unsigned int len;
string_type out;
init_string (&out);
#define NO_PARAMS 1
/* Make sure that it's not already param'd or proto'd. */
if (NO_PARAMS
|| find (tos, "PARAMS") || find (tos, "PROTO") || !find (tos, "("))
{
catstr (&out, tos);
}
else
{
/* Find the open paren. */
for (openp = 0; at (tos, openp) != '(' && at (tos, openp); openp++)
;
fname = openp;
/* Step back to the fname. */
fname--;
while (fname && isspace ((unsigned char) at (tos, fname)))
fname--;
while (fname
&& !isspace ((unsigned char) at (tos,fname))
&& at (tos,fname) != '*')
fname--;
fname++;
/* Output type, omitting trailing whitespace character(s), if
any. */
for (len = fname; 0 < len; len--)
{
if (!isspace ((unsigned char) at (tos, len - 1)))
break;
}
for (idx = 0; idx < len; idx++)
catchar (&out, at (tos, idx));
cattext (&out, "\n"); /* Insert a newline between type and fnname */
/* Output function name, omitting trailing whitespace
character(s), if any. */
for (len = openp; 0 < len; len--)
{
if (!isspace ((unsigned char) at (tos, len - 1)))
break;
}
for (idx = fname; idx < len; idx++)
catchar (&out, at (tos, idx));
cattext (&out, " PARAMS (");
for (idx = openp; at (tos, idx) && at (tos, idx) != ';'; idx++)
catchar (&out, at (tos, idx));
cattext (&out, ");\n\n");
}
overwrite_string (tos, &out);
pc++;
}
/* turn {*
and *} into comments */
static void
translatecomments ()
{
unsigned int idx = 0;
string_type out;
init_string (&out);
while (at (tos, idx))
{
if (at (tos, idx) == '{' && at (tos, idx + 1) == '*')
{
cattext (&out, "/*");
idx += 2;
}
else if (at (tos, idx) == '*' && at (tos, idx + 1) == '}')
{
cattext (&out, "*/");
idx += 2;
}
else
{
catchar (&out, at (tos, idx));
idx++;
}
}
overwrite_string (tos, &out);
pc++;
}
/* Mod tos so that only lines with leading dots remain */
static void
outputdots ()
{
unsigned int idx = 0;
string_type out;
init_string (&out);
while (at (tos, idx))
{
/* Every iteration begins at the start of a line. */
if (at (tos, idx) == '.')
{
char c;
idx++;
while ((c = at (tos, idx)) && c != '\n')
{
if (c == '{' && at (tos, idx + 1) == '*')
{
cattext (&out, "/*");
idx += 2;
}
else if (c == '*' && at (tos, idx + 1) == '}')
{
cattext (&out, "*/");
idx += 2;
}
else
{
catchar (&out, c);
idx++;
}
}
if (c == '\n')
idx++;
catchar (&out, '\n');
}
else
{
idx = skip_past_newline_1 (tos, idx);
}
}
overwrite_string (tos, &out);
pc++;
}
/* Find lines starting with . and | and put example around them on tos */
static void
courierize ()
{
string_type out;
unsigned int idx = 0;
int command = 0;
init_string (&out);
while (at (tos, idx))
{
if (at (tos, idx) == '\n'
&& (at (tos, idx +1 ) == '.'
|| at (tos, idx + 1) == '|'))
{
cattext (&out, "\n@example\n");
do
{
idx += 2;
while (at (tos, idx) && at (tos, idx) != '\n')
{
if (command > 1)
{
/* We are inside {} parameters of some command;
Just pass through until matching brace. */
if (at (tos, idx) == '{')
++command;
else if (at (tos, idx) == '}')
--command;
}
else if (command != 0)
{
if (at (tos, idx) == '{')
++command;
else if (!islower ((unsigned char) at (tos, idx)))
--command;
}
else if (at (tos, idx) == '@'
&& islower ((unsigned char) at (tos, idx + 1)))
{
++command;
}
else if (at (tos, idx) == '{' && at (tos, idx + 1) == '*')
{
cattext (&out, "/*");
idx += 2;
continue;
}
else if (at (tos, idx) == '*' && at (tos, idx + 1) == '}')
{
cattext (&out, "*/");
idx += 2;
continue;
}
else if (at (tos, idx) == '{'
|| at (tos, idx) == '}')
{
catchar (&out, '@');
}
catchar (&out, at (tos, idx));
idx++;
}
catchar (&out, '\n');
}
while (at (tos, idx) == '\n'
&& ((at (tos, idx + 1) == '.')
|| (at (tos, idx + 1) == '|')))
;
cattext (&out, "@end example");
}
else
{
catchar (&out, at (tos, idx));
idx++;
}
}
overwrite_string (tos, &out);
pc++;
}
/* Finds any lines starting with "o ", if there are any, then turns
on @itemize @bullet, and @items each of them. Then ends with @end
itemize, inplace at TOS*/
static void
bulletize ()
{
unsigned int idx = 0;
int on = 0;
string_type out;
init_string (&out);
while (at (tos, idx))
{
if (at (tos, idx) == '@'
&& at (tos, idx + 1) == '*')
{
cattext (&out, "*");
idx += 2;
}
else if (at (tos, idx) == '\n'
&& at (tos, idx + 1) == 'o'
&& isspace ((unsigned char) at (tos, idx + 2)))
{
if (!on)
{
cattext (&out, "\n@itemize @bullet\n");
on = 1;
}
cattext (&out, "\n@item\n");
idx += 3;
}
else
{
catchar (&out, at (tos, idx));
if (on && at (tos, idx) == '\n'
&& at (tos, idx + 1) == '\n'
&& at (tos, idx + 2) != 'o')
{
cattext (&out, "@end itemize");
on = 0;
}
idx++;
}
}
if (on)
{
cattext (&out, "@end itemize\n");
}
delete_string (tos);
*tos = out;
pc++;
}
/* Turn <<foo>> into @code{foo} in place at TOS*/
static void
do_fancy_stuff ()
{
unsigned int idx = 0;
string_type out;
init_string (&out);
while (at (tos, idx))
{
if (at (tos, idx) == '<'
&& at (tos, idx + 1) == '<'
&& !isspace ((unsigned char) at (tos, idx + 2)))
{
/* This qualifies as a << startup. */
idx += 2;
cattext (&out, "@code{");
while (at (tos, idx)
&& at (tos, idx) != '>' )
{
catchar (&out, at (tos, idx));
idx++;
}
cattext (&out, "}");
idx += 2;
}
else
{
catchar (&out, at (tos, idx));
idx++;
}
}
delete_string (tos);
*tos = out;
pc++;
}
/* A command is all upper case,and alone on a line. */
static int
iscommand (ptr, idx)
string_type *ptr;
unsigned int idx;
{
unsigned int len = 0;
while (at (ptr, idx))
{
if (isupper ((unsigned char) at (ptr, idx))
|| at (ptr, idx) == ' ' || at (ptr, idx) == '_')
{
len++;
idx++;
}
else if (at (ptr, idx) == '\n')
{
if (len > 3)
return 1;
return 0;
}
else
return 0;
}
return 0;
}
static int
copy_past_newline (ptr, idx, dst)
string_type *ptr;
unsigned int idx;
string_type *dst;
{
int column = 0;
while (at (ptr, idx) && at (ptr, idx) != '\n')
{
if (at (ptr, idx) == '\t')
{
/* Expand tabs. Neither makeinfo nor TeX can cope well with
them. */
do
catchar (dst, ' ');
while (++column & 7);
}
else
{
catchar (dst, at (ptr, idx));
column++;
}
idx++;
}
catchar (dst, at (ptr, idx));
idx++;
return idx;
}
static void
icopy_past_newline ()
{
tos++;
check_range ();
init_string (tos);
idx = copy_past_newline (ptr, idx, tos);
pc++;
}
/* indent
Take the string at the top of the stack, do some prettying. */
static void
kill_bogus_lines ()
{
int sl;
int idx = 0;
int c;
int dot = 0;
string_type out;
init_string (&out);
/* Drop leading nl. */
while (at (tos, idx) == '\n')
{
idx++;
}
c = idx;
/* If the first char is a '.' prepend a newline so that it is
recognized properly later. */
if (at (tos, idx) == '.')
catchar (&out, '\n');
/* Find the last char. */
while (at (tos, idx))
{
idx++;
}
/* Find the last non white before the nl. */
idx--;
while (idx && isspace ((unsigned char) at (tos, idx)))
idx--;
idx++;
/* Copy buffer upto last char, but blank lines before and after
dots don't count. */
sl = 1;
while (c < idx)
{
if (at (tos, c) == '\n'
&& at (tos, c + 1) == '\n'
&& at (tos, c + 2) == '.')
{
/* Ignore two newlines before a dot. */
c++;
}
else if (at (tos, c) == '.' && sl)
{
/* remember that this line started with a dot. */
dot = 2;
}
else if (at (tos, c) == '\n'
&& at (tos, c + 1) == '\n'
&& dot)
{
c++;
/* Ignore two newlines when last line was dot. */
}
catchar (&out, at (tos, c));
if (at (tos, c) == '\n')
{
sl = 1;
if (dot == 2)
dot = 1;
else
dot = 0;
}
else
sl = 0;
c++;
}
/* Append nl. */
catchar (&out, '\n');
pc++;
delete_string (tos);
*tos = out;
}
static void