Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/pax/nocom.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1987-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
/*
23
* Glenn Fowler
24
* AT&T Research
25
*
26
* nocom [file ...]
27
*
28
* nocom -- strip comments from C source files
29
*/
30
31
static const char usage[] =
32
"[-?\n@(#)$Id: nocom (AT&T Research) 1994-01-11 $\n]"
33
USAGE_LICENSE
34
"[+NAME?nocom - strip comments from C source files]"
35
"[+DESCRIPTION?\bnocom\b strips \b// ...\b and \b/* ... */\b comments from"
36
" each C source \afile\a and writes the result on the standard output."
37
" Comments that span multiple lines are replaced by \bnewline\b"
38
" characters to retain the original source line numbering. If \afile\a"
39
" is omitted then the standard input is read.]"
40
41
"\n"
42
"\n[ file ... ]\n"
43
"\n"
44
45
"[+SEE ALSO?\bcc\b(1), \bwc\b(1)]"
46
;
47
48
#include <ast.h>
49
#include <error.h>
50
51
#include "nocomment.c"
52
53
int
54
main(int argc, char** argv)
55
{
56
register char* s;
57
register Sfio_t* sp;
58
59
NoP(argc);
60
error_info.id = "nocom";
61
for (;;)
62
{
63
switch (optget(argv, usage))
64
{
65
case '?':
66
error(ERROR_USAGE|4, "%s", opt_info.arg);
67
break;
68
case ':':
69
error(2, "%s", opt_info.arg);
70
break;
71
}
72
break;
73
}
74
argv += opt_info.index;
75
if (error_info.errors)
76
error(ERROR_USAGE|4, "%s", optusage(NiL));
77
if (!*argv)
78
{
79
if (nocomment(sfstdin, sfstdout) < 0)
80
error(ERROR_SYSTEM|2, "write error");
81
}
82
else while (s = *argv++)
83
{
84
if (!(sp = sfopen(NiL, s, "r")))
85
error(ERROR_SYSTEM|2, "%s: cannot read", s);
86
else
87
{
88
if (nocomment(sp, sfstdout) < 0)
89
error(ERROR_SYSTEM|2, "%s: write error", s);
90
sfclose(sp);
91
}
92
}
93
return error_info.errors != 0;
94
}
95
96