1 /* CPP main program, using CPP Library.
2 * Copyright (C) 1995 Free Software Foundation, Inc.
3 * Written by Per Bothner, 1994-95.
4 * Copyright (C) 2003-2011 Kim Woelders
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 * In other words, you are welcome to use, share and improve this program.
21 * You are forbidden to forbid anyone else to use, share and improve
22 * what you give them. Help stamp out software-hoarding! */
40 main(int argc, char **argv)
44 int argi = 1; /* Next argument to handle. */
45 struct cpp_options *opts = &options;
51 p = argv[0] + strlen(argv[0]);
53 while (p != argv[0] && p[-1] != '/')
55 while (p != argv[0] && p[-1] != '/' && p[-1] != '\\')
60 init_parse_file(&parse_in);
63 init_parse_options(opts);
65 argi += cpp_handle_options(&parse_in, argc - argi, argv + argi);
67 cpp_fatal("Invalid option `%s'", argv[argi]);
68 parse_in.show_column = 1;
70 i = push_parse_file(&parse_in, opts->in_fname);
71 if (i != SUCCESS_EXIT_CODE)
74 /* Now that we know the input file is valid, open the output. */
76 if (!opts->out_fname || !strcmp(opts->out_fname, ""))
77 opts->out_fname = "stdout";
78 else if (!freopen(opts->out_fname, "w", stdout))
79 cpp_pfatal_with_name(&parse_in, opts->out_fname);
83 kind = cpp_get_token(&parse_in);
85 fprintf(stderr, "%03d: kind=%d len=%d out=%d text=%d\n", i,
86 kind, CPP_WRITTEN(&parse_in), !opts->no_output, got_text);
123 fprintf(stderr, "'");
124 fwrite(parse_in.token_buffer, 1, CPP_WRITTEN(&parse_in), stderr);
125 fprintf(stderr, "'\n");
127 if (!opts->no_output)
131 n = CPP_WRITTEN(&parse_in);
132 if (fwrite(parse_in.token_buffer, 1, n, stdout) != n)
133 exit(FATAL_EXIT_CODE);
135 parse_in.limit = parse_in.token_buffer;
142 cpp_finish(&parse_in);
145 exit(FATAL_EXIT_CODE);
146 exit(SUCCESS_EXIT_CODE);