home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1B / DATAFILE_PDCD1B.iso / _pocketbk / pocketbook / 004 / isameg_zip / LIST.OPL < prev    next >
Text File  |  1994-08-02  |  4KB  |  128 lines

  1. /*
  2. Date:    9/11/93
  3.  
  4. Files required at runtime:
  5.     M:\ISAM.DYL
  6.     M:\DAT\DATA.DBF    database file
  7.  
  8. Shows a screen-full of records in alphabetical order that match the find 
  9. string instantly as it is typed in by the user.
  10. The editor only supports Esc and Delete editing keys.
  11. Initially the find string is set to "a" so all records beginning with "a"
  12. are listed.
  13.  
  14. This program illustrates ISAM usage only and should not be used as a 
  15. template for writing an application.
  16. */
  17.  
  18. #include <l_file.oph>
  19. #include <isam.opg>
  20.  
  21. PROC main:
  22.     GLOBAL isamCat%,pIsam%
  23.     LOCAL fDef$(34),keyDef$(66)
  24.     LOCAL i%,indexId%,l&,c%,len%,alen%,k%
  25.     LOCAL nRecs&,r&,f1$(255),f2$(255),p%(10),a$(255),d$(255),n%
  26.  
  27.     loadIsam:
  28.     creaIsam:
  29.     openData:("LOC::M:\DAT\DATA.DBF",FOPEN or FUPDATE)
  30.     len%=8
  31.     keyDef$=chr$(1)+chr$(0)+chr$(0)+chr$(0)
  32.     keyDef$=keyDef$+chr$(ISAM_FIELDTYPE_STRING)+chr$(ISAM_FIELDFLAG_ASCEND)
  33.     keyDef$=keyDef$+chr$(0)+chr$(len%)+chr$(ISAM_CONVERT_FOLD)+chr$(0)
  34.     send(pIsam%,O_IS_SET_KEYDEF,#0,#uAdd(addr(keyDef$),1))
  35.     indexId%=openIx%:("LOC::M:\DATA.BTX",FREPLACE or FUPDATE)
  36.     send(pIsam%,O_IS_IFLAGS,#indexId%,#ISAM_FLAG_ALLOWDUP,#ISAM_FLAG_ALLOWDUP)
  37.     print "Building index"
  38.     send(pIsam%,O_IS_IBUILD,#indexId%)
  39.     send(pIsam%,O_IS_ICOUNT,#indexId%,nRecs&)
  40.     gIPrint "Number of records="+num$(nRecs&,6)
  41.     a$=""
  42.     do
  43.         d$=a$
  44.         if a$="" :a$="A" :endif
  45.         alen%=len(a$)
  46.         cls
  47.         gAt 0,143
  48.         gBox 280,17
  49.         at 2,17 :print "Find:";d$,"     "
  50.         p%(1)=addr(a$)
  51.         p%(2)=0
  52.         c%=send(pIsam%,O_IS_IFIND,#indexId%,p%(1))
  53.         at 1,1
  54.         if c%=0 or c%=1
  55.             send(pIsam%,O_IS_GET_FIELD,#0,f1$,#ISAM_FIELDTYPE_STRING)
  56.             send(pIsam%,O_IS_GET_FIELD,#1,f2$,#ISAM_FIELDTYPE_STRING)
  57.             n%=0
  58.             while n%<13 and upper$(left$(f1$,alen%))=upper$(left$(a$,alen%))
  59.                 print f1$,":",f2$
  60.                 c%=send(pIsam%,O_IS_INEXT,#indexId%)
  61.                 if c%<0 :break :endif
  62.                 send(pIsam%,O_IS_GET_FIELD,#0,f1$,#ISAM_FIELDTYPE_STRING)
  63.                 send(pIsam%,O_IS_GET_FIELD,#1,f2$,#ISAM_FIELDTYPE_STRING)
  64.                 n%=n%+1
  65.             endwh
  66.             if n%=0
  67.                 print "Not found"
  68.             endif
  69.         else
  70.             print "Not found"
  71.         endif
  72.  
  73.         k%=get
  74.         if k%=27
  75.             a$=""
  76.         elseif k%=8
  77.             if a$<>""
  78.                 a$=left$(a$,len(a$)-1)
  79.             endif
  80.         else
  81.             if d$=""
  82.                 a$=chr$(k%)
  83.             else
  84.                 a$=a$+chr$(k%)
  85.             endif
  86.         endif
  87.     until 0
  88. ENDP
  89.  
  90. PROC pErr:(mess$,err%)
  91.     print mess$,"failed -",err$(err%)
  92.     get
  93.     stop
  94. ENDP
  95.  
  96. PROC loadIsam:
  97.     LOCAL c%
  98.  
  99.     c%=loadlib(isamCat%,"LOC::M:\ISAM.DYL",1)
  100.     if c%<0 : pErr:("Load ISAM.DYL",c%) :endif
  101. ENDP
  102.  
  103. PROC creaIsam:
  104.     pIsam%=newObjH(isamCat%,C_BTDBF)
  105.     send(pIsam%,O_IS_INIT,#4096,#0)
  106. ENDP
  107.  
  108. PROC openData:(name$,mode%)
  109.     LOCAL xName$(255),xMode%
  110.     LOCAL c%
  111.     
  112.     xName$=name$+chr$(0)    
  113.     xMode%=mode%
  114.     c%=enterSend(pIsam%,O_IS_DOPEN,#uAdd(addr(xName$),1),#xMode%)
  115.     if c%<0 :pErr:("Open data file",c%) :endif
  116. ENDP
  117.  
  118. PROC openIx%:(name$,mode%)
  119.     LOCAL xName$(255),xMode%
  120.     LOCAL c%
  121.  
  122.     xName$=name$+chr$(0)    
  123.     xMode%=mode%
  124.     c%=enterSend(pIsam%,O_IS_IOPEN,#uAdd(addr(xName$),1),#xMode%)
  125.     if c%<0 :pErr:("Open index file",c%) :endif
  126.     return c%
  127. ENDP
  128.