home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / c_news / 05 / listings / dumbterm.c next >
Text File  |  1988-03-05  |  5KB  |  110 lines

  1. /************************************************************************/ 
  2. /*                                                                      */ 
  3. /*                      DUMBTERM.C                                      */
  4. /*                                                                      */ 
  5. /*                                                                      */ 
  6. /*   A real stupid terminal program that uses FOSSIL for ALL I/O        */ 
  7. /*                                                                      */ 
  8. /************************************************************************/
  9. /*                                                                      */ 
  10. /*       For now, we will just hard code the port and baud rate.        */ 
  11. /*      You may want to modify this program so that they are            */
  12. /*           specified on the command line.                             */
  13. /*                                                                      */ 
  14. /************************************************************************/ 
  15.  
  16. #define   PORT 1                   /* 0==COM1, 1==COM2, 2==COM3, etc       */
  17. #define   BAUD 9600           /* Put real baud rate here                   */
  18.  
  19. int  local_echo=1;            /* Make this zero if the host echos          */
  20. int  ctrl_c_flag=0;           /* Non functional - just an example          */
  21.  
  22.  void
  23. term(port)
  24.  int port;
  25. {
  26.      int       commchar;
  27.      int       keychar;
  28.  
  29.      while (1) {
  30.  
  31. /************************************************************************/ 
  32. /*                                                                      */ 
  33. /*       Now, check the communications port for any received data       */ 
  34. /*                                                                      */ 
  35. /*          If you find one, display it to the screen using ANSI 3.64   */ 
  36. /*                            emulation through the FOSSIL.             */ 
  37. /*                                                                      */ 
  38. /************************************************************************/ 
  39.  
  40.           if (f_peek(port) != -1) {
  41.                commchar = f_rx(port) & 0x00ff;
  42.                f_wransi(commchar);
  43.                if (commchar == 13)               /* CR => CR/LF translation      
  44.     */
  45.                     f_wransi(10);
  46.           }
  47.  
  48. /************************************************************************/ 
  49. /*                                                                      */ 
  50. /*           Now, check the keyboard for a character. If one is there,  */ 
  51. /*           and it is not the ESCape key (we exit on the ESCape key),  */ 
  52. /*          transmit it to the FOSSIL function to send it to the remote */ 
  53. /*           system. Also note the CR => CR/LF translation in both the  */
  54. /*                       communications and keyboard handlers.          */ 
  55. /*                                                                      */ 
  56. /************************************************************************/ 
  57.  
  58.           if (f_keyrdnowait() != -1) {
  59.                keychar = f_keyrd() & 0x00ff;
  60.                if (keychar == 27)
  61.                     return;
  62.                if (local_echo) {
  63.                     f_wransi(keychar);
  64.                     if (keychar == 13)     /* CR => CR/LF translation */
  65.                          f_wransi(10);
  66.                }
  67.                f_tx(port,keychar);
  68.                if (keychar == 13)         /* CR => CR/LF translation */
  69.                     f_tx(port,10);
  70.           }
  71.      }
  72. }
  73.  
  74. main()
  75. {
  76.  
  77. /************************************************************************/ 
  78. /*                                                                      */ 
  79. /*           Initialize the FOSSIL and check the return value for the   */ 
  80. /*                      "magic" number which indicates success.         */ 
  81. /*                                                                      */ 
  82. /************************************************************************/ 
  83.  
  84.      if (f_init(PORT,0,&ctrl_c_flag) != 0x1954) {
  85.           printf("Could not initialize FOSSIL\n");
  86.           exit(0);
  87.      }
  88.      f_baud(PORT,BAUD);
  89.      f_dtr(PORT,1);
  90.      puts("DUMBTERM Ready\n");
  91.  
  92. /************************************************************************/ 
  93. /*                                                                      */ 
  94. /*                  Throw control to the dumb terminal function.        */ 
  95. /*                                                                      */  
  96. /************************************************************************/ 
  97.      
  98.      term(PORT);
  99.  
  100. /************************************************************************/ 
  101. /*                                                                      */ 
  102. /*    When we get back, drop the DTR signal and deinitialize the        */ 
  103. /*                                      port we used.                   */ 
  104. /*                                                                      */ 
  105. /************************************************************************/ 
  106.  
  107.      f_dtr(PORT,0);
  108.      f_deinit(PORT);
  109. }
  110.