[BACK]Return to extract_func.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc

Annotation of OpenXM/src/asir-doc/extract_func.c, Revision 1.2

1.2     ! noro        1: /* $OpenXM: OpenXM/src/asir-doc/extract_func.c,v 1.1.1.1 1999/12/08 05:47:43 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]);
                     52:                                fp = fopen(fn,"w");
                     53:                                for ( j = 1; name[j]; j++ )
                     54:                                        symlink(fn,name[j]);
                     55:                                fputs(buf,fp);
                     56:                                fputs(buf1,fp);
                     57:                        } else if ( fp ) {
                     58:                                fputs(buf,fp);
                     59:                                if ( buf1[0] == 0x1f ) {
                     60:                                        fclose(fp); fp = 0;
1.2     ! noro       61:                                        if ( jis ) {
        !            62:                                                sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s",
        !            63:                                                        name[0],name[0],name[0]);
        !            64:                                                system(cmd);
        !            65:                                        }
1.1       noro       66:                                } else
                     67:                                        fputs(buf1,fp);
                     68:                        }
                     69:                } else if ( fp )
                     70:                        if ( buf[0] == 0x1f ) {
                     71:                                fclose(fp); fp = 0;
1.2     ! noro       72:                                if ( jis ) {
        !            73:                                        sprintf(cmd,"nkf %s > %s.tmp; rm -f %s; mv %s.tmp %s",
        !            74:                                                fn,fn,fn,fn,fn);
        !            75:                                        system(cmd);
        !            76:                                }
1.1       noro       77:                        } else
                     78:                                fputs(buf,fp);
                     79:        }
                     80: }
                     81:
                     82: int fname(buf,name)
                     83: char *buf;
                     84: char **name;
                     85: {
                     86:        int i,len;
                     87:        char *quote,*bquote,*comma;
                     88:
                     89:        /* XXX */
                     90:        if ( *buf != '`' )
                     91:                return 0;
                     92:
                     93:        i = 0;
                     94:        while ( 1 ) {
                     95:                /* search a back quote */
                     96:                bquote = index(buf,'`' );
                     97:                if ( !bquote )
                     98:                        return 0;
                     99:                buf = bquote+1;
                    100:
                    101:                /* buf points to a function; search a quote */
                    102:                quote = index(buf,'\'');
                    103:                if ( !quote )
                    104:                        return 0;
                    105:                len = quote-buf;
                    106:                name[i] = (char *)malloc(len+1);
                    107:                strncpy(name[i],buf,len);
                    108:                name[i][len] = 0;
                    109:                i++;
                    110:                buf = quote+1;
                    111:                /* buf points to ',' or a space char; search a comma */
                    112:                comma = index(buf,',');
                    113:                if ( !comma ) {
                    114:                        /* if the rest chars include a non-space char, then return 0 */
                    115:                        while ( *buf && isspace(*buf) ) buf++;
                    116:                        if ( *buf )
                    117:                                return 0;
                    118:                        else {
                    119:                                name[i] = 0;
                    120:                                return 1;
                    121:                        }
                    122:                }
                    123:        }
                    124: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>