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/cifunitdir.c 30.2 07/26/96 07:19:13"; 00038 00039 00040 /* 00041 * Cif_Getunitdir returns the unit directory for the requested unit from 00042 * an open sorted CIF. 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; /* status value */ 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 /* Position the file to the start of the unit, read the unit record and 00089 * discard it. 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 /* Read in the unit directory structure, then the individual record 00100 * entries. Expand to the full directory structure. 00101 */ 00102 00103 i = _Cif_filetbl[cifd].mode; 00104 /* 00105 * If memory management mode isn't set, then set to FIXED. If the 00106 * mode is FIXED, reset the amount of buffer used. 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 /* should map this */ 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 /* mask out those records that this cif version (eg v1) doesn't know about */ 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 }