home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / telix / tlx3sort.zip / READ_FON.C < prev    next >
C/C++ Source or Header  |  1988-07-13  |  2KB  |  93 lines

  1. /**
  2.  *
  3.  *  Module:       read_fon.c
  4.  *  Version:      2.0
  5.  *  Description:  routines to read Telix 3.0 fon directory
  6.  *  Author:       Paul Roub
  7.  *
  8.  *  Revision History:
  9.  *     7-13-88 : created
  10.  *
  11.  *      This program and its sources are Copyright (C) 1988 by Paul Roub
  12.  *      and may not be sold for profit without the express written
  13.  *      consent of the author.  Redistribute them (in their entirety) as
  14.  *      you wish,  provided no fee is charged and all materials are
  15.  *      present and unmodified.
  16.  *
  17. **/
  18.  
  19. /*<f>*/
  20. #include  <stdio.h>
  21. #include  "tlx30.h"
  22. #include  "tlxsort.h"
  23.  
  24.  
  25. static  fon_header *ReadFonHeader ( FILE *fil );
  26.  
  27.  
  28. /*<f>*/
  29. /**
  30.  *
  31.  *  Function:     void ReadFonFile()
  32.  *  Description:  read specified file
  33.  *  Returns:      pointers to header and entries (which we allocate)
  34.  *
  35. **/
  36. void ReadFonFile(name, header_p, entry_p)
  37. char      *name;
  38. fon_header **header_p;
  39. fon_entry **entry_p;
  40. {
  41.   fon_header *th;
  42.   fon_entry  *te;
  43.   FILE      *fil;
  44.   int       result;
  45.  
  46.   fil = ffopen(name, "rb");
  47.  
  48.   th = ReadFonHeader(fil);
  49.  
  50.   te = mmalloc(th->num_entries * sizeof(fon_entry));
  51.  
  52.   result = fread(te, sizeof(fon_entry), (size_t)th->num_entries, fil);
  53.  
  54.   if (result != th->num_entries)
  55.     quitf("error reading fon file %s", name);
  56.  
  57.   fclose(fil);
  58.  
  59.   *header_p = th;
  60.   *entry_p = te;
  61.  
  62.   return;
  63. }
  64.  
  65.  
  66. /*<f>*/
  67. /**
  68.  *
  69.  *  Function:     static fon_header *ReadFonHeader()
  70.  *  Description:  read telix 3.0 phone header
  71.  *  Returns:      pointer to (allocated) header
  72.  *
  73. **/
  74. static fon_header *ReadFonHeader(fil)
  75. FILE      *fil;
  76. {
  77.   int       result;
  78.   fon_header *th;
  79.  
  80.   th = mmalloc(sizeof(fon_header));
  81.  
  82.   result = fread(th, sizeof(fon_header), 1, fil);
  83.  
  84.   if (result != 1)
  85.     quitf("error reading fon file header");
  86.  
  87.   if (th->id != 0x2E2B291A)
  88.     quitf("invalid phone file header");
  89.  
  90.   return(th);
  91. }
  92.  
  93.