version 1.1, 2002/01/06 08:47:36 |
version 1.3, 2002/01/16 06:47:19 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/misc/packages/Windows/oxapp.c,v 1.2 2002/01/10 03:55:10 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#define LINESIZE 4096 |
#define LINESIZE 4096 |
|
|
|
int ThereIsLoad = 0; |
main(int argc,char *argv[]) { |
main(int argc,char *argv[]) { |
char s[LINESIZE]; |
char s[LINESIZE]; |
|
int i; |
int removeSharp = 0; |
int removeSharp = 0; |
if (argc > 1) { |
int checkLoad = 0; |
if (strcmp(argv[1],"--removeSharp") == 0) { |
extern ThereIsLoad; |
removeSharp = 1; |
for (i=1; i<argc; i++) { |
} |
if (strcmp(argv[i],"--removeSharp") == 0) { |
|
removeSharp = 1; |
|
}else if (strcmp(argv[i],"--load") == 0) { |
|
checkLoad = 1; |
|
} |
} |
} |
while (fgets(s,LINESIZE,stdin) != NULL) { |
while (fgets(s,LINESIZE,stdin) != NULL) { |
if (strlen(s) >= LINESIZE-1) { |
if (strlen(s) >= LINESIZE-1) { |
fprintf(stderr,"Too long line.\n"); |
fprintf(stderr,"Too long line.\n"); |
exit(20); |
exit(20); |
} |
} |
edit(s); |
edit(s); |
if (removeSharp && s[0] == '#') { |
if (removeSharp && s[0] == '#') { |
printf("\n"); |
printf("\n"); |
}else{ |
}else{ |
printf("%s",s); |
printf("%s",s); |
} |
} |
} |
} |
if (removeSharp == 0) { |
if (removeSharp == 0) { |
printf("end$\n"); |
printf("end$\n"); |
} |
} |
|
if (checkLoad) { |
|
fprintf(stderr,"checkLoad status = %d\n",ThereIsLoad); |
|
if (ThereIsLoad) exit(0); |
|
else exit(1); |
|
} |
} |
} |
|
|
edit(char s[]) { |
edit(char s[]) { |
int k,i,j; |
int k,i,j; |
char t[LINESIZE*2]; |
char t[LINESIZE*2]; |
|
extern int ThereIsLoad; |
if (strlen(s) == 0) return; |
if (strlen(s) == 0) return; |
t[0] = 0; |
t[0] = 0; |
if ((k = find(s,"load(")) >= 0) { |
if ((k = find(s,"load(")) >= 0) { |
if (k > 0 && not_separator(s[k-1]) ) return; /* bload */ |
if (k > 0 && not_separator(s[k-1]) ) return; /* bload */ |
/* Heuristic 1 */ |
/* Heuristic 1 */ |
if (k > 0) { |
if (k > 0) { |
if (s[0] == 'i' && s[1] == 'f') return; /* if ... load */ |
if (s[0] == 'i' && s[1] == 'f') return; /* if ... load */ |
} |
} |
/* Heuristic 2.A. load(User_asirrc)$ */ |
/* Heuristic 2.A. load(User_asirrc)$ */ |
if (find(s,"load(User_asirrc)")>=0) { |
if (find(s,"load(User_asirrc)")>=0) { |
s[0] = '\n'; s[1]=0; |
s[0] = '\n'; s[1]=0; |
return; |
return; |
} |
} |
/* Heuristic 2 */ |
/* Heuristic 2 */ |
if (('A' <= s[k+5]) && (s[k+5] <= 'Z')) { |
if (('A' <= s[k+5]) && (s[k+5] <= 'Z')) { |
return; /* load(User_asirrc) */ |
return; /* load(User_asirrc) */ |
} |
} |
/* Heuristic 3. load("./"+Fname) in phc */ |
/* Heuristic 3. load("./"+Fname) in phc */ |
if (find(s,"+Fname")>=0) return; |
if (find(s,"+Fname")>=0) return; |
|
|
for (i=0; i<k; i++) { |
for (i=0; i<k; i++) { |
t[i] = s[i]; t[i+1] = 0; |
t[i] = s[i]; t[i+1] = 0; |
} |
} |
strcat(t,"#include "); |
strcat(t,"#include "); |
j=k+5; |
ThereIsLoad = 1; |
for (i=strlen(t); i<LINESIZE*2-1; ) { |
j=k+5; |
if (s[j] == 0) break; |
for (i=strlen(t); i<LINESIZE*2-1; ) { |
if (s[j] == ')' || s[j] == ';' || s[j] == '$') { |
if (s[j] == 0) break; |
j += 1; |
if (s[j] == ')' || s[j] == ';' || s[j] == '$') { |
}else{ |
j += 1; |
t[i] = s[j]; t[i+1] = 0; |
}else{ |
i++; j++; |
t[i] = s[j]; t[i+1] = 0; |
} |
i++; j++; |
} |
} |
if (strlen(t) >= LINESIZE-1) { |
} |
fprintf(stderr,"Too long string %s\n",t); |
if (strlen(t) >= LINESIZE-1) { |
} |
fprintf(stderr,"Too long string %s\n",t); |
strcpy(s,t); |
} |
|
strcpy(s,t); |
} |
} |
if ((k = find(s,"end$")) >= 0) { |
if ((k = find(s,"end$")) >= 0) { |
if (k > 0 && not_separator(s[k-1])) return; |
if (k > 0 && not_separator(s[k-1])) return; |
strcpy(s,"\n"); |
strcpy(s,"\n"); |
} |
} |
} |
} |
Line 81 find(char *s,char *substr) { |
|
Line 94 find(char *s,char *substr) { |
|
m = strlen(substr); |
m = strlen(substr); |
k0 = -1; k = -1; |
k0 = -1; k = -1; |
for (i=0; i<n-m+1; i++) { |
for (i=0; i<n-m+1; i++) { |
k = i; |
k = i; |
for (j=0; j<m; j++) { |
for (j=0; j<m; j++) { |
if (s[i+j] != substr[j]) { |
if (s[i+j] != substr[j]) { |
k = -1; break; |
k = -1; break; |
} |
} |
} |
} |
if (k >= 0 && k0 >= 0) { |
if (k >= 0 && k0 >= 0) { |
fprintf(stderr,"More than appearance of %s\n",substr); |
fprintf(stderr,"More than one appearances of %s\n",substr); |
exit(20); |
exit(20); |
} |
} |
if (k >= 0) k0 = k; |
if (k >= 0) k0 = k; |
} |
} |
return k0; |
return k0; |
} |
} |