home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2597 < prev    next >
Encoding:
Text File  |  1992-11-20  |  44.2 KB  |  2,313 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!noc.near.net!mv!world!jhallen
  3. From: jhallen@world.std.com (Joseph H Allen)
  4. Subject: JOE 1.0.5 Part 8 of 10
  5. Message-ID: <By2Mrw.LCH@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. Date: Sat, 21 Nov 1992 14:55:07 GMT
  8. Lines: 2303
  9.  
  10. Submitted-by: jhallen@world.std.com
  11. Archive-name: joe1.0.5part8
  12.  
  13. #else
  14. #ifdef TIOCGWINSZ
  15. if(ioctl(fileno(term),TIOCGWINSZ,&getit)!= -1)
  16. X {
  17. X *x=getit.ws_col;
  18. X *y=getit.ws_row;
  19. X }
  20. #endif
  21. #endif
  22. }
  23. X
  24. void ttshell(cmd)
  25. char *cmd;
  26. {
  27. int x,omode=ttymode;
  28. char *s=getenv("SHELL");
  29. if(!s) return;
  30. ttclsn();
  31. if(x=fork())
  32. X {
  33. X if(x!= -1) wait(0);
  34. X if(omode) ttopnn();
  35. X }
  36. else
  37. X {
  38. X signrm();
  39. X if(cmd) execl(s,s,"-c",cmd,NULL);
  40. X else
  41. X  {
  42. X  fprintf(stderr,"You are at the command shell.  Type 'exit' to return\n");
  43. X  execl(s,s,NULL);
  44. X  }
  45. X _exit(0);
  46. X }
  47. }
  48. X
  49. static int gotsig;
  50. X
  51. static void dosi()
  52. {
  53. gotsig=1;
  54. }
  55. X
  56. void ttsusp()
  57. {
  58. #ifdef SIGCONT
  59. int omode=ttymode;
  60. ttclsn();
  61. gotsig=0;
  62. fprintf(stderr,"You have suspended the program.  Type \'fg\' to return\n");
  63. signal(SIGCONT,dosi);
  64. sigsetmask(sigmask(SIGCONT));
  65. kill(0,SIGTSTP);
  66. while(!gotsig) sigpause(0);
  67. signal(SIGCONT,SIG_DFL);
  68. if(omode) ttopnn();
  69. #else
  70. ttshell(NULL);
  71. #endif
  72. }
  73. X
  74. char *getwd();
  75. char *pwd()
  76. {
  77. static buf[1024];
  78. return getwd(buf);
  79. }
  80. SHAR_EOF
  81. chmod 0600 ttybsd.c ||
  82. echo 'restore of ttybsd.c failed'
  83. Wc_c="`wc -c < 'ttybsd.c'`"
  84. test 5407 -eq "$Wc_c" ||
  85.     echo 'ttybsd.c: original size 5407, current size' "$Wc_c"
  86. fi
  87. # ============= ttyhpux.c ==============
  88. if test -f 'ttyhpux.c' -a X"$1" != X"-c"; then
  89.     echo 'x - skipping ttyhpux.c (File already exists)'
  90. else
  91. echo 'x - extracting ttyhpux.c (Text)'
  92. sed 's/^X//' << 'SHAR_EOF' > 'ttyhpux.c' &&
  93. /* TTY interface for HPUX (AT&T SV + BSD EXTENSIONS)
  94. X   Copyright (C) 1991 Joseph H. Allen
  95. X
  96. This file is part of JOE (Joe's Own Editor)
  97. X
  98. JOE is free software; you can redistribute it and/or modify it under the terms
  99. of the GNU General Public License as published by the Free Software
  100. Foundation; either version 1, or (at your option) any later version. 
  101. X
  102. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  103. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  104. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  105. X
  106. You should have received a copy of the GNU General Public License
  107. along with JOE; see the file COPYING.  If not, write to
  108. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  109. X
  110. #include <stdio.h>
  111. #include <signal.h>
  112. #include <fcntl.h>
  113. #include <time.h>
  114. #include <sys/param.h>
  115. #include <termio.h>
  116. #include "config.h"
  117. #include "heap.h"
  118. #include "tty.h"
  119. X
  120. #ifndef HZ
  121. #define HZ 10
  122. #endif
  123. X
  124. FILE *term=0;
  125. X
  126. static struct termio oldterm;
  127. X
  128. char *obuf=0;
  129. int obufp=0;
  130. int obufsiz;
  131. X
  132. unsigned long upc;
  133. unsigned baud;
  134. X
  135. int have=0;
  136. static char havec;
  137. int leave=0;
  138. static int ttymode=0;
  139. X
  140. static int speeds[]=
  141. {
  142. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  143. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400
  144. };
  145. X
  146. void sigjoe()
  147. {
  148. signal(SIGHUP,ttsig);
  149. signal(SIGTERM,ttsig);
  150. signal(SIGINT,SIG_IGN);
  151. signal(SIGPIPE,SIG_IGN);
  152. signal(SIGQUIT,SIG_IGN);
  153. }
  154. X
  155. void signrm()
  156. {
  157. signal(SIGHUP,SIG_DFL);
  158. signal(SIGTERM,SIG_DFL);
  159. signal(SIGINT,SIG_DFL);
  160. signal(SIGPIPE,SIG_DFL);
  161. signal(SIGQUIT,SIG_DFL);
  162. }
  163. X
  164. void ttopen()
  165. {
  166. sigjoe();
  167. ttopnn();
  168. }
  169. X
  170. void ttopnn()
  171. {
  172. int x;
  173. struct termio newterm;
  174. if(!term && !(term=fopen("/dev/tty","r+")))
  175. X {
  176. X fprintf(stderr,"Couldn\'t open tty\n");
  177. X exit(1);
  178. X }
  179. if(ttymode) return;
  180. else ttymode=1;
  181. fflush(term);
  182. ioctl(fileno(term),TCGETA,&oldterm);
  183. newterm=oldterm;
  184. newterm.c_lflag=0;
  185. newterm.c_iflag&=~(ICRNL|IGNCR|INLCR);
  186. newterm.c_oflag=0;
  187. newterm.c_cc[VMIN]=1;
  188. newterm.c_cc[VTIME]=0;
  189. ioctl(fileno(term),TCSETAW,&newterm);
  190. upc=0;
  191. baud=9600;
  192. for(x=0;x!=30;x+=2)
  193. X if((newterm.c_cflag&CBAUD)==speeds[x])
  194. X  {
  195. X  baud=speeds[x+1];
  196. X  break;
  197. X  }
  198. {
  199. char *bs=getenv("BAUD");
  200. if(bs)
  201. X {
  202. X sscanf(bs,"%u",&baud);
  203. X }
  204. }
  205. upc=DIVIDEND/baud;
  206. if(obuf) free(obuf);
  207. if(!(TIMES*upc)) obufsiz=4096;
  208. else
  209. X {
  210. X obufsiz=1000000/(TIMES*upc);
  211. X if(obufsiz>4096) obufsiz=4096;
  212. X }
  213. if(!obufsiz) obufsiz=1;
  214. obuf=(char *)malloc(obufsiz);
  215. }
  216. X
  217. void ttclose()
  218. {
  219. ttclsn();
  220. signrm();
  221. }
  222. X
  223. void ttclsn()
  224. {
  225. int oleave=leave;
  226. if(ttymode) ttymode=0;
  227. else return;
  228. leave=1;
  229. ttflsh();
  230. ioctl(fileno(term),TCSETAW,&oldterm);
  231. leave=oleave;
  232. }
  233. X
  234. static int yep;
  235. X
  236. static void dosig() { yep=1; } 
  237. X
  238. int ttflsh()
  239. {
  240. if(obufp)
  241. X {
  242. X struct itimerval a,b;
  243. X unsigned long usec=obufp*upc;
  244. X if(usec>=500000/HZ && baud<38400)
  245. X  {
  246. X  a.it_value.tv_sec=usec/1000000;
  247. X  a.it_value.tv_usec=usec%1000000;
  248. X  a.it_interval.tv_usec=0;
  249. X  a.it_interval.tv_sec=0;
  250. X  signal(SIGALRM,dosig);
  251. X  yep=0;
  252. X  sigsetmask(sigmask(SIGALRM));
  253. X  setitimer(ITIMER_REAL,&a,&b);
  254. X  write(fileno(term),obuf,obufp);
  255. X  while(!yep) sigpause(0);
  256. X  signal(SIGALRM,SIG_DFL);
  257. X  }
  258. X else write(fileno(term),obuf,obufp);
  259. X obufp=0;
  260. X }
  261. if(!have && !leave)
  262. X {
  263. X fcntl(fileno(term),F_SETFL,O_NDELAY);
  264. X if(read(fileno(term),&havec,1)==1) have=1;
  265. X fcntl(fileno(term),F_SETFL,0);
  266. X }
  267. return 0;
  268. }
  269. X
  270. int ttgetc()
  271. {
  272. ttflsh();
  273. if(have) have=0;
  274. else if(read(fileno(term),&havec,1)<1) ttsig(0);
  275. return havec;
  276. }
  277. X
  278. void ttputs(s)
  279. char *s;
  280. {
  281. while(*s)
  282. X {
  283. X obuf[obufp++]= *(s++);
  284. X if(obufp==obufsiz) ttflsh();
  285. X }
  286. }
  287. X
  288. void ttgtsz(x,y)
  289. int *x, *y;
  290. {
  291. #ifdef TIOCGSIZE
  292. struct ttysize getit;
  293. #else
  294. #ifdef TIOCGWINSZ
  295. struct winsize getit;
  296. #endif
  297. #endif
  298. *x=0; *y=0;
  299. #ifdef TIOCGSIZE
  300. if(ioctl(fileno(term),TIOCGSIZE,&getit)!= -1)
  301. X {
  302. X *x=getit.ts_cols;
  303. X *y=getit.ts_lines;
  304. X }
  305. #else
  306. #ifdef TIOCGWINSZ
  307. if(ioctl(fileno(term),TIOCGWINSZ,&getit)!= -1)
  308. X {
  309. X *x=getit.ws_col;
  310. X *y=getit.ws_row;
  311. X }
  312. #endif
  313. #endif
  314. }
  315. X
  316. void ttshell(cmd)
  317. char *cmd;
  318. {
  319. int x,omode=ttymode;
  320. char *s=getenv("SHELL");
  321. if(!s) return;
  322. ttclsn();
  323. if(x=fork())
  324. X {
  325. X if(x!= -1) wait(0);
  326. X if(omode) ttopnn();
  327. X }
  328. else
  329. X {
  330. X signrm();
  331. X if(cmd) execl(s,s,"-c",cmd,NULL);
  332. X else
  333. X  {
  334. X  fprintf(stderr,"You are at the command shell.  Type 'exit' to return\n");
  335. X  execl(s,s,NULL);
  336. X  }
  337. X _exit(0);
  338. X }
  339. }
  340. X
  341. static int gotsig;
  342. X
  343. static void dosi()
  344. {
  345. gotsig=1;
  346. }
  347. X
  348. void ttsusp()
  349. {
  350. #ifdef SIGCONT
  351. int omode=ttymode;
  352. ttclsn();
  353. gotsig=0;
  354. fprintf(stderr,"You have suspended the program.  Type \'fg\' to return\n");
  355. signal(SIGCONT,dosi);
  356. sigsetmask(sigmask(SIGCONT));
  357. kill(0,SIGTSTP);
  358. while(!gotsig) sigpause(0);
  359. signal(SIGCONT,SIG_DFL);
  360. if(omode) ttopnn();
  361. #else
  362. ttshell(NULL);
  363. #endif
  364. }
  365. X
  366. char *getcwd();
  367. char *pwd()
  368. {
  369. static char buf[1024];
  370. return getcwd(buf,1024);
  371. }
  372. SHAR_EOF
  373. chmod 0600 ttyhpux.c ||
  374. echo 'restore of ttyhpux.c failed'
  375. Wc_c="`wc -c < 'ttyhpux.c'`"
  376. test 4717 -eq "$Wc_c" ||
  377.     echo 'ttyhpux.c: original size 4717, current size' "$Wc_c"
  378. fi
  379. # ============= ttymsdos.c ==============
  380. if test -f 'ttymsdos.c' -a X"$1" != X"-c"; then
  381.     echo 'x - skipping ttymsdos.c (File already exists)'
  382. else
  383. echo 'x - extracting ttymsdos.c (Text)'
  384. sed 's/^X//' << 'SHAR_EOF' > 'ttymsdos.c' &&
  385. /* TTY interface for MSDOS using TURBO-C
  386. X   Copyright (C) 1991 Joseph H. Allen
  387. X
  388. This file is part of JOE (Joe's Own Editor)
  389. X
  390. JOE is free software; you can redistribute it and/or modify it under the terms
  391. of the GNU General Public License as published by the Free Software
  392. Foundation; either version 1, or (at your option) any later version. 
  393. X
  394. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  395. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  396. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  397. X
  398. You should have received a copy of the GNU General Public License
  399. along with JOE; see the file COPYING.  If not, write to
  400. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  401. X
  402. #include <stdio.h>
  403. #include <conio.h>
  404. #include <bios.h>
  405. #include "config.h"
  406. #include "tty.h"
  407. X
  408. unsigned baud=38400;
  409. unsigned long upc;
  410. int have=0;
  411. int leave=0;
  412. static int ttymode=0;
  413. X
  414. void ttputs(s)
  415. char *s;
  416. {
  417. fputs(s,stdout);
  418. if(!have) have=bioskey(1);
  419. }
  420. X
  421. void ttputc(c)
  422. char c;
  423. {
  424. putchar(c);
  425. if(!have) have=bioskey(1);
  426. }
  427. X
  428. void sigjoe()
  429. {
  430. }
  431. X
  432. void signrm()
  433. {
  434. }
  435. X
  436. void ttopen()
  437. {
  438. ttopnn();
  439. }
  440. X
  441. void ttopnn()
  442. {
  443. fflush(stdout);
  444. {
  445. char *bs=getenv("BAUD");
  446. if(bs)
  447. X {
  448. X sscanf(bs,"%u",&baud);
  449. X }
  450. }
  451. upc=DIVIDEND/baud;
  452. }
  453. X
  454. void ttclose()
  455. {
  456. ttclsn();
  457. }
  458. X
  459. void ttclsn()
  460. {
  461. ttflsh();
  462. }
  463. X
  464. void ttflsh()
  465. {
  466. fflush(stdout);
  467. if(!have) have=bioskey(1);
  468. }
  469. X
  470. int ttgetc()
  471. {
  472. char c;
  473. have=0;
  474. c=getch();
  475. return c;
  476. }
  477. X
  478. void ttgtsz(x,y)
  479. int *x, *y;
  480. {
  481. }
  482. X
  483. void ttshell(cmd)
  484. char *cmd;
  485. {
  486. char *s=getenv("COMSPEC");
  487. if(cmd) system(cmd);
  488. else if(s) system(s);
  489. }
  490. X
  491. void ttsusp()
  492. {
  493. ttshell(NULL);
  494. }
  495. X
  496. char *getcwd();
  497. char *pwd()
  498. {
  499. static char buf[1024];
  500. return getcwd(buf,1024);
  501. }
  502. SHAR_EOF
  503. chmod 0600 ttymsdos.c ||
  504. echo 'restore of ttymsdos.c failed'
  505. Wc_c="`wc -c < 'ttymsdos.c'`"
  506. test 1705 -eq "$Wc_c" ||
  507.     echo 'ttymsdos.c: original size 1705, current size' "$Wc_c"
  508. fi
  509. # ============= ttyposix.c ==============
  510. if test -f 'ttyposix.c' -a X"$1" != X"-c"; then
  511.     echo 'x - skipping ttyposix.c (File already exists)'
  512. else
  513. echo 'x - extracting ttyposix.c (Text)'
  514. sed 's/^X//' << 'SHAR_EOF' > 'ttyposix.c' &&
  515. /* TTY interface for POSIX
  516. X   Copyright (C) 1991 Joseph H. Allen
  517. X   (Contributed by Mike Lijewski)
  518. X
  519. This file is part of JOE (Joe's Own Editor)
  520. X
  521. JOE is free software; you can redistribute it and/or modify it under the terms
  522. of the GNU General Public License as published by the Free Software
  523. Foundation; either version 1, or (at your option) any later version.  
  524. X
  525. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  526. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  527. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  528. X
  529. You should have received a copy of the GNU General Public License along with
  530. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 675
  531. Mass Ave, Cambridge, MA 02139, USA.  */ 
  532. X
  533. #include <stdio.h>
  534. #include <signal.h>
  535. #include <fcntl.h>
  536. #include <sys/time.h>
  537. #include <sys/param.h>
  538. #include <termios.h>
  539. #include <unistd.h>
  540. #include "config.h"
  541. #include "heap.h"
  542. #include "tty.h"
  543. X
  544. #ifndef HZ
  545. #define HZ 10
  546. #endif
  547. X
  548. static struct termios oldterm;
  549. X
  550. char *obuf=0;
  551. int obufp=0;
  552. int obufsiz;
  553. unsigned long upc;
  554. unsigned baud;
  555. int have=0;
  556. int leave=0;
  557. static int ttymode=0;
  558. static char havec;
  559. FILE *term=0;
  560. X
  561. static speed_t speeds[]=
  562. {
  563. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  564. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400,B19200,19200,
  565. B38400,38400
  566. };
  567. X
  568. void esignal(a,b)
  569. int a;
  570. void (*b)();
  571. {
  572. struct sigaction action;
  573. sigemptyset(&action.sa_mask);
  574. action.sa_flags=0;
  575. action.sa_handler=b;
  576. sigaction(a,&action,NULL);
  577. }
  578. X
  579. void sigjoe()
  580. {
  581. esignal(SIGHUP,ttsig);
  582. esignal(SIGTERM,ttsig);
  583. esignal(SIGPIPE,SIG_IGN);
  584. esignal(SIGINT,SIG_IGN);
  585. esignal(SIGQUIT,SIG_IGN);
  586. }
  587. X
  588. void signrm()
  589. {
  590. esignal(SIGHUP,SIG_DFL);
  591. esignal(SIGTERM,SIG_DFL);
  592. esignal(SIGQUIT,SIG_DFL);
  593. esignal(SIGPIPE,SIG_DFL);
  594. esignal(SIGINT,SIG_DFL);
  595. }
  596. X
  597. void ttopen()
  598. {
  599. sigjoe();
  600. ttopnn();
  601. }
  602. X
  603. void ttopnn()
  604. {
  605. int x;
  606. speed_t bd;
  607. struct termios newterm;
  608. if(!term && !(term=fopen("/dev/tty","r+")))
  609. X {
  610. X fprintf(stderr,"Couldn\'t open tty\n");
  611. X exit(1);
  612. X }
  613. if(ttymode) return;
  614. else ttymode=1;
  615. fflush(term);
  616. tcdrain(fileno(term));
  617. tcgetattr(fileno(term),&oldterm);
  618. newterm=oldterm;
  619. newterm.c_lflag&=0;
  620. newterm.c_iflag&=~(ICRNL|IGNCR|INLCR);
  621. newterm.c_oflag&=0;
  622. newterm.c_cc[VMIN]=1;
  623. newterm.c_cc[VTIME]=0;
  624. tcsetattr(fileno(term),TCSANOW,&newterm);
  625. upc=0;
  626. bd=cfgetospeed(&newterm);
  627. baud=9600;
  628. for(x=0;x!=34;x+=2)
  629. X if(bd==speeds[x])
  630. X  {
  631. X  baud=speeds[x+1];
  632. X  break;
  633. X  }
  634. {
  635. char *bs=getenv("BAUD");
  636. if(bs)
  637. X {
  638. X sscanf(bs,"%u",&baud);
  639. X }
  640. }
  641. upc=DIVIDEND/baud;
  642. if(obuf) free(obuf);
  643. if(!(TIMES*upc)) obufsiz=4096;
  644. else
  645. X {
  646. X obufsiz=1000000/(TIMES*upc);
  647. X if(obufsiz>4096) obufsiz=4096;
  648. X }
  649. if(!obufsiz) obufsiz=1;
  650. obuf=(char *)malloc(obufsiz);
  651. }
  652. X
  653. void ttclose()
  654. {
  655. ttclsn();
  656. signrm();
  657. }
  658. X
  659. void ttclsn()
  660. {
  661. int oleave=leave;
  662. if(ttymode) ttymode=0;
  663. else return;
  664. leave=1;
  665. ttflsh();
  666. tcsetattr(fileno(term),TCSANOW,&oldterm);
  667. leave=oleave;
  668. }
  669. X
  670. static int yep;
  671. X
  672. static void dosig() { yep=1; } 
  673. X
  674. int ttflsh()
  675. {
  676. if(obufp)
  677. X {
  678. X struct itimerval a,b;
  679. X unsigned long usec=obufp*upc;
  680. X if(usec>=500000/HZ && baud<38400)
  681. X  {
  682. X  a.it_value.tv_sec=usec/1000000;
  683. X  a.it_value.tv_usec=usec%1000000;
  684. X  a.it_interval.tv_usec=0;
  685. X  a.it_interval.tv_sec=0;
  686. X  esignal(SIGALRM,dosig);
  687. X  yep=0;
  688. X  sigsetmask(sigmask(SIGALRM));
  689. X  setitimer(ITIMER_REAL,&a,&b);
  690. X  write(fileno(term),obuf,obufp);
  691. X  while(!yep) sigpause(0);
  692. X  esignal(SIGALRM,SIG_DFL);
  693. X  }
  694. X else write(fileno(term),obuf,obufp);
  695. X obufp=0;
  696. X }
  697. if(!have && !leave)
  698. X {
  699. X fcntl(fileno(term),F_SETFL,O_NDELAY);
  700. X if(read(fileno(term),&havec,1)==1) have=1;
  701. X fcntl(fileno(term),F_SETFL,0);
  702. X }
  703. return 0;
  704. }
  705. X
  706. int ttgetc()
  707. {
  708. ttflsh();
  709. if(have) have=0;
  710. else if(read(fileno(term),&havec,1)<1) ttsig(0);
  711. return havec;
  712. }
  713. X
  714. void ttputs(s)
  715. char *s;
  716. {
  717. while(*s)
  718. X {
  719. X obuf[obufp++]= *(s++);
  720. X if(obufp==obufsiz) ttflsh();
  721. X }
  722. }
  723. X
  724. void ttgtsz(x,y)
  725. int *x, *y;
  726. {
  727. #ifdef TIOCGSIZE
  728. struct ttysize getit;
  729. #else
  730. #ifdef TIOCGWINSZ
  731. struct winsize getit;
  732. #endif
  733. #endif
  734. *x=0; *y=0;
  735. #ifdef TIOCGSIZE
  736. if(ioctl(fileno(term),TIOCGSIZE,&getit)!= -1)
  737. X {
  738. X *x=getit.ts_cols;
  739. X *y=getit.ts_lines;
  740. X }
  741. #else
  742. #ifdef TIOCGWINSZ
  743. if(ioctl(fileno(term),TIOCGWINSZ,&getit)!= -1)
  744. X {
  745. X *x=getit.ws_col;
  746. X *y=getit.ws_row;
  747. X }
  748. #endif
  749. #endif
  750. }
  751. X
  752. void ttshell(cmd)
  753. char *cmd;
  754. {
  755. int x,omode=ttymode;
  756. char *s=getenv("SHELL");
  757. if(!s) return;
  758. ttclsn();
  759. if(x=fork())
  760. X {
  761. X if(x!= -1) wait(0);
  762. X if(omode) ttopnn();
  763. X }
  764. else
  765. X {
  766. X signrm();
  767. X if(cmd) execl(s,s,"-c",cmd,NULL);
  768. X else
  769. X  {
  770. X  fprintf(stderr,"You are at the command shell.  Type 'exit' to return\n");
  771. X  execl(s,s,NULL);
  772. X  }
  773. X _exit(0);
  774. X }
  775. }
  776. X
  777. static int gotsig;
  778. X
  779. static void dosi()
  780. {
  781. gotsig=1;
  782. }
  783. X
  784. void ttsusp()
  785. {
  786. #ifdef SIGCONT
  787. int omode=ttymode;
  788. ttclsn();
  789. gotsig=0;
  790. fprintf(stderr,"You have suspended the program.  Type \'fg\' to return\n");
  791. esignal(SIGCONT,dosi);
  792. sigsetmask(sigmask(SIGCONT));
  793. kill(0,SIGTSTP);
  794. while(!gotsig) sigpause(0);
  795. esignal(SIGCONT,SIG_DFL);
  796. if(omode) ttopnn();
  797. #else
  798. ttshell(NULL);
  799. #endif
  800. }
  801. X
  802. char *getcwd();
  803. char *pwd()
  804. {
  805. static char buf[1024];
  806. return getcwd(buf,1024);
  807. }
  808. SHAR_EOF
  809. chmod 0600 ttyposix.c ||
  810. echo 'restore of ttyposix.c failed'
  811. Wc_c="`wc -c < 'ttyposix.c'`"
  812. test 5008 -eq "$Wc_c" ||
  813.     echo 'ttyposix.c: original size 5008, current size' "$Wc_c"
  814. fi
  815. # ============= ttysv.c ==============
  816. if test -f 'ttysv.c' -a X"$1" != X"-c"; then
  817.     echo 'x - skipping ttysv.c (File already exists)'
  818. else
  819. echo 'x - extracting ttysv.c (Text)'
  820. sed 's/^X//' << 'SHAR_EOF' > 'ttysv.c' &&
  821. /* TTY interface for SYS V UNIX
  822. X   Copyright (C) 1991 Joseph H. Allen
  823. X
  824. This file is part of JOE (Joe's Own Editor)
  825. X
  826. JOE is free software; you can redistribute it and/or modify it under the terms
  827. of the GNU General Public License as published by the Free Software
  828. Foundation; either version 1, or (at your option) any later version. 
  829. X
  830. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  831. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  832. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  833. X
  834. You should have received a copy of the GNU General Public License
  835. along with JOE; see the file COPYING.  If not, write to
  836. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  837. X
  838. #include <stdio.h>
  839. #include <signal.h>
  840. #include <fcntl.h>
  841. #include <time.h>
  842. #include <sys/param.h>
  843. #include <termio.h>
  844. #include "config.h"
  845. #include "tty.h"
  846. X
  847. static struct termio oldterm;
  848. X
  849. #ifndef HZ
  850. #define HZ 10
  851. #endif
  852. X
  853. FILE *term=0;
  854. X
  855. char *obuf=0;
  856. int obufp=0;
  857. int obufsiz;
  858. X
  859. unsigned baud;
  860. unsigned long upc;
  861. X
  862. static int speeds[]=
  863. {
  864. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  865. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400
  866. };
  867. X
  868. int leave=0;
  869. static char havec;
  870. int have=0;
  871. static int ttymode=0;
  872. X
  873. void sigjoe()
  874. {
  875. signal(SIGHUP,ttsig);
  876. signal(SIGTERM,ttsig);
  877. signal(SIGINT,SIG_IGN);
  878. signal(SIGPIPE,SIG_IGN);
  879. signal(SIGQUIT,SIG_IGN);
  880. }
  881. X
  882. void signrm()
  883. {
  884. signal(SIGHUP,SIG_DFL);
  885. signal(SIGTERM,SIG_DFL);
  886. signal(SIGINT,SIG_DFL);
  887. signal(SIGPIPE,SIG_DFL);
  888. signal(SIGQUIT,SIG_DFL);
  889. }
  890. X
  891. void ttopen()
  892. {
  893. sigjoe();
  894. ttopnn();
  895. }
  896. X
  897. void ttopnn()
  898. {
  899. int x;
  900. struct termio newterm;
  901. if(!term && !(term=fopen("/dev/tty","r+")))
  902. X {
  903. X fprintf(stderr,"Couldn\'t open tty\n");
  904. X exit(1);
  905. X }
  906. if(ttymode) return;
  907. else ttymode=1;
  908. fflush(term);
  909. ioctl(fileno(term),TCGETA,&oldterm);
  910. newterm=oldterm;
  911. newterm.c_lflag=0;
  912. newterm.c_iflag&=~(ICRNL|IGNCR|INLCR);
  913. newterm.c_oflag=0;
  914. newterm.c_cc[VMIN]=1;
  915. newterm.c_cc[VTIME]=0;
  916. ioctl(fileno(term),TCSETAW,&newterm);
  917. upc=0;
  918. baud=9600;
  919. for(x=0;x!=30;x+=2)
  920. X if((newterm.c_cflag&CBAUD)==speeds[x])
  921. X  {
  922. X  baud=speeds[x+1];
  923. X  break;
  924. X  }
  925. {
  926. char *bs=getenv("BAUD");
  927. if(bs)
  928. X {
  929. X sscanf(bs,"%u",&baud);
  930. X }
  931. }
  932. upc=DIVIDEND/baud;
  933. if(obuf) free(obuf);
  934. if(!(TIMES*upc)) obufsiz=4096;
  935. else
  936. X {
  937. X obufsiz=1000000/(TIMES*upc);
  938. X if(obufsiz>4096) obufsiz=4096;
  939. X }
  940. if(!obufsiz) obufsiz=1;
  941. obuf=(char *)malloc(obufsiz);
  942. }
  943. X
  944. void ttclose()
  945. {
  946. ttclsn();
  947. signrm();
  948. }
  949. X
  950. void ttclsn()
  951. {
  952. int oleave=leave;
  953. if(ttymode) ttymode=0;
  954. else return;
  955. leave=1;
  956. ttflsh();
  957. ioctl(fileno(term),TCSETAW,&oldterm);
  958. leave=oleave;
  959. }
  960. X
  961. int ttflsh()
  962. {
  963. if(obufp)
  964. X {
  965. X write(fileno(term),obuf,obufp);
  966. X obufp=0;
  967. X }
  968. /* Oh well, nothing but a second timer in SYS V */
  969. if(!have && !leave)
  970. X {
  971. X fcntl(fileno(term),F_SETFL,O_NDELAY);
  972. X if(read(fileno(term),&havec,1)==1) have=1;
  973. X fcntl(fileno(term),F_SETFL,0);
  974. X }
  975. return 0;
  976. }
  977. X
  978. int ttgetc()
  979. {
  980. ttflsh();
  981. if(have) have=0;
  982. else if(read(fileno(term),&havec,1)<1) ttsig(0);
  983. return havec;
  984. }
  985. X
  986. void ttputs(s)
  987. char *s;
  988. {
  989. while(*s)
  990. X {
  991. X obuf[obufp++]= *(s++);
  992. X if(obufp==obufsiz) ttflsh();
  993. X }
  994. }
  995. X
  996. void ttgtsz(x,y)
  997. int *x, *y;
  998. {
  999. #ifdef TIOCGSIZE
  1000. struct ttysize getit;
  1001. #else
  1002. #ifdef TIOCGWINSZ
  1003. struct winsize getit;
  1004. #endif
  1005. #endif
  1006. *x=0; *y=0;
  1007. #ifdef TIOCGSIZE
  1008. if(ioctl(fileno(term),TIOCGSIZE,&getit)!= -1)
  1009. X {
  1010. X *x=getit.ts_cols;
  1011. X *y=getit.ts_lines;
  1012. X }
  1013. #else
  1014. #ifdef TIOCGWINSZ
  1015. if(ioctl(fileno(term),TIOCGWINSZ,&getit)!= -1)
  1016. X {
  1017. X *x=getit.ws_col;
  1018. X *y=getit.ws_row;
  1019. X }
  1020. #endif
  1021. #endif
  1022. }
  1023. X
  1024. void ttshell(cmd)
  1025. char *cmd;
  1026. {
  1027. int x,omode=ttymode;
  1028. char *s=getenv("SHELL");
  1029. if(!s) return;
  1030. ttclsn();
  1031. if(x=fork())
  1032. X {
  1033. X if(x!= -1) wait(0);
  1034. X if(omode) ttopnn();
  1035. X }
  1036. else
  1037. X {
  1038. X signrm();
  1039. X if(cmd) execl(s,s,"-c",cmd,NULL);
  1040. X else
  1041. X  {
  1042. X  fprintf(stderr,"You are at the command shell.  Type 'exit' to return\n");
  1043. X  execl(s,s,NULL);
  1044. X  }
  1045. X _exit(0);
  1046. X }
  1047. }
  1048. X
  1049. static int gotsig;
  1050. X
  1051. static void dosi()
  1052. {
  1053. gotsig=1;
  1054. }
  1055. X
  1056. void ttsusp()
  1057. {
  1058. #ifdef SIGCONT
  1059. int omode=ttymode;
  1060. ttclsn();
  1061. gotsig=0;
  1062. fprintf(stderr,"You have suspended the program.  Type \'fg\' to return\n");
  1063. signal(SIGCONT,dosi);
  1064. sigsetmask(sigmask(SIGCONT));
  1065. kill(0,SIGTSTP);
  1066. while(!gotsig) sigpause(0);
  1067. signal(SIGCONT,SIG_DFL);
  1068. if(omode) ttopnn();
  1069. #else
  1070. ttshell(NULL);
  1071. #endif
  1072. }
  1073. X
  1074. char *getcwd();
  1075. char *pwd()
  1076. {
  1077. static char buf[1024];
  1078. return getcwd(buf,1024);
  1079. }
  1080. SHAR_EOF
  1081. chmod 0600 ttysv.c ||
  1082. echo 'restore of ttysv.c failed'
  1083. Wc_c="`wc -c < 'ttysv.c'`"
  1084. test 4269 -eq "$Wc_c" ||
  1085.     echo 'ttysv.c: original size 4269, current size' "$Wc_c"
  1086. fi
  1087. # ============= ttyxenix.c ==============
  1088. if test -f 'ttyxenix.c' -a X"$1" != X"-c"; then
  1089.     echo 'x - skipping ttyxenix.c (File already exists)'
  1090. else
  1091. echo 'x - extracting ttyxenix.c (Text)'
  1092. sed 's/^X//' << 'SHAR_EOF' > 'ttyxenix.c' &&
  1093. /* Terminal interface for XENIX
  1094. X   Copyright (C) 1991 Joseph H. Allen
  1095. X
  1096. This file is part of JOE (Joe's Own Editor)
  1097. X
  1098. JOE is free software; you can redistribute it and/or modify it under the terms
  1099. of the GNU General Public License as published by the Free Software
  1100. Foundation; either version 1, or (at your option) any later version. 
  1101. X
  1102. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  1103. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  1104. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  1105. X
  1106. You should have received a copy of the GNU General Public License
  1107. along with JOE; see the file COPYING.  If not, write to
  1108. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1109. X
  1110. #include <stdio.h>
  1111. #include <signal.h>
  1112. #include <termio.h>
  1113. #include "config.h"
  1114. #include "heap.h"
  1115. #include "tty.h"
  1116. X
  1117. FILE *term=0;
  1118. X
  1119. /* Original state of the tty */
  1120. X
  1121. static struct termio oldterm;
  1122. X
  1123. /* Output buffer, index and size */
  1124. X
  1125. char *obuf=0;
  1126. int obufp=0;
  1127. int obufsiz;
  1128. X
  1129. /* Baud rate */
  1130. X
  1131. unsigned long upc;
  1132. unsigned baud;
  1133. X
  1134. /* Baud rate code to baud rate translation table */
  1135. X
  1136. static int speeds[]=
  1137. {
  1138. B50,50,B75,75,B110,110,B134,134,B150,150,B200,200,B300,300,B600,600,B1200,1200,
  1139. B1800,1800,B2400,2400,B4800,4800,B9600,9600,EXTA,19200,EXTB,38400
  1140. };
  1141. X
  1142. /* 'Typeahead' and 'editor is about to exit' flag */
  1143. X
  1144. int have=0;
  1145. int leave=0;
  1146. static int ttymode=0;
  1147. X
  1148. void sigjoe()
  1149. {
  1150. signal(SIGHUP,ttsig);
  1151. signal(SIGTERM,ttsig);
  1152. signal(SIGINT,SIG_IGN);
  1153. signal(SIGPIPE,SIG_IGN);
  1154. }
  1155. X
  1156. void signrm()
  1157. {
  1158. signal(SIGHUP,SIG_DFL);
  1159. signal(SIGTERM,SIG_DFL);
  1160. signal(SIGINT,SIG_DFL);
  1161. signal(SIGPIPE,SIG_DFL);
  1162. }
  1163. X
  1164. void ttopen()
  1165. {
  1166. sigjoe();
  1167. ttopnn();
  1168. }
  1169. X
  1170. void ttopnn()
  1171. {
  1172. int x;
  1173. struct termio newterm;
  1174. if(!term && !(term=fopen("/dev/tty","r+")))
  1175. X {
  1176. X fprintf(stderr,"Couldn\'t open tty\n");
  1177. X exit(1);
  1178. X }
  1179. if(ttymode) return;
  1180. else ttymode=1;
  1181. fflush(term);
  1182. ioctl(fileno(term),TCGETA,&oldterm);
  1183. newterm=oldterm;
  1184. newterm.c_lflag=0;
  1185. newterm.c_iflag&=~(ICRNL|IGNCR|INLCR);
  1186. newterm.c_oflag=0;
  1187. newterm.c_cc[VMIN]=1;
  1188. newterm.c_cc[VTIME]=0;
  1189. ioctl(fileno(term),TCSETAW,&newterm);
  1190. upc=0;
  1191. baud=9600;
  1192. for(x=0;x!=30;x+=2)
  1193. X if((newterm.c_cflag&CBAUD)==speeds[x])
  1194. X  {
  1195. X  baud=speeds[x+1];
  1196. X  break;
  1197. X  }
  1198. {
  1199. char *bs=getenv("BAUD");
  1200. if(bs)
  1201. X {
  1202. X sscanf(bs,"%u",&baud);
  1203. X }
  1204. }
  1205. upc=DIVIDEND/baud;
  1206. if(obuf) free(obuf);
  1207. if(!(TIMES*upc)) obufsiz=4096;
  1208. else
  1209. X {
  1210. X obufsiz=1000000/(TIMES*upc);
  1211. X if(obufsiz>4096) obufsiz=4096;
  1212. X }
  1213. if(!obufsiz) obufsiz=1;
  1214. obuf=(char *)malloc(obufsiz);
  1215. }
  1216. X
  1217. void ttclose()
  1218. {
  1219. ttclsn();
  1220. signrm();
  1221. }
  1222. X
  1223. void ttclsn()
  1224. {
  1225. int oleave=leave;
  1226. if(ttymode) ttymode=0;
  1227. else return;
  1228. leave=1;
  1229. ttflsh();
  1230. ioctl(fileno(term),TCSETAW,&oldterm);
  1231. leave=oleave;
  1232. }
  1233. X
  1234. int ttflsh()
  1235. {
  1236. if(obufp)
  1237. X {
  1238. X write(fileno(term),obuf,obufp);
  1239. X if(baud<38400) if(obufp*upc/1000) nap(obufp*upc/1000);
  1240. X obufp=0;
  1241. X }
  1242. if(!have && !leave) if(rdchk(fileno(term))>0) have=1;
  1243. return 0;
  1244. }
  1245. X
  1246. int ttgetc()
  1247. {
  1248. char c;
  1249. ttflsh();
  1250. if(read(fileno(term),&c,1)<1) ttsig(0);
  1251. have=0;
  1252. return c;
  1253. }
  1254. X
  1255. void ttputs(s)
  1256. char *s;
  1257. {
  1258. while(*s)
  1259. X {
  1260. X obuf[obufp++]= *(s++);
  1261. X if(obufp==obufsiz) ttflsh();
  1262. X }
  1263. }
  1264. X
  1265. void ttgtsz(x,y)
  1266. int *x, *y;
  1267. {
  1268. #ifdef TIOCGSIZE
  1269. struct ttysize getit;
  1270. #else
  1271. #ifdef TIOCGWINSZ
  1272. struct winsize getit;
  1273. #endif
  1274. #endif
  1275. *x=0; *y=0;
  1276. #ifdef TIOCGSIZE
  1277. if(ioctl(fileno(term),TIOCGSIZE,&getit)!= -1)
  1278. X {
  1279. X *x=getit.ts_cols;
  1280. X *y=getit.ts_lines;
  1281. X }
  1282. #else
  1283. #ifdef TIOCGWINSZ
  1284. if(ioctl(fileno(term),TIOCGWINSZ,&getit)!= -1)
  1285. X {
  1286. X *x=getit.ws_col;
  1287. X *y=getit.ws_row;
  1288. X }
  1289. #endif
  1290. #endif
  1291. }
  1292. X
  1293. void ttshell(cmd)
  1294. char *cmd;
  1295. {
  1296. int x,omode=ttymode;
  1297. char *s=getenv("SHELL");
  1298. if(!s) return;
  1299. ttclsn();
  1300. if(x=fork())
  1301. X {
  1302. X if(x!= -1) wait(0);
  1303. X if(omode) ttopnn();
  1304. X }
  1305. else
  1306. X {
  1307. X signrm();
  1308. X if(cmd) execl(s,s,"-c",cmd,NULL);
  1309. X else
  1310. X  {
  1311. X  fprintf(stderr,"You are at the command shell.  Type 'exit' to return\n");
  1312. X  execl(s,s,NULL);
  1313. X  }
  1314. X _exit(0);
  1315. X }
  1316. }
  1317. X
  1318. static int gotsig;
  1319. X
  1320. static void dosi()
  1321. {
  1322. gotsig=1;
  1323. }
  1324. X
  1325. void ttsusp()
  1326. {
  1327. #ifdef SIGCONT
  1328. int omode=ttymode;
  1329. ttclsn();
  1330. gotsig=0;
  1331. fprintf(stderr,"You have suspended the program.  Type \'fg\' to return\n");
  1332. signal(SIGCONT,dosi);
  1333. sigsetmask(sigmask(SIGCONT));
  1334. kill(0,SIGTSTP);
  1335. while(!gotsig) sigpause(0);
  1336. signal(SIGCONT,SIG_DFL);
  1337. if(omode) ttopnn();
  1338. #else
  1339. ttshell(NULL);
  1340. #endif
  1341. }
  1342. X
  1343. char *getcwd();
  1344. char *pwd()
  1345. {
  1346. static char buf[1024];
  1347. return getcwd(buf,1024);
  1348. }
  1349. SHAR_EOF
  1350. chmod 0600 ttyxenix.c ||
  1351. echo 'restore of ttyxenix.c failed'
  1352. Wc_c="`wc -c < 'ttyxenix.c'`"
  1353. test 4223 -eq "$Wc_c" ||
  1354.     echo 'ttyxenix.c: original size 4223, current size' "$Wc_c"
  1355. fi
  1356. # ============= tw.c ==============
  1357. if test -f 'tw.c' -a X"$1" != X"-c"; then
  1358.     echo 'x - skipping tw.c (File already exists)'
  1359. else
  1360. echo 'x - extracting tw.c (Text)'
  1361. sed 's/^X//' << 'SHAR_EOF' > 'tw.c' &&
  1362. /* Text editing windows
  1363. X   Copyright (C) 1992 Joseph H. Allen
  1364. X
  1365. This file is part of JOE (Joe's Own Editor)
  1366. X
  1367. JOE is free software; you can redistribute it and/or modify it under the 
  1368. terms of the GNU General Public License as published by the Free Software 
  1369. Foundation; either version 1, or (at your option) any later version.  
  1370. X
  1371. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1372. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1373. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1374. details.  
  1375. X
  1376. You should have received a copy of the GNU General Public License along with 
  1377. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  1378. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  1379. X
  1380. #include "config.h"
  1381. #include "heap.h"
  1382. #include "w.h"
  1383. #include "toomany.h"
  1384. #include "termcap.h"
  1385. #include "vfile.h"
  1386. #include "b.h"
  1387. #include "edfuncs.h"
  1388. #include "tty.h"
  1389. #include "kbd.h"
  1390. #include "scrn.h"
  1391. #include "bw.h"
  1392. #include "zstr.h"
  1393. #include "vs.h"
  1394. #include "help.h"
  1395. #include "undo.h"
  1396. #include "main.h"
  1397. #include "macro.h"
  1398. #include "tw.h"
  1399. X
  1400. extern char *exmsg;
  1401. X
  1402. /* Update a text window */
  1403. X
  1404. static void followtw(w)
  1405. W *w;
  1406. {
  1407. BW *bw=(BW *)w->object;
  1408. bwfllw(bw);
  1409. }
  1410. X
  1411. int starow=0;
  1412. int stacol=0;
  1413. X
  1414. static void disptw(w)
  1415. W *w;
  1416. {
  1417. P *p;
  1418. char buf[40];
  1419. BW *bw=(BW *)w->object;
  1420. TW *tw=(TW *)bw->object;
  1421. X
  1422. w->cury=bw->cursor->line-bw->top->line+bw->y-w->y;
  1423. w->curx=bw->cursor->xcol-bw->offset+bw->x-w->x;
  1424. X
  1425. if(starow!=tw->starow || stacol!=tw->stacol ||
  1426. X   starow || stacol) w->t->t->updtab[w->y]=1;
  1427. if(bw->b->name==tw->stanam) goto nosta0;
  1428. if(bw->b->name && tw->stanam && !zcmp(bw->b->name,tw->stanam)) goto nosta0;
  1429. if(tw->stanam) free(tw->stanam), tw->stanam=0;
  1430. if(bw->b->name) tw->stanam=zdup(bw->b->name);
  1431. w->t->t->updtab[w->y]=1;
  1432. nosta0:
  1433. if(bw->b->chnged!=tw->stamod) w->t->t->updtab[w->y]=1;
  1434. if(tw->stahlp!=!!w->t->wind) w->t->t->updtab[w->y]=1;
  1435. if(tw->starec!=recmac) w->t->t->updtab[w->y]=1;
  1436. X
  1437. if(!w->t->t->updtab[w->y]) goto nosta;
  1438. X
  1439. tw->stahlp=!!w->t->wind;
  1440. tw->stamod=bw->b->chnged;
  1441. tw->starec=recmac;
  1442. tw->stalin=vstrunc(tw->stalin,0);
  1443. X
  1444. tw->starow=starow;
  1445. if(starow)
  1446. X {
  1447. X tw->stalin=vsncpy(tw->stalin,0,sc("R="));
  1448. X sprintf(buf,"%4ld",bw->cursor->line+1);
  1449. X tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sz(buf));
  1450. X tw->stalin=vsadd(tw->stalin,' ');
  1451. X }
  1452. tw->stacol=stacol;
  1453. if(stacol)
  1454. X {
  1455. X tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sc("C="));
  1456. X sprintf(buf,"%3ld",bw->cursor->col+1);
  1457. X tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sz(buf));
  1458. X tw->stalin=vsadd(tw->stalin,' ');
  1459. X }
  1460. if(bw->b->name) tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sz(bw->b->name));
  1461. else tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sc("(Unnamed)"));
  1462. if(bw->b->chnged) tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sc(" (Modified)"));
  1463. if(recmac)
  1464. X {
  1465. X sprintf(buf," (Macro %d recording...)",recmac->n);
  1466. X tw->stalin=vsncpy(tw->stalin,sLEN(tw->stalin),sz(buf));
  1467. X }
  1468. X
  1469. tw->stalin=vstrunc(tw->stalin,w->w);
  1470. if(!w->t->wind && w->w>=40)
  1471. X tw->stalin=vsncpy(tw->stalin,w->w-17,sc("Ctrl-K H for help"));
  1472. X
  1473. /* Output status line */
  1474. X {
  1475. X int z;
  1476. X int *s=w->t->t->scrn+w->x+w->t->t->co*w->y;
  1477. X for(z=0;tw->stalin[z];++z)
  1478. X  {
  1479. X  if(have) goto nosta;
  1480. X  if(s[z]!=(unsigned char)tw->stalin[z]+INVERSE)
  1481. X   {
  1482. X   int c=s[z]=(unsigned char)tw->stalin[z]+INVERSE;
  1483. X   outatr(w->t->t,w->x+z,w->y,c);
  1484. X   }
  1485. X  }
  1486. X }
  1487. w->t->t->updtab[w->y]=0;
  1488. nosta:
  1489. X
  1490. bwgen(bw);
  1491. }
  1492. X
  1493. /* Abort text window */
  1494. X
  1495. static void killtw(w)
  1496. W *w;
  1497. {
  1498. BW *bw=(BW *)w->object;
  1499. TW *tw=(TW *)bw->object;
  1500. bwrm(bw);
  1501. vsrm(tw->stalin);
  1502. free(tw);
  1503. }
  1504. X
  1505. /* Move text window */
  1506. X
  1507. static void movetw(w,x,y)
  1508. W *w;
  1509. int x,y;
  1510. {
  1511. BW *bw=(BW *)w->object;
  1512. bwmove(bw,x,y+1);
  1513. }
  1514. X
  1515. /* Resize text window */
  1516. X
  1517. static void resizetw(w,wi,he)
  1518. W *w;
  1519. int wi,he;
  1520. {
  1521. BW *bw=(BW *)w->object;
  1522. bwresz(bw,wi,he-1);
  1523. }
  1524. X
  1525. /* Split current window */
  1526. X
  1527. void usplitw(w)
  1528. W *w;
  1529. {
  1530. BW *bw=(BW *)w->object;
  1531. TW *tw=(TW *)bw->object;
  1532. int newh=getgrouph(w);
  1533. W *new;
  1534. TW *newtw;
  1535. BW *newbw;
  1536. if(newh/2<FITHEIGHT) return;
  1537. new=wcreate(w->t,w->watom,findbotw(w),NULL,w,newh/2+(newh&1),NULL);
  1538. if(!new) return;
  1539. new->object=(void *)(newbw=bwmk(w->t,bw->b,new->x,new->y+1,new->w,new->h-1));
  1540. ++bw->b->count;
  1541. newbw->lmargin=bw->lmargin;
  1542. newbw->rmargin=bw->rmargin;
  1543. newbw->autoindent=bw->autoindent;
  1544. newbw->wordwrap=bw->wordwrap;
  1545. newbw->overtype=bw->overtype;
  1546. newbw->indentc=bw->indentc;
  1547. newbw->istep=bw->istep;
  1548. newbw->offset=bw->offset;
  1549. newbw->object=(void *)(newtw=(TW *)malloc(sizeof(TW)));
  1550. newtw->staupd=tw->staupd;
  1551. newtw->stanam=0;
  1552. newtw->stalin=0;
  1553. newtw->stamod=0;
  1554. newtw->stahlp=0;
  1555. pset(newbw->top,bw->top);
  1556. pset(newbw->cursor,bw->cursor);
  1557. new->t->curwin=new;
  1558. }
  1559. X
  1560. /* User routine for aborting a text window */
  1561. X
  1562. void uaborttw(w)
  1563. W *w;
  1564. {
  1565. BW *bw=(BW *)w->object;
  1566. TW *tw=(TW *)bw->object;
  1567. if(bw->b->chnged && bw->b->count==1)
  1568. X {
  1569. X int c=query(w,"Loose changes to this file (y,n)? ");
  1570. X if(c!='y' && c!='Y') return;
  1571. X if(bw->b->name)
  1572. X  {
  1573. X  exmsg=vsncpy(NULL,0,sc("File "));
  1574. X  exmsg=vsncpy(exmsg,sLEN(exmsg),sz(bw->b->name));
  1575. X  exmsg=vsncpy(exmsg,sLEN(exmsg),sc(" not saved."));
  1576. X  }
  1577. X else exmsg=vsncpy(NULL,0,sc("File (Unnamed) not saved."));
  1578. X }
  1579. else if(!exmsg)
  1580. X {
  1581. X if(bw->b->name)
  1582. X  {
  1583. X  exmsg=vsncpy(NULL,0,sc("File "));
  1584. X  exmsg=vsncpy(exmsg,sLEN(exmsg),sz(bw->b->name));
  1585. X  exmsg=vsncpy(exmsg,sLEN(exmsg),sc(" not changed so no update needed."));
  1586. X  }
  1587. X else exmsg=vsncpy(NULL,0,sc("File (Unnamed) not changed so no update needed."));
  1588. X }
  1589. wabort(w);        /* Eliminate this window and it's children */
  1590. if(!leave) if(exmsg) vsrm(exmsg), exmsg=0;
  1591. }
  1592. X
  1593. void ucheckp(w)
  1594. W *w;
  1595. {
  1596. BW *bw=(BW *)w->object;
  1597. checkp(bw->b);
  1598. }
  1599. X
  1600. void ucheck(w)
  1601. W *w;
  1602. {
  1603. BW *bw=(BW *)w->object;
  1604. check(bw->b);
  1605. }
  1606. X
  1607. CONTEXT cmain={"main",0};
  1608. X
  1609. static void instw(w,b,l,n,flg)
  1610. W *w;
  1611. B *b;
  1612. long l,n;
  1613. int flg;
  1614. {
  1615. BW *bw=(BW *)w->object;
  1616. if(b==bw->b) bwins(bw,l,n,flg);
  1617. }
  1618. X
  1619. static void deltw(w,b,l,n,flg)
  1620. W *w;
  1621. B *b;
  1622. long l,n;
  1623. int flg;
  1624. {
  1625. BW *bw=(BW *)w->object;
  1626. if(b==bw->b) bwdel(bw,l,n,flg);
  1627. }
  1628. X
  1629. static WATOM watomtw=
  1630. {
  1631. &cmain,
  1632. disptw,
  1633. followtw,
  1634. killtw,
  1635. resizetw,
  1636. movetw,
  1637. instw,
  1638. deltw,
  1639. TYPETW
  1640. };
  1641. X
  1642. /* Create a text window.  It becomes the last window on the screen */
  1643. X
  1644. W *wmktw(t,b)
  1645. SCREEN *t;
  1646. B *b;
  1647. {
  1648. W *w;
  1649. BW *bw;
  1650. TW *tw;
  1651. w=wcreate(t,&watomtw,NULL,NULL,NULL,t->h,NULL);
  1652. w->object=(void *)(bw=bwmk(t,b,w->x,w->y+1,w->w,w->h-1));
  1653. bw->object=(void *)(tw=(TW *)malloc(sizeof(TW)));
  1654. tw->staupd=1; /* Unneeded? */
  1655. tw->stanam=0;
  1656. tw->starec=recmac;
  1657. tw->stalin=0;
  1658. tw->stamod=0;
  1659. tw->stahlp=0;
  1660. tw->starow=starow;
  1661. tw->stacol=stacol;
  1662. return w;
  1663. }
  1664. SHAR_EOF
  1665. chmod 0600 tw.c ||
  1666. echo 'restore of tw.c failed'
  1667. Wc_c="`wc -c < 'tw.c'`"
  1668. test 6362 -eq "$Wc_c" ||
  1669.     echo 'tw.c: original size 6362, current size' "$Wc_c"
  1670. fi
  1671. # ============= tw.h ==============
  1672. if test -f 'tw.h' -a X"$1" != X"-c"; then
  1673.     echo 'x - skipping tw.h (File already exists)'
  1674. else
  1675. echo 'x - extracting tw.h (Text)'
  1676. sed 's/^X//' << 'SHAR_EOF' > 'tw.h' &&
  1677. /* Text editing windows
  1678. X   Copyright (C) 1992 Joseph H. Allen
  1679. X
  1680. This file is part of JOE (Joe's Own Editor)
  1681. X
  1682. JOE is free software; you can redistribute it and/or modify it under the 
  1683. terms of the GNU General Public License as published by the Free Software 
  1684. Foundation; either version 1, or (at your option) any later version.  
  1685. X
  1686. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1687. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1688. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1689. details.  
  1690. X
  1691. You should have received a copy of the GNU General Public License along with 
  1692. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  1693. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  1694. X
  1695. #ifndef _Itw
  1696. #define _Itw 1
  1697. X
  1698. #include "config.h"
  1699. #include "kbd.h"
  1700. #include "main.h"
  1701. X
  1702. typedef struct tw TW;
  1703. X
  1704. extern int starow, stacol;
  1705. X
  1706. struct tw
  1707. X {
  1708. X /* Status line info */
  1709. X char *stanam;
  1710. X char *stalin;
  1711. X int stamod;
  1712. X int stahlp;
  1713. X struct recmac *starec;
  1714. X int starow;
  1715. X int stacol;
  1716. X int staupd;            /* Set if status line should get updated */
  1717. X };
  1718. X
  1719. #define TYPETW 0x100
  1720. X
  1721. extern CONTEXT cmain;
  1722. X
  1723. /* W *wmktw(SCREEN *t,B *b)
  1724. X */
  1725. W *wmktw();
  1726. X
  1727. void uaborttw();
  1728. void usplitw();
  1729. void ucheck();
  1730. void ucheckp();
  1731. X
  1732. #endif
  1733. SHAR_EOF
  1734. chmod 0600 tw.h ||
  1735. echo 'restore of tw.h failed'
  1736. Wc_c="`wc -c < 'tw.h'`"
  1737. test 1265 -eq "$Wc_c" ||
  1738.     echo 'tw.h: original size 1265, current size' "$Wc_c"
  1739. fi
  1740. # ============= undo.c ==============
  1741. if test -f 'undo.c' -a X"$1" != X"-c"; then
  1742.     echo 'x - skipping undo.c (File already exists)'
  1743. else
  1744. echo 'x - extracting undo.c (Text)'
  1745. sed 's/^X//' << 'SHAR_EOF' > 'undo.c' &&
  1746. /* UNDO system
  1747. X   Copyright (C) 1992 Joseph H. Allen
  1748. X
  1749. This file is part of JOE (Joe's Own Editor)
  1750. X
  1751. JOE is free software; you can redistribute it and/or modify it under the 
  1752. terms of the GNU General Public License as published by the Free Software 
  1753. Foundation; either version 1, or (at your option) any later version.  
  1754. X
  1755. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  1756. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  1757. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  1758. details.  
  1759. X
  1760. You should have received a copy of the GNU General Public License along with 
  1761. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  1762. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  1763. X
  1764. #include "b.h"
  1765. #include "w.h"
  1766. #include "bw.h"
  1767. #include "undo.h"
  1768. X
  1769. static UNDO undos={{&undos,&undos}};
  1770. X
  1771. int inundo=0;
  1772. X
  1773. void undomk(b)
  1774. B *b;
  1775. {
  1776. UNDO *undo=(UNDO *)malloc(sizeof(UNDO));
  1777. undo->nrecs=0;
  1778. undo->ptr=0;
  1779. undo->first=0;
  1780. undo->last=0;
  1781. izque(UNDOREC,link,&undo->recs);
  1782. b->undo=undo;
  1783. enquef(UNDO,link,&undos,undo);
  1784. }
  1785. X
  1786. void undorm(b)
  1787. B *b;
  1788. {
  1789. UNDO *undo=b->undo;
  1790. while(!qempty(UNDOREC,link,&undo->recs))
  1791. X {
  1792. X free(undo->recs.link.next->data);
  1793. X free(deque(UNDOREC,link,undo->recs.link.next));
  1794. X }
  1795. free(deque(UNDO,link,undo));
  1796. }
  1797. X
  1798. void uundo(w)
  1799. W *w;
  1800. {
  1801. UNDOREC *upto;
  1802. BW *bw=(BW *)w->object;
  1803. UNDO *undo=bw->b->undo;
  1804. if(!undo->nrecs) return;
  1805. if(!undo->ptr)
  1806. X {
  1807. X if(undo->recs.link.prev->where!=bw->cursor->byte)
  1808. X  pfwrd(pbof(bw->cursor),undo->recs.link.prev->where);
  1809. X undo->ptr=&undo->recs;
  1810. /* return; */
  1811. X }
  1812. if(undo->ptr->link.prev==&undo->recs) return;
  1813. upto=undo->ptr->link.prev->unit;
  1814. loop:
  1815. undo->ptr=undo->ptr->link.prev;
  1816. if(undo->ptr->where!=bw->cursor->byte)
  1817. X pfwrd(pbof(bw->cursor),undo->ptr->where);
  1818. inundo=1;
  1819. if(undo->ptr->del)
  1820. X {
  1821. X binsm(bw->cursor,undo->ptr->data,undo->ptr->len);
  1822. X undo->ptr->del=0;
  1823. X }
  1824. else
  1825. X {
  1826. X P *q=pdup(bw->cursor);
  1827. X pfwrd(q,undo->ptr->len);
  1828. X bdel(bw->cursor,q);
  1829. X prm(q);
  1830. X undo->ptr->del=1;
  1831. X }
  1832. inundo=0;
  1833. if(upto && upto!=undo->ptr) goto loop;
  1834. if(undo->ptr->first) bw->b->chnged=0;
  1835. }
  1836. X
  1837. void uredo(w)
  1838. W *w;
  1839. {
  1840. UNDOREC *upto;
  1841. BW *bw=(BW *)w->object;
  1842. UNDO *undo=bw->b->undo;
  1843. if(!undo->ptr) return;
  1844. if(undo->ptr==&undo->recs) return;
  1845. upto=undo->ptr->unit;
  1846. loop:
  1847. if(undo->ptr->where!=bw->cursor->byte)
  1848. X pfwrd(pbof(bw->cursor),undo->ptr->where);
  1849. inundo=1;
  1850. if(undo->ptr->del)
  1851. X {
  1852. X binsm(bw->cursor,undo->ptr->data,undo->ptr->len);
  1853. X undo->ptr->del=0;
  1854. X }
  1855. else
  1856. X {
  1857. X P *q=pdup(bw->cursor);
  1858. X pfwrd(q,undo->ptr->len);
  1859. X bdel(bw->cursor,q);
  1860. X prm(q);
  1861. X undo->ptr->del=1;
  1862. X }
  1863. inundo=0;
  1864. undo->ptr=undo->ptr->link.next;
  1865. if(upto && upto!=undo->ptr->link.prev) goto loop;
  1866. }
  1867. X
  1868. static void undogc(undo)
  1869. UNDO *undo;
  1870. {
  1871. UNDOREC *unit=undo->recs.link.next->unit;
  1872. if(unit)
  1873. X while(unit!=undo->recs.link.next)
  1874. X  {
  1875. X  free(undo->recs.link.next->data);
  1876. X  free(deque(UNDOREC,link,undo->recs.link.next));
  1877. X  }
  1878. free(undo->recs.link.next->data);
  1879. free(deque(UNDOREC,link,undo->recs.link.next));
  1880. --undo->nrecs;
  1881. }
  1882. X
  1883. static void undomark1(undo)
  1884. UNDO *undo;
  1885. {
  1886. if(undo->first)
  1887. X {
  1888. X undo->first->unit=undo->last;
  1889. X undo->last->unit=undo->first;
  1890. X undo->first=undo->last=0;
  1891. X if(++undo->nrecs==UNDOKEEP) undogc(undo);
  1892. X }
  1893. }
  1894. X
  1895. void umclear()
  1896. {
  1897. UNDO *undo;
  1898. for(undo=undos.link.next;undo!=&undos;undo=undo->link.next)
  1899. X {
  1900. X UNDOREC *rec;
  1901. X for(rec=undo->recs.link.next;rec!=&undo->recs;rec=rec->link.next)
  1902. X  rec->min=0;
  1903. X }
  1904. }
  1905. X
  1906. void undomark()
  1907. {
  1908. UNDO *undo;
  1909. for(undo=undos.link.next;undo!=&undos;undo=undo->link.next) undomark1(undo);
  1910. }
  1911. X
  1912. static void undoover(undo)
  1913. UNDO *undo;
  1914. {
  1915. if(undo->ptr && undo->ptr!=&undo->recs)
  1916. X {
  1917. X while(undo->recs.link.prev!=undo->ptr)
  1918. X  {
  1919. X  free(undo->recs.link.prev->data);
  1920. X  free(deque(UNDOREC,link,undo->recs.link.prev));
  1921. X  }
  1922. X free(undo->recs.link.prev->data);
  1923. X free(deque(UNDOREC,link,undo->recs.link.prev));
  1924. X }
  1925. undo->ptr=0;
  1926. }
  1927. X
  1928. void undoins(p,size)
  1929. P *p;
  1930. long size;
  1931. {
  1932. UNDOREC *rec;
  1933. if(inundo) return;
  1934. undoover(p->b->undo);
  1935. rec=p->b->undo->recs.link.prev;
  1936. if(rec->min && rec!=&p->b->undo->recs && rec->del==0 && p->byte==rec->where+rec->len)
  1937. X {
  1938. X rec->data=(char *)realloc(rec->data,rec->len+size);
  1939. X brmem(p,rec->data+rec->len,size);
  1940. X rec->len+=size;
  1941. X }
  1942. else if(rec->min &&
  1943. X        rec!=&p->b->undo->recs && rec->del==0 && p->byte==rec->where)
  1944. X {
  1945. X rec->data=(char *)realloc(rec->data,rec->len+size);
  1946. X mmove(rec->data+size,rec->data,rec->len);
  1947. X brmem(p,rec->data,size);
  1948. X rec->len+=size;
  1949. X }
  1950. else
  1951. X {
  1952. X rec=(UNDOREC *)malloc(sizeof(UNDOREC));
  1953. X rec->data=(char *)malloc(size);
  1954. X if(!p->b->undo->first) p->b->undo->first=rec;
  1955. X p->b->undo->last=rec;
  1956. X rec->where=p->byte;
  1957. X rec->min=1;
  1958. X rec->unit=0;
  1959. X rec->len=size;
  1960. X rec->del=0;
  1961. X if(qempty(UNDOREC,link,&p->b->undo->recs) && !p->b->chnged) rec->first=1;
  1962. X else rec->first=0;
  1963. X brmem(p,rec->data,rec->len);
  1964. X enqueb(UNDOREC,link,&p->b->undo->recs,rec);
  1965. X }
  1966. }
  1967. X
  1968. void undodel(p,size)
  1969. P *p;
  1970. long size;
  1971. {
  1972. UNDOREC *rec;
  1973. if(inundo) return;
  1974. undoover(p->b->undo);
  1975. rec=p->b->undo->recs.link.prev;
  1976. if(rec->min && rec!=&p->b->undo->recs && rec->del==1
  1977. X   && p->byte==rec->where)
  1978. X {
  1979. X rec->data=(char *)realloc(rec->data,rec->len+size);
  1980. X brmem(p,rec->data+rec->len,size);
  1981. X rec->len+=size;
  1982. X }
  1983. else if(rec->min &&
  1984. X        rec!=&p->b->undo->recs && rec->del==1 && p->byte+size==rec->where)
  1985. X {
  1986. X rec->data=(char *)realloc(rec->data,rec->len+size);
  1987. X mmove(rec->data+size,rec->data,rec->len);
  1988. X brmem(p,rec->data,size);
  1989. X rec->len+=size;
  1990. X rec->where=p->byte;
  1991. X }
  1992. else
  1993. X {
  1994. X rec=(UNDOREC *)malloc(sizeof(UNDOREC));
  1995. X rec->data=(char *)malloc(size);
  1996. X if(!p->b->undo->first) p->b->undo->first=rec;
  1997. X p->b->undo->last=rec;
  1998. X rec->where=p->byte;
  1999. X rec->min=1;
  2000. X rec->unit=0;
  2001. X rec->len=size;
  2002. X rec->del=1;
  2003. X if(qempty(UNDOREC,link,&p->b->undo->recs) && !p->b->chnged) rec->first=1;
  2004. X else rec->first=0;
  2005. X brmem(p,rec->data,rec->len);
  2006. X enqueb(UNDOREC,link,&p->b->undo->recs,rec);
  2007. X }
  2008. }
  2009. SHAR_EOF
  2010. chmod 0600 undo.c ||
  2011. echo 'restore of undo.c failed'
  2012. Wc_c="`wc -c < 'undo.c'`"
  2013. test 5709 -eq "$Wc_c" ||
  2014.     echo 'undo.c: original size 5709, current size' "$Wc_c"
  2015. fi
  2016. # ============= undo.h ==============
  2017. if test -f 'undo.h' -a X"$1" != X"-c"; then
  2018.     echo 'x - skipping undo.h (File already exists)'
  2019. else
  2020. echo 'x - extracting undo.h (Text)'
  2021. sed 's/^X//' << 'SHAR_EOF' > 'undo.h' &&
  2022. /* UNDO system
  2023. X   Copyright (C) 1992 Joseph H. Allen
  2024. X
  2025. This file is part of JOE (Joe's Own Editor)
  2026. X
  2027. JOE is free software; you can redistribute it and/or modify it under the 
  2028. terms of the GNU General Public License as published by the Free Software 
  2029. Foundation; either version 1, or (at your option) any later version.  
  2030. X
  2031. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  2032. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  2033. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  2034. details.  
  2035. X
  2036. You should have received a copy of the GNU General Public License along with 
  2037. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  2038. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  2039. X
  2040. #ifndef _Iundo
  2041. #define _Iundo 1
  2042. X
  2043. #include "queue.h"
  2044. X
  2045. /* Number of undo records to keep */
  2046. X
  2047. #define UNDOKEEP 100
  2048. X
  2049. typedef struct undorec UNDOREC;
  2050. typedef struct undo UNDO;
  2051. X
  2052. extern int inundo;
  2053. X
  2054. /* An undo record */
  2055. struct undorec
  2056. X {
  2057. X LINK(UNDOREC) link;        /* Doubly linked list of undo records */
  2058. X int first;            /* Set if this is the first undo rec */
  2059. X int min;            /* Set if this is from a minor change */
  2060. X long where;            /* Buffer position this are from */
  2061. X int del;            /* Set for delete, Clr for insert */
  2062. X int len;            /* No. chars in this rec */
  2063. X UNDOREC *unit;            /* Last/First rec in unit */
  2064. X char *data;            /* The chars */
  2065. X };
  2066. X
  2067. /* An undo point */
  2068. struct undo
  2069. X {
  2070. X LINK(UNDO) link;        /* Doubly linked list of undo points */
  2071. X UNDOREC recs;            /* Undo records */
  2072. X int nrecs;            /* Number of undo records */
  2073. X UNDOREC *ptr;            /* Undo/Redo location */
  2074. X UNDOREC *first;        /* First of unit */
  2075. X UNDOREC *last;            /* Last of unit */
  2076. X };
  2077. X
  2078. void umclear();            /* Prevent combinding of undo recs */
  2079. void undomark();        /* Everything from prev. mark is a unit */
  2080. void undoend();
  2081. void undomk();
  2082. void undorm();
  2083. void uundo();
  2084. void uredo();
  2085. void undoins();
  2086. void undodel();
  2087. X
  2088. #endif
  2089. SHAR_EOF
  2090. chmod 0600 undo.h ||
  2091. echo 'restore of undo.h failed'
  2092. Wc_c="`wc -c < 'undo.h'`"
  2093. test 1901 -eq "$Wc_c" ||
  2094.     echo 'undo.h: original size 1901, current size' "$Wc_c"
  2095. fi
  2096. # ============= va.c ==============
  2097. if test -f 'va.c' -a X"$1" != X"-c"; then
  2098.     echo 'x - skipping va.c (File already exists)'
  2099. else
  2100. echo 'x - extracting va.c (Text)'
  2101. sed 's/^X//' << 'SHAR_EOF' > 'va.c' &&
  2102. /* Variable length array of strings
  2103. X   Copyright (C) 1992 Joseph H. Allen
  2104. X
  2105. This file is part of JOE (Joe's Own Editor)
  2106. X
  2107. JOE is free software; you can redistribute it and/or modify it under the 
  2108. terms of the GNU General Public License as published by the Free Software 
  2109. Foundation; either version 1, or (at your option) any later version.  
  2110. X
  2111. JOE is distributed in the hope that it will be useful, but WITHOUT ANY 
  2112. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  2113. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  2114. details.  
  2115. X
  2116. You should have received a copy of the GNU General Public License along with 
  2117. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 
  2118. 675 Mass Ave, Cambridge, MA 02139, USA.  */ 
  2119. X
  2120. #include "blocks.h"
  2121. #include "heap.h"
  2122. #include "zstr.h"
  2123. #include "va.h"
  2124. X
  2125. aELEMENT(*vamk(len))
  2126. int len;
  2127. {
  2128. int *new=(int *)malloc((1+len)*sizeof(aCAST)+2*sizeof(int));
  2129. new[0]=len;
  2130. new[1]=0;
  2131. ((aELEMENT(*))(new+2))[0]=aterm;
  2132. return (aELEMENT(*))(new+2);
  2133. }
  2134. X
  2135. void varm(vary)
  2136. aELEMENT(*vary);
  2137. {
  2138. if(vary)
  2139. X {
  2140. X vazap(vary,0,aLen(vary));
  2141. X free((int *)vary-2);
  2142. X }
  2143. }
  2144. X
  2145. int alen(ary)
  2146. aELEMENT(*ary);
  2147. {
  2148. if(ary)
  2149. X {
  2150. X aELEMENT(*beg)=ary;
  2151. X while(acmp(*ary,aterm)) ++ary;
  2152. X return ary-beg;
  2153. X }
  2154. else return 0;
  2155. }
  2156. X
  2157. aELEMENT(*vaensure(vary,len))
  2158. aELEMENT(*vary);
  2159. int len;
  2160. {
  2161. if(!vary) vary=vamk(len);
  2162. else if(len>aSiz(vary))
  2163. X {
  2164. X int x;
  2165. X len+=(len>>2);
  2166. X vary=(aELEMENT(*))(2+(int *)realloc(
  2167. X       (int *)vary-2,(len+1)*sizeof(aCAST)+2*sizeof(int) ));
  2168. X aSiz(vary)=len;
  2169. X }
  2170. return vary;
  2171. }
  2172. X
  2173. aELEMENT(*vazap(vary,pos,n))
  2174. aELEMENT(*vary);
  2175. int pos,n;
  2176. {
  2177. if(vary)
  2178. X {
  2179. X int x;
  2180. X if(pos<aLen(vary))
  2181. X  if(pos+n<=aLen(vary))
  2182. X   for(x=pos;x!=pos+n;++x) adel(vary[x]);
  2183. X  else
  2184. X   for(x=pos;x!=aLen(vary);++x) adel(vary[x]);
  2185. X }
  2186. return vary;
  2187. }
  2188. X
  2189. aELEMENT(*vatrunc(vary,len))
  2190. aELEMENT(*vary);
  2191. int len;
  2192. {
  2193. if(!vary || len>aLEN(vary)) vary=vaensure(vary,len);
  2194. if(len<aLen(vary))
  2195. X {
  2196. X vary=vazap(vary,len,aLen(vary)-len);
  2197. X vary[len]=vary[aLen(vary)];
  2198. X aLen(vary)=len;
  2199. X }
  2200. else if(len>aLen(vary))
  2201. X {
  2202. X vary=vafill(vary,aLen(vary),ablank,len-aLen(vary));
  2203. X }
  2204. return vary;
  2205. }
  2206. X
  2207. aELEMENT(*vafill(vary,pos,el,len))
  2208. aELEMENT(*vary);
  2209. aELEMENT(el);
  2210. int pos,len;
  2211. {
  2212. int olen=aLEN(vary), x;
  2213. if(!vary || pos+len>aSIZ(vary))
  2214. X vary=vaensure(vary,pos+len);
  2215. if(pos+len>olen)
  2216. X {
  2217. X vary[pos+len]=vary[olen];
  2218. X aLen(vary)=pos+len;
  2219. X }
  2220. for(x=pos;x!=pos+len;++x) vary[x]=adup(el);
  2221. if(pos>olen) vary=vafill(vary,pos,ablank,pos-olen);
  2222. return vary;
  2223. }
  2224. X
  2225. aELEMENT(*vancpy(vary,pos,array,len))
  2226. aELEMENT(*vary);
  2227. aELEMENT(*array);
  2228. int pos, len;
  2229. {
  2230. int olen=aLEN(vary);
  2231. if(!vary || pos+len>aSIZ(vary)) vary=vaensure(vary,pos+len);
  2232. if(pos+len>olen)
  2233. X {
  2234. X vary[pos+len]=vary[olen];
  2235. X aLen(vary)=pos+len;
  2236. X }
  2237. if(pos>olen) vary=vafill(vary,olen,ablank,pos-olen);
  2238. mfwrd(vary+pos,array,len*sizeof(aCAST));
  2239. return vary;
  2240. }
  2241. X
  2242. aELEMENT(*vandup(vary,pos,array,len))
  2243. aELEMENT(*vary);
  2244. aELEMENT(*array);
  2245. int pos, len;
  2246. {
  2247. int olen=aLEN(vary), x;
  2248. if(!vary || pos+len>aSIZ(vary)) vary=vaensure(vary,pos+len);
  2249. if(pos+len>olen)
  2250. X {
  2251. X vary[pos+len]=vary[olen];
  2252. X aLen(vary)=pos+len;
  2253. X }
  2254. if(pos>olen) vary=vafill(vary,olen,ablank,pos-olen);
  2255. for(x=pos;x!=len;++x) vary[x]=adup(array[x]);
  2256. return vary;
  2257. }
  2258. X
  2259. aELEMENT(*vafield(vary,pos,len))
  2260. aELEMENT(*vary);
  2261. int pos,len;
  2262. {
  2263. if(pos+len>aLEN(vary)) vary=vatrunc(vary,pos,len);
  2264. return vary;
  2265. }
  2266. X
  2267. aELEMENT(*vadup(vary))
  2268. aELEMENT(*vary);
  2269. {
  2270. return vandup(NULL,0,vary,aLEN(vary));
  2271. }
  2272. X
  2273. aELEMENT(*_vaset(vary,pos,el))
  2274. aELEMENT(*vary);
  2275. aELEMENT(el);
  2276. int pos;
  2277. {
  2278. if(!vary || pos+1>aSIZ(vary)) vary=vaensure(vary,pos+1);
  2279. if(pos>aLen(vary))
  2280. X {
  2281. X vary=vafill(vary,aLen(vary),ablank,pos-aLen(vary));
  2282. X vary[pos+1]=vary[pos];
  2283. X vary[pos]=el;
  2284. X aLen(vary)=pos+1;
  2285. X }
  2286. else if(pos==aLen(vary))
  2287. X {
  2288. X vary[pos+1]=vary[pos];
  2289. X vary[pos]=el;
  2290. X aLen(vary)=pos+1;
  2291. X }
  2292. else
  2293. X {
  2294. X adel(vary[pos]);
  2295. X vary[pos]=el;
  2296. X }
  2297. return vary;
  2298. }
  2299. X
  2300. aELEMENT(*vains(vary,pos,n))
  2301. aELEMENT(*vary);
  2302. int pos,n;
  2303. {
  2304. if(!vary || aLEN(vary)+n>aSIZ(vary)) vary=vaensure(vary,aLEN(vary)+n);
  2305. if(pos>=aLen(vary)) vary=vatrunc(vary,pos+n);
  2306. else
  2307. X {
  2308. X mbkwd(vary+pos+n,vary+pos,aLen(vary)-(pos+n)+1);
  2309. X aLen(vary)+=n;
  2310. X }
  2311. return vary;
  2312. }
  2313.