#include "Includes.h"// Inclus les fichiers... #pragma comment(lib,"psapi.lib") /* Bibliothèque ESTR développé par DarkBatcher pour DOS 9. http://dos9.franceserv.fr/ */ ESTR* InitESTR(void) { ESTR* ptrESTR=NULL; ptrESTR=(ESTR*)malloc(sizeof(ESTR)); if (ptrESTR) { ptrESTR->ptrString=(char*)malloc(DEFAULT_ESTR); if (ptrESTR->ptrString) ptrESTR->iLenght=DEFAULT_ESTR; else return NULL; *(ptrESTR->ptrString)='\0'; return ptrESTR; } else return NULL; } #ifdef WIN32 int EsGetW(ESTR* ptrESTR, HANDLE hFile) { int iCurrentL=0, iBytesRead=0, iResult=0; char* crLf=NULL; char *ptrCursor=NULL; ptrCursor=ptrESTR->ptrString; iCurrentL=ptrESTR->iLenght-1; while(1) { iResult=ReadFile(hFile, ptrCursor, iCurrentL+1, (PDWORD)&iBytesRead, NULL); if (iResult && iBytesRead==0) return FILE_END; crLf=strchr(ptrESTR->ptrString, '\n'); if (crLf!=NULL) break; iCurrentL=ptrESTR->iLenght; ptrESTR->iLenght=ptrESTR->iLenght*2; ptrESTR->ptrString=(char*)realloc(ptrESTR->ptrString, ptrESTR->iLenght); if (ptrESTR->ptrString==NULL) return EXIT_FAILURE; ptrCursor=ptrESTR->ptrString+iCurrentL-1; } return EXIT_SUCCESS; } #endif int EsGet(ESTR* ptrESTR, FILE* ptrFile) { int iCurrentL=0; char* crLf=NULL; char* ptrBuffer=NULL, *ptrCursor=NULL; ptrCursor=ptrESTR->ptrString; iCurrentL=ptrESTR->iLenght-1; while(1) { if(fgets(ptrCursor, iCurrentL+1, ptrFile)==NULL) return FILE_END; crLf=strchr(ptrESTR->ptrString, '\n'); if (crLf!=NULL) break; iCurrentL=ptrESTR->iLenght; ptrESTR->iLenght=ptrESTR->iLenght*2; ptrESTR->ptrString=(char*)realloc(ptrESTR->ptrString, ptrESTR->iLenght); if (ptrESTR->ptrString==NULL) return EXIT_FAILURE; ptrCursor=ptrESTR->ptrString+iCurrentL-1; } return EXIT_SUCCESS; } int EsCpy(ESTR* ptrESTR, char* ptrChaine) { int iLen=0; iLen=((strlen(ptrChaine)+1)/DEFAULT_ESTR+1)*DEFAULT_ESTR; if (ptrESTR->iLenghtptrString=(char*)realloc(ptrESTR->ptrString,iLen); if (ptrESTR->ptrString==NULL) return 1; ptrESTR->iLenght=iLen; } strcpy(ptrESTR->ptrString, ptrChaine); return 0; } int EsCpyE(ESTR* ptrDest, ESTR* ptrSource) { int iLen; iLen=(((strlen(ptrSource->ptrString)+1)/DEFAULT_ESTR+1)*DEFAULT_ESTR); if (iLen>ptrDest->iLenght) { ptrDest->ptrString=(char*)realloc(ptrDest->ptrString,iLen); if (ptrDest->ptrString==NULL) return 1; ptrDest->iLenght=iLen; } strcpy(ptrDest->ptrString, ptrSource->ptrString); return 0; } int EsCatE(ESTR* ptrSource, ESTR* ptrDest) { int iLen=0; iLen=((strlen(ptrSource->ptrString)+strlen(ptrDest->ptrString))/DEFAULT_ESTR+1)*DEFAULT_ESTR; if (ptrDest->iLenghtptrString=(char*)realloc(ptrDest->ptrString,iLen); if (ptrDest->ptrString==NULL) return 1; ptrDest->iLenght=iLen; } strcat(ptrDest->ptrString, ptrSource->ptrString); return 0; } int EsCat(ESTR* ptrESTR, char* ptrChaine) { int iLen=0; iLen=strlen(ptrESTR->ptrString)+strlen(ptrChaine)+1; iLen=(iLen/DEFAULT_ESTR+1)*DEFAULT_ESTR; if (ptrESTR->iLenghtptrString=(char*)realloc(ptrESTR->ptrString,iLen); if (ptrESTR->ptrString==NULL) return 1; ptrESTR->iLenght=iLen; } strcat(ptrESTR->ptrString, ptrChaine); return 0; } int EsFree(ESTR* ptrESTR) { free(ptrESTR->ptrString); free(ptrESTR); return 0; }