Annotation of OpenXM/src/asir-doc/extract_func.c, Revision 1.3
1.3 ! noro 1: /* $OpenXM: OpenXM/src/asir-doc/extract_func.c,v 1.2 2000/01/20 03:26:22 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;
102: char *quote,*bquote,*comma;
103:
104: /* XXX */
105: if ( *buf != '`' )
106: return 0;
107:
108: i = 0;
109: while ( 1 ) {
110: /* search a back quote */
111: bquote = index(buf,'`' );
112: if ( !bquote )
113: return 0;
114: buf = bquote+1;
115:
116: /* buf points to a function; search a quote */
117: quote = index(buf,'\'');
118: if ( !quote )
119: return 0;
120: len = quote-buf;
121: name[i] = (char *)malloc(len+1);
122: strncpy(name[i],buf,len);
123: name[i][len] = 0;
124: i++;
125: buf = quote+1;
126: /* buf points to ',' or a space char; search a comma */
127: comma = index(buf,',');
128: if ( !comma ) {
129: /* if the rest chars include a non-space char, then return 0 */
130: while ( *buf && isspace(*buf) ) buf++;
131: if ( *buf )
132: return 0;
133: else {
134: name[i] = 0;
135: return 1;
136: }
137: }
138: }
139: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>