home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * co_handl.c - console handler functions.
- *
- * Purpose: This file contains the functions to operate an ansi handler.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <string.h>
- #include "blackstr.h"
- #include "co_head.h"
- #include "co_defs.h"
-
- int (*co_puts_)(char *);
- char *(*co_gets_)(char *);
- int (*co_getc_)(void);
- int (*co_putc_)(char);
-
-
- /********
- *
- * co_attr(attr) - set console attribute
- *
- **/
-
- void co_attr(short int attr) /* attribute number */
- {
- co_puts(co_set(SAT, (*co_attr_)[attr]));
- }
-
-
- /********
- *
- * co_sattr(attr) - return console attribute string
- *
- **/
-
- char *co_sattr(short int attr)
- {
- return(co_set(SAT, (*co_attr_)[attr]));
- }
-
-
- /********
- *
- * co_mode(mode, fcolor, bcolor) - set the console mode
- *
- **/
-
- void co_mode(int mode, short int fcolor, short int bcolor)
- {
- co_puts(co_set(MOD, (*co_mode_)[mode]));
- co_color(fcolor, bcolor);
- }
-
-
- /*********
- *
- * co_curset(col, row) - set cursor to col,row
- *
- **/
-
- void co_curset(short int col, short int row)
- {
- char buf[4];
- char *str;
-
- sprintf(buf,"%2d",col);
- st_jusr(buf,2); /* make 2 ASCII digits */
- st_zlbl(buf);
- str = co_set(CUP,buf); /* do first value (col) */
- sprintf(buf,"%2d",row);
- st_jusr(buf,2); /* make 2 ascii digits */
- st_zlbl(buf);
- st_bcpy(strchr(str,'#'),buf); /* add col */
- co_puts(str);
- }
-
-
- /*********
- *
- * co_curget(col,row) - get cursor position
- *
- **/
-
- void co_curget(short int *col, short int *row)
- {
- char colstr[32];
- int i,j;
-
- co_puts((char *)co_ctrl_[DSR]);
- fgets(colstr,MAXLINE,stdin);
- i = *(*co_ctrl_)[CPC];
- j = *(*co_ctrl_)[CPR];
- *col = colstr[i]; /* column position */
- *row = colstr[j]; /* row position */
- }
-
-
- /********
- *
- * co_init(console) - initialize to a console
- *
- **/
-
- void co_init(short int console)
- {
- co_attr_ = &co_attrptrs_[console];
- co_color_ = &co_colrptrs_[console];
- co_ctrl_ = &co_ctrlptrs_[console];
- co_mode_ = &co_modeptrs_[console];
- co_type_ = console;
- }
-
-
- /********
- *
- * co_color(fcolor,bcolor) - set console foreround & background colors
- *
- **/
-
- void co_color(short int fcolor, short int bcolor)
- {
- co_puts(co_set(FCO,(*co_color_)[fcolor]));
- co_puts(co_set(BCO,(*co_color_)[bcolor]));
- }
-
-
- /********
- *
- * co_clr() - clear the console screen
- *
- **/
-
- void co_clr(void)
- {
- co_puts((*co_ctrl_)[ED]);
- }
-
-
- /********
- *
- * co_eeol() - erase from cursor to end of line
- *
- **/
-
- void co_eeol(void)
- {
- co_puts((*co_ctrl_)[EL]);
- }
-
-
- /********
- *
- * int co_putc(c) - put character to console
- *
- **/
-
- int co_putc(char c)
- {
- int i = fputc(c,stdout);
-
- fflush(stdout);
- return(i);
- }
-
-
- /********
- *
- * int co_puts(str) - put string to console
- *
- **/
-
- int co_puts(char *str)
- {
- int i = fputs(str,stdout);
-
- fflush(stdout);
- return(i);
- }
-
-
- /********
- *
- * int co_getc() - get character from console
- *
- **/
-
- int co_getc(void)
- {
- return(fgetc(stdin));
- }
-
-
- /********
- *
- * co_gets(str) - get string from console
- *
- **/
-
- char *co_gets(char *str)
- {
- return(fgets(str,MAXLINE,stdin));
- }
-
-
- /********
- *
- * co_type(type) - set the console type
- *
- **/
-
- void co_type(int type)
- {
- switch(type){
- case ANSI:
- co_puts_ = co_puts;
- co_gets_ = co_gets;
- co_putc_ = co_putc;
- co_getc_ = co_getc;
- break;
-
- case SCREEN:
- case GRAPHIC:
- default:
- co_puts_ = sc_puts;
- co_putc_ = sc_putc;
- co_gets_ = kb_gets;
- co_getc_ = kb_getc;
- break;
- };
- }
-
-
- /********
- *
- * co_set(mod,val) - get console control string with value
- *
- **/
-
- char *co_set(int mod, char *val)
- {
- static char str[32];
-
- strcpy(str,(*co_ctrl_)[mod]);
- st_bcpy(strchr(str,'#'),val);
- return(str);
- }
-