⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sugarmemodb.h

📁 Palm上著名的背单词软件的源码
💻 H
字号:
//Sugar Memo Database header file

//bit operation
#define BitAtPosition(pos) ((UInt16)1 << (pos))
#define GetBitMacro(bitfield, index) ((bitfield) & BitAtPosition(index))
#define SetBitMacro(bitfield, index) ((bitfield) |= BitAtPosition(index))
#define RemoveBitMacro(bitfield, index) ((bitfield) &= ~BitAtPosition(index))  

//***********************************************
//
//	type define
//
//***********************************************

//***********************************************
//
//	Header type, as first double-bytes of every record, including both header record and word record
//
//***********************************************
typedef union {
	struct {
		unsigned	padding2	:2;
		unsigned	testingChoiceBuffer		:1;
		unsigned	learningChoiceBuffer	:1;
		unsigned	testingQ	:1;
		unsigned 	learningQ	:1;
		unsigned 	header		:1;
		
		unsigned 	padding		:5;

		unsigned 	waiting		:1;
		unsigned 	testing		:1;
		unsigned 	learning 	:1;
		unsigned 	raw			:1;
	} bits;
	
	UInt16 allBits;
}	Header;

typedef enum {
	RawQueue = 0,
	LearningQueue = 1,
	TestingQueue =	2,
	WaitingQueue = 3,

	HeaderFlag = 9,
	LearningQFlag = 10,
	TestingQFlag = 11,
	LearningBFlag = 12,
	TestingBFlag = 13,
	BadQueue = 15
} HeaderQueue;

typedef enum {
	FirstLook = 0,
	TranslationRecollection,
	WordRecollection,
	TranslationTest,
	WordTest
} 	LearningStatus;


typedef enum{
	NoRating = 0,
	FailRating = 1,
	PassRating = 2,
	BingoRating = 3
	
}	Rating;

typedef union {
	struct{
		unsigned padding					:3;
		unsigned wordTest					:1;
		unsigned translationTest			:1;
		unsigned wordRecollection			:1;
		unsigned translationRecollection 	:1;
		unsigned firstLook 					:1;
	} bits;
	
	UInt8 allBits;

}	ReviewMode;

typedef struct {

	ReviewMode	reviewMode ;

	unsigned	firstRating		:2;
	unsigned	secondRating	:2;
	unsigned	totalFail		:4;
	
} 	TestingStatus;



typedef union {
	TestingStatus testingStatus;
	LearningStatus learningStatus;	
}	LTStatus;

typedef struct {
	float 		eFactor;		//E-Factor
	UInt8 		difficulty;		//
	UInt8 		totalLapse;	
	UInt8 		totalRecall;
	UInt8 		step;			//step in current round
	DateType 	lastTest;
	DateType	currentTest;	//when the current test begins, only meaningful for drilling words
	DateType 	nextTest;
	DateType 	firstLearn;
	DateType 	create;
	
}	MemorizingStatus;

typedef enum {
	WordFieldQuestion = 0,
	WordFieldPhonetic,
	WordFieldAnswer,
	WordFieldWordNet,
	WordFieldMerriamWebster,
	WordFieldDict1,
	WordFieldDict2,
	WordFieldDict3,
	WordFieldNote1,
	WordFieldNote2,
	WordFieldNote3,
	
	WordFieldsCount
			
} WordFields;

//#define HeaderRecordFlag WordFieldsCount

typedef union {
	struct{
		unsigned 	reserved 	:5;
		unsigned 	note3		:1;
		unsigned 	note2		:1;
		unsigned 	note1		:1;
		unsigned 	dict3		:1;
		unsigned 	dict2		:1;
		unsigned 	dict1		:1;
		unsigned 	merriamwebster	:1;
		unsigned 	wordnet		:1;
		unsigned 	answer		:1;
		unsigned	phonetic	:1;
		unsigned 	question	:1;
	} bits;
	
	UInt16 allBits;

}	WordFieldFlags;

typedef struct {
	Header 	header;
	LTStatus	ltStatus;
	MemorizingStatus memoStatus;
	WordFieldFlags wordDBRecordFlags;
	UInt16 answerOffset;

	char firstField;	//just a placeholder

}	WordPackedRecord;

typedef struct {
	Header header;
	LTStatus ltStatus;
	MemorizingStatus memoStatus;
	char *field[WordFieldsCount];
	
}	WordRecordType;

typedef UInt32 HeaderItem;

typedef struct {
	Header header;
	UInt16 itemNumbers;
}	HeaderRecord;

typedef struct {
	Header header;
	UInt16 itemNumbers;
	HeaderItem firstItem; //place holder
} 	HeaderRecordHelper;

typedef enum{
	LeftAlignment = 0,
	CenterAlignment,
	RightAlignment
}	TextAlignment;

typedef struct {
	UInt16				renamedCategories;	// bitfield of categories with a different name
	char 				categoryLabels[dmRecNumCategories][dmCategoryLength];
	UInt8 				categoryUniqIDs[dmRecNumCategories];
	UInt8				lastUniqID;			// Uniq IDs generated by the device are between
											// 0 - 127.  Those from the PC are 128 - 255.
	UInt8				padding;			// from the compiler word aligning things
	
	DateType			lastUpdated;
	WordFieldFlags		answerPageFields;
	WordFieldFlags		questionPageFields;
	UInt16 				rawWordCount;
	
	struct {
		UInt32 reserved1;
		UInt32 reserved2;
		UInt32 reserved3;
		UInt32 reserved4;
	} misc;
	
}	SugarAppInfoType020;

typedef struct {
	UInt16				renamedCategories;	// bitfield of categories with a different name
	char 				categoryLabels[dmRecNumCategories][dmCategoryLength];
	UInt8 				categoryUniqIDs[dmRecNumCategories];
	UInt8				lastUniqID;			// Uniq IDs generated by the device are between
											// 0 - 127.  Those from the PC are 128 - 255.
	UInt8				padding;			// from the compiler word aligning things
	
	DateType			lastUpdated;
	WordFieldFlags		answerPageFields;
	WordFieldFlags		questionPageFields;
	UInt16 				rawWordCount;
	
	UInt16				version;
	
	FontID				learnFieldFont[WordFieldsCount];
	FontID				learnFieldFont2[WordFieldsCount];
	
	TextAlignment		learnFieldAlignment[WordFieldsCount];	
	
	ReviewMode			reviewMode;
	UInt8				lefty;
	
}	SugarAppInfoType;


typedef UInt16 HeaderIndex;

//App info record
SugarAppInfoType*	GetAppInfoPtr(DmOpenRef dbP);
Err   				SugarDBAppInfoInit(DmOpenRef db);

UInt16 GetRawWordCount();
void SetRawWordCount(UInt16 newWordCount);
void IncrementRawWordCount();
void DecrementRawWordCount();

//Database operation
Boolean CreateWordDB(char* name);
Boolean RenameWordDB(char* name);
Boolean DeleteWordDB(UInt16 cardNo, LocalID dbID);
void 	ResetDatabase(DmOpenRef db);


//header record operation
Boolean	CreateHeaderRecord(DmOpenRef db, HeaderIndex headerIndex);
Boolean	ClearHeaderRecord(DmOpenRef db, HeaderIndex headerIndex);
UInt16 	GetHeaderItemNumber(DmOpenRef db, HeaderIndex headerIndex);
Boolean	GetHeaderItem(DmOpenRef db, HeaderIndex headerIndex, HeaderItem* ItemP, UInt16 index);
Boolean	AddHeaderItem(DmOpenRef db, HeaderIndex headerIndex, HeaderItem* ItemP);
Boolean	AddHeaderItemByDBIndex(DmOpenRef db, HeaderIndex headerIndex, UInt16 dbIndex);
Boolean ShuffleHeaderItem(DmOpenRef db, HeaderIndex headerIndex);
Boolean FindHeaderItemByID(DmOpenRef db, HeaderIndex headerIndex, UInt32 uniqueID, UInt16* indexP);
Boolean FindHeaderItemByDBIndex(DmOpenRef db, HeaderIndex headerIndex, UInt16 dbIndex, UInt16* indexP);
Boolean RemoveHeaderItem(DmOpenRef db, HeaderIndex headerIndex, UInt16 index);
Boolean RemoveHeaderItemByID(DmOpenRef db, HeaderIndex headerIndex, UInt32 uniqueID);
Boolean RemoveHeaderItemByDBIndex(DmOpenRef db, HeaderIndex headerIndex, UInt16 dbIndex);
Boolean MoveHeaderItem(DmOpenRef db, HeaderIndex headerIndex, UInt16 index);

//header record maintenance
void 	ValidateHeaderRecord(DmOpenRef db);
void 	InitHeaderBuffer(DmOpenRef db, HeaderIndex BufferIndex);
void 	RebuildLearningQueue(DmOpenRef db);
void 	RebuildTestingQueue(DmOpenRef db, Boolean forced);
void 	PushHeaderBuffer(DmOpenRef db, HeaderIndex bufferIndex, UInt16 dbIndex);


//word record operation
Err 	NewWordRecord(DmOpenRef db, WordRecordType* record, UInt16* index);
Err		GetWordRecord(DmOpenRef db, UInt16 index, WordRecordType* recordP, MemHandle *recordH);
void 	WordDBDeleteRecord(Boolean archive);
Err 	ChangeWordRecord(DmOpenRef dbP, UInt16 *index, WordRecordType* r, WordFieldFlags changedFields);

//high level record manipulation 
HeaderQueue 	GetQueue(DmOpenRef db, UInt16 index);
void 			SetQueue(DmOpenRef db, UInt16 index, HeaderQueue queue);
LearningStatus	GetLearningStatus(DmOpenRef db, UInt16 index);
void 			SetLearningStatus(DmOpenRef db, UInt16 index, LearningStatus ls);
TestingStatus	GetTestingStatus(DmOpenRef db, UInt16 index);
void			SetTestingStatus(DmOpenRef db, UInt16 index, TestingStatus ls);
MemorizingStatus GetMemorizingStatus(DmOpenRef db, UInt16 index);
void 			SetMemorizingStatus(DmOpenRef db, UInt16 index, MemorizingStatus memoStatus);

//misc function
Boolean WordRecordContainsData (WordRecordType* recordP);
UInt16 InstantLookupPosition(DmOpenRef db, Char* p);
void GetDBList();
void UnpackSuperMemoRecord(DmOpenRef db, UInt16 index, WordRecordType* record, MemHandle* recordH, char* cache);


extern WordRecordType DefaultNewWordRecord;

void UpdateOldVersionDatabase3(DmOpenRef db);

// Added by hytown
void ResetTestingStatus(DmOpenRef db);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -