Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
s_cat.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 /* $Header: /m_home/m_utkej/Argonne/cvs2svn/cvs/Open64/osprey1.0/libF77/s_cat.c,v 1.1.1.1 2002-05-22 20:09:13 dsystem Exp $ */
00038 
00039 /* 11/9/89 fix bug 5242 */
00040 #include <stdio.h>
00041 #include <string.h>
00042 #include <stdlib.h>
00043 #include <alloca.h>
00044 #include "cmplrs/host.h"
00045 
00046 extern void s_abort(int32);
00047 #ifndef FTN90_IO
00048 extern void f77fatal (int32, char *);
00049 #endif
00050 
00051 void s_cat(string lp, string rpp[], fsize_t rnp[], int32 *np, fsize_t ll)
00052 {
00053     int32 i, n;
00054     fsize_t nc;
00055     string buf=0;
00056     fsize_t len;
00057     
00058     buf = alloca(ll);
00059     n = *np;
00060     len = 0;
00061     for(i = 0 ; i < n ; ++i) {
00062         nc = (ll-len <= rnp[i]) ? (ll-len) : rnp[i];
00063         nc = nc < 0 ? 0 : nc;
00064         memcpy (&buf[len], rpp[i], nc);
00065         len += nc;
00066     }
00067     memcpy(lp,buf,len);
00068     memset(&lp[len],' ',ll-len);  /* Why not use b_pad? */
00069 }
00070 #ifdef sgi
00071 /* Not used by Ragnarok Fortran, see s_cat_kai.c */
00072 
00073 #ifndef FTN90_IO
00074         /* not used by fortran 90 */
00075 void
00076 s_cat_tmp(char **lp, char *rpp[], int32 rnp[],
00077           int32 *np, int32 *ntemp)
00078 {
00079     int32 i, n;
00080 #define BUFSIZE 8192
00081     static char buf[BUFSIZE];
00082     static int32 len_used = 0;
00083     int32 len;
00084     char *tmpbuf;
00085     static struct bufstruct { 
00086         struct bufstruct *next;
00087         char buf[1];
00088     } *bigbuf = 0, *nxtbuf;
00089     
00090     n = *np;
00091     for (i=0, len=0; i<n; i++)
00092         len += rnp[i];
00093 
00094 #if 0
00095        Don't do this until we can resolve problem such as :
00096        
00097        call inievs("hello")
00098        end
00099        
00100        subroutine inievs(fichier)
00101        character*(*) fichier
00102        
00103        character*4 suffixe
00104        character*20 temp
00105        suffixe = '.uni'
00106        
00107        ifin = len(fichier)
00108        call abc(fichier(1:ifin)//suffixe,fichier//suffixe,
00109        1        foo(fichier(2:ifin)//suffixe,fichier),
00110        2        fichier(1:len(fichier)-1)//suffixe)
00111        return
00112        end
00113        
00114        subroutine abc(str1, str2, a, str3)
00115        character*(*) str1, str2, str3
00116        print *, "ABC:", "'", str1, "'"
00117        print *, "ABC:", "'", str2, "'"
00118        print *, "ABC:", "'", str3, "'"
00119        return
00120        end
00121        
00122        
00123        function foo(str1, str2)
00124        character*(*) str1, str2
00125        call bar("BAR:"//str1)
00126        print *, "FOO:", "'", str1, "'"
00127        print *, "FOO:", "'", str2, "'"
00128        foo = 0
00129        return
00130        end
00131        
00132        subroutine bar(str)
00133        character*(*) str
00134        print *, str
00135        return
00136        end
00137 #endif
00138 
00139     if (*ntemp == 0) {
00140         /* first temporary string in a statement.  Reset all values and
00141            free allocated space.  Do this for subroutines only since functions
00142            can be recursive in its use of character concatenation.  It's rather
00143            dumb to distinguish subroutine/function but this seems to be the
00144            most runtime efficient and safe way to do it.
00145            */
00146         len_used = 0;
00147         while (bigbuf) {
00148             nxtbuf = bigbuf->next;
00149             free(bigbuf);
00150             bigbuf = nxtbuf;
00151         }
00152     }
00153     if (len + len_used > BUFSIZE) {
00154         nxtbuf = (struct bufstruct *) malloc(len + 4);
00155         if (!nxtbuf)
00156             f77fatal(113,"s_cat_tmp");
00157         nxtbuf->next = bigbuf;
00158         bigbuf = nxtbuf;
00159         tmpbuf = bigbuf->buf;
00160     } else {
00161         tmpbuf = &buf[len_used];
00162         len_used += len;
00163     }
00164     for(i = 0, len = 0; i < n ; ++i) {
00165         memcpy (&tmpbuf[len], rpp[i], rnp[i]);
00166         len += rnp[i];
00167     }
00168     *lp = tmpbuf;
00169 }
00170 #endif /* FTN90_IO */
00171 #endif
00172 
00173 void s_cat2(string tp, fsize_t tl, string ap, string bp, fsize_t al, fsize_t bl)
00174 {
00175   if (al + bl <= tl) {
00176     /* sources same size as target or smaller than target */
00177     memcpy(tp,ap,al);           /* copy in first source */
00178     memcpy(tp+al,bp,bl);        /* copy in second source */
00179     if (al + bl < tl) {
00180       /* sources smaller than target */
00181       memset(&tp[al+bl],' ',tl-(al+bl));  /* blank pad rest of string */
00182     }
00183   } else {
00184     /* al + bl > tl -- sources larger than target */
00185     if (al <= tl) {
00186       /* first source same size as target or larger than target */
00187       memcpy(tp,ap,tl);         /* copy in first tl bytes of first source */
00188     } else {
00189       /* first source smaller than target */
00190       memcpy(tp,ap,al);         /* copy in first source */
00191       memcpy(tp+al,bp,tl-al);   /* copy in part of second source that fits */
00192     }
00193   }
00194 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines