Annotation of OpenXM/src/asir-doc/html_tools/extract_func.c, Revision 1.1
1.1 ! noro 1: /* $OpenXM: OpenXM/src/asir99/doc/extract_func.c,v 1.1 1999/11/12 09:21:36 noro Exp $ */
! 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];
! 17: int i,j;
! 18:
! 19: if ( argc != 2 ) {
! 20: fprintf(stderr,"usage : extract_func infofile\n");
! 21: exit(0);
! 22: }
! 23: in = fopen(argv[1],"rb");
! 24: if ( !in ) {
! 25: fprintf(stderr,"%s : not found",argv[1]);
! 26: exit(0);
! 27: }
! 28: fp = 0;
! 29: while ( 1 ) {
! 30: c = getc(in);
! 31: if ( c == EOF )
! 32: exit(0);
! 33: else if ( !fp && c == '\n' )
! 34: continue;
! 35: ungetc(c,in);
! 36: fgets(buf,BUFSIZ,in);
! 37: if ( fname(buf,name) ) {
! 38: fgets(buf1,BUFSIZ,in);
! 39: for ( i = 0; buf1[i] && buf1[i] == '-'; i++ );
! 40: if ( i >= 3 && buf1[i] == '\n' ) {
! 41: fputs(buf,stderr);
! 42: strcpy(fn,name[0]);
! 43: fp = fopen(fn,"w");
! 44: for ( j = 1; name[j]; j++ )
! 45: symlink(fn,name[j]);
! 46: fputs(buf,fp);
! 47: fputs(buf1,fp);
! 48: } else if ( fp ) {
! 49: fputs(buf,fp);
! 50: if ( buf1[0] == 0x1f ) {
! 51: fclose(fp); fp = 0;
! 52: sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s",
! 53: name[0],name[0],name[0]);
! 54: system(cmd);
! 55: } else
! 56: fputs(buf1,fp);
! 57: }
! 58: } else if ( fp )
! 59: if ( buf[0] == 0x1f ) {
! 60: fclose(fp); fp = 0;
! 61: sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s",
! 62: fn,fn,fn,fn,fn);
! 63: system(cmd);
! 64: } else
! 65: fputs(buf,fp);
! 66: }
! 67: }
! 68:
! 69: int fname(buf,name)
! 70: char *buf;
! 71: char **name;
! 72: {
! 73: int i,len;
! 74: char *quote,*bquote,*comma;
! 75:
! 76: /* XXX */
! 77: if ( *buf != '`' )
! 78: return 0;
! 79:
! 80: i = 0;
! 81: while ( 1 ) {
! 82: /* search a back quote */
! 83: bquote = index(buf,'`' );
! 84: if ( !bquote )
! 85: return 0;
! 86: buf = bquote+1;
! 87:
! 88: /* buf points to a function; search a quote */
! 89: quote = index(buf,'\'');
! 90: if ( !quote )
! 91: return 0;
! 92: len = quote-buf;
! 93: name[i] = (char *)malloc(len+1);
! 94: strncpy(name[i],buf,len);
! 95: name[i][len] = 0;
! 96: i++;
! 97: buf = quote+1;
! 98: /* buf points to ',' or a space char; search a comma */
! 99: comma = index(buf,',');
! 100: if ( !comma ) {
! 101: /* if the rest chars include a non-space char, then return 0 */
! 102: while ( *buf && isspace(*buf) ) buf++;
! 103: if ( *buf )
! 104: return 0;
! 105: else {
! 106: name[i] = 0;
! 107: return 1;
! 108: }
! 109: }
! 110: }
! 111: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>