📄 fv.bind.c
字号:
Rect *rn; /* Damaged area */ rn = &area->rl_bound; i = rn->r_top / Bentry_height; if (i >= Fv_nbind) return; j = (rn->r_top+rn->r_height) / Bentry_height+1; if (j >= Fv_nbind) j = Fv_nbind-1; pw_lock(pw, rn); while (i<=j) { draw_bind(i, pw); i++; } /* Repair damaged section */ if (Bchosen != EMPTY) pw_rop(pw, rn->r_left, Bchosen * Bentry_height, rn->r_width, Bentry_height, PIX_NOT(PIX_SRC)^PIX_DST, (Pixrect *)0, 0, 0); pw_unlock(pw);}staticdraw_bind(i, pw) /* Display bind entry */ register int i; /* Entry number */ register PAINTWIN pw; /* Canvas's pixwin */{ register int y, xoffset; register char *s_p; struct pr_size size; /* Display name pattern or magic number */ y = Bentry_height*i; xoffset = MARGIN; s_p = Fv_bind[i].pattern[0] ? Fv_bind[i].pattern : Fv_bind[i].magic->str; pw_text(pw, xoffset, y+(Bentry_height/2), PIX_SRC, Fv_font, s_p); size = pf_textwidth(strlen(s_p), Fv_font, s_p); xoffset += BINDGAP+size.x; pw_rop(pw, xoffset, y+(Bentry_height/2)-8, 16, 16, PIX_SRC, &Equal_pr, 0, 0); xoffset += 16 + BINDGAP; if (*Fv_bind[i].iconfile) { pw_rop(pw, xoffset, y, GLYPH_WIDTH, GLYPH_HEIGHT, PIX_SRC, Fv_bind[i].icon, 0, 0); xoffset += GLYPH_WIDTH + MARGIN; } if (*Fv_bind[i].application) { if (*Fv_bind[i].iconfile) { pw_rop(pw, xoffset, y+(Bentry_height/2)-8, 16, 16, PIX_SRC, &Plus_pr, 0, 0); xoffset += 17 + BINDGAP; } pw_text(pw, xoffset, y+(Bentry_height/2), PIX_SRC, Fv_font, Fv_bind[i].application); }}static void /* ARGS IGNORED */bind_button() /* Sanity check, and request a bind entry */{ char *pattern, *applic, *icon; char buf[256]; int choice; if (Fv_nbind >= MAXBIND) { error(TRUE, Fv_message[MEBINDENT]); return; } pattern = (char *)panel_get(Pattern_item, PANEL_VALUE); if (strchr(pattern, '/')) { error(TRUE, Fv_message[MEPATTERN]); return; } applic = (char *)panel_get(App_item, PANEL_VALUE); icon = (char *)panel_get(Icon_item, PANEL_VALUE); if (*pattern == NULL) error(TRUE, Fv_message[MEMUSTENTER1]); else if (*icon == NULL) error(TRUE, Fv_message[MEMUSTENTER2]); else { choice = (int)panel_get(Choice_item, PANEL_VALUE); (void)sprintf(buf, "%s,%s,%s,%s", choice?"":pattern, choice?pattern:"", applic, icon); if (make_entry(buf, &Fv_bind[Fv_nbind]) == 0) { /* Make the canvas bigger, scroll to new entry */ window_set(Bcanvas, CANVAS_HEIGHT, (Fv_nbind+2)*Bentry_height, 0); scrollbar_scroll_to(Bscrollbar, Fv_nbind*GLYPH_WIDTH); draw_bind(Fv_nbind, Pw); Fv_nbind++; } }}staticmake_entry(buf, bind) /* Create a bind entry */ char *buf; /* Pattern, magic, app, icon */ register FV_BIND *bind; /* Bind structure */{ register int j; /* Index */ register char *b_p, *s_p; /* Temp pointers */ char errmsg[80]; /* load icon error message */ static FV_MAGIC *make_magic(); if ((bind->buf=fv_malloc((unsigned)strlen(buf)+1))==NULL) return(-1); (void)strcpy(bind->buf, buf); /* Pattern */ b_p = bind->buf; s_p = b_p; while (*b_p && *b_p != ',') b_p++; *b_p = NULL; bind->pattern = s_p; /* Magic number */ s_p = ++b_p; while (*b_p && *b_p != ',') b_p++; *b_p = NULL; bind->magic = NULL; if (*s_p) { /* Match s_p with magic description... */ for (j=0; j<Nmagic; j++) { if (strcmp(Magic[j], s_p) == 0) { if ((bind->magic = make_magic(Magic[j]-Moffset[j]))==NULL) return(-1); bind->magic->str = s_p; break; } } if (j==Nmagic) { error(TRUE, "Unknown magic number"); return(-1); } } /* Application */ s_p = ++b_p; while (*b_p && *b_p != ',') b_p++; *b_p = NULL; bind->application = s_p; /* Icon */ s_p = ++b_p; while (*b_p && *b_p != '\n') b_p++; *b_p = NULL; if (*(bind->iconfile = s_p) == NULL) { error(TRUE, "No icon"); return(-1); } if (*s_p) { if ((bind->icon = (Pixrect *)icon_load_mpr(s_p, errmsg)) == NULL) { error(TRUE, errmsg); if (bind->magic) free((char *)bind->magic); return(-1); } } else bind->icon = NULL; return(0);}/* This stuff is based on the magic number code in file(1)... */#define FBSZ 64 /* Read this number of bytes... */#define NTYPES 4 /* Number of operand types */#define LONG 0#define STR 1#define ABYTE 2#define SHORT 3#define NOPS 5 /* Number of operators */#define EQ 0#define GT 1#define LT 2#define STRC 3 /* ...string compare */#define ANY 4#define SUB 64 /* ...or'ed in */fv_magic(fname, magic, fstatus) /* Match filename with magic number description */ char *fname; /* Candidate */ FV_MAGIC *magic; /* Magic number description */ struct stat *fstatus; /* Candidate's file status */{ int result=FALSE; /* Match? */ int fd; /* Candidate's file descriptor */ struct utimbuf { /* Reset time after open & read */ time_t actime; time_t modtime; } utb; char buf[FBSZ]; /* First n bytes of file */ if (fd=open(fname, 0)) { if (read(fd, buf, FBSZ)) result = check_magic(buf, magic); utb.actime = fstatus->st_atime; utb.modtime = fstatus->st_mtime; (void)utime(fname, &utb); (void)close(fd); } return(result);}staticcheck_magic(buf, magic) char *buf; /* First n bytes of file */ register FV_MAGIC *magic;/* Magic number description */{ register char *p; /* Temp pointer */ long val; /* Numeric value */ p = &buf[magic->off]; switch(magic->type) { case LONG: val = (*(long *) p); break; case STR: return(strncmp(p, magic->value.str, strlen(magic->value.str))==0); case ABYTE: val = (long)(*(unsigned char *) p); break; case SHORT: val = (long)(*(unsigned short *) p); break; } if (magic->mask) val &= magic->mask; switch (magic->opcode & ~SUB) { case EQ: return(val == magic->value.num); case GT: return(val <= magic->value.num); case LT: return(val >= magic->value.num); } return(FALSE);}static FV_MAGIC *make_magic(buf) char *buf; /* Raw magic number description */{ static char *types[NTYPES] = { "long", "string", "byte", "short" }; static char ops[NOPS] = { '=', '>', '<', '=', 'x' }; register char *p, *p2, *p3;/* Temp pointer */ int i; /* Index */ FV_MAGIC *magic; /* Magic number description */ char *e_p; /* Error message pointer */ char *getstr(); long atolo(); if ((magic=(FV_MAGIC *)fv_malloc(sizeof(FV_MAGIC)))==NULL) return(NULL); p = buf; p2 = strchr(p, '\t'); /* OFFSET... */ if (!p2) { e_p = "No tab after offset"; goto bad; } magic->off = atoi(p); while(*p2 == '\t') /* TYPE... */ p2++; p = p2; p2 = strchr(p, '\t'); if(p2 == NULL) { e_p = "No tab after type"; goto bad; } *p2++ = NULL; p3 = strchr(p, '&'); /* MASK... */ if (p3) { *p3++ = NULL; magic->mask = atoi(p3); } else magic->mask = 0L; for (i = 0; i < NTYPES; i++) if (strcmp(p, types[i]) == 0) break; if (i==NTYPES) { e_p = "Illegal type"; goto bad; } magic->type = i; *(p2-1) = '\t'; /* Put tab back */ while(*p2 == '\t') /* TYPE... */ p2++; p = p2; /* OP VALUE... */ p2 = strchr(p, '\t'); if (!p2) { e_p = "No tab after value"; goto bad; } *p2 = NULL; if (magic->type != STR) { /* Get operator; missing op is assumed to be '=' */ for (i = 0; i < NOPS; i++) if (*p == ops[i]) { magic->opcode = i; p++; break; } if (i==NOPS) magic->opcode = EQ; } if (magic->opcode != ANY) { if (magic->type == STR) { if ((magic->value.str = getstr(p))==NULL) { e_p = Fv_message[MENOMEMORY]; goto bad; } } else magic->value.num = atolo(p); } *p2 = '\t'; return(magic);bad: error(TRUE, e_p); if (magic) free((char *)magic); return(NULL);}static char *getstr(s) register char *s;{ static char *store; register char *p; register char c; register int val; if ((store = fv_malloc((unsigned)strlen(s) + 1)) == NULL) return(NULL); p = store; while((c = *s++) != '\0') { if(c == '\\') { switch(c = *s++) { case '\0': goto out; default: *p++ = c; break; case 'n': *p++ = '\n'; break; case 'r': *p++ = '\r'; break; case 'b': *p++ = '\b'; break; case 't': *p++ = '\t'; break; case 'f': *p++ = '\f'; break; case 'v': *p++ = '\v'; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': val = c - '0'; c = *s++; /* try for 2 */ if(c >= '0' && c <= '7') { val = (val<<3) | (c - '0'); c = *s++; /* try for 3 */ if(c >= '0' && c <= '7') val = (val<<3) | (c-'0'); else --s; } else --s; *p++ = val; break; } } else *p++ = c; }out: *p = '\0'; return(store);}static longatolo(s) register char *s;{ register char *fmt = "%ld"; auto long j = 0L; if(*s == '0') { s++; if(*s == 'x') { s++; fmt = "%lx"; } else fmt = "%lo"; } (void)sscanf(s, fmt, &j); return(j);}static error(bell, msg) BOOLEAN bell; char *msg; {#ifdef SV1# ifdef PROTO if (Bind_frame) { window_set(Bind_frame, FRAME_MESSAGE, msg, 0); if (bell) window_bell(Bind_frame); } else fv_putmsg(bell, msg, 0, 0);# else fv_putmsg(bell, msg, 0, 0);# endif#else if (Bind_frame) { window_set(Bind_frame, FRAME_MESSAGE, msg, 0); if (bell) window_bell(Bind_frame); } else fv_putmsg(bell, msg, 0, 0);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -