#include "filelist.h"
Go to the source code of this file.
Functions | |
static filelist_t * | filelist_new (void) |
static void | filelist_free (filelist_t *flist) |
static void | filelist_add (filelist_t *flist, char *filename) |
static void | filelist_addout (filelist_t *flist, char *desc) |
static void | filelist_idxshow (filelist_t *flist, int idx) |
static void | filelist_qsort (filelist_t *flist, int l, int r) |
static void | filelist_sort (filelist_t *flist) |
static void filelist_add | ( | filelist_t * | flist, | |
char * | filename | |||
) | [static] |
Definition at line 57 of file filelist.c.
References filelist_t::elements, FILELIST_LE, nmalloc, nrealloc, NULL, and filelist_t::tot.
Referenced by filedb_ls().
00058 { 00059 flist->tot++; 00060 flist->elements = nrealloc(flist->elements, flist->tot * sizeof(filelist_t)); 00061 FILELIST_LE(flist).fn = nmalloc(strlen(filename) + 1); 00062 strcpy(FILELIST_LE(flist).fn, filename); 00063 FILELIST_LE(flist).output = NULL; 00064 }
static void filelist_addout | ( | filelist_t * | flist, | |
char * | desc | |||
) | [static] |
Definition at line 68 of file filelist.c.
References FILELIST_LE, nmalloc, and nrealloc.
Referenced by filedb_ls().
00069 { 00070 if (FILELIST_LE(flist).output) { 00071 FILELIST_LE(flist).output = nrealloc(FILELIST_LE(flist).output, 00072 strlen(FILELIST_LE(flist).output) + 00073 strlen(desc) + 1); 00074 strcat(FILELIST_LE(flist).output, desc); 00075 } else { 00076 FILELIST_LE(flist).output = nmalloc(strlen(desc) + 1); 00077 strcpy(FILELIST_LE(flist).output, desc); 00078 } 00079 }
static void filelist_free | ( | filelist_t * | flist | ) | [static] |
Definition at line 39 of file filelist.c.
References filelist_t::elements, filelist_element_t::fn, my_free, filelist_element_t::output, and filelist_t::tot.
Referenced by filedb_ls().
00040 { 00041 int i; 00042 00043 if (!flist) 00044 return; 00045 for (i = 0; i < flist->tot; i++) { 00046 if (flist->elements[i].output) 00047 my_free(flist->elements[i].output); 00048 my_free(flist->elements[i].fn); 00049 } 00050 if (flist->elements) 00051 my_free(flist->elements); 00052 my_free(flist); 00053 }
static void filelist_idxshow | ( | filelist_t * | flist, | |
int | idx | |||
) | [inline, static] |
Definition at line 82 of file filelist.c.
References dprintf, filelist_t::elements, filelist_element_t::output, and filelist_t::tot.
Referenced by filedb_ls().
00083 { 00084 int i; 00085 00086 for (i = 0; i < flist->tot; i++) 00087 dprintf(idx, "%s", flist->elements[i].output); 00088 }
static filelist_t* filelist_new | ( | void | ) | [static] |
Definition at line 29 of file filelist.c.
References filelist_t::elements, nmalloc, NULL, and filelist_t::tot.
Referenced by filedb_ls().
00030 { 00031 filelist_t *flist; 00032 00033 flist = nmalloc(sizeof(filelist_t)); 00034 flist->tot = 0; 00035 flist->elements = NULL; 00036 return flist; 00037 }
static void filelist_qsort | ( | filelist_t * | flist, | |
int | l, | |||
int | r | |||
) | [static] |
Definition at line 93 of file filelist.c.
References filelist_t::elements, filelist_element_t::fn, and filelist_element_t::output.
Referenced by filelist_sort().
00094 { 00095 int i = l, j = r, middle; 00096 filelist_element_t *el = flist->elements, elt; 00097 00098 middle = ((l + r) / 2); 00099 do { 00100 while (strcmp(el[i].fn, el[middle].fn) < 0) 00101 i++; 00102 while (strcmp(el[j].fn, el[middle].fn) > 0) 00103 j--; 00104 if (i <= j) { 00105 if (strcmp(el[j].fn, el[i].fn)) { 00106 elt.fn = el[j].fn; 00107 elt.output = el[j].output; 00108 el[j].fn = el[i].fn; 00109 el[j].output = el[i].output; 00110 el[i].fn = elt.fn; 00111 el[i].output = elt.output; 00112 } 00113 i++; 00114 j--; 00115 } 00116 } while (i <= j); 00117 if (l < j) 00118 filelist_qsort(flist, l, j); 00119 if (i < r) 00120 filelist_qsort(flist, i, r); 00121 }
static void filelist_sort | ( | filelist_t * | flist | ) | [static] |
Definition at line 125 of file filelist.c.
References filelist_qsort(), and filelist_t::tot.
Referenced by filedb_ls().
00126 { 00127 if (flist->tot < 2) 00128 return; 00129 filelist_qsort(flist, 0, (flist->tot - 1)); 00130 }