/** * Discards the current token, preparing it to be built anew. Also prints * an error message and the line the error occurred on. **/ void actError(state s, token *t, char c) { unsigned int pos = bufferPos(); fprintf(stdout, "(%d,%d): error: unexpected character ", bufferLineNumber(), pos); if (c == '\n') fprintf(stdout, "'\\n'\n"); else fprintf(stdout, "'%c'\n", c); bufferPrint(stdout); for (int i = 1; i < pos; i++) fprintf(stdout, " "); fprintf(stdout, "^\n"); tokenClean(t); tokenInit(t); }
int syntakticka_anal() { //pomocna funkce pro kontrolu cele syntakticke analyzy v main.c souboru int navrat; tokenInit(&token); token = getNextToken(); if(token.stav == s_lex_error) { navrat = S_LEXIKALNI_CHYBA; } else navrat = PROGRAM(); tokenFree(&token); if(navrat == S_BEZ_CHYB) { navrat = TestFunction(ptrhtGlobal); } return navrat; }
int interactiveMode() { char cmdStr[STR_LEN]; int exitCode = 0; int status = 0; int i = 0; pid_t pid; fputs("prompt> ", stdout); fgets(cmdStr, STR_LEN, stdin); tokenInit(); cmdNumber = get_token(cmdStr); i = 0; // 명령어를 실행하는 핵심코드 while(i < cmdNumber) { pid = fork(); if(pid == 0) { execvp(t.afterToken[i][0], t.afterToken[i]); exit(1); return 0; } i++; } i = 0; // wait 함수. while(i < cmdNumber) { wait(&status); i++; } if(exitCheck == 1) exitCode = 1; return exitCode; }
/*********************************************************************** * Function Name : parser * Description : Parse the input line * Input : @pCli, cli control structure * @fd, file destripter * @pTbl, token table * Output : * Return value : CLI_PARSE_OK, parse token success * CLI_PARSE_ERROR, parse token failure * CLI_PARSE_NO_TBL, no token table valid * CLI_PARSE_NO_VALUE,no parameter in token * CLI_PARSE_TOO_FEW, not enough items in token * CLI_PARSE_TOO_MANY, items of token is more than it have to * CLI_PARSE_UNKNOWN, do not match any token in the token table * CLI_PARSE_INPUT_ERROR, withdraw charactor error form input * CLI_PARSE_INVALID_PARAMETER, parameter from item is invalide * CLI_PARSE_MULTI_MATCHES, inputed token matchs more than one token in the token table * CLI_PARSE_QUIT, parse terminate unexpected * CLI_PARSE_NOMESSAGE, no message parse from token ***********************************************************************/ int parser(CLI * pCli, int fd, struct parse_token_s *pTbl) { char buf[CLI_INBUF]; char *p; char *pBuf; char *pToken; char ch; int i, len, status; //A_UINT32 cksum = 0; int invalid = 0; char dev_name[33]={0}; char prompt[100]; //*eof = 0; p = pBuf = (char *) buf; len = 0; tokenInit(pCli); /* * Notice that country code has not been set. * modify by Tony 2008.4.16. */ if(T_FAILURE == get_sysname_from_nvram(dev_name)) { return FALSE; } //#define SINGLECRAD_DUALRADIO //#ifdef SINGLECRAD_DUALRADIO sprintf(prompt, "%s %s ", dev_name,CLI_PROMPT); //#else //sprintf(prompt, "%s %s[%d, %d] %s ", dev_name, //CLI_WLAN_PROMPT, pCli->unit, pCli->vap, CLI_PROMPT); //#endif pBuf = readline(prompt); #if 0 if (*eof == 0) { if (pCksum) { *pCksum += cksum; } } #endif if (invalid) { return CLI_PARSE_INPUT_ERROR; } if (pBuf != NULL) { /*dennis add to prevent buffer overflow. 2008-04-18. -----> */ if (strlen(pBuf) >= CLI_INBUF) return CLI_PARSE_INPUT_ERROR; /*<----- */ //ignore the heading spaces until the command begins while (*pBuf && isspace(*pBuf)) pBuf++; p = pBuf; len = strlen(p) + 1; for (i = 0; i < len; i++) { if (isspace(*pBuf)) *pBuf = 0; pBuf++; } pToken = NULL; for (i = 0; i < len; i++) { ch = *p; if (ch) { if (!pToken) { pToken = p; } } else { if (pToken) { tokenPush(pCli, pToken); } pToken = NULL; } p++; } //Dleted by Mario Huang //specialTimeofDay(pCli); //Dleted by Mario Huang //specialTimeofZone(pCli); //Dleted by Mario Huang, useless // specialFactoryDefault(pCli); status = tokenParser(pCli, pTbl); return status; } else return -1; }
/** * Discards the current token, preparing it to be built anew. **/ void actDiscard(state s, token *t, char c) { tokenClean(t); tokenInit(t); }