void goto_folder() { #ifndef _TINSPIRE char buf[MAX_LENGH]; #endif #ifdef _TINSPIRE snprintf(currentdir, MAX_LENGH, "%s%s", currentdir, file_name[fileid_selected]); #else snprintf(currentdir, MAX_LENGH, "%s/%s", currentdir, file_name[fileid_selected]); #endif #ifdef _TINSPIRE /* Set the current directory (with lots of "..") to the chosen one */ NU_Set_Current_Dir(currentdir); /* This will return the current directory properly */ NU_Current_Dir("A:",currentdir); #else /* Set it to the current directory. */ chdir(currentdir); /* Get current directory. */ currentdir = getcwd(buf, MAX_LENGH); #endif list_all_files(currentdir); refresh_cursor(2); }
static int count_all_files(struct node *n) { struct tree_node *t; int count; t = tree_first(n->provide->root); count = 0; while (t) { if (IS_FILE(t->n->name)) count++; count += list_all_files(t->n, 0); t = tree_next(t); } return count; }
/* * builtin_cmd * * 내장 명령을 수행한다. * 내장 명령이 아니면 1을 리턴한다. */ int builtin_cmd(int argc, char **argv) { // 내장 명령어 문자열과 argv[0]을 비교하여 각각의 처리 함수 호출 if ( (!strcmp (argv[0], "quit")) || (!strcmp (argv[0], "exit")) ) { exit(0); } if ( !strcmp(argv[0], "ls")){ return list_files(argc, argv); } if ( !strcmp(argv[0], "ll")){ return list_all_files(argc, argv); } if ( !strcmp(argv[0], "cp")){ return copy_file(argc, argv); } if ( !strcmp(argv[0], "rm")){ return remove_file(argc, argv); } if ( !strcmp(argv[0], "move")){ return move_file(argc, argv); } if ( !strcmp(argv[0], "cd")){ return change_directory(argc, argv); } if ( !strcmp(argv[0], "pwd")){ return print_working_directory(); } if ( !strcmp(argv[0], "mkdir")){ return make_directory(argc, argv); } if ( !strcmp(argv[0], "rmdir")){ return remove_directory(argc, argv); } if ( !strcmp(argv[0], "cpdir")){ return copy_directory(argc, argv); } // 내장 명령어가 아님. printf("command not found\n"); return 1; }
int list_files(struct hash *hash, char *pkgname) { struct node *n; if ((n = hash_search(hash, pkgname)) == NULL) { fprintf(stderr, "bee-dep: list_files: cannot find \"%s\"\n", pkgname); return 1; } if (!IS_PKG(n)) { fprintf(stderr, "bee-dep: list_files: \"%s\": no such package\n", pkgname); return 1; } list_all_files(n, 1); return 0; }
static int list_all_files(struct node *n, char print) { struct tree_node *t; int count; t = tree_first(n->provide->root); count = 0; while (t) { if (IS_FILE(t->n->name)) { count++; if (print) puts(t->n->name); } count += list_all_files(t->n, print); t = tree_next(t); } return count; }
int main(int argc, char* argv[]) { /* Buffer to hold =>the current directory */ char* buf = NULL; unsigned char exit_app = 0; #ifdef EXECUTE_APP unsigned char file_chosen; unsigned char done = 1; #endif /* Temporary array, used for starting executable*/ char file_to_start[MAX_LENGH]; /* Init video and variables */ init(); clear_entirescreen(); /* Set it to the current directory. */ /*currentdir = getcwd(buf, MAX_LENGH);*/ /* List 12 files to be shown on screen (here, it is the first chunck) */ list_all_files(getcwd(buf, MAX_LENGH)); update_entirescreen(); /* Refresh everything on screen */ refresh_cursor(1); while (exit_app==0) { while (button_state[6]<1) { /* Call function for input */ controls(); /* If Up button is pressed down... (or Left button held) */ if (button_state[0] == 1 || button_state[2] > 0) { if (choice > 0) { choice--; refresh_cursor(0); set_fileid(); } else if (scroll_choice > 0) { choice = 11; scroll_choice = scroll_choice - 1; refresh_cursor(3); set_fileid(); } } /* If Down button is pressed down... (or Right button held) */ else if (button_state[1] == 1 || button_state[3] > 0) { /* Don't let the user to scroll more than there are files... */ if (fileid_selected < numb_files) { if (choice < 11) { choice++; refresh_cursor(0); set_fileid(); } /* If the user wants to go down and there are more files, change the files to shown to the next one (thanks to scroll_choice) */ else if (numb_files > 10) { scroll_choice = scroll_choice + 1; choice = 0; set_fileid(); refresh_cursor(3); } } } if (button_state[6] == 1) { #ifdef EXECUTE_APP file_chosen = 0; #endif exit_app = 1; } /* If Control/Return button is pressed... */ if (button_state[4]==1 || button_state[5]==1) { /* If file is a tns file then launch it */ if (file_type[fileid_selected] == BLUE_C) { snprintf(file_to_start, MAX_LENGH, "%s/%s", currentdir, file_name[fileid_selected]); #ifdef EXECUTE_APP file_chosen = 1; button_state[6] = 1; #elif defined(_TINSPIRE) nl_exec(file_to_start, 0, NULL); #endif } /* If not then it is a folder, if thats the case then go to that folder */ else if (file_type[fileid_selected] == F_C || choice == 0) { goto_folder(); } } /* Don't waste CPU cycles */ #ifndef ndlib SDL_Delay(16); #endif } #ifdef EXECUTE_APP if (file_chosen == 1) { #ifdef ndlib deinitBuffering(); #else if (gui_screen) SDL_FreeSurface(gui_screen); #endif while(done == 1) { tostart(file_to_start); done = 0; } done = 1; file_chosen = 0; init(); clear_entirescreen(); /*currentdir = getcwd(buf, MAX_LENGH);*/ list_all_files(getcwd(buf, MAX_LENGH)); update_entirescreen(); refresh_cursor(2); } else { exit_app = 1; } #endif } #ifdef ndlib clearBufferB(); deinitBuffering(); #else if (gui_screen != NULL) SDL_FreeSurface(gui_screen); SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_Quit(); #endif exit(0); }
/* * builtin_cmd * * 내장 명령을 수행한다. * 내장 명령이 아니면 1을 리턴한다. */ int builtin_cmd(int argc, char **argv) { //아무것도 안들어올 경우 예외처리 if(argc == 0) { return -1; } //에러처리 if(argc < 0) { fprintf(stderr ,"error. check your commane and retry\n"); return -1; } // 내장 명령어 문자열과 argv[0]을 비교하여 각각의 처리 함수 호출 if ( (!strcmp (argv[0], "quit")) || (!strcmp (argv[0], "exit")) ) { exit(0); } if ( !strcmp(argv[0], "ls")) { return list_files(argc, argv); } if ( !strcmp(argv[0], "ll")) { return list_all_files(argc, argv); } if ( !strcmp(argv[0], "cp")) { return copy_file(argc, argv); } if ( !strcmp(argv[0], "rm")) { return remove_file(argc, argv); } if ( !strcmp(argv[0], "mv")) { return move_file(argc, argv); } if ( !strcmp(argv[0], "cd")) { return change_directory(argc, argv); } if ( !strcmp(argv[0], "pwd")) { return print_working_directory(argc); } if ( !strcmp(argv[0], "mkdir")) { return make_directory(argc, argv); } if ( !strcmp(argv[0], "rmdir")) { return remove_directory(argc, argv); } if( !strcmp(argv[0], "help")) { return help(argc); } // 내장 명령어가 아님. fprintf(stderr,"command not found\n"); return 1; }