version 1.1.1.1, 1999/12/08 05:47:43 |
version 1.7, 2016/08/29 04:56:58 |
|
|
/* $OpenXM: OpenXM/src/asir99/doc/extract_func.c,v 1.1 1999/11/12 09:21:36 noro Exp $ */ |
/* $OpenXM: OpenXM/src/asir-doc/extract_func.c,v 1.6 2009/02/22 20:27:25 ohara Exp $ */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
|
#include <stdlib.h> |
|
#include <unistd.h> |
|
#include <ctype.h> |
|
#include <sys/stat.h> |
|
|
|
#if defined(__MINGW32__) |
|
#include <io.h> |
|
#define mkdir(d,m) ((mkdir)((d))) |
|
#endif |
|
|
|
void create_dir(char *); |
|
int fname(char *,char **); |
|
|
|
int |
main(argc,argv) |
main(argc,argv) |
int argc; |
int argc; |
char **argv; |
char **argv; |
|
|
char *name[BUFSIZ]; |
char *name[BUFSIZ]; |
char cmd[BUFSIZ]; |
char cmd[BUFSIZ]; |
char fn[BUFSIZ]; |
char fn[BUFSIZ]; |
|
char *file; |
|
int jis; |
int i,j; |
int i,j; |
|
|
if ( argc != 2 ) { |
if ( (argc != 2) && (argc != 3) ) { |
fprintf(stderr,"usage : extract_func infofile\n"); |
fprintf(stderr,"usage : extract_func [-j] infofile\n"); |
exit(0); |
exit(0); |
} |
} |
in = fopen(argv[1],"rb"); |
if ( argc == 3 ) { |
|
jis = 1; |
|
file = argv[2]; |
|
} else { |
|
jis = 0; |
|
file = argv[1]; |
|
} |
|
in = fopen(file,"rb"); |
if ( !in ) { |
if ( !in ) { |
fprintf(stderr,"%s : not found",argv[1]); |
fprintf(stderr,"%s : not found",file); |
exit(0); |
exit(0); |
} |
} |
fp = 0; |
fp = 0; |
|
|
if ( i >= 3 && buf1[i] == '\n' ) { |
if ( i >= 3 && buf1[i] == '\n' ) { |
fputs(buf,stderr); |
fputs(buf,stderr); |
strcpy(fn,name[0]); |
strcpy(fn,name[0]); |
|
create_dir(fn); |
fp = fopen(fn,"w"); |
fp = fopen(fn,"w"); |
for ( j = 1; name[j]; j++ ) |
for ( j = 1; name[j]; j++ ) |
symlink(fn,name[j]); |
symlink(fn,name[j]); |
|
|
fputs(buf,fp); |
fputs(buf,fp); |
if ( buf1[0] == 0x1f ) { |
if ( buf1[0] == 0x1f ) { |
fclose(fp); fp = 0; |
fclose(fp); fp = 0; |
sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s", |
if ( jis ) { |
name[0],name[0],name[0]); |
sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s", |
system(cmd); |
name[0],name[0],name[0]); |
|
system(cmd); |
|
} |
} else |
} else |
fputs(buf1,fp); |
fputs(buf1,fp); |
} |
} |
} else if ( fp ) |
} else if ( fp ) { |
if ( buf[0] == 0x1f ) { |
if ( buf[0] == 0x1f ) { |
fclose(fp); fp = 0; |
fclose(fp); fp = 0; |
sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s", |
if ( jis ) { |
fn,fn,fn,fn,fn); |
sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s", |
system(cmd); |
fn,fn,fn,fn,fn); |
} else |
system(cmd); |
|
} |
|
} else { |
fputs(buf,fp); |
fputs(buf,fp); |
|
} |
|
} |
} |
} |
} |
} |
|
|
|
void create_dir(char *fname) |
|
{ |
|
char *p; |
|
|
|
p = fname; |
|
while ( *p && (p = strchr(p,'/')) ) { |
|
*p = 0; |
|
mkdir(fname,0755); |
|
*p = '/'; |
|
p++; |
|
} |
|
|
|
} |
|
|
int fname(buf,name) |
int fname(buf,name) |
char *buf; |
char *buf; |
char **name; |
char **name; |
{ |
{ |
int i,len; |
int i,len; |
char *quote,*bquote,*comma; |
char *quote,*bquote,*comma,*space,*p; |
|
|
/* XXX */ |
if ( *buf != '`' ) { |
if ( *buf != '`' ) |
/* skip X.X.X if exists */ |
return 0; |
space = strchr(buf,' '); |
|
if ( !space ) return 0; |
|
for ( p = buf; p < space; p++ ) |
|
if ( !isdigit(*p) && *p != '.' ) return 0; |
|
buf = space+1; |
|
} |
i = 0; |
i = 0; |
while ( 1 ) { |
while ( 1 ) { |
/* search a back quote */ |
/* makeinfo v5 outputs 'fname', while makeinfo v4 output `fname' */ |
bquote = index(buf,'`' ); |
/* search a (back) quote */ |
|
bquote = strchr(buf,'`' ); |
if ( !bquote ) |
if ( !bquote ) |
return 0; |
bquote = strchr(buf,'\''); |
|
if ( !bquote ) return 0; |
buf = bquote+1; |
buf = bquote+1; |
|
|
/* buf points to a function; search a quote */ |
/* buf points to a function; search a quote */ |
quote = index(buf,'\''); |
quote = strchr(buf,'\''); |
if ( !quote ) |
if ( !quote ) |
return 0; |
return 0; |
len = quote-buf; |
len = quote-buf; |
|
|
i++; |
i++; |
buf = quote+1; |
buf = quote+1; |
/* buf points to ',' or a space char; search a comma */ |
/* buf points to ',' or a space char; search a comma */ |
comma = index(buf,','); |
comma = strchr(buf,','); |
if ( !comma ) { |
if ( !comma ) { |
/* if the rest chars include a non-space char, then return 0 */ |
/* if the rest chars include a non-space char, then return 0 */ |
while ( *buf && isspace(*buf) ) buf++; |
while ( *buf && isspace(*buf) ) buf++; |