home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / termio.c < prev    next >
Text File  |  1994-09-25  |  9KB  |  456 lines

  1. /*  termio.c   Terminal I/O support routines
  2.     Copyright (C) 1993  Boisy G. Pitre
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26.  
  27. #ifdef TERMCAP
  28. # ifndef BSDISH
  29. #  ifdef _OSK
  30. #   include <termcap.h>
  31. #  else
  32. #   include "ttydefs.h"
  33. #  endif
  34. # endif
  35.  
  36. #ifdef _OSK
  37. #define TCAPSLEN 2048
  38. #else
  39. #define TCAPSLEN 400                                /* CoCo */
  40. #endif
  41.  
  42. extern char *getenv();
  43. void ErEOLine();
  44. void curxy();
  45.  
  46. int nrows, ncolumns;
  47. static char tcapbuf[TCAPSLEN];
  48.  
  49. # ifdef _OSK
  50. char PC_,    /* pad character */
  51.      *BC,    /* cursor backspace */
  52.      *UP;    /* cursor up */
  53. short ospeed;
  54. # else
  55. char PC_;    /* rest are defined in termcap library */
  56. #ifdef BSDISH
  57. char *UP;
  58. #endif
  59. # endif
  60.  
  61. static char *CM,
  62.             *CL,
  63.             *DL,
  64.             *CE,
  65.             *CD,
  66.             *SO,
  67.             *SE,
  68.             *BL,
  69.             *VE,
  70.             *VI,
  71.             *CR;
  72.  
  73. # ifndef _OSK
  74. #  ifndef BSDISH
  75. #   include <os9.h>
  76.  
  77. char *crtbynam();
  78. char *crtbypth();
  79.  
  80. #   define LINESIZE 80
  81.  
  82. char *crtbynam(line, buffer)
  83. char *line, *buffer;
  84. {
  85.      char linebuff[LINESIZE],
  86.      int found = 0;                      /* indicates tty line was found */
  87.      register char  *workptr;
  88.      FILE * ttysfd;
  89.  
  90.      /* Open the TTYTYPE file, in either of three directories */
  91.      if ((ttysfd = fopen ("/r0/sys/ttytype", "r")) == NULL)
  92.           if ((ttysfd = fopen ("/r/sys/ttytype", "r")) == NULL)
  93.                ttysfd = fopen ("/dd/sys/ttytype", "r");
  94.  
  95.      /* Search through the TTYTYPE file for a match on this 'line' */
  96.  
  97.      if (ttysfd != NULL) {
  98. #ifdef DEBUG
  99.           fprintf (stderr, "File 'ttytype' was found and opened ok\n");
  100. #endif
  101.  
  102.           while (fgets (linebuff, LINESIZE, ttysfd) != NULL) {
  103.                if (workptr = index (linebuff, ' ')) {
  104.                     /* Terminate the LINE name */
  105.                     *workptr++ = '\0';
  106.  
  107.                     /* Index forward to the CRT name */
  108.                     workptr = skipbl (workptr);
  109.  
  110.                     if (strucmp (line, linebuff) == 0) {
  111.                          found++;
  112. #ifdef DEBUG
  113.      fprintf(stderr,"line %s was found in the file\n",line);
  114. #endif
  115.                          strcpy (buffer, workptr);
  116.                          for (workptr = buffer; (!isspace (*workptr)); workptr++) {
  117.                               /* do nothing */;
  118.                          }
  119.                          *workptr = '\0';
  120. #ifdef DEBUG
  121.      fprintf(stderr,"content of buffer [crtname] is: %s\n",buffer);
  122. #endif
  123.                          break;
  124.                       }
  125.                  }
  126.           }
  127.           fclose (ttysfd);
  128.  
  129.           if (found)
  130.                return (buffer);
  131.           else
  132.                return ((char *)NULL);
  133.      }
  134.      else
  135.           return ((char *)NULL);
  136. }
  137.  
  138.  
  139. /* Don't need this right now on CoCo?  --REB */
  140. #   ifdef ORIGCODE
  141. char *crtbypth (path, buffer)
  142. int path;
  143. char *buffer;
  144. {
  145.      char line[32];
  146.  
  147.      *line = '/';
  148.      getstat (SS_DEVNM, path, &line[1]);
  149.      strhcpy (line, line);
  150.      return (crtbynam (line, buffer));
  151. }
  152. #   endif
  153. #  endif
  154. # endif
  155.  
  156.  
  157.  
  158. void term (str)
  159. char *str;
  160. {
  161.     fputs (str, stderr);
  162.     exit(0);
  163. }
  164.  
  165.  
  166.  
  167. void init_term_cap()
  168. {
  169. # ifdef _OSK
  170.      register char *term_type;
  171. # else
  172. #  ifdef BSDISH
  173.      char *term_type;
  174.      char tt[32];
  175. #  else
  176.      char term_type[32];
  177. #  endif
  178. # endif
  179.  
  180. #ifdef _OSK
  181.      char tcbuf[2048];
  182. #else
  183.      char tcbuf[1024];                                   /* CoCo */
  184. #endif
  185.      char *ptr = tcapbuf;
  186.  
  187.      if ((term_type = getenv ("TERM")) == 0) {
  188.           term ("Environment variable TERM not defined!\n");
  189.      }
  190.  
  191. #  ifdef BSDISH
  192.      strcpy (tt, term_type);
  193.      term_type = tt;
  194. #  endif
  195.  
  196.      if (tgetent (tcbuf, term_type) <= 0) {
  197.           sprintf (tcbuf, "Unknown terminal type '%s'\n", term_type);
  198.           term (tcbuf);
  199.      }
  200.  
  201.      if ((CL = tgetstr ("cl", &ptr)) == NULL)
  202.           term ("'cl' capability not found\n");
  203.      if ((CM = tgetstr ("cm", &ptr)) == NULL)
  204.           term ("'cm' capability not found\n");
  205.      if ((CE = tgetstr ("ce", &ptr)) == NULL)
  206.           term ("'ce' capability not found\n");
  207.      if ((CD = tgetstr ("cd", &ptr)) == NULL)
  208.           term("'cd' capability not found\n");
  209.      if ((DL = tgetstr ("dl", &ptr)) == NULL) {
  210.           if ((CR = tgetstr("cr", &ptr)) == NULL)
  211.                CR = "\015";
  212.      }
  213.      UP = tgetstr ("up", &ptr);
  214.  
  215.      if ((SO = tgetstr ("so", &ptr)) != NULL)
  216.           SE = tgetstr ("se", &ptr);
  217.      else if ((SO = tgetstr ("md", &ptr)) != NULL)
  218.           SE = tgetstr ("me", &ptr);
  219.      else if ((SO = tgetstr ("us", &ptr)) != NULL)
  220.           SE = tgetstr ("ue", &ptr);
  221.      else
  222.           SE = NULL;
  223.  
  224.     VI = tgetstr ("vi", &ptr);
  225.     VE = tgetstr ("ve", &ptr);
  226.     BL = tgetstr ("bl", &ptr);
  227.  
  228.     if (ptr >= &tcapbuf[TCAPSLEN])
  229.          term ("Terminal description too big\n");
  230.  
  231.     nrows = tgetnum ("li");
  232.     ncolumns = tgetnum ("co");
  233.     
  234.     if (!nrows || !ncolumns) {
  235.          nrows = 80;
  236.          ncolumns = 24;
  237.     }
  238. }
  239. #endif
  240.  
  241. #ifdef BSDISH
  242. void out_char (c)
  243. char c;
  244. {
  245.      write (1, &c, 1);
  246. }
  247.  
  248.  
  249.  
  250. #define FPUTS(STR,FD) tputs(STR,1,out_char)
  251. #else
  252. #define FPUTS(STR,FD) fputs(STR,FD)
  253. #endif
  254.  
  255. void CurUp()
  256. {
  257. #ifdef TERMCAP
  258. # ifdef BSDISH
  259.      fflush (stdout);
  260. # endif
  261.      FPUTS (UP, stdout);
  262. #else
  263.      putchar ('\x09');
  264. #endif
  265.      fflush (stdout);
  266. }
  267.  
  268.  
  269.  
  270. void DelLine()
  271. {
  272. #ifdef TERMCAP
  273.      if (DL == NULL) {
  274. # ifdef BSDISH
  275.           fflush(stdout);
  276. # endif
  277.           FPUTS(CR, stdout);
  278.           FPUTS(CE, stdout);
  279.      }
  280.      else {
  281.           FPUTS (DL, stdout);
  282.      }
  283. #else
  284.      FPUTS ("\x1f\x31", stdout);
  285. #endif
  286.      fflush (stdout);
  287. }
  288.  
  289.  
  290.  
  291. void DelLines (startline, numlines)
  292. int startline, numlines;
  293. {
  294.      curxy (0, startline);
  295.      while (numlines--) {
  296.           ErEOLine();
  297.           putchar ('\n');
  298.      }
  299.      curxy (0, startline);
  300. }
  301.  
  302.  
  303.  
  304. void ErEOScrn()
  305. {
  306. #ifdef TERMCAP
  307. # ifdef BSDISH
  308.      fflush(stdout);
  309. # endif
  310.      FPUTS (CD, stdout);
  311. #else
  312.      putchar ('\x0B');
  313. #endif
  314.      fflush (stdout);
  315. }
  316.  
  317.  
  318.  
  319. void ErEOLine()
  320. {
  321. #ifdef TERMCAP
  322. # ifdef BSDISH
  323.      fflush(stdout);
  324. # endif
  325.      FPUTS (CE, stdout);
  326. #else
  327.      putchar ('\x04');
  328. #endif
  329.      fflush (stdout);
  330. }
  331.  
  332.  
  333.  
  334. void Bell()
  335. {
  336. #ifdef TERMCAP
  337.      if (BL) {
  338. #  ifdef BSDISH
  339.           fflush(stdout);
  340. # endif
  341.           FPUTS (BL, stdout);
  342.      }
  343. #else
  344.      putchar ('\x07');
  345. #endif
  346.      fflush (stdout);
  347. }
  348.  
  349.  
  350.  
  351. void ReVOn()
  352. {
  353. #ifdef TERMCAP
  354.      if (SO) {
  355. # ifdef BSDISH
  356.           fflush (stdout);
  357. # endif
  358.            FPUTS (SO, stdout);
  359.      }
  360.      else
  361.            fputs ("** ", stdout);
  362. #else
  363.      FPUTS ("\x1f\x20", stdout);
  364. #endif
  365.      fflush (stdout);
  366. }
  367.  
  368.  
  369.  
  370. void ReVOff()
  371. {
  372. #ifdef TERMCAP
  373.      if (SE) {
  374. # ifdef BSDISH
  375.           fflush (stdout);
  376. # endif
  377.           FPUTS (SE, stdout);
  378.      }
  379.      else
  380.           fputs (" **", stdout);
  381. #else
  382.      FPUTS ("\x1f\x21", stdout);
  383. #endif
  384.      fflush (stdout);
  385. }
  386.  
  387.  
  388.  
  389. void CurOn()
  390. {
  391. #ifdef TERMCAP
  392.      if (VE) {
  393. # ifdef BSDISH
  394.           fflush (stdout);
  395. # endif
  396.           FPUTS (VE, stdout);
  397.      }
  398. #else
  399.      FPUTS ("\x05\x21", stdout);
  400. #endif
  401.      fflush (stdout);
  402. }
  403.  
  404.  
  405.  
  406. void CurOff()
  407. {
  408. #ifdef TERMCAP
  409.      if (VI) {
  410. # ifdef BSDISH
  411.           fflush (stdout);
  412. # endif
  413.           FPUTS (VI, stdout);
  414.      }
  415. #else
  416.      FPUTS ("\x05\x20", stdout);
  417. #endif
  418.      fflush (stdout);
  419. }
  420.  
  421.  
  422.  
  423. void cls()
  424. {
  425. #ifdef TERMCAP
  426.      if (CL) {
  427. # ifdef BSDISH
  428.           fflush (stdout);
  429. # endif
  430.           FPUTS (CL, stdout);
  431.      }
  432. #else
  433.      putchar ('\x0c');
  434. #endif
  435.      fflush(stdout);
  436. }
  437.  
  438.  
  439.  
  440. void curxy (x, y)
  441. int x,y;
  442. {
  443. #ifdef TERMCAP
  444.      char *t;
  445.  
  446.      t = tgoto (CM, x, y);
  447. # ifdef BSDISH
  448.      fflush (stdout);
  449. # endif
  450.      FPUTS (t, stdout);
  451. #else
  452.      printf ("\x02%c%c", x+32, y+32);
  453. #endif
  454.      fflush (stdout);
  455. }
  456.