?? picturebrowser.c
字號:
#include <stdio.h>#include <errno.h> //needed for errnum#include <string.h>//needed for strerror#include <shimix_pio_button.h>#include <fcntl.h>#include <dirent.h>#include <sys/stat.h>#include <sys/types.h>#define BUTTON_DEVICE "/dev/shimix"static char* pics [100];//pics = (char *) malloc(100);static int count = 0;void get_file_info(char *name, char *path){ struct stat file_stats; if(stat(name, &file_stats) == -1){ printf("\nFailed to access %s\n", name); return; } printf("\nFile found!\n"); printf( " File name: %s\n", name); printf( " Relative path: %s\n", path); printf( " Protection mode: %d\n", file_stats.st_mode); printf( " User id of owner: %d\n", file_stats.st_uid); printf( "Group id of owner: %d\n", file_stats.st_gid); printf( " Size in bytes: %d\n", file_stats.st_size); if(count < 100){ if(file_stats.st_size <= 20000){ pics[count]= strdup(name); printf("Added pic[%d] = %s\n",count, name); count ++; } else{ printf("File is too big. Skipping file...\n"); } } if((file_stats.st_mode & S_IFMT) == S_IFDIR){ printf("The file is a directory.\n\n"); }} void str_tolower(char *s) { while(*s) { *s=tolower(*s); s++; } } int StartSearch(char *name, char *path, int found_signal){ DIR *dfd; struct dirent *dp; struct stat file_stat; if((dfd = opendir(path)) == NULL){ printf("Directory [%s], failed to open.", path); return; } while (( dp = readdir(dfd)) != NULL){ if(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0){ continue; /*skipping itself and parent directories*/ } char slash[2] = "/"; char *path_cpy = (char *) malloc(sizeof(char)*strlen(path)+strlen(dp->d_name)+2); strcpy(path_cpy, path); char *d_nameCopy = (char *) malloc(sizeof(char)*strlen(dp->d_name)+2); strcpy(d_nameCopy, dp->d_name); char *combined = strcat(path_cpy, slash); char *full_name = strcat(combined, dp->d_name); if(stat(full_name, &file_stat) == -1){ printf("\nFailed to access: %s\nSkipping...\n ", full_name); continue; /*skip bad file or directory*/ } if((file_stat.st_mode & S_IFMT) == S_IFDIR){ StartSearch(name, full_name, found_signal); /*recursive search*/ } str_tolower(d_nameCopy); if(strstr(d_nameCopy, name)){ get_file_info(full_name, path); found_signal = 1; //FILE FOUND!!! } free(path_cpy); free(d_nameCopy); } closedir(dfd); return found_signal;}int main(int argc, char *argv[]){ FILE * fButton; //handle to button device char buf[1]; //read buffer to store value of button pushed when read from fButton int numBytesRead = 0; char keyInput = 0; unsigned int ioctlCmd; printf("Launching button reader v1.3\n"); /* Establishing the root directory */ char* initial_path = "mnt"; int found_signal = 0; char * jpg = ".jpeg"; int find = StartSearch(jpg, initial_path, found_signal); jpg= ".jpg"; find = StartSearch(jpg, initial_path, found_signal); char modprobe[28] = "modprobe\tshimix_pio_button"; char makeDevice[29] = "mknod\t/dev/shimix\tc\t63\t0"; //printf("mknod is ran\n\n"); int x = system(modprobe); x = system(makeDevice); fButton = fopen(BUTTON_DEVICE, "r"); //open button device for read-only if (fButton==NULL) { printf("Error opening up %s\n", BUTTON_DEVICE); return -1; } ioctl(fileno(fButton), SBLD_IOCT_LEDBUTTONNUM, 1); //enable displaying button pushed ioctl(fileno(fButton), SBLD_IOCT_LEDCOUNTER, 1); //enable button counters printf("Entering main loop\n\n"); char command1[8] = "nano-X&"; char killall[20] = "killall\t-9\tnano-X"; // position of our cursor through the pics int pos = 0; int j; char andPersand[4] = "\t&"; char resize[6] = "\t12&"; char nxview[9] = "nxview\t"; char *command2; short first_time = 0; while (keyInput!='q' && keyInput!='Q') { printf("awaiting button: "); if ((numBytesRead=read(fileno(fButton), buf, sizeof(char), 0))<= 0) { //if no bytes read or error printf("Error reading %s\n", BUTTON_DEVICE); } else { x = system(killall); j = sleep(1); if(first_time == 0){ printf("executing command nano-X....\n"); x = system(command1); j = sleep(1); command2 = (char *) malloc(sizeof(char)*strlen(nxview)); strcpy(command2, nxview); printf("%d %u\n", buf[0], buf[0]); strcat(command2, pics[pos]); strcat(command2, andPersand); printf("executing %s ....\n",command2); x = system(command2); j = sleep(1); free(command2); first_time = 1; } else{ if (buf[0] == 2) { printf("executing command nano-X....\n"); x = system(command1); j = sleep(1); command2 = (char *) malloc(sizeof(char)*strlen(nxview)); strcpy(command2, nxview); printf("%d %u\n", buf[0], buf[0]); if (pos == count-1){ pos = 0; } else{ pos = pos + 1; } strcat(command2, pics[pos]); strcat(command2, andPersand); printf("executing %s ....\n",command2); x = system(command2); j = sleep(1); free(command2); } else{ if (buf[0] == 4) { printf("executing command nano-X....\n"); x = system(command1); j = sleep(1); command2 = (char *) malloc(sizeof(char)*strlen(nxview)); strcpy(command2, nxview); printf("%d %u\n", buf[0], buf[0]); if (pos <= 0){ pos = count-1; } else{ pos = pos - 1; } strcat(command2, pics[pos]); strcat(command2, andPersand); printf("executing %s ....\n",command2); x = system(command2); j = sleep(1); free(command2); } else{ if (buf[0] == 8){ printf("executing command nano-X....\n"); x = system(command1); j = sleep(1); command2 = (char *) malloc(sizeof(char)*strlen(nxview)); strcpy(command2, nxview); printf("%d %u\n", buf[0], buf[0]); strcat(command2, pics[pos]); strcat(command2, resize); printf("executing %s ....\n",command2); x = system(command2); j = sleep(1); free(command2); } } } } } //printf("Press q to quit or any other key to continue reading buttons\n"); //keyInput = getchar(); } int i; for(i = 0; i < count; i++){ free(pics[i]); } printf("Button Reader terminating\n");}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -