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

  1. From: pgf@cayman.COM (Paul Fox)
  2. Newsgroups: alt.sources
  3. Subject: Vile 17/17 - vi feel-alike (multi-window)
  4. Message-ID: <4536@cayman.COM>
  5. Date: 7 Jun 91 22:10:29 GMT
  6.  
  7. #!/bin/sh
  8. # this is vileshar.17 (part 17 of Vile)
  9. # do not concatenate these parts, unpack them in order with /bin/sh
  10. # file window.c continued
  11. #
  12. if test ! -r _shar_seq_.tmp; then
  13.     echo 'Please unpack part 1 first!'
  14.     exit 1
  15. fi
  16. (read Scheck
  17.  if test "$Scheck" != 17; then
  18.     echo Please unpack part "$Scheck" next!
  19.     exit 1
  20.  else
  21.     exit 0
  22.  fi
  23. ) < _shar_seq_.tmp || exit 1
  24. echo 'x - continuing file window.c'
  25. sed 's/^X//' << 'SHAR_EOF' >> 'window.c' &&
  26. X * all the hard work. You don't just set "force reframe" because dot would
  27. X * move.
  28. X */
  29. enlargewind(f, n)
  30. {
  31. X        register WINDOW *adjwp;
  32. X        register LINE   *lp;
  33. X        register int    i;
  34. X
  35. X        if (n < 0)
  36. X                return (shrinkwind(f, -n));
  37. X        if (wheadp->w_wndp == NULL) {
  38. X                mlwrite("Only one window");
  39. X                return (FALSE);
  40. X        }
  41. X        if ((adjwp=curwp->w_wndp) == NULL) {
  42. X                adjwp = wheadp;
  43. X                while (adjwp->w_wndp != curwp)
  44. X                        adjwp = adjwp->w_wndp;
  45. X        }
  46. X        if (adjwp->w_ntrows <= n) {
  47. X                mlwrite("Impossible change");
  48. X                return (FALSE);
  49. X        }
  50. X        if (curwp->w_wndp == adjwp) {           /* Shrink below.        */
  51. X                lp = adjwp->w_linep;
  52. X                for (i=0; i<n && lp!=adjwp->w_bufp->b_linep; ++i)
  53. X                        lp = lforw(lp);
  54. X                adjwp->w_linep  = lp;
  55. X                adjwp->w_toprow += n;
  56. X        } else {                                /* Shrink above.        */
  57. X                lp = curwp->w_linep;
  58. X                for (i=0; i<n && lback(lp)!=curbp->b_linep; ++i)
  59. X                        lp = lback(lp);
  60. X                curwp->w_linep  = lp;
  61. X                curwp->w_toprow -= n;
  62. X        }
  63. X        curwp->w_ntrows += n;
  64. X        adjwp->w_ntrows -= n;
  65. X        curwp->w_flag |= WFMODE|WFHARD|WFINS;
  66. X        adjwp->w_flag |= WFMODE|WFHARD|WFKILLS;
  67. X        return (TRUE);
  68. }
  69. X
  70. /*
  71. X * Shrink the current window. Find the window that gains space. Hack at the
  72. X * window descriptions. Ask the redisplay to do all the hard work.
  73. X */
  74. shrinkwind(f, n)
  75. {
  76. X        register WINDOW *adjwp;
  77. X        register LINE   *lp;
  78. X        register int    i;
  79. X
  80. X        if (n < 0)
  81. X                return (enlargewind(f, -n));
  82. X        if (wheadp->w_wndp == NULL) {
  83. X                mlwrite("Only one window");
  84. X                return (FALSE);
  85. X        }
  86. X        if ((adjwp=curwp->w_wndp) == NULL) {
  87. X                adjwp = wheadp;
  88. X                while (adjwp->w_wndp != curwp)
  89. X                        adjwp = adjwp->w_wndp;
  90. X        }
  91. X        if (curwp->w_ntrows <= n) {
  92. X                mlwrite("Impossible change");
  93. X                return (FALSE);
  94. X        }
  95. X        if (curwp->w_wndp == adjwp) {           /* Grow below.          */
  96. X                lp = adjwp->w_linep;
  97. X                for (i=0; i<n && lback(lp)!=adjwp->w_bufp->b_linep; ++i)
  98. X                        lp = lback(lp);
  99. X                adjwp->w_linep  = lp;
  100. X                adjwp->w_toprow -= n;
  101. X        } else {                                /* Grow above.          */
  102. X                lp = curwp->w_linep;
  103. X                for (i=0; i<n && lp!=curbp->b_linep; ++i)
  104. X                        lp = lforw(lp);
  105. X                curwp->w_linep  = lp;
  106. X                curwp->w_toprow += n;
  107. X        }
  108. X        curwp->w_ntrows -= n;
  109. X        adjwp->w_ntrows += n;
  110. X        curwp->w_flag |= WFMODE|WFHARD|WFKILLS;
  111. X        adjwp->w_flag |= WFMODE|WFHARD|WFINS;
  112. X        return (TRUE);
  113. }
  114. X
  115. #if !SMALLER
  116. X
  117. /*    Resize the current window to the requested size    */
  118. resize(f, n)
  119. int f, n;    /* default flag and numeric argument */
  120. {
  121. X    int clines;    /* current # of lines in window */
  122. X    
  123. X    /* must have a non-default argument, else ignore call */
  124. X    if (f == FALSE)
  125. X        return(TRUE);
  126. X
  127. X    /* find out what to do */
  128. X    clines = curwp->w_ntrows;
  129. X
  130. X    /* already the right size? */
  131. X    if (clines == n)
  132. X        return(TRUE);
  133. X
  134. X    return(enlargewind(TRUE, n - clines));
  135. }
  136. #endif
  137. X
  138. /*
  139. X * Pick a window for a pop-up. Split the screen if there is only one window.
  140. X * Pick the uppermost window that isn't the current window. An LRU algorithm
  141. X * might be better. Return a pointer, or NULL on error.
  142. X */
  143. WINDOW  *
  144. wpopup()
  145. {
  146. X        register WINDOW *wp;
  147. X
  148. X        if (wheadp->w_wndp == NULL              /* Only 1 window        */
  149. X            && splitwind(FALSE, 0) == FALSE) /* and it won't split   */
  150. X                return (NULL);
  151. X        wp = wheadp;                            /* Find window to use   */
  152. X        while (wp!=NULL && wp==curwp)
  153. X                wp = wp->w_wndp;
  154. X        return (wp);
  155. }
  156. X
  157. scrnextup(f, n)        /* scroll the next window up (back) a page */
  158. {
  159. X    nextwind(FALSE, 1);
  160. X    backhpage(f, n);
  161. X    prevwind(FALSE, 1);
  162. }
  163. X
  164. scrnextdw(f, n)        /* scroll the next window down (forward) a page */
  165. {
  166. X    nextwind(FALSE, 1);
  167. X    forwhpage(f, n);
  168. X    prevwind(FALSE, 1);
  169. }
  170. X
  171. #if ! SMALLER
  172. savewnd(f, n)        /* save ptr to current window */
  173. {
  174. X    swindow = curwp;
  175. X    return(TRUE);
  176. }
  177. X
  178. restwnd(f, n)        /* restore the saved screen */
  179. {
  180. X    register WINDOW *wp;
  181. X
  182. X    /* find the window */
  183. X    wp = wheadp;
  184. X    while (wp != NULL) {
  185. X        if (wp == swindow) {
  186. X            curwp = wp;
  187. X            make_current(curwp->w_bufp);
  188. X            upmode();
  189. X            return (TRUE);
  190. X        }
  191. X        wp = wp->w_wndp;
  192. X    }
  193. X
  194. X    mlwrite("[No such window exists]");
  195. X    return(FALSE);
  196. }
  197. #endif
  198. X
  199. newlength(f,n)    /* resize the screen, re-writing the screen */
  200. int n;    /* numeric argument */
  201. {
  202. X    WINDOW *wp;    /* current window being examined */
  203. X    WINDOW *nextwp;    /* next window to scan */
  204. X    WINDOW *lastwp;    /* last window scanned */
  205. X    int lastline;    /* screen line of last line of current window */
  206. X
  207. X    if (!f) {
  208. X        mlwrite("No length given");
  209. X        return FALSE;
  210. X    }
  211. X
  212. X    /* make sure it's in range */
  213. X    if (n < 3 || n > term.t_mrow + 1) {
  214. X        mlwrite("Screen size out of range");
  215. X        return(FALSE);
  216. X    }
  217. X
  218. X    if (term.t_nrow == n - 1)
  219. X        return(TRUE);
  220. X    else if (term.t_nrow < n - 1) {
  221. X
  222. X        /* go to the last window */
  223. X        wp = wheadp;
  224. X        while (wp->w_wndp != NULL)
  225. X            wp = wp->w_wndp;
  226. X
  227. X        /* and enlarge it as needed */
  228. X        wp->w_ntrows = n - wp->w_toprow - 2;
  229. X        wp->w_flag |= WFHARD|WFMODE;
  230. X
  231. X    } else {
  232. X
  233. X        /* rebuild the window structure */
  234. X        nextwp = wheadp;
  235. X        wp = NULL;
  236. X        lastwp = NULL;
  237. X        while (nextwp != NULL) {
  238. X            wp = nextwp;
  239. X            nextwp = wp->w_wndp;
  240. X    
  241. X            /* get rid of it if it is too low */
  242. X            if (wp->w_toprow > n - 2) {
  243. X
  244. X                if (--wp->w_bufp->b_nwnd == 0) {
  245. X                    undispbuff(wp->w_bufp,wp);
  246. X                }
  247. X    
  248. X                /* update curwp and lastwp if needed */
  249. X                if (wp == curwp)
  250. X                    curwp = wheadp;
  251. X                    make_current(curwp->w_bufp);
  252. X                if (lastwp != NULL)
  253. X                    lastwp->w_wndp = NULL;
  254. X
  255. X                /* free the structure */
  256. X                free((char *)wp);
  257. X                wp = NULL;
  258. X
  259. X            } else {
  260. X                /* need to change this window size? */
  261. X                lastline = wp->w_toprow + wp->w_ntrows - 1;
  262. X                if (lastline >= n - 2) {
  263. X                    wp->w_ntrows = n - wp->w_toprow - 2;
  264. X                    wp->w_flag |= WFHARD|WFMODE;
  265. X                }
  266. X            }
  267. X    
  268. X            lastwp = wp;
  269. X        }
  270. X    }
  271. X
  272. X    /* screen is garbage */
  273. X    term.t_nrow = n - 1;
  274. X    sgarbf = TRUE;
  275. X    return(TRUE);
  276. }
  277. X
  278. newwidth(f,n)    /* resize the screen, re-writing the screen */
  279. int n;    /* numeric argument */
  280. {
  281. X    register WINDOW *wp;
  282. X
  283. X    if (!f) {
  284. X        mlwrite("No width given");
  285. X        return FALSE;
  286. X    }
  287. X
  288. X    /* make sure it's in range */
  289. X    if (n < 10 || n > term.t_mcol) {
  290. #if    NeWS        /* serious error for NeWS, halt */
  291. X        fprintf(stderr, "Screen width out of range\n") ;
  292. X        newsclose() ;
  293. X        exit(1) ;
  294. #else
  295. X        mlwrite("Screen width out of range");
  296. X        return(FALSE);
  297. #endif
  298. X    }
  299. X
  300. X    /* otherwise, just re-width it (no big deal) */
  301. X    term.t_ncol = n;
  302. X    term.t_margin = n / 10;
  303. X    term.t_scrsiz = n - (term.t_margin * 2);
  304. X
  305. X    /* force all windows to redraw */
  306. X    wp = wheadp;
  307. X    while (wp) {
  308. X        wp->w_flag |= WFHARD | WFMOVE | WFMODE;
  309. X        wp = wp->w_wndp;
  310. X    }
  311. X    sgarbf = TRUE;
  312. X
  313. X    return(TRUE);
  314. }
  315. X
  316. #if ! SMALLER
  317. int getwpos()    /* get screen offset of current line in current window */
  318. {
  319. X    register int sline;    /* screen line from top of window */
  320. X    register LINE *lp;    /* scannile line pointer */
  321. X
  322. X    /* search down the line we want */
  323. X    lp = curwp->w_linep;
  324. X    sline = 1;
  325. X    while (lp != curwp->w_dotp) {
  326. X        ++sline;
  327. X        lp = lforw(lp);
  328. X    }
  329. X
  330. X    /* and return the value */
  331. X    return(sline);
  332. }
  333. #endif
  334. X
  335. /*
  336. X * Initialize all of the windows.
  337. X */
  338. winit()
  339. {
  340. X        register WINDOW *wp;
  341. X
  342. X        wp = (WINDOW *) malloc(sizeof(WINDOW)); /* First window         */
  343. X        if (wp==NULL )
  344. X                exit(1);
  345. X        wheadp = wp;
  346. X        curwp  = wp;
  347. X        wp->w_wndp  = NULL;                     /* Initialize window    */
  348. X        wp->w_doto  = 0;
  349. X        wp->w_mkp = NULL;
  350. X        wp->w_mko = 0;
  351. X        wp->w_ldmkp = NULL;
  352. X        wp->w_ldmko = 0;
  353. X        wp->w_toprow = 0;
  354. X        wp->w_sideways = 0;
  355. #if    COLOR
  356. X    /* initalize colors to global defaults */
  357. X    wp->w_fcolor = gfcolor;
  358. X    wp->w_bcolor = gbcolor;
  359. #endif
  360. X        wp->w_ntrows = term.t_nrow-1;           /* "-1" for mode line.  */
  361. X        wp->w_force = 0;
  362. X        wp->w_flag  = WFMODE|WFHARD;            /* Full.                */
  363. }
  364. X
  365. X
  366. SHAR_EOF
  367. echo 'File window.c is complete' &&
  368. chmod 0444 window.c ||
  369. echo 'restore of window.c failed'
  370. Wc_c="`wc -c < 'window.c'`"
  371. test 20419 -eq "$Wc_c" ||
  372.     echo 'window.c: original size 20419, current size' "$Wc_c"
  373. # ============= word.c ==============
  374. echo 'x - extracting word.c (Text)'
  375. sed 's/^X//' << 'SHAR_EOF' > 'word.c' &&
  376. /*
  377. X * The routines in this file implement commands that work word or a
  378. X * paragraph at a time.  There are all sorts of word mode commands.  If I
  379. X * do any sentence mode commands, they are likely to be put in this file. 
  380. X */
  381. X
  382. #include    <stdio.h>
  383. #include    "estruct.h"
  384. #include    "edef.h"
  385. X
  386. /* Word wrap on n-spaces. Back-over whatever precedes the point on the current
  387. X * line and stop on the first word-break or the beginning of the line. If we
  388. X * reach the beginning of the line, jump back to the end of the word and start
  389. X * a new line.    Otherwise, break the line at the word-break, eat it, and jump
  390. X * back to the end of the word.
  391. X * Returns TRUE on success, FALSE on errors.
  392. X */
  393. wrapword()
  394. {
  395. X    register int cnt;    /* size of word wrapped to next line */
  396. X    register int c;        /* charector temporary */
  397. X
  398. X    /* backup from the <NL> 1 char */
  399. X    if (!backchar(0, 1))
  400. X        return(FALSE);
  401. X
  402. X    /* back up until we aren't in a word,
  403. X       make sure there is a break in the line */
  404. X    cnt = 0;
  405. X    while (c = lgetc(curwp->w_dotp, curwp->w_doto), !isspace(c)) {
  406. X        cnt++;
  407. X        if (!backchar(0, 1))
  408. X            return(FALSE);
  409. X        /* if we make it to the beginning, start a new line */
  410. X        if (curwp->w_doto == 0) {
  411. X            gotoeol(FALSE, 0);
  412. X            return(lnewline());
  413. X        }
  414. X    }
  415. X
  416. X    /* delete the forward white space */
  417. X    if (!ldelete(1L, FALSE))
  418. X        return(FALSE);
  419. X
  420. X    /* put in a end of line */
  421. X    if (!newline(TRUE,1))
  422. X        return FALSE;
  423. X
  424. X    /* and past the first word */
  425. X    while (cnt-- > 0) {
  426. X        if (forwchar(FALSE, 1) == FALSE)
  427. X            return(FALSE);
  428. X    }
  429. X    return(TRUE);
  430. }
  431. X
  432. X
  433. /*
  434. X * Move the cursor forward by the specified number of words. All of the motion
  435. X * is done by "forwchar". Error if you try and move beyond the buffer's end.
  436. X *
  437. X * Returns of SORTOFTRUE result if we're doing a non-delete operation.  
  438. X * Whitespace after a word is always included on deletes (and non-operations,
  439. X * of course), but only on intermediate words for other operations, for
  440. X * example.  The last word of non-delete ops does _not_ include its whitespace.
  441. X */
  442. X
  443. forwviword(f, n)
  444. {
  445. X    int s;
  446. X
  447. X    if (n < 0)
  448. X        return (backword(f, -n));
  449. X    setchartype();
  450. X    if (forwchar(FALSE, 1) == FALSE)
  451. X        return (FALSE);
  452. X    while (n--) {
  453. X        while (((s = isnewviwordf()) == FALSE) || 
  454. X                (s == SORTOFTRUE && n != 0)) {
  455. X            if (forwchar(FALSE, 1) == FALSE)
  456. X                return (FALSE);
  457. X        }
  458. X    }
  459. X    return TRUE;
  460. }
  461. X
  462. /*
  463. X * Move the cursor forward by the specified number of words. All of the motion
  464. X * is done by "forwchar". Error if you try and move beyond the buffer's end.
  465. X */
  466. forwword(f, n)
  467. {
  468. X    int s;
  469. X
  470. X    if (n < 0)
  471. X        return (backword(f, -n));
  472. X    setchartype();
  473. X    if (forwchar(FALSE, 1) == FALSE)
  474. X        return (FALSE);
  475. X    while (n--) {
  476. X        while (((s = isnewwordf()) == FALSE) || 
  477. X                (s == SORTOFTRUE && n != 0)) {
  478. X            if (forwchar(FALSE, 1) == FALSE)
  479. X                return (FALSE);
  480. X        }
  481. X    }
  482. X    return(TRUE);
  483. }
  484. X
  485. /*
  486. X * Move the cursor forward by the specified number of words. All of the motion
  487. X * is done by "forwchar". Error if you try and move beyond the buffer's end.
  488. X */
  489. forwviendw(f, n)
  490. {
  491. X    int s;
  492. X    if (n < 0)
  493. X        return (FALSE);
  494. X    if (forwchar(FALSE, 1) == FALSE)
  495. X        return (FALSE);
  496. X    setchartype();
  497. X    while (n--) {
  498. X        while ((s = isendviwordf()) == FALSE) {
  499. X            if (forwchar(FALSE, 1) == FALSE)
  500. X                return (FALSE);
  501. X        }
  502. X
  503. X    }
  504. X    if (s == SORTOFTRUE)
  505. X        return TRUE;
  506. X    else
  507. X        return backchar(FALSE, 1);
  508. }
  509. X
  510. /*
  511. X * Move the cursor forward by the specified number of words. All of the motion
  512. X * is done by "forwchar". Error if you try and move beyond the buffer's end.
  513. X */
  514. forwendw(f, n)
  515. {
  516. X    int s;
  517. X    if (n < 0)
  518. X        return (FALSE);
  519. X    if (forwchar(FALSE, 1) == FALSE)
  520. X        return (FALSE);
  521. X    setchartype();
  522. X    while (n--) {
  523. X        while ((s = isendwordf()) == FALSE) {
  524. X            if (forwchar(FALSE, 1) == FALSE)
  525. X                return (FALSE);
  526. X        }
  527. X
  528. X    }
  529. X    if (s == SORTOFTRUE)
  530. X        return TRUE;
  531. X    else
  532. X        return backchar(FALSE, 1);
  533. }
  534. X
  535. /*
  536. X * Move the cursor backward by "n" words. All of the details of motion are
  537. X * performed by the "backchar" and "forwchar" routines. Error if you try to
  538. X * move beyond the buffers.
  539. X */
  540. backviword(f, n)
  541. {
  542. X    if (n < 0)
  543. X        return (forwword(f, -n));
  544. X    if (backchar(FALSE, 1) == FALSE)
  545. X        return (FALSE);
  546. X    setchartype();
  547. X    while (n--) {
  548. X        while (isnewviwordb() == FALSE) {
  549. X            if (backchar(FALSE, 1) == FALSE)
  550. X                return (FALSE);
  551. X        }
  552. X    }
  553. X    return (forwchar(FALSE, 1));
  554. }
  555. X
  556. /*
  557. X * Move the cursor backward by "n" words. All of the details of motion are
  558. X * performed by the "backchar" and "forwchar" routines. Error if you try to
  559. X * move beyond the buffers.
  560. X */
  561. backword(f, n)
  562. {
  563. X    if (n < 0)
  564. X        return (forwword(f, -n));
  565. X    if (backchar(FALSE, 1) == FALSE)
  566. X        return (FALSE);
  567. X    setchartype();
  568. X    while (n--) {
  569. X        while (isnewwordb() == FALSE) {
  570. X            if (backchar(FALSE, 1) == FALSE)
  571. X                return (FALSE);
  572. X        }
  573. X    }
  574. X    return (forwchar(FALSE, 1));
  575. }
  576. X
  577. /*
  578. X * Return TRUE if the character at dot is a character that is considered to be
  579. X * part of a word. The word character list is hard coded. Should be setable.
  580. X */
  581. inword()
  582. {
  583. X    register int    c;
  584. X
  585. X    if (curwp->w_doto == llength(curwp->w_dotp))
  586. X        return (FALSE);
  587. X    c = lgetc(curwp->w_dotp, curwp->w_doto);
  588. X    if (islower(c))
  589. X        return (TRUE);
  590. X    if (isupper(c))
  591. X        return (TRUE);
  592. X    if (isdigit(c))
  593. X        return (TRUE);
  594. X    return (FALSE);
  595. }
  596. X
  597. join(f,n)
  598. {
  599. X    register int s;
  600. X    register int doto;
  601. X
  602. X    if (n < 0) return FALSE;
  603. X    if (n == 0) return TRUE;
  604. X    if (lforw(curwp->w_dotp) == curbp->b_linep)
  605. X        return FALSE;
  606. X    while(n--) {
  607. X        s = lastnonwhite(f,n);
  608. X        if (s == TRUE) s = forwchar(FALSE,1);
  609. X        if (s == TRUE) s = setmark();
  610. X        if (s == TRUE) s = forwline(f,1);
  611. X        if (s == TRUE) s = firstnonwhite(f,1);
  612. X        if (s == TRUE) s = killregion(f,1);
  613. X        if (s != TRUE)
  614. X            return s ;
  615. X
  616. X        doto = curwp->w_doto;
  617. X        if (doto == 0)
  618. X            return  TRUE;
  619. X        if (lgetc(curwp->w_dotp,doto) == ')')
  620. X            return TRUE;
  621. X        if (lgetc(curwp->w_dotp,doto-1) == '.')
  622. X            s = linsert(2,' ');
  623. X        else
  624. X            s = linsert(1,' ');
  625. X    }
  626. X
  627. X    return s;
  628. }
  629. X
  630. formatregion(f,n)
  631. {
  632. X    register int c;            /* current char durring scan    */
  633. X    register int wordlen;        /* length of current word    */
  634. X    register int clength;        /* position on line during fill    */
  635. X    register int i;            /* index during word copy    */
  636. X    register int newlength;        /* tentative new line length    */
  637. X    register int finished;        /* Are we at the End-Of-Paragraph? */
  638. X    register int firstflag;        /* first word? (needs no space)    */
  639. X    register LINE *pastline;        /* pointer to line just past EOP */
  640. X    register int sentence;        /* was the last char a period?    */
  641. X    char wbuf[NSTRING];        /* buffer for current word    */
  642. X    int secondindent;
  643. X    REGION region;
  644. X    int s;
  645. X    
  646. X    if (curbp->b_mode & MDVIEW)    /* don't allow this command if    */
  647. X        return(rdonly());    /* we are in read only mode    */
  648. X
  649. X    if (curwp->w_mkp != curwp->w_dotp) {
  650. X        getregion(®ion);
  651. X        if (region.r_linep == curwp->w_mkp)
  652. X            swapmark();
  653. X    }
  654. X    pastline = curwp->w_mkp;
  655. X    if (pastline != curbp->b_linep)
  656. X        pastline = lforw(pastline);
  657. X        
  658. X    secondindent = indentlen(curwp->w_dotp);
  659. X    
  660. X    /* go forward to get the indent for the second and following lines */
  661. X    curwp->w_dotp = lforw(curwp->w_dotp);
  662. X
  663. X    if (curwp->w_dotp != pastline) {
  664. X        secondindent = indentlen(curwp->w_dotp);
  665. X    }
  666. X        
  667. X    /* and back where we should be */
  668. X    curwp->w_dotp = lback(curwp->w_dotp);
  669. X    firstnonwhite(FALSE,1);
  670. X    
  671. X    clength = indentlen(curwp->w_dotp);
  672. X    wordlen = 0;
  673. X    sentence = FALSE;
  674. X
  675. X    /* scan through lines, filling words */
  676. X    firstflag = TRUE;
  677. X    finished = FALSE;
  678. X    while (!finished) {
  679. X
  680. X        if (interrupted) return ABORT;
  681. X
  682. X        /* get the next character in the paragraph */
  683. X        if (curwp->w_doto == llength(curwp->w_dotp)) {
  684. X            c = ' ';
  685. X            if (lforw(curwp->w_dotp) == pastline)
  686. X                finished = TRUE;
  687. X        } else {
  688. X            c = lgetc(curwp->w_dotp, curwp->w_doto);
  689. X        }
  690. X        /* and then delete it */
  691. X        if (!finished) {
  692. X            s = ldelete(1L, FALSE);
  693. X            if (s != TRUE) return s;
  694. X        }
  695. X
  696. X        /* if not a separator, just add it in */
  697. X        if (c != ' ' && c != '\t') {
  698. X            /* was it the end of a "sentence"? */
  699. X            sentence = (c == '.' || c == '?' || c == '!');
  700. X            if (wordlen < NSTRING - 1)
  701. X                wbuf[wordlen++] = c;
  702. X        } else if (wordlen) {
  703. X            /* at a word break with a word waiting */
  704. X            /* calculate tentative new length with word added */
  705. X            newlength = clength + 1 + wordlen;
  706. X            if (newlength <= fillcol) {
  707. X                /* add word to current line */
  708. X                if (!firstflag) {
  709. X                    s = linsert(1, ' '); /* the space */
  710. X                    if (s != TRUE) return s;
  711. X                    ++clength;
  712. X                }
  713. X                firstflag = FALSE;
  714. X            } else {
  715. X                        if (lnewline() == FALSE
  716. X                            || ((i=secondindent/TABVAL)!=0 &&
  717. X                                linsert(i, '\t')==FALSE)
  718. X                            || ((i=secondindent%TABVAL)!=0 &&
  719. X                                linsert(i,  ' ')==FALSE)) {
  720. X                                return FALSE;
  721. X                        }
  722. X                clength = secondindent;
  723. X            }
  724. X
  725. X            /* and add the word in in either case */
  726. X            for (i=0; i<wordlen; i++) {
  727. X                s = linsert(1, wbuf[i]);
  728. X                if (s != TRUE) return s;
  729. X                ++clength;
  730. X            }
  731. X            if (sentence) {
  732. X                s = linsert(1, ' ');
  733. X                if (s != TRUE) return s;
  734. X                ++clength;
  735. X            }
  736. X            wordlen = 0;
  737. X        }
  738. X    }
  739. X    return(TRUE);
  740. }
  741. X
  742. X
  743. #if    WORDCOUNT    /* who cares? -pgf */
  744. /*    wordcount:    count the # of words in the marked region,
  745. X            along with average word sizes, # of chars, etc,
  746. X            and report on them.            */
  747. wordcount(f, n)
  748. {
  749. X    register LINE *lp;    /* current line to scan */
  750. X    register int offset;    /* current char to scan */
  751. X    long size;        /* size of region left to count */
  752. X    register int ch;    /* current character to scan */
  753. X    register int wordflag;    /* are we in a word now? */
  754. X    register int lastword;    /* were we just in a word? */
  755. X    long nwords;        /* total # of words */
  756. X    long nchars;        /* total number of chars */
  757. X    int nlines;        /* total number of lines in region */
  758. X    int avgch;        /* average number of chars/word */
  759. X    int status;        /* status return code */
  760. X    REGION region;        /* region to look at */
  761. X
  762. X    /* make sure we have a region to count */
  763. X    if ((status = getregion(®ion)) != TRUE)
  764. X        return(status);
  765. X    lp = region.r_linep;
  766. X    offset = region.r_offset;
  767. X    size = region.r_size;
  768. X
  769. X    /* count up things */
  770. X    lastword = FALSE;
  771. X    nchars = 0L;
  772. X    nwords = 0L;
  773. X    nlines = 0;
  774. X    while (size--) {
  775. X
  776. X        /* get the current character */
  777. X        if (offset == llength(lp)) {    /* end of line */
  778. X            ch = '\n';
  779. X            lp = lforw(lp);
  780. X            offset = 0;
  781. X            ++nlines;
  782. X        } else {
  783. X            ch = lgetc(lp, offset);
  784. X            ++offset;
  785. X        }
  786. X
  787. X        /* and tabulate it */
  788. X        wordflag = ((ch >= 'a' && ch <= 'z') ||
  789. X                (ch >= 'A' && ch <= 'Z') ||
  790. X                (ch >= '0' && ch <= '9'));
  791. X        if (wordflag == TRUE && lastword == FALSE)
  792. X            ++nwords;
  793. X        lastword = wordflag;
  794. X        ++nchars;
  795. X    }
  796. X
  797. X    /* and report on the info */
  798. X    if (nwords > 0L)
  799. X        avgch = (int)((100L * nchars) / nwords);
  800. X    else
  801. X        avgch = 0;
  802. X
  803. X    mlwrite("lines %d, words, %D chars %D  avg chars/word %f",
  804. X        nlines + 1, nwords, nchars, avgch);
  805. X    return(TRUE);
  806. }
  807. #endif
  808. SHAR_EOF
  809. chmod 0444 word.c ||
  810. echo 'restore of word.c failed'
  811. Wc_c="`wc -c < 'word.c'`"
  812. test 10449 -eq "$Wc_c" ||
  813.     echo 'word.c: original size 10449, current size' "$Wc_c"
  814. # ============= wordmov.c ==============
  815. echo 'x - extracting wordmov.c (Text)'
  816. sed 's/^X//' << 'SHAR_EOF' > 'wordmov.c' &&
  817. X
  818. #include    <stdio.h>
  819. #include "estruct.h"
  820. #include "edef.h"
  821. X
  822. /* These routines report on transitions between word boundaries, both 
  823. X    in the punctuated vi sense, and in the whitespace/darkspace
  824. X    sense.  The transition is reported _after_ it has occurred.  You
  825. X    need to back up to get to the char. before the transition.
  826. X    Written for vile by Paul Fox, (c)1990
  827. */
  828. X
  829. #define WASSPACE 0
  830. #define ISSPACE 0
  831. #define WASIDENT 1
  832. #define ISIDENT 1
  833. #define WASOTHER 2
  834. #define ISOTHER 2
  835. #define WASNL 3
  836. #define ISNL 3
  837. X
  838. static int ochartype;
  839. X
  840. setchartype()
  841. {
  842. X    ochartype = getchartype();
  843. }
  844. X
  845. getchartype()
  846. {
  847. X    register int    c;
  848. X
  849. X    if (curwp->w_doto == llength(curwp->w_dotp))
  850. X        return (ISNL);
  851. X    else
  852. X        c = lgetc(curwp->w_dotp, curwp->w_doto);
  853. X    return (isspace(c) ? ISSPACE : 
  854. X            ( isident(c) ? ISIDENT : ISOTHER ) );
  855. }
  856. X
  857. X
  858. isnewwordf()
  859. {
  860. X    register int    ret;
  861. X    register int    type;
  862. X
  863. X    type = getchartype();
  864. X
  865. X    switch (ochartype) {
  866. X    case WASNL:
  867. X    case WASSPACE:
  868. X        switch (type) {
  869. X        case ISNL:    if (doingopcmd) { ret = SORTOFTRUE; break;}
  870. X        case ISSPACE: ret = FALSE;    break;
  871. X        case ISIDENT:
  872. X        case ISOTHER: ret = TRUE;    break;
  873. X        }
  874. X        break;
  875. X    case WASIDENT:
  876. X    case WASOTHER:
  877. X        switch (type) {
  878. X        case ISNL:    if (doingopcmd) { ret = SORTOFTRUE; break;}
  879. X        case ISSPACE: if (doingopcmd && opcmd != OPDEL) 
  880. X                        { ret = SORTOFTRUE; break;}
  881. X        case ISIDENT:
  882. X        case ISOTHER: ret = FALSE;    break;
  883. X        }
  884. X        break;
  885. X    }
  886. X    ochartype = type;
  887. X    return (ret);
  888. }
  889. X
  890. isnewwordb()
  891. {
  892. X    register int    ret;
  893. X    register int    type;
  894. X
  895. X    type = getchartype();
  896. X
  897. X    switch (ochartype) {
  898. X    case WASNL:
  899. X    case WASSPACE:
  900. X        ret = FALSE;    break;
  901. X    case WASIDENT:
  902. X        switch (type) {
  903. X        case ISNL:
  904. X        case ISSPACE: ret = TRUE;    break;
  905. X        case ISIDENT:
  906. X        case ISOTHER: ret = FALSE;    break;
  907. X        }
  908. X        break;
  909. X    case WASOTHER:
  910. X        switch (type) {
  911. X        case ISNL:
  912. X        case ISSPACE: ret = TRUE;    break;
  913. X        case ISIDENT:
  914. X        case ISOTHER: ret = FALSE;    break;
  915. X        }
  916. X        break;
  917. X    }
  918. X    ochartype = type;
  919. X    return (ret);
  920. }
  921. X
  922. isnewviwordf()
  923. {
  924. X    register int    ret;
  925. X    register int    type;
  926. X
  927. X    type = getchartype();
  928. X
  929. X    switch (ochartype) {
  930. X    case WASNL:
  931. X    case WASSPACE:
  932. X        switch (type) {
  933. X        case ISNL:    if (doingopcmd) { ret = SORTOFTRUE; break;}
  934. X        case ISSPACE: ret = FALSE;    break;
  935. X        case ISIDENT:
  936. X        case ISOTHER: ret = TRUE;    break;
  937. X        }
  938. X        break;
  939. X    case WASIDENT:
  940. X        switch (type) {
  941. X        case ISNL:    if (doingopcmd) { ret = SORTOFTRUE; break;}
  942. X        case ISSPACE: if (doingopcmd && opcmd != OPDEL) 
  943. X                        { ret = SORTOFTRUE; break;}
  944. X        case ISIDENT: ret = FALSE;    break;
  945. X        case ISOTHER: ret = TRUE;    break;
  946. X        }
  947. X        break;
  948. X    case WASOTHER:
  949. X        switch (type) {
  950. X        case ISNL:    if (doingopcmd) { ret = SORTOFTRUE; break;}
  951. X        case ISSPACE: if (doingopcmd && opcmd != OPDEL) 
  952. X                        { ret = SORTOFTRUE; break;}
  953. X        case ISOTHER: ret = FALSE;    break;
  954. X        case ISIDENT: ret = TRUE;    break;
  955. X        }
  956. X        break;
  957. X    }
  958. X    ochartype = type;
  959. X    return (ret);
  960. }
  961. X
  962. isnewviwordb()
  963. {
  964. X    register int    ret;
  965. X    register int    type;
  966. X
  967. X    type = getchartype();
  968. X
  969. X    switch (ochartype) {
  970. X    case WASNL:
  971. X    case WASSPACE:
  972. X        ret = FALSE;    break;
  973. X    case WASIDENT:
  974. X        switch (type) {
  975. X        case ISNL:
  976. X        case ISSPACE:
  977. X        case ISOTHER: ret = TRUE;    break;
  978. X        case ISIDENT: ret = FALSE;    break;
  979. X        }
  980. X        break;
  981. X    case WASOTHER:
  982. X        switch (type) {
  983. X        case ISNL:
  984. X        case ISSPACE:
  985. X        case ISIDENT: ret = TRUE;    break;
  986. X        case ISOTHER: ret = FALSE;    break;
  987. X        }
  988. X        break;
  989. X    }
  990. X    ochartype = type;
  991. X    return (ret);
  992. }
  993. X
  994. X
  995. isendwordb()
  996. {
  997. X    register int    ret;
  998. X    register int    type;
  999. X
  1000. X    type = getchartype();
  1001. X
  1002. X    switch (ochartype) {
  1003. X    case WASNL:
  1004. X    case WASSPACE:
  1005. X        switch (type) {
  1006. X        case ISNL:
  1007. X        case ISSPACE: ret = FALSE;    break;
  1008. X        case ISIDENT:
  1009. X        case ISOTHER: ret = TRUE;    break;
  1010. X        }
  1011. X        break;
  1012. X    case WASIDENT:
  1013. X    case WASOTHER:
  1014. X        ret = FALSE;    break;
  1015. X    }
  1016. X    ochartype = type;
  1017. X    return (ret);
  1018. }
  1019. X
  1020. isendviwordb()
  1021. {
  1022. X    register int    ret;
  1023. X    register int    type;
  1024. X
  1025. X    type = getchartype();
  1026. X
  1027. X    switch (ochartype) {
  1028. X    case WASNL:
  1029. X    case WASSPACE:
  1030. X        switch (type) {
  1031. X        case ISNL:
  1032. X        case ISSPACE: ret = FALSE;    break;
  1033. X        case ISOTHER:
  1034. X        case ISIDENT: ret = TRUE;    break;
  1035. X        }
  1036. X        break;
  1037. X    case WASIDENT:
  1038. X        switch (type) {
  1039. X        case ISNL:
  1040. X        case ISSPACE:
  1041. X        case ISOTHER: ret = TRUE;    break;
  1042. X        case ISIDENT: ret = FALSE;    break;
  1043. X        }
  1044. X        break;
  1045. X    case WASOTHER:
  1046. X        switch (type) {
  1047. X        case ISNL:
  1048. X        case ISSPACE:
  1049. X        case ISIDENT: ret = TRUE;    break;
  1050. X        case ISOTHER: ret = FALSE;    break;
  1051. X        }
  1052. X        break;
  1053. X    }
  1054. X    ochartype = type;
  1055. X    return (ret);
  1056. }
  1057. X
  1058. isendwordf()
  1059. {
  1060. X    register int    ret;
  1061. X    register int    type;
  1062. X
  1063. X    type = getchartype();
  1064. X
  1065. X    switch (ochartype) {
  1066. X    case WASNL:
  1067. X    case WASSPACE:
  1068. X        ret = FALSE;    break;
  1069. X    case WASIDENT:
  1070. X        switch (type) {
  1071. X        case ISNL:
  1072. X        case ISSPACE:
  1073. X            if (doingopcmd) ret = SORTOFTRUE;
  1074. X            else ret = TRUE;
  1075. X            break;
  1076. X        case ISIDENT:
  1077. X        case ISOTHER: ret = FALSE;    break;
  1078. X        }
  1079. X        break;
  1080. X    case WASOTHER:
  1081. X        switch (type) {
  1082. X        case ISNL:
  1083. X        case ISSPACE:
  1084. X            if (doingopcmd) ret = SORTOFTRUE;
  1085. X            else ret = TRUE;
  1086. X            break;
  1087. X        case ISIDENT:
  1088. X        case ISOTHER: ret = FALSE;    break;
  1089. X        }
  1090. X        break;
  1091. X    }
  1092. X    ochartype = type;
  1093. X    return (ret);
  1094. }
  1095. X
  1096. isendviwordf()
  1097. {
  1098. X    register int    ret;
  1099. X    register int    type;
  1100. X
  1101. X    type = getchartype();
  1102. X
  1103. X    switch (ochartype) {
  1104. X    case WASNL:
  1105. X    case WASSPACE:
  1106. X        ret = FALSE;    break;
  1107. X    case WASIDENT:
  1108. X        switch (type) {
  1109. X        case ISNL:
  1110. X        case ISSPACE:
  1111. X        case ISOTHER:
  1112. X            if (doingopcmd) ret = SORTOFTRUE;
  1113. X            else ret = TRUE;
  1114. X            break;
  1115. X        case ISIDENT: ret = FALSE;    break;
  1116. X        }
  1117. X        break;
  1118. X    case WASOTHER:
  1119. X        switch (type) {
  1120. X        case ISNL:
  1121. X        case ISSPACE:
  1122. X        case ISIDENT:
  1123. X            if (doingopcmd) ret = SORTOFTRUE;
  1124. X            else ret = TRUE;
  1125. X            break;
  1126. X        case ISOTHER: ret = FALSE;    break;
  1127. X        }
  1128. X        break;
  1129. X    }
  1130. X    ochartype = type;
  1131. X    return (ret);
  1132. }
  1133. X
  1134. #ifdef template
  1135. isANYTHING()
  1136. {
  1137. X    register int    ret;
  1138. X    register int    type;
  1139. X
  1140. X    type = getchartype();
  1141. X
  1142. X    switch (ochartype) {
  1143. X    case WASNL:
  1144. X    case WASSPACE:
  1145. X        switch (type) {
  1146. X        case ISNL:
  1147. X        case ISSPACE:
  1148. X            ret = FALSE;    break;
  1149. X        case ISIDENT:
  1150. X            ret = FALSE;    break;
  1151. X        case ISOTHER:
  1152. X            ret = FALSE;    break;
  1153. X        }
  1154. X        break;
  1155. X    case WASIDENT:
  1156. X        switch (type) {
  1157. X        case ISNL:
  1158. X        case ISSPACE:
  1159. X            ret = TRUE;    break;
  1160. X        case ISIDENT:
  1161. X            ret = FALSE;    break;
  1162. X        case ISOTHER:
  1163. X            ret = TRUE;    break;
  1164. X        }
  1165. X        break;
  1166. X    case WASOTHER:
  1167. X        switch (type) {
  1168. X        case ISNL:
  1169. X        case ISSPACE:
  1170. X            ret = TRUE;    break;
  1171. X        case ISIDENT:
  1172. X            ret = TRUE;    break;
  1173. X        case ISOTHER:
  1174. X            ret = FALSE;    break;
  1175. X        }
  1176. X        break;
  1177. X    }
  1178. X    ochartype = type;
  1179. X    return (ret);
  1180. }
  1181. #endif /* template */
  1182. X
  1183. SHAR_EOF
  1184. chmod 0444 wordmov.c ||
  1185. echo 'restore of wordmov.c failed'
  1186. Wc_c="`wc -c < 'wordmov.c'`"
  1187. test 6094 -eq "$Wc_c" ||
  1188.     echo 'wordmov.c: original size 6094, current size' "$Wc_c"
  1189. # ============= z100bios.asm ==============
  1190. echo 'x - extracting z100bios.asm (Text)'
  1191. sed 's/^X//' << 'SHAR_EOF' > 'z100bios.asm' &&
  1192. ;History:46,1
  1193. X
  1194. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  1195. _TEXT    ENDS
  1196. _DATA    SEGMENT  WORD PUBLIC 'DATA'
  1197. _DATA    ENDS
  1198. CONST    SEGMENT  WORD PUBLIC 'CONST'
  1199. CONST    ENDS
  1200. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  1201. _BSS    ENDS
  1202. X
  1203. bios_seg segment at 40h
  1204. X    org    9
  1205. bios_conout    label    far
  1206. bios_seg ends
  1207. X
  1208. DGROUP    GROUP    CONST,    _BSS,    _DATA
  1209. X    ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  1210. X
  1211. parm        equ    ss:[bp]
  1212. X
  1213. _TEXT    SEGMENT
  1214. X
  1215. X public        _asmputc
  1216. X
  1217. putc_stack        struc
  1218. X putc_bp    dw    ?
  1219. X putc_return    dd    ?
  1220. X char        db    ?
  1221. putc_stack        ends
  1222. X
  1223. _asmputc    proc    far
  1224. X        push    bp
  1225. X        mov    bp,sp
  1226. X        mov    al,parm.char
  1227. X        call    bios_conout
  1228. X        pop    bp
  1229. X        ret
  1230. _asmputc    endp
  1231. X
  1232. _TEXT        ends
  1233. X        end
  1234. X
  1235. SHAR_EOF
  1236. chmod 0444 z100bios.asm ||
  1237. echo 'restore of z100bios.asm failed'
  1238. Wc_c="`wc -c < 'z100bios.asm'`"
  1239. test 652 -eq "$Wc_c" ||
  1240.     echo 'z100bios.asm: original size 652, current size' "$Wc_c"
  1241. # ============= z309.c ==============
  1242. echo 'x - extracting z309.c (Text)'
  1243. sed 's/^X//' << 'SHAR_EOF' > 'z309.c' &&
  1244. /*
  1245. X * The routines in this file provide support for the Zenith Z-100 PC
  1246. X * family.  It goes directly to the graphics RAM to do screen output. 
  1247. X * It compiles into nothing if not a Zenith driver.
  1248. X */
  1249. X
  1250. #define    termdef    1            /* don't define "term" external */
  1251. X
  1252. #include        <stdio.h>
  1253. #include    "estruct.h"
  1254. #include        "edef.h"
  1255. X
  1256. #if     Z309
  1257. X
  1258. /* set NROW to 25 for 25-line interlaced mode */
  1259. #define NROW    50                      /* Screen size.                 */
  1260. #define NCOL    80                      /* Edit if you want to.         */
  1261. #define    MARGIN    8            /* size of minimim margin and    */
  1262. #define    SCRSIZ    64            /* scroll size for extended lines */
  1263. #define    NPAUSE    200            /* # times thru update to pause */
  1264. #define BEL     0x07                    /* BEL character.               */
  1265. #define ESC     0x1B                    /* ESC character.               */
  1266. #define    SPACE    32            /* space character        */
  1267. X
  1268. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  1269. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  1270. X
  1271. #define    CDMONO    0            /* monochrome text card        */
  1272. #define    CDCGA50    1            /* 50-line color graphics card    */
  1273. #define CDCGI25 2            /* 25-line interlaced CGA text    */
  1274. #define CDCGA25 3            /* 25-line color graphics card    */
  1275. #define    CDSENSE    9            /* detect the card type        */
  1276. X
  1277. int dtype = CDCGA50;            /* current display type        */
  1278. long scadd;                /* address of screen ram    */
  1279. int *scptr[NROW];            /* pointer to screen lines    */
  1280. int sline[NCOL];            /* screen line image        */
  1281. extern union REGS rg;            /* cpu register for use of DOS calls */
  1282. X
  1283. extern  int     ttopen();               /* Forward references.          */
  1284. extern  int     ttgetc();
  1285. extern  int     ttputc();
  1286. extern  int     ttflush();
  1287. extern  int     ttclose();
  1288. extern  int     z309move();
  1289. extern  int     z309eeol();
  1290. extern  int     z309eeop();
  1291. extern  int     z309beep();
  1292. extern  int     z309open();
  1293. extern    int    z309rev();
  1294. extern    int    z309cres();
  1295. extern    int    z309close();
  1296. extern    int    z309putc();
  1297. extern    int    z309kopen();
  1298. extern    int    z309kclose();
  1299. X
  1300. #if    COLOR
  1301. extern    int    z309fcol();
  1302. extern    int    z309bcol();
  1303. X
  1304. int    cfcolor = -1;        /* current forground color */
  1305. int    cbcolor = -1;        /* current background color */
  1306. int    ctrans[] =        /* ansi to z309 color translation table */
  1307. X    {0, 4, 2, 6, 1, 5, 3, 7};
  1308. #endif
  1309. X
  1310. /*
  1311. X * Standard terminal interface dispatch table. Most of the fields point into
  1312. X * "termio" code.
  1313. X */
  1314. TERM    term    = {
  1315. X    NROW-1,
  1316. X        NROW-1,
  1317. X        NCOL,
  1318. X        NCOL,
  1319. X    MARGIN,
  1320. X    SCRSIZ,
  1321. X    NPAUSE,
  1322. X        z309open,
  1323. X        z309close,
  1324. X    z309kopen,
  1325. X    z309kclose,
  1326. X        ttgetc,
  1327. X    z309putc,
  1328. X        ttflush,
  1329. X        z309move,
  1330. X        z309eeol,
  1331. X        z309eeop,
  1332. X        z309beep,
  1333. X    z309rev,
  1334. X    z309cres
  1335. #if    COLOR
  1336. X    , z309fcol,
  1337. X    z309bcol
  1338. #endif
  1339. };
  1340. X
  1341. extern union REGS rg;
  1342. X
  1343. #if    COLOR
  1344. z309fcol(color)        /* set the current output color */
  1345. X
  1346. int color;    /* color to set */
  1347. X
  1348. {
  1349. X    cfcolor = ctrans[color];
  1350. }
  1351. X
  1352. z309bcol(color)        /* set the current background color */
  1353. X
  1354. int color;    /* color to set */
  1355. X
  1356. {
  1357. X        cbcolor = ctrans[color];
  1358. }
  1359. #endif
  1360. z309move(row, col)
  1361. {
  1362. X    rg.h.ah = 2;        /* set cursor position function code */
  1363. X    rg.h.dl = col;
  1364. X    rg.h.dh = row;
  1365. X    rg.h.bh = 0;        /* set screen page number */
  1366. X    int86(0x10, &rg, &rg);
  1367. }
  1368. X
  1369. z309eeol()    /* erase to the end of the line */
  1370. X
  1371. {
  1372. X    int attr;    /* attribute byte mask to place in RAM */
  1373. X    int *lnptr;    /* pointer to the destination line */
  1374. X    int i;
  1375. X    int ccol;    /* current column cursor lives */
  1376. X    int crow;    /*       row    */
  1377. X
  1378. X    /* find the current cursor position */
  1379. X    rg.h.ah = 3;        /* read cursor position function code */
  1380. X    rg.h.bh = 0;        /* current video page */
  1381. X    int86(0x10, &rg, &rg);
  1382. X    ccol = rg.h.dl;        /* record current column */
  1383. X    crow = rg.h.dh;        /* and row */
  1384. X
  1385. X    /* build the attribute byte and setup the screen pointer */
  1386. #if    COLOR
  1387. X    if (dtype != CDMONO)
  1388. X        attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  1389. X    else
  1390. X        attr = 0x0700;
  1391. #else
  1392. X    attr = 0x0700;
  1393. #endif
  1394. X    lnptr = &sline[0];
  1395. X    for (i=0; i < term.t_ncol; i++)
  1396. X        *lnptr++ = SPACE | attr;
  1397. X
  1398. #if 0    /* Heath/Zenith builds flicker-less CGAs */
  1399. X    if (flickcode) {
  1400. X        /* wait for vertical retrace to be off */
  1401. X        while ((inp(0x3da) & 8))
  1402. X            ;
  1403. X    
  1404. X        /* and to be back on */
  1405. X        while ((inp(0x3da) & 8) == 0)
  1406. X            ;
  1407. X    }
  1408. #endif
  1409. X
  1410. X    /* and send the string out */
  1411. X    movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
  1412. X
  1413. }
  1414. X
  1415. z309putc(ch)    /* put a character at the current position in the
  1416. X           current colors */
  1417. X
  1418. int ch;
  1419. X
  1420. {
  1421. X    rg.h.ah = 14;        /* write char to screen with current attrs */
  1422. X    rg.h.al = ch;
  1423. #if    COLOR
  1424. X    if (dtype != CDMONO)
  1425. X        rg.h.bl = cfcolor;
  1426. X    else
  1427. X        rg.h.bl = 0x07;
  1428. #else
  1429. X    rg.h.bl = 0x07;
  1430. #endif
  1431. X    int86(0x10, &rg, &rg);
  1432. }
  1433. X
  1434. z309eeop()
  1435. {
  1436. X    int attr;        /* attribute to fill screen with */
  1437. X
  1438. X    rg.h.ah = 6;        /* scroll page up function code */
  1439. X    rg.h.al = 0;        /* # lines to scroll (clear it) */
  1440. X    rg.x.cx = 0;        /* upper left corner of scroll */
  1441. /*HERE*/    rg.x.dx = 0x184f;    /* lower right corner of scroll */
  1442. #if    COLOR
  1443. X    if (dtype != CDMONO)
  1444. X        attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  1445. X    else
  1446. X        attr = 0;
  1447. #else
  1448. X    attr = 0;
  1449. #endif
  1450. X    rg.h.bh = attr;
  1451. X    int86(0x10, &rg, &rg);
  1452. }
  1453. X
  1454. z309rev(state)        /* change reverse video state */
  1455. X
  1456. int state;    /* TRUE = reverse, FALSE = normal */
  1457. X
  1458. {
  1459. X    /* This never gets used under the z309-PC driver */
  1460. }
  1461. X
  1462. z309cres(res)    /* change screen resolution */
  1463. X
  1464. char *res;    /* resolution to change to */
  1465. X
  1466. {
  1467. X    if (strcmp(res, "CGA50") == 0) {
  1468. X        scinit(CDCGA50);
  1469. X        return(TRUE);
  1470. X    } else if (strcmp(res, "MONO") == 0) {
  1471. X        scinit(CDMONO);
  1472. X        return(TRUE);
  1473. X    } else
  1474. X        return(FALSE);
  1475. }
  1476. X
  1477. z309beep()
  1478. {
  1479. #if    MWC86
  1480. X    putcnb(BEL);
  1481. #else
  1482. X    bdos(6, BEL, 0);
  1483. #endif
  1484. }
  1485. X
  1486. z309open()
  1487. {
  1488. X    scinit(CDSENSE);
  1489. X    revexist = TRUE;
  1490. X        ttopen();
  1491. }
  1492. X
  1493. z309close()
  1494. X
  1495. {
  1496. X    rg.h.ah = 101;
  1497. X    rg.h.al = 1;    /* 25-line interlace mode */
  1498. X    int86(0x10, &rg, &rg); 
  1499. #if    COLOR
  1500. X    z309fcol(7);
  1501. X    z309bcol(0);
  1502. #endif
  1503. X    ttclose();
  1504. }
  1505. X
  1506. z309kopen()    /* open the keyboard */
  1507. X
  1508. {
  1509. }
  1510. X
  1511. z309kclose()    /* close the keyboard */
  1512. X
  1513. {
  1514. }
  1515. X
  1516. scinit(type)    /* initialize the screen head pointers */
  1517. X
  1518. int type;    /* type of adapter to init for */
  1519. X
  1520. {
  1521. X    union {
  1522. X        long laddr;    /* long form of address */
  1523. X        int *paddr;    /* pointer form of address */
  1524. X    } addr;
  1525. X    int i;
  1526. X
  1527. X    /* if asked...find out what display is connected */
  1528. X    int86(0x11, &rg, &rg);
  1529. X    dtype = CDCGA50;
  1530. X    scadd = SCADC;
  1531. X    strcpy(sres, "CGA50");
  1532. X    if ((((rg.x.ax >> 4) & 11) == 3) || type == CDMONO) {
  1533. X        strcpy(sres, "MONO");
  1534. X        dtype = CDMONO;
  1535. X        scadd = SCADM;
  1536. X    }
  1537. X    else {
  1538. X        rg.h.ah = 101;
  1539. /* set al = 1 for 25-line interlace mode */        
  1540. X        rg.h.al = 2;    /* 50-line interlace mode */
  1541. X        int86(0x10, &rg, &rg); 
  1542. X    }
  1543. X
  1544. X    /* initialize the screen pointer array */
  1545. X    for (i = 0; i < NROW; i++) {
  1546. X        addr.laddr = scadd + (long)(NCOL * i * 2);
  1547. X        scptr[i] = addr.paddr;
  1548. X    }
  1549. }
  1550. X
  1551. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  1552. X
  1553. int row;    /* row of screen to place outstr on */
  1554. char *outstr;    /* string to write out (must be term.t_ncol long) */
  1555. int forg;    /* forground color of string to write */
  1556. int bacg;    /* background color */
  1557. X
  1558. {
  1559. X    int attr;    /* attribute byte mask to place in RAM */
  1560. X    int *lnptr;    /* pointer to the destination line */
  1561. X    int i;
  1562. X
  1563. X    /* build the attribute byte and setup the screen pointer */
  1564. #if    COLOR
  1565. X    if (dtype != CDMONO)
  1566. X        attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  1567. X    else
  1568. X        attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  1569. #else
  1570. X    attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  1571. #endif
  1572. X    lnptr = &sline[0];
  1573. X    for (i=0; i<term.t_ncol; i++)
  1574. X        *lnptr++ = (outstr[i] & 255) | attr;
  1575. X
  1576. #if 0    /* Heath/Zenith builds flicker-less CGAs */
  1577. X    if (flickcode) {
  1578. X        /* wait for vertical retrace to be off */
  1579. X        while ((inp(0x3da) & 8))
  1580. X            ;
  1581. X    
  1582. X        /* and to be back on */
  1583. X        while ((inp(0x3da) & 8) == 0)
  1584. X            ;
  1585. X    }
  1586. #endif    
  1587. X
  1588. X    /* and send the string out */
  1589. X    movmem(&sline[0], scptr[row],term.t_ncol*2);
  1590. }
  1591. X
  1592. #if    FLABEL
  1593. fnclabel(f, n)        /* label a function key */
  1594. X
  1595. int f,n;    /* default flag, numeric argument [unused] */
  1596. X
  1597. {
  1598. X    /* on machines with no function keys...don't bother */
  1599. X    return(TRUE);
  1600. }
  1601. #endif
  1602. #else
  1603. z309hello()
  1604. {
  1605. }
  1606. #endif
  1607. SHAR_EOF
  1608. chmod 0444 z309.c ||
  1609. echo 'restore of z309.c failed'
  1610. Wc_c="`wc -c < 'z309.c'`"
  1611. test 7806 -eq "$Wc_c" ||
  1612.     echo 'z309.c: original size 7806, current size' "$Wc_c"
  1613. rm -f _shar_seq_.tmp
  1614. echo You have unpacked the last part
  1615. exit 0
  1616. -- 
  1617.         paul fox, pgf@cayman.com, (617)494-1999
  1618.         Cayman Systems, 26 Landsdowne St., Cambridge, MA 02139
  1619.