home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / vim / part21 < prev    next >
Internet Message Format  |  1994-08-18  |  71KB

  1. From: mool@oce.nl (Bram Moolenaar)
  2. Newsgroups: comp.sources.misc
  3. Subject: v44i040:  vim - Vi IMproved editor, v3.0, Part21/26
  4. Date: 18 Aug 1994 14:03:30 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <330ba2$e7u@sparky.sterling.com>
  9. X-Md4-Signature: b210fb44b49f8358762dc616a08b3395
  10.  
  11. Submitted-by: mool@oce.nl (Bram Moolenaar)
  12. Posting-number: Volume 44, Issue 40
  13. Archive-name: vim/part21
  14. Environment: UNIX, AMIGA, MS-DOS, Windows NT
  15. Supersedes: vim: Volume 41, Issue 50-75
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  vim/src/csearch.c vim/src/main.c vim/src/makefile.unix
  22. #   vim/src/regsub.c vim/src/structs.h
  23. # Wrapped by kent@sparky on Mon Aug 15 21:44:12 1994
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 21 (of 26)."'
  27. if test -f 'vim/src/csearch.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'vim/src/csearch.c'\"
  29. else
  30.   echo shar: Extracting \"'vim/src/csearch.c'\" \(14449 characters\)
  31.   sed "s/^X//" >'vim/src/csearch.c' <<'END_OF_FILE'
  32. X/* vi:ts=4:sw=4
  33. X *
  34. X * VIM - Vi IMproved        by Bram Moolenaar
  35. X *
  36. X * Read the file "credits.txt" for a list of people who contributed.
  37. X * Read the file "uganda.txt" for copying and usage conditions.
  38. X */
  39. X
  40. X/*
  41. X *
  42. X * csearch.c: dosub() and doglob() for :s, :g and :v
  43. X */
  44. X
  45. X#include "vim.h"
  46. X#include "globals.h"
  47. X#include "proto.h"
  48. X#include "param.h"
  49. X
  50. X/* we use modified Henry Spencer's regular expression routines */
  51. X#include "regexp.h"
  52. X
  53. X/* dosub(lp, up, cmd)
  54. X *
  55. X * Perform a substitution from line 'lp' to line 'up' using the
  56. X * command pointed to by 'cmd' which should be of the form:
  57. X *
  58. X * /pattern/substitution/gc
  59. X *
  60. X * The trailing 'g' is optional and, if present, indicates that multiple
  61. X * substitutions should be performed on each line, if applicable.
  62. X * The trailing 'c' is optional and, if present, indicates that a confirmation
  63. X * will be asked for each replacement.
  64. X * The usual escapes are supported as described in the regexp docs.
  65. X *
  66. X * use_old == 0 for :substitute
  67. X * use_old == 1 for :&
  68. X * use_old == 2 for :~
  69. X */
  70. X
  71. X    void
  72. Xdosub(lp, up, cmd, nextcommand, use_old)
  73. X    linenr_t    lp;
  74. X    linenr_t    up;
  75. X    char_u        *cmd;
  76. X    char_u        **nextcommand;
  77. X    int            use_old;
  78. X{
  79. X    linenr_t        lnum;
  80. X    long            i;
  81. X    char_u           *ptr;
  82. X    char_u           *old_line;
  83. X    regexp           *prog;
  84. X    long            nsubs = 0;
  85. X    linenr_t        nlines = 0;
  86. X    static int        do_all = FALSE;     /* do multiple substitutions per line */
  87. X    static int        do_ask = FALSE;     /* ask for confirmation */
  88. X    char_u           *pat = NULL, *sub = NULL;
  89. X    static char_u   *old_sub = NULL;
  90. X    int             delimiter;
  91. X    int             sublen;
  92. X    int                got_quit = FALSE;
  93. X    int                got_match = FALSE;
  94. X    int                temp;
  95. X    int                which_pat;
  96. X    
  97. X    if (use_old == 2)
  98. X        which_pat = 2;        /* use last used regexp */
  99. X    else
  100. X        which_pat = 1;        /* use last substitute regexp */
  101. X
  102. X                                   /* new pattern and substitution */
  103. X    if (use_old == 0 && *cmd != NUL && strchr("0123456789gcr|\"", *cmd) == NULL)
  104. X    {
  105. X        if (isalpha(*cmd))            /* don't accept alpha for separator */
  106. X        {
  107. X            emsg(e_invarg);
  108. X            return;
  109. X        }
  110. X        /*
  111. X         * undocumented vi feature:
  112. X         *    "\/sub/" and "\?sub?" use last used search pattern (almost like //sub/r).
  113. X         *  "\&sub&" use last substitute pattern (like //sub/).
  114. X         */
  115. X        if (*cmd == '\\')
  116. X        {
  117. X            ++cmd;
  118. X            if (strchr("/?&", *cmd) == NULL)
  119. X            {
  120. X                emsg(e_backslash);
  121. X                return;
  122. X            }
  123. X            if (*cmd != '&')
  124. X                which_pat = 0;                /* use last '/' pattern */
  125. X            pat = (char_u *)"";                /* empty search pattern */
  126. X            delimiter = *cmd++;                /* remember delimiter character */
  127. X        }
  128. X        else            /* find the end of the regexp */
  129. X        {
  130. X            delimiter = *cmd++;                /* remember delimiter character */
  131. X            pat = cmd;                        /* remember start of search pattern */
  132. X            cmd = skip_regexp(cmd, delimiter);
  133. X            if (cmd[0] == delimiter)        /* end delimiter found */
  134. X                *cmd++ = NUL;                /* replace it by a NUL */
  135. X        }
  136. X
  137. X        /*
  138. X         * Small incompatibility: vi sees '\n' as end of the command, but in
  139. X         * Vim we want to use '\n' to find/substitute a NUL.
  140. X         */
  141. X        sub = cmd;            /* remember the start of the substitution */
  142. X
  143. X        while (cmd[0])
  144. X        {
  145. X            if (cmd[0] == delimiter)            /* end delimiter found */
  146. X            {
  147. X                *cmd++ = NUL;                    /* replace it by a NUL */
  148. X                break;
  149. X            }
  150. X            if (cmd[0] == '\\' && cmd[1] != 0)    /* skip escaped characters */
  151. X                ++cmd;
  152. X            ++cmd;
  153. X        }
  154. X
  155. X        free(old_sub);
  156. X        old_sub = strsave(sub);
  157. X    }
  158. X    else                                /* use previous pattern and substitution */
  159. X    {
  160. X        if (old_sub == NULL)    /* there is no previous command */
  161. X        {
  162. X            emsg(e_nopresub);
  163. X            return;
  164. X        }
  165. X        pat = NULL;             /* myregcomp() will use previous pattern */
  166. X        sub = old_sub;
  167. X    }
  168. X
  169. X    /*
  170. X     * find trailing options
  171. X     */
  172. X    if (!p_ed)
  173. X    {
  174. X        if (p_gd)                /* default is global on */
  175. X            do_all = TRUE;
  176. X        else
  177. X            do_all = FALSE;
  178. X        do_ask = FALSE;
  179. X    }
  180. X    while (*cmd)
  181. X    {
  182. X        /*
  183. X         * Note that 'g' and 'c' are always inverted, also when p_ed is off
  184. X         * 'r' is never inverted.
  185. X         */
  186. X        if (*cmd == 'g')
  187. X            do_all = !do_all;
  188. X        else if (*cmd == 'c')
  189. X            do_ask = !do_ask;
  190. X        else if (*cmd == 'r')        /* use last used regexp */
  191. X            which_pat = 2;
  192. X        else
  193. X            break;
  194. X        ++cmd;
  195. X    }
  196. X
  197. X    /*
  198. X     * check for a trailing count
  199. X     */
  200. X    skipspace(&cmd);
  201. X    if (isdigit(*cmd))
  202. X    {
  203. X        i = getdigits(&cmd);
  204. X        if (i <= 0)
  205. X        {
  206. X            emsg(e_zerocount);
  207. X            return;
  208. X        }
  209. X        lp = up;
  210. X        up += i - 1;
  211. X    }
  212. X
  213. X    /*
  214. X     * check for trailing '|', '"' or '\n'
  215. X     */
  216. X    skipspace(&cmd);
  217. X    if (*cmd)
  218. X    {
  219. X        if (strchr("|\"\n", *cmd) == NULL)
  220. X        {
  221. X            emsg(e_trailing);
  222. X            return;
  223. X        }
  224. X        else
  225. X            *nextcommand = cmd;
  226. X    }
  227. X
  228. X    if ((prog = myregcomp(pat, 1, which_pat)) == NULL)
  229. X    {
  230. X        emsg(e_invcmd);
  231. X        return;
  232. X    }
  233. X
  234. X    /*
  235. X     * ~ in the substitute pattern is replaced by the old pattern.
  236. X     * We do it here once to avoid it to be replaced over and over again.
  237. X     */
  238. X    sub = regtilde(sub, (int)p_magic);
  239. X
  240. X    old_line = NULL;
  241. X    for (lnum = lp; lnum <= up && !(got_int || got_quit); ++lnum)
  242. X    {
  243. X        ptr = ml_get(lnum);
  244. X        if (regexec(prog, ptr, TRUE))  /* a match on this line */
  245. X        {
  246. X            char_u        *new_end, *new_start = NULL;
  247. X            char_u        *old_match, *old_copy;
  248. X            char_u        *prev_old_match = NULL;
  249. X            char_u        *p1;
  250. X            int            did_sub = FALSE;
  251. X            int            match, lastone;
  252. X
  253. X            /* make a copy of the line, so it won't be taken away when updating
  254. X                the screen */
  255. X            if ((old_line = strsave(ptr)) == NULL)
  256. X                continue;
  257. X            regexec(prog, old_line, TRUE);  /* match again on this line to update the pointers. TODO: remove extra regexec() */
  258. X            if (!got_match)
  259. X            {
  260. X                setpcmark();
  261. X                got_match = TRUE;
  262. X            }
  263. X
  264. X            old_copy = old_match = old_line;
  265. X            for (;;)            /* loop until nothing more to replace */
  266. X            {
  267. X                /*
  268. X                 * Save the position of the last change for the final cursor
  269. X                 * position (just like the real vi).
  270. X                 */
  271. X                curwin->w_cursor.lnum = lnum;
  272. X                curwin->w_cursor.col = (int)(prog->startp[0] - old_line);
  273. X
  274. X                /*
  275. X                 * Match empty string does not count, except for first match.
  276. X                 * This reproduces the strange vi behaviour.
  277. X                 * This also catches endless loops.
  278. X                 */
  279. X                if (old_match == prev_old_match && old_match == prog->endp[0])
  280. X                {
  281. X                    ++old_match;
  282. X                    goto skip;
  283. X                }
  284. X                old_match = prog->endp[0];
  285. X                prev_old_match = old_match;
  286. X
  287. X                while (do_ask)        /* loop until 'y', 'n' or 'q' typed */
  288. X                {
  289. X                    temp = RedrawingDisabled;
  290. X                    RedrawingDisabled = FALSE;
  291. X                    comp_Botline(curwin);
  292. X                    updateScreen(CURSUPD);
  293. X                                    /* same highlighting as for wait_return */
  294. X                    (void)set_highlight('r');
  295. X                    msg_highlight = TRUE;
  296. X                    smsg((char_u *)"replace by %s (y/n/q)?", sub);
  297. X                    showruler(TRUE);
  298. X                    setcursor();
  299. X                    RedrawingDisabled = temp;
  300. X                    if ((i = vgetc()) == 'q' || i == ESC || i == Ctrl('C'))
  301. X                    {
  302. X                        got_quit = TRUE;
  303. X                        break;
  304. X                    }
  305. X                    else if (i == 'n')
  306. X                        goto skip;
  307. X                    else if (i == 'y')
  308. X                        break;
  309. X                }
  310. X                if (got_quit)
  311. X                    break;
  312. X
  313. X                        /* get length of substitution part */
  314. X                sublen = regsub(prog, sub, old_line, 0, (int)p_magic);
  315. X                if (new_start == NULL)
  316. X                {
  317. X                    /*
  318. X                     * Get some space for a temporary buffer to do the substitution
  319. X                     * into.
  320. X                     */
  321. X                    if ((new_start = alloc((unsigned)(STRLEN(old_line) + sublen + 5))) == NULL)
  322. X                        goto outofmem;
  323. X                    *new_start = NUL;
  324. X                }
  325. X                else
  326. X                {
  327. X                    /*
  328. X                     * extend the temporary buffer to do the substitution into.
  329. X                     */
  330. X                    if ((p1 = alloc((unsigned)(STRLEN(new_start) + STRLEN(old_copy) + sublen + 1))) == NULL)
  331. X                        goto outofmem;
  332. X                    STRCPY(p1, new_start);
  333. X                    free(new_start);
  334. X                    new_start = p1;
  335. X                }
  336. X
  337. X                for (new_end = new_start; *new_end; new_end++)
  338. X                    ;
  339. X                /*
  340. X                 * copy up to the part that matched
  341. X                 */
  342. X                while (old_copy < prog->startp[0])
  343. X                    *new_end++ = *old_copy++;
  344. X
  345. X                regsub(prog, sub, new_end, 1, (int)p_magic);
  346. X                nsubs++;
  347. X                did_sub = TRUE;
  348. X
  349. X                /*
  350. X                 * Now the trick is to replace CTRL-Ms with a real line break.
  351. X                 * This would make it impossible to insert CTRL-Ms in the text.
  352. X                 * That is the way vi works. In Vim the line break can be
  353. X                 * avoided by preceding the CTRL-M with a CTRL-V. Now you can't
  354. X                 * precede a line break with a CTRL-V, big deal.
  355. X                 */
  356. X                while ((p1 = STRCHR(new_end, CR)) != NULL)
  357. X                {
  358. X                    if (p1 == new_end || p1[-1] != Ctrl('V'))
  359. X                    {
  360. X                        if (u_inssub(lnum))                /* prepare for undo */
  361. X                        {
  362. X                            *p1 = NUL;                    /* truncate up to the CR */
  363. X                            mark_adjust(lnum, MAXLNUM, 1L);
  364. X                            ml_append(lnum - 1, new_start, (colnr_t)(p1 - new_start + 1), FALSE);
  365. X                            ++lnum;
  366. X                            ++up;                    /* number of lines increases */
  367. X                            STRCPY(new_start, p1 + 1);    /* copy the rest */
  368. X                            new_end = new_start;
  369. X                        }
  370. X                    }
  371. X                    else                            /* remove CTRL-V */
  372. X                    {
  373. X                        STRCPY(p1 - 1, p1);
  374. X                        new_end = p1;
  375. X                    }
  376. X                }
  377. X
  378. X                old_copy = prog->endp[0];    /* remember next character to be copied */
  379. X                /*
  380. X                 * continue searching after the match
  381. X                 * prevent endless loop with patterns that match empty strings,
  382. X                 * e.g. :s/$/pat/g or :s/[a-z]* /(&)/g
  383. X                 */
  384. Xskip:
  385. X                match = -1;
  386. X                lastone = (*old_match == NUL || got_int || got_quit || !do_all);
  387. X                if (lastone || do_ask || (match = regexec(prog, old_match, (int)FALSE)) == 0)
  388. X                {
  389. X                    if (new_start)
  390. X                    {
  391. X                        /*
  392. X                         * Copy the rest of the line, that didn't match.
  393. X                         * Old_match has to be adjusted, we use the end of the line
  394. X                         * as reference, because the substitute may have changed
  395. X                         * the number of characters.
  396. X                         */
  397. X                        STRCAT(new_start, old_copy);
  398. X                        i = old_line + STRLEN(old_line) - old_match;
  399. X                        if (u_savesub(lnum))
  400. X                            ml_replace(lnum, new_start, TRUE);
  401. X
  402. X                        free(old_line);            /* free the temp buffer */
  403. X                        old_line = new_start;
  404. X                        new_start = NULL;
  405. X                        old_match = old_line + STRLEN(old_line) - i;
  406. X                        if (old_match < old_line)        /* safety check */
  407. X                        {
  408. X                            EMSG("dosub internal error: old_match < old_line");
  409. X                            old_match = old_line;
  410. X                        }
  411. X                        old_copy = old_line;
  412. X                    }
  413. X                    if (match == -1 && !lastone)
  414. X                        match = regexec(prog, old_match, (int)FALSE);
  415. X                    if (match <= 0)        /* quit loop if there is no more match */
  416. X                        break;
  417. X                }
  418. X                    /* breakcheck is slow, don't call it too often */
  419. X                if ((nsubs & 15) == 0)
  420. X                    breakcheck();
  421. X
  422. X            }
  423. X            if (did_sub)
  424. X                ++nlines;
  425. X            free(old_line);        /* free the copy of the original line */
  426. X            old_line = NULL;
  427. X        }
  428. X            /* breakcheck is slow, don't call it too often */
  429. X        if ((lnum & 15) == 0)
  430. X            breakcheck();
  431. X    }
  432. X
  433. Xoutofmem:
  434. X    free(old_line);        /* may have to free an allocated copy of the line */
  435. X    if (nsubs)
  436. X    {
  437. X        CHANGED;
  438. X        updateScreen(CURSUPD); /* need this to update LineSizes */
  439. X        beginline(TRUE);
  440. X        if (nsubs > p_report)
  441. X            smsg((char_u *)"%s%ld substitution%s on %ld line%s",
  442. X                                got_int ? "(Interrupted) " : "",
  443. X                                nsubs, plural(nsubs),
  444. X                                (long)nlines, plural((long)nlines));
  445. X        else if (got_int)
  446. X                emsg(e_interr);
  447. X        else if (do_ask)
  448. X                MSG("");
  449. X    }
  450. X    else if (got_int)        /* interrupted */
  451. X        emsg(e_interr);
  452. X    else if (got_match)        /* did find something but nothing substituted */
  453. X        MSG("");
  454. X    else                    /* nothing found */
  455. X        emsg(e_nomatch);
  456. X
  457. X    free(prog);
  458. X}
  459. X
  460. X/*
  461. X * doglob(cmd)
  462. X *
  463. X * Execute a global command of the form:
  464. X *
  465. X * g/pattern/X : execute X on all lines where pattern matches
  466. X * v/pattern/X : execute X on all lines where pattern does not match
  467. X *
  468. X * where 'X' is an EX command
  469. X *
  470. X * The command character (as well as the trailing slash) is optional, and
  471. X * is assumed to be 'p' if missing.
  472. X *
  473. X * This is implemented in two passes: first we scan the file for the pattern and
  474. X * set a mark for each line that (not) matches. secondly we execute the command
  475. X * for each line that has a mark. This is required because after deleting
  476. X * lines we do not know where to search for the next match.
  477. X */
  478. X
  479. X    void
  480. Xdoglob(type, lp, up, cmd)
  481. X    int         type;
  482. X    linenr_t    lp, up;
  483. X    char_u        *cmd;
  484. X{
  485. X    linenr_t        lnum;        /* line number according to old situation */
  486. X    linenr_t        old_lcount; /* curbuf->b_ml.ml_line_count before the command */
  487. X    int             ndone;
  488. X
  489. X    char_u            delim;        /* delimiter, normally '/' */
  490. X    char_u           *pat;
  491. X    regexp           *prog;
  492. X    int                match;
  493. X    int                which_pat;
  494. X
  495. X    if (global_busy)
  496. X    {
  497. X        EMSG("Cannot do :global recursive");
  498. X        ++global_busy;
  499. X        return;
  500. X    }
  501. X
  502. X    which_pat = 2;            /* default: use last used regexp */
  503. X
  504. X    /*
  505. X     * undocumented vi feature:
  506. X     *    "\/" and "\?": use previous search pattern.
  507. X     *           "\&": use previous substitute pattern.
  508. X     */
  509. X    if (*cmd == '\\')
  510. X    {
  511. X        ++cmd;
  512. X        if (strchr("/?&", *cmd) == NULL)
  513. X        {
  514. X            emsg(e_backslash);
  515. X            return;
  516. X        }
  517. X        if (*cmd == '&')
  518. X            which_pat = 1;        /* use previous substitute pattern */
  519. X        else
  520. X            which_pat = 0;        /* use previous search pattern */
  521. X        ++cmd;
  522. X        pat = (char_u *)"";
  523. X    }
  524. X    else
  525. X    {
  526. X        delim = *cmd;             /* get the delimiter */
  527. X        if (delim)
  528. X            ++cmd;                /* skip delimiter if there is one */
  529. X        pat = cmd;                /* remember start of pattern */
  530. X        cmd = skip_regexp(cmd, delim);
  531. X        if (cmd[0] == delim)                /* end delimiter found */
  532. X            *cmd++ = NUL;                    /* replace it by a NUL */
  533. X    }
  534. X
  535. X    reg_ic = p_ic;           /* set "ignore case" flag appropriately */
  536. X
  537. X    if ((prog = myregcomp(pat, 2, which_pat)) == NULL)
  538. X    {
  539. X        emsg(e_invcmd);
  540. X        return;
  541. X    }
  542. X    MSG("");
  543. X
  544. X/*
  545. X * pass 1: set marks for each (not) matching line
  546. X */
  547. X    ndone = 0;
  548. X    for (lnum = lp; lnum <= up && !got_int; ++lnum)
  549. X    {
  550. X        match = regexec(prog, ml_get(lnum), (int)TRUE);     /* a match on this line? */
  551. X        if ((type == 'g' && match) || (type == 'v' && !match))
  552. X        {
  553. X            ml_setmarked(lnum);
  554. X            ndone++;
  555. X        }
  556. X            /* breakcheck is slow, don't call it too often */
  557. X        if ((lnum & 15) == 0)
  558. X            breakcheck();
  559. X    }
  560. X
  561. X/*
  562. X * pass 2: execute the command for each line that has been marked
  563. X */
  564. X    if (got_int)
  565. X        MSG("Interrupted");
  566. X    else if (ndone == 0)
  567. X        msg(e_nomatch);
  568. X    else
  569. X    {
  570. X        global_busy = 1;
  571. X        dont_sleep = 1;            /* don't sleep in emsg() */
  572. X        no_wait_return = 1;        /* dont wait for return until finished */
  573. X        need_wait_return = FALSE;
  574. X        RedrawingDisabled = TRUE;
  575. X        old_lcount = curbuf->b_ml.ml_line_count;
  576. X        did_msg = FALSE;
  577. X        while (!got_int && (lnum = ml_firstmarked()) != 0 && global_busy == 1)
  578. X        {
  579. X            /*
  580. X             * If there was a message from the previous command, scroll
  581. X             * the lines up for the next, otherwise it will be overwritten.
  582. X             * did_msg is set by msg_start().
  583. X             */
  584. X            if (did_msg)
  585. X            {
  586. X                cmdline_row = msg_row;
  587. X                did_msg = FALSE;
  588. X            }
  589. X            curwin->w_cursor.lnum = lnum;
  590. X            curwin->w_cursor.col = 0;
  591. X            if (*cmd == NUL || *cmd == '\n')
  592. X                docmdline((char_u *)"p");
  593. X            else
  594. X                docmdline(cmd);
  595. X            breakcheck();
  596. X        }
  597. X
  598. X        RedrawingDisabled = FALSE;
  599. X        global_busy = 0;
  600. X        dont_sleep = 0;
  601. X        no_wait_return = 0;
  602. X        if (need_wait_return)                /* wait for return now */
  603. X            wait_return(FALSE);
  604. X
  605. X        screenclear();
  606. X        updateScreen(CURSUPD);
  607. X        msgmore(curbuf->b_ml.ml_line_count - old_lcount);
  608. X    }
  609. X
  610. X    ml_clearmarked();      /* clear rest of the marks */
  611. X    free(prog);
  612. X}
  613. END_OF_FILE
  614.   if test 14449 -ne `wc -c <'vim/src/csearch.c'`; then
  615.     echo shar: \"'vim/src/csearch.c'\" unpacked with wrong size!
  616.   fi
  617.   # end of 'vim/src/csearch.c'
  618. fi
  619. if test -f 'vim/src/main.c' -a "${1}" != "-c" ; then 
  620.   echo shar: Will not clobber existing file \"'vim/src/main.c'\"
  621. else
  622.   echo shar: Extracting \"'vim/src/main.c'\" \(14502 characters\)
  623.   sed "s/^X//" >'vim/src/main.c' <<'END_OF_FILE'
  624. X/* vi:ts=4:sw=4
  625. X *
  626. X * VIM - Vi IMproved        by Bram Moolenaar
  627. X *
  628. X * Read the file "credits.txt" for a list of people who contributed.
  629. X * Read the file "uganda.txt" for copying and usage conditions.
  630. X */
  631. X
  632. X#define EXTERN
  633. X#include "vim.h"
  634. X#include "globals.h"
  635. X#include "proto.h"
  636. X#include "param.h"
  637. X
  638. X#ifdef SPAWNO
  639. X# include <spawno.h>            /* special MSDOS swapping library */
  640. X#endif
  641. X
  642. Xstatic void usage __PARMS((int));
  643. X
  644. X    static void
  645. Xusage(n)
  646. X    int n;
  647. X{
  648. X    register int i;
  649. X    static char_u *(use[]) = {(char_u *)"[file ..]\n",
  650. X                            (char_u *)"-t tag\n",
  651. X                            (char_u *)"-e [errorfile]\n"};
  652. X    static char_u *(errors[]) =  {(char_u *)"Unknown option\n",        /* 0 */
  653. X                                (char_u *)"Too many arguments\n",    /* 1 */
  654. X                                (char_u *)"Argument missing\n",        /* 2 */
  655. X                                };
  656. X
  657. X    fprintf(stderr, (char *)errors[n]);
  658. X    fprintf(stderr, "usage:");
  659. X    for (i = 0; ; ++i)
  660. X    {
  661. X        fprintf(stderr, " vim [options] ");
  662. X        fprintf(stderr, (char *)use[i]);
  663. X        if (i == (sizeof(use) / sizeof(char_u *)) - 1)
  664. X            break;
  665. X        fprintf(stderr, "   or:");
  666. X    }
  667. X    fprintf(stderr, "\noptions:\t-v\t\treadonly mode (view)\n");
  668. X    fprintf(stderr, "\t\t-n\t\tno swap file, use memory only\n");
  669. X    fprintf(stderr, "\t\t-b\t\tbinary mode\n");
  670. X    fprintf(stderr, "\t\t-r\t\trecovery mode\n");
  671. X#ifdef AMIGA
  672. X    fprintf(stderr, "\t\t-x\t\tdon't use newcli to open window\n");
  673. X    fprintf(stderr, "\t\t-d device\tuse device for I/O\n");
  674. X#endif
  675. X    fprintf(stderr, "\t\t-T terminal\tset terminal type\n");
  676. X    fprintf(stderr, "\t\t-o[N]\t\topen N windows (def: one for each file)\n");
  677. X    fprintf(stderr, "\t\t+\t\tstart at end of file\n");
  678. X    fprintf(stderr, "\t\t+lnum\t\tstart at line lnum\n");
  679. X    fprintf(stderr, "\t\t-c command\texecute command first\n");
  680. X    fprintf(stderr, "\t\t-s scriptin\tread commands from script file\n");
  681. X    fprintf(stderr, "\t\t-w scriptout\twrite commands in script file\n");
  682. X    mch_windexit(1);
  683. X}
  684. X
  685. X#ifdef USE_LOCALE
  686. X# include <locale.h>
  687. X#endif
  688. X
  689. X    void
  690. Xmain(argc, argv)
  691. X    int                argc;
  692. X    char          **argv;
  693. X{
  694. X    char_u           *initstr;        /* init string from the environment */
  695. X    char_u           *term = NULL;    /* specified terminal name */
  696. X    char_u           *fname = NULL;    /* file name from command line */
  697. X    char_u           *command = NULL;    /* command from + or -c option */
  698. X    char_u           *tagname = NULL;    /* tag from -t option */
  699. X    int             c;
  700. X    int                doqf = 0;
  701. X    int                i;
  702. X    int                bin_mode = FALSE;    /* -b option used */
  703. X    int                win_count = 1;        /* number of windows to use */
  704. X
  705. X#ifdef USE_LOCALE
  706. X    setlocale(LC_ALL, "");        /* for ctype() and the like */
  707. X#endif
  708. X
  709. X/*
  710. X * Check if we have an interactive window.
  711. X * If not, open one with a newcli command (needed for :! to work).
  712. X * check_win will also handle the -d argument (for the Amiga).
  713. X */
  714. X    check_win(argc, argv);
  715. X
  716. X/*
  717. X * allocate the first window and buffer. Can't to anything without it
  718. X */
  719. X    if ((curwin = win_alloc(NULL)) == NULL ||
  720. X            (curbuf = buflist_new(NULL, NULL, 1L, FALSE)) == NULL)
  721. X        mch_windexit(0);
  722. X    curwin->w_buffer = curbuf;
  723. X
  724. X/*
  725. X * If the executable is called "view" we start in readonly mode.
  726. X */
  727. X    if (STRCMP(gettail((char_u *)argv[0]), (char_u *)"view") == 0)
  728. X    {
  729. X        readonlymode = TRUE;
  730. X        curbuf->b_p_ro = TRUE;
  731. X        p_uc = 0;
  732. X    }
  733. X
  734. X    ++argv;
  735. X    /*
  736. X     * Process the command line arguments
  737. X     *        '-c {command}'    execute command
  738. X     *        '+{command}'    execute command
  739. X     *         '-s scriptin'    read from script file
  740. X     *        '-w scriptout'    write to script file
  741. X     *        '-v'            view
  742. X     *        '-b'            binary
  743. X     *        '-n'            no .vim file
  744. X     *        '-r'            recovery mode
  745. X     *        '-x'            open window directly, not with newcli
  746. X     *        '-o[N]'            open N windows (default: number of files)
  747. X     *        '-T terminal'    terminal name
  748. X     */
  749. X    while (argc > 1 && ((c = argv[0][0]) == '+' || (c == '-' &&
  750. X            strchr("vnbrxocswTd", c = argv[0][1]) != NULL && c != NUL)))
  751. X    {
  752. X        --argc;
  753. X        switch (c)
  754. X        {
  755. X        case '+':             /* + or +{number} or +/{pat} or +{command} */
  756. X            c = argv[0][1];
  757. X            if (c == NUL)
  758. X                command = (char_u *)"$";
  759. X            else
  760. X                command = (char_u *)&(argv[0][1]);
  761. X            break;
  762. X
  763. X        case 'v':
  764. X            readonlymode = TRUE;
  765. X            curbuf->b_p_ro = TRUE;
  766. X            /*FALLTHROUGH*/
  767. X
  768. X        case 'n':
  769. X            p_uc = 0;
  770. X            break;
  771. X
  772. X        case 'b':
  773. X            bin_mode = TRUE;        /* postpone to after reading .exrc files */
  774. X            break;
  775. X
  776. X        case 'r':
  777. X            recoverymode = 1;
  778. X            break;
  779. X        
  780. X        case 'x':
  781. X            break;    /* This is ignored as it is handled in check_win() */
  782. X
  783. X        case 'o':
  784. X            c = argv[0][2];
  785. X            if (c != NUL && !isdigit(c))
  786. X            {
  787. X                fprintf(stderr, "-o option needs numeric argument (or none)\n");
  788. X                mch_windexit(2);
  789. X            }
  790. X            win_count = atoi(&(argv[0][2]));        /* 0 means: number of files */
  791. X            break;
  792. X
  793. X        default:    /* options with argument */
  794. X            ++argv;
  795. X            --argc;
  796. X            if (argc < 1)
  797. X                usage(2);
  798. X
  799. X            switch (c)
  800. X            {
  801. X            case 'c':            /* -c {command} */
  802. X                command = (char_u *)&(argv[0][0]);
  803. X                break;
  804. X
  805. X            case 's':
  806. X                if ((scriptin[0] = fopen(argv[0], READBIN)) == NULL)
  807. X                {
  808. X                    fprintf(stderr, "cannot open %s for reading\n", argv[0]);
  809. X                    mch_windexit(2);
  810. X                }
  811. X                break;
  812. X            
  813. X            case 'w':
  814. X                if ((scriptout = fopen(argv[0], APPENDBIN)) == NULL)
  815. X                {
  816. X                    fprintf(stderr, "cannot open %s for output\n", argv[0]);
  817. X                    mch_windexit(2);
  818. X                }
  819. X                break;
  820. X
  821. X/*
  822. X * The -T term option is always available and when TERMCAP is supported it
  823. X * overrides the environment variable TERM.
  824. X */
  825. X            case 'T':
  826. X                term = (char_u *)*argv;
  827. X                break;
  828. X            
  829. X        /*    case 'd':        This is ignored as it is handled in check_win() */
  830. X            }
  831. X        }
  832. X        ++argv;
  833. X    }
  834. X
  835. X    /*
  836. X     * Allocate space for the generic buffers
  837. X     */
  838. X    if ((IObuff = alloc(IOSIZE)) == NULL || (NameBuff = alloc(MAXPATHL)) == NULL)
  839. X        mch_windexit(0);
  840. X
  841. X    /* note that we may use mch_windexit() before mch_windinit()! */
  842. X    mch_windinit();
  843. X    set_init();                    /* after mch_windinit because Rows is used */
  844. X    firstwin->w_height = Rows - 1;
  845. X    cmdline_row = Rows - 1;
  846. X
  847. X    /*
  848. X     * Process the other command line arguments.
  849. X     */
  850. X    if (argc > 1)
  851. X    {
  852. X        c = argv[0][1];
  853. X        switch (argv[0][0])
  854. X        {
  855. X          case '-':
  856. X            switch (c)
  857. X            {
  858. X              case 'e':            /* -e QuickFix mode */
  859. X                switch (argc)
  860. X                {
  861. X                    case 2:
  862. X                            if (argv[0][2])        /* -eerrorfile */
  863. X                                p_ef = (char_u *)argv[0] + 2;
  864. X                            break;                /* -e */
  865. X
  866. X                    case 3:                        /* -e errorfile */
  867. X                            ++argv;
  868. X                            p_ef = (char_u *)argv[0];
  869. X                            break;
  870. X
  871. X                    default:                    /* argc > 3: too many arguments */
  872. X                            usage(1);
  873. X                }
  874. X                doqf = 1;
  875. X                break;
  876. X
  877. X            case 't':            /* -t tag  or -ttag */
  878. X                switch (argc)
  879. X                {
  880. X                    case 2:
  881. X                            if (argv[0][2])        /* -ttag */
  882. X                            {
  883. X                                tagname = (char_u *)argv[0] + 2;
  884. X                                break;
  885. X                            }
  886. X                            usage(2);            /* argument missing */
  887. X                            break;
  888. X
  889. X                    case 3:                        /* -t tag */
  890. X                            ++argv;
  891. X                            tagname = (char_u *)argv[0];
  892. X                            break;
  893. X
  894. X                    default:                    /* argc > 3: too many arguments */
  895. X                            usage(1);
  896. X                }
  897. X                break;
  898. X
  899. X            default:
  900. X                usage(0);
  901. X            }
  902. X            break;
  903. X
  904. X          default:                /* must be a file name */
  905. X#if !defined(UNIX) || defined(ARCHIE)
  906. X            if (ExpandWildCards(argc - 1, (char_u **)argv, &arg_count,
  907. X                    &arg_files, TRUE, TRUE) == OK && arg_count != 0)
  908. X            {
  909. X                fname = arg_files[0];
  910. X                arg_exp = TRUE;
  911. X            }
  912. X#else
  913. X            arg_files = (char_u **)argv;
  914. X            arg_count = argc - 1;
  915. X            fname = (char_u *)argv[0];
  916. X#endif
  917. X            if (arg_count > 1)
  918. X                printf("%d files to edit\n", arg_count);
  919. X            break;
  920. X        }
  921. X    }
  922. X
  923. X    RedrawingDisabled = TRUE;
  924. X
  925. X    curbuf->b_nwindows = 1;        /* there is one window */
  926. X    win_init(curwin);            /* init cursor position */
  927. X    init_yank();                /* init yank buffers */
  928. X    termcapinit(term);            /* get terminal capabilities */
  929. X    screenclear();                /* clear screen (just inits screen structures,
  930. X                                    because starting is TRUE) */
  931. X
  932. X#ifdef MSDOS /* default mapping for some often used keys */
  933. X    domap(0, "#1 :help\r", NORMAL);            /* F1 is help key */
  934. X    domap(0, "\316R i", NORMAL);            /* INSERT is 'i' */
  935. X    domap(0, "\316S \177", NORMAL);            /* DELETE is 0x7f */
  936. X    domap(0, "\316G 0", NORMAL);            /* HOME is '0' */
  937. X    domap(0, "\316w H", NORMAL);            /* CTRL-HOME is 'H' */
  938. X    domap(0, "\316O $", NORMAL);            /* END is '$' */
  939. X    domap(0, "\316u L", NORMAL);            /* CTRL-END is 'L' */
  940. X    domap(0, "\316I \002", NORMAL);            /* PageUp is '^B' */
  941. X    domap(0, "\316\204 1G", NORMAL);        /* CTRL-PageUp is '1G' */
  942. X    domap(0, "\316Q \006", NORMAL);            /* PageDown is '^F' */
  943. X    domap(0, "\316v G", NORMAL);            /* CTRL-PageDown is 'G' */
  944. X            /* insert mode */
  945. X    domap(0, "#1 \017:help\r", INSERT);        /* F1 is help key */
  946. X    domap(0, "\316R \033", INSERT);            /* INSERT is ESC */
  947. X            /* note: extra space needed to avoid the same memory used for this
  948. X               and the one above, domap() will add a NUL to it */
  949. X    domap(0, "\316S  \177", INSERT+CMDLINE);    /* DELETE is 0x7f */
  950. X    domap(0, "\316G \017""0", INSERT);        /* HOME is '^O0' */
  951. X    domap(0, "\316w \017H", INSERT);        /* CTRL-HOME is '^OH' */
  952. X    domap(0, "\316O \017$", INSERT);        /* END is '^O$' */
  953. X    domap(0, "\316u \017L", INSERT);        /* CTRL-END is '^OL' */
  954. X    domap(0, "\316I \017\002", INSERT);        /* PageUp is '^O^B' */
  955. X    domap(0, "\316\204 \017\061G", INSERT);    /* CTRL-PageUp is '^O1G' */
  956. X    domap(0, "\316Q \017\006", INSERT);        /* PageDown is '^O^F' */
  957. X    domap(0, "\316v \017G", INSERT);        /* CTRL-PageDown is '^OG' */
  958. X#endif
  959. X
  960. X    msg_start();        /* in case a mapping is printed */
  961. X    no_wait_return = TRUE;
  962. X
  963. X/*
  964. X * get system wide defaults (for unix)
  965. X */
  966. X#ifdef DEFVIMRC_FILE
  967. X    (void)dosource(DEFVIMRC_FILE);
  968. X#endif
  969. X
  970. X/*
  971. X * Try to read initialization commands from the following places:
  972. X * - environment variable VIMINIT
  973. X * - file s:.vimrc ($HOME/.vimrc for Unix)
  974. X * - environment variable EXINIT
  975. X * - file s:.exrc ($HOME/.exrc for Unix)
  976. X * The first that exists is used, the rest is ignored.
  977. X */
  978. X    if ((initstr = vimgetenv((char_u *)"VIMINIT")) != NULL)
  979. X        docmdline(initstr);
  980. X    else if (dosource((char_u *)SYSVIMRC_FILE) == FAIL)
  981. X    {
  982. X        if ((initstr = vimgetenv((char_u *)"EXINIT")) != NULL)
  983. X            docmdline(initstr);
  984. X        else
  985. X            (void)dosource((char_u *)SYSEXRC_FILE);
  986. X    }
  987. X
  988. X/*
  989. X * Read initialization commands from ".vimrc" or ".exrc" in current directory.
  990. X * This is only done if the 'exrc' option is set.
  991. X * Because of security reasons we disallow shell and write commands now,
  992. X * except for unix if the file is owned by the user or 'secure' option has been
  993. X * reset in environmet of global ".exrc" or ".vimrc".
  994. X * Only do this if VIMRC_FILE is not the same as SYSVIMRC_FILE or DEFVIMRC_FILE.
  995. X */
  996. X    if (p_exrc)
  997. X    {
  998. X#ifdef UNIX
  999. X        {
  1000. X            struct stat s;
  1001. X
  1002. X                /* if ".vimrc" file is not owned by user, set 'secure' mode */
  1003. X            if (stat(VIMRC_FILE, &s) || s.st_uid != getuid())
  1004. X                secure = p_secure;
  1005. X        }
  1006. X#else
  1007. X        secure = p_secure;
  1008. X#endif
  1009. X
  1010. X        i = FAIL;
  1011. X        if (fullpathcmp((char_u *)SYSVIMRC_FILE, (char_u *)VIMRC_FILE)
  1012. X#ifdef DEFVIMRC_FILE
  1013. X                && fullpathcmp((char_u *)DEFVIMRC_FILE, (char_u *)VIMRC_FILE)
  1014. X#endif
  1015. X                )
  1016. X            i = dosource((char_u *)VIMRC_FILE);
  1017. X#ifdef UNIX
  1018. X        if (i == FAIL)
  1019. X        {
  1020. X            struct stat s;
  1021. X
  1022. X                /* if ".exrc" file is not owned by user set 'secure' mode */
  1023. X            if (stat(EXRC_FILE, &s) || s.st_uid != getuid())
  1024. X                secure = p_secure;
  1025. X            else
  1026. X                secure = 0;
  1027. X        }
  1028. X#endif
  1029. X        if (i == FAIL && fullpathcmp((char_u *)SYSEXRC_FILE, (char_u *)EXRC_FILE))
  1030. X            (void)dosource((char_u *)EXRC_FILE);
  1031. X    }
  1032. X
  1033. X#ifdef SPAWNO            /* special MSDOS swapping library */
  1034. X    init_SPAWNO("", SWAP_ANY);
  1035. X#endif
  1036. X/*
  1037. X * Call settmode and starttermcap here, so the T_KS and T_TS may be defined
  1038. X * by termcapinit and redifined in .exrc.
  1039. X */
  1040. X    settmode(1);
  1041. X    starttermcap();
  1042. X
  1043. X    no_wait_return = FALSE;
  1044. X        /* done something that is not allowed or error message */
  1045. X    if (secure == 2 || need_wait_return)
  1046. X        wait_return(TRUE);        /* must be called after settmode(1) */
  1047. X    secure = 0;
  1048. X
  1049. X    if (bin_mode)                    /* -b option used */
  1050. X    {
  1051. X        curbuf->b_p_bin = 1;        /* binary file I/O */
  1052. X        curbuf->b_p_tw = 0;            /* no automatic line wrap */
  1053. X        curbuf->b_p_wm = 0;            /* no automatic line wrap */
  1054. X        curbuf->b_p_tx = 0;            /* no text mode */
  1055. X        p_ta = 0;                    /* no text auto */
  1056. X        curbuf->b_p_ml = 0;            /* no modelines */
  1057. X        curbuf->b_p_et = 0;            /* no expand tab */
  1058. X    }
  1059. X
  1060. X    (void)setfname(fname, NULL, TRUE);
  1061. X    maketitle();
  1062. X
  1063. X    if (win_count == 0)
  1064. X        win_count = arg_count;
  1065. X    if (win_count > 1)
  1066. X        win_count = make_windows(win_count);
  1067. X    else
  1068. X        win_count = 1;
  1069. X
  1070. X/*
  1071. X * Start putting things on the screen.
  1072. X * Scroll screen down before drawing over it
  1073. X * Clear screen now, so file message will not be cleared.
  1074. X */
  1075. X    starting = FALSE;
  1076. X    if (T_CVV != NULL && *T_CVV)
  1077. X    {
  1078. X        outstr(T_CVV);
  1079. X        outstr(T_CV);
  1080. X    }
  1081. X    screenclear();                        /* clear screen */
  1082. X
  1083. X    if (recoverymode)                    /* do recover */
  1084. X    {
  1085. X        if (ml_open() == FAIL)            /* Initialize storage structure */
  1086. X            getout(1);
  1087. X        ml_recover();
  1088. X    }
  1089. X    else
  1090. X        (void)open_buffer();            /* create memfile and read file */
  1091. X
  1092. X    setpcmark();
  1093. X
  1094. X    if (doqf && qf_init() == FAIL)        /* if reading error file fails: exit */
  1095. X        mch_windexit(3);
  1096. X
  1097. X    /*
  1098. X     * If opened more than one window, start editing files in the other windows.
  1099. X     * Make_windows() has already opened the windows.
  1100. X     * This is all done by putting commands in the stuff buffer.
  1101. X     */
  1102. X    for (i = 1; i < win_count; ++i)
  1103. X    {
  1104. X        if (curwin->w_next == NULL)            /* just checking */
  1105. X            break;
  1106. X        win_enter(curwin->w_next, FALSE);
  1107. X                                            /* edit file i, if there is one */
  1108. X        (void)doecmd(i < arg_count ? arg_files[i] : NULL,
  1109. X                                            NULL, NULL, TRUE, (linenr_t)1);
  1110. X        curwin->w_arg_idx = i;
  1111. X    }
  1112. X    win_enter(firstwin, FALSE);                /* back to first window */
  1113. X
  1114. X    /*
  1115. X     * If there are more file names in the argument list than windows,
  1116. X     * put the rest of the names in the buffer list.
  1117. X     */
  1118. X    for (i = win_count; i < arg_count; ++i)
  1119. X        (void)buflist_add(arg_files[i]);
  1120. X
  1121. X    if (command)
  1122. X        docmdline(command);
  1123. X    /*
  1124. X     * put the :ta command in the stuff buffer here, so that it will not
  1125. X     * be erased by an emsg().
  1126. X     */
  1127. X    if (tagname)
  1128. X    {
  1129. X        stuffReadbuff((char_u *)":ta ");
  1130. X        stuffReadbuff(tagname);
  1131. X        stuffReadbuff((char_u *)"\n");
  1132. X    }
  1133. X
  1134. X    RedrawingDisabled = FALSE;
  1135. X    updateScreen(NOT_VALID);
  1136. X
  1137. X        /* start in insert mode (already taken care of for :ta command) */
  1138. X    if (p_im && stuff_empty())
  1139. X        stuffReadbuff((char_u *)"i");
  1140. X/*
  1141. X * main command loop
  1142. X */
  1143. X    for (;;)
  1144. X    {
  1145. X        if (got_int)
  1146. X        {
  1147. X            (void)vgetc();                /* flush all buffers */
  1148. X            got_int = FALSE;
  1149. X        }
  1150. X        adjust_cursor();                /* put cursor on an existing line */
  1151. X        if (skip_redraw)                /* skip redraw (for ":" in wait_return()) */
  1152. X            skip_redraw = FALSE;
  1153. X        else if (stuff_empty())            /* only when no command pending */
  1154. X        {
  1155. X            cursupdate();                /* Figure out where the cursor is based
  1156. X                                            on curwin->w_cursor. */
  1157. X            if (VIsual.lnum)
  1158. X                updateScreen(INVERTED);    /* update inverted part */
  1159. X            if (must_redraw)
  1160. X                updateScreen(must_redraw);
  1161. X            if (keep_msg)
  1162. X                msg(keep_msg);            /* display message after redraw */
  1163. X
  1164. X            showruler(FALSE);
  1165. X
  1166. X            setcursor();
  1167. X            cursor_on();
  1168. X        }
  1169. X
  1170. X        normal();                        /* get and execute a command */
  1171. X    }
  1172. X    /*NOTREACHED*/
  1173. X}
  1174. X
  1175. X    void
  1176. Xgetout(r)
  1177. X    int             r;
  1178. X{
  1179. X    windgoto((int)Rows - 1, 0);
  1180. X    outchar('\r');
  1181. X    outchar('\n');
  1182. X    mch_windexit(r);
  1183. X}
  1184. END_OF_FILE
  1185.   if test 14502 -ne `wc -c <'vim/src/main.c'`; then
  1186.     echo shar: \"'vim/src/main.c'\" unpacked with wrong size!
  1187.   fi
  1188.   # end of 'vim/src/main.c'
  1189. fi
  1190. if test -f 'vim/src/makefile.unix' -a "${1}" != "-c" ; then 
  1191.   echo shar: Will not clobber existing file \"'vim/src/makefile.unix'\"
  1192. else
  1193.   echo shar: Extracting \"'vim/src/makefile.unix'\" \(13424 characters\)
  1194.   sed "s/^X//" >'vim/src/makefile.unix' <<'END_OF_FILE'
  1195. X#
  1196. X# Makefile for Vim on Unix
  1197. X#
  1198. X
  1199. X# Note: You MUST uncomment three hardware dependend lines!
  1200. X
  1201. X# There are three types of defines:
  1202. X#
  1203. X# 1. configuration dependend
  1204. X#    Used for "make install". Adjust the path names and protections
  1205. X#    to your desire. Also defines the root for the X11 files (not required).
  1206. X#
  1207. X# 2. various choices
  1208. X#    Can be changed to match your compiler or your preferences (not
  1209. X#    required).
  1210. X#
  1211. X# 3. hardware dependend
  1212. X#    If you machine is in the list, remove one '#' in front of the defines
  1213. X#    following it. Otherwise: Find a machine that is similar and change the
  1214. X#    defines to make it work. Normally you can just try and see what error
  1215. X#    messages you get. (REQUIRED).
  1216. X
  1217. X# The following systems have entries below. They have been tested and should
  1218. X# work without modification. But later code changes may cause small problems.
  1219. X# There are entries for other systems, but these have not been tested recently.
  1220. X
  1221. X#system:        tested configurations:        tested by:
  1222. X
  1223. X#Sun 4.1.x        cc    gcc    X11    no X11    (jw) (mool)
  1224. X#FreeBSD        cc    gcc    X11    no X11    (mool)
  1225. X#linux 1.0        cc        X11
  1226. X#Linux 1.0.9            gcc        no X11    (jw)
  1227. X#ULTRIX 4.2A on MIPS    cc    gcc        no X11    (mool)
  1228. X#HPUX            cc    gcc    X11    no X11    (jw) (mool)
  1229. X#irix 4.0.5H        cc        X11
  1230. X#IRIX 4.0  SGI        cc        X11        (jw)
  1231. X#SINIX-L 5.41        cc            no X11
  1232. X#MOT188            cc            no X11
  1233. X#Sequent/ptx 1.3    cc            no X11    (jw)
  1234. X#osf1            cc            no X11    (jw)
  1235. X#Unisys 6035        cc            no X11
  1236. X#SCO 3.2        cc    gcc        no X11    jos@oce.nl
  1237. X#Solaris        cc        X11
  1238. X#Solaris/Sun OS 5.3    cc            no X11    (jw)
  1239. X#AIX (rs6000)        cc            no X11    (jw)
  1240. X#RISCos on MIPS        cc        X11    no X11    (jw)
  1241. X
  1242. X# configurations marked by (jw) have been tested by Juergen Weigert:
  1243. X#    jnweiger@uni-erlangen.de
  1244. X
  1245. X#
  1246. X# PART 1: configuration dependend
  1247. X#
  1248. X
  1249. X### root directory for X11 files (unless overruled in hardware-dependend part)
  1250. X### Unfortunately there is no standard for these, everybody puts them
  1251. X### somewhere else
  1252. XX11LIBDIR = /usr/openwin/lib
  1253. XX11INCDIR = /usr/openwin/include
  1254. X### for some hpux systems:
  1255. X#X11LIBDIR = /usr/lib/X11R5
  1256. X#X11INCDIR = /usr/include/X11R5
  1257. X
  1258. X### Prefix for location of files
  1259. XPREFIX = /usr/local
  1260. X
  1261. X### Location of binary
  1262. XBINLOC = $(PREFIX)/bin
  1263. X
  1264. X### Name of target
  1265. XTARGET = vim
  1266. X
  1267. X### Location of man page
  1268. XMANLOC = $(PREFIX)/man/man1
  1269. X
  1270. X### Location of help file
  1271. XHELPLOC = $(PREFIX)/lib
  1272. X
  1273. X### Program to run on installed binary
  1274. XSTRIP = strip
  1275. X
  1276. X### Permissions for vim binary
  1277. XBINMOD = 755
  1278. X
  1279. X### Permissions for man page
  1280. XMANMOD = 644
  1281. X
  1282. X### Permissions for help file
  1283. XHELPMOD = 644
  1284. X
  1285. XMANFILE = ../doc/vim.1
  1286. X
  1287. XHELPFILE = ../doc/vim.hlp
  1288. X
  1289. X#
  1290. X# PART 2: various choices
  1291. X#
  1292. X
  1293. X### -DDIGRAPHS        digraph support
  1294. X### -DNO_FREE_NULL    do not call free() with a null pointer
  1295. X### -DCOMPATIBLE    start in vi-compatible mode
  1296. X### -DNOBACKUP        default is no backup file
  1297. X### -DDEBUG        output a lot of debugging garbage
  1298. X### -DSTRNCASECMP    use strncasecmp() instead of internal function
  1299. X### -DUSE_LOCALE    use setlocale() to change ctype() and others
  1300. X### -DTERMCAP        full termcap/terminfo file support
  1301. X### -DTERMINFO        use terminfo instead of termcap entries for builtin terms
  1302. X### -DNO_BUILTIN_TCAPS    do not include builtin termcap entries
  1303. X###                (use only with -DTERMCAP)
  1304. X### -DSOME_BUILTIN_TCAPS include most useful builtin termcap entries
  1305. X###                (use only without -DNO_BUILTIN_TCAPS)
  1306. X### -DALL_BUILTIN_TCAPS    include all builtin termcap entries
  1307. X###                (use only without -DNO_BUILTIN_TCAPS)
  1308. X### -DMAXNAMLEN 31    maximum length of a file name (if not defined in sys/dir.h)
  1309. X### -Dconst=        for compilers that don't have type const
  1310. X### -DVIMRC_FILE=name        name of the .vimrc file in current dir
  1311. X### -DEXRC_FILE=name        name of the .exrc file in current dir
  1312. X### -DSYSVIMRC_FILE=name    name of the global .vimrc file
  1313. X### -DSYSEXRC_FILE=name        name of the global .exrc file
  1314. X### -DDEFVIMRC_FILE=name    name of the system-wide .vimrc file
  1315. X### -DVIM_HLP=name        name of the help file
  1316. X### -DUSE_SYSTEM    use system() instead of fork/exec for starting a shell
  1317. X### -DVIM_ISSPACE    use when isspace() can't handle meta chars
  1318. X### -DNOLIMITS        limits.h does not exist
  1319. X### -DNOSTDLIB        stdlib.h does not exist
  1320. X### -DUSE_X11        include code for xterm title saving
  1321. X### -DWEBB_COMPLETE    include Webb's code for command line completion
  1322. X### -DWEBB_KEYWORD_COMPL include Webb's code for keyword completion
  1323. X### -DNOTITLE        'title' option off by default
  1324. XDEFS = -DDIGRAPHS -DTERMCAP -DSOME_BUILTIN_TCAPS -DNO_FREE_NULL -DVIM_ISSPACE \
  1325. X        -DWEBB_COMPLETE -DWEBB_KEYWORD_COMPL \
  1326. X        -DVIM_HLP=\"$(HELPLOC)/vim.hlp\"
  1327. X
  1328. X#
  1329. X# PART 3: hardware dependend
  1330. X#
  1331. X
  1332. X### CC entry:      name and arguments for the compiler (also for linking)
  1333. X### MACHINE entry: defines used for compiling (not for linking)
  1334. X### LIBS:          defines used for linking
  1335. X
  1336. X# generic for Sun, NeXT, POSIX and SYSV R4 (?) (TESTED for Sun 4.1.x)
  1337. X# standard cc with optimizer
  1338. X#
  1339. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE -DUSE_X11
  1340. X#CC=cc -O -I$(X11INCDIR)
  1341. X#LIBS = -ltermlib -L$(X11LIBDIR) -lX11
  1342. X
  1343. X# generic for Sun, FreeBSD, NetBSD, NeXT, POSIX and SYSV R4 (?) without x11 code
  1344. X#    (TESTED for Sun 4.1.x and FreeBSD)
  1345. X# standard cc with optimizer
  1346. X#
  1347. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE
  1348. X#CC=cc -O
  1349. X#LIBS = -ltermlib
  1350. X
  1351. X# FreeBSD and NetBSD with Xfree (TESTED for FreeBSD)
  1352. X# standard cc with optimizer
  1353. X#
  1354. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE -DUSE_X11
  1355. X#CC=cc -O -L/usr/X386/lib -I/usr/X386/include
  1356. X#LIBS = -ltermlib -lX11
  1357. X
  1358. X# FreeBSD and NetBSD with Xfree (TESTED for FreeBSD)
  1359. X# gcc with optimizer
  1360. X#
  1361. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE -DUSE_X11
  1362. X#CC=gcc -O -Wall -traditional -Dconst= -I/usr/X386/include
  1363. X#LIBS = -ltermlib -L/usr/X386/lib -lX11
  1364. X
  1365. X# like generic, but with termcap, for Linux, NeXT and others (NOT TESTED YET)
  1366. X# standard cc with optimizer
  1367. X#
  1368. X#MACHINE = -DBSD_UNIX
  1369. X#CC=cc -O
  1370. X#LIBS = -ltermcap
  1371. X
  1372. X# linux 1.0 with X11 (TESTED)
  1373. X#
  1374. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE -DUSE_X11
  1375. X#CC=cc -O -I/usr/X11/include
  1376. X#LIBS = -ltermcap -L/usr/X11/lib -lX11
  1377. X
  1378. X# like generic, but with debugging (NOT TESTED YET)
  1379. X#
  1380. X#MACHINE = -DBSD_UNIX -g
  1381. X#CC=cc
  1382. X#LIBS = -ltermlib
  1383. X
  1384. X# like generic, but with gcc and X11 (TESTED on Sun 4.1.x)
  1385. X#
  1386. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE -DUSE_X11
  1387. X#CC=gcc -O -Wall -traditional -Dconst= -L$(X11LIBDIR) -I$(X11INCDIR)
  1388. X#LIBS = -ltermlib -lX11
  1389. X
  1390. X# like generic, but with gcc, without X11 (TESTED on ULTRIX 4.2A on MIPS)
  1391. X#
  1392. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE
  1393. X#CC=gcc -O -Wall -traditional -Dconst=
  1394. X#LIBS = -ltermlib
  1395. X
  1396. X# like generic, but with gcc 2.5.8 (TESTED on Sun 4.1.3_U1)
  1397. X#
  1398. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE
  1399. X#CC=gcc -O1000
  1400. X#LIBS = -ltermlib
  1401. X
  1402. X# standard cc with optimizer for ULTRIX 4.2A on MIPS (ultrix defined) (TESTED)
  1403. X#
  1404. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE
  1405. X#CC=cc -O -Olimit 1500
  1406. X#LIBS = -ltermlib
  1407. X
  1408. X# GCC (2.2.2d) on Linux (1.0.9) (TESTED)
  1409. X#
  1410. X#MACHINE = -DBSD_UNIX
  1411. X#CC=gcc -O6 -Wall
  1412. X#LIBS = -ltermcap
  1413. X
  1414. X# Apollo DOMAIN (with SYSTYPE = bsd4.3) (NOT TESTED YET)
  1415. X#
  1416. X#MACHINE = -DBSD_UNIX -DDOMAIN
  1417. X#CC=cc -O -A systype,bsd4.3
  1418. X#LIBS = -ltermlib
  1419. X
  1420. X# HPUX with X11 (TESTED) (hpux is defined)
  1421. X#
  1422. X#MACHINE = -DBSD_UNIX -DTERMINFO -DUSE_X11
  1423. X#CC=cc -O -I$(X11INCDIR)
  1424. X#LIBS = -ltermcap -L$(X11LIBDIR) -lX11
  1425. X
  1426. X# HPUX (TESTED) (hpux is defined)
  1427. X#
  1428. X#MACHINE = -DBSD_UNIX -DTERMINFO
  1429. X#CC=cc -O
  1430. X#LIBS = -ltermcap
  1431. X
  1432. X# HPUX with gcc (TESTED) (hpux is defined)
  1433. X#
  1434. X#MACHINE = -DBSD_UNIX -DTERMINFO
  1435. X#CC=gcc -O
  1436. X#LIBS = -ltermcap
  1437. X
  1438. X# hpux 9.01 (with termlib instead of termcap) (TESTED)
  1439. X# irix 4.0.5H (TESTED)
  1440. X#
  1441. X#MACHINE = -DBSD_UNIX -DUSE_LOCALE -DUSE_X11
  1442. X#CC=cc -O -I$(X11INCDIR)
  1443. X#LIBS = -ltermlib -L$(X11LIBDIR) -lX11
  1444. X
  1445. X# IRIX 4.0 (Silicon Graphics Indigo, __sgi will be defined) (TESTED)
  1446. X#
  1447. X#MACHINE = -DBSD_UNIX -DUSE_X11                         
  1448. X#CC=cc -O -Olimit 1500
  1449. X#LIBS = -ltermlib -lX11 -lmalloc -lc_s
  1450. X
  1451. X# Convex (NOT TESTED YET)
  1452. X#
  1453. X#MACHINE = -DBSD_UNIX -DCONVEX
  1454. X#CC=cc -O
  1455. X#LIBS = -ltermcap
  1456. X
  1457. X# generic SYSV_UNIX for Dynix/PTX and SYSV R3 (and R4?) (TESTED on SINIX-L 5.41)
  1458. X# (TESTED on MOT188) (TESTED on Sequent/ptx 1.3) (TESTED on osf1)
  1459. X# First try the line with locale. If this gives error messages try the other one.
  1460. X#
  1461. X#MACHINE = -DSYSV_UNIX -DUSE_LOCALE
  1462. X#MACHINE = -DSYSV_UNIX
  1463. X#CC=cc -O
  1464. X#LIBS = -ltermlib
  1465. X
  1466. X# generic SYSV_UNIX with LOCALE (TESTED on Unisys 6035)
  1467. X#
  1468. X#MACHINE = -DSYSV_UNIX -DUSE_LOCALE -DUNISYS
  1469. X#CC=cc -O
  1470. X#LIBS = -ltermlib
  1471. X
  1472. X# SCO Xenix (NOT TESTED YET)
  1473. X#
  1474. X#MACHINE = -DSYSV_UNIX -DSCO
  1475. X#CC=cc -O
  1476. X#LIBS = -ltermlib
  1477. X
  1478. X# GCC on SCO 3.2 (TESTED by jos@oce.nl)
  1479. X# cc works too.
  1480. X#
  1481. X#MACHINE = -DSYSV_UNIX -UM_XENIX -DSCO
  1482. X#CC=gcc -O -Wall
  1483. X#LIBS = -ltinfo
  1484. X
  1485. X# GCC on another SCO Unix (NOT TESTED YET)
  1486. X#
  1487. X#MACHINE = -DSYSV_UNIX -UM_XENIX -DSCO -g
  1488. X#CC=gcc -O6 -fpcc-struct-return -fwritable-strings
  1489. X#LIBS = -ltermlib -lmalloc
  1490. X
  1491. X# Dynix with gcc (NOT TESTED YET)
  1492. X#
  1493. X#MACHINE = -DSYSV_UNIX
  1494. X#CC=gcc -O -Wall -traditional
  1495. X#LIBS = -ltermlib
  1496. X
  1497. X# SOLARIS with X11 anc cc (TESTED)
  1498. X#
  1499. X#MACHINE = -DSYSV_UNIX -DSOLARIS -DTERMINFO -DUSE_X11
  1500. X#CC=cc -O -Xa -v -R$(X11LIBDIR) -L$(X11LIBDIR) -I$(X11INCDIR)
  1501. X#LIBS = -ltermlib -lX11
  1502. X
  1503. X# SOLARIS with X11 and gcc (TESTED with SOLARIS 2.3 and gcc 2.5.8)
  1504. X#
  1505. X#MACHINE = -DSYSV_UNIX -DSOLARIS -DTERMINFO -DUSE_X11
  1506. X#CC=gcc -O -R$(X11LIBDIR) -L$(X11LIBDIR) -I$(X11INCDIR)
  1507. X#LIBS = -ltermlib -lX11
  1508. X
  1509. X# SOLARIS (also works for Esix 4.0.3, SYSV R4?) (TESTED on Sun OS 5.3)
  1510. X#
  1511. X#MACHINE = -DSYSV_UNIX -DSOLARIS -DTERMINFO
  1512. X#CC=cc -O -Xa -v
  1513. X#LIBS = -ltermlib
  1514. X
  1515. X# UNICOS (NOT TESTED YET)
  1516. X#
  1517. X#MACHINE = -DSYSV_UNIX -DUNICOS
  1518. X#CC=cc -O
  1519. X#LIBS = -ltermlib
  1520. X
  1521. X# AIX (rs6000) (TESTED)
  1522. X#
  1523. X#MACHINE = -DSYSV_UNIX -DAIX
  1524. X#CC=cc -O
  1525. X#LIBS=-lcur
  1526. X
  1527. X# UTS2 for Amdahl UTS 2.1.x (disable termcap below) (NOT TESTED YET)
  1528. X#
  1529. X#MACHINE = -DSYSV_UNIX -DUTS2
  1530. X#CC=cc -O
  1531. X#LIBS = -ltermlib -lsocket
  1532. X
  1533. X# UTS4 for Amdahl UTS 4.x (NOT TESTED YET)
  1534. X#
  1535. X#MACHINE = -DSYSV_UNIX -DUTS4 -Xa
  1536. X#CC=cc -O
  1537. X#LIBS = -ltermlib
  1538. X
  1539. X# USL for Unix Systems Laboratories (SYSV 4.2) (NOT TESTED YET)
  1540. X#
  1541. X#MACHINE = -DSYSV_UNIX -DUSL
  1542. X#CC=cc -O
  1543. X#LIBS = -ltermlib
  1544. X
  1545. X# RISCos on MIPS without X11 (TESTED)
  1546. X#
  1547. X#MACHINE = -DSYSV_UNIX -DMIPS
  1548. X#CC=cc -O
  1549. X#LIBS = -ltermlib
  1550. X
  1551. X# RISCos on MIPS with X11 (TESTED)
  1552. X#
  1553. X#MACHINE=-DSYSV_UNIX -DUSE_LOCALE -DUSE_X11
  1554. X#CC=cc -O -I$(X11INCDIR)
  1555. X#LIBS=-ltermlib -L$(X11LIBDIR) -lX11 -lsun
  1556. X
  1557. X################################################
  1558. X##   no changes required below this line      ##
  1559. X################################################
  1560. X
  1561. XCFLAGS = -c $(MACHINE) $(DEFS)
  1562. X
  1563. XINCL = vim.h globals.h param.h keymap.h macros.h ascii.h term.h unix.h structs.h proto.h
  1564. X
  1565. XOBJ =    alloc.o unix.o buffer.o charset.o cmdcmds.o cmdline.o \
  1566. X    csearch.o digraph.o edit.o fileio.o getchar.o help.o \
  1567. X    linefunc.o main.o mark.o memfile.o memline.o message.o misccmds.o \
  1568. X    normal.o ops.o param.o quickfix.o regexp.o \
  1569. X    regsub.o screen.o search.o \
  1570. X    tag.o term.o undo.o window.o $(TERMLIB)
  1571. X
  1572. X$(TARGET): $(OBJ) version.c
  1573. X    $(CC) $(CFLAGS) version.c
  1574. X    $(CC) -o $(TARGET) $(OBJ) version.o $(LIBS)
  1575. X
  1576. Xdebug: $(OBJ) version.c
  1577. X    $(CC) $(CFLAGS) version.c
  1578. X    $(CC) -o $(TARGET) -g $(OBJ) version.o $(LIBS)
  1579. X
  1580. Xctags:
  1581. X    ctags *.c *.h
  1582. X
  1583. Xinstall: $(TARGET)
  1584. X    -mkdir $(BINLOC)
  1585. X    cp $(TARGET) $(BINLOC)
  1586. X    chmod $(BINMOD) $(BINLOC)/$(TARGET)
  1587. X    $(STRIP) $(BINLOC)/$(TARGET)
  1588. X    -mkdir $(MANLOC)
  1589. X    cp $(MANFILE) $(MANLOC)
  1590. X    chmod $(MANMOD) $(MANLOC)/vim.1
  1591. X    -mkdir $(HELPLOC)
  1592. X    cp $(HELPFILE) $(HELPLOC)
  1593. X    chmod $(HELPMOD) $(HELPLOC)/vim.hlp
  1594. X
  1595. Xclean:
  1596. X    -rm -f $(OBJ) mkcmdtab.o version.o core $(TARGET) mkcmdtab cmdtab.h
  1597. X    -rm -f *.bak
  1598. X
  1599. X#use this in case the files have been transported via an MSDOS system
  1600. X
  1601. XFILES = *.c *.h makefile makefile.* cmdtab.tab proto/*.pro tags
  1602. X
  1603. Xdos2unix:
  1604. X    -mv arp_prot.h arp_proto.h
  1605. X    -mv ptx_stdl.h ptx_stdlib.h
  1606. X    -mv sun_stdl.h sun_stdlib.h
  1607. X    -mv makefile.dic makefile.dice
  1608. X    -mv makefile.uni makefile.unix
  1609. X    -mv makefile.man makefile.manx
  1610. X    -mv makefile.6sa makefile.6sas
  1611. X    -mv makefile.5sa makefile.5sas
  1612. X    for i in $(FILES); do tr -d '\r\032' < $$i > ~tmp~; mv ~tmp~ $$i; echo $$i; done
  1613. X
  1614. X###########################################################################
  1615. X
  1616. Xalloc.o:    alloc.c  $(INCL)
  1617. X    $(CC) $(CFLAGS) alloc.c
  1618. X
  1619. Xunix.o:    unix.c  $(INCL)
  1620. X    $(CC) $(CFLAGS) unix.c
  1621. X
  1622. Xbuffer.o:    buffer.c  $(INCL)
  1623. X    $(CC) $(CFLAGS) buffer.c
  1624. X
  1625. Xcharset.o:    charset.c  $(INCL)
  1626. X    $(CC) $(CFLAGS) charset.c
  1627. X
  1628. Xcmdcmds.o:    cmdcmds.c  $(INCL)
  1629. X    $(CC) $(CFLAGS) cmdcmds.c
  1630. X
  1631. Xcmdline.o:    cmdline.c  $(INCL) cmdtab.h ops.h
  1632. X    $(CC) $(CFLAGS) cmdline.c
  1633. X
  1634. Xcsearch.o:    csearch.c  $(INCL)
  1635. X    $(CC) $(CFLAGS) csearch.c
  1636. X
  1637. Xdigraph.o:    digraph.c  $(INCL)
  1638. X    $(CC) $(CFLAGS) digraph.c
  1639. X
  1640. Xedit.o:    edit.c  $(INCL) ops.h
  1641. X    $(CC) $(CFLAGS) edit.c
  1642. X
  1643. Xfileio.o:    fileio.c  $(INCL)
  1644. X    $(CC) $(CFLAGS) fileio.c
  1645. X
  1646. Xgetchar.o:    getchar.c  $(INCL)
  1647. X    $(CC) $(CFLAGS) getchar.c
  1648. X
  1649. Xhelp.o:    help.c  $(INCL)
  1650. X    $(CC) $(CFLAGS) help.c
  1651. X
  1652. Xlinefunc.o:    linefunc.c  $(INCL)
  1653. X    $(CC) $(CFLAGS) linefunc.c
  1654. X
  1655. Xmain.o:    main.c  $(INCL)
  1656. X    $(CC) $(CFLAGS) main.c
  1657. X
  1658. Xmark.o:    mark.c  $(INCL)
  1659. X    $(CC) $(CFLAGS) mark.c
  1660. X
  1661. Xmemfile.o:    memfile.c  $(INCL)
  1662. X    $(CC) $(CFLAGS) memfile.c
  1663. X
  1664. Xmemline.o:    memline.c  $(INCL)
  1665. X    $(CC) $(CFLAGS) memline.c
  1666. X
  1667. Xmessage.o:    message.c  $(INCL)
  1668. X    $(CC) $(CFLAGS) message.c
  1669. X
  1670. Xmisccmds.o:    misccmds.c  $(INCL)
  1671. X    $(CC) $(CFLAGS) misccmds.c
  1672. X
  1673. Xnormal.o:    normal.c  $(INCL) ops.h
  1674. X    $(CC) $(CFLAGS) normal.c
  1675. X
  1676. Xops.o:    ops.c  $(INCL) ops.h
  1677. X    $(CC) $(CFLAGS) ops.c
  1678. X
  1679. Xparam.o:    param.c  $(INCL)
  1680. X    $(CC) $(CFLAGS) param.c
  1681. X
  1682. Xquickfix.o:    quickfix.c  $(INCL)
  1683. X    $(CC) $(CFLAGS) quickfix.c
  1684. X
  1685. Xregexp.o:    regexp.c  $(INCL)
  1686. X    $(CC) $(CFLAGS) regexp.c
  1687. X
  1688. Xregsub.o:    regsub.c  $(INCL)
  1689. X    $(CC) $(CFLAGS) regsub.c
  1690. X
  1691. Xscreen.o:    screen.c  $(INCL)
  1692. X    $(CC) $(CFLAGS) screen.c
  1693. X
  1694. Xsearch.o:    search.c  $(INCL) ops.h
  1695. X    $(CC) $(CFLAGS) search.c
  1696. X
  1697. Xtag.o:    tag.c  $(INCL)
  1698. X    $(CC) $(CFLAGS) tag.c
  1699. X
  1700. Xterm.o:    term.c  $(INCL)
  1701. X    $(CC) $(CFLAGS) term.c
  1702. X
  1703. Xundo.o:    undo.c  $(INCL)
  1704. X    $(CC) $(CFLAGS) undo.c
  1705. X
  1706. Xwindow.o:    window.c  $(INCL)
  1707. X    $(CC) $(CFLAGS) window.c
  1708. X
  1709. Xcmdtab.h: cmdtab.tab mkcmdtab
  1710. X    ./mkcmdtab cmdtab.tab cmdtab.h
  1711. X
  1712. Xmkcmdtab: mkcmdtab.o
  1713. X    $(CC) -o mkcmdtab mkcmdtab.o
  1714. X
  1715. Xmkcmdtab.o: mkcmdtab.c
  1716. X    $(CC) $(CFLAGS) mkcmdtab.c
  1717. END_OF_FILE
  1718.   if test 13424 -ne `wc -c <'vim/src/makefile.unix'`; then
  1719.     echo shar: \"'vim/src/makefile.unix'\" unpacked with wrong size!
  1720.   fi
  1721.   # end of 'vim/src/makefile.unix'
  1722. fi
  1723. if test -f 'vim/src/regsub.c' -a "${1}" != "-c" ; then 
  1724.   echo shar: Will not clobber existing file \"'vim/src/regsub.c'\"
  1725. else
  1726.   echo shar: Extracting \"'vim/src/regsub.c'\" \(7512 characters\)
  1727.   sed "s/^X//" >'vim/src/regsub.c' <<'END_OF_FILE'
  1728. X/* vi:ts=4:sw=4
  1729. X * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
  1730. X *
  1731. X * This is NOT the original regular expression code as written by
  1732. X * Henry Spencer. This code has been modified specifically for use
  1733. X * with the VIM editor, and should not be used apart from compiling
  1734. X * VIM. If you want a good regular expression library, get the
  1735. X * original code. The copyright notice that follows is from the
  1736. X * original.
  1737. X *
  1738. X * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
  1739. X *
  1740. X * regsub
  1741. X *
  1742. X *        Copyright (c) 1986 by University of Toronto.
  1743. X *        Written by Henry Spencer.  Not derived from licensed software.
  1744. X *
  1745. X *        Permission is granted to anyone to use this software for any
  1746. X *        purpose on any computer system, and to redistribute it freely,
  1747. X *        subject to the following restrictions:
  1748. X *
  1749. X *        1. The author is not responsible for the consequences of use of
  1750. X *                this software, no matter how awful, even if they arise
  1751. X *                from defects in it.
  1752. X *
  1753. X *        2. The origin of this software must not be misrepresented, either
  1754. X *                by explicit claim or by omission.
  1755. X *
  1756. X *        3. Altered versions must be plainly marked as such, and must not
  1757. X *                be misrepresented as being the original software.
  1758. X *
  1759. X * $Log:        regsub.c,v $
  1760. X * Revision 1.2  88/04/28  08:11:25  tony
  1761. X * First modification of the regexp library. Added an external variable
  1762. X * 'reg_ic' which can be set to indicate that case should be ignored.
  1763. X * Added a new parameter to regexec() to indicate that the given string
  1764. X * comes from the beginning of a line and is thus eligible to match
  1765. X * 'beginning-of-line'.
  1766. X *
  1767. X * Revisions by Olaf 'Rhialto' Seibert, rhialto@cs.kun.nl:
  1768. X * Changes for vi: (the semantics of several things were rather different)
  1769. X * - Added lexical analyzer, because in vi magicness of characters
  1770. X *   is rather difficult, and may change over time.
  1771. X * - Added support for \< \> \1-\9 and ~
  1772. X * - Left some magic stuff in, but only backslashed: \| \+
  1773. X * - * and \+ still work after \) even though they shouldn't.
  1774. X */
  1775. X
  1776. X#include "vim.h"
  1777. X#include "globals.h"
  1778. X#include "proto.h"
  1779. X
  1780. X#ifdef MSDOS
  1781. X# define __ARGS(a)    a
  1782. X#endif
  1783. X
  1784. X#define CASECONVERT
  1785. X
  1786. X#include <stdio.h>
  1787. X#include "regexp.h"
  1788. X#include "regmagic.h"
  1789. X
  1790. X#ifdef LATTICE
  1791. X# include <sys/types.h>        /* for size_t */
  1792. X#endif
  1793. X
  1794. X#ifndef CHARBITS
  1795. X#define UCHARAT(p)      ((int)*(char_u *)(p))
  1796. X#else
  1797. X#define UCHARAT(p)      ((int)*(p)&CHARBITS)
  1798. X#endif
  1799. X
  1800. Xextern char_u        *reg_prev_sub;
  1801. X
  1802. X#ifdef CASECONVERT
  1803. X    /*
  1804. X     * We should define ftpr as a pointer to a function returning a pointer to
  1805. X     * a function returning a pointer to a function ...
  1806. X     * This is impossible, so we declare a pointer to a function returning a
  1807. X     * pointer to a function returning void. This should work for all compilers.
  1808. X     */
  1809. Xtypedef void (*(*fptr) __ARGS((char_u *, int)))();
  1810. Xstatic fptr strnfcpy __ARGS((fptr, char_u *, char_u *, int));
  1811. X
  1812. Xstatic fptr do_Copy __ARGS((char_u *, int));
  1813. Xstatic fptr do_upper __ARGS((char_u *, int));
  1814. Xstatic fptr do_Upper __ARGS((char_u *, int));
  1815. Xstatic fptr do_lower __ARGS((char_u *, int));
  1816. Xstatic fptr do_Lower __ARGS((char_u *, int));
  1817. X
  1818. X    static fptr
  1819. Xdo_Copy(d, c)
  1820. X    char_u *d;
  1821. X    int c;
  1822. X{
  1823. X    *d = c;
  1824. X
  1825. X    return (fptr)do_Copy;
  1826. X}
  1827. X
  1828. X    static fptr
  1829. Xdo_upper(d, c)
  1830. X    char_u *d;
  1831. X    int c;
  1832. X{
  1833. X    *d = TO_UPPER(c);
  1834. X
  1835. X    return (fptr)do_Copy;
  1836. X}
  1837. X
  1838. X    static fptr
  1839. Xdo_Upper(d, c)
  1840. X    char_u *d;
  1841. X    int c;
  1842. X{
  1843. X    *d = TO_UPPER(c);
  1844. X
  1845. X    return (fptr)do_Upper;
  1846. X}
  1847. X
  1848. X    static fptr
  1849. Xdo_lower(d, c)
  1850. X    char_u *d;
  1851. X    int c;
  1852. X{
  1853. X    *d = TO_LOWER(c);
  1854. X
  1855. X    return (fptr)do_Copy;
  1856. X}
  1857. X
  1858. X    static fptr
  1859. Xdo_Lower(d, c)
  1860. X    char_u *d;
  1861. X    int c;
  1862. X{
  1863. X    *d = TO_LOWER(c);
  1864. X
  1865. X    return (fptr)do_Lower;
  1866. X}
  1867. X
  1868. X    static fptr
  1869. Xstrnfcpy(f, d, s, n)
  1870. X    fptr f;
  1871. X    char_u *d;
  1872. X    char_u *s;
  1873. X    int n;
  1874. X{
  1875. X    while (n-- > 0) {
  1876. X        f = (fptr)(f(d, *s));        /* Turbo C complains without the typecast */
  1877. X        if (!*s++)
  1878. X            break;
  1879. X        d++;
  1880. X    }
  1881. X
  1882. X    return f;
  1883. X}
  1884. X#endif
  1885. X
  1886. X/*
  1887. X * regtilde: replace tildes in the pattern by the old pattern
  1888. X *
  1889. X * Short explanation of the tilde: it stands for the previous replacement
  1890. X * pattern. If that previous pattern also contains a ~ we should go back
  1891. X * a step further... but we insert the previous pattern into the current one
  1892. X * and remember that.
  1893. X * This still does not handle the case where "magic" changes. TODO?
  1894. X *
  1895. X * New solution: The tilde's are parsed once before the first call to regsub().
  1896. X * In the old solution (tilde handled in regsub()) is was possible to get an
  1897. X * endless loop.
  1898. X */
  1899. X    char_u *
  1900. Xregtilde(source, magic)
  1901. X    char_u    *source;
  1902. X    int        magic;
  1903. X{
  1904. X    char_u    *newsub = NULL;
  1905. X    char_u    *tmpsub;
  1906. X    char_u    *p;
  1907. X    int        len;
  1908. X    int        prevlen;
  1909. X
  1910. X    for (p = source; *p; ++p)
  1911. X    {
  1912. X        if ((*p == '~' && magic) || (*p == '\\' && *(p + 1) == '~' && !magic))
  1913. X        {
  1914. X            if (reg_prev_sub)
  1915. X            {
  1916. X                    /* length = len(current) - 1 + len(previous) + 1 */
  1917. X                prevlen = STRLEN(reg_prev_sub);
  1918. X                tmpsub = alloc((unsigned)(STRLEN(source) + prevlen));
  1919. X                if (tmpsub)
  1920. X                {
  1921. X                        /* copy prefix */
  1922. X                    len = (int)(p - source);    /* not including ~ */
  1923. X                    STRNCPY(tmpsub, source, (size_t)len);
  1924. X                        /* interpretate tilde */
  1925. X                    STRCPY(tmpsub + len, reg_prev_sub);
  1926. X                        /* copy postfix */
  1927. X                    if (!magic)
  1928. X                        ++p;                    /* back off \ */
  1929. X                    STRCAT(tmpsub + len, p + 1);
  1930. X
  1931. X                    free(newsub);
  1932. X                    newsub = tmpsub;
  1933. X                    p = newsub + len + prevlen;
  1934. X                }
  1935. X            }
  1936. X            else if (magic)
  1937. X                STRCPY(p, p + 1);                /* remove '~' */
  1938. X            else
  1939. X                STRCPY(p, p + 2);                /* remove '\~' */
  1940. X        }
  1941. X        else if (*p == '\\' && p[1])            /* skip escaped characters */
  1942. X            ++p;
  1943. X    }
  1944. X
  1945. X    free(reg_prev_sub);
  1946. X    if (newsub)
  1947. X    {
  1948. X        source = newsub;
  1949. X        reg_prev_sub = newsub;
  1950. X    }
  1951. X    else
  1952. X        reg_prev_sub = strsave(source);
  1953. X    return source;
  1954. X}
  1955. X
  1956. X/*
  1957. X - regsub - perform substitutions after a regexp match
  1958. X *
  1959. X * Returns the size of the replacement, including terminating \0.
  1960. X */
  1961. X    int
  1962. Xregsub(prog, source, dest, copy, magic)
  1963. X    regexp           *prog;
  1964. X    char_u           *source;
  1965. X    char_u           *dest;
  1966. X    int             copy;
  1967. X    int             magic;
  1968. X{
  1969. X    register char_u  *src;
  1970. X    register char_u  *dst;
  1971. X    register int    c;
  1972. X    register int    no;
  1973. X    register int    len;
  1974. X#ifdef CASECONVERT
  1975. X    fptr            func = (fptr)do_Copy;
  1976. X#endif
  1977. X
  1978. X    if (prog == NULL || source == NULL || dest == NULL)
  1979. X    {
  1980. X        emsg(e_null);
  1981. X        return 0;
  1982. X    }
  1983. X    if (UCHARAT(prog->program) != MAGIC)
  1984. X    {
  1985. X        emsg(e_re_corr);
  1986. X        return 0;
  1987. X    }
  1988. X    src = source;
  1989. X    dst = dest;
  1990. X
  1991. X    while ((c = *src++) != '\0')
  1992. X    {
  1993. X        no = -1;
  1994. X        if (c == '&' && magic)
  1995. X            no = 0;
  1996. X        else if (c == '\\' && *src != NUL)
  1997. X        {
  1998. X            if (*src == '&' && !magic)
  1999. X            {
  2000. X                ++src;
  2001. X                no = 0;
  2002. X            }
  2003. X            else if ('0' <= *src && *src <= '9')
  2004. X            {
  2005. X                no = *src++ - '0';
  2006. X            }
  2007. X#ifdef CASECONVERT
  2008. X            else if (strchr("uUlLeE", *src))
  2009. X            {
  2010. X                switch (*src++)
  2011. X                {
  2012. X                case 'u':    func = (fptr)do_upper;
  2013. X                            continue;
  2014. X                case 'U':    func = (fptr)do_Upper;
  2015. X                            continue;
  2016. X                case 'l':    func = (fptr)do_lower;
  2017. X                            continue;
  2018. X                case 'L':    func = (fptr)do_Lower;
  2019. X                            continue;
  2020. X                case 'e':
  2021. X                case 'E':    func = (fptr)do_Copy;
  2022. X                            continue;
  2023. X                }
  2024. X            }
  2025. X#endif
  2026. X        }
  2027. X        if (no < 0)           /* Ordinary character. */
  2028. X        {
  2029. X            if (c == '\\' && *src != NUL)
  2030. X                c = *src++;
  2031. X            if (copy)
  2032. X            {
  2033. X#ifdef CASECONVERT
  2034. X                func = (fptr)(func(dst, c));
  2035. X                            /* Turbo C complains without the typecast */
  2036. X#else
  2037. X                *dst = c;
  2038. X#endif
  2039. X            }
  2040. X            dst++;
  2041. X        }
  2042. X        else if (prog->startp[no] != NULL && prog->endp[no] != NULL)
  2043. X        {
  2044. X            len = (int)(prog->endp[no] - prog->startp[no]);
  2045. X            if (copy)
  2046. X            {
  2047. X#ifdef CASECONVERT
  2048. X                func = strnfcpy(func, dst, prog->startp[no], len);
  2049. X#else
  2050. X                (void) STRNCPY(dst, prog->startp[no], len);
  2051. X#endif
  2052. X            }
  2053. X            dst += len;
  2054. X            if (copy && len != 0 && *(dst - 1) == '\0') { /* strncpy hit NUL. */
  2055. X                emsg(e_re_damg);
  2056. X                goto exit;
  2057. X            }
  2058. X        }
  2059. X    }
  2060. X    if (copy)
  2061. X        *dst = '\0';
  2062. X
  2063. Xexit:
  2064. X    return (int)((dst - dest) + 1);
  2065. X}
  2066. END_OF_FILE
  2067.   if test 7512 -ne `wc -c <'vim/src/regsub.c'`; then
  2068.     echo shar: \"'vim/src/regsub.c'\" unpacked with wrong size!
  2069.   fi
  2070.   # end of 'vim/src/regsub.c'
  2071. fi
  2072. if test -f 'vim/src/structs.h' -a "${1}" != "-c" ; then 
  2073.   echo shar: Will not clobber existing file \"'vim/src/structs.h'\"
  2074. else
  2075.   echo shar: Extracting \"'vim/src/structs.h'\" \(14475 characters\)
  2076.   sed "s/^X//" >'vim/src/structs.h' <<'END_OF_FILE'
  2077. X/* vi:ts=4:sw=4
  2078. X *
  2079. X * VIM - Vi IMproved        by Bram Moolenaar
  2080. X *
  2081. X * Read the file "credits.txt" for a list of people who contributed.
  2082. X * Read the file "uganda.txt" for copying and usage conditions.
  2083. X */
  2084. X
  2085. X/*
  2086. X * This file contains various definitions of structures that are used by Vim
  2087. X */
  2088. X
  2089. X/*
  2090. X * file position
  2091. X */
  2092. X
  2093. Xtypedef struct fpos        FPOS;
  2094. X/*
  2095. X * there is something wrong in the SAS compiler that makes typedefs not
  2096. X * valid in include files
  2097. X */
  2098. X#ifdef SASC
  2099. Xtypedef long            linenr_t;
  2100. Xtypedef unsigned        colnr_t;
  2101. Xtypedef unsigned short    short_u;
  2102. X#endif
  2103. X
  2104. Xstruct fpos
  2105. X{
  2106. X    linenr_t        lnum;            /* line number */
  2107. X    colnr_t         col;            /* column number */
  2108. X};
  2109. X
  2110. X/*
  2111. X * marks: positions in a file
  2112. X * (a normal mark is a lnum/col pair, the same as a file position)
  2113. X */
  2114. X
  2115. X#define NMARKS            26            /* max. # of named marks */
  2116. X#define JUMPLISTSIZE    30            /* max. # of marks in jump list */
  2117. X#define TAGSTACKSIZE    20            /* max. # of tags in tag stack */
  2118. X
  2119. Xstruct filemark
  2120. X{
  2121. X    FPOS            mark;            /* cursor position */
  2122. X    int                fnum;            /* file number */
  2123. X};
  2124. X
  2125. X/*
  2126. X * the taggy struct is used to store the information about a :tag command:
  2127. X *    the tag name and the cursor position BEFORE the :tag command
  2128. X */
  2129. Xstruct taggy
  2130. X{
  2131. X    char_u            *tagname;            /* tag name */
  2132. X    struct filemark fmark;                /* cursor position */
  2133. X};
  2134. X
  2135. X/*
  2136. X * line number list
  2137. X */
  2138. X
  2139. X/*
  2140. X * Each window can have a different line number associated with a buffer.
  2141. X * The window-pointer/line-number pairs are kept in the line number list.
  2142. X * The list of line numbers is kept in most-recently-used order.
  2143. X */
  2144. X
  2145. Xtypedef struct window        WIN;
  2146. Xtypedef struct winlnum        WINLNUM;
  2147. X
  2148. Xstruct winlnum
  2149. X{
  2150. X    WINLNUM        *wl_next;            /* next entry or NULL for last entry */
  2151. X    WINLNUM        *wl_prev;            /* previous entry or NULL for first entry */
  2152. X    WIN            *wl_win;            /* pointer to window that did set wl_lnum */
  2153. X    linenr_t     wl_lnum;            /* last cursor line in the file */
  2154. X};
  2155. X
  2156. X/*
  2157. X * stuctures used for undo
  2158. X */
  2159. X
  2160. Xstruct u_entry
  2161. X{
  2162. X    struct u_entry    *ue_next;    /* pointer to next entry in list */
  2163. X    linenr_t        ue_top;        /* number of line above undo block */
  2164. X    linenr_t        ue_bot;        /* number of line below undo block */
  2165. X    linenr_t        ue_lcount;    /* linecount when u_save called */
  2166. X    char_u            **ue_array;    /* array of lines in undo block */
  2167. X    long            ue_size;    /* number of lines in ue_array */
  2168. X};
  2169. X
  2170. Xstruct u_header
  2171. X{
  2172. X    struct u_header    *uh_next;    /* pointer to next header in list */
  2173. X    struct u_header    *uh_prev;    /* pointer to previous header in list */
  2174. X    struct u_entry    *uh_entry;    /* pointer to first entry */
  2175. X    FPOS             uh_cursor;    /* cursor position before saving */
  2176. X    int                 uh_changed;/* b_changed flag before undo/after redo */
  2177. X    FPOS             uh_namedm[NMARKS];    /* marks before undo/after redo */
  2178. X};
  2179. X
  2180. X/*
  2181. X * stuctures used in undo.c
  2182. X */
  2183. X#ifdef UNIX
  2184. X# define ALIGN_LONG        /* longword alignment and use filler byte */
  2185. X# define ALIGN_SIZE (sizeof(long))
  2186. X#else
  2187. X# define ALIGN_SIZE (sizeof(short))
  2188. X#endif
  2189. X
  2190. X#define ALIGN_MASK (ALIGN_SIZE - 1)
  2191. X
  2192. Xtypedef struct m_info info_t;
  2193. X
  2194. X/*
  2195. X * stucture used to link chunks in one of the free chunk lists.
  2196. X */
  2197. Xstruct m_info
  2198. X{
  2199. X#ifdef ALIGN_LONG
  2200. X    long_u     m_size;    /* size of the chunk (including m_info) */
  2201. X#else
  2202. X    short_u  m_size;    /* size of the chunk (including m_info) */
  2203. X#endif
  2204. X    info_t    *m_next;    /* pointer to next free chunk in the list */
  2205. X};
  2206. X
  2207. X/*
  2208. X * structure used to link blocks in the list of allocated blocks.
  2209. X */
  2210. Xstruct m_block
  2211. X{
  2212. X    struct m_block    *mb_next;    /* pointer to next allocated block */
  2213. X    info_t            mb_info;    /* head of free chuck list for this block */
  2214. X};
  2215. X
  2216. X/*
  2217. X * things used in memfile.c
  2218. X */
  2219. X
  2220. Xtypedef struct block_hdr    BHDR;
  2221. Xtypedef struct memfile        MEMFILE;
  2222. Xtypedef long                blocknr_t;
  2223. X
  2224. X/*
  2225. X * for each (previously) used block in the memfile there is one block header.
  2226. X * 
  2227. X * The block may be linked in the used list OR in the free list.
  2228. X * The used blocks are also kept in hash lists.
  2229. X *
  2230. X * The used list is a doubly linked list, most recently used block first.
  2231. X *         The blocks in the used list have a block of memory allocated.
  2232. X *        mf_used_count is the number of pages in the used list.
  2233. X * The hash lists are used to quickly find a block in the used list.
  2234. X * The free list is a single linked list, not sorted.
  2235. X *        The blocks in the free list have no block of memory allocated and
  2236. X *        the contents of the block in the file (if any) is irrelevant.
  2237. X */
  2238. X
  2239. Xstruct block_hdr
  2240. X{
  2241. X    BHDR        *bh_next;            /* next block_hdr in free or used list */
  2242. X    BHDR        *bh_prev;            /* previous block_hdr in used list */
  2243. X    BHDR        *bh_hash_next;        /* next block_hdr in hash list */
  2244. X    BHDR        *bh_hash_prev;        /* previous block_hdr in hash list */
  2245. X    blocknr_t    bh_bnum;                /* block number */
  2246. X    char_u        *bh_data;            /* pointer to memory (for used block) */
  2247. X    int            bh_page_count;        /* number of pages in this block */
  2248. X
  2249. X#define BH_DIRTY    1
  2250. X#define BH_LOCKED    2
  2251. X    char        bh_flags;            /* BH_DIRTY or BH_LOCKED */
  2252. X};
  2253. X
  2254. X/*
  2255. X * when a block with a negative number is flushed to the file, it gets
  2256. X * a positive number. Because the reference to the block is still the negative
  2257. X * number, we remember the translation to the new positive number in the
  2258. X * double linked trans lists. The structure is the same as the hash lists.
  2259. X */
  2260. Xtypedef struct nr_trans NR_TRANS;
  2261. X
  2262. Xstruct nr_trans
  2263. X{
  2264. X    NR_TRANS    *nt_next;            /* next nr_trans in hash list */
  2265. X    NR_TRANS    *nt_prev;            /* previous nr_trans in hash list */
  2266. X    blocknr_t    nt_old_bnum;            /* old, negative, number */
  2267. X    blocknr_t    nt_new_bnum;            /* new, positive, number */
  2268. X};
  2269. X
  2270. X/*
  2271. X * Simplistic hashing scheme to quickly locate the blocks in the used list.
  2272. X * 64 blocks are found directly (64 * 4K = 256K, most files are smaller).
  2273. X */
  2274. X#define MEMHASHSIZE        64
  2275. X#define MEMHASH(nr)        ((nr) & (MEMHASHSIZE - 1))
  2276. X
  2277. Xstruct memfile
  2278. X{
  2279. X    char_u        *mf_fname;            /* name of the file */
  2280. X    char_u        *mf_xfname;            /* idem, full path */
  2281. X    int            mf_fd;                /* file descriptor */
  2282. X    BHDR        *mf_free_first;        /* first block_hdr in free list */
  2283. X    BHDR        *mf_used_first;        /* mru block_hdr in used list */
  2284. X    BHDR        *mf_used_last;        /* lru block_hdr in used list */
  2285. X    unsigned    mf_used_count;        /* number of pages in used list */
  2286. X    unsigned    mf_used_count_max;    /* maximum number of pages in memory */
  2287. X    BHDR        *mf_hash[MEMHASHSIZE];    /* array of hash lists */
  2288. X    NR_TRANS    *mf_trans[MEMHASHSIZE];    /* array of trans lists */
  2289. X    blocknr_t    mf_blocknr_max;        /* highest positive block number + 1*/
  2290. X    blocknr_t    mf_blocknr_min;        /* lowest negative block number - 1 */
  2291. X    blocknr_t    mf_neg_count;        /* number of negative blocks numbers */
  2292. X    blocknr_t    mf_infile_count;    /* number of pages in the file */
  2293. X    unsigned    mf_page_size;        /* number of bytes in a page */
  2294. X    int            mf_dirty;            /* Set to TRUE if there are dirty blocks */
  2295. X};
  2296. X
  2297. X/*
  2298. X * things used in memline.c
  2299. X */
  2300. Xtypedef struct info_pointer        IPTR;        /* block/index pair */
  2301. X
  2302. X/*
  2303. X * When searching for a specific line, we remember what blocks in the tree
  2304. X * are the branches leading to that block. This is stored in ml_stack.
  2305. X * Each entry is a pointer to info in a block (may be data block or pointer block)
  2306. X */
  2307. Xstruct info_pointer
  2308. X{
  2309. X    blocknr_t    ip_bnum;        /* block number */
  2310. X    linenr_t    ip_low;            /* lowest lnum in this block */
  2311. X    linenr_t    ip_high;        /* highest lnum in this block */
  2312. X    int            ip_index;        /* index for block with current lnum */
  2313. X};
  2314. X
  2315. Xtypedef struct memline MEMLINE;
  2316. X
  2317. X/*
  2318. X * the memline structure holds all the information about a memline
  2319. X */
  2320. Xstruct memline
  2321. X{
  2322. X    linenr_t    ml_line_count;    /* number of lines in the buffer */
  2323. X
  2324. X    MEMFILE        *ml_mfp;        /* pointer to associated memfile */
  2325. X
  2326. X#define ML_EMPTY        1        /* empty buffer (one empty line */
  2327. X#define ML_LINE_DIRTY    2        /* cached line was changed and allocated */
  2328. X#define ML_LOCKED_DIRTY    4        /* ml_locked was changed */
  2329. X#define ML_LOCKED_POS    8        /* ml_locked needs positive block number */
  2330. X    int            ml_flags;
  2331. X
  2332. X    IPTR        *ml_stack;        /* stack of pointer blocks (array of IPTRs) */
  2333. X    int            ml_stack_top;    /* current top if ml_stack */
  2334. X    int            ml_stack_size;    /* total number of entries in ml_stack */
  2335. X
  2336. X    linenr_t    ml_line_lnum;    /* line number of cached line, 0 if not valid */
  2337. X    char_u        *ml_line_ptr;    /* pointer to cached line */
  2338. X
  2339. X    BHDR        *ml_locked;        /* block used by last ml_get */
  2340. X    linenr_t    ml_locked_low;    /* first line in ml_locked */
  2341. X    linenr_t    ml_locked_high;    /* last line in ml_locked */
  2342. X    int            ml_locked_lineadd;    /* number of lines inserted in ml_locked */
  2343. X};
  2344. X
  2345. X/*
  2346. X * buffer: structure that holds information about one file
  2347. X *
  2348. X * Several windows can share a single Buffer
  2349. X * A buffer is unallocated if there is no memfile for it.
  2350. X * A buffer is new if the associated file has never been loaded yet.
  2351. X */
  2352. X
  2353. Xtypedef struct buffer BUF;
  2354. X
  2355. Xstruct buffer
  2356. X{
  2357. X    MEMLINE             b_ml;                /* associated memline (also contains
  2358. X                                         * line count) */
  2359. X
  2360. X    BUF                *b_next;            /* links in list of buffers */
  2361. X    BUF                *b_prev;
  2362. X
  2363. X    int                 b_changed;            /* Set to 1 if something in the file has
  2364. X                                          * been changed and not written out. */
  2365. X
  2366. X    int                 b_notedited;        /* Set to TRUE when file name is
  2367. X                                         * changed after starting to edit, 
  2368. X                                          * reset when file is written out. */
  2369. X
  2370. X    int              b_nwindows;        /* nr of windows open on this buffer */
  2371. X
  2372. X    int                 b_neverloaded;        /* file has never been loaded into
  2373. X                                         * buffer, many variables still need
  2374. X                                         * to be set */
  2375. X
  2376. X    /*
  2377. X     * b_filename has the full path of the file.
  2378. X     * b_sfilename is the name as the user typed it.
  2379. X     * b_xfilename is the same as b_sfilename, unless did_cd is set, then it
  2380. X     *               is the same as b_filename.
  2381. X     */
  2382. X    char_u            *b_filename;
  2383. X    char_u            *b_sfilename;
  2384. X    char_u            *b_xfilename;
  2385. X
  2386. X    int                 b_fnum;            /* file number for this file. */
  2387. X    WINLNUM            *b_winlnum;            /* list of last used lnum for
  2388. X                                         * each window */
  2389. X
  2390. X    long             b_mtime;            /* last change time of original file */
  2391. X
  2392. X    /*
  2393. X     * The following only used in mark.c.
  2394. X     */
  2395. X    FPOS               b_namedm[NMARKS];    /* current marks */
  2396. X
  2397. X    /*
  2398. X     * start and end of an operator, also used for '[ and ']
  2399. X     */
  2400. X    FPOS             b_startop;
  2401. X    FPOS             b_endop;
  2402. X
  2403. X    /*
  2404. X     * The following only used in undo.c.
  2405. X     */
  2406. X    struct u_header    *b_u_oldhead;        /* pointer to oldest header */
  2407. X    struct u_header    *b_u_newhead;        /* pointer to newest header */
  2408. X    struct u_header    *b_u_curhead;        /* pointer to current header */
  2409. X    int                 b_u_numhead;        /* current number of headers */
  2410. X    int                 b_u_synced;        /* entry lists are synced */
  2411. X
  2412. X    /*
  2413. X     * variables for "U" command in undo.c
  2414. X     */
  2415. X    char_u            *b_u_line_ptr;        /* saved line for "U" command */
  2416. X    linenr_t         b_u_line_lnum;        /* line number of line in u_line */
  2417. X    colnr_t             b_u_line_colnr;    /* optional column number */
  2418. X
  2419. X    /*
  2420. X     * The following only used in undo.c
  2421. X     */
  2422. X    struct m_block     b_block_head;        /* head of allocated memory block list */
  2423. X    info_t            *b_m_search;         /* pointer to chunk before previously
  2424. X                                            * allocated/freed chunk */
  2425. X    struct m_block    *b_mb_current;        /* block where m_search points in */
  2426. X
  2427. X    /*
  2428. X     * Variables "local" to a buffer.
  2429. X     * They are here because their value depends on the type of file
  2430. X     * or contents of the file being edited.
  2431. X     * The "save" options are for when the paste option is set.
  2432. X     */
  2433. X    int                 b_p_ai, b_p_si, b_p_ro;
  2434. X    int                 b_p_bin, b_p_eol, b_p_et, b_p_ml, b_p_sn, b_p_tx;
  2435. X    long             b_p_sw, b_p_ts, b_p_tw, b_p_wm;
  2436. X    int                 b_p_ai_save, b_p_si_save;
  2437. X    long             b_p_tw_save, b_p_wm_save;
  2438. X
  2439. X    char             b_did_warn;        /* Set to 1 if user has been warned on
  2440. X                                         * first change of a read-only file */
  2441. X
  2442. X#ifndef MSDOS
  2443. X    int                 b_shortname;        /* this file has an 8.3 filename */
  2444. X#endif
  2445. X};
  2446. X
  2447. X/*
  2448. X * Structure which contains all information that belongs to a window
  2449. X *
  2450. X * All row numbers are relative to the start of the window, except w_winpos.
  2451. X */
  2452. X
  2453. Xstruct window
  2454. X{
  2455. X    BUF            *w_buffer;             /* buffer we are a window into */
  2456. X
  2457. X    WIN            *w_prev;            /* link to previous window (above) */
  2458. X    WIN            *w_next;            /* link to next window (below) */
  2459. X
  2460. X    FPOS        w_cursor;            /* cursor's position in buffer */
  2461. X
  2462. X    /*
  2463. X     * These elements are related to the cursor's position in the window.
  2464. X     * This is related to character positions in the window, not in the file.
  2465. X     */
  2466. X    int            w_row, w_col;        /* cursor's position in window */
  2467. X
  2468. X    colnr_t        w_virtcol;            /* column number of the file's actual */
  2469. X                                    /* line, as opposed to the column */
  2470. X                                    /* number we're at on the screen. */
  2471. X                                    /* This makes a difference on lines */
  2472. X                                    /* which span more than one screen */
  2473. X                                    /* line. */
  2474. X
  2475. X    colnr_t        w_curswant;            /* The column we'd like to be at. */
  2476. X                                    /* This is used to try to stay in */
  2477. X                                    /* the same column through up/down */
  2478. X                                    /* cursor motions. */
  2479. X
  2480. X    int            w_set_curswant;        /* If set, then update w_curswant */
  2481. X                                    /* the next time through cursupdate() */
  2482. X                                    /* to the current virtual column */
  2483. X
  2484. X    linenr_t    w_topline;            /* number of the line at the top of
  2485. X                                     * the screen */
  2486. X    linenr_t    w_botline;            /* number of the line below the bottom
  2487. X                                     * of the screen */
  2488. X    int            w_empty_rows;        /* number of ~ rows in window */
  2489. X
  2490. X    int            w_winpos;            /* row of topline of window in screen */
  2491. X    int            w_height;            /* number of rows in window, excluding
  2492. X                                        status/command line */
  2493. X    int            w_status_height;    /* number of status lines (0 or 1) */
  2494. X
  2495. X    int            w_redr_status;        /* if TRUE status line must be redrawn */
  2496. X    int            w_redr_type;        /* type of redraw to be performed on win */
  2497. X
  2498. X    int            w_leftcol;            /* starting column of the screen */
  2499. X
  2500. X/*
  2501. X * The height of the lines currently in the window is remembered
  2502. X * to avoid recomputing it every time. The number of entries is w_nrows.
  2503. X */
  2504. X    int             w_lsize_valid;        /* nr. of valid LineSizes */
  2505. X    linenr_t     *w_lsize_lnum;        /* array of line numbers for w_lsize */
  2506. X    char_u          *w_lsize;            /* array of line heights */
  2507. X
  2508. X    int            w_alt_fnum;            /* alternate file (for # and CTRL-^) */
  2509. X
  2510. X    int            w_arg_idx;            /* current index in argument list */
  2511. X
  2512. X    /*
  2513. X     * Variables "local" to a window.
  2514. X     * They are here because they influence the layout of the window or
  2515. X     * depend on the window layout.
  2516. X     */
  2517. X    int            w_p_list,
  2518. X                w_p_nu,
  2519. X                w_p_wrap;
  2520. X    long        w_p_scroll;
  2521. X
  2522. X    /*
  2523. X     * The w_prev_pcmark field is used to check whether we really did jump to
  2524. X     * a new line after setting the w_pcmark.  If not, then we revert to
  2525. X     * using the previous w_pcmark.
  2526. X     */
  2527. X    FPOS        w_pcmark;            /* previous context mark */
  2528. X    FPOS        w_prev_pcmark;        /* previous w_pcmark */
  2529. X
  2530. X    /*
  2531. X     * the jumplist contains old cursor positions
  2532. X     */
  2533. X    struct filemark w_jumplist[JUMPLISTSIZE];
  2534. X    int             w_jumplistlen;    /* number of active entries */
  2535. X    int                w_jumplistidx;    /* current position */
  2536. X
  2537. X    /*
  2538. X     * the tagstack grows from 0 upwards:
  2539. X     * entry 0: older
  2540. X     * entry 1: newer
  2541. X     * entry 2: newest
  2542. X     */
  2543. X    struct taggy    w_tagstack[TAGSTACKSIZE];    /* the tag stack */
  2544. X    int                w_tagstackidx;                /* index just below active entry */
  2545. X    int                w_tagstacklen;                /* number of tags on the stack */
  2546. X
  2547. X};
  2548. END_OF_FILE
  2549.   if test 14475 -ne `wc -c <'vim/src/structs.h'`; then
  2550.     echo shar: \"'vim/src/structs.h'\" unpacked with wrong size!
  2551.   fi
  2552.   # end of 'vim/src/structs.h'
  2553. fi
  2554. echo shar: End of archive 21 \(of 26\).
  2555. cp /dev/null ark21isdone
  2556. MISSING=""
  2557. 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 23 24 25 26 ; do
  2558.     if test ! -f ark${I}isdone ; then
  2559.     MISSING="${MISSING} ${I}"
  2560.     fi
  2561. done
  2562. if test "${MISSING}" = "" ; then
  2563.     echo You have unpacked all 26 archives.
  2564.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2565. else
  2566.     echo You still must unpack the following archives:
  2567.     echo "        " ${MISSING}
  2568. fi
  2569. exit 0
  2570. exit 0 # Just in case...
  2571.