home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / RPRINTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  5.2 KB  |  238 lines

  1. /*
  2.  * rprints.c
  3.  * contains: rprints(),rprintf(),rcprints(),rcprintf(),rjprints(),rjprintf()
  4.  *     
  5.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "color.h"
  13. #include "gfuncts.h"
  14.  
  15.  
  16. /*
  17.  *  void
  18.  * rprints(color,page,str)
  19.  *
  20.  * ARGUMENT
  21.  *  (int)    color    -    color to use (see color.h)
  22.  *  (int)    page    -    video page to use
  23.  *  (char *)    str    -    string to display.
  24.  *
  25.  * DESCRIPTION
  26.  *  This function sends a string to the display via putcinc().
  27.  */
  28. void GF_CONV rprints(color,page,str)
  29. char *str;
  30. int color, page;
  31. {
  32.     while(*str)
  33.         putcinc(*str++,color, page);
  34. }
  35.  
  36. /*
  37.  *  void
  38.  * rprintf(color,page,control,args)
  39.  *
  40.  * ARGUMENT
  41.  *  (int)    color    -    color to use
  42.  *  (int)    page    -    video page
  43.  *  (char *)    control    -    control string for sprintf()
  44.  *        args    -    arguments for sprintf()
  45.  *
  46.  * DESCRIPTION
  47.  *  This function formats a string with sprintf() in a local 200 byte buffer
  48.  *  then calls rprints() to display it.
  49.  */
  50.  
  51. #ifndef    _MSC
  52. void GF_CDECL rprintf(color,page,control)
  53. #else
  54. #if    _MSC > 4
  55. void GF_CDECL rprintf(color,page,control,...)
  56. #else
  57. void rprintf(color,page,control)
  58. #endif
  59. #endif
  60.  
  61. int color, page;
  62. char *control;
  63. {
  64.     char *buf,**value;
  65.  
  66.     value=&control;
  67.     if((buf=malloc(200))==NULL)
  68.         return;
  69.     sprintf(buf,control,
  70.         value[1],value[2],value[3],value[4],value[5],value[6],
  71.         value[7],value[8],value[9],value[10]
  72. #ifndef _LDATA
  73.         ,value[11],value[12],value[13],value[14],value[15],value[16],
  74.         value[17],value[18],value[19],value[20]
  75. #endif
  76.             );
  77.     rprints(color,page,buf);
  78.     free(buf);
  79. }
  80.  
  81. /*
  82.  *  void
  83.  * rcprints(cols,color,page,str)
  84.  *
  85.  * ARGUMENT
  86.  *  (int)    cols    -    Number of columns to center on
  87.  *  (int)    color    -    color to use.
  88.  *  (int)    page    -    video page to use
  89.  *  (char *)    str    -    null terminated string to display
  90.  *
  91.  * DESCRIPTION
  92.  *  Centers text on the lesser of cols and gmaxcol then outputs with
  93.  *  putcinc().
  94.  * MODIFICATIONS:
  95.  *  "" Tue 08-Nov-1988 13:36:40
  96.  *    was using the current video page instead of the one specified
  97.  *    in the parameter. (SAR #106)
  98.  */
  99. void GF_CONV rcprints(cols,color,page,instr)
  100. int cols,color,page;
  101. char *instr;
  102. {
  103.     curset((getcur(page)&0xff00)>>8,
  104.         xmin(cols,gmaxcol)/2-(strlen(instr)/2),page);
  105.     while(*instr)
  106.         putcinc(*instr++,color,page);
  107. }
  108.  
  109. /*
  110.  *  void
  111.  * rcprintf(cols,color,page,format,args,)
  112.  *
  113.  * ARGUMENT
  114.  *  (int)    cols    -    Columns to center
  115.  *  (int)    color    -    Attribute
  116.  *  (int)    page    -    video page
  117.  *  (char *)    format    -    format string for sprintf()
  118.  *        args    -    args for sprintf()
  119.  *
  120.  * DESCRIPTION
  121.  *  Format string with sprintf(), then center and print with rcprints()
  122.  *  Note: internal buffer is 200 characters.
  123.  */
  124.  
  125. #ifndef    _MSC
  126. void GF_CDECL rcprintf(cols,color,page,format)
  127. #else
  128. #if  _MSC > 4
  129. void GF_CDECL rcprintf(cols,color,page,format,...)
  130. #else
  131. void rcprintf(cols,color,page,format)
  132. #endif
  133. #endif
  134.  
  135. int cols,color,page;
  136. char *format;
  137. {
  138.     char *buf,**value;
  139.  
  140.     value=&format;
  141.     if((buf=malloc(200))==NULL)
  142.         return;
  143.     sprintf(buf,format,
  144.         value[1],value[2],value[3],value[4],value[5],value[6],
  145.         value[7],value[8],value[9],value[10]
  146. #ifndef _LDATA
  147.         ,value[11],value[12],value[13],value[14],value[15],value[16],
  148.         value[17],value[18],value[19],value[20]
  149. #endif
  150.             );
  151.     rcprints(cols,color,page,buf);
  152.     free(buf);
  153. }
  154.  
  155. /*
  156.  *  bool
  157.  * rjprints(cols,color,page,instr)
  158.  *
  159.  * ARGUMENT
  160.  *  (int)    cols    - Justify on lesser of this or gmaxcol
  161.  *  (int)    color    - Color/Attribute
  162.  *  (int)    page    - Video page to use
  163.  *  (char *)    instr    - pointer to string to display.
  164.  *
  165.  * DESCRIPTION
  166.  *  This function justifies the string with justify(), then displays it
  167.  *  with rprints.
  168.  *
  169.  * RETURNS
  170.  *  TRUE if justification is successful, else FALSE
  171.  */
  172. bool GF_CONV rjprints(cols,color,page,instr)
  173. int cols,color,page;
  174. char *instr;
  175. {
  176.     char *outstr;
  177.     int icols;
  178.     bool bret;
  179.  
  180.     if((outstr=malloc(200))==NULL)
  181.         return(FALSE);
  182.     icols=xmin(cols,gmaxcol);
  183.     bret=justify(outstr,instr,icols);
  184.     rprints(color,page,outstr);
  185.     free(outstr);
  186.     return bret;
  187. }
  188.  
  189. /*
  190.  *  bool
  191.  * rjprintf(cols,color,page,format,args,)
  192.  *
  193.  * ARGUMENT
  194.  *  (int)    cols    -    Justify on lesser of this and gmaxcol
  195.  *  (int)    color    -    Attribute/Color
  196.  *  (int)    page    -    video page to use
  197.  *  (char *)    format    -    format string for sprintf(),
  198.  *        args    -    arguments for sprintf().
  199.  *
  200.  * DESCRIPTION
  201.  *  Color print formatted line with justification.
  202.  *
  203.  * RETURNS
  204.  *  TRUE if justification is successful, false otherwise.
  205.  */
  206.  
  207. #ifndef    _MSC
  208. bool GF_CDECL rjprintf(cols,color,page,format)
  209. #else
  210. #if    _MSC > 4
  211. bool GF_CDECL rjprintf(cols,color,page,format,...)
  212. #else
  213. bool rjprintf(cols,color,page,format)
  214. #endif
  215. #endif
  216.  
  217. int cols,color,page;
  218. char *format;
  219. {
  220.     char *buf,**value;
  221.     bool bret;
  222.     
  223.     value=&format;
  224.     if((buf=malloc(200))==NULL)
  225.         return(FALSE);
  226.     sprintf(buf,format,
  227.         value[1],value[2],value[3],value[4],value[5],value[6],
  228.         value[7],value[8],value[9],value[10]
  229. #ifndef _LDATA
  230.         ,value[11],value[12],value[13],value[14],value[15],value[16],
  231.         value[17],value[18],value[19],value[20]
  232. #endif
  233.            );
  234.     bret=rjprints(cols,color,page,buf);
  235.     free(buf);
  236.     return bret;
  237. }
  238.