Annotation of OpenXM/src/asir-doc/extract_func.c, Revision 1.4
1.4 ! noro 1: /* $OpenXM: OpenXM/src/asir-doc/extract_func.c,v 1.3 2005/02/09 03:25:50 noro Exp $ */
1.1 noro 2:
3: #include <stdio.h>
4: #include <string.h>
5:
6: main(argc,argv)
7: int argc;
8: char **argv;
9: {
10: int c;
11: FILE *in,*fp;
12: char buf[BUFSIZ*100];
13: char buf1[BUFSIZ*100];
14: char *name[BUFSIZ];
15: char cmd[BUFSIZ];
16: char fn[BUFSIZ];
1.2 noro 17: char *file;
18: int jis;
1.1 noro 19: int i,j;
20:
1.2 noro 21: if ( (argc != 2) && (argc != 3) ) {
22: fprintf(stderr,"usage : extract_func [-j] infofile\n");
1.1 noro 23: exit(0);
24: }
1.2 noro 25: if ( argc == 3 ) {
26: jis = 1;
27: file = argv[2];
28: } else {
29: jis = 0;
30: file = argv[1];
31: }
32: in = fopen(file,"rb");
1.1 noro 33: if ( !in ) {
1.2 noro 34: fprintf(stderr,"%s : not found",file);
1.1 noro 35: exit(0);
36: }
37: fp = 0;
38: while ( 1 ) {
39: c = getc(in);
40: if ( c == EOF )
41: exit(0);
42: else if ( !fp && c == '\n' )
43: continue;
44: ungetc(c,in);
45: fgets(buf,BUFSIZ,in);
46: if ( fname(buf,name) ) {
47: fgets(buf1,BUFSIZ,in);
48: for ( i = 0; buf1[i] && buf1[i] == '-'; i++ );
49: if ( i >= 3 && buf1[i] == '\n' ) {
50: fputs(buf,stderr);
51: strcpy(fn,name[0]);
1.3 noro 52: create_dir(fn);
1.1 noro 53: fp = fopen(fn,"w");
54: for ( j = 1; name[j]; j++ )
55: symlink(fn,name[j]);
56: fputs(buf,fp);
57: fputs(buf1,fp);
58: } else if ( fp ) {
59: fputs(buf,fp);
60: if ( buf1[0] == 0x1f ) {
61: fclose(fp); fp = 0;
1.2 noro 62: if ( jis ) {
63: sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s",
64: name[0],name[0],name[0]);
65: system(cmd);
66: }
1.1 noro 67: } else
68: fputs(buf1,fp);
69: }
70: } else if ( fp )
71: if ( buf[0] == 0x1f ) {
72: fclose(fp); fp = 0;
1.2 noro 73: if ( jis ) {
74: sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s",
75: fn,fn,fn,fn,fn);
76: system(cmd);
77: }
1.1 noro 78: } else
79: fputs(buf,fp);
80: }
1.3 noro 81: }
82:
83: int create_dir(char *fname)
84: {
85: char *p;
86:
87: p = fname;
88: while ( *p && (p = strchr(p,'/')) ) {
89: *p = 0;
90: mkdir(fname,0755);
91: *p = '/';
92: p++;
93: }
94:
1.1 noro 95: }
96:
97: int fname(buf,name)
98: char *buf;
99: char **name;
100: {
101: int i,len;
1.4 ! noro 102: char *quote,*bquote,*comma,*space,*p;
1.1 noro 103:
1.4 ! noro 104: if ( *buf != '`' ) {
! 105: /* skip X.X.X if exists */
! 106: space = index(buf,' ');
! 107: if ( !space ) return 0;
! 108: for ( p = buf; p < space; p++ )
! 109: if ( !isdigit(*p) && *p != '.' ) return 0;
! 110: buf = space+1;
! 111: }
1.1 noro 112: i = 0;
113: while ( 1 ) {
114: /* search a back quote */
115: bquote = index(buf,'`' );
116: if ( !bquote )
117: return 0;
118: buf = bquote+1;
119:
120: /* buf points to a function; search a quote */
121: quote = index(buf,'\'');
122: if ( !quote )
123: return 0;
124: len = quote-buf;
125: name[i] = (char *)malloc(len+1);
126: strncpy(name[i],buf,len);
127: name[i][len] = 0;
128: i++;
129: buf = quote+1;
130: /* buf points to ',' or a space char; search a comma */
131: comma = index(buf,',');
132: if ( !comma ) {
133: /* if the rest chars include a non-space char, then return 0 */
134: while ( *buf && isspace(*buf) ) buf++;
135: if ( *buf )
136: return 0;
137: else {
138: name[i] = 0;
139: return 1;
140: }
141: }
142: }
143: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>