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/repeat.c 92.2 07/30/99 10:09:59" 00038 00039 /* REPEAT - Concatenate several copies of a string */ 00040 00041 #include <fortran.h> 00042 #include <liberrno.h> 00043 #include <stdlib.h> 00044 #include <stddef.h> 00045 #include <string.h> 00046 #include <cray/dopevec.h> 00047 00048 void 00049 _REPEAT( 00050 DopeVectorType *result, 00051 _fcd source, 00052 _f_int *ncopies) 00053 { 00054 char *sptr; /* source pointer */ 00055 char *rptr; /* result pointer */ 00056 char *rptr1; /* result pointer */ 00057 int src_len; /* source length */ 00058 int i, j, k; /* index variables */ 00059 int tot_chr; /* total characters to copy */ 00060 int lp_cnt; /* loop count */ 00061 _f_int copies; /* number of copies */ 00062 00063 /* Get source and result pointers and lengths */ 00064 00065 sptr = _fcdtocp (source); 00066 src_len = _fcdlen (source); 00067 00068 /* See if ncopies is valid */ 00069 00070 copies = (_f_int) *ncopies; 00071 00072 if (copies < 0) 00073 _lerror (_LELVL_ABORT, FERPTNEG); 00074 else if (copies == 0 || src_len == 0) { 00075 result->base_addr.charptr = _cptofcd ((char *) NULL, 0); 00076 #if !defined(_ADDR64) && !defined(_WORD32) && !defined(__mips) && !defined(_LITTLE_ENDIAN) 00077 result->base_addr.a.el_len = 0; 00078 #endif 00079 return; 00080 } 00081 00082 /* Determine total count of characters to copy and loop count */ 00083 00084 tot_chr = src_len * copies; 00085 00086 /* If necessary, allocate space for result */ 00087 00088 if (result->assoc) 00089 _lerror (_LELVL_ABORT, FEINTUNK); 00090 00091 result->assoc = 1; 00092 result->base_addr.a.ptr = (void *) malloc (tot_chr); 00093 if (result->base_addr.a.ptr == NULL) 00094 _lerror (_LELVL_ABORT, FENOMEMY); 00095 rptr = (char *) result->base_addr.a.ptr; 00096 result->base_addr.charptr = _cptofcd (rptr, tot_chr); 00097 result->orig_base = result->base_addr.a.ptr; 00098 result->orig_size = tot_chr; 00099 #if !defined(_ADDR64) && !defined(_WORD32) && !defined(__mips) && !defined(_LITTLE_ENDIAN) 00100 result->base_addr.a.el_len = tot_chr << 3; 00101 #endif 00102 00103 /* Copy characters and return */ 00104 00105 for (i = 0; i < copies; i++) { 00106 rptr1 = (char *) rptr + (i * src_len); 00107 (void) memcpy (rptr1, sptr, src_len); 00108 } 00109 00110 return; 00111 }