/* Подпрограмма работы с файлами - выбор файлов и правое меню */ #define pas (BLUE << 4) + LIGHTGRAY #define act (MAGENTA << 4) + WHITE #define R_ITEMS 4 char hk[]={ _ESC,0 }, hk0[]={/*_F5,*/0 }, fhk[]={ _ESC, _ENTER, 0 }, fhk0[]={ /* _F5, */ 0 }; string lhk; string dest_name; FILE *dest; static menu_item_t items[]={ { " Просмотр ","",NULL,0,0,0,0,BLACK,1,1,"",""}, { " Редактор ","",NULL,0,2,0,0,BLACK,1,2,"",""}, { " Копировать","",NULL,0,4,0,0,BLACK,1,3,"",""}, { " Удалить ","",NULL,0,6,0,0,BLACK,1,4,"",""}, }; void my_show_right(menu_t *mnu, void *data, struct fchk_wc *wc) { int i; lhk[0]=_TAB; strcat(lhk+1,wc->hk); for(i=0; i < R_ITEMS; i++) { items[i].act_col=wc->file_col; items[i].pas_col=wc->string_col; } show_menu(mnu,2,0,0,0,0,items,R_ITEMS,lhk,wc->hk0); } void copy_file(char *src_name, FILE *dest) { void *buf1, *buf2; FILE *src; src=fopen(src_name,"rb"); if(buf1=malloc(10000)) setvbuf(src,buf1,_IOFBF,10000); if(buf2=malloc(10000)) setvbuf(dest,buf2,_IOFBF,10000); while(!feof(src) && !ferror(dest)) fputc(fgetc(src),dest); fclose(src); fclose(dest); } int dest_valid(void *p) { char *str=(char *)p; dest=NULL; return (dest=fopen(str,"w")) != NULL; } ml_retcode_t my_choose_right(menu_t *mnu, void *data, struct fchk_wc *wc) { ml_retcode_t ch; char drive[3], mask_drive[4], mask_dir[65], dir[65], name[9], ext[5], buf[85]; window_t wnd; menu_t name_mnu; long l; string full_name; char *scr_mem; static edit_field_t edf={ 0,0,0,act,pas,"",STRING,fhk,hk0,dest_name,dest_valid }; static menu_item_t item={ "","",&edf,0,0,act,pas,BLACK,1,1,hk,hk0 }; char **pmask_name=data, *pmask=pmask_name[0],*pname=pmask_name[1]; int is_name,sys_res; edf.maxlen=wc->x2-wc->x1-5; fnsplit(pmask,mask_drive,mask_dir,name,ext); fnsplit(pname,buf,buf,name,ext); fnmerge(full_name,mask_drive,mask_dir,name,ext); ch=choose_from_menu(mnu); switch(ch){ case 1: case 2: store_scr_state(); store_scr(&scr_mem); if(ch==1) sprintf(buf,"wpview %s",full_name); else sprintf(buf,"turbo %s",full_name); sys_res=system(buf); restore_scr(&scr_mem); restore_scr_state(); break; case 3: if(!is_subdir(pname)){ fnsplit(dest_name,drive,dir,name,ext); fnsplit(pname,buf,buf,name,ext); /* fnmerge(dest_name,drive,dir,name,ext); */ fnmerge(dest_name,mask_drive,mask_dir,name,ext); show_window(&wnd,wc->x1,wc->y1,wc->x2,wc->y1+2, GREEN,CYAN,DOUBLE_BORDER, " Имя файла назначения "," ESC - отказ "); /* cprintf("F5 - имя с текущим каталогом"); */ show_menu(&name_mnu,0,0,0,0,0,&item,1,hk,hk0); do { ch=choose_from_menu(&name_mnu); /* if(GETK0(ch)==_F5) { fnsplit(dest_name,drive,dir,name,ext); fnmerge(dest_name,drive,mask_dir,name,ext); } */ } while(ch != 1 && ch != _ESC); if(ch==1) { strcpy(buf,searchpath(full_name)); if(strcmp(buf,searchpath(dest_name))) copy_file(full_name,dest); } erase_window(&wnd); ch=CH_REDRAW_LEFT; } break; case 4: if(is_subdir(pname)) message_box(wc->x1,wc->y1,"Не могу стереть каталог!",GREEN,MAGENTA); else { if(unlink(full_name)==-1) if(in_str(get_answer(wc->x1,wc->y1,"Файл помечен только для чтения. Стирать (Y/N)?", "YyNn","",RED,MAGENTA),"Yy")) { if(chmod(full_name,S_IWRITE) != -1) unlink(full_name); else message_box(wc->x1,wc->y1,"Не могу его стереть!",GREEN,MAGENTA); } } ch=CH_REDRAW_LEFT; break; } return ch; } void file_menu(void) { extern fch_wndclass_t STD_fchclass; ml_retcode_t ch; fch_wndclass_t fchclass; char buf[100]; string mask,name; char *pmask_name[2]; /* указатели для my_choose_right */ pmask_name[0]=mask; pmask_name[1]=name; strcpy(mask,"*.*"); fchclass=STD_fchclass; fchclass.right_menu_width=15; fchclass.show_right_menu=my_show_right; fchclass.choose_right=my_choose_right; ch=get_fname_rmenu(&fchclass," File "," Name ", mask,name,NULL,pmask_name); if(ch==_ENTER) { sprintf(buf,"Выбран файл:%s",name); message_box(4,9,buf,LIGHTGRAY,GREEN); } }