void compile(){ fileSave(); SendMessage(hNotifs, WM_SETTEXT, 0, (LPARAM) ""); FILE *fp; // file input FILE *fo; // file output TokenList * tokenList; fp = fopen(openedFileName, "r"); fo = fopen("SYMBOL TABLE.txt", "w"); tokenList = createTokenList(); initLexer(fp, fo); initToken(tokenList); readToken(); generateCode(tokenList); fclose(fp); fclose(fo); if(strcmp(errorList[0], "") == 0){ SendMessage(hNotifs, WM_SETTEXT, 0, (LPARAM) "No error"); hasError = 0; } else { hasError = 1; int i; for(i = 0; i < sizeof(errorList) / sizeof(errorList[0]); i++){ int index = GetWindowTextLength(hNotifs); SetFocus(hNotifs); SendMessageA(hNotifs, EM_SETSEL, (WPARAM)index, (LPARAM)index); // set selection - end of text SendMessageA(hNotifs, EM_REPLACESEL, 0, (LPARAM) errorList[i]); // append! } } memset(errorList, 0, sizeof(errorList) / sizeof(errorList[0])); }
int main(int argc, char* argv[]){ //Inicializace MMU mmuInit(); if(argc != 2){ fprintf(stderr, "Invalid arguments\n"); return ERROR_COMPILATOR; } if(!(gFileHandler = mmuFopen(argv[1], "r"))){ fprintf(stderr, "Cannot open input file\n"); return ERROR_COMPILATOR; } initToken(&gToken); E_CODE err = ERROR_OK; tSymbolTable table; symbolTableInit(&table); err = parser(&table); if (err == ERROR_OK) err = interpret(&table); mmuFclose(gFileHandler); //mmuDump(); mmuGlobalFree(); return err; }
int Parse(const char *strExpr, double *dblRet) { int ret = 1; ParserData md; *dblRet = 0; strcpy(md.m_strExpr, strExpr); md.m_top = -1; md.m_value = 0; initToken(&(md.m_Token)); GetNextToken(md.m_strExpr, &(md.m_Token)); while ( ret && md.m_Token.Type != T_EOL ) { ret = expr(&md); } if ( md.m_top >= 0 ) md.m_value = md.m_stack[md.m_top--]; md.m_top = -1; *dblRet = md.m_value; return ret; }
/** * Allocate and initialize a new xQSearchExpr object from an expression * string. * * Returns a pointer to the new instance or 0 on error */ xQStatusCode xQSearchExpr_alloc_init(xQSearchExpr** self, const xmlChar* expr) { const xmlChar* ptr = expr; xQStatusCode status = XQ_OK; xQToken tok; initToken(&tok); tok.strPtr = expr; nextToken(&tok); status = xQSearchExpr_parseSelector(self, &tok); if (status == XQ_NO_MATCH) { if (tok.lastStatus != XQ_OK && tok.lastStatus != XQ_NO_TOKEN) status = tok.lastStatus; else if (tok.type != XQ_TT_NONE) status = XQ_INVALID_SEL_UNEXPECTED_TOKEN; else status = XQ_OK; } destroyToken(&tok); if (status == XQ_OK && (!*self)) status = xQSearchExpr_alloc_init_copy(self); if (status != XQ_OK) { xQSearchExpr_free(*self); *self = 0; } return status; }
int main(int argc, char* argv[]){ //Inicializace MMU mmuInit(); if(argc != 2){ fprintf(stderr, "Invalid arguments\n"); return ERROR_COMPILATOR; } if(!(gFileHandler = mmuFopen(argv[1], "r"))){ fprintf(stderr, "Cannot open input file\n"); return ERROR_COMPILATOR; } initToken(&gToken); E_CODE err=ERROR_OK; tString func=strCreate("function"); tString x = strCreate("x");x=x; tSymbolTable table; symbolTableInit(&table); err=symbolTableInsertFunction(&table,func); table.currentFunc=symbolTableSearchFunction(&table,func); if(table.currentFunc==NULL)printf("funkce nenalezena"); functionInsertSymbol(table.currentFunc,x); tSymbol *result=NULL; // if(getToken()==LEX_L_BRACKET)printf("leva zavorka\n"); //if(getToken()==LEX_R_BRACKET)printf("prava zavorka\n"); if(getToken()==LEX_ID)printf("tady je ID\n"); if(getToken()==LEX_ASSIGN)printf("tady je =\n"); if(getToken()==LEX_STRING)printf("cislo\n"); printf("string je:%s\n",gToken.data.data); if(getToken()==LEX_ADDITION)printf("plus"); if(getToken()==LEX_STRING)printf("cislo\n"); if(getToken()==LEX_EOL)printf("konec radku\n"); tKeyword kw=getToken();kw=kw; err=prsExpression(&table,kw,&result); printf("err je : %d\n",err); if(result==NULL)printf("chyba: vysledek je null\n"); mmuFclose(gFileHandler); mmuDump(); mmuGlobalFree(); }
void gameMap::tryConquere(Area *area) { if(area->getOwnerPlayerName() == partie->getP1()->getName()) return; if(area->type() == QLatin1String("aqua") && partie->getP1()->getPower()->getName() != QLatin1String("Pirates")) return; QList<mapItem * > p1Items = getPlayerTokensOnArea(area,partie->getP1()); QList<mapItem * > p2Items = getPlayerTokensOnArea(area,partie->getP2()); if(p1Items.size() < area->getTokensToConquiert()) return; if((p1Items.length() > p2Items.length()) || (p1Items.size() == 0 && p2Items.size() == 0)) { area->setOwnerPlayerName(partie->getP1()->getName()); if(partie->nbTour % 2 == 0) viewer->setColorToAreaBorder(QPen(Qt::red,3.0),area); else viewer->setColorToAreaBorder(QPen(Qt::green,3.0),area); if(p2Items.size() > 0) { removePlayerTokensArea(area,partie->getP2(),p2Items.size()); if(partie->nbTour % 2 == 0) initToken(partie->getP2(),QPoint(-100,400),1); else initToken(partie->getP2(),QPoint(-100,200),1); } } }
/** * Allocate and initialize a new xQSearchExpr object from an expression * string. The created expression can be used for filtering a node list, * as opposted to searching (searching self instead of descendants). * * Returns a pointer to the new instance or 0 on error */ xQStatusCode xQSearchExpr_alloc_initFilter(xQSearchExpr** self, const xmlChar* expr) { const xmlChar* ptr = expr; xQStatusCode status = XQ_OK; xQToken tok; initToken(&tok); tok.strPtr = expr; nextToken(&tok); status = xQSearchExpr_parseSelector(self, &tok); if (status == XQ_NO_MATCH) { if (tok.lastStatus != XQ_OK && tok.lastStatus != XQ_NO_TOKEN) status = tok.lastStatus; else if (tok.type != XQ_TT_NONE) status = XQ_INVALID_SEL_UNEXPECTED_TOKEN; else status = XQ_OK; } destroyToken(&tok); if (status == XQ_OK && (!*self)) status = xQSearchExpr_alloc_init_copy(self); else if (status == XQ_OK) { // convert to self-search if ((*self)->operation == _xQ_findDescendants) (*self)->operation = _xQ_addToOutput; else if ((*self)->operation == _xQ_findDescendantsByName) (*self)->operation = _xQ_filterByName; } if (status != XQ_OK) xQSearchExpr_free(*self); return status; }
import = menuBar()->addMenu(tr("I&mport")); import->addAction(tr("Keys"), keyView, SLOT(load()) ); import->addAction(tr("Requests"), reqView, SLOT(load()) ); import->addAction(tr("Certificates"), certView, SLOT(load()) ); import->addAction(tr("PKCS#12"), certView, SLOT(loadPKCS12()) ); import->addAction(tr("PKCS#7"), certView, SLOT(loadPKCS7()) ); import->addAction(tr("Template"), tempView, SLOT(load()) ); import->addAction(tr("Revocation list"), crlView, SLOT(load())); import->addAction(tr("PEM file"), this, SLOT(loadPem()) ); import->addAction(tr("Paste PEM file"), this, SLOT(pastePem())); token = menuBar()->addMenu(tr("&Token")); token->addAction(tr("&Manage Security token"), this, SLOT(manageToken())); token->addAction(tr("&Init Security token"), this, SLOT(initToken())); token->addAction(tr("&Change PIN"), this, SLOT(changePin()) ); token->addAction(tr("Change &SO PIN"), this, SLOT(changeSoPin()) ); token->addAction(tr("Init PIN"), this, SLOT(initPin()) ); extra = menuBar()->addMenu(tr("Extra")); acList += extra->addAction(tr("&Dump DataBase"), this, SLOT(dump_database())); acList += extra->addAction(tr("&Export Certificate Index"), this, SLOT(exportIndex())); acList += extra->addAction(tr("&Export Certificate Index hierarchy"), this, SLOT(exportIndexHierarchy())); acList += extra->addAction(tr("C&hange DataBase password"), this,
void MainWindow::init_menu() { QMenu *file, *help, *import, *token; file = menuBar()->addMenu(tr("&File")); file->addAction(tr("&New DataBase"), this, SLOT(new_database()), QKeySequence::New); file->addAction(tr("&Open DataBase"), this, SLOT(load_database()), QKeySequence::Open); file->addAction(tr("Generate DH parameter"), this, SLOT(generateDHparam())); acList += file->addAction(tr("&Close DataBase"), this, SLOT(close_database()), QKeySequence(QKeySequence::Close)); acList += file->addAction(tr("&Dump DataBase"), this, SLOT(dump_database())); acList += file->addAction(tr("C&hange DataBase password"), this, SLOT(changeDbPass())); acList += file->addAction(tr("&Import old db_dump"), this, SLOT(import_dbdump())); acList += file->addAction(tr("&Undelete items"), this, SLOT(undelete())); file->addSeparator(); acList += file->addAction(tr("Options"), this, SLOT(setOptions())); file->addSeparator(); file->addAction(tr("Exit"), qApp, SLOT(quit()), Qt::ALT+Qt::Key_F4); import = menuBar()->addMenu(tr("I&mport")); import->addAction(tr("Keys"), this, SLOT(on_BNimportKey_clicked()) ); import->addAction(tr("Requests"), this, SLOT(on_BNimportReq_clicked()) ); import->addAction(tr("Certificates"), this, SLOT(on_BNimportCert_clicked()) ); import->addAction(tr("PKCS#12"), this, SLOT(on_BNimportPKCS12_clicked()) ); import->addAction(tr("PKCS#7"), this, SLOT(on_BNimportPKCS7_clicked()) ); import->addAction(tr("Template"), this, SLOT(on_BNimportTemp_clicked()) ); import->addAction(tr("Revocation list"), this, SLOT(on_BNimportCrl_clicked()) ); import->addAction(tr("PEM file"), this, SLOT(loadPem()) ); import->addAction(tr("paste PEM file"), this, SLOT(pastePem()) ); token = menuBar()->addMenu(tr("&Token")); token->addAction(tr("&Manage Security token"), this, SLOT(manageToken())); token->addAction(tr("&Init Security token"), this, SLOT(initToken())); token->addAction(tr("&Change PIN"), this, SLOT(changePin()) ); token->addAction(tr("Change &SO PIN"), this, SLOT(changeSoPin()) ); token->addAction(tr("Init PIN"), this, SLOT(initPin()) ); help = menuBar()->addMenu(tr("&Help") ); help->addAction(tr("&Content"), this, SLOT(help()), QKeySequence::HelpContents); help->addAction(tr("&About"), this, SLOT(about()) ); help->addAction(tr("Donations"), this, SLOT(donations()) ); wdList += import; scardList += token; }
int main( int a_iArgc, char **a_pszArgv ) { int rc = 1; // Create buffers for PIN prompts for formatting using sprintf char szSoNewPinPrompt[ strlen( TOKEN_SO_NEW_PIN_PROMPT ) + 16 ]; char szUserNewPinPrompt[ strlen( TOKEN_USER_NEW_PIN_PROMPT ) + 16 ]; char *pszReply = NULL; char *pszSoPin = NULL; char *pszNewSoPin = NULL; char *pszNewUserPin = NULL; CK_RV rv = CKR_OK; CK_SESSION_HANDLE hSession = 0; // Set up i18n initIntlSys( ); // Parse the command if ( parseCmd( a_iArgc, a_pszArgv ) == -1 ) goto out; // Open the PKCS#11 TPM Token rv = openToken( g_pszToken ); if ( rv != CKR_OK ) goto out; // Check if the token is already initialized if ( isTokenInitialized( ) ) { // Warn and ask the user before clearing if ( !g_bYes ) { pszReply = getReply( TOKEN_CLEAR_PROMPT, 1 ); if ( !pszReply || ( strlen( pszReply ) == 0 ) || ( strcasecmp( pszReply, TOKEN_CLEAR_NO ) == 0 ) ) { goto out; } } // Prompt for the current SO password pszSoPin = getPlainPasswd( TOKEN_SO_PIN_PROMPT, FALSE ); if ( !pszSoPin ) goto out; } else pszSoPin = strdup( TOKEN_SO_INIT_PIN ); // Clear the TPM token rv = initToken( pszSoPin ); if ( rv != CKR_OK ) goto out; // Open a session rv = openTokenSession( CKF_RW_SESSION, &hSession ); if ( rv != CKR_OK ) goto out; // Login to the token rv = loginToken( hSession, CKU_SO, TOKEN_SO_INIT_PIN ); if ( rv != CKR_OK ) goto out; sprintf( szSoNewPinPrompt, TOKEN_SO_NEW_PIN_PROMPT, getMinPinLen( ), getMaxPinLen( ) ); while ( TRUE ) { // Prompt for a new SO password pszNewSoPin = getPlainPasswd( szSoNewPinPrompt, TRUE ); if ( !pszNewSoPin ) goto out; // Set the new password rv = setPin( hSession, TOKEN_SO_INIT_PIN, pszNewSoPin ); if ( rv == CKR_OK ) break; if ( ( rv == CKR_PIN_INVALID ) || ( rv == CKR_PIN_LEN_RANGE ) ) logError( TOKEN_INVALID_PIN ); else goto out; shredPasswd( pszNewSoPin ); } // Open a new session closeTokenSession( hSession ); hSession = 0; rv = openTokenSession( CKF_RW_SESSION, &hSession ); if ( rv != CKR_OK ) goto out; // Login to the token rv = loginToken( hSession, CKU_USER, TOKEN_USER_INIT_PIN ); if ( rv != CKR_OK ) goto out; sprintf( szUserNewPinPrompt, TOKEN_USER_NEW_PIN_PROMPT, getMinPinLen( ), getMaxPinLen( ) ); while ( TRUE ) { // Prompt for a new User password pszNewUserPin = getPlainPasswd( szUserNewPinPrompt, TRUE ); if ( !pszNewUserPin ) goto out; // Set the new password rv = setPin( hSession, TOKEN_USER_INIT_PIN, pszNewUserPin ); if ( rv == CKR_OK ) break; if ( ( rv == CKR_PIN_INVALID ) || ( rv == CKR_PIN_LEN_RANGE ) ) logError( TOKEN_INVALID_PIN ); else goto out; shredPasswd( pszNewUserPin ); } rc = 0; out: free( pszReply ); shredPasswd( pszSoPin ); shredPasswd( pszNewSoPin ); shredPasswd( pszNewUserPin ); if ( hSession ) closeTokenSession( hSession ); closeToken( ); if ( rc == 0 ) logInfo( TOKEN_CMD_SUCCESS, a_pszArgv[ 0 ] ); else logInfo( TOKEN_CMD_FAILED, a_pszArgv[ 0 ] ); return rc; }
int Parse(const char *strExpr, double *dblRet) { int ret = 1; ParserData md; int8_t parseTable[9][9] = { /* -------------- input ------------- */ /* + - * / UM ^ ( ) $ */ /* -- -- -- -- -- -- -- -- -- */ /* stack */ /* ----- */ /* + */ { R, R, S, S, S, S, S, R, R }, /* - */ { R, R, S, S, S, S, S, R, R }, /* * */ { R, R, R, R, S, S, S, R, R }, /* / */ { R, R, R, R, S, S, S, R, R }, /* UM */ { R, R, R, R, S, S, S, R, R }, /* ^ */ { R, R, R, R, R, S, S, R, R }, /* ( */ { S, S, S, S, S, S, S, R, E1}, /* ) */ { R, R, R, R, R, R, E2, R, R }, /* $ */ { S, S, S, S, S, S, S, E3, A } }; *dblRet = 0; strcpy(md.m_strExpr, strExpr); md.m_top = -1; md.m_value = 0; md.m_topOpr = 0; md.m_stackOpr[0] = T_EOL; /* printf("SHIFT $\n"); */ initToken(&(md.m_Token)); GetNextToken(md.m_strExpr, &(md.m_Token)); if ( md.m_Token.Type == T_EOL ) { return 1; } while ( 1 ) { switch ( md.m_Token.Type ) { case T_UNKNOWN: printf("Error 0: invalid token: %s\n", md.m_Token.str); return 0; case T_NUMBER: md.m_stack[++md.m_top] = md.m_Token.Value; /* printf("PUSH %s\n", md.m_Token.str); */ GetNextToken(md.m_strExpr, &(md.m_Token)); break; case T_UPLUS: GetNextToken(md.m_strExpr, &(md.m_Token)); break; default: switch ( parseTable[md.m_stackOpr[md.m_topOpr]][md.m_Token.Type] ) { case S: if ( !shift(&md) ) return 0; break; case R: if ( !reduce(&md) ) return 0; break; case A: if ( md.m_top != 0 ) { printf("Error 10: missing operator.\n"); return 0; } if ( md.m_topOpr != 0 ) { printf("Error 11: missing operand.\n"); return 0; } md.m_value = md.m_stack[(md.m_top)--]; *dblRet = md.m_value; /* printf("ACCEPT: %g\n", *dblRet); */ return 1; case E1: printf("Error 1: missing right parenthesis\n"); return 0; case E2: printf("Error 2: missing operator\n"); return 0; case E3: printf("Error 3: unbalanced parenthesis\n"); return 0; } break; } } return ret; }