[Trainsched-commit] trainsched selectform.c, 1.1, 1.2 selectform.h, 1.1, 1.2 timetable.c, 1.1, 1.2
Brought to you by:
philm
|
From: Steve M. <sma...@us...> - 2009-04-26 08:06:56
|
Update of /cvsroot/trainsched/trainsched In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv452 Modified Files: selectform.c selectform.h timetable.c timetable.h trainsched.c trainsched.h Log Message: Restored newline characters to Unix style. Index: selectform.h =================================================================== RCS file: /cvsroot/trainsched/trainsched/selectform.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** selectform.h 25 Apr 2009 16:14:10 -0000 1.1 --- selectform.h 26 Apr 2009 08:06:50 -0000 1.2 *************** *** 1,31 **** ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! ! /* to store Databases info */ ! typedef struct { ! char DBName[dmDBNameLength]; ! LocalID pdbid; ! UInt16 CardNo; ! } dbrowType; ! ! // Function Prototypes. ! Boolean selectFormEventHandler(EventPtr event); ! void LoadSelTable(FormPtr pForm, Boolean Update); ! void InitSelTable(FormPtr pForm); ! Err WriteDBData(const void *dataP, UInt32 *sizeP, void *userDataP); --- 1,31 ---- ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! ! /* to store Databases info */ ! typedef struct { ! char DBName[dmDBNameLength]; ! LocalID pdbid; ! UInt16 CardNo; ! } dbrowType; ! ! // Function Prototypes. ! Boolean selectFormEventHandler(EventPtr event); ! void LoadSelTable(FormPtr pForm, Boolean Update); ! void InitSelTable(FormPtr pForm); ! Err WriteDBData(const void *dataP, UInt32 *sizeP, void *userDataP); Index: selectform.c =================================================================== RCS file: /cvsroot/trainsched/trainsched/selectform.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** selectform.c 25 Apr 2009 16:14:10 -0000 1.1 --- selectform.c 26 Apr 2009 08:06:50 -0000 1.2 *************** *** 1,350 **** ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! #include <PalmOS.h> ! ! #include "trainsched.h" ! #include "selectform.h" ! ! // from trainsched.c ! void ResetPrefs(); ! ! // Global Variables ! Int16 ScrollSelectValue=0; ! MemHandle pdbarrayH=NULL; ! Int16 selpdbcount=0; ! ! // External veriables ! extern LocalID pdbid; ! extern UInt16 CardNo; ! extern char DBName[dmDBNameLength]; ! ! Boolean selectFormEventHandler(EventPtr event) ! { ! Boolean handled = false; ! FormPtr pForm = FrmGetActiveForm(); ! Int16 val, min, max, page; ! RectangleType r; ! TablePtr tableP; ! Int16 rowP, columnP; ! dbrowType *data; ! MemHandle TextH; ! ExgSocketType exgSocket; ! Err err = 0; ! ! switch (event->eType) { ! case frmOpenEvent: ! InitSelTable(pForm); ! // Fall through to the frmUpdateEvent. ! case frmUpdateEvent: ! FrmDrawForm(pForm); ! LoadSelTable(pForm, false); ! /* Draw the outline of the table */ ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! TblGetBounds(tableP, &r); ! WinDrawRectangleFrame( simpleFrame, &r ); ! handled = true; ! break; ! case sclRepeatEvent: ! ScrollSelectValue = event->data.sclRepeat.newValue; ! LoadSelTable(pForm, false); ! break; ! case ctlSelectEvent: ! switch (event->data.ctlSelect.controlID) { ! case selectFrmCancel: ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! FrmReturnToForm(0); ! handled = true; ! break; ! case selectFrmOKButton: ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! ! if (true == TblGetSelection(tableP, &rowP, &columnP)) { ! data = TblGetItemPtr (tableP, rowP, columnP); ! if (data) { ! ResetPrefs(); ! pdbid = data->pdbid; ! CardNo = data->CardNo; ! MemMove (DBName,data->DBName,dmDBNameLength); ! } ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! FrmUpdateForm(resFormMain, 0); ! FrmReturnToForm(0); ! } else { ! TextH = DmGetResource(strRsc, NO_SELECTION); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! } ! handled = true; ! break; ! case selectFrmBeamButton: ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! ! if (true == TblGetSelection(tableP, &rowP, &columnP)) { ! data = TblGetItemPtr (tableP, rowP, columnP); ! if (data) { ! MemSet(&exgSocket, sizeof(exgSocket),0); ! exgSocket.description = data->DBName; ! exgSocket.name = "trainsched.pdb"; ! ! err = ExgPut(&exgSocket); ! if (!err) { ! err = ExgDBWrite(WriteDBData, &exgSocket, data->DBName, data->pdbid, data->CardNo); ! err = ExgDisconnect(&exgSocket, err); ! } ! } ! } else { ! TextH = DmGetResource(strRsc, NO_SELECTION); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! } ! handled = true; ! break; ! case selectFrmDeleteButton: ! tableP = FrmGetObjectPtr(pForm, ! FrmGetObjectIndex(pForm,selectFrmTable)); ! if (true == TblGetSelection(tableP, &rowP, &columnP)) { ! data = TblGetItemPtr (tableP, rowP, columnP); ! if (data) { ! if ((pdbid == data->pdbid) && (CardNo == data->CardNo)) { ! TextH = DmGetResource(strRsc, NO_DELETE); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! } else { ! /* FIXME error handling on delete */ ! DmDeleteDatabase (data->CardNo, data->pdbid); ! LoadSelTable(pForm, false); ! } ! } ! } else { ! TextH = DmGetResource(strRsc, NO_SELECTION); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! TblUnhighlightSelection(tableP); ! } ! handled = true; ! break; ! default: ! break; ! } ! break; ! case keyDownEvent: ! if (event->data.keyDown.modifiers & commandKeyMask) { /* physical key */ ! if (event->data.keyDown.chr == chrPageUp) { ! SclGetScrollBar(FrmGetObjectPtr(pForm, ! FrmGetObjectIndex(pForm, selectFrmTableScrollBar)), ! &val, &min, &max, &page); ! if ( val >= min ) { ! if ((val - min) < page) ! ScrollSelectValue -= val - min; ! else ! ScrollSelectValue -= page; ! LoadSelTable(pForm, false); ! } ! handled = true; ! } else if (event->data.keyDown.chr == chrPageDown) { ! SclGetScrollBar(FrmGetObjectPtr(pForm, ! FrmGetObjectIndex(pForm, selectFrmTableScrollBar)), ! &val, &min, &max, &page); ! if (val < max) { ! if ((max - val) < page) ! ScrollSelectValue += max - val; ! else ! ScrollSelectValue += page; ! LoadSelTable(pForm, false); ! } ! handled = true; ! } ! } ! break; ! case appStopEvent: ! // Just to make sure we free memory (NB: don't mark as handled). ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! default: ! break; ! } ! return handled; ! } ! ! /* Draws items in selection table */ ! void SelTableDrawItem(void * table, Int16 row, Int16 column, ! RectanglePtr bounds ) ! { ! TablePtr tableP = (TablePtr)table; ! char str[dmDBNameLength]={0}; ! RectangleType rect; ! dbrowType *data; ! ! /* Erase previous label */ ! rect = *bounds; ! rect.topLeft.x += 1; ! rect.topLeft.y += 1; ! rect.extent.y -= 1; ! WinEraseRectangle( &rect, 0 ); ! ! data = TblGetItemPtr(tableP,row,column); ! ! if (data) StrCopy (str, data->DBName); ! ! /* Draw new label */ ! FntSetFont(stdFont); ! WinDrawChars(str, StrLen(str), bounds->topLeft.x+2, bounds->topLeft.y); ! } ! ! /* Initialize The selectForm Table */ ! void InitSelTable(FormPtr pForm) ! { ! TablePtr tableP; ! Int32 i; ! UInt16 numRows=0; ! ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! numRows = TblGetNumberOfRows(tableP); ! ! /* Setup the rows of the table */ ! for(i=0; i<numRows;i++) { ! TblSetItemStyle( tableP, i, SELECTCOL, customTableItem ); ! } ! ! /* Make sure the columns are usable - so they draw */ ! TblSetColumnUsable( tableP, SELECTCOL, true ); ! TblHasScrollBar( tableP, true ); ! ! /* Set our custom table item draw callback */ ! TblSetCustomDrawProcedure( tableP, SELECTCOL, SelTableDrawItem ); ! } ! ! /* Populates and draw selectForm table ! * Update : false if this is the first call, true for a refresh (scrolling...) ! */ ! void LoadSelTable(FormPtr pForm, Boolean Update) ! { ! TablePtr tableP; ! Int16 i=0, j=0, oldscrollvalue=0; ! UInt16 numRows=0; ! Boolean newSearch = true; ! DmSearchStateType searchState; ! UInt16 CardNo; ! LocalID dbID; ! char name[dmDBNameLength]; ! dbrowType *pdbarrayP = NULL; ! ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! numRows = TblGetNumberOfRows(tableP); ! ! oldscrollvalue = ScrollSelectValue; ! ! if (Update == false) { ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! ! /* let's count how many databases we have in memory */ ! while (0 == DmGetNextDatabaseByTypeCreator(newSearch, &searchState, ! PDBTYPE, CREATORID, ! false, &CardNo, &dbID)) { ! selpdbcount++; ! newSearch=false; ! } ! ! if (selpdbcount > 0) { ! pdbarrayH = MemHandleNew(selpdbcount * sizeof(dbrowType)); ! pdbarrayP=MemHandleLock(pdbarrayH); ! ! newSearch = true; ! selpdbcount=0; ! while (0 == DmGetNextDatabaseByTypeCreator(newSearch, &searchState, ! PDBTYPE, CREATORID, ! false, &CardNo, &dbID)) { ! newSearch=false; ! ! DmDatabaseInfo(CardNo, dbID, name, NULL, NULL, NULL, NULL, NULL, ! NULL, NULL, NULL, NULL, NULL); ! ! MemMove(pdbarrayP[selpdbcount].DBName, name, dmDBNameLength); ! pdbarrayP[selpdbcount].CardNo = CardNo; ! pdbarrayP[selpdbcount].pdbid = dbID; ! ! selpdbcount++; ! } ! } ! } else { ! pdbarrayP=MemHandleLock(pdbarrayH); ! } ! ! /* avoid scrolling too much */ ! if ((selpdbcount - ScrollSelectValue) < numRows) { ! if (selpdbcount > numRows) { ! ScrollSelectValue = selpdbcount-numRows; ! } else { ! ScrollSelectValue = 0; ! } ! } ! ! i=j=0; ! while ((i < selpdbcount) && (j < numRows)) { ! if ((i < ScrollSelectValue) || (i > (ScrollSelectValue+numRows))) { ! pdbarrayP++; ! } else { ! TblSetItemPtr(tableP,j,SELECTCOL,(dbrowType*)pdbarrayP++); ! TblSetRowUsable(tableP, j, true); ! j++; ! } ! i++; ! } ! ! if (j < numRows) { ! while (j < numRows) { ! TblSetRowUsable(tableP, j, false); ! j++; ! } ! } ! ! SclSetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, ! selectFrmTableScrollBar)), ! oldscrollvalue, /* current value */ ! 0, /* min */ ! selpdbcount >= numRows ? selpdbcount-numRows+1 : 0, /*max*/ ! numRows-1 ); /* page size */ ! ! TblEraseTable(tableP); ! TblDrawTable(tableP); ! } ! ! /* Callback to ExgDBWrite for beaming */ ! Err WriteDBData(const void *dataP, UInt32 *sizeP, void *userDataP) ! { ! Err err; ! ! *sizeP = ExgSend((ExgSocketPtr)userDataP, (void*)dataP, *sizeP, &err); ! return err; ! } --- 1,350 ---- ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! #include <PalmOS.h> ! ! #include "trainsched.h" ! #include "selectform.h" ! ! // from trainsched.c ! void ResetPrefs(); ! ! // Global Variables ! Int16 ScrollSelectValue=0; ! MemHandle pdbarrayH=NULL; ! Int16 selpdbcount=0; ! ! // External veriables ! extern LocalID pdbid; ! extern UInt16 CardNo; ! extern char DBName[dmDBNameLength]; ! ! Boolean selectFormEventHandler(EventPtr event) ! { ! Boolean handled = false; ! FormPtr pForm = FrmGetActiveForm(); ! Int16 val, min, max, page; ! RectangleType r; ! TablePtr tableP; ! Int16 rowP, columnP; ! dbrowType *data; ! MemHandle TextH; ! ExgSocketType exgSocket; ! Err err = 0; ! ! switch (event->eType) { ! case frmOpenEvent: ! InitSelTable(pForm); ! // Fall through to the frmUpdateEvent. ! case frmUpdateEvent: ! FrmDrawForm(pForm); ! LoadSelTable(pForm, false); ! /* Draw the outline of the table */ ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! TblGetBounds(tableP, &r); ! WinDrawRectangleFrame( simpleFrame, &r ); ! handled = true; ! break; ! case sclRepeatEvent: ! ScrollSelectValue = event->data.sclRepeat.newValue; ! LoadSelTable(pForm, false); ! break; ! case ctlSelectEvent: ! switch (event->data.ctlSelect.controlID) { ! case selectFrmCancel: ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! FrmReturnToForm(0); ! handled = true; ! break; ! case selectFrmOKButton: ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! ! if (true == TblGetSelection(tableP, &rowP, &columnP)) { ! data = TblGetItemPtr (tableP, rowP, columnP); ! if (data) { ! ResetPrefs(); ! pdbid = data->pdbid; ! CardNo = data->CardNo; ! MemMove (DBName,data->DBName,dmDBNameLength); ! } ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! FrmUpdateForm(resFormMain, 0); ! FrmReturnToForm(0); ! } else { ! TextH = DmGetResource(strRsc, NO_SELECTION); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! } ! handled = true; ! break; ! case selectFrmBeamButton: ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! ! if (true == TblGetSelection(tableP, &rowP, &columnP)) { ! data = TblGetItemPtr (tableP, rowP, columnP); ! if (data) { ! MemSet(&exgSocket, sizeof(exgSocket),0); ! exgSocket.description = data->DBName; ! exgSocket.name = "trainsched.pdb"; ! ! err = ExgPut(&exgSocket); ! if (!err) { ! err = ExgDBWrite(WriteDBData, &exgSocket, data->DBName, data->pdbid, data->CardNo); ! err = ExgDisconnect(&exgSocket, err); ! } ! } ! } else { ! TextH = DmGetResource(strRsc, NO_SELECTION); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! } ! handled = true; ! break; ! case selectFrmDeleteButton: ! tableP = FrmGetObjectPtr(pForm, ! FrmGetObjectIndex(pForm,selectFrmTable)); ! if (true == TblGetSelection(tableP, &rowP, &columnP)) { ! data = TblGetItemPtr (tableP, rowP, columnP); ! if (data) { ! if ((pdbid == data->pdbid) && (CardNo == data->CardNo)) { ! TextH = DmGetResource(strRsc, NO_DELETE); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! } else { ! /* FIXME error handling on delete */ ! DmDeleteDatabase (data->CardNo, data->pdbid); ! LoadSelTable(pForm, false); ! } ! } ! } else { ! TextH = DmGetResource(strRsc, NO_SELECTION); ! FrmCustomAlert(alertDialog1, (char*) MemHandleLock(TextH), " ", " "); ! MemHandleUnlock(TextH); ! DmReleaseResource(TextH); ! TblUnhighlightSelection(tableP); ! } ! handled = true; ! break; ! default: ! break; ! } ! break; ! case keyDownEvent: ! if (event->data.keyDown.modifiers & commandKeyMask) { /* physical key */ ! if (event->data.keyDown.chr == chrPageUp) { ! SclGetScrollBar(FrmGetObjectPtr(pForm, ! FrmGetObjectIndex(pForm, selectFrmTableScrollBar)), ! &val, &min, &max, &page); ! if ( val >= min ) { ! if ((val - min) < page) ! ScrollSelectValue -= val - min; ! else ! ScrollSelectValue -= page; ! LoadSelTable(pForm, false); ! } ! handled = true; ! } else if (event->data.keyDown.chr == chrPageDown) { ! SclGetScrollBar(FrmGetObjectPtr(pForm, ! FrmGetObjectIndex(pForm, selectFrmTableScrollBar)), ! &val, &min, &max, &page); ! if (val < max) { ! if ((max - val) < page) ! ScrollSelectValue += max - val; ! else ! ScrollSelectValue += page; ! LoadSelTable(pForm, false); ! } ! handled = true; ! } ! } ! break; ! case appStopEvent: ! // Just to make sure we free memory (NB: don't mark as handled). ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! default: ! break; ! } ! return handled; ! } ! ! /* Draws items in selection table */ ! void SelTableDrawItem(void * table, Int16 row, Int16 column, ! RectanglePtr bounds ) ! { ! TablePtr tableP = (TablePtr)table; ! char str[dmDBNameLength]={0}; ! RectangleType rect; ! dbrowType *data; ! ! /* Erase previous label */ ! rect = *bounds; ! rect.topLeft.x += 1; ! rect.topLeft.y += 1; ! rect.extent.y -= 1; ! WinEraseRectangle( &rect, 0 ); ! ! data = TblGetItemPtr(tableP,row,column); ! ! if (data) StrCopy (str, data->DBName); ! ! /* Draw new label */ ! FntSetFont(stdFont); ! WinDrawChars(str, StrLen(str), bounds->topLeft.x+2, bounds->topLeft.y); ! } ! ! /* Initialize The selectForm Table */ ! void InitSelTable(FormPtr pForm) ! { ! TablePtr tableP; ! Int32 i; ! UInt16 numRows=0; ! ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! numRows = TblGetNumberOfRows(tableP); ! ! /* Setup the rows of the table */ ! for(i=0; i<numRows;i++) { ! TblSetItemStyle( tableP, i, SELECTCOL, customTableItem ); ! } ! ! /* Make sure the columns are usable - so they draw */ ! TblSetColumnUsable( tableP, SELECTCOL, true ); ! TblHasScrollBar( tableP, true ); ! ! /* Set our custom table item draw callback */ ! TblSetCustomDrawProcedure( tableP, SELECTCOL, SelTableDrawItem ); ! } ! ! /* Populates and draw selectForm table ! * Update : false if this is the first call, true for a refresh (scrolling...) ! */ ! void LoadSelTable(FormPtr pForm, Boolean Update) ! { ! TablePtr tableP; ! Int16 i=0, j=0, oldscrollvalue=0; ! UInt16 numRows=0; ! Boolean newSearch = true; ! DmSearchStateType searchState; ! UInt16 CardNo; ! LocalID dbID; ! char name[dmDBNameLength]; ! dbrowType *pdbarrayP = NULL; ! ! tableP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,selectFrmTable)); ! numRows = TblGetNumberOfRows(tableP); ! ! oldscrollvalue = ScrollSelectValue; ! ! if (Update == false) { ! if (pdbarrayH) { ! MemHandleFree(pdbarrayH); ! pdbarrayH = NULL; ! } ! ! /* let's count how many databases we have in memory */ ! while (0 == DmGetNextDatabaseByTypeCreator(newSearch, &searchState, ! PDBTYPE, CREATORID, ! false, &CardNo, &dbID)) { ! selpdbcount++; ! newSearch=false; ! } ! ! if (selpdbcount > 0) { ! pdbarrayH = MemHandleNew(selpdbcount * sizeof(dbrowType)); ! pdbarrayP=MemHandleLock(pdbarrayH); ! ! newSearch = true; ! selpdbcount=0; ! while (0 == DmGetNextDatabaseByTypeCreator(newSearch, &searchState, ! PDBTYPE, CREATORID, ! false, &CardNo, &dbID)) { ! newSearch=false; ! ! DmDatabaseInfo(CardNo, dbID, name, NULL, NULL, NULL, NULL, NULL, ! NULL, NULL, NULL, NULL, NULL); ! ! MemMove(pdbarrayP[selpdbcount].DBName, name, dmDBNameLength); ! pdbarrayP[selpdbcount].CardNo = CardNo; ! pdbarrayP[selpdbcount].pdbid = dbID; ! ! selpdbcount++; ! } ! } ! } else { ! pdbarrayP=MemHandleLock(pdbarrayH); ! } ! ! /* avoid scrolling too much */ ! if ((selpdbcount - ScrollSelectValue) < numRows) { ! if (selpdbcount > numRows) { ! ScrollSelectValue = selpdbcount-numRows; ! } else { ! ScrollSelectValue = 0; ! } ! } ! ! i=j=0; ! while ((i < selpdbcount) && (j < numRows)) { ! if ((i < ScrollSelectValue) || (i > (ScrollSelectValue+numRows))) { ! pdbarrayP++; ! } else { ! TblSetItemPtr(tableP,j,SELECTCOL,(dbrowType*)pdbarrayP++); ! TblSetRowUsable(tableP, j, true); ! j++; ! } ! i++; ! } ! ! if (j < numRows) { ! while (j < numRows) { ! TblSetRowUsable(tableP, j, false); ! j++; ! } ! } ! ! SclSetScrollBar(FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, ! selectFrmTableScrollBar)), ! oldscrollvalue, /* current value */ ! 0, /* min */ ! selpdbcount >= numRows ? selpdbcount-numRows+1 : 0, /*max*/ ! numRows-1 ); /* page size */ ! ! TblEraseTable(tableP); ! TblDrawTable(tableP); ! } ! ! /* Callback to ExgDBWrite for beaming */ ! Err WriteDBData(const void *dataP, UInt32 *sizeP, void *userDataP) ! { ! Err err; ! ! *sizeP = ExgSend((ExgSocketPtr)userDataP, (void*)dataP, *sizeP, &err); ! return err; ! } Index: trainsched.h =================================================================== RCS file: /cvsroot/trainsched/trainsched/trainsched.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** trainsched.h 25 Apr 2009 16:14:10 -0000 1.10 --- trainsched.h 26 Apr 2009 08:06:50 -0000 1.11 *************** *** 1,76 **** ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! ! /************************************************************************** ! * Resources ! **************************************************************************/ ! /* Main Form */ ! #define resFormMain 1000 ! ! #define resTimeTable 1001 ! #define resTableScrollBar 1002 ! #define resFromList 1003 ! #define resFromTrigger 1004 ! #define resToList 1005 ! #define resToTrigger 1006 ! #define resDayList 1007 ! #define resDayTrigger 1008 ! #define resReverseBtn 1009 ! #define resTimeTable3c 1010 ! ! /* Menu */ ! #define MainFormMenuBar 2000 ! #define MainOptionsAboutCmd 2001 ! #define MainOptionsSelectCmd 2002 ! #define MainOptionsAbbreviations 2003 ! ! /* About dialog */ ! #define aboutForm 1100 ! #define aboutFormOkButton 1101 ! #define aboutBitmap 1102 ! ! /* Database selection dialog */ ! #define selectForm 1200 ! #define selectFrmTable 1201 ! #define selectFrmTableScrollBar 1202 ! #define selectFrmBeamButton 1203 ! #define selectFrmDeleteButton 1204 ! #define selectFrmOKButton 1205 ! #define selectFrmCancel 1206 ! ! /* Alert Dialog */ ! #define alertDialog1 1300 ! #define alertAbbreviations 1306 ! #define NO_PDB 1301 ! #define NO_SELECTION 1302 ! #define NO_DELETE 1303 ! #define NOT_IMPL 1304 ! ! /* Constants */ ! #define SHOWMAX 10 ! #define NOSELECTION 100 ! #define FROMCOL 0 ! #define TOCOL 1 ! #define INFOCOL 2 ! #define SELECTCOL 0 ! ! #define PREFAPPVERSION 2 ! #define CREATORID 'TRSC' ! #define PDBTYPE 'DATA' ! --- 1,76 ---- ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! ! /************************************************************************** ! * Resources ! **************************************************************************/ ! /* Main Form */ ! #define resFormMain 1000 ! ! #define resTimeTable 1001 ! #define resTableScrollBar 1002 ! #define resFromList 1003 ! #define resFromTrigger 1004 ! #define resToList 1005 ! #define resToTrigger 1006 ! #define resDayList 1007 ! #define resDayTrigger 1008 ! #define resReverseBtn 1009 ! #define resTimeTable3c 1010 ! ! /* Menu */ ! #define MainFormMenuBar 2000 ! #define MainOptionsAboutCmd 2001 ! #define MainOptionsSelectCmd 2002 ! #define MainOptionsAbbreviations 2003 ! ! /* About dialog */ ! #define aboutForm 1100 ! #define aboutFormOkButton 1101 ! #define aboutBitmap 1102 ! ! /* Database selection dialog */ ! #define selectForm 1200 ! #define selectFrmTable 1201 ! #define selectFrmTableScrollBar 1202 ! #define selectFrmBeamButton 1203 ! #define selectFrmDeleteButton 1204 ! #define selectFrmOKButton 1205 ! #define selectFrmCancel 1206 ! ! /* Alert Dialog */ ! #define alertDialog1 1300 ! #define alertAbbreviations 1306 ! #define NO_PDB 1301 ! #define NO_SELECTION 1302 ! #define NO_DELETE 1303 ! #define NOT_IMPL 1304 ! ! /* Constants */ ! #define SHOWMAX 10 ! #define NOSELECTION 100 ! #define FROMCOL 0 ! #define TOCOL 1 ! #define INFOCOL 2 ! #define SELECTCOL 0 ! ! #define PREFAPPVERSION 2 ! #define CREATORID 'TRSC' ! #define PDBTYPE 'DATA' ! Index: timetable.h =================================================================== RCS file: /cvsroot/trainsched/trainsched/timetable.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** timetable.h 25 Apr 2009 16:14:10 -0000 1.1 --- timetable.h 26 Apr 2009 08:06:50 -0000 1.2 *************** *** 1,38 **** ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! #define STATIONRECORD 0 ! #define DAYRECORD 1 ! #define OFFSETRECORD 2 ! ! #define STATIONMAXNUM 30 ! #define STATIONMAXLENGTH 20 ! #define DAYMAXLENGTH 9 ! #define MAX_ABBREVIATIONS 40 ! ! #define ABBR_PDB 'ABBR' ! ! // Function prototypes ! Int16 getStationNames(DmOpenRef pdbfd); ! Boolean getAbbreviationsDefined(); ! UInt16 getNumberOfRecords(); ! void getAbbreviations(); ! Int16 getDays(DmOpenRef pdbfd); ! Int16 getOffsets(DmOpenRef pdbfd); ! Int16 getTime(DmOpenRef pdbfd, UInt16 recNum, Int8 station); ! Int16 getAbbrev(DmOpenRef pdbfd, UInt16 recNum); --- 1,38 ---- ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! #define STATIONRECORD 0 ! #define DAYRECORD 1 ! #define OFFSETRECORD 2 ! ! #define STATIONMAXNUM 30 ! #define STATIONMAXLENGTH 20 ! #define DAYMAXLENGTH 9 ! #define MAX_ABBREVIATIONS 40 ! ! #define ABBR_PDB 'ABBR' ! ! // Function prototypes ! Int16 getStationNames(DmOpenRef pdbfd); ! Boolean getAbbreviationsDefined(); ! UInt16 getNumberOfRecords(); ! void getAbbreviations(); ! Int16 getDays(DmOpenRef pdbfd); ! Int16 getOffsets(DmOpenRef pdbfd); ! Int16 getTime(DmOpenRef pdbfd, UInt16 recNum, Int8 station); ! Int16 getAbbrev(DmOpenRef pdbfd, UInt16 recNum); Index: trainsched.c =================================================================== RCS file: /cvsroot/trainsched/trainsched/trainsched.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** trainsched.c 25 Apr 2009 16:14:10 -0000 1.24 --- trainsched.c 26 Apr 2009 08:06:50 -0000 1.25 *************** *** 1,798 **** ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, [...1582 lines suppressed...] ! seconds = TimGetSeconds(); ! dateTimeP = MemPtrNew(sizeof(DateTimeType)); ! TimSecondsToDateTime(seconds,dateTimeP); ! ! len = StrLen(DBName); ! if(len>31) len = 31; /* bad hack */ ! ! StrNCopy(FormTitle,DBName,len); ! StrCat(FormTitle," "); ! ! asctime=MemPtrNew(10); ! TimeToAscii(dateTimeP->hour,dateTimeP->minute,tfColon24h,asctime); ! ! StrCat(FormTitle,asctime); ! ! FrmSetTitle(pForm,FormTitle); ! ! MemPtrFree(asctime); ! MemPtrFree(dateTimeP); ! } Index: timetable.c =================================================================== RCS file: /cvsroot/trainsched/trainsched/timetable.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** timetable.c 25 Apr 2009 16:14:10 -0000 1.1 --- timetable.c 26 Apr 2009 08:06:50 -0000 1.2 *************** *** 1,313 **** ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! #include <PalmOS.h> ! ! #include "timetable.h" ! #include "trainsched.h" ! ! extern char StationNames[STATIONMAXNUM][STATIONMAXLENGTH+1]; ! extern char DayNames[7][DAYMAXLENGTH+1]; ! extern UInt16 OffsetList[14]; ! extern UInt16 numstations,numdays; ! extern char Abbreviations[MAX_ABBREVIATIONS][10]; ! extern char szAbbreviations[300]; ! ! UInt16 NumRecords=0; ! Boolean abbrevDefined; ! ! /* ! * Get the Station Names. This function sets the global variables StationNames ! * and numstations for the current timetable database. If the variables were ! * successfully initialised then true is returned. If there was a problem ! * accessing the database then false is returned. ! */ ! Int16 getStationNames(DmOpenRef pdbfd) ! { ! char *recordP; ! MemHandle rec_mh; ! UInt16 recPos; ! UInt16 strPos; ! Int16 result = false; ! ! MemSet (StationNames, sizeof(StationNames), 0); ! numstations=0; ! abbrevDefined=false; ! ! // Get number of records in database. ! NumRecords = DmNumRecords(pdbfd); ! ! if (NumRecords > STATIONRECORD) ! { ! // populate StationNames from database. ! rec_mh = DmQueryRecord(pdbfd,STATIONRECORD); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! recPos = 0; ! strPos = 0; ! while (recordP[recPos] != '\0') { ! if(recordP[recPos] == '\t') { ! StationNames[numstations][strPos]='\0'; ! numstations++; ! strPos=0; ! } else { ! StationNames[numstations][strPos]=recordP[recPos]; ! strPos++; ! } ! recPos++; ! } ! StationNames[numstations][strPos]='\0'; ! numstations++; ! ! // release lock on record. ! MemHandleUnlock(rec_mh); ! result = true; // We successfully read the record. ! ! // Special case if last Station name is DUMMY, it is the abbreviations column. ! if (StrNCompare("DUMMY", StationNames[numstations-1], 5) == 0) { ! abbrevDefined=true; ! numstations--; ! } ! } ! } ! return result; ! } ! ! /* ! * Determines whether or not the current database contains abbreviations. ! * This will only be valid after the StationNames have been retrieved for the ! * first time. ! * Returns true if abbreviations are present. ! */ ! Boolean getAbbreviationsDefined() ! { ! return abbrevDefined; ! } ! ! /* ! * Determine the total number of records in the timetable database. ! * This will only be valid after the StationNames have been retrieved for the ! * first time. ! */ ! UInt16 getNumberOfRecords() ! { ! return NumRecords; ! } ! ! /* ! * Get the Abbreviations. This function sets the global variable Abbreviations ! * either from a defined database, or default values if the database does not exist. ! */ ! void getAbbreviations() ! { ! DmOpenRef hAbbrevDb; ! DmSearchStateType searchState; ! UInt16 nNumRecords, uCardNum; ! Int16 i, strLen; ! LocalID lID; ! MemHandle hAbbrevRec; ! uCardNum = 0; ! ! // See if there is an Abbreviations Database. ! if (0 == DmGetNextDatabaseByTypeCreator(true, &searchState, ABBR_PDB, CREATORID, false, &uCardNum, &lID)) ! { ! // Yes, load the defined Abbreviations from it. ! hAbbrevDb = DmOpenDatabase(uCardNum, lID, dmModeReadOnly); ! if (hAbbrevDb != 0) ! { ! hAbbrevRec = DmQueryRecord(hAbbrevDb, 0); ! StrCopy(szAbbreviations, MemHandleLock(hAbbrevRec)); ! MemHandleUnlock(hAbbrevRec); ! /* Convert '|' to '\n'. */ ! strLen = StrLen(szAbbreviations); ! for (i=0; i<strLen; i++) ! if (szAbbreviations[i] == '|') szAbbreviations[i] = '\n'; ! ! nNumRecords = DmNumRecords(hAbbrevDb); ! /* Read in the abbreviations. */ ! for (i=1; i<=MAX_ABBREVIATIONS; i++) ! { ! /* Default to an empty string. */ ! StrCopy(Abbreviations[i], ""); ! ! /* Ensure index is in range because some releases will */ ! /* display fatal error message if DmQueryRecords() called */ ! /* an out-of-range record number. */ ! if (i <= nNumRecords) ! { ! hAbbrevRec = DmQueryRecord(hAbbrevDb, i); ! if (hAbbrevRec != NULL) ! { ! StrCopy(Abbreviations[i], MemHandleLock(hAbbrevRec)); ! MemHandleUnlock(hAbbrevRec); ! } ! } ! } ! } ! } ! else ! { ! // No Abbreviations DB, use default values. ! StrCopy( szAbbreviations, "EWD = Mon to Sat\nM-F = Monday to Friday\nT-F = Tuesday to Friday\nMO/WO/FO/SO = Mon/Wed/Fri/Sat only\nWX/FX = Except Wed/Fri\nFSX = Fri/Sat excluded\nFSO = Fri/Sat only\nM-TH = Mon to Thurs" ); ! ! for (i=1; i<=MAX_ABBREVIATIONS; i++) StrCopy(Abbreviations[i], ""); ! StrCopy(Abbreviations[1], "EWD"); ! StrCopy(Abbreviations[2], "M-F"); ! StrCopy(Abbreviations[3], "FO"); ! StrCopy(Abbreviations[4], "SO"); ! StrCopy(Abbreviations[5], "T-F"); ! StrCopy(Abbreviations[6], "MO"); ! StrCopy(Abbreviations[7], "WO"); ! StrCopy(Abbreviations[8], "WX"); ! StrCopy(Abbreviations[9], "FX"); ! StrCopy(Abbreviations[10], "FSX"); ! StrCopy(Abbreviations[11], "FSO"); ! StrCopy(Abbreviations[12], "M-TH"); ! } ! } ! ! /* ! * Get the Days. This function sets the global variables DayNames ! * and numdays for the current timetable database. If the variables were ! * successfully initialised then true is returned. If there was a problem ! * accessing the database then false is returned. ! */ ! Int16 getDays(DmOpenRef pdbfd) ! { ! MemHandle rec_mh; ! char *recordP; ! UInt16 recPos; ! UInt16 strPos; ! Int16 result = false; ! ! MemSet (DayNames, sizeof(DayNames), 0); ! numdays=0; ! ! // Get number of records in database. ! NumRecords = DmNumRecords(pdbfd); ! ! if (NumRecords > DAYRECORD) ! { ! // populate DayList from database. ! rec_mh = DmQueryRecord(pdbfd,DAYRECORD); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! recPos=0; ! strPos=0; ! while (recordP[recPos] != '\0') { ! if(recordP[recPos] == '\t') { ! DayNames[numdays][strPos]='\0'; ! numdays++; ! strPos=0; ! } else { ! DayNames[numdays][strPos] = recordP[recPos]; ! strPos++; ! } ! recPos++; ! } ! DayNames[numdays][strPos]='\0'; ! numdays++; ! ! // release lock on record. ! MemHandleUnlock(rec_mh); ! result = true; ! } ! } ! return result; ! } ! ! /* ! * Get the Offsets for the start of each timetable entry. This function sets ! * the global variable Offsets for the current timetable database. If the ! * variable was successfully initialised then true is returned. If there was a ! * problem accessing the database then false is returned. ! */ ! Int16 getOffsets(DmOpenRef pdbfd) ! { ! MemHandle rec_mh; ! char *recordP; ! Int16 offsetNo; ! Int16 result = false; ! ! // Get number of records in database. ! NumRecords = DmNumRecords(pdbfd); ! ! if (NumRecords > OFFSETRECORD) ! { ! // get offset for directions and days from database. ! rec_mh = DmQueryRecord(pdbfd, OFFSETRECORD); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! ! for(offsetNo=0; offsetNo<(numdays*2); offsetNo++) ! OffsetList[offsetNo] = (recordP[(offsetNo*2)+1] & 0xFF) | (recordP[offsetNo*2] << 8); ! ! // release lock on record. ! MemHandleUnlock(rec_mh); ! ! result = true; ! } ! } ! return result; ! } ! ! /* ! * Get the time for a given timetable entry and station. Returns time as a ! * signed number (e.g. 07:45 = 745). -1 indicates no time for given station. ! */ ! Int16 getTime(DmOpenRef pdbfd, UInt16 recNum, Int8 station) ! { ! MemHandle rec_mh; ! char *recordP; ! Int16 time = -1; ! ! rec_mh = DmQueryRecord(pdbfd, recNum); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! time = (recordP[(station*2)+1] & 0xFF) | (recordP[station*2] << 8); ! MemHandleUnlock(rec_mh); ! } ! return time; ! } ! ! /* ! * Get the abbreviation entry number for a given timetable entry. Will return ! * 0 if the database does not support abbreviations. ! */ ! Int16 getAbbrev(DmOpenRef pdbfd, UInt16 recNum) ! { ! MemHandle rec_mh; ! char *recordP; ! Int16 abbrev = 0; ! ! if (abbrevDefined) ! { ! rec_mh = DmQueryRecord(pdbfd, recNum); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! abbrev = (recordP[(numstations*2)+1] & 0xFF) | (recordP[numstations*2] << 8); ! MemHandleUnlock(rec_mh); ! } ! } ! return abbrev; } \ No newline at end of file --- 1,313 ---- ! /* Trainsched.c - display train schedule on Palm Pilot ! * (C) 2001 Philippe Marzouk <ph...@us...> ! */ ! /* ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! */ ! #include <PalmOS.h> ! ! #include "timetable.h" ! #include "trainsched.h" ! ! extern char StationNames[STATIONMAXNUM][STATIONMAXLENGTH+1]; ! extern char DayNames[7][DAYMAXLENGTH+1]; ! extern UInt16 OffsetList[14]; ! extern UInt16 numstations,numdays; ! extern char Abbreviations[MAX_ABBREVIATIONS][10]; ! extern char szAbbreviations[300]; ! ! UInt16 NumRecords=0; ! Boolean abbrevDefined; ! ! /* ! * Get the Station Names. This function sets the global variables StationNames ! * and numstations for the current timetable database. If the variables were ! * successfully initialised then true is returned. If there was a problem ! * accessing the database then false is returned. ! */ ! Int16 getStationNames(DmOpenRef pdbfd) ! { ! char *recordP; ! MemHandle rec_mh; ! UInt16 recPos; ! UInt16 strPos; ! Int16 result = false; ! ! MemSet (StationNames, sizeof(StationNames), 0); ! numstations=0; ! abbrevDefined=false; ! ! // Get number of records in database. ! NumRecords = DmNumRecords(pdbfd); ! ! if (NumRecords > STATIONRECORD) ! { ! // populate StationNames from database. ! rec_mh = DmQueryRecord(pdbfd,STATIONRECORD); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! recPos = 0; ! strPos = 0; ! while (recordP[recPos] != '\0') { ! if(recordP[recPos] == '\t') { ! StationNames[numstations][strPos]='\0'; ! numstations++; ! strPos=0; ! } else { ! StationNames[numstations][strPos]=recordP[recPos]; ! strPos++; ! } ! recPos++; ! } ! StationNames[numstations][strPos]='\0'; ! numstations++; ! ! // release lock on record. ! MemHandleUnlock(rec_mh); ! result = true; // We successfully read the record. ! ! // Special case if last Station name is DUMMY, it is the abbreviations column. ! if (StrNCompare("DUMMY", StationNames[numstations-1], 5) == 0) { ! abbrevDefined=true; ! numstations--; ! } ! } ! } ! return result; ! } ! ! /* ! * Determines whether or not the current database contains abbreviations. ! * This will only be valid after the StationNames have been retrieved for the ! * first time. ! * Returns true if abbreviations are present. ! */ ! Boolean getAbbreviationsDefined() ! { ! return abbrevDefined; ! } ! ! /* ! * Determine the total number of records in the timetable database. ! * This will only be valid after the StationNames have been retrieved for the ! * first time. ! */ ! UInt16 getNumberOfRecords() ! { ! return NumRecords; ! } ! ! /* ! * Get the Abbreviations. This function sets the global variable Abbreviations ! * either from a defined database, or default values if the database does not exist. ! */ ! void getAbbreviations() ! { ! DmOpenRef hAbbrevDb; ! DmSearchStateType searchState; ! UInt16 nNumRecords, uCardNum; ! Int16 i, strLen; ! LocalID lID; ! MemHandle hAbbrevRec; ! uCardNum = 0; ! ! // See if there is an Abbreviations Database. ! if (0 == DmGetNextDatabaseByTypeCreator(true, &searchState, ABBR_PDB, CREATORID, false, &uCardNum, &lID)) ! { ! // Yes, load the defined Abbreviations from it. ! hAbbrevDb = DmOpenDatabase(uCardNum, lID, dmModeReadOnly); ! if (hAbbrevDb != 0) ! { ! hAbbrevRec = DmQueryRecord(hAbbrevDb, 0); ! StrCopy(szAbbreviations, MemHandleLock(hAbbrevRec)); ! MemHandleUnlock(hAbbrevRec); ! /* Convert '|' to '\n'. */ ! strLen = StrLen(szAbbreviations); ! for (i=0; i<strLen; i++) ! if (szAbbreviations[i] == '|') szAbbreviations[i] = '\n'; ! ! nNumRecords = DmNumRecords(hAbbrevDb); ! /* Read in the abbreviations. */ ! for (i=1; i<=MAX_ABBREVIATIONS; i++) ! { ! /* Default to an empty string. */ ! StrCopy(Abbreviations[i], ""); ! ! /* Ensure index is in range because some releases will */ ! /* display fatal error message if DmQueryRecords() called */ ! /* an out-of-range record number. */ ! if (i <= nNumRecords) ! { ! hAbbrevRec = DmQueryRecord(hAbbrevDb, i); ! if (hAbbrevRec != NULL) ! { ! StrCopy(Abbreviations[i], MemHandleLock(hAbbrevRec)); ! MemHandleUnlock(hAbbrevRec); ! } ! } ! } ! } ! } ! else ! { ! // No Abbreviations DB, use default values. ! StrCopy( szAbbreviations, "EWD = Mon to Sat\nM-F = Monday to Friday\nT-F = Tuesday to Friday\nMO/WO/FO/SO = Mon/Wed/Fri/Sat only\nWX/FX = Except Wed/Fri\nFSX = Fri/Sat excluded\nFSO = Fri/Sat only\nM-TH = Mon to Thurs" ); ! ! for (i=1; i<=MAX_ABBREVIATIONS; i++) StrCopy(Abbreviations[i], ""); ! StrCopy(Abbreviations[1], "EWD"); ! StrCopy(Abbreviations[2], "M-F"); ! StrCopy(Abbreviations[3], "FO"); ! StrCopy(Abbreviations[4], "SO"); ! StrCopy(Abbreviations[5], "T-F"); ! StrCopy(Abbreviations[6], "MO"); ! StrCopy(Abbreviations[7], "WO"); ! StrCopy(Abbreviations[8], "WX"); ! StrCopy(Abbreviations[9], "FX"); ! StrCopy(Abbreviations[10], "FSX"); ! StrCopy(Abbreviations[11], "FSO"); ! StrCopy(Abbreviations[12], "M-TH"); ! } ! } ! ! /* ! * Get the Days. This function sets the global variables DayNames ! * and numdays for the current timetable database. If the variables were ! * successfully initialised then true is returned. If there was a problem ! * accessing the database then false is returned. ! */ ! Int16 getDays(DmOpenRef pdbfd) ! { ! MemHandle rec_mh; ! char *recordP; ! UInt16 recPos; ! UInt16 strPos; ! Int16 result = false; ! ! MemSet (DayNames, sizeof(DayNames), 0); ! numdays=0; ! ! // Get number of records in database. ! NumRecords = DmNumRecords(pdbfd); ! ! if (NumRecords > DAYRECORD) ! { ! // populate DayList from database. ! rec_mh = DmQueryRecord(pdbfd,DAYRECORD); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! recPos=0; ! strPos=0; ! while (recordP[recPos] != '\0') { ! if(recordP[recPos] == '\t') { ! DayNames[numdays][strPos]='\0'; ! numdays++; ! strPos=0; ! } else { ! DayNames[numdays][strPos] = recordP[recPos]; ! strPos++; ! } ! recPos++; ! } ! DayNames[numdays][strPos]='\0'; ! numdays++; ! ! // release lock on record. ! MemHandleUnlock(rec_mh); ! result = true; ! } ! } ! return result; ! } ! ! /* ! * Get the Offsets for the start of each timetable entry. This function sets ! * the global variable Offsets for the current timetable database. If the ! * variable was successfully initialised then true is returned. If there was a ! * problem accessing the database then false is returned. ! */ ! Int16 getOffsets(DmOpenRef pdbfd) ! { ! MemHandle rec_mh; ! char *recordP; ! Int16 offsetNo; ! Int16 result = false; ! ! // Get number of records in database. ! NumRecords = DmNumRecords(pdbfd); ! ! if (NumRecords > OFFSETRECORD) ! { ! // get offset for directions and days from database. ! rec_mh = DmQueryRecord(pdbfd, OFFSETRECORD); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! ! for(offsetNo=0; offsetNo<(numdays*2); offsetNo++) ! OffsetList[offsetNo] = (recordP[(offsetNo*2)+1] & 0xFF) | (recordP[offsetNo*2] << 8); ! ! // release lock on record. ! MemHandleUnlock(rec_mh); ! ! result = true; ! } ! } ! return result; ! } ! ! /* ! * Get the time for a given timetable entry and station. Returns time as a ! * signed number (e.g. 07:45 = 745). -1 indicates no time for given station. ! */ ! Int16 getTime(DmOpenRef pdbfd, UInt16 recNum, Int8 station) ! { ! MemHandle rec_mh; ! char *recordP; ! Int16 time = -1; ! ! rec_mh = DmQueryRecord(pdbfd, recNum); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! time = (recordP[(station*2)+1] & 0xFF) | (recordP[station*2] << 8); ! MemHandleUnlock(rec_mh); ! } ! return time; ! } ! ! /* ! * Get the abbreviation entry number for a given timetable entry. Will return ! * 0 if the database does not support abbreviations. ! */ ! Int16 getAbbrev(DmOpenRef pdbfd, UInt16 recNum) ! { ! MemHandle rec_mh; ! char *recordP; ! Int16 abbrev = 0; ! ! if (abbrevDefined) ! { ! rec_mh = DmQueryRecord(pdbfd, recNum); ! if (rec_mh) ! { ! recordP = MemHandleLock(rec_mh); ! abbrev = (recordP[(numstations*2)+1] & 0xFF) | (recordP[numstations*2] << 8); ! MemHandleUnlock(rec_mh); ! } ! } ! return abbrev; } \ No newline at end of file |