📄 fv.find.c
字号:
(void)close(i); i = 0; av[i++] = "find"; av[i++] = from; if (name[0]) { if (panel_get_value(Nametoggle)) av[i++] = "!"; av[i++] = "-name"; av[i++] = name; } if (owner[0]) { if (panel_get_value(Ownertoggle)) av[i++] = "!"; av[i++] = "-user"; av[i++] = owner; } if (after[0]) { av[i++] = "-mtime"; (void)sprintf(buf, "-%d", today-after_days-1); av[i++] = buf; } if (before[0]) { av[i++] = "!"; av[i++] = "-mtime"; (void)sprintf(buf1, "-%d", today-before_days); av[i++] = buf1; } if (pattern[0]) { av[i++] = "-exec"; av[i++] = "egrep"; av[i++] = "-l"; if (panel_get_value(Casetoggle)) av[i++] = "-i"; av[i++] = pattern; av[i++] = "{}"; av[i++] = ";"; } else av[i++] = "-print"; av[i++] = NULL; execve(FINDPROG, av, (char **)0); (void)fprintf(stderr, "exec failed\n"); exit(127); } if ((Ptyfp = fdopen(Master, "r")) == NULL) error(TRUE, Fv_message[MEREAD], 0); else { error(FALSE, "Searching...", 0);#ifdef OPENLOOK panel_set(Cancel_button, PANEL_INACTIVE, FALSE, 0); panel_set(Open_button, PANEL_INACTIVE, TRUE, 0);#endif Pid = pid; notify_set_input_func(&Pid, find_input, Master); }}static Notify_value /* Stick find's output into text subwindow... */find_input() /* ARGS IGNORED */{ char buf[255]; unsigned len; static int threshold = CANVAS_ROWS; if (fgets(buf, sizeof(buf), Ptyfp)) { /* Find has output... */ /* Errors typically have a colon before the error * message. Touch luck if the filename has an embedded * colon! * Put errors from command on message line. * Note: Find quits without informing us on sparc m/cs. */ if (strchr(buf, ':')) error(FALSE, buf, 0); else if (Nfound > MAXFIND) { cancel_button(); error(FALSE, Fv_message[ME2MANYFILES], MAXFIND); } else { /* Strip off newline at end */ len = (unsigned)strlen(buf); len--; buf[len] = NULL; if ((Found[Nfound]=fv_malloc(len+1))==0) goto cleanup; (void)strcpy(Found[Nfound], buf); Find_canvas_y += Fv_fontsize.y; pw_text(Pw, 5, Find_canvas_y, PIX_SRC, Fv_font, buf); Nfound++; if (Nfound>=threshold) { scrollbar_scroll_to(Find_canvassb, (Nfound-1)*Fv_fontsize.y); threshold += CANVAS_ROWS; } } } else {cleanup: (void)close(Master); notify_set_input_func(&Pid, NOTIFY_FUNC_NULL, Master); if (Nfound) error(TRUE, "%d file(s) found", Nfound); else error(TRUE, "Nothing found", 0); window_set(Find_canvas, CANVAS_HEIGHT, (Nfound+1)*Fv_fontsize.y, 0);#ifdef OPENLOOK panel_set(Cancel_button, PANEL_INACTIVE, TRUE, 0);#endif threshold = CANVAS_ROWS; /* Reset */ } return(NOTIFY_DONE);}static voidcancel_button() /* ARGS IGNORED */{ /* XXX Must find a way of flushing Find's buffer */ /* Kill find in progress... */ if (Pid > 0) { if (kill(Pid, SIGTERM) == -1) error(TRUE, "Can't signal find", 0); else error(TRUE, "Find stopped", 0); Pid = 0; (void)close(Master); notify_set_input_func(&Pid, NOTIFY_FUNC_NULL, Master);#ifdef OPENLOOK panel_set(Cancel_button, PANEL_INACTIVE, TRUE, 0);#endif }}static voidopen_notify(){#ifdef OPENLOOK panel_set(Open_button, PANEL_INACTIVE, FALSE, 0);#endif}static voiddone(){ register int i; (void)window_set(Find_frame, WIN_SHOW, FALSE, 0); /*fv_lb_delete(Find_canvas);*/ /* If you do delete... */ for (i=0; i < Nfound; i++) free(Found[i]); Nfound = 0;}staticgetunum(s) char *s;{ register i; struct passwd *getpwnam(), *pw; i = -1; if (((pw = getpwnam(s)) != NULL) && pw != (struct passwd *)EOF) i = pw->pw_uid; return(i);}staticgetMaster(){ char *pty, *bank, *cp; struct stat stb; int i; pty = &Line[LENDEVPTY]; for (bank = "pqrs"; *bank; bank++) { Line[LENDEVPTY-1] = *bank; *pty = '0'; if (stat(Line, &stb) < 0) break; for (cp = "0123456789abcdef"; *cp; cp++) { *pty = *cp; i = open(Line, O_RDWR); if (i >= 0) { char *tp = &Line[LENDEV]; int ok; /* verify Slave side is usable */ *tp = 't'; ok = access(Line, R_OK|W_OK) == 0; *tp = 'p'; if (ok) return(i); (void) close(i); } } } return(-1);}static struct sgttyb b = {13, 13, CTRL(?), CTRL(U), 06310};staticgetSlave(){ int i; Line[LENDEV] = 't'; i = open(Line, O_RDWR); if (i < 0) return(-1); (void) ioctl(i, TIOCSETP, (char *)&b); return(i);}static voidopen_button() /* ARGS IGNORED */{ if (Found_chosen >=0 && Found_chosen < Nfound) fv_openfile(Found[Found_chosen], (char *)panel_get(Patternitem, PANEL_VALUE), FALSE); else error(TRUE, Fv_message[MESELFIRST], 0);}static short Month_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};/* Returns number of days since start of century; no error checking */staticget_days(month, day, year) register int month; int day; register int year;{ register int days = 0; short leap; year += 1900; leap = year%4 == 0 && year%100 != 0 || year%400 == 0; year--; while (year >= 1900) { days += 365 + (year%4 == 0 && year%100 || year%400 == 0); year--; } if (leap && month > 2) days++; month -= 2; while (month >= 0) days += Month_days[month--]; days += day; return(days);}staticcalc_days(mdy) /* Validate and return # of days from string */ char *mdy; /* Month, day, year */{ int scanned; int month, day, year; short leap; scanned = sscanf(mdy, "%d/%d/%d", &month, &day, &year); if (scanned==2) { /* Complete the year for the user */ struct tm *today; year = time((time_t *)0); today = localtime((long *)&year); year = today->tm_year; } else if (scanned!=3) return(-1); /* Do we have a valid date? */ year += 1900; leap = year%4 == 0 && year%100 != 0 || year%400 == 0; year -= 1900; if (month<1 || month>12 || day < 1 || year < 0 || year > 99) return(-1); if (leap && month==2 && day>29) return(-1); if (day > Month_days[month-1]) return(-1); /* We do indeed have a valid date, now calculate the number * of days from today... */ return(get_days(month, day, year));}/* Return the number of days from century start 'til today */statictoday_in_days(){ time_t time_p; struct tm *ltime; time_p = time((time_t *)0); ltime = localtime(&time_p); return(get_days(ltime->tm_mon+1, ltime->tm_mday, ltime->tm_year));}staticerror(bell, msg, arg) char bell; char *msg; char *arg;{ char buffer[256]; if (arg) { (void)sprintf(buffer, msg, arg); msg = buffer; }#ifdef SV1# ifdef PROTO window_set(Find_frame, FRAME_MESSAGE, msg, 0); if (bell) window_bell(Find_frame);# else fv_putmsg(bell, msg, (int)arg, 0);# endif#else window_set(Find_frame, FRAME_MESSAGE, msg, 0); if (bell) window_bell(Find_frame);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -