source: branches/1.7/src/core/RpFortranCommon.cc @ 6226

Last change on this file since 6226 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Fortran Rappture Common Functions Source
4 *
5 *    Fortran functions common to all interfaces.
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15
16#include "RpFortranCommon.h"
17#include <stdlib.h>
18#include <ctype.h>
19#include <string.h>
20
21char* null_terminate(char* inStr, int len) {
22    int retVal = 0;
23    char* newStr = NULL;
24    char* current = NULL;
25
26    if (inStr && (len > 0) ) {
27
28        current = inStr+len-1;
29
30        while ((len > 0) && (isspace(*(current)))) {
31            // dont strip off newlines
32
33            if ( (*(current) == '\f')
34              || (*(current) == '\n')
35              || (*(current) == '\r')
36              || (*(current) == '\t')
37              || (*(current) == '\v') )
38            {
39                break;
40            }
41
42            if (--len) {
43                current--;
44            }
45        }
46
47        newStr = (char*) calloc(len+1,(sizeof(char)));
48        strncpy(newStr,inStr,len);
49        *(newStr+len) = '\0';
50
51        retVal++;
52    }
53
54    return newStr;
55}
56
57std::string null_terminate_str(const char* inStr, int len)
58{
59    int retVal = 0;
60    std::string newStr = "";
61    const char* current = NULL;
62
63    if (inStr) {
64
65        current = inStr+len-1;
66
67        while ((len > 0) && (isspace(*(current)))) {
68            // dont strip off newlines
69
70            if ( (*(current) == '\f')
71              || (*(current) == '\n')
72              || (*(current) == '\r')
73              || (*(current) == '\t')
74              || (*(current) == '\v') )
75            {
76                break;
77            }
78
79            if (--len) {
80                current--;
81            }
82        }
83
84        newStr = std::string(inStr,len);
85
86        retVal++;
87    }
88
89    // return retVal;
90
91    return newStr;
92}
93
94
95void fortranify(const char* inBuff, char* retText, int retTextLen) {
96
97    int inBuffLen = 0;
98    int i = 0;
99
100    if (inBuff && retText && (retTextLen > 0)) {
101        inBuffLen = strlen(inBuff);
102
103        strncpy(retText, inBuff, retTextLen);
104
105        // fortran-ify the string
106        if (inBuffLen < retTextLen) {
107            for (i = inBuffLen; i < retTextLen; i++) {
108                retText[i] = ' ';
109            }
110        }
111    }
112}
Note: See TracBrowser for help on using the repository browser.