File: s_cat.c

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (87 lines) | stat: -rw-r--r-- 2,038 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Unless compiled with -DNO_OVERWRITE, this variant of s_cat allows the
 * target of a concatenation to appear on its right-hand side (contrary
 * to the Fortran 77 Standard, but in accordance with Fortran 90).
 */

#include "v3p_f2c.h"
#ifndef NO_OVERWRITE
#include "stdio.h"
#undef abs
#ifdef KR_headers
 extern char *F77_aloc();
 extern void free();
 extern void exit_();
#else
#undef min
#undef max
#include "stdlib.h"
extern
#ifdef __cplusplus
        "C"
#endif
        char *F77_aloc(ftnlen, char*);
#endif
#include "string.h"
#endif /* NO_OVERWRITE */

#ifdef __cplusplus
extern "C" {
#endif

int
#ifdef KR_headers
s_cat(lp, rpp, rnp, np, ll) char *lp, **rpp; integer *rnp, *np; ftnlen ll;
#else
s_cat(char *lp, char **rpp, integer *rnp, integer *np, ftnlen ll)
#endif
{
        ftnlen i, nc;
        char *rp;
        ftnlen n = *np;
#ifndef NO_OVERWRITE
        ftnlen L, m;
        char *lp0, *lp1;

        lp0 = 0;
        lp1 = lp;
        L = ll;
        i = 0;
        while(i < n) {
                rp = rpp[i];
                m = rnp[i++];
                if (rp >= lp1 || rp + m <= lp) {
                        if ((L -= m) <= 0) {
                                n = i;
                                break;
                                }
                        lp1 += m;
                        continue;
                        }
                lp0 = lp;
                lp = lp1 = F77_aloc(L = ll, "s_cat");
                break;
                }
        lp1 = lp;
#endif /* NO_OVERWRITE */
        for(i = 0 ; i < n ; ++i) {
                nc = ll;
                if(rnp[i] < nc)
                        nc = rnp[i];
                ll -= nc;
                rp = rpp[i];
                while(--nc >= 0)
                        *lp++ = *rp++;
                }
        while(--ll >= 0)
                *lp++ = ' ';
#ifndef NO_OVERWRITE
        if (lp0) {
                memcpy(lp0, lp1, L);
                free(lp1);
                }
#endif
        return 0;
        }
#ifdef __cplusplus
}
#endif