/** * @brief Generates a string. * * Will seek until the @p endMarker is found, any '\' escapes * the marker. The resulting string is stored in @p arg. * * At the end of this function, the parser cursor is just after the closing * marker. * * @return true if an error occurred, false otherwise. */ bool NepParser::helpGenString(std::string& arg, char endMarker) { size_t start = getCurPos(); size_t stLine=getCurLine(), stCol=getCurCol(); while( notEof() ) { char ch = getCurRaw(); if( ch == endMarker ) { arg += getSubString(start, getCurPos()); iterCur(); return false; } else if( ch == '\\') { arg += getSubString(start, getCurPos()); iterCur(); start = getCurPos(); } else if( isNewline(ch) ) break; iterCur(); } mScript.addError(Nepeta::ErrNoCloseString, "", stLine, stCol, getCurLine(), getCurCol()); return true; }
main(int argc, char *argv[]) { int pid, cmd, i; char name[64]; ucolor = 0; clearScreen(UMODE); printf("enter main() : argc = %d\n", argc); for (i=0; i<argc; i++) printf("argv[%d] = %s\n", i, argv[i]); while(1){ pid = getpid(); color = ucolor ? ucolor:0x000B + (pid % 5);// avoid black on black baground cmd?resetCursor(UMODE):1; printf("----------------------------------------------\n"); printf("I am proc %din U mode: segment=%x\n", pid, (pid+1)*0x1000); show_menu(); printf("Command ? "); getCurPos(UMODE); printf(" \n"); setCurPos(ux_col,uy_row,UMODE); gets(name); clearScreenRegion(K_X_PRINT_OFFSET,80,U_Y_PRINT_OFFSET-1,24,UMODE); if (name[0]==0) continue; cmd = find_cmd(name); getCurPos(UMODE); setCurPos(K_X_PRINT_OFFSET,U_Y_PRINT_OFFSET,UMODE); switch(cmd){ case 0 : do_getpid(); break; case 1 : ps(); break; case 2 : chname(); break; case 3 : kmode(); break; case 4 : kswitch(); break; case 5 : wait(); break; case 6 : exit(); break; case 7 : fork(); break; case 8 : exec(); break; case 9 : ucolor = chcolor(); break; case 10: pipe(); break; case 11: pfd(); break; case 12: read_pipe(); break; case 13: write_pipe(); break; case 14: close_pipe(); break; default: invalid(name); break; } setCurPos(ux_col,uy_row,UMODE); } }
/** * @brief Generates an identifier. * * At the end of a a call to this, the parser cursor is * just after the parsed identifier. * * @param idStart Desitnation for the beginning of the identifier * @param idEnd Destination for the end of the identifier */ void NepParser::helpGenIdent(size_t& idStart, size_t& idEnd) { idStart = getCurPos(); while( true ) { char ch = getCur(); if( !checkIdentifier(ch) ) { idEnd = getCurPos(); break; } iterCur(); } }
/** * @brief Generates a reference-type argument. * * A reference argument is identified by a '&', and contains a * \c Node::lookupNode() compatible string. * * Parsing starts on the '&' marker, and ends just after the end of the * reference string. */ void NepParser::genArgReference(Nepeta::Node& data) { iterCur(); size_t start = getCurPos(); size_t stLine=getCurLine(), stCol=getCurCol(); while( true ) { char ch = getCur(); if( checkReference(ch) ) iterCur(); else { mRef.push_back( Reference(&data, getSubString(start,getCurPos()), stLine, stCol) ); return; } } }
/** * @brief Generates a string buffer from the current cursor position. * * A string buffer is closed when a @p endMarker is detected on an * empty line at the indentation of @p baseInd. When the function is * over, the parser cursor is at the character just after the closing marker. * * @param baseInd The indentation at which end marker is checked and the * number of whitespace to skip for each line of data. * @param endMarker Character that marks the end of a buffer. * * @return true if an error occurred, false otherwise. */ bool NepParser::helpGenBuffer(std::string& arg, size_t baseInd, char endMarker) { size_t stLine = getCurLine(), stCol = getCurCol(); int curTab = baseInd; int lineStart = getCurPos(); while( notEof() ) { char ch = getCurRaw(); if(curTab<=0) { if(isNewline(ch)) { std::string line = getSubString(lineStart, getCurPos()+1); line[line.size()-1] = '\n'; arg.append( line ); curTab = baseInd; lineStart=getCurPos()+1; } iterCur(); } else if( isSpace(ch) ) { curTab--; if(curTab<=0) lineStart=getCurPos()+1; iterCur(); } else if( ch == endMarker ) { // Move past the end marker iterCur(); if(arg.size()>0) arg.erase(arg.size()-1); return false; } else { curTab=0; lineStart=getCurPos(); } } mScript.addError(Nepeta::ErrBlockNoClosing, "", stLine,stCol, getCurLine(), getCurCol()); return true; }
clearScreenRegion(int w1, int w2, int h1, int h2, int m){ int i,j; lock(); getCurPos(m); for(i=w1;i<w2;i++){ for(j=h1;j<h2;j++){ setCurPos(i,j,m); putc(' '); } } setCurPos(getXCol(m),getYRow(m)); unlock(); }
/** * @brief Parses in the data context for the given node. * * The data context first detects the node identifier and whether * the node has any nested nodes, then starts parsing the new node's * arguments. * * If this node has nested nodes, then the parser enters the * block context for the node right after the argument context. * * @return false if this node is a closing block marker. */ bool NepParser::genCtxData(Nepeta::Node &node) { size_t stL=getCurLine(), stC=getCurCol(); // Analyse the hash marker to determine type bool isHash = false; if(getCurRaw() == '#') { iterCur(); char ch = getCur(); if( checkIdentifier(ch) ) // This is a normal opening block isHash = true; else if( isWhite(ch) ) // This is a closing block return false; else { // This is not valid data mScript.addError(Nepeta::ErrIllegalCharacter, std::string(1,ch),getCurLine(),getCurCol() ); helpSeekNewline(false); return true; } } // Build the identifier and create the data node size_t start, end; helpGenIdent(start,end); Nepeta::Node &data = node.createNode( getSubString(start,getCurPos()), Nepeta::NoPos, stL, stC ); // Process the data context genCtxArg(data); if(isHash) genCtxBlock(data); return true; }