#include typedef unsigned char BOOL; typedef unsigned short WORD; typedef unsigned long DWORD; typedef unsigned char BYTE; typedef unsigned long tTime; typedef struct { unsigned char hours; unsigned char minutes; } TimeType; typedef struct { unsigned short year :7; // years since 1904 (MAC format) unsigned short month :4; unsigned short day :5; } DateType; #define CURRENT_VERSION 576 // the top 4 bits of the AppInfo flags are reserved for indexes into the 16 categories // which are saved in the prefs structure, so 'new' databases should have the top 4 bits always // 0 out #define INFOFLAGS_LOCKPWONEXIT 0x0001 #define INFOFLAGS_VIEWONLY 0x0002 #define INFOFLAGS_CATPRIV_LOCKED 0x0004 // the category and private record flags are 'locked' by another app for this db #define INFOFLAGS_STRUCTLOCK 0x0008 // structure locked - takes precedence over // INFOFLAGS_VIEWONLY if set #define INFOFLAGS_PRIVATEDB 0x0010 // instead of password, use the normal Palm Privacy settings // only first 8 bits should be used #define FLDTYPE_STRING 0x0001 // strlen + 1 (for null) bytes of data #define FLDTYPE_BOOLEAN 0x0002 // 1 byte of data #define FLDTYPE_DATE 0x0004 // 2 bytes DateType = 2 bytes #define FLDTYPE_INT 0x0008 // 4 byte ints #define FLDTYPE_FLOAT 0x0010 // maintained as a string type due to PalmOS floating point routine oddities #define FLDTYPE_TIME 0x0020 // 2 bytes (TimeType = 2 bytes) #define FLDTYPE_LIST 0x0040 // strlen + 1 (for null) bytes of data #define FLDTYPE_AUTODATE 0x0041 // 2 bytes DateType = 2 bytes #define FLDTYPE_AUTOTIME 0x0042 // 2 bytes (TimeType = 2 bytes) #define FLDTYPE_AUTOINC 0x0043 // 4 byte ints #define FLDTYPE_BINARY 0x0044 // variable length - always a 'hidden' field type #define FLDTYPE_RELLIST 0x0045 // not yet implemented #define FLDTYPE_CALC 0x0046 // not yet implemented // these are the top 8 bits of the fld type , which are reserved for options currently #define FLDOPT_PROTECTED 0x8000 // shown but not edited #define FLDOPT_HIDDEN 0x4000 // not visible to end user #define FLDOPT_CLEAR 0x00ff // mask for easy removal of above settings #define MAX_EXTRACHARDATA_LENGTH 10 #define MAX_TOTAL_POPUP_PER_LIST_LENGTH 2000 #define MAX_POPUP_ITEMS 100 #define MAX_POPUP_ITEM_LENGTH 25 #define MAX_DB_NAME_LENGTH 30 #define MAX_FIELDS 50 #define MAX_FIELD_NAME_LENGTH 20 #define MAIN_TABLE_ROWS 10 #define NEWDB_FIELD_ROWS 10 #define MAX_DATA_LENGTH 4000 #define NORMAL_DATA_LENGTH 50 #define MAX_TITLE_LENGTH 50 #define SHOWITEM_ROWS 11 #define SHOWITEM_TABLE_HEIGHT 122 #define SHOWDB_TABLE_ROWS 11 #define MAX_FIND_STRING 16 #define MAX_CATEGORY_NAME_LENGTH 15 #define MAX_CATEGORIES 16 #define MAX_RECORDS 32000 #define MAX_RECORD_LENGTH 10000 typedef struct { char fieldData[MAX_FIELDS][MAX_DATA_LENGTH]; // holds the data for each field int fieldLen[MAX_FIELDS]; } JBaseRecordType; typedef struct { char fieldNames[MAX_FIELDS][MAX_FIELD_NAME_LENGTH+1]; // holds the field names short fieldTypes[MAX_FIELDS]; short numFields; short version; short showDBColumnWidths[MAX_FIELDS]; short showDataWidth; short sort1Field; short sort2Field; short sort3Field; short findField; short filterField; char findString[MAX_FIND_STRING]; char filterString[MAX_FIND_STRING]; short flags; short firstColumnToShow; long fieldExtraData[MAX_FIELDS]; // increment counters, calculated field info etc long fieldExtraData2[MAX_FIELDS]; // increment counters, calculated field info etc char* popupLists; // any 'binary' data will follow this in the appinfo. // if there is a popup list it will end in 2 nulls // if there is no popuplist, there will be 4 nulls here // binary data can then follow this popup list data and will be of the following format // 2 bytes of length data for each length segment, followed by the data // continue this until a final 2 byte sequence of 0 0 } JFileAppInfoType; #define JFILEAPPINFOSIZE 1652 typedef struct { char sTitle[32]; // description of this collection WORD wAttr; // 8=request for backup WORD wVersion; tTime tCreated; tTime tModded; // in "seconds since Jan 1, 1970" tTime tLastHS; // time of last hotsync long dwRes0; long ofsAttributes; // long ofsCategories; // DWORD dwType; // 'Data' DWORD dwCreator; // 'dwDP' DWORD dwRes1; DWORD dwRes2; // reserved WORD nRecs; // number of records } tHeader; typedef struct { union { DWORD ofs; // on disk, file offset to this record char* pRec; // in ram, this is a pointer to the compressed data } rp; DWORD _id; // one byte with flags from kRec* above // merged with 3 bytes of unique ID } tRecEntry; WORD FlipWord(WORD wSubj); unsigned long SwapDWordToIntel(DWORD dwSubj); unsigned long SwapDWordToMotor(unsigned long dwSubj); int ReadJFileInfoFile(JFileAppInfoType* appInfo, FILE* info, char* popupListString, FILE * output); int FindJFileAppInfoSize(JFileAppInfoType* appInfo); int ReadInJFileAppInfo(JFileAppInfoType* appInfo, FILE* input, FILE* info); int TypeIsString(int t); int CSVToJFile(); int JFileToCSV(); void DecodeField(unsigned char* inData, char* outData, int type, int len); int ReadJFileInfoFileFieldTypesOnly(JFileAppInfoType * appInfo, FILE * info); void MessageBox2(char* lpszText, char* lpszCaption , unsigned int nType ); void MessageBox(char* lpszText, char* lpszCaption , unsigned int nType ); void showsynopsis(); void showversion(); char* basename(char* file); BOOL m_UseInfoFile; int m_CommaDelim; char PopupListString[10000]; JBaseRecordType tempRec; char m_CSVName[FILENAME_MAX]; char m_PDBName[FILENAME_MAX]; char m_PDBPath[FILENAME_MAX]; char m_CSVPath[FILENAME_MAX]; char m_InfoPath[FILENAME_MAX]; char m_DBName[FILENAME_MAX]; int m_IsCommandLine; int m_IsFirstConvert; char m_ProFileNameQ[500]; char m_OldFileNameQ[500]; char m_ProFileName[500]; char m_OldFileName[500]; int m_CommandLineComma; char delimChar;