code cleanup: fsmenu.c names were confusing - fsms / fsme / prev --> fsm_head / fsm_iter / fsm_prev

This commit is contained in:
Campbell Barton 2012-09-17 04:29:43 +00:00
parent 00c37e1ff6
commit 13918dffd2

@ -97,87 +97,89 @@ FSMenu *fsmenu_get(void)
static FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category) static FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category)
{ {
FSMenuEntry *fsms = NULL; FSMenuEntry *fsm_head = NULL;
switch (category) { switch (category) {
case FS_CATEGORY_SYSTEM: case FS_CATEGORY_SYSTEM:
fsms = fsmenu->fsmenu_system; fsm_head = fsmenu->fsmenu_system;
break; break;
case FS_CATEGORY_BOOKMARKS: case FS_CATEGORY_BOOKMARKS:
fsms = fsmenu->fsmenu_bookmarks; fsm_head = fsmenu->fsmenu_bookmarks;
break; break;
case FS_CATEGORY_RECENT: case FS_CATEGORY_RECENT:
fsms = fsmenu->fsmenu_recent; fsm_head = fsmenu->fsmenu_recent;
break; break;
} }
return fsms; return fsm_head;
} }
static void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsms) static void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head)
{ {
switch (category) { switch (category) {
case FS_CATEGORY_SYSTEM: case FS_CATEGORY_SYSTEM:
fsmenu->fsmenu_system = fsms; fsmenu->fsmenu_system = fsm_head;
break; break;
case FS_CATEGORY_BOOKMARKS: case FS_CATEGORY_BOOKMARKS:
fsmenu->fsmenu_bookmarks = fsms; fsmenu->fsmenu_bookmarks = fsm_head;
break; break;
case FS_CATEGORY_RECENT: case FS_CATEGORY_RECENT:
fsmenu->fsmenu_recent = fsms; fsmenu->fsmenu_recent = fsm_head;
break; break;
} }
} }
int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category) int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category)
{ {
FSMenuEntry *fsme; FSMenuEntry *fsm_iter;
int count = 0; int count = 0;
for (fsme = fsmenu_get_category(fsmenu, category); fsme; fsme = fsme->next) for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter; fsm_iter = fsm_iter->next) {
count++; count++;
}
return count; return count;
} }
char *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx) char *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
{ {
FSMenuEntry *fsme; FSMenuEntry *fsm_iter;
for (fsme = fsmenu_get_category(fsmenu, category); fsme && idx; fsme = fsme->next) for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) {
idx--; idx--;
}
return fsme ? fsme->path : NULL; return fsm_iter ? fsm_iter->path : NULL;
} }
short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx) short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
{ {
FSMenuEntry *fsme; FSMenuEntry *fsm_iter;
for (fsme = fsmenu_get_category(fsmenu, category); fsme && idx; fsme = fsme->next) for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) {
idx--; idx--;
}
return fsme ? fsme->save : 0; return fsm_iter ? fsm_iter->save : 0;
} }
void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, FSMenuInsert flag) void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, FSMenuInsert flag)
{ {
FSMenuEntry *prev; FSMenuEntry *fsm_prev;
FSMenuEntry *fsme; FSMenuEntry *fsm_iter;
FSMenuEntry *fsms; FSMenuEntry *fsm_head;
FSMenuEntry *fsms_first;
fsms = fsmenu_get_category(fsmenu, category); fsm_head = fsmenu_get_category(fsmenu, category);
prev = fsme = fsms_first = fsms; fsm_prev = fsm_head; /* this is odd and not really correct? */
for (; fsme; prev = fsme, fsme = fsme->next) { for (fsm_iter = fsm_head; fsm_iter; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) {
if (fsme->path) { if (fsm_iter->path) {
const int cmp_ret = BLI_path_cmp(path, fsme->path); const int cmp_ret = BLI_path_cmp(path, fsm_iter->path);
if (cmp_ret == 0) { if (cmp_ret == 0) {
if (FS_INSERT_FIRST) { if (FS_INSERT_FIRST) {
if (fsme != fsms_first) { if (fsm_iter != fsm_head) {
prev->next = fsme->next; fsm_prev->next = fsm_iter->next;
fsme->next = fsms_first; fsm_iter->next = fsm_head;
fsmenu_set_category(fsmenu, category, fsme); fsmenu_set_category(fsmenu, category, fsm_iter);
} }
} }
return; return;
@ -196,72 +198,75 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c
} }
} }
fsme = MEM_mallocN(sizeof(*fsme), "fsme"); fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme");
fsme->path = BLI_strdup(path); fsm_iter->path = BLI_strdup(path);
fsme->save = (flag & FS_INSERT_SAVE) != 0; fsm_iter->save = (flag & FS_INSERT_SAVE) != 0;
if (prev) { if (fsm_prev) {
fsme->next = prev->next; fsm_iter->next = fsm_prev->next;
prev->next = fsme; fsm_prev->next = fsm_iter;
} }
else { else {
fsme->next = fsms; fsm_iter->next = fsm_head;
fsmenu_set_category(fsmenu, category, fsme); fsmenu_set_category(fsmenu, category, fsm_iter);
} }
} }
void fsmenu_remove_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx) void fsmenu_remove_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
{ {
FSMenuEntry *prev = NULL, *fsme = NULL; FSMenuEntry *fsm_prev = NULL;
FSMenuEntry *fsms = fsmenu_get_category(fsmenu, category); FSMenuEntry *fsm_iter;
FSMenuEntry *fsm_head;
for (fsme = fsms; fsme && idx; prev = fsme, fsme = fsme->next) fsm_head = fsmenu_get_category(fsmenu, category);
for (fsm_iter = fsm_head; fsm_iter && idx; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next)
idx--; idx--;
if (fsme) { if (fsm_iter) {
/* you should only be able to remove entries that were /* you should only be able to remove entries that were
* not added by default, like windows drives. * not added by default, like windows drives.
* also separators (where path == NULL) shouldn't be removed */ * also separators (where path == NULL) shouldn't be removed */
if (fsme->save && fsme->path) { if (fsm_iter->save && fsm_iter->path) {
/* remove fsme from list */ /* remove fsme from list */
if (prev) { if (fsm_prev) {
prev->next = fsme->next; fsm_prev->next = fsm_iter->next;
} }
else { else {
fsms = fsme->next; fsm_head = fsm_iter->next;
fsmenu_set_category(fsmenu, category, fsms); fsmenu_set_category(fsmenu, category, fsm_head);
} }
/* free entry */ /* free entry */
MEM_freeN(fsme->path); MEM_freeN(fsm_iter->path);
MEM_freeN(fsme); MEM_freeN(fsm_iter);
} }
} }
} }
void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename) void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename)
{ {
FSMenuEntry *fsme = NULL; FSMenuEntry *fsm_iter = NULL;
int nskip = 0; int nskip = 0;
FILE *fp = BLI_fopen(filename, "w"); FILE *fp = BLI_fopen(filename, "w");
if (!fp) return; if (!fp) return;
fprintf(fp, "[Bookmarks]\n"); fprintf(fp, "[Bookmarks]\n");
for (fsme = fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsme; fsme = fsme->next) { for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsm_iter; fsm_iter = fsm_iter->next) {
if (fsme->path && fsme->save) { if (fsm_iter->path && fsm_iter->save) {
fprintf(fp, "%s\n", fsme->path); fprintf(fp, "%s\n", fsm_iter->path);
} }
} }
fprintf(fp, "[Recent]\n"); fprintf(fp, "[Recent]\n");
nskip = fsmenu_get_nentries(fsmenu, FS_CATEGORY_RECENT) - FSMENU_RECENT_MAX; nskip = fsmenu_get_nentries(fsmenu, FS_CATEGORY_RECENT) - FSMENU_RECENT_MAX;
/* skip first entries if list too long */ /* skip first entries if list too long */
for (fsme = fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsme && (nskip > 0); fsme = fsme->next, --nskip) { for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsm_iter && (nskip > 0); fsm_iter = fsm_iter->next, --nskip) {
/* pass */ /* pass */
} }
for (; fsme; fsme = fsme->next) { for (; fsm_iter; fsm_iter = fsm_iter->next) {
if (fsme->path && fsme->save) { if (fsm_iter->path && fsm_iter->save) {
fprintf(fp, "%s\n", fsme->path); fprintf(fp, "%s\n", fsm_iter->path);
} }
} }
fclose(fp); fclose(fp);
@ -539,15 +544,17 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
static void fsmenu_free_category(struct FSMenu *fsmenu, FSMenuCategory category) static void fsmenu_free_category(struct FSMenu *fsmenu, FSMenuCategory category)
{ {
FSMenuEntry *fsme = fsmenu_get_category(fsmenu, category); FSMenuEntry *fsm_iter = fsmenu_get_category(fsmenu, category);
while (fsme) { while (fsm_iter) {
FSMenuEntry *n = fsme->next; FSMenuEntry *fsm_next = fsm_iter->next;
if (fsme->path) MEM_freeN(fsme->path); if (fsm_iter->path) {
MEM_freeN(fsme); MEM_freeN(fsm_iter->path);
}
MEM_freeN(fsm_iter);
fsme = n; fsm_iter = fsm_next;
} }
} }