home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / utilsm / pelagn / AGN_READ.OPL next >
Text File  |  1995-01-02  |  13KB  |  337 lines

  1. REM ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  2. REM ³                          Pelican Software Inc.                         ³
  3. REM ³                          P.O.Box 741072                                ³
  4. REM ³                          Houston, Tx. 77274-1072                       ³
  5. REM ³                          713 242-8928 (voice)                          ³
  6. REM ³                          713 242-9573 (fax)                            ³
  7. REM ³                                                                        ³
  8. REM ³           Authors of Banker software for the Psion Series 3/3a         ³
  9. REM ³           This code is a gift to the Psion community and can be used   ³
  10. REM ³           in your own programs.                                        ³
  11. REM ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  12.  
  13.  
  14. Proc Main:
  15. local agn$(128),ch%
  16. global act%
  17. screen 59,12,2,1
  18. Actwin:
  19. agn$="\agn\*.agn"
  20. top::
  21. ch%=1
  22. guse act% :gvisible off :guse 1
  23. dinit
  24. dtext"","Open Agenda File",$302
  25. dfile agn$,"",0
  26. dchoice ch%,"Type to find","All,0 (Deleted),1 (Timed Day Entries),2 (Un-Timed Day Entries),3 (Anniversaries),4 (To-do Entries),Other"
  27. if dialog=0 :return :endif
  28. if ch%=7
  29.         dinit
  30.         dtext"","Enter Record Type to Find",$302
  31.         dchoice ch%,"Type:","0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
  32.         if dialog=0 :return :endif
  33.         ch%=ch%+1
  34. endif
  35. AgnEng:(agn$,ch%)
  36. goto top
  37. Endp
  38.  
  39. REM  The following Globals represent the C type structures that are described
  40. REM  in the Agenda file format in the C SDK. The order that they are declared in
  41. REM  is very important and cannot be changed. Instead of reading a byte at a time
  42. REM  when we read the Agenda file, we will read a number of bytes starting at
  43. REM  the first byte of the struct, thereby filling the structure with the
  44. REM  appropriate data. The variable names closely describe the type of data
  45. REM  they hold. The number of bytes read in changes based on the record type
  46. REM  which is determined first. Different record types have a different
  47. REM  structure to the data, and thus the need for different sets of variables.
  48. REM  If you have trouble understanding this, look at the following:
  49. REM
  50. REM     Type 1 record:
  51. REM             UWORD day       daynum of the day on which the entry appears
  52. REM             UWORD time      time - start of apptment. Minutes from Midnight
  53. REM             UBYTE attr      flag for attributes of entry.
  54. REM                     bit 00000001 - Once only  (opposites are true if not set)
  55. REM                     bit 00000010 - pending - not crossed out
  56. REM                     bit 00000100 - displayed in Year view
  57. REM                     bit 00001000 - No alarm
  58. REM                     bit 00010000 - No memo
  59. REM             UBYTE code      ASCII code for year symbol
  60. REM             UWORD dur       duration of apptment in minutes (0-1459)
  61. REM
  62. REM  The above shows that if we want to read a type 1 record, we should read in
  63. REM  8 bytes to get the entire record details. From the attributes we can determine
  64. REM  whether or not the record has a memo attached. When we do our IOREAD for a
  65. REM  type 1 record, we use the global t1day% as the pointer to receive the eight
  66. REM  bytes of data, thereby filling our structure with appropriate data.
  67.  
  68.  
  69. PROC AgnEng:(agnfile$,typ%)
  70. global agn$(128),shead$(16),mode%,ret%,bufaddr%,buffer$(255),g%,rec%,pos%,match%
  71. global acb%,toread%,err%,offset&,len%,type%
  72.         REM Type 1 structure
  73. global t1day%,t1tim%,t1attr%,t1dur%,t1read%
  74.         REM Type 2 Structure
  75. global t2day%,t2slot%,t2attr%,t2read%
  76.         REM Type 3 Structure
  77. global t3day%,t3slot%,t3attr%,t3basyr%,t3disp%,t3read%
  78.         REM Type 4 Structure
  79. global t4disp%,t4slot%,t4attr%,t4dat%,t4list%,t4order,t4read%
  80.         REM Attributes
  81. global aonce%,apend%,ayear%,aNoAlm%,aNoMemo% REM attributes
  82.         REM Alarm structure
  83. global pretime%,lensnd%(9)
  84.         REM Memo structure
  85. global datalen%
  86. global ch%,fl%
  87. global xday&,yr%,mo%,dy%,hr%,mn%,sc%,yd%
  88. global ampm$(3)
  89. global typ$(16,32)
  90. agn$=agnfile$ :ch%=typ%
  91. typinit:
  92. shead$="AgendaFileType"
  93. t1read%=8       REM read 8 bytes if type1
  94. t2read%=6       REM read 6 bytes if type2
  95. t3read%=9
  96. t4read%=14
  97.  
  98. load::
  99. bufaddr%=addr(buffer$)+1
  100. mode%=$0600             REM  Existing file/Byte stream/Random access
  101. if agnfile$=""
  102.     dinit
  103.     dtext"","Open Agenda File",$302
  104.     dfile agn$,"",0
  105.     dchoice ch%,"Type to find","All,0 (Deleted),1 (Timed Day Entries),2 (Un-Timed Day Entries),3 (Anniversaries),4 (To-do Entries)"
  106.     if dialog=0 :return :endif
  107. endif
  108. fl%=0 :if ch%<>1 :ch%=ch%-2 :fl%=1 :endif       REM set type
  109. toread%=14
  110. err% = ioopen(acb%,agn$,mode%)                  REM acb%=handle agn$=filename   mode%=read mode
  111. if err%
  112.     alert(err$(err%))
  113.     return
  114. endif
  115.  
  116. ret%=ioread(acb%,bufaddr%,14)                   REM read header into buffer
  117. if ret%
  118.         pokeb bufaddr%-1,ret%
  119.         if buffer$<>shead$                      REM check for legal header
  120.         alert("Not an Agenda File")
  121.                 ioclose(acb%) :return           REM close handle
  122.     endif
  123. else
  124.     alert(err$(ret%))
  125.         ioclose(acb%) : return
  126. endif
  127.  
  128. mode%=1 :offset&=32                             REM go to the first record (byte 32)
  129. busy"Reading records..."
  130.  
  131. REM ------ Get number of records in Agenda file -------
  132. Do
  133.         ret%=ioseek(acb%,mode%,offset&)
  134.         if ret% < 0                             REM handle error
  135.                 goto loop
  136.         endif
  137.         ret%=ioread(acb%,addr(len%),2)          REM first byte shows length of record
  138.         mode%=3
  139.         offset& = len% and &0000ffff            REM get length byte
  140.         if ret%<0 :break :endif
  141.         if (offset& and $f000)/256/16=ch% or fl%=0
  142.                 match%=match%+1                 REM count matches
  143.         endif
  144.         offset& = (offset& and $0fff)           REM TLV fields. Top four bits are type
  145.         rec%=rec%+1                             REM bottom 12 bits = length
  146. Until 0
  147. REM ------- Done -----------------------------------------
  148. guse act% :gvisible on :guse 1
  149. mode%=1 :offset&=32 :pos%=0
  150. loop::
  151. busy off
  152. Do
  153.         ret%=ioseek(acb%,mode%,offset&)         REM Move to a spot in the .agn file
  154.         if ret% < 0                             REM handle error
  155.                 alert(err$(ret%))
  156.                 ioclose(acb%)
  157.                 return
  158.         endif
  159.         ret%=ioread(acb%,addr(len%),2)          REM first byte shows length of record
  160.         mode%=3
  161.         pos%=pos%+1                             REM increment record position ctr
  162.         offset& = len% and &0000ffff            REM get length byte
  163.         if ret%<0 :break :endif
  164.         type% = (offset& and $f000)/256/16      REM set offset& to length of record
  165.         offset& = (offset& and $0fff)
  166.         if fl%
  167.             if type%<>ch% :continue :endif
  168.         endif
  169.         gcls :cls
  170.         Print "Agenda File:  ",agn$
  171.         print "Matching:     ",match%,"of",rec%
  172.         at 48,2
  173.         print "Record: ";pos%
  174.         print
  175.         gat 0,0 :ginvert 480,25
  176.         print "Record type:  ",type%,typ$(type%+1)
  177.         print
  178.         if type%=1
  179.                 ret%=ioread(acb%,addr(t1day%),t1read%)  REM first byte in struct
  180.                 offset&=offset&-t1read%         REM subtract amount read in
  181.                 Pday:(t1day%)                   REM from offset
  182.                 Ptim:(t1tim%)                   REM t1day%,t1tim%,t1attr% have
  183.                 Pattr:(t1attr%)                 REM appropriate data in them already
  184.                 Pmess:                          REM Read title field
  185.                 if aNoalm%=0                    REM bit 3 not set means there is an alarm
  186.                         Palm:                   REM Read alarm
  187.                 endif
  188.                 if aNoMemo%=0
  189.                         Pmemo:                  REM Read the memo
  190.                 endif
  191.         elseif type%=2
  192.                 ret%=ioread(acb%,addr(t2day%),t2read%)
  193.                 offset&=offset&-t2read%
  194.                 Pday:(t2day%)
  195.                 Pslot:(t2slot%)
  196.