#include #include #include #include #include "globals.h" #include "functions.h" int parse_body(int iflag) { char token[TOKENSIZE]; char tmptoken[TOKENSIZE]; char newtoken[LINELENGTH]; int tokentype,c,ch; in_body++; while((tokentype=gettoken(token))!=0) { newtoken[0]=0; #ifdef DEBUG printf("parse_body(%i): %s (type=%i)\n",iflag,token,tokentype); #endif if (tokentype==5) /* EOL */ { if (iflag==1) { break; } putc('\n',out); } else if (tokentype==6) { if (iflag==1) { tokentypepush=tokentype; strcpy(tokenpush,token); putc('\n',out); if (in_body==1) { in_body--; return 0; } else { copyhtml(); } } else { fprintf(out,"?>"); if (in_body==1) { in_body--; return 0; } else { copyhtml(); } } } else if (strcasecmp(token,"case")==0) { strcpy(tokenpush,token); tokentypepush=tokentype; break; } else if ((strcasecmp(token,"loop")==0 || strcasecmp(token,"wend")==0) || (strcasecmp(token,"next")==0)) { break; } else if (strcasecmp(token,"end")==0) { c=gettoken(tmptoken); if (c!=5) { push(tmptoken,c); break; } autoindent(); fprintf(out,"exit();\n"); } else if (strcasecmp(token,"elseif")==0) { indent--; autoindent(); fprintf(out,"}\n"); autoindent(); fprintf(out," else\n"); autoindent(); fprintf(out,"if "); parse_condition(); tokentype=gettoken(token); fprintf(out,"\n"); autoindent(); fprintf(out,"{\n"); indent++; } else if (strcasecmp(token,"session")==0) { parse_session(); } else if (strcasecmp(token,"else")==0) { /* single line if/then/else needs an extra newline - MHB - 4/10/06 */ if (iflag==1) fprintf(out,"\n"); indent--; autoindent(); #ifdef DEBUG printf("parse_body: close bracket\n"); #endif fprintf(out,"}\n"); autoindent(); fprintf(out," else\n"); autoindent(); #ifdef DEBUG printf("parse_body: open bracket\n"); #endif fprintf(out,"{\n"); indent++; } else if (tokentype==15) { fprintf(out,"%s",token); } else if (tokentype==0) { return 0; } else if (isfunction(token)!=-1) { strcpy(tmptoken,token); c=gettoken(token); if (strcmp(token,"=")==0) { autoindent(); fprintf(out,"$function_ret="); eval_expression(" "); } else { autoindent(); fprintf(out,"%s",tmptoken); push(token,c); convert_funct(newtoken,"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15",4); fprintf(out,"%s;",newtoken); } } else if (tokentype==2 || strcmp("=",token)==0) { eval_token(tokentype,token); } else if (tokentype==11) { /* This kinda sucks but.. if token is 11 at the beginning of the line lets assume that it's a comment line.. this might cause problems.. if you have problems, comment this crap out */ fprintf(out,"//%s",&token[1]); ch=0; while (ch!='\r' && ch!='\n') { if (pushback!=-1) { ch=pushback; pushback=-1; } else { ch=getc(in); } if (ch==EOF) break; if (ch=='%') { ch=getc(in); if (ch=='>') { putc('?',out); putc('>',out); /* copyhtml(); */ return 0; } else { putc('%',out);} } putc(ch,out); } line++; pushback=getc(in); if (pushback=='\n' || pushback=='\r') { if (ch!=pushback) pushback=-1; } } else if (strcmp(token,"<")==0) { if (is_endscript()==1) { if (in_body==1) { in_body--; fprintf(out,"?>\n"); return 0; } else { copyhtml(); } } } /* don't return from single line if/then/else until we reach EOL - MHB - 4/10/06 */ if (iflag==1 && tokentype==5) break; } in_body--; if (tokentype==5) { putc('\n',out); } if (strcasecmp(token,"end")==0) return 1; return 0; } int parse_command_set(char *newtoken,char *variable) { int tokentype; char token[TOKENSIZE]; tokentype=gettoken(token); strcpy(newtoken,""); if (tokentype==2) { autoindent(); fprintf(out,"$%s_%s=",variable,token); tokentype=gettoken(token); if (strcmp(token,"=")!=0) { error(token,"=","Command Object"); } eval_expression(" "); } return 0; } int parse_command(char *newtoken,char *variable) { int tokentype; char token[TOKENSIZE]; char temp[1024]; sprintf(newtoken,"%s",variable); while(1) { tokentype=gettoken(token); if (tokentype!=2) { push(token,tokentype); break; } sprintf(temp,"_%s",token); tokentype=gettoken(token); if (strcmp(token,".")!=0) { push(token,tokentype); break; } } return 0; } int parse_set(char *newtoken) { int tokentype; char token[TOKENSIZE]; char temptoken[TOKENSIZE]; char temp_spaces[100]; char molecule1[LINELENGTH]; int t; temp_spaces[0]=0; molecule1[0]=0; tokentype=gettoken(token); strcpy(temptoken,token); for (t=0; t