Changeset 10647 for trunk/Ohana/src/opihi/lib.shell/ListOps.c
- Timestamp:
- Dec 11, 2006, 10:15:41 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/ListOps.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/ListOps.c
r4763 r10647 1 1 # include "opihi.h" 2 2 # include "macro.h" 3 4 /*** local static variables used to track the command lists ***/ 5 static List *lists; /* variable to store the list of all lists */ 6 static int Nlists; /* number of currently available lists */ 3 7 4 8 void InitLists () { … … 8 12 } 9 13 14 int current_list_depth () { 15 return Nlists; 16 } 17 18 int increase_list_depth () { 19 Nlists ++; 20 REALLOCATE (lists, List, MAX (Nlists + 1, 0) + 1); 21 ALLOCATE (lists[Nlists].line, char *, 16); 22 lists[Nlists].Nalloc = 16; 23 lists[Nlists].Nlines = 0; 24 lists[Nlists].n = 0; 25 return Nlists; 26 } 27 28 int decrease_list_depth () { 29 30 int i; 31 32 for (i = 0; i < lists[Nlists].Nlines; i++) { 33 free (lists[Nlists].line[i]); 34 } 35 free (lists[Nlists].line); 36 Nlists --; 37 REALLOCATE (lists, List, MAX (Nlists + 1, 0) + 1); 38 return Nlists; 39 } 40 10 41 /* return a new string consisting of the next line in the current list */ 11 42 char *get_next_listentry (int ThisList) { 12 43 44 int Nline; 13 45 char *output; 14 46 15 lists[ThisList].n++;16 17 if ( lists[ThisList].n >= lists[Nlists].Nlines)18 return ((char *) NULL); 19 20 output = lists[Nlists].line[lists[ThisList].n];47 Nline = lists[ThisList].n; 48 49 if (Nline >= lists[ThisList].Nlines) return (NULL); 50 51 output = strcreate (lists[ThisList].line[Nline]); 52 lists[ThisList].n ++; 21 53 22 54 return (output); 23 24 } 25 55 } 56 57 # if (0) 26 58 char *remove_listentry (int current) { 27 59 … … 41 73 return (output); 42 74 75 } 76 # endif 77 78 int add_listentry (int ThisList, char *line) { 79 80 int Nlines; 81 char *output; 82 83 Nlines = lists[ThisList].Nlines; 84 lists[ThisList].line[Nlines] = strcreate (line); 85 lists[ThisList].Nlines ++; 86 87 if (lists[ThisList].Nlines == lists[ThisList].Nalloc) { 88 lists[ThisList].Nalloc += 16; 89 REALLOCATE (lists[ThisList].line, char *, lists[ThisList].Nalloc); 90 } 91 92 return (lists[ThisList].Nlines); 43 93 } 44 94
Note:
See TracChangeset
for help on using the changeset viewer.
