home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / jove414s.zip / os2util.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  18KB  |  892 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is    *
  5.  * included in all the files.                                              *
  6.  ***************************************************************************/
  7. #ifdef OS2
  8. #define INCL_BASE
  9. #include <os2.h>
  10. #endif
  11.  
  12.  
  13. #define UTIL
  14. #include "jove.h"
  15. #include "ctype.h"
  16. #include "termcap.h"
  17. #include "disp.h"
  18. #include "fp.h"
  19. #include <signal.h>
  20.  
  21. #ifdef MAC
  22. #include "mac.h"
  23. #else
  24. #ifdef    STDARGS
  25. #include <stdarg.h>
  26. #else
  27. #include <varargs.h>
  28. #endif
  29. #endif
  30.  
  31. #ifdef MSDOS
  32. #include <time.h>
  33. #endif
  34.  
  35. const struct cmd *
  36.  FindCmd(proc)
  37.  register  void (*proc) proto((void));
  38. {
  39.     register const struct cmd *cp;
  40.  
  41.     for (cp = commands; cp->Name; cp++)
  42.     if (cp->c_proc == proc)
  43.         return cp;
  44.     return 0;
  45. }
  46.  
  47. int Interactive;        /* True when we invoke with the command handler? */
  48. data_obj *LastCmd;
  49. char *ProcFmt = ": %f ";
  50.  
  51. /********************************************/
  52. void _fastcall ExecCmd (struct data_obj *cp)
  53. /********************************************/
  54. {
  55.     LastCmd = cp;
  56.     if (cp->Type & MAJOR_MODE) {
  57.     SetMajor((cp->Type >> 8));
  58.     } else if (cp->Type & MINOR_MODE) {
  59.     TogMinor((cp->Type >> 8));
  60.     } else
  61.     switch (cp->Type & TYPEMASK) {
  62.     case MACRO:
  63.         do_macro((struct macro *) cp);
  64.         break;
  65.  
  66.     case FUNCTION:
  67.         {
  68.         register  struct cmd *cmd = (struct cmd *) cp;
  69.  
  70.         if (cmd->c_proc) {
  71.             if ((cmd->Type & MODIFIER) &&
  72.             (BufMinorMode(curbuf, ReadOnly))) {
  73.             rbell();
  74.             message("[Buffer is read-only]");
  75.             } else
  76.             (*cmd->c_proc) ();
  77.         }
  78.         }
  79.     }
  80. }
  81.  
  82. /**********************************/
  83. Line *lastline( register Line *lp )
  84. /**********************************/
  85. {
  86.     register  Line *next;
  87.  
  88.     while ((next = lp->l_next) != NULL)
  89.     lp = next;
  90.     return lp;
  91. }
  92.  
  93. char key_strokes[100], *keys_p = key_strokes;
  94.  
  95. void pp_key_strokes(buffer, size)
  96. char *buffer;
  97. size_t size;
  98. {
  99.     char *buf_end = buffer + size - 5,    /* leave some extra space */
  100.     *kp = key_strokes, c;
  101.  
  102.     *buffer = '\0';
  103.     while ((c = *kp++) != '\0') {
  104.     swritef(buffer, "%p ", c);
  105.     buffer += strlen(buffer);
  106.     if (buffer > buf_end)
  107.         break;
  108.     }
  109. }
  110.  
  111. private int *slowp = 0;        /* for waitchar() */
  112.  
  113. private SIGRESULT
  114.  slowpoke(junk)
  115. int junk;
  116. {
  117.     char buffer[100];
  118.  
  119.     if (slowp)
  120.     *slowp = YES;
  121.     pp_key_strokes(buffer, sizeof(buffer));
  122.     f_mess (buffer);
  123.     SIGRETURN;
  124. }
  125.  
  126. #define N_SEC    1
  127. int in_macro();
  128.  
  129. /*********************************/
  130. int _fastcall waitchar (int *slow)
  131. /*********************************/
  132. {
  133.     int c;
  134.     long     sleep_time = 1000L;
  135.     long     sleep_interval = 100L;
  136.     int      _fastcall get_ch(void);
  137.  
  138.     slowp = slow;
  139.  
  140.     if (in_macro())        /* make macros faster ... */
  141.     return get_ch();
  142.  
  143.     /* If slow is a valid pointer and it's value is yes, then
  144.        we know we have already been slow during this sequence,
  145.        so we just wait for the character and then echo it. */
  146.     if (slow != 0 && *slow == YES) {
  147.     c = get_ch();
  148.     slowpoke(0);
  149.     return c;
  150.     }
  151.     while (sleep_time >= 0) {
  152.     if (charp() || in_macro())
  153.         return (get_ch());
  154.     DosSleep(sleep_interval);
  155.     sleep_time -= sleep_interval;
  156.     }
  157.     slowpoke ();
  158.     c = get_ch ();
  159.     slowpoke ();
  160.  
  161.     return c;
  162. }
  163.  
  164. /* dir > 0 means forward; else means backward. */
  165.  
  166. char *
  167.  StrIndex(dir, buf, charpos, what)
  168. int dir;
  169. register  char *buf;
  170. int charpos;
  171. register  int what;
  172. {
  173.     /* register */ char *cp = &buf[charpos];
  174.     /* register */ int c;
  175.  
  176.     if (dir > 0) {
  177.     while ((c = *cp++) != '\0')
  178.         if ((c == what) != '\0')
  179.         return (cp - 1);
  180.     } else {
  181.     while (cp >= buf && (c = *cp--) != '\0')
  182.         if (c == what)
  183.         return (cp + 1);
  184.     }
  185.     return 0;
  186. }
  187.  
  188. int blnkp(buf)
  189. register  char *buf;
  190. {
  191.     /* register */ char c;
  192.  
  193.     while ((c = *buf++) != '\0' && (c == ' ' || c == '\t'));
  194.     return c == 0;        /* It's zero if we got to the end of the Line */
  195. }
  196. /***********************/
  197. int within_indent (void)
  198. /***********************/
  199. {
  200.     /* register */ char c;
  201.     /* register */ int i;
  202.  
  203.     i = curchar;
  204.     while (--i >= 0 && ((c = linebuf[i]) == ' ' || c == '\t'));
  205.     return (i < 0);        /* it's < 0 if we got to the beginning */
  206. }
  207.  
  208. /***********************************************/
  209. Line  * next_line(Line *line, int num)
  210. /***********************************************/
  211. {
  212.     if (num < 0)
  213.     return prev_line(line, -num);
  214.     if (line)
  215.     while (--num >= 0 && line->l_next != 0)
  216.         line = line->l_next;
  217.     return line;
  218. }
  219.  
  220. /************************************************/
  221. Line *  prev_line (Line *line, int num)
  222. /************************************************/
  223. {
  224.     if (num < 0)
  225.     return next_line(line, -num);
  226.     if (line)
  227.     while (--num >= 0 && line->l_prev != 0)
  228.         line = line->l_prev;
  229.     return line;
  230. }
  231. /*****************************************/
  232. void _fastcall DotTo(Line *line, int col)
  233. /*****************************************/
  234. {
  235.     Bufpos bp;
  236.  
  237.     bp.p_line = line;
  238.     bp.p_char = col;
  239.     SetDot(&bp);
  240. }
  241.  
  242. /* If bp->p_line is != current line, then save current line.  Then set dot
  243.    to bp->p_line, and if they weren't equal get that line into linebuf.  */
  244. /***********************************/
  245. void _fastcall SetDot (Bufpos *bp)
  246. /***********************************/
  247. {
  248.     /* register */ int notequal;
  249.  
  250.     if (bp == 0)
  251.     return;
  252.  
  253.     notequal = bp->p_line != curline;
  254.     if (notequal)
  255.     lsave();
  256.     if (bp->p_line)
  257.     curline = bp->p_line;
  258.     if (notequal)
  259.     getDOT();
  260.     curchar = bp->p_char;
  261.     if (curchar > length(curline))
  262.     curchar = length(curline);
  263. }
  264. /***************************/
  265. void _fastcall ToLast(void)
  266. /***************************/
  267. {
  268.     SetLine(curbuf->b_last);
  269.     Eol();
  270. }
  271.  
  272. int MarkThresh = 22;        /* average screen size ... */
  273. static int line_diff;
  274.  
  275. int LineDist(nextp, endp)
  276. /* register */ Line *nextp, *endp;
  277. {
  278.     (void) inorder(nextp, 0, endp, 0);
  279.     return line_diff;
  280. }
  281.  
  282. int inorder(nextp, char1, endp, char2)
  283. /* register */ Line *nextp, *endp;
  284. int char1, char2;
  285. {
  286.     int count = 0;
  287.     /* register */ Line *prevp = nextp;
  288.  
  289.     line_diff = 0;
  290.     if (nextp == endp)
  291.     return char1 < char2;
  292.  
  293.     while (nextp || prevp) {
  294.     if (nextp == endp || prevp == endp)
  295.         break;
  296.     if (nextp)
  297.         nextp = nextp->l_next;
  298.     if (prevp)
  299.         prevp = prevp->l_prev;
  300.     count += 1;
  301.     }
  302.     if (nextp == 0 && prevp == 0)
  303.     return -1;
  304.     line_diff = count;
  305.  
  306.     return nextp == endp;
  307. }
  308.  
  309. void PushPntp(line)
  310. /* register */ Line *line;
  311. {
  312.     if (LineDist(curline, line) >= MarkThresh)
  313.     set_mark();
  314. }
  315. /****************************/
  316. void _fastcall ToFirst(void)
  317. /****************************/
  318. {
  319.     SetLine(curbuf->b_first);
  320. }
  321. /********************************/
  322. int _fastcall length(Line *line)
  323. /********************************/
  324. {
  325.     return strlen(lcontents(line));
  326. }
  327. /***************************/
  328. void _fastcall to_word(dir)
  329. /***************************/
  330. {
  331.     register  char c;
  332.  
  333.     if (dir == FORWARD) {
  334.     while ((c = linebuf[curchar]) != 0 && !isword(c))
  335.         curchar += 1;
  336.     if (eolp()) {
  337.         if (curline->l_next == 0)
  338.         return;
  339.         SetLine(curline->l_next);
  340.         to_word(dir);
  341.         return;
  342.     }
  343.     } else {
  344.     while (!bolp() && (c = linebuf[curchar - 1], !isword(c)))
  345.         curchar -= 1;
  346.     if (bolp()) {
  347.         if (curline->l_prev == 0)
  348.         return;
  349.         SetLine(curline->l_prev);
  350.         Eol();
  351.         to_word(dir);
  352.     }
  353.     }
  354. }
  355.  
  356. /* Are there any modified buffers?  Allp means include B_PROCESS
  357.    buffers in the check. */
  358. /*******************************/
  359. int _fastcall ModBufs(int allp)
  360. /*******************************/
  361. {
  362.     /* register */ Buffer *b;
  363.  
  364.     for (b = world; b != 0; b = b->b_next) {
  365.     if (b->b_type == B_SCRATCH)
  366.         continue;
  367.     if ((b->b_type == B_FILE || allp) && IsModified(b))
  368.         return 1;
  369.     }
  370.     return 0;
  371. }
  372.  
  373. /***********************************/
  374. char *_fastcall filename(Buffer *b)
  375. /***********************************/
  376. {
  377.     return b->b_fname ? pr_name(b->b_fname, YES) : "[No file]";
  378. }
  379.  
  380. char *
  381.  itoa(num)
  382. /* register */ int num;
  383. {
  384.     static char line[15];
  385.  
  386.     swritef(line, "%d", num);
  387.     return line;
  388. }
  389.  
  390. int min(a, b)
  391. /* register */ int a, b;
  392. {
  393.     return (a < b) ? a : b;
  394. }
  395.  
  396. int max(a, b)
  397. /* register */ int a, b;
  398. {
  399.     return (a > b) ? a : b;
  400. }
  401.  
  402. void tiewind(w, bp)
  403. /* register */ Window *w;
  404. /* register */ Buffer *bp;
  405. {
  406.     int not_tied = (w->w_bufp != bp);
  407.  
  408.     UpdModLine = YES;        /* kludge ... but speeds things up considerably */
  409.     w->w_line = bp->b_dot;
  410.     w->w_char = bp->b_char;
  411.     w->w_bufp = bp;
  412.     if (not_tied)
  413.     CalcWind(w);        /* ah, this has been missing since the
  414.                    beginning of time! */
  415. }
  416.  
  417. char *
  418.  lcontents(line)
  419. /* register */ Line *line;
  420. {
  421.     if (line == curline)
  422.     return linebuf;
  423.     else
  424.     return lbptr(line);
  425. }
  426.  
  427. char *
  428.  ltobuf(line, buf)
  429. Line *line;
  430. char *buf;
  431. {
  432.     if (line == curline) {
  433.     if (buf != linebuf)
  434.         strcpy(buf, linebuf);
  435.     Jr_Len = strlen(linebuf);
  436.     } else
  437.     getline(line->l_dline, buf);
  438.     return buf;
  439. }
  440.  
  441. void DOTsave(buf)
  442. Bufpos *buf;
  443. {
  444.     buf->p_line = curline;
  445.     buf->p_char = curchar;
  446. }
  447.  
  448. /* Return none-zero if we had to rearrange the order. */
  449.  
  450. int fixorder(line1, char1, line2, char2)
  451. /* register */ Line **line1, **line2;
  452. /* register */ int *char1, *char2;
  453. {
  454.     Line *tline;
  455.     int tchar;
  456.  
  457.     if (inorder(*line1, *char1, *line2, *char2))
  458.     return 0;
  459.  
  460.     tline = *line1;
  461.     tchar = *char1;
  462.     *line1 = *line2;
  463.     *char1 = *char2;
  464.     *line2 = tline;
  465.     *char2 = tchar;
  466.  
  467.     return 1;
  468. }
  469.  
  470. int inlist(first, what)
  471. /* register */ Line *first, *what;
  472. {
  473.     while (first) {
  474.     if (first == what)
  475.         return 1;
  476.     first = first->l_next;
  477.     }
  478.     return 0;
  479. }
  480.  
  481. /* Make `buf' (un)modified and tell the redisplay code to update the modeline
  482.    if it will need to be changed. */
  483.  
  484. int ModCount = 0;
  485.  
  486. void modify()
  487. {
  488.     if (!curbuf->b_modified) {
  489.     UpdModLine = YES;
  490.     curbuf->b_modified = YES;
  491.     }
  492.     DOLsave = YES;
  493.     if (!Asking)
  494.     ModCount += 1;
  495. }
  496.  
  497. void unmodify()
  498. {
  499.     if (curbuf->b_modified) {
  500.     UpdModLine = YES;
  501.     curbuf->b_modified = NO;
  502.     }
  503. }
  504.  
  505. int numcomp(s1, s2)
  506. /* register */ char *s1, *s2;
  507. {
  508.     /* register */ int count = 0;
  509.  
  510.     while (*s1 != 0 && *s1++ == *s2++)
  511.     count += 1;
  512.     return count;
  513. }
  514.  
  515. char *
  516.  copystr(str)
  517. char *str;
  518. {
  519.     char *val;
  520.  
  521.     if (str == 0)
  522.     return 0;
  523.     val = emalloc((size_t) (strlen(str) + 1));
  524.  
  525.     strcpy(val, str);
  526.     return val;
  527. }
  528.  
  529. #ifndef byte_copy
  530. void byte_copy(from, to, count)
  531. /* register */ char *from, *to;
  532. /* register */ size_t count;
  533. {
  534.     while (count-- > 0)
  535.     *to++ = *from++;
  536. }
  537.  
  538. #endif
  539.  
  540. void len_error(flag)
  541. int flag;
  542. {
  543.     char *mesg = "[line too long]";
  544.  
  545.     if (flag == COMPLAIN)
  546.     complain(mesg);
  547.     else
  548.     error(mesg);
  549. }
  550.  
  551. /* Insert num number of c's at offset atchar in a linebuf of LBSIZE */
  552.  
  553. void ins_c(c, buf, atchar, num, max)
  554. int c;
  555. char *buf;
  556. int atchar, num, max;
  557. {
  558.     /* register */ char *pp, *pp1;
  559.     /* register */ int len;
  560.     int numchars;        /* number of characters to copy forward */
  561.  
  562.     if (num <= 0)
  563.     return;
  564.     len = atchar + strlen(&buf[atchar]);
  565.     if (len + num >= max)
  566.     len_error(COMPLAIN);
  567.     pp = &buf[len + 1];        /* + 1 so we can --pp (not pp--) */
  568.     pp1 = &buf[len + num + 1];
  569.     numchars = len - atchar;
  570.     while (numchars-- >= 0)
  571.     *--pp1 = *--pp;
  572.     pp = &buf[atchar];
  573.     while (--num >= 0)
  574.     *pp++ = c;
  575. }
  576.  
  577. int TwoBlank()
  578. {
  579.     /* register */ Line *next = curline->l_next;
  580.  
  581.     return ((next != 0) &&
  582.         (*(lcontents(next)) == '\0') &&
  583.         (next->l_next != 0) &&
  584.         (*(lcontents(next->l_next)) == '\0'));
  585. }
  586.  
  587. void linecopy(onto, atchar, from)
  588. /* register */ char *onto, *from;
  589. int atchar;
  590. {
  591.     /* register */ char *endp = &onto[LBSIZE - 2];
  592.  
  593.     onto += atchar;
  594.  
  595.     while ((*onto = *from++) != '\0')
  596.     if (onto++ >= endp)
  597.         len_error(ERROR);
  598. }
  599.  
  600. char *
  601.  IOerr(err, file)
  602. char *err, *file;
  603. {
  604.     return sprint("Couldn't %s \"%s\".", err, file);
  605. }
  606.  
  607. #ifdef UNIX
  608. void dopipe(p)
  609. int *p;
  610. {
  611.     if (pipe(p) == -1)
  612.     complain("[Pipe failed]");
  613. }
  614.  
  615. void pclose(p)
  616. int *p;
  617. {
  618.     (void) close(p[0]);
  619.     (void) close(p[1]);
  620. }
  621.  
  622. #endif                /* UNIX */
  623.  
  624. /* NOSTRICT */
  625.  
  626. char *
  627.  emalloc(size)
  628. size_t size;
  629. {
  630.     /* register */ char *ptr;
  631.  
  632.     if ((ptr = malloc(size)) != NULL)
  633.     return ptr;
  634.     /* Try garbage collecting lines */
  635.     GCchunks();
  636.     if ((ptr = malloc(size)) != NULL)
  637.     return ptr;
  638.     /* Uh ... Oh screw it! */
  639.     error("[Out of memory] ");
  640.     /* NOTREACHED */
  641. }
  642.  
  643. /* Return the basename of file F. */
  644.  
  645. char *
  646.  basename(f)
  647. /* register */ char *f;
  648. {
  649.     /* register */ char *cp;
  650.  
  651.     if ((cp = strrchr(f, '/')) != NULL)
  652.     return cp + 1;
  653.     else
  654. #ifdef MSDOS
  655.     if (cp = strrchr(f, '\\'))
  656.     return cp + 1;
  657.     else if (cp = strrchr(f, ':'))
  658.     return cp + 1;
  659. #endif                /* MSDOS */
  660.     return f;
  661. }
  662.  
  663. void push_env(savejmp)
  664. jmp_buf savejmp;
  665. {
  666.     byte_copy((char *) mainjmp, (char *) savejmp, sizeof(jmp_buf));
  667. }
  668.  
  669. void pop_env(savejmp)
  670. jmp_buf savejmp;
  671. {
  672.     byte_copy((char *) savejmp, (char *) mainjmp, sizeof(jmp_buf));
  673. }
  674.  
  675. #ifdef LOAD_AV
  676. #if defined(BSD4_2) && !defined(BSD2_10)
  677. #if defined(PURDUE_EE) && (defined(vax) || defined(gould))
  678.  
  679. void get_la(dp)
  680. double *dp;
  681. {
  682.     *dp = (double) loadav(0) / 100.0;
  683. }
  684.  
  685. #else                /* !PURDUE_EE || (!vax && !gould) */
  686.  
  687. #ifdef sun
  688. #include <sys/param.h>
  689. #endif
  690. #include <nlist.h>
  691.  
  692. static struct nlist nl[] =
  693. {
  694.     {"_avenrun", 0, 0, 0, 0},
  695. #define    X_AVENRUN    0
  696.     {"", 0, 0, 0, 0}
  697. };
  698.  
  699. void get_la(dp)
  700. double *dp;
  701. {
  702. #ifdef sun
  703.     long avenrun[3];
  704. #else
  705.     double avenrun[3];
  706. #endif
  707.     static int kmem = 0;
  708.     extern long lseek proto((int, long, int));
  709.  
  710.     if (kmem == -1) {
  711.     *dp = 4.0;        /* So shell commands will say "Chugging" */
  712.     return;
  713.     } else if (kmem == 0) {
  714.     if ((kmem = open("/dev/kmem", 0)) == -1) {
  715.         f_mess("Can't open kmem for load average.");
  716.         *dp = 4.0;
  717.         return;
  718.     }
  719.     nlist("/vmunix", nl);
  720.     }
  721.     lseek(kmem, (long) nl[X_AVENRUN].n_value, 0);
  722.     read(kmem, (char *) avenrun, sizeof(avenrun));
  723. #ifdef sun
  724.     *dp = (double) avenrun[0] / FSCALE;
  725. #else
  726.     *dp = avenrun[0];
  727. #endif
  728. }
  729.  
  730. #endif
  731. #else                /* !BSD4_2 || BSD2_10 */
  732.  
  733. void get_la(dp)
  734. double *dp;
  735. {
  736.     short avg[3];
  737.  
  738.     gldav(avg);
  739.     *dp = (double) avg[0] / 256;
  740. }
  741.  
  742. #endif
  743. #endif                /* LOAD_AV */
  744.  
  745. /* get the time buf, designated by *timep, from FROM to TO. */
  746. char *
  747.  get_time(timep, buf, from, to)
  748. time_t *timep;
  749. char *buf;
  750. int from, to;
  751. {
  752.     time_t now;
  753.     char *cp;
  754.     extern char *ctime();
  755.  
  756.     if (timep != 0)
  757.     now = *timep;
  758.     else
  759.     (void) time(&now);
  760.     cp = ctime(&now) + from;
  761. #ifndef MSDOS
  762.     if (to == -1)
  763. #else                /* MSDOS */
  764.     if ((to == -1) && (cp[strlen(cp) - 1] == '\n'))
  765. #endif                /* MSDOS */
  766.     cp[strlen(cp) - 1] = '\0';    /* Get rid of \n */
  767.     else
  768.     cp[to - from] = '\0';
  769.     if (buf) {
  770.     strcpy(buf, cp);
  771.     return buf;
  772.     } else
  773.     return cp;
  774. }
  775.  
  776. int casecmp(s1, s2)
  777. /* register */ char *s1, *s2;
  778. {
  779.     if (!s1 || !s2)
  780.     return 1;        /* which is not zero ... */
  781.     while (CharUpcase(*s1) == CharUpcase(*s2++))
  782.     if (*s1++ == '\0')
  783.         return 0;
  784.     return (*s1 - *--s2);
  785. }
  786.  
  787. int casencmp(s1, s2, n)
  788. /* register */ char *s1, *s2;
  789. /* register */ size_t n;
  790. {
  791.     if (!s1 || !s2)
  792.     return 1;        /* which is not zero ... */
  793.     for (;;) {
  794.     if (n == 0)
  795.         return 0;
  796.     n--;
  797.     if (CharUpcase(*s1) != CharUpcase(*s2++))
  798.         return *s1 - *--s2;
  799.     if (*s1++ == '\0')
  800.         return 0;
  801.     }
  802. }
  803.  
  804. void null_ncpy(to, from, n)
  805. char *to, *from;
  806. size_t n;
  807. {
  808.     (void) strncpy(to, from, n);
  809.     to[n] = '\0';
  810. }
  811.  
  812. /* Tries to pause for delay/10 seconds OR until a character is typed
  813.    at the keyboard.  This works well on BSD4_2 and not so well on the
  814.    rest.  Returns 1 if it returned because of keyboard input, or 0
  815.    otherwise. */
  816.  
  817. /***********************/
  818. void SitFor (int delay)
  819. /***********************/
  820. {
  821. #include <dos.h>
  822.  
  823.     long start, end;
  824.     DATETIME DateTime;
  825.     unsigned long sleep_interval = 100L;
  826.     unsigned long alarm_mls = delay * 100;    /* delay in milliseconds */
  827.     unsigned long sleep_time = 0L;
  828.  
  829.     redisplay();
  830.     do {
  831.     if (InputPending = charp())
  832.         break;
  833.     sleep_time += sleep_interval;
  834.     DosSleep(sleep_interval);
  835.     }
  836.     while (sleep_time < alarm_mls);
  837. }
  838.  
  839. int sindex(pattern, string)
  840. /* register */ char *pattern, *string;
  841. {
  842.     /* register */ size_t len = strlen(pattern);
  843.  
  844.     while (*string != '\0') {
  845.     if (*pattern == *string && strncmp(pattern, string, len) == 0)
  846.         return TRUE;
  847.     string += 1;
  848.     }
  849.     return FALSE;
  850. }
  851.  
  852. void make_argv(argv, ap)
  853. /* register */ char *argv[];
  854. va_list ap;
  855. {
  856.     register  char *cp;
  857.     register  int i = 0;
  858.  
  859.     argv[i++] = va_arg(ap, char *);
  860.     argv[i++] = basename(argv[0]);
  861.     while ((cp = va_arg(ap, char *)) != NULL)
  862.     argv[i++] = cp;
  863.     argv[i] = 0;
  864. }
  865.  
  866. /******************/
  867. int pnt_line(void)
  868. /******************/
  869. {
  870.     register Line *lp = curbuf->b_first;
  871.     register int i;
  872.  
  873.     for (i = 0; lp != 0; i++, lp = lp->l_next)
  874.     if (lp == curline)
  875.         break;
  876.     return i + 1;
  877. }
  878.  
  879. char *
  880.  ralloc(obj, size)
  881. /* register */ char *obj;
  882. size_t size;
  883. {
  884.     /* register */ char *new;
  885.  
  886.     if (obj)
  887.     new = realloc(obj, size);
  888.     if (new == 0 || !obj)
  889.     new = emalloc(size);
  890.     return new;
  891. }
  892.