home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-04-23 | 32.9 KB | 1,485 lines |
- Newsgroups: comp.sources.misc
- From: mool@oce.nl (Bram Moolenaar)
- Subject: v37i017: vim - Vi IMitation editor v1.27, Part17/24
- Message-ID: <1993Apr25.013614.22697@sparky.imd.sterling.com>
- X-Md4-Signature: 0044c144201d429f4b7d7b5dce8628e3
- Date: Sun, 25 Apr 1993 01:36:14 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: mool@oce.nl (Bram Moolenaar)
- Posting-number: Volume 37, Issue 17
- Archive-name: vim/part17
- Environment: UNIX, AMIGA, MS-DOS
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 17 (of 23)."
- # Contents: vim/src/amiga.c
- # Wrapped by mool@oce-rd2 on Mon Apr 19 15:50:12 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'vim/src/amiga.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vim/src/amiga.c'\"
- else
- echo shar: Extracting \"'vim/src/amiga.c'\" \(29917 characters\)
- sed "s/^X//" >'vim/src/amiga.c' <<'END_OF_FILE'
- X/* vi:ts=4:sw=4
- X *
- X * VIM - Vi IMitation
- X *
- X * Code Contributions By: Bram Moolenaar mool@oce.nl
- X * Tim Thompson twitch!tjt
- X * Tony Andrews onecom!wldrdg!tony
- X * G. R. (Fred) Walter watmath!watcgl!grwalter
- X */
- X
- X/*
- X * amiga.c
- X *
- X * Amiga system-dependent routines.
- X */
- X
- X#include "vim.h"
- X#include "globals.h"
- X#include "proto.h"
- X#include "param.h"
- X
- X#include <fcntl.h>
- X
- X#undef TRUE /* will be redefined by exec/types.h */
- X#undef FALSE
- X
- X#ifndef LATTICE
- X# include <exec/types.h>
- X# include <exec/exec.h>
- X# include <libraries/dos.h>
- X# include <libraries/dosextens.h>
- X# include <intuition/intuition.h>
- X#else
- X# include <proto/dos.h>
- X# include <libraries/dosextens.h>
- X# include <proto/intuition.h>
- X# include <proto/exec.h>
- X#endif
- X
- X#ifndef NO_ARP
- X#include <libraries/arpbase.h> /* for arp.library */
- X#endif
- X#include <dos/dostags.h> /* for 2.0 functions */
- X#include <dos/dosasl.h>
- X
- X#if defined(LATTICE) && !defined(SASC) && !defined(NO_ARP)
- X# include <libraries/arp_pragmas.h>
- X#endif
- X
- X/*
- X * At this point TRUE and FALSE are defined as 1L and 0L, but we want 1 and 0.
- X */
- X#undef TRUE
- X#define TRUE (1)
- X#undef FALSE
- X#define FALSE (0)
- X
- X#ifndef AZTEC_C
- Xstatic long dos_packet __ARGS((struct MsgPort *, long, long));
- X#endif
- Xstatic int lock2name __ARGS((BPTR lock, char *buf, long len));
- Xstatic struct FileInfoBlock *get_fib __ARGS((char *));
- X
- Xstatic BPTR raw_in = (BPTR)NULL;
- Xstatic BPTR raw_out = (BPTR)NULL;
- Xstatic int close_win = FALSE; /* set if Vim opened the window */
- X
- Xstruct IntuitionBase *IntuitionBase = NULL;
- X#ifndef NO_ARP
- Xstruct ArpBase *ArpBase = NULL;
- X#endif
- X
- Xstatic struct Window *wb_window;
- Xstatic char *oldwindowtitle = NULL;
- Xstatic int quickfix = FALSE;
- X
- X#ifndef NO_ARP
- Xint dos2 = FALSE; /* Amiga DOS 2.0x or higher */
- X#endif
- Xint size_set = FALSE; /* set to TRUE if window size was set */
- X
- X void
- Xwin_resize_on()
- X{
- X outstrn("\033[12{");
- X}
- X
- X void
- Xwin_resize_off()
- X{
- X outstrn("\033[12}");
- X}
- X
- X/*
- X * the number of calls to Write is reduced by using the buffer "outbuf"
- X */
- X#define BSIZE 2048
- Xstatic u_char outbuf[BSIZE];
- Xstatic int bpos = 0; /* number of chars in outbuf */
- X
- X/*
- X * flushbuf(): flush the output buffer
- X */
- X void
- Xflushbuf()
- X{
- X if (bpos != 0)
- X {
- X Write(raw_out, (char *)outbuf, (long)bpos);
- X bpos = 0;
- X }
- X}
- X
- X/*
- X * outchar(c): put a character into the output buffer.
- X * Flush it if it becomes full.
- X */
- X void
- Xoutchar(c)
- X unsigned c;
- X{
- X outbuf[bpos] = c;
- X ++bpos;
- X if (bpos >= BSIZE)
- X flushbuf();
- X}
- X
- X/*
- X * GetChars(): low level input funcion.
- X * Get a characters from the keyboard.
- X * If type == T_PEEK do not wait for characters.
- X * If type == T_WAIT wait a short time for characters.
- X * If type == T_BLOCK wait for characters.
- X */
- X int
- XGetChars(buf, maxlen, type)
- X char *buf;
- X int maxlen;
- X int type;
- X{
- X int len;
- X long time = 1000000L; /* one second */
- X
- X switch (type)
- X {
- X case T_PEEK:
- X time = 100L;
- X case T_WAIT:
- X if (WaitForChar(raw_in, time) == 0) /* no character available */
- X return 0;
- X break;
- X
- X case T_BLOCK:
- X /*
- X * If there is no character available within 2 seconds (default)
- X * write the autoscript file to disk
- X */
- X if (WaitForChar(raw_in, p_ut * 1000L) == 0)
- X updatescript(0);
- X }
- X
- X for (;;) /* repeat until we got a character */
- X {
- X len = Read(raw_in, buf, (long)maxlen);
- X if (len > 0)
- X return len;
- X }
- X}
- X
- X void
- Xsleep(n)
- X int n;
- X{
- X#ifndef LATTICE /* SAS declares void Delay(UNLONG) */
- X void Delay __ARGS((long));
- X#endif
- X
- X if (n > 0)
- X Delay((long)(50L * n));
- X}
- X
- X void
- Xvim_delay()
- X{
- X Delay(25L);
- X}
- X
- X/*
- X * We have no job control, fake it by starting a new shell.
- X */
- Xvoid
- Xmch_suspend()
- X{
- X outstr("new shell started\n");
- X stoptermcap();
- X call_shell(NULL, 0);
- X starttermcap();
- X}
- X
- X#define DOS_LIBRARY ((UBYTE *) "dos.library")
- X
- X void
- Xmch_windinit()
- X{
- X static char intlibname[] = "intuition.library";
- X
- X#ifdef AZTEC_C
- X Enable_Abort = 0; /* disallow vim to be aborted */
- X#endif
- X Columns = 80;
- X Rows = 24;
- X
- X /*
- X * Set input and output channels, unless we have opened our own window
- X */
- X if (raw_in == (BPTR)NULL)
- X {
- X raw_in = Input();
- X raw_out = Output();
- X }
- X
- X flushbuf();
- X
- X wb_window = NULL;
- X if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)intlibname, 0L)) == NULL)
- X {
- X fprintf(stderr, "cannot open %s!?\n", intlibname);
- X mch_windexit(3);
- X }
- X mch_get_winsize();
- X}
- X
- X#include <workbench/startup.h>
- X
- X/*
- X * Check_win checks whether we have an interactive window.
- X * If not, a new window is opened with the newcli command.
- X * If we would open a window ourselves, the :sh and :! commands would not
- X * work properly (Why? probably because we are then running in a background CLI).
- X * This also is the best way to assure proper working in a next Workbench release.
- X *
- X * For the -e option (quickfix mode) we open our own window and disable :sh.
- X * Otherwise the compiler would never know when editing is finished.
- X */
- X#define BUF2SIZE 320 /* lenght of buffer for argument with complete path */
- X
- X void
- Xcheck_win(argc, argv)
- X int argc;
- X char **argv;
- X{
- X int i;
- X BPTR nilfh, fh;
- X char buf1[20];
- X char buf2[BUF2SIZE];
- X static char *(constrings[3]) = {"con:0/0/662/210/",
- X "con:0/0/640/200/",
- X "con:0/0/320/200/"};
- X static char winerr[] = "VIM: Can't open window!\n";
- X struct WBArg *argp;
- X int ac;
- X char *av;
- X char *device = NULL;
- X int exitval = 4;
- X struct Library *DosBase;
- X
- X/*
- X * check if we are running under DOS 2.0x or higher
- X */
- X if (DosBase = OpenLibrary(DOS_LIBRARY, 37L))
- X {
- X CloseLibrary(DosBase);
- X#ifndef NO_ARP
- X dos2 = TRUE;
- X#endif
- X }
- X else /* without arp functions we NEED 2.0 */
- X {
- X#ifdef NO_ARP
- X fprintf(stderr, "Need Amigados version 2.04 or later\n");
- X exit(3);
- X#else
- X /* need arp functions for dos 1.x */
- X if (!(ArpBase = (struct ArpBase *) OpenLibrary((UBYTE *)ArpName, ArpVersion)))
- X {
- X fprintf(stderr, "Need %s version %ld\n", ArpName, ArpVersion);
- X exit(3);
- X }
- X#endif
- X }
- X
- X/*
- X * scan argv[] for the '-e' and '-d' arguments
- X */
- X for (i = 1; i < argc; ++i)
- X if (argv[i][0] == '-')
- X {
- X switch (argv[i][1])
- X {
- X case 'e':
- X quickfix = TRUE;
- X break;
- X
- X case 'd':
- X if (i < argc - 1)
- X device = argv[i + 1];
- X break;
- X }
- X }
- X
- X/*
- X * If we were not started from workbench, do not have a '-d' argument and
- X * we have been started with an interactive window, use that window.
- X */
- X if (argc != 0 && device == NULL &&
- X IsInteractive(Input()) && IsInteractive(Output()))
- X return;
- X
- X/*
- X * If we are in quickfix mode, we open our own window. We can't use the
- X * newcli trick below, because the compiler would not know when we are finished.
- X */
- X if (quickfix)
- X {
- X /*
- X * Try to open a window. First try the specified device.
- X * Then try a 24 line 80 column window.
- X * If that fails, try two smaller ones.
- X */
- X for (i = -1; i < 3; ++i)
- X {
- X if (i >= 0)
- X device = constrings[i];
- X if (device && (raw_in = Open((UBYTE *)device, (long)MODE_NEWFILE)) != (BPTR)NULL)
- X break;
- X }
- X if (raw_in == (BPTR)NULL) /* all three failed */
- X {
- X fprintf(stderr, winerr);
- X goto exit;
- X }
- X raw_out = raw_in;
- X close_win = TRUE;
- X return;
- X }
- X
- X if ((nilfh = Open((UBYTE *)"NIL:", (long)MODE_NEWFILE)) == (BPTR)NULL)
- X {
- X fprintf(stderr, "Cannot open NIL:\n");
- X goto exit;
- X }
- X
- X /*
- X * make a unique name for the temp file (which we will not delete!)
- X */
- X sprintf(buf1, "t:nc%ld", buf1); /* nobody else is using our stack */
- X if ((fh = Open((UBYTE *)buf1, (long)MODE_NEWFILE)) == (BPTR)NULL)
- X {
- X fprintf(stderr, "Cannot create %s\n", buf1);
- X goto exit;
- X }
- X /*
- X * Write the command into the file, put quotes around the arguments that
- X * have a space in them.
- X */
- X if (argc == 0) /* run from workbench */
- X ac = ((struct WBStartup *)argv)->sm_NumArgs;
- X else
- X ac = argc;
- X for (i = 0; i < ac; ++i)
- X {
- X if (argc == 0)
- X {
- X *buf2 = NUL;
- X argp = &(((struct WBStartup *)argv)->sm_ArgList[i]);
- X if (argp->wa_Lock)
- X lock2name(argp->wa_Lock, buf2, (long)(BUF2SIZE - 1));
- X#ifndef NO_ARP
- X if (dos2) /* use 2.0 function */
- X#endif
- X AddPart((UBYTE *)buf2, (UBYTE *)argp->wa_Name, (long)(BUF2SIZE - 1));
- X#ifndef NO_ARP
- X else /* use arp function */
- X TackOn(buf2, argp->wa_Name);
- X#endif
- X av = buf2;
- X }
- X else
- X av = argv[i];
- X
- X if (av[0] == '-' && av[1] == 'd') /* skip '-d' option */
- X {
- X ++i;
- X continue;
- X }
- X if (strchr(av, ' '))
- X Write(fh, "\"", 1L);
- X Write(fh, av, (long)strlen(av));
- X if (strchr(av, ' '))
- X Write(fh, "\"", 1L);
- X Write(fh, " ", 1L);
- X }
- X Write(fh, "\nendcli\n", 8L);
- X Close(fh);
- X
- X/*
- X * Try to open a new cli in a window. If '-d' argument was given try to open
- X * the specified device. Then try a 24 line 80 column window.
- X * If that fails, try two smaller ones.
- X */
- X for (i = -1; i < 3; ++i)
- X {
- X if (i >= 0)
- X device = constrings[i];
- X else if (device == NULL)
- X continue;
- X sprintf(buf2, "newcli <nil: >nil: %s from %s", device, buf1);
- X#ifndef NO_ARP
- X if (dos2)
- X {
- X#endif
- X if (!SystemTags((UBYTE *)buf2, SYS_UserShell, TRUE, TAG_DONE))
- X break;
- X#ifndef NO_ARP
- X }
- X else
- X {
- X if (Execute((UBYTE *)buf2, nilfh, nilfh))
- X break;
- X }
- X#endif
- X }
- X if (i == 3) /* all three failed */
- X {
- X DeleteFile((UBYTE *)buf1);
- X fprintf(stderr, winerr);
- X goto exit;
- X }
- X exitval = 0; /* The Execute succeeded: exit this program */
- X
- Xexit:
- X#ifndef NO_ARP
- X if (ArpBase)
- X CloseLibrary((struct Library *) ArpBase);
- X#endif
- X exit(exitval);
- X}
- X
- X/*
- X * fname_case(): Set the case of the filename, if it already exists.
- X * This will cause the filename to remain exactly the same.
- X */
- X void
- Xfname_case(name)
- X char *name;
- X{
- X register struct FileInfoBlock *fib;
- X register size_t len;
- X
- X fib = get_fib(name);
- X if (fib != NULL)
- X {
- X len = strlen(name);
- X if (len == strlen(fib->fib_FileName)) /* safety check */
- X memmove(name, fib->fib_FileName, len);
- X free(fib);
- X }
- X}
- X
- X/*
- X * Get the FileInfoBlock for file "fname"
- X * The returned structure has to be free()d.
- X * Returns NULL on error.
- X */
- X static struct FileInfoBlock *
- Xget_fib(fname)
- X char *fname;
- X{
- X register BPTR flock;
- X register struct FileInfoBlock *fib;
- X
- X if (fname == NULL) /* safety check */
- X return NULL;
- X fib = (struct FileInfoBlock *)malloc(sizeof(struct FileInfoBlock));
- X if (fib != NULL)
- X {
- X flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
- X if (flock == (BPTR)NULL || !Examine(flock, fib))
- X {
- X free(fib); /* in case of an error the memory is freed here */
- X fib = NULL;
- X }
- X if (flock)
- X UnLock(flock);
- X }
- X return fib;
- X}
- X
- X/*
- X * settitle(): set titlebar of our window
- X */
- Xstatic char *lasttitle = NULL;
- X
- X void
- Xsettitle(str)
- X char *str;
- X{
- X
- X if (wb_window != NULL)
- X {
- X free(lasttitle);
- X lasttitle = alloc((unsigned)(strlen(str) + 7));
- X if (lasttitle != NULL)
- X {
- X sprintf(lasttitle, "VIM - %s", str);
- X SetWindowTitles(wb_window, (UBYTE *)lasttitle, (UBYTE *)-1L);
- X }
- X }
- X}
- X
- X void
- Xresettitle()
- X{
- X if (wb_window != NULL && lasttitle != NULL)
- X SetWindowTitles(wb_window, (UBYTE *)lasttitle, (UBYTE *)-1L);
- X}
- X
- X/*
- X * get name of current directory into buffer 'buf' of length 'len' bytes
- X */
- Xdirname(buf, len)
- X char *buf;
- X int len;
- X{
- X return FullName("", buf, len);
- X}
- X
- X/*
- X * get absolute filename into buffer 'buf' of length 'len' bytes
- X */
- XFullName(fname, buf, len)
- X char *fname, *buf;
- X int len;
- X{
- X BPTR l;
- X int retval = 0;
- X
- X if (fname == NULL) /* always fail */
- X return 0;
- X
- X if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)))/* lock the file */
- X {
- X retval = lock2name(l, buf, (long)len);
- X UnLock(l);
- X }
- X if (retval == 0 || *buf == 0 || *buf == ':')
- X strcpy(buf, fname); /* something failed; use the filename */
- X return retval;
- X}
- X
- X/*
- X * Get the full filename from a lock. Use 2.0 function if possible, because
- X * the arp function has more restrictions on the path length.
- X */
- X static int
- Xlock2name(lock, buf, len)
- X BPTR lock;
- X char *buf;
- X long len;
- X{
- X#ifndef NO_ARP
- X if (dos2) /* use 2.0 function */
- X#endif
- X return (int)NameFromLock(lock, (UBYTE *)buf, len);
- X#ifndef NO_ARP
- X else /* use arp function */
- X return (int)PathName(lock, buf, (long)(len/32));
- X#endif
- X}
- X
- X/*
- X * get file permissions for 'name'
- X */
- X long
- Xgetperm(name)
- X char *name;
- X{
- X struct FileInfoBlock *fib;
- X long retval = -1;
- X
- X fib = get_fib(name);
- X if (fib != NULL)
- X {
- X retval = fib->fib_Protection;
- X free(fib);
- X }
- X return retval;
- X}
- X
- X/*
- X * set file permission for 'name' to 'perm'
- X */
- Xsetperm(name, perm)
- X char *name;
- X long perm;
- X{
- X perm &= ~FIBF_ARCHIVE; /* reset archived bit */
- X return (int)SetProtection((UBYTE *)name, (long)perm);
- X}
- X
- X/*
- X * check if "name" is a directory
- X */
- Xisdir(name)
- X char *name;
- X{
- X struct FileInfoBlock *fib;
- X int retval = -1;
- X
- X fib = get_fib(name);
- X if (fib != NULL)
- X {
- X retval = (fib->fib_DirEntryType >= 0);
- X free(fib);
- X }
- X return retval;
- X}
- X
- X/*
- X * Careful: mch_windexit() may be called before mch_windinit()!
- X */
- X void
- Xmch_windexit(r)
- X int r;
- X{
- X if (raw_in) /* put terminal in 'normal' mode */
- X {
- X settmode(0);
- X stoptermcap();
- X }
- X if (raw_out)
- X {
- X if (term_console)
- X {
- X win_resize_off(); /* window resize events de-activated */
- X if (size_set)
- X outstr("\233t\233u"); /* reset window size (CSI t CSI u) */
- X }
- X flushbuf();
- X }
- X
- X if (wb_window != NULL) /* disable window title */
- X SetWindowTitles(wb_window, (UBYTE *)oldwindowtitle, (UBYTE *)-1L);
- X stopscript(); /* remove autoscript file */
- X#ifndef NO_ARP
- X if (ArpBase)
- X CloseLibrary((struct Library *) ArpBase);
- X#endif
- X if (close_win)
- X Close(raw_in);
- X if (r)
- X printf("exiting with %d\n", r); /* somehow this makes :cq work!? */
- X exit(r);
- X}
- X
- X/*
- X * This is a routine for setting a given stream to raw or cooked mode on the
- X * Amiga . This is useful when you are using Lattice C to produce programs
- X * that want to read single characters with the "getch()" or "fgetc" call.
- X *
- X * Written : 18-Jun-87 By Chuck McManis.
- X */
- X
- X#define MP(xx) ((struct MsgPort *)((struct FileHandle *) (BADDR(xx)))->fh_Type)
- X
- X/*
- X * Function mch_settmode() - Convert the specified file pointer to 'raw' or 'cooked'
- X * mode. This only works on TTY's.
- X *
- X * Raw: keeps DOS from translating keys for you, also (BIG WIN) it means
- X * getch() will return immediately rather than wait for a return. You
- X * lose editing features though.
- X *
- X * Cooked: This function returns the designate file pointer to it's normal,
- X * wait for a <CR> mode. This is exactly like raw() except that
- X * it sends a 0 to the console to make it back into a CON: from a RAW:
- X */
- X void
- Xmch_settmode(raw)
- X int raw;
- X{
- X if (dos_packet(MP(raw_in), (long)ACTION_SCREEN_MODE, raw ? -1L : 0L) == 0)
- X fprintf(stderr, "cannot change console mode ?!\n");
- X}
- X
- X/*
- X * Code for this routine came from the following :
- X *
- X * ConPackets.c - C. Scheppner, A. Finkel, P. Lindsay CBM
- X * DOS packet example
- X * Requires 1.2
- X *
- X * Found on Fish Disk 56.
- X *
- X * Heavely modified by mool.
- X */
- X
- X#include <devices/conunit.h>
- X
- X/*
- X * try to get the real window size
- X * return non-zero for failure
- X */
- X int
- Xmch_get_winsize()
- X{
- X struct ConUnit *conUnit;
- X char id_a[sizeof(struct InfoData) + 3];
- X struct InfoData *id;
- X
- X if (!term_console) /* not an amiga window */
- X return 1;
- X
- X /* insure longword alignment */
- X id = (struct InfoData *)(((long)id_a + 3L) & ~3L);
- X
- X /*
- X * Should make console aware of real window size, not the one we set.
- X * Unfortunately, under DOS 2.0x this redraws the window and it
- X * is rarely needed, so we skip it now, unless we changed the size.
- X */
- X if (size_set)
- X outstr("\233t\233u"); /* CSI t CSI u */
- X flushbuf();
- X
- X if (dos_packet(MP(raw_out), (long)ACTION_DISK_INFO, ((ULONG) id) >> 2) == 0 ||
- X (wb_window = (struct Window *)id->id_VolumeNode) == NULL)
- X {
- X /* it's not an amiga window, maybe aux device */
- X /* terminal type should be set */
- X term_console = FALSE;
- X return 1;
- X }
- X if (oldwindowtitle == NULL)
- X oldwindowtitle = (char *)wb_window->Title;
- X if (id->id_InUse == (BPTR)NULL)
- X {
- X fprintf(stderr, "mch_get_winsize: not a console??\n");
- X return (2);
- X }
- X conUnit = (struct ConUnit *) ((struct IOStdReq *) id->id_InUse)->io_Unit;
- X
- X /* get window size */
- X Rows = conUnit->cu_YMax + 1;
- X Columns = conUnit->cu_XMax + 1;
- X if (Rows < 0 || Rows > 200) /* cannot be an amiga window */
- X {
- X Columns = 80;
- X Rows = 24;
- X term_console = FALSE;
- X return 1;
- X }
- X
- X check_winsize();
- X script_winsize();
- X
- X return 0;
- X}
- X
- X/*
- X * try to set the real window size
- X */
- X void
- Xmch_set_winsize()
- X{
- X if (term_console)
- X {
- X size_set = TRUE;
- X outchar(CSI);
- X outnum((long)Rows);
- X outchar('t');
- X outchar(CSI);
- X outnum((long)Columns);
- X outchar('u');
- X flushbuf();
- X }
- X}
- X
- X#ifdef SETKEYMAP
- X/*
- X * load and activate a new keymap for our CLI - DOES NOT WORK -
- X * The problem is that after the setting of the keymap the input blocks
- X * But the new keymap works allright in another window.
- X * Tried but no improvement:
- X * - remembering the length, data and command fields in request->io_xxx
- X * - settmode(0) first, settmode(1) afterwards
- X * - putting the keymap directly in conunit structure
- X */
- X
- X#include <devices/keymap.h>
- X
- X void
- Xset_keymap(name)
- X char *name;
- X{
- X char id_a[sizeof(struct InfoData) + 3];
- X struct InfoData *id;
- X static struct KeyMap *old;
- X static BPTR segment = (BPTR)NULL;
- X struct IOStdReq *request;
- X int c;
- X
- X if (!term_console)
- X return;
- X
- X /* insure longword alignment */
- X id = (struct InfoData *)(((long)id_a + 3L) & ~3L);
- X
- X if (dos_packet(MP(raw_out), (long)ACTION_DISK_INFO, ((ULONG) id) >> 2) == 0)
- X {
- X emsg("dos_packet failed");
- X return;
- X }
- X if (id->id_InUse == (BPTR)NULL)
- X {
- X emsg("not a console??");
- X return;
- X }
- X request = (struct IOStdReq *) id->id_InUse;
- X
- X if (segment != (BPTR)NULL) /* restore old keymap */
- X {
- X request->io_Command = CD_SETKEYMAP;
- X request->io_Length = sizeof(struct KeyMap);
- X request->io_Data = (APTR)old;
- X DoIO((struct IORequest *)request);
- X if (request->io_Error)
- X emsg("Cannot reset keymap");
- X else /* no error, free the allocated memory */
- X {
- X UnLoadSeg(segment);
- X FreeMem(old, sizeof(struct KeyMap));
- X segment = (BPTR)NULL;
- X }
- X }
- X if (name != NULL)
- X {
- X segment = LoadSeg(name);
- X if (segment == (BPTR)NULL)
- X {
- X emsg("Cannot open keymap file");
- X return;
- X }
- X old = (struct KeyMap *)AllocMem(sizeof(struct KeyMap), MEMF_PUBLIC);
- X if (old == NULL)
- X {
- X emsg(e_outofmem);
- X UnLoadSeg(segment);
- X segment = (BPTR)NULL;
- X }
- X else
- X {
- X request->io_Command = CD_ASKKEYMAP;
- X request->io_Length = sizeof(struct KeyMap);
- X request->io_Data = (APTR)old;
- X DoIO((struct IORequest *)request);
- X if (request->io_Error)
- X {
- X emsg("Cannot get old keymap");
- X UnLoadSeg(segment);
- X segment = (BPTR)NULL;
- X FreeMem(old, sizeof(struct KeyMap));
- X }
- X else
- X {
- X request->io_Command = CD_SETKEYMAP;
- X request->io_Length = sizeof(struct KeyMap);
- X request->io_Data = (APTR)((segment << 2) + 18);
- X DoIO((struct IORequest *)request);
- X if (request->io_Error)
- X emsg("Cannot set keymap");
- X
- X /* test for blocking */
- X request->io_Command = CMD_READ;
- X request->io_Length = 1;
- X request->io_Data = (APTR)&c;
- X DoIO((struct IORequest *)request); /* BLOCK HERE! */
- X if (request->io_Error)
- X emsg("Cannot set keymap");
- X }
- X }
- X }
- X}
- X#endif
- X
- X#ifndef AZTEC_C
- X/*
- X * Sendpacket.c
- X *
- X * An invaluable addition to your Amiga.lib file. This code sends a packet to
- X * the given message port. This makes working around DOS lots easier.
- X *
- X * Note, I didn't write this, those wonderful folks at CBM did. I do suggest
- X * however that you may wish to add it to Amiga.Lib, to do so, compile it and
- X * say 'oml lib:amiga.lib -r sendpacket.o'
- X */
- X
- X/* #include <proto/exec.h> */
- X/* #include <proto/dos.h> */
- X#include <exec/memory.h>
- X
- X/*
- X * Function - dos_packet written by Phil Lindsay, Carolyn Scheppner, and Andy
- X * Finkel. This function will send a packet of the given type to the Message
- X * Port supplied.
- X */
- X
- X static long
- Xdos_packet(pid, action, arg)
- X struct MsgPort *pid; /* process indentifier ... (handlers message port) */
- X long action, /* packet type ... (what you want handler to do) */
- X arg; /* single argument */
- X{
- X# ifndef NO_ARP
- X struct MsgPort *replyport;
- X struct StandardPacket *packet;
- X long res1;
- X
- X if (dos2)
- X# endif
- X return DoPkt(pid, action, arg, 0L, 0L, 0L, 0L); /* use 2.0 function */
- X# ifndef NO_ARP
- X
- X replyport = (struct MsgPort *) CreatePort(NULL, 0); /* use arp function */
- X if (!replyport)
- X return (0);
- X
- X /* Allocate space for a packet, make it public and clear it */
- X packet = (struct StandardPacket *)
- X AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
- X if (!packet) {
- X DeletePort(replyport);
- X return (0);
- X }
- X packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
- X packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
- X packet->sp_Pkt.dp_Port = replyport;
- X packet->sp_Pkt.dp_Type = action;
- X packet->sp_Pkt.dp_Arg1 = arg;
- X
- X PutMsg(pid, (struct Message *)packet); /* send packet */
- X
- X WaitPort(replyport);
- X GetMsg(replyport);
- X
- X res1 = packet->sp_Pkt.dp_Res1;
- X
- X FreeMem(packet, (long) sizeof(struct StandardPacket));
- X DeletePort(replyport);
- X
- X return (res1);
- X# endif
- X}
- X#endif
- X
- X/*
- X * call shell, return non-zero for failure
- X */
- X int
- Xcall_shell(cmd, filter)
- X char *cmd;
- X int filter; /* if != 0: called by dofilter() */
- X{
- X BPTR mydir;
- X int x;
- X#ifndef LATTICE
- X int use_execute;
- X char *shellcmd = NULL;
- X char *shellarg;
- X#endif
- X int retval = 0;
- X
- X if (close_win)
- X {
- X /* if Vim opened a window: Executing a shell may cause crashes */
- X emsg("Cannot execute shell with -e option");
- X return 1;
- X }
- X
- X if (term_console)
- X win_resize_off(); /* window resize events de-activated */
- X flushbuf();
- X
- X settmode(0); /* set to cooked mode */
- X mydir = Lock((UBYTE *)"", (long)ACCESS_READ); /* remember current directory */
- X
- X#ifdef LATTICE /* not tested very much */
- X if (cmd == NULL)
- X {
- X#ifndef NO_ARP
- X if (dos2)
- X#endif
- X x = SystemTags(p_sh, SYS_UserShell, TRUE, TAG_DONE);
- X#ifndef NO_ARP
- X else
- X x = Execute(p_sh, raw_in, raw_out);
- X#endif
- X }
- X else
- X {
- X#ifndef NO_ARP
- X if (dos2)
- X#endif
- X x = SystemTags(cmd, SYS_UserShell, TRUE, TAG_DONE);
- X#ifndef NO_ARP
- X else
- X x = Execute(cmd, 0L, raw_out);
- X#endif
- X }
- X#ifdef NO_ARP
- X if (x < 0)
- X#else
- X if ((dos2 && x < 0) || (!dos2 && !x))
- X#endif
- X {
- X if (cmd == NULL)
- X smsg("Cannot execute shell %s", p_sh);
- X else
- X smsg("Cannot execute %s", cmd);
- X outchar('\n');
- X retval = 1;
- X }
- X#ifdef NO_ARP
- X else if (x)
- X#else
- X else if (!dos2 || x)
- X#endif
- X {
- X if (x = IoErr())
- X {
- X smsg("%d returned", x);
- X outchar('\n');
- X retval = 1;
- X }
- X }
- X#else
- X if (p_st >= 4 || (p_st >= 2 && !filter))
- X use_execute = 1;
- X else
- X use_execute = 0;
- X if (!use_execute)
- X {
- X /*
- X * separate shell name from argument
- X */
- X shellcmd = strsave(p_sh);
- X if (shellcmd == NULL) /* out of memory, use Execute */
- X use_execute = 1;
- X else
- X {
- X shellarg = shellcmd;
- X skiptospace(&shellarg);
- X *shellarg = NUL;
- X skipspace(&shellarg);
- X }
- X }
- X if (cmd == NULL)
- X {
- X if (use_execute)
- X {
- X#ifndef NO_ARP
- X if (dos2)
- X#endif
- X x = SystemTags((UBYTE *)p_sh, SYS_UserShell, TRUE, TAG_DONE);
- X#ifndef NO_ARP
- X else
- X x = !Execute((UBYTE *)p_sh, raw_in, raw_out);
- X#endif
- X }
- X else
- X x = fexecl(shellcmd, shellcmd, shellarg, NULL);
- X }
- X else if (use_execute)
- X {
- X#ifndef NO_ARP
- X if (dos2)
- X#endif
- X x = SystemTags((UBYTE *)cmd, SYS_UserShell, TRUE, TAG_DONE);
- X#ifndef NO_ARP
- X else
- X x = !Execute((UBYTE *)cmd, 0L, raw_out);
- X#endif
- X }
- X else if (p_st & 1)
- X x = fexecl(shellcmd, shellcmd, shellarg, cmd, NULL);
- X else
- X x = fexecl(shellcmd, shellcmd, shellarg, "-c", cmd, NULL);
- X#ifdef NO_ARP
- X if (x < 0)
- X#else
- X if ((dos2 && x < 0) || (!dos2 && x))
- X#endif
- X {
- X if (use_execute)
- X smsg("Cannot execute %s", cmd == NULL ? p_sh : cmd);
- X else
- X smsg("Cannot execute shell %s", shellcmd);
- X outchar('\n');
- X retval = 1;
- X }
- X else
- X {
- X if (use_execute)
- X {
- X#ifdef NO_ARP
- X if (x)
- X#else
- X if (!dos2 || x)
- X#endif
- X x = IoErr();
- X }
- X else
- X x = wait();
- X if (x)
- X {
- X smsg("%d returned", x);
- X outchar('\n');
- X retval = 1;
- X }
- X }
- X free(shellcmd);
- X#endif
- X
- X if (mydir = CurrentDir(mydir)) /* make sure we stay in the same directory */
- X UnLock(mydir);
- X settmode(1); /* set to raw mode */
- X resettitle();
- X if (term_console)
- X win_resize_on(); /* window resize events activated */
- X return retval;
- X}
- X
- X/*
- X * check for an "interrupt signal"
- X * We only react to a CTRL-C, but also clear the other break signals to avoid trouble
- X * with lattice-c programs.
- X */
- X void
- Xbreakcheck()
- X{
- X if (SetSignal(0L, (long)(SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F)) & SIGBREAKF_CTRL_C)
- X {
- X got_int = TRUE;
- X flush_buffers(); /* remove all typeahead and macro stuff */
- X }
- X}
- X
- X/* this routine causes manx to use this Chk_Abort() rather than it's own */
- X/* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
- X/* is zero). Since we want to check for our own ^C's */
- X
- X#ifdef _DCC
- X#define Chk_Abort chkabort
- X#endif
- X
- X long
- XChk_Abort()
- X{
- X return(0L);
- X}
- X
- X#ifdef WILD_CARDS
- X/*
- X * ExpandWildCard() - this code does wild-card pattern matching using the arp
- X * routines. This is based on WildDemo2.c (found in arp1.1
- X * distribution). That code's copyright follows :
- X *-------------------------------------------------------------------------
- X * WildDemo2.c - Search filesystem for patterns, and separate into directories
- X * and files, sorting each separately using DA lists.
- X *
- X * -+=SDB=+-
- X *
- X * Copyright (c) 1987, Scott Ballantyne
- X * Use and abuse as you please.
- X *
- X * num_pat is number of input patterns
- X * pat is array of pointers to input patterns
- X * num_file is pointer to number of matched file names
- X * file is pointer to array of pointers to matched file names
- X * if file_only is TRUE we match only files, no dirs
- X * if list_notfound is TRUE we include not-found entries (probably locked)
- X * return 0 for success, 1 for error (you may loose some memory)
- X *-------------------------------------------------------------------------
- X */
- X
- X/* #include <arpfunctions.h> */
- Xextern void *malloc __ARGS((size_t)), *calloc __ARGS((size_t, size_t));
- Xstatic int insfile __ARGS((char *));
- Xstatic void freefiles __ARGS((void));
- X
- X#define ANCHOR_BUF_SIZE (512)
- X#define ANCHOR_SIZE (sizeof(struct AnchorPath) + ANCHOR_BUF_SIZE)
- X
- X/*
- X * we use this structure to built a list of file names
- X */
- Xstruct onefile
- X{
- X struct onefile *next;
- X char name[1]; /* really longer */
- X} *namelist = NULL;
- X
- X/*
- X * insert one file into the list of file names
- X * return -1 for failure
- X * return 0 for success
- X */
- X static int
- Xinsfile(name)
- X char *name;
- X{
- X struct onefile *new;
- X
- X new = (struct onefile *)alloc((unsigned)(sizeof(struct onefile) + strlen(name)));
- X if (new == NULL)
- X return -1;
- X strcpy(&(new->name[0]), name);
- X new->next = namelist;
- X namelist = new;
- X return 0;
- X}
- X
- X/*
- X * free a whole list of file names
- X */
- X static void
- Xfreefiles()
- X{
- X struct onefile *p;
- X
- X while (namelist)
- X {
- X p = namelist->next;
- X free(namelist);
- X namelist = p;
- X }
- X}
- X
- XExpandWildCards(num_pat, pat, num_file, file, files_only, list_notfound)
- X int num_pat;
- X char **pat;
- X int *num_file;
- X char ***file;
- X int files_only;
- X int list_notfound;
- X{
- X int i;
- X struct AnchorPath *Anchor;
- X int domatchend = FALSE;
- X LONG Result;
- X struct onefile *p;
- X char *errmsg = NULL;
- X char *starbuf, *sp, *dp;
- X
- X *num_file = 0;
- X *file = (char **)"";
- X
- X /* Get our AnchorBase */
- X Anchor = (struct AnchorPath *) calloc((size_t)1, (size_t)ANCHOR_SIZE);
- X if (!Anchor)
- X goto OUT_OF_MEMORY;
- X Anchor->ap_StrLen = ANCHOR_BUF_SIZE; /* ap_Length not supported anymore */
- X#ifdef APF_DODOT
- X Anchor->ap_Flags = APF_DODOT | APF_DOWILD; /* allow '.' for current dir */
- X#else
- X Anchor->ap_Flags = APF_DoDot | APF_DoWild; /* allow '.' for current dir */
- X#endif
- X
- X for (i = 0; i < num_pat; i++)
- X {
- X#ifndef NO_ARP
- X if (dos2)
- X {
- X#endif
- X /* hack to replace '*' by '#?' */
- X starbuf = alloc((unsigned)(2 * strlen(pat[i]) + 1)); /* maximum required */
- X if (starbuf == NULL)
- X goto OUT_OF_MEMORY;
- X for (sp = pat[i], dp = starbuf; *sp; ++sp)
- X {
- X if (*sp == '*')
- X {
- X *dp++ = '#';
- X *dp++ = '?';
- X }
- X else
- X *dp++ = *sp;
- X }
- X *dp = NUL;
- X Result = MatchFirst((UBYTE *)starbuf, Anchor);
- X free(starbuf);
- X#ifndef NO_ARP
- X }
- X else
- X Result = FindFirst(pat[i], Anchor);
- X#endif
- X domatchend = TRUE;
- X while (Result == 0)
- X {
- X if (!files_only || Anchor->ap_Info.fib_DirEntryType < 0)
- X {
- X (*num_file)++;
- X if (insfile(Anchor->ap_Buf))
- X {
- XOUT_OF_MEMORY:
- X errmsg = "Out of memory";
- X goto Return;
- X }
- X }
- X#ifndef NO_ARP
- X if (dos2)
- X#endif
- X Result = MatchNext(Anchor);
- X#ifndef NO_ARP
- X else
- X Result = FindNext(Anchor);
- X#endif
- X }
- X if (Result == ERROR_BUFFER_OVERFLOW)
- X {
- X errmsg = "ANCHOR_BUF_SIZE too small.";
- X goto Return;
- X }
- X if (Result != ERROR_NO_MORE_ENTRIES)
- X {
- X if (list_notfound) /* put object with error in list */
- X {
- X (*num_file)++;
- X if (insfile(pat[i]))
- X goto OUT_OF_MEMORY;
- X }
- X else if (Result != ERROR_OBJECT_NOT_FOUND)
- X {
- X errmsg = "I/O ERROR";
- X goto Return;
- X }
- X }
- X MatchEnd(Anchor);
- X domatchend = FALSE;
- X }
- X
- X p = namelist;
- X if (p)
- X {
- X *file = (char **) malloc(sizeof(char *) * (*num_file));
- X if (*file == NULL)
- X goto OUT_OF_MEMORY;
- X for (i = *num_file - 1; p; p = p->next, --i)
- X {
- X (*file)[i] = (char *) malloc(strlen(p->name) + 1);
- X if ((*file)[i] == NULL)
- X goto OUT_OF_MEMORY;
- X strcpy((*file)[i], p->name);
- X }
- X }
- XReturn:
- X if (domatchend)
- X MatchEnd(Anchor);
- X if (Anchor)
- X free(Anchor);
- X freefiles();
- X if (errmsg)
- X {
- X emsg(errmsg);
- X *num_file = 0;
- X return 1;
- X }
- X return 0;
- X}
- X
- Xvoid
- XFreeWild(num, file)
- X int num;
- X char **file;
- X{
- X if (file == NULL || num == 0)
- X return;
- X while (num--)
- X free(file[num]);
- X free(file);
- X}
- X
- X int
- Xhas_wildcard(p)
- X char *p;
- X{
- X for ( ; *p; ++p)
- X if (strchr("*?[(~#", *p) != NULL)
- X return 1;
- X return 0;
- X}
- X#endif /* WILD_CARDS */
- X
- X/*
- X * With 2.0 support for reading local environment variables
- X */
- X
- X char *
- Xvimgetenv(var)
- X char *var;
- X{
- X int len;
- X
- X#ifndef NO_ARP
- X if (!dos2)
- X return getenv(var);
- X#endif
- X
- X len = GetVar((UBYTE *)var, (UBYTE *)IObuff, (long)(IOSIZE - 1), (long)0);
- X
- X if (len == -1)
- X return NULL;
- X else
- X return IObuff;
- X}
- END_OF_FILE
- if test 29917 -ne `wc -c <'vim/src/amiga.c'`; then
- echo shar: \"'vim/src/amiga.c'\" unpacked with wrong size!
- fi
- # end of 'vim/src/amiga.c'
- fi
- echo shar: End of archive 17 \(of 23\).
- cp /dev/null ark17isdone
- MISSING=""
- 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
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 23 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- -------------8<----------------8<----------------8<---------------8<--------
- Bram Moolenaar | DISCLAIMER: This note does not
- Oce Nederland B.V., Research & Development | necessarily represent the position
- p.o. box 101, 5900 MA Venlo | of Oce-Nederland B.V. Therefore
- The Netherlands phone +31 77 594077 | no liability or responsibility for
- UUCP: mool@oce.nl fax +31 77 595450 | whatever will be accepted.
-
- exit 0 # Just in case...
-