[BACK]Return to oxapp.c CVS log [TXT][DIR] Up to [local] / OpenXM / misc / packages / Windows

Annotation of OpenXM/misc/packages/Windows/oxapp.c, Revision 1.2

1.2     ! takayama    1: /* $OpenXM: OpenXM/misc/packages/Windows/oxapp.c,v 1.1 2002/01/06 08:47:36 takayama Exp $ */
1.1       takayama    2: #include <stdio.h>
                      3: #define LINESIZE 4096
                      4:
1.2     ! takayama    5: int ThereIsLoad = 0;
1.1       takayama    6: main(int argc,char *argv[]) {
                      7:   char s[LINESIZE];
1.2     ! takayama    8:   int i;
1.1       takayama    9:   int removeSharp = 0;
1.2     ! takayama   10:   int checkLoad = 0;
        !            11:   extern ThereIsLoad;
        !            12:   for (i=1; i<argc; i++) {
        !            13:        if (strcmp(argv[i],"--removeSharp") == 0) {
1.1       takayama   14:          removeSharp = 1;
1.2     ! takayama   15:        }else if (strcmp(argv[i],"--load") == 0) {
        !            16:          checkLoad = 1;
1.1       takayama   17:        }
                     18:   }
                     19:   while (fgets(s,LINESIZE,stdin) != NULL) {
                     20:        if (strlen(s) >= LINESIZE-1) {
                     21:          fprintf(stderr,"Too long line.\n");
                     22:          exit(20);
                     23:        }
                     24:        edit(s);
                     25:        if (removeSharp && s[0] == '#') {
                     26:          printf("\n");
                     27:        }else{
                     28:          printf("%s",s);
                     29:        }
                     30:   }
                     31:   if (removeSharp == 0) {
                     32:        printf("end$\n");
                     33:   }
1.2     ! takayama   34:   if (checkLoad) {
        !            35:        fprintf(stderr,"checkLoad status = %d\n",ThereIsLoad);
        !            36:        if (ThereIsLoad) exit(0);
        !            37:        else exit(1);
        !            38:   }
1.1       takayama   39: }
                     40:
                     41: edit(char s[]) {
                     42:   int k,i,j;
                     43:   char t[LINESIZE*2];
1.2     ! takayama   44:   extern int ThereIsLoad;
1.1       takayama   45:   if (strlen(s) == 0) return;
                     46:   t[0] = 0;
                     47:   if ((k = find(s,"load(")) >= 0) {
                     48:        if (k > 0 && not_separator(s[k-1]) ) return; /* bload */
                     49:        /* Heuristic 1 */
                     50:        if (k > 0) {
                     51:          if (s[0] == 'i' && s[1] == 'f') return; /* if ... load */
                     52:        }
                     53:        /* Heuristic 2.A.    load(User_asirrc)$ */
                     54:        if (find(s,"load(User_asirrc)")>=0) {
                     55:          s[0] = '\n'; s[1]=0;
                     56:          return;
                     57:        }
                     58:        /* Heuristic 2 */
                     59:        if (('A' <= s[k+5]) && (s[k+5] <= 'Z')) {
                     60:          return; /* load(User_asirrc) */
                     61:        }
                     62:        /* Heuristic 3. load("./"+Fname) in phc */
                     63:        if (find(s,"+Fname")>=0) return;
                     64:
                     65:        for (i=0; i<k; i++) {
                     66:          t[i] = s[i]; t[i+1] = 0;
                     67:        }
                     68:     strcat(t,"#include ");
1.2     ! takayama   69:        ThereIsLoad = 1;
1.1       takayama   70:        j=k+5;
                     71:        for (i=strlen(t); i<LINESIZE*2-1; ) {
                     72:          if (s[j] == 0) break;
                     73:          if (s[j] == ')' || s[j] == ';' || s[j] == '$')  {
                     74:                j += 1;
                     75:          }else{
                     76:                t[i] = s[j]; t[i+1] = 0;
                     77:                i++; j++;
                     78:          }
                     79:        }
                     80:        if (strlen(t) >= LINESIZE-1) {
                     81:          fprintf(stderr,"Too long string %s\n",t);
                     82:        }
                     83:        strcpy(s,t);
                     84:   }
                     85:   if ((k = find(s,"end$")) >= 0) {
                     86:        if (k > 0 && not_separator(s[k-1])) return;
                     87:     strcpy(s,"\n");
                     88:   }
                     89: }
                     90:
                     91: find(char *s,char *substr) {
                     92:   int n,m,i,j,k,k0;
                     93:   n = strlen(s);
                     94:   m = strlen(substr);
                     95:   k0 = -1; k = -1;
                     96:   for (i=0; i<n-m+1; i++) {
                     97:        k = i;
                     98:        for (j=0; j<m; j++) {
                     99:       if (s[i+j] != substr[j]) {
                    100:                k = -1; break;
                    101:          }
                    102:        }
                    103:     if (k >= 0 && k0 >= 0) {
                    104:          fprintf(stderr,"More than appearance of %s\n",substr);
                    105:          exit(20);
                    106:        }
                    107:        if (k >= 0) k0 = k;
                    108:   }
                    109:   return k0;
                    110: }
                    111:
                    112: not_separator(c) {
                    113:   if (c >='A' && c <='Z') return 1;
                    114:   if (c >='a' && c <='z') return 1;
                    115:   if (c >='0' && c <='9') return 1;
                    116:   if (c =='_') return 1;
                    117:   return 0;
                    118: }
                    119:

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