📄 fv.file.c
字号:
return; (void)strcpy((*f_p)->name, dp->d_name); (*f_p)->width = fv_strlen(dp->d_name); if ((*f_p)->width > Widest_name) Widest_name = (short)(*f_p)->width; (*f_p)->color = BLACK; /* Store other file status stuff */ (*f_p)->mode = fstatus.st_mode; (*f_p)->nlink = fstatus.st_nlink; (*f_p)->uid = fstatus.st_uid; (*f_p)->gid = fstatus.st_gid; (*f_p)->mtime = fstatus.st_mtime; (*f_p)->size = fstatus.st_size; f_p++; i++; if (i==Max_alloc) { if (Max_alloc == MAXFILES) { fv_putmsg(FALSE, Fv_message[ME2MANYFILES], MAXFILES, 0); break; } /* Allocate another chunk of memory for these file * structures. (We never free this memory, but we * also may never need it.) */ j = Max_alloc; Max_alloc += 128; for (; j<Max_alloc; j++) { Fv_file[j] = (FV_FILE *)fv_malloc(sizeof(FV_FILE)); if (Fv_file[j] == NULL) break; } } } (void)closedir(dirp); Fv_nfiles = i;}/* Return -1, 0, 1 if less than, equal to, or greater than */staticcompare_name(f1, f2) FV_FILE **f1, **f2;{ return(strcmp((*f1)->name, (*f2)->name));}staticcompare_time(f1, f2) register FV_FILE **f1, **f2;{ if ((*f1)->mtime > (*f2)->mtime) return(-1); else if ((*f1)->mtime < (*f2)->mtime) return(1); else return(0);}staticcompare_size(f1, f2) register FV_FILE **f1, **f2;{ if ((*f1)->size > (*f2)->size) return(-1); else if ((*f1)->size < (*f2)->size) return(1); else return(0);}staticcompare_type(f1, f2) register FV_FILE **f1, **f2;{ if ((*f1)->type > (*f2)->type) return(1); else if ((*f1)->type < (*f2)->type) return(-1); else return(strcmp((*f1)->name, (*f2)->name));}staticcompare_color(f1, f2) register FV_FILE **f1, **f2;{ if ((*f1)->color > (*f2)->color) return(1); else if ((*f1)->color < (*f2)->color) return(-1); else return(strcmp((*f1)->name, (*f2)->name));}statictrans(y) /* Translate File index to y coordinate */ register int y;{ if (Fv_style & FV_DICON ) { y /= Maxfilesperline; y *= ICON_AREA_HEIGHT; return(y+TOP_MARGIN); } else if (!Fv_style) y /= Maxfilesperline; return(y*LIST_HEIGHT);}statictext_start(i) /* Return text start */{ if (Fv_style & FV_DICON) return(Fv_file[i]->x+(GLYPH_WIDTH>>1) -(Fv_file[i]->width>>1)); else if (Fv_style) return(Fv_file[i]->x); else return(Fv_file[i]->x+LIST_HEIGHT);}staticover_object_name(x, y) /* Return file index if over name */ register int x, y;{ register int i, j;#ifdef SV1 y += GET_SCROLL_VIEW_START;#endif if (Fv_style & FV_DICON) { y -= TOP_MARGIN; i = y/ICON_AREA_HEIGHT; y -= i*ICON_AREA_HEIGHT; if (y >= GLYPH_HEIGHT && y <= GLYPH_HEIGHT+Fv_fontsize.y) { /* y coordinate is over text */ j = (x-Startx)/Incx; j = x/Incx; i = (i*Maxfilesperline)+j; if (i < Fv_nfiles) { j = Fv_file[i]->x + (GLYPH_WIDTH/2); y = Fv_file[i]->width/2; if (x >= j-y && x <= j+y) return(i); } } } else if (Fv_style) { y /= LIST_HEIGHT; if (y < Fv_nfiles && x >= Fv_file[y]->x && x <= Fv_file[y]->x + Fv_file[y]->width) return(y); } else { y /= LIST_HEIGHT; y *= Maxfilesperline; y += (x-Startx)/Incx; if (y < Fv_nfiles) if (x >= Fv_file[y]->x+LIST_HEIGHT && x <= Fv_file[y]->x+LIST_HEIGHT+Fv_file[y]->width) return(y); } return(EMPTY);}staticover_object(x, y) /* Return file index if over icon */ register int x, y;{ register int i, j;#ifdef SV1 y += GET_SCROLL_VIEW_START;#endif /* Validate coordinates */ if (x<0 || y<0) return(EMPTY); if (Fv_style & FV_DICON) { /* Before top margin? */ if (y<TOP_MARGIN) return(EMPTY); y -= TOP_MARGIN; i = y/ICON_AREA_HEIGHT; y -= i*ICON_AREA_HEIGHT; /* Over name bar? */ if (y>GLYPH_HEIGHT+Fv_fontsize.y) return(EMPTY); /* Before 1st? */ if (x<Startx) return(EMPTY); j = (x-Startx)/Incx; i = (i*Maxfilesperline)+j; if (i < Fv_nfiles) if (x >= Fv_file[i]->x && x <= Fv_file[i]->x+GLYPH_WIDTH) return(i); } else if (!Fv_style) { /* Columnar names */ y /= LIST_HEIGHT; y *= Maxfilesperline; y += (x-Startx)/Incx; if (y < Fv_nfiles) if (x >= Fv_file[y]->x && x <= Fv_file[y]->x+LIST_HEIGHT+Fv_file[y]->width) return(y); } else { /* Single file per line */ y /= LIST_HEIGHT; if (y<Fv_nfiles) if (x >= MARGIN && x < MARGIN+LIST_HEIGHT || x >= Fv_file[y]->x && x <= Fv_file[y]->x+Fv_file[y]->width) return(y); } return(EMPTY);}fv_reverse(i) /* Reverse object on canvas */ register int i;{ int x, y; SBYTE color = Fv_file[i]->color; if (Fv_style & FV_DICON) { /* Bound application icons are inverted with an ixon box */ pw_rop(Fv_foldr.pw, Fv_file[i]->x, trans(i), GLYPH_WIDTH, GLYPH_HEIGHT, (PIX_SRC^PIX_DST) | PIX_COLOR(color), Fv_file[i]->type == FV_IAPPLICATION && Fv_file[i]->icon != EMPTY ? 0 : Fv_invert[Fv_file[i]->type], 0, 0); } else { if (!Fv_style) { x = Fv_file[i]->x-1; y = (i/Maxfilesperline) * LIST_HEIGHT+4; } else { x = MARGIN-1; y = (i)*LIST_HEIGHT+4; } pw_rop(Fv_foldr.pw, x, y, 18, 18, (PIX_SRC^PIX_DST) | PIX_COLOR(color), (Pixrect *)0, 0, 0); }}fv_file_open(seln, force_edit, arguments, shelltool) /* Open file */ int seln; BOOLEAN force_edit; char *arguments; /* Run arg or Edit pattern */ BOOLEAN shelltool; /* Run in shelltool */{ register FV_FILE *n_p; register FV_TNODE *f_p; register char *s_p; BOOLEAN draw; BOOLEAN symlink; struct stat fstatus; char buf[MAXPATH]; char *argv[32]; /* Big enough for most cases */ int i; char red[4], green[4], blue[4]; /* Error check */ if (seln == EMPTY) return; n_p = Fv_file[seln]; if (n_p->color > BLACK) { (void)sprintf(red, "%d", Fv_red[n_p->color]); (void)sprintf(green, "%d", Fv_green[n_p->color]); (void)sprintf(blue, "%d", Fv_blue[n_p->color]); } switch (n_p->type) { case FV_IFOLDER: symlink = ((lstat(n_p->name, &fstatus)==0) && (fstatus.st_mode & S_IFMT) == S_IFLNK); if (strcmp("/net", Fv_path) == 0) { (void)strcpy(buf, "/net/"); (void)strcat(buf, n_p->name); if (chdir(buf) == -1) { fv_putmsg(TRUE, sys_errlist[errno], 0, 0); return; } } else if (chdir(n_p->name) == -1) { fv_putmsg(TRUE, sys_errlist[errno], 0, 0); return; } if (getwd(Fv_path) == 0) { /* Error message placed in pathname */ fv_putmsg(TRUE, Fv_path, 0, 0); (void)strcpy(Fv_path, Fv_openfolder_path); } if (symlink) { fv_openfile(Fv_path, (char *)0, TRUE); break; } /* Keep current pointer in tree up to date */ for (f_p = Fv_current->child; f_p; f_p = f_p->sibling) if (strcmp(f_p->name, n_p->name) == 0) { Fv_current = f_p; break; } /* Tell tree to redraw if we have't seen * this folder before. (The folder repaint * routine informs the tree and resets the * seen time.) */ draw = Fv_current->mtime == 0; (void)strcpy(Fv_openfolder_path, Fv_path); fv_display_folder(FV_BUILD_FOLDER); scrollbar_scroll_to(Fv_foldr.vsbar, 0); if (draw) { fv_drawtree(TRUE); fv_visiblefolder(Fv_current); } else fv_showopen(); break; case FV_IAPPLICATION: if (force_edit) edit(n_p->name, (char *)0, EMPTY, EMPTY, n_p->color); else { /* Supply arguments to application */ i = 0; if (shelltool) argv[i++] = "/usr/bin/shelltool"; else argv[i++] = n_p->name; if (n_p->color > BLACK) { argv[i++] = "-Wb"; argv[i++] = red; argv[i++] = green; argv[i++] = blue; } if (shelltool) argv[i++] = n_p->name; if (arguments) { (void)strcpy(buf, arguments); s_p = (char *)strtok(buf, " "); while (s_p) { argv[i++] = s_p; s_p = (char *)strtok((char *)0, " "); } } argv[i] = 0; fv_execit(argv[0], argv); } break; case FV_IDOCUMENT: /* No large icons showing; check for bound applications */ if ( !(Fv_style & FV_DICON) && n_p->icon == EMPTY) check_bind(n_p); if (n_p->icon != EMPTY && *Fv_bind[n_p->icon].application) { /* The user may have specified arguments; ie * /bin/rm -r */ i = 0; (void)strcpy(buf, Fv_bind[n_p->icon].application); s_p = strtok(buf, " "); while (s_p) { argv[i++] = s_p; s_p = (char *)strtok((char *)0, " "); } if (n_p->color > BLACK) { argv[i++] = "-Wb"; argv[i++] = red; argv[i++] = green; argv[i++] = blue; } argv[i++] = n_p->name; argv[i++] = 0; fv_execit(argv[0], argv); } else edit(n_p->name, arguments, EMPTY, EMPTY, n_p->color); break; default: fv_putmsg(TRUE, Fv_message[MEREAD], (int)n_p->name, 0); }}staticedit(name, pattern, x, y, color) /* Edit filename */ char *name; /* Filename */ char *pattern; /* String pattern */ int x, y; /* Screen coordinates */ SBYTE color; /* Frame color */{ Textsw editsw; /* Text editor window */ Frame editframe; /* Window frame */ char buf[MAXPATH+30]; /* Buffer */ Textsw_index first; Textsw_index last_plus_one; /* Pattern match positions */ Rect *r; int argc; char xpos[5], ypos[5]; char *argv[14]; char red[5], green[5], blue[5]; static Notify_value textsw_recover();#ifndef SV1 static Notify_value editsw_event();#endif if (Fv_editor == FV_TEXTEDIT) argv[0] = "textedit"; else if (Fv_editor == FV_OTHER_EDITOR) argv[0] = Fv_other_editor; else argv[0] = "/bin/shelltool"; argc = 1; if (color > BLACK) { argv[argc++] = "-Wb"; (void)sprintf(red, "%d", Fv_red[color]); (void)sprintf(green, "%d", Fv_green[color]); (void)sprintf(blue, "%d", Fv_blue[color]); argv[argc++] = red; argv[argc++] = green; argv[argc++] = blue; }#ifndef BUG /* XXX BUG IN LEIF LOOK */ if (Fv_editor == FV_TEXTEDIT) {#ifdef SV1 D_icon.ic_width = 56; D_icon.ic_height = 64; D_icon.ic_gfxrect.r_width = 56; D_icon.ic_gfxrect.r_height = 64; D_icon.ic_mpr = &d_icon_pr;#endif argv[argc] = 0; editframe = window_create(0, FRAME, FRAME_SHOW_LABEL, TRUE, FRAME_CLOSED, x != EMPTY,#ifdef SV1 FRAME_ARGS, argc, argv, FRAME_EMBOLDEN_LABEL, TRUE, FRAME_ICON, &D_icon,# ifdef PROTO FRAME_SHOW_FOOTER, FALSE,# endif#else FRAME_ICON, vu_create(VU_NULL, ICON, ICON_IMAGE, &d_icon_pr, ICON_WIDTH, 56, ICON_HEIGHT, 64, 0),#endif FRAME_NO_CONFIRM, TRUE, 0); if ((editframe == NULL) || (editsw = (Textsw)window_create(editframe, TEXTSW, WIN_ROWS, 20, WIN_COLUMNS, 60, 0)) == NULL) { fv_putmsg(TRUE, Fv_message[MEWIN], 0, 0); return; }#ifndef SV1 notify_interpose_event_func(vu_get(editsw, OPENWIN_NTH_VIEW, 0), editsw_event, NOTIFY_SAFE);#endif if (Edit_no < MAX_TEXTSW) {#ifdef SV1 Edit_id[Edit_no] = (int)window_get(editsw, WIN_DEVICE_NUMBER); Edit_sw[Edit_no] = editsw;#endif Edit_fr[Edit_no] = editframe; notify_interpose_destroy_func(editframe, textsw_recover); Edit_no++; } if (x != EMPTY && (r = (Rect *)window_get(editframe, FRAME_CLOSED_RECT))) { r->r_top = y; r->r_left = x; window_set(editframe, FRAME_CLOSED_RECT, r, 0); }#ifdef PROTO frame_set_font_size(editframe, window_get(Fv_frame, WIN_FONT_SIZE));#endif window_fit(editframe);#ifndef SV1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -