home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / PFC / SRC / DBIST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-10  |  1.6 KB  |  70 lines

  1. /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
  2.  
  3. #include "compiler.h"
  4.  
  5. #include "cptpdf.h"
  6. #include "pdb.h"
  7.  
  8. static dbinitfil();
  9.  
  10. int dbist(dbfnam, f_create)
  11.     char        *dbfnam;
  12.     int        f_create;
  13. {
  14.     HDL        h_db_fil, flopen(), h_db, dbopen();
  15.     int        rc;
  16.     RHDL        recadd();
  17. //    FILEINFO      filinfo;
  18.  
  19.     rc = DB_FAIL;
  20.     syerrrset();
  21.  
  22.     if    (!f_create)    /* don't create if already exists.    */
  23.     {
  24. //      if      (drinfo(dbfnam,FA_ORDINARY,&filinfo)==RC_FAIL)
  25.     if (access(dbfnam, 0))
  26.         f_create++;    /* doesn't exist. Ok to create. */
  27.     }
  28.     
  29.     if    ((f_create) && (h_db_fil = flopen(dbfnam, "w+")))
  30.         {
  31.         dbinitfil(h_db_fil);
  32.         flclose(h_db_fil);
  33.         h_db = dbopen(dbfnam);    /* open database for use*/
  34.         recadd (h_db, xc, sizeof(xc));
  35.         recadd (h_db, NULLPTR, 0);
  36.         recadd (h_db, NULLPTR, 0);
  37.         recadd (h_db, NULLPTR, 0);
  38.         dbclose(h_db);
  39.         rc = DB_SUCCESS;
  40.         }
  41.     return  (rc);
  42. }
  43.  
  44. static dbinitfil(h_db_fil)
  45.     HDL    h_db_fil;
  46. {
  47.     char    *pg, *memgive();
  48.     HDL        h_rec;
  49.     char    *dbdummypg();
  50.     int     fhdr_siz, pg_siz, fhdr_free, free_sp;
  51.     
  52.     pg_siz = dbpgsiz();
  53.     pg = memgive(dbpgsiz());
  54.     fhdr_siz = fhdrsizof();
  55.     
  56.     h_rec = (HDL) dbdummypg(pg, fhdr_siz, &fhdr_free);
  57.     
  58.     fhdrist (h_rec, pg_siz);
  59.     flput (pg, dbpgsiz(), h_db_fil);
  60.     h_rec = (HDL) dbdummypg(pg, recsizmax(), &free_sp);
  61.  
  62.     dbmist (h_rec);
  63.     dbmsetfree (h_rec, 0, fhdr_free);
  64.     dbmsetfree (h_rec, 1, 0);
  65.     dbmsetpgct (h_rec, 1);
  66.     
  67.     flput (pg, dbpgsiz(), h_db_fil);
  68.     memtake ((char *)pg);
  69. }
  70.