home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / FOXPRO / TABLES / TBLSRC / TBLINIT.PRG < prev    next >
Text File  |  1992-11-13  |  3KB  |  106 lines

  1. * Program   :TblInit.prg
  2. * Author    :Mark D. Miller
  3. * Date      :12-Nov-1992
  4. * Notice    : Copyright (c) 12-Nov-1992 by Mark D. Miller
  5. *             All Rights Reserved.
  6. * Notes     :The table initialization routines for individual tables
  7. *
  8. * The includes
  9. *
  10. #include table.hdr
  11. #include string.hdr
  12. #include fileio.hdr
  13. #include pick.hdr
  14. #include colors.hdr
  15. #include io.hdr
  16. #include warn.hdr
  17. *
  18. * FORCE externs
  19. *
  20. VARDEF  EXTERN
  21.     byte        __color_std
  22. ENDDEF
  23. *
  24. * Global Table Memory
  25. *
  26. VARDEF
  27.     CHAR( 12 )  OpenTableName
  28.     CHAR( 40 )  TblPath                 && This var only needs to be here
  29.     FILE        OpenTableHandle
  30.     UINT        TableCnt, TableCnt2, TableKy
  31.     LONG        DataList, KeyList
  32.     INT         TableType
  33.     INT         TableIdx
  34. ENDDEF
  35. *...
  36. *                   T H E    R O U T I N E S                          *
  37. *...
  38. * Function  :InitTable
  39. * Date      :11-Nov-1992
  40. * Parameters:Name           Name of the table file to initialize
  41. *           :
  42. * Return Val:.T.            Initialization successfull
  43. *           :.F.            Initialization failed
  44. * Notes     :This routine opens and reads the specified table file into
  45. *            pick lists for field processing.
  46. *
  47. FUNCTION LOGICAL InitTable
  48.     PARAMETERS  const CHAR( 8 ) name
  49.  
  50.     VARDEF
  51.         CHAR( 255 ) TableIn
  52.         uint        s
  53.         byte        c_color_std
  54.     ENDDEF
  55.     *
  56.     * Create Pick list to show entries in.
  57.     *
  58.     TblPath = trim(TblPath)
  59.     OpenTableName = TRIM( name )+".tbl"
  60.     IF .NOT. F_OPEN( OpenTableHandle, TblPath+OpenTableName, &F_READ )
  61.         s = savescrn(24,0,24,79)
  62.         c_color_std = __color_std
  63.         __color_std = &RED_WHITE
  64.         @ 23, 1
  65.         WAIT CHR( 7 )+"InitTable: Fatal Error: can't find table!"+TblPath+OpenTableName
  66.         restorescrn(s)
  67.         __color_std = c_color_std
  68.         RETURN .F.
  69.     ENDIF
  70.  
  71.     *
  72.     * Bypass first line which is comment line (get table type)
  73.     *
  74.     DataList = PICK_INIT()
  75.     F_GETLN( OpenTableHandle, TableIn )
  76.     TableType = i_VAL( TableIn )
  77.     IF TableType = 0 .OR. TableType > 2
  78.         TableType = 1                   && Numerical table
  79.     ENDIF
  80.  
  81.     IF TableType = 2                    && Keyed table
  82.         KeyList = PICK_INIT()
  83.     ENDIF
  84.  
  85.     *
  86.     * Load the table entries in the pick list
  87.     *
  88.     TableCnt = 0
  89.     DO WHILE .NOT. F_EOF( OpenTableHandle )
  90.         F_GETLN( OpenTableHandle, TableIn )
  91.         IF TableType = 2
  92.             PICK_ADD( KeyList, LEFT( TableIn, AT( "-", TableIn )-1 ) )
  93.             PICK_ADD( DataList, SUBSTR( TableIn, AT( "-", TableIn )+1, LEN( TableIn ) ) )
  94.         ELSE
  95.             PICK_ADD( DataList, TableIn )
  96.         ENDIF
  97.  
  98.         TableCnt = TableCnt + 1
  99.     ENDDO
  100.  
  101.     F_CLOSE( OpenTableHandle )
  102.     RETURN .T.
  103. ENDPRO
  104.  
  105. *  EOF : TblInit.prg
  106.