void on_logentry_edit_clicked(GtkButton *button, gpointer user_data) { log_search(); gtk_widget_hide(Wsearchlogentr); if (actlog == 0) { return; } if (log_on == 0) { gtk_widget_show(wqsoeditor); } log_set(actlog); display_status("log entry loaded, You can edit it!"); }
void on_qso_clear_clicked (GtkButton *button, gpointer user_data) { log_search(); if (actlog > 0) { log_delete_entry(actlog); log_shift_entries(actlog); actlog = 0; log_set(0); display_status("log entry cleared."); log_store(); } else { log_set(0); display_status("nothing changed in log."); } gtk_widget_hide(wqsoeditor); }
int main() { log_t l; log_init(&l); int i; log_append(&l,"Iddd am a genius"); log_append(&l,"2"); log_append(&l, "ab 1"); log_append(&l, "a 2"); log_append(&l, "abc 3"); log_append(&l, "ab 4"); log_append(&l, "a 5"); printf("search: %s\n",log_search(&l,"a")); printf("pop: %s\n",log_pop(&l)); printf("search: %s\n",log_search(&l,"a")); printf("search: %s\n",log_search(&l,"ab")); printf("pop: %s\n",log_pop(&l)); printf("search: %s\n",log_search(&l,"ab")); printf("search: %s\n",log_search(&l,"abc")); for(i=0;i<1024*1024*100;++i){ log_append(&l,"I am a genius"); } printf("size: %ul \n",log_size(&l)); printf("search: %s\n",log_search(&l,"I am")); for(i=0;i<1024*1024;++i){ log_pop(&l); } printf("size: %u \n",log_size(&l)); printf("search: %s\n",log_search(&l,"I am")); log_destroy(&l); return 0; }
void on_logentry_clear_clicked (GtkButton *button, gpointer user_data) { log_search(); gtk_widget_hide(Wsearchlogentr); if (actlog == 0) //only clear window { log_set(0); display_status("entry was not yet stored, only mask cleared."); return; } else { log_delete_entry(actlog); log_shift_entries(actlog); actlog = 0; log_set(0); display_status("log entry cleared."); log_store(); } }
int main() { log_t l; log_init(&l); printf("\nTesting log_append():\n"); log_append(&l, "ab 1"); log_append(&l, "a 2"); log_append(&l, "abc 3"); log_append(&l, "ab 4"); log_append(&l, "a 5"); printf("0: '%s'\n",log_at(&l, 0)); printf("1: '%s'\n",log_at(&l, 1)); printf("2: '%s'\n",log_at(&l, 2)); printf("3: '%s'\n",log_at(&l, 3)); printf("4: '%s'\n",log_at(&l, 4)); printf("log size: %d\n", log_size(&l)); printf("\n"); // Are you copying the contents of the string into your log or are you // just storing a pointer to the string? printf("Testing method of appending entries:\n"); char * temp = malloc(11), * temp2 = malloc(10); // "cba 6" temp[0] = 'c'; temp[1] = 'b'; temp[2] = 'a'; temp[3] = ' '; temp[4] = '6'; temp[5]= '\0'; // Copy of "cba 6" temp2[0] = temp[0]; temp2[1] = temp[1]; temp2[2] = temp[2]; temp2[3] = temp[3]; temp2[4] = temp[4]; temp2[5] = temp[5]; log_append(&l, temp); // "abc 6" temp[0] = 'a'; temp[1] = 'b'; temp[2] = 'c'; if (strncmp(temp, temp2, 6) == 0) printf("FAIL:\tNew log entries are copied instead of pointed to.\n\tExpected: '%s'\n\tActual: '%s'\n\n",temp2,log_pop(&l)); else printf("SUCC:\tExpected: '%s'\n\tActual: '%s'\n\n",temp,log_pop(&l)); printf("Testing log_pop():\n"); printf("Popped: '%s'. ", log_pop(&l)); printf("Current size: %d\n", log_size(&l)); printf("Popped: '%s'. ", log_pop(&l)); printf("Current size: %d\n", log_size(&l)); printf("Popped: '%s'. ", log_pop(&l)); printf("Current size: %d\n", log_size(&l)); printf("Popped: '%s'. ", log_pop(&l)); printf("Current size: %d\n", log_size(&l)); printf("Popped: '%s'. ", log_pop(&l)); printf("Current size: %d\n", log_size(&l)); printf("Popped: '%s'. ", log_pop(&l)); printf("Current size: %d\n", log_size(&l)); printf("\n"); printf("Re-populating log entries:\n"); log_append(&l, "ab 1"); log_append(&l, "a 2"); log_append(&l, "abc 3"); log_append(&l, "ab 4"); log_append(&l, "a 5"); printf("0: '%s'\n",log_at(&l, 0)); printf("1: '%s'\n",log_at(&l, 1)); printf("2: '%s'\n",log_at(&l, 2)); printf("3: '%s'\n",log_at(&l, 3)); printf("4: '%s'\n",log_at(&l, 4)); printf("log size: %d\n", log_size(&l)); printf("\n"); printf("Testing log_search():\n"); printf("searching 'ab': '%s'\n",log_search(&l, "ab")); printf("searching 'a': '%s'\n",log_search(&l, "a")); printf("searching 'abc': '%s'\n",log_search(&l, "abc")); printf("searching 'd': '%s'\n",log_search(&l, "d")); printf("\nDone.\n\n"); log_destroy(&l); free(temp); free(temp2); return 0; }
int main() { log_t l; log_init( &l ); while(1) { size_t length = 1; char * buff = calloc( length, sizeof( char ) ); char * cwd = getcwd( buff, length ); while( cwd == NULL ) { length *= 2; buff = realloc( buff, length * sizeof(char) ); cwd = getcwd( buff, length ); } pid_t pid = getpid(); printf("(pid=%d)%s$ ", pid, cwd); free( buff ); char * input = NULL; size_t leng = 0; size_t read = 0; read = getline( &input, &leng, stdin); if( strcmp( input, "\n" ) == 0) { free( input ); continue; } if( *input == '!' ) { printf("Command executed by pid=%d\n", pid); if( strcmp( input, "!#\n" ) == 0 ) { int i; for( i = 0; i < l.num; i++ ) { printf("%s", l.histo[i] ); } free( input ); continue; } else { char * result = log_search( &l, input +1 ); if( result == NULL ) { puts("No Match"); free( input ); continue; } char * temp = malloc( strlen( input + 1) ); int k; for(k = 0; k < strlen( input + 1 ) - 1; k ++) { temp[k] = input[k+1]; } temp[k] = '\0'; printf("%s matches %s", temp, result); free(temp); log_push( &l, result ); free( input ); input = calloc( strlen( result ) + 1, sizeof( char ) ); strcpy( input, result ); } } else { log_push( &l, input ); } /*if( feof( stdin ) ) { log_destroy( &l ); exit( 0 ); }*/ if( strcmp( input, "exit\n" ) == 0 ) { printf("Command executed by pid=%d\n", pid); free( input ); log_destroy( &l ); exit( 0 ); } char * token = strtok( input, " \n" ); char * first = token; char ** follower = calloc( 100, sizeof( char * ) ); int i = 1; while( token ) { token = strtok( NULL, " \n" ); follower[i] = token; i++; } follower[0] = first; follower[i] = NULL; if( strcmp( first, "cd") == 0 ) { printf("Command executed by pid=%d\n", pid); if( chdir( follower[1] ) ) printf("%s: No such file or directory\n", follower[1] ); free( follower ); free( input ); continue; } pid_t child; int status; if ( ( child = fork() ) < 0 ) { perror("Filed to fork"); exit(1); } else if ( child == 0 ) { pid_t pid = getpid(); printf("Command executed by pid=%d\n", pid); execvp( first, follower ); printf("%s: not found\n", first); free(follower); free( input ); log_destroy( &l ); exit(1); } else { child = wait( &status ); } free( follower ); free( input ); } log_destroy( &l ); return 0; }
/** * Starting point for shell. */ int main() { log_init(&Log); char cwd[1024]; int pid; size_t size= 0; while(1){ pid= getpid(); getcwd(cwd, 1024); printf("(pid=%d)%s$ ", pid, cwd); char * line= NULL; getline(&line, &size, stdin); line[strlen(line)-1]= '\0'; if(strstr(line, "cd") == line){ const char * path= line+3; int change= chdir(path); if(change==0){ int pid= getpid(); printf("Command executed by pid=%d\n", pid); log_push(&Log, line); continue; } else{ printf("%s: No such file or directory\n", path); log_push(&Log, line); continue; } } if(strstr(line, "exit") == line){ int pid= getpid(); printf("Command executed by pid=%d\n", pid); log_push(&Log, line); log_destroy(&Log); exit(1); } if(strstr(line, "!#")){ log_entry * curr= Log.head; while(curr){ printf("%s\n", curr->data); curr= curr->next; } free(line); continue; } if(strstr(line, "!") == line){ const char * query= line+1; char * match= NULL; if((&Log)->size > 0) match= log_search(&Log, query); if(match){ printf("%s matches %s\n", query, match); char * line2= malloc(strlen(match)+1); strcpy(line2, match); log_push(&Log, line2); free(line); if(strstr(match, "cd ")){ char * path= match + 3; int change= chdir(path); if(change == 0){ int pid= getpid(); printf("Command executed by pid=%d\n", pid); continue; } else{ printf("%s: No such file or directory\n",path); continue; } } char * array[5]= {NULL, NULL, NULL, NULL, NULL}; char * temp2= malloc(strlen(match)+1); strcpy(temp2, match); char * str= strtok(temp2, " "); if(!str){ array[0] = malloc(strlen(temp2)+1); strcpy(array[0], temp2); } else{ int i=0; for(i=0; i < 5 && str; i++){ array[i]= malloc(strlen(str)+1); strcpy(array[i], str); str= strtok(NULL, " "); } } int status; pid_t child= fork(); if(child >= 0){ if(child == 0){ execvp(array[0], array); printf("%s: not found\n", line); exit(1); } else{ pid_t pid= getpid(); while(pid != child){ pid= wait(&status); } printf("Command executed by pid=%d\n", pid); } } else{ printf("fork failed\n"); exit(1); } free(temp2); free(str); int i=0; for(i=0; i < 5; i++){ free(array[i]); } continue; } else printf("No Match\n"); continue; } char * array[5]= {NULL, NULL, NULL, NULL, NULL}; char * temp= malloc(strlen(line)+1); strcpy(temp, line); char * str= strtok(temp, " "); if(!str){ array[0] = malloc(strlen(temp)+1); strcpy(array[0], temp); } else{ int i=0; for(i=0; i < 5 && str; i++){ array[i]= malloc(strlen(str)+1); strcpy(array[i], str); str= strtok(NULL, " "); } } int status; pid_t child= fork(); if(child == 0){ execvp(array[0], array); printf("%s: not found\n", temp); exit(1); } else{ pid_t pid= getpid(); while(pid != child){ pid= wait(&status); } printf("Command executed by pid=%d\n", pid); log_push(&Log, line); } int i=0; for(i=0; i < 5; i++){ free(array[i]); } free(str); free(temp); } return 0; }
search_list P4C(const_string, path, const_string*, names, boolean, must_exist, boolean, all) { str_list_type ret_list; const_string* namep; string elt; boolean done = false; #ifdef __DJGPP__ /* We will use `stat' heavily, so let's request for the fastest possible version of `stat', by telling it what members of struct stat do we really need. We need to set this on each call because this is a library function; the caller might need other options from `stat'. Thus save the flags and restore them before exit. This call tells `stat' that we do NOT need to recognize executable files (neither by an extension nor by a magic signature); that we do NOT need time stamp of root directories; and that we do NOT need the write access bit in st_mode. Note that `kpse_set_progname' needs the EXEC bits, but it was already called by the time we get here. */ unsigned short save_djgpp_flags = _djstat_flags; _djstat_flags = _STAT_EXEC_MAGIC | _STAT_EXEC_EXT | _STAT_ROOT_TIME | _STAT_WRITEBIT; #endif ret_list = str_list_init(); if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) { DEBUGF1 ("start search(files=[%s", *names); for (namep = names+1; *namep != NULL; namep++) { fputc(' ', stderr); fputs(*namep, stderr); } fprintf (stderr, "], must_exist=%d, find_all=%d, path=%s).\n", must_exist, all, path); } /* No need to do any expansion on names. */ for (namep = names; *namep; namep++) { if (kpse_absolute_p(*namep, true) && kpse_readable_file(*namep)) { str_list_add(&ret_list, xstrdup(*namep)); /* I know, I know... */ goto out; } } /* Look at each path element in turn. */ for (elt = kpse_path_element (path); !done && elt; elt = kpse_path_element (NULL)) { str_list_type *found; boolean allow_disk_search = true; if (elt[0] == '!' && elt[1] == '!') { /* !! magic -> disallow disk searches. */ allow_disk_search = false; elt += 2; } /* See elt-dirs.c for side effects of this function. */ kpse_normalize_path(elt); /* Try ls-R, unless we're searching for texmf.cnf. */ found = first_search ? NULL : kpse_db_search_list(names, elt, all); /* Search the filesystem if (1) the path spec allows it, and either (2a) we are searching for texmf.cnf ; or (2b) no db exists; or (2c) no db's are relevant to this elt; or (3) MUST_EXIST && NAME was not in the db. In (2*), `found' will be NULL. In (3), `found' will be an empty list. */ if (allow_disk_search && (!found || (must_exist && !STR_LIST(*found)))) { str_llist_type *dirs = kpse_element_dirs (elt); if (dirs && *dirs) { if (!found) found = XTALLOC1 (str_list_type); *found = dir_list_search_list (dirs, names, all); } } /* Did we find anything? */ if (found && STR_LIST (*found)) { if (all) { str_list_concat (&ret_list, *found); } else { str_list_add (&ret_list, STR_LIST_ELT (*found, 0)); done = true; } } } out: if (STR_LIST_LENGTH (ret_list) == 0 || (all && STR_LIST_LAST_ELT (ret_list) != NULL)) str_list_add (&ret_list, NULL); if (first_search) { first_search = false; } else { /* Record the filenames we found, if desired. And wrap them in a debugging line if we're doing that. */ if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) { DEBUGF1 ("search([%s", *names); for (namep = names+1; *namep != NULL; namep++) { fputc(' ', stderr); fputs(*namep, stderr); } fputs ("]) =>", stderr); } log_search (ret_list); if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) putc ('\n', stderr); } #ifdef __DJGPP__ /* Undo any side effects. */ _djstat_flags = save_djgpp_flags; #endif return STR_LIST (ret_list); }
search P4C(const_string, path, const_string, original_name, boolean, must_exist, boolean, all) { str_list_type ret_list; string name; boolean absolute_p; #ifdef __DJGPP__ /* We will use `stat' heavily, so let's request for the fastest possible version of `stat', by telling it what members of struct stat do we really need. We need to set this on each call because this is a library function; the caller might need other options from `stat'. Thus save the flags and restore them before exit. This call tells `stat' that we do NOT need to recognize executable files (neither by an extension nor by a magic signature); that we do NOT need time stamp of root directories; and that we do NOT need the write access bit in st_mode. Note that `kpse_set_progname' needs the EXEC bits, but it was already called by the time we get here. */ unsigned short save_djgpp_flags = _djstat_flags; _djstat_flags = _STAT_EXEC_MAGIC | _STAT_EXEC_EXT | _STAT_ROOT_TIME | _STAT_WRITEBIT; #endif /* Make a leading ~ count as an absolute filename, and expand $FOO's. */ name = kpse_expand (original_name); /* If the first name is absolute or explicitly relative, no need to consider PATH at all. */ absolute_p = kpse_absolute_p (name, true); if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) DEBUGF4 ("start search(file=%s, must_exist=%d, find_all=%d, path=%s).\n", name, must_exist, all, path); /* Find the file(s). */ ret_list = absolute_p ? absolute_search (name) : path_search (path, name, must_exist, all); /* Append NULL terminator if we didn't find anything at all, or we're supposed to find ALL and the list doesn't end in NULL now. */ if (STR_LIST_LENGTH (ret_list) == 0 || (all && STR_LIST_LAST_ELT (ret_list) != NULL)) str_list_add (&ret_list, NULL); /* The very first search is for texmf.cnf. We can't log that, since we want to allow setting TEXMFLOG in texmf.cnf. */ if (first_search) { first_search = false; } else { /* Record the filenames we found, if desired. And wrap them in a debugging line if we're doing that. */ if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) DEBUGF1 ("search(%s) =>", original_name); log_search (ret_list); if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) putc ('\n', stderr); } #ifdef __DJGPP__ /* Undo any side effects. */ _djstat_flags = save_djgpp_flags; #endif return STR_LIST (ret_list); }