source: trunk/src/fortran/RpFortranCommon.c @ 76

Last change on this file since 76 was 76, checked in by dkearney, 15 years ago
  1. cleaned up make files some more, deleted make.inc files
  2. updated RpUnits module and Cee and Fortran interfaces
  3. changed return values for some fortran interfaces,

error messages not working yet

  1. still need to add copy assignment code to RpUnits
File size: 1.1 KB
Line 
1#include "RpFortranCommon.h"
2
3char* null_terminate(char* inStr, int len) {
4    int retVal = 0;
5    char* newStr = NULL;
6    char* current = NULL;
7
8    if (inStr && (len > 0) ) {
9
10        current = inStr+len-1;
11
12        while ((len > 0) && (isspace(*(current)))) {
13            // dont strip off newlines
14
15            if ( (*(current) == '\f')
16              || (*(current) == '\n')
17              || (*(current) == '\r')
18              || (*(current) == '\t')
19              || (*(current) == '\v') )
20            {
21                break;
22            }
23
24            if (--len) {
25                current--;
26            }
27        }
28
29        newStr = (char*) calloc(len+1,(sizeof(char)));
30        strncpy(newStr,inStr,len);
31        *(newStr+len) = '\0';
32
33        retVal++;
34    }
35
36    return newStr;
37}
38
39void fortranify(const char* inBuff, char* retText, int retTextLen) {
40
41    int inBuffLen = 0;
42    int i = 0;
43
44    inBuffLen = strlen(inBuff);
45
46    strncpy(retText, inBuff, retTextLen);
47
48    // fortran-ify the string
49    if (inBuffLen < retTextLen) {
50        for (i = inBuffLen; i < retTextLen; i++) {
51            retText[i] = ' ';
52        }
53    }
54}
Note: See TracBrowser for help on using the repository browser.