17
* Converts C strings to Fortran strings.
19
* @param cstring C buffer
20
* @param fstring Fortran string
21
* @param flength length of fstring
23
void ga_c2fstring(char *cstring, char *fstring, int flength)
25
int clength = strlen(cstring);
27
/* remove terminal \n character if any */
28
if(cstring[clength] == '\n') {
32
/* Truncate C string into Fortran string */
33
if (clength > flength) {
34
clength = (int)flength;
37
/* Copy characters over */
40
*fstring++ = *cstring++;
43
/* Now terminate with blanks */
51
* Converts Fortran strings to C strings.
53
* Strip trailing blanks from fstring and copy it to cstring,
54
* truncating if necessary to fit in cstring, and ensuring that
55
* cstring is NUL-terminated.
57
* @param fstring Fortran string
58
* @param flength length of fstring
59
* @param cstring C buffer
60
* @param clength max length (including NUL) of cstring
62
void ga_f2cstring(char *fstring, int flength, char *cstring, int clength)
64
/* remove trailing blanks from fstring */
65
while (flength-- && fstring[flength] == ' ') ;
67
/* the postdecrement above went one too far */
70
/* truncate fstring to cstring size */
71
if (flength >= clength) {
72
flength = clength - 1;
75
/* ensure that cstring is NUL-terminated */
76
cstring[flength] = '\0';
78
/* copy fstring to cstring */
80
cstring[flength] = fstring[flength];
84
void ga_f2c_get_cmd_args(int *argc, char ***argv)
87
int iargc=F2C_IARGC();
90
if (iargc > F2C_GETARG_ARGV_MAX) {
91
printf("ga_f2c_get_cmd_args: too many cmd line args");
94
iargv = malloc(sizeof(char*)*F2C_GETARG_ARGV_MAX);
96
printf("ga_f2c_get_cmd_args: malloc iargv failed");
99
for (i=0; i<iargc; i++) {
100
char fstring[F2C_GETARG_ARGLEN_MAX];
101
char cstring[F2C_GETARG_ARGLEN_MAX];
102
F2C_GETARG(&i, fstring, F2C_GETARG_ARGLEN_MAX);
103
ga_f2cstring(fstring, F2C_GETARG_ARGLEN_MAX,
104
cstring, F2C_GETARG_ARGLEN_MAX);
105
iargv[i] = strdup(cstring);
114
/* To avoid missing symbols even though these should never be called. */
118
void F2C_GETARG(Integer *a, char *b, int c)
120
printf("GA was built without support for Fortran. You have attempted "
121
"to retreive command line arguments from a Fortran program. "
122
"Please recompile GA and avoid using --disable-f77");
131
printf("GA was built without support for Fortran. You have attempted "
132
"to retreive command line arguments from a Fortran program. "
133
"Please recompile GA and avoid using --disable-f77");