home *** CD-ROM | disk | FTP | other *** search
- #pragma once
-
- #include <Types.h>
-
- const ResType TYPE_COOKIE = 'coOK'; // resource type of the cookie
- const short ID_COOKIE = 128; // resource number of the cookie
- const unsigned char COOKIE_SEPARATOR = '\r'; // return character
- struct CookieResource {
- unsigned long size; // size of the data fork
- int cFortune; // number of fortunes
- long fortune[1]; // fortune[0] = 0, fortune[cFortune] = position of EOF
- };
- typedef struct CookieResource CookieResource;
-
- enum CookieSave {SAVE_NO, SAVE_UPDATE, SAVE_NEW};
- typedef enum CookieSave CookieSave;
-
- // cookie, the file that contains the fortunes
- // cookie, also the index resource in the file, and in memory
- // since resources are limited to 32K in size, the fortunes array is limited to 8190 entries
- // 8190 = (32768-8)/4, the last entry of fortunes points to EOF, one character past the end of the cookie
- const int LAST_FORTUNE = 8190;
- const long MAX_FORTUNE = 32767;
- class QuotesDocument {
- public:
- int available(void) const; // return number of quotes
- OSErr draw(int); // return the text of a quote
- void discard(void); // when asked to save a cookie before closing, user said discard changes
- Boolean save(void) const; // does this cookie need to be saved?
- unsigned char *text(void) const; // return pointer to text of quote
- QuotesDocument(FSSpec, OSErr&); // constructor
- ~QuotesDocument(void); // destructor
- private:
- FSSpec fsCookie; // file specification of the cookie data file
- short selData; // file reference number of cookie data file
- short selResource; // file reference number of cookie resource file
- CookieSave selSave; // need to save cookie resource to file
- CookieResource **hrsrcCookie; // handle to cookie resource
- unsigned char *pchFortune; // handle to text of quote
- OSErr scan(void); // read through the data of the cookie looking for repeated cookie separators
- unsigned long resource_size(void) const; // size of the cookie resource
- unsigned long current_size(void) const; // size of file referenced by selCookie
- };
-