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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/**
*
* VOCUTIL_F77.C -- Utility routines to support Fortran bindings.
*
* @file vocUtil_f77.c
* @author Michael Fitzpatrick
* @version June 2006
*
*************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#define _VOCLIENT_LIB_
#include "VOClient.h"
/**
* Local interface declarations.
*/
char *sstrip (char *instr, int len);
void spad (char *outstr, int len);
int typecode (char *typestr);
/**
* SSTRIP -- Strip trailing blanks from a string and add null terminator.
*
* @brief Strip trailing blanks from a string and add null terminator
* @fn outstr = sstrip (char *instr, int len)
*
* @param instr string to strip
* @param len length of input string
* @returns stripped output string
*/
#define SZ_LINE 1024
char *sstrip (char *instr, int len)
{
if (len > 0 && instr) {
char *newstr = calloc (1, len+1);
int i = len;
strncpy (newstr, instr, len);
/* trim trailing blanks */
for (i=len; newstr[i] == ' ' || newstr[i] == '\0'; i--)
newstr[i] = '\0';
return (newstr);
}
return ((char *) NULL);
}
/**
* SPAD -- Pad a string to length 'len' with blanks, as Fortran requires.
*
* @brief Pad a string to length 'len' with blanks, as Fortran requires.
* @fn spad (char *outstr, int len)
*
* @param outstr string to pad
* @param len pad string to this length
* @returns nothing
*/
void spad (char *outstr, int len)
{
int i=0;
#ifndef _NO_SPAD_
for (i = strlen(outstr); i < len; i++)
outstr[i] = ' ';
#endif
}
/**
* TYPECODE -- Convert a DAL type string to a code value.
*
* @brief Convert a DAL type string to a code value.
* @fn val = typecode (char *typestr)
*
* @param typestr DAL type string
* @returns DAL type code
*/
#define SZ_TYPECODE 32
int typecode (char *typestr)
{
char type[SZ_TYPECODE];
int i = 0;
memset (type, 0, SZ_TYPECODE);
for (i=0; typestr[i] && i < SZ_TYPECODE; i++)
type[i] = tolower (typestr[i]);
if (strcmp (type, "dal") == 0) return (DAL_CONN);
if (strcmp (type, "cone") == 0) return (CONE_CONN);
if (strcmp (type, "siap") == 0) return (SIAP_CONN);
if (strcmp (type, "ssap") == 0) return (SSAP_CONN);
if (strcmp (type, "slap") == 0) return (SLAP_CONN);
return (ERR);
}
|