61 |
char *buf; |
char *buf; |
62 |
char **fields; |
char **fields; |
63 |
PR *nextPR; |
PR *nextPR; |
64 |
|
PR *prevPR; |
65 |
}; |
}; |
66 |
|
|
67 |
static PR *nextIndexEntryBinary (IndexFileDesc fp); |
static PR *nextIndexEntryBinary (IndexFileDesc fp); |
235 |
p = res->index; |
p = res->index; |
236 |
seplen = strlen (fp->desc->separator); |
seplen = strlen (fp->desc->separator); |
237 |
|
|
238 |
|
p->prevPR = NULL; |
239 |
p->nextPR = NULL; |
p->nextPR = NULL; |
240 |
p->fields = (char **) xmalloc (sizeof (char *) |
p->fields = (char **) xmalloc (sizeof (char *) |
241 |
* get_num_fields (fp->desc->database)); |
* get_num_fields (fp->desc->database)); |
328 |
|
|
329 |
res = allocPR (fp->desc->database); |
res = allocPR (fp->desc->database); |
330 |
indexEnt = res->index; |
indexEnt = res->index; |
331 |
|
indexEnt->prevPR = NULL; |
332 |
indexEnt->nextPR = NULL; |
indexEnt->nextPR = NULL; |
333 |
indexEnt->fields |
indexEnt->fields |
334 |
= (char **) xmalloc (sizeof (char *) |
= (char **) xmalloc (sizeof (char *) |
576 |
} |
} |
577 |
else |
else |
578 |
{ |
{ |
579 |
|
i->index->prevPR = end_chain; |
580 |
end_chain->index->nextPR = i; |
end_chain->index->nextPR = i; |
581 |
end_chain = i; |
end_chain = i; |
582 |
} |
} |
666 |
pr->index = (Index *) xmalloc (sizeof (Index)); |
pr->index = (Index *) xmalloc (sizeof (Index)); |
667 |
pr->index->buf = NULL; |
pr->index->buf = NULL; |
668 |
pr->index->fields = NULL; |
pr->index->fields = NULL; |
669 |
|
pr->index->prevPR = NULL; |
670 |
pr->index->nextPR = NULL; |
pr->index->nextPR = NULL; |
671 |
} |
} |
672 |
|
|
1120 |
} |
} |
1121 |
} |
} |
1122 |
|
|
1123 |
/* Find the PR in the current index with the same PR number as NEW_PR, |
/* Replace a PR in the index with a copy of a new PR. |
1124 |
and replace it with NEW_PR. The old PR is returned, or a NULL |
By generating a copy of the new PR, we allow for the new PR |
1125 |
pointer if a PR with the same number is not found. */ |
to be free'd without harming the index pr chain. */ |
1126 |
|
|
1127 |
PR * |
int |
1128 |
replaceCurrentPRInIndex (PR *new_pr) |
replaceCurrentPRInIndex (PR *curr_pr, PR *new_pr, ErrorDesc *err) |
1129 |
{ |
{ |
1130 |
ErrorDesc err; |
PR *pr_replace, *pr_copy; |
1131 |
IndexDesc indexDesc = getIndexDesc (new_pr->database); |
const DatabaseInfo database = curr_pr->database; |
1132 |
PR **currptr = &(indexDesc->prChain); |
const char *new_pr_num = field_value (new_pr, NUMBER (database)); |
1133 |
const char *new_pr_num = field_value (new_pr, NUMBER (new_pr->database)); |
const char *curr_pr_num = field_value (curr_pr, NUMBER (database)); |
1134 |
|
|
1135 |
|
if (strcmp (curr_pr_num, new_pr_num) != 0) |
1136 |
|
{ |
1137 |
|
return 0; |
1138 |
|
} |
1139 |
|
|
1140 |
|
/* create a copy of the new pr to be put into the index pr chain */ |
1141 |
|
pr_copy = allocPR (database); |
1142 |
|
set_field (pr_copy, NUMBER (curr_pr->database), new_pr_num, err); |
1143 |
|
set_field (pr_copy, CATEGORY (database), |
1144 |
|
field_value (new_pr, CATEGORY (database)), err); |
1145 |
|
setPrevPR (pr_copy, curr_pr->index->prevPR); |
1146 |
|
setNextPR (pr_copy, curr_pr->index->nextPR); |
1147 |
|
fillInPR (pr_copy, err); |
1148 |
|
|
1149 |
|
/* put the copy of new_pr into place in the index pr chain... */ |
1150 |
|
|
1151 |
|
if (curr_pr->index->prevPR == NULL) |
1152 |
|
{ |
1153 |
|
/* the pr to be replaced is at the head of the pr chain */ |
1154 |
|
IndexDesc indexDesc = getIndexDesc (database); |
1155 |
|
free_pr (indexDesc->prChain); |
1156 |
|
indexDesc->prChain = pr_copy; |
1157 |
|
return 1; |
1158 |
|
} |
1159 |
|
|
1160 |
getFirstPR (new_pr->database, &err); |
/* save a pointer to the pr to be replaced so that it can later be free'd */ |
1161 |
|
pr_replace = getNextPR (curr_pr->index->prevPR); |
1162 |
|
|
1163 |
while ((*currptr) != NULL) |
setNextPR (curr_pr->index->prevPR, pr_copy); |
1164 |
|
|
1165 |
|
if (curr_pr->index->nextPR != NULL) |
1166 |
{ |
{ |
1167 |
if (strcmp (field_value (*currptr, NUMBER (new_pr->database)), |
/* the pr to be replaced is not at the end of the pr chain */ |
1168 |
new_pr_num) == 0) |
setPrevPR (curr_pr->index->nextPR, pr_copy); |
|
{ |
|
|
PR *old_pr = (*currptr); |
|
|
new_pr->index->nextPR = old_pr->index->nextPR; |
|
|
old_pr->index->nextPR = NULL; |
|
|
(*currptr) = new_pr; |
|
|
return old_pr; |
|
|
} |
|
|
currptr = &((*currptr)->index->nextPR); |
|
1169 |
} |
} |
1170 |
return NULL; |
|
1171 |
|
free_pr (pr_replace); |
1172 |
|
|
1173 |
|
return 1; |
1174 |
} |
} |
1175 |
|
|
1176 |
/* Remove PR PRNUM from the index for the current database, and rewrite the |
/* Remove PR PRNUM from the index for the current database, and rewrite the |
1224 |
return pr->index->nextPR; |
return pr->index->nextPR; |
1225 |
} |
} |
1226 |
|
|
1227 |
|
void |
1228 |
|
setNextPR (PR *pr, PR *next_pr) |
1229 |
|
{ |
1230 |
|
pr->index->nextPR = next_pr; |
1231 |
|
} |
1232 |
|
|
1233 |
|
PR * |
1234 |
|
getPrevPR (PR *pr) |
1235 |
|
{ |
1236 |
|
return pr->index->prevPR; |
1237 |
|
} |
1238 |
|
|
1239 |
|
void |
1240 |
|
setPrevPR (PR *pr, PR *prev_pr) |
1241 |
|
{ |
1242 |
|
pr->index->prevPR = prev_pr; |
1243 |
|
} |
1244 |
|
|
1245 |
int |
int |
1246 |
indexIsBinary (const DatabaseInfo database) |
indexIsBinary (const DatabaseInfo database) |
1247 |
{ |
{ |