home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / MISC / HYPOC / IMPDATA.OPL < prev    next >
Encoding:
Text File  |  1994-08-24  |  12.0 KB  |  270 lines

  1. app hyperpoc
  2. enda
  3. rem ---------------------------------
  4. proc impdata%:(par$)
  5. rem ---------------------------------
  6. rem
  7. rem  impdata% reads records from the PSION database.
  8. rem     When called at card open time fields from the record found
  9. rem     are displayed in the card area.
  10. rem     When called at object activation time it reads the same record
  11. rem     and offers the phone numbers contained in the record for dialling.
  12. rem  par$ is a chr$(13) separated list with the following items:
  13. rem     1. Search string (can contain wild cards)
  14. rem     2. Data File name (can be short name)
  15. rem     3. Occurence (the n-th matching record is displayed)
  16. rem     4. List of up to 16 fields to be displayed (e.g. 1,3-5,7)
  17. rem        (Phone numbers are extracted on activation from the 
  18. rem         first 32 fields of the record regardless of this list).
  19. rem
  20. rem  a special edparm routine (see below) supports the definition
  21. rem  of imported objects during card definition
  22. rem
  23.  
  24. rem variables
  25. local r%,p%,i%,k%,j%,u%,px%,py%,pw%,ph%,y%,fil$(128),srch$(50),fl$(50),occur&,h%,buf$(255),abuf&,p&,l%,s%,pk%
  26. local flds%(16),s$(255),t$(255),off%(6),inf%(32),phone$(6,24),lab$(6,10),pn%,tw%,mxw%
  27.  
  28. onerr err1
  29.  
  30. rem analyze parameter string
  31.         abuf& = (int(addr(buf$)) and &00ffff) : rem make save pointer
  32.         r% = loc(par$,chr$(13))
  33.         srch$ = mid$(par$,1,r%-1)
  34.         p% = r%
  35.         r% = loc(right$(par$,len(par$)-p%),chr$(13))
  36.         fil$ = mid$(par$,p%+1,r%-1)
  37.         p% = p%+r%
  38.         r% = loc(right$(par$,len(par$)-p%),chr$(13))
  39.         occur& = val(mid$(par$,p%+1,r%-1))
  40.         fl$ = right$(par$,len(par$)-p%-r%)
  41.         fil$ = parse$(fil$,"LOC::M:\DAT\*.DBF",off%())
  42.         if onAct%       rem activated
  43. rem get label information from DBF file
  44.                 r% = ioopen(h%,fil$,$200)
  45.                 if r% < 0 : raise r% : endif
  46.                 r% = ioread(h%,abuf&+1,20)                 rem read File Header
  47.                 if r% < 0 : raise r% : endif
  48.                 p& = peekw(abuf&+19)                      rem position of first record
  49.                 pokeb abuf&,15                             rem set signature length
  50.                 if buf$ <> "OPLDatabaseFile" : raise -109 : endif
  51.                 while 1
  52.                         r% = ioseek(h%,1,p&)            rem to first record
  53.                         if r% < 0 : break : endif
  54.                         r% = ioread(h%,abuf&,2)  rem length byte and tag
  55.                         if r% < 0 : break : endif
  56.                         l% = peekw(abuf&)
  57.                         if (l% and $f000) = $3000            rem Skip instruction
  58.                                 p& = p&+2                    rem Just ignore it
  59.                         elseif (l% and $f000) <> $4000
  60.                                 p& = p& + (l% and $0fff) + 2    rem ignore any other record
  61.                         else                                rem Start of labels
  62.                                 l% = l% and $0fff            rem total length of labels
  63.                                 while l% > 0 and i% < 6
  64.                                         r% = ioread(h%,abuf&,1)  rem label length byte
  65.                                         if r% < 0 : break : endif
  66.                                         s% = peekb(abuf&)
  67.                                         pn% = pn%+1                     rem field number
  68.                                         if s%
  69.                                                 r% = ioread(h%,abuf&+1,s%) rem read label
  70.                                                 if r% < 0 : break : endif
  71.                                                 if asc(buf$) = 5        rem label contains phone symbol
  72.                                                         i% = i%+1
  73.                                                         lab$(i%) = left$(right$(buf$,len(buf$)-1),10)
  74.                                                         flds%(i%) = pn%
  75.                                                         if i% = 6 : break : endif
  76.                                                 endif
  77.                                         endif
  78.                                         l% = l% - s% - 1
  79.                                 endwh
  80.                                 break
  81.                         endif
  82.                 endwh
  83.                 ioclose(h%)
  84.         else    
  85. rem get default print area
  86.                 px% = gx
  87.                 py% = gy
  88.                 pw% = ObjW%+ObjX%-px%
  89.                 ph% = ObjH%+ObjY%-py%
  90. rem process rest of parameter string
  91.                 i% = 0
  92.                 while j% < 16 and i% < 16
  93.                         i% = i%+1
  94.                         t$ = extract$:(fl$,i%)
  95.                         if len(t$)
  96.                                 r% = loc(t$,"-") rem range specification
  97.                                 if r%
  98.                                         u% = val(left$(t$,r%-1))
  99.                                         r% = val(right$(t$,len(t$)-r%))
  100.                                         while u% <= r% and j% < 16
  101.                                                 j% = j%+1
  102.                                                 flds%(j%) = u%
  103.                                                 u% = u%+1
  104.                                         endwh
  105.                                 else
  106.                                         j% = j%+1
  107.                                         flds%(j%) = val(t$)
  108.                                 endif
  109.                         endif
  110.                 endwh
  111. rem set field default numbers
  112.                 if j% = 0
  113.                         flds%(1) = 1 : flds%(2) = 2 : flds%(3) = 3 : flds%(4) = 4
  114.                 endif
  115.         endif
  116. rem open file
  117.         open fil$,b,f1$,f2$,f3$,f4$,f5$,f6$,f7$,f8$,f9$,f10$,f11$,f12$,f13$,f14$,f15$,f16$,f17$,f18$,f19$,f20$,f21$,f22$,f23$,f24$,f25$,f26$,f27$,f28$,f29$,f30$,f31$,f32$
  118. rem find record
  119.         while 1
  120.                 if find("*"+srch$+"*") = 0
  121.                         close
  122.                         return
  123.                 endif
  124.                 if occur& = 1 : break : endif
  125.                 occur& = occur& - 1
  126.                 next
  127.         endwh
  128. rem initialize display
  129.         if onAct%
  130.                 lock on
  131.                 dinit "Dial"
  132.         else
  133.                 gfont trfont%:(-1) : gstyle 0 : gtmode 3 : rem illegal value for trfont% returns stack default font.
  134.                 y% = py%+1
  135.                 ginfo inf%()
  136.         endif
  137. rem process fields
  138.         while k% < 16 and ( y% < py%+ph%-1 or onAct% )
  139.                 k% = k%+1
  140.                 j% = flds%(k%)
  141.                 if j% > 0 and j% <= 32
  142.                         vector j%
  143.                         j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12,j13,j14,j15,j16,j17,j18,j19,j20,j21,j22,j23,j24,j25,j26,j27,j28,j29,j30,j31,j32
  144.                         endv
  145. j1::
  146.                         s$ = b.f1$
  147. j0::
  148.                         while len(s$)
  149.                                 r% = loc(s$,chr$(21))  rem find line breaks
  150.                                 if r%
  151.                                         t$ = left$(s$,r%-1)
  152.                                         s$ = right$(s$,len(s$)-r%)
  153.                                 else
  154.                                         t$ = s$ : s$ = ""
  155.                                 endif
  156.                                 if onAct%
  157.                                         if pk% = 4 : break : endif
  158.                                         pk% = pk% + 1
  159.                                         phone$(pk%) = strip$:(t$)       rem collect phone numbers
  160.                                         dedit phone$(pk%),lab$(k%)      rem build dialog box
  161.                                 else
  162.                                         if y% >= py%+ph%-1 : break : endif
  163.                                         tw% = min(pw%-4,gtwidth(t$))
  164.                                         if tw% > mxw%
  165.                                                 gat px%+mxw%+2,py%
  166.                                                 gfill tw%-mxw%,y%-py%,1 rem extend print area
  167.                                                 mxw% = tw%
  168.                                         else
  169.                                                 tw% = mxw%
  170.                                         endif
  171.                                         y% = y% + inf%(3)               rem character height
  172.                                         gat px%+2,y%
  173.                                         gprintclip(t$,tw%)              rem print line
  174.                                 endif
  175.                         endwh
  176.                         continue
  177. j2::                    s$ = b.f2$ : goto j0
  178. j3::                    s$ = b.f3$ : goto j0
  179. j4::                    s$ = b.f4$ : goto j0
  180. j5::                    s$ = b.f5$ : goto j0
  181. j6::                    s$ = b.f6$ : goto j0
  182. j7::                    s$ = b.f7$ : goto j0
  183. j8::                    s$ = b.f8$ : goto j0
  184. j9::                    s$ = b.f9$ : goto j0
  185. j10::                   s$ = b.f10$ : goto j0
  186. j11::                   s$ = b.f11$ : goto j0
  187. j12::                   s$ = b.f12$ : goto j0
  188. j13::                   s$ = b.f13$ : goto j0
  189. j14::                   s$ = b.f14$ : goto j0
  190. j15::                   s$ = b.f15$ : goto j0
  191. j16::                   s$ = b.f16$ : goto j0
  192. j17::                   s$ = b.f17$ : goto j0
  193. j18::                   s$ = b.f18$ : goto j0
  194. j19::                   s$ = b.f19$ : goto j0
  195. j20::                   s$ = b.f20$ : goto j0
  196. j21::                   s$ = b.f21$ : goto j0
  197. j22::                   s$ = b.f22$ : goto j0
  198. j23::                   s$ = b.f23$ : goto j0
  199. j24::                   s$ = b.f24$ : goto j0
  200. j25::                   s$ = b.f25$ : goto j0
  201. j26::                   s$ = b.f26$ : goto j0
  202. j27::                   s$ = b.f27$ : goto j0
  203. j28::                   s$ = b.f28$ : goto j0
  204. j29::                   s$ = b.f29$ : goto j0
  205. j30::                   s$ = b.f30$ : goto j0
  206. j31::                   s$ = b.f31$ : goto j0
  207. j32::                   s$ = b.f32$ : goto j0
  208.                 endif
  209.         endwh
  210.         close
  211.         if onAct%
  212.                 if pk% = 0 : return : endif : rem no phone number found
  213.                 i% = 1
  214.                 if pk% > 1
  215.                         i% = dialog - 1         rem Unfortunately we have to use 2 steps
  216.                         if i% <= 0 : return : endif
  217.                         dinit tx$:(104) : rem "Dial"
  218.                         dedit phone$(i%),tx$:(105) : rem "Phone number"
  219.                 endif
  220.                 dbuttons tx$:(106),-27,tx$:(104),9,tx$:(107),13 : rem "Cancel" "Dial" "Dial out"
  221.                 r% = dialog
  222.                 if r%
  223.                         dial:(phone$(i%),(r%=13))
  224.                 endif
  225.         else
  226.                 gat px%,py%
  227.                 gborder 0,mxw%+3,y%-py%+1
  228.         endif
  229.         return
  230. err1::
  231.         r% = err
  232.         ioclose(h%)
  233.         trap use b              rem make sure we are talking to dbf file
  234.         if err = 0
  235.                 trap close      rem close dbf file
  236.         endif
  237.         return r%
  238. endp
  239.  
  240. rem edParm$: supports the editing process for impdata objects.
  241.  
  242. proc edParm$:(parm$)
  243. local r%,p%,off%(6),srch$(50),fil$(128),fl$(50),occur&
  244.         if len(parm$)
  245.                 r% = loc(parm$,chr$(13))
  246.                 srch$ = mid$(parm$,1,r%-1)
  247.                 p% = r%
  248.                 r% = loc(right$(parm$,len(parm$)-p%),chr$(13))
  249.                 fil$ = mid$(parm$,p%+1,r%-1)
  250.                 p% = p%+r%
  251.                 r% = loc(right$(parm$,len(parm$)-p%),chr$(13))
  252.                 occur& = val(mid$(parm$,p%+1,r%-1))
  253.                 fl$ = right$(parm$,len(parm$)-p%-r%)
  254.         else
  255.                 occur& = 1
  256.                 fil$ = "M:\DAT\DATA"
  257.                 fl$ = "1-4"
  258.         endif
  259.         fil$ = parse$(fil$,"LOC::M:\DAT\*.DBF",off%())
  260.         dinit tx$:(169) : rem "Import database record"
  261.         dfile fil$,tx$:(170),16 : rem "Data"
  262.         dedit srch$,tx$:(144) : rem "Search string"
  263.         dlong occur&,tx$:(171),1,32 : rem "Occurence"
  264.         dedit fl$,tx$:(172) : rem "Fields displayed"
  265.         dialog
  266.         fil$ = parse$(fil$,"",off%())
  267.         return srch$+chr$(13)+mid$(fil$,off%(2),off%(5)-off%(2))+chr$(13)+num$(occur&,2)+chr$(13)+fl$
  268. endp
  269.  
  270.