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 #pragma ident "@(#) libfi/element/date.c 92.1 06/16/99 15:47:23" 00038 #include <fortran.h> 00039 #include <stdio.h> 00040 #include <string.h> 00041 #include <time.h> 00042 #include <sys/types.h> 00043 00044 /* 00045 * DATE Returns the current date in "MM/DD/YY" format. 00046 * MM = Month (1 - 12). 00047 * DD = Day (01 - 31). 00048 * YY = Year modulus 100 (00 - 99). 00049 * 00050 * May be called either as a function or a subroutine. 00051 * If called as a subroutine, the parameter may be 00052 * CHARACTER or INTEGER type. 00053 */ 00054 00055 /* 00056 * Duplicate names 00057 * 00058 * _DATE_ - for f90 intrinsic 00059 * DATE - if called as a subroutine 00060 * $DATE - for cf77 intrinsic 00061 * _DATE - for f90 3.0? and previous on PVP systems 00062 */ 00063 #if !defined(__mips) && !defined(_LITTLE_ENDIAN) 00064 #pragma _CRI duplicate _DATE_ as DATE 00065 #pragma _CRI duplicate _DATE_ as $DATE 00066 #pragma _CRI duplicate _DATE_ as _DATE 00067 #endif 00068 00069 00070 /* NOTE: For 32-bit architectures, the DATE function is quite 00071 * different from the 64-bit version. Two parameters vs 00072 * one, pointer to a pararmater vs. not, and different 00073 * return values. It was decided that it would be much 00074 * easier to deal with these problems with two separate 00075 * routines, using #ifdefs. 00076 */ 00077 00078 #ifdef _UNICOS 00079 00080 _f_int 00081 _DATE_(dayofyear) 00082 _fcd dayofyear; 00083 { 00084 long date; 00085 struct tm *sp; 00086 time_t now; 00087 char str[sizeof(long) + 1]; 00088 00089 now = time((time_t *) NULL); 00090 sp = localtime(&now); 00091 00092 /* 00093 * Mod the year by 100 so it will be correct after year 1999; 00094 * user is required to know the century. 00095 */ 00096 00097 (void) sprintf(str, "%02d/%02d/%02d", sp->tm_mon+1, sp->tm_mday, 00098 sp->tm_year % 100); 00099 00100 date = *(long *) str; 00101 00102 if ( _numargs() > 0) 00103 #ifdef _ADDR64 00104 if (_numargs() > 1) { /* If Fortran character */ 00105 #else 00106 if (_isfcd(dayofyear)) { /* If Fortran character */ 00107 #endif 00108 unsigned int len; 00109 char *cp; 00110 00111 cp = _fcdtocp(dayofyear); 00112 len = _fcdlen (dayofyear); 00113 00114 (void) strncpy(cp, str, len); 00115 00116 if (len > sizeof(long)) 00117 (void) memset(cp + sizeof(long), (_f_int) ' ', 00118 len - sizeof(long)); 00119 } 00120 else /* Hollerith */ 00121 **(long **) &dayofyear = date; 00122 00123 return( (_f_int) date ); 00124 } 00125 00126 #else 00127 00128 #define DATE_CHRS 8 00129 00130 _fcd 00131 _DATE_(dayofyear, iffcd) 00132 void *dayofyear; /* address of result, unless NULL */ 00133 int iffcd; /* zero if 1st param is long long */ 00134 /* non-zero if 1st param is _fcd */ 00135 00136 { 00137 struct tm *sp; 00138 time_t now; 00139 char str[DATE_CHRS + 1]; 00140 00141 now = time((time_t *) NULL); 00142 sp = localtime(&now); 00143 00144 /* 00145 * Mod the year by 100 so it will be correct after 1999. The use 00146 * is required to know the century. 00147 */ 00148 00149 (void) sprintf(str, "%02d/%02d/%02d", sp->tm_mon+1, sp->tm_mday, 00150 sp->tm_year %100); 00151 00152 if (dayofyear != NULL) /* parameter was passed */ 00153 if (iffcd != 0) { /* If Fortran character */ 00154 unsigned int len; 00155 char *cp; 00156 00157 cp = (char *) dayofyear; 00158 len = iffcd; 00159 (void) strncpy (cp, str, len); 00160 if (len > DATE_CHRS) 00161 (void) memset (cp + DATE_CHRS, (int) ' ', len -DATE_CHRS); 00162 } 00163 00164 return (_cptofcd(str, strlen(str))); 00165 } 00166 #endif