home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / CO_HANDL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  4.0 KB  |  252 lines

  1. /*********************
  2.  *
  3.  *  co_handl.c - console handler functions.
  4.  *
  5.  *  Purpose: This file contains the functions to operate an ansi handler.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include <string.h>
  13. #include "blackstr.h"
  14. #include "co_head.h"
  15. #include "co_defs.h"
  16.  
  17. int (*co_puts_)(char *);
  18. char *(*co_gets_)(char *);
  19. int (*co_getc_)(void);
  20. int (*co_putc_)(char);
  21.  
  22.  
  23. /********
  24.  *
  25.  *  co_attr(attr) - set console attribute
  26.  *
  27.  **/
  28.  
  29. void co_attr(short int attr) /* attribute number */
  30. {
  31.     co_puts(co_set(SAT, (*co_attr_)[attr]));
  32. }
  33.  
  34.  
  35. /********
  36.  *
  37.  *  co_sattr(attr) -  return console attribute string
  38.  *
  39.  **/
  40.  
  41. char *co_sattr(short int attr)
  42. {
  43.     return(co_set(SAT, (*co_attr_)[attr]));
  44. }
  45.  
  46.  
  47. /********
  48.  *
  49.  *   co_mode(mode, fcolor, bcolor) - set the console mode
  50.  *
  51.  **/
  52.  
  53. void co_mode(int mode, short int fcolor, short int bcolor)
  54. {
  55.     co_puts(co_set(MOD, (*co_mode_)[mode]));
  56.     co_color(fcolor, bcolor);
  57. }
  58.  
  59.  
  60. /*********
  61.  *
  62.  *   co_curset(col, row) - set cursor to col,row
  63.  *
  64.  **/
  65.  
  66. void co_curset(short int col, short int row)
  67. {
  68.     char buf[4];
  69.     char *str;
  70.  
  71.     sprintf(buf,"%2d",col);
  72.     st_jusr(buf,2);                 /* make 2 ASCII digits  */
  73.     st_zlbl(buf);
  74.     str = co_set(CUP,buf);          /* do first value (col) */
  75.     sprintf(buf,"%2d",row);
  76.     st_jusr(buf,2);                 /* make 2 ascii digits  */
  77.     st_zlbl(buf);
  78.     st_bcpy(strchr(str,'#'),buf);   /* add col */
  79.     co_puts(str);
  80. }
  81.  
  82.  
  83. /*********
  84.  *
  85.  *   co_curget(col,row) - get cursor position
  86.  *
  87.  **/
  88.  
  89. void co_curget(short int *col, short int *row)
  90. {
  91.     char colstr[32];
  92.     int i,j;
  93.  
  94.     co_puts((char *)co_ctrl_[DSR]);
  95.     fgets(colstr,MAXLINE,stdin);
  96.     i = *(*co_ctrl_)[CPC];
  97.     j = *(*co_ctrl_)[CPR];
  98.     *col = colstr[i];       /* column position */
  99.     *row = colstr[j];       /* row position */
  100. }
  101.  
  102.  
  103. /********
  104.  *
  105.  *   co_init(console) - initialize to a console
  106.  *
  107.  **/
  108.  
  109. void co_init(short int console)
  110. {
  111.     co_attr_  = &co_attrptrs_[console];
  112.     co_color_ = &co_colrptrs_[console];
  113.     co_ctrl_  = &co_ctrlptrs_[console];
  114.     co_mode_  = &co_modeptrs_[console];
  115.     co_type_  = console;
  116. }
  117.  
  118.  
  119. /********
  120.  *
  121.  *   co_color(fcolor,bcolor) - set console foreround & background colors
  122.  *
  123.  **/
  124.  
  125. void co_color(short int fcolor, short int bcolor)
  126. {
  127.     co_puts(co_set(FCO,(*co_color_)[fcolor]));
  128.     co_puts(co_set(BCO,(*co_color_)[bcolor]));
  129. }
  130.  
  131.  
  132. /********
  133.  *
  134.  *   co_clr() - clear the console screen
  135.  *
  136.  **/
  137.  
  138. void co_clr(void)
  139. {
  140.     co_puts((*co_ctrl_)[ED]);
  141. }
  142.  
  143.  
  144. /********
  145.  *
  146.  *   co_eeol() - erase from cursor to end of line
  147.  *
  148.  **/
  149.  
  150. void co_eeol(void)
  151. {
  152.     co_puts((*co_ctrl_)[EL]);
  153. }
  154.  
  155.  
  156. /********
  157.  *
  158.  *   int co_putc(c) - put character to console
  159.  *
  160.  **/
  161.  
  162. int co_putc(char c)
  163. {
  164.     int i = fputc(c,stdout);
  165.  
  166.     fflush(stdout);
  167.     return(i);
  168. }
  169.  
  170.  
  171. /********
  172.  *
  173.  *   int co_puts(str) - put string to console
  174.  *
  175.  **/
  176.  
  177. int co_puts(char *str)
  178. {
  179.     int i = fputs(str,stdout);
  180.  
  181.     fflush(stdout);
  182.     return(i);
  183. }
  184.  
  185.  
  186. /********
  187.  *
  188.  *   int co_getc() - get character from console
  189.  *
  190.  **/
  191.  
  192. int co_getc(void)
  193. {
  194.     return(fgetc(stdin));
  195. }
  196.  
  197.  
  198. /********
  199.  *
  200.  *   co_gets(str) - get string from console
  201.  *
  202.  **/
  203.  
  204. char *co_gets(char *str)
  205. {
  206.     return(fgets(str,MAXLINE,stdin));
  207. }
  208.  
  209.  
  210. /********
  211.  *
  212.  *   co_type(type) - set the console type
  213.  *
  214.  **/
  215.  
  216. void co_type(int type)
  217. {
  218.     switch(type){
  219.       case ANSI:
  220.       co_puts_ = co_puts;
  221.       co_gets_ = co_gets;
  222.       co_putc_ = co_putc;
  223.       co_getc_ = co_getc;
  224.       break;
  225.  
  226.       case SCREEN:
  227.       case GRAPHIC:
  228.       default:
  229.       co_puts_ = sc_puts;
  230.       co_putc_ = sc_putc;
  231.       co_gets_ = kb_gets;
  232.       co_getc_ = kb_getc;
  233.       break;
  234.     };
  235. }
  236.  
  237.  
  238. /********
  239.  *
  240.  *   co_set(mod,val) - get console control string with value
  241.  *
  242.  **/
  243.  
  244. char *co_set(int mod, char *val)
  245. {
  246.     static char str[32];
  247.  
  248.     strcpy(str,(*co_ctrl_)[mod]);
  249.     st_bcpy(strchr(str,'#'),val);
  250.     return(str);
  251. }
  252.