void main(void) { char src[50]=" option = valeur # commentaire"; char dest[30], dest2[30], option[30], valeur[30]; int pos=0; AllTrim(dest,src); pos=At(dest,"#"); if(pos) { if(pos>1) { Substr(dest2,dest,1,pos-1); RTrim(dest2); } } else strcpy(dest2,dest); printf("Ligne nettoyee= :%s:\n",dest2); pos=At(dest2,"="); if(!pos) printf("Attention, ce n'est pas une option.\n"); else { Substr(option,dest2,1,pos-1); RTrim(option); Substr(dest,dest2,pos+1,0); } }
bool CDBF::Locate(bool bLoca) { unsigned int uiHave,i,j; unsigned long ulPrevious=m_ulCurRecLine; char cResult[MAX_CHAR_LENGTH+1]; memset(cResult,0,MAX_CHAR_LENGTH+1); for (i=0;i<m_ulRecCount;i++) { uiHave=0; m_ulCurRecLine=i; for (j=0;j<m_uiCond;j++) { ReadField(m_pszCondition[j][0],cResult,MAX_CHAR_LENGTH); AllTrim(cResult); if (strnicmp(cResult,m_pszCondition[j][1],MAX_CHAR_LENGTH)==0) { uiHave++; } } if (uiHave==m_uiCond) { if (bLoca) m_ulCurRecLine=i; else m_ulCurRecLine=ulPrevious; return true; } } m_ulCurRecLine=ulPrevious; return false; }
void main(void) { char *res; char source[]=" Essai de ligne de texte "; res=AllTrim(source,'\0'); printf("Resultat :%s:\n",res); free(res); }
void main(int argc,char *argv[]) { FILE *in; FILE *out; int i=0,boucle=0; char nom[]="TEMP.TMP"; int bavard=0; int debut=1; if(argc==1) { printf("AllTrim, par Herve\n"); printf("Supprime les espaces inutiles … droite et … gauche dans les lignes d'un fichier\n"); printf("Utilisation : Alltrim [-v] <nomfichier.ext>\n"); printf("\t<nomfichier) peut ˆtre *.txt par exemple\n"); printf("\t-v affiche le fichier en cours de traitement\n"); exit(1); } if(strcmp(argv[1],"-v")==0) { bavard=1; debut=2; } for(boucle=debut;boucle<argc;boucle++) { if (bavard) printf("%s\n",argv[boucle]); if((in=fopen(argv[boucle],"rt"))==NULL) { printf("Impossible d'ouvrir le fichier \"%s\" \n",argv[boucle]); getchar(); exit(2); } if((out=fopen(nom,"wt"))==NULL) { printf("Impossible de creer le fichier \"%s\" \n",nom); getchar(); exit(2); } fgets(ligne1,5000,in); while(!feof(in)) { suppcr(ligne1); AllTrim(ligne2,ligne1); fprintf(out,"%s\n",ligne2); fgets(ligne1,5000,in) ; } fclose(in); fclose(out); unlink(argv[boucle]); rename(nom,argv[boucle]); } }
/***************************************************** ** ** AtlasLogic --- setFilterConditions ** ******************************************************/ void AtlasLogic::setFilterConditions( wxString f, wxString c, const int& m ) { filter = AllTrim( f ); filter.Replace( wxT( "*" ), wxT( "%" )); //filter.Replace( wxT( "'" ), wxT( "\"" )); filter.Replace( wxT( "?" ), wxT( "_" )); country = c; mode = m; assert( sharedSection ); sharedSection->fetchOffset = 0; updateFilter(); }
unsigned long CDBF::Count() { unsigned int i,j; unsigned long ulPrevious=m_ulCurRecLine; unsigned long ulCount=0; char cResult[MAX_CHAR_LENGTH+1]; memset(cResult,0,MAX_CHAR_LENGTH+1); for (i=0;i<m_ulRecCount;i++) { m_ulCurRecLine=i; for (j=0;j<m_uiCond;j++) { ReadField(m_pszCondition[j][0],cResult,MAX_CHAR_LENGTH); AllTrim(cResult); if (strnicmp(cResult,m_pszCondition[j][1],0)==0) { ulCount++; } } } m_ulCurRecLine=ulPrevious; return ulCount; }
/***************************************************** ** ** AtlasImportWorker --- addQueryPart ** ******************************************************/ void addQueryPart( wxString buf ) { buf = AllTrim( buf ); // Comment, skip if ( buf.StartsWith( wxT( "--" ))) return; if ( ! currentQuery.IsEmpty()) currentQuery << wxT( " " ); currentQuery << buf; if ( buf.Find( ';' ) != wxNOT_FOUND ) { sharedSection->readSize += buf.Length(); sharedSection->readSize += 2; sharedSection->progress = (long)(100.0 * (double)sharedSection->readSize / (double)sharedSection->totalSize); qb.push_back( currentQuery ); currentQuery.Clear(); if ( qb.size() > 0 && ( qb.size() % QUERY_BUNDLESIZE ) == 0 ) { execQueryBundle(); } } }
printf("Rtrim:%s:\n",ptr); free(ptr); ptr=RTrim(" ESSAI I ","\0"); printf(":%s:\n",ptr); free(ptr); ptr=RTrim(" ","\0"); printf(":%s:\n",ptr); free(ptr); ptr=RTrim("","\0"); printf(":%s:\n",ptr); free(ptr); ptr=AllTrim("ESSAI I","\0"); printf("Alltrim:%s:\n",ptr); free(ptr); ptr=AllTrim(" ESSAI I ","\0"); printf(":%s:\n",ptr); free(ptr); ptr=AllTrim("ESSAI I ","\0"); printf(":%s:\n",ptr); free(ptr); ptr=AllTrim("ESSAI I ","\0"); printf(":%s:\n",ptr); free(ptr);
// ************************************************************************************************ int main(int argc,char *argv[]) { FILE *in; char NomSRC[100]; char ligne1[1000]; char ligne2[1000]; unsigned long lignencours=0; unsigned long OpenBraces=0; unsigned long CloseBraces=0; int OpenParent=0,CloseParent=0,nberreurs=0,nbcomment=0; int Quotes=0,a,b,c,nbcall=0,nbsetout=0,nbsetindex=0,nbsetin=0,nbsettable=0,nbload=0; int nbif=0; printf("Entrez le nom du programme :\n"); gets(NomSRC); if((in=fopen(NomSRC,"rt"))==NULL) { fprintf(stderr,"Impossible d'ouvrir le fichier \"%s\" \n",NomSRC); getchar(); exit(2); } printf("-------------------------------------------------------------------------------\n"); fgets(ligne1,1000,in); while(!feof(in)) { lignencours++; suppcr(ligne1); supptab(ligne1); AllTrim(ligne2,ligne1); if(ligne2[0]!=47 and ligne2[1]!=47) // On évite les lignes de commentaires. { if(strlen(ligne2)!=0) { if(strstr(ligne2,"call")!=NULL) nbcall++; if(strstr(ligne2,"setout")!=NULL) nbsetout++; if(strstr(ligne2,"setindex")!=NULL) nbsetindex++; if(strstr(ligne2,"setin ")!=NULL) nbsetin++; if(strstr(ligne2,"settable")!=NULL) nbsettable++; if(strstr(ligne2,"load")!=NULL) nbload++; OpenBraces+=Occurs("{",ligne2); CloseBraces+=Occurs("}",ligne2); OpenParent=Occurs("(",ligne2); CloseParent=Occurs(")",ligne2); if(OpenParent!=CloseParent) { printf("\n%s\n",ligne2); printf("Ligne %lu, nb de parenthŠses ouvrantes diff‚rent du nb de parenthŠses fermantes\n",lignencours); nberreurs++; } Quotes=Occurs("\"",ligne2); if(Quotes & 0x0001==1) { printf("\n%s\n",ligne2); printf("Ligne %lu, Pas assez de quotes.\n",lignencours); nberreurs++; } if(strstr(ligne2,"if ")!=NULL) // Recherche de = seuls. (source fréquente d'erreurs) { nbif++; if(a=Occurs("=",ligne2)) { c=0; while(a) { c++; b=At2(ligne2,"=",c); if(b==0) break; if(ligne2[b+1]==61) a--; // egal else { if(ligne2[b-1]!=60 and ligne2[b-1]!=62 and ligne2[b-1]!=33) { if(ligne2[b+1]!=60 and ligne2[b+1]!=62) { printf("\n%s\n",ligne2); printf("Ligne %lu, erreur possible dans un \"if\", un seul egal au lieu de deux.\n",lignencours); nberreurs++; } } } } } } // Vérification des if } } else nbcomment++; fgets(ligne1,1000,in); } fclose(in); if(OpenBraces!=CloseBraces) { printf("Le programme ne contient pas autant d'accolades ouvertes que de ferm‚es.\n"); nberreurs++; } printf("\n"); printf("Nombre total d'erreurs : %d\n",nberreurs); printf("Nombre total de lignes de commentaires : %d\n",nbcomment); printf("Nombre total de tests (if) : %d\n",nbif); printf("Nombre total de lignes : %lu\n\n",lignencours); printf("R‚sum‚ par fonction :\n"); printf("nb call = %d\nnb setout = %d\nnb setindex= %d\nnb setin = %d\nnb settable= %d\nnb load = %d\n",nbcall,nbsetout,nbsetindex,nbsetin,nbsettable,nbload); return(nberreurs); }