[net.micro.6809] MicroEMACS OS-9 Part 4 of 7

jimomura@lsuc.UUCP (Jim Omura) (05/04/86)

==========
os.9/public.domain #86, from jimomura, 489 chars, Sat Mar 22 19:32:57 1986

----------
TITLE: 'microEMACS' part 17 'uemacs.hlp'
Instalation:

Os9/68000: 
  Vt52: rename uemacs.mak to makefile and use make.
  Other: Modify makefile to use appropriate terminal module (i.e. ansi)
        rather than the vt52 module.

Os9/6809: See uemacs.mak to see what modules are needed.

Known Problem:
  The 68000 version seems to have problems editing large (or many small)
files (long before memory is exausted).  The malloc routine apperently 
does not work well for many small allocations.  

==========
os.9/public.domain #87, from jimomura, 610 chars, Sat Mar 22 19:35:00 1986

----------
TITLE: 'microEMACS' part 18 'uemacs.mak'
#  makefile for Micro emacs for os9/68000
# temp files on ram disk
CFLAGS = -t=/r0

MAINR  = uemain1.r uemain2.r uemain3.r uemain4.r uemaintable.r
DISPR  = uedisplay1.r uedisplay2.r uedisplay3.r
RESTR  = uebasic.r uebuffer1.r uebuffer2.r uefile1.r uefile2.r uefileio.r \
  ueline1.r ueline2.r uerandom1.r uerandom2.r ueregion.r uesearch.r uespawn.r \
  uetermio.r uevt52.r uewindow.r ueword.r
RFILES = $(MAINR) $(DISPR) $(RESTR)

# use cio libarary
umacs: $(RFILES)
  cc -i $(RFILES) -f=umacs
  
$(MAINR): ueed.h uemain.h
$(DISPR): ueed.h uedisplay.h
$(RESTR): ueed.h


==========
os.9/public.domain #88, from jimomura, 10635 chars, Sat Mar 22 19:52:40 1986

----------
TITLE: 'microEMACS' part 19 'uemain.h'
/* Main header */

#ifdef MAINTABLE
int  currow;       /* Working cursor row   */
int  curcol;       /* Working cursor column  */
int  fillcol;      /* Current fill column  */
int  thisflag;      /* Flags, this command  */
int  lastflag;      /* Flags, last command  */
int  curgoal;      /* Goal column    */
BUFFER *curbp;       /* Current buffer    */
WINDOW *curwp;       /* Current window    */
BUFFER *bheadp;      /* BUFFER listhead   */
WINDOW *wheadp;      /* WINDOW listhead   */
BUFFER *blistp;      /* Buffer list BUFFER   */
short kbdm[NKBDM] = {CTLX|')'};  /* Macro      */
short *kbdmip;      /* Input for above   */
short *kbdmop;      /* Output for above   */
char pat[NPAT];      /* Pattern     */
#else
extern int  currow;       /* Working cursor row   */
extern int  curcol;       /* Working cursor column  */
extern int  fillcol;      /* Current fill column  */
extern int  thisflag;      /* Flags, this command  */
extern int  lastflag;      /* Flags, last command  */
extern int  curgoal;      /* Goal column    */
extern BUFFER *curbp;       /* Current buffer    */
extern WINDOW *curwp;       /* Current window    */
extern BUFFER *bheadp;      /* BUFFER listhead   */
extern WINDOW *wheadp;      /* WINDOW listhead   */
extern BUFFER *blistp;      /* Buffer list BUFFER   */
extern short kbdm[];        /* Macro      */
extern short *kbdmip;      /* Input for above   */
extern short *kbdmop;      /* Output for above   */
extern char pat[];      /* Pattern     */
#endif

typedef struct {
  short k_code;     /* Key code      */
  int (*k_fp)();    /* Routine to handle it   */
}  KEYTAB;

/*
 * Command table.
 * This table is *roughly* in ASCII order, left to right across the
 * characters of the command. This expains the funny location of the
 * control-X commands.
 */
#ifdef MAINTABLE

extern      int ctrlg();                /* Abort out of things          */
extern      int quit();                 /* Quit                         */
extern      int ctlxlp();               /* Begin macro                  */
extern      int ctlxrp();               /* End macro                    */
extern     int  ctlxe();                /* Execute macro                */
extern     int  fileread();             /* Get a file, read only        */
extern     int  filevisit();            /* Get a file, read write       */
extern     int  filewrite();            /* Write a file                 */
extern     int  filesave();             /* Save current file            */
extern     int  filename();             /* Adjust file name             */
extern     int  getccol();              /* Get current column           */
extern     int  gotobol();              /* Move to start of line        */
extern     int  forwchar();             /* Move forward by characters   */
extern     int  gotoeol();              /* Move to end of line          */
extern     int  backchar();             /* Move backward by characters  */
extern     int  forwline();             /* Move forward by lines        */
extern     int  backline();             /* Move backward by lines       */
extern     int  forwpage();             /* Move forward by pages        */
extern     int  backpage();             /* Move backward by pages       */
extern     int  gotobob();              /* Move to start of buffer      */
extern     int  gotoeob();              /* Move to end of buffer        */
extern     int  setfillcol();           /* Set fill column.             */
extern     int  setmark();              /* Set mark                     */
extern     int  swapmark();             /* Swap "." and mark            */
extern     int  forwsearch();           /* Search forward               */
extern     int  backsearch();           /* Search backwards             */
extern     int  showcpos();             /* Show the cursor position     */
#ifndef OS9
extern     int  nextwind();             /* Move to the next window      */
extern     int  prevwind();             /* Move to the previous window  */
extern     int  onlywind();             /* Make current window only one */
extern     int  splitwind();            /* Split current window         */
extern     int  mvdnwind();             /* Move window down             */
extern     int  mvupwind();             /* Move window up               */
extern     int  enlargewind();          /* Enlarge display window.      */
extern     int  shrinkwind();           /* Shrink window.               */
extern     int  listbuffers();          /* Display list of buffers      */
extern     int  usebuffer();            /* Switch a window to a buffer  */
extern     int  killbuffer();           /* Make a buffer go away.       */
#endif
extern     int  reposition();           /* Reposition window            */
extern     int  refresh();              /* Refresh the screen           */
extern     int  twiddle();              /* Twiddle characters           */
extern     int  tab();                  /* Insert tab                   */
extern     int  newline();              /* Insert CR-LF                 */
extern     int  indent();               /* Insert CR-LF, then indent    */
extern     int  openline();             /* Open up a blank line         */
extern     int  deblank();              /* Delete blank lines           */
extern     int  quote();                /* Insert literal               */
extern     int  backword();             /* Backup by words              */
extern     int  forwword();             /* Advance by words             */
extern     int  forwdel();              /* Forward delete               */
extern     int  backdel();              /* Backward delete              */
extern     int  killer();               /* Kill forward                 */
extern     int  yank();                 /* Yank back from killbuffer.   */
extern     int  upperword();            /* Upper case word.             */
extern     int  lowerword();            /* Lower case word.             */
extern     int  upperregion();          /* Upper case region.           */
extern     int  lowerregion();          /* Lower case region.           */
extern     int  capword();              /* Initial capitalize word.     */
extern     int  delfword();             /* Delete forward word.         */
extern     int  delbword();             /* Delete backward word.        */
extern     int  killregion();           /* Kill region.                 */
extern     int  copyregion();           /* Copy region to kill buffer.  */
extern     int  spawncli();             /* Run CLI in a subjob.         */
extern     int  spawn();                /* Run a command in a subjob.   */
extern     int  quickexit();            /* low keystroke style exit.    */

KEYTAB keytab[] = {
  CTRL|'@',    setmark,
  CTRL|'A',    gotobol,
  CTRL|'B',    backchar,
  CTRL|'C',    spawncli,  /* Run CLI in subjob. */
  CTRL|'D',    forwdel,
  CTRL|'E',    gotoeol,
  CTRL|'F',    forwchar,
  CTRL|'G',    ctrlg,
  CTRL|'H',    backdel,
  CTRL|'I',    tab,
  CTRL|'J',    indent,
  CTRL|'K',    killer,
  CTRL|'L',    refresh,
  CTRL|'M',    newline,
  CTRL|'N',    forwline,
  CTRL|'O',    openline,
  CTRL|'P',    backline,
  CTRL|'Q',    quote,   /* Often unreachable */
  CTRL|'R',    backsearch,
  CTRL|'S',    forwsearch, /* Often unreachable */
  CTRL|'T',    twiddle,
  CTRL|'V',    forwpage,
  CTRL|'W',    killregion,
  CTRL|'Y',    yank,
  CTRL|'Z',    quickexit,  /* quick save and exit */
#ifndef OS9
  CTLX|CTRL|'B',   listbuffers,
#endif
  CTLX|CTRL|'C',   quit,   /* Hard quit.   */
  CTLX|CTRL|'F',   filename,
  CTLX|CTRL|'L',   lowerregion,
  CTLX|CTRL|'O',   deblank,
#ifndef OS9
  CTLX|CTRL|'N',   mvdnwind,
  CTLX|CTRL|'P',   mvupwind,
#endif
  CTLX|CTRL|'R',   fileread,
  CTLX|CTRL|'S',   filesave,  /* Often unreachable */
  CTLX|CTRL|'U',   upperregion,
#ifndef OS9
  CTLX|CTRL|'V',   filevisit,
#endif
  CTLX|CTRL|'W',   filewrite,
  CTLX|CTRL|'X',   swapmark,
#ifndef OS9
  CTLX|CTRL|'Z',   shrinkwind,
#endif
  CTLX|'!',    spawn,   /* Run 1 command.  */
  CTLX|'=',    showcpos,
  CTLX|'(',    ctlxlp,
  CTLX|')',    ctlxrp,
#ifndef OS9
  CTLX|'1',    onlywind,
  CTLX|'2',    splitwind,
  CTLX|'B',    usebuffer,
#endif
  CTLX|'E',    ctlxe,
  CTLX|'F',    setfillcol,
#ifndef OS9
  CTLX|'K',    killbuffer,
  CTLX|'N',    nextwind,
  CTLX|'P',    prevwind,
  CTLX|'Z',    enlargewind,
#endif
  META|CTRL|'H',   delbword,
  META|'!',    reposition,
  META|'.',    setmark,
  META|'>',    gotoeob,
  META|'<',    gotobob,
  META|'B',    backword,
  META|'C',    capword,
  META|'D',    delfword,
  META|'F',    forwword,
  META|'L',    lowerword,
  META|'U',    upperword,
  META|'V',    backpage,
#ifndef OS9
  META|'W',    copyregion,
#endif
  META|0x7F,    delbword,
  0x7F,     backdel,
  0,        0 /* Signals end of table */
};
#else
extern KEYTAB keytab[];
#endif

#define NKEYTAB (sizeof(keytab)/sizeof(keytab[0]))

#ifdef RAINBOW

#include "rainbow.h"

/*
 * Mapping table from the LK201 function keys to the internal EMACS character.
 */

short lk_map[][2] = {
  Up_Key,       CTRL+'P',
  Down_Key,      CTRL+'N',
  Left_Key,      CTRL+'B',
  Right_Key,      CTRL+'F',
  Shift+Left_Key,     META+'B',
  Shift+Right_Key,    META+'F',
  Control+Left_Key,    CTRL+'A',
  Control+Right_Key,    CTRL+'E',
  Prev_Scr_Key,     META+'V',
  Next_Scr_Key,     CTRL+'V',
  Shift+Up_Key,     META+'<',
  Shift+Down_Key,     META+'>',
  Cancel_Key,      CTRL+'G',
  Find_Key,      CTRL+'S',
  Shift+Find_Key,     CTRL+'R',
  Insert_Key,      CTRL+'Y',
  Options_Key,     CTRL+'D',
  Shift+Options_Key,    META+'D',
  Remove_Key,      CTRL+'W',
  Shift+Remove_Key,    META+'W',
  Select_Key,      CTRL+'@',
  Shift+Select_Key,    CTLX+CTRL+'X',
  Interrupt_Key,     CTRL+'U',
  Keypad_PF2,      META+'L',
  Keypad_PF3,      META+'C',
  Keypad_PF4,      META+'U',
  Shift+Keypad_PF2,    CTLX+CTRL+'L',
  Shift+Keypad_PF4,    CTLX+CTRL+'U',
  Keypad_1,      CTLX+'1',
  Keypad_2,      CTLX+'2',
  Do_Key,       CTLX+'E',
  Keypad_4,      CTLX+CTRL+'B',
  Keypad_5,      CTLX+'B',
  Keypad_6,      CTLX+'K',
  Resume_Key,      META+'!',
  Control+Next_Scr_Key,   CTLX+'N',
  Control+Prev_Scr_Key,   CTLX+'P',
  Control+Up_Key,     CTLX+CTRL+'P',
  Control+Down_Key,    CTLX+CTRL+'N',
  Help_Key,      CTLX+'=',
  Shift+Do_Key,     CTLX+'(',
  Control+Do_Key,     CTLX+')',
  Keypad_0,      CTLX+'Z',
  Shift+Keypad_0,     CTLX+CTRL+'Z',
  Main_Scr_Key,     CTRL+'C',
  Keypad_Enter,     CTLX+'!',
  Exit_Key,      CTLX+CTRL+'C',
  Shift+Exit_Key,     CTRL+'Z'
  };

#define lk_map_size  (sizeof(lk_map)/2)

#endif

#define NULL 0


==========
os.9/public.domain #89, from jimomura, 4682 chars, Sat Mar 22 19:59:57 1986

----------
TITLE: 'microEMACS' part 20 'uemain1.c'
/*
 * This program is in public domain; written by Dave G. Conroy.
 * This file contains the main driving routine, and some keyboard processing
 * code, for the MicroEMACS screen editor.
 *
 * REVISION HISTORY:
 *
 * 1.0  Steve Wilhite, 30-Nov-85
 *      - Removed the old LK201 and VT100 logic. Added code to support the
 *        DEC Rainbow keyboard (which is a LK201 layout) using the the Level
 *        1 Console In ROM INT. See "rainbow.h" for the function key definitions
.
 *
 * 2.0  George Jones, 12-Dec-85
 *      - Ported to Amiga.
 *
 * 3.0  Bob Santy, 5-Jan-86
 *      - Ported to Tandy Color Computer OS9.
 *      - COCO version has window functions
 *        removed to save memory.
 *      - Source modules split into more,
 *        smaller files.
 * ?.?  Robert Larson
 *      - Os9/68000 version (OSK)
 *      - Fixes to ^X= command   
 */
  
/* #include        <stdio.h> */
#include        "ueed.h"
#ifdef VMS
#include        <ssdef.h>
#define GOOD    (SS$_NORMAL)
#endif

#ifndef GOOD
#define GOOD    0
#endif

#define MAIN1 1
#include "uemain.h"

main(argc, argv)
char    *argv[];
{
        register int    c;
        register int    f;
        register int    n;
        register int    mflag;
        char            bname[NBUFN];

        strcpy(bname, "main");                  /* Work out the name of */
        if (argc > 1)                           /* the default buffer.  */
                makename(bname, argv[1]);
        edinit(bname);                          /* Buffers, windows.    */
        vtinit();                               /* Displays.            */
        if (argc > 1) {
                update();                       /* You have to update   */
                readin(argv[1]);                /* in case "[New file]" */
        }
        lastflag = 0;                           /* Fake last flags.     */
loop:
        update();                               /* Fix up the screen    */
        c = getkey();
        if (mpresf != FALSE) {
                mlerase();
                update();
                if (c == ' ')                   /* ITS EMACS does this  */
                        goto loop;
        }
        f = FALSE;
        n = 1;
        if (c == (CTRL|'U')) {                  /* ^U, start argument   */
                f = TRUE;
                n = 4;                          /* with argument of 4 */
                mflag = 0;                      /* that can be discarded. */
                mlwrite("Arg: 4");
                while ((c=getkey()) >='0' && c<='9' || c==(CTRL|'U') || c=='-'){
                        if (c == (CTRL|'U'))
                                n = n*4;
                        /*
                         * If dash, and start of argument string, set arg.
                         * to -1.  Otherwise, insert it.
                         */
                        else if (c == '-') {
                                if (mflag)
                                        break;
                                n = 0;
                                mflag = -1;
                        }
                        /*
                         * If first digit entered, replace previous argument
                         * with digit and set sign.  Otherwise, append to arg.
                         */
                        else {
                                if (!mflag) {
                                        n = 0;
                                        mflag = 1;
                                }
                                n = 10*n + c - '0';
                        }
                        mlwrite("Arg: %d", (mflag >=0) ? n : (n ? -n : -1));
                }
                /*
                 * Make arguments preceded by a minus sign negative and change
                 * the special argument "^U -" to an effective "^U -1".
                 */
                if (mflag == -1) {
                        if (n == 0)
                                n++;
                        n = -n;
                }
        }
        if (c == (CTRL|'X'))                    /* ^X is a prefix       */
                c = CTLX | getctl();
        if (kbdmip != NULL) {                   /* Save macro strokes.  */
                if (c!=(CTLX|')') && kbdmip>&kbdm[NKBDM-6]) {
                        ctrlg(FALSE, 0);
                        goto loop;
                }
                if (f != FALSE) {
                        *kbdmip++ = (CTRL|'U');
                        *kbdmip++ = n;
                }
                *kbdmip++ = c;
        }
        execute(c, f, n);                       /* Do it.               */
        goto loop;
}

==========
os.9/public.domain #90, from jimomura, 4182 chars, Sat Mar 22 20:06:55 1986

----------
TITLE: 'microEMACS' part 21 'uemain2.c'
/*
 * This program is in public domain; written by Dave G. Conroy.
 * This file contains the main driving routine, and some keyboard processing
 * code, for the MicroEMACS screen editor.
 *
 * REVISION HISTORY:
 *
 * 1.0  Steve Wilhite, 30-Nov-85
 *      - Removed the old LK201 and VT100 logic. Added code to support the
 *        DEC Rainbow keyboard (which is a LK201 layout) using the the Level
 *        1 Console In ROM INT. See "rainbow.h" for the function key definitions
.
 *
 * 2.0  George Jones, 12-Dec-85
 *      - Ported to Amiga.
 */
#include        <stdio.h>
#include        "ueed.h"
#ifdef VMS
#include        <ssdef.h>
#define GOOD    (SS$_NORMAL)
#endif

#ifndef GOOD
#define GOOD    0
#endif

#include "uemain.h"
        
/*
 * This is the general command execution routine. It handles the fake binding
 * of all the keys to "self-insert". It also clears out the "thisflag" word,
 * and arranges to move it to the "lastflag", so that the next command can
 * look at it. Return the status of command.
 */
execute(c, f, n)
int c,f,n;
{
        register KEYTAB *ktp;
        int status;

        status = TRUE;
        ktp = &keytab[0];                       /* Look in key table.   */
        while (ktp->k_code) {
                if (ktp->k_code == c) {
                        thisflag = 0;
                        status = (*ktp->k_fp)(f, n);
                        lastflag = thisflag;
                        return(status);
                }
                ++ktp;
        }

        /*
         * If a space was typed, fill column is defined, the argument is non-
         * negative, and we are now past fill column, perform word wrap.
         */
        if (c == ' ' && fillcol > 0 && n>=0 && getccol(FALSE) > fillcol)
                wrapword();

        if ((c>=0x20 && c<=0x7E)                /* Self inserting.      */
        ||  (c>=0xA0 && c<=0xFE)) {
                if (n <= 0) {                   /* Fenceposts.          */
                        lastflag = 0;
                }
                thisflag = 0;                   /* For the future.      */
                linsert(n, c);
                lastflag = thisflag;
                return(TRUE);
        } else {
                lastflag = 0;                   /* Fake last flags.     */
                return(FALSE);
        }
}

/*
 * Read in a key.
 * Do the standard keyboard preprocessing. Convert the keys to the internal
 * character set.
 */
getkey()
{
        register int    c;

        c = (*term.t_getchar)();
#ifdef DEBUG
        printf("%4X",c);
#endif

#ifdef RAINBOW

        if (c & Function_Key)
                {
                int i;

                for (i = 0; i < lk_map_size; i++)
                        if (c == lk_map[i][0])
                                return lk_map[i][1];
                }
        else if (c == Shift + 015) return CTRL | 'J';
        else if (c == Shift + 0x7F) return META | 0x7F;
#endif

        if (c == METACH) {                      /* Apply M- prefix      */
#ifdef DEBUG
                printf("META");
#endif
                c = getctl();
#ifdef DEBUG
                printf("CTL=%4X",c);
#endif
                return (META | c);
        }

        if (c>=0x00 && c<=0x1F)                 /* C0 control -> C-     */
                c = CTRL | (c+'@');
#ifdef DEBUG
        printf("CTRL=%4X",c);
#endif
        return (c);
}

/*
 * Get a key.
 * Apply control modifications to the read key.
 */
getctl()
{
        register int    c;

        c = (*term.t_getchar)();
        if (c>='a' && c<='z')                   /* Force to upper       */
                c -= 0x20;
        if (c>=0x00 && c<=0x1F)                 /* C0 control -> C-     */
                c = CTRL | (c+'@');
        return (c);
}

/*
 * Fancy quit command, as implemented by Norm. If the current buffer has
 * changed do a write current buffer and exit emacs, otherwise simply exit.
 */
quickexit(f, n)
{
        if ((curbp->b_flag&BFCHG) != 0          /* Changed.             */
        && (curbp->b_flag&BFTEMP) == 0)         /* Real.                */
                filesave(f, n);
        quit(f, n);                             /* conditionally quit   */
}

-- 
James Omura, Barrister & Solicitor, Toronto
ihnp4!utzoo!lsuc!jimomura
Byte Information eXchange: jimomura
(416) 652-3880