📄 opts.c
字号:
{ widths[i] = width; } } } /* if the total width is narrow enough, then use it */ for (width = -2, i = 0; i < ncols; i++) { width += widths[i] + 2; } if (width < COLS - 1) { break; } } /* step 3: output the columns */ nrows = (nset + ncols - 1) / ncols; for (i = 0; i < nrows; i++) { for (j = 0; j < ncols; j++) { /* if we hit the end of the options, quit */ k = i + j * nrows; if (k >= nset) { break; } /* output this option's value */ width = 0; switch (opts[todump[k]].type) { case BOOL: if (!*opts[todump[k]].value) { qaddch('n'); qaddch('o'); width = 2; } qaddstr(opts[todump[k]].name); width += strlen(opts[todump[k]].name); break; case NUM: sprintf(nbuf, "%-3d", UCHAR(*opts[todump[k]].value)); qaddstr(opts[todump[k]].name); qaddch('='); qaddstr(nbuf); width = 4 + strlen(opts[todump[k]].name); break; case STR: qaddstr(opts[todump[k]].name); qaddch('='); qaddch('"'); strcpy(tmpblk.c, opts[todump[k]].value); width = 3 + strlen(tmpblk.c); if (width > MAXWIDTH) { width = MAXWIDTH; strcpy(tmpblk.c + MAXWIDTH - 6, "..."); } qaddstr(tmpblk.c); qaddch('"'); width += strlen(opts[todump[k]].name); break; } /* pad the field to the correct size */ if (k + nrows <= nset) { while (width < widths[j] + 2) { qaddch(' '); width++; } } } addch('\n'); exrefresh(); }#else int i; int col; char nbuf[4]; for (i = col = 0; opts[i].name; i++) { /* if not set and not all, ignore this option */ if (!all && !(opts[i].flags & SET)) { continue; } /* align this option in one of the columns */ if (col > 52) { addch('\n'); col = 0; } else if (col > 26) { while (col < 52) { qaddch(' '); col++; } } else if (col > 0) { while (col < 26) { qaddch(' '); col++; } } switch (opts[i].type) { case BOOL: if (!*opts[i].value) { qaddch('n'); qaddch('o'); col += 2; } qaddstr(opts[i].name); col += strlen(opts[i].name); break; case NUM: sprintf(nbuf, "%-3d", UCHAR(*opts[i].value)); qaddstr(opts[i].name); qaddch('='); qaddstr(nbuf); col += 4 + strlen(opts[i].name); break; case STR: qaddstr(opts[i].name); qaddch('='); qaddch('"'); qaddstr(opts[i].value); qaddch('"'); col += 3 + strlen(opts[i].name) + strlen(opts[i].value); break; } exrefresh(); } if (col > 0) { addch('\n'); exrefresh(); }#endif}#ifndef NO_MKEXRC/* This function saves the current configuration of options to a file */void saveopts(fd) int fd; /* file descriptor to write to */{ int i; char buf[256], *pos; /* write each set options */ for (i = 0; opts[i].name; i++) { /* if unset or unsettable, ignore this option */ if ((opts[i].flags & (SET|CANSET|NOSAVE)) != (SET|CANSET)) { continue; } strcpy(buf, "set "); pos = &buf[4]; switch (opts[i].type) { case BOOL: if (!*opts[i].value) { *pos++='n'; *pos++='o'; } strcpy(pos, opts[i].name); strcat(pos, "\n"); break; case NUM: sprintf(pos, "%s=%-3d\n", opts[i].name, *opts[i].value & 0xff); break; case STR: sprintf(pos, "%s=\"%s\"\n", opts[i].name, opts[i].value); break; } twrite(fd, buf, (unsigned)strlen(buf)); }}#endif/* This function changes the values of one or more options. */void setopts(assignments) char *assignments; /* a string containing option assignments */{ char *name; /* name of variable in assignments */ char *value; /* value of the variable */ char *scan; /* used for moving through strings */ char *build; /* used for copying chars from "scan" */ char *prefix; /* pointer to "neg" or "no" at front of a boolean */ int quote; /* boolean: inside '"' quotes? */ int i, j;#ifndef CRUNCH /* reset the upper limit of "window" option to lines-1 */ *o_window = *o_lines - 1;#endif /* for each assignment... */ for (name = assignments; *name; ) { /* skip whitespace */ if (*name == ' ' || *name == '\t') { name++; continue; } /* after the name, find the value (if any) */ for (scan = name; isalnum(*scan); scan++) { } if (*scan == '=') { *scan++ = '\0'; value = build = scan; for (quote = FALSE; *scan && (quote || !isspace(*scan)); scan++) { if (*scan == '"') { quote = !quote; } else if (*scan == '\\' && scan[1]) { *build++ = *++scan; } else { *build++ = *scan; } } if (*scan) scan++; *build = '\0'; } else /* no "=" so it is probably boolean... */ { if (*scan) { *scan++ = '\0'; } value = NULL; prefix = name;#ifndef CRUNCH if (!strcmp(name, "novice")) /* don't check for a "no" prefix */; else#endif if (prefix[0] == 'n' && prefix[1] == 'o') name += 2; else if (prefix[0] == 'n' && prefix[1] == 'e' && prefix[2] == 'g') name += 3; } /* find the variable */ for (i = 0; opts[i].name && strcmp(opts[i].name, name) && strcmp(opts[i].nm, name); i++) { } /* change the variable */ if (!opts[i].name) { msg("invalid option name \"%s\"", name); } else if ((opts[i].flags & CANSET) != CANSET) { msg("option \"%s\" can't be altered", name); } else if ((opts[i].flags & RCSET) != CANSET && nlines >= 1L) { msg("option \"%s\" can only be set in a %s file", name, EXRC); } else if (value) { switch (opts[i].type) { case BOOL: msg("option \"[no]%s\" is boolean", name); break; case NUM: j = atoi(value); if (j == 0 && *value != '0') { msg("option \"%s\" must have a numeric value", name); } else if (j < opts[i].value[1] || j > (opts[i].value[2] & 0xff)) { msg("option \"%s\" must have a value between %d and %d", name, opts[i].value[1], opts[i].value[2] & 0xff); } else { *opts[i].value = atoi(value); opts[i].flags |= SET; } break; case STR: strcpy(opts[i].value, value); opts[i].flags |= SET; break; } if (opts[i].flags & MR) { redraw(MARK_UNSET, FALSE); }#ifndef CRUNCH if (opts[i].flags & WSET) { wset = TRUE; }#endif } else /* valid option, no value */ { if (opts[i].type == BOOL) { if (prefix == name) *opts[i].value = TRUE; else if (prefix[1] == 'o') *opts[i].value = FALSE; else *opts[i].value = !*opts[i].value; opts[i].flags |= SET; if (opts[i].flags & MR) { redraw(MARK_UNSET, FALSE); } } else { msg("option \"%s\" must be given a value", name); } } /* move on to the next option */ name = scan; } /* special processing ... */#ifndef CRUNCH /* if "novice" is set, then ":set report=1 showmode nomagic" */ if (*o_novice) { *o_report = 1;# ifndef NO_SHOWMODE *o_smd = TRUE;# endif# ifndef NO_MAGIC *o_magic = FALSE;# endif }#endif /* if "readonly" then set the READONLY flag for this file */ if (*o_readonly) { setflag(file, READONLY); }#ifndef NO_DIGRAPH /* re-initialize the ctype package */ _ct_init(o_flipcase);#endif /* not NO_DIGRAPH */ /* copy o_lines and o_columns into LINES and COLS */ LINES = (*o_lines & 255); COLS = (*o_columns & 255);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -