|
|
1.1 root 1: /* baja.c */
2:
3: /* Synchronet command shell/module compiler */
4:
5: /* $Id: baja.c,v 1.42 2006/12/19 21:43:16 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: /* OS-specific */
39: #ifndef __unix__
40: #include <io.h>
41: #include <share.h>
42: #endif
43: #ifdef _WIN32
44: #include <windows.h>
45: #endif
46:
47: /* ANSI */
48: #include <stdio.h>
49: #include <string.h>
50: #include <ctype.h>
51: #include <fcntl.h>
52: #include <errno.h>
53:
54: /* Synchronet-specific */
55: #include "cmdshell.h"
56: #include "ars_defs.h"
57: #include "crc32.h"
58: #include "genwrap.h" /* portability wrappers */
59: #include "dirwrap.h" /* MAX_PATH */
60:
61: #ifdef __BORLANDC__
62: unsigned _stklen=20000; /* Set stack size in code, not header */
63: #endif
64:
65: char **label_name=NULL
66: ,**goto_file=NULL
67: ,**goto_label=NULL
68: ,**call_file=NULL
69: ,**call_label=NULL;
70:
71: ulong *var_name=NULL,vars=0;
72:
73: char **define_str=NULL
74: ,**define_val=NULL;
75:
76: char *linestr="%s %d: %s\n";
77: char tmp[256];
78:
79: uint *label_indx=NULL
80: ,*goto_indx=NULL
81: ,*goto_line=NULL
82: ,*call_indx=NULL
83: ,*call_line=NULL;
84:
85: char bin_file[MAX_PATH+1];
86: char output_dir[MAX_PATH+1];
87: char include_dir[MAX_PATH+1];
88:
89: uint display=0,line=0,labels=0,gotos=0,calls=0,defines=0,case_sens=0;
90: BOOL pause_on_error=FALSE;
91:
92: FILE *out=NULL;
93:
94: void bail(int retval)
95: {
96: if(out)
97: fclose(out);
98:
99: if(retval!=0) {
100: if(bin_file[0]!=0)
101: remove(bin_file);
102: if(pause_on_error) {
103: printf("\nHit enter to contiue...");
104: getchar();
105: }
106: }
107:
108: exit(retval);
109: }
110:
111: /****************************************************************************/
112: /* Converts an ASCII Hex string into an ulong */
113: /****************************************************************************/
114: ulong ahtoul(char *str)
115: {
116: ulong l,val=0;
117:
118: while((l=(*str++)|0x20)!=0x20)
119: val=(l&0xf)+(l>>6&1)*9+val*16;
120: return(val);
121: }
122:
123: /* C Escape char */
124:
125: uchar cesc(char ch)
126: {
127: switch(ch) {
128: case 'e':
129: return(ESC);
130: case 'r':
131: return(CR);
132: case 'n':
133: return(LF);
134: case 't':
135: return(TAB);
136: case 'b':
137: return(BS);
138: case 'a':
139: return(BEL);
140: case 'f':
141: return(FF);
142: case 'v':
143: return(11);
144: default:
145: return(ch);
146: }
147: }
148:
149: long val(char *src, char *p)
150: {
151: static int inside;
152: long l;
153:
154: if(isdigit(*p) || *p=='-') /* Dec, Hex, or Oct */
155: l=strtol(p,&p,0);
156: else if(*p=='\'') { /* Char */
157: p++;
158: if(*p=='\\') {
159: p++;
160: l=cesc(*p); }
161: else
162: l=*p;
163: p++; }
164: else if(*p=='.') /* Bit */
165: l=1L<<strtol(p+1,&p,0);
166: else {
167: printf("!SYNTAX ERROR (expecting integer constant):\n");
168: printf(linestr,src,line,*p ? p : "<end of line>");
169: bail(1);
170: return(0); }
171: if(inside) {
172: return(l); }
173: inside=1;
174: while(*p)
175: switch(*(p++)) {
176: case '+':
177: l+=val(src,p);
178: break;
179: case '-':
180: l-=val(src,p);
181: break;
182: case '*':
183: l*=val(src,p);
184: break;
185: case '/':
186: l/=val(src,p);
187: break;
188: case '%':
189: l%=val(src,p);
190: break;
191: case '&':
192: l&=val(src,p);
193: break;
194: case '|':
195: l|=val(src,p);
196: break;
197: case '~':
198: l&=~val(src,p);
199: break;
200: case '^':
201: l^=val(src,p);
202: break;
203: case '>':
204: if(*p=='>') {
205: p++;
206: l>>=val(src,p); }
207: break;
208: case '<':
209: if(*p=='<') {
210: p++;
211: l<<=val(src,p); }
212: break;
213: case ' ':
214: case '#':
215: inside=0;
216: return(l); }
217: inside=0;
218: return(l);
219: }
220:
221:
222: void writecstr(uchar *p)
223: {
224: char str[1024];
225: int j=0,inquotes=0;
226:
227: while(*p) {
228: if(*p=='"') { /* ignore quotes */
229: if(inquotes)
230: break;
231: inquotes=1;
232: p++;
233: continue; }
234: if(*p=='\\') { /* escape */
235: p++;
236: if(isdigit(*p)) {
237: sprintf(tmp,"%.3s",p);
238: str[j]=atoi(tmp); /* decimal, NOT octal */
239: if(isdigit(*(++p))) /* skip up to 3 digits */
240: if(isdigit(*(++p)))
241: p++;
242: j++;
243: continue; }
244: switch(*(p++)) {
245: case 'x':
246: tmp[0]=*(p++);
247: tmp[1]=0;
248: if(isxdigit(*p)) { /* if another hex digit, skip too */
249: tmp[1]=*(p++);
250: tmp[2]=0; }
251: str[j]=(char)ahtoul(tmp);
252: break;
253: case 'e':
254: str[j]=ESC;
255: break;
256: case 'r':
257: str[j]=CR;
258: break;
259: case 'n':
260: str[j]=LF;
261: break;
262: case 't':
263: str[j]=TAB;
264: break;
265: case 'b':
266: str[j]=BS;
267: break;
268: case 'a':
269: str[j]=BEL;
270: break;
271: case 'f':
272: str[j]=FF;
273: break;
274: case 'v':
275: str[j]=11; /* VT */
276: break;
277: default:
278: str[j]=*(p-1);
279: break; }
280: j++;
281: continue; }
282: str[j++]=*(p++); }
283: str[j]=0;
284: fwrite(str,1,j+1,out);
285: }
286:
287: void writestr(uchar *p)
288: {
289: char str[1024];
290: int j=0;
291:
292: while(*p) {
293: if(*p=='"') { /* ignore quotes */
294: p++;
295: continue; }
296: if(*p=='\\' && *(p+1)=='"' && *(p+2))
297: p++;
298: str[j++]=*(p++); }
299: str[j]=0;
300: fwrite(str,1,j+1,out);
301: }
302:
303: void cvttab(char *str)
304: {
305: int i;
306:
307: for(i=0;str[i];i++)
308: if(str[i]==TAB)
309: str[i]=' ';
310: }
311:
312: void newvar(uchar* src, uchar *in)
313: {
314: uchar name[128];
315: long i,l;
316:
317: if(isdigit(*in)) {
318: printf("!SYNTAX ERROR (illegal variable name):\n");
319: printf(linestr,src,line,(char*)in);
320: bail(1);
321: }
322:
323: sprintf(name,"%.80s",in);
324: if(strncmp(name,"var_",4)==0) /* decompiled source? */
325: l=strtoul(name+4,NULL,16);
326: else {
327: if(!case_sens)
328: strupr(name);
329: l=crc32(name,0);
330: for(i=0;i<vars;i++)
331: if(var_name[i]==l)
332: break;
333: if(i<vars)
334: return;
335: }
336: if((var_name=(ulong *)realloc(var_name,sizeof(long)*(vars+1)))==NULL) {
337: printf("Too many (%lu) variables!\n",vars);
338: bail(1); }
339: var_name[vars]=l;
340: if(display)
341: printf("newvar(%08lX)=%s\n",l,in);
342: vars++;
343: }
344:
345: void writecrc(uchar *src, uchar *in)
346: {
347: uchar name[128];
348: uchar* p;
349: long i,l;
350:
351: /* Automatically terminate variable name Oct-09-2000 rswindell */
352: sprintf(name,"%.80s",in);
353: p=strchr(name,' ');
354: if(p) *p=0;
355:
356: if(!stricmp(name,"STR") || !name[0])
357: l=0;
358: else if(strncmp(name,"var_",4)==0) /* decompiled source? */
359: l=strtoul(name+4,NULL,16);
360: else {
361: if(!case_sens)
362: strupr(name);
363: l=crc32(name,0);
364:
365: for(i=0;i<vars;i++)
366: if(var_name[i]==l)
367: break;
368: if(i==vars) {
369: printf("!SYNTAX ERROR (expecting variable name):\n");
370: printf(linestr,src,line,*in ? (char*)in : "<end of line>");
371: bail(1);
372: }
373: }
374: fwrite(&l,4,1,out);
375: }
376:
377: long isvar(uchar *arg)
378: {
379: uchar name[128],*p;
380: long i,l;
381:
382: if(!arg || !(*arg) || isdigit(*arg))
383: return(0);
384:
385: sprintf(name,"%.80s",arg);
386: if((p=strchr(name,' '))!=NULL) /* Truncate at first space */
387: *p=0;
388: if(strncmp(name,"var_",4)==0) /* decompiled source? */
389: return(strtoul(name+4,NULL,16));
390: if(!case_sens)
391: strupr(name);
392: l=crc32(name,0);
393:
394: for(i=0;i<vars;i++)
395: if(var_name[i]==l)
396: break;
397: if(i==vars)
398: return(0);
399: return(l);
400: }
401:
402: int str_cmp(char *s1, char *s2)
403: {
404: if(case_sens)
405: return(strcmp(s1,s2));
406: return(stricmp(s1,s2));
407: }
408:
409: void expdefs(uchar *line)
410: {
411: uchar str[512],*p,*sp,sav[2]={0};
412: int i;
413:
414: str[0]=0;
415: for(p=line;*p;p++) {
416: if(*p==' ') {
417: strcat(str," ");
418: continue; }
419:
420: if(*p=='"') { /* Skip quoted text */
421: sp=strchr(p+1,'"');
422: if(sp) *sp=0;
423: strcat(str,p);
424: if(!sp)
425: break;
426: strcat(str,"\"");
427: p+=strlen(p);
428: continue; }
429:
430: for(sp=p;*sp;sp++)
431: if(!isalnum(*sp) && *sp!='_')
432: break;
433: sav[0]=*sp; /* Save delimiter */
434: sav[1]=0;
435: *sp=0;
436: for(i=0;i<defines;i++)
437: if(!str_cmp(define_str[i],p))
438: break;
439: if(i<defines)
440: strcat(str,define_val[i]);
441: else
442: strcat(str,p);
443: if(!sav[0]) /* Last argument */
444: break;
445: p+=strlen(p);
446: strcat(str,sav); /* Restore delimiter */
447: }
448: strcpy(line,str);
449: }
450:
451:
452:
453: void compile(char *src)
454: {
455: uchar *str,*save,*p,*sp,*tp,*arg,*arg2,*arg3,*arg4,*ar,ch;
456: char path[MAX_PATH+1];
457: ushort i,j;
458: long l,savline;
459: FILE *in;
460:
461: if((in=fopen(src,"rb"))==NULL) {
462: printf("error %d opening %s for read\n",errno,src);
463: bail(1); }
464: line=0;
465:
466: if((str=malloc(1024))==NULL) {
467: printf("malloc error\n");
468: bail(1);
469: }
470:
471: if((save=malloc(1024))==NULL) {
472: printf("malloc error\n");
473: bail(1);
474: }
475:
476: while(!feof(in) && !ferror(in)) {
477: if(!fgets(str,1000,in))
478: break;
479: truncsp(str);
480: cvttab(str);
481: line++;
482: strcpy(save,str);
483: p=str;
484: while(*p && *p<=' ') /* look for beginning of command */
485: p++;
486: if((*p)==0)
487: continue;
488: if(*p=='#') /* remarks start with # */
489: continue;
490: expdefs(p); /* expand defines */
491: if(display)
492: printf("%s\n",p);
493: sp=strchr(p,' ');
494: arg=arg2=arg3=arg4="";
495: if(sp) {
496: *sp=0;
497: arg=sp+1;
498: while(*arg && *arg<=' ') arg++;
499: sp=strchr(arg,' ');
500: if(sp) {
501: arg2=sp+1;
502: while(*arg2 && *arg2<=' ') arg2++;
503: sp=strchr(arg2,' ');
504: if(sp) {
505: arg3=sp+1;
506: while(*arg3 && *arg3<=' ') arg3++;
507: sp=strchr(arg3,' ');
508: if(sp) {
509: arg4=sp+1;
510: while(*arg4 && *arg4<=' ') arg4++; } } } }
511:
512: if(!stricmp(p,"!INCLUDE")) {
513: savline=line;
514: sp=strchr(arg,' ');
515: if(sp) *sp=0;
516: sprintf(path,"%s%s",include_dir,arg);
517: compile(path);
518: line=savline;
519: continue;
520: }
521:
522: if(!stricmp(p,"!DEFINE")) { /* define */
523: sp=strchr(arg,' ');
524: if(sp)
525: *sp=0;
526: else
527: break;
528: tp=strrchr(arg2,'\"');
529: if(!tp)
530: tp=arg2;
531: sp=strchr(tp,'#');
532: if(sp)
533: *sp=0;
534: truncsp(arg2);
535: if((define_str=(char **)realloc(define_str,sizeof(char *)*(defines+1)))
536: ==NULL) {
537: printf("Too many defines.\n");
538: bail(1); }
539: if((define_str[defines]=(char *)malloc(strlen(arg)+1))==NULL) {
540: printf("Too many defines.\n");
541: bail(1); }
542: if((define_val=(char **)realloc(define_val,sizeof(char *)*(defines+1)))
543: ==NULL) {
544: printf("Too many defines.\n");
545: bail(1); }
546: if((define_val[defines]=(char *)malloc(strlen(arg2)+1))==NULL) {
547: printf("Too many defines.\n");
548: bail(1); }
549: strcpy(define_str[defines],arg);
550: strcpy(define_val[defines],arg2);
551: defines++;
552: continue; }
553:
554: if(!stricmp(p,"!GLOBAL")) { /* declare global variables */
555: if(!(*arg)) break;
556: for(p=arg;*p && *p!='#';) {
557: sp=strchr(p,' ');
558: if(sp) *sp=0;
559: newvar(src,p);
560: if(!sp)
561: break;
562: p=sp+1;
563: while(*p && *p<=' ')
564: p++; }
565: continue; }
566:
567: if(!stricmp(p,"PATCH")) {
568: if(!(*arg)) break;
569: p=arg;
570: while(*p) {
571: while(*p && *p<=' ') p++;
572: tmp[0]=*p++;
573: tmp[1]=*p++;
574: tmp[2]=0;
575: if(!tmp[0])
576: break;
577: ch=ahtoul(tmp);
578: fputc(ch,out); }
579: continue; }
580:
581: if(!stricmp(p,"SHOW_VARS")) {
582: fputc(CS_VAR_INSTRUCTION,out);
583: fputc(SHOW_VARS,out);
584: continue; }
585:
586: if(!stricmp(p,"COMPARE_ARS")) {
587: if(!(*arg)) break;
588: strupr(arg);
589: ar=arstr(&i,arg,NULL);
590: fprintf(out,"%c%c",CS_COMPARE_ARS,(uchar)i);
591: fwrite(ar,i,1,out);
592: continue; }
593:
594: if(!stricmp(p,"CHKSYSPASS")) {
595: fprintf(out,"%c",CS_CHKSYSPASS);
596: continue; }
597: if(!stricmp(p,"INFO_SYSTEM")) {
598: fprintf(out,"%c",CS_INFO_SYSTEM);
599: continue; }
600: if(!stricmp(p,"INFO_SUBBOARD")) {
601: fprintf(out,"%c",CS_INFO_SUBBOARD);
602: continue; }
603: if(!stricmp(p,"INFO_DIRECTORY")) {
604: fprintf(out,"%c",CS_INFO_DIRECTORY);
605: continue; }
606: if(!stricmp(p,"INFO_VERSION")) {
607: fprintf(out,"%c",CS_INFO_VERSION);
608: continue; }
609: if(!stricmp(p,"INFO_USER")) {
610: fprintf(out,"%c",CS_INFO_USER);
611: continue; }
612: if(!stricmp(p,"INFO_XFER_POLICY")) {
613: fprintf(out,"%c",CS_INFO_XFER_POLICY);
614: continue; }
615: if(!stricmp(p,"LOGKEY")) {
616: fprintf(out,"%c",CS_LOGKEY);
617: continue; }
618: if(!stricmp(p,"LOGKEY_COMMA")) {
619: fprintf(out,"%c",CS_LOGKEY_COMMA);
620: continue; }
621: if(!stricmp(p,"LOGSTR")) {
622: fprintf(out,"%c",CS_LOGSTR);
623: continue; }
624:
625: if(!stricmp(p,"ONLINE")) {
626: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_ONLINE);
627: continue; }
628: if(!stricmp(p,"OFFLINE")) {
629: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_OFFLINE);
630: continue; }
631: if(!stricmp(p,"NEWUSER")) {
632: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_NEWUSER);
633: continue; }
634: if(!stricmp(p,"LOGON")) {
635: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_LOGON);
636: continue; }
637: if(!stricmp(p,"LOGOUT")) {
638: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_LOGOUT);
639: continue; }
640: if(!stricmp(p,"EXIT")) {
641: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_EXIT);
642: continue; }
643:
644: if(!stricmp(p,"LOOP") || !stricmp(p,"LOOP_BEGIN")) {
645: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_LOOP_BEGIN);
646: continue; }
647: if(!stricmp(p,"CONTINUE") || !stricmp(p,"CONTINUE_LOOP")) {
648: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_CONTINUE_LOOP);
649: continue; }
650: if(!stricmp(p,"BREAK") || !stricmp(p,"BREAK_LOOP")) {
651: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_BREAK_LOOP);
652: continue; }
653: if(!stricmp(p,"END_LOOP")) {
654: fprintf(out,"%c%c",CS_ONE_MORE_BYTE,CS_END_LOOP);
655: continue; }
656:
657: if(!stricmp(p,"USER_EVENT")) {
658: if(!(*arg))
659: break;
660: if((l=isvar(arg))!=0) {
661: fputc(CS_USE_INT_VAR,out);
662: fwrite(&l,4,1,out); /* variable */
663: fputc(2,out); /* int offset */
664: fputc(1,out); /* int length */
665: ch=0; } /* place holder */
666: else
667: ch=val(src,arg);
668: fprintf(out,"%c%c",CS_TWO_MORE_BYTES,CS_USER_EVENT);
669: fwrite(&ch,1,1,out);
670: continue; }
671:
672: if(!stricmp(p,"PUT_NODE")) {
673: fprintf(out,"%c",CS_PUT_NODE);
674: continue; }
675: if(!stricmp(p,"SYNC")) {
676: fprintf(out,"%c",CS_SYNC);
677: continue; }
678: if(!stricmp(p,"ASYNC")) {
679: fprintf(out,"%c",CS_ASYNC);
680: continue; }
681: if(!stricmp(p,"RIOSYNC")) { /* deprecated */
682: fprintf(out,"%c",CS_SYNC);
683: continue; }
684: if(!stricmp(p,"GETTIMELEFT")) {
685: fprintf(out,"%c",CS_GETTIMELEFT);
686: continue; }
687: if(!stricmp(p,"SAVELINE")) {
688: fprintf(out,"%c",CS_SAVELINE);
689: continue; }
690: if(!stricmp(p,"RESTORELINE")) {
691: fprintf(out,"%c",CS_RESTORELINE);
692: continue; }
693: if(!stricmp(p,"IF_TRUE") || !stricmp(p,"IF_EQUAL")) {
694: fprintf(out,"%c",CS_IF_TRUE);
695: continue; }
696: if(!stricmp(p,"IF_FALSE") || !stricmp(p,"IF_NOT_EQUAL")) {
697: fprintf(out,"%c",CS_IF_FALSE);
698: continue; }
699: if(!stricmp(p,"IF_GREATER")) {
700: fprintf(out,"%c",CS_IF_GREATER);
701: continue; }
702: if(!stricmp(p,"IF_GREATER_OR_EQUAL")
703: || !stricmp(p,"IF_EQUAL_OR_GREATER")) {
704: fprintf(out,"%c",CS_IF_GREATER_OR_EQUAL);
705: continue; }
706: if(!stricmp(p,"IF_LESS")) {
707: fprintf(out,"%c",CS_IF_LESS);
708: continue; }
709: if(!stricmp(p,"IF_LESS_OR_EQUAL")
710: || !stricmp(p,"IF_EQUAL_OR_LESS")) {
711: fprintf(out,"%c",CS_IF_LESS_OR_EQUAL);
712: continue; }
713: if(!stricmp(p,"ENDIF") || !stricmp(p,"END_IF")) {
714: fprintf(out,"%c",CS_ENDIF);
715: continue; }
716: if(!stricmp(p,"ELSE")) {
717: fprintf(out,"%c",CS_ELSE);
718: continue; }
719: if(p[0]==':') { /* :label */
720: p++;
721: sp=strchr(p,' ');
722: if(sp)
723: *sp=0;
724: for(i=0;i<labels;i++)
725: if(!stricmp(label_name[i],p))
726: break;
727: if(i<labels) {
728: printf("!SYNTAX ERROR (duplicate label name):\n");
729: printf(linestr,src,line,p);
730: bail(1); }
731: if((label_name=(char **)realloc(label_name,sizeof(char *)*(labels+1)))
732: ==NULL) {
733: printf("Too many labels.\n");
734: bail(1); }
735: if((label_indx=(uint *)realloc(label_indx,sizeof(int)*(labels+1)))
736: ==NULL) {
737: printf("Too many labels.\n");
738: bail(1); }
739: if((label_name[labels]=(char *)malloc(strlen(p)+1))==NULL) {
740: printf("Too many labels.\n");
741: bail(1); }
742: strcpy(label_name[labels],p);
743: label_indx[labels]=ftell(out);
744: labels++;
745: continue; }
746: if(!stricmp(p,"GOTO")) { /* goto */
747: if(!(*arg)) break;
748: sp=strchr(arg,' ');
749: if(sp)
750: *sp=0;
751: if((goto_label=(char **)realloc(goto_label,sizeof(char *)*(gotos+1)))
752: ==NULL) {
753: printf("Too many gotos.\n");
754: bail(1); }
755: if((goto_file=(char **)realloc(goto_file,sizeof(char *)*(gotos+1)))
756: ==NULL) {
757: printf("Too many gotos.\n");
758: bail(1); }
759: if((goto_indx=(uint *)realloc(goto_indx,sizeof(int)*(gotos+1)))
760: ==NULL) {
761: printf("Too many gotos.\n");
762: bail(1); }
763: if((goto_line=(uint *)realloc(goto_line,sizeof(int)*(gotos+1)))
764: ==NULL) {
765: printf("Too many gotos.\n");
766: bail(1); }
767: if((goto_label[gotos]=(char *)malloc(strlen(arg)+1))==NULL) {
768: printf("Too many gotos.\n");
769: bail(1); }
770: if((goto_file[gotos]=(char *)malloc(strlen(str)+1))==NULL) {
771: printf("Too many gotos.\n");
772: bail(1); }
773: strcpy(goto_label[gotos],arg);
774: strcpy(goto_file[gotos],str);
775: goto_indx[gotos]=ftell(out);
776: goto_line[gotos]=line;
777: gotos++;
778: fprintf(out,"%c%c%c",CS_GOTO,0xff,0xff);
779: continue; }
780: if(!stricmp(p,"CALL")) { /* call */
781: if(!(*arg)) break;
782: sp=strchr(arg,' ');
783: if(sp)
784: *sp=0;
785: if((call_label=(char **)realloc(call_label,sizeof(char *)*(calls+1)))
786: ==NULL) {
787: printf("Too many calls.\n");
788: bail(1); }
789: if((call_file=(char **)realloc(call_file,sizeof(char *)*(calls+1)))
790: ==NULL) {
791: printf("Too many calls.\n");
792: bail(1); }
793: if((call_indx=(uint *)realloc(call_indx,sizeof(int)*(calls+1)))
794: ==NULL) {
795: printf("Too many calls.\n");
796: bail(1); }
797: if((call_line=(uint *)realloc(call_line,sizeof(int)*(calls+1)))
798: ==NULL) {
799: printf("Too many calls.\n");
800: bail(1); }
801: if((call_label[calls]=(char *)malloc(strlen(arg)+1))==NULL) {
802: printf("Too many calls.\n");
803: bail(1); }
804: if((call_file[calls]=(char *)malloc(strlen(src)+1))==NULL) {
805: printf("Too many calls.\n");
806: bail(1); }
807:
808: strcpy(call_label[calls],arg);
809: strcpy(call_file[calls],src);
810: call_indx[calls]=ftell(out);
811: call_line[calls]=line;
812: calls++;
813: fprintf(out,"%c%c%c",CS_CALL,0xff,0xff);
814: continue; }
815:
816: if(!stricmp(p,"RETURN")) {
817: fprintf(out,"%c",CS_RETURN);
818: continue; }
819: if(!stricmp(p,"CMD_HOME")) {
820: fprintf(out,"%c",CS_CMD_HOME);
821: continue; }
822: if(!stricmp(p,"CMDKEY")) {
823: if(!(*arg)) break;
824: if(!stricmp(arg,"DIGIT"))
825: ch=CS_DIGIT;
826: else if(!stricmp(arg,"EDIGIT"))
827: ch=CS_EDIGIT;
828: else
829: ch=toupper(*arg);
830: if(ch=='/')
831: ch=*(arg+1)|0x80; /* high bit indicates slash required */
832: else if(ch=='^' && *(arg+1)>=0x40)
833: ch=*(arg+1)-0x40; /* ctrl char */
834: else if(ch=='\\')
835: ch=cesc(*(arg+1));
836: else if(ch=='\'')
837: ch=*(arg+1);
838: fprintf(out,"%c%c",CS_CMDKEY,ch);
839: continue; }
840: if(!stricmp(p,"CMDCHAR")) {
841: if(!(*arg)) break;
842: fprintf(out,"%c%c",CS_CMDKEY,*arg);
843: continue; }
844: if(!stricmp(p,"SETLOGIC") || !stricmp(p,"SET_LOGIC")) {
845: if(!(*arg)) break;
846: if(!stricmp(arg,"TRUE") || !stricmp(arg,"EQUAL"))
847: ch=LOGIC_TRUE;
848: else if(!stricmp(arg,"GREATER"))
849: ch=LOGIC_GREATER;
850: else if(!stricmp(arg,"LESS"))
851: ch=LOGIC_LESS;
852: else
853: ch=LOGIC_FALSE;
854: fprintf(out,"%c%c",CS_SETLOGIC,ch);
855: continue; }
856:
857: if(!stricmp(p,"DEFINE_STR_VAR") || !stricmp(p,"STR")) {
858: if(!(*arg)) break;
859: for(p=arg;*p && *p!='#';) {
860: sp=strchr(p,' ');
861: if(sp) *sp=0;
862: fputc(CS_VAR_INSTRUCTION,out);
863: fputc(DEFINE_STR_VAR,out);
864: newvar(src,p);
865: writecrc(src,p);
866: if(!sp)
867: break;
868: p=sp+1;
869: while(*p && *p<=' ')
870: p++; }
871: continue; }
872: if(!stricmp(p,"DEFINE_INT_VAR") || !stricmp(p,"INT")) {
873: if(!(*arg)) break;
874: for(p=arg;*p && *p!='#';) {
875: sp=strchr(p,' ');
876: if(sp) *sp=0;
877: fputc(CS_VAR_INSTRUCTION,out);
878: fputc(DEFINE_INT_VAR,out);
879: newvar(src,p);
880: writecrc(src,p);
881: if(!sp)
882: break;
883: p=sp+1;
884: while(*p && *p<=' ')
885: p++; }
886: continue; }
887: if(!stricmp(p,"DEFINE_GLOBAL_STR_VAR") || !stricmp(p,"GLOBAL_STR")) {
888: if(!(*arg)) break;
889: for(p=arg;*p && *p!='#';) {
890: sp=strchr(p,' ');
891: if(sp) *sp=0;
892: fputc(CS_VAR_INSTRUCTION,out);
893: fputc(DEFINE_GLOBAL_STR_VAR,out);
894: newvar(src,p);
895: writecrc(src,p);
896: if(!sp)
897: break;
898: p=sp+1;
899: while(*p && *p<=' ')
900: p++; }
901: continue; }
902: if(!stricmp(p,"DEFINE_GLOBAL_INT_VAR") || !stricmp(p,"GLOBAL_INT")) {
903: if(!(*arg)) break;
904: for(p=arg;*p && *p!='#';) {
905: sp=strchr(p,' ');
906: if(sp) *sp=0;
907: fputc(CS_VAR_INSTRUCTION,out);
908: fputc(DEFINE_GLOBAL_INT_VAR,out);
909: newvar(src,p);
910: writecrc(src,p);
911: if(!sp)
912: break;
913: p=sp+1;
914: while(*p && *p<=' ')
915: p++; }
916: continue; }
917:
918: if(!stricmp(p,"LOGIN")) {
919: if(!(*arg)) break;
920: fputc(CS_STR_FUNCTION,out);
921: fputc(CS_LOGIN,out);
922: writecstr(arg);
923: continue; }
924:
925: if(!stricmp(p,"LOAD_TEXT")) {
926: if(!(*arg)) break;
927: fputc(CS_STR_FUNCTION,out);
928: fputc(CS_LOAD_TEXT,out);
929: writestr(arg);
930: continue; }
931:
932: if(!stricmp(p,"SET_STR_VAR")
933: || (!stricmp(p,"SET") && strchr(arg,'"'))) {
934: if(!(*arg)) break;
935: fputc(CS_VAR_INSTRUCTION,out);
936: fputc(SET_STR_VAR,out);
937: p=strchr(arg,' ');
938: if(!p)
939: break;
940: *p=0;
941: writecrc(src,arg);
942: writecstr(arg2);
943: continue; }
944: if(!stricmp(p,"CAT_STR_VAR")
945: || (!stricmp(p,"STRCAT") && strchr(arg,'"'))) {
946: fputc(CS_VAR_INSTRUCTION,out);
947: fputc(CAT_STR_VAR,out);
948: p=strchr(arg,' ');
949: if(!p)
950: break;
951: *p=0;
952: writecrc(src,arg);
953: writecstr(arg2);
954: continue; }
955: if((!stricmp(p,"STRSTR") || !stricmp(p,"COMPARE_SUBSTR"))
956: && strchr(arg,'"')) {
957: fputc(CS_VAR_INSTRUCTION,out);
958: fputc(STRSTR_VAR,out);
959: p=strchr(arg,' ');
960: if(!p)
961: break;
962: *p=0;
963: writecrc(src,arg);
964: writecstr(arg2);
965: continue; }
966: if(!stricmp(p,"STRSTR") || !stricmp(p,"COMPARE_SUBSTR")) {
967: if(!(*arg)) break;
968: fputc(CS_VAR_INSTRUCTION,out);
969: fputc(STRSTR_VARS,out);
970: p=strchr(arg,' ');
971: if(!p)
972: break;
973: *p=0;
974: writecrc(src,arg);
975: writecrc(src,arg2);
976: continue; }
977: if(!stricmp(p,"COPY_CHAR") || !stricmp(p,"COPY_KEY")) {
978: if(!(*arg)) break;
979: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,COPY_CHAR);
980: writecrc(src,arg);
981: continue; }
982: if(!stricmp(p,"COPY_FIRST_CHAR")) {
983: if(!(*arg) || !(*arg2)) break;
984: fputc(CS_VAR_INSTRUCTION,out);
985: fputc(COPY_FIRST_CHAR,out);
986: writecrc(src,arg);
987: writecrc(src,arg2);
988: continue; }
989: if(!stricmp(p,"COMPARE_FIRST_CHAR")) {
990: if(!(*arg) || !(*arg2)) break;
991: fputc(CS_VAR_INSTRUCTION,out);
992: fputc(COMPARE_FIRST_CHAR,out);
993: writecrc(src,arg);
994: fputc((uchar)val(src,arg2),out);
995: continue; }
996: if(!stricmp(p,"CAT_STR_VARS") || !stricmp(p,"STRCAT")) {
997: if(!(*arg)) break;
998: fputc(CS_VAR_INSTRUCTION,out);
999: fputc(CAT_STR_VARS,out);
1000: p=strchr(arg,' ');
1001: if(!p)
1002: break;
1003: *p=0;
1004: writecrc(src,arg);
1005: writecrc(src,arg2);
1006: continue; }
1007: if(!stricmp(p,"FORMAT") || !stricmp(p,"SPRINTF")) {
1008: if(!(*arg)) break;
1009: fputc(CS_VAR_INSTRUCTION,out);
1010: fputc(FORMAT_STR_VAR,out);
1011: p=strchr(arg,' ');
1012: if(!p)
1013: break;
1014: *p=0;
1015: writecrc(src,arg); /* Write destination variable */
1016: p++;
1017: while(*p && *p<=' ') p++;
1018: arg=p;
1019: p=strrchr(arg,'"');
1020: if(!p)
1021: break;
1022: *p=0;
1023: p++;
1024: while(*p && *p<=' ') p++;
1025: writecstr(arg); /* Write string */
1026: l=ftell(out);
1027: fputc(0,out); /* Write total number of args */
1028: i=0;
1029: while(p && *p) {
1030: arg=p;
1031: p=strchr(arg,' ');
1032: if(p) {
1033: *p=0;
1034: p++; }
1035: writecrc(src,arg);
1036: i++; }
1037: fseek(out,l,SEEK_SET);
1038: fputc((char)i,out);
1039: fseek(out,i*4,SEEK_CUR);
1040: continue; }
1041:
1042: if(!stricmp(p,"STRFTIME") || !stricmp(p,"FTIME_STR")) {
1043: if(!(*arg) || !(*arg2) || !(*arg3)) break;
1044: fputc(CS_VAR_INSTRUCTION,out);
1045: fputc(FORMAT_TIME_STR,out);
1046: p=strchr(arg,' ');
1047: if(!p)
1048: break;
1049: *p=0;
1050: writecrc(src,arg); /* Write destination variable */
1051: p++;
1052: while(*p && *p<=' ') p++;
1053: arg=p;
1054: p=strrchr(arg,'"');
1055: if(!p)
1056: break;
1057: *p=0;
1058: writecstr(arg); /* Write string */
1059: p++;
1060: while(*p && *p<=' ') p++;
1061: writecrc(src,p);
1062: continue; }
1063:
1064: if(!stricmp(p,"TIME_STR")) {
1065: if(!(*arg)) break;
1066: fputc(CS_VAR_INSTRUCTION,out);
1067: fputc(TIME_STR,out);
1068: p=strchr(arg,' ');
1069: if(!p)
1070: break;
1071: *p=0;
1072: writecrc(src,arg);
1073: writecrc(src,arg2);
1074: continue; }
1075:
1076: if(!stricmp(p,"DATE_STR")) {
1077: if(!(*arg)) break;
1078: fputc(CS_VAR_INSTRUCTION,out);
1079: fputc(DATE_STR,out);
1080: p=strchr(arg,' ');
1081: if(!p)
1082: break;
1083: *p=0;
1084: writecrc(src,arg);
1085: writecrc(src,arg2);
1086: continue; }
1087:
1088: if(!stricmp(p,"SECOND_STR")) {
1089: if(!(*arg)) break;
1090: fputc(CS_VAR_INSTRUCTION,out);
1091: fputc(SECOND_STR,out);
1092: p=strchr(arg,' ');
1093: if(!p)
1094: break;
1095: *p=0;
1096: writecrc(src,arg);
1097: writecrc(src,arg2);
1098: continue; }
1099:
1100:
1101: if(!stricmp(p,"SET_INT_VAR")
1102: || (!stricmp(p,"SET") && *arg2!='"')) {
1103: if(!(*arg)) break;
1104: fputc(CS_VAR_INSTRUCTION,out);
1105: fputc(SET_INT_VAR,out);
1106: p=strchr(arg,' ');
1107: if(!p)
1108: break;
1109: *p=0;
1110: writecrc(src,arg);
1111: l=val(src,arg2);
1112: fwrite(&l,4,1,out);
1113: continue; }
1114:
1115: if(!stricmp(p,"COMPARE_STR_VAR") ||
1116: (!stricmp(p,"COMPARE") && *arg2=='"')) {
1117: if(!(*arg)) break;
1118: fputc(CS_VAR_INSTRUCTION,out);
1119: fputc(COMPARE_STR_VAR,out);
1120: p=strchr(arg,' ');
1121: if(!p)
1122: break;
1123: *p=0;
1124: writecrc(src,arg);
1125: writecstr(arg2);
1126: continue; }
1127:
1128: if(!stricmp(p,"COMPARE_STRN_VAR") ||
1129: ((!stricmp(p,"STRNCMP") || !stricmp(p,"COMPARE_STRN"))
1130: && *arg3 && strchr(arg3,'"'))) {
1131: if((l=isvar(arg))!=0) {
1132: fputc(CS_USE_INT_VAR,out);
1133: fwrite(&l,4,1,out); /* variable */
1134: fputc(2,out); /* int offset */
1135: fputc(1,out); /* int length */
1136: i=0; } /* place holder */
1137: else
1138: i=val(src,arg);
1139: fputc(CS_VAR_INSTRUCTION,out);
1140: fputc(STRNCMP_VAR,out);
1141: fwrite(&i,1,1,out); /* Length */
1142: p=strchr(arg2,' ');
1143: if(!p)
1144: break;
1145: *p=0;
1146: p++;
1147: while(*p && *p<=' ') p++;
1148: writecrc(src,arg2);
1149: writecstr(p);
1150: continue; }
1151:
1152: if(!stricmp(p,"COMPARE_STRN_VARS") || !stricmp(p,"STRNCMP")
1153: || !stricmp(p,"COMPARE_STRN")) {
1154: if(!(*arg) || !(*arg2) || !(*arg3))
1155: break;
1156: if((l=isvar(arg))!=0) {
1157: fputc(CS_USE_INT_VAR,out);
1158: fwrite(&l,4,1,out); /* variable */
1159: fputc(2,out); /* int offset */
1160: fputc(1,out); /* int length */
1161: i=0; } /* place holder */
1162: else
1163: i=val(src,arg);
1164: fputc(CS_VAR_INSTRUCTION,out);
1165: fputc(STRNCMP_VARS,out);
1166:
1167: fwrite(&i,1,1,out); /* Length */
1168: p=strchr(arg2,' ');
1169: if(!p)
1170: break;
1171: *p=0;
1172: p++;
1173: while(*p && *p<=' ') p++;
1174: writecrc(src,arg2);
1175: writecrc(src,p);
1176: continue; }
1177:
1178: if(!stricmp(p,"COMPARE_INT_VAR") ||
1179: (!stricmp(p,"COMPARE")
1180: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1181: if(!(*arg)) break;
1182:
1183: fputc(CS_VAR_INSTRUCTION,out);
1184: fputc(COMPARE_INT_VAR,out);
1185: p=strchr(arg,' ');
1186: if(!p)
1187: break;
1188: *p=0;
1189: writecrc(src,arg);
1190: l=val(src,arg2);
1191: fwrite(&l,4,1,out);
1192: continue; }
1193:
1194: if(!stricmp(p,"COMPARE")) {
1195: if(!(*arg)) break;
1196: fputc(CS_VAR_INSTRUCTION,out);
1197: fputc(COMPARE_VARS,out);
1198: p=strchr(arg,' ');
1199: if(!p)
1200: break;
1201: *p=0;
1202: writecrc(src,arg);
1203: writecrc(src,arg2);
1204: continue; }
1205: if(!stricmp(p,"COPY")) {
1206: if(!(*arg)) break;
1207: fputc(CS_VAR_INSTRUCTION,out);
1208: fputc(COPY_VAR,out);
1209: p=strchr(arg,' ');
1210: if(!p)
1211: break;
1212: *p=0;
1213: writecrc(src,arg);
1214: writecrc(src,arg2);
1215: continue; }
1216: if(!stricmp(p,"SWAP")) {
1217: if(!(*arg)) break;
1218: fputc(CS_VAR_INSTRUCTION,out);
1219: fputc(SWAP_VARS,out);
1220: p=strchr(arg,' ');
1221: if(!p)
1222: break;
1223: *p=0;
1224: writecrc(src,arg);
1225: writecrc(src,arg2);
1226: continue; }
1227:
1228: if(!stricmp(p,"TIME")) {
1229: if(!(*arg)) break;
1230: fputc(CS_VAR_INSTRUCTION,out);
1231: fputc(TIME_INT_VAR,out);
1232: writecrc(src,arg);
1233: continue; }
1234:
1235: if(!stricmp(p,"DATE_INT")) {
1236: if(!(*arg)) break;
1237: fputc(CS_VAR_INSTRUCTION,out);
1238: fputc(DATE_STR_TO_INT,out);
1239: p=strchr(arg,' ');
1240: if(!p)
1241: break;
1242: *p=0;
1243: writecrc(src,arg);
1244: writecrc(src,arg2);
1245: continue; }
1246:
1247: if(!stricmp(p,"CRC16")) {
1248: if(!(*arg)) break;
1249: fputc(CS_VAR_INSTRUCTION,out);
1250: fputc(CRC16_TO_INT,out);
1251: p=strchr(arg,' ');
1252: if(!p)
1253: break;
1254: *p=0;
1255: writecrc(src,arg);
1256: writecrc(src,arg2);
1257: continue; }
1258:
1259: if(!stricmp(p,"CRC32")) {
1260: if(!(*arg)) break;
1261: fputc(CS_VAR_INSTRUCTION,out);
1262: fputc(CRC32_TO_INT,out);
1263: p=strchr(arg,' ');
1264: if(!p)
1265: break;
1266: *p=0;
1267: writecrc(src,arg);
1268: writecrc(src,arg2);
1269: continue; }
1270:
1271: if(!stricmp(p,"CHKSUM")) {
1272: if(!(*arg)) break;
1273: fputc(CS_VAR_INSTRUCTION,out);
1274: fputc(CHKSUM_TO_INT,out);
1275: p=strchr(arg,' ');
1276: if(!p)
1277: break;
1278: *p=0;
1279: writecrc(src,arg);
1280: writecrc(src,arg2);
1281: continue; }
1282:
1283: if(!stricmp(p,"ADD_INT_VAR")
1284: || (!stricmp(p,"ADD")
1285: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1286: if(!(*arg)) break;
1287: fputc(CS_VAR_INSTRUCTION,out);
1288: fputc(ADD_INT_VAR,out);
1289: p=strchr(arg,' ');
1290: if(!p)
1291: break;
1292: *p=0;
1293: writecrc(src,arg);
1294: l=val(src,arg2);
1295: if(!l)
1296: break;
1297: fwrite(&l,4,1,out);
1298: continue; }
1299: if(!stricmp(p,"ADD_INT_VARS") || !stricmp(p,"ADD")) {
1300: if(!(*arg)) break;
1301: fputc(CS_VAR_INSTRUCTION,out);
1302: fputc(ADD_INT_VARS,out);
1303: p=strchr(arg,' ');
1304: if(!p)
1305: break;
1306: *p=0;
1307: writecrc(src,arg);
1308: writecrc(src,arg2);
1309: continue; }
1310:
1311: if(!stricmp(p,"SUB_INT_VAR")
1312: || (!stricmp(p,"SUB")
1313: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1314: if(!(*arg)) break;
1315: fputc(CS_VAR_INSTRUCTION,out);
1316: fputc(SUB_INT_VAR,out);
1317: p=strchr(arg,' ');
1318: if(!p)
1319: break;
1320: *p=0;
1321: writecrc(src,arg);
1322: l=val(src,arg2);
1323: if(!l)
1324: break;
1325: fwrite(&l,4,1,out);
1326: continue; }
1327: if(!stricmp(p,"SUB_INT_VARS") || !stricmp(p,"SUB")) {
1328: if(!(*arg)) break;
1329: fputc(CS_VAR_INSTRUCTION,out);
1330: fputc(SUB_INT_VARS,out);
1331: p=strchr(arg,' ');
1332: if(!p)
1333: break;
1334: *p=0;
1335: writecrc(src,arg);
1336: writecrc(src,arg2);
1337: continue; }
1338:
1339: if(!stricmp(p,"MUL_INT_VAR")
1340: || (!stricmp(p,"MUL")
1341: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1342: if(!(*arg)) break;
1343: fputc(CS_VAR_INSTRUCTION,out);
1344: fputc(MUL_INT_VAR,out);
1345: p=strchr(arg,' ');
1346: if(!p)
1347: break;
1348: *p=0;
1349: writecrc(src,arg);
1350: l=val(src,arg2);
1351: if(!l)
1352: break;
1353: fwrite(&l,4,1,out);
1354: continue; }
1355: if(!stricmp(p,"MUL_INT_VARS") || !stricmp(p,"MUL")) {
1356: if(!(*arg)) break;
1357: fputc(CS_VAR_INSTRUCTION,out);
1358: fputc(MUL_INT_VARS,out);
1359: p=strchr(arg,' ');
1360: if(!p)
1361: break;
1362: *p=0;
1363: writecrc(src,arg);
1364: writecrc(src,arg2);
1365: continue; }
1366:
1367: if(!stricmp(p,"DIV_INT_VAR")
1368: || (!stricmp(p,"DIV")
1369: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1370: if(!(*arg)) break;
1371: fputc(CS_VAR_INSTRUCTION,out);
1372: fputc(DIV_INT_VAR,out);
1373: p=strchr(arg,' ');
1374: if(!p)
1375: break;
1376: *p=0;
1377: writecrc(src,arg);
1378: l=val(src,arg2);
1379: if(!l)
1380: break;
1381: fwrite(&l,4,1,out);
1382: continue; }
1383: if(!stricmp(p,"DIV_INT_VARS") || !stricmp(p,"DIV")) {
1384: if(!(*arg)) break;
1385: fputc(CS_VAR_INSTRUCTION,out);
1386: fputc(DIV_INT_VARS,out);
1387: p=strchr(arg,' ');
1388: if(!p)
1389: break;
1390: *p=0;
1391: writecrc(src,arg);
1392: writecrc(src,arg2);
1393: continue; }
1394:
1395: if(!stricmp(p,"MOD_INT_VAR")
1396: || (!stricmp(p,"MOD")
1397: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1398: if(!(*arg)) break;
1399: fputc(CS_VAR_INSTRUCTION,out);
1400: fputc(MOD_INT_VAR,out);
1401: p=strchr(arg,' ');
1402: if(!p)
1403: break;
1404: *p=0;
1405: writecrc(src,arg);
1406: l=val(src,arg2);
1407: if(!l)
1408: break;
1409: fwrite(&l,4,1,out);
1410: continue; }
1411: if(!stricmp(p,"MOD_INT_VARS") || !stricmp(p,"MOD")) {
1412: if(!(*arg)) break;
1413: fputc(CS_VAR_INSTRUCTION,out);
1414: fputc(MOD_INT_VARS,out);
1415: p=strchr(arg,' ');
1416: if(!p)
1417: break;
1418: *p=0;
1419: writecrc(src,arg);
1420: writecrc(src,arg2);
1421: continue; }
1422:
1423: if(!stricmp(p,"AND_INT_VAR")
1424: || (!stricmp(p,"AND")
1425: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1426: if(!(*arg)) break;
1427: fputc(CS_VAR_INSTRUCTION,out);
1428: fputc(AND_INT_VAR,out);
1429: p=strchr(arg,' ');
1430: if(!p)
1431: break;
1432: *p=0;
1433: writecrc(src,arg);
1434: l=val(src,arg2);
1435: fwrite(&l,4,1,out);
1436: continue; }
1437: if(!stricmp(p,"AND_INT_VARS") || !stricmp(p,"AND")) {
1438: if(!(*arg)) break;
1439: fputc(CS_VAR_INSTRUCTION,out);
1440: fputc(AND_INT_VARS,out);
1441: p=strchr(arg,' ');
1442: if(!p)
1443: break;
1444: *p=0;
1445: writecrc(src,arg);
1446: writecrc(src,arg2);
1447: continue; }
1448:
1449: if(!stricmp(p,"COMPARE_ANY_BITS") || !stricmp(p,"COMPARE_ALL_BITS")) {
1450: if(!(*arg) || !(*arg2))
1451: break;
1452: if((l=isvar(arg2))!=0) {
1453: fputc(CS_USE_INT_VAR,out);
1454: fwrite(&l,4,1,out); /* variable */
1455: fputc(6,out); /* int offset */
1456: fputc(4,out); /* int length */
1457: l=0; } /* place holder */
1458: else
1459: l=val(src,arg2);
1460: fprintf(out,"%c%c",CS_VAR_INSTRUCTION
1461: ,!stricmp(p,"COMPARE_ANY_BITS") ? COMPARE_ANY_BITS : COMPARE_ALL_BITS);
1462: writecrc(src,arg);
1463: fwrite(&l,sizeof(l),1,out);
1464: continue;
1465: }
1466:
1467: if(!stricmp(p,"OR_INT_VAR")
1468: || (!stricmp(p,"OR")
1469: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1470: if(!(*arg)) break;
1471: fputc(CS_VAR_INSTRUCTION,out);
1472: fputc(OR_INT_VAR,out);
1473: p=strchr(arg,' ');
1474: if(!p)
1475: break;
1476: *p=0;
1477: writecrc(src,arg);
1478: l=val(src,arg2);
1479: fwrite(&l,4,1,out);
1480: continue; }
1481: if(!stricmp(p,"OR_INT_VARS") || !stricmp(p,"OR")) {
1482: if(!(*arg)) break;
1483: fputc(CS_VAR_INSTRUCTION,out);
1484: fputc(OR_INT_VARS,out);
1485: p=strchr(arg,' ');
1486: if(!p)
1487: break;
1488: *p=0;
1489: writecrc(src,arg);
1490: writecrc(src,arg2);
1491: continue; }
1492:
1493: if(!stricmp(p,"NOT_INT_VAR")
1494: || (!stricmp(p,"NOT")
1495: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1496: if(!(*arg)) break;
1497: fputc(CS_VAR_INSTRUCTION,out);
1498: fputc(NOT_INT_VAR,out);
1499: p=strchr(arg,' ');
1500: if(!p)
1501: break;
1502: *p=0;
1503: writecrc(src,arg);
1504: l=val(src,arg2);
1505: fwrite(&l,4,1,out);
1506: continue; }
1507: if(!stricmp(p,"NOT_INT_VARS") || !stricmp(p,"NOT")) {
1508: if(!(*arg)) break;
1509: fputc(CS_VAR_INSTRUCTION,out);
1510: fputc(NOT_INT_VARS,out);
1511: p=strchr(arg,' ');
1512: if(!p)
1513: break;
1514: *p=0;
1515: writecrc(src,arg);
1516: writecrc(src,arg2);
1517: continue; }
1518:
1519: if(!stricmp(p,"XOR_INT_VAR")
1520: || (!stricmp(p,"XOR")
1521: && (isdigit(*arg2) || atol(arg2) || *arg2=='\'' || *arg2=='.'))) {
1522: if(!(*arg)) break;
1523: fputc(CS_VAR_INSTRUCTION,out);
1524: fputc(XOR_INT_VAR,out);
1525: p=strchr(arg,' ');
1526: if(!p)
1527: break;
1528: *p=0;
1529: writecrc(src,arg);
1530: l=val(src,arg2);
1531: fwrite(&l,4,1,out);
1532: continue; }
1533: if(!stricmp(p,"XOR_INT_VARS") || !stricmp(p,"XOR")) {
1534: if(!(*arg)) break;
1535: fputc(CS_VAR_INSTRUCTION,out);
1536: fputc(XOR_INT_VARS,out);
1537: p=strchr(arg,' ');
1538: if(!p)
1539: break;
1540: *p=0;
1541: writecrc(src,arg);
1542: writecrc(src,arg2);
1543: continue; }
1544:
1545: if(!stricmp(p,"RANDOM_INT_VAR") || !stricmp(p,"RANDOM")) {
1546: if(!(*arg)) break;
1547: if((l=isvar(arg2))!=0) {
1548: fputc(CS_USE_INT_VAR,out);
1549: fwrite(&l,4,1,out); /* variable */
1550: fputc(6,out); /* int offset */
1551: fputc(4,out); /* int length */
1552: l=0; } /* place holder */
1553: else
1554: l=val(src,arg2);
1555: fputc(CS_VAR_INSTRUCTION,out);
1556: fputc(RANDOM_INT_VAR,out);
1557: p=strchr(arg,' ');
1558: if(!p)
1559: break;
1560: *p=0;
1561: writecrc(src,arg);
1562: fwrite(&l,4,1,out);
1563: continue; }
1564:
1565: if(!stricmp(p,"SWITCH")) {
1566: if(!(*arg)) break;
1567: fputc(CS_SWITCH,out);
1568: writecrc(src,arg);
1569: continue; }
1570: if(!stricmp(p,"END_SWITCH")) {
1571: fputc(CS_END_SWITCH,out);
1572: continue; }
1573: if(!stricmp(p,"CASE")) {
1574: if(!(*arg)) break;
1575: fputc(CS_CASE,out);
1576: l=val(src,arg);
1577: fwrite(&l,4,1,out);
1578: continue; }
1579: if(!stricmp(p,"DEFAULT")) {
1580: fputc(CS_DEFAULT,out);
1581: continue; }
1582: if(!stricmp(p,"END_CASE")) {
1583: fputc(CS_END_CASE,out);
1584: continue; }
1585:
1586: if(!stricmp(p,"PRINT") && !strchr(arg,'"') && !strchr(arg,'\\')
1587: && !strchr(arg,' ')) {
1588: if(!(*arg)) break;
1589: fputc(CS_VAR_INSTRUCTION,out);
1590: fputc(PRINT_VAR,out);
1591: writecrc(src,arg);
1592: continue; }
1593:
1594: if(!stricmp(p,"PRINTF") || !stricmp(p,"LPRINTF") || !stricmp(p,"PRINTF_LOCAL")) {
1595: if(!(*arg)) break;
1596: fputc(CS_VAR_INSTRUCTION,out);
1597: if(!stricmp(p,"PRINTF"))
1598: fputc(VAR_PRINTF,out);
1599: else
1600: fputc(VAR_PRINTF_LOCAL,out);
1601: p=strrchr(arg,'"');
1602: if(!p)
1603: break;
1604: *p=0;
1605: p++;
1606: while(*p && *p<=' ') p++;
1607: writecstr(arg); /* Write string */
1608: l=ftell(out);
1609: fputc(0,out); /* Write total number of args */
1610: i=0;
1611: while(p && *p) {
1612: arg=p;
1613: p=strchr(arg,' ');
1614: if(p) {
1615: *p=0;
1616: p++; }
1617: writecrc(src,arg);
1618: i++; }
1619: fseek(out,l,SEEK_SET);
1620: fputc((char)i,out);
1621: fseek(out,i*4,SEEK_CUR);
1622: continue; }
1623:
1624: if(!stricmp(p,"FOPEN")) {
1625: if(!(*arg) || !(*arg2) || !(*arg3)) break;
1626: if((l=isvar(arg2))!=0) {
1627: fputc(CS_USE_INT_VAR,out);
1628: fwrite(&l,4,1,out); /* variable */
1629: fputc(6,out); /* int offset */
1630: fputc(2,out); /* int length */
1631: i=0; } /* place holder */
1632: else
1633: i=val(src,arg2);
1634:
1635: fputc(CS_FIO_FUNCTION,out);
1636: if(*arg3=='"')
1637: fputc(FIO_OPEN,out);
1638: else
1639: fputc(FIO_OPEN_VAR,out);
1640: p=strchr(arg,' ');
1641: if(!p)
1642: break;
1643: *p=0;
1644: writecrc(src,arg);
1645: p=strchr(arg2,' ');
1646: if(!p)
1647: break;
1648: *p=0;
1649: p++;
1650: fwrite(&i,2,1,out);
1651: while(*p && *p<=' ') p++;
1652: if(*p=='"')
1653: writestr(p);
1654: else
1655: writecrc(src,p);
1656: continue; }
1657: if(!stricmp(p,"FCLOSE")) {
1658: if(!(*arg)) break;
1659: fputc(CS_FIO_FUNCTION,out);
1660: fputc(FIO_CLOSE,out);
1661: writecrc(src,arg);
1662: continue; }
1663: if(!stricmp(p,"FFLUSH")) {
1664: if(!(*arg)) break;
1665: fputc(CS_FIO_FUNCTION,out);
1666: fputc(FIO_FLUSH,out);
1667: writecrc(src,arg);
1668: continue; }
1669: if(!stricmp(p,"FREAD")) {
1670: if(!(*arg)) break;
1671:
1672: fputc(CS_FIO_FUNCTION,out);
1673: if(!(*arg3) || isdigit(*arg3) || atoi(arg3))
1674: fputc(FIO_READ,out);
1675: else
1676: fputc(FIO_READ_VAR,out);
1677: p=strchr(arg,' ');
1678: if(!p)
1679: break;
1680: *p=0;
1681: writecrc(src,arg); /* File handle */
1682: p=strchr(arg2,' ');
1683: if(p)
1684: *p=0;
1685: writecrc(src,arg2); /* Variable */
1686: if(isdigit(*arg3))
1687: i=val(src,arg3); /* Length */
1688: else
1689: i=0;
1690: if(i || !(*arg3))
1691: fwrite(&i,2,1,out);
1692: else
1693: writecrc(src,arg3);
1694: continue; }
1695: if(!stricmp(p,"FWRITE")) {
1696: if(!(*arg)) break;
1697: fputc(CS_FIO_FUNCTION,out);
1698: if(!(*arg3) || isdigit(*arg3) || atoi(arg3))
1699: fputc(FIO_WRITE,out);
1700: else
1701: fputc(FIO_WRITE_VAR,out);
1702: p=strchr(arg,' ');
1703: if(!p)
1704: break;
1705: *p=0;
1706: writecrc(src,arg); /* File handle */
1707: p=strchr(arg2,' ');
1708: if(p)
1709: *p=0;
1710: writecrc(src,arg2); /* Variable */
1711: if(isdigit(*arg3))
1712: i=val(src,arg3); /* Length */
1713: else
1714: i=0;
1715: if(i || !(*arg3))
1716: fwrite(&i,2,1,out);
1717: else
1718: writecrc(src,arg3);
1719: continue; }
1720: if(!stricmp(p,"FGET_LENGTH")
1721: || !stricmp(p,"FGETLENGTH")
1722: || !stricmp(p,"GETFLENGTH")) {
1723: if(!(*arg) || !(*arg2)) break;
1724: fputc(CS_FIO_FUNCTION,out);
1725: fputc(FIO_GET_LENGTH,out);
1726: p=strchr(arg,' ');
1727: if(!p)
1728: break;
1729: *p=0;
1730: writecrc(src,arg); /* File handle */
1731: writecrc(src,arg2); /* Variable */
1732: continue; }
1733: if(!stricmp(p,"FREAD_LINE")) {
1734: if(!(*arg) || !(*arg2)) break;
1735: fputc(CS_FIO_FUNCTION,out);
1736: fputc(FIO_READ_LINE,out);
1737: p=strchr(arg,' ');
1738: if(!p)
1739: break;
1740: *p=0;
1741: writecrc(src,arg); /* File handle */
1742: writecrc(src,arg2); /* Variable */
1743: continue; }
1744: if(!stricmp(p,"FEOF")) {
1745: if(!(*arg)) break;
1746: fputc(CS_FIO_FUNCTION,out);
1747: fputc(FIO_EOF,out);
1748: writecrc(src,arg);
1749: continue; }
1750: if(!stricmp(p,"FGET_POS")) {
1751: if(!(*arg) || !(*arg2)) break;
1752: fputc(CS_FIO_FUNCTION,out);
1753: fputc(FIO_GET_POS,out);
1754: p=strchr(arg,' ');
1755: if(!p)
1756: break;
1757: *p=0;
1758: writecrc(src,arg); /* File handle */
1759: writecrc(src,arg2); /* Variable */
1760: continue; }
1761: if(!stricmp(p,"FSET_POS") || !stricmp(p,"FSEEK")) {
1762: if(!(*arg)) break;
1763: fputc(CS_FIO_FUNCTION,out);
1764: if(isdigit(*arg2) || atol(arg2))
1765: fputc(FIO_SEEK,out);
1766: else
1767: fputc(FIO_SEEK_VAR,out);
1768: p=strchr(arg,' ');
1769: if(!p)
1770: break;
1771: *p=0;
1772: writecrc(src,arg); /* File handle */
1773: p=strchr(arg2,' ');
1774: if(p)
1775: *p=0;
1776: if(atol(arg2) || isdigit(*arg2)) {
1777: l=val(src,arg2);
1778: fwrite(&l,4,1,out); }
1779: else
1780: writecrc(src,arg2); /* Offset variable */
1781: i=0;
1782: if(p) {
1783: p++;
1784: while(*p && *p<=' ') p++;
1785: i=atoi(p);
1786: if(!stricmp(p,"CUR"))
1787: i=SEEK_CUR;
1788: else if(!stricmp(p,"END"))
1789: i=SEEK_END; }
1790: fwrite(&i,2,1,out);
1791: continue; }
1792: if(!stricmp(p,"FLOCK")) {
1793: if(!(*arg)) break;
1794: fputc(CS_FIO_FUNCTION,out);
1795: if(isdigit(*arg2) || atol(arg2))
1796: fputc(FIO_LOCK,out);
1797: else
1798: fputc(FIO_LOCK_VAR,out);
1799: p=strchr(arg,' ');
1800: if(!p)
1801: break;
1802: *p=0;
1803: writecrc(src,arg); /* File handle */
1804: if(atol(arg2) || isdigit(*arg2)) {
1805: l=val(src,arg2);
1806: if(!l)
1807: break;
1808: fwrite(&l,4,1,out); }
1809: else
1810: writecrc(src,arg2); /* Length variable */
1811: continue; }
1812: if(!stricmp(p,"FUNLOCK")) {
1813: if(!(*arg)) break;
1814: fputc(CS_FIO_FUNCTION,out);
1815: if(isdigit(*arg2) || atol(arg2))
1816: fputc(FIO_UNLOCK,out);
1817: else
1818: fputc(FIO_UNLOCK_VAR,out);
1819: p=strchr(arg,' ');
1820: if(!p)
1821: break;
1822: *p=0;
1823: writecrc(src,arg); /* File handle */
1824: if(atol(arg2) || isdigit(*arg2)) {
1825: l=val(src,arg2);
1826: if(!l)
1827: break;
1828: fwrite(&l,4,1,out); }
1829: else
1830: writecrc(src,arg2); /* Length variable */
1831: continue; }
1832: if(!stricmp(p,"FSET_LENGTH")) {
1833: if(!(*arg)) break;
1834: fputc(CS_FIO_FUNCTION,out);
1835: if(isdigit(*arg2) || atol(arg2))
1836: fputc(FIO_SET_LENGTH,out);
1837: else
1838: fputc(FIO_SET_LENGTH_VAR,out);
1839: p=strchr(arg,' ');
1840: if(!p)
1841: break;
1842: *p=0;
1843: writecrc(src,arg); /* File handle */
1844: if(atol(arg2) || isdigit(*arg2)) {
1845: l=val(src,arg2);
1846: fwrite(&l,4,1,out); }
1847: else
1848: writecrc(src,arg2); /* Length variable */
1849: continue; }
1850: if(!stricmp(p,"FPRINTF")) {
1851: if(!(*arg)) break;
1852: fputc(CS_FIO_FUNCTION,out);
1853: fputc(FIO_PRINTF,out);
1854: p=strchr(arg,' ');
1855: if(!p)
1856: break;
1857: *p=0;
1858: writecrc(src,arg); /* Write destination variable */
1859: p++;
1860: while(*p && *p<=' ') p++;
1861: arg=p;
1862: p=strrchr(arg,'"');
1863: if(!p)
1864: break;
1865: *p=0;
1866: p++;
1867: while(*p && *p<=' ') p++;
1868: writecstr(arg); /* Write string */
1869: l=ftell(out);
1870: fputc(0,out); /* Write total number of args */
1871: i=0;
1872: while(p && *p) {
1873: arg=p;
1874: p=strchr(arg,' ');
1875: if(p) {
1876: *p=0;
1877: p++; }
1878: writecrc(src,arg);
1879: i++; }
1880: fseek(out,l,SEEK_SET);
1881: fputc((char)i,out);
1882: fseek(out,i*4,SEEK_CUR);
1883: continue; }
1884: if(!stricmp(p,"FSET_ETX")) {
1885: if(!(*arg)) break;
1886: if((l=isvar(arg))!=0) {
1887: fputc(CS_USE_INT_VAR,out);
1888: fwrite(&l,4,1,out); /* variable */
1889: fputc(2,out); /* int offset */
1890: fputc(1,out); /* int length */
1891: ch=0; } /* place holder */
1892: else
1893: ch=val(src,arg);
1894:
1895: fputc(CS_FIO_FUNCTION,out);
1896: fputc(FIO_SET_ETX,out);
1897: fwrite(&ch,1,1,out);
1898: continue; }
1899: if(!stricmp(p,"FGET_TIME")) {
1900: if(!(*arg) || !(*arg2)) break;
1901: fputc(CS_FIO_FUNCTION,out);
1902: fputc(FIO_GET_TIME,out);
1903: p=strchr(arg,' ');
1904: if(!p)
1905: break;
1906: *p=0;
1907: writecrc(src,arg); /* File handle */
1908: writecrc(src,arg2); /* Variable */
1909: continue; }
1910: if(!stricmp(p,"FSET_TIME")) {
1911: if(!(*arg) || !(*arg2)) break;
1912: fputc(CS_FIO_FUNCTION,out);
1913: fputc(FIO_SET_TIME,out);
1914: p=strchr(arg,' ');
1915: if(!p)
1916: break;
1917: *p=0;
1918: writecrc(src,arg); /* File handle */
1919: writecrc(src,arg2); /* Variable */
1920: continue; }
1921: if(!stricmp(p,"REMOVE_FILE")) {
1922: if(!(*arg)) break;
1923: fputc(CS_FIO_FUNCTION,out);
1924: fputc(REMOVE_FILE,out);
1925: writecrc(src,arg); /* Str var */
1926: continue; }
1927: if(!stricmp(p,"RENAME_FILE")) {
1928: if(!(*arg) || !(*arg2)) break;
1929: fputc(CS_FIO_FUNCTION,out);
1930: fputc(RENAME_FILE,out);
1931: p=strchr(arg,' ');
1932: if(!p)
1933: break;
1934: *p=0;
1935: writecrc(src,arg); /* str var */
1936: writecrc(src,arg2); /* str var */
1937: continue; }
1938: if(!stricmp(p,"COPY_FILE")) {
1939: if(!(*arg) || !(*arg2)) break;
1940: fputc(CS_FIO_FUNCTION,out);
1941: fputc(COPY_FILE,out);
1942: p=strchr(arg,' ');
1943: if(!p)
1944: break;
1945: *p=0;
1946: writecrc(src,arg); /* str var */
1947: writecrc(src,arg2); /* str var */
1948: continue; }
1949: if(!stricmp(p,"MOVE_FILE")) {
1950: if(!(*arg) || !(*arg2)) break;
1951: fputc(CS_FIO_FUNCTION,out);
1952: fputc(MOVE_FILE,out);
1953: p=strchr(arg,' ');
1954: if(!p)
1955: break;
1956: *p=0;
1957: writecrc(src,arg); /* str var */
1958: writecrc(src,arg2); /* str var */
1959: continue; }
1960: if(!stricmp(p,"GET_FILE_ATTRIB")) {
1961: if(!(*arg) || !(*arg2)) break;
1962: fputc(CS_FIO_FUNCTION,out);
1963: fputc(GET_FILE_ATTRIB,out);
1964: p=strchr(arg,' ');
1965: if(!p)
1966: break;
1967: *p=0;
1968: writecrc(src,arg); /* str var */
1969: writecrc(src,arg2); /* int var */
1970: continue; }
1971: if(!stricmp(p,"SET_FILE_ATTRIB")) {
1972: if(!(*arg) || !(*arg2)) break;
1973: fputc(CS_FIO_FUNCTION,out);
1974: fputc(SET_FILE_ATTRIB,out);
1975: p=strchr(arg,' ');
1976: if(!p)
1977: break;
1978: *p=0;
1979: writecrc(src,arg); /* str var */
1980: writecrc(src,arg2); /* int var */
1981: continue; }
1982: if(!stricmp(p,"RMDIR") || !stricmp(p,"REMOVE_DIR")) {
1983: if(!(*arg)) break;
1984: fputc(CS_FIO_FUNCTION,out);
1985: fputc(REMOVE_DIR,out);
1986: writecrc(src,arg); /* Str var */
1987: continue; }
1988: if(!stricmp(p,"MKDIR") || !stricmp(p,"MAKE_DIR")) {
1989: if(!(*arg)) break;
1990: fputc(CS_FIO_FUNCTION,out);
1991: fputc(MAKE_DIR,out);
1992: writecrc(src,arg); /* Str var */
1993: continue; }
1994: if(!stricmp(p,"CHDIR") || !stricmp(p,"CHANGE_DIR")) {
1995: if(!(*arg)) break;
1996: printf("!WARNING: CHANGE_DIR deprecated in Synchronet v3+\n");
1997: printf(linestr,src,line,save);
1998: fputc(CS_FIO_FUNCTION,out);
1999: fputc(CHANGE_DIR,out);
2000: writecrc(src,arg); /* Str var */
2001: continue; }
2002: if(!stricmp(p,"OPEN_DIR")) {
2003: if(!(*arg) || !(*arg2)) break;
2004: fputc(CS_FIO_FUNCTION,out);
2005: fputc(OPEN_DIR,out);
2006: p=strchr(arg,' ');
2007: if(!p)
2008: break;
2009: *p=0;
2010: writecrc(src,arg); /* int var */
2011: writecrc(src,arg2); /* str var */
2012: continue; }
2013: if(!stricmp(p,"READ_DIR")) {
2014: if(!(*arg) || !(*arg2)) break;
2015: fputc(CS_FIO_FUNCTION,out);
2016: fputc(READ_DIR,out);
2017: p=strchr(arg,' ');
2018: if(!p)
2019: break;
2020: *p=0;
2021: writecrc(src,arg); /* int var */
2022: writecrc(src,arg2); /* str var */
2023: continue; }
2024: if(!stricmp(p,"REWIND_DIR")) {
2025: if(!(*arg)) break;
2026: fputc(CS_FIO_FUNCTION,out);
2027: fputc(REWIND_DIR,out);
2028: writecrc(src,arg); /* int var */
2029: continue; }
2030: if(!stricmp(p,"CLOSE_DIR")) {
2031: if(!(*arg)) break;
2032: fputc(CS_FIO_FUNCTION,out);
2033: fputc(CLOSE_DIR,out);
2034: writecrc(src,arg); /* int var */
2035: continue; }
2036:
2037: /* NET_FUNCTIONS */
2038:
2039: if(!stricmp(p,"SOCKET_OPEN")) {
2040: if(!(*arg)) break;
2041: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_OPEN);
2042: writecrc(src,arg); /* int var (socket) */
2043: continue;
2044: }
2045: if(!stricmp(p,"SOCKET_CLOSE")) {
2046: if(!(*arg)) break;
2047: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_CLOSE);
2048: writecrc(src,arg); /* int var (socket) */
2049: continue;
2050: }
2051: if(!stricmp(p,"SOCKET_CHECK")) {
2052: if(!(*arg)) break;
2053: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_CHECK);
2054: writecrc(src,arg); /* int var (socket) */
2055: continue;
2056: }
2057: if(!stricmp(p,"SOCKET_CONNECT")) {
2058: if(!(*arg) || !(*arg2) || !(*arg3)) break;
2059:
2060: /* TCP port */
2061: if((l=isvar(arg3))!=0) {
2062: fputc(CS_USE_INT_VAR,out);
2063: fwrite(&l,4,1,out); /* variable */
2064: fputc(10,out); /* int offset */
2065: fputc(2,out); /* int length */
2066: i=0; } /* place holder */
2067: else
2068: i=val(src,arg3);
2069:
2070: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_CONNECT);
2071: writecrc(src,arg); /* int var (socket) */
2072: writecrc(src,arg2); /* str var (address) */
2073: fwrite(&i,2,1,out);
2074: continue;
2075: }
2076: if(!stricmp(p,"SOCKET_ACCEPT")) {
2077: if(!(*arg)) break;
2078: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_ACCEPT);
2079: writecrc(src,arg); /* int var (socket) */
2080: continue;
2081: }
2082: if(!stricmp(p,"SOCKET_NREAD")) {
2083: if(!(*arg) || !(*arg2)) break;
2084: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_NREAD);
2085: writecrc(src,arg); /* int var (socket) */
2086: writecrc(src,arg2); /* int var (nbytes) */
2087: continue;
2088: }
2089: if(!stricmp(p,"SOCKET_READ")
2090: || !stricmp(p,"SOCKET_READLINE")
2091: || !stricmp(p,"SOCKET_PEEK")) {
2092: if(!(*arg) || !(*arg2)) break;
2093:
2094: /* length */
2095: if(!(*arg3))
2096: i=0;
2097: else if((l=isvar(arg3))!=0) {
2098: fputc(CS_USE_INT_VAR,out);
2099: fwrite(&l,4,1,out); /* variable */
2100: fputc(10,out); /* int offset */
2101: fputc(2,out); /* int length */
2102: i=0; } /* place holder */
2103: else
2104: i=val(src,arg3);
2105:
2106: if(!stricmp(p,"SOCKET_READ"))
2107: ch=CS_SOCKET_READ;
2108: else if(!stricmp(p,"SOCKET_READLINE"))
2109: ch=CS_SOCKET_READLINE;
2110: else
2111: ch=CS_SOCKET_PEEK;
2112: fprintf(out,"%c%c",CS_NET_FUNCTION,ch);
2113: writecrc(src,arg); /* int var (socket) */
2114: writecrc(src,arg2); /* str var (buffer) */
2115: fwrite(&i,sizeof(i),1,out); /* word (length) */
2116: continue;
2117: }
2118: if(!stricmp(p,"SOCKET_WRITE")) {
2119: if(!(*arg) || !(*arg2)) break;
2120: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_SOCKET_WRITE);
2121: writecrc(src,arg); /* int var (socket) */
2122: writecrc(src,arg2); /* str var (buffer) */
2123: continue;
2124: }
2125:
2126: /* FTP functions */
2127: if(!stricmp(p,"FTP_LOGIN")) {
2128: if(!(*arg) || !(*arg2) || !(*arg3)) break;
2129: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_LOGIN);
2130: writecrc(src,arg); /* int var (socket) */
2131: writecrc(src,arg2); /* int var (user) */
2132: writecrc(src,arg3); /* int var (password) */
2133: continue;
2134: }
2135: if(!stricmp(p,"FTP_LOGOUT")) {
2136: if(!(*arg)) break;
2137: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_LOGOUT);
2138: writecrc(src,arg); /* int var (socket) */
2139: continue;
2140: }
2141: if(!stricmp(p,"FTP_PWD")) {
2142: if(!(*arg)) break;
2143: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_PWD);
2144: writecrc(src,arg); /* int var (socket) */
2145: continue;
2146: }
2147: if(!stricmp(p,"FTP_CWD")) {
2148: if(!(*arg) || !(*arg2)) break;
2149: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_CWD);
2150: writecrc(src,arg); /* int var (socket) */
2151: writecrc(src,arg2); /* str var (path) */
2152: continue;
2153: }
2154: if(!stricmp(p,"FTP_DIR")) {
2155: if(!(*arg) || !(*arg2)) break;
2156: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_DIR);
2157: writecrc(src,arg); /* int var (socket) */
2158: writecrc(src,arg2); /* str var (path) */
2159: continue;
2160: }
2161: if(!stricmp(p,"FTP_GET")) {
2162: if(!(*arg) || !(*arg2) || !(*arg3)) break;
2163: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_GET);
2164: writecrc(src,arg); /* int var (socket) */
2165: writecrc(src,arg2); /* str var (src path) */
2166: writecrc(src,arg3); /* str var (dest path) */
2167: continue;
2168: }
2169: if(!stricmp(p,"FTP_PUT")) {
2170: if(!(*arg) || !(*arg2) || !(*arg3)) break;
2171: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_PUT);
2172: writecrc(src,arg); /* int var (socket) */
2173: writecrc(src,arg2); /* str var (src path) */
2174: writecrc(src,arg3); /* str var (dest path) */
2175: continue;
2176: }
2177: if(!stricmp(p,"FTP_DELETE")) {
2178: if(!(*arg) || !(*arg2)) break;
2179: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_DELETE);
2180: writecrc(src,arg); /* int var (socket) */
2181: writecrc(src,arg2); /* str var (path) */
2182: continue;
2183: }
2184: if(!stricmp(p,"FTP_RENAME")) {
2185: if(!(*arg) || !(*arg2) || !(*arg3)) break;
2186: fprintf(out,"%c%c",CS_NET_FUNCTION,CS_FTP_RENAME);
2187: writecrc(src,arg); /* int var (socket) */
2188: writecrc(src,arg2); /* str var (org name) */
2189: writecrc(src,arg3); /* str var (new name) */
2190: continue;
2191: }
2192:
2193: if(!stricmp(p,"NODE_ACTION")) {
2194: if(!(*arg)) break;
2195: if((l=isvar(arg))!=0) {
2196: fputc(CS_USE_INT_VAR,out);
2197: fwrite(&l,4,1,out); /* variable */
2198: fputc(1,out); /* int offset */
2199: fputc(1,out); /* int length */
2200: ch=0; } /* place holder */
2201: else
2202: ch=val(src,arg);
2203:
2204: fprintf(out,"%c%c",CS_NODE_ACTION,ch);
2205: continue; }
2206: if(!stricmp(p,"NODE_STATUS")) {
2207: if(!(*arg)) break;
2208: if((l=isvar(arg))!=0) {
2209: fputc(CS_USE_INT_VAR,out);
2210: fwrite(&l,4,1,out); /* variable */
2211: fputc(1,out); /* int offset */
2212: fputc(1,out); /* int length */
2213: ch=0; } /* place holder */
2214: else
2215: ch=val(src,arg);
2216:
2217: fprintf(out,"%c%c",CS_NODE_STATUS,ch);
2218: continue; }
2219: if(!stricmp(p,"END_CMD") || !stricmp(p,"ENDCMD")) {
2220: fprintf(out,"%c",CS_END_CMD);
2221: continue; }
2222: if(!stricmp(p,"CMD_POP") || !stricmp(p,"CMDPOP")) {
2223: fprintf(out,"%c",CS_CMD_POP);
2224: continue; }
2225: if(!stricmp(p,"CLS")) {
2226: fprintf(out,"%c",CS_CLS);
2227: continue; }
2228: if(!stricmp(p,"CRLF")) {
2229: fprintf(out,"%c",CS_CRLF);
2230: continue; }
2231: if(!stricmp(p,"PAUSE")) {
2232: fprintf(out,"%c",CS_PAUSE);
2233: continue; }
2234: if(!stricmp(p,"PAUSE_RESET")) {
2235: fprintf(out,"%c",CS_PAUSE_RESET);
2236: continue; }
2237: if(!stricmp(p,"CLEAR_ABORT")) {
2238: fprintf(out,"%c",CS_CLEAR_ABORT);
2239: continue; }
2240: if(!stricmp(p,"GETLINES")) {
2241: fprintf(out,"%c",CS_GETLINES);
2242: continue; }
2243: if(!stricmp(p,"GETFILESPEC")) {
2244: fprintf(out,"%c",CS_GETFILESPEC);
2245: continue; }
2246: if(!stricmp(p,"FINDUSER")) {
2247: fprintf(out,"%c",CS_FINDUSER);
2248: continue; }
2249: if(!stricmp(p,"MATCHUSER")) {
2250: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,MATCHUSER);
2251: writecrc(src,arg);
2252: writecrc(src,arg2);
2253: continue; }
2254:
2255: if(!stricmp(p,"LOG")) {
2256: if(!(*arg)) break;
2257: fprintf(out,"%c",CS_LOG);
2258: writecstr(arg);
2259: continue; }
2260: if(!stricmp(p,"MNEMONICS")) {
2261: if(!(*arg)) break;
2262: fprintf(out,"%c",CS_MNEMONICS);
2263: writecstr(arg);
2264: continue; }
2265: if(!stricmp(p,"PRINT")) {
2266: if(!(*arg)) break;
2267: fprintf(out,"%c",CS_PRINT);
2268: if(strstr(arg,"%s")!=NULL) {
2269: printf("!WARNING: PRINT \"%%s\" is a security hole if STR contains unvalidated input\n");
2270: printf(linestr,src,line,save);
2271: }
2272: writecstr(arg);
2273: continue; }
2274: if(!stricmp(p,"PRINT_LOCAL")) {
2275: if(!(*arg)) break;
2276: fprintf(out,"%c",CS_PRINT_LOCAL);
2277: writecstr(arg);
2278: continue; }
2279: if(!stricmp(p,"PRINT_REMOTE")) {
2280: if(!(*arg)) break;
2281: fprintf(out,"%c",CS_PRINT_REMOTE);
2282: writecstr(arg);
2283: continue; }
2284: if(!stricmp(p,"PRINTFILE")) {
2285: if(!(*arg)) break;
2286: if(*arg=='"') { /* NEED TO SUPPORT MODE HERE */
2287: fprintf(out,"%c",CS_PRINTFILE);
2288: writestr(arg); }
2289: else {
2290: if((l=isvar(arg2))!=0) {
2291: fputc(CS_USE_INT_VAR,out);
2292: fwrite(&l,4,1,out); /* variable */
2293: fputc(6,out); /* int offset */
2294: fputc(2,out); /* int length */
2295: i=0; } /* place holder */
2296: else
2297: i=val(src,arg2);
2298:
2299: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,PRINTFILE_VAR_MODE);
2300: p=strchr(arg,' ');
2301: if(p) *p=0;
2302: writecrc(src,arg);
2303: fwrite(&i,2,1,out); }
2304: continue; }
2305: if(!stricmp(p,"PRINTTAIL")) {
2306: if(!(*arg) || !(*arg2))
2307: break;
2308: if((l=isvar(arg3))!=0) {
2309: fputc(CS_USE_INT_VAR,out);
2310: fwrite(&l,4,1,out); /* variable */
2311: fputc(8,out); /* int offset */
2312: fputc(1,out); /* int length */
2313: j=0; } /* place holder */
2314: else
2315: j=val(src,arg3);
2316:
2317: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,PRINTTAIL_VAR_MODE);
2318: p=strchr(arg,' ');
2319: if(p) *p=0;
2320: writecrc(src,arg);
2321: i=val(src,arg2);
2322: fwrite(&i,2,1,out);
2323: fwrite(&j,1,1,out);
2324: continue; }
2325:
2326: if(!stricmp(p,"PRINTFILE_STR")) {
2327: fprintf(out,"%c",CS_PRINTFILE_STR);
2328: continue; }
2329: if(!stricmp(p,"PRINTFILE_LOCAL")) {
2330: if(!(*arg)) break;
2331: fprintf(out,"%c",CS_PRINTFILE_LOCAL);
2332: writestr(arg);
2333: continue; }
2334: if(!stricmp(p,"PRINTFILE_REMOTE")) {
2335: if(!(*arg)) break;
2336: fprintf(out,"%c",CS_PRINTFILE_REMOTE);
2337: writestr(arg);
2338: continue; }
2339:
2340: if(!stricmp(p,"TELNET_GATE")) {
2341: if(!(*arg)) break;
2342: if((l=isvar(arg2))!=0) {
2343: fputc(CS_USE_INT_VAR,out);
2344: fwrite(&l,4,1,out); /* variable */
2345: fputc(2,out); /* int offset */
2346: fputc(4,out); /* int length */
2347: l=0; } /* place holder */
2348: else if(*arg2)
2349: l=val(src,arg2);
2350: else
2351: l=0;
2352:
2353: if(*arg=='"') {
2354: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,TELNET_GATE_STR);
2355: fwrite(&l,4,1,out);
2356: writestr(arg);
2357: } else {
2358: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,TELNET_GATE_VAR);
2359: fwrite(&l,4,1,out);
2360: p=strchr(arg,' ');
2361: if(p) *p=0;
2362: writecrc(src,arg);
2363: }
2364: continue;
2365: }
2366:
2367: if(!stricmp(p,"EXEC")) {
2368: if(!(*arg)) break;
2369: fprintf(out,"%c",CS_EXEC);
2370: writestr(arg);
2371: continue; }
2372: if(!stricmp(p,"EXEC_INT")) {
2373: if(!(*arg)) break;
2374: fprintf(out,"%c",CS_EXEC_INT);
2375: writestr(arg);
2376: continue; }
2377: if(!stricmp(p,"EXEC_BIN")) {
2378: if(!(*arg)) break;
2379: fprintf(out,"%c",CS_EXEC_BIN);
2380: writestr(arg);
2381: continue; }
2382: if(!stricmp(p,"EXEC_XTRN")) {
2383: if(!(*arg)) break;
2384: fprintf(out,"%c",CS_EXEC_XTRN);
2385: writestr(arg);
2386: continue; }
2387:
2388: if(!stricmp(p,"SELECT_SHELL")) {
2389: fprintf(out,"%c",CS_SELECT_SHELL);
2390: continue; }
2391: if(!stricmp(p,"SET_SHELL")) {
2392: fprintf(out,"%c",CS_SET_SHELL);
2393: continue; }
2394: if(!stricmp(p,"SELECT_EDITOR")) {
2395: fprintf(out,"%c",CS_SELECT_EDITOR);
2396: continue; }
2397: if(!stricmp(p,"SET_EDITOR")) {
2398: fprintf(out,"%c",CS_SET_EDITOR);
2399: continue; }
2400:
2401: if(!stricmp(p,"YES_NO")) {
2402: if(!(*arg)) break;
2403: fprintf(out,"%c",CS_YES_NO);
2404: writecstr(arg);
2405: continue; }
2406: if(!stricmp(p,"NO_YES")) {
2407: if(!(*arg)) break;
2408: fprintf(out,"%c",CS_NO_YES);
2409: writecstr(arg);
2410: continue; }
2411: if(!stricmp(p,"MENU")) {
2412: if(!(*arg)) break;
2413: fprintf(out,"%c",CS_MENU);
2414: writestr(arg);
2415: continue; }
2416: if(!stricmp(p,"SET_MENU_DIR")) {
2417: if(!(*arg)) break;
2418: fprintf(out,"%c",CS_SET_MENU_DIR);
2419: writestr(arg);
2420: continue; }
2421: if(!stricmp(p,"SET_MENU_FILE")) {
2422: if(!(*arg)) break;
2423: fprintf(out,"%c",CS_SET_MENU_FILE);
2424: writestr(arg);
2425: continue; }
2426: if(!stricmp(p,"SEND_FILE_VIA")) {
2427: if(!(*arg) || !(*arg2)) break;
2428: if(*arg2=='"') {
2429: fprintf(out,"%c%c%c",CS_VAR_INSTRUCTION,SEND_FILE_VIA,*arg);
2430: writestr(arg2); }
2431: else {
2432: fprintf(out,"%c%c%c",CS_VAR_INSTRUCTION,SEND_FILE_VIA_VAR,*arg);
2433: writecrc(src,arg2); }
2434: continue; }
2435: if(!stricmp(p,"RECEIVE_FILE_VIA")) {
2436: if(!(*arg) || !(*arg2)) break;
2437: if(*arg2=='"') {
2438: fprintf(out,"%c%c%c",CS_VAR_INSTRUCTION,RECEIVE_FILE_VIA,*arg);
2439: writestr(arg2); }
2440: else {
2441: fprintf(out,"%c%c%c",CS_VAR_INSTRUCTION,RECEIVE_FILE_VIA_VAR,*arg);
2442: writecrc(src,arg2); }
2443: continue; }
2444: if(!stricmp(p,"CHKFILE")) {
2445: if(!(*arg)) break;
2446: if(*arg=='"') {
2447: fprintf(out,"%c",CS_CHKFILE);
2448: writestr(arg); }
2449: else {
2450: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,CHKFILE_VAR);
2451: writecrc(src,arg); }
2452: continue; }
2453: if(!stricmp(p,"GET_FILE_LENGTH")) {
2454: if(!(*arg) || !(*arg2))
2455: break;
2456: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,FLENGTH_TO_INT);
2457: p=strchr(arg,' ');
2458: if(p) *p=0;
2459: writecrc(src,arg);
2460: writecrc(src,arg2);
2461: continue; }
2462: if(!stricmp(p,"GET_FILE_TIME")) {
2463: if(!(*arg) || !(*arg2))
2464: break;
2465: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,FTIME_TO_INT);
2466: p=strchr(arg,' ');
2467: if(p) *p=0;
2468: writecrc(src,arg);
2469: writecrc(src,arg2);
2470: continue; }
2471: if(!stricmp(p,"CHARVAL")) {
2472: if(!(*arg) || !(*arg2))
2473: break;
2474: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,CHARVAL_TO_INT);
2475: p=strchr(arg,' ');
2476: if(p) *p=0;
2477: writecrc(src,arg);
2478: writecrc(src,arg2);
2479: continue; }
2480: if(!stricmp(p,"SETSTR")) {
2481: if(!(*arg)) break;
2482: fprintf(out,"%c",CS_SETSTR);
2483: writecstr(arg);
2484: continue; }
2485: if(!stricmp(p,"COMPARE_STR")) {
2486: if(!(*arg)) break;
2487: fprintf(out,"%c",CS_COMPARE_STR);
2488: writecstr(arg);
2489: continue; }
2490: if(!stricmp(p,"GET_TEMPLATE")) {
2491: if(!(*arg)) break;
2492: fprintf(out,"%c",CS_GET_TEMPLATE);
2493: writestr(arg);
2494: continue; }
2495: if(!stricmp(p,"READ_SIF")) {
2496: if(!(*arg)) break;
2497: fprintf(out,"%c",CS_READ_SIF);
2498: writestr(arg);
2499: continue; }
2500: if(!stricmp(p,"CREATE_SIF")) {
2501: if(!(*arg)) break;
2502: fprintf(out,"%c",CS_CREATE_SIF);
2503: writestr(arg);
2504: continue; }
2505: if(!stricmp(p,"TRASHCAN")) {
2506: if(!(*arg)) break;
2507: fprintf(out,"%c",CS_TRASHCAN);
2508: writestr(arg);
2509: continue; }
2510: if(!stricmp(p,"CMDSTR")) {
2511: if(!(*arg)) break;
2512: fprintf(out,"%c",CS_CMDSTR);
2513: writecstr(arg);
2514: continue; }
2515: if(!stricmp(p,"CMDKEYS")) {
2516: if(!(*arg)) break;
2517: fprintf(out,"%c",CS_CMDKEYS);
2518: for(p=arg;*p && *p!='#';p++) {
2519: ch=*p;
2520: if(ch=='"')
2521: continue;
2522: if(ch=='/') {
2523: p++;
2524: ch=*p|0x80; } /* high bit indicates slash required */
2525: else if(ch=='^' && *(p+1)>=0x40) {
2526: p++;
2527: ch=*p;
2528: ch-=0x40; }
2529: else if(ch=='\\') {
2530: p++;
2531: ch=cesc(*p); }
2532: fputc(ch,out); }
2533: fputc(0,out);
2534: continue; }
2535: if(!stricmp(p,"COMPARE_WORD")) {
2536: if(!(*arg)) break;
2537: fprintf(out,"%c",CS_COMPARE_WORD);
2538: writecstr(arg);
2539: continue; }
2540: if(!stricmp(p,"GETSTR")) {
2541: p=strchr(arg,' ');
2542: if(p) *p=0;
2543: if((!(*arg) || isdigit(*arg) || !stricmp(arg,"STR")) && !(*arg3))
2544: fprintf(out,"%c%c",CS_GETSTR,atoi(arg) ? atoi(arg)
2545: : *arg2 ? atoi(arg2) : 128);
2546: else {
2547: if((l=isvar(arg2))!=0) {
2548: fputc(CS_USE_INT_VAR,out);
2549: fwrite(&l,4,1,out); /* variable */
2550: fputc(6,out); /* int offset */
2551: fputc(1,out); /* int length */
2552: i=0; } /* place holder */
2553: else if(*arg2)
2554: i=val(src,arg2);
2555: else
2556: i=0;
2557:
2558: fprintf(out,"%c%c",CS_VAR_INSTRUCTION
2559: ,*arg3 ? GETSTR_MODE : GETSTR_VAR);
2560: writecrc(src,arg);
2561:
2562: if(!i) i=128;
2563: fwrite(&i,1,1,out);
2564: if(*arg3) {
2565: l=val(src,arg3);
2566: fwrite(&l,4,1,out); } }
2567: continue; }
2568: if(!stricmp(p,"GETNUM")) {
2569: if(!(*arg)) break;
2570: p=strchr(arg,' ');
2571: if(p) *p=0;
2572: if(isdigit(*arg)) {
2573: i=val(src,arg);
2574: fprintf(out,"%c",CS_GETNUM);
2575: fwrite(&i,2,1,out); }
2576: else {
2577: if((l=isvar(arg2))!=0) {
2578: fputc(CS_USE_INT_VAR,out);
2579: fwrite(&l,4,1,out); /* variable */
2580: fputc(6,out); /* int offset */
2581: fputc(2,out); /* int length */
2582: i=0; } /* place holder */
2583: else
2584: i=val(src,arg2);
2585:
2586: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,GETNUM_VAR);
2587: writecrc(src,arg);
2588: fwrite(&i,2,1,out); }
2589: continue; }
2590: if(!stricmp(p,"MSWAIT")) {
2591: if(!(*arg)) break;
2592: if((l=isvar(arg))!=0) {
2593: fputc(CS_USE_INT_VAR,out);
2594: fwrite(&l,4,1,out); /* variable */
2595: fputc(1,out); /* int offset */
2596: fputc(2,out); /* int length */
2597: i=0; } /* place holder */
2598: else
2599: i=val(src,arg);
2600:
2601: fprintf(out,"%c",CS_MSWAIT);
2602: fwrite(&i,2,1,out);
2603: continue; }
2604: if(!stricmp(p,"GETLINE")) {
2605: p=strchr(arg,' ');
2606: if(p) *p=0;
2607: if(!(*arg) || isdigit(*arg))
2608: fprintf(out,"%c%c",CS_GETLINE,*arg ? atoi(arg) :128);
2609: else {
2610: if((l=isvar(arg2))!=0) {
2611: fputc(CS_USE_INT_VAR,out);
2612: fwrite(&l,4,1,out); /* variable */
2613: fputc(6,out); /* int offset */
2614: fputc(1,out); /* int length */
2615: i=0; } /* place holder */
2616: else
2617: i=val(src,arg2);
2618:
2619: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,GETLINE_VAR);
2620: writecrc(src,arg);
2621: if(!i) i=128;
2622: fwrite(&i,1,1,out); }
2623: continue; }
2624: if(!stricmp(p,"GETSTRUPR")) {
2625: p=strchr(arg,' ');
2626: if(p) *p=0;
2627: if(!(*arg) || isdigit(*arg))
2628: fprintf(out,"%c%c",CS_GETSTRUPR,*arg ? atoi(arg) :128);
2629: else {
2630: if((l=isvar(arg2))!=0) {
2631: fputc(CS_USE_INT_VAR,out);
2632: fwrite(&l,4,1,out); /* variable */
2633: fputc(6,out); /* int offset */
2634: fputc(1,out); /* int length */
2635: i=0; } /* place holder */
2636: else
2637: i=val(src,arg2);
2638:
2639: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,GETSTRUPR_VAR);
2640: writecrc(src,arg);
2641: if(!i) i=128;
2642: fwrite(&i,1,1,out); }
2643: continue; }
2644: if(!stricmp(p,"GETNAME")) {
2645: p=strchr(arg,' ');
2646: if(p) *p=0;
2647: if(!(*arg) || isdigit(*arg))
2648: fprintf(out,"%c%c",CS_GETNAME,*arg ? atoi(arg) :25);
2649: else {
2650: if((l=isvar(arg2))!=0) {
2651: fputc(CS_USE_INT_VAR,out);
2652: fwrite(&l,4,1,out); /* variable */
2653: fputc(6,out); /* int offset */
2654: fputc(1,out); /* int length */
2655: i=0; } /* place holder */
2656: else
2657: i=atoi(arg2);
2658:
2659: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,GETNAME_VAR);
2660: writecrc(src,arg);
2661: if(!i) i=128;
2662: fwrite(&i,1,1,out); }
2663: continue; }
2664: if(!stricmp(p,"SHIFT_STR")) {
2665: if(!(*arg)) break;
2666: p=strchr(arg,' ');
2667: if(p) *p=0;
2668: if(isdigit(*arg))
2669: fprintf(out,"%c%c",CS_SHIFT_STR,atoi(arg));
2670: else {
2671: if((l=isvar(arg2))!=0) {
2672: fputc(CS_USE_INT_VAR,out);
2673: fwrite(&l,4,1,out); /* variable */
2674: fputc(6,out); /* int offset */
2675: fputc(1,out); /* int length */
2676: i=0; } /* place holder */
2677: else
2678: i=atoi(arg2);
2679:
2680: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,SHIFT_STR_VAR);
2681: writecrc(src,arg);
2682: if(!i) i=128;
2683: fwrite(&i,1,1,out); }
2684: continue; }
2685: if(!stricmp(p,"SHIFT_TO_FIRST_CHAR") || !stricmp(p,"SHIFT_TO_LAST_CHAR")) {
2686: if(!(*arg) || !(*arg2)) break;
2687: if((l=isvar(arg2))!=0) {
2688: fputc(CS_USE_INT_VAR,out);
2689: fwrite(&l,4,1,out); /* variable */
2690: fputc(6,out); /* int offset */
2691: fputc(1,out); /* int length */
2692: ch=0; } /* place holder */
2693: else
2694: ch=val(src,arg2);
2695:
2696: fprintf(out,"%c%c",CS_VAR_INSTRUCTION
2697: ,!stricmp(p,"SHIFT_TO_FIRST_CHAR") ? SHIFT_TO_FIRST_CHAR : SHIFT_TO_LAST_CHAR);
2698: writecrc(src,arg);
2699: fwrite(&ch,sizeof(ch),1,out);
2700: continue;
2701: }
2702: if(!stricmp(p,"TRUNCSP")) {
2703: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,TRUNCSP_STR_VAR);
2704: writecrc(src,arg);
2705: continue; }
2706: if(!stricmp(p,"STRIP_CTRL")) {
2707: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,STRIP_CTRL_STR_VAR);
2708: writecrc(src,arg);
2709: continue; }
2710: if(!stricmp(p,"STRUPR")) {
2711: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,STRUPR_VAR);
2712: writecrc(src,arg);
2713: continue; }
2714: if(!stricmp(p,"STRLWR")) {
2715: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,STRLWR_VAR);
2716: writecrc(src,arg);
2717: continue; }
2718: if(!stricmp(p,"STRLEN")) {
2719: if(!(*arg)) break;
2720: fprintf(out,"%c%c",CS_VAR_INSTRUCTION,STRLEN_INT_VAR);
2721: p=strchr(arg,' ');
2722: if(!p)
2723: break;
2724: *p=0;
2725: writecrc(src,arg);
2726: writecrc(src,arg2);
2727: continue; }
2728: if(!stricmp(p,"REPLACE_TEXT")) {
2729: if(!(*arg) || !(*arg2)) break;
2730: if((l=isvar(arg))!=0) {
2731: fputc(CS_USE_INT_VAR,out);
2732: fwrite(&l,4,1,out); /* variable */
2733: fputc(1,out); /* int offset */
2734: fputc(2,out); /* int length */
2735: i=0; } /* place holder */
2736: else
2737: i=val(src,arg);
2738:
2739: fprintf(out,"%c",CS_REPLACE_TEXT);
2740: fwrite(&i,2,1,out);
2741: writecstr(arg2);
2742: continue; }
2743: if(!stricmp(p,"REVERT_TEXT")) {
2744: if(!(*arg)) break;
2745: if(!stricmp(arg,"ALL"))
2746: i=0xffff;
2747: else {
2748: if((l=isvar(arg))!=0) {
2749: fputc(CS_USE_INT_VAR,out);
2750: fwrite(&l,4,1,out); /* variable */
2751: fputc(1,out); /* int offset */
2752: fputc(2,out); /* int length */
2753: i=0; } /* place holder */
2754: else
2755: i=val(src,arg); }
2756:
2757: fprintf(out,"%c",CS_REVERT_TEXT);
2758: fwrite(&i,2,1,out);
2759: continue; }
2760: if(!stricmp(p,"TOGGLE_USER_MISC")
2761: || !stricmp(p,"COMPARE_USER_MISC")) {
2762: if(!(*arg)) break;
2763:
2764: if((l=isvar(arg))!=0) {
2765: fputc(CS_USE_INT_VAR,out);
2766: fwrite(&l,4,1,out); /* variable */
2767: fputc(1,out); /* int offset */
2768: fputc(4,out); /* int length */
2769: l=0; } /* place holder */
2770: else
2771: l=val(src,arg);
2772:
2773: if(!stricmp(p,"TOGGLE_USER_MISC"))
2774: fprintf(out,"%c",CS_TOGGLE_USER_MISC);
2775: else
2776: fprintf(out,"%c",CS_COMPARE_USER_MISC);
2777: fwrite(&l,4,1,out);
2778: continue; }
2779:
2780: if(!stricmp(p,"TOGGLE_USER_CHAT")
2781: || !stricmp(p,"COMPARE_USER_CHAT")) {
2782: if(!(*arg)) break;
2783:
2784: if((l=isvar(arg))!=0) {
2785: fputc(CS_USE_INT_VAR,out);
2786: fwrite(&l,4,1,out); /* variable */
2787: fputc(1,out); /* int offset */
2788: fputc(4,out); /* int length */
2789: l=0; } /* place holder */
2790: else
2791: l=val(src,arg);
2792:
2793: if(!stricmp(p,"TOGGLE_USER_CHAT"))
2794: fprintf(out,"%c",CS_TOGGLE_USER_CHAT);
2795: else
2796: fprintf(out,"%c",CS_COMPARE_USER_CHAT);
2797: fwrite(&l,4,1,out);
2798: continue; }
2799:
2800: if(!stricmp(p,"TOGGLE_USER_QWK")
2801: || !stricmp(p,"COMPARE_USER_QWK")) {
2802: if(!(*arg)) break;
2803:
2804: if((l=isvar(arg))!=0) {
2805: fputc(CS_USE_INT_VAR,out);
2806: fwrite(&l,4,1,out); /* variable */
2807: fputc(1,out); /* int offset */
2808: fputc(4,out); /* int length */
2809: l=0; } /* place holder */
2810: else
2811: l=val(src,arg);
2812:
2813: if(!stricmp(p,"TOGGLE_USER_QWK"))
2814: fprintf(out,"%c",CS_TOGGLE_USER_QWK);
2815: else
2816: fprintf(out,"%c",CS_COMPARE_USER_QWK);
2817: fwrite(&l,4,1,out);
2818: continue; }
2819:
2820: if(!stricmp(p,"TOGGLE_NODE_MISC")
2821: || !stricmp(p,"COMPARE_NODE_MISC")) {
2822: if(!(*arg)) break;
2823:
2824: if((l=isvar(arg))!=0) {
2825: fputc(CS_USE_INT_VAR,out);
2826: fwrite(&l,4,1,out); /* variable */
2827: fputc(1,out); /* int offset */
2828: fputc(2,out); /* int length */
2829: i=0; } /* place holder */
2830: else
2831: i=val(src,arg);
2832:
2833: if(!stricmp(p,"TOGGLE_NODE_MISC"))
2834: fprintf(out,"%c",CS_TOGGLE_NODE_MISC);
2835: else
2836: fprintf(out,"%c",CS_COMPARE_NODE_MISC);
2837: fwrite(&i,2,1,out);
2838: continue; }
2839:
2840: if(!stricmp(p,"TOGGLE_USER_FLAG")) {
2841: if(!(*arg)) break;
2842: p=arg;
2843: fprintf(out,"%c%c",CS_TOGGLE_USER_FLAG,toupper(*p++));
2844: while(*p && *p<=' ') p++;
2845: fprintf(out,"%c",toupper(*p));
2846: continue; }
2847:
2848: if(!stricmp(p,"SET_USER_LEVEL")) {
2849: if(!(*arg)) break;
2850:
2851: if((l=isvar(arg))!=0) {
2852: fputc(CS_USE_INT_VAR,out);
2853: fwrite(&l,4,1,out); /* variable */
2854: fputc(1,out); /* int offset */
2855: fputc(1,out); /* int length */
2856: ch=0; } /* place holder */
2857: else
2858: ch=val(src,arg);
2859:
2860: fprintf(out,"%c%c",CS_SET_USER_LEVEL,ch);
2861: continue; }
2862:
2863: if(!stricmp(p,"SET_USER_STRING")) {
2864: if(!(*arg)) break;
2865:
2866: if((l=isvar(arg))!=0) {
2867: fputc(CS_USE_INT_VAR,out);
2868: fwrite(&l,4,1,out); /* variable */
2869: fputc(1,out); /* int offset */
2870: fputc(1,out); /* int length */
2871: ch=0; } /* place holder */
2872: else
2873: ch=val(src,arg);
2874:
2875: fprintf(out,"%c%c",CS_SET_USER_STRING,ch);
2876: continue; }
2877:
2878:
2879: if(!stricmp(p,"ADJUST_USER_CREDITS")) {
2880: if(!(*arg)) break;
2881:
2882: if((l=isvar(arg))!=0) {
2883: fputc(CS_USE_INT_VAR,out);
2884: fwrite(&l,4,1,out); /* variable */
2885: fputc(1,out); /* int offset */
2886: fputc(2,out); /* int length */
2887: i=0; } /* place holder */
2888: else
2889: i=val(src,arg);
2890:
2891: fprintf(out,"%c",CS_ADJUST_USER_CREDITS);
2892: fwrite(&i,2,1,out);
2893: continue; }
2894:
2895: if(!stricmp(p,"ADJUST_USER_MINUTES")) {
2896: if(!(*arg)) break;
2897:
2898: if((l=isvar(arg))!=0) {
2899: fputc(CS_USE_INT_VAR,out);
2900: fwrite(&l,4,1,out); /* variable */
2901: fputc(1,out); /* int offset */
2902: fputc(2,out); /* int length */
2903: i=0; } /* place holder */
2904: else
2905: i=val(src,arg);
2906:
2907: fprintf(out,"%c",CS_ADJUST_USER_MINUTES);
2908: fwrite(&i,2,1,out);
2909: continue; }
2910:
2911: if(!stricmp(p,"SHOW_MEM")) {
2912: fprintf(out,"%c",CS_SHOW_MEM);
2913: continue; }
2914: if(!stricmp(p,"GURU_LOG")) {
2915: fprintf(out,"%c",CS_GURU_LOG);
2916: continue; }
2917: if(!stricmp(p,"ERROR_LOG")) {
2918: fprintf(out,"%c",CS_ERROR_LOG);
2919: continue; }
2920: if(!stricmp(p,"SYSTEM_LOG")) {
2921: fprintf(out,"%c",CS_SYSTEM_LOG);
2922: continue; }
2923: if(!stricmp(p,"SYSTEM_YLOG")) {
2924: fprintf(out,"%c",CS_SYSTEM_YLOG);
2925: continue; }
2926: if(!stricmp(p,"SYSTEM_STATS")) {
2927: fprintf(out,"%c",CS_SYSTEM_STATS);
2928: continue; }
2929: if(!stricmp(p,"NODE_STATS")) {
2930: fprintf(out,"%c",CS_NODE_STATS);
2931: continue; }
2932: if(!stricmp(p,"CHANGE_USER")) {
2933: fprintf(out,"%c",CS_CHANGE_USER);
2934: continue; }
2935: if(!stricmp(p,"ANSI_CAPTURE")) {
2936: fprintf(out,"%c",CS_ANSI_CAPTURE);
2937: continue; }
2938: if(!stricmp(p,"LIST_TEXT_FILE")) {
2939: fprintf(out,"%c",CS_LIST_TEXT_FILE);
2940: continue; }
2941: if(!stricmp(p,"EDIT_TEXT_FILE")) {
2942: fprintf(out,"%c",CS_EDIT_TEXT_FILE);
2943: continue; }
2944:
2945:
2946: if(!stricmp(p,"COMPARE_KEY")) {
2947: if(!stricmp(arg,"DIGIT"))
2948: ch=CS_DIGIT;
2949: else if(!stricmp(arg,"EDIGIT"))
2950: ch=CS_EDIGIT;
2951: else
2952: ch=toupper(*arg);
2953: if(ch=='/')
2954: ch=(*arg)|0x80; /* high bit indicates slash required */
2955: else if(ch=='^' && (*(arg+1))>=0x40)
2956: ch=(*(arg+1))-0x40; /* ctrl char */
2957: else if(ch=='\\')
2958: ch=cesc(*(arg+1));
2959: else if(ch=='\'')
2960: ch=*(arg+1);
2961: fprintf(out,"%c%c",CS_COMPARE_KEY,ch);
2962: continue; }
2963: if(!stricmp(p,"COMPARE_CHAR")) {
2964: ch=*arg;
2965: fprintf(out,"%c%c",CS_COMPARE_CHAR,ch);
2966: continue; }
2967: if(!stricmp(p,"COMPARE_KEYS")) {
2968: fputc(CS_COMPARE_KEYS,out);
2969: for(p=arg;*p && *p!='#';p++) {
2970: ch=*p;
2971: if(ch=='"')
2972: continue;
2973: if(ch=='/') {
2974: p++;
2975: ch=*p|0x80; } /* high bit indicates slash required */
2976: else if(ch=='^' && *(p+1)>=0x40) {
2977: p++;
2978: ch=*p;
2979: ch-=0x40; }
2980: else if(ch=='\\') {
2981: p++;
2982: ch=cesc(*p); }
2983: fputc(ch,out); }
2984: fputc(0,out);
2985: continue; }
2986: if(!stricmp(p,"GETCMD")) {
2987: fprintf(out,"%c",CS_GETCMD);
2988: writecstr(arg);
2989: continue; }
2990: if(!stricmp(p,"INKEY")) {
2991: fprintf(out,"%c",CS_INKEY);
2992: continue; }
2993: if(!stricmp(p,"INCHAR")) {
2994: fprintf(out,"%c",CS_INCHAR);
2995: continue; }
2996: if(!stricmp(p,"GETKEY")) {
2997: fprintf(out,"%c",CS_GETKEY);
2998: continue; }
2999: if(!stricmp(p,"GETCHAR")) {
3000: fprintf(out,"%c",CS_GETCHAR);
3001: continue; }
3002: if(!stricmp(p,"GETKEYE")) {
3003: fprintf(out,"%c",CS_GETKEYE);
3004: continue; }
3005: if(!stricmp(p,"UNGETKEY")) {
3006: fprintf(out,"%c",CS_UNGETKEY);
3007: continue; }
3008: if(!stricmp(p,"UNGETSTR")) {
3009: fprintf(out,"%c",CS_UNGETSTR);
3010: continue; }
3011: if(!stricmp(p,"PRINTKEY")) {
3012: fprintf(out,"%c",CS_PRINTKEY);
3013: continue; }
3014: if(!stricmp(p,"PRINTSTR")) {
3015: fprintf(out,"%c",CS_PRINTSTR);
3016: continue; }
3017:
3018: /* FUNCTIONS */
3019:
3020: if(!stricmp(p,"NODELIST_ALL")) {
3021: fprintf(out,"%c",CS_NODELIST_ALL);
3022: continue; }
3023: if(!stricmp(p,"NODELIST_USERS")) {
3024: fprintf(out,"%c",CS_NODELIST_USERS);
3025: continue; }
3026:
3027: if(!stricmp(p,"USERLIST_ALL")) {
3028: fprintf(out,"%c",CS_USERLIST_ALL);
3029: continue; }
3030: if(!stricmp(p,"USERLIST_SUB")) {
3031: fprintf(out,"%c",CS_USERLIST_SUB);
3032: continue; }
3033: if(!stricmp(p,"USERLIST_DIR")) {
3034: fprintf(out,"%c",CS_USERLIST_DIR);
3035: continue; }
3036: if(!stricmp(p,"USERLIST_LOGONS")) {
3037: fprintf(out,"%c",CS_USERLIST_LOGONS);
3038: continue; }
3039:
3040: if(!stricmp(p,"HANGUP")) {
3041: fprintf(out,"%c",CS_HANGUP);
3042: continue; }
3043:
3044: if(!stricmp(p,"LOGOFF")) {
3045: fprintf(out,"%c",CS_LOGOFF);
3046: continue; }
3047:
3048: if(!stricmp(p,"LOGOFF_FAST")) {
3049: fprintf(out,"%c",CS_LOGOFF_FAST);
3050: continue; }
3051:
3052: if(!stricmp(p,"AUTO_MESSAGE")) {
3053: fprintf(out,"%c",CS_AUTO_MESSAGE);
3054: continue; }
3055:
3056: if(!stricmp(p,"MINUTE_BANK")) {
3057: fprintf(out,"%c",CS_MINUTE_BANK);
3058: continue; }
3059:
3060: if(!stricmp(p,"USER_EDIT")) {
3061: fprintf(out,"%c",CS_USER_EDIT);
3062: continue; }
3063:
3064: if(!stricmp(p,"USER_DEFAULTS")) {
3065: fprintf(out,"%c",CS_USER_DEFAULTS);
3066: continue; }
3067:
3068: if(!stricmp(p,"PAGE_SYSOP")) {
3069: fprintf(out,"%c",CS_PAGE_SYSOP);
3070: continue; }
3071: if(!stricmp(p,"PAGE_GURU")) {
3072: fprintf(out,"%c",CS_PAGE_GURU);
3073: continue; }
3074: if(!stricmp(p,"SPY")) {
3075: fprintf(out,"%c",CS_SPY);
3076: continue; }
3077:
3078:
3079: if(!stricmp(p,"PRIVATE_CHAT")) {
3080: fprintf(out,"%c",CS_PRIVATE_CHAT);
3081: continue; }
3082:
3083: if(!stricmp(p,"PRIVATE_MESSAGE")) {
3084: fprintf(out,"%c",CS_PRIVATE_MESSAGE);
3085: continue; }
3086:
3087: if(!stricmp(p,"MULTINODE_CHAT")) {
3088: if(!(*arg))
3089: ch=1;
3090: else {
3091: if((l=isvar(arg))!=0) {
3092: fputc(CS_USE_INT_VAR,out);
3093: fwrite(&l,4,1,out); /* variable */
3094: fputc(1,out); /* int offset */
3095: fputc(1,out); /* int length */
3096: ch=0; } /* place holder */
3097: else
3098: ch=val(src,arg);
3099: }
3100:
3101: fprintf(out,"%c%c",CS_MULTINODE_CHAT,ch);
3102: continue; }
3103:
3104: if(!stricmp(p,"MAIL_READ")) {
3105: fprintf(out,"%c",CS_MAIL_READ);
3106: continue; }
3107: if(!stricmp(p,"MAIL_READ_SENT")) { /* Kill/read sent mail */
3108: fprintf(out,"%c",CS_MAIL_READ_SENT);
3109: continue; }
3110: if(!stricmp(p,"MAIL_READ_ALL")) {
3111: fprintf(out,"%c",CS_MAIL_READ_ALL);
3112: continue; }
3113: if(!stricmp(p,"MAIL_SEND")) { /* Send E-mail */
3114: fprintf(out,"%c",CS_MAIL_SEND);
3115: continue; }
3116: if(!stricmp(p,"MAIL_SEND_FEEDBACK")) { /* Feedback */
3117: fprintf(out,"%c",CS_MAIL_SEND_FEEDBACK);
3118: continue; }
3119: if(!stricmp(p,"MAIL_SEND_NETMAIL")) {
3120: fprintf(out,"%c",CS_MAIL_SEND_NETMAIL);
3121: continue; }
3122: if(!stricmp(p,"MAIL_SEND_NETFILE")) {
3123: fprintf(out,"%c",CS_MAIL_SEND_NETFILE);
3124: continue; }
3125: if(!stricmp(p,"MAIL_SEND_FILE")) { /* Upload Attached File to E-mail */
3126: fprintf(out,"%c",CS_MAIL_SEND_FILE);
3127: continue; }
3128: if(!stricmp(p,"MAIL_SEND_BULK")) {
3129: fprintf(out,"%c",CS_MAIL_SEND_BULK);
3130: continue; }
3131:
3132:
3133: if(!stricmp(p,"MSG_SET_AREA")) {
3134: fprintf(out,"%c",CS_MSG_SET_AREA);
3135: continue; }
3136: if(!stricmp(p,"MSG_SET_GROUP")) {
3137: fprintf(out,"%c",CS_MSG_SET_GROUP);
3138: continue; }
3139: if(!stricmp(p,"MSG_SELECT_AREA")) {
3140: fprintf(out,"%c",CS_MSG_SELECT_AREA);
3141: continue; }
3142: if(!stricmp(p,"MSG_SHOW_GROUPS")) {
3143: fprintf(out,"%c",CS_MSG_SHOW_GROUPS);
3144: continue; }
3145: if(!stricmp(p,"MSG_SHOW_SUBBOARDS")) {
3146: fprintf(out,"%c",CS_MSG_SHOW_SUBBOARDS);
3147: continue; }
3148: if(!stricmp(p,"MSG_GROUP_UP")) {
3149: fprintf(out,"%c",CS_MSG_GROUP_UP);
3150: continue; }
3151: if(!stricmp(p,"MSG_GROUP_DOWN")) {
3152: fprintf(out,"%c",CS_MSG_GROUP_DOWN);
3153: continue; }
3154: if(!stricmp(p,"MSG_SUBBOARD_UP")) {
3155: fprintf(out,"%c",CS_MSG_SUBBOARD_UP);
3156: continue; }
3157: if(!stricmp(p,"MSG_SUBBOARD_DOWN")) {
3158: fprintf(out,"%c",CS_MSG_SUBBOARD_DOWN);
3159: continue; }
3160: if(!stricmp(p,"MSG_GET_SUB_NUM")) {
3161: fprintf(out,"%c",CS_MSG_GET_SUB_NUM);
3162: continue; }
3163: if(!stricmp(p,"MSG_GET_GRP_NUM")) {
3164: fprintf(out,"%c",CS_MSG_GET_GRP_NUM);
3165: continue; }
3166: if(!stricmp(p,"MSG_READ")) {
3167: fprintf(out,"%c",CS_MSG_READ);
3168: continue; }
3169: if(!stricmp(p,"MSG_POST")) {
3170: fprintf(out,"%c",CS_MSG_POST);
3171: continue; }
3172: if(!stricmp(p,"MSG_QWK")) {
3173: fprintf(out,"%c",CS_MSG_QWK);
3174: continue; }
3175: if(!stricmp(p,"MSG_PTRS_CFG")) {
3176: fprintf(out,"%c",CS_MSG_PTRS_CFG);
3177: continue; }
3178: if(!stricmp(p,"MSG_PTRS_REINIT")) {
3179: fprintf(out,"%c",CS_MSG_PTRS_REINIT);
3180: continue; }
3181: if(!stricmp(p,"MSG_NEW_SCAN_CFG")) {
3182: fprintf(out,"%c",CS_MSG_NEW_SCAN_CFG);
3183: continue; }
3184: if(!stricmp(p,"MSG_NEW_SCAN")) {
3185: fprintf(out,"%c",CS_MSG_NEW_SCAN);
3186: continue; }
3187: if(!stricmp(p,"MSG_NEW_SCAN_SUB")) {
3188: fprintf(out,"%c",CS_MSG_NEW_SCAN_SUB);
3189: continue; }
3190: if(!stricmp(p,"MSG_NEW_SCAN_ALL")) {
3191: fprintf(out,"%c",CS_MSG_NEW_SCAN_ALL);
3192: continue; }
3193: if(!stricmp(p,"MSG_CONT_SCAN")) {
3194: fprintf(out,"%c",CS_MSG_CONT_SCAN);
3195: continue; }
3196: if(!stricmp(p,"MSG_CONT_SCAN_ALL")) {
3197: fprintf(out,"%c",CS_MSG_CONT_SCAN_ALL);
3198: continue; }
3199: if(!stricmp(p,"MSG_BROWSE_SCAN")) {
3200: fprintf(out,"%c",CS_MSG_BROWSE_SCAN);
3201: continue; }
3202: if(!stricmp(p,"MSG_BROWSE_SCAN_ALL")) {
3203: fprintf(out,"%c",CS_MSG_BROWSE_SCAN_ALL);
3204: continue; }
3205: if(!stricmp(p,"MSG_FIND_TEXT")) {
3206: fprintf(out,"%c",CS_MSG_FIND_TEXT);
3207: continue; }
3208: if(!stricmp(p,"MSG_FIND_TEXT_ALL")) {
3209: fprintf(out,"%c",CS_MSG_FIND_TEXT_ALL);
3210: continue; }
3211: if(!stricmp(p,"MSG_YOUR_SCAN_CFG")) {
3212: fprintf(out,"%c",CS_MSG_YOUR_SCAN_CFG);
3213: continue; }
3214: if(!stricmp(p,"MSG_YOUR_SCAN")) {
3215: fprintf(out,"%c",CS_MSG_YOUR_SCAN);
3216: continue; }
3217: if(!stricmp(p,"MSG_YOUR_SCAN_ALL")) {
3218: fprintf(out,"%c",CS_MSG_YOUR_SCAN_ALL);
3219: continue; }
3220: if(!stricmp(p,"CHAT_SECTION")) {
3221: fprintf(out,"%c",CS_CHAT_SECTION);
3222: continue; }
3223: if(!stricmp(p,"TEXT_FILE_SECTION")) {
3224: fprintf(out,"%c",CS_TEXT_FILE_SECTION);
3225: continue; }
3226: if(!stricmp(p,"XTRN_EXEC")) {
3227: fprintf(out,"%c",CS_XTRN_EXEC);
3228: continue; }
3229: if(!stricmp(p,"XTRN_SECTION")) {
3230: fprintf(out,"%c",CS_XTRN_SECTION);
3231: continue; }
3232:
3233: if(!stricmp(p,"FILE_SET_AREA")) {
3234: fprintf(out,"%c",CS_FILE_SET_AREA);
3235: continue; }
3236: if(!stricmp(p,"FILE_SET_LIBRARY")) {
3237: fprintf(out,"%c",CS_FILE_SET_LIBRARY);
3238: continue; }
3239: if(!stricmp(p,"FILE_SELECT_AREA")) {
3240: fprintf(out,"%c",CS_FILE_SELECT_AREA);
3241: continue; }
3242: if(!stricmp(p,"FILE_SHOW_LIBRARIES")) {
3243: fprintf(out,"%c",CS_FILE_SHOW_LIBRARIES);
3244: continue; }
3245: if(!stricmp(p,"FILE_SHOW_DIRECTORIES")) {
3246: fprintf(out,"%c",CS_FILE_SHOW_DIRECTORIES);
3247: continue; }
3248: if(!stricmp(p,"FILE_LIBRARY_UP")) {
3249: fprintf(out,"%c",CS_FILE_LIBRARY_UP);
3250: continue; }
3251: if(!stricmp(p,"FILE_LIBRARY_DOWN")) {
3252: fprintf(out,"%c",CS_FILE_LIBRARY_DOWN);
3253: continue; }
3254: if(!stricmp(p,"FILE_DIRECTORY_UP")) {
3255: fprintf(out,"%c",CS_FILE_DIRECTORY_UP);
3256: continue; }
3257: if(!stricmp(p,"FILE_DIRECTORY_DOWN")) {
3258: fprintf(out,"%c",CS_FILE_DIRECTORY_DOWN);
3259: continue; }
3260: if(!stricmp(p,"FILE_GET_DIR_NUM")) {
3261: fprintf(out,"%c",CS_FILE_GET_DIR_NUM);
3262: continue; }
3263: if(!stricmp(p,"FILE_GET_LIB_NUM")) {
3264: fprintf(out,"%c",CS_FILE_GET_LIB_NUM);
3265: continue; }
3266: if(!stricmp(p,"FILE_UPLOAD")) {
3267: fprintf(out,"%c",CS_FILE_UPLOAD);
3268: continue; }
3269: if(!stricmp(p,"FILE_UPLOAD_USER")) {
3270: fprintf(out,"%c",CS_FILE_UPLOAD_USER);
3271: continue; }
3272: if(!stricmp(p,"FILE_UPLOAD_BULK")) {
3273: fprintf(out,"%c",CS_FILE_UPLOAD_BULK);
3274: continue; }
3275: if(!stricmp(p,"FILE_UPLOAD_SYSOP")) {
3276: fprintf(out,"%c",CS_FILE_UPLOAD_SYSOP);
3277: continue; }
3278: if(!stricmp(p,"FILE_RESORT_DIRECTORY")) {
3279: fprintf(out,"%c",CS_FILE_RESORT_DIRECTORY);
3280: continue; }
3281: if(!stricmp(p,"FILE_SET_ALT_PATH")) {
3282: fprintf(out,"%c",CS_FILE_SET_ALT_PATH);
3283: continue; }
3284: if(!stricmp(p,"FILE_GET")) {
3285: fprintf(out,"%c",CS_FILE_GET);
3286: continue; }
3287: if(!stricmp(p,"FILE_SEND")) {
3288: fprintf(out,"%c",CS_FILE_SEND);
3289: continue; }
3290: if(!stricmp(p,"FILE_PUT")) {
3291: fprintf(out,"%c",CS_FILE_PUT);
3292: continue; }
3293: if(!stricmp(p,"FILE_RECEIVE")) {
3294: fprintf(out,"%c",CS_FILE_RECEIVE);
3295: continue; }
3296: if(!stricmp(p,"FILE_FIND_OLD")) {
3297: fprintf(out,"%c",CS_FILE_FIND_OLD);
3298: continue; }
3299: if(!stricmp(p,"FILE_FIND_OPEN")) {
3300: fprintf(out,"%c",CS_FILE_FIND_OPEN);
3301: continue; }
3302: if(!stricmp(p,"FILE_FIND_OFFLINE")) {
3303: fprintf(out,"%c",CS_FILE_FIND_OFFLINE);
3304: continue; }
3305: if(!stricmp(p,"FILE_FIND_OLD_UPLOADS")) {
3306: fprintf(out,"%c",CS_FILE_FIND_OLD_UPLOADS);
3307: continue; }
3308: if(!stricmp(p,"FILE_DOWNLOAD")) {
3309: fprintf(out,"%c",CS_FILE_DOWNLOAD);
3310: continue; }
3311: if(!stricmp(p,"FILE_DOWNLOAD_USER")) {
3312: fprintf(out,"%c",CS_FILE_DOWNLOAD_USER);
3313: continue; }
3314: if(!stricmp(p,"FILE_DOWNLOAD_BATCH")) {
3315: fprintf(out,"%c",CS_FILE_DOWNLOAD_BATCH);
3316: continue; }
3317: if(!stricmp(p,"FILE_REMOVE")) {
3318: fprintf(out,"%c",CS_FILE_REMOVE);
3319: continue; }
3320: if(!stricmp(p,"FILE_LIST")) {
3321: fprintf(out,"%c",CS_FILE_LIST);
3322: continue; }
3323: if(!stricmp(p,"FILE_LIST_EXTENDED")) {
3324: fprintf(out,"%c",CS_FILE_LIST_EXTENDED);
3325: continue; }
3326: if(!stricmp(p,"FILE_VIEW")) {
3327: fprintf(out,"%c",CS_FILE_VIEW);
3328: continue; }
3329: if(!stricmp(p,"FILE_FIND_TEXT")) {
3330: fprintf(out,"%c",CS_FILE_FIND_TEXT);
3331: continue; }
3332: if(!stricmp(p,"FILE_FIND_TEXT_ALL")) {
3333: fprintf(out,"%c",CS_FILE_FIND_TEXT_ALL);
3334: continue; }
3335: if(!stricmp(p,"FILE_FIND_NAME")) {
3336: fprintf(out,"%c",CS_FILE_FIND_NAME);
3337: continue; }
3338: if(!stricmp(p,"FILE_FIND_NAME_ALL")) {
3339: fprintf(out,"%c",CS_FILE_FIND_NAME_ALL);
3340: continue; }
3341: if(!stricmp(p,"FILE_BATCH_SECTION")) {
3342: fprintf(out,"%c",CS_FILE_BATCH_SECTION);
3343: continue; }
3344: if(!stricmp(p,"FILE_TEMP_SECTION")) {
3345: fprintf(out,"%c",CS_FILE_TEMP_SECTION);
3346: continue; }
3347: if(!stricmp(p,"FILE_NEW_SCAN")) {
3348: fprintf(out,"%c",CS_FILE_NEW_SCAN);
3349: continue; }
3350: if(!stricmp(p,"FILE_NEW_SCAN_ALL")) {
3351: fprintf(out,"%c",CS_FILE_NEW_SCAN_ALL);
3352: continue; }
3353: if(!stricmp(p,"FILE_NEW_SCAN_CFG")) {
3354: fprintf(out,"%c",CS_FILE_NEW_SCAN_CFG);
3355: continue; }
3356: if(!stricmp(p,"FILE_PTRS_CFG")) {
3357: fprintf(out,"%c",CS_FILE_PTRS_CFG);
3358: continue; }
3359: if(!stricmp(p,"FILE_BATCH_ADD")) {
3360: fprintf(out,"%c",CS_FILE_BATCH_ADD);
3361: continue; }
3362: if(!stricmp(p,"FILE_BATCH_ADD_LIST")) {
3363: fprintf(out,"%c",CS_FILE_BATCH_ADD_LIST);
3364: continue; }
3365: if(!stricmp(p,"FILE_BATCH_CLEAR")) {
3366: fprintf(out,"%c",CS_FILE_BATCH_CLEAR);
3367: continue; }
3368:
3369: if(!stricmp(p,"INC_MAIN_CMDS")) {
3370: fprintf(out,"%c",CS_INC_MAIN_CMDS);
3371: continue; }
3372: if(!stricmp(p,"INC_FILE_CMDS")) {
3373: fprintf(out,"%c",CS_INC_FILE_CMDS);
3374: continue; }
3375:
3376: break; }
3377:
3378:
3379: if(!feof(in)) {
3380: printf("!SYNTAX ERROR:\n");
3381: printf(linestr,src,line,save);
3382: bail(1); }
3383: fclose(in);
3384: free(str);
3385: free(save);
3386: }
3387:
3388: char *banner= "\n"
3389: "BAJA v2.34-%s (rev %s) - Synchronet Shell/Module Compiler\n";
3390:
3391: char *usage= "\n"
3392: "usage: baja [-opts] file[.src]\n"
3393: "\n"
3394: " opts: -d display debug during compile\n"
3395: " -c case sensitive variables, labels, and macros\n"
3396: " -o set output directory (e.g. -o/sbbs/exec)\n"
3397: " -i set include directory (e.g. -i/sbbs/exec)\n"
3398: " -q quiet mode (no banner)\n"
3399: " -p pause on error\n"
3400: ;
3401:
3402: int main(int argc, char **argv)
3403: {
3404: char src[MAX_PATH+1]="",*p;
3405: char path[MAX_PATH+1];
3406: int i,j;
3407: int show_banner=TRUE;
3408: char revision[16];
3409:
3410: sscanf("$Revision: 1.42 $", "%*s %s", revision);
3411:
3412: for(i=1;i<argc;i++)
3413: if(argv[i][0]=='-'
3414: #ifdef _WIN32
3415: || argv[i][0]=='/'
3416: #endif
3417: )
3418: switch(toupper(argv[i][1])) {
3419: case 'D':
3420: display=1;
3421: break;
3422: case 'C':
3423: case_sens=1;
3424: break;
3425: case 'O':
3426: SAFECOPY(output_dir,argv[i]+2);
3427: backslash(output_dir);
3428: break;
3429: case 'I':
3430: SAFECOPY(include_dir,argv[i]+2);
3431: backslash(include_dir);
3432: break;
3433: case 'P':
3434: pause_on_error=TRUE;
3435: break;
3436: case 'Q':
3437: show_banner=0;
3438: break;
3439: default:
3440: printf(banner,PLATFORM_DESC,revision);
3441: printf(usage);
3442: bail(1); }
3443: else
3444: sprintf(src,"%.*s",sizeof(src)-5,argv[i]); /* leave room for '.src' to be appended */
3445:
3446: if(show_banner)
3447: printf(banner,PLATFORM_DESC,revision);
3448:
3449: if(!src[0]) {
3450: printf(usage);
3451: bail(1);
3452: }
3453:
3454: if(include_dir[0]==0) { /* Include directory not specified */
3455: SAFECOPY(include_dir,src); /* Default to same dir as src file */
3456: if((p=getfname(include_dir))!=NULL)
3457: *p=0; /* Truncate off the src filename */
3458: }
3459: if(getfext(src)==NULL)
3460: strcat(src,".src");
3461:
3462: SAFECOPY(bin_file,src);
3463: if((p=getfext(bin_file))!=NULL)
3464: *p=0;
3465: strcat(bin_file,".bin");
3466:
3467: if(output_dir[0]) {
3468: p=getfname(bin_file);
3469: SAFEPRINTF2(path,"%s%s",output_dir,p);
3470: SAFECOPY(bin_file,path);
3471: }
3472:
3473: if((out=fopen(bin_file,"w+b"))==NULL) {
3474: printf("error %d opening %s for write\n",errno,bin_file);
3475: bail(1);
3476: }
3477:
3478: printf("\nCompiling %s...\n",src);
3479:
3480: compile(src);
3481:
3482: /****************************/
3483: /* Resolve GOTOS and CALLS */
3484: /****************************/
3485:
3486: printf("Resolving labels...\n");
3487:
3488: for(i=0;i<gotos;i++) {
3489: for(j=0;j<labels;j++)
3490: if(!stricmp(goto_label[i],label_name[j]))
3491: break;
3492: if(j>=labels) {
3493: printf("%s line %d: label (%s) not found.\n"
3494: ,goto_file[i],goto_line[i],goto_label[i]);
3495: bail(1); }
3496: fseek(out,(long)(goto_indx[i]+1),SEEK_SET);
3497: fwrite(&label_indx[j],2,1,out); }
3498:
3499: for(i=0;i<calls;i++) {
3500: for(j=0;j<labels;j++)
3501: if((!case_sens
3502: && !strnicmp(call_label[i],label_name[j],strlen(call_label[i])))
3503: || (case_sens
3504: && !strncmp(call_label[i],label_name[j],strlen(call_label[i]))))
3505: break;
3506: if(j>=labels) {
3507: printf("%s line %d: label (%s) not found.\n"
3508: ,call_file[i],call_line[i],call_label[i]);
3509: bail(1); }
3510: fseek(out,(long)(call_indx[i]+1),SEEK_SET);
3511: fwrite(&label_indx[j],2,1,out); }
3512:
3513: printf("\nDone.\n");
3514: return(0);
3515: }
3516:
3517:
3518:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.