home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / SC_FIELD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-17  |  3.4 KB  |  219 lines

  1. /*********************
  2.  *
  3.  *  sc_field.c - screen primitives for fields.
  4.  *
  5.  *  Purpose: This file contains the low level screen functions for fields.
  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 "kb_head.h"
  15. #include "sc_head.h"
  16.  
  17.  
  18. /********
  19.  *
  20.  *   sc_scrlu(row,nrows) - scroll screen up
  21.  *
  22.  **/
  23.  
  24. void sc_scrlu(int row, int nrows)
  25. {
  26.     if(row<rowen_)
  27.     sc_scroll(nrows,row,colst_,rowen_,colen_);
  28.     else
  29.        {
  30.        sc_setcur(colst_,rowen_);
  31.        sc_scroll(nrows,row,colst_,rowen_,colen_);
  32.        }
  33. }
  34.  
  35.  
  36. /********
  37.  *
  38.  *   sc_scrld(row,nrows) - scroll screen down nrows
  39.  *
  40.  **/
  41.  
  42. void sc_scrld(int row, int nrows)
  43. {
  44.     if(row<rowen_-1)
  45.     sc_scroll(-nrows,row+1,colst_,rowen_,colen_);
  46.     else if(row<rowen_)
  47.         {
  48.     sc_setcur(colst_,rowen_);
  49.     sc_eeol();
  50.     }
  51. }
  52.  
  53.  
  54. /********
  55.  *
  56.  *   sc_clrf(n) - clear the screen field for n bytes
  57.  *
  58.  **/
  59.  
  60. void sc_clrf(int n)
  61. {
  62.     ut_push(sc_col_);
  63.     n = min(n,colen_-sc_col_+1);
  64.     sc_clrwin(sc_col_,sc_row_,sc_col_+n,sc_row_);
  65.     sc_col_=ut_pop();
  66. }
  67.  
  68.  
  69. /********
  70.  *
  71.  *   sc_putfi(i,n) - ouput integer onto screen in field n
  72.  *
  73.  **/
  74.  
  75. void sc_putfi(int i, int n)
  76. {
  77.     char str[16];
  78.  
  79.     sprintf(str,"%15d",i);          /* convert to string */
  80.     sc_putsfl(str,n);
  81. }
  82.  
  83.  
  84. /********
  85.  *
  86.  *   sc_putsfl(str,n) - put string in field with clear
  87.  *
  88.  **/
  89.  
  90. void sc_putsfl(char *str, int n)
  91. {
  92.     sc_clrf(n);             /* clear it first */
  93.     sc_putsf(str,n);
  94. }
  95.  
  96.  
  97. /********
  98.  *
  99.  *   sc_putsf(str,n) - put string in field of n bytes
  100.  *
  101.  **/
  102.  
  103. void sc_putsf(char *str, int n)
  104. {
  105.     ut_push(wrapf_);
  106.     wrapf_ = FALSE;         /* turn off wrap */
  107.     while((n) && (*str!=NUL)) {
  108.     sc_putc(*str++);
  109.     --n;
  110.     }
  111.     wrapf_=ut_pop();
  112. }
  113.  
  114.  
  115. /********
  116.  *
  117.  *   sc_putlf(line,n) - put line in field of n bytes
  118.  *
  119.  **/
  120.  
  121. void sc_putlf(char *line, int n)
  122. {
  123.     ut_push(wrapf_);
  124.     wrapf_ = FALSE;         /* turn off wrap */
  125.     sc_clrf(n);
  126.     while((n) && (*line!=NUL) && (*line!=NEWLINE)) {
  127.     sc_putc(*line++);
  128.     --n;
  129.     }
  130.     wrapf_=ut_pop();
  131. }
  132.  
  133.  
  134. /********
  135.  *
  136.  *   sc_putsfr(str,n) - put string into field right justified
  137.  *
  138.  **/
  139.  
  140. void sc_putsfr(char *str, int n)
  141. {
  142.     int nf;
  143.  
  144.     nf = max(n-strlen(str),0);
  145.     sc_movcur(nf,0);
  146.     sc_putsfl(str,n-nf);    /* clear field too */
  147. }
  148.  
  149.  
  150. /********
  151.  *
  152.  *   sc_putsflr(str,n) - put string into field right justified w/clear
  153.  *
  154.  **/
  155.  
  156. void sc_putsflr(char *str, int n)
  157. {
  158.     sc_clrf(n);
  159.     sc_putsfr(str,n);       /* clear field too */
  160. }
  161.  
  162.  
  163. /********
  164.  *
  165.  *   sc_putsflc(str,n) - put string in field cntr with clear
  166.  *
  167.  **/
  168.  
  169. void sc_putsflc(char *str, int n)
  170. {
  171.     sc_clrf(n);
  172.     sc_putsfc(str,n);
  173. }
  174.  
  175.  
  176. /********
  177.  *
  178.  *   sc_putsfc(char *str, int n) - put string into field centered
  179.  *
  180.  **/
  181.  
  182. void sc_putsfc(char *str, int n)
  183. {
  184.     int nf;
  185.  
  186.     nf = max(1+(n-strlen(str))/2,0);
  187.     sc_movcur(nf,0);
  188.     sc_putsf(str,n-nf);
  189. }
  190.  
  191. /********
  192.  *
  193.  *   sc_putifr(i,n) - put integer into field right justified
  194.  *
  195.  **/
  196.  
  197. void sc_putifr(int i, int n)
  198. {
  199.     char str[16];
  200.  
  201.     sprintf(str,"%d",i);            /* convert to string base 10 */
  202.     sc_putsfr(str,n);
  203. }
  204.  
  205.  
  206. /********
  207.  *
  208.  *   sc_putifc(i,n) - put integer into field centered
  209.  *
  210.  **/
  211.  
  212. void sc_putifc(int i, int n)
  213. {
  214.     char str[16];
  215.  
  216.     sprintf(str,"%d",i);
  217.     sc_putsfc(str,n);
  218. }
  219.