📄 main.c
字号:
explanation[cPUSHSTR]="PUSHSTR"; explanation[cCONCAT]="CONCAT"; explanation[cPUSHSTRPTR]="PUSHSTRPTR"; explanation[cCHANGESTRING]="CHANGESTRING"; explanation[cGLOB]="GLOB"; explanation[cPRINT]="PRINT"; explanation[cREAD]="READ"; explanation[cRESTORE]="RESTORE"; explanation[cQRESTORE]="QRESTORE"; explanation[cREADDATA]="READDATA"; explanation[cONESTRING]="ONESTRING"; explanation[cDATA]="DATA"; explanation[cOPEN]="OPEN"; explanation[cCHECKOPEN]="CHECKOPEN"; explanation[cCHECKSEEK]="CHECKSEEK"; explanation[cCOMPILE]="COMPILE"; explanation[cEXECUTE]="EXECUTE"; explanation[cEXECUTE2]="EXECUTE$"; explanation[cCLOSE]="CLOSE"; explanation[cSEEK]="SEEK"; explanation[cSEEK2]="SEEK2"; explanation[cPUSHSTREAM]="cPUSHSTREAM"; explanation[cPOPSTREAM]="cPOPSTREAM"; explanation[cWAIT]="WAIT"; explanation[cBELL]="BELL"; explanation[cMOVE]="MOVE"; explanation[cMOVEORIGIN]="MOVEORIGIN"; explanation[cCLEARSCR]="CLEARSCR"; explanation[cOPENWIN]="OPENWIN"; explanation[cDOT]="DOT"; explanation[cPUTBIT]="PUTBIT"; explanation[cPUTCHAR]="PUTCHAR"; explanation[cLINE]="LINE"; explanation[cCIRCLE]="CIRCLE"; explanation[cTEXT]="TEXT"; explanation[cCLOSEWIN]="CLOSEWIN"; explanation[cCLEARWIN]="CLEARWIN"; explanation[cOPENPRN]="OPENPRN"; explanation[cCLOSEPRN]="CLOSEPRN"; explanation[cTESTEOF]="TESTEOF"; explanation[cCOLOUR]="COLOUR"; explanation[cDUPLICATE]="DUPLICATE"; explanation[cDOCU]="DOCU"; explanation[cEND]="END"; explanation[cEXIT]="EXIT"; explanation[cBIND]="BIND"; explanation[cERROR]="ERROR"; explanation[cSTARTFOR]="STARTFOR"; explanation[cFORCHECK]="FORCHECK"; explanation[cFORINCREMENT]="FORINCREMENT"; explanation[cBREAK_MARK]="BREAK_MARK"; explanation[cPUSH_SWITCH_MARK]="PUSH_SWITCH_MARK"; explanation[cCLEAN_SWITCH_MARK]="CLEAN_SWITCH_MARK"; explanation[cSWITCH_COMPARE]="SWITCH_COMPARE"; explanation[cNEXT_CASE]="NEXT_CASE"; explanation[cBREAK]="BREAK"; explanation[cMINOR_BREAK]="MINOR_BREAK"; explanation[cCONTINUE]="CONTINUE"; explanation[cBREAK_HERE]="BREAK_HERE"; explanation[cCONTINUE_HERE]="CONTINUE_HERE"; explanation[cBREAK_MARK]="BREAK_MARK"; explanation[cCONTINUE_CORRECTION]="CONTINUE_CORRECTION"; explanation[cLAST_COMMAND]="???"; ykey[kERR]="error"; ykey[kUP]="up"; ykey[kDOWN]="down"; ykey[kLEFT]="left"; ykey[kRIGHT]="right"; ykey[kDEL]="del"; ykey[kINS]="ins"; ykey[kCLEAR]="clear"; ykey[kHOME]="home"; ykey[kEND]="end"; ykey[kF0]="f0"; ykey[kF1]="f1"; ykey[kF2]="f2"; ykey[kF3]="f3"; ykey[kF4]="f4"; ykey[kF5]="f5"; ykey[kF6]="f6"; ykey[kF7]="f7"; ykey[kF8]="f8"; ykey[kF9]="f9"; ykey[kF10]="f10"; ykey[kF11]="f11"; ykey[kF12]="f12"; ykey[kF13]="f13"; ykey[kF14]="f14"; ykey[kF15]="f15"; ykey[kF16]="f16"; ykey[kF17]="f17"; ykey[kF18]="f18"; ykey[kF19]="f19"; ykey[kF20]="f20"; ykey[kF21]="f21"; ykey[kF22]="f22"; ykey[kF23]="f23"; ykey[kF24]="f24"; ykey[kBACKSPACE]="backspace"; ykey[kSCRNDOWN]="scrndown"; ykey[kSCRNUP]="scrnup"; ykey[kENTER]="enter"; ykey[kESC]="esc"; ykey[kTAB]="tab"; ykey[kLASTKEY]="";}void signal_handler(int sig) /* handle signals */{ signal(sig,SIG_DFL); if (program_state==FINISHED) { exit(1); } signal_arrived=sig;#ifdef WINDOWS if (signal_arrived) { SuspendThread(mainthread); if (wthandle!=INVALID_HANDLE_VALUE) SuspendThread(wthandle); if (kthandle!=INVALID_HANDLE_VALUE) TerminateThread(kthandle,0); }#endif switch(sig) { case SIGFPE: error(FATAL,"floating point exception, cannot proceed."); case SIGSEGV: error(FATAL,"segmentation fault, cannot proceed."); case SIGINT:#ifdef UNIX if (winpid==0 || termpid==0 || backpid==0) exit(1);#endif error(FATAL,"keyboard interrupt, cannot proceed.");#ifdef SIGHUP case SIGHUP: error(FATAL,"received signal HANGUP, cannot proceed.");#endif#ifdef SIGQUIT case SIGQUIT: error(FATAL,"received signal QUIT, cannot proceed.");#endif#ifdef SIGABRT case SIGABRT: error(FATAL,"received signal ABORT, cannot proceed.");#endif default: break; }}static void run_it() /* execute the compiled code */{ int l=0; current=cmdroot; /* start with first comand */ if (print_docu) { /* don't execute program, just print docu */ while(current!=cmdhead) { if (current->type==cDOCU) { if (infolevel>=DEBUG) std_diag("executing",current->type,current->name); printf("%s\n",(char *)current->pointer); l++; if (hold_docu && !(l%24)) { printf("---Press RETURN to continue "); fgets(string,20,stdin); } } else { if (infolevel>=DEBUG) std_diag("skipping",current->type,current->name); } current=current->next; } if (!l) printf("---No embbeded documentation\n"); if (hold_docu) { printf("---End of embbedded documentation, press RETURN "); fgets(string,20,stdin); } } else { while(current!=cmdhead && endreason==erNONE) { if (infolevel>=DEBUG) std_diag("executing",current->type,current->name); switch(current->type) { case cGOTO:case cQGOTO:case cGOSUB:case cQGOSUB:case cCALL:case cQCALL: jump(current); DONE; case cEXCEPTION: exception(current); DONE; case cSKIPPER: skipper(); break; case cSKIPONCE: skiponce(current); DONE; case cRESETSKIPONCE: resetskiponce(current); DONE; case cNEXT_CASE: next_case(); DONE; case cBREAK:case cMINOR_BREAK: mybreak(current); DONE; case cSWITCH_COMPARE: switch_compare(); DONE; case cPUSH_SWITCH_MARK: push_switch_mark(); DONE; case cCLEAN_SWITCH_MARK: clean_switch_mark(current); DONE; case cCONTINUE: mycontinue(current); DONE; case cFINDNOP: findnop(); DONE; case cFUNCTION_OR_ARRAY: case cSTRINGFUNCTION_OR_ARRAY: function_or_array(current); break; /* NOT 'DONE' ! */ case cLABEL:case cDATA:case cNOP:case cUSER_FUNCTION: case cSUBLINK:case cEND_FUNCTION: case cDOCU: case cBREAK_HERE: case cCONTINUE_HERE:case cBREAK_MARK:case cCONTINUE_CORRECTION: DONE; case cERROR: do_error(current); DONE; case cCOMPILE: compile(); DONE; case cEXECUTE: case cEXECUTE2: execute(current); DONE; case cRETURN:case cRET_FROM_FUN: myreturn(current); DONE; case cRETVAL: retval(current); DONE; case cPUSHDBLSYM: pushdblsym(current); DONE; case cPUSHDBL: pushdbl(current); DONE; case cPOPDBLSYM: popdblsym(current); DONE; case cPOP: pop(stANY); DONE; case cPOPSTRSYM: popstrsym(current); DONE; case cPUSHSTRSYM: pushstrsym(current); DONE; case cPUSHSTR: pushstr(current); DONE; case cCLEARREFS: clearrefs(current); DONE; case cPUSHSYMLIST: pushsymlist(); DONE; case cPOPSYMLIST: popsymlist(); DONE; case cREQUIRE: require(current); DONE; case cMAKELOCAL: makelocal(current); DONE; case cNUMPARAM: numparam(current); DONE; case cMAKESTATIC: makestatic(current); DONE; case cARRAYLINK: arraylink(current); DONE; case cPUSHARRAYREF: pusharrayref(current); DONE; case cTOKEN: case cTOKEN2: case cSPLIT: case cSPLIT2: token(current); DONE; case cTOKENALT: case cTOKENALT2: case cSPLITALT: case cSPLITALT2: tokenalt(current); DONE; case cARDIM: case cARSIZE: query_array(current); DONE; case cPUSHFREE: push()->type=stFREE; DONE; case cCONCAT: concat(); DONE; case cPRINT: print(current); DONE; case cMOVE: mymove(); DONE; case cCOLOUR: colour(current); DONE; case cCLEARSCR: clearscreen(); DONE; case cONESTRING: onestring(current->pointer); DONE; case cTESTEOF: testeof(current); DONE; case cOPEN: myopen(current); DONE; case cCHECKOPEN:case cCHECKSEEK: checkopen(); DONE; case cCLOSE: myclose(); DONE; case cSEEK:case cSEEK2: myseek(current); DONE; case cPUSHSTREAM: push_switch(current); DONE; case cPOPSTREAM: pop_switch(); DONE; case cCHKPROMPT: chkprompt(); DONE; case cREAD: myread(current); DONE; case cRESTORE:case cQRESTORE: restore(current); DONE; case cREADDATA: readdata(current); DONE; case cDBLADD:case cDBLMIN:case cDBLMUL:case cDBLDIV:case cDBLPOW: dblbin(current); DONE; case cNEGATE: negate(); DONE; case cEQ:case cNE:case cGT:case cGE:case cLT:case cLE: dblrelop(current); DONE; case cSTREQ:case cSTRNE:case cSTRLT:case cSTRLE:case cSTRGT:case cSTRGE: strrelop(current); DONE; case cAND:case cOR:case cNOT: boole(current); DONE; case cFUNCTION: function(current); DONE; case cGLOB: glob(); DONE; case cDOARRAY: doarray(current); DONE; case cCHANGESTRING: changestring(current); DONE; case cPUSHSTRPTR: pushstrptr(current); DONE; case cDIM: dim(current); DONE; case cDECIDE: decide(); DONE; case cANDSHORT:case cORSHORT: logical_shortcut(current); DONE; case cOPENWIN: openwin(current); DONE; case cMOVEORIGIN: moveorigin(NULL); DONE; case cOPENPRN: openprinter(current); DONE; case cCLOSEPRN: closeprinter(); DONE; case cDOT: dot(current); DONE; case cPUTBIT: putbit(); DONE; case cPUTCHAR: putchars(); DONE; case cLINE: line(current); DONE; case cCIRCLE: circle(current); DONE; case cTEXT: text(current); DONE; case cCLOSEWIN: closewin(); DONE; case cCLEARWIN: clearwin(); DONE; case cRECT: rect(current); DONE; case cWAIT: mywait(); DONE; case cBELL: mybell(); DONE; case cPOKE: poke(current); DONE; case cPOKEFILE: pokefile(current); DONE; case cSWAP: swap(); DONE; case cDUPLICATE: duplicate(); DONE; case cFORCHECK: forcheck(); DONE; case cFORINCREMENT: forincrement(); DONE; case cSTARTFOR: startfor(); DONE; case cBIND: mybind(pop(stSTRING)->pointer); DONE; case cEND: endreason=erEOF; break; case cEXIT: exitcode=(int)pop(stNUMBER)->value;endreason=erREQUEST; break; default: sprintf(string,"Command %s (%d, right before '%s') not implemented", explanation[current->type],current->type,explanation[current->type+1]); error(ERROR,string); } } } program_state=FINISHED; switch(errorlevel) { case NOTE:case DEBUG: error(NOTE,"Program ended normally."); break; case WARNING: error(WARNING,"Program ended with a warning"); break; case ERROR: error(ERROR,"Program stopped due to an error"); break; case FATAL: /* should not come here ... */ error(FATAL,"Program terminated due to FATAL error"); break; }}void error(int severity, char *messageline) /* reports an basic error to the user and possibly exits */{ if (program_state==COMPILING) error_with_line(severity,messageline,yylineno); else if (program_state==RUNNING && current->line>0) error_with_line(severity,messageline,current->line); else error_with_line(severity,messageline,-1);}void error_with_line(int severity, char *message,int line) /* reports an basic error to the user and possibly exits */{ char *callstack; char *stext; char *f=NULL; int l; static int lastline; static int first=TRUE; if (severity<=infolevel) {#ifdef UNIX if (curinized) reset_shell_mode();#endif switch(severity) { case(INFO): stext="---Info"; break; case(DUMP): stext="---Dump"; break; case(DEBUG): stext="---Debug"; debug_count++; break; case(NOTE): stext="---Note"; note_count++; break; case(WARNING): stext="---Warning"; warning_count++; break; case(ERROR): stext="---Error"; error_count++; break; case(FATAL): stext="---Fatal"; break; } fprintf(stderr,"%s",stext); if (line>=0) { if (program_state==COMPILING) { f=currlib->l; l=yylineno; } else if (program_state==RUNNING && current->line>0) { f=current->lib->l; l=current->line; } if (f) { if (first || lastline!=l) { fprintf(stderr," in %s, line %d",f,l); } lastline=l; first=FALSE; } } fprintf(stderr,": %s\n",message); if (program_state==RUNNING && severity<=ERROR && severity!=DUMP) dump_sub(1); } if (severity<errorlevel) errorlevel=severity; if (severity<=ERROR) { program_state=FINISHED; endreason=erERROR; exitcode=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -