oga's tools
修訂 | 1a9aa91c35b8f69631392402d6cc73efc1c75f5e (tree) |
---|---|
時間 | 2013-12-29 22:00:39 |
作者 | oga <oga@mxg....> |
Commiter | oga |
add comdel.c
@@ -19,7 +19,7 @@ TARGETS=$(VP)/age $(VP)/cal2 $(VP)/cgrep $(VP)/cmem $(VP)/cpkt $(VP)/cpuid \ | ||
19 | 19 | $(VP)/sosu $(VP)/sosum $(VP)/stat $(VP)/stereo3d $(VP)/strftime \ |
20 | 20 | $(VP)/subdecode $(VP)/sysinfd $(VP)/tbl2csv $(VP)/tcpan $(VP)/tcpdmpan \ |
21 | 21 | $(VP)/test64 $(VP)/train $(VP)/u2dos $(VP)/ifchk $(VP)/ifchk2 $(VP)/rand \ |
22 | - $(VP)/base64 $(VP)/ht $(VP)/filer | |
22 | + $(VP)/base64 $(VP)/ht $(VP)/filer $(VP)/comdel | |
23 | 23 | |
24 | 24 | all: $(TARGETS) |
25 | 25 |
@@ -44,6 +44,9 @@ $(VP)/cgrep : $(TOOL)/cgrep.c | ||
44 | 44 | $(VP)/cmem : $(TOOL)/cmem.c |
45 | 45 | ${CC} $? -o $@ -O |
46 | 46 | |
47 | +$(VP)/comdel : $(TOOL)/comdel.c | |
48 | + ${CC} $? -o $@ -O | |
49 | + | |
47 | 50 | $(VP)/cpkt : $(TOOL)/cpkt.c |
48 | 51 | ${CC} $? -o $@ -O |
49 | 52 |
@@ -0,0 +1,65 @@ | ||
1 | +/******************************************************************** | |
2 | + * comment delete filter by Hyper halx.oga * | |
3 | + * 199X.XX.XX first version * | |
4 | + * 1994.09.20 add stdin/filename * | |
5 | + * 1995.05.11 add error line * | |
6 | + * * | |
7 | + * usage : cat filename | comdel * | |
8 | + * comdel [filename] * | |
9 | + ********************************************************************/ | |
10 | +#include <stdio.h> | |
11 | +#include <stdlib.h> | |
12 | +#include <string.h> | |
13 | + | |
14 | +#define LINEUP(z) if (z == '\n') ++line | |
15 | + | |
16 | +main(a,b) | |
17 | +int a; | |
18 | +char *b[]; | |
19 | +{ | |
20 | + FILE *fpin; | |
21 | + | |
22 | + char xx[3]; /* char xx[2]; */ | |
23 | + int c; | |
24 | + int i, j, line=1, saveline; | |
25 | + | |
26 | + if (a == 1) | |
27 | + fpin = stdin; | |
28 | + else { | |
29 | + if ((fpin = fopen(b[1],"r")) == NULL) { | |
30 | + perror("comdel"); | |
31 | + exit(1); | |
32 | + } | |
33 | + | |
34 | + } | |
35 | + xx[2] = '\0'; /**/ | |
36 | + xx[0] = getc(fpin); | |
37 | + LINEUP(xx[0]); | |
38 | + xx[1] = getc(fpin); | |
39 | + LINEUP(xx[1]); | |
40 | + while (xx[1] != EOF) { | |
41 | + if (strcmp(xx,"/*") == 0 ) { | |
42 | + saveline = line; | |
43 | + putchar(xx[0]); | |
44 | + putchar(xx[1]); | |
45 | + while(strcmp(xx,"*/") != 0) { | |
46 | + xx[0] = xx[1]; | |
47 | + if ((xx[1] = getc(fpin)) == EOF ) { | |
48 | + putchar('\n'); | |
49 | + if (a == 1) | |
50 | + fprintf(stderr, "*** Error : comment not closed. (line=%d) *** \n",saveline); | |
51 | + else | |
52 | + fprintf(stderr, "*** Error : comment not closed. (line=%d) *** (%s)\n",saveline,b[1]); | |
53 | + exit(1); | |
54 | + } | |
55 | + LINEUP(xx[1]); | |
56 | + } | |
57 | + } | |
58 | + putchar(xx[0]); | |
59 | + xx[0] = xx[1]; | |
60 | + xx[1] = getc(fpin); | |
61 | + LINEUP(xx[1]); | |
62 | + } | |
63 | + putchar(xx[0]); | |
64 | + exit(0); | |
65 | +} |