home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * tx_field.c - text display functions.
- *
- * Purpose: This file contains functions to display text in fields
- * and windows on the screen.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <stdlib.h>
- #include <string.h>
- #include "blackstr.h"
- #include "kb_head.h"
- #include "sc_head.h"
- #include "tx_head.h"
-
-
- /********
- *
- * tx_putf(fp) - put file to screen
- *
- **/
-
- int tx_putf(FILE *fp)
- {
- long *pgloc;
- int page,c;
-
- pgloc = (long*)calloc(100,sizeof(long));
- page = 0;
- pgloc[page] = 0;
- pgloc[++page] = tx_putfp(fp,0L); /* put first page */
- while((c = kb_getch()) != 0) {
- switch(c){
- case PG_DN:
- if(pgloc[page]>0) page++;
- break;
- case PG_UP:
- page--;
- if(page<0) page=0;
- break;
- case ESC:
- free(pgloc);
- return(ESC);
- }
- pgloc[page+1] = tx_putfp(fp,pgloc[page]);
- }
- return(NUL);
- }
-
-
- /********
- *
- * tx_putfp(fp,flpos) - put file page to screen
- *
- **/
-
- long tx_putfp(FILE *fp, long flpos)
- {
- char *lptr,line[MAX_ST];
-
- lptr = line;
- fseek(fp,flpos,0);
- while(fl_getl(line, fp)!=EOF) {
- if((lptr=tx_putl(line)) != NULL)
- return(ftell(fp)-strlen(lptr));
- }
- return(EOF);
- }
-
-
- /********
- *
- * tx_mesg(mesg) - put message to screen page at a time
- *
- **/
-
- void tx_mesg(struct MESG *mesg)
- {
- char *buf,c;
- int col,row;
-
- buf = mesg->text;
- c = BLANK;
- tx_windo(mesg->col1,mesg->row1,mesg->col2,mesg->row2);
- while((buf)&&(!kb_isfun(c))) {
- if((buf=tx_putl(buf))!=NULL) {
- col=colst_;
- row = rowen_+1;
- sc_winfull();
- sc_setcur(col,row);
- sc_puts("<more...>");
- c = kb_getch(); /* wait for key to be hit */
- tx_windo(mesg->col1,mesg->row1,mesg->col2,mesg->row2);
- tx_putw(buf); /* put overflow word */
- buf += strlen(buf)+1;
- }
- }
- }
-
-
- /********
- *
- * tx_putw(str) - put word to screen
- *
- **/
-
- char *tx_putw(char *str)
- {
- int len,cols;
-
- cols = colen_-sc_col_+1;
- len = strlen(str);
- if((len>cols)&&(sc_row_<rowen_)) {
- sc_puts("\n\r"); /* go to next line */
- cols= colen_-sc_col_+1;
- }
- if(len<=cols ) {
- sc_puts(str);
- if(len<cols)
- sc_putc(BLANK); /* after blank */
- return(NULL);
- } else
- return(str); /* no room in windo */
- }
-
-
- /********
- *
- * tx_putl(line) - put line of text to screen
- *
- **/
-
- char *tx_putl(char *line)
- {
- char *wptr;
-
- wptr = strtok(line," ");
- do {
- while((*line++==BLANK)&&(sc_row_<rowen_ || sc_col_<colen_))
- sc_putc(BLANK);
- line += strlen(wptr);
- if(!tx_putw(wptr))
- wptr = strtok(NULL," "); /* next word */
- else
- return(wptr);
- } while(wptr);
- return(NULL);
- }
-
-
- /********
- *
- * tx_windo(col1,row1,col2,row2) - create a text windo
- *
- **/
-
- void tx_windo(int col1, int row1, int col2, int row2)
- {
- sc_winfull();
- sc_box(col1-1,row1-1,col2+1,row2+1);
- sc_windo(col1,row1,col2,row2);
- sc_clr(); /* clear screen */
- }
-