void* gt_rbtree_next_equal_key(GtRBTree *tree, void *key, GtCompareWithData cmpfun, void *cmpinfo) { int cmp; const GtRBTreeNode *current, *found = NULL; gt_assert(tree); gt_assert(key); gt_assert(cmpfun); current = tree->root; while (current != NULL) { cmp = cmpfun(key, current->key, cmpinfo); if (cmp == 0) { return current->key; } else { if (cmp < 0) { found = current; current = current->link[0]; } else { current = current->link[1]; } } } if (found == NULL) { return NULL; } return found->key; }
char *parse_header(char *input, struct MailHeader *mh) { static char *buf = NULL; static size_t buflen = BUF_LEN; char *next_line = NULL; int i; int (*cmpfun)(const char *, const char *, size_t); if (!input || !mh) return NULL; /* * Set default value */ memset(mh, 0, sizeof(struct MailHeader)); strcpy(mh->content_type, "text/plain"); strcpy(mh->charset, "iso-8859-1"); strcpy(mh->transenc, "7bit"); if (!buf) buf = (char *)malloc(buflen); if (!buf) return NULL; memset(buf, 0, buflen); next_line = cgetline(input, &buf, 0, &buflen); while (buf[0] && buf[0] != '\n') { for (i = 0 ; hh[i].header ; ++i) { cmpfun = (hh[i].casesence) ? strncmp : strncasecmp; if (!cmpfun(buf, hh[i].header, strlen(hh[i].header))) { if (hh[i].multiline) next_line = merge_input(next_line, &buf, &buflen); if (hh[i].hdl(buf + strlen(hh[i].header) + 1, mh)) { next_line = NULL; dbg("Error at %s %30.30s\n", hh[i].header, buf + strlen(hh[i].header) + 1); goto out; } break; } } next_line = cgetline(next_line, &buf, 0, &buflen); } out: return next_line; }
int recover_dirent(const char *direct) { struct file_list *dl; size_t dl_size; int i = 0, cmp, fdr, fdw; char dirpath[PATHLEN]; FILEHEADER fhr, nfhr; FILE *fhw; int result = 0; setdotfile(dirpath, direct, NULL); dl = get_file_list(dirpath, &dl_size, "M."); if (!dl) return -1; qsort(dl, dl_size, sizeof(struct file_list), cmpfun); if ((fdr = open(direct, O_RDWR)) < 0) return -1; if (myflock(fdr, LOCK_EX)) { close(fdr); return -1; } fhw = tmpfile(); fdw = fileno(fhw); while (myread(fdr, &fhr, FH_SIZE) == FH_SIZE) { cmp = cmpfun(fhr.filename, dl[i].fname); while (cmp > 0) { restore_fileheader(&nfhr, direct, dl[i].fname); dbg("Inserted %s\n", dl[i].fname); dbg("\tDate: %s User: %s Ident: %d\n", nfhr.date, nfhr.owner, nfhr.ident); dbg("\tTitle: %s\n", nfhr.title); if (mywrite(fdw, &nfhr, FH_SIZE) != FH_SIZE) { result = -1; break; } cmp = cmpfun(fhr.filename, dl[++i].fname); ++result; } if (cmp == 0) { ++i; } else { dbg("Missing %s\n", fhr.filename); dbg("\tDate: %s User: %s Ident: %d\n", fhr.date, fhr.owner, fhr.ident); dbg("\tTitle: %s\n", fhr.title); } if (mywrite(fdw, &fhr, FH_SIZE) != FH_SIZE) { result = -1; break; } } if (result > 0) result = myfdcp(fdw, fdr); fclose(fhw); flock(fdr, LOCK_UN); close(fdr); free(dl); return result; }