int CharacterListMgnt::getObjektsFromFile ( char *  filename  ) 

Definition at line 250 of file CharacterListMgnt.cpp.

00250                                                         {
00251     int errorVar = 0;
00252     int counter = 0;
00253     char regExp[] = "inUse :[ \t]*([0-9]+)\\|\\| finished :[ \t]*([0-9]+)\\|\\| int96 :[ \t]*([0-9a-f]+)\\|\\| id:[ \t]*([0-9]+)";
00254     int subExpCount = 4;
00255     regex_t regEx;
00256     regEx.re_nsub = subExpCount;
00257     regmatch_t* regMatch = (regmatch_t *) malloc(sizeof(regmatch_t) * regEx.re_nsub);
00258     char filebuff[1024];
00259     FILE* datei;
00260     filebuff[0] = '\0';
00261 
00262     errorVar =  regcomp(&regEx, regExp, REG_EXTENDED);
00263     if( errorVar != 0 ){
00264         return 1;
00265     }
00266     datei = fopen(filename,"r");
00267     if(datei == NULL){
00268         return 1;
00269     }
00270     fseek(datei,0 , SEEK_SET);
00271     while( !feof(datei) ){
00272         fgets(filebuff, 1023, datei);
00273         errorVar = regexec(&regEx, filebuff, regEx.re_nsub + 1, regMatch, 0);
00274         if( errorVar == REG_ESPACE ){
00275             return 2;
00276         }
00277         else if( errorVar == REG_NOMATCH ){
00278             return 3;
00279         }
00280         else{
00281             CharacterItem* ci;
00282             ci = new CharacterItem();
00283 
00284             char* filebuff2 = new char[regMatch[3].rm_eo - regMatch[3].rm_so + 2];
00285             filebuff2[0] = '\0';
00286             strncat(filebuff2, &filebuff[regMatch[3].rm_so], ( regMatch[3].rm_eo - regMatch[3].rm_so ));
00287                         if( charToInt(regMatch[1].rm_so, regMatch[1].rm_eo - 1, filebuff) != 0){
00288                                 ci->set_inUse( 1 );
00289                         }
00290                         else{
00291                                 ci->set_inUse( 0 );
00292                         }
00293             if( charToInt(regMatch[2].rm_so, regMatch[2].rm_eo - 1, filebuff) != 0){
00294                 ci->set_inUse( 1 );
00295             }
00296             else{
00297                 ci->set_inUse( 0 );
00298             }
00299             ci->set_u_int_96(filebuff2);
00300             ci->set_ID(charToInt(regMatch[4].rm_so, regMatch[4].rm_eo - 1, filebuff));
00301             ciVector.push_back(ci);
00302             counter = counter + 1;
00303         }
00304                 filebuff[0] = '\0';
00305     }
00306         return 0;
00307 }


Generated on Wed Jun 25 14:47:07 2008 for keyvil by  doxygen 1.5.1