/[gnats]/gnats/gnats/ds-file/index.c
ViewVC logotype

Diff of /gnats/gnats/ds-file/index.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by hatzis, Sat Apr 23 05:15:21 2005 UTC revision 1.2 by amanou, Mon Nov 7 20:41:48 2005 UTC
# Line 426  createIndexEntryBinary (PR *pr, size_t * Line 426  createIndexEntryBinary (PR *pr, size_t *
426    return res;    return res;
427  }  }
428    
 static char *  
 findPrCategoryBinary (IndexFileDesc fp, const char *number)  
 {  
   unsigned char fieldcount;  
   char *record;  
   size_t recLen;  
     
   if (fread (&fieldcount, 1, 1, fp->fileDes) != 1)  
     {  
       return NULL;  
     }  
   while ((record = readBinaryRecord (fp, &recLen)) != NULL)  
     {  
       char *recPos = record;  
       char *prNum = extractBinaryField (&recPos, &recLen);  
       if (prNum != NULL && strcmp (prNum, number) == 0)  
         {  
           char *category = extractBinaryField (&recPos, &recLen);  
           free (record);  
           return category;  
         }  
       free (record);  
     }  
   return NULL;  
 }  
   
 /* Find problem report NUMBER in the index file, returning its category.  */  
 static char *  
 findPrCategory (IndexFileDesc fp, const char *number)  
 {  
   char *buf;  
   char *res = NULL;  
   
   while ((res == NULL) && (buf = read_line (fp->fileDes, NULL)) != NULL)  
     {  
       if (buf[0] != '#')  
         {  
           char *start = buf;  
           char *end = strchr (start, '/');  
           if (end != NULL)  
             {  
               char *numStart = end + 1;  
               char *category = start;  
   
               *end = '\0';  
               end = find_sep (fp->desc, numStart);  
               if (end != NULL)  
                 {  
                   *end = '\0';  
   
                   if (strcmp (numStart, number) == 0)  
                     {  
                       res = xstrdup (category);  
                     }  
                 }  
             }  
         }  
       free (buf);  
     }  
   
   return res;  
 }  
   
429  static time_t  static time_t
430  statIndex (char *name)  statIndex (char *name)
431  {  {
# Line 975  indexValue (PR *pr, FieldIndex field) Line 912  indexValue (PR *pr, FieldIndex field)
912      }      }
913    else    else
914      {      {
       return NULL;  
     }  
 }  
   
 char *  
 getCategoryFromIndex (const DatabaseInfo database, const char *prnum,  
                       ErrorDesc *err)  
 {  
   IndexDesc indexDesc = getIndexDesc (database);  
   IndexFileDesc fp = openIndex (indexDesc, err);  
   if (fp != NULL)  
     {  
       char *category;  
       if (fp->desc->isBinary)  
         {  
           category = findPrCategoryBinary (fp, prnum);  
         }  
       else  
         {  
           category = findPrCategory (fp, prnum);  
         }  
       closeIndex (fp);  
       if (category == NULL)  
         {  
           setError (err, CODE_NONEXISTENT_PR,  
                     "PR %s is not listed in the index.", prnum);  
         }  
       return category;  
     }  
   else  
     {  
915        return NULL;        return NULL;
916      }      }
917  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26