home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / dic / src / catalog.c next >
Text File  |  1995-06-20  |  2KB  |  82 lines

  1. /******************************************
  2.  
  3.     CATALOG? Load
  4.  
  5. *******************************************/
  6. #include    "defs.h"
  7.  
  8. CATALOG    *catalog_load(char *file)
  9. {
  10.     int     n, i, gz, gh;
  11.     char    ttl[82];
  12. #ifndef    UNIX
  13.     struct _CATALOG {
  14.     char    type;
  15.     char    resv;
  16.     char    name[80];
  17.     struct    {
  18.         uchar    no_hi, no_low;
  19.         char    path[44];
  20.     } file[10];
  21.     } id;
  22. #else
  23.     uchar    id[542];
  24. #endif
  25.     uchar  tmp[4];
  26.     CATALOG    *tp = NULL;
  27.     CATALOG    *cp, *bp;
  28.  
  29.     for ( n = 1 ; n <= vtoc_file_max ; n++ ) {
  30.     if ( !CD_file_open(n) && strcmp(file_name, file) == 0 )
  31.         break;
  32.     }
  33.  
  34.     if ( n > vtoc_file_max || IO_seek(1, 0) || IO_read(tmp, 4) != 4 )
  35.     return NULL;
  36.  
  37.     n = tmp[2] * 256 + tmp[3];
  38.     while ( n-- > 0 ) {
  39. #ifndef    UNIX
  40.     if ( IO_read((char *)(&id), sizeof(id)) != sizeof(id) )
  41.         return NULL;
  42.     str_cnv(ttl, id.name, 80);
  43.     i = id.file[0].no_hi * 256 + id.file[0].no_low;
  44.     gz = id.file[2].no_hi * 256 + id.file[2].no_low;    /* 外字 16全 */
  45.     gh = id.file[6].no_hi * 256 + id.file[6].no_low;    /* 外字 16半 */
  46. #else
  47.     if ( IO_read(id, 542) != 542 )
  48.         return NULL;
  49.     str_cnv(ttl, id + 2, 80);
  50.     i  = id[82] * 256 + id[83];
  51.     gz = id[82 + 46 * 2] * 256 + id[83 + 46 * 2];    /* 外字 16全 */
  52.     gh = id[82 + 46 * 6] * 256 + id[83 + 46 * 6];    /* 外字 16半 */
  53. #endif
  54.  
  55.     if ( (cp = (CATALOG *)malloc(sizeof(CATALOG))) == NULL )
  56.         break;
  57.     cp->next = NULL;
  58.     cp->ttl  = strdup(ttl);
  59.     cp->no   = i;
  60.     cp->gah  = gh;
  61.     cp->gaz  = gz;
  62.  
  63.     if ( tp == NULL )
  64.         tp = bp = cp;
  65.     else {
  66.         bp->next = cp;
  67.         bp = cp;
  68.     }
  69.     }
  70.  
  71.     return tp;
  72. }
  73. void    catalog_free(CATALOG *cp)
  74. {
  75.     CATALOG    *tp;
  76.  
  77.     while ( (tp = cp) != NULL ) {
  78.     cp = cp->next;
  79.     free(tp);
  80.     }
  81. }
  82.