📄 user.c
字号:
/********************************************************************* FILE: User.c** DESCRIPTION: User-level code for the MyDBViewer.c project.* This file is the place you put YOUR functions for* showing YOUR data in the MyDBViewer test application.** VERSION: 1.0**********************************************************************/#include <PalmOS.h>#include "User.h"#define userNoTextStr "No text representation is available for this type."/*********************************************************************** * FUNCTION: UserRecordToText_mpoi * * DESCRIPTION: Converts records to text. * This function is for the ppoi type used in Chapter 4. * * RETURNED: pointer to the text representation. Caller must free. ***********************************************************************/static Char *UserRecordToText_mpoi( MemPtr dataP // (in) data to be shown){ Char *resultP; int sz; Char *labelP; struct mpoi { Int32 top, left; /* label follows */ } *recordP; recordP = ( struct mpoi *)dataP; labelP = (Char *)((char *)(dataP)+sizeof( struct mpoi )); sz = StrLen( labelP ) + 128; // It's just a string! resultP = MemPtrNew( sz * sizeof( Char *) ); if ( resultP ) { StrPrintF( resultP, "(%ld, %ld) -", recordP->left, recordP->top ); StrCat( resultP, labelP ); } return resultP;}/*********************************************************************** * FUNCTION: UserRecordToText_text * * DESCRIPTION: Converts records to text. Copy and mutate this method * as appropriate for the types you create. * * RETURNED: pointer to the text representation. Caller must free. ***********************************************************************/static Char *UserRecordToText_text( MemPtr dataP // (in) data to be shown){ Char *resultP; int sz; /* * When creating text representations of arbitrary data, StrPrintF * is your friend. Although this isn't the most efficient * implementation for the 'text' type (since the data is text anyway!) * we're going to do this this way to show you what we mean. */ sz = StrLen( (Char *)dataP ) + 1; // It's just a string! resultP = MemPtrNew( sz * sizeof( Char *) ); if ( resultP ) { StrPrintF( resultP, "%s", dataP ); } return resultP;}/*********************************************************************** * FUNCTION: UserRecordToText_noType * * DESCRIPTION: Converts records to text. Mutate this method * as appropriate for the no-type databases you create. * * RETURNED: pointer to the text representation. Caller must free. ***********************************************************************/static Char *UserRecordToText_noType( MemPtr dataP // (in) data to be shown){ Char *resultP; int sz; /* * When creating text representations of arbitrary data, StrPrintF * is your friend. Although this isn't the most efficient * implementation for the 'text' type (since the data is text anyway!) * we're going to do this this way to show you what we mean. */ sz = StrLen( (Char *)dataP ) + 1; // It's just a string! resultP = MemPtrNew( sz * sizeof( Char *) ); if ( resultP ) { StrPrintF( resultP, "%s", dataP ); } return resultP;}/*********************************************************************** * FUNCTION: UserRecordToText * * DESCRIPTION: This routine creates a text representation of the * data of the given PalmDatabaseBuilder type. It's * up to YOU to handle types other than 'text'! * * RETURNED: pointer to the text representation. Caller must free. ***********************************************************************/Char *UserRecordToText( UInt32 type, // (in) type of data to be shown MemPtr dataP // (in) data to be shown){ Char *strP; switch( type ) { case 'text': strP = UserRecordToText_text( dataP ); break; /* * Your types go here... */ case 'mpoi': strP = UserRecordToText_mpoi( dataP ); break; case 0: strP = UserRecordToText_noType( dataP ); break; default: strP = MemPtrNew( ( StrLen( userNoTextStr ) + 1 ) * sizeof( Char *) ); if ( strP ) { StrCopy( strP, userNoTextStr ); } } return strP;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -