Subversion Repositories wimsdev

Rev

Rev 8353 | Rev 13380 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8353 Rev 12247
Line 25... Line 25...
25
 
25
 
26
#include "../Lib/libwims.h"
26
#include "../Lib/libwims.h"
27
#include "msg2wims.h"
27
#include "msg2wims.h"
28
 
28
 
29
struct {
29
struct {
30
    char *name;
30
  char *name;
31
    int serial;
31
  int serial;
32
    int type;
32
  int type;
33
} param[MAX_PARAM+32];
33
} param[MAX_PARAM+32];
34
 
34
 
35
char *inbuf;
35
char *inbuf;
36
FILE *inf, *outf;
36
FILE *inf, *outf;
37
int inlen=0,outlen=0;
37
int inlen=0,outlen=0;
Line 41... Line 41...
41
void internal_warn(char *p)
41
void internal_warn(char *p)
42
{}
42
{}
43
 
43
 
44
void get_inf(char *fname)
44
void get_inf(char *fname)
45
{
45
{
46
    int i,l;
46
  int i,l;
47
    inf=fopen(fname,"r");
47
  inf=fopen(fname,"r");
48
    if(inf==NULL) bailout(0,0,"");
48
  if(inf==NULL) bailout(0,0,"");
49
    fseek(inf,0,SEEK_END); l=ftell(inf); fseek(inf,0,SEEK_SET);
49
  fseek(inf,0,SEEK_END); l=ftell(inf); fseek(inf,0,SEEK_SET);
50
    if(l<=0) bailout(0,0,"");
50
  if(l<=0) bailout(0,0,"");
51
    inbuf=xmalloc(l+16);
51
  inbuf=xmalloc(l+16);
52
    l=fread(inbuf,1,l,inf);
52
  l=fread(inbuf,1,l,inf);
53
    if(l<=0) bailout(0,0,"error opening input file");
53
  if(l<=0) bailout(0,0,"error opening input file");
54
    else inbuf[l]=0;
54
  else inbuf[l]=0;
55
    fclose(inf); inlen=l;
55
  fclose(inf); inlen=l;
56
    for(i=0;i<l;i++)
56
  for(i=0;i<l;i++)
57
      if(inbuf[i]==elsechar || inbuf[i]==endifchar ||
57
    if(inbuf[i]==elsechar || inbuf[i]==endifchar ||
58
       inbuf[i]==nextchar || inbuf[i]==whilechar) inbuf[i]=' ';
58
     inbuf[i]==nextchar || inbuf[i]==whilechar) inbuf[i]=' ';
59
}
59
}
60
 
60
 
61
void open_outf(char *fname)
61
void open_outf(char *fname)
62
{
62
{
63
    outf=fopen(fname,"w");
63
  outf=fopen(fname,"w");
64
    if(outf==NULL) bailout(inlen,0,"error opening output file");
64
  if(outf==NULL) bailout(inlen,0,"error opening output file");
65
}
65
}
66
 
66
 
67
void process_formula(char *p)
67
void process_formula(char *p)
68
{
68
{
69
    char *p3, bf[MAX_LINELEN+1];
69
  char *p3, bf[MAX_LINELEN+1];
70
 
70
 
71
    if(strlen(p)>=MAX_LINELEN)
71
  if(strlen(p)>=MAX_LINELEN)
72
      bailout(inlen,0,"formula too long");
72
    bailout(inlen,0,"formula too long");
73
    while((p3=strstr(p,"&lt;"))!=NULL) memmove(p3," <  ",4);
73
  while((p3=strstr(p,"&lt;"))!=NULL) memmove(p3," <  ",4);
74
    while((p3=strstr(p,"&gt;"))!=NULL) memmove(p3," >  ",4);
74
  while((p3=strstr(p,"&gt;"))!=NULL) memmove(p3," >  ",4);
75
    for(p3=strchr(p,'\n'); p3!=NULL; p3=strchr(p3,'\n')) *p3=' ';
75
  for(p3=strchr(p,'\n'); p3!=NULL; p3=strchr(p3,'\n')) *p3=' ';
76
    snprintf(bf,sizeof(bf),"%s",p);
76
  snprintf(bf,sizeof(bf),"%s",p);
77
    if(strchr(bf,'\\')==NULL && strchr(bf,'}')==NULL && strlen(bf)>2) {
77
  if(strchr(bf,'\\')==NULL && strchr(bf,'}')==NULL && strlen(bf)>2) {
78
      for(p3=strstr(bf,".."); p3!=NULL; p3=strstr(p3,"..")) {
78
    for(p3=strstr(bf,".."); p3!=NULL; p3=strstr(p3,"..")) {
79
          if(*(p3+2)=='.' || *(p3+2)==',') {
79
      if(*(p3+2)=='.' || *(p3+2)==',') {
80
            do p3++; while(*p3=='.'); continue;
80
        do p3++; while(*p3=='.'); continue;
81
          }
-
 
82
          *p3=','; *(p3+1)=' ';
-
 
83
      }
81
      }
-
 
82
      *p3=','; *(p3+1)=' ';
84
    }
83
    }
-
 
84
  }
85
    fprintf(outf,"\n!insmath %s\n",bf);
85
  fprintf(outf,"\n!insmath %s\n",bf);
86
}
86
}
87
 
