static int readPIMFile(char *pfile) { char *fname = "readPIMFile"; struct lsPidInfo *tmp; char *buffer,*tmpbuf; char pimString[MAXLINELEN]; if ((buffer=readPIMBuf(pfile))==NULL) { ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "readPIMBuf"); return(FALSE); } FREEUP(pinfoList); npinfoList = 0; pinfoList = (struct lsPidInfo *)malloc(sizeof(struct lsPidInfo) * MAX_NUM_PID); if (pinfoList == NULL) { ls_syslog(LOG_ERR, I18N_FUNC_D_FAIL_M, fname, "malloc", sizeof(struct lsPidInfo) * MAX_NUM_PID); return(FALSE); } tmpbuf = getNextString(buffer,pimString); if (tmpbuf == NULL) { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5908, "%s format error"), "pim.info"); /* catgets 5908 */ return(FALSE); } buffer = tmpbuf; while ((tmpbuf = getNextString(buffer,pimString))!=NULL) { buffer = tmpbuf; if (logclass & LC_PIM) ls_syslog(LOG_DEBUG3,"pim info string is %s",pimString); sscanf(pimString, "%d %d %d %d %d %d %d %d %d %d %d %d", &pinfoList[npinfoList].pid, &pinfoList[npinfoList].ppid, &pinfoList[npinfoList].pgid, &pinfoList[npinfoList].jobid, &pinfoList[npinfoList].utime, &pinfoList[npinfoList].stime, &pinfoList[npinfoList].cutime, &pinfoList[npinfoList].cstime, &pinfoList[npinfoList].proc_size, &pinfoList[npinfoList].resident_size, &pinfoList[npinfoList].stack_size, (int *)&pinfoList[npinfoList].status); npinfoList ++; if (npinfoList % MAX_NUM_PID == 0) { tmp = (struct lsPidInfo *)realloc(pinfoList, sizeof(struct lsPidInfo) * (npinfoList + MAX_NUM_PID)); if (tmp == NULL) { ls_syslog(LOG_ERR, I18N_FUNC_D_FAIL_M, fname, "realloc", sizeof(struct lsPidInfo) * (npinfoList + MAX_NUM_PID)); return(FALSE); } pinfoList = tmp; } } return(TRUE); }
tree buildTree(char* obj,char* trace){ tree t = (tree)malloc(sizeof(node)); strcpy(t->data,obj); t->right = (isOperator(obj[0])==1)?buildTree(getNextString(),trace):NULL; t->left = (isOperator(obj[0])==1)?buildTree(getNextString(),trace):NULL; if(trace!=NULL){ printf("\n"); inorder(t); } return t; }
// Parses a JSON schedule into the global variable // schedule and sorts it void scheduleParse(void) { char key[11]; enum key_t i; unsigned long value, current_zone; while(RxFifo_Size() > 0) { if(!getNextString(key)) break; for(i = ZONE; i < (sizeof(KEYS)/sizeof(char*)); i++) { if(!strcmp(key, KEYS[i])) { if(!getNextNum(&value)) break; switch(i) { case ZONE: current_zone = value; break; case START: schedule[schedule_idx].zone = current_zone; schedule[schedule_idx].start_time = value; break; case END: schedule[schedule_idx].end_time = value; schedule_idx++; break; default: break; } } } } }
int FWScript::o2_loadAbs() { byte param1 = getNextByte(); const char *param2 = getNextString(); debugC(5, kCineDebugScript, "Line: %d: loadABS(%d,%s)", _line, param1, param2); // Load the resource to an absolute position if (loadResource(param2, param1) == -1) { // Check if the loading failed // WORKAROUND: In the 256 color PC version of Operation Stealth when // walking out of the airport in Santa Paragua to the street the // player character should be seen as a grey silhuette while walking // behind the glass. But actually the player character is completely // invisible when walking behind the glass because the animation files // used are wrongly loaded. In AIRPORT.PRC's 6th script there are // calls loadAbs("JOHN01.ANI", 73) and loadAbs("JOHN02.ANI", 37) to // load the animations involved but no such files are found with the // game. Corresponding SET-files are found though. As it worked and // looked fine when I tried loading them instead of the missing ANI // files I'm doing so here. NOTE: At least the German Amiga version // of Operation Stealth seems to have all the files involved // (JOHN01.ANI, JOHN02.ANI, JOHN01.SET and JOHN02.SET). if (scumm_stricmp(param2, "JOHN01.ANI") == 0 && param1 == 73) { loadResource("JOHN01.SET", param1); } else if (scumm_stricmp(param2, "JOHN02.ANI") == 0 && param1 == 37) { loadResource("JOHN02.SET", param1); } } return 0; }
/** Load collision table data */ int FWScript::o2_loadCt() { const char *param = getNextString(); debugC(5, kCineDebugScript, "Line: %d: loadCt(\"%s\")", _line, param); loadCtOS(param); return 0; }
int FWScript::o2_addBackground() { byte param1 = getNextByte(); const char *param2 = getNextString(); debugC(5, kCineDebugScript, "Line: %d: addBackground(%s,%d)", _line, param2, param1); addBackground(param2, param1); return 0; }
bool CzDataInput::getNextString(CzString *pString) { char buffer[2048]; if (getNextString(buffer, 2048)) { pString->Copy(buffer); return true; } return false; }
void Engine::init(int _len) { len=_len; finalInt=0; for (int i=9; i>9-len; i--) finalInt=finalInt*10+i; if (len==10) finalInt*=10; currString=GAME_START; q.clear(); QString str; str="10"; for (int i=0; i<len-2; i++) str+=('2'+i); q.push_back(str); do q.push_back(getNextString(q.back())); while (q.back()!=LAST_STRING); }
int main(int argC,char* argV[]){ int i; tree t; if(argC==1) printf("Usage : %s <RPN expression enclosed by quotes> <optional parameter to trace the build process>",argV[0]); else{ buildStack(argV[1]); if(checkRPN()==0){ printf("\nInvalid RPN !"); return 0; } t = buildTree(getNextString(),argV[2]); printf("\nFinal infix expression : "); inorder(t); } return 0; }
void *trata_cliente(void *client_connection){ /*Variaveis exclusivas da thread*/ socklen_t ns; int l; char sendbuf[TAM_BUF], recvbuf[TAM_BUF]; int i=0, j=0, tid; int lidos, conectado = 1; printf("ns..."); paramCliente* par = (paramCliente*) (client_connection); ns = par->s; //tid = par->tid; tid = pthread_self(); struct sockaddr_in client = par->cli; printf("thr[%u]: Cliente se conectou com %d\n",(unsigned) tid,ns); while (conectado) { printf("thr[%u]: Aguardando mensagem do cliente\n", (unsigned)tid); if ( (lidos = recv(ns, recvbuf, sizeof(recvbuf), 0)) == -1) { perror("Recv()"); continue; } switch ( recvbuf[protocol_i]) { case cadastrar: printf("thr[%u]: O cliente na porta %d deseja cadastrar uma mensagem\n",(unsigned) tid,ntohs(client.sin_port)); pthread_mutex_lock(&mutex); if (mensagensCadastradas >= MAXMSGS) { pthread_mutex_unlock(&mutex); printf("thr[%u]: ERRO! Limite de mensagens cadastradas atingido. Enviando mensagem de erro ao cliente da porta %d\n",(unsigned)tid,ntohs(client.sin_port)); sendResp(sendbuf,ns,erro); break; } printf("thr[%u]: Cadastrando a mensagem\n",(unsigned)tid); strcpy(mensagensDB[mensagensCadastradas].nome,recvbuf+1); l = getNextString(recvbuf,1); strcpy(mensagensDB[mensagensCadastradas].msg,recvbuf+l); printf("thr[%u]: Cadastrado: Nome: %s, Mensagem: %s. Enviando Confirmacao ao cliente da porta %d\n",(unsigned)tid,mensagensDB[mensagensCadastradas].nome,mensagensDB[mensagensCadastradas].msg,ntohs(client.sin_port)); sendResp(sendbuf,ns,ack); mensagensCadastradas++; pthread_mutex_unlock(&mutex); break; case apagar: l = 1; int apagadas = 0; printf("thr[%u]: Cliente da porta %d deseja apagar mensagens de %s\n",(unsigned)tid,ntohs(client.sin_port),recvbuf+1); pthread_mutex_lock(&mutex); for (i =0; i < mensagensCadastradas;i++) { if (strcmp(recvbuf+1,mensagensDB[i].nome) == 0) { l = putBuff(sendbuf,l,mensagensDB[i].nome); l = putBuff(sendbuf,l,mensagensDB[i].msg); printf("thr[%u]: apagando mensagem de %s : %s...como pedido pelo cliete da porta %d\n",(unsigned) tid,mensagensDB[i].nome,mensagensDB[i].msg,ntohs(client.sin_port)); for (j = i+1; j<mensagensCadastradas;j++) //'puxa' as mensagens subsequentes, deletando a atual mensagensDB[j-1] = mensagensDB[j]; //não é eficiente, mas n vou criar uma lista ligada '-' mensagensCadastradas--; i--; apagadas++; } } pthread_mutex_unlock(&mutex); if (apagadas == 0) { sendResp(sendbuf,ns,vazio); } else { sendbuf[protocol_i] = ack; sendbuf[l] = '#'; //sinaliza sinal da lista de mensagens if (send(ns, sendbuf,l+1, 0) < 0) perror("Send()"); } break; case querSair: printf("thr[%u]: Cliente da porta %d deseja encerrar a conexao.\n",(unsigned) tid,ntohs(client.sin_port)); conectado = 0; break; case ler: printf("thr[%u]: Cliente da porta %d deseja ler as mensagens. Listando as mensagens cadastradas\n",(unsigned) tid,ntohs(client.sin_port)); pthread_mutex_lock(&mutex); if (mensagensCadastradas == 0) { pthread_mutex_unlock(&mutex); printf("thr[%u]: Nenhuma mensagem cadastrada. Enviando informacao ao cliente da porta %d.\n",(unsigned) tid,ntohs(client.sin_port)); sendResp(sendbuf,ns,vazio); break; } l = 1; for (i =0; i < mensagensCadastradas;i++) { l = putBuff(sendbuf,l,mensagensDB[i].nome); l = putBuff(sendbuf,l,mensagensDB[i].msg); printf("thr[%u]: Adicionando mensagem: Autor: %s Conteudo: %s, ao pacote para enviar ao cliente da porta %d\n",(unsigned) tid,mensagensDB[i].nome,mensagensDB[i].msg,ntohs(client.sin_port)); } pthread_mutex_unlock(&mutex); sendbuf[protocol_i] = ack; sendbuf[l] = '#'; //sinaliza final da lista de mensagens if (send(ns, sendbuf,l+1, 0) < 0) perror("Send()"); break; default: printf("thr[%u]: Comando de código %d desconhecido. Enviando resposta ao cliente da porta %d\n",(unsigned) tid,recvbuf[protocol_i],ntohs(client.sin_port)); sendResp(sendbuf,ns,invalido); break; } } pthread_exit(0); }
/* ** The output variable *ppExpr is populated with an allocated Fts3Expr ** structure, or set to 0 if the end of the input buffer is reached. ** ** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM ** if a malloc failure occurs, or SQLITE_ERROR if a parse error is encountered. ** If SQLITE_ERROR is returned, pContext is populated with an error message. */ static int getNextNode( ParseContext *pParse, /* fts3 query parse context */ const char *z, int n, /* Input string */ Fts3Expr **ppExpr, /* OUT: expression */ int *pnConsumed /* OUT: Number of bytes consumed */ ){ static const struct Fts3Keyword { char *z; /* Keyword text */ unsigned char n; /* Length of the keyword */ unsigned char parenOnly; /* Only valid in paren mode */ unsigned char eType; /* Keyword code */ } aKeyword[] = { { "OR" , 2, 0, FTSQUERY_OR }, { "AND", 3, 1, FTSQUERY_AND }, { "NOT", 3, 1, FTSQUERY_NOT }, { "NEAR", 4, 0, FTSQUERY_NEAR } }; int ii; int iCol; int iColLen; int rc; Fts3Expr *pRet = 0; const char *zInput = z; int nInput = n; /* Skip over any whitespace before checking for a keyword, an open or ** close bracket, or a quoted string. */ while( nInput>0 && fts3isspace(*zInput) ){ nInput--; zInput++; } if( nInput==0 ){ return SQLITE_DONE; } /* See if we are dealing with a keyword. */ for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){ const struct Fts3Keyword *pKey = &aKeyword[ii]; if( (pKey->parenOnly & ~sqlite3_fts3_enable_parentheses)!=0 ){ continue; } if( nInput>=pKey->n && 0==memcmp(zInput, pKey->z, pKey->n) ){ int nNear = SQLITE_FTS3_DEFAULT_NEAR_PARAM; int nKey = pKey->n; char cNext; /* If this is a "NEAR" keyword, check for an explicit nearness. */ if( pKey->eType==FTSQUERY_NEAR ){ assert( nKey==4 ); if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){ nNear = 0; for(nKey=5; zInput[nKey]>='0' && zInput[nKey]<='9'; nKey++){ nNear = nNear * 10 + (zInput[nKey] - '0'); } } } /* At this point this is probably a keyword. But for that to be true, ** the next byte must contain either whitespace, an open or close ** parenthesis, a quote character, or EOF. */ cNext = zInput[nKey]; if( fts3isspace(cNext) || cNext=='"' || cNext=='(' || cNext==')' || cNext==0 ){ pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr)); if( !pRet ){ return SQLITE_NOMEM; } pRet->eType = pKey->eType; pRet->nNear = nNear; *ppExpr = pRet; *pnConsumed = (int)((zInput - z) + nKey); return SQLITE_OK; } /* Turns out that wasn't a keyword after all. This happens if the ** user has supplied a token such as "ORacle". Continue. */ } } /* Check for an open bracket. */ if( sqlite3_fts3_enable_parentheses ){ if( *zInput=='(' ){ int nConsumed; pParse->nNest++; rc = fts3ExprParse(pParse, &zInput[1], nInput-1, ppExpr, &nConsumed); if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; } *pnConsumed = (int)((zInput - z) + 1 + nConsumed); return rc; } /* Check for a close bracket. */ if( *zInput==')' ){ pParse->nNest--; *pnConsumed = (int)((zInput - z) + 1); return SQLITE_DONE; } } /* See if we are dealing with a quoted phrase. If this is the case, then ** search for the closing quote and pass the whole string to getNextString() ** for processing. This is easy to do, as fts3 has no syntax for escaping ** a quote character embedded in a string. */ if( *zInput=='"' ){ for(ii=1; ii<nInput && zInput[ii]!='"'; ii++); *pnConsumed = (int)((zInput - z) + ii + 1); if( ii==nInput ){ return SQLITE_ERROR; } return getNextString(pParse, &zInput[1], ii-1, ppExpr); } /* If control flows to this point, this must be a regular token, or ** the end of the input. Read a regular token using the sqlite3_tokenizer ** interface. Before doing so, figure out if there is an explicit ** column specifier for the token. ** ** TODO: Strangely, it is not possible to associate a column specifier ** with a quoted phrase, only with a single token. Not sure if this was ** an implementation artifact or an intentional decision when fts3 was ** first implemented. Whichever it was, this module duplicates the ** limitation. */ iCol = pParse->iDefaultCol; iColLen = 0; for(ii=0; ii<pParse->nCol; ii++){ const char *zStr = pParse->azCol[ii]; int nStr = (int)strlen(zStr); if( nInput>nStr && zInput[nStr]==':' && sqlite3_strnicmp(zStr, zInput, nStr)==0 ){ iCol = ii; iColLen = (int)((zInput - z) + nStr + 1); break; } } rc = getNextToken(pParse, iCol, &z[iColLen], n-iColLen, ppExpr, pnConsumed); *pnConsumed += iColLen; return rc; }
Image* ImageFactory::initializeImage(){ int type; int width; int height; int maxVal = 1; char string[128]; getNextString(string); // Checks type type = string[1] - '0'; if (string[0] != 'P' || type < 1 || type > 6){ throw "Invalid image format. The file should begin with \'P\' and the value after that should be between 1 and 6."; } // Get width getNextString(string); width = (int) std::strtoul(string, NULL, 0); if (width <= 0){ throw "Invalid image size. Width should be greater than 0."; } // Get height getNextString(string); height = (int)std::strtoul(string, NULL, 0); if (height <= 0){ throw "Invalid image size. Height should be greater than 0."; } // Get maxVal if needed if (type != 1 && type != 4){ getNextString(string); maxVal = (int)std::strtoul(string, NULL, 0); if (maxVal <= 0 || maxVal > Image::MAX_VAL_MAX){ throw "Invalid maxVal value. It should be between 1 and 65536"; } } Image * pImage = NULL; // Construct Image: try { switch (type){ case(1): pImage = new PlainMonochromeImage(width, height, PlainMonochromeImage::defaultMaxVal, type, *stream); break; case(2) : pImage = new PlainGrayscaleImage(width, height, maxVal, type, *stream); break; case(3) : pImage = new PlainPixmapImage(width, height, maxVal, type, *stream); break; case(4): //TODO : Binary monochrome case(5): //TODO : Binary grayscale case(6): //TODO : Binary pixmap default: throw "Invalid image type."; } } catch (std::exception e)//TODO: make more cases { std::cerr << e.what() << std::endl; throw e; } catch (char* e) { std::cerr << e << std::endl; throw e; } return pImage; }