2 /* Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.uucp)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 1, or (at your option) any later
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file LICENSE. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #include "stringclass.h"
31 int compatible_flag
= 0;
33 extern int interpret_lf_args(const char *);
35 int do_file(const char *filename
);
39 fprintf(stderr
, "usage: %s [ -vC ] [ files ]\n", program_name
);
43 int main(int argc
, char **argv
)
45 program_name
= argv
[0];
47 while ((opt
= getopt(argc
, argv
, "vC")) != EOF
)
51 extern const char *version_string
;
52 fprintf(stderr
, "GNU soelim version %s\n", version_string
);
67 nbad
+= !do_file("-");
69 for (int i
= optind
; i
< argc
; i
++)
70 nbad
+= !do_file(argv
[i
]);
71 if (ferror(stdout
) || fflush(stdout
) < 0)
72 fatal("output error");
78 printf(".lf %d %s\n", current_lineno
, current_filename
);
81 void do_so(const char *line
)
88 for (const char *q
= p
;
89 success
&& *q
!= '\0' && *q
!= '\n' && *q
!= ' ';
106 filename
+= char(*q
);
107 if (success
&& filename
.length() > 0) {
109 const char *fn
= current_filename
;
110 int ln
= current_lineno
;
112 if (do_file(filename
.contents())) {
113 current_filename
= fn
;
120 fputs(".so", stdout
);
124 int do_file(const char *filename
)
127 if (strcmp(filename
, "-") == 0)
131 fp
= fopen(filename
, "r");
133 error("can't open `%1': %2", filename
, strerror(errno
));
137 current_filename
= filename
;
140 enum { START
, MIDDLE
, HAD_DOT
, HAD_s
, HAD_so
, HAD_l
, HAD_lf
} state
= START
;
198 if (c
== ' ' || c
== '\n' || compatible_flag
) {
200 for (; c
!= EOF
&& c
!= '\n'; c
= getc(fp
))
205 do_so(line
.contents());
209 fputs(".so", stdout
);
230 if (c
== ' ' || c
== '\n' || compatible_flag
) {
232 for (; c
!= EOF
&& c
!= '\n'; c
= getc(fp
))
237 interpret_lf_args(line
.contents());
238 printf(".lf%s", line
.contents());
242 fputs(".lf", stdout
);
253 fputs(".\n", stdout
);
256 fputs(".l\n", stdout
);
259 fputs(".s\n", stdout
);
262 fputs(".lf\n", stdout
);
265 fputs(".so\n", stdout
);
275 current_filename
= 0;