Inserting Rows in a Memory File

A row of text can be inserted in a memory file by the memory file row insert function, mf_rowins():

int mf_rowins(stp, mf_row, mfp)
 
UCHAR *stp;
/* Pointer to string to insert in memory file
*/
int mf_row;
/* Row to insert in
*/
MFILEPTR mfp;
/* Memory file to insert string in
*/

mf_rowins() effectively inserts the passed text string at the specified row, moving down the contents of all rows below and including the specified row to make room for the insertion.

The text string passed to mf_rowins() can contain embedded newlines.

If the file is full (contains the maximum rows specified for the file in mf_def()) before the insertion is made, the global error code is set and the string is not inserted. If the string to be inserted contains embedded newlines, no line segment will be transferred. An error code is also set if the entire string cannot be inserted.

Caution: Inserting rows near the beginning of long memory files requires substantial computing time. Pointers to the contents of every row below the specified row must be moved.

Using mf_rowins() to Fill a Memory File

You can use the #defined value APPEND_ROW when using mf_rowins(). When APPEND_ROW is specified, the string will be appended after the last non-empty row of the file.

When used to append a row to a memory file, mf_rowins() provides an alternative to mf_rowrpl(). Used in this way, the two functions behave identically. Thus, you can use either mf_rowrpl() or mf_rowins() to build a memory file, and the previous discussion of mf_rowrpl() in this context applies equally to mf_rowins(). Embedded newlines and strings longer than the file column-size are handled in the same manner by mf_rowrpl() and mf_rowins() when appending strings to the end of the memory file.

Error Handling by mf_rowins()

Error handling by mf_rowins() is identical to that in mf_rowrpl(), with the addition that VV_ERR will be set to MFILETOOBIG if inserting a row would cause the file length to exceed the maximum number of rows in the file.


Home Contents Previous Next