Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 static char USMID[] = "@(#) libcif/ciffiledir.c 30.3 07/26/96 07:19:13"; 00038 00039 00040 /* 00041 * Cif_Getfiledir returns the file directory from an open sorted CIF. 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; /* status value */ 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 /* Read a byte. If not a header or file directory, reset to the start 00082 * of the file and read again. If a header, skip the record and read 00083 * again. If file directory, read it. 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 * If memory management mode isn't set, then set to FIXED. If the 00111 * mode is FIXED, reset the amount of buffer used. 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 /* _Cif_filetbl[cifd].return_version is what the user wants */ 00123 /* _Cif_filetbl[cifd].version is what the cif on disk is */ 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 }