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/char/trim.c 92.2 07/30/99 10:09:59" 00038 00039 /* 00040 * TRIM - Return the character argument with trailing blank characters 00041 * removed 00042 */ 00043 00044 #include <fortran.h> 00045 #include <liberrno.h> 00046 #include <stdlib.h> 00047 #include <stddef.h> 00048 #include <string.h> 00049 #include <cray/dopevec.h> 00050 00051 extern long _zero_entity; /* nonzero addr for PRESENT func */ 00052 00053 void 00054 _TRIM( 00055 DopeVectorType *result, 00056 _fcd source) 00057 { 00058 int src_len; 00059 int leng; 00060 char *sptr; 00061 char *rptr; 00062 int i; 00063 00064 /* Convert Fortran Character Descriptors to C pointers */ 00065 00066 src_len = _fcdlen (source); 00067 sptr = _fcdtocp (source); 00068 00069 /* Determine length of string to return */ 00070 00071 leng = 0; 00072 for (i = src_len - 1; i >= 0; i--) { 00073 if (sptr[i] != ' ') { 00074 leng = i+1; 00075 break; 00076 } 00077 } 00078 00079 /* Allocate result space, if necessary */ 00080 00081 if (!result->assoc) { 00082 00083 /* Set the base address of the result dope vector to special 00084 * address when source string is null or all blanks so the 00085 * compiler can do a check of nonzero to distinguish between 00086 * an argument that is not present and one that is zero-sized. 00087 */ 00088 00089 if (leng > 0) { 00090 result->base_addr.a.ptr = (void *) malloc(leng); 00091 if (result->base_addr.a.ptr == NULL) 00092 _lerror(_LELVL_ABORT, FENOMEMY); 00093 rptr = (char *) result->base_addr.a.ptr; 00094 } else 00095 rptr = (void *) &_zero_entity; 00096 00097 /* set assoc flag even for zero-sized allocation */ 00098 result->assoc = 1; 00099 result->orig_base = result->base_addr.a.ptr; 00100 result->base_addr.charptr = _cptofcd (rptr, leng); 00101 result->orig_size = leng << 3; 00102 #if !defined(_ADDR64) && !defined(_WORD32) && !defined(__mips) && !defined(_LITTLE_ENDIAN) 00103 result->base_addr.a.el_len = leng << 3; 00104 #endif 00105 } else 00106 _lerror(_LELVL_ABORT, FEINTUNK); 00107 00108 /* If source string is all null, all blanks, or no trailing blanks, 00109 * return string without any assignment. Otherwise, return the 00110 * entire string without trailing blanks. 00111 */ 00112 if (leng > 0) 00113 (void) memcpy (rptr, sptr, leng); 00114 00115 return; 00116 }