home *** CD-ROM | disk | FTP | other *** search
- /* sti_buf.c -- an example of how mf_rwrpl() and mf_scrl() can be used to
- maintain an "off-screen buffer".
-
- DISCUSSION
-
- Before calling this function, a memory file MFILE must have been initialized
- with a call to mf_def(). The maximum number of lines and the maximum number of
- columns in the file will be dependent on your requirements.
-
- This function will place the specified string in first empty line of the memory
- file, if space is available. If the file is full, all of the lines in the file
- will be scrolled up 1 line. This will cause the first line in the file to be
- scrolled off the top of the file and lost. The specified string is then placed
- in the last line of the file.
-
- CALL
-
- sti_buf(st, mfp)
- char *st; pointer to string to be placed in file
- MFILEPTR mfp; pointer to a MFILE structure
-
- RETURNS
-
- = -2 if string is truncated and file is scrolled
-
- = -1 if string is truncated and file not scrolled
-
- = 0 if unable to allocate memory
-
- = 1 if full string is written and file not scrolled
-
- = 2 if full string is written and file is scrolled
-
- CAUTIONS
-
- This is NOT a main program. It is a sub-routine.
-
- Before using this function, the memory file must be initialized by a call to
- mf_def().
-
- */
-
- #include <wfc.h>
-
- sti_buf(st, mfp)
- char *st;
- MFILEPTR mfp;
- {
- int ln_q;
- int retval;
- int scroll; /* = 1 if no scroll; = 2 if scroll */
-
- scroll = 1;
- ln_q = mfp->ln_q; /*avoid indirection */
-
- if(ln_q >= mfp->fmaxline) /*no more room -- must scroll file */
- {
- scroll = 2;
- if(mf_scrl(1, UP, ALL_ROWS, mfp) == 0) /*scroll whole file */
- return(0);
- if((retval = mf_rwrpl(st, ln_q - 1, mfp)) == 0)/*replace last line */
- return(0);
- }
- else /*room available -- simply append */
- if((retval = mf_rwrpl(st, ln_q, mfp)) == 0) /*add new line to end */
- return(0);
-
- return(retval * scroll);
- }