Project Homepage | Sourceforge Page | CVS Repository | Freshmeat.net Page | Download project | Author's Homepage |
Definition in file comboHandlers.h.
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
command line lengths | |
Figure out the maximum command line lengths for the current shell | |
#define | RF_LINE_MAX_LEN 1026 |
use a standard line length | |
Functions | |
void | freeList (GList *list) |
free a GList object and all it's members | |
GList * | readHistory (GList *list, char *filename) |
read a history file | |
int | writeHistory (char *command, char *filename) |
write to a history file (append) |
|
use a standard line length
Definition at line 46 of file comboHandlers.h. Referenced by readHistory(). |
|
free a GList object and all it's members
Definition at line 176 of file comboHandlers.c. Referenced by main(), and on_mainWindow_destroy().
00177 { 00178 int i =0; 00179 for(; i < (int)g_list_length(list); i++, list = list->next) 00180 g_free(list->data); 00181 00182 g_list_free(list); 00183 } |
|
read a history file
Definition at line 57 of file comboHandlers.c. References dprint, history_len, and RF_LINE_MAX_LEN. Referenced by combo_init().
00058 { 00059 FILE *fp; 00060 00061 /** \warning This caused alot of headeache. In the first place, gtk 00062 GList operations are not intuitive at all. In the end it was 00063 discovered that, because the values of the glist are pointers, 00064 that we must use a persistant glist to populate our target 00065 glist. What this means is that we end up passing in and returning 00066 the same pointer (not the same address) in order to properly 00067 populate our GList. 00068 */ 00069 00070 //grab the environment $HOME directory 00071 //TODO 00072 if( (fp = fopen(filename, "a+") ) == NULL) 00073 { 00074 dprint("run-free: bash_history file not found"); 00075 00076 /**\todo 00077 we are not handling file operations properly here -I was 00078 probably tired and lazy at the time. This MUST be fixed in 00079 the near future! 00080 */ 00081 00082 //ok, try a different file 00083 //TODO 00084 //else pop up a dialog 00085 g_print("could not open history file\n"); 00086 } 00087 00088 //max line length is the system max (this could be huge!) 00089 char line[RF_LINE_MAX_LEN+1]; 00090 int c; 00091 int i =0, numItems =0; 00092 //char *string; 00093 00094 memset(line, '\0', sizeof(line)); 00095 00096 do 00097 { 00098 if( (c = fgetc(fp)) == EOF) 00099 { 00100 //dprint("end of file\n"); 00101 break; 00102 } 00103 if(c != '\n') 00104 { 00105 if(i >= RF_LINE_MAX_LEN) 00106 dprint("HISTORY LINE LEN TOO LONG!\n"); 00107 00108 line[i] = c; 00109 i++; 00110 continue; 00111 } 00112 else 00113 { 00114 i=0; 00115 if(strcmp(line, "\n") == 0) 00116 { 00117 memset(line, '\0', sizeof(line)); 00118 continue; 00119 } 00120 } 00121 00122 list = g_list_prepend(list, strdup(line)); 00123 numItems++; 00124 00125 memset(line, '\0', sizeof(line)); 00126 }while(1); 00127 00128 fclose(fp); 00129 00130 //list = g_list_reverse(list); 00131 00132 //eliminate duplicates 00133 GList *newList = NULL; 00134 00135 i=0; 00136 00137 //this is how we set the combo box length 00138 //int loop_num = RF_MAX_HISTLIST_LEN-1; 00139 int loop_num = history_len -1; 00140 00141 //weed out duplicates and only keep the first instance of a history 00142 //line 00143 for(;i < loop_num && (list != NULL); i++, 00144 list = g_list_next(list)) 00145 { 00146 00147 //see if we've seen this one before 00148 if(g_list_find_custom(newList, list->data, 00149 (GCompareFunc)strcmp) == NULL) 00150 { 00151 //put the old command in the combo box 00152 newList = g_list_append(newList, (char *)list->data); 00153 } 00154 else 00155 { 00156 //increase the number of loops we're going to try and 00157 // grab the next one (unless NULL happens on next) 00158 ++loop_num; 00159 } 00160 }//end for 00161 00162 newList = g_list_prepend(newList, ""); 00163 return(newList); 00164 } |
|
write to a history file (append)
Definition at line 198 of file comboHandlers.c. References command. Referenced by on_combo_entry1_key_press_event(), on_runButton_clicked(), and run_command().
00199 { 00200 //always writes to the end of the file 00201 00202 FILE *fp; 00203 int retval = 0; 00204 int wLen = 0; 00205 00206 00207 fp = fopen(filename, "a+"); 00208 if(fp == NULL) 00209 { 00210 /**\todo FIX THIS I'm not handling file operations properly 00211 -probably tired at the time... -parasyte. 00212 */ 00213 //display dialog 00214 } 00215 00216 //write command line to file 00217 if((wLen = fputs(command, fp)) > 0) 00218 { 00219 retval = -1; 00220 } 00221 //else write a new line 00222 fputs("\n", fp); 00223 00224 fclose(fp); // close file 00225 00226 return retval; 00227 } |