home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume37 / vim / part17 < prev    next >
Encoding:
Text File  |  1993-04-23  |  32.9 KB  |  1,485 lines

  1. Newsgroups: comp.sources.misc
  2. From: mool@oce.nl (Bram Moolenaar)
  3. Subject: v37i017:  vim - Vi IMitation editor v1.27, Part17/24
  4. Message-ID: <1993Apr25.013614.22697@sparky.imd.sterling.com>
  5. X-Md4-Signature: 0044c144201d429f4b7d7b5dce8628e3
  6. Date: Sun, 25 Apr 1993 01:36:14 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: mool@oce.nl (Bram Moolenaar)
  10. Posting-number: Volume 37, Issue 17
  11. Archive-name: vim/part17
  12. Environment: UNIX, AMIGA, MS-DOS
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 17 (of 23)."
  21. # Contents:  vim/src/amiga.c
  22. # Wrapped by mool@oce-rd2 on Mon Apr 19 15:50:12 1993
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'vim/src/amiga.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'vim/src/amiga.c'\"
  26. else
  27. echo shar: Extracting \"'vim/src/amiga.c'\" \(29917 characters\)
  28. sed "s/^X//" >'vim/src/amiga.c' <<'END_OF_FILE'
  29. X/* vi:ts=4:sw=4
  30. X *
  31. X * VIM - Vi IMitation
  32. X *
  33. X * Code Contributions By:    Bram Moolenaar            mool@oce.nl
  34. X *                            Tim Thompson            twitch!tjt
  35. X *                            Tony Andrews            onecom!wldrdg!tony 
  36. X *                            G. R. (Fred) Walter        watmath!watcgl!grwalter 
  37. X */
  38. X
  39. X/*
  40. X * amiga.c
  41. X *
  42. X * Amiga system-dependent routines.
  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#include <fcntl.h>
  51. X
  52. X#undef TRUE             /* will be redefined by exec/types.h */
  53. X#undef FALSE
  54. X
  55. X#ifndef LATTICE
  56. X#  include <exec/types.h>
  57. X#  include <exec/exec.h>
  58. X#  include <libraries/dos.h>
  59. X#  include <libraries/dosextens.h>
  60. X#  include <intuition/intuition.h>
  61. X#else
  62. X#  include <proto/dos.h>
  63. X#  include <libraries/dosextens.h>
  64. X#  include <proto/intuition.h>
  65. X#  include <proto/exec.h>
  66. X#endif
  67. X
  68. X#ifndef NO_ARP
  69. X#include <libraries/arpbase.h>        /* for arp.library */
  70. X#endif
  71. X#include <dos/dostags.h>            /* for 2.0 functions */
  72. X#include <dos/dosasl.h>
  73. X
  74. X#if defined(LATTICE) && !defined(SASC) && !defined(NO_ARP)
  75. X# include <libraries/arp_pragmas.h>
  76. X#endif
  77. X
  78. X/*
  79. X * At this point TRUE and FALSE are defined as 1L and 0L, but we want 1 and 0.
  80. X */
  81. X#undef TRUE
  82. X#define TRUE (1)
  83. X#undef FALSE
  84. X#define FALSE (0)
  85. X
  86. X#ifndef AZTEC_C
  87. Xstatic long dos_packet __ARGS((struct MsgPort *, long, long));
  88. X#endif
  89. Xstatic int lock2name __ARGS((BPTR lock, char *buf, long    len));
  90. Xstatic struct FileInfoBlock *get_fib __ARGS((char *));
  91. X
  92. Xstatic BPTR                raw_in = (BPTR)NULL;
  93. Xstatic BPTR                raw_out = (BPTR)NULL;
  94. Xstatic int                close_win = FALSE;    /* set if Vim opened the window */
  95. X
  96. Xstruct IntuitionBase    *IntuitionBase = NULL;
  97. X#ifndef NO_ARP
  98. Xstruct ArpBase            *ArpBase = NULL;
  99. X#endif
  100. X
  101. Xstatic struct Window    *wb_window;
  102. Xstatic char                *oldwindowtitle = NULL;
  103. Xstatic int                quickfix = FALSE;
  104. X
  105. X#ifndef NO_ARP
  106. Xint                        dos2 = FALSE;        /* Amiga DOS 2.0x or higher */
  107. X#endif
  108. Xint                        size_set = FALSE;    /* set to TRUE if window size was set */
  109. X
  110. X    void
  111. Xwin_resize_on()
  112. X{
  113. X    outstrn("\033[12{");
  114. X}
  115. X
  116. X    void
  117. Xwin_resize_off()
  118. X{
  119. X    outstrn("\033[12}");
  120. X}
  121. X
  122. X/*
  123. X * the number of calls to Write is reduced by using the buffer "outbuf"
  124. X */
  125. X#define BSIZE    2048
  126. Xstatic u_char            outbuf[BSIZE];
  127. Xstatic int                bpos = 0;        /* number of chars in outbuf */
  128. X
  129. X/*
  130. X * flushbuf(): flush the output buffer
  131. X */
  132. X    void
  133. Xflushbuf()
  134. X{
  135. X    if (bpos != 0)
  136. X    {
  137. X        Write(raw_out, (char *)outbuf, (long)bpos);
  138. X        bpos = 0;
  139. X    }
  140. X}
  141. X
  142. X/*
  143. X * outchar(c): put a character into the output buffer.
  144. X *               Flush it if it becomes full.
  145. X */
  146. X    void
  147. Xoutchar(c)
  148. X    unsigned    c;
  149. X{
  150. X    outbuf[bpos] = c;
  151. X    ++bpos;
  152. X    if (bpos >= BSIZE)
  153. X        flushbuf();
  154. X}
  155. X
  156. X/*
  157. X * GetChars(): low level input funcion.
  158. X * Get a characters from the keyboard.
  159. X * If type == T_PEEK do not wait for characters.
  160. X * If type == T_WAIT wait a short time for characters.
  161. X * If type == T_BLOCK wait for characters.
  162. X */
  163. X    int
  164. XGetChars(buf, maxlen, type)
  165. X    char    *buf;
  166. X    int        maxlen;
  167. X    int        type;
  168. X{
  169. X    int        len;
  170. X    long    time = 1000000L;    /* one second */
  171. X
  172. X    switch (type)
  173. X    {
  174. X    case T_PEEK:
  175. X        time = 100L;
  176. X    case T_WAIT:
  177. X        if (WaitForChar(raw_in, time) == 0)    /* no character available */
  178. X            return 0;
  179. X        break;
  180. X
  181. X    case T_BLOCK:
  182. X    /*
  183. X     * If there is no character available within 2 seconds (default)
  184. X     * write the autoscript file to disk
  185. X     */
  186. X        if (WaitForChar(raw_in, p_ut * 1000L) == 0)
  187. X            updatescript(0);
  188. X    }
  189. X
  190. X    for (;;)        /* repeat until we got a character */
  191. X    {
  192. X        len = Read(raw_in, buf, (long)maxlen);
  193. X        if (len > 0)
  194. X            return len;
  195. X    }
  196. X}
  197. X
  198. X    void
  199. Xsleep(n)
  200. X    int             n;
  201. X{
  202. X#ifndef LATTICE            /* SAS declares void Delay(UNLONG) */
  203. X    void            Delay __ARGS((long));
  204. X#endif
  205. X
  206. X    if (n > 0)
  207. X        Delay((long)(50L * n));
  208. X}
  209. X
  210. X    void
  211. Xvim_delay()
  212. X{
  213. X    Delay(25L);
  214. X}
  215. X
  216. X/*
  217. X * We have no job control, fake it by starting a new shell.
  218. X */
  219. Xvoid
  220. Xmch_suspend()
  221. X{
  222. X    outstr("new shell started\n");
  223. X    stoptermcap();
  224. X    call_shell(NULL, 0);
  225. X    starttermcap();
  226. X}
  227. X
  228. X#define DOS_LIBRARY     ((UBYTE *) "dos.library")
  229. X
  230. X    void
  231. Xmch_windinit()
  232. X{
  233. X    static char        intlibname[] = "intuition.library";
  234. X
  235. X#ifdef AZTEC_C
  236. X    Enable_Abort = 0;            /* disallow vim to be aborted */
  237. X#endif
  238. X    Columns = 80;
  239. X    Rows = 24;
  240. X
  241. X    /*
  242. X     * Set input and output channels, unless we have opened our own window
  243. X     */
  244. X    if (raw_in == (BPTR)NULL)
  245. X    {
  246. X        raw_in = Input();
  247. X        raw_out = Output();
  248. X    }
  249. X
  250. X    flushbuf();
  251. X
  252. X    wb_window = NULL;
  253. X    if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)intlibname, 0L)) == NULL)
  254. X    {
  255. X        fprintf(stderr, "cannot open %s!?\n", intlibname);
  256. X        mch_windexit(3);
  257. X    }
  258. X    mch_get_winsize();
  259. X}
  260. X
  261. X#include <workbench/startup.h>
  262. X
  263. X/*
  264. X * Check_win checks whether we have an interactive window.
  265. X * If not, a new window is opened with the newcli command.
  266. X * If we would open a window ourselves, the :sh and :! commands would not
  267. X * work properly (Why? probably because we are then running in a background CLI).
  268. X * This also is the best way to assure proper working in a next Workbench release.
  269. X *
  270. X * For the -e option (quickfix mode) we open our own window and disable :sh.
  271. X * Otherwise the compiler would never know when editing is finished.
  272. X */
  273. X#define BUF2SIZE 320        /* lenght of buffer for argument with complete path */
  274. X
  275. X    void
  276. Xcheck_win(argc, argv)
  277. X    int argc;
  278. X    char **argv;
  279. X{
  280. X    int                i;
  281. X    BPTR            nilfh, fh;
  282. X    char            buf1[20];
  283. X    char            buf2[BUF2SIZE];
  284. X    static char        *(constrings[3]) = {"con:0/0/662/210/",
  285. X                                      "con:0/0/640/200/",
  286. X                                      "con:0/0/320/200/"};
  287. X    static char        winerr[] = "VIM: Can't open window!\n";
  288. X    struct WBArg    *argp;
  289. X    int                ac;
  290. X    char            *av;
  291. X    char            *device = NULL;
  292. X    int                exitval = 4;
  293. X    struct Library    *DosBase;
  294. X
  295. X/*
  296. X * check if we are running under DOS 2.0x or higher
  297. X */
  298. X    if (DosBase = OpenLibrary(DOS_LIBRARY, 37L))
  299. X    {
  300. X        CloseLibrary(DosBase);
  301. X#ifndef NO_ARP
  302. X        dos2 = TRUE;
  303. X#endif
  304. X    }
  305. X    else            /* without arp functions we NEED 2.0 */
  306. X    {
  307. X#ifdef NO_ARP
  308. X        fprintf(stderr, "Need Amigados version 2.04 or later\n");
  309. X        exit(3);
  310. X#else
  311. X                    /* need arp functions for dos 1.x */
  312. X        if (!(ArpBase = (struct ArpBase *) OpenLibrary((UBYTE *)ArpName, ArpVersion)))
  313. X        {
  314. X            fprintf(stderr, "Need %s version %ld\n", ArpName, ArpVersion);
  315. X            exit(3);
  316. X        }
  317. X#endif
  318. X    }
  319. X
  320. X/*
  321. X * scan argv[] for the '-e' and '-d' arguments
  322. X */
  323. X    for (i = 1; i < argc; ++i)
  324. X        if (argv[i][0] == '-')
  325. X        {
  326. X            switch (argv[i][1])
  327. X            {
  328. X            case 'e':
  329. X                quickfix = TRUE;
  330. X                break;
  331. X
  332. X            case 'd':
  333. X                if (i < argc - 1)
  334. X                    device = argv[i + 1];
  335. X                break;
  336. X            }
  337. X        }
  338. X
  339. X/*
  340. X * If we were not started from workbench, do not have a '-d' argument and
  341. X * we have been started with an interactive window, use that window.
  342. X */
  343. X    if (argc != 0 && device == NULL &&
  344. X                IsInteractive(Input()) && IsInteractive(Output()))
  345. X        return;
  346. X
  347. X/*
  348. X * If we are in quickfix mode, we open our own window. We can't use the
  349. X * newcli trick below, because the compiler would not know when we are finished.
  350. X */
  351. X    if (quickfix)
  352. X    {
  353. X        /*
  354. X         * Try to open a window. First try the specified device.
  355. X         * Then try a 24 line 80 column window.
  356. X         * If that fails, try two smaller ones.
  357. X         */
  358. X        for (i = -1; i < 3; ++i)
  359. X        {
  360. X            if (i >= 0)
  361. X                device = constrings[i];
  362. X            if (device && (raw_in = Open((UBYTE *)device, (long)MODE_NEWFILE)) != (BPTR)NULL)
  363. X                break;
  364. X        }
  365. X        if (raw_in == (BPTR)NULL)        /* all three failed */
  366. X        {
  367. X            fprintf(stderr, winerr);
  368. X            goto exit;
  369. X        }
  370. X        raw_out = raw_in;
  371. X        close_win = TRUE;
  372. X        return;
  373. X    }
  374. X
  375. X    if ((nilfh = Open((UBYTE *)"NIL:", (long)MODE_NEWFILE)) == (BPTR)NULL)
  376. X    {
  377. X        fprintf(stderr, "Cannot open NIL:\n");
  378. X        goto exit;
  379. X    }
  380. X
  381. X    /*
  382. X     * make a unique name for the temp file (which we will not delete!)
  383. X     */
  384. X    sprintf(buf1, "t:nc%ld", buf1);    /* nobody else is using our stack */
  385. X    if ((fh = Open((UBYTE *)buf1, (long)MODE_NEWFILE)) == (BPTR)NULL)
  386. X    {
  387. X        fprintf(stderr, "Cannot create %s\n", buf1);
  388. X        goto exit;
  389. X    }
  390. X    /*
  391. X     * Write the command into the file, put quotes around the arguments that
  392. X     * have a space in them.
  393. X     */
  394. X    if (argc == 0)        /* run from workbench */
  395. X        ac = ((struct WBStartup *)argv)->sm_NumArgs;
  396. X    else
  397. X        ac = argc;
  398. X    for (i = 0; i < ac; ++i)
  399. X    {
  400. X        if (argc == 0)
  401. X        {
  402. X            *buf2 = NUL;
  403. X            argp = &(((struct WBStartup *)argv)->sm_ArgList[i]);
  404. X            if (argp->wa_Lock)
  405. X                lock2name(argp->wa_Lock, buf2, (long)(BUF2SIZE - 1));
  406. X#ifndef NO_ARP
  407. X            if (dos2)        /* use 2.0 function */
  408. X#endif
  409. X                AddPart((UBYTE *)buf2, (UBYTE *)argp->wa_Name, (long)(BUF2SIZE - 1));
  410. X#ifndef NO_ARP
  411. X            else            /* use arp function */
  412. X                TackOn(buf2, argp->wa_Name);
  413. X#endif
  414. X            av = buf2;
  415. X        }
  416. X        else
  417. X            av = argv[i];
  418. X
  419. X        if (av[0] == '-' && av[1] == 'd')        /* skip '-d' option */
  420. X        {
  421. X            ++i;
  422. X            continue;
  423. X        }
  424. X        if (strchr(av, ' '))
  425. X            Write(fh, "\"", 1L);
  426. X        Write(fh, av, (long)strlen(av));
  427. X        if (strchr(av, ' '))
  428. X            Write(fh, "\"", 1L);
  429. X        Write(fh, " ", 1L);
  430. X    }
  431. X    Write(fh, "\nendcli\n", 8L);
  432. X    Close(fh);
  433. X
  434. X/*
  435. X * Try to open a new cli in a window. If '-d' argument was given try to open
  436. X * the specified device. Then try a 24 line 80 column window.
  437. X * If that fails, try two smaller ones.
  438. X */
  439. X    for (i = -1; i < 3; ++i)
  440. X    {
  441. X        if (i >= 0)
  442. X            device = constrings[i];
  443. X        else if (device == NULL)
  444. X            continue;
  445. X        sprintf(buf2, "newcli <nil: >nil: %s from %s", device, buf1);
  446. X#ifndef NO_ARP
  447. X        if (dos2)
  448. X        {
  449. X#endif
  450. X            if (!SystemTags((UBYTE *)buf2, SYS_UserShell, TRUE, TAG_DONE))
  451. X                break;
  452. X#ifndef NO_ARP
  453. X        }
  454. X        else
  455. X        {
  456. X            if (Execute((UBYTE *)buf2, nilfh, nilfh))
  457. X                break;
  458. X        }
  459. X#endif
  460. X    }
  461. X    if (i == 3)        /* all three failed */
  462. X    {
  463. X        DeleteFile((UBYTE *)buf1);
  464. X        fprintf(stderr, winerr);
  465. X        goto exit;
  466. X    }
  467. X    exitval = 0;    /* The Execute succeeded: exit this program */
  468. X
  469. Xexit:
  470. X#ifndef NO_ARP
  471. X    if (ArpBase)
  472. X        CloseLibrary((struct Library *) ArpBase);
  473. X#endif
  474. X    exit(exitval);
  475. X}
  476. X
  477. X/*
  478. X * fname_case(): Set the case of the filename, if it already exists.
  479. X *                 This will cause the filename to remain exactly the same.
  480. X */
  481. X    void
  482. Xfname_case(name)
  483. X    char *name;
  484. X{
  485. X    register struct FileInfoBlock    *fib;
  486. X    register size_t                    len;
  487. X
  488. X    fib = get_fib(name);
  489. X    if (fib != NULL)
  490. X    {
  491. X        len = strlen(name);
  492. X        if (len == strlen(fib->fib_FileName))    /* safety check */
  493. X                memmove(name, fib->fib_FileName, len);
  494. X        free(fib);
  495. X    }
  496. X}
  497. X
  498. X/*
  499. X * Get the FileInfoBlock for file "fname"
  500. X * The returned structure has to be free()d.
  501. X * Returns NULL on error.
  502. X */
  503. X    static struct FileInfoBlock *
  504. Xget_fib(fname)
  505. X    char *fname;
  506. X{
  507. X    register BPTR                    flock;
  508. X    register struct FileInfoBlock    *fib;
  509. X
  510. X    if (fname == NULL)        /* safety check */
  511. X        return NULL;
  512. X    fib = (struct FileInfoBlock *)malloc(sizeof(struct FileInfoBlock));
  513. X    if (fib != NULL)
  514. X    {
  515. X        flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
  516. X        if (flock == (BPTR)NULL || !Examine(flock, fib))
  517. X        {
  518. X            free(fib);    /* in case of an error the memory is freed here */
  519. X            fib = NULL;
  520. X        }
  521. X        if (flock)
  522. X            UnLock(flock);
  523. X    }
  524. X    return fib;
  525. X}
  526. X
  527. X/*
  528. X * settitle(): set titlebar of our window
  529. X */
  530. Xstatic char *lasttitle = NULL;
  531. X
  532. X    void
  533. Xsettitle(str)
  534. X    char *str;
  535. X{
  536. X
  537. X    if (wb_window != NULL)
  538. X    {
  539. X        free(lasttitle);
  540. X        lasttitle = alloc((unsigned)(strlen(str) + 7));
  541. X        if (lasttitle != NULL)
  542. X        {
  543. X            sprintf(lasttitle, "VIM - %s", str);
  544. X            SetWindowTitles(wb_window, (UBYTE *)lasttitle, (UBYTE *)-1L);
  545. X        }
  546. X    }
  547. X}
  548. X
  549. X    void
  550. Xresettitle()
  551. X{
  552. X        if (wb_window != NULL && lasttitle != NULL)
  553. X                SetWindowTitles(wb_window, (UBYTE *)lasttitle, (UBYTE *)-1L);
  554. X}
  555. X
  556. X/*
  557. X * get name of current directory into buffer 'buf' of length 'len' bytes
  558. X */
  559. Xdirname(buf, len)
  560. X    char        *buf;
  561. X    int            len;
  562. X{
  563. X    return FullName("", buf, len);
  564. X}
  565. X
  566. X/*
  567. X * get absolute filename into buffer 'buf' of length 'len' bytes
  568. X */
  569. XFullName(fname, buf, len)
  570. X    char        *fname, *buf;
  571. X    int            len;
  572. X{
  573. X    BPTR        l;
  574. X    int            retval = 0;
  575. X
  576. X    if (fname == NULL)    /* always fail */
  577. X        return 0;
  578. X
  579. X    if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)))/* lock the file */
  580. X    {
  581. X        retval = lock2name(l, buf, (long)len);
  582. X        UnLock(l);
  583. X    }
  584. X    if (retval == 0 || *buf == 0 || *buf == ':')
  585. X        strcpy(buf, fname);            /* something failed; use the filename */
  586. X    return retval;
  587. X}
  588. X
  589. X/*
  590. X * Get the full filename from a lock. Use 2.0 function if possible, because
  591. X * the arp function has more restrictions on the path length.
  592. X */
  593. X    static int
  594. Xlock2name(lock, buf, len)
  595. X    BPTR    lock;
  596. X    char    *buf;
  597. X    long    len;
  598. X{
  599. X#ifndef NO_ARP
  600. X    if (dos2)                /* use 2.0 function */
  601. X#endif
  602. X        return (int)NameFromLock(lock, (UBYTE *)buf, len);
  603. X#ifndef NO_ARP
  604. X    else                /* use arp function */
  605. X        return (int)PathName(lock, buf, (long)(len/32));
  606. X#endif
  607. X}
  608. X
  609. X/*
  610. X * get file permissions for 'name'
  611. X */
  612. X    long
  613. Xgetperm(name)
  614. X    char        *name;
  615. X{
  616. X    struct FileInfoBlock    *fib;
  617. X    long                     retval = -1;
  618. X
  619. X    fib = get_fib(name);
  620. X    if (fib != NULL)
  621. X    {
  622. X        retval = fib->fib_Protection;
  623. X        free(fib);
  624. X    }
  625. X    return retval;
  626. X}
  627. X
  628. X/*
  629. X * set file permission for 'name' to 'perm'
  630. X */
  631. Xsetperm(name, perm)
  632. X    char        *name;
  633. X    long        perm;
  634. X{
  635. X    perm &= ~FIBF_ARCHIVE;                /* reset archived bit */
  636. X    return (int)SetProtection((UBYTE *)name, (long)perm);
  637. X}
  638. X
  639. X/*
  640. X * check if "name" is a directory
  641. X */
  642. Xisdir(name)
  643. X    char        *name;
  644. X{
  645. X    struct FileInfoBlock    *fib;
  646. X    int                     retval = -1;
  647. X
  648. X    fib = get_fib(name);
  649. X    if (fib != NULL)
  650. X    {
  651. X        retval = (fib->fib_DirEntryType >= 0);
  652. X        free(fib);
  653. X    }
  654. X    return retval;
  655. X}
  656. X
  657. X/*
  658. X * Careful: mch_windexit() may be called before mch_windinit()!
  659. X */
  660. X    void
  661. Xmch_windexit(r)
  662. X    int             r;
  663. X{
  664. X    if (raw_in)                        /* put terminal in 'normal' mode */
  665. X    {
  666. X        settmode(0);
  667. X        stoptermcap();
  668. X    }
  669. X    if (raw_out)
  670. X    {
  671. X        if (term_console)
  672. X        {
  673. X            win_resize_off();        /* window resize events de-activated */
  674. X            if (size_set)
  675. X                outstr("\233t\233u");        /* reset window size (CSI t CSI u) */
  676. X        }
  677. X        flushbuf();
  678. X    }
  679. X
  680. X    if (wb_window != NULL)            /* disable window title */
  681. X        SetWindowTitles(wb_window, (UBYTE *)oldwindowtitle, (UBYTE *)-1L);
  682. X    stopscript();                    /* remove autoscript file */
  683. X#ifndef NO_ARP
  684. X    if (ArpBase)
  685. X        CloseLibrary((struct Library *) ArpBase);
  686. X#endif
  687. X    if (close_win)
  688. X        Close(raw_in);
  689. X    if (r)
  690. X        printf("exiting with %d\n", r);    /* somehow this makes :cq work!? */
  691. X    exit(r);
  692. X}
  693. X
  694. X/*
  695. X * This is a routine for setting a given stream to raw or cooked mode on the
  696. X * Amiga . This is useful when you are using Lattice C to produce programs
  697. X * that want to read single characters with the "getch()" or "fgetc" call.
  698. X *
  699. X * Written : 18-Jun-87 By Chuck McManis.
  700. X */
  701. X
  702. X#define MP(xx)    ((struct MsgPort *)((struct FileHandle *) (BADDR(xx)))->fh_Type)
  703. X
  704. X/*
  705. X * Function mch_settmode() - Convert the specified file pointer to 'raw' or 'cooked'
  706. X * mode. This only works on TTY's.
  707. X *
  708. X * Raw: keeps DOS from translating keys for you, also (BIG WIN) it means
  709. X *        getch() will return immediately rather than wait for a return. You
  710. X *        lose editing features though.
  711. X *
  712. X * Cooked: This function returns the designate file pointer to it's normal,
  713. X *        wait for a <CR> mode. This is exactly like raw() except that
  714. X *        it sends a 0 to the console to make it back into a CON: from a RAW:
  715. X */
  716. X    void
  717. Xmch_settmode(raw)
  718. X    int            raw;
  719. X{
  720. X    if (dos_packet(MP(raw_in), (long)ACTION_SCREEN_MODE, raw ? -1L : 0L) == 0)
  721. X        fprintf(stderr, "cannot change console mode ?!\n");
  722. X}
  723. X
  724. X/*
  725. X * Code for this routine came from the following :
  726. X *
  727. X * ConPackets.c -  C. Scheppner, A. Finkel, P. Lindsay    CBM
  728. X *     DOS packet example
  729. X *     Requires 1.2
  730. X *
  731. X * Found on Fish Disk 56.
  732. X *
  733. X * Heavely modified by mool.
  734. X */
  735. X
  736. X#include <devices/conunit.h>
  737. X
  738. X/*
  739. X * try to get the real window size
  740. X * return non-zero for failure
  741. X */
  742. X    int
  743. Xmch_get_winsize()
  744. X{
  745. X    struct ConUnit    *conUnit;
  746. X     char            id_a[sizeof(struct InfoData) + 3];
  747. X    struct InfoData *id;
  748. X
  749. X    if (!term_console)    /* not an amiga window */
  750. X        return 1;
  751. X
  752. X    /* insure longword alignment */
  753. X     id = (struct InfoData *)(((long)id_a + 3L) & ~3L);
  754. X
  755. X    /*
  756. X     * Should make console aware of real window size, not the one we set.
  757. X     * Unfortunately, under DOS 2.0x this redraws the window and it
  758. X     * is rarely needed, so we skip it now, unless we changed the size.
  759. X     */
  760. X    if (size_set)
  761. X        outstr("\233t\233u");    /* CSI t CSI u */
  762. X    flushbuf();
  763. X
  764. X    if (dos_packet(MP(raw_out), (long)ACTION_DISK_INFO, ((ULONG) id) >> 2) == 0 ||
  765. X                (wb_window = (struct Window *)id->id_VolumeNode) == NULL)
  766. X    {
  767. X        /* it's not an amiga window, maybe aux device */
  768. X        /* terminal type should be set */
  769. X        term_console = FALSE;
  770. X        return 1;
  771. X    }
  772. X    if (oldwindowtitle == NULL)
  773. X        oldwindowtitle = (char *)wb_window->Title;
  774. X    if (id->id_InUse == (BPTR)NULL)
  775. X    {
  776. X        fprintf(stderr, "mch_get_winsize: not a console??\n");
  777. X        return (2);
  778. X    }
  779. X    conUnit = (struct ConUnit *) ((struct IOStdReq *) id->id_InUse)->io_Unit;
  780. X
  781. X    /* get window size */
  782. X    Rows = conUnit->cu_YMax + 1;
  783. X    Columns = conUnit->cu_XMax + 1;
  784. X    if (Rows < 0 || Rows > 200)     /* cannot be an amiga window */
  785. X    {
  786. X        Columns = 80;
  787. X        Rows = 24;
  788. X        term_console = FALSE;
  789. X        return 1;
  790. X    }
  791. X
  792. X    check_winsize();
  793. X    script_winsize();
  794. X
  795. X    return 0;
  796. X}
  797. X
  798. X/*
  799. X * try to set the real window size
  800. X */
  801. X    void
  802. Xmch_set_winsize()
  803. X{
  804. X    if (term_console)
  805. X    {
  806. X        size_set = TRUE;
  807. X        outchar(CSI);
  808. X        outnum((long)Rows);
  809. X        outchar('t');
  810. X        outchar(CSI);
  811. X        outnum((long)Columns);
  812. X        outchar('u');
  813. X        flushbuf();
  814. X    }
  815. X}
  816. X
  817. X#ifdef SETKEYMAP
  818. X/*
  819. X * load and activate a new keymap for our CLI - DOES NOT WORK -
  820. X * The problem is that after the setting of the keymap the input blocks
  821. X * But the new keymap works allright in another window.
  822. X * Tried but no improvement:
  823. X * - remembering the length, data and command fields in request->io_xxx
  824. X * - settmode(0) first, settmode(1) afterwards
  825. X * - putting the keymap directly in conunit structure
  826. X */
  827. X
  828. X#include <devices/keymap.h>
  829. X
  830. X    void
  831. Xset_keymap(name)
  832. X    char *name;
  833. X{
  834. X     char                    id_a[sizeof(struct InfoData) + 3];
  835. X    struct InfoData            *id;
  836. X    static struct KeyMap    *old;
  837. X    static BPTR                segment = (BPTR)NULL;
  838. X    struct IOStdReq            *request;
  839. X    int                        c;
  840. X
  841. X    if (!term_console)
  842. X        return;
  843. X
  844. X    /* insure longword alignment */
  845. X     id = (struct InfoData *)(((long)id_a + 3L) & ~3L);
  846. X
  847. X    if (dos_packet(MP(raw_out), (long)ACTION_DISK_INFO, ((ULONG) id) >> 2) == 0)
  848. X    {
  849. X        emsg("dos_packet failed");
  850. X        return;
  851. X    }
  852. X    if (id->id_InUse == (BPTR)NULL)
  853. X    {
  854. X        emsg("not a console??");
  855. X        return;
  856. X    }
  857. X    request = (struct IOStdReq *) id->id_InUse;
  858. X
  859. X    if (segment != (BPTR)NULL)    /* restore old keymap */
  860. X    {
  861. X        request->io_Command = CD_SETKEYMAP;
  862. X        request->io_Length = sizeof(struct KeyMap);
  863. X        request->io_Data = (APTR)old;
  864. X        DoIO((struct IORequest *)request);
  865. X        if (request->io_Error)
  866. X            emsg("Cannot reset keymap");
  867. X        else                /* no error, free the allocated memory */
  868. X        {
  869. X            UnLoadSeg(segment);
  870. X            FreeMem(old, sizeof(struct KeyMap));
  871. X            segment = (BPTR)NULL;
  872. X        }
  873. X    }
  874. X    if (name != NULL)
  875. X    {
  876. X        segment = LoadSeg(name);
  877. X        if (segment == (BPTR)NULL)
  878. X        {
  879. X            emsg("Cannot open keymap file");
  880. X            return;
  881. X        }
  882. X        old = (struct KeyMap *)AllocMem(sizeof(struct KeyMap), MEMF_PUBLIC);
  883. X        if (old == NULL)
  884. X        {
  885. X            emsg(e_outofmem);
  886. X            UnLoadSeg(segment);
  887. X            segment = (BPTR)NULL;
  888. X        }
  889. X        else
  890. X        {
  891. X            request->io_Command = CD_ASKKEYMAP;
  892. X            request->io_Length = sizeof(struct KeyMap);
  893. X            request->io_Data = (APTR)old;
  894. X            DoIO((struct IORequest *)request);
  895. X            if (request->io_Error)
  896. X            {
  897. X                emsg("Cannot get old keymap");
  898. X                UnLoadSeg(segment);
  899. X                segment = (BPTR)NULL;
  900. X                FreeMem(old, sizeof(struct KeyMap));
  901. X            }
  902. X            else
  903. X            {
  904. X                request->io_Command = CD_SETKEYMAP;
  905. X                request->io_Length = sizeof(struct KeyMap);
  906. X                request->io_Data = (APTR)((segment << 2) + 18);
  907. X                DoIO((struct IORequest *)request);
  908. X                if (request->io_Error)
  909. X                    emsg("Cannot set keymap");
  910. X
  911. X                /* test for blocking */
  912. X                request->io_Command = CMD_READ;
  913. X                request->io_Length = 1;
  914. X                request->io_Data = (APTR)&c;
  915. X                DoIO((struct IORequest *)request);    /* BLOCK HERE! */
  916. X                if (request->io_Error)
  917. X                    emsg("Cannot set keymap");
  918. X            }
  919. X        }
  920. X    }
  921. X}
  922. X#endif
  923. X
  924. X#ifndef AZTEC_C
  925. X/*
  926. X * Sendpacket.c
  927. X *
  928. X * An invaluable addition to your Amiga.lib file. This code sends a packet to
  929. X * the given message port. This makes working around DOS lots easier.
  930. X *
  931. X * Note, I didn't write this, those wonderful folks at CBM did. I do suggest
  932. X * however that you may wish to add it to Amiga.Lib, to do so, compile it and
  933. X * say 'oml lib:amiga.lib -r sendpacket.o'
  934. X */
  935. X
  936. X/* #include <proto/exec.h> */
  937. X/* #include <proto/dos.h> */
  938. X#include <exec/memory.h>
  939. X
  940. X/*
  941. X * Function - dos_packet written by Phil Lindsay, Carolyn Scheppner, and Andy
  942. X * Finkel. This function will send a packet of the given type to the Message
  943. X * Port supplied.
  944. X */
  945. X
  946. X    static long
  947. Xdos_packet(pid, action, arg)
  948. X    struct MsgPort *pid;    /* process indentifier ... (handlers message port) */
  949. X    long            action, /* packet type ... (what you want handler to do)   */
  950. X                    arg;    /* single argument */
  951. X{
  952. X# ifndef NO_ARP
  953. X    struct MsgPort            *replyport;
  954. X    struct StandardPacket    *packet;
  955. X    long                    res1;
  956. X
  957. X    if (dos2)
  958. X# endif
  959. X        return DoPkt(pid, action, arg, 0L, 0L, 0L, 0L);    /* use 2.0 function */
  960. X# ifndef NO_ARP
  961. X
  962. X    replyport = (struct MsgPort *) CreatePort(NULL, 0);    /* use arp function */
  963. X    if (!replyport)
  964. X        return (0);
  965. X
  966. X    /* Allocate space for a packet, make it public and clear it */
  967. X    packet = (struct StandardPacket *)
  968. X        AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
  969. X    if (!packet) {
  970. X        DeletePort(replyport);
  971. X        return (0);
  972. X    }
  973. X    packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
  974. X    packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  975. X    packet->sp_Pkt.dp_Port = replyport;
  976. X    packet->sp_Pkt.dp_Type = action;
  977. X    packet->sp_Pkt.dp_Arg1 = arg;
  978. X
  979. X    PutMsg(pid, (struct Message *)packet);        /* send packet */
  980. X
  981. X    WaitPort(replyport);
  982. X    GetMsg(replyport);
  983. X
  984. X    res1 = packet->sp_Pkt.dp_Res1;
  985. X
  986. X    FreeMem(packet, (long) sizeof(struct StandardPacket));
  987. X    DeletePort(replyport);
  988. X
  989. X    return (res1);
  990. X# endif
  991. X}
  992. X#endif
  993. X
  994. X/*
  995. X * call shell, return non-zero for failure
  996. X */
  997. X    int
  998. Xcall_shell(cmd, filter)
  999. X        char    *cmd;
  1000. X        int        filter;        /* if != 0: called by dofilter() */
  1001. X{
  1002. X    BPTR mydir;
  1003. X    int x;
  1004. X#ifndef LATTICE
  1005. X    int    use_execute;
  1006. X    char *shellcmd = NULL;
  1007. X    char *shellarg;
  1008. X#endif
  1009. X    int    retval = 0;
  1010. X
  1011. X    if (close_win)
  1012. X    {
  1013. X        /* if Vim opened a window: Executing a shell may cause crashes */
  1014. X        emsg("Cannot execute shell with -e option");
  1015. X        return 1;
  1016. X    }
  1017. X
  1018. X    if (term_console)
  1019. X        win_resize_off();     /* window resize events de-activated */
  1020. X    flushbuf();
  1021. X
  1022. X    settmode(0);                 /* set to cooked mode */
  1023. X    mydir = Lock((UBYTE *)"", (long)ACCESS_READ);    /* remember current directory */
  1024. X
  1025. X#ifdef LATTICE        /* not tested very much */
  1026. X    if (cmd == NULL)
  1027. X    {
  1028. X#ifndef NO_ARP
  1029. X        if (dos2)
  1030. X#endif
  1031. X            x = SystemTags(p_sh, SYS_UserShell, TRUE, TAG_DONE);
  1032. X#ifndef NO_ARP
  1033. X        else
  1034. X            x = Execute(p_sh, raw_in, raw_out);
  1035. X#endif
  1036. X    }
  1037. X    else
  1038. X    {
  1039. X#ifndef NO_ARP
  1040. X        if (dos2)
  1041. X#endif
  1042. X            x = SystemTags(cmd, SYS_UserShell, TRUE, TAG_DONE);
  1043. X#ifndef NO_ARP
  1044. X        else
  1045. X            x = Execute(cmd, 0L, raw_out);
  1046. X#endif
  1047. X    }
  1048. X#ifdef NO_ARP
  1049. X    if (x < 0)
  1050. X#else
  1051. X    if ((dos2 && x < 0) || (!dos2 && !x))
  1052. X#endif
  1053. X    {
  1054. X        if (cmd == NULL)
  1055. X            smsg("Cannot execute shell %s", p_sh);
  1056. X        else
  1057. X            smsg("Cannot execute %s", cmd);
  1058. X        outchar('\n');
  1059. X        retval = 1;
  1060. X    }
  1061. X#ifdef NO_ARP
  1062. X    else if (x)
  1063. X#else
  1064. X    else if (!dos2 || x)
  1065. X#endif
  1066. X    {
  1067. X        if (x = IoErr())
  1068. X        {
  1069. X            smsg("%d returned", x);
  1070. X            outchar('\n');
  1071. X            retval = 1;
  1072. X        }
  1073. X    }
  1074. X#else
  1075. X    if (p_st >= 4 || (p_st >= 2 && !filter))
  1076. X        use_execute = 1;
  1077. X    else
  1078. X        use_execute = 0;
  1079. X    if (!use_execute)
  1080. X    {
  1081. X        /*
  1082. X         * separate shell name from argument
  1083. X         */
  1084. X        shellcmd = strsave(p_sh);
  1085. X        if (shellcmd == NULL)        /* out of memory, use Execute */
  1086. X            use_execute = 1;
  1087. X        else
  1088. X        {
  1089. X            shellarg = shellcmd;
  1090. X            skiptospace(&shellarg);
  1091. X            *shellarg = NUL;
  1092. X            skipspace(&shellarg);
  1093. X        }
  1094. X    }
  1095. X    if (cmd == NULL)
  1096. X    {
  1097. X        if (use_execute)
  1098. X        {
  1099. X#ifndef NO_ARP
  1100. X            if (dos2)
  1101. X#endif
  1102. X                x = SystemTags((UBYTE *)p_sh, SYS_UserShell, TRUE, TAG_DONE);
  1103. X#ifndef NO_ARP
  1104. X            else
  1105. X                x = !Execute((UBYTE *)p_sh, raw_in, raw_out);
  1106. X#endif
  1107. X        }
  1108. X        else
  1109. X            x = fexecl(shellcmd, shellcmd, shellarg, NULL);
  1110. X    }
  1111. X    else if (use_execute)
  1112. X    {
  1113. X#ifndef NO_ARP
  1114. X        if (dos2)
  1115. X#endif
  1116. X            x = SystemTags((UBYTE *)cmd, SYS_UserShell, TRUE, TAG_DONE);
  1117. X#ifndef NO_ARP
  1118. X        else
  1119. X            x = !Execute((UBYTE *)cmd, 0L, raw_out);
  1120. X#endif
  1121. X    }
  1122. X    else if (p_st & 1)
  1123. X        x = fexecl(shellcmd, shellcmd, shellarg, cmd, NULL);
  1124. X    else
  1125. X        x = fexecl(shellcmd, shellcmd, shellarg, "-c", cmd, NULL);
  1126. X#ifdef NO_ARP
  1127. X    if (x < 0)
  1128. X#else
  1129. X    if ((dos2 && x < 0) || (!dos2 && x))
  1130. X#endif
  1131. X    {
  1132. X        if (use_execute)
  1133. X            smsg("Cannot execute %s", cmd == NULL ? p_sh : cmd);
  1134. X        else
  1135. X            smsg("Cannot execute shell %s", shellcmd);
  1136. X        outchar('\n');
  1137. X        retval = 1;
  1138. X    }
  1139. X    else
  1140. X    {
  1141. X        if (use_execute)
  1142. X        {
  1143. X#ifdef NO_ARP
  1144. X            if (x)
  1145. X#else
  1146. X            if (!dos2 || x)
  1147. X#endif
  1148. X                x = IoErr();
  1149. X        }
  1150. X        else
  1151. X            x = wait();
  1152. X        if (x)
  1153. X        {
  1154. X            smsg("%d returned", x);
  1155. X            outchar('\n');
  1156. X            retval = 1;
  1157. X        }
  1158. X    }
  1159. X    free(shellcmd);
  1160. X#endif
  1161. X
  1162. X    if (mydir = CurrentDir(mydir))        /* make sure we stay in the same directory */
  1163. X        UnLock(mydir);
  1164. X    settmode(1);                         /* set to raw mode */
  1165. X    resettitle();
  1166. X    if (term_console)
  1167. X        win_resize_on();             /* window resize events activated */
  1168. X    return retval;
  1169. X}
  1170. X
  1171. X/*
  1172. X * check for an "interrupt signal"
  1173. X * We only react to a CTRL-C, but also clear the other break signals to avoid trouble
  1174. X * with lattice-c programs.
  1175. X */
  1176. X    void
  1177. Xbreakcheck()
  1178. X{
  1179. X   if (SetSignal(0L, (long)(SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F)) & SIGBREAKF_CTRL_C)
  1180. X    {
  1181. X        got_int = TRUE;
  1182. X        flush_buffers();    /* remove all typeahead and macro stuff */
  1183. X    }
  1184. X}
  1185. X
  1186. X/* this routine causes manx to use this Chk_Abort() rather than it's own */
  1187. X/* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  1188. X/* is zero).  Since we want to check for our own ^C's                    */
  1189. X
  1190. X#ifdef _DCC
  1191. X#define Chk_Abort chkabort
  1192. X#endif
  1193. X
  1194. X    long
  1195. XChk_Abort()
  1196. X{
  1197. X    return(0L);
  1198. X}
  1199. X
  1200. X#ifdef WILD_CARDS
  1201. X/*
  1202. X * ExpandWildCard() - this code does wild-card pattern matching using the arp
  1203. X *                      routines. This is based on WildDemo2.c (found in arp1.1
  1204. X *                      distribution). That code's copyright follows :
  1205. X *-------------------------------------------------------------------------
  1206. X * WildDemo2.c - Search filesystem for patterns, and separate into directories
  1207. X *         and files, sorting each separately using DA lists.
  1208. X *
  1209. X * -+=SDB=+-
  1210. X *
  1211. X * Copyright (c) 1987, Scott Ballantyne
  1212. X * Use and abuse as you please.
  1213. X *
  1214. X * num_pat is number of input patterns
  1215. X * pat is array of pointers to input patterns
  1216. X * num_file is pointer to number of matched file names
  1217. X * file is pointer to array of pointers to matched file names
  1218. X * if file_only is TRUE we match only files, no dirs
  1219. X * if list_notfound is TRUE we include not-found entries (probably locked)
  1220. X * return 0 for success, 1 for error (you may loose some memory)
  1221. X *-------------------------------------------------------------------------
  1222. X */
  1223. X
  1224. X/* #include <arpfunctions.h> */
  1225. Xextern void *malloc __ARGS((size_t)), *calloc __ARGS((size_t, size_t));
  1226. Xstatic int insfile __ARGS((char *));
  1227. Xstatic void freefiles __ARGS((void));
  1228. X
  1229. X#define ANCHOR_BUF_SIZE (512)
  1230. X#define ANCHOR_SIZE (sizeof(struct AnchorPath) + ANCHOR_BUF_SIZE)
  1231. X
  1232. X/*
  1233. X * we use this structure to built a list of file names
  1234. X */
  1235. Xstruct onefile
  1236. X{
  1237. X    struct onefile    *next;
  1238. X    char            name[1];    /* really longer */
  1239. X} *namelist = NULL;
  1240. X
  1241. X/*
  1242. X * insert one file into the list of file names
  1243. X * return -1 for failure
  1244. X * return 0 for success
  1245. X */
  1246. X    static int
  1247. Xinsfile(name)
  1248. X    char *name;
  1249. X{
  1250. X    struct onefile *new;
  1251. X
  1252. X    new = (struct onefile *)alloc((unsigned)(sizeof(struct onefile) + strlen(name)));
  1253. X    if (new == NULL)
  1254. X        return -1;
  1255. X    strcpy(&(new->name[0]), name);
  1256. X    new->next = namelist;
  1257. X    namelist = new;
  1258. X    return 0;
  1259. X}
  1260. X
  1261. X/*
  1262. X * free a whole list of file names
  1263. X */
  1264. X    static void
  1265. Xfreefiles()
  1266. X{
  1267. X    struct onefile *p;
  1268. X
  1269. X    while (namelist)
  1270. X    {
  1271. X        p = namelist->next;
  1272. X        free(namelist);
  1273. X        namelist = p;
  1274. X    }
  1275. X}
  1276. X
  1277. XExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound)
  1278. X    int             num_pat;
  1279. X    char          **pat;
  1280. X    int            *num_file;
  1281. X    char         ***file;
  1282. X    int            files_only;
  1283. X    int            list_notfound;
  1284. X{
  1285. X    int                     i;
  1286. X    struct AnchorPath        *Anchor;
  1287. X    int                        domatchend = FALSE;
  1288. X    LONG                    Result;
  1289. X    struct onefile            *p;
  1290. X    char                    *errmsg = NULL;
  1291. X    char                    *starbuf, *sp, *dp;
  1292. X
  1293. X    *num_file = 0;
  1294. X    *file = (char **)"";
  1295. X
  1296. X    /* Get our AnchorBase */
  1297. X    Anchor = (struct AnchorPath *) calloc((size_t)1, (size_t)ANCHOR_SIZE);
  1298. X    if (!Anchor)
  1299. X        goto OUT_OF_MEMORY;
  1300. X    Anchor->ap_StrLen = ANCHOR_BUF_SIZE;    /* ap_Length not supported anymore */
  1301. X#ifdef APF_DODOT
  1302. X    Anchor->ap_Flags = APF_DODOT | APF_DOWILD;        /* allow '.' for current dir */
  1303. X#else
  1304. X    Anchor->ap_Flags = APF_DoDot | APF_DoWild;        /* allow '.' for current dir */
  1305. X#endif
  1306. X
  1307. X    for (i = 0; i < num_pat; i++)
  1308. X    {
  1309. X#ifndef NO_ARP
  1310. X        if (dos2)
  1311. X        {
  1312. X#endif
  1313. X                /* hack to replace '*' by '#?' */
  1314. X            starbuf = alloc((unsigned)(2 * strlen(pat[i]) + 1));    /* maximum required */
  1315. X            if (starbuf == NULL)
  1316. X                goto OUT_OF_MEMORY;
  1317. X            for (sp = pat[i], dp = starbuf; *sp; ++sp)
  1318. X            {
  1319. X                if (*sp == '*')
  1320. X                {
  1321. X                    *dp++ = '#';
  1322. X                    *dp++ = '?';
  1323. X                }
  1324. X                else
  1325. X                    *dp++ = *sp;
  1326. X            }
  1327. X            *dp = NUL;
  1328. X            Result = MatchFirst((UBYTE *)starbuf, Anchor);
  1329. X            free(starbuf);
  1330. X#ifndef NO_ARP
  1331. X        }
  1332. X        else
  1333. X            Result = FindFirst(pat[i], Anchor);
  1334. X#endif
  1335. X        domatchend = TRUE;
  1336. X        while (Result == 0)
  1337. X        {
  1338. X            if (!files_only || Anchor->ap_Info.fib_DirEntryType < 0)
  1339. X            {
  1340. X                (*num_file)++;
  1341. X                if (insfile(Anchor->ap_Buf))
  1342. X                {
  1343. XOUT_OF_MEMORY:
  1344. X                    errmsg = "Out of memory";
  1345. X                    goto Return;
  1346. X                }
  1347. X            }
  1348. X#ifndef NO_ARP
  1349. X            if (dos2)
  1350. X#endif
  1351. X                Result = MatchNext(Anchor);
  1352. X#ifndef NO_ARP
  1353. X            else
  1354. X                Result = FindNext(Anchor);
  1355. X#endif
  1356. X        }
  1357. X        if (Result == ERROR_BUFFER_OVERFLOW)
  1358. X        {
  1359. X            errmsg = "ANCHOR_BUF_SIZE too small.";
  1360. X            goto Return;
  1361. X        }
  1362. X        if (Result != ERROR_NO_MORE_ENTRIES)
  1363. X        {
  1364. X            if (list_notfound)    /* put object with error in list */
  1365. X            {
  1366. X                (*num_file)++;
  1367. X                if (insfile(pat[i]))
  1368. X                    goto OUT_OF_MEMORY;
  1369. X            }
  1370. X            else if (Result != ERROR_OBJECT_NOT_FOUND)
  1371. X            {
  1372. X                errmsg = "I/O ERROR";
  1373. X                goto Return;
  1374. X            }
  1375. X        }
  1376. X        MatchEnd(Anchor);
  1377. X        domatchend = FALSE;
  1378. X    }
  1379. X
  1380. X    p = namelist;
  1381. X    if (p)
  1382. X    {
  1383. X        *file = (char **) malloc(sizeof(char *) * (*num_file));
  1384. X        if (*file == NULL)
  1385. X            goto OUT_OF_MEMORY;
  1386. X        for (i = *num_file - 1; p; p = p->next, --i)
  1387. X        {
  1388. X            (*file)[i] = (char *) malloc(strlen(p->name) + 1);
  1389. X            if ((*file)[i] == NULL)
  1390. X                goto OUT_OF_MEMORY;
  1391. X            strcpy((*file)[i], p->name);
  1392. X        }
  1393. X    }
  1394. XReturn:
  1395. X    if (domatchend)
  1396. X        MatchEnd(Anchor);
  1397. X    if (Anchor)
  1398. X        free(Anchor);
  1399. X    freefiles();
  1400. X    if (errmsg)
  1401. X    {
  1402. X        emsg(errmsg);
  1403. X        *num_file = 0;
  1404. X        return 1;
  1405. X    }
  1406. X    return 0;
  1407. X}
  1408. X
  1409. Xvoid
  1410. XFreeWild(num, file)
  1411. X        int num;
  1412. X        char **file;
  1413. X{
  1414. X        if (file == NULL || num == 0)
  1415. X                return;
  1416. X        while (num--)
  1417. X                free(file[num]);
  1418. X        free(file);
  1419. X}
  1420. X
  1421. X    int
  1422. Xhas_wildcard(p)
  1423. X    char *p;
  1424. X{
  1425. X    for ( ; *p; ++p)
  1426. X        if (strchr("*?[(~#", *p) != NULL)
  1427. X            return 1;
  1428. X    return 0;
  1429. X}
  1430. X#endif /* WILD_CARDS */
  1431. X
  1432. X/*
  1433. X * With 2.0 support for reading local environment variables
  1434. X */
  1435. X
  1436. X    char *
  1437. Xvimgetenv(var)
  1438. X    char *var;
  1439. X{
  1440. X  int len;
  1441. X
  1442. X#ifndef NO_ARP
  1443. X  if (!dos2)
  1444. X        return getenv(var);
  1445. X#endif
  1446. X
  1447. X  len = GetVar((UBYTE *)var, (UBYTE *)IObuff, (long)(IOSIZE - 1), (long)0);
  1448. X
  1449. X  if (len == -1)
  1450. X      return NULL;
  1451. X  else
  1452. X      return IObuff;
  1453. X}
  1454. END_OF_FILE
  1455. if test 29917 -ne `wc -c <'vim/src/amiga.c'`; then
  1456.     echo shar: \"'vim/src/amiga.c'\" unpacked with wrong size!
  1457. fi
  1458. # end of 'vim/src/amiga.c'
  1459. fi
  1460. echo shar: End of archive 17 \(of 23\).
  1461. cp /dev/null ark17isdone
  1462. MISSING=""
  1463. 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 ; do
  1464.     if test ! -f ark${I}isdone ; then
  1465.     MISSING="${MISSING} ${I}"
  1466.     fi
  1467. done
  1468. if test "${MISSING}" = "" ; then
  1469.     echo You have unpacked all 23 archives.
  1470.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1471. else
  1472.     echo You still need to unpack the following archives:
  1473.     echo "        " ${MISSING}
  1474. fi
  1475. ##  End of shell archive.
  1476. exit 0
  1477. -------------8<----------------8<----------------8<---------------8<--------
  1478. Bram Moolenaar                             | DISCLAIMER:  This  note  does  not
  1479. Oce Nederland B.V., Research & Development | necessarily represent the position
  1480. p.o. box 101, 5900 MA  Venlo               | of  Oce-Nederland  B.V.  Therefore
  1481. The Netherlands        phone +31 77 594077 | no liability or responsibility for
  1482. UUCP: mool@oce.nl        fax +31 77 595450 | whatever will be accepted.
  1483.  
  1484. exit 0 # Just in case...
  1485.