int main(int argc, char **argv) { char revision[16]; int i; str_list_t list; sscanf("$Revision: 1.30 $", "%*s %s", revision); printf("\nFIXSMB v2.10-%s (rev %s) SMBLIB %s - Rebuild Synchronet Message Base\n\n" ,PLATFORM_DESC,revision,smb_lib_ver()); list=strListInit(); for(i=1;i<argc;i++) { if(argv[i][0]=='-') { if(!stricmp(argv[i],"-renumber")) renumber=TRUE; } else strListPush(&list,argv[i]); } if(!strListCount(list)) { printf(usage); exit(1); } atexit(unlock_msgbase); for(i=0;list[i]!=NULL;i++) fixsmb(list[i]); return(0); }
static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_len) { char* buf=NULL; size_t count; str_list_t list; if(max_line_len<1) max_line_len=2048; if(lp==NULL) { if((list = strListInit())==NULL) return(NULL); lp=&list; } if(fp!=NULL) { count=strListCount(*lp); while(!feof(fp)) { if(buf==NULL && (buf=(char*)malloc(max_line_len+1))==NULL) return(NULL); if(fgets(buf,max_line_len+1,fp)==NULL) break; strListAppend(lp, buf, count++); } } if(buf) free(buf); return(*lp); }
str_list_t* dataParseList(const str_list_t records, str_list_t* columns, dataLineParser_t lineParser) { size_t ri=0; size_t li=0; str_list_t* list; if(records==NULL) return(NULL); if((list=(str_list_t*)malloc(sizeof(str_list_t)*(strListCount(records)+1)))==NULL) return(NULL); if(columns!=NULL) { if((*columns=lineParser(records[ri++]))==NULL) { free(list); return(NULL); } } while(records[ri]!=NULL) list[li++]=lineParser(records[ri++]); list[li]=NULL; /* terminate */ return(list); }
char* strListRemove(str_list_t* list, size_t index) { char* str; size_t i; size_t count; str_list_t lp; count = strListCount(*list); if(index==STR_LIST_LAST_INDEX && count) index = count-1; if(index >= count) /* invalid index, do nothing */ return(NULL); count--; if((lp=(str_list_t)realloc(*list,sizeof(char*)*(count+1)))==NULL) return(NULL); *list=lp; str=lp[index]; for(i=index; i<count; i++) lp[i]=lp[i+1]; lp[count]=NULL; return(str); }
size_t strListMerge(str_list_t* list, str_list_t add_list) { size_t i; size_t count; count=strListCount(*list); for(i=0; add_list[i]!=NULL; i++) str_list_append(list,add_list[i],count++); return(i); }
size_t strListAppendList(str_list_t* list, const str_list_t add_list) { size_t i; size_t count; count=strListCount(*list); for(i=0; add_list[i]!=NULL; i++) strListAppend(list,add_list[i],count++); return(count); }
char* strListAppend(str_list_t* list, const char* str, size_t index) { char* buf; if(str==NULL) return(NULL); if((buf=strdup(str))==NULL) return(NULL); if(index==STR_LIST_LAST_INDEX) index=strListCount(*list); return(str_list_append(list,buf,index)); }
BOOL dataWriteFile(FILE* fp, const str_list_t records[], const str_list_t columns, const char* separator ,dataLineCreator_t lineCreator) { size_t count,total; str_list_t list; rewind(fp); if(chsize(fileno(fp),0)!=0) /* truncate */ return(FALSE); if((list=dataCreateList(records,columns,lineCreator))==NULL) return(FALSE); total = strListCount(list); count = strListWriteFile(fp,list,separator); strListFree(&list); return(count == total); }
static char* str_list_insert(str_list_t* list, char* str, size_t index) { size_t i; size_t count; str_list_t lp; count = strListCount(*list); if(index > count) /* invalid index, do nothing */ return(NULL); count++; if((lp=(str_list_t)realloc(*list,sizeof(char*)*(count+1)))==NULL) return(NULL); *list=lp; for(i=count; i>index; i--) lp[i]=lp[i-1]; lp[index]=str; return(str); }
BOOL strListSwap(const str_list_t list, size_t index1, size_t index2) { char* tmp; size_t count; count = strListCount(list); if(index1==STR_LIST_LAST_INDEX && count) index1 = count-1; if(index2==STR_LIST_LAST_INDEX && count) index2 = count-1; if(index1 >= count || index2 >= count || index1 == index2) return(FALSE); /* invalid index, do nothing */ tmp=list[index1]; list[index1]=list[index2]; list[index2]=tmp; return(TRUE); }
str_list_t strListSplit(str_list_t* lp, char* str, const char* delimit) { size_t count; char* token; char* tmp; str_list_t list; if(str==NULL || delimit==NULL) return(NULL); if(lp==NULL) { if((list = strListInit())==NULL) return(NULL); lp=&list; count=0; } else count=strListCount(*lp); for(token = strtok_r(str, delimit, &tmp); token!=NULL; token=strtok_r(NULL, delimit, &tmp)) if(strListAppend(lp, token, count++)==NULL) break; return(*lp); }
char* strListReplace(const str_list_t list, size_t index, const char* str) { char* buf; size_t count; if(str==NULL) return(NULL); count = strListCount(list); if(index==STR_LIST_LAST_INDEX && count) index = count-1; if(index >= count) /* invalid index, do nothing */ return(NULL); if((buf=(char*)realloc(list[index],strlen(str)+1))==NULL) return(NULL); list[index]=buf; strcpy(buf,str); return(buf); }
void strListSortAlphaCaseReverse(str_list_t list) { qsort(list,strListCount(list),sizeof(char*),strListCompareAlphaCaseReverse); }
void strListSortAlpha(str_list_t list) { qsort(list,strListCount(list),sizeof(char*),strListCompareAlpha); }