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

  1. /*********************
  2.  *
  3.  *  tx_field.c - text display functions.
  4.  *
  5.  *  Purpose: This file contains functions to display text in fields
  6.  *           and windows on the screen.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "blackstr.h"
  16. #include "kb_head.h"
  17. #include "sc_head.h"
  18. #include "tx_head.h"
  19.  
  20.  
  21. /********
  22.  *
  23.  *   tx_putf(fp) - put file to screen
  24.  *
  25.  **/
  26.  
  27. int tx_putf(FILE *fp)
  28. {
  29.     long *pgloc;
  30.     int page,c;
  31.  
  32.     pgloc = (long*)calloc(100,sizeof(long));
  33.     page = 0;
  34.     pgloc[page] = 0;
  35.     pgloc[++page] = tx_putfp(fp,0L);        /* put first page */
  36.     while((c = kb_getch()) != 0) {
  37.     switch(c){
  38.       case PG_DN:
  39.           if(pgloc[page]>0) page++;
  40.           break;
  41.       case PG_UP:
  42.           page--;
  43.           if(page<0) page=0;
  44.           break;
  45.       case ESC:
  46.           free(pgloc);
  47.           return(ESC);
  48.     }
  49.     pgloc[page+1] = tx_putfp(fp,pgloc[page]);
  50.     }
  51.     return(NUL);
  52. }
  53.     
  54.  
  55. /********
  56.  *
  57.  *   tx_putfp(fp,flpos) - put file page to screen
  58.  *
  59.  **/
  60.  
  61. long tx_putfp(FILE *fp, long flpos)
  62. {
  63.     char *lptr,line[MAX_ST];
  64.  
  65.     lptr = line;
  66.     fseek(fp,flpos,0);
  67.     while(fl_getl(line, fp)!=EOF) {
  68.     if((lptr=tx_putl(line)) != NULL)
  69.         return(ftell(fp)-strlen(lptr));
  70.     }
  71.     return(EOF);
  72. }
  73.  
  74.  
  75. /********
  76.  *
  77.  *   tx_mesg(mesg) - put message to screen page at a time
  78.  *
  79.  **/
  80.  
  81. void tx_mesg(struct MESG *mesg)
  82. {
  83.     char *buf,c;
  84.     int col,row;
  85.  
  86.     buf = mesg->text;
  87.     c = BLANK;
  88.     tx_windo(mesg->col1,mesg->row1,mesg->col2,mesg->row2);
  89.     while((buf)&&(!kb_isfun(c))) {
  90.     if((buf=tx_putl(buf))!=NULL) {
  91.         col=colst_;
  92.         row = rowen_+1;
  93.         sc_winfull();
  94.         sc_setcur(col,row);
  95.         sc_puts("<more...>");
  96.         c = kb_getch();         /* wait for key to be hit */
  97.         tx_windo(mesg->col1,mesg->row1,mesg->col2,mesg->row2);
  98.         tx_putw(buf);           /* put overflow word */
  99.         buf += strlen(buf)+1;
  100.     }
  101.     }
  102. }
  103.  
  104.  
  105. /********
  106.  *
  107.  *   tx_putw(str) - put word to screen
  108.  *
  109.  **/
  110.  
  111. char *tx_putw(char *str)
  112. {
  113.     int len,cols;
  114.  
  115.     cols = colen_-sc_col_+1;
  116.     len = strlen(str);
  117.     if((len>cols)&&(sc_row_<rowen_)) {
  118.     sc_puts("\n\r");                                /* go to next line */
  119.     cols= colen_-sc_col_+1;
  120.     }
  121.     if(len<=cols ) {
  122.     sc_puts(str);
  123.     if(len<cols)
  124.         sc_putc(BLANK);                 /* after blank */
  125.     return(NULL);
  126.     } else
  127.     return(str);                    /* no room in windo */
  128. }
  129.  
  130.  
  131. /********
  132.  *
  133.  *   tx_putl(line) - put line of text to screen
  134.  *
  135.  **/
  136.  
  137. char *tx_putl(char *line)
  138. {
  139.     char *wptr;
  140.  
  141.     wptr = strtok(line," ");
  142.     do {
  143.     while((*line++==BLANK)&&(sc_row_<rowen_ || sc_col_<colen_))
  144.         sc_putc(BLANK);
  145.     line += strlen(wptr);
  146.     if(!tx_putw(wptr))
  147.         wptr = strtok(NULL," ");        /* next word */
  148.     else
  149.         return(wptr);
  150.     } while(wptr);
  151.     return(NULL);
  152. }
  153.  
  154.  
  155. /********
  156.  *
  157.  *   tx_windo(col1,row1,col2,row2) - create a text windo
  158.  *
  159.  **/
  160.  
  161. void tx_windo(int col1, int row1, int col2, int row2)
  162. {
  163.     sc_winfull();
  164.     sc_box(col1-1,row1-1,col2+1,row2+1);
  165.     sc_windo(col1,row1,col2,row2);
  166.     sc_clr();                               /* clear screen */
  167. }
  168.