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