ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sla.h
Go to the documentation of this file.
1 /*
2 
3 String list assignment (sla) functions to process assignment instructions and flags.
4 Copyright (C) 1998,1999 Brian T. N. Gunney
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15 
16 You should have received a copy of the GNU Library General Public
17 License along with this library; if not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20 
21 Brian T. N. Gunney, brlynn@minn.net
22 
23 $Id: sla.h,v 1.3 2008/01/08 02:56:44 dquinlan Exp $
24 
25 */
26 
27 /*
28  *
29  * Jeremiah J. Willcock, 10-16-2007
30  * Changed the C++ version of this code to use std::strings rather than char*
31  * to allow better integration with the string version of ROSE command line
32  * processing.
33  *
34  */
35 
36 #ifndef __INCLUDED_sla_hh__
37 #define __INCLUDED_sla_hh__
38 /*
39 $Header: /nfs/casc/overture/ROSE/ROSE2_Repository/ROSE/src/util/commandlineProcessing/sla.h,v 1.3 2008/01/08 02:56:44 dquinlan Exp $
40 */
41 
42 #include "rosedll.h"
43 
44 #ifdef __cplusplus
45 #include <vector>
46 #include <string>
47 #endif
48 
49 #ifndef ARGVCONST
50 #define ARGVCONST
51 #endif
52 
53 ROSE_UTIL_API void sla_set_debug( int d );
54 
55 #if 1
56 #ifdef __cplusplus
57 #define sla_str sla
58 #define sla_none sla
59 #define sla_float sla
60 #define sla_double sla
61 #define sla_int sla
62 #define sla_short sla
63 #define sla_long sla
64 #define sla_uint sla
65 #define sla_ushort sla
66 #define sla_ulong sla
67 #define sla_char sla
68 #endif
69 #endif
70 
71 #ifdef __cplusplus
72 ROSE_UTIL_API int sla_none( std::vector<std::string> &argv, const std::string& flind, const std::string& assop, const std::string& pname, int argd=0 );
73 #else
74 ROSE_UTIL_API int sla_none( int *argc, ARGVCONST char **argv, const char *flind, const char *assop, const char *pname, int argd );
75 #endif
76 
77 /*** generates code for sla prototypes ***/
78 #ifndef SLA_FCN_PROTO
79 #ifdef __cplusplus
80 #define SLA_FCN_PROTO(N,T) \
81 ROSE_UTIL_API int N( std::vector<std::string>& argv \
82  , const std::string& flind \
83  , const std::string& assop \
84  , const std::string& pname \
85  , T *value \
86  , int argd = 0 /* default argument */ \
87  )
88 #else
89 #define SLA_FCN_PROTO(N,T) \
90 ROSE_UTIL_API int N( int *argc \
91  , ARGVCONST char **argv \
92  , const char *flind \
93  , const char *assop \
94  , const char *pname \
95  , T *value \
96  , int argd /* no default argument */ \
97  )
98 #endif
99 #endif
100 
101 /*** generates code for sla function headers ***/
102 #ifndef SLA_FCN_BEGIN
103 #ifdef __cplusplus
104 #define SLA_FCN_BEGIN(N,T) \
105 ROSE_UTIL_API int N( std::vector<std::string>& argv \
106  , const std::string& flind \
107  , const std::string& assop \
108  , const std::string& pname \
109  , T *value \
110  , int argd \
111  )
112 #else
113 #define SLA_FCN_BEGIN(N,T) SLA_FCN_PROTO(N,T)
114 #endif
115 #endif
116 
117 /*** For allocating and deleting memory ***/
118 #include <stdlib.h>
119 
120 /*** Sla for type T (automatically uses function M to modify). ***/
121 #ifndef SLA_MOD
122 #ifdef __cplusplus
123 #define SLA_MOD(M) \
124  std::vector<std::string> rr(argv.size()); \
125  int i, nvalue; \
126  std::string ppname = pname; \
127  if ( !pname.empty() && pname[0] != '*' ) { \
128  ppname = "*" + ppname; \
129  } \
130  nvalue = sla_str( argv, flind, assop, ppname, rr, argd ); \
131  if ( nvalue > 0 && value != NULL ) { \
132  if ( !pname.empty() && pname[0] == '*' ) { \
133  for ( i=0; i<nvalue; i++ ) M( value+i, rr[i] ); \
134  } \
135  else { \
136  for ( i=0; i<nvalue; i++ ) M( value , rr[i] ); \
137  } \
138  } \
139  return nvalue;
140 #else
141 #define SLA_MOD(M) \
142  ARGVCONST char **rr, eol='\0'; \
143  int i, nvalue; \
144  rr = (ARGVCONST char**)malloc( (*argc)*sizeof(ARGVCONST char*) ); \
145  for ( i=0; i<*argc; i++ ) rr[i] = &eol; \
146  nvalue = sla_str( argc, argv, flind, assop, pname, rr, argd ); \
147  if ( nvalue > 0 && value != NULL ) { \
148  if ( *pname == '*' ) { \
149  for ( i=0; i<nvalue; i++ ) M( value+i, rr[i] ); \
150  } \
151  else { \
152  for ( i=0; i<nvalue; i++ ) M( value , rr[i] ); \
153  } \
154  } \
155  free(rr); \
156  return nvalue;
157 #endif
158 #endif
159 
160 /*** Sla for type T (automatically uses function C to convert). ***/
161 #ifndef SLA_CNV
162 #ifdef __cplusplus
163 #define SLA_CNV(C) \
164  std::vector<std::string> rr(argv.size()); \
165  int i, nvalue; \
166  std::string ppname = pname; \
167  if ( pname.empty() || pname[0] != '*' ) { \
168  ppname = "*" + ppname; \
169  } \
170  nvalue = sla_str( argv, flind, assop, ppname, &rr[0], argd ); \
171  if ( nvalue > 0 && value != NULL ) { \
172  if ( !pname.empty() && pname[0] == '*' ) { \
173  for ( i=0; i<nvalue; i++ ) value[i] = C(rr[i].c_str()); \
174  } \
175  else { \
176  for ( i=0; i<nvalue; i++ ) value[0] = C(rr[i].c_str()); \
177  } \
178  } \
179  return nvalue;
180 #else
181 #define SLA_CNV(C) \
182  ARGVCONST char **rr, eol='\0'; \
183  int i, nvalue; \
184  rr = (ARGVCONST char**)malloc( (*argc)*sizeof(ARGVCONST char*) ); \
185  for ( i=0; i<*argc; i++ ) rr[i] = &eol; \
186  nvalue = sla_str( argc, argv, flind, assop, pname, rr, argd ); \
187  if ( nvalue > 0 && value != NULL ) { \
188  if ( *pname == '*' ) { \
189  for ( i=0; i<nvalue; i++ ) value[i] = C(rr[i]); \
190  } \
191  else { \
192  for ( i=0; i<nvalue; i++ ) value[0] = C(rr[i]); \
193  } \
194  } \
195  free(rr); \
196  return nvalue;
197 #endif
198 #endif
199 
200 
201 /*
202  Generate additional sla for various primitive types.
203  The use of the SLA macro makes it
204  difficult to see the prototypes of the functions created.
205  To find the prototypes, try this:
206  > CC -P sla.cc
207  > pgrep 's/^(int sla\s*\([^\{]*).*$/$1;/' sla.i -s
208  */
209 #ifdef __cplusplus
210 SLA_FCN_PROTO( sla_str, std::string );
211 #else
212 SLA_FCN_PROTO( sla_str, ARGVCONST char * );
213 #endif
214 SLA_FCN_PROTO( sla_float, float );
215 SLA_FCN_PROTO( sla_double, double );
216 SLA_FCN_PROTO( sla_int, int );
217 SLA_FCN_PROTO( sla_short, short );
218 SLA_FCN_PROTO( sla_long, long );
219 SLA_FCN_PROTO( sla_uint, unsigned int );
220 SLA_FCN_PROTO( sla_ushort, unsigned short );
221 SLA_FCN_PROTO( sla_ulong, unsigned long );
222 SLA_FCN_PROTO( sla_char, char );
223 
224 
225 
226 
227 #endif