home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
pocketbk
/
utilsm
/
pelagn
/
AGN_READ.OPL
next >
Wrap
Text File
|
1995-01-02
|
13KB
|
337 lines
REM ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
REM ³ Pelican Software Inc. ³
REM ³ P.O.Box 741072 ³
REM ³ Houston, Tx. 77274-1072 ³
REM ³ 713 242-8928 (voice) ³
REM ³ 713 242-9573 (fax) ³
REM ³ ³
REM ³ Authors of Banker software for the Psion Series 3/3a ³
REM ³ This code is a gift to the Psion community and can be used ³
REM ³ in your own programs. ³
REM ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
Proc Main:
local agn$(128),ch%
global act%
screen 59,12,2,1
Actwin:
agn$="\agn\*.agn"
top::
ch%=1
guse act% :gvisible off :guse 1
dinit
dtext"","Open Agenda File",$302
dfile agn$,"",0
dchoice ch%,"Type to find","All,0 (Deleted),1 (Timed Day Entries),2 (Un-Timed Day Entries),3 (Anniversaries),4 (To-do Entries),Other"
if dialog=0 :return :endif
if ch%=7
dinit
dtext"","Enter Record Type to Find",$302
dchoice ch%,"Type:","0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
if dialog=0 :return :endif
ch%=ch%+1
endif
AgnEng:(agn$,ch%)
goto top
Endp
REM The following Globals represent the C type structures that are described
REM in the Agenda file format in the C SDK. The order that they are declared in
REM is very important and cannot be changed. Instead of reading a byte at a time
REM when we read the Agenda file, we will read a number of bytes starting at
REM the first byte of the struct, thereby filling the structure with the
REM appropriate data. The variable names closely describe the type of data
REM they hold. The number of bytes read in changes based on the record type
REM which is determined first. Different record types have a different
REM structure to the data, and thus the need for different sets of variables.
REM If you have trouble understanding this, look at the following:
REM
REM Type 1 record:
REM UWORD day daynum of the day on which the entry appears
REM UWORD time time - start of apptment. Minutes from Midnight
REM UBYTE attr flag for attributes of entry.
REM bit 00000001 - Once only (opposites are true if not set)
REM bit 00000010 - pending - not crossed out
REM bit 00000100 - displayed in Year view
REM bit 00001000 - No alarm
REM bit 00010000 - No memo
REM UBYTE code ASCII code for year symbol
REM UWORD dur duration of apptment in minutes (0-1459)
REM
REM The above shows that if we want to read a type 1 record, we should read in
REM 8 bytes to get the entire record details. From the attributes we can determine
REM whether or not the record has a memo attached. When we do our IOREAD for a
REM type 1 record, we use the global t1day% as the pointer to receive the eight
REM bytes of data, thereby filling our structure with appropriate data.
PROC AgnEng:(agnfile$,typ%)
global agn$(128),shead$(16),mode%,ret%,bufaddr%,buffer$(255),g%,rec%,pos%,match%
global acb%,toread%,err%,offset&,len%,type%
REM Type 1 structure
global t1day%,t1tim%,t1attr%,t1dur%,t1read%
REM Type 2 Structure
global t2day%,t2slot%,t2attr%,t2read%
REM Type 3 Structure
global t3day%,t3slot%,t3attr%,t3basyr%,t3disp%,t3read%
REM Type 4 Structure
global t4disp%,t4slot%,t4attr%,t4dat%,t4list%,t4order,t4read%
REM Attributes
global aonce%,apend%,ayear%,aNoAlm%,aNoMemo% REM attributes
REM Alarm structure
global pretime%,lensnd%(9)
REM Memo structure
global datalen%
global ch%,fl%
global xday&,yr%,mo%,dy%,hr%,mn%,sc%,yd%
global ampm$(3)
global typ$(16,32)
agn$=agnfile$ :ch%=typ%
typinit:
shead$="AgendaFileType"
t1read%=8 REM read 8 bytes if type1
t2read%=6 REM read 6 bytes if type2
t3read%=9
t4read%=14
load::
bufaddr%=addr(buffer$)+1
mode%=$0600 REM Existing file/Byte stream/Random access
if agnfile$=""
dinit
dtext"","Open Agenda File",$302
dfile agn$,"",0
dchoice ch%,"Type to find","All,0 (Deleted),1 (Timed Day Entries),2 (Un-Timed Day Entries),3 (Anniversaries),4 (To-do Entries)"
if dialog=0 :return :endif
endif
fl%=0 :if ch%<>1 :ch%=ch%-2 :fl%=1 :endif REM set type
toread%=14
err% = ioopen(acb%,agn$,mode%) REM acb%=handle agn$=filename mode%=read mode
if err%
alert(err$(err%))
return
endif
ret%=ioread(acb%,bufaddr%,14) REM read header into buffer
if ret%
pokeb bufaddr%-1,ret%
if buffer$<>shead$ REM check for legal header
alert("Not an Agenda File")
ioclose(acb%) :return REM close handle
endif
else
alert(err$(ret%))
ioclose(acb%) : return
endif
mode%=1 :offset&=32 REM go to the first record (byte 32)
busy"Reading records..."
REM ------ Get number of records in Agenda file -------
Do
ret%=ioseek(acb%,mode%,offset&)
if ret% < 0 REM handle error
goto loop
endif
ret%=ioread(acb%,addr(len%),2) REM first byte shows length of record
mode%=3
offset& = len% and &0000ffff REM get length byte
if ret%<0 :break :endif
if (offset& and $f000)/256/16=ch% or fl%=0
match%=match%+1 REM count matches
endif
offset& = (offset& and $0fff) REM TLV fields. Top four bits are type
rec%=rec%+1 REM bottom 12 bits = length
Until 0
REM ------- Done -----------------------------------------
guse act% :gvisible on :guse 1
mode%=1 :offset&=32 :pos%=0
loop::
busy off
Do
ret%=ioseek(acb%,mode%,offset&) REM Move to a spot in the .agn file
if ret% < 0 REM handle error
alert(err$(ret%))
ioclose(acb%)
return
endif
ret%=ioread(acb%,addr(len%),2) REM first byte shows length of record
mode%=3
pos%=pos%+1 REM increment record position ctr
offset& = len% and &0000ffff REM get length byte
if ret%<0 :break :endif
type% = (offset& and $f000)/256/16 REM set offset& to length of record
offset& = (offset& and $0fff)
if fl%
if type%<>ch% :continue :endif
endif
gcls :cls
Print "Agenda File: ",agn$
print "Matching: ",match%,"of",rec%
at 48,2
print "Record: ";pos%
print
gat 0,0 :ginvert 480,25
print "Record type: ",type%,typ$(type%+1)
print
if type%=1
ret%=ioread(acb%,addr(t1day%),t1read%) REM first byte in struct
offset&=offset&-t1read% REM subtract amount read in
Pday:(t1day%) REM from offset
Ptim:(t1tim%) REM t1day%,t1tim%,t1attr% have
Pattr:(t1attr%) REM appropriate data in them already
Pmess: REM Read title field
if aNoalm%=0 REM bit 3 not set means there is an alarm
Palm: REM Read alarm
endif
if aNoMemo%=0
Pmemo: REM Read the memo
endif
elseif type%=2
ret%=ioread(acb%,addr(t2day%),t2read%)
offset&=offset&-t2read%
Pday:(t2day%)
Pslot:(t2slot%)