home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 1B
/
DATAFILE_PDCD1B.iso
/
_pocketbk
/
pocketbook
/
004
/
oplexamp_z
/
ORG2AGN.OPL
< prev
next >
Wrap
Text File
|
1992-08-27
|
5KB
|
228 lines
rem !!! Program to convert Organiser II format diary to Series 3 Agenda file !!!
rem ! Top level procedure
proc org2agn:
local dry$(130),agn$(130),off%(6),handle%,ret%,vb%
dry$="\odb\*.odb"
agn$="\agn\.agn"
dInit "ORGII Diary Conversion V1.0"
dFile dry$,"OrgII diary file:",0 :rem selector
dFile agn$,"To Series 3 file:",49 :rem editor,query existing,allow null
vb%=1
dChoice vb%,"Verbose","No,Yes"
if dialog=0 :return :endif
agn$=parse$(agn$,"\agn\.agn",off%())
if off%(6)
print "Wild cards not handled"
get
return
endif
if (off%(5)-off%(4))=0
agn$=parse$(agn$,dry$,off%())
endif
print "Converting",dry$
print " to",agn$;"..."
ret%=acreate%:(agn$)
if showErr%:(ret%)
return
endif
ret%=dOpen%:(dry$,addr(handle%))
if ret%
goto tidy1
endif
ret%=conv%:(handle%,vb%-1)
if showErr%:(ret%)
goto tidy2
endif
tidy2::
ioClose(handle%)
tidy1::
busy "Closing...",1,4
close
busy off
if ret%
trap delete agn$
else
ret%=fixHead%:(agn$)
if ret%<0
print "Error fixing version in header"
showErr%:(ret%)
endif
endif
beep 5,200
print "Finished"
get
endp
rem ! Fix version numbers in header from $110f to $100f at offset $11 and $15
proc fixHead%:(name$)
local h%,ret%,off&,oneZero%,p%
ret%=ioOpen(h%,name$,$0300) :rem open for update and random access
if ret%<>0
return(ret%)
endif
off&=$11
ret%=ioSeek(h%,1,off&)
if ret%<0
goto closeIt
endif
oneZero%=$10
p%=addr(oneZero%)
ret%=ioWrite(h%,p%,1)
if ret%<0
goto closeIt
endif
off&=$15
ret%=ioSeek(h%,1,off&)
if ret%<0
goto closeIt
endif
ret%=ioWrite(h%,p%,1)
closeIt::
ioclose(h%)
return ret%
endp
rem ! Procedure to open a saved Organiser diary text file
proc dOpen%:(name$,pHand%)
local ret%,mode%
mode%= $0400 OR $0020 :rem open mode=$0000, text=$0020, share=$0400
ret%=ioOpen(#pHand%,name$,mode%)
if showErr%:(ret%)
return ret%
endif
return(0)
endp
proc conv%:(handle%,vb%)
local dy%,mt%,yr%,hh%,mm%,dur%,pre%,i$(64),txt$(255)
local address%,ret%,l%,i&,badDate%
address%=addr(txt$)
while 1
ret%=ioread(handle%,address%+1,255)
if ret%=0 :rem TO OVERCOME BUG: ^Z at eof gives never-ending file
:rem 0 length will never be generated by ORG diary
return(0)
endif
if ret%<0
if ret%<>-36 :rem if not eof
showErr%:(ret%)
endif
break
endif
pokeb address%,ret% :rem poke leading byte count of string variable
yr%=stoui%:(left$(txt$,4))
mt%=stoui%:(mid$(txt$,5,2))
dy%=stoui%:(mid$(txt$,7,2))
hh%=stoui%:(mid$(txt$,9,2))
mm%=stoui%:(mid$(txt$,11,2))
dur%=stoui%:(mid$(txt$,13,2))*15
pre%=stoui%:(mid$(txt$,15,2))-1
i$=mid$(txt$,18,255)
badDate%=(yr%<1980) or (yr%>2049)
if badDate% or vb%
print dy%;"/";mt%;"/";yr%,hh%;":";mm%
print " ";i$
gIPrint "Record "+num$(i&+1,8)
if badDate%
beep 5,100
print "WARNING: Record ignored",
if yr%<1980
print "before 1980"
else
print "after 2049"
endif
print "Press any key to continue..."
get
continue
else
if key
get
endif
endif
endif
l%=len(i$)
if l%>64
print "Text length",l%,"exceeds 64 character maximum"
get
endif
ret%=aadd%:(dy%,mt%,yr%,hh%,mm%,dur%,pre%,i$)
i&=i&+1
if ret%<0
print "Error appending record",i&
showErr%:(ret%)
endif
endwh
endp
rem ! Convert string to unsigned integer
proc stoui%:(inS$)
local ax%,bx%,cx%,dx%,si%,di%
local s$(255)
local flags%
s$=inS$+chr$(0)
cx%=10
si%=addr(s$)+1
ax%=$0500
flags%=os($8a,addr(ax%))
if (flags% and 1)
print "Error converting",ins$,"to unsigned int"
print "Flags=$";hex$(flags%)
showErr%:(ax% or $ff00)
raise ax%
else
return ax%
endif
endp
proc showerr%:(err%)
if err%<0
print "Error",err%,err$(err%)
print "Press any key to continue..."
get
return err%
endif
return 0
endp
rem ! Procedure to create an agenda dbf file
proc acreate%:(name$)
trap delete name$
trap create name$,a,i1%,i2%,i3%,i4%,info$
return err
endp
rem ! Conversion subroutine to add a timed agenda entry
proc aadd%:(dy%,mt%,yr%,hh%,mm%,dur%,pre%,i$)
rem dy%,mt%,yr% 1-31,1-12,1980-2049
rem hh%,mm% 0-23,0-59
rem dur%<(1440-(hh%*60+mm%))
rem pre% must be such that ((hh%*60+mm%)-pre%)>=0
rem if pre%<0 then no alarm
rem len(i$)<=64
local xd&,t%
xd&=days(dy%,mt%,yr%)
pokeB addr(t%),peekB(addr(xd&))
pokeB addr(t%)+1,peekB(addr(xd&)+1)
a.i1%=t%
a.i2%=dur%*2
a.i3%=hh%*60+mm%
a.i4%=-1
if (pre%<0)
a.i2%=a.i2%+1
else
a.i4%=1439-((hh%*60+mm%)-pre%)
endif
a.info$=i$
trap append
return err
endp