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

  1. From: pgf@cayman.COM (Paul Fox)
  2. Newsgroups: alt.sources
  3. Subject: Vile 07/17 - vi feel-alike (multi-window)
  4. Message-ID: <4526@cayman.COM>
  5. Date: 7 Jun 91 22:09:37 GMT
  6.  
  7. #!/bin/sh
  8. # this is vileshar.07 (part 7 of Vile)
  9. # do not concatenate these parts, unpack them in order with /bin/sh
  10. # file file.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" != 7; 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 file.c'
  25. sed 's/^X//' << 'SHAR_EOF' >> 'file.c' &&
  26. X
  27. #ifdef BEFORE
  28. X        if ((s=mlreply("Write file: ", fname, NFILEN)) != TRUE)
  29. X                return s;
  30. X    if ((s = glob(fname)) != TRUE)
  31. X        return FALSE;
  32. #else
  33. X    if (isnamedcmd && lastkey == '\r') {
  34. X        strncpy(fname, curbp->b_fname, NFILEN);
  35. X
  36. X        if (mlyesno("Okay to write [possible] partial range") != TRUE) {
  37. X            mlwrite("Range not written");
  38. X            return FALSE;
  39. X        }
  40. X    } else {
  41. X        /* HACK -- this implies knowledge of 
  42. X                    how kbd_engl works! */
  43. X            if ((s=mlreply("Write region to file: ", fname, NFILEN))
  44. X                             != TRUE)
  45. X                    return s;
  46. X        if ((s = glob(fname)) != TRUE)
  47. X            return FALSE;
  48. X        if (strcmp(fname,curbp->b_fname) &&
  49. X            fname[0] != '!' && flook(fname,FL_HERE)) {
  50. X            if (mlyesno("File exists, okay to overwrite")
  51. X                            != TRUE) {
  52. X                mlwrite("File not written");
  53. X                return FALSE;
  54. X            }
  55. X        }
  56. X        }
  57. #endif
  58. X        if ((s=getregion(®ion,NULL)) != TRUE)
  59. X                return s;
  60. #if DOSFILES
  61. X    dosfile = curbp->b_mode & MDDOS;
  62. #endif
  63. X    s = writereg(®ion,fname,TRUE);
  64. X        return s;
  65. }
  66. X
  67. X
  68. writereg(rp,fn,msgf)
  69. REGION *rp;
  70. char    *fn;
  71. {
  72. X        register int    s;
  73. X        register LINE   *lp;
  74. X        register int    nline;
  75. X    register int i;
  76. X    long lim;
  77. X    long nchar;
  78. X
  79. #if    CRYPT
  80. X    s = resetkey(curbp);
  81. X    if (s != TRUE)
  82. X        return s;
  83. #endif
  84. X        if (*fn == '[' || *fn == ' ') {
  85. X            mlwrite("No filename");
  86. X            return FALSE;
  87. X        }
  88. X        
  89. X        if ((s=ffwopen(fn)) != FIOSUC)       /* Open writes message. */
  90. X                return FALSE;
  91. X
  92. X    /* tell us we're writing */
  93. X    if (msgf == TRUE)
  94. X        mlwrite("[Writing...]");
  95. X
  96. #if UNIX & ! NeWS
  97. X    if (fileispipe)
  98. X        ttclean(TRUE);
  99. #else
  100. X    TTkclose();
  101. #endif
  102. X
  103. X        lp = rp->r_linep;
  104. X        nline = 0;                              /* Number of lines     */
  105. X        nchar = 0;                              /* Number of chars     */
  106. X
  107. X    /* First and maybe only line. */
  108. X    if (rp->r_offset <= llength(lp)) {
  109. X        if ((lim = rp->r_offset+rp->r_size) > llength(lp))
  110. X            lim = (long)llength(lp);
  111. X        for (i = rp->r_offset; i < lim; i++) {
  112. X                if ((s=ffputc(lgetc(lp,i))) != FIOSUC)
  113. X                        goto out;
  114. X            nchar++;
  115. X        }
  116. X        rp->r_size -= nchar;
  117. X
  118. X        if (rp->r_size <= 0)
  119. X            goto out;
  120. X
  121. X            if ((s=ffputc('\n')) != FIOSUC)
  122. X                    goto out;
  123. X
  124. X        nchar++;
  125. X        nline++;
  126. X        rp->r_size--;
  127. X                lp = lforw(lp);
  128. X
  129. X    }
  130. X
  131. X    /* whole lines */
  132. X        while (rp->r_size >= llength(lp)+1) {
  133. X                if ((s=ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
  134. X                        goto out;
  135. X                ++nline;
  136. X        nchar += llength(lp) + 1;
  137. X        rp->r_size -= llength(lp) + 1;
  138. X                lp = lforw(lp);
  139. X        }
  140. X
  141. X    /* last line */
  142. X    if (rp->r_size > 0) {
  143. X        lim = rp->r_size;
  144. X        for (i = 0; i < lim; i++) {
  145. X                if ((s=ffputc(lgetc(lp,i))) != FIOSUC)
  146. X                        goto out;
  147. X            nchar++;
  148. X            rp->r_size--;
  149. X        }
  150. X    }
  151. X    if (rp->r_size != 0)
  152. X        mlwrite("Bug: writereg, rsize == %d",rp->r_size);
  153. X
  154. X out:
  155. X        if (s == FIOSUC) {                      /* No write error.      */
  156. X                s = ffclose();
  157. X                if (s == FIOSUC && msgf) {      /* No close error.      */
  158. X                    mlwrite("[Wrote %d line%s %d char%s to %s]", 
  159. X                nline, (nline>1)?"s":"",
  160. X                nchar, (nchar>1)?"s":"", fn);
  161. X                }
  162. X        } else {                                /* Ignore close error   */
  163. X                ffclose();                      /* if a write error.    */
  164. X    }
  165. #if UNIX & ! NeWS
  166. X    if (fileispipe == TRUE) {
  167. X        ttunclean();
  168. X            TTflush();
  169. X        sgarbf = TRUE;
  170. X        pressreturn();
  171. X    }
  172. #else
  173. X    TTkopen();
  174. #endif
  175. X        if (s != FIOSUC)                        /* Some sort of error.  */
  176. X                return FALSE;
  177. X        return TRUE;
  178. }
  179. X
  180. /*
  181. X * This function writes the kill register to a file
  182. X * Uses the file management routines in the
  183. X * "fileio.c" package. The number of lines written is
  184. X * displayed.
  185. X */
  186. kwrite(fn,msgf)
  187. char    *fn;
  188. {
  189. X    register KILL *kp;        /* pointer into kill register */
  190. X    register int    nline;
  191. X    register int    s;
  192. X    register int    c;
  193. X    register int    i;
  194. X    register char    *sp;    /* pointer into string to insert */
  195. X
  196. X    /* make sure there is something to put */
  197. X    if (kbs[ukb].kbufh == NULL) {
  198. X        if (msgf) mlwrite("Nothing to write");
  199. X        return FALSE;        /* not an error, just nothing */
  200. X    }
  201. X
  202. #if    CRYPT
  203. X    s = resetkey(curbp);
  204. X    if (s != TRUE)
  205. X        return s;
  206. #endif
  207. X    /* turn off ALL keyboard translation in case we get a dos error */
  208. X    TTkclose();
  209. X
  210. X    if ((s=ffwopen(fn)) != FIOSUC) {    /* Open writes message. */
  211. X        TTkopen();
  212. X        return FALSE;
  213. X    }
  214. X    /* tell us we're writing */
  215. X    if (msgf == TRUE)
  216. X        mlwrite("[Writing...]");
  217. X    nline = 0;                /* Number of lines.    */
  218. X
  219. X    kp = kbs[ukb].kbufh;
  220. X    while (kp != NULL) {
  221. X        if (kp->d_next == NULL)
  222. X            i = kbs[ukb].kused;
  223. X        else
  224. X            i = KBLOCK;
  225. X        sp = kp->d_chunk;
  226. X        while (i--) {
  227. X            if ((c = *sp++) == '\n')
  228. X                nline++;
  229. X            if ((s = ffputc(c)) != FIOSUC)
  230. X                break;
  231. X        }
  232. X        kp = kp->d_next;
  233. X    }
  234. X    if (s == FIOSUC) {            /* No write error.    */
  235. X        s = ffclose();
  236. X        if (s == FIOSUC && msgf) {    /* No close error.    */
  237. X            mlwrite("[Wrote %d line%s to %s ]",
  238. X                    nline,nline!=1?"s":"", fn);
  239. X        }
  240. X    } else    {                /* Ignore close error    */
  241. X        ffclose();            /* if a write error.    */
  242. X    }
  243. X    TTkopen();
  244. X    if (s != FIOSUC)            /* Some sort of error.    */
  245. X        return FALSE;
  246. X    return TRUE;
  247. }
  248. X
  249. X
  250. /*
  251. X * The command allows the user
  252. X * to modify the file name associated with
  253. X * the current buffer. It is like the "f" command
  254. X * in UNIX "ed". The operation is simple; just zap
  255. X * the name in the BUFFER structure, and mark the windows
  256. X * as needing an update. You can type a blank line at the
  257. X * prompt if you wish.
  258. X */
  259. filename(f, n)
  260. {
  261. X        register int    s;
  262. X        static char            fname[NFILEN];
  263. X
  264. X        if ((s=mlreply("Name: ", fname, NFILEN)) == ABORT)
  265. X                return s;
  266. X    if ((s = glob(fname)) != TRUE)
  267. X        return FALSE;
  268. X        if (s == FALSE)
  269. X                strcpy(curbp->b_fname, "");
  270. X        else
  271. X                strcpy(curbp->b_fname, fname);
  272. X    curbp->b_mode &= ~MDVIEW;    /* no longer read only mode */
  273. X    markWFMODE(curbp);
  274. X        return TRUE;
  275. }
  276. X
  277. /*
  278. X * Insert file "fname" into the current
  279. X * buffer, Called by insert file command. Return the final
  280. X * status of the read.
  281. X */
  282. ifile(fname,belowthisline,haveffp)
  283. char    fname[];
  284. FILE *haveffp;
  285. {
  286. X        register LINE   *lp0;
  287. X        register LINE   *lp1;
  288. X        register LINE   *lp2;
  289. X        register int    i;
  290. X        register BUFFER *bp;
  291. X        register int    s;
  292. X        int    nbytes;
  293. X        register int    nline;
  294. X    char mesg[NSTRING];
  295. X    extern FILE    *ffp;
  296. X
  297. X        bp = curbp;                             /* Cheap.               */
  298. X        bp->b_flag |= BFCHG;            /* we have changed    */
  299. X    bp->b_flag &= ~BFINVS;            /* and are not temporary*/
  300. X    if (!haveffp) {
  301. X            if ((s=ffropen(fname)) == FIOERR)       /* Hard file open.      */
  302. X                    goto out;
  303. X            if (s == FIOFNF) {                      /* File not found.      */
  304. X                    mlwrite("[No such file \"%s\" ]", fname);
  305. X            return FALSE;
  306. X            }
  307. X            mlwrite("[Inserting...]");
  308. #if UNIX
  309. X        if (fileispipe)
  310. X            ttclean(TRUE);
  311. #endif
  312. X
  313. #if    CRYPT
  314. X        s = resetkey(curbp);
  315. X        if (s != TRUE)
  316. X            return s;
  317. #endif
  318. X    } else { /* we already have the file pointer */
  319. X        ffp = haveffp;
  320. X    }
  321. X    lp0 = curwp->w_dotp;
  322. X    curwp->w_doto = 0;
  323. X    setmark();
  324. X
  325. X    nline = 0;
  326. X    while ((s=ffgetline(&nbytes)) == FIOSUC) {
  327. X        if ((lp1=lalloc(nbytes)) == NULL) {
  328. X            s = FIOMEM;        /* Keep message on the    */
  329. X            break;            /* display.        */
  330. X        }
  331. X        if (belowthisline) {
  332. X            lp2 = lp0->l_fp;    /* line after insert */
  333. X        } else {
  334. X            lp2 = lp0;
  335. X            lp0 = lp0->l_bp;
  336. X        }
  337. X
  338. X        /* re-link new line between lp0 and lp2 */
  339. X        lp2->l_bp = lp1;
  340. X        lp0->l_fp = lp1;
  341. X        lp1->l_bp = lp0;
  342. X        lp1->l_fp = lp2;
  343. X
  344. #if BEFORE
  345. X        /* and advance and write out the current line */
  346. X        curwp->w_dotp = lp1;
  347. #endif
  348. #if BEFORE
  349. X        for (i=0; i<nbytes; ++i)
  350. X            lputc(lp1, i, fline[i]);
  351. #else
  352. X        memcpy(lp1->l_text, fline, nbytes);
  353. #endif
  354. #if BEFORE
  355. X        curwp->w_dotp = curwp->w_mkp;
  356. #endif
  357. X        tag_for_undo(lp1);
  358. X        if (belowthisline)
  359. X            lp0 = lp1;
  360. X        else
  361. X            lp0 = lp2;
  362. X        ++nline;
  363. X    }
  364. X    if (!haveffp) {
  365. #if UNIX
  366. X        if (fileispipe == TRUE) {
  367. X            ttunclean();
  368. X            TTflush();
  369. X            sgarbf = TRUE;
  370. X        }
  371. #endif
  372. X        ffclose();                /* Ignore errors.    */
  373. X        readlinesmsg(nline,s,fname,FALSE);
  374. X    }
  375. #if BEFORE
  376. X    curwp->w_mkp = lforw(curwp->w_mkp);
  377. #endif
  378. out:
  379. X    /* advance to the next line and mark the window for changes */
  380. X    curwp->w_dotp = lforw(curwp->w_dotp);
  381. X    curwp->w_flag |= WFHARD | WFMODE;
  382. X
  383. X    /* copy window parameters back to the buffer structure */
  384. X    curbp->b_dotp = curwp->w_dotp;
  385. X    curbp->b_doto = curwp->w_doto;
  386. X    curbp->b_markp = curwp->w_mkp;
  387. X    curbp->b_marko = curwp->w_mko;
  388. X    curbp->b_ldmkp = curwp->w_ldmkp;
  389. X    curbp->b_ldmko = curwp->w_ldmko;
  390. X
  391. X        if (s == FIOERR)                        /* False if error.      */
  392. X                return FALSE;
  393. X        return TRUE;
  394. }
  395. X
  396. /*
  397. X * Insert file "fname" into the kill register
  398. X * Called by insert file command. Return the final
  399. X * status of the read.
  400. X */
  401. kifile(fname)
  402. char    fname[];
  403. {
  404. X        register int    i;
  405. X        register int    s;
  406. X        register int    nline;
  407. X        int    nbytes;
  408. X
  409. X    kdelete();
  410. X        if ((s=ffropen(fname)) == FIOERR)       /* Hard file open.      */
  411. X                goto out;
  412. X        if (s == FIOFNF) {                      /* File not found.      */
  413. X                mlwrite("[No such file \"%s\"]", fname);
  414. X        return FALSE;
  415. X        }
  416. X        mlwrite("[Reading...]");
  417. X
  418. #if UNIX
  419. X    if (fileispipe)
  420. X        ttclean(TRUE);
  421. #endif
  422. X
  423. #if    CRYPT
  424. X    s = resetkey(curbp);
  425. X    if (s != TRUE)
  426. X        return s;
  427. #endif
  428. X        nline = 0;
  429. X        while ((s=ffgetline(&nbytes)) == FIOSUC) {
  430. X                for (i=0; i<nbytes; ++i)
  431. X                        kinsert(fline[i]);
  432. X                kinsert('\n');
  433. X                ++nline;
  434. X        }
  435. #if UNIX
  436. X    if (fileispipe == TRUE) {
  437. X        ttunclean();
  438. X            TTflush();
  439. X            sgarbf = TRUE;
  440. X    }
  441. #endif
  442. X        ffclose();                              /* Ignore errors.       */
  443. X    readlinesmsg(nline,s,fname,FALSE);
  444. X
  445. out:
  446. X        if (s == FIOERR)                        /* False if error.      */
  447. X                return FALSE;
  448. X        return TRUE;
  449. }
  450. X
  451. #if UNIX
  452. X
  453. /* called on hangups, interrupts, and quits */
  454. /* This code is definitely not production quality, or probably very
  455. X    robust, or probably very secure.  I whipped it up to save
  456. X    myself while debugging...        pgf */
  457. imdying(signo)
  458. {
  459. #if HAVE_MKDIR
  460. X    static char dirnam[NSTRING] = "/tmp/vileDXXXXXX";
  461. #else
  462. X    static char dirnam[NSTRING] = "/tmp";
  463. #endif
  464. X    char filnam[50];
  465. X    char cmd[80];
  466. X    BUFFER *bp;
  467. X    char *np;
  468. X    int wrote = 0;
  469. X    int created = 0;
  470. X    char *getenv();
  471. X    char *mktemp();
  472. X
  473. X
  474. X    bp = bheadp;
  475. X    while (bp != NULL) {
  476. X        if (((bp->b_flag & BFINVS) == 0) && 
  477. X             bp->b_active == TRUE && 
  478. X                     (bp->b_flag&BFCHG) != 0) {
  479. #if HAVE_MKDIR
  480. X            if (!created) {
  481. X                (void)mktemp(dirnam);
  482. X                if(mkdir(dirnam,0700) != 0) {
  483. X                    vttidy(FALSE);
  484. X                    exit(1);
  485. X                }
  486. X                created = 1;
  487. X            }
  488. #endif
  489. X            strcpy(filnam,dirnam);
  490. X            strcat(filnam,"/");
  491. #if ! HAVE_MKDIR
  492. X            strcat(filnam,"V");
  493. #endif
  494. X            strcat(filnam,bp->b_bname);
  495. X            if (writeout(filnam,bp,FALSE) != TRUE) {
  496. X                vttidy(FALSE);
  497. X                exit(1);
  498. X            }
  499. X            wrote++;
  500. X        }
  501. X        bp = bp->b_bufp;
  502. X    }
  503. X    if (wrote) {
  504. X        if ((np = getenv("LOGNAME")) || (np = getenv("USER"))) {
  505. X            sprintf(cmd,
  506. #if HAVE_MKDIR
  507. X    "(echo Subject: vile died; echo Files saved: ; ls %s/* ) | /bin/mail %s",
  508. #else
  509. X    "(echo Subject: vile died; echo Files saved: ; ls %s/V* ) | /bin/mail %s",
  510. #endif
  511. X                dirnam, np);
  512. X            system(cmd);
  513. X        }
  514. X    }
  515. X    vttidy(FALSE);
  516. X    if (signo > 2) abort();
  517. X    exit(wrote);
  518. }
  519. #endif
  520. X
  521. markWFMODE(bp)
  522. BUFFER *bp;
  523. {
  524. X    register WINDOW *wp;    /* scan for windows that need updating */
  525. X        wp = wheadp;                    /* Update mode lines.   */
  526. X        while (wp != NULL) {
  527. X                if (wp->w_bufp == bp)
  528. X                        wp->w_flag |= WFMODE;
  529. X                wp = wp->w_wndp;
  530. X        }
  531. }
  532. X
  533. /* use the shell to expand wildcards */
  534. /*  should optimize this to only call shell if wildcards are suspected */
  535. glob(buf)
  536. char *buf;
  537. {
  538. #if UNIX
  539. X    char *cp;
  540. X    char cmd[NFILEN+50];
  541. X    FILE *cf;
  542. X    FILE *npopen();
  543. X
  544. X    /* trim trailing whitespace */
  545. X    cp = &buf[strlen(buf)-1];
  546. X    while (cp != buf) {
  547. X        if (isspace(*cp))
  548. X            *cp = '\0';
  549. X        else
  550. X            break;
  551. X        cp--;
  552. X    }
  553. X
  554. X    cp = buf;
  555. X    if (*cp == '!' || *cp == '[')    /* it's a shell command, or an */
  556. X        return TRUE;        /* internal name, don't bother */
  557. X
  558. X    while (*cp) {
  559. X        if (iswild(*cp)) {
  560. X            sprintf(cmd, "echo %s", buf);
  561. X            cf = npopen(cmd,"r");
  562. X            if (cf == NULL) {
  563. X                return TRUE;
  564. X            }
  565. X            if (fread(buf,1,NFILEN,cf) <= 0) {
  566. X                npclose(cf);
  567. X                return FALSE;
  568. X            }
  569. X            npclose(cf);
  570. X            cp = buf;
  571. X            while (*cp) {
  572. X                if (*cp == ' ' ) {
  573. X                    if (mlyesno(
  574. X                    "Too many filenames.  Use first"
  575. X                            ) == TRUE) {
  576. X                        *cp = '\0';
  577. X                        break;
  578. X                    } else {
  579. X                        buf[0] = 0;
  580. X                        return FALSE;
  581. X                    }
  582. X                } else if (*cp == '\n') {
  583. X                    *cp = '\0';
  584. X                    break;
  585. X                }
  586. X                cp++;
  587. X            }
  588. X            return TRUE;
  589. X
  590. X        }
  591. X        cp++;
  592. X    }
  593. X    return TRUE;
  594. #endif
  595. }
  596. X
  597. #if    CRYPT
  598. resetkey(bp)    /* reset the encryption key if needed */
  599. BUFFER *bp;
  600. {
  601. X    register int s;    /* return status */
  602. X
  603. X    /* turn off the encryption flag */
  604. X    cryptflag = FALSE;
  605. X
  606. X    /* if we are in crypt mode */
  607. X    if (bp->b_mode & MDCRYPT) {
  608. X        if (bp->b_key[0] == 0) {
  609. X            s = setkey(FALSE, 0);
  610. X            if (s != TRUE)
  611. X                return s;
  612. X        }
  613. X
  614. X        /* let others know... */
  615. X        cryptflag = TRUE;
  616. X
  617. X        /* and set up the key to be used! */
  618. X        /* de-encrypt it */
  619. X        crypt((char *)NULL, 0);
  620. X        crypt(bp->b_key, strlen(bp->b_key));
  621. X
  622. X        /* re-encrypt it...seeding it to start */
  623. X        crypt((char *)NULL, 0);
  624. X        crypt(bp->b_key, strlen(bp->b_key));
  625. X    }
  626. X
  627. X    return TRUE;
  628. }
  629. #endif
  630. X
  631. SHAR_EOF
  632. echo 'File file.c is complete' &&
  633. chmod 0444 file.c ||
  634. echo 'restore of file.c failed'
  635. Wc_c="`wc -c < 'file.c'`"
  636. test 28527 -eq "$Wc_c" ||
  637.     echo 'file.c: original size 28527, current size' "$Wc_c"
  638. # ============= fileio.c ==============
  639. echo 'x - extracting fileio.c (Text)'
  640. sed 's/^X//' << 'SHAR_EOF' > 'fileio.c' &&
  641. /*
  642. X * The routines in this file read and write ASCII files from the disk. All of
  643. X * the knowledge about files are here.
  644. X */
  645. X
  646. #include        <stdio.h>
  647. #include    "estruct.h"
  648. #include        "edef.h"
  649. #if UNIX
  650. #include        <errno.h>
  651. #include        <fcntl.h>
  652. #endif
  653. #if    BSD
  654. #include "sys/filio.h"
  655. #endif
  656. X
  657. /* possibly non-portable addition to stdio set of macros */
  658. #define    isready_c(p)    ((p)->_cnt>0? TRUE:FALSE)
  659. X
  660. FILE    *ffp;        /* File pointer, all functions. */
  661. int fileispipe;
  662. int eofflag;        /* end-of-file flag */
  663. #if DOSFILES
  664. int doslines, unixlines;
  665. int dosfile;
  666. #endif
  667. X
  668. X
  669. /*
  670. X * Open a file for reading.
  671. X */
  672. ffropen(fn)
  673. char    *fn;
  674. {
  675. #if UNIX
  676. X    FILE *npopen();
  677. #endif
  678. X
  679. #if DOSFILES
  680. X    doslines = unixlines = 0;
  681. #endif
  682. X
  683. #if UNIX
  684. X    
  685. X    if (*fn == '!') {
  686. X            if ((ffp=npopen(fn+1, "r")) == NULL)
  687. X                    return (FIOERR);
  688. X        fileispipe = TRUE;
  689. X    } else {
  690. X            if ((ffp=fopen(fn, "r")) == NULL) {
  691. X            if (errno == ENOENT)
  692. X                        return (FIOFNF);
  693. X                    return (FIOERR);
  694. X        }
  695. X        fileispipe = FALSE;
  696. X    }
  697. #else
  698. X        if ((ffp=fopen(fn, "r")) == NULL)
  699. X                return (FIOFNF);
  700. #endif
  701. X    eofflag = FALSE;
  702. X        return (FIOSUC);
  703. }
  704. X
  705. /*
  706. X * Open a file for writing. Return TRUE if all is well, and FALSE on error
  707. X * (cannot create).
  708. X */
  709. ffwopen(fn)
  710. char    *fn;
  711. {
  712. #if UNIX
  713. X    if (*fn == '!') {
  714. X            if ((ffp=npopen(fn+1, "w")) == NULL) {
  715. X                    mlwrite("Cannot open pipe for writing");
  716. X            TTbeep();
  717. X                    return (FIOERR);
  718. X        }
  719. X        fileispipe = TRUE;
  720. X    } else {
  721. X            if ((ffp=fopen(fn, "w")) == NULL) {
  722. X                    mlwrite("Cannot open file for writing");
  723. X            TTbeep();
  724. X                    return (FIOERR);
  725. X        }
  726. X        fileispipe = FALSE;
  727. X    }
  728. #else
  729. #if     VMS
  730. X        register int    fd;
  731. X
  732. X        if ((fd=creat(fn, 0666, "rfm=var", "rat=cr")) < 0
  733. X        || (ffp=fdopen(fd, "w")) == NULL) {
  734. X                mlwrite("Cannot open file for writing");
  735. X                return (FIOERR);
  736. X        }
  737. #else
  738. X        if ((ffp=fopen(fn, "w")) == NULL) {
  739. X                mlwrite("Cannot open file for writing");
  740. X                return (FIOERR);
  741. X        }
  742. #endif
  743. #endif
  744. X        return (FIOSUC);
  745. }
  746. X
  747. /* is the file read-only?  true or false */
  748. #if UNIX  /* don't know how to do it for other systems */
  749. ffronly(fn)
  750. char    *fn;
  751. {
  752. X    int fd;
  753. X
  754. X    if (*fn == '!') {
  755. X        return TRUE;
  756. X    } else {
  757. X            if ((fd=open(fn, O_WRONLY)) < 0) {
  758. X                    return TRUE;
  759. X        }
  760. X        close(fd);
  761. X        return FALSE;
  762. X    }
  763. }
  764. #endif
  765. X
  766. /*
  767. X * Close a file. Should look at the status in all systems.
  768. X */
  769. ffclose()
  770. {
  771. X    int s;
  772. X
  773. X    /* free this since we do not need it anymore */
  774. X    if (fline) {
  775. X        free(fline);
  776. X        fline = NULL;
  777. X        flen = 0;
  778. X    }
  779. X
  780. #if    MSDOS & CTRLZ & NEVER
  781. X     but we NEVER want to do this on read closes!!!
  782. X    fputc(26, ffp);        /* add a ^Z at the end of the file */
  783. #endif
  784. X    
  785. #if DOSFILES
  786. X    /* did we get more dos-style lines than unix-style? */
  787. X    dosfile = (doslines > unixlines);
  788. X    unixlines = 0;
  789. #endif
  790. #if UNIX | (MSDOS & (LATTICE | MSC | TURBO))
  791. #if UNIX
  792. X    
  793. X    if (fileispipe)
  794. X        s = npclose(ffp);
  795. X    else
  796. #endif
  797. X        s = fclose(ffp);
  798. X        if (s != 0) {
  799. X                mlwrite("Error on close");
  800. X                return(FIOERR);
  801. X        }
  802. X        return(FIOSUC);
  803. #else
  804. X        fclose(ffp);
  805. X        return (FIOSUC);
  806. #endif
  807. }
  808. X
  809. /*
  810. X * Write a line to the already opened file. The "buf" points to the buffer,
  811. X * and the "nbuf" is its length, less the free newline. Return the status.
  812. X * Check only at the newline.
  813. X */
  814. ffputline(buf, nbuf)
  815. char    buf[];
  816. {
  817. X        register int    i;
  818. #if    CRYPT
  819. X    char c;        /* character to translate */
  820. X
  821. X    if (cryptflag) {
  822. X            for (i = 0; i < nbuf; ++i) {
  823. X            c = buf[i] & 0xff;
  824. X            crypt(&c, 1);
  825. X            fputc(c, ffp);
  826. X        }
  827. X    } else
  828. X            for (i = 0; i < nbuf; ++i)
  829. X                    fputc(buf[i]&0xFF, ffp);
  830. #else
  831. X        for (i = 0; i < nbuf; ++i)
  832. X                fputc(buf[i]&0xFF, ffp);
  833. #endif
  834. X
  835. #if    ST520
  836. X        fputc('\r', ffp);
  837. #endif        
  838. #if DOSFILES
  839. X    if (dosfile) {
  840. X        /* put out CR, unless we just did */
  841. X        if (i == 0 || buf[i-1] != '\r')
  842. X                fputc('\r', ffp);
  843. X    }
  844. #endif
  845. X        fputc('\n', ffp);
  846. X
  847. X        if (ferror(ffp)) {
  848. X                mlwrite("Write I/O error");
  849. X                return (FIOERR);
  850. X        }
  851. X
  852. X        return (FIOSUC);
  853. }
  854. /*
  855. X * Write a charto the already opened file.
  856. X * Return the status.
  857. X */
  858. ffputc(c)
  859. {
  860. X    static lastc;
  861. X    c &= 0xff;
  862. #if DOSFILES
  863. X    if (dosfile && c == '\n' && lastc != '\r')
  864. X         fputc('\r',ffp);
  865. #endif
  866. X    lastc = c;
  867. X
  868. #if    CRYPT
  869. X    if (cryptflag)
  870. X        crypt(&c, 1);
  871. #endif
  872. X        fputc(c, ffp);
  873. X
  874. X        if (ferror(ffp)) {
  875. X                mlwrite("Write I/O error");
  876. X                return (FIOERR);
  877. X        }
  878. X
  879. X        return (FIOSUC);
  880. }
  881. X
  882. /*
  883. X * Read a line from a file, and store the bytes in an allocated buffer.
  884. X * "flen" is the length of the buffer. Reallocate and copy as necessary.
  885. X * Check for I/O errors. Return status.
  886. X */
  887. ffgetline(lenp)
  888. int *lenp;    /* to return the final length */
  889. {
  890. X        register int c;        /* current character read */
  891. X        register int i;        /* current index into fline */
  892. X    register char *tmpline;    /* temp storage for expanding line */
  893. X
  894. X    /* if we are at the end...return it */
  895. X    if (eofflag)
  896. X        return(FIOEOF);
  897. X
  898. #if BEFORE    /* no no no -- malloc is expensive... */
  899. X    /* dump fline if it ended up too big */
  900. X    if (flen > NSTRING) {
  901. X        free(fline);
  902. X        fline = NULL;
  903. X        flen = 0;
  904. X    }
  905. #endif
  906. X
  907. X    /* if we don't have an fline, allocate one */
  908. X    if (fline == NULL)
  909. X        if ((fline = malloc(flen = NSTRING)) == NULL)
  910. X            return(FIOMEM);
  911. X
  912. X    /* read the line in */
  913. X        i = 0;
  914. X        while ((c = fgetc(ffp)) != EOF && c != '\n') {
  915. X                fline[i++] = c;
  916. X        /* if it's longer, get more room */
  917. X                if (i >= flen) {
  918. X                    if ((tmpline = malloc(flen+NSTRING)) == NULL)
  919. X                        return(FIOMEM);
  920. X                    strncpy(tmpline, fline, flen);
  921. X                    flen += NSTRING;
  922. X                    free(fline);
  923. X                    fline = tmpline;
  924. X                }
  925. X        }
  926. X
  927. #if !DOSFILES
  928. #if    ST520
  929. X    if(fline[i-1] == '\r') {
  930. X        i--;
  931. X    }
  932. #endif
  933. #else
  934. X    if(fline[i-1] == '\r') {
  935. X        doslines++;
  936. X        i--;
  937. X    } else {
  938. X        unixlines++;
  939. X    }
  940. #endif
  941. X
  942. X    *lenp = i;    /* return the length, not including final null */
  943. X        fline[i] = 0;
  944. #if TESTING
  945. if (i > 0) {
  946. X    if (isready_c(ffp))
  947. X        fline[0] = 'y';
  948. X    else
  949. X        fline[0] = 'n';
  950. X    if (i > 1) {
  951. X        long x;
  952. X        if ((ioctl(fileno(ffp),FIONREAD,&x) < 0) || x == 0)
  953. X            fline[1] = 'n';
  954. X        else
  955. X            fline[1] = 'y';
  956. X    }    
  957. }    
  958. #endif
  959. X    /* test for any errors that may have occured */
  960. X        if (c == EOF) {
  961. X                if (ferror(ffp)) {
  962. X                        mlwrite("File read error");
  963. X                        return(FIOERR);
  964. X                }
  965. X
  966. X                if (i != 0)
  967. X            eofflag = TRUE;
  968. X        else
  969. X            return(FIOEOF);
  970. X        }
  971. X
  972. #if    CRYPT
  973. X    /* decrypt the string */
  974. X    if (cryptflag)
  975. X        crypt(fline, strlen(fline));
  976. #endif
  977. X        return(FIOSUC);
  978. }
  979. X
  980. ffhasdata()
  981. {
  982. X    long x;
  983. #if    BSD
  984. X    if (isready_c(ffp))
  985. X        return TRUE;
  986. X    return(((ioctl(fileno(ffp),FIONREAD,&x) < 0) || x == 0) ? FALSE : TRUE);
  987. #else
  988. X    return FALSE;
  989. #endif
  990. }
  991. X
  992. #if    AZTEC & MSDOS
  993. #undef    fgetc
  994. /*    a1getc:        Get an ascii char from the file input stream
  995. X            but DO NOT strip the high bit
  996. */
  997. X
  998. int a1getc(fp)
  999. X
  1000. FILE *fp;
  1001. X
  1002. {
  1003. X    int c;        /* translated character */
  1004. X
  1005. X    c = getc(fp);    /* get the character */
  1006. X
  1007. X    /* if its a <LF> char, throw it out  */
  1008. X    while (c == '\n')
  1009. X        c = getc(fp);
  1010. X
  1011. X    /* if its a <RETURN> char, change it to a LF */
  1012. X    if (c == '\r')
  1013. X        c = '\n';
  1014. X
  1015. X    /* if its a ^Z, its an EOF */
  1016. X    if (c == 26)
  1017. X        c = EOF;
  1018. X
  1019. X    return(c);
  1020. }
  1021. #endif
  1022. SHAR_EOF
  1023. chmod 0444 fileio.c ||
  1024. echo 'restore of fileio.c failed'
  1025. Wc_c="`wc -c < 'fileio.c'`"
  1026. test 7384 -eq "$Wc_c" ||
  1027.     echo 'fileio.c: original size 7384, current size' "$Wc_c"
  1028. # ============= finderr.c ==============
  1029. echo 'x - extracting finderr.c (Text)'
  1030. sed 's/^X//' << 'SHAR_EOF' > 'finderr.c' &&
  1031. /* written for vile by Paul Fox, (c)1990 */
  1032. X
  1033. #include    "estruct.h"
  1034. #include        "edef.h"
  1035. X
  1036. #if FINDERR
  1037. X
  1038. #ifndef NULL
  1039. #define NULL 0
  1040. #endif
  1041. X
  1042. struct LINE *getdot();
  1043. X
  1044. /* edits the file and goes to the line pointed at by the next compiler
  1045. X        error in the "[output]" window.  It unfortunately doesn't mark
  1046. X        the lines for you, so adding lines to the file throws off the
  1047. X        later numbering.  Solutions to this seem messy at the moment */
  1048. X
  1049. finderr(f,n)
  1050. {
  1051. X    register BUFFER *sbp;
  1052. X    register LINE *lp;
  1053. X    register int i = 0;
  1054. X    register int s = TRUE;
  1055. X    struct LINE *dotp;
  1056. X    int moveddot = FALSE;
  1057. X    
  1058. X    int errline;
  1059. X    char errfile[NFILEN];
  1060. X    
  1061. X    static int oerrline = -1;
  1062. X    static char oerrfile[NFILEN];
  1063. X
  1064. X    /* look up the right buffer */
  1065. X        if ((sbp=bfind(febuff, NO_CREAT, 0)) == NULL) {
  1066. X            mlwrite("No buffer to search for errors.");
  1067. X                return(FALSE);
  1068. X        }
  1069. X        
  1070. X        if (newfebuff) {
  1071. X            oerrline = -1;
  1072. X            oerrfile[0] = '\0';
  1073. X        }
  1074. X        newfebuff = FALSE;
  1075. X
  1076. X    dotp = getdot(sbp);
  1077. X
  1078. X    for(;;) {
  1079. X        /* to use this line, we need both the filename and the line
  1080. X            number in the expected places, and a different line
  1081. X            than last time */
  1082. X        /* accept lines of the form:
  1083. X            "file.c", line 223: error....
  1084. X            or
  1085. X            file.c: 223: error....
  1086. X        */
  1087. X        if ((sscanf(dotp->l_text,
  1088. X            "\"%[^\"     ]\", line %d:",errfile,&errline) == 2 ||
  1089. X             sscanf(dotp->l_text,
  1090. X            "%[^:     ]: %d:",errfile,&errline) == 2 
  1091. X            ) &&
  1092. X            (oerrline != errline || strcmp(errfile,oerrfile))) {
  1093. X                break;
  1094. X        }
  1095. X            
  1096. X        if (lforw(dotp) == sbp->b_linep) {
  1097. X            mlwrite("No more errors in %s buffer", febuff);
  1098. X            TTbeep();
  1099. X            /* start over at the top of file */
  1100. X            putdotback(sbp, lforw(sbp->b_linep));
  1101. X            return FALSE;
  1102. X        }
  1103. X        dotp = lforw(dotp);
  1104. X        moveddot = TRUE;
  1105. X    }
  1106. X    /* put the new dot back, before possible changes to contents
  1107. X                of current window from getfile() */
  1108. X    if (moveddot)
  1109. X        putdotback(sbp,dotp);
  1110. X
  1111. X    if (strcmp(errfile,curbp->b_fname)) { /* if we must change windows */
  1112. X        struct WINDOW *wp;
  1113. X        wp = wheadp;
  1114. X        while (wp != NULL) {
  1115. X            if (!strcmp(wp->w_bufp->b_fname,errfile))
  1116. X                break;
  1117. X            wp = wp->w_wndp;
  1118. X        }
  1119. X        if (wp) {
  1120. X            curwp = wp;
  1121. X            make_current(curwp->w_bufp);
  1122. X            upmode();
  1123. X        } else {
  1124. X            s = getfile(errfile,TRUE);
  1125. X            if (s != TRUE)
  1126. X                return s;
  1127. X        }
  1128. X    }
  1129. X
  1130. X    mlwrite("Error is %S", dotp->l_used, dotp->l_text);
  1131. X
  1132. X    /* it's an absolute move */
  1133. X    curwp->w_ldmkp = curwp->w_dotp;
  1134. X    curwp->w_ldmko = curwp->w_doto;
  1135. X    gotoline(TRUE,errline);
  1136. X
  1137. X    oerrline = errline;
  1138. X    strcpy(oerrfile,errfile);
  1139. X
  1140. X    return TRUE;
  1141. X
  1142. }
  1143. X
  1144. struct LINE *
  1145. getdot(bp)
  1146. struct BUFFER *bp;
  1147. {
  1148. X    register WINDOW *wp;
  1149. X    if (bp->b_nwnd) {
  1150. X        /* scan for windows holding that buffer, 
  1151. X                    pull dot from the first */
  1152. X            wp = wheadp;
  1153. X            while (wp != NULL) {
  1154. X                    if (wp->w_bufp == bp) {
  1155. X                            return wp->w_dotp;
  1156. X            }
  1157. X                    wp = wp->w_wndp;
  1158. X            }
  1159. X    }
  1160. X        return bp->b_dotp;
  1161. }
  1162. X
  1163. putdotback(bp,dotp)
  1164. struct BUFFER *bp;
  1165. struct LINE *dotp;
  1166. {
  1167. X    register WINDOW *wp;
  1168. X
  1169. X    if (bp->b_nwnd) {
  1170. X            wp = wheadp;
  1171. X            while (wp != NULL) {
  1172. X                    if (wp->w_bufp == bp) {
  1173. X                        wp->w_dotp = dotp;
  1174. X                        wp->w_doto = 0;
  1175. X                    wp->w_flag |= WFMOVE;
  1176. X            }
  1177. X                    wp = wp->w_wndp;
  1178. X            }
  1179. X        return;
  1180. X    }
  1181. X    /* then the buffer isn't displayed */
  1182. X        bp->b_dotp = dotp;
  1183. X        bp->b_doto = 0;
  1184. }
  1185. X
  1186. #else
  1187. finderrhello() { }
  1188. #endif
  1189. SHAR_EOF
  1190. chmod 0444 finderr.c ||
  1191. echo 'restore of finderr.c failed'
  1192. Wc_c="`wc -c < 'finderr.c'`"
  1193. test 3373 -eq "$Wc_c" ||
  1194.     echo 'finderr.c: original size 3373, current size' "$Wc_c"
  1195. # ============= globals.c ==============
  1196. echo 'x - extracting globals.c (Text)'
  1197. sed 's/^X//' << 'SHAR_EOF' > 'globals.c' &&
  1198. #include    "estruct.h"
  1199. #include        "edef.h"
  1200. #include        <stdio.h>
  1201. X
  1202. /* ed/vi/ex style global commands, where first the file is scanned for
  1203. X    matching lines, then for each such line, an action is performed.
  1204. X    written for vile by Paul Fox, (c)1990
  1205. */
  1206. #if GLOBALS
  1207. X
  1208. globals(f,n)
  1209. {
  1210. X    return globber(f,n,'g');
  1211. }
  1212. X
  1213. vglobals(f,n)
  1214. {
  1215. #ifdef SOMEDAY
  1216. X    return globber(f,n,'v');
  1217. #else
  1218. X    return unimpl();
  1219. #endif
  1220. }
  1221. X
  1222. globber(f, n, g_or_v)
  1223. {
  1224. X    static char buf[NFILEN];
  1225. X    int c, s;
  1226. X    register LINE *lp;
  1227. X    register char *fnp;    /* ptr to the name of the cmd to exec */
  1228. X    char *kbd_engl();
  1229. X    CMDFUNC *engl2fnc();
  1230. X    CMDFUNC *cfp;
  1231. X    int foundone;
  1232. X    extern CMDFUNC f_godotplus;
  1233. X    
  1234. X    c = '\n';
  1235. X    if (isnamedcmd) {
  1236. X        c = tpeekc();
  1237. X        if (c < 0) {
  1238. X            c = '\n';
  1239. X        } else {
  1240. X            if (ispunct(c)) {
  1241. X                (void)kbd_key();
  1242. X            }
  1243. X        }
  1244. X    }
  1245. X    if (readpattern("global pattern: ", &pat[0], TRUE, c, FALSE) != TRUE) {
  1246. X        mlwrite("No pattern.");
  1247. X        return FALSE;
  1248. X    }
  1249. X
  1250. X    /* in some sense, it would be nice to search first, before
  1251. X                making the user answer the next question, but the
  1252. X                searching delay is too long, and unexpected in the
  1253. X                middle of a command.  */
  1254. X
  1255. X    mlwrite("action to perform on each matching line: ");
  1256. X    /* and now get the name of, and then the function to execute */
  1257. X    cfp = NULL;
  1258. X    fnp = kbd_engl();
  1259. X    if (!fnp || !fnp[0]) {
  1260. X            mlwrite("[No function]");
  1261. X        return FALSE;
  1262. X    } else if (!(cfp = engl2fnc(fnp))) {
  1263. X            mlwrite("[No such function]");
  1264. X        return FALSE;
  1265. X    } else if ((cfp->c_flags & GLOBOK) == 0) {
  1266. X            mlwrite("[Function not allowed]");
  1267. X        return FALSE;
  1268. X    }
  1269. X    
  1270. X    
  1271. X    /* call the searcher, telling it to do line marking */
  1272. X    s = fsearch(FALSE,0,TRUE,NULL);
  1273. X    if (s != TRUE)
  1274. X        return s;
  1275. X    
  1276. X    calledbefore = FALSE;
  1277. X    
  1278. X    /* loop through the buffer -- we must clear the marks no matter what */
  1279. X    s = TRUE;
  1280. X    lp = lforw(curbp->b_linep);
  1281. X    /* loop until there are no marked lines in the buffer */
  1282. X    foundone = FALSE;
  1283. X    for(;;) {
  1284. X        if (lp == curbp->b_linep) {
  1285. X            /* at the end -- only quit if we found no 
  1286. X                marks on the last pass through. otherwise,
  1287. X                go through again */
  1288. X            if (foundone)
  1289. X                foundone = FALSE;
  1290. X            else
  1291. X                break;
  1292. X        }
  1293. X        if (lismarked(lp)) {
  1294. X            foundone = TRUE;
  1295. X            lsetnotmarked(lp);
  1296. X            curwp->w_dotp = lp;
  1297. X            curwp->w_doto = 0;
  1298. X            /* call the function, if there is one, and results
  1299. X                have been ok so far */
  1300. X            if (cfp && s) {
  1301. X                if (!calledbefore && (cfp->c_flags & UNDO)) {
  1302. X                    if (curbp->b_mode&MDVIEW)
  1303. X                        return(rdonly());
  1304. X                    mayneedundo();
  1305. X                }
  1306. X                havemotion = &f_godotplus;
  1307. X                s = (cfp->c_func)(FALSE, 1, NULL, NULL);
  1308. X                havemotion = NULL;
  1309. X                calledbefore = TRUE;
  1310. X            }
  1311. X            if (lp != curwp->w_dotp) {
  1312. X                /* make sure we're still in the buffer, since
  1313. X                    action might have caused delete, etc. */
  1314. X                lp = curwp->w_dotp;
  1315. X            }
  1316. X        }
  1317. X        lp = lforw(lp);
  1318. X    }
  1319. X
  1320. X    cfp = NULL;
  1321. X
  1322. X    return s;
  1323. }
  1324. X
  1325. #else
  1326. globalhello() { }
  1327. #endif
  1328. SHAR_EOF
  1329. chmod 0444 globals.c ||
  1330. echo 'restore of globals.c failed'
  1331. Wc_c="`wc -c < 'globals.c'`"
  1332. test 2834 -eq "$Wc_c" ||
  1333.     echo 'globals.c: original size 2834, current size' "$Wc_c"
  1334. # ============= hp110.c ==============
  1335. echo 'x - extracting hp110.c (Text)'
  1336. sed 's/^X//' << 'SHAR_EOF' > 'hp110.c' &&
  1337. /*
  1338. X *    HP110:    Hewlett Packard 110 Screen Driver
  1339. X */
  1340. X
  1341. #define    termdef    1            /* don't define "term" external */
  1342. X
  1343. #include        <stdio.h>
  1344. #include    "estruct.h"
  1345. #include        "edef.h"
  1346. X
  1347. #if     HP110
  1348. X
  1349. #define NROW    16                      /* Screen size.                 */
  1350. #define NCOL    80                      /* Edit if you want to.         */
  1351. #define    NPAUSE    100            /* # times thru update to pause */
  1352. #define    MARGIN    8            /* size of minimim margin and    */
  1353. #define    SCRSIZ    64            /* scroll size for extended lines */
  1354. #define BEL     0x07                    /* BEL character.               */
  1355. #define ESC     0x1B                    /* ESC character.               */
  1356. X
  1357. extern  int     ttopen();               /* Forward references.          */
  1358. extern  int     ttgetc();
  1359. extern  int     ttputc();
  1360. extern  int     ttflush();
  1361. extern  int     ttclose();
  1362. extern  int     h110move();
  1363. extern  int     h110eeol();
  1364. extern  int     h110eeop();
  1365. extern  int     h110beep();
  1366. extern  int     h110open();
  1367. extern    int    h110rev();
  1368. extern    int    h110cres();
  1369. extern    int    h110close();
  1370. extern    int    h110kopen();
  1371. extern    int    h110kclose();
  1372. X
  1373. #if    COLOR
  1374. extern    int    h110fcol();
  1375. extern    int    h110bcol();
  1376. X
  1377. int    cfcolor = -1;        /* current forground color */
  1378. int    cbcolor = -1;        /* current background color */
  1379. #endif
  1380. X
  1381. /*
  1382. X * Standard terminal interface dispatch table. Most of the fields point into
  1383. X * "termio" code.
  1384. X */
  1385. TERM    term    = {
  1386. X    NROW-1,
  1387. X        NROW-1,
  1388. X        NCOL,
  1389. X        NCOL,
  1390. X    MARGIN,
  1391. X    SCRSIZ,
  1392. X    NPAUSE,
  1393. X        h110open,
  1394. X        h110close,
  1395. X    h110kopen,
  1396. X    h110kclose,
  1397. X        ttgetc,
  1398. X        ttputc,
  1399. X        ttflush,
  1400. X        h110move,
  1401. X        h110eeol,
  1402. X        h110eeop,
  1403. X        h110beep,
  1404. X    h110rev,
  1405. X    h110cres
  1406. #if    COLOR
  1407. X    , h110fcol,
  1408. X    h110bcol
  1409. #endif
  1410. };
  1411. X
  1412. #if    COLOR
  1413. h110fcol(color)        /* set the current output color */
  1414. X
  1415. int color;    /* color to set */
  1416. X
  1417. {
  1418. X    if (color == cfcolor)
  1419. X        return;
  1420. X    ttputc(ESC);
  1421. X    ttputc('[');
  1422. X    h110parm(color+30);
  1423. X    ttputc('m');
  1424. X    cfcolor = color;
  1425. }
  1426. X
  1427. h110bcol(color)        /* set the current background color */
  1428. X
  1429. int color;    /* color to set */
  1430. X
  1431. {
  1432. X    if (color == cbcolor)
  1433. X        return;
  1434. X    ttputc(ESC);
  1435. X    ttputc('[');
  1436. X    h110parm(color+40);
  1437. X    ttputc('m');
  1438. X        cbcolor = color;
  1439. }
  1440. #endif
  1441. X
  1442. h110move(row, col)
  1443. {
  1444. X        ttputc(ESC);
  1445. X        ttputc('[');
  1446. X        h110parm(row+1);
  1447. X        ttputc(';');
  1448. X        h110parm(col+1);
  1449. X        ttputc('H');
  1450. }
  1451. X
  1452. h110eeol()
  1453. {
  1454. X        ttputc(ESC);
  1455. X        ttputc('[');
  1456. X    ttputc('0');
  1457. X        ttputc('K');
  1458. }
  1459. X
  1460. h110eeop()
  1461. {
  1462. #if    COLOR
  1463. X    h110fcol(gfcolor);
  1464. X    h110bcol(gbcolor);
  1465. #endif
  1466. X        ttputc(ESC);
  1467. X        ttputc('[');
  1468. X    ttputc('0');
  1469. X        ttputc('J');
  1470. }
  1471. X
  1472. h110rev(state)        /* change reverse video state */
  1473. X
  1474. int state;    /* TRUE = reverse, FALSE = normal */
  1475. X
  1476. {
  1477. #if    COLOR
  1478. X    int ftmp, btmp;        /* temporaries for colors */
  1479. #endif
  1480. X
  1481. X    ttputc(ESC);
  1482. X    ttputc('[');
  1483. X    ttputc(state ? '7': '0');
  1484. X    ttputc('m');
  1485. #if    COLOR
  1486. X    if (state == FALSE) {
  1487. X        ftmp = cfcolor;
  1488. X        btmp = cbcolor;
  1489. X        cfcolor = -1;
  1490. X        cbcolor = -1;
  1491. X        h110fcol(ftmp);
  1492. X        h110bcol(btmp);
  1493. X    }
  1494. #endif
  1495. }
  1496. X
  1497. h110cres()    /* change screen resolution */
  1498. X
  1499. {
  1500. X    return(TRUE);
  1501. }
  1502. X
  1503. spal()        /* change pallette register */
  1504. X
  1505. {
  1506. X    /*   not here */
  1507. }
  1508. X
  1509. h110beep()
  1510. {
  1511. X        ttputc(BEL);
  1512. X        ttflush();
  1513. }
  1514. X
  1515. h110parm(n)
  1516. register int    n;
  1517. {
  1518. X        register int q,r;
  1519. X
  1520. X        q = n/10;
  1521. X        if (q != 0) {
  1522. X        r = q/10;
  1523. X        if (r != 0) {
  1524. X            ttputc((r%10)+'0');
  1525. X        }
  1526. X        ttputc((q%10) + '0');
  1527. X        }
  1528. X        ttputc((n%10) + '0');
  1529. }
  1530. X
  1531. h110open()
  1532. {
  1533. X    strcpy(sres, "15LINE");
  1534. X    revexist = TRUE;
  1535. X        ttopen();
  1536. }
  1537. X
  1538. h110close()
  1539. X
  1540. {
  1541. #if    COLOR
  1542. X    h110fcol(7);
  1543. X    h110bcol(0);
  1544. #endif
  1545. X    ttclose();
  1546. }
  1547. X
  1548. h110kopen()
  1549. X
  1550. {
  1551. }
  1552. X
  1553. h110kclose()
  1554. X
  1555. {
  1556. }
  1557. X
  1558. #if    FLABEL
  1559. fnclabel(f, n)        /* label a function key */
  1560. X
  1561. int f,n;    /* default flag, numeric argument [unused] */
  1562. X
  1563. {
  1564. X    /* on machines with no function keys...don't bother */
  1565. X    return(TRUE);
  1566. }
  1567. #endif
  1568. #else
  1569. h110hello()
  1570. {
  1571. }
  1572. #endif
  1573. SHAR_EOF
  1574. chmod 0444 hp110.c ||
  1575. echo 'restore of hp110.c failed'
  1576. Wc_c="`wc -c < 'hp110.c'`"
  1577. test 3750 -eq "$Wc_c" ||
  1578.     echo 'hp110.c: original size 3750, current size' "$Wc_c"
  1579. # ============= hp150.c ==============
  1580. echo 'x - extracting hp150.c (Text)'
  1581. sed 's/^X//' << 'SHAR_EOF' > 'hp150.c' &&
  1582. /*
  1583. X * The routines in this file provide support for HP150 screens
  1584. X * and routines to access the Keyboard through KEYCODE mode.
  1585. X * It compiles into nothing if not an HP150 screen device.
  1586. X * added by Daniel Lawrence
  1587. X */
  1588. X
  1589. #define    termdef    1            /* don't define "term" external */
  1590. X
  1591. #include        <stdio.h>
  1592. #include        "estruct.h"
  1593. #include    "edef.h"
  1594. X
  1595. #if     HP150
  1596. X
  1597. #define NROW    24                      /* Screen size.                 */
  1598. #define NCOL    80                      /* Edit if you want to.         */
  1599. #define    MARGIN    8            /* size of minimim margin and    */
  1600. #define    SCRSIZ    64            /* scroll size for extended lines */
  1601. #define    NPAUSE    15            /* # times thru update to pause */
  1602. #define BEL     0x07                    /* BEL character.               */
  1603. #define ESC     0x1B                    /* ESC character.               */
  1604. X
  1605. extern  int     openhp();               /* Forward references.          */
  1606. extern  int     ttgetc();
  1607. extern  int     ttputc();
  1608. extern  int     ttflush();
  1609. extern    int    hpflush();
  1610. extern  int     closehp();
  1611. extern    int    hp15kopen();
  1612. extern    int    hp15kclose();
  1613. extern  int     hp15move();
  1614. extern  int     hp15eeol();
  1615. extern  int     hp15eeop();
  1616. extern  int     hp15beep();
  1617. extern    int    gethpkey();
  1618. extern    int    hp15rev();
  1619. extern    int    hp15cres();
  1620. #if    COLOR
  1621. extern    int    hp15fcol();
  1622. extern    int    hp15bcol();
  1623. #endif
  1624. X
  1625. /* weird to ascii translation table */
  1626. X
  1627. char trans[][2] = {
  1628. X    0x24,    9,    /* tab */
  1629. X    0x25,    13,    /* ret */
  1630. X    0x27,    8,    /* backspace */
  1631. X    0x30,    48,    /* zero */
  1632. X    0x31,    49,    /* one */
  1633. X    0x32,    50,    /* two */
  1634. X    0x33,    51,    /* three */
  1635. X    0x34,    52,    /* four */
  1636. X    0x35,    53,    /* five */
  1637. X    0x36,    54,    /* six */
  1638. X    0x37,    55,    /* seven */
  1639. X    0x38,    56,    /* eight */
  1640. X    0x39,    57,    /* nine */
  1641. X    0x50,    13,    /* enter */
  1642. X    0x54,    27,    /* break -> ESC */
  1643. X    0x55,    27,    /* esc */
  1644. X    0x58,    24,    /* stop -> ^X */
  1645. X    0x70,    45,    /* N-minus */
  1646. X    0x71,    42,    /* N-asterisk */
  1647. X    0x72,    43,    /* N-plus */
  1648. X    0x73,    47,    /* N-slash */
  1649. X    0x74,    44,    /* N-comma */
  1650. X    0x75,    13,    /* N-enter */
  1651. X    0x76,    9,    /* N-tab */
  1652. X    0x77,    46    /* N-period */
  1653. };
  1654. X
  1655. #define NTRANS    sizeof(trans) / 2
  1656. X
  1657. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  1658. int capslock = 0;    /* caps lock flag */
  1659. X
  1660. /*
  1661. X * Standard terminal interface dispatch table. Most of the fields point into
  1662. X * "termio" code.
  1663. X */
  1664. TERM    term    = {
  1665. X    NROW-1,
  1666. X        NROW-1,
  1667. X        NCOL,
  1668. X        NCOL,
  1669. X    MARGIN,
  1670. X    SCRSIZ,
  1671. X    NPAUSE,
  1672. X    openhp,
  1673. X        closehp,
  1674. X    hp15kopen,
  1675. X    hp15kclose,
  1676. X    gethpkey,
  1677. X        ttputc,
  1678. X        hpflush,
  1679. X        hp15move,
  1680. X        hp15eeol,
  1681. X        hp15eeop,
  1682. X        hp15beep,
  1683. X        hp15rev,
  1684. X        hp15cres
  1685. #if    COLOR
  1686. X    , hp15fcol,
  1687. X    hp15bcol
  1688. #endif
  1689. };
  1690. X
  1691. hp15move(row, col)
  1692. {
  1693. X        ttputc(ESC);
  1694. X        ttputc('&');
  1695. X        ttputc('a');
  1696. X        hp15parm(col);
  1697. X        ttputc('c');
  1698. X        hp15parm(row);
  1699. X        ttputc('R');
  1700. }
  1701. X
  1702. hpflush()
  1703. X
  1704. {
  1705. X
  1706. }
  1707. X
  1708. hp15eeol()
  1709. {
  1710. X        ttputc(ESC);
  1711. X        ttputc('K');
  1712. }
  1713. X
  1714. hp15eeop()
  1715. {
  1716. X        ttputc(ESC);
  1717. X        ttputc('J');
  1718. }
  1719. X
  1720. hp15rev(status)        /* change the reverse video status */
  1721. X
  1722. int status;    /* TRUE = on, FALSE = off */
  1723. X
  1724. {
  1725. X    ttputc(ESC);
  1726. X    ttputc('&');
  1727. X    ttputc('d');
  1728. X    ttputc((status != FALSE) ? 'B': '@');
  1729. }
  1730. X
  1731. hp15cres()    /* change screen resolution */
  1732. X
  1733. {
  1734. X    return(TRUE);
  1735. }
  1736. X
  1737. spal()        /* change pallette register */
  1738. X
  1739. {
  1740. X    /*   not here */
  1741. }
  1742. X
  1743. hp15beep()
  1744. {
  1745. X        ttputc(BEL);
  1746. X        ttflush();
  1747. }
  1748. X
  1749. hp15parm(n)
  1750. register int    n;
  1751. {
  1752. X        register int    q;
  1753. X
  1754. X        q = n/10;
  1755. X        if (q != 0)
  1756. X                hp15parm(q);
  1757. X        ttputc((n%10) + '0');
  1758. }
  1759. X
  1760. #if    COLOR
  1761. hp15fcol()    /* we really can't do colors here, so just ignore it */
  1762. {
  1763. }
  1764. X
  1765. hp15bcol()    /* we really can't do colors here, so just ignore it */
  1766. {
  1767. }
  1768. #endif
  1769. X
  1770. gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  1771. X
  1772. {
  1773. X    static int keepflag = 0;    /* kept ahead char flag */
  1774. X    static int keepchar = 0;    /* kept ehead flag */
  1775. X    int c;
  1776. X    int devid;            /* device ID */
  1777. X    int ctype;            /* type of character gotten */
  1778. X    int shiftb;            /* state of shift keys */
  1779. X    int i;
  1780. X    
  1781. X    /* if we are in an extended char sequence, finish it */
  1782. X    if (keepflag != 0) {
  1783. X        keepflag = 0;
  1784. X        return(keepchar);
  1785. X    }
  1786. X
  1787. X    /* grab the next 4 char sequence */
  1788. next:    shiftb = ttgetc();
  1789. X    devid = ttgetc();
  1790. X    c = ttgetc();
  1791. X    ttgetc();        /* skip null byte */
  1792. X    
  1793. X    /* make sure we are from the keyboard */
  1794. X    if (devid != 192)
  1795. X        goto next;
  1796. X
  1797. X    /* if normal ascii, return it */
  1798. X    if ((shiftb & 0x80) == 0) {
  1799. X        if (capslock && c >= 'a' && c <= 'z')
  1800. X            c -= 32;
  1801. X        return(c);
  1802. X    }
  1803. X
  1804. X    /* check specifically for the caps lock key */
  1805. X    if (c == 0x56) {
  1806. X        capslock = ~capslock;
  1807. X        goto next;
  1808. X    }
  1809. X
  1810. X    /* check to see if it needs translation */
  1811. X    for (i=0; i < NTRANS; i++)
  1812. X        if (trans[i][0] == c)
  1813. X            return((int)trans[i][1]);
  1814. X
  1815. X    /* other wise, shove it in the keep char and return the leadin code */
  1816. X    keepchar = c;
  1817. X    keepflag = 1;
  1818. X    return(0);
  1819. }
  1820. X
  1821. openhp()        /* open the HP150 screen for input */
  1822. X
  1823. {
  1824. X    strcpy(sres, "NORMAL");
  1825. X    revexist = TRUE;
  1826. }
  1827. X
  1828. closehp()        /* close the HP150 screen for input */
  1829. X
  1830. {
  1831. }
  1832. X
  1833. hp15kopen()        /* open the HP150 keyboard for input */
  1834. X
  1835. {
  1836. X    /* define key charectoristics with AGIOS call (0, 40) */
  1837. X    defkey();
  1838. X
  1839. X    /* Turn on RAW mode with MSDOS call 44h */
  1840. X    rawon();
  1841. X
  1842. X    /* Turn off Control-C checking  MS-DOS 33h */
  1843. X    ckeyoff();
  1844. X
  1845. X    /* Turn on keycode mode with AGIOS call (0,43) */
  1846. X    keycon();
  1847. X
  1848. X    /* display the application softkey labels */
  1849. X    dsplbls();
  1850. }
  1851. X
  1852. hp15kclose()        /* close the HP150 keyboard for input */
  1853. X
  1854. {
  1855. X    /* define key charectoristics with AGIOS call (0, 40) */
  1856. X    undefkey();
  1857. X    
  1858. X    /* Turn off RAW mode with MSDOS call 44h */
  1859. X    rawoff();
  1860. X
  1861. X    /* Turn on Control-C checking  MS-DOS 33h */
  1862. X    ckeyon();
  1863. X
  1864. X    /* Turn off keycode mode with AGIOS call (0,43) */
  1865. X    keycoff();
  1866. }
  1867. X
  1868. rawon()        /* put the HP150 keyboard into RAW mode */
  1869. X
  1870. {
  1871. X    /* get the IO control info */
  1872. X
  1873. X    r.x.ax = 0x4400;    /* IO ctrl get device information */
  1874. X    r.x.bx = 0x0001;    /* File handle; 1 for console */
  1875. X    intdos(&r, &r);        /* go fer it */
  1876. X
  1877. X    r.h.dh = 0;        /* clear high byte for put */
  1878. X    r.h.dl |= 0x20;        /* set raw bit */
  1879. X
  1880. X    /* and put it back */
  1881. X
  1882. X    r.x.ax = 0x4401;    /* IO ctrl put device information */
  1883. X    r.x.bx = 0x0001;    /* File handle; 1 for console */
  1884. X    intdos(&r, &r);        /* go fer it */
  1885. }
  1886. X
  1887. rawoff()    /* put the HP150 keyboard into COOKED mode */
  1888. X
  1889. {
  1890. X    /* get the IO control info */
  1891. X
  1892. X    r.x.ax = 0x4400;    /* IO ctrl get device information */
  1893. X    r.x.bx = 0x0001;    /* File handle; 1 for console */
  1894. X    intdos(&r, &r);        /* go fer it */
  1895. X
  1896. X    r.h.dh = 0;        /* clear high byte for put */
  1897. X    r.h.dl &= 0xdf;        /* set raw bit */
  1898. X
  1899. X    /* and put it back */
  1900. X
  1901. X    r.x.ax = 0x4401;    /* IO ctrl put device information */
  1902. X    r.x.bx = 0x0001;    /* File handle; 1 for console */
  1903. X    intdos(&r, &r);        /* go fer it */
  1904. }
  1905. X
  1906. X
  1907. ckeyoff()    /* turn control-C trapping off */
  1908. X
  1909. {
  1910. X    r.h.ah = 0x33;    /* ctrl-break check */
  1911. X    r.h.al = 1;    /* set the state of the ctrl-break check */
  1912. X    r.h.dl = 0;    /* turn it off */
  1913. X    intdos(&r, &r);
  1914. }
  1915. X
  1916. ckeyon()    /* turn control-C trapping on */
  1917. X
  1918. {
  1919. X    r.h.ah = 0x33;    /* ctrl-break check */
  1920. X    r.h.al = 1;    /* set the state of the ctrl-break check */
  1921. X    r.h.dl = 1;    /* turn it on */
  1922. X    intdos(&r, &r);
  1923. }
  1924. X
  1925. #ifdef    unsigned
  1926. #undef    unsigned
  1927. #endif
  1928. X
  1929. agios(buf, len)    /* perform an AGIOS call */
  1930. X
  1931. char *buf;    /* sequence of bytes in command */
  1932. int len;    /* length of command in bytes */
  1933. X
  1934. {
  1935. X    r.x.ax = 0x4403;    /* I/O ctrl write */
  1936. X    r.x.bx = 1;        /* console handle */
  1937. X    r.x.cx = len;        /* buffer length */
  1938. X    r.x.dx = (unsigned)buf;    /* buffer address */
  1939. X    return(intdos(&r, &r));    /* do it */
  1940. }
  1941. X
  1942. keycon()    /* turn keycode mode on */
  1943. X
  1944. {
  1945. X    static char cmd[] = {43, 0, 1};
  1946. X
  1947. X    return(agios(&cmd[0], 3));
  1948. }
  1949. X
  1950. keycoff()    /* turn keycode mode off */
  1951. X
  1952. {
  1953. X    static char cmd[] = {43, 0, 0};
  1954. X
  1955. X    return(agios(&cmd[0], 3));
  1956. }
  1957. X
  1958. defkey()    /* change all special keys to intercept mode */
  1959. X
  1960. {
  1961. X    static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  1962. X
  1963. X    return(agios(&cmd[0], 6));
  1964. }
  1965. X
  1966. undefkey()    /* change all special keys to intercept mode */
  1967. X
  1968. {
  1969. X    static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  1970. X
  1971. X    return(agios(&cmd[0], 6));
  1972. }
  1973. X
  1974. dsplbls()    /* display the application softkey labels on the screen */
  1975. X
  1976. {
  1977. X    static char cmd[] = {11, 0};
  1978. X
  1979. X    return(agios(&cmd[0], 2));
  1980. }
  1981. X
  1982. #if    FLABEL
  1983. fnclabel(f, n)        /* label a function key */
  1984. X
  1985. int f,n;    /* default flag, numeric argument */
  1986. X
  1987. {
  1988. X    register int status;    /* return status */
  1989. X    register int i;        /* loop index */
  1990. X    char lbl[17];    /* returned label contents */
  1991. X    /* AGIOS command buffer */
  1992. X    static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
  1993. X    /*                   code  key#  ptr to      top    bottom
  1994. X                                     label string  attribute */
  1995. X    union {        /* union to cast ptr into AGIOS arg string */
  1996. X        char *ptr;    /* pointer to arg string */
  1997. X        char cstr[4];
  1998. X    } ptru;
  1999. X
  2000. X    /* must have a numeric argument */
  2001. X    if (f == FALSE) {
  2002. X        mlwrite("%Need function key number");
  2003. X        return(FALSE);
  2004. X    }
  2005. X
  2006. X    /* and it must be a legal key number */
  2007. X    if (n < 1 || n > 8) {
  2008. X        mlwrite("%Function key number out of range");
  2009. X        return(FALSE);
  2010. X    }
  2011. X
  2012. X    /* get the string to send */
  2013. X    lbl[0] = 0;
  2014. X    status = mlreply("Label contents: ", &lbl[0], 17);
  2015. X    if (status != TRUE)
  2016. X        return(status);
  2017. X
  2018. X    /* pad the label out */
  2019. X    for (i=0; i < 17; i++) {
  2020. X        if (lbl[i] == 0)
  2021. X            break;
  2022. X    }
  2023. X    for (; i < 16; i++)
  2024. X        lbl[i] = ' ';
  2025. X    lbl[16] = 0;
  2026. X
  2027. X    /* set up the parameters */
  2028. X    cmd[2] = n;            /* function key number */
  2029. X    ptru.ptr = &lbl[0];        /* set up pointer to label string */
  2030. force:    cmd[4] = ptru.cstr[0];
  2031. X    cmd[5] = ptru.cstr[1];
  2032. X    cmd[6] = ptru.cstr[2];
  2033. X    cmd[7] = ptru.cstr[3];
  2034. X
  2035. X    /* and send it out */
  2036. X    agios(&cmd[0], 12);
  2037. X    return(TRUE);
  2038. }
  2039. #endif
  2040. #else
  2041. X
  2042. h15hello()
  2043. X
  2044. {
  2045. }
  2046. #endif
  2047. SHAR_EOF
  2048. chmod 0444 hp150.c ||
  2049. echo 'restore of hp150.c failed'
  2050. Wc_c="`wc -c < 'hp150.c'`"
  2051. test 9245 -eq "$Wc_c" ||
  2052.     echo 'hp150.c: original size 9245, current size' "$Wc_c"
  2053. # ============= ibmpc.c ==============
  2054. echo 'x - extracting ibmpc.c (Text)'
  2055. sed 's/^X//' << 'SHAR_EOF' > 'ibmpc.c' &&
  2056. /*
  2057. X * The routines in this file provide support for the IBM-PC and other
  2058. X * compatible terminals. It goes directly to the graphics RAM to do
  2059. X * screen output. It compiles into nothing if not an IBM-PC driver
  2060. X * Supported monitor cards include CGA, MONO and EGA.
  2061. X */
  2062. X
  2063. #define    termdef    1            /* don't define "term" external */
  2064. X
  2065. #include        <stdio.h>
  2066. #include    "estruct.h"
  2067. #include        "edef.h"
  2068. X
  2069. #if     IBMPC
  2070. #define NROW    43            /* Max Screen size.        */
  2071. #define NCOL    80                      /* Edit if you want to.         */
  2072. #define    MARGIN    8            /* size of minimim margin and    */
  2073. #define    SCRSIZ    64            /* scroll size for extended lines */
  2074. #define    NPAUSE    200            /* # times thru update to pause */
  2075. #define BEL     0x07                    /* BEL character.               */
  2076. #define ESC     0x1B                    /* ESC character.               */
  2077. #define    SPACE    32            /* space character        */
  2078. X
  2079. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  2080. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  2081. #define SCADE    0xb8000000L        /* EGA address of screen RAM    */
  2082. X
  2083. #define MONOCRSR 0x0B0D            /* monochrome cursor        */
  2084. #define CGACRSR 0x0607            /* CGA cursor            */
  2085. #define EGACRSR 0x0709            /* EGA cursor            */
  2086. X
  2087. #define    CDCGA    0            /* color graphics card        */
  2088. #define    CDMONO    1            /* monochrome text card        */
  2089. #define    CDEGA    2            /* EGA color adapter        */
  2090. #define    CDSENSE    9            /* detect the card type        */
  2091. X
  2092. #define NDRIVE    3            /* number of screen drivers    */
  2093. X
  2094. int dtype = -1;                /* current display type        */
  2095. char drvname[][8] = {            /* screen resolution names    */
  2096. X    "CGA", "MONO", "EGA"
  2097. };
  2098. long scadd;                /* address of screen ram    */
  2099. int *scptr[NROW];            /* pointer to screen lines    */
  2100. unsigned int sline[NCOL];        /* screen line image        */
  2101. int egaexist = FALSE;            /* is an EGA card available?    */
  2102. extern union REGS rg;            /* cpu register for use of DOS calls */
  2103. X
  2104. extern  int     ttopen();               /* Forward references.          */
  2105. extern  int     ttgetc();
  2106. extern  int     ttputc();
  2107. extern  int     ttflush();
  2108. extern  int     ttclose();
  2109. extern  int     ibmmove();
  2110. extern  int     ibmeeol();
  2111. extern  int     ibmeeop();
  2112. extern  int     ibmbeep();
  2113. extern  int     ibmopen();
  2114. extern    int    ibmrev();
  2115. extern    int    ibmcres();
  2116. extern    int    ibmclose();
  2117. extern    int    ibmputc();
  2118. extern    int    ibmkopen();
  2119. extern    int    ibmkclose();
  2120. X
  2121. #if    COLOR
  2122. extern    int    ibmfcol();
  2123. extern    int    ibmbcol();
  2124. X
  2125. int    cfcolor = -1;        /* current forground color */
  2126. int    cbcolor = -1;        /* current background color */
  2127. int    ctrans[] =        /* ansi to ibm color translation table */
  2128. X    {0, 4, 2, 6, 1, 5, 3, 7};
  2129. #endif
  2130. X
  2131. /*
  2132. X * Standard terminal interface dispatch table. Most of the fields point into
  2133. X * "termio" code.
  2134. X */
  2135. TERM    term    = {
  2136. X    NROW-1,
  2137. X        NROW-1,
  2138. X        NCOL,
  2139. X        NCOL,
  2140. X    MARGIN,
  2141. X    SCRSIZ,
  2142. X    NPAUSE,
  2143. X        ibmopen,
  2144. X        ibmclose,
  2145. X    ibmkopen,
  2146. X    ibmkclose,
  2147. X        ttgetc,
  2148. X    ibmputc,
  2149. X        ttflush,
  2150. X        ibmmove,
  2151. X        ibmeeol,
  2152. X        ibmeeop,
  2153. X        ibmbeep,
  2154. X    ibmrev,
  2155. X    ibmcres
  2156. #if    COLOR
  2157. X    , ibmfcol,
  2158. X    ibmbcol
  2159. #endif
  2160. };
  2161. X
  2162. #if    COLOR
  2163. ibmfcol(color)        /* set the current output color */
  2164. X
  2165. int color;    /* color to set */
  2166. X
  2167. {
  2168. X    cfcolor = ctrans[color];
  2169. }
  2170. X
  2171. ibmbcol(color)        /* set the current background color */
  2172. X
  2173. int color;    /* color to set */
  2174. X
  2175. {
  2176. X        cbcolor = ctrans[color];
  2177. }
  2178. #endif
  2179. X
  2180. ibmmove(row, col)
  2181. {
  2182. X    rg.h.ah = 2;        /* set cursor position function code */
  2183. X    rg.h.dl = col;
  2184. X    rg.h.dh = row;
  2185. X    rg.h.bh = 0;        /* set screen page number */
  2186. X    int86(0x10, &rg, &rg);
  2187. }
  2188. X
  2189. ibmeeol()    /* erase to the end of the line */
  2190. X
  2191. {
  2192. X    unsigned int attr;    /* attribute byte mask to place in RAM */
  2193. X    unsigned int *lnptr;    /* pointer to the destination line */
  2194. X    int i;
  2195. X    int ccol;    /* current column cursor lives */
  2196. X    int crow;    /*       row    */
  2197. X
  2198. X    /* find the current cursor position */
  2199. X    rg.h.ah = 3;        /* read cursor position function code */
  2200. X    rg.h.bh = 0;        /* current video page */
  2201. X    int86(0x10, &rg, &rg);
  2202. X    ccol = rg.h.dl;        /* record current column */
  2203. X    crow = rg.h.dh;        /* and row */
  2204. X
  2205. X    /* build the attribute byte and setup the screen pointer */
  2206. #if    COLOR
  2207. X    if (dtype != CDMONO)
  2208. X        attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  2209. X    else
  2210. X        attr = 0x0700;
  2211. #else
  2212. X    attr = 0x0700;
  2213. #endif
  2214. X    lnptr = &sline[0];
  2215. X    for (i=0; i < term.t_ncol; i++)
  2216. X        *lnptr++ = SPACE | attr;
  2217. X
  2218. X    if (flickcode && (dtype == CDCGA)) {
  2219. X        /* wait for vertical retrace to be off */
  2220. X        while ((inp(0x3da) & 8))
  2221. X            ;
  2222. X    
  2223. X        /* and to be back on */
  2224. X        while ((inp(0x3da) & 8) == 0)
  2225. X            ;
  2226. X    }            
  2227. X
  2228. X    /* and send the string out */
  2229. X    movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
  2230. X
  2231. }
  2232. X
  2233. ibmputc(ch)    /* put a character at the current position in the
  2234. X           current colors */
  2235. X
  2236. int ch;
  2237. X
  2238. {
  2239. X    rg.h.ah = 14;        /* write char to screen with current attrs */
  2240. X    rg.h.al = ch;
  2241. #if    COLOR
  2242. X    if (dtype != CDMONO)
  2243. X        rg.h.bl = cfcolor;
  2244. X    else
  2245. X        rg.h.bl = 0x07;
  2246. #else
  2247. X    rg.h.bl = 0x07;
  2248. #endif
  2249. X    int86(0x10, &rg, &rg);
  2250. }
  2251. X
  2252. ibmeeop()
  2253. {
  2254. X    int attr;        /* attribute to fill screen with */
  2255. X
  2256. X    rg.h.ah = 6;        /* scroll page up function code */
  2257. X    rg.h.al = 0;        /* # lines to scroll (clear it) */
  2258. X    rg.x.cx = 0;        /* upper left corner of scroll */
  2259. X    rg.x.dx = (term.t_nrow << 8) | (term.t_ncol - 1);
  2260. X                /* lower right corner of scroll */
  2261. #if    COLOR
  2262. X    if (dtype != CDMONO)
  2263. X        attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  2264. X    else
  2265. X        attr = 0;
  2266. #else
  2267. X    attr = 0;
  2268. #endif
  2269. X    rg.h.bh = attr;
  2270. X    int86(0x10, &rg, &rg);
  2271. }
  2272. X
  2273. ibmrev(state)        /* change reverse video state */
  2274. X
  2275. int state;    /* TRUE = reverse, FALSE = normal */
  2276. X
  2277. {
  2278. X    /* This never gets used under the IBM-PC driver */
  2279. }
  2280. X
  2281. ibmcres(res)    /* change screen resolution */
  2282. X
  2283. char *res;    /* resolution to change to */
  2284. X
  2285. {
  2286. X    int i;        /* index */
  2287. X
  2288. X    for (i = 0; i < NDRIVE; i++)
  2289. X        if (strcmp(res, drvname[i]) == 0) {
  2290. X            scinit(i);
  2291. X            return(TRUE);
  2292. X        }
  2293. X    return(FALSE);
  2294. }
  2295. X
  2296. spal()    /* reset the pallette registers */
  2297. X
  2298. {
  2299. X    /* nothin here now..... */
  2300. }
  2301. X
  2302. ibmbeep()
  2303. {
  2304. #if    MWC86
  2305. X    putcnb(BEL);
  2306. #else
  2307. X    bdos(6, BEL, 0);
  2308. #endif
  2309. }
  2310. X
  2311. ibmopen()
  2312. {
  2313. X    scinit(CDSENSE);
  2314. X    revexist = TRUE;
  2315. X        ttopen();
  2316. }
  2317. X
  2318. ibmclose()
  2319. X
  2320. {
  2321. #if    COLOR
  2322. X    ibmfcol(7);
  2323. X    ibmbcol(0);
  2324. #endif
  2325. X    /* if we had the EGA open... close it */
  2326. X    if (dtype == CDEGA)
  2327. X        egaclose();
  2328. X
  2329. X    ttclose();
  2330. }
  2331. X
  2332. ibmkopen()    /* open the keyboard */
  2333. X
  2334. {
  2335. }
  2336. X
  2337. ibmkclose()    /* close the keyboard */
  2338. X
  2339. {
  2340. }
  2341. X
  2342. scinit(type)    /* initialize the screen head pointers */
  2343. X
  2344. int type;    /* type of adapter to init for */
  2345. X
  2346. {
  2347. X    union {
  2348. X        long laddr;    /* long form of address */
  2349. X        int *paddr;    /* pointer form of address */
  2350. X    } addr;
  2351. X    int i;
  2352. X
  2353. X    /* if asked...find out what display is connected */
  2354. X    if (type == CDSENSE)
  2355. X        type = getboard();
  2356. X
  2357. X    /* if we have nothing to do....don't do it */
  2358. X    if (dtype == type)
  2359. X        return(TRUE);
  2360. X
  2361. X    /* if we try to switch to EGA and there is none, don't */
  2362. X    if (type == CDEGA && egaexist != TRUE)
  2363. X        return(FALSE);
  2364. X
  2365. X    /* if we had the EGA open... close it */
  2366. X    if (dtype == CDEGA)
  2367. X        egaclose();
  2368. X
  2369. X    /* and set up the various parameters as needed */
  2370. X    switch (type) {
  2371. X        case CDMONO:    /* Monochrome adapter */
  2372. X                scadd = SCADM;
  2373. X                newscreensize(25, term.t_ncol);
  2374. X                break;
  2375. X
  2376. X        case CDCGA:    /* Color graphics adapter */
  2377. X                scadd = SCADC;
  2378. X                newscreensize(25, term.t_ncol);
  2379. X                break;
  2380. X
  2381. X        case CDEGA:    /* Enhanced graphics adapter */
  2382. X                scadd = SCADE;
  2383. X                egaopen();
  2384. X                newscreensize(43, term.t_ncol);
  2385. X                break;
  2386. X    }
  2387. X
  2388. X    /* reset the $sres environment variable */
  2389. X    strcpy(sres, drvname[type]);
  2390. X    dtype = type;
  2391. X
  2392. X    /* initialize the screen pointer array */
  2393. X    for (i = 0; i < NROW; i++) {
  2394. X        addr.laddr = scadd + (long)(NCOL * i * 2);
  2395. X        scptr[i] = addr.paddr;
  2396. X    }
  2397. X    return(TRUE);
  2398. }
  2399. X
  2400. /* getboard:    Determine which type of display board is attached.
  2401. X        Current known types include:
  2402. X
  2403. X        CDMONO    Monochrome graphics adapter
  2404. X        CDCGA    Color Graphics Adapter
  2405. X        CDEGA    Extended graphics Adapter
  2406. */
  2407. X
  2408. /* getbaord:    Detect the current display adapter
  2409. X        if MONO        set to MONO
  2410. X           CGA        set to CGA    EGAexist = FALSE
  2411. X           EGA        set to CGA    EGAexist = TRUE
  2412. */
  2413. X
  2414. int getboard()
  2415. X
  2416. {
  2417. X    int type;    /* board type to return */
  2418. X
  2419. X    type = CDCGA;
  2420. X    int86(0x11, &rg, &rg);
  2421. X    if ((((rg.x.ax >> 4) & 3) == 3))
  2422. X        type = CDMONO;
  2423. X
  2424. X    /* test if EGA present */
  2425. X    rg.x.ax = 0x1200;
  2426. X    rg.x.bx = 0xff10;
  2427. X    int86(0x10,&rg, &rg);        /* If EGA, bh=0-1 and bl=0-3 */
  2428. X    egaexist = !(rg.x.bx & 0xfefc);    /* Yes, it's EGA */
  2429. X    return(type);
  2430. }
  2431. X
  2432. egaopen()    /* init the computer to work with the EGA */
  2433. X
  2434. {
  2435. X    /* put the beast into EGA 43 row mode */
  2436. X    rg.x.ax = 3;
  2437. X    int86(16, &rg, &rg);
  2438. X
  2439. X    rg.h.ah = 17;        /* set char. generator function code */
  2440. X    rg.h.al = 18;        /*  to 8 by 8 double dot ROM         */
  2441. X    rg.h.bl = 0;        /* block 0                           */
  2442. X    int86(16, &rg, &rg);
  2443. X
  2444. X    rg.h.ah = 18;        /* alternate select function code    */
  2445. X    rg.h.al = 0;        /* clear AL for no good reason       */
  2446. X    rg.h.bl = 32;        /* alt. print screen routine         */
  2447. X    int86(16, &rg, &rg);
  2448. X
  2449. X    rg.h.ah = 1;        /* set cursor size function code */
  2450. X    rg.x.cx = 0x0607;    /* turn cursor on code */
  2451. X    int86(0x10, &rg, &rg);
  2452. X
  2453. X    outp(0x3d4, 10);    /* video bios bug patch */
  2454. X    outp(0x3d5, 6);
  2455. }
  2456. X
  2457. egaclose()
  2458. X
  2459. {
  2460. X    /* put the beast into 80 column mode */
  2461. X    rg.x.ax = 3;
  2462. X    int86(16, &rg, &rg);
  2463. }
  2464. X
  2465. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  2466. X
  2467. int row;    /* row of screen to place outstr on */
  2468. char *outstr;    /* string to write out (must be term.t_ncol long) */
  2469. int forg;    /* forground color of string to write */
  2470. int bacg;    /* background color */
  2471. X
  2472. {
  2473. X    unsigned int attr;    /* attribute byte mask to place in RAM */
  2474. X    unsigned int *lnptr;    /* pointer to the destination line */
  2475. X    int i;
  2476. X
  2477. X    /* build the attribute byte and setup the screen pointer */
  2478. #if    COLOR
  2479. X    if (dtype != CDMONO)
  2480. X        attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  2481. X    else
  2482. X        attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  2483. #else
  2484. X    attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  2485. #endif
  2486. X    lnptr = &sline[0];
  2487. X    for (i=0; i<term.t_ncol; i++)
  2488. X        *lnptr++ = (outstr[i] & 255) | attr;
  2489. X
  2490. X    if (flickcode && (dtype == CDCGA)) {
  2491. X        /* wait for vertical retrace to be off */
  2492. X        while ((inp(0x3da) & 8))
  2493. X            ;
  2494. X    
  2495. X        /* and to be back on */
  2496. X        while ((inp(0x3da) & 8) == 0)
  2497. X            ;
  2498. X    }
  2499. X
  2500. X    /* and send the string out */
  2501. X    movmem(&sline[0], scptr[row],term.t_ncol*2);
  2502. }
  2503. X
  2504. #if    FLABEL
  2505. fnclabel(f, n)        /* label a function key */
  2506. X
  2507. int f,n;    /* default flag, numeric argument [unused] */
  2508. X
  2509. {
  2510. X    /* on machines with no function keys...don't bother */
  2511. X    return(TRUE);
  2512. }
  2513. #endif
  2514. #else
  2515. ibmhello()
  2516. {
  2517. }
  2518. #endif
  2519. X
  2520. SHAR_EOF
  2521. chmod 0444 ibmpc.c ||
  2522. echo 'restore of ibmpc.c failed'
  2523. Wc_c="`wc -c < 'ibmpc.c'`"
  2524. test 10074 -eq "$Wc_c" ||
  2525.     echo 'ibmpc.c: original size 10074, current size' "$Wc_c"
  2526. # ============= input.c ==============
  2527. echo 'x - extracting input.c (Text)'
  2528. sed 's/^X//' << 'SHAR_EOF' > 'input.c' &&
  2529. /*    INPUT:    Various input routines for MicroEMACS
  2530. X        written by Daniel Lawrence
  2531. X        5/9/86                        */
  2532. X
  2533. #include    <stdio.h>
  2534. #include    "estruct.h"
  2535. #include    "edef.h"
  2536. X
  2537. /*
  2538. X * Ask a yes or no question in the message line. Return either TRUE, FALSE, or
  2539. X * ABORT. The ABORT status is returned if the user bumps out of the question
  2540. X * with a ^G. Used any time a confirmation is required.
  2541. X */
  2542. X
  2543. mlyesno(prompt)
  2544. char *prompt;
  2545. {
  2546. X    char c;            /* input character */
  2547. X
  2548. X    for (;;) {
  2549. #if     NeWS
  2550. X        newsimmediateon() ;
  2551. X        mlwrite(,"%s [y/n]? ",prompt);
  2552. X        c = tgetc();        /* get the responce */
  2553. X        newsimmediateoff() ;
  2554. #else
  2555. X        mlwrite("%s [y/n]? ",prompt);
  2556. X        c = tgetc();        /* get the responce */
  2557. #endif
  2558. X
  2559. X        if (c == kcod2key(abortc))        /* Bail out! */
  2560. X            return(ABORT);
  2561. X
  2562. X        if (c=='y' || c=='Y')
  2563. X            return(TRUE);
  2564. X
  2565. X        if (c=='n' || c=='N')
  2566. X            return(FALSE);
  2567. X    }
  2568. }
  2569. X
  2570. /*
  2571. X * Write a prompt into the message line, then read back a response. Keep
  2572. X * track of the physical position of the cursor. If we are in a keyboard
  2573. SHAR_EOF
  2574. true || echo 'restore of input.c failed'
  2575. echo 'End of Vile part 7'
  2576. echo 'File input.c is continued in part 8'
  2577. echo 8 > _shar_seq_.tmp
  2578. exit 0
  2579. -- 
  2580.         paul fox, pgf@cayman.com, (617)494-1999
  2581.         Cayman Systems, 26 Landsdowne St., Cambridge, MA 02139
  2582.