static void read_cmd(menu_t* menu,int cmd) { switch(cmd) { case MENU_CMD_LEFT: mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../ case MENU_CMD_RIGHT: case MENU_CMD_OK: { // Directory if(mpriv->p.current->d && !mpriv->dir_action) { // Default action : open this dirctory ourself int l = strlen(mpriv->dir); char *slash = NULL, *p = NULL; if(strcmp(mpriv->p.current->p.txt,"../") == 0) { if(l <= 1) break; mpriv->dir[l-1] = '\0'; slash = strrchr(mpriv->dir,'/'); #if HAVE_DOS_PATHS if (!slash) slash = strrchr(mpriv->dir,'\\'); #endif if(!slash) break; slash[1] = '\0'; p = strdup(mpriv->dir); } else { p = malloc(l + strlen(mpriv->p.current->p.txt) + 1); sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt); } menu_list_uninit(menu,free_entry); if(!open_dir(menu,p)) { mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_CantOpenDirectory,p); menu->cl = 1; } free(p); } else { // File and directory dealt with action string. int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; char filename[fname_len]; char *str; char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action; sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); str = replace_path(action, filename,1); mp_input_parse_and_queue_cmds(str); if (str != action) free(str); } } break; case MENU_CMD_ACTION: { int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; char filename[fname_len]; char *str; sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); str = replace_path(action, filename,1); mp_input_parse_and_queue_cmds(str); if(str != action) free(str); } break; default: menu_list_read_cmd(menu,cmd); } }
void add_Info(DownloadNode *s,DownInfo *p,int year,int day,int hour,int minute) { //add filename s->filename = (char*)malloc( sizeof(char) * MAX_SIZE ); memset( s->filename, 0, MAX_SIZE ); creat_filename( year, day, hour, minute, p->fileType, p->timeType, s->filename ); //add filepath(server local) s->remotePath = replace_path( p->dataCenterPath, year, day, hour, minute, p->fileType ); s->localPath = replace_path( p->localPath, year, day, hour, minute, p->fileType ); s->isHandled = HANDLE_NO; //add ftpserver FtpServer *f = fs->next; while( strcmp( p->downloadServer, f->ip ) !=0 ) { f = f->next; } s -> server = f; //add station list StationNode * w = sl->next; while( w != NULL) { if(strcmp( p->stationList, w->name ) == 0) { break; } w = w->next; } //s->station = w->station; s->stationList = w; int i = 0; int k = 0; s->state = ( char* )malloc( sizeof(char) * ( w->stationNum + 1 )); //sizeof(char)* memset( s->state, 0, ( w->stationNum + 1 ) ); char *filepath1 = ( char* ) malloc( sizeof(char) * MAX_SIZE ); char *filepath2 = ( char* ) malloc( sizeof(char) * MAX_SIZE ); while(i < w->stationNum ) { memset( filepath1, 0, sizeof(char)*MAX_SIZE ); strcpy( filepath1, s->localPath ); char capitalFileName[MAX_SIZE]; memset(capitalFileName, 0, MAX_SIZE); //toCapital( s->filename, capitalFileName ); strcpy(capitalFileName, s->filename); strcat( filepath1, capitalFileName ); memset(capitalFileName, 0, MAX_SIZE); //toCapital( (s->stationList->station)[i], capitalFileName ); strcpy(capitalFileName, (s->stationList->station)[i]); replace( filepath1, STATIONNAME, capitalFileName); memset( filepath2, 0, MAX_SIZE ); strcpy( filepath2, filepath1 ); strcat( filepath2, tempDownloadFileSuffix ); //add state if( strcmp("210.72.144.2", s->server->ip ) == 0) { filepath1[strlen(filepath1)-3] -= 32; filepath2[strlen(filepath2)-8] -= 32; } if( (Search_file(filepath1)==DOWNLOAD_FILE_EXIST) || (Search_file(filepath2)==DOWNLOAD_FILE_EXIST)) { (s->state)[i]=DOWNLOAD_FILE_EXIST; } else { (s->state)[i]=DOWNLOAD_FILE_NONEXIST; k++; } i++; } free(filepath1); free(filepath2); //add taskNum s->taskNum=k; }
static int open_dir(menu_t* menu,char* args) { char **namelist, **tp; struct dirent *dp; struct stat st; int n; int path_fp; char* p = NULL; list_entry_t* e; DIR* dirp; extern int file_filter; char **extensions, **elem, *ext; menu_list_init(menu); if(mpriv->dir) free(mpriv->dir); mpriv->dir = strdup(args); if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title) free(mpriv->p.title); p = strstr(mpriv->title,"%p"); mpriv->p.title = replace_path(mpriv->title,mpriv->dir,0); if ((dirp = opendir (mpriv->dir)) == NULL){ mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_OpendirError, strerror(errno)); return 0; } if (menu_keepdir) { path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (path_fp >= 0) { write (path_fp, mpriv->dir, strlen (mpriv->dir)); close (path_fp); } } namelist = malloc(sizeof(char *)); extensions = get_extensions(menu); n=0; while ((dp = readdir(dirp)) != NULL) { if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0) continue; if (menu_chroot && !strcmp (dp->d_name,"..")) { size_t len = strlen (menu_chroot); if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1) && !strncmp (mpriv->dir, menu_chroot, len)) continue; } if (mylstat(args,dp->d_name,&st)) continue; if (file_filter && extensions && !S_ISDIR(st.st_mode)) { if((ext = strrchr(dp->d_name,'.')) == NULL) continue; ext++; elem = extensions; do { if (!strcasecmp(ext, *elem)) break; } while (*++elem); if (*elem == NULL) continue; } if(n%20 == 0){ // Get some more mem if((tp = realloc(namelist, (n+20) * sizeof (char *))) == NULL) { mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReallocError, strerror(errno)); n--; goto bailout; } namelist=tp; } namelist[n] = malloc(strlen(dp->d_name) + 2); if(namelist[n] == NULL){ mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno)); n--; goto bailout; } strcpy(namelist[n], dp->d_name); if(S_ISDIR(st.st_mode)) strcat(namelist[n], "/"); n++; } bailout: free_extensions (extensions); closedir(dirp); qsort(namelist, n, sizeof(char *), (kill_warn)compare); if (n < 0) { mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReaddirError,strerror(errno)); return 0; } while(n--) { if((e = calloc(1,sizeof(list_entry_t))) != NULL){ e->p.next = NULL; e->p.txt = strdup(namelist[n]); if(strchr(namelist[n], '/') != NULL) e->d = 1; menu_list_add_entry(menu,e); }else{ mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno)); } free(namelist[n]); } free(namelist); return 1; }
void add_Info(DownloadNode *s,DownInfo *p,int year,int day,int hour,int minute) { //add filename s->filename=(char*)malloc(sizeof(char)*MAX_size); memset(s->filename,0,MAX_size); creat_filename(year,day,hour,minute,p->fileType,p->timeType,s->filename); //add filepath(server local) s->remotePath=replace_path(p->dataCenterPath,year,day,hour,minute,p->fileType); s->localPath=replace_path(p->localPath,year,day,hour,minute,p->fileType); //add ftpserver FtpServer *f=fs->next; while(strcmp(p->downloadServer,f->ip)!=0) { f=f->next; } s->server=f; //add station list StationNode * w=sl->next; while(strcmp(p->stationList,w->name)!=0) { w=w->next; } s->station=w->station; int i=0; int k=0; s->state=(char*)malloc(sizeof(char)*MAX_size); memset(s->state,0,MAX_size); while((s->station)[i]!=NULL) { char *filepath1=(char*)malloc(sizeof(char)*MAX_size); memset(filepath1,0,sizeof(char)*MAX_size); strcpy(filepath1,s->localPath); strcat(filepath1,s->filename); char *check1=replace(filepath1,stationame,(s->station)[i]); #ifdef DEBUG printf("check1=%s\n",check1); #endif char *tmp1=(char*)malloc(sizeof(char)*MAX_size); memset(tmp1,0,sizeof(char)*MAX_size); strcpy(tmp1,s->filename); char *tmp2=replace(tmp1,success_extension,extensioname); char *filepath2=(char*)malloc(sizeof(char)*MAX_size); memset(filepath2,0,MAX_size); strcpy(filepath2,s->localPath); strcat(filepath2,tmp2); char *check2=replace(filepath2,stationame,(s->station)[i]); #ifdef DEBUG printf("check2=%s\n",check2); #endif //add state if(Search_file(check1)==DOWNLOAD_FILE_EXIST||Search_file(check2)==DOWNLOAD_FILE_EXIST) { s->state[i]=DOWNLOAD_FILE_EXIST; } else { s->state[i]==DOWNLOAD_FILE_NONEXIST; k++; } i++; } //add taskNum s->taskNum=k; }