int main(int argc, char *argv[]) { int ofd = 1; int i = 1; char *s1, *s2; int len = 0; char *cbuf; int clen; while (i < argc && argv[i][0] == '-') { if (argv[i][1] == 'I') cpp_addpath(argv[i][2] ? argv[i] + 2 : argv[++i]); if (argv[i][1] == 'D') { char *name = argv[i] + 2; char *def = ""; char *eq = strchr(name, '='); if (eq) { *eq = '\0'; def = eq + 1; } cpp_define(name, def); } i++; } if (i + 1 >= argc) { printf("usage: npp [-I idir] [-D define] input output\n"); return 0; } if (cpp_init(argv[i++])) die("npp: cannot open <%s>\n", argv[i - 1]); ofd = open(argv[i++], O_WRONLY | O_TRUNC | O_CREAT, 0600); if (ofd < 0) die("npp: cannot open <%s>\n", argv[i - 1]); s1 = malloc(OBUFSZ); s2 = malloc(OBUFSZ); if (!s1 || !s2) die("npp: cannot allocate enough memory\n"); while (!cpp_read(&cbuf, &clen)) { memcpy(s1 + len, cbuf, clen); len += clen; } len = rmcomments(s2, s1, len); xwrite(ofd, s2, len); close(ofd); return 0; }
static int __init link_init(void) { return cpp_init(); }