void traiterDataGPS(void){ int i,j,chk; i = 0; while(i<lengthWaitBuffer){ //avencée vers le premier $ while(i<lengthWaitBuffer && waitBuffer[i]!='$') i++; // waitBuffer[i+1] contient le début des données de la trames //calcul du checksum j = i+1; chk = 0; while(j<lengthWaitBuffer && waitBuffer[j]!='*'){ chk ^= waitBuffer[j]; j++; } //trame valide ? if((j+3 < lengthWaitBuffer) && (chk == hexToInt(waitBuffer+j+1,2))){ waitBuffer[j+3] = 0; if(!strCmp(waitBuffer+i,"$GPGGA")){ i += 7; i += strCpy(gps_UTCPos, waitBuffer+i, 10) + 1; i += strCpy(gps_Latitude, waitBuffer+i, 9) + 1; i += strCpy(gps_NSind, waitBuffer+i, 1) + 1; i += strCpy(gps_Longitude, waitBuffer+i, 10) + 1; i += strCpy(gps_EWind, waitBuffer+i, 1) + 1; i += strCpy(gps_PosFixInd, waitBuffer+i, 1) + 1; i += strCpy(gps_SatUsed, waitBuffer+i, 2) + 1; i += strCpy(gps_HDOP, waitBuffer+i, 16) + 1; i += strCpy(gps_Altitude, waitBuffer+i, 16) + 1; i += strCpy(gps_AltUnit, waitBuffer+i, 16) + 1; } else if(!strCmp(waitBuffer+i,"$GPRMC")){ i += 7; i += strCpy(gps_UTCPos, waitBuffer+i, 10) + 1; i += strCpy(gps_Status, waitBuffer+i, 1) + 1; i += strCpy(gps_Latitude, waitBuffer+i, 9) + 1; i += strCpy(gps_NSind, waitBuffer+i, 1) + 1; i += strCpy(gps_Longitude, waitBuffer+i, 10) + 1; i += strCpy(gps_EWind, waitBuffer+i, 1) + 1; i += strCpy(gps_SpeedOverGround, waitBuffer+i, 16) + 1; i += strCpy(gps_CourseOverGround, waitBuffer+i, 16) + 1; i += strCpy(gps_Date, waitBuffer+i, 6) + 1; } } i++; } lengthWaitBuffer = 0; }
int findFileInDirectory(directoryBlock directory, char * fileName) { int y = 0; while (y < DIRECTORYENTRYCOUNT) { char *tempFileName = (char*)mallocFS(mystrlen(directory.entries[y].fileName)); tempFileName = getData(directory.entries[y].fileName); if (strCmp(tempFileName, fileName) == 1 || strCmp(directory.entries[y].fileName, fileName) == 1) return y; y++; } return -1; }
/* * httpHdrMangle checks the anonymizer (header_access) configuration. * Returns 1 if the header is allowed. */ static int httpHdrMangle(HttpHeaderEntry * e, request_t * request) { int retval = 1; /* check with anonymizer tables */ header_mangler *hm; assert(e); if (e->id == HDR_OTHER) { for (hm = Config.header_access[HDR_OTHER].next; hm; hm = hm->next) { if (strCmp(e->name, hm->name) == 0) break; } if (!hm) return 1; } else hm = &Config.header_access[e->id]; if (!hm->access_list) return 1; if (aclCheckFastRequest(hm->access_list, request)) { retval = 1; } else if (NULL == hm->replacement) { /* It was denied, and we don't have any replacement */ retval = 0; } else { /* It was denied, but we have a replacement. Replace the * header on the fly, and return that the new header * is allowed. */ stringReset(&e->value, hm->replacement); retval = -1; } return retval != 0; }
/* sort input lines */ int main(int argc, char *argv[]) { char *lineptr[MAXLINES]; /* pointers to text lines */ int nlines; /* number of input lines read */ int numeric = 0; /* 1 if numeric sort */ /* If the optional argument -n is given, it will sort the input lines * numerically instead of lexicographically. */ if (argc > 1 && strCmp(argv[1], "-n") == 0) numeric = 1; /* lineptr是一个指针,指向的变量类型是char *, 则lineptr对应的数据类型是 * char **,后面一个 * 表示这是一个指针,前面的char * 表示指针指向的类型 * 是 char *; 所以要下面使用 void ** 来进行强制转换,而不是 void * */ if ((nlines = readlines(lineptr, MAXLINES)) >= 0) { qsort((void **)lineptr, 0, nlines - 1, (int (*)(const void*, const void*))(numeric ? numcmp : strCmp)); printf("-------------After sort----------\n"); writelines(lineptr, nlines); return 0; } else { printf("error: input too big to sort\n"); return 1; } }
int main() { //Open a FILE FILE *fp =fopen("yourname.c","r"); //Read a string of length 49 char str[50]; int i=0; int space=0; //int keyword=0; int j; int n; while (fgets(str,49,fp)) // fgets goes line by line so simply putting a counter is fine { i=i+1; for (j=0;j<50;j++) // made up large random end point { if (str[j]==' '){ space=space+1; } } n += strCmp("int",str); } printf("\n number of lines is %d \n",i); printf("\n number of spaces is %d \n",space); printf("\n number of int keywords is %d \n",n); //printf("number of keywords is %d \n",keyword); //Count number of lines //Count number of spaces //Count number of keyword //close a file fclose(fp); return 0; }
int compare(Rich a, Rich b) { if(a.wealth != b.wealth) return a.wealth - b.wealth; else if(a.age != b.age) return b.age - a.age; else return strCmp(b.name, a.name); }
const char* CommandLine::find(int32_t _skip, const char _short, const char* _long, int32_t _numParams) const { for (int32_t ii = 0; ii < m_argc && 0 != strCmp(m_argv[ii], "--"); ++ii) { const char* arg = m_argv[ii]; if ('-' == *arg) { ++arg; if (_short == *arg) { if (1 == strLen(arg) ) { if (0 == _skip) { if (0 == _numParams) { return ""; } else if (ii+_numParams < m_argc && '-' != *m_argv[ii+1] ) { return m_argv[ii+1]; } return NULL; } --_skip; ii += _numParams; } } else if (NULL != _long && '-' == *arg && 0 == strCmpI(arg+1, _long) ) { if (0 == _skip) { if (0 == _numParams) { return ""; } else if (ii+_numParams < m_argc && '-' != *m_argv[ii+1] ) { return m_argv[ii+1]; } return NULL; } --_skip; ii += _numParams; } } } return NULL; }
int main() { static char message[20] = "Salut"; static char ch2[] = "hello"; static char ch1[] = "hi"; printf("\nEntrez un message\n"); getS(message,25); printf("\nAffichage message : "); putS(message); strCpy(ch2,ch1); printf("\nAffichage message apres copy de hi dans hello: "); putS(ch2); printf("%d",strLen("Plop8")); printf("\nstrCmp1 : %d",strCmp("plop","plop")); printf("\nstrCmp2 : %d",strCmp("ABCD","ABEFG")); printf("\nstrCmp3 : %d",strCmp("plop","plo")); printf("\nstrCat : "); strCat(message," Denis"); putS(message); }
tBTNode searchNodes(tBTNode N, tString *key){ if(N==NULL) return NULL; else { int cmp=strCmp(key,N->key); if(cmp!=0){ if(cmp<0)return searchNodes(N->left,key); else return searchNodes(N->right,key); } else return N; } }
int mkdir(char * filePath, char * fileName) { unsigned int destinationDirBlockNumber,newDirBlockNumber; directoryBlock destinationDirectory,newDirectory; int z, y, isfile; if (strCmp(filePath, "/") == 1) destinationDirBlockNumber = ROOTBLOCK; else destinationDirBlockNumber = findFileBlockInPath(filePath); if (destinationDirBlockNumber == -1) { printstring("Directory does not exists"); return -1; } filePath = getData(filePath); fileName = getData(fileName); readsector(destinationDirBlockNumber, &destinationDirectory); isfile = IsNewFile(destinationDirectory, fileName); if (isfile == -1) { printstring("Directory already exist\n"); return -1; } newDirBlockNumber = AllocateBlock(); y = 0; while(y < DIRECTORYENTRYCOUNT) { newDirectory.entries[y].fileType = IS_FILE; newDirectory.entries[y].fileBlockStart = 0; newDirectory.entries[y].fileBlockSize = 0; y++; } writesector(newDirBlockNumber, &newDirectory); z = 0; while (z < DIRECTORYENTRYCOUNT) { if (destinationDirectory.entries[z].fileBlockStart == 0) { strcpy(fileName, destinationDirectory.entries[z].fileName); destinationDirectory.entries[z].fileType = IS_DIRECTORY; destinationDirectory.entries[z].fileBlockStart = newDirBlockNumber; destinationDirectory.entries[z].fileBlockSize = 1; break; } z++; } writesector(destinationDirBlockNumber, &destinationDirectory); printstring("Directory "); printstring(fileName); printstring(" Created!\n"); return newDirBlockNumber; }
E_CODE BTInsert (tBTree *T,tString *key, void *data) { /* -------- ** Vloží do stromu nový uzel s hodnotou Content. ** ** Z pohledu vkládání chápejte vytvářený strom jako binární vyhledávací strom, ** kde uzly s hodnotou menší než má otec leží v levém podstromu a uzly větší ** leží vpravo. Pokud vkládaný uzel již existuje, neprovádí se nic (daná hodnota ** se ve stromu může vyskytnout nejvýše jednou). Pokud se vytváří nový uzel, ** vzniká vždy jako list stromu. Funkci implementujte nerekurzivně. **/ if (T->root==NULL){ //prázdný strom T->root=mmuMalloc(sizeof(struct tBTreeNode)); T->root->key=key; T->root->data=data; T->root->left=T->root->right=NULL; T->root->height=0; T->lastAdded=T->root; return ERROR_OK; } tBTNode tmp = T->root; int cmpResult; while(tmp!=NULL){ cmpResult=strCmp(key,tmp->key); if (cmpResult<0){ if(tmp->left==NULL){ //vlož levý tmp->left=mmuMalloc(sizeof(struct tBTreeNode)); tmp->left->key=key; tmp->left->data=data; tmp->left->left=tmp->left->right=NULL; tmp->left->height=(tmp->height)+1; T->lastAdded=tmp->left; return ERROR_OK; } else tmp=tmp->left;//hledej dál vlevo } else if (cmpResult>0){ if (tmp->right==NULL){ //vlož pravý tmp->right=mmuMalloc(sizeof(struct tBTreeNode)); tmp->right->key=key; tmp->right->data=data; tmp->right->left=tmp->right->right=NULL; tmp->right->height=(tmp->height)+1; T->lastAdded=tmp->right; return ERROR_OK; } else tmp=tmp->right;//hledej dál vpravo } else{ T->lastAdded=tmp;return ERROR_INS_EXIST; } } return ERROR_OK; }
boolean esp8266ConnectAP(char *name, char *password) { INT8U err; char *str; esp8266RxBufferFlash(); usart0Print("AT+CWJAP=\""); usart0Print(name); usart0Print("\",\""); usart0Print(password); usart0Print("\"\r\n"); while (1) { err = usart0Read(&str, ESP8266_LONG_TIMEOUT); if (err == OS_ERR_TIMEOUT) { return FALSE; } else if (strCmp(str, "OK")) { return TRUE; } else if (strCmp(str, "FAIL")) { return FALSE; } } }
boolean esp8266GetIP(char *buf) { INT8U err; char *str; boolean result; result = FALSE; esp8266RxBufferFlash(); usart0Print("AT+CIFSR\r\n"); while (1) { err = usart0Read(&str, ESP8266_SHORT_TIMEOUT); if (err == OS_ERR_TIMEOUT || strCmp(str, "OK")) { break; } else if (*str >= '0' && *str <= '9') { if (!strCmp(str, "192.168.4.1")) { strCpy(str, buf); result = TRUE; } } } return result; }
int IsNewFile(directoryBlock dirBlock, char *fileName) { int y = 0; while (y < DIRECTORYENTRYCOUNT) { if (strCmp(getData(dirBlock.entries[y].fileName), fileName) == 1) { return -1; } y++; } return 1; }
void mkf(char * path, char* fileName, char acess[], char *data) { int y,isfile; directoryBlock destinationDirectory; fileBlock file; unsigned int newDirBlockNumber, destinationDirBlockNumber; if (strCmp(getData(path), "/") != 1) { destinationDirBlockNumber = findFileBlockInPath(getData(path)); } else { destinationDirBlockNumber = ROOTBLOCK; } if (destinationDirBlockNumber == -1) { printstring("Path cannot be found, creating file failed"); return; } readsector(destinationDirBlockNumber, (char*)&destinationDirectory); isfile = IsNewFile(destinationDirectory, getData(fileName)); if (isfile == -1) { printstring("File already exist\n"); return; } file.size = 0; file.type = IS_FILE; file.data[0] = '\0'; strcpy(getData(fileName), file.fileName); strcpy(getData(acess), file.acessRights); strcpy(getData(data), file.data); newDirBlockNumber = AllocateBlock(); wf(&file, getData(data), newDirBlockNumber); y = 0; while( y < DIRECTORYENTRYCOUNT) { if (destinationDirectory.entries[y].fileBlockStart == 0) { strcpy(destinationDirectory.entries[y].fileName, file.fileName); destinationDirectory.entries[y].fileType = IS_FILE; destinationDirectory.entries[y].fileBlockStart = newDirBlockNumber; destinationDirectory.entries[y].fileBlockSize = file.size; break; } y++; } writesector(destinationDirBlockNumber, (char*)&destinationDirectory); return; }
/* lookup: look for s in hashtab; 该函数调用hash()函数,由所给字符串得到一个 * 较小的非负数,使用该非负数作为hash表的数组下标,得到一个指向链表头的指针, * 在该链表中查找所给字符串是否存在. If lookup finds the entry already * present, it returns a pointer to is; if not, it returns NULL. */ struct nlist *lookup(const char *s) { struct nlist *np; /* The for loop in this function is the standard idiom for walking * along a linked list: * for (ptr = head; ptr != NULL; ptr = ptr->next) * .... */ for (np = hashtab[hash(s)]; np != NULL; np = np->next) if (strCmp(s, np->name) == 0) return np; /* found */ return NULL; /* not found */ }
int main() { tBTree *T; tBTNode N; mmuInit(); T=mmuMalloc(sizeof(tBTree)); btInit(T); tString str,str1,str2,str3; void *nic=NULL; str=strCreate("ahoj"); str1=strCreate("nazdar"); str2=strCreate("valhala"); str3=strCreate("abcd"); if(strCmp(&str1,&str1)!=0)printf("chyba strCmp"); //printf("%s\n",str.data); BTInsert(T,&str,nic); BTInsert(T,&str1,nic); BTInsert(T,&str2,nic); BTInsert(T,&str3,nic); printf("%d\n",T->root->height); printf("%s\n",T->root->left->key->data); printf("%s\n",T->root->right->key->data); printf("%s\n",T->root->right->right->key->data); printf("%s\n",T->root->key->data); N=btFind(T,&str1); //BTInsert(T,&str2,nic); if(N!=NULL)printf("%s\n",N->key->data); else printf("nic se nenaslo\n"); if(T->root->left==NULL && T->root->right==NULL) printf("chyba\n"); int cmp=strCmp(&str1,&str); printf("%d\n",cmp); //btFree(T); mmuGlobalFree(); return 0; }
void updateCmd(char* cmdName,char* cmdValue) { /* this function test the command ID matching * and if a received command is valid, set the UARTCde[].ready variable at 1. * It is used to get the value of the new command*/ unsigned char i; for(i=1;i<NB_CMD;i++) { if(strCmp(cmdName,commandID[i],3)) { //compare command ID with stored ID UARTCde[i].value=toShort(cmdValue); //convert received value to a short and store it UARTCde[i].ready=1; } } }
/* qsort: sort v[left] ... v[right] into increasing order */ void qsort(char *v[], int left, int right) { int i, last; if (left >= right) return ; /* 快速排序的终止条件,当传入的数组中只有一个元素时退出 */ swap (v, left, (left + right) / 2); last = left; for (i = left + 1; i <= right; ++i) if (strCmp(v[i], v[left]) < 0) swap (v, ++last, i); swap (v, left, last); qsort (v, left, last - 1); qsort (v, last + 1, right); }
boolean esp8266Cmd(char *cmd, char *response) { INT8U err; char *str; esp8266RxBufferFlash(); usart0Print(cmd); usart0Print("\r\n"); while (1) { err = usart0Read(&str, ESP8266_SHORT_TIMEOUT); if (err == OS_ERR_TIMEOUT) { return FALSE; } else if (strCmp(str, response)) { return TRUE; } } }
/* foldcmp: fold upper and lower case together */ int foldcmp(const char *s1, const char *s2) { char *x, *y; int i; x = alloc(strLen(s1) + 1); y = alloc(strLen(s2) + 1); strCpy(x, s1); strCpy(y, s2); upperstring(x); upperstring(y); i = strCmp(x, y); afree(x); afree(y); return i; }
void addWord(char *place, char *word) { char *current = place; char *parent = NULL; int resCmp = 0; for (;;) { resCmp = strCmp(word, current); if (resCmp > 0) { parent = current - 1; if (*parent) current = place + *parent + wordNodeHeaderSize; else break; } else if (resCmp < 0) { parent = current - 2; if (*parent) current = place + *parent + wordNodeHeaderSize; else break; } else break; } if (resCmp) { WordBST * bst = (WordBST *) (place - fullHeaderSize); if (bst->current + wordNodeHeaderSize + strlen(word) >= wordBSTSize) throw OverflowException(); *parent = bst->current; bst->current += WordNodeInit(place + bst->current, word) + wordNodeHeaderSize; } else { WordNode * node = (WordNode *) (current - wordNodeHeaderSize); node->counter++; } }
void cpy(char *pathSource, char *destinyPath, char *copyName) { directoryBlock source, destiny; int sourceBlock, destinyBlock, newBlockDir, z; char *sourcePathName,*dirName; sourceBlock = findFileBlockInPath(getData(pathSource)); destinyBlock = findFileBlockInPath(getData(destinyPath)); if (sourceBlock == 0 || destinyBlock == 0) { return; } sourcePathName = getPathName(getData(pathSource), 2); readsector(sourceBlock, (char *)&source); readsector(destinyBlock, (char *)&destiny); { newBlockDir = mkdir(getData(destinyPath), getData(copyName)); if (strCmp(getData(getData(destinyPath)), "/") != 1) { dirName = mistrcat(getData(destinyPath), "/"); dirName = mistrcat(getData(dirName), getData(copyName)); dirName = getData(dirName); } else dirName = getData(getData(destinyPath)); z = 0; while(z < DIRECTORYENTRYCOUNT) { if (destiny.entries[z].fileBlockStart == 0) { destiny.entries[z].fileName[0] = '\0'; strcpy(getData(copyName), destiny.entries[z].fileName); destiny.entries[z].fileType = IS_DIRECTORY; destiny.entries[z].fileBlockStart = newBlockDir; destiny.entries[z].fileBlockSize = 1; break; } z++; } writesector(destinyBlock, (char *)&destiny); cpyDir(sourceBlock, newBlockDir, dirName); } }
int main() { char str[80]; char str1[80]; char *ptr; int len; printf("input string: "); gets(str); printf("原始字串: \"%s\"\n", str); len = strLen(str); printf("字串\"%s\"的長度為: %d\n", str, len); printf("複製字串: \"%s\"\n", strCpy(str1, str)); printf("請輸入欲連接的字串: "); gets(str1); printf("欲連接字串: \"%s\"\n", str1); ptr = strCat(str, str1); printf("連接結果的字串: \"%s\"\n", ptr); printf("請輸入欲比較的字串: "); gets(str1); printf("欲比較的字串: \"%s\"\n", str1); printf("字串比較結果: %d\n", strCmp(str, str1)); }
int main(){ str_t *s = strNew("Testing"); str_t *s2 = strNew(" this thing \n"); str_t *s3 = strNew(NULL); strCat(s, s2); strCpy(s3, s); strAppend(s3, "aaaaa"); printf("%lu, %lu, %lu %s\n", s->len, s->size, strlen(s->str), s->str); printf("%lu, %lu, %lu %s\n", s3->len, s3->size, strlen(s3->str), s3->str); str_t *c = strNew("testing"); strCpy(s, c); // strCpy(s2, c); printf("compare: %d\n", strCmp(s, s2)); strDel(s); strDel(s2); strDel(s3); return 0; }
void rn(char *dirPath, char *newDirName) { directoryBlock dir; int dirBlockPos,entryNumber, pathLenght,y; char *path,*previousDirName,*tempDirName; pathLenght = mystrlen(getData(dirPath)); path= (char*)mallocFS(pathLenght); path = getPathName(getData(dirPath), 1); previousDirName = getPathName(getData(dirPath), 2); dirBlockPos = findFileBlockInPath(path); if (dirBlockPos == -1) { printstring("Directory does not exists"); return; } readsector(dirBlockPos, &dir); entryNumber = findFileInDirectory(dir, previousDirName); if (entryNumber == -1) { printstring("Directory does not exists"); return; } tempDirName = (char*)mallocFS(mystrlen(getData(dirPath))); tempDirName = getData(dir.entries[entryNumber].fileName); if (strCmp(tempDirName, previousDirName) == 1) { y = 0; while( y < mystrlen(dir.entries[entryNumber].fileName)) { dir.entries[entryNumber].fileName[y] = ' '; y++; } strcpy(dir.entries[entryNumber].fileName, getData(newDirName)); dir.entries[entryNumber].fileType = IS_DIRECTORY; writesector(dirBlockPos, (char*)&dir); } }
// // Driver Odbc // void * sqlLiteScroll(struct OBJ *objCalled,EN_MESSAGE cmd,LONG info,CHAR *str) { static struct WINSCR rit,*PtScr; EH_DISPEXT *psExt; S_SCR_INFO * psSI,sSqlInfo; INT a;//,b; // INT ptClient; // SQLRETURN sqlReturn; // // Inizializzazione // if (_local.bReset) { _local.lstScr=lstCreate(sizeof(S_SCR_INFO)); FTIME_on(_SqlThreadRefresh,1); _local.bReset=false; } // Oggetto buono ? if ((objCalled->tipo!=OW_SCR)&&(objCalled->tipo!=OW_SCRDB)) return 0; psSI=objCalled->pOther; if (cmd==WS_INF) return &psSI->ws; switch (cmd) { // ----------------------------------- // APERTURA DEL DRIVER | // ----------------------------------- case WS_CREATE: //break; #ifdef OS_DEBUG printf("OdbcScroll: Create" CRLF); #endif _(sSqlInfo); objCalled->pOther=lstPush(_local.lstScr,&sSqlInfo); psSI=objCalled->pOther; psSI->ObjClient=objCalled; psSI->ObjClient->bFreeze=TRUE; // Blocco la gestione dell'oggetto psSI->bDrawLineDiv=TRUE; #ifdef EH_SQL_SQLITE psSI->enPlatform=_SQL_SQLITE; #endif #ifdef EH_SQL_MYSQL psSI->enPlatform=_SQL_MYSQL; #endif // // Alla prima chiamata creo thread e "finestrame" necessario // // Tecnologia sqlLite // - La connessione deve essere inizializzata // if (!psSI->hThread) { memset(&psSI->csSqdStruct,0,sizeof(CRITICAL_SECTION)); memset(&psSI->csSqdQuery,0,sizeof(CRITICAL_SECTION)); InitializeCriticalSection(&psSI->csSqdStruct); InitializeCriticalSection(&psSI->csSqdQuery); /* // // Alloco lo stantment clone ( Si libererà con WS_DESTROY) // sqlReturn=SQLAllocHandle(SQL_HANDLE_STMT, sOdbcSection.hConn, &psSI->hStmtScroll); if (sqlReturn!=SQL_SUCCESS&&sqlReturn!=SQL_SUCCESS_WITH_INFO) ehExit("OdbcScroll:hStmt Clone impossible %d",sqlReturn); // Bho ? SQLSetStmtAttr(psSI->hStmtScroll, SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_READ_ONLY, 0); sqlReturn=SQLSetStmtAttr(psSI->hStmtScroll, SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_SCROLLABLE , 0); if (sqlReturn==SQL_ERROR) // Altro metodo { sqlReturn=SQLSetStmtAttr( psSI->hStmtScroll,SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_STATIC, 0); if (sqlReturn==SQL_ERROR) win_infoarg("errore in assegnazione cursore"); sqlReturn=SQLSetStmtAttr( psSI->hStmtScroll, SQL_ATTR_USE_BOOKMARKS, (SQLPOINTER) SQL_UB_VARIABLE, 0); if (sqlReturn==SQL_ERROR) win_infoarg("SQL_ATTR_USE_BOOKMARKS"); } //sprintf(szCursor,"SQD%d",ptClient); //SQLTRY(SQL_HANDLE_STMT,"SQD->",psSI->hStmtScroll,SQLSetCursorName(psSI->hStmtScroll, szCursor, SQL_NTS)); //SQLTRY("ASYNC",psSI->hStmtScroll,SQLSetStmtAttr(psSI->hStmtScroll, SQL_ATTR_ASYNC_ENABLE, (SQLPOINTER) SQL_ASYNC_ENABLE_ON , 0)); // // 4) Creo il Thread (SQLExecuteThread) per l'elaborazione delle query // */ for (a=0;a<ESQL_MAXEVENTLOAD;a++) psSI->arhEvent[a]=CreateEvent(NULL,true,FALSE,NULL); psSI->hThread = CreateThread(NULL, 0, _sqlExecuteThread, (LPDWORD) psSI, 0, &psSI->dwThread); psSI->bAutoRowSelect=TRUE; // <-- 2010 - Inserito auto select in partenza SetThreadPriority(psSI->hThread,THREAD_PRIORITY_NORMAL); } break; case WS_OPEN: // // Inizializzazione della finestra // if (info<3) {ehExit("Field ? " __FUNCTION__);} psSI->ws.numcam=info;// Assegna il numero di campi da visualizzare psSI->ws.selez=-1; psSI->ws.maxcam=0; psSI->ObjClient->tipo=OW_SCR; psSI->lRowsTotal=0; psSI->fChanged=0; psSI->ObjClient->bFreeze=FALSE; if (psSI->funcNotify) psSI->funcNotify(_adaptor(objCalled,WS_OPEN,0,NULL,NULL));//objCalled,NULL,0,NULL,WS_OPEN,NULL,NULL); psSI->ws.bExtSelection=TRUE; // Gestione esterna della selezione psSI->ws.fNoBlankLine=TRUE; case WS_LOAD: break; // ----------------------------------- // Richiesta di refresh // ----------------------------------- case WS_RELOAD: if (info) _queryExecute(psSI,__LINE__); else _fetch(psSI); return NULL; // Non serve stampare // ----------------------------------- // WS_CLOSE IL DRIVER | // ----------------------------------- case WS_CLOSE: sqlLiteScroll(objCalled,WS_PROCESS,STOP,NULL); // Chiedo di fermare il processo in corso psSI->ObjClient->bFreeze=true; if (psSI->funcNotify) (psSI->funcNotify)(_adaptor(objCalled,WS_CLOSE,0,NULL,NULL)); break; // ----------------------------------- // CHIUSURA DEFINITIVA DEL GESTORE (chiamato in obj_close()); // ----------------------------------- case WS_DESTROY: // // Notifico la chiusura alla funzione esterna // if (psSI->funcNotify) (psSI->funcNotify)(_adaptor(objCalled,WS_DESTROY,0,NULL,NULL)); // Fermo il Thread SetEvent(psSI->arhEvent[ESQL_STOP]); // Segnalo che siamo in chiusura if (WaitForSingleObject(psSI->hThread,5000)) { //_dx_(0,20,"Entro qui"); //SQLFetchScroll(psSI->hStmtScroll,SQL_FETCH_FIRST,0); //SQLFreeHandle(SQL_HANDLE_STMT,psSI->hStmtScroll); psSI->hStmtScroll=0; //_dx_(0,40,"Terminate %d",TerminateThread(psSI->hThread,0)); } /* if (psSI->hStmtScroll) {SQLFreeHandle(SQL_HANDLE_STMT,psSI->hStmtScroll); psSI->hStmtScroll=0;} if (psSI->rsSet) {odbc_QueryResultDestroy(psSI->rsSet); ehFree(psSI->rsSet);} psSI->rsSet=NULL; // Libero la memoria usata per la Query ehFreePtr(&psSI->pQueryActive); ehFreePtr(&psSI->pszQueryCount); ehFreePtr(&psSI->pLastErrorText); // Libero la memoria usata per la WhereAdd ehFreePtr(&psSI->pQuerySelect); ehFreePtr(&psSI->pszKeyCode); ARDestroy(psSI->arKeyCodeFld); ehFreePtr(&psSI->pCodeFocused); ehFreePtr(&psSI->pCodeSelected); ehFreePtr(&psSI->pCodeReturn); // Libero gli Handle degli eventi for (a=0;a<ESQL_MAXEVENTLOAD;a++) CloseHandle(psSI->arhEvent[a]); // 1.2.3. Liberi tutti !! DeleteCriticalSection(&psSI->csSqdStruct); DeleteCriticalSection(&psSI->csSqdQuery); // Azzero la struttura di riferimento memset(psSI,0,sizeof(S_SCR_INFO)); */ { EH_LST_I * psi; psi=lstSearch(_local.lstScr,objCalled->pOther); lstRemoveI(_local.lstScr,psi); } ehFreePtr(&objCalled->pOther); break; // ----------------------------------- // PRESSIONE DI UN TASTO/MOUSE | // ----------------------------------- case WS_KEYPRESS: if (key_press2(KEY_F9)) {strcpy(str,"ESC:F9"); break;} if (psSI->funcNotify) (psSI->funcNotify)(_adaptor(objCalled,cmd,info,str,NULL)); break; // ----------------------------------- // SETTA SELEZIONE RECORD | // ----------------------------------- case WS_SEL: if (!psSI->funcNotify) break;//ehExit(SdbDriver32 ":No ext/disp function"); // if (!psSI->rsSet) break; // printf("%d",psSI->rsSet->iCurrentRow); //if (psSI->ws.selez==-1) break; break; // ------------------------------------- // SETTA L'OFFSET (Solo Modo O_SCROLL | // ------------------------------------- case WS_OFF: break; // ------------------------------------- // // ------------------------------------- case WS_PTREC : // Restituisce pt alla chiave selezionata case WS_GET_SELECTED: _(rit); rit.record=-1; if (strEmpty(psSI->pszKeyCode)) {efx2(); return NULL;} /* // // Selezione in scroll // if (psSI->rsSet&&psSI->ws.selez>-1) { psSI->rsSet->iCurrentRow=psSI->ws.selez; if (strEmpty(psSI->pszKeyCode)) ehExit("%s:%d manca assegnazione pszKeyCode",__FILE__,__LINE__); _keyCodeBuilder(&psSI->pCodeReturn,psSI); rit.record=psSI->ws.selez; rit.keypt=psSI->pCodeReturn; if (psSI->bAutoRowSelect) { strAssign(&psSI->pCodeSelected,psSI->pCodeReturn); InvalidateRect(objCalled->hWnd,NULL,FALSE); } } // // Pre-selezione (non entrao in scroll // else if (!strEmpty(psSI->pCodeSelected)) { rit.record=psSI->ws.selez; rit.keypt=psSI->pCodeSelected; } if (cmd==WS_GET_SELECTED) return retCreate(_ALFA,rit.record,rit.keypt); */ return &rit; // ------------------------------------- // RITORNA Selez ?????????? | // ------------------------------------- case WS_REALGET: break; // ------------------------------------- // Refresh a ON | // ------------------------------------- case WS_REFON : psSI->ws.refre=ON; break; case WS_REFOFF : psSI->ws.refre=OFF; break; case WS_PROCESS: if (info==STOP&&!str) { // SQLCancel(psSI->hStmtScroll); // Cancello il processo nello stantment printf("> cancellare processo in corso"); EnterCriticalSection(&psSI->csSqdStruct); psSI->fBreak=true; LeaveCriticalSection(&psSI->csSqdStruct); while (TRUE) {if (!psSI->fInProcess) break; else Sleep(50);} //win_infoarg("SQL stop"); } // Controllo se l'elaborazione è in corso if ((info==0)&&(*str=='?')) { if (psSI->fInProcess) return "!"; else return NULL; } break; // // Chiedo di cambiare il la Where di ricerca // case WS_SETFILTER: EnterCriticalSection(&psSI->csSqdStruct); ehFreePtr(&psSI->pQuerySelect); psSI->pQuerySelect=strDup(str); psSI->ws.selez=-1; psSI->ws.maxcam=0; psSI->lRowsReady=0; psSI->lRowsTotal=0; LeaveCriticalSection(&psSI->csSqdStruct); if (info) { InvalidateRect(objCalled->hWnd,NULL,TRUE); _message(psSI,TRUE,"Attendere\nRichiesta al server ..."); OsEventLoop(5); } psSI->fQueryToExecute=true; // _queryExecute(psSI,__LINE__); // Me ne arriva uno dopo break; case WS_SETFLAG: objCalled->pOtherEx=str; // Assegno un puntatore esterno if (psSI->funcNotify) (psSI->funcNotify)(_adaptor(objCalled,WS_SETFLAG,info,NULL,NULL)); break; // ------------------------------------- // Richiesta di Stampa dei Dati | // ------------------------------------- case WS_DISPLAY : // Richiesta buffer psExt=(EH_DISPEXT *) str; if (!psSI->funcNotify) { Tboxp( psExt->rClientArea.left, psExt->rClientArea.top, psExt->rClientArea.right, psExt->rClientArea.bottom-1, RGB(255,128,0),SET); // arError=ARCreate(psSI->pLastErrorText,"\n",&iRow); dispf(psExt->px+1,psExt->py+1,RGB(255,255,255),-1,STYLE_NORMAL,"SMALL F",3,"-Not func for Display-"); break; } // // Richiesta di stampa del titolo // if (psExt->ncam==-10) { psSI->funcNotify(_adaptor(objCalled,WS_DISPLAY,0,psExt,NULL));//psSI->Hdb,psSI->iIndex); break; } /* if (!psSI->rsSet) { if (psSI->bSqlError) { Tboxp(psExt->px,psExt->py,psExt->px+psExt->lx-1,psExt->py+psExt->ly-1,sys.Color3DShadow,SET); if (psSI->pLastErrorText) { EH_AR arError; INT iRow; arError=ARCreate(psSI->pLastErrorText,"\n",&iRow); if (psExt->ncam<iRow) dispf(psExt->px+1,psExt->py+1,RGB(255,255,255),-1,STYLE_NORMAL,"SMALL F",3,arError[psExt->ncam]); ARDestroy(arError); } } else Tboxp(psExt->px,psExt->py,psExt->px+psExt->lx-1,psExt->py+psExt->ly-1,sys.Color3DLight,SET); break; } psExt->col1=GetSysColor(COLOR_MENUTEXT); psExt->col2=GetSysColor(COLOR_WINDOW); if (psExt->bFocus) // selezione con il mouse { psExt->col1=GetSysColor(COLOR_HIGHLIGHTTEXT); psExt->col2=ColorLum(GetSysColor(COLOR_HIGHLIGHT),30); } if (psExt->bSelected) // Selezionato fisso { psExt->col1=GetSysColor(COLOR_HIGHLIGHTTEXT); psExt->col2=GetSysColor(COLOR_HIGHLIGHT); } Tboxp(psExt->px,psExt->py,psExt->px+psExt->lx-1,psExt->py+psExt->ly-2,psExt->col2,SET); //Sleep(100); psSI->rsSet->iCurrentRow=info; psSI->rsSet->iOffset=psSI->iSQLOffset; // Non ho ancora le linee da visualizzare if (psExt->ncam>=psSI->lRowsReady|| (psSI->rsSet->iCurrentRow<psSI->iSQLOffset)|| ((psSI->rsSet->iCurrentRow-psSI->iSQLOffset)>=psSI->rsSet->iRowsLimit)) { boxBrush(psExt->px,psExt->py,psExt->rClientArea.right,psExt->rClientArea.bottom,HS_VERTICAL,sys.Color3DLight,ColorLum(sys.Color3DHighLight,-10)); Tline(psExt->px,psExt->rClientArea.bottom,psExt->rClientArea.right,psExt->rClientArea.bottom,sys.Color3DShadow,SET); break; } // RIchiedo stampa della riga psSI->funcNotify( _adaptor(objCalled,WS_DISPLAY,info,psExt, psSI->rsSet)); if (psSI->bDrawLineDiv) line(psExt->px,psExt->rClientArea.bottom,psExt->rClientArea.right,psExt->rClientArea.bottom,sys.colScrollDiv,SET); if (psExt->bFocus) { boxFocus(psExt->px,psExt->py,psExt->px+psExt->lx-1,psExt->py+psExt->ly-2); } */ break; // -------------------------------------------------------------------------- // SET della funzione esterna // -------------------------------------------------------------------------- case WS_EXTNOTIFY: psSI->funcNotify=(LRESULT (*)(EH_NOTIFYPARAMS)) str;//(INT (*)(struct OBJ *,INT ,LONG ,void *str,EH_ODBC_RS )) str; psSI->funcNotify(_adaptor(objCalled,WS_CREATE,0,NULL,NULL)); break; case WS_LINEVIEW: // psSI->ws.numcam=info; break; case WS_LINEEDIT: // psSI->ws.Enumcam=info; break; case WS_SIZE: break; case WS_MOVE: break; case WS_SETTITLE: break; case WS_CODENAME: strAssign(&psSI->pszKeyCode,str); strTrim(psSI->pszKeyCode); ARDestroy(psSI->arKeyCodeFld); psSI->arKeyCodeFld=ARCreate(psSI->pszKeyCode,"+",&psSI->iKeyCodePart); break; // // Riga in FOCUS // /* case WS_SET_ROWFOCUS: if (!str) // Dal gestore oggetti { if (info<0) {strAssign(&psSI->pCodeFocused,NULL); break;} if (psSI->pCodeName&&psSI->rsSet) { psSI->rsSet->iCurrentRow=info; psSI->rsSet->iOffset=psSI->ws.offset; // psSI->rsSet->iCurrentRow riga della query if (psSI->rsSet->iCurrentRow>=psSI->iSQLOffset&& psSI->rsSet->iCurrentRow<(psSI->iSQLOffset+psSI->lRowsReady)) { strAssign(&psSI->pCodeFocused,sql_ptr(psSI->rsSet,psSI->pCodeName)); strTrim(psSI->pCodeFocused); } else { strAssign(&psSI->pCodeFocused,NULL); // Non ho la selezione richiesta in memoria } dispxEx(0,80,"%d,%d = %s ", psSI->rsSet->iCurrentRow, psSI->iSQLOffset+psSI->lRowsReady, psSI->pCodeFocused); } return NULL; } else // Esterno { strAssign(&psSI->pCodeFocused,str); InvalidateRect(objCalled->hWnd,NULL,FALSE); } break; case WS_GET_ROWFOCUS: if (psSI->pCodeName&&psSI->pCodeFocused&&psSI->rsSet) { CHAR *p; if (info<0) return NULL; psSI->rsSet->iCurrentRow=info; psSI->rsSet->iOffset=psSI->ws.offset; p=sql_ptr(psSI->rsSet,psSI->pCodeName); strTrimRight(p); if (!strcmp(p,psSI->pCodeFocused)) break; } return NULL; */ // // Riga in SELECTED // case WS_SET_ROWSELECTED: printf("qui"); /* if (!str) // Dal gestore oggetti { if (info<0) {strAssign(&psSI->pCodeSelected,NULL); InvalidateRect(objCalled->hWnd,NULL,FALSE); break;} if (psSI->pszKeyCode&&psSI->rsSet) { psSI->rsSet->iCurrentRow=info; psSI->rsSet->iOffset=psSI->ws.offset; _keyCodeBuilder(&psSI->pCodeSelected,psSI); //if (!strEmpty(p)) break; } InvalidateRect(objCalled->hWnd,NULL,FALSE); return NULL; } else // Esterno { strAssign(&psSI->pCodeSelected,str); InvalidateRect(objCalled->hWnd,NULL,FALSE); } */ break; case WS_GET_ROWSELECTED: // // Controllo di selezione // if (psSI->pszKeyCode&&!strEmpty(psSI->pCodeSelected)&&psSI->rsSet) { CHAR * p; if (info<0) return NULL; //psSI->rsSet->iCurrent=info; p=_keyCodeBuilder(psSI,info); // Può ritornare Null in p se sto chiedendo una riga che non c'è (in fase di ingrandimento) if (!strCmp(p,psSI->pCodeSelected)) {ehFreeNN(p); break;} ehFreeNN(p); } return NULL; case WS_EVENT: /* if (!psSI->rsSet) break; psSI->rsSet->iCurrentRow=info; psSI->rsSet->iOffset=psSI->iSQLOffset; if (psSI->funcNotify) { BYTE *ptr=(BYTE *) (psSI->funcNotify)(_adaptor(objCalled,cmd,info,str,psSI->rsSet)); return ptr; } */ printf("qui"); break; case WS_BUF: break; default: /* if (psSI->funcNotify) (psSI->funcNotify)(_adaptor(objCalled,cmd,info,str,psSI->rsSet)); else printf(__FUNCTION__ "Event ? [%d][%s]" CRLF,cmd,objCalled->nome); */ break; } //PtScr=psSI->WinScr; PtScr=NULL; if (!PtScr) PtScr=&rit; return PtScr; }
void CEditListCtrl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; LV_ITEM *plvItem = &pDispInfo->item; if (m_iSubItem == 1 || m_iSubItem == 2) { if (plvItem->pszText != NULL ) { SetItemText(plvItem->iItem,m_iSubItem, plvItem->pszText);//m_iSubItem为1就是X坐标,2就是Y坐标 CString strCmp(_T("")); if (GetItemText(plvItem->iItem,1)!=strCmp && GetItemText(plvItem->iItem,2)!=strCmp) { SetItemText(plvItem->iItem,3,_T("")); } else { SetItemText(plvItem->iItem,3,_T("非法点")); } if (preEditString != plvItem->pszText) { m_bEditDataChanged = TRUE;//文字改变标志改变 } if (m_iSubItem == 1) { if (plvItem->pszText == strCmp) { vctPoint[plvItem->iItem].x = -9999999; } else { vctPoint[plvItem->iItem].x = _wtoi(plvItem->pszText); } } else if (m_iSubItem == 2) { if (plvItem->pszText == strCmp) { vctPoint[plvItem->iItem].y = -9999999; } else { vctPoint[plvItem->iItem].y = _wtoi(plvItem->pszText); } } } VERIFY(m_edtItemEdit.UnsubclassWindow()!=NULL); *pResult = 0; } //编辑文本时对控件父窗口操作(如单击其它控件)引发"OnEndlabeledit"时刷新控件 CRect rect; GetWindowRect(&rect); CPoint point; ::GetCursorPos(&point); if(!rect.PtInRect(point)) { m_iItem = -1; m_iSubItem = -1; m_bFocus = FALSE; m_bHighLight = FALSE; } }
char* Parser::calculateResult(char *exp) { tmpStr[0] = '\0'; //reseting... operator_s op0 = findOperator(exp, 0); char lhs[INSTRUCTIONSIZE]; char rhs[INSTRUCTIONSIZE]; memcpy(lhs, exp, op0.pos); lhs[op0.pos] = '\0'; int rhsLen = strlen(exp) - op0.pos; memcpy(rhs, exp + op0.pos + op0.len, rhsLen); rhs[rhsLen] = '\0'; Alias_s aliasLhs = parseKeywords(lhs); Alias_s aliasRhs = parseKeywords(rhs); if (strCmp(aliasLhs.value, "")) { //alias need to be set to an default value, DO CRASH!!! } else if (strCmp(aliasRhs.value, "")) { //alias need to be set to an default value, DO CRASH!!! } //do calculation //Both are digits if (strCmp(aliasLhs.type, "int") && strCmp(aliasRhs.type, "int")) { if (strCmp(op0.op, "+")) { sprintf(tmpStr, "%d", atoi(aliasLhs.value) + atoi(aliasRhs.value)); } else if (strCmp(op0.op, "-")) { sprintf(tmpStr, "%d", atoi(aliasLhs.value) - atoi(aliasRhs.value)); } else if (strCmp(op0.op, "*")) { sprintf(tmpStr, "%d", atoi(aliasLhs.value) * atoi(aliasRhs.value)); } else if (strCmp(op0.op, "/")) { sprintf(tmpStr, "%d", atoi(aliasLhs.value) / atoi(aliasRhs.value)); int v = atoi(tmpStr); if (v < 0) { tmpStr[0] = '0'; tmpStr[1] = '\0'; } } else if (strCmp(op0.op, "==")) { if (strCmp(aliasLhs.value, aliasRhs.value)) { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } else { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } } else if (strCmp(op0.op, "!=")) { if (strCmp(aliasLhs.value, aliasRhs.value)) { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } else { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } } else if (strCmp(op0.op, "<")) { int l = atoi(aliasLhs.value); int r = atoi(aliasRhs.value); if (l < r) { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } else { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } } else if (strCmp(op0.op, ">")) { int l = atoi(aliasLhs.value); int r = atoi(aliasRhs.value); if (l < r) { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } else { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } } else if (strCmp(op0.op, "=")) { memcpy(&aliasLhs.value, &aliasRhs.value, aliasRhs.len); aliasLhs.value[aliasRhs.len] = '\0'; aliasLhs.len = aliasRhs.len; int a = heap.getAddress(aliasLhs.name); heap.insertAliasAt(a, aliasLhs); } else { //Wrong syntax do CRASH!!! } } //Both are text strings. else if (strCmp(aliasLhs.type, "string") && strCmp(aliasRhs.type, "string")) { if (strCmp(op0.op, "+")) { return strcat(aliasLhs.value, aliasRhs.value); } else if (strCmp(op0.op, "-")) { //Wrong syntax do CRASH!!! } else if (strCmp(op0.op, "*")) { //Wrong syntax do CRASH!!! } else if (strCmp(op0.op, "/")) { //Wrong syntax do CRASH!!! } else if (strCmp(op0.op, "==")) { if (strCmp(aliasLhs.value, aliasRhs.value)) { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } else { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } } else if (strCmp(op0.op, "!=")) { if (strCmp(aliasLhs.value, aliasRhs.value)) { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } else { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } } else if (strCmp(op0.op, "<")) { if (aliasLhs.len < aliasRhs.len) { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } else { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } } else if (strCmp(op0.op, ">")) { if (aliasLhs.len > aliasRhs.len) { memcpy(tmpStr, "true", 4); tmpStr[4] = '\0'; } else { memcpy(tmpStr, "false", 5); tmpStr[5] = '\0'; } } else if (strCmp(op0.op, "=")) { memcpy(aliasLhs.value, aliasRhs.value, strlen(aliasLhs.value)); aliasLhs.len == aliasRhs.len; int a = heap.getAddress(aliasLhs.name); heap.insertAliasAt(a, aliasLhs); } else { //Wrong syntax do CRASH! } } else { //Cannot compare digits and strings. } return tmpStr; }
bool phone::isMsg(char *str) // check if get some message { if(strCmp(8, str, "CMTI: \"SM\","))return 1; else return 0; }