2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
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 2, 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 COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "stringclass.h"
32 int compatible_flag = 0;
34 extern int interpret_lf_args(const char *);
36 int do_file(const char *filename);
40 fprintf(stderr, "usage: %s [ -vC ] [ files ]\n", program_name);
44 int main(int argc, char **argv)
46 program_name = argv[0];
48 while ((opt = getopt(argc, argv, "vC")) != EOF)
52 extern const char *version_string;
53 fprintf(stderr, "GNU soelim version %s\n", version_string);
68 nbad += !do_file("-");
70 for (int i = optind; i < argc; i++)
71 nbad += !do_file(argv[i]);
72 if (ferror(stdout) || fflush(stdout) < 0)
73 fatal("output error");
79 printf(".lf %d %s\n", current_lineno, current_filename);
82 void do_so(const char *line)
89 for (const char *q = p;
90 success && *q != '\0' && *q != '\n' && *q != ' ';
107 filename += char(*q);
108 if (success && filename.length() > 0) {
110 const char *fn = current_filename;
111 int ln = current_lineno;
113 if (do_file(filename.contents())) {
114 current_filename = fn;
121 fputs(".so", stdout);
125 int do_file(const char *filename)
128 if (strcmp(filename, "-") == 0)
132 fp = fopen(filename, "r");
134 error("can't open `%1': %2", filename, strerror(errno));
138 current_filename = filename;
141 enum { START, MIDDLE, HAD_DOT, HAD_s, HAD_so, HAD_l, HAD_lf } state = START;
199 if (c == ' ' || c == '\n' || compatible_flag) {
201 for (; c != EOF && c != '\n'; c = getc(fp))
206 do_so(line.contents());
210 fputs(".so", stdout);
231 if (c == ' ' || c == '\n' || compatible_flag) {
233 for (; c != EOF && c != '\n'; c = getc(fp))
238 interpret_lf_args(line.contents());
239 printf(".lf%s", line.contents());
243 fputs(".lf", stdout);
254 fputs(".\n", stdout);
257 fputs(".l\n", stdout);
260 fputs(".s\n", stdout);
263 fputs(".lf\n", stdout);
266 fputs(".so\n", stdout);
276 current_filename = 0;