home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / EVAL.C < prev    next >
C/C++ Source or Header  |  1991-10-30  |  35KB  |  1,382 lines

  1. /*    EVAL.C: Expresion evaluation functions for
  2.         MicroEMACS
  3.  
  4.     written 1986 by Daniel Lawrence             */
  5.  
  6. #include    <stdio.h>
  7. #include    "estruct.h"
  8. #include    "eproto.h"
  9. #include    "edef.h"
  10. #include    "elang.h"
  11. #include    "evar.h"
  12.  
  13. PASCAL NEAR varinit()    /* initialize the user variable list */
  14.  
  15. {
  16.     register int i;
  17.  
  18.     for (i=0; i < MAXVARS; i++)
  19.         uv[i].u_name[0] = 0;
  20. }
  21.  
  22. PASCAL NEAR varclean()    /* initialize the user variable list */
  23.  
  24. {
  25.     register int i;
  26.  
  27.     for (i=0; i < MAXVARS; i++)
  28.         if (uv[i].u_name[0] != 0)
  29.             free(uv[i].u_value);
  30. }
  31.  
  32. char *PASCAL NEAR gtfun(fname)    /* evaluate a function */
  33.  
  34. char *fname;        /* name of function to evaluate */
  35.  
  36. {
  37.     register int fnum;        /* index to function to eval */
  38.     register int arg;        /* value of some arguments */
  39.     char arg1[NSTRING];        /* value of first argument */
  40.     char arg2[NSTRING];        /* value of second argument */
  41.     char arg3[NSTRING];        /* value of third argument */
  42.     static char result[2 * NSTRING];    /* string result */
  43. #if    ENVFUNC
  44.     char *getenv();         /* get environment string */
  45. #endif
  46.  
  47.     /* look the function up in the function table */
  48.     fname[3] = 0;    /* only first 3 chars significant */
  49.     mklower(fname); /* and let it be upper or lower case */
  50.     fnum = binary(fname, funval, NFUNCS);
  51.  
  52.     /* return errorm on a bad reference */
  53.     if (fnum == -1)
  54.         return(errorm);
  55.  
  56.     /* if needed, retrieve the first argument */
  57.     if (funcs[fnum].f_type >= MONAMIC) {
  58.         if (macarg(arg1) != TRUE)
  59.             return(errorm);
  60.  
  61.         /* if needed, retrieve the second argument */
  62.         if (funcs[fnum].f_type >= DYNAMIC) {
  63.             if (macarg(arg2) != TRUE)
  64.                 return(errorm);
  65.  
  66.             /* if needed, retrieve the third argument */
  67.             if (funcs[fnum].f_type >= TRINAMIC)
  68.                 if (macarg(arg3) != TRUE)
  69.                     return(errorm);
  70.         }
  71.     }
  72.  
  73.  
  74.     /* and now evaluate it! */
  75.     switch (fnum) {
  76.         case UFADD:    return(int_asc(asc_int(arg1) + asc_int(arg2)));
  77.         case UFSUB:    return(int_asc(asc_int(arg1) - asc_int(arg2)));
  78.         case UFTIMES:    return(int_asc(asc_int(arg1) * asc_int(arg2)));
  79.         case UFDIV:    return(int_asc(asc_int(arg1) / asc_int(arg2)));
  80.         case UFMOD:    return(int_asc(asc_int(arg1) % asc_int(arg2)));
  81.         case UFNEG:    return(int_asc(-asc_int(arg1)));
  82.         case UFCAT:    strcpy(result, arg1);
  83.                 return(strcat(result, arg2));
  84.         case UFLEFT:    return(bytecopy(result, arg1, asc_int(arg2)));
  85.         case UFRIGHT:    arg = asc_int(arg2);
  86.                 if (arg > strlen(arg1))
  87.                     arg = strlen(arg1);
  88.                 return(strcpy(result,
  89.                     &arg1[strlen(arg1) - arg]));
  90.         case UFMID:    arg = asc_int(arg2);
  91.                 if (arg > strlen(arg1))
  92.                     arg = strlen(arg1);
  93.                 return(bytecopy(result, &arg1[arg-1],
  94.                     asc_int(arg3)));
  95.         case UFNOT:    return(ltos(stol(arg1) == FALSE));
  96.         case UFEQUAL:    return(ltos(asc_int(arg1) == asc_int(arg2)));
  97.         case UFLESS:    return(ltos(asc_int(arg1) < asc_int(arg2)));
  98.         case UFGREATER: return(ltos(asc_int(arg1) > asc_int(arg2)));
  99.         case UFGROUP:
  100.                 if ((arg = asc_int(arg1)) < 0 || arg >= MAXGROUPS)
  101.                     return(bytecopy(result, errorm, NSTRING * 2));
  102.                     
  103. #if    MAGIC
  104.                 return(bytecopy(result, fixnull(grpmatch[arg]),
  105.                      NSTRING * 2));
  106. #else
  107.                 if (arg == 0)
  108.                     bytecopy(result, patmatch, NSTRING * 2);
  109.                 else
  110.                     result[0] = '\0';
  111.                 return(result);
  112. #endif
  113.         case UFSEQUAL:    return(ltos(strcmp(arg1, arg2) == 0));
  114.         case UFSLESS:    return(ltos(strcmp(arg1, arg2) < 0));
  115.         case UFSGREAT:    return(ltos(strcmp(arg1, arg2) > 0));
  116.         case UFIND:    return(strcpy(result, fixnull(getval(arg1))));
  117.         case UFAND:    return(ltos(stol(arg1) && stol(arg2)));
  118.         case UFOR:    return(ltos(stol(arg1) || stol(arg2)));
  119.         case UFLENGTH:    return(int_asc(strlen(arg1)));
  120.         case UFUPPER:    return(mkupper(arg1));
  121.         case UFLOWER:    return(mklower(arg1));
  122.         case UFTRUTH:    return(ltos(asc_int(arg1) == 42));
  123.         case UFASCII:    return(int_asc((int)arg1[0]));
  124.         case UFCHR:    result[0] = asc_int(arg1);
  125.                 result[1] = 0;
  126.                 return(result);
  127.         case UFGTCMD:    cmdstr(getcmd(), result);
  128.                 return(result);
  129.         case UFGTKEY:    result[0] = tgetc();
  130.                 result[1] = 0;
  131.                 return(result);
  132.         case UFRND:    return(int_asc((ernd() % absv(asc_int(arg1))) + 1));
  133.         case UFABS:    return(int_asc(absv(asc_int(arg1))));
  134.         case UFSINDEX:    return(int_asc(sindex(arg1, arg2)));
  135.         case UFENV:
  136. #if    ENVFUNC
  137.                 return(fixnull(getenv(arg1)));
  138. #else
  139.                 return("");
  140. #endif
  141.         case UFBIND:    return(transbind(arg1));
  142.         case UFEXIST:    return(ltos(fexist(arg1)));
  143.         case UFFIND:
  144.                 return(fixnull(flook(arg1, TRUE)));
  145.         case UFBAND:    return(int_asc(asc_int(arg1) & asc_int(arg2)));
  146.         case UFBOR:    return(int_asc(asc_int(arg1) | asc_int(arg2)));
  147.         case UFBXOR:    return(int_asc(asc_int(arg1) ^ asc_int(arg2)));
  148.         case UFBNOT:    return(int_asc(~asc_int(arg1)));
  149.         case UFXLATE:    return(xlat(arg1, arg2, arg3));
  150.         case UFTRIM:    return(trimstr(arg1));
  151.         case UFSLOWER:    return(setlower(arg1, arg2), "");
  152.         case UFSUPPER:    return(setupper(arg1, arg2), "");
  153.          case UFISNUM:    return(ltos(is_num(arg1)));
  154.     }
  155.  
  156.     meexit(-11);    /* never should get here */
  157. }
  158.  
  159. char *PASCAL NEAR gtusr(vname)    /* look up a user var's value */
  160.  
  161. char *vname;        /* name of user variable to fetch */
  162.  
  163. {
  164.     register int vnum;    /* ordinal number of user var */
  165.     register char *vptr;    /* temp pointer to function value */
  166.  
  167.     /* limit comparisons to significant length */
  168.     if (strlen(vname) >= NVSIZE)    /* "%" counts, but is not passed */
  169.         vname[NVSIZE-1] = '\0';
  170.  
  171.     /* scan the list looking for the user var name */
  172.     for (vnum = 0; vnum < MAXVARS; vnum++) {
  173.         if (uv[vnum].u_name[0] == 0)
  174.             return(errorm);
  175.         if (strcmp(vname, uv[vnum].u_name) == 0) {
  176.             vptr = uv[vnum].u_value;
  177.             if (vptr)
  178.                 return(vptr);
  179.             else
  180.                 return(errorm);
  181.         }
  182.     }
  183.  
  184.     /* return errorm if we run off the end */
  185.     return(errorm);
  186. }
  187.  
  188. char *PASCAL NEAR funval(i)
  189.  
  190. int i;
  191.  
  192. {
  193.     return(funcs[i].f_name);
  194. }
  195.  
  196. char *PASCAL NEAR envval(i)
  197.  
  198. int i;
  199.  
  200. {
  201.     return(envars[i]);
  202. }
  203.  
  204. PASCAL NEAR binary(key, tval, tlength)
  205.  
  206. char *key;        /* key string to look for */
  207. char *(PASCAL NEAR *tval)();    /* ptr to function to fetch table value with */
  208. int tlength;        /* length of table to search */
  209.  
  210. {
  211.     int l, u;    /* lower and upper limits of binary search */
  212.     int i;        /* current search index */
  213.     int cresult;    /* result of comparison */
  214.  
  215.     /* set current search limit as entire list */
  216.     l = 0;
  217.     u = tlength - 1;
  218.  
  219.     /* get the midpoint! */
  220.     while (u >= l) {
  221.         i = (l + u) >> 1;
  222.  
  223.         /* do the comparison */
  224.         cresult = strcmp(key, (*tval)(i));
  225.         if (cresult == 0)
  226.             return(i);
  227.         if (cresult < 0)
  228.             u = i - 1;
  229.         else
  230.             l = i + 1;
  231.     }
  232.     return(-1);
  233. }
  234.  
  235. char *PASCAL NEAR gtenv(vname)
  236.  
  237. char *vname;        /* name of environment variable to retrieve */
  238.  
  239. {
  240.     register int vnum;    /* ordinal number of var refrenced */
  241.     static char result[2 * NSTRING];    /* string result */
  242.  
  243.     /* scan the list, looking for the referenced name */
  244.     vnum = binary(vname, envval, NEVARS);
  245.  
  246.     /* return errorm on a bad reference */
  247.     if (vnum == -1)
  248.         return(errorm);
  249.  
  250.     /* otherwise, fetch the appropriate value */
  251.     switch (vnum) {
  252.         case EVFILLCOL: return(int_asc(fillcol));
  253.         case EVPAGELEN: return(int_asc(term.t_nrow + 1));
  254.         case EVCURCOL:    return(int_asc(getccol(FALSE)));
  255.         case EVCURLINE: return(int_asc(getlinenum(curbp, curwp->w_dotp)));
  256.         case EVRAM:    return(int_asc((int)(envram / 1024l)));
  257.         case EVFLICKER: return(ltos(flickcode));
  258.         case EVCURWIDTH:return(int_asc(term.t_ncol));
  259.         case EVCBFLAGS: return(int_asc(curbp->b_flag));
  260.         case EVCBUFNAME:return(curbp->b_bname);
  261.         case EVCFNAME:    return(curbp->b_fname);
  262.         case EVSRES:    return(sres);
  263.         case EVDEBUG:    return(ltos(macbug));
  264.         case EVSTATUS:    return(ltos(cmdstatus));
  265.         case EVPALETTE: return(palstr);
  266.         case EVASAVE:    return(int_asc(gasave));
  267.         case EVACOUNT:    return(int_asc(gacount));
  268.         case EVLASTKEY: return(int_asc(lastkey));
  269.         case EVCURCHAR:
  270.             return(curwp->w_dotp->l_used ==
  271.                     curwp->w_doto ? int_asc('\r') :
  272.                 int_asc(lgetc(curwp->w_dotp, curwp->w_doto)));
  273.         case EVDISCMD:    return(ltos(discmd));
  274.         case EVVERSION: return(VERSION);
  275.         case EVPROGNAME:return(PROGNAME);
  276.         case EVLANG:    return(LANGUAGE);
  277.         case EVSEED:    return(int_asc(seed));
  278.         case EVDISINP:    return(ltos(disinp));
  279.         case EVWLINE:    return(int_asc(curwp->w_ntrows));
  280.         case EVCWLINE:    return(int_asc(getwpos()));
  281.         case EVTARGET:    saveflag = lastflag;
  282.                 return(int_asc(curgoal));
  283.         case EVSEARCH:    return(pat);
  284.         case EVTIME:    return(timeset());
  285.         case EVREPLACE: return(rpat);
  286.         case EVMATCH:    return(fixnull(patmatch));
  287.         case EVKILL:    return(getkill());
  288.         case EVREGION:    return(getreg(result));
  289.         case EVCMODE:    return(int_asc(curbp->b_mode));
  290.         case EVGMODE:    return(int_asc(gmode));
  291.         case EVTPAUSE:    return(int_asc(term.t_pause));
  292.         case EVPENDING:
  293. #if    TYPEAH
  294.                 return(ltos(typahead()));
  295. #else
  296.                 return(falsem);
  297. #endif
  298.         case EVLWIDTH:    return(int_asc(llength(curwp->w_dotp)));
  299.         case EVLINE:    return(getctext());
  300.         case EVGFLAGS:    return(int_asc(gflags));
  301.         case EVRVAL:    return(int_asc(rval));
  302.         case EVREADHK:    return(fixnull(getfname(&readhook)));
  303.         case EVWRAPHK:    return(fixnull(getfname(&wraphook)));
  304.         case EVCMDHK:    return(fixnull(getfname(&cmdhook)));
  305.         case EVXPOS:    return(int_asc(xpos));
  306.         case EVYPOS:    return(int_asc(ypos));
  307.         case EVSTERM:    cmdstr(sterm, result);
  308.                 return(result);
  309.         case EVMODEFLAG:return(ltos(modeflag));
  310.         case EVSSCROLL: return(ltos(sscroll));
  311.         case EVLASTMESG:return(lastmesg);
  312.         case EVHARDTAB: return(int_asc(tabsize));
  313.         case EVSOFTTAB: return(int_asc(stabsize));
  314.         case EVSSAVE:    return(ltos(ssave));
  315.         case EVFCOL:    return(int_asc(curwp->w_fcol));
  316.         case EVHSCROLL: return(ltos(hscroll));
  317.         case EVHJUMP:    return(int_asc(hjump));
  318.         case EVBUFHOOK: return(fixnull(getfname(&bufhook)));
  319.         case EVEXBHOOK: return(fixnull(getfname(&exbhook)));
  320.         case EVWRITEHK: return(fixnull(getfname(&writehook)));
  321.         case EVDIAGFLAG:return(ltos(diagflag));
  322.         case EVMSFLAG:    return(ltos(mouseflag));
  323.         case EVOCRYPT:    return(ltos(oldcrypt));
  324.         case EVSEARCHPNT:    return(int_asc(searchtype));
  325.         case EVDISPHIGH:return(ltos(disphigh));
  326.         case EVLTERM:    return(lterm);
  327.         case EVPARALEAD:return(paralead);
  328.         case EVFMTLEAD:    return(fmtlead);
  329.         case EVWCHARS:    return(getwlist(result));
  330.         case EVPOPFLAG: return(ltos(popflag));
  331.         case EVYANKFLAG:    return(ltos(yankflag));
  332.         case EVSCRNAME:    return(first_screen->s_screen_name);
  333.         case EVCURWIND: return(int_asc(getcwnum()));
  334.         case EVNUMWIND: return(int_asc(gettwnum()));
  335.         case EVORGCOL:    return(int_asc(term.t_colorg));
  336.         case EVORGROW:    return(int_asc(term.t_roworg));
  337.         case EVDESKCLR:    return(cname[deskcolor]);
  338.     }
  339.     meexit(-12);    /* again, we should never get here */
  340. }
  341.  
  342. char *PASCAL NEAR fixnull(s)    /* Don't return NULL pointers! */
  343.  
  344. char *s;
  345.  
  346. {
  347.     if (s == NULL)
  348.         return("");
  349.     else
  350.         return(s);
  351. }
  352.  
  353. /* return some of the contents of the kill buffer */
  354.  
  355. char *PASCAL NEAR getkill()
  356.  
  357. {
  358.     register int size;    /* max number of chars left to return */
  359.     register char *sp;    /* ptr into KILL block data chunk */
  360.     register char *vp;    /* ptr into return value */
  361.     KILL *kptr;        /* ptr to the current KILL block */
  362.     int counter;        /* index into data chunk */
  363.     static char value[NSTRING];    /* temp buffer for value */
  364.  
  365.     /* no kill buffer....just a null string */
  366.     if (kbufh == (KILL *)NULL) {
  367.         value[0] = 0;
  368.         return(value);
  369.     }
  370.  
  371.     /* set up the output buffer */
  372.     vp = value;
  373.     size = NSTRING - 1;
  374.  
  375.     /* backed up characters? */
  376.     if (kskip > 0) {
  377.         kptr = kbufh;
  378.         sp = &(kptr->d_chunk[kskip]);
  379.         counter = kskip;
  380.         while (counter++ < KBLOCK) {
  381.             *vp++ = *sp++;
  382.             if (--size == 0) {
  383.                 *vp = 0;
  384.                 return(value);
  385.             }
  386.         }
  387.         kptr = kptr->d_next;
  388.     } else {
  389.         kptr = kbufh;
  390.     }
  391.  
  392.     if (kptr != (KILL *)NULL) {
  393.         while (kptr != kbufp) {
  394.             sp = kptr->d_chunk;
  395.             for (counter = 0; counter < KBLOCK; counter++) {
  396.                 *vp++ = *sp++;
  397.                 if (--size == 0) {
  398.                     *vp = 0;
  399.                     return(value);
  400.                 }
  401.             }
  402.             kptr = kptr->d_next;
  403.         }
  404.         counter = kused;
  405.         sp = kptr->d_chunk;
  406.         while (counter--) {
  407.             *vp++ = *sp++;
  408.             if (--size == 0) {
  409.                 *vp = 0;
  410.                 return(value);
  411.             }
  412.         }
  413.     }
  414.     
  415.     /* and return the constructed value */
  416.     *vp = 0;
  417.     return(value);
  418. }
  419.  
  420. char *PASCAL NEAR trimstr(s)    /* trim whitespace off the end of a string */
  421.  
  422. char *s;    /* string to trim */
  423.  
  424. {
  425.     char *sp;    /* backward index */
  426.  
  427.     sp = s + strlen(s) - 1;
  428.     while ((sp >= s) && (*sp == ' ' || *sp == '\t'))
  429.         --sp;
  430.     *(sp+1) = 0;
  431.     return(s);
  432. }
  433.  
  434. int PASCAL NEAR setvar(f, n)        /* set a variable */
  435.  
  436. int f;        /* default flag */
  437. int n;        /* numeric arg (can overide prompted value) */
  438.  
  439. {
  440.     register int status;    /* status return */
  441.     VDESC vd;        /* variable num/type */
  442.     char var[NVSIZE+1];    /* name of variable to fetch */
  443.     char value[NSTRING];    /* value to set variable to */
  444.  
  445.     /* first get the variable to set.. */
  446.     if (clexec == FALSE) {
  447.         status = mlreply(TEXT51, &var[0], NVSIZE+1);
  448. /*                 "Variable to set: " */
  449.         if (status != TRUE)
  450.             return(status);
  451.     } else {    /* macro line argument */
  452.         /* grab token and skip it */
  453.         execstr = token(execstr, var, NVSIZE + 1);
  454.     }
  455.  
  456.     /* check the legality and find the var */
  457.     findvar(var, &vd, NVSIZE + 1);
  458.         
  459.     /* if its not legal....bitch */
  460.     if (vd.v_type == -1) {
  461.         mlwrite(TEXT52, var);
  462. /*            "%%No such variable as '%s'" */
  463.         return(FALSE);
  464.     }
  465.  
  466.     /* get the value for that variable */
  467.     if (f == TRUE)
  468.         strcpy(value, int_asc(n));
  469.     else {
  470.         status = mlreply(TEXT53, &value[0], NSTRING);
  471. /*                 "Value: " */
  472.         if (status == ABORT)
  473.             return(status);
  474.     }
  475.  
  476.     /* and set the appropriate value */
  477.     status = svar(&vd, value);
  478.  
  479. #if    DEBUGM
  480.     /* if $debug == TRUE, every assignment will echo a statment to
  481.        that effect here. */
  482.         
  483.     if (macbug && (strcmp(var, "%track") != 0)) {
  484.         strcpy(outline, "(((");
  485.  
  486.         strcat(outline, var);
  487.         strcat(outline, " <- ");
  488.  
  489.         /* and lastly the value we tried to assign */
  490.         strcat(outline, value);
  491.         strcat(outline, ")))");
  492.  
  493.         /* expand '%' to "%%" so mlwrite wont bitch */
  494.         makelit(outline);
  495.  
  496.         /* write out the debug line */
  497.         mlforce(outline);
  498.         update(TRUE);
  499.  
  500.         /* and get the keystroke to hold the output */
  501.         if (getkey() == abortc) {
  502.             mlforce(TEXT54);
  503. /*                "[Macro aborted]" */
  504.             status = FALSE;
  505.         }
  506.     }
  507. #endif
  508.  
  509.     /* and return it */
  510.     return(status);
  511. }
  512.  
  513. PASCAL NEAR findvar(var, vd, size)    /* find a variables type and name */
  514.  
  515. char *var;    /* name of var to get */
  516. VDESC *vd;    /* structure to hold type and ptr */
  517. int size;    /* size of var array */
  518.  
  519. {
  520.     register int vnum;    /* subscript in varable arrays */
  521.     register int vtype;    /* type to return */
  522.  
  523. fvar:    vtype = -1;
  524.     switch (var[0]) {
  525.  
  526.         case '$': /* check for legal enviromnent var */
  527.             for (vnum = 0; vnum < NEVARS; vnum++)
  528.                 if (strcmp(&var[1], envars[vnum]) == 0) {
  529.                     vtype = TKENV;
  530.                     break;
  531.                 }
  532.             break;
  533.  
  534.         case '%': /* check for existing legal user variable */
  535.             for (vnum = 0; vnum < MAXVARS; vnum++)
  536.                 if (strcmp(&var[1], uv[vnum].u_name) == 0) {
  537.                     vtype = TKVAR;
  538.                     break;
  539.                 }
  540.             if (vnum < MAXVARS)
  541.                 break;
  542.  
  543.             /* create a new one??? */
  544.             for (vnum = 0; vnum < MAXVARS; vnum++)
  545.                 if (uv[vnum].u_name[0] == 0) {
  546.                     vtype = TKVAR;
  547.                     strcpy(uv[vnum].u_name, &var[1]);
  548.                     uv[vnum].u_value = NULL;
  549.                     break;
  550.                 }
  551.             break;
  552.  
  553.         case '&':    /* indirect operator? */
  554.             var[4] = 0;
  555.             if (strcmp(&var[1], "ind") == 0) {
  556.                 /* grab token, and eval it */
  557.                 execstr = token(execstr, var, size);
  558.                 strcpy(var, fixnull(getval(var)));
  559.                 goto fvar;
  560.             }
  561.     }
  562.  
  563.     /* return the results */
  564.     vd->v_num = vnum;
  565.     vd->v_type = vtype;
  566.     return;
  567. }
  568.  
  569. int PASCAL NEAR svar(var, value)    /* set a variable */
  570.  
  571. VDESC *var;    /* variable to set */
  572. char *value;    /* value to set to */
  573.  
  574. {
  575.     register int vnum;    /* ordinal number of var refrenced */
  576.     register int vtype;    /* type of variable to set */
  577.     register int status;    /* status return */
  578.     register int c;     /* translated character */
  579.     register char *sp;    /* scratch string pointer */
  580.  
  581.     /* simplify the vd structure (we are gonna look at it a lot) */
  582.     vnum = var->v_num;
  583.     vtype = var->v_type;
  584.  
  585.     /* and set the appropriate value */
  586.     status = TRUE;
  587.     switch (vtype) {
  588.     case TKVAR: /* set a user variable */
  589.         if (uv[vnum].u_value != NULL)
  590.             free(uv[vnum].u_value);
  591.         sp = malloc(strlen(value) + 1);
  592.         if (sp == NULL)
  593.             return(FALSE);
  594.         strcpy(sp, value);
  595.         uv[vnum].u_value = sp;
  596.         break;
  597.  
  598.     case TKENV: /* set an environment variable */
  599.         status = TRUE;    /* by default */
  600.         switch (vnum) {
  601.         case EVFILLCOL: fillcol = asc_int(value);
  602.                 break;
  603.         case EVPAGELEN: status = newsize(TRUE, asc_int(value));
  604.                 break;
  605.         case EVCURCOL:    status = setccol(asc_int(value));
  606.                 break;
  607.         case EVCURLINE: status = gotoline(TRUE, asc_int(value));
  608.                 break;
  609.         case EVRAM:    break;
  610.         case EVFLICKER: flickcode = stol(value);
  611.                 break;
  612.         case EVCURWIDTH:status = newwidth(TRUE, asc_int(value));
  613.                 break;
  614.         case EVCBFLAGS: curbp->b_flag = (curbp->b_flag & ~(BFCHG|BFINVS))
  615.                     | (asc_int(value) & (BFCHG|BFINVS));
  616.                 lchange(WFMODE);
  617.                 break;
  618.         case EVCBUFNAME:strcpy(curbp->b_bname, value);
  619.                 curwp->w_flag |= WFMODE;
  620.                 break;
  621.         case EVCFNAME:    strcpy(curbp->b_fname, value);
  622.                 curwp->w_flag |= WFMODE;
  623.                 break;
  624.         case EVSRES:    status = TTrez(value);
  625.                 break;
  626.         case EVDEBUG:    macbug = stol(value);
  627.                 break;
  628.         case EVSTATUS:    cmdstatus = stol(value);
  629.                 break;
  630.         case EVPALETTE: bytecopy(palstr, value, 48);
  631.                 spal(palstr);
  632.                 break;
  633.         case EVASAVE:    gasave = asc_int(value);
  634.                 break;
  635.         case EVACOUNT:    gacount = asc_int(value);
  636.                 break;
  637.         case EVLASTKEY: lastkey = asc_int(value);
  638.                 break;
  639.         case EVCURCHAR: ldelete(1L, FALSE);    /* delete 1 char */
  640.                 c = asc_int(value);
  641.                 if (c == '\r')
  642.                     lnewline();
  643.                 else
  644.                     linsert(1, (char)c);
  645.                 backchar(FALSE, 1);
  646.                 break;
  647.         case EVDISCMD:    discmd = stol(value);
  648.                 break;
  649.         case EVVERSION: break;
  650.         case EVPROGNAME:break;
  651.         case EVLANG:    break;
  652.         case EVSEED:    seed = asc_int(value);
  653.                 break;
  654.         case EVDISINP:    disinp = stol(value);
  655.                 break;
  656.         case EVWLINE:    status = resize(TRUE, asc_int(value));
  657.                 break;
  658.         case EVCWLINE:    status = forwline(TRUE,
  659.                         asc_int(value) - getwpos());
  660.                 break;
  661.         case EVTARGET:    curgoal = asc_int(value);
  662.                 thisflag = saveflag;
  663.                 break;
  664.         case EVSEARCH:    strcpy(pat, value);
  665.                 setjtable(); /* Set up fast search arrays  */
  666. #if    MAGIC
  667.                 mcclear();
  668. #endif
  669.                 break;
  670.         case EVTIME:    break;
  671.         case EVREPLACE: strcpy(rpat, value);
  672. #if    MAGIC
  673.                 rmcclear();
  674. #endif 
  675.                 break;
  676.         case EVMATCH:    break;
  677.         case EVKILL:    break;
  678.         case EVREGION:    break;
  679.         case EVCMODE:    curbp->b_mode = asc_int(value);
  680.                 curwp->w_flag |= WFMODE;
  681.                 break;
  682.         case EVGMODE:    gmode = asc_int(value);
  683.                 break;
  684.         case EVTPAUSE:    term.t_pause = asc_int(value);
  685.                 break;
  686.         case EVPENDING: break;
  687.         case EVLWIDTH:    break;
  688.         case EVLINE:    putctext(value);
  689.                 break;
  690.         case EVGFLAGS:    gflags = asc_int(value);
  691.                 break;
  692.         case EVRVAL:    break;
  693.         case EVREADHK:    setkey(&readhook, value);
  694.                 break;
  695.         case EVWRAPHK:    setkey(&wraphook, value);
  696.                 break;
  697.         case EVCMDHK:    setkey(&cmdhook, value);
  698.                 break;
  699.         case EVXPOS:    xpos = asc_int(value);
  700.                 break;
  701.         case EVYPOS:    ypos = asc_int(value);
  702.                 break;
  703.         case EVSTERM:    sterm = stock(value);
  704.                 break;
  705.         case EVMODEFLAG:modeflag = stol(value);
  706.                 upwind();
  707.                 break;
  708.         case EVSSCROLL: sscroll = stol(value);
  709.                 break;
  710.         case EVLASTMESG:strcpy(lastmesg, value);
  711.                 break;
  712.         case EVHARDTAB: tabsize = asc_int(value);
  713.                 upwind();
  714.                 break;
  715.         case EVSOFTTAB: stabsize = asc_int(value);
  716.                 upwind();
  717.                 break;
  718.         case EVSSAVE:    ssave = stol(value);
  719.                 break;
  720.         case EVFCOL:    curwp->w_fcol = asc_int(value);
  721.                 if (curwp->w_fcol < 0)
  722.                     curwp->w_fcol = 0;
  723.                 curwp->w_flag |= WFHARD | WFMODE;
  724.                 break;
  725.         case EVHSCROLL: hscroll = stol(value);
  726.                 lbound = 0;
  727.                 break;
  728.         case EVHJUMP:    hjump = asc_int(value);
  729.                 if (hjump < 1)
  730.                     hjump = 1;
  731.                 if (hjump > term.t_ncol - 1)
  732.                     hjump = term.t_ncol - 1;
  733.                 break;
  734.         case EVBUFHOOK: setkey(&bufhook, value);
  735.                 break;
  736.         case EVEXBHOOK: setkey(&exbhook, value);
  737.                 break;
  738.         case EVWRITEHK: setkey(&writehook, value);
  739.                 break;
  740.         case EVDIAGFLAG:diagflag = stol(value);
  741.                 break;
  742.         case EVMSFLAG:    mouseflag = stol(value);
  743.                 break;
  744.         case EVOCRYPT:    oldcrypt = stol(value);
  745.                 break;
  746.         case EVSEARCHPNT:    searchtype = asc_int(value);
  747.                 if (searchtype < SRNORM  || searchtype > SREND)
  748.                     searchtype = SRNORM;
  749.                 break;
  750.         case EVDISPHIGH:
  751.                 c = disphigh;
  752.                 disphigh = stol(value);
  753.                 if (c != disphigh)
  754.                     upwind();
  755.                 break;
  756.         case EVLTERM:    bytecopy(lterm, value, NSTRING);
  757.                 break;
  758.         case EVPARALEAD:bytecopy(paralead, value, NSTRING);
  759.                 break;
  760.         case EVFMTLEAD:    bytecopy(fmtlead, value, NSTRING);
  761.                 break;
  762.         case EVWCHARS:    setwlist(value);
  763.                 break;
  764.         case EVPOPFLAG: popflag = stol(value);
  765.                 break;
  766.         case EVYANKFLAG:    yankflag = stol(value);
  767.                 break;
  768.         case EVSCRNAME:    select_screen(lookup_screen(value), TRUE);
  769.                 break;
  770.         case EVCURWIND:    nextwind(TRUE, asc_int(value));
  771.                 break;
  772.         case EVNUMWIND:    break;
  773.         case EVORGCOL:    status = new_col_org(TRUE, asc_int(value));
  774.                 break;
  775.         case EVORGROW:    status = new_row_org(TRUE, asc_int(value));
  776.                 break;
  777.         case EVDESKCLR:    c = lookup_color(mkupper(value));
  778.                 if (c != -1) {
  779.                     deskcolor = c;
  780. #if    WINDOW_TEXT
  781.                     refresh_screen(first_screen);
  782. #endif
  783.                 }
  784.                 break;
  785.         }
  786.         break;
  787.     }
  788.     return(status);
  789. }
  790.  
  791. /*    asc_int:    ascii string to integer......This is too
  792.         inconsistant to use the system's    */
  793.  
  794. int PASCAL NEAR asc_int(st)
  795.  
  796. char *st;
  797.  
  798. {
  799.     int result;    /* resulting number */
  800.     int sign;    /* sign of resulting number */
  801.     char c;     /* current char being examined */
  802.  
  803.     result = 0;
  804.     sign = 1;
  805.  
  806.     /* skip preceding whitespace */
  807.     while (*st == ' ' || *st == '\t')
  808.         ++st;
  809.  
  810.     /* check for sign */
  811.     if (*st == '-') {
  812.         sign = -1;
  813.         ++st;
  814.     }
  815.     if (*st == '+')
  816.         ++st;
  817.  
  818.     /* scan digits, build value */
  819.     while ((c = *st++))
  820.         if (c >= '0' && c <= '9')
  821.             result = result * 10 + c - '0';
  822.         else
  823.             break;
  824.  
  825.     return(result * sign);
  826. }
  827.  
  828. /*    int_asc:    integer to ascii string.......... This is too
  829.             inconsistant to use the system's    */
  830.  
  831. char *PASCAL NEAR int_asc(i)
  832.  
  833. int i;    /* integer to translate to a string */
  834.  
  835. {
  836.     register int digit;        /* current digit being used */
  837.     register char *sp;        /* pointer into result */
  838.     register int sign;        /* sign of resulting number */
  839.     static char result[INTWIDTH+1]; /* resulting string */
  840.  
  841.     /* record the sign...*/
  842.     sign = 1;
  843.     if (i < 0) {
  844.         sign = -1;
  845.         i = -i;
  846.     }
  847.  
  848.     /* and build the string (backwards!) */
  849.     sp = result + INTWIDTH;
  850.     *sp = 0;
  851.     do {
  852.         digit = i % 10;
  853.         *(--sp) = '0' + digit;    /* and install the new digit */
  854.         i = i / 10;
  855.     } while (i);
  856.  
  857.     /* and fix the sign */
  858.     if (sign == -1) {
  859.         *(--sp) = '-';    /* and install the minus sign */
  860.     }
  861.  
  862.     return(sp);
  863. }
  864.  
  865. int PASCAL NEAR gettyp(token)    /* find the type of a passed token */
  866.  
  867. char *token;    /* token to analyze */
  868.  
  869. {
  870.     register char c;    /* first char in token */
  871.  
  872.     /* grab the first char (this is all we need) */
  873.     c = *token;
  874.  
  875.     /* no blanks!!! */
  876.     if (c == 0)
  877.         return(TKNUL);
  878.  
  879.     /* a numeric literal? */
  880.     if (c >= '0' && c <= '9')
  881.         return(TKLIT);
  882.  
  883.     switch (c) {
  884.         case '"':    return(TKSTR);
  885.  
  886.         case '!':    return(TKDIR);
  887.         case '@':    return(TKARG);
  888.         case '#':    return(TKBUF);
  889.         case '$':    return(TKENV);
  890.         case '%':    return(TKVAR);
  891.         case '&':    return(TKFUN);
  892.         case '*':    return(TKLBL);
  893.  
  894.         default:    return(TKCMD);
  895.     }
  896. }
  897.  
  898. char *PASCAL NEAR getval(token) /* find the value of a token */
  899.  
  900. char *token;        /* token to evaluate */
  901.  
  902. {
  903.     register int status;    /* error return */
  904.     register BUFFER *bp;    /* temp buffer pointer */
  905.     register int blen;    /* length of buffer argument */
  906.     register int distmp;    /* temporary discmd flag */
  907.     static char buf[NSTRING];/* string buffer for some returns */
  908.  
  909.     switch (gettyp(token)) {
  910.         case TKNUL:    return("");
  911.  
  912.         case TKARG:    /* interactive argument */
  913.                 strcpy(token, fixnull(getval(&token[1])));
  914.                 distmp = discmd;    /* echo it always! */
  915.                 discmd = TRUE;
  916.                 status = getstring(token,
  917.                        buf, NSTRING, ctoec('\r'));
  918.                 discmd = distmp;
  919.                 if (status == ABORT)
  920.                     return(NULL);
  921.                 return(buf);
  922.  
  923.         case TKBUF:    /* buffer contents fetch */
  924.  
  925.                 /* grab the right buffer */
  926.                 strcpy(token, fixnull(getval(&token[1])));
  927.                 bp = bfind(token, FALSE, 0);
  928.                 if (bp == NULL)
  929.                     return(NULL);
  930.             
  931.                 /* if the buffer is displayed, get the window
  932.                    vars instead of the buffer vars */
  933.                 if (bp->b_nwnd > 0) {
  934.                     curbp->b_dotp = curwp->w_dotp;
  935.                     curbp->b_doto = curwp->w_doto;
  936.                 }
  937.  
  938.                 /* make sure we are not at the end */
  939.                 if (bp->b_linep == bp->b_dotp)
  940.                     return(NULL);
  941.             
  942.                 /* grab the line as an argument */
  943.                 blen = bp->b_dotp->l_used - bp->b_doto;
  944.                 if (blen > NSTRING)
  945.                     blen = NSTRING;
  946.                 bytecopy(buf, bp->b_dotp->l_text + bp->b_doto,
  947.                     blen);
  948.                 buf[blen] = 0;
  949.             
  950.                 /* and step the buffer's line ptr ahead a line */
  951.                 bp->b_dotp = bp->b_dotp->l_fp;
  952.                 bp->b_doto = 0;
  953.  
  954.                 /* if displayed buffer, reset window ptr vars*/
  955.                 if (bp->b_nwnd > 0) {
  956.                     curwp->w_dotp = curbp->b_dotp;
  957.                     curwp->w_doto = 0;
  958.                     curwp->w_flag |= WFMOVE;
  959.                 }
  960.  
  961.                 /* and return the spoils */
  962.                 return(buf);            
  963.  
  964.         case TKVAR:    return(gtusr(token+1));
  965.         case TKENV:    return(gtenv(token+1));
  966.         case TKFUN:    return(gtfun(token+1));
  967.         case TKDIR:    return(NULL);
  968.         case TKLBL:    return(NULL);
  969.         case TKLIT:    return(token);
  970.         case TKSTR:    return(token+1);
  971.         case TKCMD:    return(token);
  972.     }
  973. }
  974.  
  975. int PASCAL NEAR stol(val)    /* convert a string to a numeric logical */
  976.  
  977. char *val;    /* value to check for stol */
  978.  
  979. {
  980.     /* check for logical values */
  981.     if (val[0] == 'F')
  982.         return(FALSE);
  983.     if (val[0] == 'T')
  984.         return(TRUE);
  985.  
  986.     /* check for numeric truth (!= 0) */
  987.     return((asc_int(val) != 0));
  988. }
  989.  
  990. char *PASCAL NEAR ltos(val)    /* numeric logical to string logical */
  991.  
  992. int val;    /* value to translate */
  993.  
  994. {
  995.     if (val)
  996.         return(truem);
  997.     else
  998.         return(falsem);
  999. }
  1000.  
  1001. char *PASCAL NEAR mkupper(str)    /* make a string upper case */
  1002.  
  1003. char *str;        /* string to upper case */
  1004.  
  1005. {
  1006.     char *sp;
  1007.  
  1008.     sp = str;
  1009.     while (*sp)
  1010.         uppercase(sp++);
  1011.     return(str);
  1012. }
  1013.  
  1014. char *PASCAL NEAR mklower(str)    /* make a string lower case */
  1015.  
  1016. char *str;        /* string to lower case */
  1017.  
  1018. {
  1019.     char *sp;
  1020.  
  1021.     sp = str;
  1022.     while (*sp)
  1023.         lowercase(sp++);
  1024.     return(str);
  1025. }
  1026.  
  1027. int PASCAL NEAR absv(x) /* take the absolute value of an integer */
  1028.  
  1029. int x;
  1030.  
  1031. {
  1032.     return(x < 0 ? -x : x);
  1033. }
  1034.  
  1035. int PASCAL NEAR ernd()    /* returns a random integer */
  1036.  
  1037. {
  1038.     seed = absv(seed * 1721 + 10007);
  1039.     return(seed);
  1040. }
  1041.  
  1042. int PASCAL NEAR sindex(source, pattern) /* find pattern within source */
  1043.  
  1044. char *source;    /* source string to search */
  1045. char *pattern;    /* string to look for */
  1046.  
  1047. {
  1048.     char *sp;    /* ptr to current position to scan */
  1049.     char *csp;    /* ptr to source string during comparison */
  1050.     char *cp;    /* ptr to place to check for equality */
  1051.  
  1052.     /* scanning through the source string */
  1053.     sp = source;
  1054.     while (*sp) {
  1055.         /* scan through the pattern */
  1056.         cp = pattern;
  1057.         csp = sp;
  1058.         while (*cp) {
  1059.             if (!eq(*cp, *csp))
  1060.                 break;
  1061.             ++cp;
  1062.             ++csp;
  1063.         }
  1064.  
  1065.         /* was it a match? */
  1066.         if (*cp == 0)
  1067.             return((int)(sp - source) + 1);
  1068.         ++sp;
  1069.     }
  1070.  
  1071.     /* no match at all.. */
  1072.     return(0);
  1073. }
  1074.  
  1075. /*    Filter a string through a translation table    */
  1076.  
  1077. char *PASCAL NEAR xlat(source, lookup, trans)
  1078.  
  1079. char *source;    /* string to filter */
  1080. char *lookup;    /* characters to translate */
  1081. char *trans;    /* resulting translated characters */
  1082.  
  1083. {
  1084.     register char *sp;    /* pointer into source table */
  1085.     register char *lp;    /* pointer into lookup table */
  1086.     register char *rp;    /* pointer into result */
  1087.     static char result[NSTRING];    /* temporary result */
  1088.  
  1089.     /* scan source string */
  1090.     sp = source;
  1091.     rp = result;
  1092.     while (*sp) {
  1093.         /* scan lookup table for a match */
  1094.         lp = lookup;
  1095.         while (*lp) {
  1096.             if (*sp == *lp) {
  1097.                 *rp++ = trans[lp - lookup];
  1098.                 goto xnext;
  1099.             }
  1100.             ++lp;
  1101.         }
  1102.  
  1103.         /* no match, copy in the source char untranslated */
  1104.         *rp++ = *sp;
  1105.  
  1106. xnext:        ++sp;
  1107.     }
  1108.  
  1109.     /* terminate and return the result */
  1110.     *rp = 0;
  1111.     return(result);
  1112. }
  1113.  
  1114. /*    setwlist:    Set an alternative list of character to be
  1115.             considered "in a word */
  1116.  
  1117. PASCAL NEAR setwlist(wclist)
  1118.  
  1119. char *wclist;    /* list of characters to consider "in a word" */
  1120.  
  1121. {
  1122.     register int index;
  1123.  
  1124.     /* if we are turning this facility off, just flag so */
  1125.     if (wclist == NULL || *wclist == 0) {
  1126.         wlflag = FALSE;
  1127.         return;
  1128.     }
  1129.  
  1130.     /* first clear the table */
  1131.     for (index = 0; index < 256; index++)
  1132.         wordlist[index] = FALSE;
  1133.  
  1134.     /* and for each character in the new value, set that element
  1135.        of the word character list */
  1136.     while (*wclist)
  1137.         wordlist[*wclist++] = TRUE;
  1138.     wlflag = TRUE;
  1139.     return;
  1140. }
  1141.  
  1142. /*    getwlist:    place in a buffer a list of characters
  1143.             considered "in a word"            */
  1144.  
  1145. char *PASCAL NEAR getwlist(buf)
  1146.  
  1147. char *buf;    /* buffer to place list of characters */
  1148.  
  1149. {
  1150.     register int index;
  1151.     register char *sp;
  1152.  
  1153.     /* if we are defaulting to a standard word char list... */
  1154.     if (wlflag == FALSE)
  1155.         return("");
  1156.  
  1157.     /* build the string of characters in the return buffer */
  1158.     sp = buf;
  1159.     for (index = 0; index < 256; index++)
  1160.         if (wordlist[index])
  1161.             *sp++ = index;
  1162.     *sp = 0;
  1163.     return(buf);
  1164. }
  1165.  
  1166. /*    is_num:    ascii string is integer......This is too
  1167.         inconsistant to use the system's    */
  1168.  
  1169. int PASCAL NEAR is_num(st)
  1170.  
  1171. char *st;
  1172.  
  1173. {
  1174.     int period_flag;    /* have we seen a period yet? */
  1175.  
  1176.     /* skip preceding whitespace */
  1177.     while (*st == ' ' || *st == '\t')
  1178.         ++st;
  1179.  
  1180.     /* check for sign */
  1181.     if ((*st == '-') || (*st == '+'))
  1182.         ++st;
  1183.  
  1184.     /* scan digits */
  1185.     period_flag = FALSE;
  1186.     while ((*st >= '0') && (*st <= '9') ||
  1187.            (*st == '.' && period_flag == FALSE)) {
  1188.         if (*st == '.')
  1189.             period_flag = TRUE;
  1190.         st++;
  1191.     }
  1192.  
  1193.     /* scan rest of line for just white space */
  1194.     while (*st) {
  1195.         if ((*st != '\t') && (*st != ' '))
  1196.             return(FALSE);
  1197.         st++;
  1198.     }
  1199.     return(TRUE);
  1200. }
  1201.  
  1202. #if    DEBUGM
  1203. int PASCAL NEAR dispvar(f, n)        /* display a variable's value */
  1204.  
  1205. int f;        /* default flag */
  1206. int n;        /* numeric arg (can overide prompted value) */
  1207.  
  1208. {
  1209.     register int status;    /* status return */
  1210.     VDESC vd;        /* variable num/type */
  1211.     char var[NVSIZE+1];    /* name of variable to fetch */
  1212.  
  1213.     /* first get the variable to display.. */
  1214.     if (clexec == FALSE) {
  1215.         status = mlreply(TEXT55, &var[0], NVSIZE+1);
  1216. /*                 "Variable to display: " */
  1217.         if (status != TRUE)
  1218.             return(status);
  1219.     } else {    /* macro line argument */
  1220.         /* grab token and skip it */
  1221.         execstr = token(execstr, var, NVSIZE + 1);
  1222.     }
  1223.  
  1224.     /* check the legality and find the var */
  1225.     findvar(var, &vd, NVSIZE + 1);
  1226.         
  1227.     /* if its not legal....bitch */
  1228.     if (vd.v_type == -1) {
  1229.         mlwrite(TEXT52, var);
  1230. /*            "%%No such variable as '%s'" */
  1231.         return(FALSE);
  1232.     }
  1233.  
  1234.     /* and display the value */
  1235.     strcpy(outline, var);
  1236.     strcat(outline, " = ");
  1237.  
  1238.     /* and lastly the current value */
  1239.     strcat(outline, fixnull(getval(var)));
  1240.  
  1241.     /* expand '%' to "%%" so mlwrite wont bitch */
  1242.     makelit(outline);
  1243.  
  1244.     /* write out the result */
  1245.     mlforce(outline);
  1246.     update(TRUE);
  1247.  
  1248.     /* and return */
  1249.     return(TRUE);
  1250. }
  1251.  
  1252. /*    describe-variables    Bring up a fake buffer and list the contents
  1253.                 of all the environment variables
  1254. */
  1255.  
  1256. PASCAL NEAR desvars(f, n)
  1257.  
  1258. int f,n;    /* prefix flag and argument */
  1259.  
  1260. {
  1261.     register WINDOW *wp;    /* scanning pointer to windows */
  1262.     register BUFFER *varbuf;/* buffer to put variable list into */
  1263.     register int uindex;    /* index into uvar table */
  1264.     char outseq[256];    /* output buffer for keystroke sequence */
  1265.  
  1266.     /* and get a buffer for it */
  1267.     varbuf = bfind(TEXT56, TRUE, 0);
  1268. /*           "Variable list" */
  1269.     if (varbuf == NULL || bclear(varbuf) == FALSE) {
  1270.         mlwrite(TEXT57);
  1271. /*            "Can not display variable list" */
  1272.         return(FALSE);
  1273.     }
  1274.  
  1275.     /* let us know this is in progress */
  1276.     mlwrite(TEXT58);
  1277. /*        "[Building variable list]" */
  1278.  
  1279.     /* build the environment variable list */
  1280.     for (uindex = 0; uindex < NEVARS; uindex++) {
  1281.  
  1282.         /* add in the environment variable name */
  1283.         strcpy(outseq, "$");
  1284.         strcat(outseq, envars[uindex]);
  1285.         pad(outseq, 14);
  1286.             
  1287.         /* add in the value */
  1288.         strcat(outseq, gtenv(envars[uindex]));
  1289.  
  1290.         /* and add it as a line into the buffer */
  1291.         if (addline(varbuf, outseq) != TRUE)
  1292.             return(FALSE);
  1293.     }
  1294.  
  1295.     if (addline(varbuf, "") != TRUE)
  1296.         return(FALSE);
  1297.  
  1298.     /* build the user variable list */
  1299.     for (uindex = 0; uindex < MAXVARS; uindex++) {
  1300.         if (uv[uindex].u_name[0] == 0)
  1301.             break;
  1302.  
  1303.         /* add in the user variable name */
  1304.         strcpy(outseq, "%");
  1305.         strcat(outseq, uv[uindex].u_name);
  1306.         pad(outseq, 14);
  1307.             
  1308.         /* add in the value */
  1309.         strcat(outseq, uv[uindex].u_value);
  1310.  
  1311.         /* and add it as a line into the buffer */
  1312.         if (addline(varbuf, outseq) != TRUE)
  1313.             return(FALSE);
  1314.     }
  1315.  
  1316.     /* display the list */
  1317.     wpopup(varbuf);
  1318.     mlerase();    /* clear the mode line */
  1319.     return(TRUE);
  1320. }
  1321.  
  1322. /*    describe-functions    Bring up a fake buffer and list the
  1323.                 names of all the functions
  1324. */
  1325.  
  1326. PASCAL NEAR desfunc(f, n)
  1327.  
  1328. int f,n;    /* prefix flag and argument */
  1329.  
  1330. {
  1331.     register WINDOW *wp;    /* scanning pointer to windows */
  1332.     register BUFFER *fncbuf;/* buffer to put function list into */
  1333.     register int uindex;    /* index into funcs table */
  1334.     char outseq[80];    /* output buffer for keystroke sequence */
  1335.  
  1336.     /* get a buffer for the function list */
  1337.     fncbuf = bfind(TEXT211, TRUE, 0);
  1338. /*           "Function list" */
  1339.     if (fncbuf == NULL || bclear(fncbuf) == FALSE) {
  1340.         mlwrite(TEXT212);
  1341. /*            "Can not display function list" */
  1342.         return(FALSE);
  1343.     }
  1344.  
  1345.     /* let us know this is in progress */
  1346.     mlwrite(TEXT213);
  1347. /*        "[Building function list]" */
  1348.  
  1349.     /* build the function list */
  1350.     for (uindex = 0; uindex < NFUNCS; uindex++) {
  1351.  
  1352.         /* add in the environment variable name */
  1353.         strcpy(outseq, "&");
  1354.         strcat(outseq, funcs[uindex].f_name);
  1355.  
  1356.         /* and add it as a line into the buffer */
  1357.         if (addline(fncbuf, outseq) != TRUE)
  1358.             return(FALSE);
  1359.     }
  1360.  
  1361.     if (addline(fncbuf, "") != TRUE)
  1362.         return(FALSE);
  1363.  
  1364.     /* display the list */
  1365.     wpopup(fncbuf);
  1366.     mlerase();    /* clear the mode line */
  1367.     return(TRUE);
  1368. }
  1369.  
  1370. pad(s, len)    /* pad a string to indicated length */
  1371.  
  1372. char *s;    /* string to add spaces to */
  1373. int len;    /* wanted length of string */
  1374.  
  1375. {
  1376.     while (strlen(s) < len) {
  1377.                 strcat(s, "          ");
  1378.         s[len] = 0;
  1379.     }
  1380. }
  1381. #endif
  1382.