home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c003 / 1.ddi / DEMOS / STI_BUF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-02-02  |  1.9 KB  |  70 lines

  1. /* sti_buf.c -- an example of how mf_rwrpl() and mf_scrl() can be used to
  2.         maintain an "off-screen buffer".
  3.  
  4. DISCUSSION
  5.  
  6. Before calling this function, a memory file MFILE must have been initialized
  7. with a call to mf_def().  The maximum number of lines and the maximum number of
  8. columns in the file will be dependent on your requirements.
  9.  
  10. This function will place the specified string in first empty line of the memory
  11. file, if space is available.  If the file is full, all of the lines in the file
  12. will be scrolled up 1 line.  This will cause the first line in the file to be
  13. scrolled off the top of the file and lost.  The specified string is then placed
  14. in the last line of the file.
  15.  
  16. CALL
  17.  
  18. sti_buf(st, mfp)
  19. char *st;             pointer to string to be placed in file
  20. MFILEPTR mfp;             pointer to a MFILE structure
  21.  
  22. RETURNS
  23.  
  24. = -2 if string is truncated and file is scrolled
  25.  
  26. = -1 if string is truncated and file not scrolled
  27.  
  28. = 0 if unable to allocate memory
  29.  
  30. = 1 if full string is written and file not scrolled
  31.  
  32. = 2 if full string is written and file is scrolled
  33.  
  34. CAUTIONS
  35.  
  36. This is NOT a main program.  It is a sub-routine.
  37.  
  38. Before using this function, the memory file must be initialized by a call to
  39. mf_def().
  40.  
  41. */
  42.  
  43. #include <wfc.h>
  44.  
  45. sti_buf(st, mfp)
  46. char *st;
  47. MFILEPTR mfp;
  48. {
  49.     int ln_q;
  50.     int retval;
  51.     int scroll;             /* = 1 if no scroll; = 2 if scroll    */
  52.  
  53.     scroll = 1;
  54.     ln_q = mfp->ln_q;            /*avoid indirection              */
  55.  
  56.     if(ln_q >= mfp->fmaxline)        /*no more room -- must scroll file    */
  57.     {
  58.     scroll = 2;
  59.     if(mf_scrl(1, UP, ALL_ROWS, mfp) == 0)           /*scroll whole file    */
  60.         return(0);
  61.     if((retval = mf_rwrpl(st, ln_q - 1, mfp)) == 0)/*replace last line    */
  62.         return(0);
  63.     }
  64.     else                /*room available -- simply append     */
  65.     if((retval = mf_rwrpl(st, ln_q, mfp)) == 0)    /*add new line to end  */
  66.         return(0);
  67.  
  68.     return(retval * scroll);
  69. }
  70.