| 209 | */ |
| 210 | |
| 211 | help_index_t * /* O - Index pointer or NULL */ |
| 212 | helpLoadIndex(const char *hifile, /* I - Index filename */ |
| 213 | const char *directory) /* I - Directory that is indexed */ |
| 214 | { |
| 215 | help_index_t *hi; /* Help index */ |
| 216 | cups_file_t *fp; /* Current file */ |
| 217 | char line[2048], /* Line from file */ |
| 218 | *ptr, /* Pointer into line */ |
| 219 | *filename, /* Filename in line */ |
| 220 | *anchor, /* Anchor in line */ |
| 221 | *sectptr, /* Section pointer in line */ |
| 222 | section[1024], /* Section name */ |
| 223 | *text; /* Text in line */ |
| 224 | time_t mtime; /* Modification time */ |
| 225 | off_t offset; /* Offset into file */ |
| 226 | size_t length; /* Length in bytes */ |
| 227 | int update; /* Update? */ |
| 228 | help_node_t *node; /* Current node */ |
| 229 | help_word_t *word; /* Current word */ |
| 230 | |
| 231 | |
| 232 | /* |
| 233 | * Create a new, empty index. |
| 234 | */ |
| 235 | |
| 236 | if ((hi = (help_index_t *)calloc(1, sizeof(help_index_t))) == NULL) |
| 237 | return (NULL); |
| 238 | |
| 239 | hi->nodes = cupsArrayNew((cups_array_func_t)help_sort_by_name, NULL); |
| 240 | hi->sorted = cupsArrayNew((cups_array_func_t)help_sort_by_score, NULL); |
| 241 | |
| 242 | if (!hi->nodes || !hi->sorted) |
| 243 | { |
| 244 | cupsArrayDelete(hi->nodes); |
| 245 | cupsArrayDelete(hi->sorted); |
| 246 | free(hi); |
| 247 | return (NULL); |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Try loading the existing index file... |
| 252 | */ |
| 253 | |
| 254 | if ((fp = cupsFileOpen(hifile, "r")) != NULL) |
| 255 | { |
| 256 | /* |
| 257 | * Lock the file and then read the first line... |
| 258 | */ |
| 259 | |
| 260 | cupsFileLock(fp, 1); |
| 261 | |
| 262 | if (cupsFileGets(fp, line, sizeof(line)) && !strcmp(line, "HELPV2")) |
| 263 | { |
| 264 | /* |
| 265 | * Got a valid header line, now read the data lines... |
| 266 | */ |
| 267 | |
| 268 | node = NULL; |