Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 static char USMID[] = "@(#) libcif/cifunitdir.c 30.2 07/26/96 07:19:13";
00038
00039
00040
00041
00042
00043
00044
00045 #define CIF_VERSION 3
00046
00047 #ifdef _ABSOFT
00048 #include "cif.h"
00049 #else
00050 #include <cif.h>
00051 #endif
00052
00053 #include <memory.h>
00054 #include <stdio.h>
00055
00056 #include "cif_int.h"
00057
00058 int
00059 Cif_Getunitdir
00060 #ifdef __STDC__
00061 (int cifd, struct Cif_unittbl *utp, struct Cif_unitdir **unitdir)
00062 #else
00063 (cifd, utp, unitdir)
00064 int cifd;
00065 struct Cif_unittbl *utp;
00066 struct Cif_unitdir **unitdir;
00067 #endif
00068 {
00069
00070 FILE *fd;
00071 int i, n;
00072 struct Cif_unitdir *udp;
00073 struct Cif_urectbl *urp;
00074
00075 char buf[64];
00076 struct Cif_urectbl ur[CIF_MAXRECORD];
00077 struct Cif_unit unit;
00078
00079 int status = 0;
00080
00081 if (cifd < 0 || cifd > CIF_FT_SIZE || _Cif_filetbl[cifd].form == NOT_A_CIF)
00082 return (CIF_NOTOPEN);
00083 else if (_Cif_filetbl[cifd].optype == 'w' || _Cif_filetbl[cifd].form ==
00084 ASCII_CIF || _Cif_filetbl[cifd].seek == NO)
00085 return (CIF_BADREQ);
00086 _Cif_filetbl[cifd].ifull = NO;
00087
00088
00089
00090
00091
00092 fd = _Cif_filetbl[cifd].fd;
00093 if (fseek (fd, utp->unitpos, 0))
00094 return (CIF_SYSERR);
00095 if (fread (&unit, _Cif_shortsize[CIF_UNIT][_Cif_filetbl[cifd].version], 1, fd) != 1) IO_ERROR;
00096 if ((n = unit.nlen) > 0)
00097 if (fread (buf, sizeof(char), n, fd) != n) IO_ERROR;
00098
00099
00100
00101
00102
00103 i = _Cif_filetbl[cifd].mode;
00104
00105
00106
00107
00108
00109 if (i == CIF_MEM_DEFAULT) {
00110 if ((status = Cif_Memmode (cifd, CIF_MEM_FIXED)) != 0)
00111 return (status);
00112 i = _Cif_filetbl[cifd].mode;
00113 }
00114 if (i == CIF_MEM_FIXED)
00115 _Cif_memarea[_Cif_filetbl[cifd].fme].mused = 0;
00116
00117 udp = *unitdir = (struct Cif_unitdir *) _Cif_space[i]
00118 (_Cif_structsize[CIF_UNITDIR][_Cif_filetbl[cifd].return_version], cifd);
00119 if (udp == NULL)
00120 return (CIF_NOMEM);
00121 if (fread ((char *)udp, _Cif_shortsize[CIF_UNITDIR][_Cif_filetbl[cifd].version], 1, fd) != 1) IO_ERROR;
00122
00123
00124
00125 n = sizeof(struct Cif_urectbl) * CIF_MAXRECORD;
00126 urp = udp->ur = (struct Cif_urectbl *) _Cif_space[i] (n, cifd);
00127 if (urp == NULL)
00128 return (CIF_NOMEM);
00129 (void) memset ((char *)urp, '\0', n);
00130 n = udp->nsections;
00131 if (fread ((char *)ur, sizeof(struct Cif_urectbl), n, fd) != n) IO_ERROR;
00132 for (i = 0; i < n; i++) {
00133 urp[ur[i].rectype] = ur[i];
00134
00135
00136
00137 if (_Cif_shortsize[ur[i].rectype][_Cif_filetbl[cifd].return_version] == 0)
00138 urp[ur[i].rectype].nrecords = 0;
00139 }
00140
00141 if (_Cif_filetbl[cifd].return_version == 1)
00142 udp->nsections = CIF_MAXRECORD_1;
00143 else
00144 udp->nsections = CIF_MAXRECORD;
00145
00146 return (0);
00147 }