/* Web interface for colorer.c/colorer.h/lex.yy.c Works in both CGI and command line mode. 2000 by Nikolai Golovchenko Sep 9, Sat Started Lots of hack to interface C and C++ code. Sep 10, Sun Worked around file based conversion to string based. Basically copied and modified some routines from colorer.c to HTML_ColorerPage object. Added sanity checking for really bad input to prevent server flooding. Added initializing with external "colorer_links.cfg" file for links. Tested - okay. --------------------2001------------------------------- January 13, Sat Started working on analizing operands to sx instructions to allow exact linking of an instruction to a tutorial. Operands are converted to a template which is appended to mnemonic, and then all this serves as an index to the links vocabulary file. From pic.l: We extract only a number of elements from operands: ',': '' 'w' | '-' | '+' 'm' | '<' | '>' '- w' | '/' | '#' '+ w' | 'w' | 'm' '!': 'option' | 'R'... | 'wdt' In this way an instrucion template is extracted, which is then used as a suffix to the mnemonic, when looking for a corresponding URL describing the instruction. For example, mov w, #1 translates to-> mov_w# mov w, fr-w -> mov_w,-w jmp pc+w -> jmp_+w clr !wdt -> clr_!wdt mov w, >>fr -> mov_w,>> clr reg -> clr clr w -> clr_w mov !option, #%00001111 -> mov_!option,# mov !RA, w -> mov_!r,w mov !RA, #$FF -> mov_!r,# If a full instruction template isn't found in the links vocabulary, then the search is repeated using only the mnemonic To do: Avoid picking 'w' and 'm' elements in identifiers others than 'w' and 'm' January 14, Sun The problem above solved by refining rules: 1) after -,+,<,>,!,#,/ any character can follow; 2) after w, m, option, wdt, rx only non-digit, non-letter, or non-underscore can follow; and by fixing comments ignoration (';' didn't work, but ";" worked. This is required in flex rules, characters definition must be enclosed in double quotes!, not single as in C) Added a function stylePrintAndLinkToOr(...) to print style and search for link by full template or, if not found, by mnemonic. Extended readLinksFile(FILE* links) function to accept non-letters in the links keys. Copied changes to HTML_ColorerPage::readLinksString(const char* links), which is a copy working in web mode. Tested. */ extern "C" { //C colorer #include "lex.yy.c" //CGI library #include "../CGIHTML/cgi-lib.h" #include "../CGIHTML/html-lib.h" char** CommandLineArguments; } //HTML library #include "../HTML/HTML.h" //library #include "HTML_ColorerPage.h" //custom classes #include "HTML_ColorerPage1.h" #include "HTML_ColorerPage2.h" #include "HTML_ColorerPage3.h" #include "webcolorer.h" //Global variables bool isCGI; //is in CGI mode? (handled by main) int main(int argc, char *argv[ ], char *envp[ ]) { llist entries = {NULL}; //clear list int result; char* value; HTML_ColorerPage* page; /********* DEBUG ***************** _putenv("SERVER_SOFTWARE=Microsoft-IIS/4.0"); _putenv("SERVER_NAME=www.piclist.com"); _putenv("GATEWAY_INTERFACE=CGI/1.1"); _putenv("SERVER_PROTOCOL=HTTP/1.1"); _putenv("SERVER_PORT=80"); _putenv("REQUEST_METHOD=GET"); _putenv("PATH_TRANSLATED=C:\\Inetpub\\wwwroot"); _putenv("SCRIPT_NAME=/cgi-bin/test.exe"); _putenv("REMOTE_HOST=204.210.50.240"); _putenv("REMOTE_ADDR=204.210.50.240"); _putenv("CONTENT_LENGTH=0"); //_putenv("QUERY_STRING=html=no&asm=TABLE_JUMP%09MACRO%09%0D%0A%09MOVWF%09Table_Temp%09%3B+save+wanted+offset%0D%0A%09MOVLW%09LOW%28%24%2B8%29%09%3B+get+low+adress+%28+of+first+instr.+after+macro+%29%0D%0A%09ADDWF%09Table_Temp%2CF%09%3B+add+offset%0D%0A%09MOVLW%09HIGH%28%24%2B6%29%09%3B+get+highest+5+bits+%28+of+first+instr.+after+macro+%29%0D%0A%09BTFSC%09STATUS%2CC%09%3B+page+crossed+%3F+%28+256+byte+%29%0D%0A%09ADDLW%090x01%09%09%3B+Yes+add+one+to+high+adress%0D%0A%09MOVWF%09PCLATH%09%09%3B+load+high+adress+in+latch%0D%0A%09MOVF%09Table_Temp%2CW%09%3B+get+computed+adress%0D%0A%09MOVWF+++PCL%09+++++++++++%3B+And+jump%0D%0A%09ENDM%0D%0A&usestyle=yes&style=%2Fimages%2Fasm.css&expandtab=yes&tab=8&links=.Inst%0D%0A%09addlw%3A%09%2Finstr%2Faddlw.htm%0D%0A%09goto%3A%09%2Finstr%2Fgoto.htm%0D%0A.Dir%0D%0A%09%24%3A%09%2Fdir%2Fpc.htm%0D%0A%09while%3A%09%2Fdir%2Fdir.htm%0D%0A%0D%0A&convert=Convert"); //_putenv("QUERY_STRING=html=yes&asm=&usestyle=yes&style=%2Fimages%2Fasm.css&expandtab=yes&tab=80&links=%0D%0A&convert=Convert"); //_putenv("QUERY_STRING=html=no&asm=&usestyle=no&style=%2Fimages%2Fasm.css&expandtab=yes&tab=8&uselinks=yes&links=%0D%0A.Inst%0D%0A;%0D%0A$:%20xyz&convert=Convert"); //_putenv("QUERY_STRING=html=no&asm=%3B+handy+ASCII+character+table%0D%0ASTX%09EQU%090x02%09%3B+stx%0D%0AETX%09EQU%090x03%09%3B+etx%0D%0ABEL%09EQU%090x07%09%3B+bell%0D%0ABS%09EQU%090x08%09%3B+backspace%0D%0ATAB%09EQU%090x09%09%3B+horizontal+tab%0D%0ALF%09EQU%090x0A%09%3B+line+feed%0D%0AFF%09EQU%090x0C%09%3B+form+feed%0D%0ACR%09EQU%090x0D%09%3B+carriage+return%0D%0AXON%09EQU%090x11%09%3B+transmit+on%0D%0AXOFF%09EQU%090x13%09%3B+transmit+off%0D%0AEOF%09EQU%090x1A%09%3B+end+of+file%0D%0AESC%09EQU%090x1B%09%3B+escape%0D%0ASP%09EQU%090x20%09%3B+space%0D%0A%0D%0A%3B+buffers+for+serial+communication%0D%0ARX_BUFFER_SIZE%09EQU%0916%09%3B+serial+receive+buffer+allocation+%28+best+when+power+of+2+%29%0D%0ATX_BUFFER_SIZE%09EQU%0916%09%3B+serial+transmit+buffer+allocation%0D%0A%0D%0A&style=%2Fimages%2Fasm.css&expandtab=yes&tab=8&uselinks=yes&links=.Inst%0D%0A%09addlw%3A%09%2Finstr%2Faddlw.htm%0D%0A%09goto%3A%09%2Finstr%2Fgoto.htm%0D%0A.Dir%0D%0A%09%24%3A%09%2Fdir%2Fdir.htm%23pc.htm%0D%0A%09while%3A%09%2Fdir%2Fdir.htm%23while%0D%0A;%0D%0A&convert=Convert"); _putenv("QUERY_STRING=html=no&asm=&usestyle=yes&style=%2Fimages%2Fasm.css&expandtab=yes&tab=8&uselinks=yes&links=.Inst%0D%0A%09mov%3A%09%09%2Finstr%2Fmov.htm%0D%0A%09mov_w%2C%23%3A%09%2Finstr%2Fmovwlit.htm%0D%0A%09MOV_%21OPTION%2C%23%3A+%09%2Finstr%2Fmovoptionlit.htm%0D%0A%09MOV_%21OPTION%2C%3A+++%2Finstr%2Fmovoptionfr.htm%0D%0A%09MOV_%21OPTION%2CW%3A++%2Finstr%2Fmovoptionw.htm%0D%0A%09MOV_%21R%2C%23%3A+++++++%2Finstr%2Fmovportlit.htm%0D%0A%09MOV_%21R%2C%3A++++++++%2Finstr%2Fmovportfr.htm%0D%0A%09MOV_%21R%2CW%3A+++++++%2Finstr%2Fmovportw.htm%0D%0A%09MOV_%2C%23%3A+++++++++%2Finstr%2Fmovfrlit.htm%0D%0A%09MOV_%2CM%3A+++++++++%2Finstr%2Fmovfrm.htm%0D%0A%09MOV_%2CW%3A+++++++++%2Finstr%2Fmovfrw.htm%0D%0A%09MOV_%2C%3A++++++++++%2Finstr%2Fmovfrfr.htm%0D%0A%09MOV_M%2C%23%3A++++++++%2Finstr%2Fmovmlit.htm%0D%0A%09MOV_M%2C%3A+++++++++%2Finstr%2Fmovmfr.htm%0D%0A%09MOV_M%2CW%3A++++++++%2Finstr%2Fmovmw.htm%0D%0A%09MOV_W%2C%23%3A++++++++%2Finstr%2Fmovwlit.htm%0D%0A%09MOV_W%2C%2F%3A++++++++%2Finstr%2Fmovwinvfr.htm%0D%0A%09MOV_W%2C%2B%2B%3A+++++++%2Finstr%2Fmovwincfr.htm%0D%0A%09MOV_W%2C%3C%3E%3A+++++++%2Finstr%2Fmovwswapfr.htm%0D%0A%09MOV_W%2C%3C%3C%3A+++++++%2Finstr%2Fmovwrlfr.htm%0D%0A%09MOV_W%2C%3E%3E%3A+++++++%2Finstr%2Fmovwrrfr.htm%0D%0A%09MOV_W%2C%3A+++++++++%2Finstr%2Fmovwfr.htm%0D%0A%09MOV_W%2C--%3A+++++++%2Finstr%2Fmovwdecfr.htm%0D%0A%09MOV_W%2C-W%3A+++++++%2Finstr%2Fmovwsubfr.htm%0D%0A%09MOV_W%2CM%3A++++++++%2Finstr%2Fmovwm.htm%0D%0A%0D%0A.Dir%0D%0A%09%24%3A+%2Finstr%2Fdir.htm%23pc.htm%0D%0A%09while%3A+%2Finstr%2Fdir.htm%23while%0D%0A%09%0D%0A&convert=Convert"); /***********************************/ //pass comand line to CGI module CommandLineArguments = argv; isCGI = getenv("REQUEST_METHOD") != NULL; if(!isCGI) { //pass command line parameters to mainConsole in colorer.c result = mainConsole(argc, argv, envp); return(result); } ////// Read form values /////////////////////////////////// read_cgi_input(&entries); //print HTML header for server html_header(); /////// check current page //////////////////////////////// if(is_field_exists(entries, "convert")) { //second page - results page = new HTML_ColorerPage2(); } else if(is_field_exists(entries, "test")) { //second page - results page = new HTML_ColorerPage3(); } else { //first page for any other page = new HTML_ColorerPage1(); } /////// pass data from form to page object /////////////////// value= cgi_val(entries, "asm"); if(value != NULL) { page->setInput(value); } value = cgi_val(entries, "usestyle"); if(value != NULL && strcmp(value, "yes") == 0) { page->setCsspath(cgi_val(entries, "style")); } value= cgi_val(entries, "expandtab"); if(value != NULL && strcmp(value, "yes") == 0) { value = cgi_val(entries, "tab"); if(value != NULL) { result = atoi(value); if(result <= 0 || result > 10) { page->error("Tabs can only have size in the range 1..10. Replaced by 8"); result = 8; } page->setTabs(result); } } value = cgi_val(entries, "uselinks"); if(value != NULL && strcmp(value, "yes") == 0) { page->setLinks(cgi_val(entries, "links")); } value= cgi_val(entries, "html"); if(value != NULL && strcmp(value, "yes") == 0) { page->setIsHTML(1); } ////////////// do the job /////////////////////////// page->generatePage(); ////////////// print results /////////////////////// page->print(); ////////////// clean up //////////////////////////// delete(page); list_clear(&entries); return(0); } void scan_string(const char* x) { YY_BUFFER_STATE state; //wrapper for lex function (don't know what it returns) state = yy_scan_string(x); //run Lex on string yylex(); if(state != NULL) { yy_delete_buffer(state); } }