Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
cls.c
Go to the documentation of this file.
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 
00038 #pragma ident "@(#) libf/fio/cls.c      92.2    06/18/99 18:41:40"
00039 
00040 #include <stdio.h>
00041 #include <cray/nassert.h>
00042 #include "fio.h"
00043 #include "f90io.h"
00044 #include "fmt.h"
00045 #ifdef  _CRAYMPP
00046 #include <stdarg.h>
00047 #endif
00048 
00049 
00050 /*
00051  *      $CLS - routine called to process the Fortran CLOSE statement.
00052  *
00053  *      _CLS - obsolete Fortran 90 CLOSE interface routine.
00054  */
00055 #ifdef  _UNICOS
00056 #pragma _CRI duplicate _CLS as $CLS
00057 #endif
00058 #ifdef  _CRAYMPP
00059 _CLS (
00060         _f_int  *unump,         /* Pointer to unit identifier   */
00061         _f_int  *iostat,        /* Pointer to IOSTAT variable   */
00062         int     *err,           /* Pointer to ERR specifier     */
00063         ...                     /* STATUS character descriptor  */
00064 )
00065 #else
00066 _CLS (
00067         _f_int  *unump,         /* Pointer to unit identifier   */
00068         _f_int  *iostat,        /* Pointer to IOSTAT variable   */
00069         int     *err,           /* Pointer to ERR specifier     */
00070         _fcd    status          /* STATUS character descriptor  */
00071 )
00072 #endif
00073 {
00074 #ifdef _CRAYMPP
00075         va_list args;           /* Variable argument list */
00076         _fcd    status;         /* STATUS character descriptor  */
00077 #endif
00078         register int    csta;   /* STATUS= specifier value */
00079         register int    errn;   /* Error status */
00080         int             errflag;/* Contains _UERRF/_UIOSTF flag bits */
00081         long            fstrlen;/* Length of Fortran string */
00082         char            *fstr;  /* Pointer to Fortran string */
00083         plock_t         *lockp; /* Pointer to the unit lock */
00084         register unum_t unum;   /* Fortran unit number */
00085         unit            *cup;   /* Pointer to unit table */
00086         struct fiostate cfs;
00087         static  char    keep[] = "KEEP";
00088         static  char    delete[] = "DELETE";
00089   
00090         int     _string_cmp();  /* String compare routine in libu */
00091 
00092         OPENLOCK();             /* prevent other OPENs or CLOSEs right now */
00093 
00094         unum    = *unump;
00095 
00096         STMT_BEGIN(unum, 0, T_CLOSE, NULL, &cfs, cup);
00097 
00098         errflag         = (iostat != NULL ? _UIOSTF : 0) |
00099                           (   err != NULL ?  _UERRF : 0);
00100         errn    = 0;
00101         csta    = CLST_UNSPEC;
00102   
00103         /* Validate STATUS parameter, if specified */
00104   
00105 #ifdef  _CRAYMPP
00106         va_start(args, err);
00107         status  = va_arg(args, _fcd);
00108         va_end(args);
00109 #endif
00110         fstr    = _fcdtocp(status);
00111         fstrlen = _fcdlen (status);
00112 
00113         if (fstr != NULL) {
00114                 if     (_string_cmp(  keep, fstr, fstrlen))
00115                         csta    = CLST_KEEP;
00116                 else if(_string_cmp(delete, fstr, fstrlen))
00117                         csta    = CLST_DELETE;
00118                 else
00119                         errn    = FECLSTAT;     /* Invalid status parameter */
00120         }
00121 /*
00122  *      A CLOSE for a unit which doesn't exist or isn't connected is a no-op.
00123  */
00124         if (!GOOD_UNUM(unum) || RSVD_UNUM(unum) || cup == NULL) goto done;
00125   
00126         cup->uflag      = errflag;
00127 
00128         if (csta == CLST_KEEP && cup->uscrtch) 
00129                 errn    = FECLSTIV;     /* Can't KEEP scratch file  */
00130   
00131         lockp   = &cup->uiolock;        /* save the unit lock pointer address */
00132 
00133         if (errn == 0)
00134                 errn    = _unit_close(cup, csta, &cfs); /* low level close */
00135   
00136 /*
00137  *      The unit pointer cup normally is not connected after return from
00138  *      _unit_close.  So cup would point to deallocated memory if units
00139  *      were allocated dynamically.
00140  */
00141         MEM_UNLOCK(lockp);              /* Unlock the unit lock */
00142   
00143 done:
00144         OPENUNLOCK();
00145 
00146         if (iostat != NULL)
00147                 *iostat = errn;
00148   
00149         if ((errn != 0) && (errflag == 0))
00150                 _ferr(&cfs, errn);
00151 
00152         STMT_END((unit *)NULL, T_CLOSE, NULL, &cfs); /* unit already unlocked */
00153   
00154         errn    = (errn != 0) ? IO_ERR : IO_OKAY;
00155   
00156         return(CFT77_RETVAL(errn));
00157 }
00158 
00159 /*
00160  *      _CLOSE - process Fortran-90 CLOSE statement.
00161  */
00162 int
00163 _CLOSE(struct close_spec_list *c)
00164 {
00165         assert ( c->version == 0 );
00166 
00167         return(_CLS(c->unit, c->iostat, (int *)c->err, c->status));
00168 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines