home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / accell-text / Part4 < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  38.8 KB

  1. From: ustel@well.UUCP (Mark Hargrove)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i053: Unify TEXT fields from ACCELL Part 4/5
  4. Message-ID: <7221@ncoast.UUCP>
  5. Date: 11 Feb 88 00:52:50 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 53
  9. Submitted-By: "Mark Hargrove" <ustel@well.UUCP>
  10. Archive-Name: accell-text/Part4
  11.  
  12. [Beware of substandard shar.  I saw a man page ripe for chomping.  ++bsa]
  13.  
  14. #!/bin/sh
  15. # to extract, remove the header and type "sh filename"
  16. if `test ! -s ./README`
  17. then
  18. echo "writing ./README"
  19. cat > ./README << '\Rogue\Monster\'
  20.     To change the function key bindings in mgx:
  21.  
  22.     The actual function key bindings are in the file "ttykbd.c", in the
  23. function "ttykeymapinit". All other keys are bound in the "key" array in
  24. the file "symbol.c". If the function you are binding to has already been
  25. mapped (in the "key" array definition), then you only need to use the
  26. function "keydup( KEY fkey, char *function_name)".  If you are adding a
  27. function that has NOT been previously defined in the "key" array, you
  28. must use the function "keyadd( KEY fkey, int (*func)(), char
  29. *function_name)". Things bomb spectacularly if you mess up here! 
  30.  
  31.     The "help" line for function key usage is done using the functions
  32. "modeline" and "rotatmode" in the file "display.c", which is not really
  33. the correct place for a user-accessible function, but I didn't want to
  34. make another global variable, and rebuild the whole program again!. The
  35. help usage attempts to model after the ACCELL function key help, and
  36. should be updated when the function key bindings are changed.
  37.  
  38. \Rogue\Monster\
  39. else
  40.   echo "will not over write ./README"
  41. fi
  42. if `test ! -s ./Makefile`
  43. then
  44. echo "writing ./Makefile"
  45. cat > ./Makefile << '\Rogue\Monster\'
  46. # Makefile for TinyMG.
  47. # This is a very small word-processor, designed to be called from Accell
  48. #  that is based upon MicroGnuEmacs V.1b, but without multi-window support
  49. #  or run-time configurability. (It really ain't emacs anymore!)
  50.  
  51. SHELL   = /bin/sh
  52. # This program needs termcap, not terminfo (not enough function keys)
  53. # On our NCR Tower, libtermcap.a is linked to libterminfo.a, however
  54. #  accell comes with a termcap library, which I copied over into
  55. #  /usr/lib/libscotterm.a (name it as you will - but order is IMPORTANT,
  56. #  as on the Tower, libcurses.a includes terminfo)
  57. LIBS    = -lscottterm -lcurses
  58. BIN    = /usr/lbin
  59. # NCR's implementation of SysV defaults to non-shareable text segments
  60. # this option forces the link of a shareable text segment
  61. LDFLAGS = -Wl,-n
  62. # CDEFS gets defines, and gets passed to lint. CFLAGS gets flags, and doesn't
  63. # get passed to lint.
  64. #
  65. # (Common) compile-time options:
  66. #
  67. #    DO_METAKEY    -- if bit 7 is set for a key, treat like a META key
  68. #    STARTUP        -- look for and handle initialization file
  69. #    XKEYS        -- use termcap function key definitions
  70. #    BACKUP        -- enable "make-backup-files"
  71. #    PREFIXREGION    -- enable function "prefix-region"
  72. #    BIT7EVEN    -- 7-bits/even parity. should be XOR with DO_METAKEY
  73. #    TINY        -- very small version
  74. #
  75. CDEFS    = -DXKEYS -DNOTAB -DMISLOG -DTINY
  76. CFLAGS    = -g $(CDEFS)
  77.  
  78. OBJ =    basic.o buffer.o cinfo.o display.o echo.o extend.o file.o kbd.o \
  79.     line.o main.o random.o region.o search.o symbol.o version.o \
  80.     window.o paragraph.o word.o fileio.o ttyio.o tty.o ttykbd.o spawn.o \
  81.     newlog.o
  82. SRCS =    basic.c buffer.c cinfo.c display.c echo.c extend.c file.c kbd.c \
  83.     line.c main.c random.c region.c search.c symbol.c version.c \
  84.     window.c word.c paragraph.c fileio.c ttyio.c tty.c ttykbd.c spawn.c \
  85.     newlog.c
  86. INCS =    ttydef.h sysdef.h def.h
  87.  
  88. .c.o    :
  89.     $(CC) $(CFLAGS) -c $<
  90.  
  91. mgx    : $(OBJ)
  92.     cc $(CFLAGS) $(LDFLAGS) -o mgx $(OBJ) $(LIBS)
  93.  
  94. lin    : $(SRCS)
  95.     lint $(CDEFS) $(SRCS)
  96.  
  97. $(OBJ)    :    $(INCS)
  98.  
  99. clean    :
  100.     rm -f $(OBJ)
  101.  
  102. install : mgx
  103.     cp mgx $(BIN)
  104.     strip $(BIN)/mgx
  105. \Rogue\Monster\
  106. else
  107.   echo "will not over write ./Makefile"
  108. fi
  109. if `test ! -s ./def.h`
  110. then
  111. echo "writing ./def.h"
  112. cat > ./def.h << '\Rogue\Monster\'
  113. /*
  114.  * This file is the general header file for all parts
  115.  * of the MicroEMACS display editor. It contains all of the
  116.  * general definitions and macros. It also contains some
  117.  * conditional compilation flags. All of the per-system and
  118.  * per-terminal definitions are in special header files.
  119.  * The most common reason to edit this file would be to zap
  120.  * the definition of CVMVAS or BACKUP.
  121.  */
  122. #include    "sysdef.h"        /* Order is critical.        */
  123. #include    "ttydef.h"
  124. #include    <stdio.h>
  125.  
  126. /*
  127.  * If your system and/or compiler does not support the "void" type
  128.  * then define NO_VOID_TYPE in sysdef.h.  In the absence of some
  129.  * other definition for VOID, the default in that case will be to
  130.  * turn it into an int, which works with most compilers that don't
  131.  * support void.  In the absence of any definition of VOID or
  132.  * NO_VOID_TYPE, the default is to assume void is supported, which
  133.  * should be the case for most modern C compilers.
  134.  */
  135.  
  136. #ifdef NO_VOID_TYPE
  137. #  undef VOID
  138. #  define VOID int            /* Default for no void is int */
  139. #else
  140. #ifndef    VOID
  141. #  define VOID void            /* Just use normal void */
  142. #endif /* VOID */
  143. #endif /* NO_VOID_TYPE */
  144.  
  145. /*
  146.  * Table sizes, etc.
  147.  */
  148. #ifdef    HASH
  149. #define    NSHASH    31            /* Symbol table hash size.    */
  150. #endif
  151. #define    NFILEN    80            /* Length, file name.        */
  152. #define    NBUFN    24            /* Length, buffer name.        */
  153. #ifndef NLINE            /* allow it to be defined in makefile */
  154. #define    NLINE    256            /* Length, line.        */
  155. #endif
  156. #define    NKBDM    256            /* Length, keyboard macro.    */
  157. #define    NPAT    80            /* Length, pattern.        */
  158. #define    HUGE    1000            /* A rather large number.    */
  159. #define NSRCH    128            /* Undoable search commands.    */
  160. #define    NXNAME    64            /* Length, extended command.    */
  161. #define    NKNAME    20            /* Length, key names        */
  162. /*
  163.  * Universal.
  164.  */
  165. #define    FALSE    0            /* False, no, bad, etc.        */
  166. #define    TRUE    1            /* True, yes, good, etc.    */
  167. #define    ABORT    2            /* Death, ^G, abort, etc.    */
  168.  
  169. /*
  170.  * These flag bits keep track of
  171.  * some aspects of the last command. The CFCPCN
  172.  * flag controls goal column setting. The CFKILL
  173.  * flag controls the clearing versus appending
  174.  * of data in the kill buffer.
  175.  */
  176. #define    CFCPCN    0x0001            /* Last command was C-P, C-N    */
  177. #define    CFKILL    0x0002            /* Last command was a kill    */
  178.  
  179. /*
  180.  * File I/O.
  181.  */
  182. #define    FIOSUC    0            /* Success.            */
  183. #define    FIOFNF    1            /* File not found.        */
  184. #define    FIOEOF    2            /* End of file.            */
  185. #define    FIOERR    3            /* Error.            */
  186.  
  187. /*
  188.  * Directory I/O.
  189.  */
  190. #define    DIOSUC    0            /* Success.            */
  191. #define    DIOEOF    1            /* End of file.            */
  192. #define    DIOERR    2            /* Error.            */
  193.  
  194. /*
  195.  * Display colors.
  196.  */
  197. #define    CNONE    0            /* Unknown color.        */
  198. #define    CTEXT    1            /* Text color.            */
  199. #define    CMODE    2            /* Mode line color.        */
  200.  
  201. /*
  202.  * global mode
  203.  */
  204. #define    MBSMAP    0x0001            /* Map bs<->del            */
  205. #define MFLOW    0x0002            /* Use ^^ for ^Q and ^/ for ^S    */
  206. #define    MINDENT    0x0004            /* autoindent            */
  207. #define    MFILL    0x0008            /* fill mode            */
  208. #ifdef    NOTAB
  209. #define MNOTAB    0x0010            /* no tab mode            */
  210. #endif
  211. #define MOVRSTK    0x0020            /* insert / over-strike mode    */
  212.  
  213. /*
  214.  * Flags for "eread".
  215.  */
  216. #define    EFFUNC    0x0001            /* Autocomplete functions.    */
  217. #define EFBUF    0x0002            /* Autocomplete buffers.    */
  218. #define EFFILE    0x0004            /* " files (maybe someday)    */
  219. #define    EFAUTO    0x0007            /* Some autocompleteion on    */
  220. #define    EFNEW    0x0008            /* New prompt.            */
  221. #define    EFCR    0x0010            /* Echo CR at end; last read.    */
  222.  
  223. /*
  224.  * Flags for "getkey".
  225.  */
  226. #define KQUOTE    0x0001            /* Get raw character        */
  227. #define    KNOMAC    0x0002            /* Don't record for macros    */
  228. #define    KPROMPT 0x0004            /* do delayed prompting        */
  229.  
  230. /*
  231.  * Flags for "ldelete"/"kinsert"
  232.  */
  233.  
  234. #define KNONE    0
  235. #define KFORW    1
  236. #define KBACK    2
  237.  
  238. /*
  239.  * Keys are represented inside using an 11 bit
  240.  * keyboard code. The transformation between the keys on
  241.  * the keyboard and 11 bit code is done by terminal specific
  242.  * code in the "kbd.c" file. The actual character is stored
  243.  * in 8 bits (DEC multinationals work); there is also a control
  244.  * flag KCTRL, a meta flag KMETA, and a control-X flag KCTLX.
  245.  * ASCII control characters are always represented using the
  246.  * KCTRL form. Although the C0 control set is free, it is
  247.  * reserved for C0 controls because it makes the communication
  248.  * between "getkey" and "getkbd" easier. The funny keys get
  249.  * mapped into the C1 control area. The KEY type is typedefed in
  250.  * sysdef.h, as it may depeond on compiler/machine.
  251.  */
  252. #define    NKEYS    2048            /* 11 bit code.            */
  253.  
  254. #define    METACH    0x1B            /* M- prefix,   Control-[, ESC    */
  255. #define    CTMECH    0x1C            /* C-M- prefix, Control-\    */
  256. #define    EXITCH    0x1D            /* Exit level,  Control-]    */
  257. #define    CTRLCH    0x1E            /* C- prefix,    Control-^    */
  258. #define    HELPCH    0x1F            /* Help key,    Control-_    */
  259.  
  260. #define    KCHAR    0x00FF            /* The basic character code.    */
  261. #define    KCTRL    0x0100            /* Control flag.        */
  262. #define    KMETA    0x0200            /* Meta flag.            */
  263. #define    KCTLX    0x0400            /* Control-X flag.        */
  264.  
  265. #define    KFIRST    0x0080            /* First special.        */
  266. #define    KLAST    0x009F            /* Last special.        */
  267.  
  268. #define    KRANDOM    0x0080            /* A "no key" code.        */
  269. #define    K01    0x0081            /* Use these names to define    */
  270. #define    K02    0x0082            /* the special keys on your    */
  271. #define    K03    0x0083            /* terminal.            */
  272. #define    K04    0x0084
  273. #define    K05    0x0085
  274. #define    K06    0x0086
  275. #define    K07    0x0087
  276. #define    K08    0x0088
  277. #define    K09    0x0089
  278. #define    K0A    0x008A
  279. #define    K0B    0x008B
  280. #define    K0C    0x008C
  281. #define    K0D    0x008D
  282. #define    K0E    0x008E
  283. #define    K0F    0x008F
  284. #define    K10    0x0090
  285. #define    K11    0x0091
  286. #define    K12    0x0092
  287. #define    K13    0x0093
  288. #define    K14    0x0094
  289. #define    K15    0x0095
  290. #define    K16    0x0096
  291. #define    K17    0x0097
  292. #define    K18    0x0098
  293. #define    K19    0x0099
  294. #define    K1A    0x009A
  295. #define    K1B    0x009B
  296. #define    K1C    0x009C
  297. #define    K1D    0x009D
  298. #define    K1E    0x009E
  299. #define    K1F    0x009F
  300.  
  301. #ifndef SEOL        /* needed for OSK, where '\r' == '\n' */
  302. #  define SEOL '\n'
  303. #endif
  304.  
  305. /*
  306.  * These flags, and the macros below them,
  307.  * make up a do-it-yourself set of "ctype" macros that
  308.  * understand the DEC multinational set, and let me ask
  309.  * a slightly different set of questions.
  310.  */
  311. #define    _W    0x01            /* Word.            */
  312. #define    _U    0x02            /* Upper case letter.        */
  313. #define    _L    0x04            /* Lower case letter.        */
  314. #define    _C    0x08            /* Control.            */
  315. #define _P    0x10            /* end of sentence punctuation    */
  316.  
  317. #define    ISWORD(c)    ((cinfo[(c)]&_W)!=0)
  318. #define    ISCTRL(c)    ((cinfo[(c)]&_C)!=0)
  319. #define    ISUPPER(c)    ((cinfo[(c)]&_U)!=0)
  320. #define    ISLOWER(c)    ((cinfo[(c)]&_L)!=0)
  321. #define    ISEOSP(c)    ((cinfo[(c)]&_P)!=0)
  322. #define    TOUPPER(c)    ((c)-0x20)
  323. #define    TOLOWER(c)    ((c)+0x20)
  324.  
  325. /*
  326.  * generally useful thing for chars
  327.  */
  328. #define CCHR(x)        ((x)-'@')
  329.  
  330. /*
  331.  * All repeated structures are kept as linked lists of structures.
  332.  * All of these start with a LIST structure (except lines, which
  333.  * have their own abstraction). This will allow for
  334.  * later conversion to generic list manipulation routines should
  335.  * I decide to do that. it does mean that there are four extra
  336.  * bytes per window. I feel that this is an acceptable price,
  337.  * considering that there are usually only one or two windows.
  338.  */
  339. typedef struct LIST {
  340.     union {
  341.         struct SYMBOL    *l_sp;
  342.         struct WINDOW    *l_wp;
  343.         struct BUFFER    *l_bp;
  344.         struct LIST    *l_nxt;
  345.     } l_p;
  346.     char    *l_name;
  347. } LIST;
  348. /*
  349.  * Usual hack - to keep from uglifying the code with lotsa
  350.  * references through the union, we #define something for it.
  351.  */
  352. #define    l_next    l_p.l_nxt
  353.  
  354. /*
  355.  * The symbol table links editing functions
  356.  * to names. Entries in the key map point at the symbol
  357.  * table entry.
  358.  */
  359. typedef    struct    SYMBOL {
  360.     LIST    s_list;            /* List chain.            */
  361.     int    (*s_funcp)();        /* Function.            */
  362. #ifdef    HASH
  363.     short    s_flags;        /* Flags for this symbol    */
  364. #endif
  365. }    SYMBOL;
  366. #define    s_symp    s_list.l_p.l_sp
  367. #define s_name    s_list.l_name
  368. #ifdef    HASH
  369. #define SFEND    0x001            /* End of has list        */
  370. #endif
  371.  
  372. /*
  373.  * There is a window structure allocated for
  374.  * every active display window. The windows are kept in a
  375.  * big list, in top to bottom screen order, with the listhead at
  376.  * "wheadp". Each window contains its own values of dot and mark.
  377.  * The flag field contains some bits that are set by commands
  378.  * to guide redisplay; although this is a bit of a compromise in
  379.  * terms of decoupling, the full blown redisplay is just too
  380.  * expensive to run for every input character. 
  381.  */
  382. typedef    struct    WINDOW {
  383.     LIST    w_list;            /* List header               */
  384.     struct    BUFFER *w_bufp;        /* Buffer displayed in window    */
  385.     struct    LINE *w_linep;        /* Top line in the window    */
  386.     struct    LINE *w_dotp;        /* Line containing "."        */
  387.     struct    LINE *w_markp;        /* Line containing "mark"    */
  388.     short    w_doto;            /* Byte offset for "."        */
  389.     short    w_marko;        /* Byte offset for "mark"    */
  390.     char    w_toprow;        /* Origin 0 top row of window    */
  391.     char    w_ntrows;        /* # of rows of text in window    */
  392.     char    w_force;        /* If NZ, forcing row.        */
  393.     char    w_flag;            /* Flags.            */
  394. }    WINDOW;
  395. #define    w_wndp    w_list.l_p.l_wp
  396. #define w_name    w_list.l_name
  397.  
  398. /*
  399.  * Window flags are set by command processors to
  400.  * tell the display system what has happened to the buffer
  401.  * mapped by the window. Setting "WFHARD" is always a safe thing
  402.  * to do, but it may do more work than is necessary. Always try
  403.  * to set the simplest action that achieves the required update.
  404.  * Because commands set bits in the "w_flag", update will see
  405.  * all change flags, and do the most general one.
  406.  */
  407. #define    WFFORCE    0x01            /* Force reframe.        */
  408. #define    WFMOVE    0x02            /* Movement from line to line.    */
  409. #define    WFEDIT    0x04            /* Editing within a line.    */
  410. #define    WFHARD    0x08            /* Better to a full display.    */
  411. #define    WFMODE    0x10            /* Update mode line.        */
  412.  
  413. /*
  414.  * Text is kept in buffers. A buffer header, described
  415.  * below, exists for every buffer in the system. The buffers are
  416.  * kept in a big list, so that commands that search for a buffer by
  417.  * name can find the buffer header. There is a safe store for the
  418.  * dot and mark in the header, but this is only valid if the buffer
  419.  * is not being displayed (that is, if "b_nwnd" is 0). The text for
  420.  * the buffer is kept in a circularly linked list of lines, with
  421.  * a pointer to the header line in "b_linep".
  422.  */
  423. typedef    struct    BUFFER {
  424.     LIST    b_list;            /* buffer list pointer        */
  425.     struct    BUFFER *b_altb;        /* Link to alternate buffer    */
  426.     struct    LINE *b_dotp;        /* Link to "." LINE structure    */
  427.     struct    LINE *b_markp;        /* The same as the above two,    */
  428.     struct    LINE *b_linep;        /* Link to the header LINE    */
  429.     short    b_doto;            /* Offset of "." in above LINE    */
  430.     short    b_marko;        /* but for the "mark"        */
  431.     char    b_nwnd;            /* Count of windows on buffer    */
  432.     char    b_flag;            /* Flags            */
  433.     char    b_fname[NFILEN];    /* File name            */
  434. }    BUFFER;
  435. #define    b_bufp    b_list.l_p.l_bp
  436. #define b_bname    b_list.l_name
  437.  
  438. #define    BFCHG    0x01            /* Changed.            */
  439. #define    BFBAK    0x02            /* Need to make a backup.    */
  440.  
  441. /*
  442.  * This structure holds the starting position
  443.  * (as a line/offset pair) and the number of characters in a
  444.  * region of a buffer. This makes passing the specification
  445.  * of a region around a little bit easier.
  446.  */
  447. typedef    struct    {
  448.     struct    LINE *r_linep;        /* Origin LINE address.        */
  449.     short    r_offset;        /* Origin LINE offset.        */
  450.     RSIZE    r_size;            /* Length in characters.    */
  451. }    REGION;
  452.  
  453. /*
  454.  * All text is kept in circularly linked
  455.  * lists of "LINE" structures. These begin at the
  456.  * header line (which is the blank line beyond the
  457.  * end of the buffer). This line is pointed to by
  458.  * the "BUFFER". Each line contains a the number of
  459.  * bytes in the line (the "used" size), the size
  460.  * of the text array, and the text. The end of line
  461.  * is not stored as a byte; it's implied. Future
  462.  * additions will include update hints, and a
  463.  * list of marks into the line.
  464.  */
  465. typedef    struct    LINE {
  466.     struct    LINE *l_fp;        /* Link to the next line    */
  467.     struct    LINE *l_bp;        /* Link to the previous line    */
  468.     short    l_size;            /* Allocated size        */
  469.     short    l_used;            /* Used size            */
  470. #ifdef    PCC
  471.     char    l_text[1];        /* A bunch of characters.    */
  472. #else
  473.     char    l_text[];        /* A bunch of characters.    */
  474. #endif
  475. }    LINE;
  476.  
  477. /*
  478.  * The rationale behind these macros is that you
  479.  * could (with some editing, like changing the type of a line
  480.  * link from a "LINE *" to a "REFLINE", and fixing the commands
  481.  * like file reading that break the rules) change the actual
  482.  * storage representation of lines to use something fancy on
  483.  * machines with small address spaces.
  484.  */
  485. #define    lforw(lp)    ((lp)->l_fp)
  486. #define    lback(lp)    ((lp)->l_bp)
  487. #define    lgetc(lp, n)    ((lp)->l_text[(n)]&0xFF)
  488. #define    lputc(lp, n, c)    ((lp)->l_text[(n)]=(c))
  489. #define    llength(lp)    ((lp)->l_used)
  490. #define    ltext(lp)    ((lp)->l_text)
  491.  
  492. /*
  493.  * Externals.
  494.  */
  495. extern    int    thisflag;
  496. extern    int    lastflag;
  497. extern    int    curgoal;
  498. extern    int    epresf;
  499. extern    int    sgarbf;
  500. extern    int    mode;
  501. extern    WINDOW    *curwp;
  502. extern    BUFFER    *curbp;
  503. extern    WINDOW    *wheadp;
  504. extern    BUFFER    *bheadp;
  505. extern    KEY    kbdm[];
  506. extern    KEY    *kbdmip;
  507. extern    KEY    *kbdmop;
  508. extern    KEY    getkey();
  509. extern    char    pat[];
  510. extern    SYMBOL    *symbol[];
  511. extern    SYMBOL    *binding[];
  512. extern    BUFFER    *bfind();
  513. extern    WINDOW    *popbuf();
  514. extern    WINDOW    *wpopup();
  515. extern    LINE    *lalloc();
  516. extern  int    nrow;
  517. extern  int    ncol;
  518. extern    char    *version;
  519. extern    int    ttrow;
  520. extern    int    ttcol;
  521. extern    int    tceeol;
  522. extern    int    tcinsl;
  523. extern    int    tcdell;
  524. extern    char    cinfo[];
  525. extern    char    *keystrings[];
  526. extern    SYMBOL    *symlookup();
  527. VOID        update();
  528. VOID        keyname();
  529. /*
  530.  * Standard I/O.
  531.  */
  532. extern    char    *strcpy();
  533. extern    char    *strcat();
  534. extern    char    *malloc();
  535. \Rogue\Monster\
  536. else
  537.   echo "will not over write ./def.h"
  538. fi
  539. if `test ! -s ./sysdef.h`
  540. then
  541. echo "writing ./sysdef.h"
  542. cat > ./sysdef.h << '\Rogue\Monster\'
  543. /*
  544.  * Name:    MicroEMACS
  545.  *        Ultrix-32 system header file same for System V.
  546.  * Version:    29
  547.  * Last edit:    05-Feb-86
  548.  * By:        rex::conroy
  549.  *        decvax!decwrl!dec-rhea!dec-rex!conroy
  550.  */
  551. #define    PCC    1            /* "[]" gets an error.        */
  552. #define    KBLOCK    8192            /* Kill grow.            */
  553. #define    GOOD    0            /* Good exit status.        */
  554.  
  555. typedef int    RSIZE;            /* Type for file/region sizes    */
  556. typedef short    KEY;            /* Type for internal keystrokes    */
  557.  
  558. /*
  559.  * Macros used by the buffer name making code.
  560.  * Start at the end of the file name, scan to the left
  561.  * until BDC1 (or BDC2, if defined) is reached. The buffer
  562.  * name starts just to the right of that location, and
  563.  * stops at end of string (or at the next BDC3 character,
  564.  * if defined). BDC2 and BDC3 are mainly for VMS.
  565.  */
  566. #define    BDC1    '/'            /* Buffer names.        */
  567. \Rogue\Monster\
  568. else
  569.   echo "will not over write ./sysdef.h"
  570. fi
  571. if `test ! -s ./ttydef.h`
  572. then
  573. echo "writing ./ttydef.h"
  574. cat > ./ttydef.h << '\Rogue\Monster\'
  575. /*
  576.  *    Termcap terminal file, nothing special, just make it big
  577.  *    enough for windowing systems.
  578.  */
  579.  
  580. #define    GOSLING            /* Compile in fancy display.    */
  581. /* #define    MEMMAP        */    /* Not memory mapped video.    */
  582.  
  583. #define    NROW    66                /* Rows.            */
  584. #define    NCOL    132            /* Columns.            */
  585. /* #define    MOVE_STANDOUT        /* don't move in standout mode    */
  586. #define    STANDOUT_GLITCH            /* possible standout glitch    */
  587. #define    TERMCAP                /* for possible use in ttyio.c    */
  588.  
  589. /*
  590.  * Termcap function keys.  The last 10 keys correspond to the
  591.  * non-standard termcap entries K0-K9 (instead of k0-k9).
  592.  */
  593. #ifdef    XKEYS
  594. /*
  595. #define    KFIRST    K01
  596. #define KLAST    K1A
  597. */
  598. #define KHOME    K01
  599. #define KDOWN    K02
  600. #define    KUP    K03
  601. #define    KLEFT    K04
  602. #define    KRIGHT    K05
  603. #define    KF0    K06
  604. #define    KF1    K07
  605. #define KF2    K08
  606. #define KF3    K09
  607. #define KF4    K0A
  608. #define KF5    K0B
  609. #define KF6    K0C
  610. #define KF7    K0D
  611. #define KF8    K0E
  612. #define    KF9    K0F
  613. #define KF10    K10
  614. #define    KF11    K11
  615. #define    KF12    K12
  616. #define    KF13    K13
  617. #define    KF14    K14
  618. #define    KF15    K15
  619. #define    KF16    K16
  620. #define    KF17    K17
  621. #define    KF18    K18
  622. #define    KF19    K19
  623. #define    KF20    K1A
  624.  
  625. #define    NFKEYS    20        /* # of function keys (k0-k9, K0-K9) */
  626. #endif
  627. \Rogue\Monster\
  628. else
  629.   echo "will not over write ./ttydef.h"
  630. fi
  631. if `test ! -s ./basic.c`
  632. then
  633. echo "writing ./basic.c"
  634. cat > ./basic.c << '\Rogue\Monster\'
  635. /*
  636.  *        Basic cursor motion commands.
  637.  * 
  638.  * The routines in this file are the basic
  639.  * command functions for moving the cursor around on
  640.  * the screen, setting mark, and swapping dot with
  641.  * mark. Only moves between lines, which might make the
  642.  * current buffer framing bad, are hard.
  643.  */
  644. #include    "def.h"
  645.  
  646. VOID    setgoal();
  647.  
  648. /*
  649.  * Go to beginning of line.
  650.  */
  651. /*ARGSUSED*/
  652. gotobol(f, n, k)
  653. {
  654.     curwp->w_doto  = 0;
  655.     return (TRUE);
  656. }
  657.  
  658. /*
  659.  * Move cursor backwards. Do the
  660.  * right thing if the count is less than
  661.  * 0. Error if you try to move back from
  662.  * the beginning of the buffer.
  663.  */
  664. /*ARGSUSED*/
  665. backchar(f, n, k) register int n;
  666. {
  667.     register LINE    *lp;
  668.  
  669.     if (n < 0)
  670.         return (forwchar(f, -n, k));
  671.     while (n--)
  672.     {
  673.         if (curwp->w_doto == 0)
  674.         {
  675.             if ((lp=lback(curwp->w_dotp)) == curbp->b_linep)
  676.             {
  677.                 if (k != KRANDOM)
  678.                     ewprintf("Beginning of buffer");
  679.                 return (FALSE);
  680.             }
  681.             curwp->w_dotp  = lp;
  682.             curwp->w_doto  = llength(lp);
  683.             curwp->w_flag |= WFMOVE;
  684.         }
  685.         else
  686.             curwp->w_doto--;
  687.     }
  688.     return (TRUE);
  689. }
  690.  
  691. /*
  692.  * Go to end of line.
  693.  */
  694. /*ARGSUSED*/
  695. gotoeol(f, n, k)
  696. {
  697.     curwp->w_doto  = llength(curwp->w_dotp);
  698.     return (TRUE);
  699. }
  700.  
  701. /*
  702.  * Move cursor forwards. Do the
  703.  * right thing if the count is less than
  704.  * 0. Error if you try to move forward
  705.  * from the end of the buffer.
  706.  */
  707. /*ARGSUSED*/
  708. forwchar(f, n, k) register int n;
  709. {
  710.     if (n < 0)
  711.         return (backchar(f, -n, k));
  712.     while (n--)
  713.     {
  714.         if (curwp->w_doto == llength(curwp->w_dotp))
  715.         {
  716.             if (curwp->w_dotp == curbp->b_linep)
  717.             {
  718.                 if (k != KRANDOM)
  719.                     ewprintf("End of buffer");
  720.                 return (FALSE);
  721.             }
  722.             curwp->w_dotp  = lforw(curwp->w_dotp);
  723.             curwp->w_doto  = 0;
  724.             curwp->w_flag |= WFMOVE;
  725.         }
  726.         else
  727.             curwp->w_doto++;
  728.     }
  729.     return (TRUE);
  730. }
  731.  
  732. /*
  733.  * Go to the beginning of the
  734.  * buffer. Setting WFHARD is conservative,
  735.  * but almost always the case.
  736.  */
  737. gotobob(f, n, k)
  738. {
  739.     (VOID) setmark(f, n, k) ;
  740.     curwp->w_dotp  = lforw(curbp->b_linep);
  741.     curwp->w_doto  = 0;
  742.     curwp->w_flag |= WFHARD;
  743.     return (TRUE);
  744. }
  745.  
  746. /*
  747.  * Go to the end of the buffer.
  748.  * Setting WFHARD is conservative, but
  749.  * almost always the case.
  750.  */
  751. gotoeob(f, n, k)
  752. {
  753.     (VOID) setmark(f, n, k) ;
  754.     curwp->w_dotp  = curbp->b_linep;
  755.     curwp->w_doto  = 0;
  756.     curwp->w_flag |= WFHARD;
  757.     return (TRUE);
  758. }
  759.  
  760. /*
  761.  * Move forward by full lines.
  762.  * If the number of lines to move is less
  763.  * than zero, call the backward line function to
  764.  * actually do it. The last command controls how
  765.  * the goal column is set.
  766.  */
  767. /*ARGSUSED*/
  768. forwline(f, n, k)
  769. {
  770.     register LINE    *dlp;
  771.  
  772.     if (n < 0)
  773.         return (backline(f, -n, KRANDOM));
  774.     if ((lastflag&CFCPCN) == 0)        /* Fix goal.        */
  775.         setgoal();
  776.     thisflag |= CFCPCN;
  777.     dlp = curwp->w_dotp;
  778.     while (n-- && dlp!=curbp->b_linep)
  779.         dlp = lforw(dlp);
  780.     curwp->w_dotp  = dlp;
  781.     curwp->w_doto  = getgoal(dlp);
  782.     curwp->w_flag |= WFMOVE;
  783.     return (TRUE);
  784. }
  785.  
  786. /*
  787.  * This function is like "forwline", but
  788.  * goes backwards. The scheme is exactly the same.
  789.  * Check for arguments that are less than zero and
  790.  * call your alternate. Figure out the new line and
  791.  * call "movedot" to perform the motion.
  792.  */
  793. /*ARGSUSED*/
  794. backline(f, n, k)
  795. {
  796.     register LINE    *dlp;
  797.  
  798.     if (n < 0)
  799.         return (forwline(f, -n, KRANDOM));
  800.     if ((lastflag&CFCPCN) == 0)        /* Fix goal.        */
  801.         setgoal();
  802.     thisflag |= CFCPCN;
  803.     dlp = curwp->w_dotp;
  804.     while (n-- && lback(dlp)!=curbp->b_linep)
  805.         dlp = lback(dlp);
  806.     curwp->w_dotp  = dlp;
  807.     curwp->w_doto  = getgoal(dlp);
  808.     curwp->w_flag |= WFMOVE;
  809.     return (TRUE);
  810. }
  811.  
  812. /*
  813.  * Set the current goal column,
  814.  * which is saved in the external variable "curgoal",
  815.  * to the current cursor column. The column is never off
  816.  * the edge of the screen; it's more like display then
  817.  * show position.
  818.  */
  819. VOID
  820. setgoal()
  821. {
  822.  
  823.     curgoal = getcolpos() - 1;        /* Get the position.    */
  824.     if (curgoal >= ncol)            /* Chop to tty width.    */
  825.         curgoal = ncol-1;
  826. }
  827.  
  828. /*
  829.  * This routine looks at a line (pointed
  830.  * to by the LINE pointer "dlp") and the current
  831.  * vertical motion goal column (set by the "setgoal"
  832.  * routine above) and returns the best offset to use
  833.  * when a vertical motion is made into the line.
  834.  */
  835. getgoal(dlp) register LINE *dlp;
  836. {
  837.     register int    c;
  838.     register int    col;
  839.     register int    newcol;
  840.     register int    dbo;
  841.  
  842.     col = 0;
  843.     dbo = 0;
  844.     while (dbo != llength(dlp))
  845.     {
  846.         c = lgetc(dlp, dbo);
  847.         newcol = col;
  848.         if (
  849. #ifdef    NOTAB
  850.             !(mode&MNOTAB) &&
  851. #endif
  852.             c == '\t')
  853.             newcol |= 0x07;
  854.         else if (ISCTRL(c) != FALSE)
  855.             ++newcol;
  856.         ++newcol;
  857.         if (newcol > curgoal)
  858.             break;
  859.         col = newcol;
  860.         ++dbo;
  861.     }
  862.     return (dbo);
  863. }
  864.  
  865. #ifndef TINY
  866. /*
  867.  * Scroll forward by a specified number
  868.  * of lines, or by a full page if no argument.
  869.  * The "2" is the window overlap (this is the default
  870.  * value from ITS EMACS). Because the top line in
  871.  * the window is zapped, we have to do a hard
  872.  * update and get it back.
  873.  */
  874. /*ARGSUSED*/
  875. forwpage(f, n, k) register int n;
  876. {
  877.     register LINE    *lp;
  878.  
  879.     if (f == FALSE)
  880.     {
  881.         n = curwp->w_ntrows - 2;    /* Default scroll.    */
  882.         if (n <= 0)            /* Forget the overlap    */
  883.             n = 1;            /* if tiny window.    */
  884.     }
  885.     else if (n < 0)
  886.         return (backpage(f, -n, KRANDOM));
  887. #ifdef    CVMVAS
  888.     else                    /* Convert from pages    */
  889.         n *= curwp->w_ntrows;        /* to lines.        */
  890. #endif
  891.     lp = curwp->w_linep;
  892.     while (n-- && lp!=curbp->b_linep)
  893.         lp = lforw(lp);
  894.     curwp->w_linep = lp;
  895.     curwp->w_dotp  = lp;
  896.     curwp->w_doto  = 0;
  897.     curwp->w_flag |= WFHARD;
  898.     return (TRUE);
  899. }
  900.  
  901. /*
  902.  * This command is like "forwpage",
  903.  * but it goes backwards. The "2", like above,
  904.  * is the overlap between the two windows. The
  905.  * value is from the ITS EMACS manual. The
  906.  * hard update is done because the top line in
  907.  * the window is zapped.
  908.  */
  909. /*ARGSUSED*/
  910. backpage(f, n, k) register int n;
  911. {
  912.     register LINE    *lp;
  913.  
  914.     if (f == FALSE)
  915.     {
  916.         n = curwp->w_ntrows - 2;    /* Default scroll.    */
  917.         if (n <= 0)            /* Don't blow up if the    */
  918.             n = 1;            /* window is tiny.    */
  919.     }
  920.     else if (n < 0)
  921.         return (forwpage(f, -n, KRANDOM));
  922. #ifdef    CVMVAS
  923.     else                    /* Convert from pages    */
  924.         n *= curwp->w_ntrows;        /* to lines.        */
  925. #endif
  926.     lp = curwp->w_linep;
  927.     while (n-- && lback(lp)!=curbp->b_linep)
  928.         lp = lback(lp);
  929.     curwp->w_linep = lp;
  930.     curwp->w_dotp  = lp;
  931.     curwp->w_doto  = 0;
  932.     curwp->w_flag |= WFHARD;
  933.     return (TRUE);
  934. }
  935.  
  936. #endif
  937.  
  938. /* 
  939.  * Internal set mark routine, used by other functions (daveb).
  940.  */
  941. VOID
  942. isetmark()
  943. {
  944.     curwp->w_markp = curwp->w_dotp;
  945.     curwp->w_marko = curwp->w_doto;
  946. }
  947.  
  948. /*
  949.  * Set the mark in the current window
  950.  * to the value of dot. A message is written to
  951.  * the echo line unless we are running in a keyboard
  952.  * macro, when it would be silly.
  953.  */
  954. /*ARGSUSED*/
  955. setmark(f, n, k)
  956. {
  957.     isetmark();
  958.     if (kbdmop == NULL)
  959.         ewprintf("Mark set");
  960.     return (TRUE);
  961. }
  962.  
  963. /*
  964.  * Swap the values of "dot" and "mark" in
  965.  * the current window. This is pretty easy, because
  966.  * all of the hard work gets done by the standard routine
  967.  * that moves the mark about. The only possible
  968.  * error is "no mark".
  969.  */
  970.  
  971. #ifndef TINY
  972. /*ARGSUSED*/
  973. swapmark(f, n, k)
  974. {
  975.     register LINE    *odotp;
  976.     register int    odoto;
  977.  
  978.     if (curwp->w_markp == NULL)
  979.     {
  980.         ewprintf("No mark in this window");
  981.         return (FALSE);
  982.     }
  983.     odotp = curwp->w_dotp;
  984.     odoto = curwp->w_doto;
  985.     curwp->w_dotp  = curwp->w_markp;
  986.     curwp->w_doto  = curwp->w_marko;
  987.     curwp->w_markp = odotp;
  988.     curwp->w_marko = odoto;
  989.     curwp->w_flag |= WFMOVE;
  990.     return (TRUE);
  991. }
  992.  
  993. /*
  994.  * Go to a specific line, mostly for
  995.  * looking up errors in C programs, which give the
  996.  * error a line number. If an argument is present, then
  997.  * it is the line number, else prompt for a line number
  998.  * to use.
  999.  */
  1000. /*ARGSUSED*/
  1001. gotoline(f, n, k) register int n;
  1002. {
  1003.     register LINE    *clp;
  1004.     register int    s;
  1005.     char        buf[32];
  1006.  
  1007.     if (f == FALSE)
  1008.     {
  1009.         if ((s=ereply("Goto line: ", buf, sizeof(buf))) != TRUE)
  1010.             return (s);
  1011.         n = atoi(buf);
  1012.     }
  1013.  
  1014.     clp = lforw(curbp->b_linep);        /* "clp" is first line    */
  1015.     while (n > 1)
  1016.     {
  1017.         if (lforw(clp) == curbp->b_linep) break;
  1018.         clp = lforw(clp);
  1019.         --n;
  1020.     }
  1021.     curwp->w_dotp = clp;
  1022.     curwp->w_doto = 0;
  1023.     curwp->w_flag |= WFMOVE;
  1024.     return (TRUE);
  1025. }
  1026. #endif
  1027. \Rogue\Monster\
  1028. else
  1029.   echo "will not over write ./basic.c"
  1030. fi
  1031. if `test ! -s ./buffer.c`
  1032. then
  1033. echo "writing ./buffer.c"
  1034. cat > ./buffer.c << '\Rogue\Monster\'
  1035. /*
  1036.  *        Buffer handling.
  1037.  */
  1038. #include    "def.h"
  1039.  
  1040. static    itor();
  1041.  
  1042. #ifndef TINY
  1043. /*
  1044.  * Attach a buffer to a window. The
  1045.  * values of dot and mark come from the buffer
  1046.  * if the use count is 0. Otherwise, they come
  1047.  * from some other window.
  1048.  */
  1049. /*ARGSUSED*/
  1050. usebuffer(f, n, k)
  1051. {
  1052.     register BUFFER    *bp;
  1053.     register int    s;
  1054.     char        bufn[NBUFN];
  1055.  
  1056.     /* Get buffer to use from user */
  1057.     if (curbp->b_altb != NULL)
  1058.         s=eread("Switch to buffer: (default %s) ", bufn, NBUFN,
  1059.              EFNEW|EFBUF, 
  1060. #ifdef    VARARGS
  1061.              curbp->b_altb->b_bname
  1062. #else
  1063.              &(curbp->b_altb->b_bname), (char *) NULL
  1064. #endif
  1065.              ) ;
  1066.     else
  1067.         s=eread("Switch to buffer: ", bufn, NBUFN, EFNEW|EFBUF
  1068. #ifndef VARARGS
  1069.              ,(char *) NULL
  1070. #endif
  1071.              );
  1072.     if (s == ABORT)
  1073.         return (s);
  1074.     if (s == FALSE && curbp->b_altb != NULL)
  1075.         bp = curbp->b_altb ;
  1076.     else if ((bp=bfind(bufn, TRUE)) == NULL)
  1077.         return (FALSE);
  1078.  
  1079.     /* and put it in current window */
  1080.     curbp = bp;
  1081.     return showbuffer(bp, curwp, WFFORCE|WFHARD);
  1082. }
  1083.  
  1084. /*
  1085.  * pop to buffer asked for by the user.
  1086.  */
  1087. /*ARGSUSED*/
  1088. poptobuffer(f, n, k)
  1089. {
  1090.     register BUFFER    *bp;
  1091.     register WINDOW    *wp;
  1092.     register int    s;
  1093.     char        bufn[NBUFN];
  1094.     WINDOW        *popbuf();
  1095.  
  1096.     /* Get buffer to use from user */
  1097.     if (curbp->b_altb != NULL)
  1098.         s=eread("Switch to buffer in other window: (default %s) ",
  1099.              bufn, NBUFN, EFNEW|EFBUF, 
  1100. #ifdef    VARARGS
  1101.              curbp->b_altb->b_bname
  1102. #else
  1103.              &(curbp->b_altb->b_bname) ,(char *) NULL
  1104. #endif
  1105.              ) ;
  1106.     else
  1107.         s=eread("Switch to buffer in other window: ", bufn, NBUFN,
  1108.         EFNEW|EFBUF
  1109. #ifndef VARARGS
  1110.         , (char *) NULL
  1111. #endif
  1112.         ) ;
  1113.     if (s == ABORT)
  1114.         return (s);
  1115.     if (s == FALSE && curbp->b_altb != NULL)
  1116.         bp = curbp->b_altb ;
  1117.     else if ((bp=bfind(bufn, TRUE)) == NULL)
  1118.         return (FALSE);
  1119.  
  1120.     /* and put it in a new window */
  1121.     if ((wp = popbuf(bp)) == NULL)
  1122.         return FALSE;
  1123.     curbp = bp;
  1124.     curwp = wp;
  1125.     return TRUE;
  1126. }
  1127.  
  1128. /*
  1129.  * Dispose of a buffer, by name.
  1130.  * Ask for the name. Look it up (don't get too
  1131.  * upset if it isn't there at all!). Clear the buffer (ask
  1132.  * if the buffer has been changed). Then free the header
  1133.  * line and the buffer header. Bound to "C-X K".
  1134.  */
  1135. /*ARGSUSED*/
  1136. killbuffer(f, n, k)
  1137. {
  1138.     register BUFFER    *bp;
  1139.     register BUFFER    *bp1;
  1140.     register BUFFER    *bp2;
  1141.     WINDOW        *wp;
  1142.     register int    s;
  1143.     char        bufn[NBUFN];
  1144.  
  1145.     if ((s=eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW|EFBUF,
  1146. #ifdef    VARARGS
  1147.             curbp->b_bname
  1148. #else
  1149.             &(curbp->b_bname)
  1150. #endif
  1151.             )) == ABORT) return (s);
  1152.     else if (s == FALSE)
  1153.         bp = curbp ;
  1154.     else if ((bp=bfind(bufn, FALSE)) == NULL)
  1155.         return FALSE;
  1156.  
  1157.     if (bp->b_nwnd != 0)
  1158.     {
  1159.         if ((bp1 = bp->b_altb) == NULL) return FALSE;
  1160.         if (bclear(bp) != TRUE) return TRUE;
  1161.         for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp)
  1162.         {
  1163.             /* Special case - could use showbuf, but don't */
  1164.             if (wp->w_bufp == bp)
  1165.             {
  1166.                 --bp->b_nwnd;
  1167.                 ++bp1->b_nwnd;
  1168.                 wp->w_bufp  = bp1 ;
  1169.                 wp->w_dotp  = bp1->b_dotp;
  1170.                 wp->w_doto  = bp1->b_doto;
  1171.                 wp->w_markp = bp1->b_markp;
  1172.                 wp->w_marko = bp1->b_marko;
  1173.                 wp->w_linep = bp1->b_linep;
  1174.                 wp->w_flag |= WFMODE|WFFORCE|WFHARD;
  1175.             }
  1176.         }
  1177.     }
  1178.     else if (bclear(bp) != TRUE)
  1179.         return TRUE;
  1180.     if (bp == curbp)
  1181.         curbp = bp->b_altb;
  1182.     free((char *) bp->b_linep);        /* Release header line.    */
  1183.     bp1 = NULL;                /* Find the header.    */
  1184.     bp2 = bheadp;
  1185.     while (bp2 != bp)
  1186.     {
  1187.         if (bp2->b_altb == bp) 
  1188.             bp2->b_altb = (bp->b_altb == bp2) ? NULL : bp->b_altb;
  1189.         bp1 = bp2;
  1190.         bp2 = bp2->b_bufp;
  1191.     }
  1192.     bp2 = bp2->b_bufp;            /* Next one in chain.    */
  1193.     if (bp1 == NULL)            /* Unlink it.        */
  1194.         bheadp = bp2;
  1195.     else
  1196.         bp1->b_bufp = bp2;
  1197.     while (bp2 != NULL)
  1198.     {            /* Finish with altb's    */
  1199.         if (bp2->b_altb == bp) 
  1200.             bp2->b_altb = (bp->b_altb == bp2) ? NULL : bp->b_altb;
  1201.         bp2 = bp2->b_bufp;
  1202.     }
  1203.     free(bp->b_bname);        /* Release name block    */
  1204.     free((char *) bp);            /* Release buffer block    */
  1205.     return (TRUE);
  1206. }
  1207. #endif
  1208.  
  1209. /*
  1210.  * Save some buffers - just call anycb with the arg flag.
  1211.  */
  1212. /*ARGSUSED*/
  1213. savebuffers(f, n, k)
  1214. {
  1215.     if (anycb(f) == ABORT) return ABORT;
  1216.     return TRUE;
  1217. }
  1218.  
  1219. #ifndef TINY
  1220. /*
  1221.  * Display the buffer list. This is done
  1222.  * in two parts. The "makelist" routine figures out
  1223.  * the text, and puts it in a buffer. "popbuf"
  1224.  * then pops the data onto the screen. Bound to
  1225.  * "C-X C-B".
  1226.  */
  1227. /*ARGSUSED*/
  1228. listbuffers(f, n, k)
  1229. {
  1230.     register BUFFER    *bp;
  1231.     register WINDOW *wp;
  1232.     BUFFER         *makelist();
  1233.         WINDOW          *popbuf();
  1234.  
  1235.     if ((bp=makelist()) == NULL
  1236. #ifndef TINY
  1237.             || (wp=popbuf(bp)) == NULL
  1238. #endif
  1239.                         )
  1240.         return FALSE;
  1241.     wp->w_dotp = bp->b_dotp;    /* fix up if window already on screen */
  1242.     wp->w_doto = bp->b_doto;
  1243.     return TRUE;
  1244. }
  1245.  
  1246. /*
  1247.  * This routine rebuilds the text for the
  1248.  * list buffers command. Return TRUE if
  1249.  * everything works. Return FALSE if there
  1250.  * is an error (if there is no memory).
  1251.  */
  1252. BUFFER *
  1253. makelist()
  1254. {
  1255.     register char    *cp1;
  1256.     register char    *cp2;
  1257.     register int    c;
  1258.     register BUFFER    *bp;
  1259.     LINE        *lp;
  1260.     register RSIZE    nbytes;
  1261.     BUFFER        *blp;
  1262.     char        b[6+1];
  1263.     char        line[128];
  1264.     
  1265.     if ((blp = bfind("*Buffer List*", TRUE)) == NULL) return NULL;
  1266.     if (bclear(blp) != TRUE) return NULL;
  1267.     blp->b_flag &= ~BFCHG;            /* Blow away old.    */
  1268.  
  1269.     (VOID) strcpy(line, " MR Buffer");
  1270.     cp1 = line + 10;
  1271.     while(cp1 < line + 4 + NBUFN + 1) *cp1++ = ' ';
  1272.     (VOID) strcpy(cp1, "Size   File");
  1273.     if (addline(blp, line) == FALSE) return NULL;
  1274.     (VOID) strcpy(line, " -- ------");
  1275.     cp1 = line + 10;
  1276.     while(cp1 < line + 4 + NBUFN + 1) *cp1++ = ' ';
  1277.     (VOID) strcpy(cp1, "----   ----");
  1278.     if (addline(blp, line) == FALSE) return NULL;
  1279.     bp = bheadp;                /* For all buffers    */
  1280.     while (bp != NULL)
  1281.     {
  1282.         cp1 = &line[0];            /* Start at left edge    */
  1283.         *cp1++ = (bp == curbp) ? '.' : ' ';
  1284.         *cp1++ = ((bp->b_flag&BFCHG) != 0) ? '*' : ' ';
  1285.         *cp1++ = ' ';            /* Gap.            */
  1286.         *cp1++ = ' ';
  1287.         cp2 = &bp->b_bname[0];        /* Buffer name        */
  1288.         while ((c = *cp2++) != 0)
  1289.             *cp1++ = c;
  1290.         while (cp1 < &line[4+NBUFN+1])
  1291.             *cp1++ = ' ';        
  1292.         nbytes = 0;            /* Count bytes in buf.    */
  1293.         if (bp != blp)
  1294.         {
  1295.             lp = lforw(bp->b_linep);
  1296.             while (lp != bp->b_linep)
  1297.             {
  1298.                 nbytes += llength(lp)+1;
  1299.                 lp = lforw(lp);
  1300.             }
  1301.         }
  1302.         (VOID) itor(b, 6, nbytes);    /* 6 digit buffer size.    */
  1303.         cp2 = &b[0];
  1304.         while ((c = *cp2++) != 0)
  1305.             *cp1++ = c;
  1306.         *cp1++ = ' ';            /* Gap..            */
  1307.         cp2 = &bp->b_fname[0];        /* File name        */
  1308.         if (*cp2 != 0)
  1309.         {
  1310.             while ((c = *cp2++) != 0)
  1311.             {
  1312.                 if (cp1 < &line[128-1])
  1313.                     *cp1++ = c;
  1314.             }
  1315.         }
  1316.         *cp1 = 0;            /* Add to the buffer.    */
  1317.         if (addline(blp, line) == FALSE)
  1318.             return NULL;
  1319.         bp = bp->b_bufp;
  1320.     }
  1321.     blp->b_dotp = lforw(blp->b_linep);    /* put dot at beginning of buffer */
  1322.     blp->b_doto = 0;
  1323.     return blp;                /* All done        */
  1324. }
  1325.  
  1326. /*
  1327.  * Used above.
  1328.  */
  1329. static itor(buf, width, num)
  1330. register char buf[]; register int width; register RSIZE num;
  1331. {
  1332.     register RSIZE r;
  1333.  
  1334.     if (num / 10 == 0)
  1335.     {
  1336.         buf[0] = (num % 10) + '0';
  1337.         for (r = 1; r < width; buf[r++] = ' ')
  1338.             ;
  1339.         buf[width] = '\0';
  1340.         return 1;
  1341.     }
  1342.     else
  1343.     {
  1344.         buf[r = itor(buf, width, num / (RSIZE)10)] = 
  1345.                 (num % (RSIZE)10) + '0';
  1346.         return r + 1;
  1347.     }
  1348.     /*NOTREACHED*/
  1349. }
  1350.  
  1351. /*
  1352.  * The argument "text" points to
  1353.  * a string. Append this line to the
  1354.  * buffer. Handcraft the EOL
  1355.  * on the end. Return TRUE if it worked and
  1356.  * FALSE if you ran out of room.
  1357.  */
  1358. addline(bp, text) register BUFFER *bp; char *text;
  1359. {
  1360.     register LINE    *lp;
  1361.     register int    i;
  1362.     register int    ntext;
  1363.  
  1364.     ntext = strlen(text);
  1365.     if ((lp=lalloc((RSIZE) ntext)) == NULL)
  1366.         return (FALSE);
  1367.     for (i=0; i<ntext; ++i)
  1368.         lputc(lp, i, text[i]);
  1369.     bp->b_linep->l_bp->l_fp = lp;        /* Hook onto the end    */
  1370.     lp->l_bp = bp->b_linep->l_bp;
  1371.     bp->b_linep->l_bp = lp;
  1372.     lp->l_fp = bp->b_linep;
  1373.     if (bp->b_dotp == bp->b_linep)        /* If "." is at the end    */
  1374.         bp->b_dotp = lp;        /* move it to new line    */
  1375.     if (bp->b_markp == bp->b_linep)        /* ditto for mark     */
  1376.         bp->b_markp = lp;
  1377.     return (TRUE);
  1378. }
  1379. #endif
  1380.  
  1381. /*
  1382.  * Look through the list of buffers, giving the user
  1383.  * a chance to save them.  Return TRUE if there are
  1384.  * any changed buffers afterwards. Buffers that don't
  1385.  * have an associated file don't count. Return FALSE
  1386.  * if there are no changed buffers.
  1387.  */
  1388. anycb(f)
  1389. {
  1390.     register BUFFER    *bp;
  1391.     register int    s = FALSE, save = FALSE;
  1392.     char        prompt[NFILEN + 11];
  1393.  
  1394.     for (bp = bheadp; bp != NULL; bp = bp->b_bufp)
  1395.     {
  1396.         if (*(bp->b_fname) != '\0'
  1397.                     &&  (bp->b_flag&BFCHG) != 0)
  1398.         {
  1399.             (VOID) strcpy(prompt, "Save text before exiting?");
  1400.             if ((f == TRUE || (save = eyorn(prompt)) == TRUE)
  1401.             &&  writeout(bp, bp->b_fname) == TRUE)
  1402.             {
  1403.                 bp->b_flag &= ~BFCHG;
  1404.                 upmodes(bp);
  1405.             }
  1406.             else
  1407.                 s = TRUE;
  1408.             if (save == ABORT)
  1409.                 return (save);
  1410.             save = TRUE;
  1411.         }
  1412.     }
  1413.  
  1414.     return s;
  1415. }
  1416.  
  1417. /*
  1418.  * Search for a buffer, by name.
  1419.  * If not found, and the "cflag" is TRUE,
  1420.  * create a buffer and put it in the list of
  1421.  * all buffers. Return pointer to the BUFFER
  1422.  * block for the buffer.
  1423.  */
  1424. BUFFER    *
  1425. bfind(bname, cflag) register char *bname;
  1426. {
  1427.     register BUFFER    *bp;
  1428.     char        *malloc();
  1429.     register LINE    *lp;
  1430.  
  1431.     bp = bheadp;
  1432.     while (bp != NULL)
  1433.     {
  1434.         if (strcmp(bname, bp->b_bname) == 0)
  1435.             return (bp);
  1436.         bp = bp->b_bufp;
  1437.     }
  1438.     if (cflag!=TRUE) return NULL;
  1439.     /*NOSTRICT*/
  1440.     if ((bp=(BUFFER *)malloc(sizeof(BUFFER))) == NULL)
  1441.     {
  1442.         ewprintf("Can't get %d bytes", sizeof(BUFFER));
  1443.         return NULL;
  1444.     }
  1445.     if ((bp->b_bname=malloc(strlen(bname)+1)) == NULL)
  1446.     {
  1447.         ewprintf("Can't get %d bytes", strlen(bname)+1);
  1448.         free((char *) bp);
  1449.         return NULL;
  1450.     }
  1451.     if ((lp=lalloc((RSIZE) 0)) == NULL)
  1452.     {
  1453.         free(bp->b_bname);
  1454.         free((char *) bp);
  1455.         return NULL;
  1456.     }
  1457.     bp->b_altb = bp->b_bufp  = NULL;
  1458.     bp->b_dotp  = lp;
  1459.     bp->b_doto  = 0;
  1460.     bp->b_markp = NULL;
  1461.     bp->b_marko = 0;
  1462.     bp->b_flag  = 0;
  1463.     bp->b_nwnd  = 0;
  1464.     bp->b_linep = lp;
  1465.     (VOID) strcpy(bp->b_fname, "");
  1466.     (VOID) strcpy(bp->b_bname, bname);
  1467.     lp->l_fp = lp;
  1468.     lp->l_bp = lp;
  1469.     bp->b_bufp = bheadp;
  1470.     bheadp = bp;
  1471.     return (bp);
  1472. }
  1473.  
  1474. /*
  1475.  * This routine blows away all of the text
  1476.  * in a buffer. If the buffer is marked as changed
  1477.  * then we ask if it is ok to blow it away; this is
  1478.  * to save the user the grief of losing text. The
  1479.  * window chain is nearly always wrong if this gets
  1480.  * called; the caller must arrange for the updates
  1481.  * that are required. Return TRUE if everything
  1482.  * looks good.
  1483.  */
  1484. bclear(bp) register BUFFER *bp;
  1485. {
  1486.     register LINE    *lp;
  1487.     register int    s;
  1488.     
  1489.     if ((bp->b_flag&BFCHG) != 0        /* Changed.        */
  1490.     && (s=eyesno("Text modified -- are you sure")) != TRUE)
  1491.         return (s);
  1492.     bp->b_flag  &= ~BFCHG;            /* Not changed        */
  1493.     while ((lp=lforw(bp->b_linep)) != bp->b_linep)
  1494.         lfree(lp);
  1495.     bp->b_dotp  = bp->b_linep;        /* Fix "."        */
  1496.     bp->b_doto  = 0;
  1497.     bp->b_markp = NULL;            /* Invalidate "mark"    */
  1498.     bp->b_marko = 0;
  1499.     return (TRUE);
  1500. }
  1501.  
  1502. /*
  1503.  * Display the given buffer in the given window. Flags indicated
  1504.  * action on redisplay.
  1505.  */
  1506. showbuffer(bp, wp, flags) register BUFFER *bp; register WINDOW *wp;
  1507. {
  1508.     register BUFFER    *obp;
  1509.     WINDOW        *owp;
  1510.  
  1511.     if (wp->w_bufp == bp)
  1512.     {            /* Easy case!    */
  1513.         wp->w_flag |= flags;
  1514.         return TRUE ;
  1515.     }
  1516.  
  1517.     /* First, dettach the old buffer from the window */
  1518.     if ((bp->b_altb = obp = wp->w_bufp) != NULL)
  1519.     {
  1520.         if (--obp->b_nwnd == 0)
  1521.         {
  1522.             obp->b_dotp  = wp->w_dotp;
  1523.             obp->b_doto  = wp->w_doto;
  1524.             obp->b_markp = wp->w_markp;
  1525.             obp->b_marko = wp->w_marko;
  1526.         }
  1527.     }
  1528.  
  1529.     /* Now, attach the new buffer to the window */
  1530.     wp->w_bufp = bp;
  1531.  
  1532.     if (bp->b_nwnd++ == 0)
  1533.     {        /* First use.        */
  1534.         wp->w_dotp  = bp->b_dotp;
  1535.         wp->w_doto  = bp->b_doto;
  1536.         wp->w_markp = bp->b_markp;
  1537.         wp->w_marko = bp->b_marko;
  1538.     }
  1539.     else
  1540.     /* already on screen, steal values from other window */
  1541.         for (owp = wheadp; owp != NULL; owp = wp->w_wndp)
  1542.             if (wp->w_bufp == bp && owp != wp)
  1543.             {
  1544.                 wp->w_dotp  = owp->w_dotp;
  1545.                 wp->w_doto  = owp->w_doto;
  1546.                 wp->w_markp = owp->w_markp;
  1547.                 wp->w_marko = owp->w_marko;
  1548.                 break;
  1549.             }
  1550.     wp->w_flag |= WFMODE|flags;
  1551.     return TRUE;
  1552. }
  1553.  
  1554. /*
  1555.  * Turn off the dirty bit on this buffer.
  1556.  */
  1557. /*ARGSUSED*/
  1558. notmodified(f, n, k)
  1559. {
  1560.     register WINDOW *wp;
  1561.     
  1562.     curbp->b_flag &= ~BFCHG;
  1563.     wp = wheadp;                /* Update mode lines.    */
  1564.     while (wp != NULL)
  1565.     {
  1566.         if (wp->w_bufp == curbp)
  1567.             wp->w_flag |= WFMODE;
  1568.         wp = wp->w_wndp;
  1569.     }
  1570.  
  1571.     return (TRUE);
  1572. }
  1573. \Rogue\Monster\
  1574. else
  1575.   echo "will not over write ./buffer.c"
  1576. fi
  1577. echo "Finished archive 4 of 5"
  1578. exit
  1579. -- 
  1580. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1581. Mark A. Hargrove                                             U.S. TeleCenters
  1582. Voice: 408-496-1800                                          Santa Clara, CA
  1583. uucp : {dual, hoptoad, hplabs, portal, ptsfa}!well!ustel
  1584.