00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
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);
00069 }
00070 #ifdef sgi
00071
00072
00073 #ifndef FTN90_IO
00074
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
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
00177 memcpy(tp,ap,al);
00178 memcpy(tp+al,bp,bl);
00179 if (al + bl < tl) {
00180
00181 memset(&tp[al+bl],' ',tl-(al+bl));
00182 }
00183 } else {
00184
00185 if (al <= tl) {
00186
00187 memcpy(tp,ap,tl);
00188 } else {
00189
00190 memcpy(tp,ap,al);
00191 memcpy(tp+al,bp,tl-al);
00192 }
00193 }
00194 }