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/ciffiledir.c 30.3 07/26/96 07:19:13";
00038
00039
00040
00041
00042
00043
00044 #define CIF_VERSION 3
00045
00046 #ifdef _ABSOFT
00047 #include "cif.h"
00048 #else
00049 #include <cif.h>
00050 #endif
00051
00052 #include <memory.h>
00053 #include <stdio.h>
00054
00055 #include "cif_int.h"
00056
00057 int Cif_Getfiledir
00058 #ifdef __STDC__
00059 (int cifd, struct Cif_filedir **fdir)
00060 #else
00061 (cifd, fdir)
00062 int cifd;
00063 struct Cif_filedir **fdir;
00064 #endif
00065 {
00066
00067 char buf[128], *cp;
00068 int i, mode, n, rtype;
00069 struct Cif_filedir *fp;
00070 struct Cif_unittbl *ut;
00071 FILE *fd;
00072 int status = 0;
00073
00074
00075 if (cifd < 0 || cifd > CIF_FT_SIZE || _Cif_filetbl[cifd].form == NOT_A_CIF)
00076 return (CIF_NOTOPEN);
00077 else if (_Cif_filetbl[cifd].optype == 'w' || _Cif_filetbl[cifd].form ==
00078 ASCII_CIF || _Cif_filetbl[cifd].seek == NO)
00079 return (CIF_BADREQ);
00080
00081
00082
00083
00084
00085
00086 _Cif_filetbl[cifd].ifull = NO;
00087 fd = _Cif_filetbl[cifd].fd;
00088 if (fread (buf, sizeof(char), 1, fd) != 1) {
00089 if (feof(fd)) rtype = 0;
00090 else return (CIF_SYSERR);
00091 }
00092 rtype = ((struct Cif_generic *)buf)->rectype;
00093 if (rtype != CIF_CIFHDR && rtype != CIF_FILEDIR) {
00094 if (fseek (fd, 0L, 0))
00095 return (CIF_SYSERR);
00096 if (fread (buf, sizeof(char), BINARY_HDR_LEN, fd) != BINARY_HDR_LEN)
00097 return (CIF_SYSERR);
00098 if (fread (buf, sizeof(char), 1, fd) != 1) IO_ERROR;
00099 rtype = ((struct Cif_generic *)buf)->rectype;
00100 }
00101 if (rtype == CIF_CIFHDR) {
00102 if (fread(&buf[1], _Cif_shortsize[CIF_CIFHDR][_Cif_filetbl[cifd].version]-1, 1, fd) != 1) IO_ERROR;
00103 if (fread (buf, sizeof(char), 1, fd) != 1) IO_ERROR;
00104 rtype = ((struct Cif_generic *)buf)->rectype;
00105 }
00106 if (rtype == CIF_FILEDIR) {
00107 mode = _Cif_filetbl[cifd].mode;
00108
00109
00110
00111
00112
00113
00114 if (mode == CIF_MEM_DEFAULT) {
00115 if ((status = Cif_Memmode (cifd, CIF_MEM_FIXED)) != 0)
00116 return (status);
00117 mode = _Cif_filetbl[cifd].mode;
00118 }
00119 if (mode == CIF_MEM_FIXED)
00120 _Cif_memarea[_Cif_filetbl[cifd].fme].mused = 0;
00121
00122
00123
00124
00125 fp = *fdir = (struct Cif_filedir *)_Cif_space[mode]
00126 (_Cif_structsize[CIF_FILEDIR][_Cif_filetbl[cifd].return_version], cifd);
00127 if (fp == NULL)
00128 return (CIF_NOMEM);
00129 cp = (char *)fp;
00130 (void) memset (cp, '\0', _Cif_structsize[CIF_FILEDIR][_Cif_filetbl[cifd].return_version]);
00131 if (fread (++cp, _Cif_shortsize[CIF_FILEDIR][_Cif_filetbl[cifd].version]-1, 1, fd) != 1) IO_ERROR;
00132 n = fp->nunits;
00133 fp->rectype = rtype;
00134 ut = fp->ut = (struct Cif_unittbl *) _Cif_space[mode]
00135 (sizeof(struct Cif_unittbl)*n, cifd);
00136 if (ut == NULL)
00137 return (CIF_NOMEM);
00138 (void) memset((char *)ut, 0, n * sizeof(struct Cif_unittbl));
00139 for (i = 0; i < n; i++, ut++) {
00140 if (fread ((char *)ut, UNITTBL_SSIZE, 1, fd) != 1) IO_ERROR;
00141 cp = ut->name = _Cif_space[mode] (ut->nlen+1, cifd);
00142 if (cp == NULL)
00143 return (CIF_NOMEM);
00144 if (fread (cp, sizeof(char), ut->nlen, fd) != ut->nlen) IO_ERROR;
00145 cp[ut->nlen] = '\0';
00146 }
00147 }
00148 else
00149 return (CIF_BADFORM);
00150 return (0);
00151 }