home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume35 / zsh / part18 < prev    next >
Text File  |  1993-02-20  |  56KB  |  2,616 lines

  1. Newsgroups: comp.sources.misc
  2. From: zsh-list@cs.uow.edu.au (The Zsh Mailing List)
  3. Subject: v35i068:  zsh - The Z Shell, version 2.3.1, Part18/22
  4. Message-ID: <1993Feb20.212820.29364@sparky.imd.sterling.com>
  5. X-Md4-Signature: 025e7dcfe312099fc7d46c9c6cc19e87
  6. Date: Sat, 20 Feb 1993 21:28:20 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: zsh-list@cs.uow.edu.au (The Zsh Mailing List)
  10. Posting-number: Volume 35, Issue 68
  11. Archive-name: zsh/part18
  12. Environment: UNIX
  13. Supersedes: zsh2.2: Volume 29, Issue 97-113
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  func/namedir help/typeset src/lex.c src/zle_main.c
  22. #   src/zle_misc.c
  23. # Wrapped by mattson@odin on Sat Feb  6 14:41:55 1993
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 18 (of 22)."'
  27. if test -f 'func/namedir' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'func/namedir'\"
  29. else
  30.   echo shar: Extracting \"'func/namedir'\" \(412 characters\)
  31.   sed "s/^X//" >'func/namedir' <<'END_OF_FILE'
  32. X# give a name to a directory
  33. X
  34. X$1=~+
  35. X: ~$1
  36. X
  37. X# for example, if we say: namedir foo
  38. X# where the current directory is /usr/princeton/common/src/news/nntp/inews
  39. X# this will do:
  40. X#
  41. X# foo=/usr/princeton/common/src/news/nntp/inews
  42. X# : ~foo
  43. X#
  44. X# The : ~foo just evaluates ~foo, which declares foo as a named directory.
  45. X# The first time a parameter is used with tilde expansion, it is declared
  46. X# as the name of a named dir.
  47. END_OF_FILE
  48.   if test 412 -ne `wc -c <'func/namedir'`; then
  49.     echo shar: \"'func/namedir'\" unpacked with wrong size!
  50.   fi
  51.   chmod +x 'func/namedir'
  52.   # end of 'func/namedir'
  53. fi
  54. if test -f 'help/typeset' -a "${1}" != "-c" ; then 
  55.   echo shar: Will not clobber existing file \"'help/typeset'\"
  56. else
  57.   echo shar: Extracting \"'help/typeset'\" \(3168 characters\)
  58.   sed "s/^X//" >'help/typeset' <<'END_OF_FILE'
  59. X     declare [ arg ... ]
  60. X          Same as typeset.
  61. X     functions [ +-tu ] [ name ... ]
  62. X          Equivalent to typeset -f.
  63. X     integer
  64. X          Same as typeset -i.
  65. X     local
  66. X          Same as typeset.
  67. X     typeset [ +-LRZfilrtux [n]] [ name[=value] ] ...
  68. X          Set attributes and values for shell  parameters.   When
  69. X          invoked  inside  a  function,  if  name  is not already
  70. X          defined, a new parameter is created which will be unset
  71. X          when  the function completes.  The following attributes
  72. X          are valid:
  73. X          -L   Left justify and remove leading blanks from value.
  74. X               If  n  is  nonzero,  it  defines  the width of the
  75. X               field; otherwise it is determined by the width  of
  76. X               the  value  of  the  first  assignment.   When the
  77. X               parameter is printed, it is filled  on  the  right
  78. X               with  blanks  or truncated if necessary to fit the
  79. X               field.  Leading zeros are removed if the  -Z  flag
  80. X               is also set.
  81. X          -R   Right justify and fill with leading blanks.  If  n
  82. X               is nonzero if defines the width of the field; oth-
  83. X               erwise it is determined by the width of the  value
  84. X               of  the  first  assignment.  When the parameter is
  85. X               printed, the field is left filled with  blanks  or
  86. X               truncated from the end.
  87. X          -Z   Right justify and fill with leading zeros  if  the
  88. X               first  non-blank  character  is a digit and the -L
  89. X               flag has not been set.  If n is nonzero it defines
  90. X               the width of the field; otherwise it is determined
  91. X               by the width of the value of the first assignment.
  92. X          -f   The names refer to functions rather  than  parame-
  93. X               ters.   No  assignments  can be made, and the only
  94. X               other valid flags are -t  and  -u.   The  flag  -t
  95. X               turns on execution tracing for this function.  The
  96. X               flag -u causes this  function  to  be  marked  for
  97. X               autoloading.  The fpath parameter will be searched
  98. X               to find the function definition when the  function
  99. X               is first referenced.
  100. X          -i   Use an internal integer representation.  If  i  is
  101. X               nonzero  it  defines  the  output arithmetic base,
  102. X               otherwise it is determined by  the  first  assign-
  103. X               ment.
  104. X          -l   Convert to lower case.
  105. X          -r   The given names are marked readonly.
  106. X          -t   Tags the named parameters.  Tags have  no  special
  107. X               meaning to the shell.
  108. X          -u   Convert to upper case.
  109. X          -x   Mark for automatic export to  the  environment  of
  110. X               subsequently executed commands.
  111. X
  112. X     Using + rather than - causes these flags to be  turned  off.
  113. X     If no arguments are given but flags are specified, a list of
  114. X     named parameters which have  these  flags  set  is  printed.
  115. X     Using  + instead of - keeps their values from being printed.
  116. X     If no arguments or options are given, the names  and  attri-
  117. X     butes of all parameters are printed.
  118. END_OF_FILE
  119.   if test 3168 -ne `wc -c <'help/typeset'`; then
  120.     echo shar: \"'help/typeset'\" unpacked with wrong size!
  121.   fi
  122.   # end of 'help/typeset'
  123. fi
  124. if test -f 'src/lex.c' -a "${1}" != "-c" ; then 
  125.   echo shar: Will not clobber existing file \"'src/lex.c'\"
  126. else
  127.   echo shar: Extracting \"'src/lex.c'\" \(16177 characters\)
  128.   sed "s/^X//" >'src/lex.c' <<'END_OF_FILE'
  129. X/*
  130. X *
  131. X * lex.c - lexical analysis
  132. X *
  133. X * This file is part of zsh, the Z shell.
  134. X *
  135. X * This software is Copyright 1992 by Paul Falstad
  136. X *
  137. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  138. X * use this software as long as: there is no monetary profit gained
  139. X * specifically from the use or reproduction of this software, it is not
  140. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  141. X * included prominently in any copy made. 
  142. X *
  143. X * The author make no claims as to the fitness or correctness of this software
  144. X * for any use whatsoever, and it is provided as is. Any use of this software
  145. X * is at the user's own risk. 
  146. X *
  147. X */
  148. X
  149. X#include "zsh.h"
  150. X
  151. X/* lexical state */
  152. X
  153. Xstatic int xincmdpos,xincond,xincasepat,dbparens,xdbparens,xalstat;
  154. Xstatic char *xhlastw;
  155. X
  156. Xstatic int xisfirstln, xisfirstch, xhistremmed, xhistdone,
  157. X    xspaceflag, xstophist, xlithist, xalstackind,xhlinesz;
  158. Xstatic char *xhline, *xhptr;
  159. X
  160. X/* save the lexical state */
  161. X
  162. X/* is this a hack or what? */
  163. X
  164. Xvoid lexsave() /**/
  165. X{
  166. X    xincmdpos = incmdpos;
  167. X    xincond = incond;
  168. X    xincasepat = incasepat;
  169. X    xdbparens = dbparens;
  170. X    xalstat = alstat;
  171. X    xalstackind = alstackind;
  172. X    xisfirstln = isfirstln;
  173. X    xisfirstch = isfirstch;
  174. X    xhistremmed = histremmed;
  175. X    xhistdone = histdone;
  176. X    xspaceflag = spaceflag;
  177. X    xstophist = stophist;
  178. X    xlithist = lithist;
  179. X    xhline = chline;
  180. X    xhptr = hptr;
  181. X    xhlastw = hlastw;
  182. X    xhlinesz = hlinesz;
  183. X    inredir = 0;
  184. X}
  185. X
  186. X/* restore lexical state */
  187. X
  188. Xvoid lexrestore() /**/
  189. X{
  190. X    incmdpos = xincmdpos;
  191. X    incond = xincond;
  192. X    incasepat = xincasepat;
  193. X    dbparens = xdbparens;
  194. X    alstat = xalstat;
  195. X    isfirstln = xisfirstln;
  196. X    isfirstch = xisfirstch;
  197. X    histremmed = xhistremmed;
  198. X    histdone = xhistdone;
  199. X    spaceflag = xspaceflag;
  200. X    stophist = xstophist;
  201. X    lithist = xlithist;
  202. X    chline = xhline;
  203. X    hptr = xhptr;
  204. X    hlastw = xhlastw;
  205. X    clearalstack();
  206. X    alstackind = xalstackind;
  207. X    hlinesz = xhlinesz;
  208. X    lexstop = errflag = 0;
  209. X}
  210. X
  211. Xvoid yylex() /**/
  212. X{
  213. X    if (tok == LEXERR) return;
  214. X    do
  215. X        tok = gettok();
  216. X    while (tok != ENDINPUT && exalias());
  217. X    if (tok != NEWLIN) isnewlin = 0;
  218. X    else isnewlin = (inbufct) ? -1 : 1;
  219. X    if (tok == SEMI || tok == NEWLIN) tok = SEPER;
  220. X}
  221. X
  222. Xvoid ctxtlex() /**/
  223. X{
  224. Xstatic int oldpos;
  225. X
  226. X    yylex();
  227. X    switch (tok) {
  228. X    case SEPER: case NEWLIN: case SEMI: case DSEMI: case AMPER:
  229. X    case INPAR: case INBRACE: case DBAR: case DAMPER: case BAR:
  230. X    case BARAMP: case INOUTPAR: case DO: case THEN: case ELIF:
  231. X    case ELSE: incmdpos = 1; break;
  232. X    case STRING: /* case ENVSTRING: */ case ENVARRAY: case OUTPAR:
  233. X    case CASE: incmdpos = 0; break;
  234. X    }
  235. X    if (IS_REDIROP(tok) || tok == FOR || tok == FOREACH || tok == SELECT) {
  236. X        inredir = 1;
  237. X        oldpos = incmdpos;
  238. X        incmdpos = 0;
  239. X    } else if (inredir) {
  240. X        incmdpos = oldpos;
  241. X        inredir = 0;
  242. X    }
  243. X}
  244. X
  245. X#define LX1_BKSLASH 0
  246. X#define LX1_COMMENT 1
  247. X#define LX1_NEWLIN 2
  248. X#define LX1_SEMI 3
  249. X#define LX1_BANG 4
  250. X#define LX1_AMPER 5
  251. X#define LX1_BAR 6
  252. X#define LX1_INPAR 7
  253. X#define LX1_OUTPAR 8
  254. X#define LX1_INBRACE 9
  255. X#define LX1_OUTBRACE 10
  256. X#define LX1_INBRACK 11
  257. X#define LX1_OUTBRACK 12
  258. X#define LX1_INANG 13
  259. X#define LX1_OUTANG 14
  260. X#define LX1_OTHER 15
  261. X
  262. X#define LX2_BREAK 0
  263. X#define LX2_OUTPAR 1
  264. X#define LX2_BAR 2
  265. X#define LX2_STRING 3
  266. X#define LX2_INBRACK 4
  267. X#define LX2_OUTBRACK 5
  268. X#define LX2_TILDE 6
  269. X#define LX2_INPAR 7
  270. X#define LX2_INBRACE 8
  271. X#define LX2_OUTBRACE 9
  272. X#define LX2_OUTANG 10
  273. X#define LX2_INANG 11
  274. X#define LX2_EQUALS 12
  275. X#define LX2_BKSLASH 13
  276. X#define LX2_QUOTE 14
  277. X#define LX2_DQUOTE 15
  278. X#define LX2_BQUOTE 16
  279. X#define LX2_OTHER 17
  280. X
  281. Xunsigned char lexact1[256],lexact2[256],lextok2[256];
  282. X
  283. Xvoid initlextabs() /**/
  284. X{
  285. Xint t0;
  286. Xstatic char *lx1 = "\\q\n;!&|(){}[]<>xx";
  287. Xstatic char *lx2 = "x)|$[]~({}><=\\\'\"`x";
  288. X
  289. X    for (t0 = 0; t0 != 256; t0++) {
  290. X        lexact1[t0] = LX1_OTHER;
  291. X        lexact2[t0] = LX2_OTHER;
  292. X        lextok2[t0] = t0;
  293. X    }
  294. X    for (t0 = 0; lx1[t0]; t0++)
  295. X        if (lx1[t0] != 'x')
  296. X            lexact1[(int)lx1[t0]] = t0;
  297. X    for (t0 = 0; lx2[t0]; t0++)
  298. X        if (lx2[t0] != 'x')
  299. X            lexact2[(int)lx2[t0]] = t0;
  300. X    lexact2[';'] = LX2_BREAK;
  301. X    lexact2['&'] = LX2_BREAK;
  302. X    lextok2[','] = Comma;
  303. X    lextok2['*'] = Star;
  304. X    lextok2['?'] = Quest;
  305. X    lextok2['{'] = Inbrace;
  306. X    lextok2['['] = Inbrack;
  307. X    lextok2['$'] = String;
  308. X}
  309. X
  310. X/* initialize lexical state */
  311. X
  312. Xvoid lexinit() /**/
  313. X{
  314. X    incond = incasepat = nocorrect =
  315. X        dbparens = alstat = lexstop = 0;
  316. X    incmdpos = 1;
  317. X    tok = ENDINPUT;
  318. X    if (isset(EXTENDEDGLOB))
  319. X        {
  320. X        lextok2['#'] = Pound;
  321. X        lextok2['^'] = Hat;
  322. X        }
  323. X    else
  324. X        {
  325. X        lextok2['#'] = '#'; 
  326. X        lextok2['^'] = '^';
  327. X        }
  328. X}
  329. X
  330. Xint len = 0,bsiz = 256;
  331. Xchar *bptr;
  332. X
  333. X/* add a char to the string buffer */
  334. X
  335. Xvoid add(c) /**/
  336. Xint c;
  337. X{
  338. X    *bptr++ = c;
  339. X    if (bsiz == ++len)
  340. X        {
  341. X        int newbsiz;
  342. X
  343. X        newbsiz = bsiz * 8;
  344. X        while (newbsiz < inbufct)
  345. X            newbsiz *= 2;
  346. X        bptr = len+(tokstr = hrealloc(tokstr,bsiz,newbsiz));
  347. X        bsiz = newbsiz;
  348. X        }
  349. X}
  350. X
  351. Xstatic void unadd()
  352. X{
  353. X    bptr--; len--;
  354. X}
  355. X
  356. Xint gettok() /**/
  357. X{
  358. Xint bct = 0,pct = 0,brct = 0;
  359. Xint c,d,intpos = 1;
  360. Xint peekfd = -1,peek,ninbracks;
  361. X
  362. Xbeginning:
  363. X    hlastw = NULL;
  364. X    tokstr = NULL;
  365. X    parbegin = -1;
  366. X    while (iblank(c = hgetc()) && !lexstop);
  367. X    isfirstln = 0;
  368. X    wordbeg = inbufct;
  369. X    hwbegin();
  370. X    hwaddc(c);
  371. X    if (dbparens)    /* handle ((...)) */
  372. X        {
  373. X        pct = 2;
  374. X        peek = STRING;
  375. X        len = dbparens = 0;
  376. X        bptr = tokstr = ncalloc(bsiz = 256);
  377. X        for (;;)
  378. X            {
  379. X            if (c == '(')
  380. X                pct++;
  381. X            else if (c == ')')
  382. X                pct--;
  383. X            else if (c == '\n')
  384. X                {
  385. X                zerr("parse error: )) expected",NULL,0);
  386. X                peek = LEXERR;
  387. X                return peek;
  388. X                }
  389. X            else if (c == '$')
  390. X                c = String;
  391. X            if (pct >= 2)
  392. X                add(c);
  393. X            if (pct)
  394. X                c = hgetc();
  395. X            else
  396. X                break;
  397. X            }
  398. X        *bptr = '\0';
  399. X        return peek;
  400. X        }
  401. X    if (idigit(c))    /* handle 1< foo */
  402. X        {
  403. X        d = hgetc();
  404. X        hungetc(d);
  405. X        lexstop = 0;
  406. X        if (d == '>' || d == '<')
  407. X            {
  408. X            peekfd = c-'0';
  409. X            c = hgetc();
  410. X            }
  411. X        }
  412. X
  413. X    /* chars in initial position in word */
  414. X
  415. X    if (c == hashchar &&
  416. X            (isset(INTERACTIVECOMMENTS) ||
  417. X            (!zleparse && (!interact || unset(SHINSTDIN) || strin))))
  418. X        {
  419. X        /* History is handled here to prevent extra newlines
  420. X         * being inserted into the history.
  421. X         *
  422. X         * Also ignore trailing spaces to prevent history from
  423. X         * changing. If trailing spaces are not ignored then
  424. X         * each time a comment inside a command (a 'for' loop
  425. X         * is a good example) is seen an extra space is appended
  426. X         * to the end of the comment causing a new history entry
  427. X         * even if HISTIGNOREDUPS is set.
  428. X         */
  429. X        int nsp = 0;        /* number of contiguos spaces */
  430. X        while ((c = hgetch()) != '\n' && !lexstop) {
  431. X            if (c == ' ')
  432. X                ++nsp;
  433. X            else {
  434. X                while (nsp) {
  435. X                    hwaddc(' ');
  436. X                    --nsp;
  437. X                }
  438. X                hwaddc(c);
  439. X            }
  440. X        }
  441. X        if (c == '\n') {
  442. X            hwadd();
  443. X            hwbegin();
  444. X            hwaddc(c);
  445. X             peek = NEWLIN;
  446. X         } else {
  447. X             peek = (errflag) ? LEXERR : ENDINPUT;
  448. X             errflag = 1;
  449. X         }
  450. X        return peek;
  451. X        }
  452. X    if (lexstop)
  453. X        return (errflag) ? LEXERR : ENDINPUT;
  454. X    switch (lexact1[(unsigned char) c])
  455. X        {
  456. X        case LX1_BKSLASH:
  457. X            d = hgetc();
  458. X            if (d == '\n')
  459. X                goto beginning;
  460. X            hungetc(d);
  461. X            break;
  462. X        case LX1_NEWLIN: return NEWLIN;
  463. X        case LX1_SEMI:
  464. X            d = hgetc();
  465. X            if (d != ';')
  466. X                {
  467. X                hungetc(d);
  468. X                return SEMI;
  469. X                }
  470. X            return DSEMI;
  471. X        case LX1_BANG:
  472. X            d = hgetc();
  473. X            hungetc(d);
  474. X            if (!inblank(d))
  475. X                break;
  476. X            if (incmdpos || incond)
  477. X                return BANG;
  478. X            break;
  479. X        case LX1_AMPER:
  480. X            d = hgetc();
  481. X            if (d != '&')
  482. X                {
  483. X                hungetc(d);
  484. X                return AMPER;
  485. X                }
  486. X            return DAMPER;
  487. X        case LX1_BAR:
  488. X            d = hgetc();
  489. X            if (d == '|')
  490. X                return DBAR;
  491. X            else if (d == '&')
  492. X                return BARAMP;
  493. X            hungetc(d);
  494. X            return BAR;
  495. X        case LX1_INPAR:
  496. X            d = hgetc();
  497. X            if (d == '(' && incmdpos)
  498. X                {
  499. X                tokstr = strdup("let");
  500. X                dbparens = 1;
  501. X                return STRING;
  502. X                }
  503. X            else if (d == ')')
  504. X                return INOUTPAR;
  505. X            hungetc(d);
  506. X            if (!(incond || incmdpos))
  507. X                break;
  508. X            return INPAR;
  509. X        case LX1_OUTPAR: return OUTPAR;
  510. X        case LX1_INBRACE: if (!incmdpos) break; return INBRACE;
  511. X        case LX1_OUTBRACE: return OUTBRACE;
  512. X        case LX1_INBRACK:
  513. X            if (!incmdpos)
  514. X                break;
  515. X            d = hgetc();
  516. X            if (d == '[')
  517. X                return DINBRACK;
  518. X            hungetc(d);
  519. X            break;
  520. X        case LX1_OUTBRACK:
  521. X            if (!incond)
  522. X                break;
  523. X            d = hgetc();
  524. X            if (d == ']')
  525. X                return DOUTBRACK;
  526. X            hungetc(d);
  527. X            break;
  528. X        case LX1_INANG:
  529. X            d = hgetc();
  530. X            if ((!incmdpos && d == '(') || incasepat ||
  531. X                    idigit(d) || d == '-' || d == '>') {
  532. X                hungetc(d);
  533. X                break;
  534. X            } else if (d == '<') {
  535. X                int e = hgetc();
  536. X
  537. X                if (e == '(') {
  538. X                    hungetc(e);
  539. X                    hungetc(d);
  540. X                    peek = INANG;
  541. X                } else if (e == '<')
  542. X                    peek = TRINANG;
  543. X                else if (e == '-')
  544. X                    peek = DINANGDASH;
  545. X                else {
  546. X                    hungetc(e);
  547. X                    peek = DINANG;
  548. X                }
  549. X            } else if (d == '&')
  550. X                peek = INANGAMP;
  551. X            else {
  552. X                peek = INANG;
  553. X                hungetc(d);
  554. X            }
  555. X            tokfd = peekfd;
  556. X            return peek;
  557. X        case LX1_OUTANG:
  558. X            d = hgetc();
  559. X            if (d == '(')
  560. X                {
  561. X                hungetc(d);
  562. X                break;
  563. X                }
  564. X            else if (d == '&')
  565. X                {
  566. X                d = hgetc();
  567. X                if (d == '!')
  568. X                    peek = OUTANGAMPBANG;
  569. X                else
  570. X                    {
  571. X                    hungetc(d);
  572. X                    peek = OUTANGAMP;
  573. X                    }
  574. X                }
  575. X            else if (d == '!')
  576. X                peek = OUTANGBANG;
  577. X            else if (d == '>')
  578. X                {
  579. X                d = hgetc();
  580. X                if (d == '&')
  581. X                    {
  582. X                    d = hgetc();
  583. X                    if (d == '!')
  584. X                        peek = DOUTANGAMPBANG;
  585. X                    else
  586. X                        {
  587. X                        hungetc(d);
  588. X                        peek = DOUTANGAMP;
  589. X                        }
  590. X                    }
  591. X                else if (d == '!')
  592. X                    peek = DOUTANGBANG;
  593. X                else if (d == '(')
  594. X                    {
  595. X                    hungetc(d);
  596. X                    hungetc('>');
  597. X                    peek = OUTANG;
  598. X                    }
  599. X                else
  600. X                    {
  601. X                    hungetc(d);
  602. X                    peek = DOUTANG;
  603. X                    if (isset(NOCLOBBER)) hwaddc('!');
  604. X                    }
  605. X                }
  606. X            else
  607. X                {
  608. X                hungetc(d);
  609. X                peek = OUTANG;
  610. X                if (isset(NOCLOBBER)) hwaddc('!');
  611. X                }
  612. X            tokfd = peekfd;
  613. X            return peek;
  614. X        }
  615. X
  616. X    /* we've started a string, now get the rest of it, performing
  617. X        tokenization */
  618. X
  619. X    peek = STRING;
  620. X    len = 0;
  621. X    bptr = tokstr = ncalloc(bsiz = 256);
  622. X    for(;;)
  623. X        {
  624. X        int act;
  625. X        int d;
  626. X        
  627. X        if (inblank(c) && !bct)
  628. X            act = LX2_BREAK;
  629. X        else
  630. X            {
  631. X            act = lexact2[(unsigned char) c];
  632. X            c = lextok2[(unsigned char) c];
  633. X            }
  634. X        switch (act)
  635. X            {
  636. X            case LX2_BREAK: goto brk;
  637. X            case LX2_OUTPAR:
  638. X                if (!pct)
  639. X                    goto brk;
  640. X                c = Outpar;
  641. X                pct--;
  642. X                break;
  643. X            case LX2_BAR:
  644. X                if (!pct && !incasepat)
  645. X                    goto brk;
  646. X                c = Bar;
  647. X                break;
  648. X            case LX2_STRING:
  649. X                d = hgetc();
  650. X                if (d == '[')
  651. X                    {
  652. X                    add(String);
  653. X                    add(Inbrack);
  654. X                    ninbracks = 1;
  655. X                    while (ninbracks && (c = hgetc()) && !lexstop) {
  656. X                        if (c == '[') ninbracks++;
  657. X                        else if (c == ']') ninbracks--;
  658. X                        if (ninbracks) add(c);
  659. X                    }
  660. X                    c = Outbrack;
  661. X                    }
  662. X                else if (d == '(')
  663. X                    {
  664. X                    add(String);
  665. X                    if (skipcomm()) { peek = LEXERR; goto brk; }
  666. X                    c = Outpar;
  667. X                    }
  668. X                else
  669. X                    hungetc(d);
  670. X                break;
  671. X            case LX2_INBRACK: brct++; break;
  672. X            case LX2_OUTBRACK:
  673. X                if (incond && !brct)
  674. X                    goto brk;
  675. X                brct--;
  676. X                c = Outbrack;
  677. X                break;
  678. X            case LX2_TILDE: /* if (intpos) */ c = Tilde; break;
  679. X            case LX2_INPAR:
  680. X                d = hgetc();
  681. X                hungetc(d);
  682. X                if (d == ')' || (incmdpos && peek != ENVSTRING))
  683. X                    goto brk;
  684. X                pct++;
  685. X                c = Inpar;
  686. X                break;
  687. X            case LX2_INBRACE: bct++; break;
  688. X            case LX2_OUTBRACE:
  689. X                if (!bct)
  690. X                    goto brk;
  691. X                bct--;
  692. X                c = Outbrace;
  693. X                break;
  694. X            case LX2_OUTANG:
  695. X                d = hgetc();
  696. X                if (d != '(')
  697. X                    {
  698. X                    hungetc(d);
  699. X                    goto brk;
  700. X                    }
  701. X                add(Outang);
  702. X                if (skipcomm()) { peek = LEXERR; goto brk; }
  703. X                c = Outpar;
  704. X                break;
  705. X            case LX2_INANG:
  706. X                d = hgetc();
  707. X                if (!(idigit(d) || d == '-' || d == '>' || d == '(' || d == ')'))
  708. X                    {
  709. X                    hungetc(d);
  710. X                    goto brk;
  711. X                    }
  712. X                c = Inang;
  713. X                if (d == '(')
  714. X                    {
  715. X                    add(c);
  716. X                    if (skipcomm()) { peek = LEXERR; goto brk; }
  717. X                    c = Outpar;
  718. X                    }
  719. X                else if (d == ')')
  720. X                    hungetc(d);
  721. X                else
  722. X                    {
  723. X                    add(c);
  724. X                    c = d;
  725. X                    while (c != '>' && !lexstop)
  726. X                        add(c),c = hgetc();
  727. X                    c = Outang;
  728. X                    }
  729. X                break;
  730. X            case LX2_EQUALS:
  731. X                if (intpos)
  732. X                    {
  733. X                    d = hgetc();
  734. X                    if (d != '(')
  735. X                        {
  736. X                        hungetc(d);
  737. X                        c = Equals;
  738. X                        }
  739. X                    else
  740. X                        {
  741. X                        add(Equals);
  742. X                        if (skipcomm()) { peek = LEXERR; goto brk; }
  743. X                        c = Outpar;
  744. X                        }
  745. X                    }
  746. X                else if (peek != ENVSTRING && incmdpos && !bct)
  747. X                    {
  748. X                    d = hgetc();
  749. X                    if (d == '(' && incmdpos)
  750. X                        {
  751. X                        *bptr = '\0';
  752. X                        return ENVARRAY;
  753. X                        }
  754. X                    hungetc(d);
  755. X                    peek = ENVSTRING;
  756. X                    intpos = 2;
  757. X                    }
  758. X                break;
  759. X            case LX2_BKSLASH:
  760. X                c = hgetc();
  761. X                if (c == '\n')
  762. X                    {
  763. X                    c = hgetc();
  764. X                    continue;
  765. X                    }
  766. X                add(Bnull);
  767. X                add(c);
  768. X                c = hgetc();
  769. X                continue;
  770. X            case LX2_QUOTE:
  771. X                add(Snull);
  772. X
  773. X                /* we add the Nularg to prevent this:
  774. X
  775. X                echo $PA'TH'
  776. X
  777. X                from printing the path. */
  778. X
  779. X                for (;;) {
  780. X                    while ((c = hgetc()) != '\'' && !lexstop) {
  781. X                        if (isset(CSHJUNKIEQUOTES) && c == '\n') {
  782. X                            if (bptr[-1] == '\\') unadd(); else break;
  783. X                        }
  784. X                        add(c);
  785. X                    }
  786. X                    if (c != '\'') {
  787. X                        zerr("unmatched \'",NULL,0);
  788. X                        peek = LEXERR;
  789. X                        goto brk;
  790. X                    }
  791. X                    d = hgetc();
  792. X                    if (d != '\'' || unset(RCQUOTES)) break;
  793. X                    add(c);
  794. X                }
  795. X                hungetc(d);
  796. X                c = Snull;
  797. X                break;
  798. X            case LX2_DQUOTE:
  799. X                add(Dnull);
  800. X                while ((c = hgetc()) != '\"' && !lexstop)
  801. X                    if (c == '\\')
  802. X                        {
  803. X                        c = hgetc();
  804. X                        if (c != '\n')
  805. X                            {
  806. X                            if (c != '$' && c != '\\' && c != '\"' && c != '`')
  807. X                                add('\\');
  808. X                            add(c);
  809. X                            }
  810. X                        }
  811. X                    else {
  812. X                        if (isset(CSHJUNKIEQUOTES) && c == '\n') {
  813. X                            if (bptr[-1] == '\\') unadd(); else break;
  814. X                        }
  815. X                        if (c == '$') {
  816. X                            d = hgetc();
  817. X                            if (d == '(') {
  818. X                                add(Qstring);
  819. X                                if (skipcomm()) { peek = LEXERR; goto brk; }
  820. X                                c = Outpar;
  821. X                            } else if (d == '[') {
  822. X                                add(String);
  823. X                                add(Inbrack);
  824. X                                while ((c = hgetc()) != ']' && !lexstop)
  825. X                                    add(c);
  826. X                                c = Outbrack;
  827. X                            } else {
  828. X                                c = Qstring;
  829. X                                hungetc(d);
  830. X                            }
  831. X                        } else if (c == '`')
  832. X                            c = Qtick;
  833. X                        add(c);
  834. X                    }
  835. X                if (c != '\"') {
  836. X                    zerr("unmatched \"",NULL,0);
  837. X                    peek = LEXERR;
  838. X                    goto brk;
  839. X                }
  840. X                c = Dnull;
  841. X                break;
  842. X            case LX2_BQUOTE:
  843. X                add(Tick);
  844. X                parbegin = inbufct;
  845. X                while ((c = hgetc()) != '`' && !lexstop)
  846. X                    if (c == '\\')
  847. X                        {
  848. X                        c = hgetc();
  849. X                        if (c != '\n')
  850. X                            {
  851. X                            if (c != '`' && c != '\\' && c != '$')
  852. X                                add('\\');
  853. X                            add(c);
  854. X                            }
  855. X                        }
  856. X                    else {
  857. X                        if (isset(CSHJUNKIEQUOTES) && c == '\n') {
  858. X                            if (bptr[-1] == '\\') unadd(); else break;
  859. X                        }
  860. X                        add(c);
  861. X                    }
  862. X                if (c != '`') {
  863. X                    if (!zleparse) zerr("unmatched `",NULL,0);
  864. X                    peek = LEXERR;
  865. X                    goto brk;
  866. X                }
  867. X                c = Tick;
  868. X                parbegin = -1;
  869. X                break;
  870. X            }
  871. X        add(c);
  872. X        c = hgetc();
  873. X        if (intpos)
  874. X            intpos--;
  875. X        if (lexstop)
  876. X            break;
  877. X        }
  878. Xbrk:
  879. X    hungetc(c);
  880. X    *bptr = '\0';
  881. X    return peek;
  882. X}
  883. X
  884. X/* expand aliases, perhaps */
  885. X
  886. Xint exalias() /**/
  887. X{
  888. Xstruct alias *an;
  889. Xchar *s,*t;
  890. X
  891. X    s = yytext = hwadd();
  892. X    for (t = s; *t && *t != HISTSPACE; t++);
  893. X    if (!*t)
  894. X        t = NULL;
  895. X    else
  896. X        *t = '\0';
  897. X    if (interact && isset(SHINSTDIN) && !strin && !incasepat && tok == STRING &&
  898. X        (isset(CORRECTALL) || (isset(CORRECT) && incmdpos)) && !nocorrect)
  899. X            spckword(&tokstr,&s,&t,!incmdpos,1);
  900. X    if (zleparse && !alstackind) {
  901. X        int zp = zleparse;
  902. X        gotword(s);
  903. X        if (zp && !zleparse) {
  904. X            if (t) *t = HISTSPACE;
  905. X            return 0;
  906. X        }
  907. X    }
  908. X    an = gethnode(s,aliastab);
  909. X    if (t) *t = HISTSPACE;
  910. X    if (alstackind != MAXAL && an && !an->inuse)
  911. X        if (!(an->cmd && !incmdpos && alstat != ALSTAT_MORE)) {
  912. X            if (an->cmd < 0) {
  913. X                tok = DO-an->cmd-1;
  914. X                return 0;
  915. X            } else {
  916. X                an->inuse = 1;
  917. X                hungets(ALPOPS);
  918. X                hungets((alstack[alstackind++] = an)->text);
  919. X                alstat = 0;
  920. X                /* remove from history if it begins with space */
  921. X                if (isset(HISTIGNORESPACE) && an->text[0] == ' ') remhist();
  922. X                lexstop = 0;
  923. X                return 1;
  924. X            }
  925. X        }
  926. X    return 0;
  927. X}
  928. X
  929. X/* skip (...) */
  930. X
  931. Xint skipcomm() /**/
  932. X{
  933. Xint pct = 1,c;
  934. X
  935. X    parbegin = inbufct;
  936. X    c = Inpar;
  937. X    do
  938. X        {
  939. X        add(c);
  940. X        c = hgetc();
  941. X        if (itok(c) || lexstop)
  942. X            break;
  943. X        else if (c == '(') pct++;
  944. X        else if (c == ')') pct--;
  945. X        else if (c == '\\')
  946. X            {
  947. X            add(c);
  948. X            c = hgetc();
  949. X            }
  950. X        else if (c == '\'')
  951. X            {
  952. X            add(c);
  953. X            while ((c = hgetc()) != '\'' && !lexstop)
  954. X                add(c);
  955. X            }
  956. X        else if (c == '\"')
  957. X            {
  958. X            add(c);
  959. X            while ((c = hgetc()) != '\"' && !lexstop)
  960. X                if (c == '\\')
  961. X                    {
  962. X                    add(c);
  963. X                    add(hgetc());
  964. X                    }
  965. X                else add(c);
  966. X            }
  967. X        else if (c == '`')
  968. X            {
  969. X            add(c);
  970. X            while ((c = hgetc()) != '`' && !lexstop)
  971. X                if (c == '\\') add(c), add(hgetc());
  972. X                else add(c);
  973. X            }
  974. X        }
  975. X    while(pct);
  976. X    if (!lexstop) parbegin = -1;
  977. X    return lexstop;
  978. X}
  979. END_OF_FILE
  980.   if test 16177 -ne `wc -c <'src/lex.c'`; then
  981.     echo shar: \"'src/lex.c'\" unpacked with wrong size!
  982.   fi
  983.   # end of 'src/lex.c'
  984. fi
  985. if test -f 'src/zle_main.c' -a "${1}" != "-c" ; then 
  986.   echo shar: Will not clobber existing file \"'src/zle_main.c'\"
  987. else
  988.   echo shar: Extracting \"'src/zle_main.c'\" \(15021 characters\)
  989.   sed "s/^X//" >'src/zle_main.c' <<'END_OF_FILE'
  990. X/*
  991. X *
  992. X * zle_main.c - main routines for line editor
  993. X *
  994. X * This file is part of zsh, the Z shell.
  995. X *
  996. X * This software is Copyright 1992 by Paul Falstad
  997. X *
  998. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  999. X * use this software as long as: there is no monetary profit gained
  1000. X * specifically from the use or reproduction of this software, it is not
  1001. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1002. X * included prominently in any copy made. 
  1003. X *
  1004. X * The author make no claims as to the fitness or correctness of this software
  1005. X * for any use whatsoever, and it is provided as is. Any use of this software
  1006. X * is at the user's own risk. 
  1007. X *
  1008. X */
  1009. X
  1010. X#define ZLEGLOBALS
  1011. X#define ZLE
  1012. X#include "zsh.h"
  1013. X#include <sys/types.h>
  1014. X#include <sys/errno.h>
  1015. X#ifdef HAS_SYS_SELECT
  1016. X#include <sys/select.h>
  1017. X#endif
  1018. X
  1019. Xstatic Key cky;
  1020. X
  1021. X/* set up terminal */
  1022. X
  1023. Xvoid setterm() /**/
  1024. X{
  1025. Xstruct ttyinfo ti;
  1026. X#ifdef CLOBBERS_TYPEAHEAD
  1027. X#ifdef FIONREAD
  1028. Xlong val;
  1029. X#endif
  1030. X#endif
  1031. X
  1032. X#ifdef CLOBBERS_TYPEAHEAD
  1033. X#ifdef FIONREAD
  1034. X    ioctl(SHTTY, FIONREAD, &val);
  1035. X    if (val) return;
  1036. X#endif
  1037. X#endif
  1038. X    inittty();
  1039. X    ti = shttyinfo;
  1040. X#ifdef TIO
  1041. X    ti.tio.c_lflag &= ~(ICANON|ECHO
  1042. X#ifdef FLUSHO
  1043. X        |FLUSHO
  1044. X#endif
  1045. X        );
  1046. X    ti.tio.c_cc[VQUIT] =
  1047. X#ifdef VDISCARD
  1048. X        ti.tio.c_cc[VDISCARD] = 
  1049. X#endif
  1050. X#ifdef VSUSP
  1051. X        ti.tio.c_cc[VSUSP] =
  1052. X#endif
  1053. X#ifdef VDSUSP
  1054. X        ti.tio.c_cc[VDSUSP] =
  1055. X#endif
  1056. X#ifdef VSWTCH
  1057. X        ti.tio.c_cc[VSWTCH] =
  1058. X#endif
  1059. X        VDISABLEVAL;
  1060. X    ti.tio.c_cc[VMIN] = 1;
  1061. X    ti.tio.c_cc[VTIME] = 0;
  1062. X    ti.tio.c_iflag &= ~(INLCR|ICRNL);
  1063. X#else
  1064. X    ti.sgttyb.sg_flags = (ti.sgttyb.sg_flags | CBREAK) & ~ECHO;
  1065. X    ti.lmodes &= ~LFLUSHO;
  1066. X    ti.tchars.t_quitc =
  1067. X        ti.ltchars.t_suspc =
  1068. X        ti.ltchars.t_flushc =
  1069. X        ti.ltchars.t_dsuspc = ti.ltchars.t_lnextc = -1;
  1070. X#endif
  1071. X#ifdef TTY_NEEDS_DRAINING
  1072. X    drainoutput();
  1073. X#endif
  1074. X    settyinfo(&ti);
  1075. X}
  1076. X
  1077. Xvoid unsetterm() /**/
  1078. X{
  1079. X    settyinfo(&shttyinfo);
  1080. X}
  1081. X
  1082. Xstatic char *kungetbuf;
  1083. Xstatic int kungetct,kungetsz;
  1084. X
  1085. Xvoid ungetkey(ch) /**/
  1086. Xint ch;
  1087. X{
  1088. X    if (kungetct == kungetsz)
  1089. X        kungetbuf = realloc(kungetbuf,kungetsz *= 2);
  1090. X    kungetbuf[kungetct++] = ch;
  1091. X}
  1092. X
  1093. Xvoid ungetkeys(s,len) /**/
  1094. Xchar *s;int len;
  1095. X{
  1096. X    s += len;
  1097. X    while (len--)
  1098. X        ungetkey(*--s);
  1099. X}
  1100. X
  1101. X#if (defined(hpux) || defined(pyr)) && defined(HAS_SELECT)
  1102. Xstatic int
  1103. Xbreakread(fd, buf, n)
  1104. Xint fd, n;
  1105. Xchar *buf;
  1106. X{
  1107. X    fd_set    f;
  1108. X
  1109. X    FD_ZERO(&f);
  1110. X    FD_SET(fd, &f);
  1111. X    return(select(fd+1, &f, NULL, NULL, NULL) == -1 ? -1 : read(fd, buf, n));
  1112. X}
  1113. X#define    read    breakread
  1114. X#endif
  1115. X
  1116. Xunsigned int getkey(tmok) /**/
  1117. Xint tmok;
  1118. X{
  1119. Xchar cc;
  1120. Xunsigned int ret;
  1121. Xint die = 0, r;
  1122. X
  1123. X    if (kungetct)
  1124. X        ret = (unsigned int) (unsigned char) kungetbuf[--kungetct];
  1125. X    else {
  1126. X        while ( (r = read(0,&cc,1)) != 1){
  1127. X            if ( r == 0 ){
  1128. X                stopmsg = 1;
  1129. X                zexit(1);
  1130. X            }
  1131. X            if (errno == EINTR) {
  1132. X                if (!errflag)
  1133. X                    continue;
  1134. X                errflag = 0;
  1135. X                if (tmok)
  1136. X                    return -1;
  1137. X                return 3;
  1138. X            } else if (errno == EWOULDBLOCK) {
  1139. X                fcntl(0,F_SETFL,0);
  1140. X            } else if (errno == EIO && !die) {
  1141. X                ret = jobbing;
  1142. X                jobbingv = 1;
  1143. X                attachtty(mypgrp);
  1144. X                refresh(); /* kludge! */
  1145. X                jobbingv = ret;
  1146. X                die = 1;
  1147. X            } else if (errno != 0) {
  1148. X                zerr("error on TTY read: %e",NULL,errno);
  1149. X                stopmsg = 1;
  1150. X                zexit(1);
  1151. X            }
  1152. X        }
  1153. X        ret = (unsigned int) (unsigned char) cc;
  1154. X    }
  1155. X    if (vichgflag) {
  1156. X        if (vichgbufptr == vichgbufsz)
  1157. X            vichgbuf = realloc(vichgbuf,vichgbufsz *= 2);
  1158. X        vichgbuf[vichgbufptr++] = ret;
  1159. X    }
  1160. X    return ret;
  1161. X}
  1162. X
  1163. X/* read a line */
  1164. X
  1165. Xunsigned char *zleread(ppt,ppt2,plen) /**/
  1166. Xunsigned char *ppt;unsigned char *ppt2;int plen;
  1167. X{
  1168. Xint z;
  1169. Xlong costmult;
  1170. Xunsigned char *s;
  1171. X#ifdef HAS_SELECT
  1172. Xstruct timeval tv;
  1173. Xfd_set foofd;
  1174. X
  1175. X    tv.tv_sec = 0;
  1176. X#endif
  1177. X    fflush(stdout);
  1178. X    fflush(stderr);
  1179. X    intr();
  1180. X    costmult = 3840000L/((baud) ? baud : 2400);
  1181. X    insmode = unset(OVERSTRIKE); eofsent = 0; resetneeded =0 ;
  1182. X    pmpt = (char *)ppt;
  1183. X    pmpt2 = (char *)ppt2;
  1184. X    permalloc();
  1185. X    histline = curhist;
  1186. X    pptlen = plen;
  1187. X    resetneeded = 1;
  1188. X#ifdef HAS_SELECT
  1189. X    FD_ZERO(&foofd);
  1190. X#endif
  1191. X    undoing = 1;
  1192. X    line = zalloc(linesz = 256);
  1193. X    *line = '\0';
  1194. X    virangeflag = lastcmd = done = cs = ll = mark = 0;
  1195. X    curhistline = NULL;
  1196. X    mult = 1;
  1197. X    vibufspec = 0;
  1198. X    bindtab = mainbindtab;
  1199. X    addedslash = vichgflag = 0;
  1200. X    viinsbegin = 0;
  1201. X    statusline = NULL;
  1202. X    if (s = getnode(bufstack))
  1203. X        {
  1204. X        setline((char *) s);
  1205. X        free(s);
  1206. X        if (stackcs != -1)
  1207. X            {
  1208. X            cs = stackcs;
  1209. X            stackcs = -1;
  1210. X            if (cs > ll)
  1211. X                cs = ll;
  1212. X            }
  1213. X        if (stackhist != -1)
  1214. X            {
  1215. X            histline = stackhist;
  1216. X            stackhist = -1;
  1217. X            }
  1218. X        }
  1219. X    initundo();
  1220. X    if (unset(NOPROMPTCR))
  1221. X        putchar('\r');
  1222. X    if (tmout)
  1223. X        alarm(tmout);
  1224. X    refresh();
  1225. X    errflag = retflag = 0;
  1226. X    while (!done && !errflag)
  1227. X        {
  1228. X        struct zlecmd *zc;
  1229. X        
  1230. X        statusline = NULL;
  1231. X        bindk = getkeycmd();
  1232. X        if (c == 4 && !ll)
  1233. X            {
  1234. X            eofsent = 1;
  1235. X            break;
  1236. X            }
  1237. X        if (bindk != -1)
  1238. X            {
  1239. X            zc = zlecmds+bindk;
  1240. X            if (!(lastcmd & ZLE_ARG))
  1241. X                mult = 1;
  1242. X            if ((lastcmd & ZLE_UNDO) != (zc->flags & ZLE_UNDO) && undoing)
  1243. X                addundo();
  1244. X            if (!(zc->flags & ZLE_MENUCMP)) {
  1245. X                if (menucmp) freemenu();
  1246. X                if (addedslash && !(zc->flags & ZLE_DELETE) &&
  1247. X                        !((zc->flags & ZLE_INSERT) && c != ' ')) {
  1248. X                    backdel(1);
  1249. X                }
  1250. X                addedslash = 0;
  1251. X            }
  1252. X            if (zc->func)
  1253. X                (*zc->func)();
  1254. X            lastcmd = zc->flags;
  1255. X            if (!(lastcmd & ZLE_UNDO) && undoing) addundo();
  1256. X            }
  1257. X        else
  1258. X            {
  1259. X            errflag = 1;
  1260. X            break;
  1261. X            }
  1262. X#ifdef HAS_SELECT
  1263. X        FD_SET(0,&foofd);
  1264. X        if ((tv.tv_usec = cost*costmult) > 500000)
  1265. X            tv.tv_usec = 500000;
  1266. X#endif
  1267. X        if (!kungetct
  1268. X#ifdef HAS_SELECT
  1269. X            && select(1,&foofd,NULL,NULL,&tv) <= 0
  1270. X#endif
  1271. X            )
  1272. X            refresh();
  1273. X        }
  1274. X    if (menucmp)
  1275. X        freemenu();
  1276. X    statusline = NULL;
  1277. X    trashzle();
  1278. X    alarm(0);
  1279. X    z = strlen((char *)line);
  1280. X    line[z] = '\n';
  1281. X    line[z+1] = 0;
  1282. X    heapalloc();
  1283. X    if (curhistline)
  1284. X        free(curhistline);
  1285. X    if (eofsent)
  1286. X        {
  1287. X        free(line);
  1288. X        line = NULL;
  1289. X        }
  1290. X    zleactive = 0;
  1291. X    freeundo();
  1292. X    return line;
  1293. X}
  1294. X
  1295. Xint getkeycmd() /**/
  1296. X{
  1297. Xchar buf[10];
  1298. Xint t0,ret;
  1299. XKey ky;
  1300. X
  1301. X    t0 = 1;
  1302. X    cky = NULL;
  1303. X    if ((c = getkey(1)) == -1)
  1304. X        return -1;
  1305. X    if ((ret = bindtab[c]) == z_sequenceleadin)
  1306. X        {
  1307. X        buf[0] = (c) ? c : 0x80;
  1308. X        for (;;)
  1309. X            {
  1310. X            c = getkey(0);
  1311. X            buf[t0++] = (c) ? c : 0x80;
  1312. X            buf[t0] = '\0';
  1313. X            if (!(ky = (Key) gethnode(buf,xbindtab)))
  1314. X                return z_undefinedkey;
  1315. X            if (ky->func != z_sequenceleadin)
  1316. X                {
  1317. X                cky = ky;
  1318. X                ret = ky->func;
  1319. X                break;
  1320. X                }
  1321. X            }
  1322. X        }
  1323. X    if (ret == z_vidigitorbeginningofline)
  1324. X        ret = (lastcmd & ZLE_ARG) ? z_digitargument : z_beginningofline;
  1325. X    else if (ret == z_executenamedcmd)
  1326. X        ret = executenamedcommand();
  1327. X    else if (ret == z_executelastnamedcmd)
  1328. X        ret = lastnamed;
  1329. X    return ret;
  1330. X}
  1331. X
  1332. Xvoid sendstring() /**/
  1333. X{
  1334. Xchar buf[2];
  1335. X
  1336. X    buf[0] = c;
  1337. X    buf[1] = '\0';
  1338. X    if (!cky)
  1339. X        cky = (Key) gethnode(buf,xbindtab);
  1340. X    ungetkeys(cky->str,cky->len);
  1341. X}
  1342. X
  1343. XKey makefunckey(fun) /**/
  1344. Xint fun;
  1345. X{
  1346. XKey ky = zcalloc(sizeof *ky);
  1347. X
  1348. X    ky->func = fun;
  1349. X    return ky;
  1350. X}
  1351. X
  1352. X/* initialize the bindings */
  1353. X
  1354. Xvoid initxbindtab() /**/
  1355. X{
  1356. Xint t0,vi = 0;
  1357. Xchar buf[3],*s;
  1358. X
  1359. X    lastnamed = z_undefinedkey;
  1360. X    if (s = zgetenv("VISUAL")) {
  1361. X        if (ztrstr(s,"vi"))
  1362. X            vi = 1;
  1363. X    }
  1364. X    else if ((s = zgetenv("EDITOR")) && ztrstr(s,"vi"))
  1365. X        vi = 1;
  1366. X    if (vi) {
  1367. X        for (t0 = 0; t0 != 32; t0++)
  1368. X            mainbindtab[t0] = viinsbind[t0];
  1369. X        for (t0 = 32; t0 != 256; t0++)
  1370. X            mainbindtab[t0] = z_selfinsert;
  1371. X        mainbindtab[127] = z_backwarddeletechar;
  1372. X    } else {
  1373. X        for (t0 = 0; t0 != 128; t0++)
  1374. X            mainbindtab[t0] = emacsbind[t0];
  1375. X        for (t0 = 128; t0 != 256; t0++)
  1376. X            mainbindtab[t0] = z_selfinsert;
  1377. X    }
  1378. X    for (t0 = 0200; t0 != 0240; t0++)
  1379. X        mainbindtab[t0] = z_undefinedkey;
  1380. X    for (t0 = 0; t0 != 128; t0++)
  1381. X        altbindtab[t0] = vicmdbind[t0];
  1382. X    for (t0 = 128; t0 != 256; t0++)
  1383. X        altbindtab[t0] = emacsbind[t0];
  1384. X    bindtab = mainbindtab;
  1385. X    kungetbuf = zalloc(kungetsz = 32);
  1386. X    kungetct = 0;
  1387. X    xbindtab = newhtable(67);
  1388. X    addhperm("\33\133C",makefunckey(z_forwardchar),xbindtab,(FFunc) 0);
  1389. X    addhperm("\33\133D",makefunckey(z_backwardchar),xbindtab,(FFunc) 0);
  1390. X    addhperm("\33\133A",makefunckey(z_uplineorhistory),xbindtab,(FFunc) 0);
  1391. X    addhperm("\33\133B",makefunckey(z_downlineorhistory),xbindtab,(FFunc) 0);
  1392. X    addhperm("\30*",makefunckey(z_expandword),xbindtab,(FFunc) 0);
  1393. X    addhperm("\30g",makefunckey(z_listexpand),xbindtab,(FFunc) 0);
  1394. X    addhperm("\30G",makefunckey(z_listexpand),xbindtab,(FFunc) 0);
  1395. X    addhperm("\30\16",makefunckey(z_infernexthistory),xbindtab,(FFunc) 0);
  1396. X    addhperm("\30\13",makefunckey(z_killbuffer),xbindtab,(FFunc) 0);
  1397. X    addhperm("\30\6",makefunckey(z_vifindnextchar),xbindtab,(FFunc) 0);
  1398. X    addhperm("\30\17",makefunckey(z_overwritemode),xbindtab,(FFunc) 0);
  1399. X    addhperm("\30\25",makefunckey(z_undo),xbindtab,(FFunc) 0);
  1400. X    addhperm("\30\26",makefunckey(z_vicmdmode),xbindtab,(FFunc) 0);
  1401. X    addhperm("\30\12",makefunckey(z_vijoin),xbindtab,(FFunc) 0);
  1402. X    addhperm("\30\2",makefunckey(z_vimatchbracket),xbindtab,(FFunc) 0);
  1403. X    addhperm("\30s",makefunckey(z_historyincrementalsearchforward),
  1404. X        xbindtab,(FFunc) 0);
  1405. X    addhperm("\30r",makefunckey(z_historyincrementalsearchbackward),
  1406. X        xbindtab,(FFunc) 0);
  1407. X    addhperm("\30u",makefunckey(z_undo),xbindtab,(FFunc) 0);
  1408. X    addhperm("\30\30",makefunckey(z_exchangepointandmark),
  1409. X        xbindtab,(FFunc) 0);
  1410. X    addhperm("run-help",mkanode(ztrdup("man"),1),aliastab,(FFunc) 0);
  1411. X    addhperm("which-command",mkanode(ztrdup("whence"),1),aliastab,(FFunc) 0);
  1412. X    strcpy(buf,"\33q");
  1413. X    for (t0 = 128; t0 != 256; t0++)
  1414. X        if (emacsbind[t0] != z_undefinedkey) {
  1415. X            buf[1] = t0 & 0x7f;
  1416. X            addhnode(ztrdup(buf),makefunckey(emacsbind[t0]),xbindtab,(FFunc) 0);
  1417. X        }
  1418. X    for (t0 = 0; t0 != 36; t0++) vibuf[t0] = NULL;
  1419. X    for (t0 = 0; t0 != 26; t0++) vimarkline[t0] = 0;
  1420. X    stackhist = stackcs = -1;
  1421. X    vichgbufsz = 0;
  1422. X    vichgbuf = NULL;
  1423. X    usernamescached=0;
  1424. X}
  1425. X
  1426. Xchar *getkeystring(s,len) /**/
  1427. Xchar *s;int *len;
  1428. X{
  1429. Xstatic char buf[512];
  1430. Xchar *t = buf;
  1431. Xint x,metanext = 0;
  1432. X
  1433. X    for (;*s;s++)
  1434. X        {
  1435. X        if (*s == '\\' && s[1])
  1436. X            switch(*++s)
  1437. X                {
  1438. X                case 'a': *t++ = '\07'; break;
  1439. X                case 'n': *t++ = '\n'; break;
  1440. X                case 'b': *t++ = '\010'; break;
  1441. X                case 't': *t++ = '\t'; break;
  1442. X                case 'v': *t++ = '\v'; break;
  1443. X                case 'f': *t++ = '\f'; break;
  1444. X                case 'r': *t++ = '\r'; break;
  1445. X                case 'e': *t++ = '\033'; break;
  1446. X                case 'M':
  1447. X                    if (s[1] == '-')
  1448. X                        s++;
  1449. X                    metanext = 2;
  1450. X                    break;
  1451. X                default:
  1452. X                    if (idigit(*s))
  1453. X                        {
  1454. X                        for (x = 0; idigit(*s); s++)
  1455. X                            x = x*8+(*s-'0');
  1456. X                        s--;
  1457. X                        *t++ = x;
  1458. X                        }
  1459. X                    else
  1460. X                        *t++ = *s;
  1461. X                    break;
  1462. X                }
  1463. X        else if (*s == '^')
  1464. X            if (*++s == '?')
  1465. X                *t++ = 0x7f;
  1466. X            else
  1467. X                *t++ = *s & 0x9f;
  1468. X        else
  1469. X            *t++ = *s;
  1470. X        if (metanext && !(--metanext))
  1471. X            {
  1472. X            t[-1] |= 0x80;
  1473. X            metanext = 0;
  1474. X            }
  1475. X        if (t > buf+500)
  1476. X            break;
  1477. X        }
  1478. X    *t = '\0';
  1479. X    *len = t-buf;
  1480. X    return buf;
  1481. X}
  1482. X
  1483. Xvoid printbind(s,len) /**/
  1484. Xchar *s;int len;
  1485. X{
  1486. Xint ch;
  1487. X
  1488. X    while (len--)
  1489. X        {
  1490. X        ch = (unsigned char) *s++;
  1491. X        if (ch & 0x80)
  1492. X            {
  1493. X            printf("\\M-");
  1494. X            ch &= 0x7f;
  1495. X            }
  1496. X        if (icntrl(ch))
  1497. X            switch(ch)
  1498. X                {
  1499. X                case 0x7f: printf("^?"); break;
  1500. X                default: printf("^%c",(ch|0x40)); break;
  1501. X                }
  1502. X        else
  1503. X            putchar(ch);
  1504. X        }
  1505. X}
  1506. X
  1507. Xvoid printbinding(str,k) /**/
  1508. Xchar *str;Key k;
  1509. X{
  1510. X    if (k->func == z_sequenceleadin)
  1511. X        return;
  1512. X    putchar('\"');
  1513. X    printbind(str,strlen(str));
  1514. X    printf("\"\t");
  1515. X    if (k->func == z_sendstring)
  1516. X        {
  1517. X        putchar('\"');
  1518. X        printbind(k->str,k->len);
  1519. X        printf("\"\n");
  1520. X        }
  1521. X    else
  1522. X        printf("%s\n",zlecmds[k->func].name);
  1523. X}
  1524. X
  1525. Xint bin_bindkey(name,argv,ops,junc) /**/
  1526. Xchar *name;char **argv;char *ops;int junc;
  1527. X{
  1528. Xint t0 = 0,len;
  1529. Xchar *s;
  1530. Xint func,*tab;
  1531. X
  1532. X    tab = (ops['a']) ? altbindtab : mainbindtab;
  1533. X    if (ops['v'] || ops['e'] || ops['d'])
  1534. X        {
  1535. X        if (*argv)
  1536. X            {
  1537. X            zerrnam(name,"too many arguments",NULL,0);
  1538. X            return 1;
  1539. X            }
  1540. X        if (ops['d'] || ops['e'])
  1541. X            if (ops['m'])
  1542. X                for (t0 = 0; t0 != 256; t0++)
  1543. X                    tab[t0] = emacsbind[t0];
  1544. X            else
  1545. X                {
  1546. X                for (t0 = 0; t0 != 128; t0++)
  1547. X                    tab[t0] = emacsbind[t0];
  1548. X                for (t0 = 128; t0 != 256; t0++)
  1549. X                    tab[t0] = z_selfinsert;
  1550. X                }
  1551. X        else
  1552. X            {
  1553. X            for (t0 = 0; t0 != 32; t0++)
  1554. X                mainbindtab[t0] = viinsbind[t0];
  1555. X            for (t0 = 32; t0 != 256; t0++)
  1556. X                mainbindtab[t0] = z_selfinsert;
  1557. X            mainbindtab[127] = z_backwarddeletechar;
  1558. X            }
  1559. X        for (t0 = 0; t0 != 128; t0++)
  1560. X            altbindtab[t0] = vicmdbind[t0];
  1561. X        for (t0 = 128; t0 != 256; t0++)
  1562. X            altbindtab[t0] = emacsbind[t0];
  1563. X        for (t0 = 0200; t0 != 0240; t0++)
  1564. X            tab[t0] = z_undefinedkey;
  1565. X        return 0;
  1566. X        }
  1567. X    if (!*argv)
  1568. X        {
  1569. X        char buf[2];
  1570. X        
  1571. X        buf[0] = 'x'; buf[1] = '\0';
  1572. X        for (t0 = 0; t0 != 256; t0++)
  1573. X            {
  1574. X            buf[0] = t0;
  1575. X            putchar('\"');
  1576. X            printbind(buf,1);
  1577. X            if (t0 < 254 && tab[t0] == tab[t0+1] && tab[t0] == tab[t0+2])
  1578. X                {
  1579. X                printf("\" to \"");
  1580. X                while (tab[t0] == tab[t0+1]) t0++;
  1581. X                buf[0] = t0;
  1582. X                printbind(buf,1);
  1583. X                }
  1584. X            printf("\"\t%s\n",zlecmds[tab[t0]].name);
  1585. X            }
  1586. X        listhtable(xbindtab,(HFunc) printbinding);
  1587. X        return 0;
  1588. X        }
  1589. X    while (*argv)
  1590. X        {
  1591. X        s = getkeystring(*argv++,&len);
  1592. X        if (len > 8)
  1593. X            {
  1594. X            zerrnam(name,"in-string too long",NULL,0);
  1595. X            return 1;
  1596. X            }
  1597. X        if (!*argv || ops['r'])
  1598. X            {
  1599. X            Key ky;
  1600. X
  1601. X            ky = gethnode(s,xbindtab);
  1602. X            if (len == 1)
  1603. X                func = tab[(unsigned char) *s];
  1604. X            else
  1605. X                func = (ky) ? ky->func : z_undefinedkey;
  1606. X            if (func == z_undefinedkey)
  1607. X                {
  1608. X                zerrnam(name,"in-string is not bound",NULL,0);
  1609. X                return 1;
  1610. X                }
  1611. X            if (ops['r'])
  1612. X                {
  1613. X                if (len == 1)
  1614. X                    tab[(unsigned char) *s] = z_undefinedkey;
  1615. X                else
  1616. X                    {
  1617. X                    while (strlen(s) > 1)
  1618. X                        {
  1619. X                        free(remhnode(s,xbindtab));
  1620. X                        s[strlen(s)-1] = '\0';
  1621. X                        }
  1622. X                    }
  1623. X                continue;
  1624. X                }
  1625. X            if (func == z_sendstring)
  1626. X                {
  1627. X                printbind(ky->str,ky->len);
  1628. X                putchar('\n');
  1629. X                return 0;
  1630. X                }
  1631. X            printf("%s\n",zlecmds[func].name);
  1632. X            return 0;
  1633. X            }
  1634. X        if (!ops['s'])
  1635. X            {
  1636. X            for (t0 = 0; t0 != ZLECMDCOUNT; t0++)
  1637. X                if (!strcmp(*argv,zlecmds[t0].name))
  1638. X                    break;
  1639. X            if (t0 == ZLECMDCOUNT)
  1640. X                {
  1641. X                zerr("undefined function: %s",*argv,0);
  1642. X                return 1;
  1643. X                }
  1644. X            func = t0;
  1645. X            }
  1646. X        else
  1647. X            func = z_sendstring;
  1648. X        if (len == 1)
  1649. X            {
  1650. X            Key ky;
  1651. X
  1652. X            tab[(unsigned char) *s] = (ops['s']) ? z_sendstring : t0;
  1653. X            if (ops['s'])
  1654. X                {
  1655. X                addhnode(ztrdup(s),ky = makefunckey(z_sendstring),xbindtab,freekey);
  1656. X                ky->str = ztrdup(getkeystring(*argv,&ky->len));
  1657. X                }
  1658. X            }
  1659. X        else
  1660. X            {
  1661. X            int t1;
  1662. X            Key ky;
  1663. X
  1664. X            if (tab[(unsigned char) *s] != z_undefinedkey &&
  1665. X                    tab[(unsigned char) *s] != z_sequenceleadin)
  1666. X                {
  1667. X                zerrnam(name,"in-string has already bound prefix",NULL,0);
  1668. X                return 1;
  1669. X                }
  1670. X            tab[(unsigned char) *s] = z_sequenceleadin;
  1671. X            if (!s[1])
  1672. X                s[1] = 0x80;
  1673. X            for (t1 = 1; t1 != len-1; t1++)
  1674. X                {
  1675. X                char sav;
  1676. X
  1677. X                sav = s[t1+1];
  1678. X                s[t1+1] = '\0';
  1679. X                ky = gethnode(s,xbindtab);
  1680. X                if (ky && ky->func != z_sequenceleadin)
  1681. X                    {
  1682. X                    zerrnam(name,"in-string has already bound prefix",NULL,0);
  1683. X                    return 1;
  1684. X                    }
  1685. X                if (!ky)
  1686. X                    addhnode(ztrdup(s),makefunckey(z_sequenceleadin),xbindtab,
  1687. X                        freekey);
  1688. X                if (!sav)
  1689. X                    sav = 0x80;
  1690. X                s[t1+1] = sav;
  1691. X                }
  1692. X            addhnode(ztrdup(s),ky = makefunckey(func),xbindtab,freekey);
  1693. X            if (ops['s'])
  1694. X                ky->str = ztrdup(getkeystring(*argv,&ky->len));
  1695. X            }
  1696. X        argv++;
  1697. X        }
  1698. X    return 0;
  1699. X}
  1700. X
  1701. Xvoid freekey(x) /**/
  1702. Xvptr x;
  1703. X{
  1704. XKey k = x;
  1705. X
  1706. X    if (k->str)
  1707. X        free(k->str);
  1708. X    free(k);
  1709. X}
  1710. X
  1711. X/* this is mostly stolen from bash's draino() */
  1712. X
  1713. Xvoid drainoutput() /**/
  1714. X{
  1715. Xint n = 0;
  1716. X
  1717. X    if (!baud) return;
  1718. X#ifdef TIOCOUTQ
  1719. X#ifdef HAS_SELECT
  1720. X    while ((ioctl(SHTTY,TIOCOUTQ,&n) >= 0) && n) {
  1721. X        struct timeval tv;
  1722. X        tv.tv_sec = n/baud;
  1723. X        tv.tv_usec = ((n%baud)*1000000)/baud;
  1724. X        select (0,(fd_set *)0,(fd_set *)0,(fd_set *)0,&tv);
  1725. X    }
  1726. X#endif
  1727. X#endif
  1728. X}
  1729. X
  1730. END_OF_FILE
  1731.   if test 15021 -ne `wc -c <'src/zle_main.c'`; then
  1732.     echo shar: \"'src/zle_main.c'\" unpacked with wrong size!
  1733.   fi
  1734.   # end of 'src/zle_main.c'
  1735. fi
  1736. if test -f 'src/zle_misc.c' -a "${1}" != "-c" ; then 
  1737.   echo shar: Will not clobber existing file \"'src/zle_misc.c'\"
  1738. else
  1739.   echo shar: Extracting \"'src/zle_misc.c'\" \(15185 characters\)
  1740.   sed "s/^X//" >'src/zle_misc.c' <<'END_OF_FILE'
  1741. X/*
  1742. X *
  1743. X * zle_misc.c - miscellaneous editor routines
  1744. X *
  1745. X * This file is part of zsh, the Z shell.
  1746. X *
  1747. X * This software is Copyright 1992 by Paul Falstad
  1748. X *
  1749. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1750. X * use this software as long as: there is no monetary profit gained
  1751. X * specifically from the use or reproduction of this software, it is not
  1752. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1753. X * included prominently in any copy made. 
  1754. X *
  1755. X * The author make no claims as to the fitness or correctness of this software
  1756. X * for any use whatsoever, and it is provided as is. Any use of this software
  1757. X * is at the user's own risk. 
  1758. X *
  1759. X */
  1760. X
  1761. X#define ZLE
  1762. X#include "zsh.h"
  1763. X
  1764. X
  1765. Xvoid selfinsert() /**/
  1766. X{
  1767. Xint ncs = cs+mult;
  1768. X
  1769. X    if (mult < 0) { mult = -mult; ncs = cs; }
  1770. X    if (insmode || ll == cs)
  1771. X        spaceinline(mult);
  1772. X    else if (mult+cs > ll)
  1773. X        spaceinline(ll-(mult+cs));
  1774. X    while (mult--)
  1775. X        line[cs++] = c;
  1776. X    cs = ncs;
  1777. X}
  1778. X
  1779. Xvoid selfinsertunmeta() /**/
  1780. X{
  1781. X    c &= 0x7f;
  1782. X    if (c == '\r') c = '\n';
  1783. X    selfinsert();
  1784. X}
  1785. X
  1786. Xvoid deletechar() /**/
  1787. X{
  1788. X    if (mult < 0) { mult = -mult; backwarddeletechar(); return; }
  1789. X    if (c == 4 && !ll)
  1790. X        {
  1791. X        eofsent = 1;
  1792. X        return;
  1793. X        }
  1794. X    if (!(cs+mult > ll || line[cs] == '\n'))
  1795. X        {
  1796. X        cs += mult;
  1797. X        backdel(mult);
  1798. X        }
  1799. X    else
  1800. X        feep();
  1801. X}
  1802. X
  1803. Xvoid backwarddeletechar() /**/
  1804. X{
  1805. X    if (mult < 0) { mult = -mult; deletechar(); return; }
  1806. X    if (mult > cs)
  1807. X        mult = cs;
  1808. X    backdel(mult);
  1809. X}
  1810. X
  1811. Xvoid vibackwarddeletechar() /**/
  1812. X{
  1813. X    if (mult < 0) { mult = -mult; videletechar(); return; }
  1814. X    if (mult > cs)
  1815. X        mult = cs;
  1816. X    if (cs-mult < viinsbegin) { feep(); return; }
  1817. X    backkill(mult,1);
  1818. X}
  1819. X
  1820. Xvoid vikillline() /**/
  1821. X{
  1822. X    if (viinsbegin > cs) { feep(); return; }
  1823. X    backdel(cs-viinsbegin);
  1824. X}
  1825. X
  1826. Xvoid killwholeline() /**/
  1827. X{
  1828. Xint i,fg;
  1829. X
  1830. X    if (mult < 0) return;
  1831. X    while (mult--)
  1832. X        {
  1833. X        if (fg = (cs && cs == ll))
  1834. X            cs--;
  1835. X        while (cs && line[cs-1] != '\n') cs--;
  1836. X        for (i = cs; i != ll && line[i] != '\n'; i++);
  1837. X        forekill(i-cs+(i != ll),fg);
  1838. X        }
  1839. X}
  1840. X
  1841. Xvoid killbuffer() /**/
  1842. X{
  1843. X    cs = 0;
  1844. X    forekill(ll,0);
  1845. X}
  1846. X
  1847. Xvoid backwardkillline() /**/
  1848. X{
  1849. Xint i = 0;
  1850. X
  1851. X    if (mult < 0) { mult = -mult; killline(); return; }
  1852. X    while (mult--)
  1853. X        {
  1854. X        while (cs && line[cs-1] != '\n') cs--,i++;
  1855. X        if (mult && cs && line[cs-1] == '\n')
  1856. X            cs--,i++;
  1857. X        }
  1858. X    forekill(i,1);
  1859. X}
  1860. X
  1861. Xvoid gosmacstransposechars() /**/
  1862. X{
  1863. Xint cc;
  1864. X
  1865. X    if (cs < 2 || line[cs-1] == '\n' || line[cs-2] == '\n')
  1866. X        {
  1867. X        if (line[cs] == '\n' || line[cs+1] == '\n')
  1868. X            {
  1869. X            feep();
  1870. X            return;
  1871. X            }
  1872. X        cs += (cs == 0 || line[cs-1] == '\n') ? 2 : 1;
  1873. X        }
  1874. X    cc = line[cs-2];
  1875. X    line[cs-2] = line[cs-1];
  1876. X    line[cs-1] = cc;
  1877. X}
  1878. X
  1879. Xvoid transposechars() /**/
  1880. X{
  1881. Xint cc, ct;
  1882. Xint neg = mult < 0;
  1883. X
  1884. X    if (neg) mult = -mult;
  1885. X    while (mult--) {
  1886. X        if (!(ct = cs) || line[cs-1] == '\n') {
  1887. X            if (ll == cs || line[cs] == '\n') {
  1888. X                feep();
  1889. X                return;
  1890. X            }
  1891. X            if (!neg) cs++;
  1892. X           ct++;
  1893. X        }
  1894. X        if (neg) {
  1895. X            if (cs && line[cs-1] != '\n') {
  1896. X              cs--;
  1897. X              if (ct > 1 && line[ct-2] != '\n') ct--;
  1898. X            }
  1899. X        } else {
  1900. X            if (cs != ll && line[cs] != '\n') cs++;
  1901. X        }
  1902. X        if (ct == ll || line[ct] == '\n') ct--;
  1903. X        if (ct < 1 || line[ct-1] == '\n') {
  1904. X           feep();
  1905. X            return;
  1906. X        }
  1907. X        cc = line[ct-1];
  1908. X        line[ct-1] = line[ct];
  1909. X        line[ct] = cc;
  1910. X    }
  1911. X}
  1912. X
  1913. Xvoid poundinsert() /**/
  1914. X{
  1915. X    if (*line != '#') {
  1916. X        cs = 0;
  1917. X        spaceinline(1);
  1918. X        *line = '#';
  1919. X    } else {
  1920. X        cs = 0;
  1921. X        foredel(1);
  1922. X    }
  1923. X    done = 1;
  1924. X}
  1925. X
  1926. Xvoid acceptline() /**/
  1927. X{
  1928. X    done = 1;
  1929. X}
  1930. X
  1931. Xvoid acceptandhold() /**/
  1932. X{
  1933. X    pushnode(bufstack,ztrdup((char *) line));
  1934. X    stackcs = cs;
  1935. X    done = 1;
  1936. X}
  1937. X
  1938. Xvoid killline() /**/
  1939. X{
  1940. Xint i = 0;
  1941. X
  1942. X    if (mult < 0) { mult = -mult; backwardkillline(); return; }
  1943. X    while (mult--) {
  1944. X        if (line[cs] == '\n')
  1945. X            cs++,i++;
  1946. X        while (cs != ll && line[cs] != '\n') cs++,i++;
  1947. X    }
  1948. X    backkill(i,0);
  1949. X}
  1950. X
  1951. Xvoid killregion() /**/
  1952. X{
  1953. X    if (mark > ll)
  1954. X        mark = ll;
  1955. X    if (mark > cs)
  1956. X        forekill(mark-cs,0);
  1957. X    else
  1958. X        backkill(cs-mark,1);
  1959. X}
  1960. X
  1961. Xvoid copyregionaskill() /**/
  1962. X{
  1963. X    if (mark > ll)
  1964. X        mark = ll;
  1965. X    if (mark > cs)
  1966. X        cut(cs,mark-cs,0);
  1967. X    else
  1968. X        cut(mark,cs-mark,1);
  1969. X}
  1970. X
  1971. Xstatic int kct,yankb,yanke;
  1972. X
  1973. Xvoid yank() /**/
  1974. X{
  1975. Xint cc;
  1976. Xchar *buf = cutbuf;
  1977. X
  1978. X    if (!cutbuf) {
  1979. X        feep();
  1980. X        return;
  1981. X    }
  1982. X    if (mult < 0) return;
  1983. X    if (vibufspec) {
  1984. X        vibufspec = tolower(vibufspec);
  1985. X        vibufspec += (idigit(vibufspec)) ? -'1'+26 : -'a';
  1986. X        if (!(buf = vibuf[vibufspec])) {
  1987. X            feep();
  1988. X            vibufspec = 0;
  1989. X            return;
  1990. X        }
  1991. X        vibufspec = 0;
  1992. X    }
  1993. X    yankb = cs;
  1994. X    while (mult--) {
  1995. X        kct = kringnum;
  1996. X        cc = strlen(buf);
  1997. X        spaceinline(cc);
  1998. X        strncpy((char *) line+cs,buf,cc);
  1999. X        cs += cc;
  2000. X        yanke = cs;
  2001. X    }
  2002. X}
  2003. X
  2004. Xvoid viputafter() /**/
  2005. X{
  2006. Xint cc;
  2007. Xchar *buf = cutbuf;
  2008. X
  2009. X    if (!cutbuf) {
  2010. X        feep();
  2011. X        return;
  2012. X    }
  2013. X    if (mult < 0) return;
  2014. X    if (vibufspec) {
  2015. X        vibufspec = tolower(vibufspec);
  2016. X        vibufspec += (idigit(vibufspec)) ? -'1'+26 : -'a';
  2017. X        if (!(buf = vibuf[vibufspec])) {
  2018. X            feep();
  2019. X            vibufspec = 0;
  2020. X            return;
  2021. X        }
  2022. X        vibufspec = 0;
  2023. X    }
  2024. X    if (strchr(buf,'\n')) {
  2025. X        cs = findeol();
  2026. X        if (cs == ll) { spaceinline(1); line[cs] = '\n'; }
  2027. X    }
  2028. X    if (cs != ll) cs++;
  2029. X    yankb = cs;
  2030. X    while (mult--) {
  2031. X        kct = kringnum;
  2032. X        cc = strlen(buf);
  2033. X        spaceinline(cc);
  2034. X        strncpy((char *) line+cs,buf,cc);
  2035. X        cs += cc;
  2036. X        yanke = cs;
  2037. X    }
  2038. X    cs = yankb;
  2039. X}
  2040. X
  2041. Xvoid yankpop() /**/
  2042. X{
  2043. Xint cc;
  2044. X
  2045. X    if (!(lastcmd & ZLE_YANK) || !kring[kct]) {
  2046. X        feep();
  2047. X        return;
  2048. X    }
  2049. X    cs = yankb;
  2050. X    foredel(yanke-yankb);
  2051. X    cc = strlen(kring[kct]);
  2052. X    spaceinline(cc);
  2053. X    strncpy((char *) line+cs,kring[kct],cc);
  2054. X    cs += cc;
  2055. X    yanke = cs;
  2056. X    kct = (kct-1) & (KRINGCT-1);
  2057. X}
  2058. X
  2059. Xvoid overwritemode() /**/
  2060. X{
  2061. X    insmode ^= 1;
  2062. X}
  2063. X
  2064. Xvoid undefinedkey() /**/
  2065. X{
  2066. X    feep();
  2067. X}
  2068. X
  2069. Xvoid quotedinsert() /**/
  2070. X{
  2071. X#ifndef TIO
  2072. Xstruct sgttyb sob;
  2073. X    sob = shttyinfo.sgttyb;
  2074. X    sob.sg_flags = (sob.sg_flags|RAW) & ~ECHO;
  2075. X    ioctl(SHTTY,TIOCSETN,&sob);
  2076. X#endif
  2077. X    c = getkey(0);
  2078. X#ifndef TIO
  2079. X    setterm();
  2080. X#endif
  2081. X    if (c) selfinsert(); else feep();
  2082. X}
  2083. X
  2084. Xvoid digitargument() /**/
  2085. X{
  2086. X    int sign = (mult < 0 || (lastcmd & ZLE_NEGARG)) ? -1 : 1;
  2087. X    if ((lastcmd & (ZLE_ARG|ZLE_NEGARG)) != ZLE_ARG)
  2088. X        mult = 0;
  2089. X    mult = mult*10 + sign*(c&0xf);
  2090. X}
  2091. X
  2092. Xvoid negargument() /**/
  2093. X{
  2094. X    if (lastcmd & ZLE_ARG) feep();
  2095. X    mult = -1;
  2096. X}
  2097. X
  2098. Xvoid universalargument() /**/
  2099. X{
  2100. X    if (!(lastcmd & ZLE_ARG))
  2101. X        mult = 4;
  2102. X    else
  2103. X        mult *= 4;
  2104. X}
  2105. X
  2106. Xvoid copyprevword() /**/
  2107. X{
  2108. Xint len,t0;
  2109. X
  2110. X    for (t0 = cs-1; t0 >= 0; t0--)
  2111. X        if (iword(line[t0]))
  2112. X            break;
  2113. X    for (; t0 >= 0; t0--)
  2114. X        if (!iword(line[t0]))
  2115. X            break;
  2116. X    if (t0)
  2117. X        t0++;
  2118. X    len = cs-t0;
  2119. X    spaceinline(len);
  2120. X    strncpy((char *) line+cs,(char *) line+t0,len);
  2121. X    cs += len;
  2122. X}
  2123. X
  2124. Xvoid sendbreak() /**/
  2125. X{
  2126. X    errflag = done = 1;
  2127. X}
  2128. X
  2129. Xvoid undo() /**/
  2130. X{
  2131. Xchar *s;
  2132. Xstruct undoent *ue;
  2133. X
  2134. X    ue = undos+undoct;
  2135. X    if (!ue->change)
  2136. X        {
  2137. X        feep();
  2138. X        return;
  2139. X        }
  2140. X    line[ll] = '\0';
  2141. X    s = ztrdup((char *) line+ll-ue->suff);
  2142. X    sizeline((ll = ue->pref+ue->suff+ue->len)+1);
  2143. X    strncpy((char *) line+ue->pref,ue->change,ue->len);
  2144. X    strcpy((char *) line+ue->pref+ue->len,s);
  2145. X    free(s);
  2146. X    ue->change = NULL;
  2147. X    undoct = (undoct-1) & (UNDOCT-1);
  2148. X    cs = ue->cs;
  2149. X}
  2150. X
  2151. Xvoid quoteregion() /**/
  2152. X{
  2153. Xchar *s,*t;
  2154. Xint x,y;
  2155. X
  2156. X    if (mark > ll)
  2157. X        mark = ll;
  2158. X    if (mark < cs)
  2159. X        {
  2160. X        x = mark;
  2161. X        mark = cs;
  2162. X        cs = x;
  2163. X        }
  2164. X    s = hcalloc((y = mark-cs)+1);
  2165. X    strncpy(s,(char *) line+cs,y);
  2166. X    s[y] = '\0';
  2167. X    foredel(mark-cs);
  2168. X    t = makequote(s);
  2169. X    spaceinline(x = strlen(t));
  2170. X    strncpy((char *) line+cs,t,x);
  2171. X    mark = cs;
  2172. X    cs += x;
  2173. X}
  2174. X
  2175. Xvoid quoteline() /**/
  2176. X{
  2177. Xchar *s;
  2178. X
  2179. X    line[ll] = '\0';
  2180. X    s = makequote((char *) line);
  2181. X    setline(s);
  2182. X}
  2183. X
  2184. Xchar *makequote(s) /**/
  2185. Xchar *s;
  2186. X{
  2187. Xint qtct = 0;
  2188. Xchar *l,*ol;
  2189. X
  2190. X    for (l = s; *l; l++)
  2191. X        if (*l == '\'')
  2192. X            qtct++;
  2193. X    l = ol = halloc((qtct*3)+3+strlen(s));
  2194. X    *l++ = '\'';
  2195. X    for (; *s; s++)
  2196. X        if (*s == '\'')
  2197. X            {
  2198. X            *l++ = '\'';
  2199. X            *l++ = '\\';
  2200. X            *l++ = '\'';
  2201. X            *l++ = '\'';
  2202. X            }
  2203. X        else
  2204. X            *l++ = *s;
  2205. X    *l++ = '\'';
  2206. X    *l = '\0';
  2207. X    return ol;
  2208. X}
  2209. X
  2210. X#define NAMLEN 70
  2211. X
  2212. Xint executenamedcommand() /**/
  2213. X{
  2214. Xchar buf[NAMLEN],*ptr;
  2215. Xint len,ch,t0;
  2216. X
  2217. X    strcpy(buf,"execute: ");
  2218. X    ptr = buf+9;
  2219. X    len = 0;
  2220. X    statusline = buf;
  2221. X    refresh();
  2222. X    for (;ch = getkey(1);refresh())
  2223. X        {
  2224. X        switch (ch)
  2225. X            {
  2226. X            case 8: case 127:
  2227. X                if (len)
  2228. X                    {
  2229. X                    len--;
  2230. X                    *--ptr = '\0';
  2231. X                    }
  2232. X                break;
  2233. X            case 23:
  2234. X                while (len && (len--, *--ptr != '-'))
  2235. X                    *ptr = '\0';
  2236. X                break;
  2237. X            case 21:
  2238. X                len = 0;
  2239. X                ptr = buf+9;
  2240. X                *ptr = '\0';
  2241. X                break;
  2242. X            case 10: case 13: goto brk;
  2243. X            case 7: case -1: statusline = NULL; return z_undefinedkey;
  2244. X            case 9: case 32:
  2245. X                {
  2246. X                Lklist ll;
  2247. X                int ambig = 100;
  2248. X
  2249. X                heapalloc();
  2250. X                ll = newlist();
  2251. X                for (t0 = 0; t0 != ZLECMDCOUNT; t0++)
  2252. X                    if (strpfx(buf+9,zlecmds[t0].name))
  2253. X                        {
  2254. X                        int xx;
  2255. X
  2256. X                        addnode(ll,zlecmds[t0].name);
  2257. X                        xx = pfxlen(peekfirst(ll),zlecmds[t0].name);
  2258. X                        if (xx < ambig)
  2259. X                            ambig = xx;
  2260. X                        }
  2261. X                permalloc();
  2262. X                if (empty(ll))
  2263. X                    feep();
  2264. X                else if (!nextnode(firstnode(ll)))
  2265. X                    {
  2266. X                    strcpy(buf+9,peekfirst(ll));
  2267. X                    ptr = buf+(len = strlen(buf));
  2268. X                    }
  2269. X                else
  2270. X                    {
  2271. X                    strcpy(buf+9,peekfirst(ll));
  2272. X                    len = ambig;
  2273. X                    ptr = buf+9+len;
  2274. X                    *ptr = '\0';
  2275. X                    feep();
  2276. X                    listmatches(ll,NULL);
  2277. X                    }
  2278. X                break;
  2279. X                }
  2280. X            default:
  2281. X                if (len == NAMLEN-10 || icntrl(ch))
  2282. X                    feep();
  2283. X                else
  2284. X                    *ptr++ = ch, *ptr = '\0', len++;
  2285. X                break;
  2286. X            }
  2287. X        }
  2288. Xbrk:
  2289. X    statusline = NULL;
  2290. X    ptr = buf+9;
  2291. X    for (t0 = 0; t0 != ZLECMDCOUNT; t0++)
  2292. X        if (!strcmp(ptr,zlecmds[t0].name))
  2293. X            break;
  2294. X    if (t0 != ZLECMDCOUNT)
  2295. X        return lastnamed = t0;
  2296. X    else
  2297. X        return z_undefinedkey;
  2298. X}
  2299. X
  2300. Xvoid vijoin() /**/
  2301. X{
  2302. Xint x;
  2303. X
  2304. X    if ((x = findeol()) == ll)
  2305. X        {
  2306. X        feep();
  2307. X        return;
  2308. X        }
  2309. X    cs = x+1;
  2310. X    for (x = 1; cs != ll && iblank(line[cs]); cs++,x++);
  2311. X    backdel(x);
  2312. X    spaceinline(1);
  2313. X    line[cs] = ' ';
  2314. X}
  2315. X
  2316. Xvoid viswapcase() /**/
  2317. X{
  2318. X    if (cs < ll)
  2319. X        {
  2320. X        int ch = line[cs];
  2321. X
  2322. X        if (islower(ch))
  2323. X            ch = tuupper(ch);
  2324. X        else if (isupper(ch))
  2325. X            ch = tulower(ch);
  2326. X        line[cs++] = ch;
  2327. X        }
  2328. X}
  2329. X
  2330. Xvoid vicapslockpanic() /**/
  2331. X{
  2332. Xchar ch;
  2333. X
  2334. X    statusline = "press a lowercase key to continue";
  2335. X    refresh();
  2336. X    do
  2337. X        ch = getkey(0);
  2338. X    while (!islower(ch));
  2339. X}
  2340. X
  2341. Xvoid visetbuffer() /**/
  2342. X{
  2343. Xint ch;
  2344. X
  2345. X    ch = getkey(1);
  2346. X    if (!ialnum(ch)) {
  2347. X        feep();
  2348. X        return;
  2349. X    }
  2350. X    vibufspec = ch;
  2351. X}
  2352. X
  2353. Xstatic char *bp;
  2354. Xstatic int lensb,countp;
  2355. X
  2356. Xvoid stradd(d) /**/
  2357. Xchar *d;
  2358. X{
  2359. X    while (*bp++ = *d++);
  2360. X    bp--;
  2361. X}
  2362. X
  2363. Xint putstr(d) /**/
  2364. Xint d;
  2365. X{
  2366. X    *bp++ = d;
  2367. X    if (countp)
  2368. X        lensb++;
  2369. X    return 0;
  2370. X}
  2371. X
  2372. X#define tstradd(X) \
  2373. X    if (termok && unset(SINGLELINEZLE)) { \
  2374. X        char tbuf[2048],*tptr = tbuf; \
  2375. X        if (tgetstr(X,&tptr)) \
  2376. X            tputs(tbuf,1,putstr); \
  2377. X    } \
  2378. X    break
  2379. X
  2380. X/* get a prompt string */
  2381. X
  2382. Xchar *putprompt(fm,lenp,isspell) /**/
  2383. Xchar *fm;int *lenp;int isspell;
  2384. X{
  2385. Xchar *ss,*bl0;
  2386. Xstatic char buf0[256],buf1[256],buf2[256],*buf;
  2387. Xchar buf3[MAXPATHLEN];
  2388. Xint t0,bracepos = 0,arg;
  2389. Xstruct tm *tm;
  2390. Xtime_t timet;
  2391. X
  2392. X    lensb = 0; countp = 1;
  2393. X    if (!fm) { *lenp = 0; return ""; }
  2394. X    /* KLUDGE ALERT!  What we have here are three buffers:
  2395. X     *  buf1 and buf2 alternate between PS1 and PS2, though which is
  2396. X     *   which is indeterminate depending on spellchecking, "select",
  2397. X     *   etc. -- those operations also share these two buffers.
  2398. X     *  buf0 is used for any prompting that manages to happen while
  2399. X     *   zleread() is in progress (signal traps, etc.), because
  2400. X     *   zleread() re-uses the pointers returned to buf1 and buf2
  2401. X     *   and will be confused if either of those is overwritten.
  2402. X     */
  2403. X    buf = zleactive ? buf0 : ((buf == buf1) ? buf2 : buf1);
  2404. X    bp = bl0 = buf;
  2405. X    if (!columns) columns = 80;
  2406. X    clearerr(stdin);
  2407. X    for(;*fm;fm++) {
  2408. X        if (bp-buf >= 220)
  2409. X            break;
  2410. X        arg = 0;
  2411. X        if (*fm == '%')
  2412. X            {
  2413. X            if (idigit(*++fm))
  2414. X                {
  2415. X                arg = zstrtol(fm, &fm, 10);
  2416. X                }
  2417. X            switch (*fm)
  2418. X                {
  2419. X                case '~':
  2420. X                    t0 = finddir(pwd);
  2421. X                    if (t0 != -1) {
  2422. X                        *bp++ = '~';
  2423. X                        stradd(usernames[t0]);
  2424. X                        stradd(pwd+strlen(userdirs[t0]));
  2425. X                        break;
  2426. X                    }
  2427. X                case 'd': case '/': stradd(pwd); break;
  2428. X                case 'c': case '.':
  2429. X                    t0 = finddir(pwd);
  2430. X                    if (t0 != -1) {
  2431. X                        sprintf(buf3,"~%s%s",usernames[t0],
  2432. X                            pwd+strlen(userdirs[t0]));
  2433. X                    } else {
  2434. X                        strcpy(buf3,pwd);
  2435. X                    }
  2436. X                    if (!arg) arg++;
  2437. X                    for (ss = buf3+strlen(buf3); ss > buf3; ss--)
  2438. X                        if (*ss == '/' && !--arg) {
  2439. X                            ss++;
  2440. X                            break;
  2441. X                        }
  2442. X                    if (*ss == '/' && ss[1] && (ss != buf3)) ss++;
  2443. X                    stradd(ss);
  2444. X                    break;
  2445. X                case 'C':
  2446. X                    strcpy(buf3,pwd);
  2447. X                    if (!arg) arg++;
  2448. X                    for (ss = buf3+strlen(buf3); ss > buf3; ss--)
  2449. X                        if (*ss == '/' && !--arg) {
  2450. X                            ss++;
  2451. X                            break;
  2452. X                        }
  2453. X                    if (*ss == '/' && ss[1] && (ss != buf3)) ss++;
  2454. X                    stradd(ss);
  2455. X                    break;
  2456. X                case 'h': case '!':
  2457. X                    sprintf(bp,"%d",curhist);
  2458. X                    bp += strlen(bp);
  2459. X                    break;
  2460. X                case 'M': stradd(hostnam); break;
  2461. X                case 'm':
  2462. X                    if (!arg) arg++;
  2463. X                    for (ss = hostnam; *ss; ss++)
  2464. X                        if (*ss == '.' && !--arg)
  2465. X                            break;
  2466. X                    t0 = *ss;
  2467. X                    *ss = '\0';
  2468. X                    stradd(hostnam);
  2469. X                    *ss = t0;
  2470. X                    break;
  2471. X                case 'S': tstradd("so"); /* <- this is a macro */
  2472. X                case 's': tstradd("se");
  2473. X                case 'B': tstradd("md");
  2474. X                case 'b': tstradd("me");
  2475. X                case 'U': tstradd("us");
  2476. X                case 'u': tstradd("ue");
  2477. X                case '{': bracepos = bp-buf; countp = 0; break;
  2478. X                case '}': lensb += (bp-buf)-bracepos; countp = 1; break;
  2479. X                case 't': case '@':
  2480. X                    timet = time(NULL);
  2481. X                    tm = localtime(&timet);
  2482. X                    ztrftime(bp,16,"%l:%M%p",tm);
  2483. X                    if (*bp == ' ')
  2484. X                        chuck(bp);
  2485. X                    bp += strlen(bp);
  2486. X                    break;
  2487. X                case 'T':
  2488. X                    timet = time(NULL);
  2489. X                    tm = localtime(&timet);
  2490. X                    ztrftime(bp,16,"%k:%M",tm);
  2491. X                    bp += strlen(bp);
  2492. X                    break;
  2493. X                case '*':
  2494. X                    timet = time(NULL);
  2495. X                    tm = localtime(&timet);
  2496. X                    ztrftime(bp,16,"%k:%M:%S",tm);
  2497. X                    bp += strlen(bp);
  2498. X                    break;
  2499. X                case 'n': stradd(username); break;
  2500. X                case 'w':
  2501. X                    timet = time(NULL);
  2502. X                    tm = localtime(&timet);
  2503. X                    ztrftime(bp,16,"%a %e",tm);
  2504. X                    bp += strlen(bp);
  2505. X                    break;
  2506. X                case 'W':
  2507. X                    timet = time(NULL);
  2508. X                    tm = localtime(&timet);
  2509. X                    ztrftime(bp,16,"%m/%d/%y",tm);
  2510. X                    bp += strlen(bp);
  2511. X                    break;
  2512. X                case 'D':
  2513. X                     strcpy(buf3, "%y-%m-%d");
  2514. X                     if (fm[1] == '{') {
  2515. X                         for (ss = fm + 1, t0 = 0; *ss; ++ss)
  2516. X                             if (*ss == '{')
  2517. X                                 ++t0;
  2518. X                             else if (*ss == '}')
  2519. X                                 if (--t0 == 0)
  2520. X                                     break;
  2521. X                         if (*ss == '}' && t0 == 0) {
  2522. X                             t0 = (ss - 1) - (fm + 1);
  2523. X                             strncpy(buf3, fm + 2, t0);
  2524. X                             buf3[t0] = 0;
  2525. X                             fm = ss;
  2526. X                         }
  2527. X                     }
  2528. X                      timet = time(NULL);
  2529. X                      tm = localtime(&timet);
  2530. X                     ztrftime(bp,16,buf3,tm);
  2531. X                      bp += strlen(bp);
  2532. X                      break;
  2533. X                case 'l':
  2534. X                    if (*ttystrname) stradd((strncmp(ttystrname,"/dev/tty",8) ? 
  2535. X                        ttystrname+5 : ttystrname+8));
  2536. X                    else stradd("()");
  2537. X                    break;
  2538. X                case '?':
  2539. X                    sprintf(bp,"%d",lastval);
  2540. X                    bp += strlen(bp);
  2541. X                    break;
  2542. X                case '%': *bp++ = '%'; break;
  2543. X                case '#': *bp++ = (geteuid()) ? '%' : '#'; break;
  2544. X                case 'v':
  2545. X                    if (!arg) arg++;
  2546. X                    /* The number 35 here comes from 256-220-1, where 256 is
  2547. X                     * sizeof(buf), 220 is from the overflow test made at the
  2548. X                     * top of the loop, and 1 is for the \0 byte at the end.
  2549. X                     */
  2550. X                    if (arrlen(psvar) >= arg && strlen(psvar[arg-1]) < 35)
  2551. X                        stradd(psvar[arg-1]);
  2552. X                    else
  2553. X                        stradd("");
  2554. X                    break;
  2555. X                case 'r':
  2556. X                    if (isspell)
  2557. X                        {
  2558. X                        stradd(rstring);
  2559. X                        break;
  2560. X                        }
  2561. X                case 'R':
  2562. X                    if (isspell)
  2563. X                        {
  2564. X                        stradd(Rstring);
  2565. X                        break;
  2566. X                        }
  2567. X                default:
  2568. X                    *bp++ = '%'; *bp++ = *fm;
  2569. X                    break;
  2570. X                }
  2571. X            }
  2572. X        else if (*fm == '!') {
  2573. X            sprintf(bp,"%d",curhist);
  2574. X            bp += strlen(bp);
  2575. X        } else {
  2576. X            if (fm[0] == '\\' && fm[1])
  2577. X                fm++;
  2578. X            if ((*bp++ = *fm) == '\n')
  2579. X                bl0 = bp, lensb = 0;
  2580. X        }
  2581. X    }
  2582. X    *lenp = (bp-bl0)-lensb;
  2583. X    *lenp %= columns;
  2584. X    if (*lenp == columns-1) {
  2585. X        *lenp = 0;
  2586. X        *bp++ = ' ';
  2587. X    }
  2588. X    *bp = '\0';
  2589. X    return buf;
  2590. X}
  2591. X
  2592. END_OF_FILE
  2593.   if test 15185 -ne `wc -c <'src/zle_misc.c'`; then
  2594.     echo shar: \"'src/zle_misc.c'\" unpacked with wrong size!
  2595.   fi
  2596.   # end of 'src/zle_misc.c'
  2597. fi
  2598. echo shar: End of archive 18 \(of 22\).
  2599. cp /dev/null ark18isdone
  2600. MISSING=""
  2601. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ; do
  2602.     if test ! -f ark${I}isdone ; then
  2603.     MISSING="${MISSING} ${I}"
  2604.     fi
  2605. done
  2606. if test "${MISSING}" = "" ; then
  2607.     echo You have unpacked all 22 archives.
  2608.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2609. else
  2610.     echo You still must unpack the following archives:
  2611.     echo "        " ${MISSING}
  2612. fi
  2613. exit 0
  2614.  
  2615. exit 0 # Just in case...
  2616.