home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / MC2AGN.OPL < prev    next >
Text File  |  1992-08-26  |  4KB  |  218 lines

  1. rem !!!     Program to convert MC400 diary to Seies 3 Agenda file    !!!
  2.  
  3. rem ! Top level procedure
  4. proc mc2agn:
  5.     local dry$(130),agn$(130),off%(6),handle%,ret%,vb%
  6.  
  7.     dry$="\dry\*.dry"
  8.     agn$="\agn\.agn"
  9.     dInit "MC Diary Conversion V1.0"
  10.     dFile dry$,"MC diary:",0 :rem selector
  11.     dFile agn$,"To Series 3 file:",49 :rem editor,query existing
  12.         vb%=1
  13.         dChoice vb%,"Verbose","No,Yes"
  14.     if dialog=0 :return :endif
  15.     agn$=parse$(agn$,"\agn\.agn",off%())
  16.     if off%(6)
  17.         print "Wild cards not handled"
  18.         get
  19.         return
  20.     endif
  21.     if (off%(5)-off%(4))=0
  22.         agn$=parse$(agn$,dry$,off%())
  23.     endif
  24.     print "Converting",dry$
  25.     print "        to",agn$;"..."
  26.     ret%=acreate%:(agn$)
  27.     if showErr%:(ret%)
  28.         return
  29.     endif
  30.     ret%=dOpen%:(dry$)
  31.     if showErr%:(ret%)
  32.         goto tidy1
  33.     endif
  34.     ret%=convMc%:(vb%-1)
  35.     if     showErr%:(ret%)
  36.         goto tidy2
  37.     endif
  38. tidy2::
  39.     busy "Closing...",1,4
  40.     close   :rem close the MC diary
  41. tidy1::
  42.     busy "Closing...",1,4
  43.     close
  44.     busy off
  45.     if ret%
  46.         trap delete agn$
  47.     else
  48.         ret%=fixHead%:(agn$)
  49.         if ret%<0
  50.             print "Error fixing version in header"
  51.             showErr%:(ret%)
  52.         endif
  53.     endif
  54.     beep 5,200
  55.     print "Finished"
  56.     get
  57. endp
  58.  
  59. rem ! Fix version numbers in header from $110f to $100f at offset $11 and $15
  60. proc fixHead%:(name$)
  61.     local h%,ret%,off&,oneZero%,p%
  62.  
  63.     ret%=ioOpen(h%,name$,$0300)    :rem open for update and random access
  64.     if ret%<>0
  65.         return(ret%)
  66.     endif
  67.     off&=$11
  68.     ret%=ioSeek(h%,1,off&)
  69.     if ret%<0
  70.         goto closeIt
  71.     endif
  72.     oneZero%=$10
  73.     p%=addr(oneZero%)
  74.     ret%=ioWrite(h%,p%,1)
  75.     if ret%<0
  76.         goto closeIt
  77.     endif
  78.     off&=$15
  79.     ret%=ioSeek(h%,1,off&)
  80.     if ret%<0
  81.         goto closeIt
  82.     endif
  83.     ret%=ioWrite(h%,p%,1)
  84. closeIt::
  85.     ioclose(h%)
  86.     return ret%
  87. endp
  88.  
  89. rem ! Convert logical B (MC diary) to logical A (Series 3 Agenda)
  90. proc convMc%:(vb%)
  91.     local address%,ret%,l%,i&,pre%,badDate%,d1980&,d2049&,d&
  92.  
  93.     d1980&=days(1,1,1980)
  94.     d2049&=days(31,12,2049)
  95.     do
  96.         d&=b.i1%
  97.         if d&<0
  98.             d&=&10000+d&
  99.         endif
  100.         badDate%=(d&<d1980&) or (d&>d2049&)
  101.         if badDate% or vb%
  102.             print b.info$
  103.             gIPrint "Record "+num$(i&+1,8)
  104.             if badDate%
  105.                 beep 5,100
  106.                 print "WARNING: Record ignored",
  107.                 if d&<d1980&
  108.                     print "before 1980"
  109.                 else
  110.                     print "after 2049"
  111.                 endif
  112.                 print "Press any key to continue..."
  113.                 use b
  114.                 next
  115.                 get
  116.                 continue
  117.             else
  118.                 if key
  119.                     get
  120.                 endif
  121.             endif
  122.         endif
  123.         l%=len(b.info$)
  124.         if l%>64
  125.             print "Text length",l%,"exceeds 64 character maximum"
  126.             get
  127.         endif
  128.  
  129.         pre%=-1
  130.         if (b.i5% and 1)
  131.             pre%=1439-b.i4%
  132.         endif
  133.         use a
  134.         if b.i2% and $8000
  135.             aadd%:(b.i1%,b.i2% and $7fff,b.i3%,pre%,b.info$)
  136.         else
  137.             tadd%:(b.i1%,b.i2%,pre%,b.info$)
  138.         endif
  139.  
  140.         i&=i&+1
  141.         if ret%<0
  142.             print "Error appending record",i&
  143.             showErr%:(ret%)
  144.         endif
  145.         use b
  146.         next
  147.     until eof
  148. endp
  149.  
  150. proc showerr%:(err%)
  151.     if err%<0
  152.         print "Error",err%,err$(err%)
  153.         print "Press any key to continue..."
  154.         get
  155.         return(err%)
  156.     endif
  157.     return(0)
  158. endp
  159.  
  160. rem ! Procedure to create a Series 3 agenda dbf file
  161. proc acreate%:(name$)
  162.     trap delete name$
  163.     trap create name$,a,i1%,i2%,i3%,i4%,info$
  164.     return(err)
  165. endp
  166.  
  167. rem ! Procedure to open an MC400 diary dbf file
  168. proc dOpen%:(name$)
  169.  
  170.     trap open name$,b,i1%,i2%,i3%,i4%,i5%,info$
  171.     return(err)
  172. endp
  173.  
  174. rem ! Conversion subroutine to add a timed agenda entry
  175. proc aadd%:(dy%,tm%,dur%,pre%,i$)
  176.     rem dy% days since 1900
  177.     rem tm% minutes
  178.     rem dur%<(1440-tm%))
  179.     rem if pre%<0 then no alarm
  180.     rem len(i$)<=64
  181.  
  182.     a.i1%=dy%
  183.     a.i2%=dur%*2
  184.     a.i3%=tm%
  185.     a.i4%=-1
  186.     if (pre%<0)
  187.     a.i2%=a.i2%+1
  188.     else
  189.     a.i4%=pre%
  190.     endif
  191.     a.info$=i$
  192.     trap append
  193.     return err
  194. endp
  195.  
  196. rem ! Conversion subroutine to add an untimed agenda entry
  197. proc tadd%:(dy%,slot%,pre%,i$)
  198.     rem dy% days since 1900
  199.     rem slot% - notes key 0-N
  200.     rem if pre%<0 then no alarm
  201.     rem len(i$)<=64
  202.  
  203.     a.i1%=dy%
  204.     a.i2%=0
  205.     a.i3%=($8000 or (slot%+1))
  206.     a.i4%=-1
  207.     if (pre%<0)
  208.     a.i2%=a.i2%+1
  209.     else
  210.     a.i4%=pre%
  211.     endif
  212.     a.info$=i$
  213.     trap append
  214.     return err
  215. endp
  216.  
  217.  
  218.