87
 
88
int main(int argc, char *argv[])
88
int main(int argc, char *argv[])
89
{
89
{
90
    char *p, *p1, *p2, *tend;
90
  char *p, *p1, *p2, *tend;
91
    sp_error=msg_error;
91
  sp_error=msg_error;
92
    string_modify=string_modify2;
92
  string_modify=string_modify2;
93
    substitute=substit;
93
  substitute=substit;
94
    if(argc==2 && strcmp(argv[1],"table")==0) {
94
  if(argc==2 && strcmp(argv[1],"table")==0) {
95
      if(verify_order(specialfn, specialfn_no, sizeof(specialfn[0]))) return -1;
95
    if(verify_order(specialfn, specialfn_no, sizeof(specialfn[0]))) return -1;
96
      puts("Table orders OK."); return 0;
96
    puts("Table orders OK."); return 0;
97
    }
97
  }
98
/* is defined in public_html/scripts/docu/mkindex and in public_html/modules/adm/doc/var.proc */
98
/* is defined in public_html/scripts/docu/mkindex and in public_html/modules/adm/doc/var.proc */
99
    p=getenv("w_msg2wims_primitives"); if(p!=NULL) {
99
  p=getenv("w_msg2wims_primitives"); if(p!=NULL) {
100
      snprintf(primbuf,sizeof(primbuf),"%s",p);
100
    snprintf(primbuf,sizeof(primbuf),"%s",p);
101
      for(p=primbuf; *p; p++) if(!isalnum(*p)) *p=' ';
101
    for(p=primbuf; *p; p++) if(!isalnum(*p)) *p=' ';
102
      p=find_word_start(primbuf);
102
    p=find_word_start(primbuf);
103
      for(primcnt=0; primcnt<256 && *p; primcnt++, p=find_word_start(p1)) {
103
    for(primcnt=0; primcnt<256 && *p; primcnt++, p=find_word_start(p1)) {
104
          p1=find_word_end(p); if(*p1) *p1++=0;
104
      p1=find_word_end(p); if(*p1) *p1++=0;
105
          primitive[primcnt]=p;
105
      primitive[primcnt]=p;
-
 
106
    }
-
 
107
    if(primcnt>0) qsort(primitive,primcnt,sizeof(primitive[0]),_scmp);
-
 
108
  }
-
 
109
  if(argc<3) bailout(0,0,"missing file names");
-
 
110
  p1=argv[1]; p2=argv[2];
-
 
111
  get_inf(p1); open_outf(p2);
-
 
112
  for(p=tend=inbuf;*p;p++) {
-
 
113
    switch(*p) {
-
 
114
      case '$': fputs("&#36;",outf); break;
-
 
115
      case '!': fputs("&#33;",outf); break;
-
 
116
      case ':': fputs("&#58;",outf); break;
-
 
117
 
-
 
118
      case elsechar: {
-
 
119
        if(primcnt>0) fputs("\n!else\n",outf);
-
 
120
        else fputc(*p,outf);
-
 
121
        break;
-
 
122
      }
-
 
123
      case endifchar: {
-
 
124
        if(primcnt>0) fputs("\n!endif\n",outf);
-
 
125
        else fputc(*p,outf);
-
 
126
        break;
106
      }
127
      }
107
      if(primcnt>0) qsort(primitive,primcnt,sizeof(primitive[0]),_scmp);
-
 
108
    }
-
 
109
    if(argc<3) bailout(0,0,"missing file names");
-
 
110
    p1=argv[1]; p2=argv[2];
-
 
111
    get_inf(p1); open_outf(p2);
-
 
112
    for(p=tend=inbuf;*p;p++) {
-
 
113
      switch(*p) {
-
 
114
          case '$': fputs("&#36;",outf); break;
-
 
115
          case '!': fputs("&#33;",outf); break;
-
 
116
          case ':': fputs("&#58;",outf); break;
-
 
117
 
-
 
118
          case elsechar: {
128
      case nextchar: {
119
            if(primcnt>0) fputs("\n!else\n",outf);
129
        if(primcnt>0) fputs("\n!next\n",outf);
120
            else fputc(*p,outf);
130
        else fputc(*p,outf);
121
            break;
131
        break;
122
          }
132
      }
123
          case endifchar: {
133
      case whilechar: {
124
            if(primcnt>0) fputs("\n!endif\n",outf);
134
        if(primcnt>0) fputs("\n!endwhile\n",outf);
125
            else fputc(*p,outf);
135
        else fputc(*p,outf);
126
            break;
136
        break;
127
          }
137
      }
-
 
138
/* lines begining by > are in small; italics and pre  */
128
          case nextchar: {
139
      case '\n': {
-
 
140
        if(*(p+1)=='>') {
129
            if(primcnt>0) fputs("\n!next\n",outf);
141
          pre: p++; fputs("\n<i><small><pre wrap>",outf);
130
            else fputc(*p,outf);
142
          for(p1=strchr(p,'\n'); p1!=NULL && *(p1+1)=='>';
131
            break;
143
          p1=strchr(++p1,'\n'));
132
          }
144
          if(p1!=NULL) *p1++=0; else p1=p+strlen(p);
133
          case whilechar: {
145
          for(p2=p;*p2;p2++) {
134
            if(primcnt>0) fputs("\n!endwhile\n",outf);
146
            if(*p2!='<') fputc(*p2,outf);
135
            else fputc(*p,outf);
147
            else fputs("&lt;",outf);
136
            break;
-
 
137
          }
148
          }
138
/* lines begining by > are in small; italics and pre  */
-
 
139
          case '\n': {
-
 
140
            if(*(p+1)=='>') {
-
 
141
                pre: p++; fputs("\n<i><small><pre wrap>",outf);
-
 
142
                for(p1=strchr(p,'\n'); p1!=NULL && *(p1+1)=='>';
-
 
143
                  p1=strchr(++p1,'\n'));
-
 
144
                if(p1!=NULL) *p1++=0; else p1=p+strlen(p);
-
 
145
                for(p2=p;*p2;p2++) {
-
 
146
                  if(*p2!='<') fputc(*p2,outf);
-
 
147
                  else fputs("&lt;",outf);
-
 
148
                }
-
 
149
                fputs("</pre></small></i>\n",outf);
149
          fputs("</pre></small></i>\n",outf);
150
                p=p1-1; break;
150
          p=p1-1; break;
151
            }
151
        }
152
/* two successive lines are replaced by an <p> - has to be fixed */
152
/* two successive lines are replaced by an <p> - has to be fixed */
153
            if(*(p+1)!='\n') {fputc(*p,outf);break;}
153
        if(*(p+1)!='\n') {fputc(*p,outf);break;}
154
            p++; fputs("\n<br/>\n",outf);
154
        p++; fputs("\n<br/>\n",outf);
155
            while(*(p+1)=='\n') p++;
155
        while(*(p+1)=='\n') p++;
156
            if(*(p+1)=='>') goto pre;
156
        if(*(p+1)=='>') goto pre;
157
            break;
157
        break;
158
          }
158
      }
159
 
159
 
160
          case '<': {
160
      case '<': {
161
            char *p2;
161
        char *p2;
162
            if(tend>p || (!isalpha(*(p+1)) && *(p+1)!='!')) {
162
        if(tend>p || (!isalpha(*(p+1)) && *(p+1)!='!')) {
163
                fputc(*p,outf); break;
163
          fputc(*p,outf); break;
164
            }
164
        }
165
            p2=find_tag_end(p);
165
        p2=find_tag_end(p);
166
            if(!*p2) {msg_error("open_tag"); p2--;}
166
        if(!*p2) {msg_error("open_tag"); p2--;}
167
            tend=p2;
167
        tend=p2;
168
            fputc(*p, outf); break;
168
        fputc(*p, outf); break;
169
          }
169
      }
170
/* interpretation of variables */
170
/* interpretation of variables */
171
          case '\\': {
171
      case '\\': {
172
            char *pe;
172
       char *pe;
173
            p++;
173
        p++;
174
            if(isalpha(*p)) {
174
        if(isalpha(*p)) {
175
                if(primcnt>0) {
175
           if(primcnt>0) {
176
                  pe=doccheck(p);
176
             pe=doccheck(p);
177
                  if(pe>p) {p=pe-1; break;}
177
             if(pe>p) {p=pe-1; break;}
178
                }
178
           }
179
                for(pe=p;isalnum(*pe) || *pe=='_';pe++);
179
           for(pe=p;isalnum(*pe) || *pe=='_';pe++);
180
                if(*pe=='[') {
180
           if(*pe=='[') {
181
                  char *pv=find_matching(pe+1,']');
181
             char *pv=find_matching(pe+1,']');
182
                  if(pv!=NULL) {
182
             if(pv!=NULL) {
183
                      char c=*p;
183
               char c=*p;
184
                      memmove(p,p+1,pv-p); *pv=')';
184
               memmove(p,p+1,pv-p); *pv=')';
185
                      fprintf(outf,"$(m_%c",c); p--; break;
185
               fprintf(outf,"$(m_%c",c); p--; break;
186
                  }
186
             }
187
                }
187
           }
188
                fprintf(outf,"$m_%c",*p); break;
188
           fprintf(outf,"$m_%c",*p); break;
189
            }
189
        }
190
            switch(*p) {
190
        switch(*p) {
191
                case '\\': fputc(*p,outf); break;
191
          case '\\': fputc(*p,outf); break;
192
                case '{':
192
          case '{':
193
                case '(': {
193
          case '(': {
194
                  char *p2, *p3, c;
194
            char *p2, *p3, c;
195
                  if(*p=='{') c='}'; else c=')';
195
            if(*p=='{') c='}'; else c=')';
196
                        p++; p2=find_matching(p,c);
196
            p++; p2=find_matching(p,c);
197
                  if(c==')') p3=strstr(p,"\\)");
197
            if(c==')') p3=strstr(p,"\\)");
198
                  else p3=strstr(p,"\\}");
198
            else p3=strstr(p,"\\}");
199
                  if((p2==NULL && p3!=NULL) ||
199
            if((p2==NULL && p3!=NULL) ||
200
                     (p2!=NULL && p3!=NULL && p3<p2)) p2=p3+1;
200
               (p2!=NULL && p3!=NULL && p3<p2)) p2=p3+1;
201
                  if(p2==NULL) fputc(*p,outf);
201
              if(p2==NULL) fputc(*p,outf);
202
                  else {
202
            else {
203
                      *p2=0; if(*(p2-1)=='\\') *(p2-1)=0;
203
              *p2=0; if(*(p2-1)=='\\') *(p2-1)=0;
204
                      process_formula(p); p=p2;
204
              process_formula(p); p=p2;
205
                  }
-
 
206
                  break;
-
 
207
                }
-
 
208
                default: fputc(*p,outf); break;
-
 
209
            }
205
            }
210
            break;
206
            break;
211
          }
207
          }
212
 
-
 
213
          default: fputc(*p,outf); break;
208
          default: fputc(*p,outf); break;
-
 
209
        }
-
 
210
        break;
214
      }
211
      }
-
 
212
 
-
 
213
      default: fputc(*p,outf); break;
215
    }
214
    }
-
 
215
  }
216
    fputc('\n',outf);
216
  fputc('\n',outf);
217
    outlen=ftell(outf);  fclose(outf); bailout(inlen,outlen,"");
217
  outlen=ftell(outf);  fclose(outf); bailout(inlen,outlen,"");
218
    return 0;
218
  return 0;
219
}
219
}