home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / SFILTEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-23  |  1.7 KB  |  85 lines

  1. /*
  2.     sfiltext.c
  3.  
  4.     % sfile_SaveText, sfile_LoadText
  5.  
  6.  
  7.     OWL 1.2
  8.     Copyright (c) 1990 by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.      9/26/90 jmd     put into owl
  14.      9/27/90 jsm    Added casts to make C++ happy
  15.     10/22/90 jmd    added \0 termination of text string
  16.  
  17.     Note:    this entire mechanism will be re-written in a future release.
  18.             also, start your text names with an '_' character to
  19.             prevent them from being listed by LNF.
  20. */
  21.  
  22. #include "oakhead.h"
  23. #include "disppriv.h"
  24.  
  25. #include "winsfile.h"
  26. #include "winspriv.h"
  27.  
  28. #define BUFLEN 100
  29.  
  30. char *sfile_LoadText(sfile_type sfile, char *name)
  31. /*
  32.     Load a text string from an sfile.
  33.     Allocates space for the text that must later be freed with
  34.  
  35.     ofree(OA_SFTEXT, text);
  36.  
  37.     returns NULL if unable to load the text.
  38. */
  39. {
  40.     char     *text;
  41.     char       buffer[BUFLEN];
  42.     unsigned len, total;
  43.  
  44.     if (oslist_FindHandle(sfile->bfile->dir, name) == -1
  45.         || !sfile_Find(sfile, name, ID_SFTEXT)) {
  46.  
  47.         return(NULL);
  48.     }
  49.  
  50.     /* first, read the text to figure out how long it is */
  51.     total = 0;
  52.     len = BUFLEN;
  53.  
  54.     while(len == BUFLEN) {
  55.         len = bfile_Read(sfile->bfile, buffer, BUFLEN);
  56.         total += len;
  57.     }
  58.  
  59.     /* next, allocate space for the text */
  60.     if ((text = (char *) omalloc(OA_SFTEXT, total + 1)) == NULL) {
  61.         return(NULL);
  62.     }
  63.  
  64.     /* now, read in the text for real */
  65.     sfile_Find(sfile, name, ID_SFTEXT);
  66.     bfile_Read(sfile->bfile, text, total);
  67.     text[total] = '\0';
  68.  
  69.     return(text);
  70. }
  71.  
  72. boolean sfile_SaveText(sfile_type sfile, char *name, char *text)
  73. /*
  74.     Save a text string to an sfile.
  75. */
  76. {
  77.     if (!sfile_Find(sfile, name, ID_SFTEXT)) {
  78.         return(FALSE);
  79.     }
  80.  
  81.     bfile_Write(sfile->bfile, text, strlen(text));
  82.  
  83.     return(TRUE);
  84. }
  85.