LSTList rgbGetBasicColors () { int i; static RGBColor_ST basic_colors_vc[] = { { 000, 000, 000 }, { 255, 255, 255 }, { 255, 000, 000 }, { 000, 255, 000 }, { 000, 000, 255 }, { 255, 000, 255 }, { 000, 255, 255 }, { 255, 255, 000 } }; RGBColor_ST* curr_color_p; LSTList basic_colors = lstNew(); if (basic_colors) for (i = 0; i < 8; i ++) { curr_color_p = rgbAlloc(basic_colors_vc[i]); if (curr_color_p) lstAppend(basic_colors, curr_color_p); else { rgb_current_error = RGB_NOT_ENOUGH_SPACE; lstDestroy(&basic_colors); return NULL; } } else rgb_current_error = RGB_NOT_ENOUGH_SPACE; return basic_colors; }
struct List* getUnwarnedAppointements(Int32 patId) { struct List* retVal = lstCreate(gAppointments->_allocateData, gAppointments->_printData, gAppointments->_cloneData); struct List* uwApts = lstFilter(gAppointments,NULL, &isUnwarned); struct ListNode* n = uwApts->rootNode; while( n != NULL ) { struct Appointment* apt = (struct Appointment*) n->data; // ajouter le rdv si le patient n'a pas déjà été ajouté if(apt->fk_pat == patId ) lstAdd(retVal, retVal->_cloneData(apt)); n = n->next; } lstDestroy(uwApts); return retVal; }
static S_PHRASES * _phraseDestroy(S_PHRASES * psPh) { CHAR * pTradotto; S_PHSTR * psPhs; pTradotto=tagDecode(psPh->psTag,NULL,FALSE,TRUE); ehFreePtr(&pTradotto); for (lstLoop(psPh->lstPhrase,psPhs)) { ehFreeNN(psPhs->pszStr); ehFreeNN(psPhs->pszAfter); ehFreeNN(psPhs->pszBefore); } psPh->lstPhrase=lstDestroy(psPh->lstPhrase); ehFree(psPh); return NULL; }
struct List* getUnwarnedPatients() { struct List* retVal = lstCreate(gPatients->_allocateData, gPatients->_printData, gPatients->_cloneData); struct List* uwApts = lstFilter(gAppointments,NULL, &isUnwarned); struct ListNode* n = uwApts->rootNode; while( n != NULL ) { struct Appointment* apt = (struct Appointment*) n->data; // ajouter le rdv si le patient n'a pas déjà été ajouté struct Patient* found = (struct Patient*) lstFind(retVal, &apt->fk_pat, &checkPatientId); struct Patient* toAdd = (struct Patient*) lstFind(gPatients, &apt->fk_pat, &checkPatientId); if(!found) lstAdd(retVal, retVal->_cloneData(toAdd)); n = n->next; } lstDestroy(uwApts); return retVal; }
/*-------------------------- Implementation------------------------------*/ void closeLists() { lstSerialize(gAbsences, sizeof(struct Absence), FILE_ABSENCES); lstDestroy(gAbsences); lstSerialize(gAppointments, sizeof(struct Appointment), FILE_APPOINTMENTS); lstDestroy(gAppointments); lstSerialize(gConsultations, sizeof(struct Consultation),FILE_CONSULTATIONS); lstDestroy(gConsultations); lstSerialize(gDoctors, sizeof(struct Doctor),FILE_DOCTORS); lstDestroy(gDoctors); lstSerialize(gPatients, sizeof(struct Patient),FILE_PATIENTS); lstDestroy(gPatients); lstSerialize(gRooms, sizeof(Uint8),FILE_ROOMS); lstDestroy(gRooms); }
void mnuDestroy(struct Menu *mnu) { lstDestroy(mnu->menuEntries); free(mnu); }
// // ehTranslate() // UTF8 * ehTranslate( ET_PARAM enParam, UTF8 * pszSource, CHAR * pszLangSource, CHAR * pszLangDest, CHAR * pszJsonParams, // {googlekey:"asda", bingkey:"asd"} ET_REPORT * psReport, void * (* extAssist)(EN_MESSAGE enMess,LONG lParam,void *pVoid), EH_LST lstBlackKey ) { WCHAR *pw; BYTE *pTradotto=NULL; S_PHRASES * psPh=NULL; S_PHSTR * psPhs; //INT f; BOOL bError=FALSE; INT iLen; INT iCharsBad; BYTE *pUtf; CHAR szLangDetect[20]=""; double dRap; INT iWords; ET_REPORT sReportTemp; EH_JSON * psJson=NULL; CHAR * pszUserIp=NULL; INT iMaxPhrases=0; ET_BLACK_ITEM sBlack; if (lstBlackKey) { if (lstBlackKey->iSize!=sizeof(ET_BLACK_ITEM)) ehExit("Usare transBlackListCreate();"); } if (!_s.bReady) {_(_s); _s.bReady=true; ehAddExit(_transEndPoint);} // <-- Resetto la struttura Privata if (!psReport) psReport=&sReportTemp; memset(psReport,0,sizeof(ET_REPORT)); if (!(enParam&ET_TRY_LOCAL)) extAssist=NULL; if (!pszLangSource) ehError(); strcpy(psReport->szLangSource,pszLangSource); if (!pszLangDest) ehError(); strcpy(psReport->szLangDest,pszLangDest); // // Assistente: ricerco prima in cache la frase completa // strTrim(pszSource); if (!*pszSource) { return strDup(""); } if (enParam&ET_STAT) { psReport->dwChars=strlen(pszSource); psReport->dwWords=strWordCount(pszSource); } if (!(enParam&ET_TRANS)&&!(enParam&ET_LANGDETECT)) return NULL; // Nessun servizio richiesto if (pszJsonParams) { CHAR * psz; psJson=jsonCreate(pszJsonParams); psz=jsonGet(psJson,"maxPhrases"); if (psz) iMaxPhrases=atoi(psz); } // // PREPARAZIONE FRASI DA RICHIEDERE // A seconda del servizio esterno di traduzione creo le frasi richieste // psPh=_phraseCreate(pszSource,iMaxPhrases);//,TTE_BING); if (!psPh) { psReport->etError=GE_STRING_TOO_LONG; return NULL; } // // Richiesta traduzioni frasi // if (enParam&ET_OUTPUTDETT) { if (psPh->iPhraseToTrans>1) printf("%s|%d}",pszLangDest,psPh->iPhraseToTrans); else printf("%s}",pszLangDest); } if (iMaxPhrases&&psPh->iPhraseToTrans>iMaxPhrases) { psReport->etError=GE_TOO_PHRASES; _phraseDestroy(psPh); jsonDestroy(psJson); return NULL; } if (enParam&ET_OUTPUTDETT) printf("|Phrase: total %d, problems %d, html:%d|" CRLF,psPh->iPhraseToTrans,psPh->iPhraseProblems,psPh->psTag->bHtml); if (enParam&ET_DOT_PROGRESS) printf("%d",psPh->iPhraseToTrans); //for (f=0;psPh->arPhrase[f];f++) for (lstLoop(psPh->lstPhrase,psPhs)) { CHAR * pszPhrase; CHAR * pszPrefix=NULL; if (!psPhs->bTranslate) continue; // strTrim(psPhs->pszStr); pszPhrase=psPhs->pszStr; if (strEmpty(pszPhrase)) continue; iLen=strlen(pszPhrase); if (iLen<2) continue; // Non traduco frasi con meno di 2 caratteri // // a. Controllo se è un numero // if (!_isNaN(pszPhrase)) {ehFreePtr(&pszPrefix); continue;} // // b. Conto le parole // iWords=0; iCharsBad=0; dRap=0; if (enParam&ET_LANGDETECT) { iWords=strWordCount(pszPhrase); // Precontrollo stringa // Proporzione: iCharsBad:iLen=x:100 iCharsBad=strCount(pszPhrase,".()[],-*_"); dRap=iCharsBad*100/iLen; if (dRap>50) // Frase composta da oltre il 50% di simboli e non di lettere { psReport->etError=GE_STRING_SUSPECT; // L'indicazione della lingua sorgente è errata psPh->iPhraseProblems++; if (enParam&ET_OUTPUTDETT) printf("?"); ehFreePtr(&pszPrefix); continue; } } // // Local request ########################################################################################### // pUtf=NULL; if (extAssist) { S_TRANSLATION sTrans; sTrans.pszLangSource=pszLangSource; sTrans.pszLangDest=pszLangDest; sTrans.utfSource=pszPhrase; sTrans.utfDest=NULL; if (extAssist(WS_FIND,0,&sTrans)) { psReport->iLocalResponse++; if (enParam&ET_STAT) { psReport->dwLocalChars+=strlen(pszPhrase); psReport->dwLocalWords+=strWordCount(pszPhrase); } pUtf=sTrans.utfDest; if (pUtf) { psReport->enTech=ET_LOCAL; if (enParam&ET_SERVICE_CALL) printf("l$"); if (enParam&ET_OUTPUTDETT) printf("l"); } } } // // BING request ########################################################################################### // if (!pUtf&& psJson&& enParam&ET_TRY_BING) { CHAR * pszBingApp; INT iRequestDone=0; EH_LST lstKey; // Cerco Appi o multi Appid lstKey=lstNew(); pszBingApp=jsonGet(psJson,"bingAppId"); if (pszBingApp) lstPush(lstKey,pszBingApp); else { pszBingApp=jsonGet(psJson,"arBingAppId.length"); if (pszBingApp) { INT a,iLen=atoi(pszBingApp); for (a=0;a<iLen;a++) { lstPush(lstKey,jsonGetf(psJson,"arBingAppId[%d]",a)); } } } if (enParam&ET_OUTPUTDETT) printf("|pszBingApp:%s|" CRLF,pszBingApp); if (lstKey->iLength) { CHAR * pszAppId; if (enParam&ET_STAT) { psReport->dwBingChars+=strlen(pszPhrase); psReport->dwBingWords+=strWordCount(pszPhrase); } for (lstLoop(lstKey,pszAppId)) { if (_isBlackList(lstBlackKey,ET_BING,pszAppId)) continue; pUtf=_bingCall( enParam, pszPhrase, pszLangSource, pszLangDest, pszAppId, &iRequestDone, &psReport->etError); if (enParam&ET_OUTPUTDETT) { printf("(%s) > (%s) #%d",pszPhrase,pUtf,psReport->etError); } psReport->iBingRequest+=iRequestDone; if (!strEmpty(pUtf)) { psReport->enTech=ET_BING; psReport->iBingResponse++; if (enParam&ET_OUTPUTDETT) printf("B"); break; } else { psReport->iBingErrors++; if (enParam&ET_OUTPUTDETT) printf("Bx"); ehSleep(1000); } // // Abuso + BlackList // if (psReport->etError==GE_ABUSE&& lstBlackKey) { _(sBlack); sBlack.enTech=ET_BING; sBlack.pszAppId=strDup(pszAppId); lstPush(lstBlackKey,&sBlack); } } } lstDestroy(lstKey); }
static CHAR * _azureTokenRequest(ET_PARAM enParam,CHAR * pszJsonString) { EH_WEB *psWeb; // CHAR * pszTranslateParams=pszJsonString; if (!_s.lstAzureToken) _s.lstAzureToken=lstNew(); // Creo la prima volta la lista // // Richiedo 'azureToken' a 'mamma' Microsoft // if (strstr(pszJsonString,"arAzureClient")) { CHAR * pszAppTranslatorUrl="https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate"; CHAR * pszScope="http://api.microsofttranslator.com"; CHAR * pszGrantType="client_credentials"; CHAR * pszAuthUrl="https://datamarket.accesscontrol.windows.net/v2/OAuth2-13"; // // https://datamarket.azure.com/developer/applications/ // EH_LST lst; CHAR * pszUrl; S_SEN * psSen; INT a,iLen; EH_JSON * psJson=jsonCreate(pszJsonString); // EH_LST lstToken=lstNew(); lstClean(_s.lstAzureToken); if (psJson->enType==JSON_ERROR) ehError(); iLen=atoi(jsonGet(psJson,"arAzureClient.length")); for (a=0;a<iLen;a++) { CHAR * psz=jsonGetf(psJson,"arAzureClient[%d]",a); EH_AR ar; if (strEmpty(psz)) continue; ar=strSplit(psz,"|"); psSen=senCreate(); lst=lstNew(); lstPushf(lst,"%s?",pszAuthUrl); lstPushf(lst,"grant_type=%s",senEncode(psSen,SE_URL,pszGrantType)); lstPushf(lst,"&scope=%s",pszScope);//senEncode(psSen,SE_URL,pszScope)); lstPushf(lst,"&client_id=%s",senEncode(psSen,SE_URL,ar[0])); lstPushf(lst,"&client_secret=%s",senEncode(psSen,SE_URL,ar[1])); senDestroy(psSen); pszUrl=lstToString(lst,"","",""); psWeb=webHttpReq(pszUrl,"POST",NULL,FALSE,60); if (enParam&ET_SERVICE_CALL) printf(">azureToken:"); if (!psWeb->sError.enCode) { // Leggi pagina caricata EH_JSON * psJson; psJson=jsonCreate(psWeb->pData); psz=jsonGet(psJson,"access_token"); lstPush(_s.lstAzureToken,strEver(psz)); jsonDestroy(psJson); if (enParam&ET_SERVICE_CALL) printf("ok." CRLF); } else { lstPush(_s.lstAzureToken,""); printf("\7Azure Error: Account %s accesso error" CRLF,ar[0]); if (enParam&ET_SERVICE_CALL) printf("ko!" CRLF); } ehFree(ar); webHttpReqFree(psWeb); ehFree(pszUrl); lstDestroy(lst); } // // Aggiungo Token di accesso Trovati // /* if (lstToken->iLength) { CHAR * psz=lstToString(lstToken,","," ,arAzureToken:[","]"); xx pszTranslateParams[strlen(pszTranslateParams)-1]=0; strCat(&pszTranslateParams,psz); strCat(&pszTranslateParams,"}"); ehFree(psz); } */ jsonDestroy(psJson); // lstDestroy(lstToken); } // ehFree(pszJsonString); return pszJsonString; }
static void _transEndPoint(BOOL x) { if (!_s.bReady) return; if (_s.lstAzureToken) _s.lstAzureToken=lstDestroy(_s.lstAzureToken); }