home *** CD-ROM | disk | FTP | other *** search
- /*
- sfiltext.c
-
- % sfile_SaveText, sfile_LoadText
-
-
- OWL 1.2
- Copyright (c) 1990 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 9/26/90 jmd put into owl
- 9/27/90 jsm Added casts to make C++ happy
- 10/22/90 jmd added \0 termination of text string
-
- Note: this entire mechanism will be re-written in a future release.
- also, start your text names with an '_' character to
- prevent them from being listed by LNF.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
-
- #include "winsfile.h"
- #include "winspriv.h"
-
- #define BUFLEN 100
-
- char *sfile_LoadText(sfile_type sfile, char *name)
- /*
- Load a text string from an sfile.
- Allocates space for the text that must later be freed with
-
- ofree(OA_SFTEXT, text);
-
- returns NULL if unable to load the text.
- */
- {
- char *text;
- char buffer[BUFLEN];
- unsigned len, total;
-
- if (oslist_FindHandle(sfile->bfile->dir, name) == -1
- || !sfile_Find(sfile, name, ID_SFTEXT)) {
-
- return(NULL);
- }
-
- /* first, read the text to figure out how long it is */
- total = 0;
- len = BUFLEN;
-
- while(len == BUFLEN) {
- len = bfile_Read(sfile->bfile, buffer, BUFLEN);
- total += len;
- }
-
- /* next, allocate space for the text */
- if ((text = (char *) omalloc(OA_SFTEXT, total + 1)) == NULL) {
- return(NULL);
- }
-
- /* now, read in the text for real */
- sfile_Find(sfile, name, ID_SFTEXT);
- bfile_Read(sfile->bfile, text, total);
- text[total] = '\0';
-
- return(text);
- }
-
- boolean sfile_SaveText(sfile_type sfile, char *name, char *text)
- /*
- Save a text string to an sfile.
- */
- {
- if (!sfile_Find(sfile, name, ID_SFTEXT)) {
- return(FALSE);
- }
-
- bfile_Write(sfile->bfile, text, strlen(text));
-
- return(TRUE);
- }
-