1 line
15 KiB
C
1 line
15 KiB
C
|
/* Copyright (c) 2017, Computer History Museum
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted (subject to
the limitations in the disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Computer History Museum nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. */
#include "emoticon.h"
typedef struct EmoRec EmoRec, *EmoRecPtr;
struct EmoRec
{
Str31 ascii;
Str31 meaning;
FSSpec spec;
Handle iconSuite;
Boolean notInMenu;
EmoRecPtr next;
};
Boolean EmoInitted;
EmoRecPtr EmoRoot;
#define EmoScanFinished(pte) (!(*PeteExtra(pte))->emoDesired || (*PeteExtra(pte))->emoScanned==kEmoScanFinished)
void EmoScanPete(PETEHandle pte, Boolean toCompletion);
void EmoScanPeteInner(PETEHandle pte, long *pScanned);
UPtr EmoScanPtr(UPtr start,long offset,UPtr end,EmoRecPtr *emoOut);
OSErr EmoApply(PETEHandle pte,long spot,EmoRecPtr emo);
OSErr EmoApplyIcon(PETEHandle pte,long start,EmoRecPtr emo);
void EmoInitMenu(void);
OSErr EmoSniffer(short vRefNum, long parID, uLong refCon);
Boolean IsEmoFile(FSSpecPtr spec,Handle *iconSuite);
/**********************************************************************
* EmoInit - initialize the emoticon system
**********************************************************************/
void EmoInit(void)
{
short size = GetPrefLong(PREF_FONT_SIZE);
long minSize;
Str63 itemStr;
UPtr spot;
Str255 alternateFolders;
FolderSniffer(EMOTICON_FOLDER,EmoSniffer,0);
GetRString(alternateFolders,ALTERNATE_EMOTICONS);
spot = alternateFolders+1;
for(;;)
{
// get size
if (!PToken(alternateFolders,itemStr,&spot,",") || !*itemStr) break;
StringToNum(itemStr,&minSize);
// string is ordered. If our font size is smaller than the min
// font size for this folder, we're done
if (minSize > size) break;
// foldername
if (!PToken(alternateFolders,itemStr,&spot,",") || !*itemStr) break;
// Go forth and sniff!
FolderSnifferStr(itemStr,EmoSniffer,0);
}
if (EmoRoot) EmoInitMenu();
EmoInitted = true;
}
/**********************************************************************
* EmoSniffer - sniff a folder for emoticons
**********************************************************************/
OSErr EmoSniffer(short vRefNum, long parID, uLong refCon)
{
CInfoPBRec hfi;
FSSpec spec;
OSErr err = noErr;
EmoRecPtr emo, lastEmo;
Handle suite;
Zero(hfi);
hfi.hFileInfo.ioNamePtr = spec.name;
while (!err && !DirIterate(vRefNum,parID,&hfi))
{
// files only. So solly, no recursion...
if (!(hfi.hFileInfo.ioFlAttrib & ioDirMask))
spec.vRefNum = vRefNum;
spec.parID = parID;
IsAlias(&spec,&spec);
if (IsEmoFile(&spec,&suite) && (emo=NewPtr(sizeof(EmoRec))))
{
long len;
Str31 s;
Str63 name;
|