Another stringlist fix
The previous one didn't quite work with the docstring list.
This commit is contained in:
parent
0aba449b68
commit
74625128c4
@ -264,8 +264,10 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef struct s_stringlist {
|
typedef struct s_stringlist {
|
||||||
struct s_stringlist *next;
|
char **data;
|
||||||
char *line;
|
char **strings;
|
||||||
|
int length;
|
||||||
|
int size;
|
||||||
} stringlist;
|
} stringlist;
|
||||||
|
|
||||||
typedef struct s_stringpair {
|
typedef struct s_stringpair {
|
||||||
|
@ -135,71 +135,70 @@ static int delete_stringpair(stringpair *root,stringpair *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----- string list functions ----------------------------------- */
|
/* ----- string list functions ----------------------------------- */
|
||||||
static stringlist *insert_string(stringlist *root,char *string)
|
static stringlist *insert_string(stringlist *list,char *string)
|
||||||
{
|
{
|
||||||
stringlist *cur;
|
stringlist newlist;
|
||||||
|
|
||||||
|
assert(list!=NULL);
|
||||||
assert(string!=NULL);
|
assert(string!=NULL);
|
||||||
if ((cur=(stringlist*)malloc(sizeof(stringlist)))==NULL)
|
if (list->data==NULL) {
|
||||||
error(103); /* insufficient memory (fatal error) */
|
/* inserted for the first time */
|
||||||
if ((cur->line=duplicatestring(string))==NULL)
|
newlist.length=0;
|
||||||
error(103); /* insufficient memory (fatal error) */
|
newlist.size=2;
|
||||||
/* insert as "last" */
|
newlist.data=calloc(newlist.size,sizeof(char*));
|
||||||
assert(root!=NULL);
|
newlist.strings=newlist.data;
|
||||||
while (root->next!=NULL)
|
if (newlist.data==NULL)
|
||||||
root=root->next;
|
error(103); /* insufficient memory (fatal error) */
|
||||||
cur->next=root->next;
|
*list=newlist;
|
||||||
root->next=cur;
|
} else if (list->length==list->size ||
|
||||||
return cur;
|
list->length==list->data+list->size-list->strings) {
|
||||||
|
/* allocate more elements */
|
||||||
|
newlist.length=list->length;
|
||||||
|
newlist.size=list->size+list->size/2;
|
||||||
|
newlist.data=realloc(list->data,newlist.size*sizeof(char*));
|
||||||
|
newlist.strings=newlist.data+(list->strings-list->data);
|
||||||
|
if (newlist.data==NULL)
|
||||||
|
error(103); /* insufficient memory (fatal error) */
|
||||||
|
memset(newlist.data+list->size,0,list->size/2*sizeof(char*));
|
||||||
|
*list=newlist;
|
||||||
|
} /* if */
|
||||||
|
if ((list->strings[list->length]=duplicatestring(string))==NULL)
|
||||||
|
error(103); /* insufficient memory (fatal error) */
|
||||||
|
list->length++;
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_string(stringlist *root,int index)
|
static char *get_string(stringlist *list,int index)
|
||||||
{
|
{
|
||||||
stringlist *cur;
|
assert(list!=NULL);
|
||||||
|
if (index>=0 && index<list->size)
|
||||||
assert(root!=NULL);
|
return list->strings[index];
|
||||||
cur=root->next;
|
|
||||||
while (cur!=NULL && index-->0)
|
|
||||||
cur=cur->next;
|
|
||||||
if (cur!=NULL) {
|
|
||||||
assert(cur->line!=NULL);
|
|
||||||
return cur->line;
|
|
||||||
} /* if */
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int delete_string(stringlist *root,int index)
|
static int delete_string(stringlist *list,int index)
|
||||||
{
|
{
|
||||||
stringlist *cur,*item;
|
assert(list!=NULL);
|
||||||
|
assert(index==0);
|
||||||
assert(root!=NULL);
|
if (list->length>0) {
|
||||||
for (cur=root; cur->next!=NULL && index>0; cur=cur->next,index--)
|
free(list->strings[0]);
|
||||||
/* nothing */;
|
list->strings[0]=NULL;
|
||||||
if (cur->next!=NULL) {
|
list->strings++;
|
||||||
item=cur->next;
|
list->length--;
|
||||||
cur->next=item->next; /* unlink from list */
|
|
||||||
assert(item->line!=NULL);
|
|
||||||
free(item->line);
|
|
||||||
free(item);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} /* if */
|
} /* if */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_FUNC void delete_stringtable(stringlist *root)
|
SC_FUNC void delete_stringtable(stringlist *list)
|
||||||
{
|
{
|
||||||
stringlist *cur,*next;
|
int i;
|
||||||
|
|
||||||
assert(root!=NULL);
|
assert(list!=NULL);
|
||||||
cur=root->next;
|
for (i=0; i<list->size; i++)
|
||||||
while (cur!=NULL) {
|
free(list->data[i]);
|
||||||
next=cur->next;
|
free(list->data);
|
||||||
assert(cur->line!=NULL);
|
memset(list,0,sizeof(stringlist));
|
||||||
free(cur->line);
|
|
||||||
free(cur);
|
|
||||||
cur=next;
|
|
||||||
} /* while */
|
|
||||||
memset(root,0,sizeof(stringlist));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -235,7 +234,7 @@ SC_FUNC void delete_aliastable(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----- include paths list -------------------------------------- */
|
/* ----- include paths list -------------------------------------- */
|
||||||
static stringlist includepaths = {NULL, NULL}; /* directory list for include files */
|
static stringlist includepaths = {NULL, NULL, 0, 0}; /* directory list for include files */
|
||||||
|
|
||||||
SC_FUNC stringlist *insert_path(char *path)
|
SC_FUNC stringlist *insert_path(char *path)
|
||||||
{
|
{
|
||||||
@ -250,7 +249,7 @@ SC_FUNC char *get_path(int index)
|
|||||||
SC_FUNC void delete_pathtable(void)
|
SC_FUNC void delete_pathtable(void)
|
||||||
{
|
{
|
||||||
delete_stringtable(&includepaths);
|
delete_stringtable(&includepaths);
|
||||||
assert(includepaths.next==NULL);
|
assert(includepaths.strings==NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -323,7 +322,7 @@ SC_FUNC void delete_substtable(void)
|
|||||||
|
|
||||||
|
|
||||||
/* ----- input file list ----------------------------------------- */
|
/* ----- input file list ----------------------------------------- */
|
||||||
static stringlist sourcefiles = {NULL, NULL};
|
static stringlist sourcefiles = {NULL, NULL, 0, 0};
|
||||||
|
|
||||||
SC_FUNC stringlist *insert_sourcefile(char *string)
|
SC_FUNC stringlist *insert_sourcefile(char *string)
|
||||||
{
|
{
|
||||||
@ -338,13 +337,13 @@ SC_FUNC char *get_sourcefile(int index)
|
|||||||
SC_FUNC void delete_sourcefiletable(void)
|
SC_FUNC void delete_sourcefiletable(void)
|
||||||
{
|
{
|
||||||
delete_stringtable(&sourcefiles);
|
delete_stringtable(&sourcefiles);
|
||||||
assert(sourcefiles.next==NULL);
|
assert(sourcefiles.strings==NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----- documentation tags -------------------------------------- */
|
/* ----- documentation tags -------------------------------------- */
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
static stringlist docstrings = {NULL, NULL};
|
static stringlist docstrings = {NULL, NULL, 0, 0};
|
||||||
|
|
||||||
SC_FUNC stringlist *insert_docstring(char *string)
|
SC_FUNC stringlist *insert_docstring(char *string)
|
||||||
{
|
{
|
||||||
@ -358,19 +357,20 @@ SC_FUNC char *get_docstring(int index)
|
|||||||
|
|
||||||
SC_FUNC void delete_docstring(int index)
|
SC_FUNC void delete_docstring(int index)
|
||||||
{
|
{
|
||||||
delete_string(&docstrings,index);
|
assert(index==0);
|
||||||
|
delete_string(&docstrings, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_FUNC void delete_docstringtable(void)
|
SC_FUNC void delete_docstringtable(void)
|
||||||
{
|
{
|
||||||
delete_stringtable(&docstrings);
|
delete_stringtable(&docstrings);
|
||||||
assert(docstrings.next==NULL);
|
assert(docstrings.strings==NULL);
|
||||||
}
|
}
|
||||||
#endif /* !defined SC_LIGHT */
|
#endif /* !defined SC_LIGHT */
|
||||||
|
|
||||||
|
|
||||||
/* ----- autolisting --------------------------------------------- */
|
/* ----- autolisting --------------------------------------------- */
|
||||||
static stringlist autolist = {NULL, NULL};
|
static stringlist autolist = {NULL, NULL, 0, 0};
|
||||||
|
|
||||||
SC_FUNC stringlist *insert_autolist(char *string)
|
SC_FUNC stringlist *insert_autolist(char *string)
|
||||||
{
|
{
|
||||||
@ -385,7 +385,7 @@ SC_FUNC char *get_autolist(int index)
|
|||||||
SC_FUNC void delete_autolisttable(void)
|
SC_FUNC void delete_autolisttable(void)
|
||||||
{
|
{
|
||||||
delete_stringtable(&autolist);
|
delete_stringtable(&autolist);
|
||||||
assert(autolist.next==NULL);
|
assert(autolist.strings==NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -462,11 +462,10 @@ SC_FUNC void delete_heaplisttable(void)
|
|||||||
#define PRIxC "x"
|
#define PRIxC "x"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static stringlist dbgstrings = {NULL, NULL};
|
static stringlist dbgstrings = {NULL, NULL, 0, 0};
|
||||||
|
|
||||||
SC_FUNC stringlist *insert_dbgfile(const char *filename)
|
SC_FUNC stringlist *insert_dbgfile(const char *filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) {
|
if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) {
|
||||||
char string[_MAX_PATH+40];
|
char string[_MAX_PATH+40];
|
||||||
assert(filename!=NULL);
|
assert(filename!=NULL);
|
||||||
@ -530,5 +529,5 @@ SC_FUNC char *get_dbgstring(int index)
|
|||||||
SC_FUNC void delete_dbgstringtable(void)
|
SC_FUNC void delete_dbgstringtable(void)
|
||||||
{
|
{
|
||||||
delete_stringtable(&dbgstrings);
|
delete_stringtable(&dbgstrings);
|
||||||
assert(dbgstrings.next==NULL);
|
assert(dbgstrings.strings==NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user