Annotation of OpenXM_contrib2/fep/fep_set.c, Revision 1.1
1.1 ! noro 1: /* Copyright (c) 1987, 1988 by Software Research Associates, Inc. */
! 2:
! 3: #ifndef lint
! 4: static char rcsid[]=
! 5: "$Header: fep_set.c,v 4.3 91/05/29 14:31:08 utashiro Exp $ (SRA)";
! 6: #endif /* lint */
! 7:
! 8: #include <stdio.h>
! 9: #include "fep_defs.h"
! 10: #include "fep_glob.h"
! 11:
! 12: VAR default_set_vars [] = {
! 13: {"expand-tilde", "",
! 14: "Expand ~ to home directory name", (VAR*)0},
! 15: {"ignore-empty-line", "",
! 16: "Don't put empty line to history", (VAR*)0},
! 17: {"ignore-same-line", "",
! 18: "Don't put same line to history", (VAR*)0},
! 19: {"editmode", "emacs",
! 20: "Fep command line edit mode", (VAR*)0},
! 21: {"history-file", ".fephistory",
! 22: "Name of history file", (VAR*)0},
! 23: {"shell", "/bin/sh",
! 24: "Shell name used by invoke-shell", (VAR*)0},
! 25: {"auto-tty-fix", "",
! 26: "Fix tty mode automatically", (VAR*)0},
! 27: {"script-file", "fepscript",
! 28: "Script file name", (VAR*)0},
! 29: {"crt", "24",
! 30: "Terminal lines", (VAR*)0},
! 31: {"showhist", "24",
! 32: "History length used by show-history", (VAR*)0},
! 33: {"delimiters", " \t",
! 34: "Argument delemiter characters", (VAR*)0},
! 35: {"buffer", "5120",
! 36: "Output buffer size", (VAR*)0},
! 37: {NULL, NULL,
! 38: NULL, (VAR*)0}
! 39: };
! 40:
! 41: VAR default_unset_vars [] = {
! 42: /* below from here is unset by default */
! 43: {"alarm-on-eof", "",
! 44: "Alarm once to eof character", (VAR*)0},
! 45: {"ignore-eof", "",
! 46: "Never treat eof character as eof", (VAR*)0},
! 47: {"savehist", "",
! 48: "Length of save history", (VAR*)0},
! 49: {"verbose", "",
! 50: NULL, (VAR*)0},
! 51: {"search-string", "",
! 52: NULL, (VAR*)0},
! 53: {"noalias", "",
! 54: "Not use alias", (VAR*)0},
! 55: {"tty-fix-bell", "",
! 56: "Ring bell when tty mode changed", (VAR*)0},
! 57: {"auto-repaint", "",
! 58: "Repaint screen when restarting", (VAR*)0},
! 59: {"clear-repaint", "",
! 60: "Clear screen before repaint", (VAR*)0},
! 61: {"ignore-short-line", "3",
! 62: "Don't put short line to history", (VAR*)0},
! 63: {NULL, NULL,
! 64: NULL, (VAR*)0}
! 65: };
! 66:
! 67: #ifdef HASH
! 68: #define HASHNUM 10
! 69: VAR *var_htab[HASHNUM];
! 70: #else /* HASH */
! 71: VAR var_top = {"top", "top", (char *)0, (VAR *)0};
! 72: VAR *var_list = &var_top;
! 73: #endif /* HASH */
! 74:
! 75: /*
! 76: * Functions
! 77: */
! 78: int set_var (/* char *name, char *value */);
! 79: char *look_var (/* char *name */);
! 80: int lookd_var (/* char *name */);
! 81: VAR *getvp (/* char *name */);
! 82:
! 83: extern char *allocAndCopyThere();
! 84: extern char *prompt;
! 85:
! 86: /*
! 87: * Set default variables
! 88: */
! 89: set_default_vars ()
! 90: {
! 91: register VAR *vp;
! 92:
! 93: for (vp = default_set_vars; vp->v_name; vp++)
! 94: set_only_var (vp->v_name, vp->v_value);
! 95: }
! 96:
! 97: /*
! 98: * Set variable
! 99: */
! 100: set_var (name, value)
! 101: char *name;
! 102: char *value;
! 103: {
! 104: /*
! 105: * Process special variable
! 106: */
! 107: if (eq (name, "history")) {
! 108: if (!changeHistorySize (atoi (value)))
! 109: return (0);
! 110: }
! 111: else if (eq (name, "prompt")) {
! 112: free (prompt);
! 113: prompt = allocAndCopyThere (value);
! 114: }
! 115: else if (eq (name, "editmode")) {
! 116: if (eq (value, "emacs")) {
! 117: editmode = EMACS;
! 118: initEmacsBindings (curFuncTab, altFuncTab);
! 119: }
! 120: else if (eq (value, "vi")) {
! 121: editmode = VI;
! 122: initViBindings (curFuncTab, altFuncTab);
! 123: }
! 124: else
! 125: printf ("%s: Unknown editmode\n", value);
! 126: }
! 127: else if (eq (name, "auto-tty-fix"))
! 128: auto_tty_fix = ON;
! 129: else if (eq (name, "debug"))
! 130: debug = ON;
! 131: else if (eq (name, "tty-fix-bell"))
! 132: tty_fix_bell = ON;
! 133: else if (eq (name, "delimiters")) {
! 134: /* only in this case, variable points allocated area */
! 135: set_only_var (name, value);
! 136: delimiters = look_var ("delimiters");
! 137: }
! 138: else if (eq (name, "crt"))
! 139: lines = atoi (value);
! 140: else if (eq(name, "buffer")) {
! 141: int s;
! 142:
! 143: if ((s = atoi(value)) <= 0)
! 144: return;
! 145:
! 146: if (!set_buffer (output_buffer, s))
! 147: return;
! 148: }
! 149:
! 150: set_only_var (name, value);
! 151: }
! 152:
! 153: set_only_var (name, value)
! 154: char *name, *value;
! 155: {
! 156: VAR *vp;
! 157:
! 158: vp = getvp (name, 1, 0);
! 159:
! 160: if (vp->v_value == value)
! 161: return;
! 162:
! 163: if (vp->v_value)
! 164: free (vp->v_value);
! 165:
! 166: vp->v_value = allocAndCopyThere (value);
! 167: }
! 168:
! 169: /*
! 170: * Unset variable
! 171: */
! 172: unset_var (name)
! 173: char *name;
! 174: {
! 175: VAR *vp, *prev;
! 176:
! 177: vp = getvp (name, 0, &prev);
! 178:
! 179: if (!vp)
! 180: return;
! 181:
! 182: prev->v_next = vp->v_next;
! 183: free (vp->v_name);
! 184: free (vp->v_value);
! 185: free (vp);
! 186:
! 187: if (eq (name, "auto-tty-fix"))
! 188: auto_tty_fix = OFF;
! 189:
! 190: if (eq (name, "debug"))
! 191: debug = OFF;
! 192:
! 193: if (eq (name, "tty-fix-bell"))
! 194: tty_fix_bell = OFF;
! 195:
! 196: if (eq (name, "delimiters"))
! 197: delimiters = DEFAULT_DELIMITERS;
! 198: return;
! 199: }
! 200:
! 201: /*
! 202: * Look up variable
! 203: */
! 204: char *
! 205: look_var (name)
! 206: char *name;
! 207: {
! 208:
! 209: VAR *vp;
! 210:
! 211: vp = getvp (name, 0, 0);
! 212:
! 213: if (vp && vp->v_value)
! 214: return (vp->v_value);
! 215: else
! 216: return ((char *)0);
! 217: }
! 218:
! 219: /*
! 220: * Look up variable and get integer result
! 221: */
! 222: int
! 223: lookd_var (name)
! 224: char *name;
! 225: {
! 226: VAR *vp;
! 227:
! 228: vp = getvp (name, 0, 0);
! 229:
! 230: if (vp && vp->v_value)
! 231: return (atoi (vp->v_value));
! 232: else
! 233: return (0);
! 234: }
! 235:
! 236: /*
! 237: * Show variable list
! 238: */
! 239: show_varlist ()
! 240: {
! 241: #ifdef HASH
! 242: register int i;
! 243:
! 244: for (i = 0; i< HASHNUM; i++) {
! 245: register VAR *vp;
! 246:
! 247: vp = var_htab[i];
! 248: if (vp == (VAR *)0)
! 249: continue;
! 250:
! 251: for (; vp != (VAR *)0; vp = vp->v_next)
! 252: printf ("%-16s %s\n", vp->v_name, vp->v_value);
! 253: }
! 254: #else /* HASH */
! 255: register VAR *vp;
! 256:
! 257: for (vp = var_list->v_next; vp; vp = vp->v_next)
! 258: printf ("%-16s %s\n", vp->v_name, vp->v_value);
! 259: #endif /* HASH */
! 260: }
! 261:
! 262: #ifdef HASH
! 263: /*
! 264: * Get hash index from variable name
! 265: */
! 266: static getindex (s)
! 267: register char *s;
! 268: {
! 269: register int sum = 0;
! 270:
! 271: while (*s)
! 272: sum += *s++;
! 273:
! 274: return (sum % HASHNUM);
! 275: }
! 276: #endif /* HASH */
! 277:
! 278: /*
! 279: * Get pointer to VAR.
! 280: * If there is no memoly associated to the variable and alloc argument is 1,
! 281: * allocate the area and initialize name field.
! 282: */
! 283: VAR *
! 284: getvp (name, alloc, lastvp)
! 285: char *name;
! 286: int alloc;
! 287: VAR **lastvp;
! 288: {
! 289: #ifdef HASH
! 290: register i = getindex (name);
! 291: #endif /* HASH */
! 292: VAR *vp, *last = (VAR *)0;
! 293:
! 294: #ifdef HASH
! 295: for (vp = var_htab[i]; vp; last = vp, vp->v_next) {
! 296: if (strcmp (name, vp->v_value) == 0)
! 297: return (vp);
! 298: }
! 299: #else /* HASH */
! 300: for (vp = var_list->v_next, last = var_list; vp; last = vp, vp = vp->v_next) {
! 301: int r;
! 302:
! 303: r = strcmp (name, vp->v_name);
! 304: if (r == 0) {
! 305: if (lastvp)
! 306: *lastvp = last;
! 307: return (vp);
! 308: }
! 309: else if (r < 0)
! 310: break;
! 311: }
! 312: #endif /* HASH */
! 313:
! 314: if (alloc == 0)
! 315: return (0);
! 316:
! 317: vp = (VAR *) calloc (sizeof (VAR), 1);
! 318: vp->v_value = (char *)0;
! 319: vp->v_next = (VAR *) 0;
! 320: vp->v_name = allocAndCopyThere (name);
! 321:
! 322: #ifdef HASH
! 323: if (last) {
! 324: vp->v_next = last->v_next;
! 325: last->v_next = vp;
! 326: }
! 327: else {
! 328: var_htab[i] = vp;
! 329: }
! 330: #else /* HASH */
! 331: vp->v_next = last->v_next;
! 332: last->v_next = vp;
! 333: #endif /* HASH */
! 334: return (vp);
! 335: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>