home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3878 < prev    next >
Encoding:
Internet Message Format  |  1991-08-22  |  51.3 KB

  1. Path: wupost!decwrl!amdcad!pyramid!oliveb!olivea!samsung!crackers!m2c!wpi.WPI.EDU!rcarter
  2. From: rcarter@wpi.WPI.EDU (Randolph Carter (nee. Joseph H. Allen))
  3. Newsgroups: alt.sources
  4. Subject: J (Joe's Editor) - Part 1 of 3
  5. Message-ID: <1991Aug22.043241.4493@wpi.WPI.EDU>
  6. Date: 22 Aug 91 04:32:41 GMT
  7. Sender: rcarter@wpi.WPI.EDU (Randolph Carter (nee. Joseph H. Allen))
  8. Organization: Kadath Tours, Inc.
  9. Lines: 2011
  10.  
  11.  
  12. Concatenate the indicated parts of these 3 posts into a file called 'parts'
  13. Make a directory called 'j' and go into it
  14. Type sh ../parts to unpack the archive
  15.  
  16. -- Cut here; take text between this line and the last 'cut' line
  17. # This is a shell archive.  Remove anything before this line,
  18. # then unpack it by saving it in a file and typing "sh file".
  19. #
  20. # Wrapped by Joseph Allen <jallen@libserv1> on Thu Aug 22 00:17:52 1991
  21. #
  22. # This archive contains:
  23. #    COPYING        Makefile    NEWS        README        
  24. #    async.h        asyncbsd.c    asynchpux.c    asyncxenix.c    
  25. #    blocks.c    blocks.h    cruddy.c    j.1        
  26. #    j.c        j.h        keymapbsd    keymapxenix    
  27. #
  28.  
  29. LANG=""; export LANG
  30. PATH=/bin:/usr/bin:$PATH; export PATH
  31.  
  32. echo x - COPYING
  33. cat >COPYING <<'@EOF'
  34.  
  35.             GNU GENERAL PUBLIC LICENSE
  36.              Version 1, February 1989
  37.  
  38.  Copyright (C) 1989 Free Software Foundation, Inc.
  39.                     675 Mass Ave, Cambridge, MA 02139, USA
  40.  Everyone is permitted to copy and distribute verbatim copies
  41.  of this license document, but changing it is not allowed.
  42.  
  43.                 Preamble
  44.  
  45.   The license agreements of most software companies try to keep users
  46. at the mercy of those companies.  By contrast, our General Public
  47. License is intended to guarantee your freedom to share and change free
  48. software--to make sure the software is free for all its users.  The
  49. General Public License applies to the Free Software Foundation's
  50. software and to any other program whose authors commit to using it.
  51. You can use it for your programs, too.
  52.  
  53.   When we speak of free software, we are referring to freedom, not
  54. price.  Specifically, the General Public License is designed to make
  55. sure that you have the freedom to give away or sell copies of free
  56. software, that you receive source code or can get it if you want it,
  57. that you can change the software or use pieces of it in new free
  58. programs; and that you know you can do these things.
  59.  
  60.   To protect your rights, we need to make restrictions that forbid
  61. anyone to deny you these rights or to ask you to surrender the rights.
  62. These restrictions translate to certain responsibilities for you if you
  63. distribute copies of the software, or if you modify it.
  64.  
  65.   For example, if you distribute copies of a such a program, whether
  66. gratis or for a fee, you must give the recipients all the rights that
  67. you have.  You must make sure that they, too, receive or can get the
  68. source code.  And you must tell them their rights.
  69.  
  70.   We protect your rights with two steps: (1) copyright the software, and
  71. (2) offer you this license which gives you legal permission to copy,
  72. distribute and/or modify the software.
  73.  
  74.   Also, for each author's protection and ours, we want to make certain
  75. that everyone understands that there is no warranty for this free
  76. software.  If the software is modified by someone else and passed on, we
  77. want its recipients to know that what they have is not the original, so
  78. that any problems introduced by others will not reflect on the original
  79. authors' reputations.
  80.  
  81.   The precise terms and conditions for copying, distribution and
  82. modification follow.
  83.  
  84.             GNU GENERAL PUBLIC LICENSE
  85.    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  86.  
  87.   0. This License Agreement applies to any program or other work which
  88. contains a notice placed by the copyright holder saying it may be
  89. distributed under the terms of this General Public License.  The
  90. "Program", below, refers to any such program or work, and a "work based
  91. on the Program" means either the Program or any work containing the
  92. Program or a portion of it, either verbatim or with modifications.  Each
  93. licensee is addressed as "you".
  94.  
  95.   1. You may copy and distribute verbatim copies of the Program's source
  96. code as you receive it, in any medium, provided that you conspicuously and
  97. appropriately publish on each copy an appropriate copyright notice and
  98. disclaimer of warranty; keep intact all the notices that refer to this
  99. General Public License and to the absence of any warranty; and give any
  100. other recipients of the Program a copy of this General Public License
  101. along with the Program.  You may charge a fee for the physical act of
  102. transferring a copy.
  103.  
  104.   2. You may modify your copy or copies of the Program or any portion of
  105. it, and copy and distribute such modifications under the terms of Paragraph
  106. 1 above, provided that you also do the following:
  107.  
  108.     a) cause the modified files to carry prominent notices stating that
  109.     you changed the files and the date of any change; and
  110.  
  111.     b) cause the whole of any work that you distribute or publish, that
  112.     in whole or in part contains the Program or any part thereof, either
  113.     with or without modifications, to be licensed at no charge to all
  114.     third parties under the terms of this General Public License (except
  115.     that you may choose to grant warranty protection to some or all
  116.     third parties, at your option).
  117.  
  118.     c) If the modified program normally reads commands interactively when
  119.     run, you must cause it, when started running for such interactive use
  120.     in the simplest and most usual way, to print or display an
  121.     announcement including an appropriate copyright notice and a notice
  122.     that there is no warranty (or else, saying that you provide a
  123.     warranty) and that users may redistribute the program under these
  124.     conditions, and telling the user how to view a copy of this General
  125.     Public License.
  126.  
  127.     d) You may charge a fee for the physical act of transferring a
  128.     copy, and you may at your option offer warranty protection in
  129.     exchange for a fee.
  130.  
  131. Mere aggregation of another independent work with the Program (or its
  132. derivative) on a volume of a storage or distribution medium does not bring
  133. the other work under the scope of these terms.
  134.  
  135.   3. You may copy and distribute the Program (or a portion or derivative of
  136. it, under Paragraph 2) in object code or executable form under the terms of
  137. Paragraphs 1 and 2 above provided that you also do one of the following:
  138.  
  139.     a) accompany it with the complete corresponding machine-readable
  140.     source code, which must be distributed under the terms of
  141.     Paragraphs 1 and 2 above; or,
  142.  
  143.     b) accompany it with a written offer, valid for at least three
  144.     years, to give any third party free (except for a nominal charge
  145.     for the cost of distribution) a complete machine-readable copy of the
  146.     corresponding source code, to be distributed under the terms of
  147.     Paragraphs 1 and 2 above; or,
  148.  
  149.     c) accompany it with the information you received as to where the
  150.     corresponding source code may be obtained.  (This alternative is
  151.     allowed only for noncommercial distribution and only if you
  152.     received the program in object code or executable form alone.)
  153.  
  154. Source code for a work means the preferred form of the work for making
  155. modifications to it.  For an executable file, complete source code means
  156. all the source code for all modules it contains; but, as a special
  157. exception, it need not include source code for modules which are standard
  158. libraries that accompany the operating system on which the executable
  159. file runs, or for standard header files or definitions files that
  160. accompany that operating system.
  161.  
  162.   4. You may not copy, modify, sublicense, distribute or transfer the
  163. Program except as expressly provided under this General Public License.
  164. Any attempt otherwise to copy, modify, sublicense, distribute or transfer
  165. the Program is void, and will automatically terminate your rights to use
  166. the Program under this License.  However, parties who have received
  167. copies, or rights to use copies, from you under this General Public
  168. License will not have their licenses terminated so long as such parties
  169. remain in full compliance.
  170.  
  171.   5. By copying, distributing or modifying the Program (or any work based
  172. on the Program) you indicate your acceptance of this license to do so,
  173. and all its terms and conditions.
  174.  
  175.   6. Each time you redistribute the Program (or any work based on the
  176. Program), the recipient automatically receives a license from the original
  177. licensor to copy, distribute or modify the Program subject to these
  178. terms and conditions.  You may not impose any further restrictions on the
  179. recipients' exercise of the rights granted herein.
  180.  
  181.   7. The Free Software Foundation may publish revised and/or new versions
  182. of the General Public License from time to time.  Such new versions will
  183. be similar in spirit to the present version, but may differ in detail to
  184. address new problems or concerns.
  185.  
  186. Each version is given a distinguishing version number.  If the Program
  187. specifies a version number of the license which applies to it and "any
  188. later version", you have the option of following the terms and conditions
  189. either of that version or of any later version published by the Free
  190. Software Foundation.  If the Program does not specify a version number of
  191. the license, you may choose any version ever published by the Free Software
  192. Foundation.
  193.  
  194.   8. If you wish to incorporate parts of the Program into other free
  195. programs whose distribution conditions are different, write to the author
  196. to ask for permission.  For software which is copyrighted by the Free
  197. Software Foundation, write to the Free Software Foundation; we sometimes
  198. make exceptions for this.  Our decision will be guided by the two goals
  199. of preserving the free status of all derivatives of our free software and
  200. of promoting the sharing and reuse of software generally.
  201.  
  202.                 NO WARRANTY
  203.  
  204.   9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  205. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  206. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  207. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  208. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  209. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  210. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  211. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  212. REPAIR OR CORRECTION.
  213.  
  214.   10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  215. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  216. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  217. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  218. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  219. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  220. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  221. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  222. POSSIBILITY OF SUCH DAMAGES.
  223.  
  224.              END OF TERMS AND CONDITIONS
  225.  
  226.     Appendix: How to Apply These Terms to Your New Programs
  227.  
  228.   If you develop a new program, and you want it to be of the greatest
  229. possible use to humanity, the best way to achieve this is to make it
  230. free software which everyone can redistribute and change under these
  231. terms.
  232.  
  233.   To do so, attach the following notices to the program.  It is safest to
  234. attach them to the start of each source file to most effectively convey
  235. the exclusion of warranty; and each file should have at least the
  236. "copyright" line and a pointer to where the full notice is found.
  237.  
  238.     <one line to give the program's name and a brief idea of what it does.>
  239.     Copyright (C) 19yy  <name of author>
  240.  
  241.     This program is free software; you can redistribute it and/or modify
  242.     it under the terms of the GNU General Public License as published by
  243.     the Free Software Foundation; either version 1, or (at your option)
  244.     any later version.
  245.  
  246.     This program is distributed in the hope that it will be useful,
  247.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  248.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  249.     GNU General Public License for more details.
  250.  
  251.     You should have received a copy of the GNU General Public License
  252.     along with this program; if not, write to the Free Software
  253.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  254.  
  255. Also add information on how to contact you by electronic and paper mail.
  256.  
  257. If the program is interactive, make it output a short notice like this
  258. when it starts in an interactive mode:
  259.  
  260.     Gnomovision version 69, Copyright (C) 19xx name of author
  261.     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  262.     This is free software, and you are welcome to redistribute it
  263.     under certain conditions; type `show c' for details.
  264.  
  265. The hypothetical commands `show w' and `show c' should show the
  266. appropriate parts of the General Public License.  Of course, the
  267. commands you use may be called something other than `show w' and `show
  268. c'; they could even be mouse-clicks or menu items--whatever suits your
  269. program.
  270.  
  271. You should also get your employer (if you work as a programmer) or your
  272. school, if any, to sign a "copyright disclaimer" for the program, if
  273. necessary.  Here a sample; alter the names:
  274.  
  275.   Yoyodyne, Inc., hereby disclaims all copyright interest in the
  276.   program `Gnomovision' (a program to direct compilers to make passes
  277.   at assemblers) written by James Hacker.
  278.  
  279.   <signature of Ty Coon>, 1 April 1989
  280.   Ty Coon, President of Vice
  281.  
  282. That's all there is to it!
  283. @EOF
  284.  
  285. chmod 600 COPYING
  286.  
  287. echo x - Makefile
  288. cat >Makefile <<'@EOF'
  289. # Makefile for Joe's Editor
  290.  
  291. # Directory to install j into
  292. WHERE = /usr/bin
  293.  
  294. # Use these two for 'cc'
  295. CC = cc
  296. CFLAGS = -DKEYDEF=\"$(WHERE)/keymap.j\" -O
  297.  
  298. # Use these two for 'gcc'
  299. #CC = gcc
  300. #CFLAGS = -DKEYDEF=\"$(WHERE)/keymap.j\" -traditional -O
  301.  
  302. foo:
  303.     @echo Type make followed by one of the following
  304.     @echo
  305.     @echo bsd hpux xenix cruddy install clean
  306.  
  307. bsd: j.o asyncbsd.o blocks.o
  308.     $(CC) $(CFLAGS) j.o asyncbsd.o blocks.o -ltermcap -o j
  309.     cp keymapbsd keymap.j
  310.  
  311. xenix: j.o asyncxenix.o blocks.o
  312.     $(CC) $(CFLAGS) j.o asyncxenix.o blocks.o -lx -ltermcap -o j
  313.     cp keymapxenix keymap.j
  314.  
  315. hpux: j.o asynchpux.o blocks.o
  316.     $(CC) $(CFLAGS) j.o asynchpux.o blocks.o -ltermcap -o j
  317.     cp keymapbsd keymap.j
  318.  
  319. cruddy: j.o cruddy.o blocks.o
  320.     $(CC) $(CFLAGS) j.o cruddy.o blocks.o -o j
  321.     cp keymapbsd keymap.j
  322.  
  323. install:
  324.     strip j
  325.     mv j $(WHERE)
  326.     mv keymap.j $(WHERE)
  327.     chmod a+x $(WHERE)/j
  328.     chmod a+r $(WHERE)/keymap.j
  329.  
  330. clean:
  331.     rm asyncbsd.o asyncxenix.o asynchpux.o cruddy.o blocks.o j.o keymap.j
  332.  
  333. asyncbsd.o cruddy.o asyncxenix.o asynxhpux.o : async.h
  334.  
  335. blocks.o : blocks.h
  336.  
  337. j.o : blocks.h j.h async.h
  338. @EOF
  339.  
  340. chmod 600 Makefile
  341.  
  342. echo x - NEWS
  343. cat >NEWS <<'@EOF'
  344.  
  345. Release 0.0.0 of 'J' (Joe's Editor):  This release supersedes all previous
  346. versions which lack a release number.  Note that this program was previously
  347. called 'E' but the name has been changed ('E' turns out to be one of the
  348. synonyms for 'vi').  See below for list of bug fixes and new features.  The
  349. 2 following posts contain the source.
  350.  
  351. Introduction
  352.  
  353.     'J' is a small screen editor which was designed to be easy to use for
  354. novice users but also to be powerful and complete enough for experienced
  355. users.  Several elements of its design are unique innovations.  Here is a
  356. copy of the on-line help text to give you a feel for this editor:
  357.  
  358. GO TO              DELETE    MISC      BLOCK    FIND     QUOTE    WINDOW
  359. ^B left  ^F right ^D single ^T  mode   ^KB mark ^KF text `  Ctrl  ^KO split
  360. ^Z word  ^X word  ^W >word  ^R  retype ^KK end  ^L  next ^\ bit-7 ^KI 1 / all
  361. ^A edge  ^E edge  ^O word<  ^KA center ^KC copy ^KL line FILE     ^KP up
  362. ^P up    ^N down  ^J >line  ^KJ format ^KM move EXIT     ^KD save ^KN down
  363. ^U page  ^V page  ^Y line   ^KZ shell  ^KW save ^KX save ^KR read ^KG grow
  364. ^KU top ^KV end   ^K- undo  ^K, indnt< ^KY kill ^C abort/         ^KT shrink
  365. ^G matching ([<{` ^K+ redo  ^K. indnt>             close window  ^KE get file
  366.  
  367. Other relevent features:
  368.  
  369.     * Extremely small - the XENIX version is only 58K
  370.  
  371.     * Help text can be left on while editing
  372.  
  373.     * Key layout designed to eliminate headaches: ^Q and ^S are not used,
  374.       both ^H and DEL are backspace.  Also, each user may customize
  375.       his key layout by modifying a simple initialization file
  376.  
  377.     * Versions for BSD, HPUX and XENIX 386 are included.  A simple tty
  378.       driver is also provided to ease porting to other systems
  379.  
  380.     * Currently only VT100/ANSI terminals are supported.  If the terminal
  381.       has scrolling regions, J uses them.  Has well-tuned interruptable
  382.       screen update algorithm
  383.  
  384.     * Has: autoindent, word-wrap, overtype/insert, picture mode (right-
  385.       arrow makes space past ends of lines), right margin (for paragraph
  386.       formatting and center), and magic tabs (the column number of text
  387.       after tab stops is preserved when inserting and deleting)
  388.  
  389.     * The cursor column doesn't 'jump' when you move between long and
  390.       short lines.  Instead the cursor column only jumps when you try to
  391.       edit in an invalid place or if picture mode is set, the invalid
  392.       place is made real by space filling
  393.  
  394.     * Editor modes can be set depending on file extension
  395.  
  396.     * No line length restrictions.  Binary files can be edited without
  397.       difficulty
  398.  
  399.     * Long lines are truncated, not wrapped (I.E., the screen scrolls to
  400.       the right to get to the truncated parts)
  401.  
  402. FIXES FOR THIS VERSION
  403.  
  404.     * Shell escape lock-ups are fixed
  405.  
  406.     * Paragraph reformat glitch is fixed
  407.  
  408.     * Cursor update screwynesses fixed for picture mode
  409.  
  410.     * Goto next word/Goto previous word/Delete word left and Delete word
  411.       right were made more consistant
  412.  
  413. NEW FEATURES FOR THIS VERSION
  414.  
  415.     * ~ can be used at file name prompts to expand user home directories
  416.  
  417.     * J now has undelete and redelete (you can go backwards and forewards
  418.       through the delete buffer to select which text you want to undelete)
  419.  
  420.     * J now has indent functions.  A marked block can be indented more
  421.       or less. If you use an indent function outside a marked block, the
  422.       lines with the same or greater indent level surrounding the cursor
  423.       are marked
  424.  
  425.     * Right margin was added for paragraph format and center line
  426.  
  427.     * Goto matching parenthasis (or [ { ` < )
  428.  
  429.     * ` was made the quote control character key because ^_ is not easy
  430.       generate on many keyboard.  `` gets `
  431.  
  432.     * tty drivers were rewritten.  This made the screen update faster
  433.       (now the screen update is instantaneous on 20MHz 386s).  Screen
  434.       update preempting also works better
  435.  
  436. THE PLAN
  437.  
  438.     Version 1.0.0 will be a complete rewrite.  It should be done sometime
  439. before january.  These are my goals for it:
  440.  
  441.     * Block oriented software virtual memory support (for less thrashing
  442.       and elimination of file size limits caused by the system's process
  443.       size limit)
  444.  
  445.     * MS-DOS support
  446.  
  447.     * X windows support
  448.  
  449.     * Better integration with UNIX:  J will be able to process text
  450.       through pipes (like vi), will have standard unix regular expressions,
  451.       and will be usable as a 'more' program.
  452.  
  453.     * Will be terminal independant and use termcap and terminfo
  454.  
  455.     * Will have a ASCII/HEX dump display mode
  456.  
  457.     * Will have complete program developement support (save&make, next
  458.       error/previous error, tags file support)
  459.  
  460.     * Will have a much more powerful scrolling algorithm.  I have a
  461.       methode which is simpler and faster than even GNU-EMACS' Gosling
  462.       algorithm
  463.  
  464.     * All of this will require no changes to the basic keyboard layout-
  465.       maybe one more added line of help text for new things
  466.  
  467.     * It will probably have keyboard macros but it won't have much of
  468.       an extension language.  Maybe in version 2.0.0
  469.  
  470.     * I expect all of this not to add more than 30 or 40% to the size
  471.  
  472.         Joseph H. Allen
  473.         28 Dale Lane
  474.         Smithtown, N.Y. 11787
  475.  
  476. /*  rcarter@wpi.wpi.edu */      /* Amazing */             /* Joseph H. Allen */
  477. int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
  478. +r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2
  479. ]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}
  480. @EOF
  481.  
  482. chmod 600 NEWS
  483.  
  484. echo x - README
  485. cat >README <<'@EOF'
  486. If you don't know what this is, read the NEWS file.
  487.  
  488. To compile:
  489.  
  490.     (1) Determine where you want to install the editor program and the
  491.         system default keymap file.  Put this path in the Makefile.  If
  492.         you're a mere user, don't worry about this.  Instead, place a copy
  493.         of the 'keymap.j' file (created after you make) in your home
  494.         directory. 
  495.  
  496.     (2) type 'make xenix' for xenix systems, 'make hpux' for hpux systems
  497.         or 'make bsd' for BSD systems.  If none of these work, type
  498.         'make cruddy' to make a version with an inferior terminal driver.
  499.  
  500.     (3) To install it in the system, log in as superuser and do
  501.         'make install'
  502. @EOF
  503.  
  504. chmod 600 README
  505.  
  506. echo x - async.h
  507. cat >async.h <<'@EOF'
  508. /* Terminal interface header file
  509.    Copyright (C) 1991 Joseph H. Allen
  510.  
  511. This file is part of J (Joe's Editor)
  512.  
  513. J is free software; you can redistribute it and/or modify it under the terms
  514. of the GNU General Public License as published by the Free Software
  515. Foundation; either version 1, or (at your option) any later version. 
  516.  
  517. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  518. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  519. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  520.  
  521. You should have received a copy of the GNU General Public License
  522. along with GNU Emacs; see the file COPYING.  If not, write to
  523. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  524.  
  525. aopen();                /* Set terminal to raw (character at a time) mode */
  526. aclose();               /* Restore terminal to cooked (line at a time) mode */
  527. aflush();               /* Flush the output */
  528. anext();                /* Get next key */
  529.  
  530. extern int have;    /* Set if there is typeahead */
  531.  
  532. /* All of the above functions do a fflush(stdout) before doing anything else */
  533.  
  534. eputs();        /* Write string to terminal */
  535. eputc();        /* Write character to terminal */
  536.  
  537. shell();        /* Shell escape */
  538. tsignal();              /* E's signal handler.  This function saves the current
  539.                            edit file in .cut.e and then exists some signals
  540.                            might be set up to call this */
  541.  
  542. termtype();             /* Determine the following terminal parameters */
  543.  
  544. extern int width;       /* Screen width */
  545. extern int height;      /* Screen height */
  546. extern int scroll;      /* Set=use scrolling regions, Clr=don't use them */
  547.  
  548. /* If termtype does nothing, these value defualt to: width=80, height=24,
  549.    scroll=1 (true).
  550.  
  551.    Note that the only terminal type supported is ANSI/VT100
  552.  */
  553.  
  554.  
  555. /* For Best operation:
  556.  *
  557.  *    acheck  returns true if the user typed ahead
  558.  *
  559.  *    acheck  should sleep (nap) for number*(10000/baud) milliseconds
  560.  *            immediately after its fflush(stdout) call.  Number is
  561.  *            the number of characters the call to fflush(stdout)
  562.  *            wrote.
  563.  *
  564.  *    aopen & aclose should not loose any typeahead when they change modes
  565.  *
  566.  * For example:  see the async*.c files
  567.  */
  568.  
  569. /* For O.K. operation:
  570.  *
  571.  *    acheck  always returns 0 (false).  If acheck is going to do this, don't
  572.  *            even have it fflush(stdout).
  573.  *
  574.  *    aopen & aclose do system("/bin/stty ...."); so they invariably loose
  575.  *                   any typeahead
  576.  *
  577.  * For example: see the cruddy.c file
  578.  */
  579. @EOF
  580.  
  581. chmod 600 async.h
  582.  
  583. echo x - asyncbsd.c
  584. cat >asyncbsd.c <<'@EOF'
  585. /* Terminal interface for BSD
  586.    Copyright (C) 1991 Joseph H. Allen
  587.  
  588. This file is part of J (Joe's Editor)
  589.  
  590. J is free software; you can redistribute it and/or modify it under the terms
  591. of the GNU General Public License as published by the Free Software
  592. Foundation; either version 1, or (at your option) any later version. 
  593.  
  594. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  595. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  596. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  597.  
  598. You should have received a copy of the GNU General Public License
  599. along with GNU Emacs; see the file COPYING.  If not, write to
  600. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  601.  
  602. #include <sgtty.h>
  603. #include <fcntl.h>
  604. #include <stdio.h>
  605. #include <signal.h>
  606. #include <sys/time.h>
  607. #include "async.h"
  608.  
  609. #define HZ 10            /* Clock ticks/second */
  610.  
  611. #define DIVISOR 11000000    /* The baud rate divided into this should
  612.                    give the number of microseconds per
  613.                    character.  It should attempt to
  614.                    reflect the true throughput, which is
  615.                    usually slower than the best possible
  616.                    for a given baud rate */
  617.  
  618. #define TIMES 3            /* Times per second that we check for
  619.                    typeahead */
  620.  
  621. static struct sgttyb oarg;
  622. static struct tchars otarg;
  623. static struct ltchars oltarg;
  624.  
  625. static unsigned char *obuf=0;
  626. static unsigned obufp=0;
  627. static unsigned obufsiz;
  628. static unsigned long ccc;
  629.  
  630. static unsigned speeds[]=
  631. {
  632. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  633. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400
  634. };
  635.  
  636. aopen()
  637. {
  638. int x;
  639. struct sgttyb arg;
  640. struct tchars targ;
  641. struct ltchars ltarg;
  642. fflush(stdout);
  643. signal(SIGHUP,tsignal);
  644. signal(SIGINT,SIG_IGN);
  645. signal(SIGQUIT,SIG_IGN);
  646. signal(SIGPIPE,SIG_IGN);
  647. signal(SIGALRM,SIG_IGN);
  648. signal(SIGTERM,tsignal);
  649. signal(SIGUSR1,SIG_IGN);
  650. signal(SIGUSR2,SIG_IGN);
  651. ioctl(fileno(stdin),TIOCGETP,&arg);
  652. ioctl(fileno(stdin),TIOCGETC,&targ);
  653. ioctl(fileno(stdin),TIOCGLTC,<arg);
  654. oarg=arg; otarg=targ; oltarg=ltarg;
  655. arg.sg_flags=( (arg.sg_flags&~(ECHO|CRMOD) ) | CBREAK) ;
  656. targ.t_intrc= -1;
  657. targ.t_quitc= -1;
  658. targ.t_eofc= -1;
  659. targ.t_brkc= -1;
  660. ltarg.t_suspc= -1;
  661. ltarg.t_dsuspc= -1;
  662. ltarg.t_rprntc= -1;
  663. ltarg.t_flushc= -1;
  664. ltarg.t_werasc= -1;
  665. ltarg.t_lnextc= -1;
  666. ioctl(fileno(stdin),TIOCSETN,&arg);
  667. ioctl(fileno(stdin),TIOCSETC,&targ);
  668. ioctl(fileno(stdin),TIOCSLTC,<arg);
  669. ccc=0;
  670. for(x=0;x!=30;x+=2)
  671.  if(arg.sg_ospeed==speeds[x])
  672.   {
  673.   ccc=DIVISOR/speeds[x+1];
  674.   break;
  675.   }
  676. if(!obuf)
  677.  {
  678.  if(!(TIMES*ccc)) obufsiz=4096;
  679.  else
  680.   {
  681.   obufsiz=1000000/(TIMES*ccc);
  682.   if(obufsiz>4096) obufsiz=4096;
  683.   }
  684.  if(!obufsiz) obufsiz=1;
  685.  obuf=(unsigned char *)malloc(obufsiz);
  686.  }
  687. }
  688.  
  689. aclose()
  690. {
  691. aflush();
  692. ioctl(fileno(stdin),TIOCSETN,&oarg);
  693. ioctl(fileno(stdin),TIOCSETC,&otarg);
  694. ioctl(fileno(stdin),TIOCSLTC,&oltarg);
  695. signal(SIGHUP,SIG_DFL);
  696. signal(SIGINT,SIG_DFL);
  697. signal(SIGQUIT,SIG_DFL);
  698. signal(SIGPIPE,SIG_DFL);
  699. signal(SIGALRM,SIG_DFL);
  700. signal(SIGTERM,SIG_DFL);
  701. signal(SIGUSR1,SIG_DFL);
  702. signal(SIGUSR2,SIG_DFL);
  703. }
  704.  
  705. int have=0;
  706. static unsigned char havec;
  707. static int yep;
  708.  
  709. static dosig()
  710. {
  711. yep=1;
  712. }
  713.  
  714. aflush()
  715. {
  716. if(obufp)
  717.  {
  718.  struct itimerval a,b;
  719.  unsigned long usec=obufp*ccc;
  720.  if(usec>=500000/HZ)
  721.   {
  722.   a.it_value.tv_sec=usec/1000000;
  723.   a.it_value.tv_usec=usec%1000000;
  724.   a.it_interval.tv_usec=0;
  725.   a.it_interval.tv_sec=0;
  726.   signal(SIGALRM,dosig);
  727.   yep=0;
  728.   sigsetmask(sigmask(SIGALRM));
  729.   setitimer(ITIMER_REAL,&a,&b);
  730.   write(fileno(stdout),obuf,obufp);
  731.   while(!yep) sigpause(0);
  732.   signal(SIGALRM,SIG_DFL);
  733.   }
  734.  else write(fileno(stdout),obuf,obufp);
  735.  obufp=0;
  736.  }
  737. if(!have)
  738.  {
  739.  fcntl(fileno(stdin),F_SETFL,FNDELAY);
  740.  if(read(fileno(stdin),&havec,1)==1) have=1;
  741.  fcntl(fileno(stdin),F_SETFL,0);
  742.  }
  743. }
  744.  
  745. anext()
  746. {
  747. aflush();
  748. if(have) have=0;
  749. else if(read(fileno(stdin),&havec,1)<1) tsignal();
  750. return havec;
  751. }
  752.  
  753. eputc(c)
  754. unsigned char c;
  755. {
  756. obuf[obufp++]=c;
  757. if(obufp==obufsiz) aflush();
  758. }
  759.  
  760. eputs(s)
  761. char *s;
  762. {
  763. while(*s)
  764.  {
  765.  obuf[obufp++]= *(s++);
  766.  if(obufp==obufsiz) aflush();
  767.  }
  768. }
  769.  
  770. termtype()
  771. {
  772. unsigned char entry[1024];
  773. unsigned char area[1024];
  774. unsigned char *foo=area;
  775. unsigned char *x=(unsigned char *)getenv("TERM");
  776. if(!x) return;
  777. if(tgetent(entry,x)!=1) return;
  778. height=tgetnum("li");
  779. if(height<2) height=24;
  780. width=tgetnum("co");
  781. if(width<2) width=80;
  782. if(!tgetstr("cs",&foo)) scroll=0;
  783. }
  784.  
  785. shell(s)
  786. char *s;
  787. {
  788. aclose();
  789. if(fork()) wait(0);
  790. else
  791.  {
  792.  execl(s,s,0);
  793.  _exit(0);
  794.  }
  795. aopen();
  796. }
  797. @EOF
  798.  
  799. chmod 600 asyncbsd.c
  800.  
  801. echo x - asynchpux.c
  802. cat >asynchpux.c <<'@EOF'
  803. /* Terminal interface for HPUX
  804.    Copyright (C) 1991 Joseph H. Allen
  805.  
  806. This file is part of J (Joe's Editor)
  807.  
  808. J is free software; you can redistribute it and/or modify it under the terms
  809. of the GNU General Public License as published by the Free Software
  810. Foundation; either version 1, or (at your option) any later version. 
  811.  
  812. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  813. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  814. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  815.  
  816. You should have received a copy of the GNU General Public License
  817. along with GNU Emacs; see the file COPYING.  If not, write to
  818. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  819.  
  820. #include <stdio.h>
  821. #include <signal.h>
  822. #include <fcntl.h>
  823. #include <time.h>
  824. #include <sys/param.h>
  825. #include <termio.h>
  826. #include "async.h"
  827.  
  828. #define DIVISOR 12000000
  829. #define TIMES 2
  830.  
  831. static struct termio oldterm;
  832.  
  833. static unsigned char *obuf=0;
  834. static unsigned obufp=0;
  835. static unsigned obufsiz;
  836. static unsigned long ccc;
  837.  
  838. static unsigned speeds[]=
  839. {
  840. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  841. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400
  842. };
  843.  
  844. aopen()
  845. {
  846. int x;
  847. struct termio newterm;
  848. fflush(stdout);
  849. signal(SIGHUP,tsignal);
  850. signal(SIGINT,SIG_IGN);
  851. signal(SIGQUIT,SIG_IGN);
  852. signal(SIGPIPE,SIG_IGN);
  853. signal(SIGALRM,SIG_IGN);
  854. signal(SIGTERM,tsignal);
  855. signal(SIGUSR1,SIG_IGN);
  856. signal(SIGUSR2,SIG_IGN);
  857. signal(SIGPWR,tsignal);
  858. ioctl(fileno(stdin),TCGETA,&oldterm);
  859. newterm=oldterm;
  860. newterm.c_lflag=0;
  861. newterm.c_iflag=IXON|IXOFF|IGNBRK;
  862. newterm.c_oflag=0;
  863. newterm.c_cc[VINTR]= -1;
  864. newterm.c_cc[VQUIT]= -1;
  865. newterm.c_cc[VMIN]=1;
  866. newterm.c_cc[VTIME]=0;
  867. ioctl(fileno(stdin),TCSETAW,&newterm);
  868. ccc=0;
  869. for(x=0;x!=30;x+=2)
  870.  if((newterm.c_cflag&CBAUD)==speeds[x])
  871.   {
  872.   ccc=DIVISOR/speeds[x+1];
  873.   break;
  874.   }
  875. if(!obuf)
  876.  {
  877.  if(!(TIMES*ccc)) obufsiz=4096;
  878.  else
  879.   {
  880.   obufsiz=1000000/(TIMES*ccc);
  881.   if(obufsiz>4096) obufsiz=4096;
  882.   }
  883.  if(!obufsiz) obufsiz=1;
  884.  obuf=(unsigned char *)malloc(obufsiz);
  885.  }
  886. }
  887.  
  888. aclose()
  889. {
  890. aflush();
  891. ioctl(fileno(stdin),TCSETAW,&oldterm);
  892. signal(SIGHUP,SIG_DFL);
  893. signal(SIGINT,SIG_DFL);
  894. signal(SIGQUIT,SIG_DFL);
  895. signal(SIGPIPE,SIG_DFL);
  896. signal(SIGALRM,SIG_DFL);
  897. signal(SIGTERM,SIG_DFL);
  898. signal(SIGUSR1,SIG_DFL);
  899. signal(SIGUSR2,SIG_DFL);
  900. signal(SIGPWR,SIG_DFL);
  901. }
  902.  
  903. int have=0;
  904. static unsigned char havec;
  905. static int yep;
  906.  
  907. static dosig()
  908. {
  909. yep=1;
  910. }
  911.  
  912. aflush()
  913. {
  914. if(obufp)
  915.  {
  916.  struct itimerval a,b;
  917.  unsigned long usec=obufp*ccc;
  918.  if(usec>=500000/HZ)
  919.   {
  920.   a.it_value.tv_sec=usec/1000000;
  921.   a.it_value.tv_usec=usec%1000000;
  922.   a.it_interval.tv_usec=0;
  923.   a.it_interval.tv_sec=0;
  924.   signal(SIGALRM,dosig);
  925.   yep=0;
  926.   sigsetmask(sigmask(SIGALRM));
  927.   setitimer(ITIMER_REAL,&a,&b);
  928.   write(fileno(stdout),obuf,obufp);
  929.   while(!yep) sigpause(0);
  930.   signal(SIGALRM,SIG_DFL);
  931.   }
  932.  else write(fileno(stdout),obuf,obufp);
  933.  obufp=0;
  934.  }
  935. if(!have)
  936.  {
  937.  fcntl(fileno(stdin),F_SETFL,O_NDELAY);
  938.  if(read(fileno(stdin),&havec,1)==1) have=1;
  939.  fcntl(fileno(stdin),F_SETFL,0);
  940.  }
  941. }
  942.  
  943. anext()
  944. {
  945. aflush();
  946. if(have) have=0;
  947. else if(read(fileno(stdin),&havec,1)<1) tsignal();
  948. return havec;
  949. }
  950.  
  951. eputc(c)
  952. unsigned char c;
  953. {
  954. obuf[obufp++]=c;
  955. if(obufp==obufsiz) aflush();
  956. }
  957.  
  958. eputs(s)
  959. char *s;
  960. {
  961. while(*s)
  962.  {
  963.  obuf[obufp++]= *(s++);
  964.  if(obufp==obufsiz) aflush();
  965.  }
  966. }
  967.  
  968. termtype()
  969. {
  970. unsigned char entry[1024];
  971. unsigned char area[1024];
  972. unsigned char *foo=area;
  973. unsigned char *x=(unsigned char *)getenv("TERM");
  974. if(!x) return;
  975. if(tgetent(entry,x)!=1) return;
  976. height=tgetnum("li");
  977. if(height<2) height=24;
  978. width=tgetnum("co");
  979. if(width<2) width=80;
  980. if(!tgetstr("cs",&foo)) scroll=0;
  981. }
  982.  
  983. shell(s)
  984. char *s;
  985. {
  986. aclose();
  987. if(fork()) wait(0);
  988. else
  989.  {
  990.  execl(s,s,0);
  991.  _exit(0);
  992.  }
  993. aopen();
  994. }
  995. @EOF
  996.  
  997. chmod 600 asynchpux.c
  998.  
  999. echo x - asyncxenix.c
  1000. cat >asyncxenix.c <<'@EOF'
  1001. /* Terminal interface for XENIX
  1002.    Copyright (C) 1991 Joseph H. Allen
  1003.  
  1004. This file is part of J (Joe's Editor)
  1005.  
  1006. J is free software; you can redistribute it and/or modify it under the terms
  1007. of the GNU General Public License as published by the Free Software
  1008. Foundation; either version 1, or (at your option) any later version. 
  1009.  
  1010. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  1011. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1012. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  1013.  
  1014. You should have received a copy of the GNU General Public License
  1015. along with GNU Emacs; see the file COPYING.  If not, write to
  1016. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1017.  
  1018. #include <stdio.h>
  1019. #include <signal.h>
  1020. #include <termio.h>
  1021. #include "async.h"
  1022.  
  1023. #define DIVISOR 12000
  1024. #define TIMES 2
  1025.  
  1026. static struct termio oldterm;
  1027.  
  1028. static unsigned char *obuf=0;
  1029. static unsigned obufp=0;
  1030. static unsigned obufsiz;
  1031. static unsigned long ccc;
  1032.  
  1033. static unsigned speeds[]=
  1034. {
  1035. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  1036. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400
  1037. };
  1038.  
  1039. aopen()
  1040. {
  1041. int x;
  1042. struct termio newterm;
  1043. fflush(stdout);
  1044. signal(SIGHUP,tsignal);
  1045. signal(SIGINT,SIG_IGN);
  1046. signal(SIGQUIT,SIG_IGN);
  1047. signal(SIGPIPE,SIG_IGN);
  1048. signal(SIGALRM,SIG_IGN);
  1049. signal(SIGTERM,tsignal);
  1050. signal(SIGUSR1,SIG_IGN);
  1051. signal(SIGUSR2,SIG_IGN);
  1052. signal(SIGPWR,tsignal);
  1053. ioctl(fileno(stdin),TCGETA,&oldterm);
  1054. newterm=oldterm;
  1055. newterm.c_lflag=0;
  1056. newterm.c_iflag=IXON|IXOFF|IGNBRK;
  1057. newterm.c_oflag=0;
  1058. newterm.c_cc[VINTR]= -1;
  1059. newterm.c_cc[VQUIT]= -1;
  1060. newterm.c_cc[VMIN]=1;
  1061. newterm.c_cc[VTIME]=0;
  1062. ioctl(fileno(stdin),TCSETAW,&newterm);
  1063. ccc=0;
  1064. for(x=0;x!=30;x+=2)
  1065.  if((newterm.c_cflag&CBAUD)==speeds[x])
  1066.   {
  1067.   ccc=DIVISOR/speeds[x+1];
  1068.   break;
  1069.   }
  1070. if(!obuf)
  1071.  {
  1072.  if(!(TIMES*ccc)) obufsiz=4096;
  1073.  else
  1074.   {
  1075.   obufsiz=1000/(TIMES*ccc);
  1076.   if(obufsiz>4096) obufsiz=4096;
  1077.   }
  1078.  if(!obufsiz) obufsiz=1;
  1079.  obuf=(unsigned char *)malloc(obufsiz);
  1080.  }
  1081. }
  1082.  
  1083. aclose()
  1084. {
  1085. aflush();
  1086. ioctl(fileno(stdin),TCSETAW,&oldterm);
  1087. signal(SIGHUP,SIG_DFL);
  1088. signal(SIGINT,SIG_DFL);
  1089. signal(SIGQUIT,SIG_DFL);
  1090. signal(SIGPIPE,SIG_DFL);
  1091. signal(SIGALRM,SIG_DFL);
  1092. signal(SIGTERM,SIG_DFL);
  1093. signal(SIGUSR1,SIG_DFL);
  1094. signal(SIGUSR2,SIG_DFL);
  1095. signal(SIGPWR,SIG_DFL);
  1096. }
  1097.  
  1098. int have=0;
  1099.  
  1100. aflush()
  1101. {
  1102. if(obufp)
  1103.  {
  1104.  write(fileno(stdout),obuf,obufp);
  1105.  nap(obufp*ccc);
  1106.  obufp=0;
  1107.  }
  1108. if(!have) if(rdchk(fileno(stdin))>0) have=1;
  1109. }
  1110.  
  1111. anext()
  1112. {
  1113. unsigned char c;
  1114. aflush();
  1115. if(read(fileno(stdin),&c,1)<1) tsignal();
  1116. have=0;
  1117. return c;
  1118. }
  1119.  
  1120. eputc(c)
  1121. unsigned char c;
  1122. {
  1123. obuf[obufp++]=c;
  1124. if(obufp==obufsiz) aflush();
  1125. }
  1126.  
  1127. eputs(s)
  1128. char *s;
  1129. {
  1130. while(*s)
  1131.  {
  1132.  obuf[obufp++]= *(s++);
  1133.  if(obufp==obufsiz) aflush();
  1134.  }
  1135. }
  1136.  
  1137. termtype()
  1138. {
  1139. unsigned char entry[1024];
  1140. unsigned char area[1024];
  1141. unsigned char *foo=area;
  1142. unsigned char *x=(unsigned char *)getenv("TERM");
  1143. if(!x) return;
  1144. if(tgetent(entry,x)!=1) return;
  1145. height=tgetnum("li");
  1146. if(height<2) height=24;
  1147. width=tgetnum("co");
  1148. if(width<2) width=2;
  1149. if(!tgetstr("cs",&foo)) scroll=0;
  1150. }
  1151.  
  1152. shell(s)
  1153. char *s;
  1154. {
  1155. aclose();
  1156. if(fork()) wait(0);
  1157. else
  1158.  {
  1159.  execl(s,s,0);
  1160.  _exit(0);
  1161.  }
  1162. aopen();
  1163. }
  1164. @EOF
  1165.  
  1166. chmod 600 asyncxenix.c
  1167.  
  1168. echo x - blocks.c
  1169. cat >blocks.c <<'@EOF'
  1170. /* Various memory block functions
  1171.    Copyright (C) 1991 Joseph H. Allen
  1172.  
  1173. This file is part of J (Joe's Editor)
  1174.  
  1175. J is free software; you can redistribute it and/or modify it under the terms
  1176. of the GNU General Public License as published by the Free Software
  1177. Foundation; either version 1, or (at your option) any later version. 
  1178.  
  1179. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  1180. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1181. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  1182.  
  1183. You should have received a copy of the GNU General Public License
  1184. along with GNU Emacs; see the file COPYING.  If not, write to
  1185. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1186.  
  1187.  
  1188. #include "blocks.h"
  1189.  
  1190. /* Set block to zero */
  1191.  
  1192. unsigned char *bzero(bk,sz)
  1193. unsigned char *bk;
  1194. {
  1195. unsigned char *b=bk-1;
  1196. if(sz) do b[sz]=0; while(--sz);
  1197. return bk;
  1198. }
  1199.  
  1200. /* Set block to unsigned character */
  1201.  
  1202. unsigned char *bset(bk,sz,c)
  1203. unsigned char *bk;
  1204. unsigned char c;
  1205. {
  1206. unsigned char *b=bk-1;
  1207. if(sz) do b[sz]=c; while(--sz);
  1208. return bk;
  1209. }
  1210.  
  1211. /* Move a possibly overlapping block of memory without loosing any data */
  1212.  
  1213. unsigned char *bmove(dst,src,sz)
  1214. unsigned char *dst;
  1215. unsigned char *src;
  1216. {
  1217. if(src==dst || !sz) return dst;
  1218. if(src>dst)
  1219.  {
  1220.  unsigned x=0;
  1221.  do dst[x]=src[x]; while(++x, --sz);
  1222.  }
  1223. else
  1224.  {
  1225.  unsigned char *d=dst-1;
  1226.  --src;
  1227.  do d[sz]=src[sz]; while(--sz);
  1228.  } 
  1229. return dst;
  1230. }
  1231.  
  1232. /* Move a block in the forward direction */
  1233.  
  1234. unsigned char *bfwrd(dst,src,sz)
  1235. unsigned char *dst;
  1236. unsigned char *src;
  1237. {
  1238. if(src!=dst && sz)
  1239.  {
  1240.  unsigned x=0;
  1241.  do dst[x]=src[x]; while(++x,--sz);
  1242.  }
  1243. return dst;
  1244. }
  1245.  
  1246. /* Move a block in the backward direction */
  1247.  
  1248. unsigned char *bbkwd(dst,src,sz)
  1249. unsigned char *dst;
  1250. unsigned char *src;
  1251. {
  1252. unsigned char *s=src-1, *d=dst-1;
  1253. if(s!=d && sz) do d[sz]=s[sz]; while(--sz);
  1254. return dst;
  1255. }
  1256.  
  1257. unsigned umin(a,b)
  1258. unsigned a,b;
  1259. {
  1260. return (a>b)?b:a;
  1261. }
  1262.  
  1263. unsigned umax(a,b)
  1264. unsigned a,b;
  1265. {
  1266. return (a>b)?a:b;
  1267. }
  1268.  
  1269. int min(a,b)
  1270. {
  1271. return (a>b)?b:a;
  1272. }
  1273.  
  1274. int max(a,b)
  1275. {
  1276. return (a>b)?a:b;
  1277. }
  1278.  
  1279. /* Compare blocks for equality */
  1280.  
  1281. int beq(dst,src,sz)
  1282. unsigned char *dst;
  1283. unsigned char *src;
  1284. {
  1285. unsigned char *d=dst-1, *s=src-1;
  1286. if(!sz) return 1;
  1287. do
  1288.  if(d[sz]!=s[sz]) return 0;
  1289. while(--sz);
  1290. return 1;
  1291. }
  1292.  
  1293. /* Compare blocks for equality case insensitive */
  1294.  
  1295. int bieq(dst,src,sz)
  1296. unsigned char *dst;
  1297. unsigned char *src;
  1298. {
  1299. unsigned char *d=dst, *s=src; int cnt=sz;
  1300. if(!cnt) return 1;
  1301. do
  1302.  if(*s>='a' && *s<='z')
  1303.   {
  1304.   if(*d>='a' && *d<='z') { if(*(d++)!=*(s++)) return 0; }
  1305.   else if(*(d++)!=(0x5f&*(s++))) return 0;
  1306.   }
  1307.  else if(*d>='a' && *d<='z')
  1308.   {
  1309.   if(*s>='a' && *s<='z') { if(*(d++)!=*(s++)) return 0; }
  1310.   else if(*(s++)!=(0x5f&*(d++))) return 0;
  1311.   }
  1312.  else if(*(d++)!=*(s++)) return 0;
  1313. while(--cnt);
  1314. return 1;
  1315. }
  1316.  
  1317. unsigned char *bchr(bk,sz,c)
  1318. unsigned char *bk;
  1319. unsigned char c;
  1320. {
  1321. unsigned char *s=bk;
  1322. int cnt=sz;
  1323. if(cnt)
  1324.  do if(*s==c) return s;
  1325.  while(++s, --cnt);
  1326. return 0;
  1327. }
  1328.  
  1329. unsigned char *brchr(bk,sz,c)
  1330. unsigned char *bk, c;
  1331. {
  1332. unsigned char *s=bk+sz;
  1333. int cnt=sz;
  1334. if(cnt)
  1335.  do if(*(--s)==c) return s;
  1336.  while(--cnt);
  1337. return 0;
  1338. }
  1339. @EOF
  1340.  
  1341. chmod 600 blocks.c
  1342.  
  1343. echo x - blocks.h
  1344. cat >blocks.h <<'@EOF'
  1345. /* Memory block functions header file
  1346.    Copyright (C) 1991 Joseph H. Allen
  1347.  
  1348. This file is part of J (Joe's Editor)
  1349.  
  1350. J is free software; you can redistribute it and/or modify it under the terms
  1351. of the GNU General Public License as published by the Free Software
  1352. Foundation; either version 1, or (at your option) any later version. 
  1353.  
  1354. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  1355. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1356. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  1357.  
  1358. You should have received a copy of the GNU General Public License
  1359. along with GNU Emacs; see the file COPYING.  If not, write to
  1360. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1361.  
  1362. unsigned char *bzero();
  1363. unsigned char *bset();
  1364. unsigned char *bmove();
  1365. unsigned char *bfwrd();
  1366. unsigned char *bbkwd();
  1367. unsigned umin();
  1368. unsigned umax();
  1369. int min();
  1370. int max();
  1371. int beq();
  1372. int bieq();
  1373. unsigned char *bchr();
  1374. unsigned char *brchr();
  1375. @EOF
  1376.  
  1377. chmod 600 blocks.h
  1378.  
  1379. echo x - cruddy.c
  1380. cat >cruddy.c <<'@EOF'
  1381. /* Cruddy terminal interface - should be very portable though
  1382.    Copyright (C) 1991 Joseph H. Allen
  1383.  
  1384. This file is part of J (Joe's Editor)
  1385.  
  1386. J is free software; you can redistribute it and/or modify it under the terms
  1387. of the GNU General Public License as published by the Free Software
  1388. Foundation; either version 1, or (at your option) any later version. 
  1389.  
  1390. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  1391. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1392. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  1393.  
  1394. You should have received a copy of the GNU General Public License
  1395. along with GNU Emacs; see the file COPYING.  If not, write to
  1396. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1397.  
  1398.  
  1399. #include <stdio.h>
  1400. #include <signal.h>
  1401. #include "async.h"
  1402.  
  1403. int have=0;
  1404.  
  1405. eputs(s)
  1406. char *s;
  1407. {
  1408. fputs(s,stdout);
  1409. }
  1410.  
  1411. eputc(c)
  1412. {
  1413. putchar(c);
  1414. }
  1415.  
  1416. aopen()
  1417. {
  1418. fflush(stdout);
  1419. system("/bin/stty raw -echo ixon ixoff");
  1420. signal(SIGHUP,tsignal);
  1421. signal(SIGINT,SIG_IGN);
  1422. signal(SIGQUIT,SIG_IGN);
  1423. signal(SIGPIPE,SIG_IGN);
  1424. signal(SIGALRM,SIG_IGN);
  1425. signal(SIGTERM,tsignal);
  1426. signal(SIGUSR1,SIG_IGN);
  1427. signal(SIGUSR2,SIG_IGN);
  1428. }
  1429.  
  1430. aclose()
  1431. {
  1432. fflush(stdout);
  1433. signal(SIGHUP,SIG_DFL);
  1434. signal(SIGINT,SIG_DFL);
  1435. signal(SIGQUIT,SIG_DFL);
  1436. signal(SIGPIPE,SIG_DFL);
  1437. signal(SIGALRM,SIG_DFL);
  1438. signal(SIGTERM,SIG_DFL);
  1439. signal(SIGUSR1,SIG_DFL);
  1440. signal(SIGUSR2,SIG_DFL);
  1441. system("/bin/stty cooked echo");
  1442. }
  1443.  
  1444. aflush()
  1445. {
  1446. }
  1447.  
  1448. anext()
  1449. {
  1450. unsigned char c;
  1451. fflush(stdout);
  1452. while(read(fileno(stdin),&c,1)!=1);
  1453. return c;
  1454. }
  1455.  
  1456. termtype()
  1457. {
  1458. /*
  1459. char entry[1024];
  1460. char area[1024];
  1461. char *foo=area;
  1462. char *x=(char *)getenv("TERM");
  1463. if(!x) return;
  1464. if(tgetent(entry,x)<1) return;
  1465. height=tgetnum("li");
  1466. if(height<1) height=24;
  1467. width=tgetnum("co");
  1468. if(width<2) width=80;
  1469. if(!tgetstr("cs",&foo)) scroll=0;
  1470. */
  1471. }
  1472.  
  1473. shell(s)
  1474. char *s;
  1475. {
  1476. aclose();
  1477. if(fork()) wait(0);
  1478. else
  1479.  {
  1480.  execl(s,s,0);
  1481.  _exit(0);
  1482.  }
  1483. aopen();
  1484. }
  1485. @EOF
  1486.  
  1487. chmod 600 cruddy.c
  1488.  
  1489. echo x - j.1
  1490. cat >j.1 <<'@EOF'
  1491. ..TH J 1
  1492. ..SH NAME
  1493. j \- Joe's Screen Editor
  1494. ..SH SYNOPSIS
  1495. ..B j file
  1496. ..br
  1497. ..BR j
  1498. ..SH DESCRIPTION
  1499. J is a screen editor designed to be easy to learn for novice users and
  1500. powerfull enough for experienced users.  After you invoke the editor, you can
  1501. hit ^K H ('^' mean hold the Ctrl key down while pressing the following key) to
  1502. turn on the help text.  From this you should be able to figure out how to use
  1503. the editor.  A few things need further explanation however:
  1504.  
  1505. J uses the "TERM" environment entry and termcap to determine the height and
  1506. width of the screen and to determine if the terminal uses scrolling regions. 
  1507. Except for these differences the terminal must be ANSI/VT100 compatible.
  1508.  
  1509. ^K J reformats the current paragraph.  ^T R can be used to change the right
  1510. margin.  The default is the width of the screen.  If auto-indent mode is set,
  1511. indented paragraphs are formated.
  1512.  
  1513. Use ^K B to set the beginning of a block and ^K K to set the end of a block. 
  1514. You can then copy, move save or delete the marked blocsk.  To turn the
  1515. highlighting off, hit ^K B ^K K (make the beginning and ending the same or
  1516. move the beginning past the ending or move the ending before the beginning).
  1517.  
  1518. ^K O splits a window into two.  You can then use ^K E to load a file into the
  1519. new window.  ^K I shows either one window or it shows all of the windows.  Use
  1520. ^C to eliminate a window.
  1521.  
  1522. Control characters (0-31, 127) are shown underlined.  Characters above 127 are
  1523. shown in inverse.  You can use ` and ^\ to enter control characters
  1524. orcharacters with the 7th bit set.
  1525.  
  1526. Hit ^K F to find text.  You will be prompted to enter the search string. 
  1527. After hitting Return, you will be prompted for options- you can type 1 or more
  1528. of:  
  1529.  
  1530. ..br
  1531.             i    Ignore case
  1532. ..br
  1533.             b    Backwards
  1534. ..br
  1535.             r    Replace
  1536. ..br
  1537.             nnn    Find the nth occurance or do nnn replacements
  1538. ..br
  1539.  
  1540.         If you hit r, you will also be prompted to enter the
  1541.         replacement string.
  1542.  
  1543.         Hit ^L to find the next occurance of the previous search
  1544.         string (with all the same options).
  1545.  
  1546. If for some reason J gets a signal (that it's going to crash or that the
  1547. system is messing up), it attempts to save the last file edited in a file
  1548. "aborted.j" in the current directory.
  1549.  
  1550. ..SH FILES
  1551. ..DT
  1552. ..ta 25n
  1553. keymap.j            Keymap file.  J looks for this in the current
  1554.                 directory, the user's home directory and in
  1555.                 the directory containing J
  1556. ..SH RESTRICTIONS
  1557. The file size is limited to the system process size limit
  1558.  
  1559. ..SH BUGS
  1560. Send bug reports to rcarter@wpi.wpi.edu (Joseph H. Allen).  This should be
  1561. valid to at least January, 1991.  You can also contact me through snail mail:
  1562.  
  1563. ..br
  1564.         Joseph H. Allen
  1565. ..br
  1566.         28 Dale Lane
  1567. ..br
  1568.         Smithtown, N.Y. 11787
  1569. @EOF
  1570.  
  1571. chmod 600 j.1
  1572.  
  1573. echo x - j.c
  1574. cat >j.c <<'@EOF'
  1575. /* J - Joe's Editor - the bulk of the code is here
  1576.    Copyright (C) 1991 Joseph H. Allen
  1577.  
  1578. This file is part of J (Joe's Editor)
  1579.  
  1580. J is free software; you can redistribute it and/or modify it under the terms
  1581. of the GNU General Public License as published by the Free Software
  1582. Foundation; either version 1, or (at your option) any later version. 
  1583.  
  1584. J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  1585. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1586. PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
  1587.  
  1588. You should have received a copy of the GNU General Public License
  1589. along with GNU Emacs; see the file COPYING.  If not, write to
  1590. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1591.  
  1592. #include <stdio.h>
  1593. /* #include <stdlib.h> */
  1594. #include <string.h>
  1595. #include <sys/types.h>
  1596. #include <sys/stat.h>
  1597. #include <errno.h>
  1598. #include <pwd.h>
  1599. extern errno;
  1600. #include "async.h"
  1601. #include "blocks.h"
  1602. #include "j.h"
  1603. int width=80;
  1604. int height=24;
  1605. int scroll=1;
  1606.  
  1607. unsigned char stalin[PATHSIZE];
  1608.  
  1609. int smode=0;
  1610. int tops=0;
  1611. int bots;
  1612. int oxpos=0;            /* Current cursor position */
  1613. int oypos=0;
  1614. int *scrn;            /* Screen buffer address */
  1615.  
  1616. unsigned char *omsg=0;           /* Pointer to opening message */
  1617.  
  1618. dopen()
  1619. {
  1620. int x;
  1621. unsigned char buf[30];
  1622. scrn=(int *)malloc(width*height*sizeof(int));
  1623. for(x=0;x<width*height;x++) scrn[x]= ' ';
  1624. if(scroll)
  1625.  {
  1626.  sprintf(buf,"\033[0m\033[1;%dr\033[H\033[J",height), eputs(buf);
  1627.  bots=height-1;
  1628.  }
  1629. else eputs("\033[0m\033[H\033[J");
  1630. }
  1631.  
  1632. dclose(ms)
  1633. unsigned char *ms;
  1634. {
  1635. setregn(0,height-1);
  1636. cpos(height-1,0);
  1637. tputss(ms);
  1638. eputs("\033[K");
  1639. oxpos=strlen(ms);
  1640. cpos(height-1,0);
  1641. eputc(10);
  1642. }
  1643.  
  1644. cposs(y,x)
  1645. {
  1646. unsigned char s[9];
  1647. if(y>bots || y<tops) setregn(0,height-1);
  1648. if(y==oypos)
  1649.  {
  1650.  if(x==oxpos) return;
  1651.  if(x==0)
  1652.   {
  1653.   eputc(13);
  1654.   return;
  1655.   }
  1656.  if(oxpos>=x+1 && oxpos<=x+4)
  1657.   {
  1658.   while(oxpos!=x) eputc(8), x++;
  1659.   return;
  1660.   }
  1661.  if(x>=oxpos+1 && x<=oxpos+4)
  1662.   {
  1663.   while(x!=oxpos) tputcc(scrn[oypos*width+oxpos++]);
  1664.   return;
  1665.   }
  1666.  if(x>oxpos)
  1667.   sprintf(s,"\033[%dC",x-oxpos);
  1668.  else
  1669.   sprintf(s,"\033[%dD",oxpos-x);
  1670.  eputs(s);
  1671.  return;
  1672.  }
  1673. if(x==oxpos)
  1674.  {
  1675.  if(y>=oypos+1 && y<=oypos+4)
  1676.   {
  1677.   while(y!=oypos) /* acheck(), */ eputc(10), oypos++;
  1678.   return;
  1679.   }
  1680.  if(y==0 && x==0)
  1681.   {
  1682.   eputs("\033[H");
  1683.   }
  1684.  if(y>oypos)
  1685.   sprintf(s,"\033[%dB",y-oypos);
  1686.  else
  1687.   sprintf(s,"\033[%dA",oypos-y);
  1688.  eputs(s);
  1689.  return;
  1690.  }
  1691. if(x<3 && y>oypos && y<oypos+5)
  1692.  {
  1693.  while(oypos!=y) ++oypos, eputc('\012');
  1694.  eputc('\015'); oxpos=0;
  1695.  while(x!=oxpos) tputcc(scrn[oypos*width+oxpos++]);
  1696.  return;
  1697.  }
  1698. if(x==0 && y==0)
  1699.  {
  1700.  eputs("\033[H");
  1701.  return;
  1702.  }
  1703. if(x==0)
  1704.  {
  1705.  sprintf(s,"\033[%dH",y+1);
  1706.  eputs(s);
  1707.  return;
  1708.  }
  1709. sprintf(s,"\033[%d;%dH",y+1,x+1);
  1710. eputs(s);
  1711. return;
  1712. }
  1713.  
  1714. cpos(y,x)
  1715. {
  1716. cposs(y,x);
  1717. oxpos=x;
  1718. oypos=y;
  1719. }
  1720.  
  1721. setregn(top,bot)
  1722. {
  1723. unsigned char sst[16];
  1724. if(top!=tops || bots!=bot)
  1725.  {
  1726.  tops=top;
  1727.  bots=bot;
  1728.  if(scroll)
  1729.   {
  1730.   oxpos=0;
  1731.   oypos=0;
  1732.   sprintf(sst,"\033[%d;%dr",top+1,bot+1);
  1733.   eputs(sst);
  1734.   }
  1735.  }
  1736. }
  1737.  
  1738. attrib(x)
  1739. {
  1740. if(smode== -1) goto clr;
  1741. if(!(x&INVERSE) && (smode&INVERSE)) goto clr;
  1742. if(!(x&BLINK) && (smode&BLINK)) goto clr;
  1743. if(!(x&UNDERLINE) && (smode&UNDERLINE)) goto clr;
  1744. if(!(x&BOLD) && (smode&BOLD)) goto clr;
  1745. goto ovr;
  1746. clr:
  1747. smode=0;
  1748. eputs("\033[m");
  1749. ovr:
  1750. if(x&INVERSE && !(smode&INVERSE)) eputs("\033[7m");
  1751. if(x&BLINK && !(smode&BLINK)) eputs("\033[5m");
  1752. if(x&UNDERLINE && !(smode&UNDERLINE)) eputs("\033[4m");
  1753. if(x&BOLD && !(smode&BOLD)) eputs("\033[1m");
  1754. smode=x;
  1755. }
  1756.  
  1757. int uuu=0;
  1758. int cntr=0;
  1759. int upd=1;
  1760. int hupd=0;
  1761. int newy=1;
  1762. int helpon=0;
  1763. int wind=0;
  1764. int xpos=0;
  1765. int ypos=0;
  1766. TXTSIZ saddr=0;
  1767. TXTSIZ xoffset=0;
  1768.  
  1769. unsigned char help[]=
  1770. "\
  1771. \240\240\240\310\345\354\360\240\323\343\362\345\345\356\240\240\240\364\365\
  1772. \362\356\240\357\346\346\240\367\351\364\350\240\336\313\310\240\240\
  1773. \240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\
  1774. \240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\
  1775. \240\240\240\240\240\240\240\
  1776. \240\
  1777. \7\017 \024\017             \4\5\014\5\024\5    \015\011\023\03       \02\
  1778. \014\017\03\013    \06\011\016\04     \021\025\017\024\05    \027\011\016\04\017\
  1779. \027     \
  1780. \240\
  1781. \240\
  1782. ^B left  ^F right ^D single ^T  mode   ^KB mark ^KF text `  Ctrl  ^KO split  \
  1783. \240\
  1784. \240\
  1785. ^Z word  ^X word  ^W >word  ^R  retype ^KK end  ^L  next ^\\ bit-7 ^KI 1 / all\
  1786. \240\
  1787. \240\
  1788. ^A edge  ^E edge  ^O word<  ^KA center ^KC copy ^KL line \06\011\014\
  1789. \05     ^KP up     \
  1790. \240\
  1791. \240\
  1792. ^P up    ^N down  ^J >line  ^KJ format ^KM move \05\
  1793. \030\011\024     ^KD save ^KN down   \
  1794. \240\
  1795. \240\
  1796. ^U page  ^V page  ^Y line   ^KZ shell  ^KW save ^KX save ^KR read ^KG grow   \
  1797. \240\
  1798. \240\
  1799. ^KU top ^KV end   ^K- undo  ^K, indnt< ^KY kill ^C abort/         ^KT shrink \
  1800. \240\
  1801. \240\
  1802. ^G matching ([<{` ^K+ redo  ^K. indnt>             close window  ^KE get file\
  1803. \240";
  1804.  
  1805. /* Clear end of line if needed.  i is row number and j is column number */
  1806.  
  1807. clreolchk(i,j)
  1808. TXTSIZ j;
  1809. {
  1810. int *k=scrn+i*width;
  1811. int t, jj;
  1812. if(j<xoffset) jj=0;
  1813. else
  1814.  if(j>=xoffset+width-1) return;
  1815.  else jj=j-xoffset;
  1816. for(t=width-1;t>=jj;--t) if(k[t]!=' ') goto ohoh;
  1817. return;
  1818. ohoh:
  1819. if(t==jj)
  1820.  {
  1821.  cpos(i,jj);
  1822.  tputcc(' ');
  1823.  k[jj]=' ';
  1824.  oxpos++;
  1825.  return;
  1826.  }
  1827. while(t>=jj) k[t--]=' ';
  1828. cpos(i,jj);
  1829. tattrib(' ');
  1830. eputs("\033[K");
  1831. }
  1832.  
  1833. int udline(i)
  1834. {
  1835. int q=i*width;
  1836. TXTSIZ j;
  1837. int t;
  1838. int u;
  1839. unsigned char ch;
  1840. for(j=0;1;j++)
  1841.  {
  1842.  if(have) return -1;
  1843.  if(fmeof())
  1844.   {
  1845.   clreolchk(i++,j);
  1846.   j=0;
  1847.   while(i<curwin->wind+curwin->height) clreolchk(i++,j);
  1848.   return 1;
  1849.   }
  1850.  ch=fmgetc();
  1851.  if(ch==NL)
  1852.   {
  1853.   clreolchk(i,j);
  1854.   return 0;
  1855.   }
  1856.  if(ch==TAB)
  1857.   {
  1858.   ch=' ';
  1859.   if(fmnote()-1>=markb && fmnote()<=marke && curbuf==markbuf) ch^=128;
  1860.   t=i*width+j-xoffset;
  1861.   do
  1862.    {
  1863.    if(j>=xoffset && j<xoffset+width-1)
  1864.     {
  1865.     u=scrn[t];
  1866.     if(ch!=u || u==-1)
  1867.      {
  1868.      cpos(i,(int)(j-xoffset));
  1869.      scrn[t]=ch;
  1870.      tputcc(ch);
  1871.      oxpos++;
  1872.      }
  1873.     }
  1874.    t++;
  1875.    j++;
  1876.    } while(j&7);
  1877.   j--;
  1878.   }
  1879.  else
  1880.   {
  1881.   if(fmnote()-1>=markb && fmnote()<=marke && curbuf==markbuf) ch^=128;
  1882.   t=q+j-xoffset;
  1883.   if(j>=xoffset && j<xoffset+width-1)
  1884.    {
  1885.    u=scrn[t];
  1886.    if(ch!=u || u==-1)
  1887.     {
  1888.     cpos(i,(int)(j-xoffset));
  1889.     scrn[t]=ch;
  1890.     tputcc(ch);
  1891.     oxpos++;
  1892.     }
  1893.    }
  1894.   }
  1895.  }
  1896. }
  1897.  
  1898. int udscrn()
  1899. {
  1900. int i;
  1901. int v;
  1902. for(i=ypos;i<curwin->height+curwin->wind;i++)
  1903.  if(v=udline(i)) break;
  1904. if(v== -1) return 0;
  1905. fmpoint(saddr);
  1906. for(i=curwin->wind+1;i<ypos;i++)
  1907.  if(udline(i)) return 0;
  1908. return 1;
  1909. }
  1910.  
  1911. dupdate1(fgf)
  1912. {
  1913. int y;
  1914. TXTSIZ x;
  1915. TXTSIZ sve=fmnote();
  1916.  
  1917. TXTSIZ sve1;
  1918.  
  1919. /* Status line */
  1920. bset(stalin,width-1,' ');
  1921. bfwrd(stalin,"File:",5);
  1922. if(changed)
  1923.  if(gfnam[0]) bfwrd(bfwrd(stalin+6,gfnam,strlen(gfnam))+strlen(gfnam),
  1924.  " (Modified)",11);
  1925.  else bfwrd(bfwrd(stalin+6,"(Unnamed)",9)+9," (Modified)",11);
  1926. else
  1927.  if(gfnam[0]) bfwrd(stalin+6,gfnam,strlen(gfnam));
  1928.  else bfwrd(stalin+6,"(Unnamed)",9);
  1929. if(!helpon) bfwrd(stalin+width-22,"Hit Ctrl-K H for help",21);
  1930.  
  1931. for(y=0;y<width-1;y++)
  1932.  if(scrn[y+curwin->wind*width]!=stalin[y]+128)
  1933.   {
  1934.   if(have) break;
  1935.   cpos(curwin->wind,y);
  1936.   tputcc(stalin[y]+128);
  1937.   scrn[y+curwin->wind*width]=stalin[y]+128;
  1938.   oxpos++;
  1939.   }
  1940.  
  1941. x=getcol();
  1942. if(fmnrnl()) fmpoint(fmnote()+1);
  1943. sve1=fmnote();
  1944.  
  1945. /* calculate what screen cursor position should be */
  1946.  
  1947. if(x>xoffset+width-2)
  1948.  xpos=width-2, xoffset=x-width+2;
  1949. else
  1950.  if(x<xoffset)
  1951.   xpos=0, xoffset=x;
  1952.  else
  1953.   xpos=x-xoffset;
  1954.  
  1955. /* calculate new y cursor position and point to beginning of screen */
  1956.  
  1957. if(newy)
  1958.  {
  1959.  if(fmnote()<=saddr)
  1960.   {
  1961.   ypos=curwin->wind+1;
  1962.   saddr=fmnote();
  1963.   }
  1964.  else
  1965.   {
  1966.   /* is cursor within 24 lines of old beginning of screen */
  1967.  
  1968.   for(y=0;y!=curwin->height-2;y++)
  1969.    {
  1970.    if(fmnote()==saddr) goto over;
  1971.    fmrgetc();
  1972.    if(fmnrnl()) fmpoint(fmnote()+1);
  1973.    }
  1974.   if(cntr)
  1975.    {
  1976.    for(x=0;x<(curwin->height-1)/2;x++)
  1977.     {
  1978.     fmfnl();
  1979.     y--;
  1980.     fmgetc();
  1981.     }
  1982.    }
  1983.   over:
  1984.   cntr=0;
  1985.   saddr=fmnote();
  1986.   ypos=y+curwin->wind+1;
  1987.   }
  1988.  newy=0;
  1989.  }
  1990.  
  1991. /* Now update screen */
  1992. if(have)
  1993.  { if(fgf) cpos(ypos,xpos); }
  1994. else
  1995.  {
  1996.  fmpoint(sve1);
  1997.  if(udscrn()) upd=0;
  1998.  if(fgf) cpos(ypos,xpos);
  1999.  }
  2000. fmpoint(sve);
  2001. }
  2002.  
  2003. dupdatehelp()
  2004. {
  2005. int i,j;
  2006. unsigned char *from=help;
  2007. int *too=scrn;
  2008. wind=helplines;
  2009. for(i=0;i!=helplines;i++)
  2010.  {
  2011.  for(j=0;j!=helpwidth;j++)
  2012.   {
  2013.   if(have) return;
  2014.   if(j>=width-1)
  2015.    {
  2016. -- Cut here
  2017. -- 
  2018. /*  rcarter@wpi.wpi.edu */      /* Amazing */             /* Joseph H. Allen */
  2019. int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
  2020. +r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2
  2021. ]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}
  2022.