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