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 |
{ |
{ |
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 |
} |
} |