static stringpair *insert_stringpair(stringpair *root,char *first,char *second,int matchlength) { stringpair *cur,*pred; assert(root!=NULL); assert(first!=NULL); assert(second!=NULL); /* create a new node, and check whether all is okay */ if ((cur=(stringpair*)malloc(sizeof(stringpair)))==NULL) return NULL; cur->first=duplicatestring(first); cur->second=duplicatestring(second); cur->matchlength=matchlength; cur->documentation=NULL; if (cur->first==NULL || cur->second==NULL) { if (cur->first!=NULL) free(cur->first); if (cur->second!=NULL) free(cur->second); free(cur); return NULL; } /* if */ /* link the node to the tree, find the position */ for (pred=root; pred->next!=NULL && strcmp(pred->next->first,first)<0; pred=pred->next) /* nothing */; cur->next=pred->next; pred->next=cur; return cur; }
SC_FUNC stringlist *insert_path(char *path) { stringlist *cur; assert(path!=NULL); if ((cur=(stringlist*)malloc(sizeof(stringlist)))==NULL) error(103); /* insufficient memory (fatal error) */ if ((cur->line=duplicatestring(path))==NULL) error(103); /* insufficient memory (fatal error) */ cur->next=includepaths.next; includepaths.next=cur; return cur; }
/* ----- string list functions ----------------------------------- */ static stringlist *insert_string(stringlist *root,char *string) { stringlist *cur; assert(string!=NULL); if ((cur=(stringlist*)malloc(sizeof(stringlist)))==NULL) error(103); /* insufficient memory (fatal error) */ if ((cur->line=duplicatestring(string))==NULL) error(103); /* insufficient memory (fatal error) */ cur->next=NULL; if (root->tail) root->tail->next=cur; else root->next=cur; root->tail=cur; return cur; }
/* ----- string list functions ----------------------------------- */ static stringlist *insert_string(stringlist *root,char *string) { stringlist *cur; assert(string!=NULL); if ((cur=(stringlist*)malloc(sizeof(stringlist)))==NULL) error(103); /* insufficient memory (fatal error) */ if ((cur->line=duplicatestring(string))==NULL) error(103); /* insufficient memory (fatal error) */ /* insert as "last" */ assert(root!=NULL); while (root->next!=NULL) root=root->next; cur->next=root->next; root->next=cur; return cur; }
/* ----- string list functions ----------------------------------- */ static stringlist *insert_string(stringlist *root,char *string,int append) { stringlist *cur; assert(string!=NULL); if ((cur=(stringlist*)malloc(sizeof(stringlist)))==NULL) error(103); /* insufficient memory (fatal error) */ if ((cur->line=duplicatestring(string))==NULL) error(103); /* insufficient memory (fatal error) */ if (append) { /* insert as "last" (append mode) */ assert(root!=NULL); while (root->next!=NULL) root=root->next; } /* if */ /* if not appending, the string is inserted at the beginning */ cur->next=root->next; root->next=cur; return cur; }
memfile_t *memfile_creat(const char *name, size_t init) { memfile_t mf; memfile_t *pmf; mf.size = init; mf.base = (char *)malloc(init); mf.usedoffs = 0; if (!mf.base) { return NULL; } mf.offs = 0; pmf = (memfile_t *)malloc(sizeof(memfile_t)); memcpy(pmf, &mf, sizeof(memfile_t)); pmf->name = duplicatestring(name); return pmf; }