Changeset 1384 for trunk/lang
- Timestamp:
- Apr 6, 2009, 10:19:50 AM (16 years ago)
- Location:
- trunk/lang
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/python/Rappture/PyRpEncode.cc
r1368 r1384 45 45 } 46 46 47 rv = PyFloat_FromDouble(Rappture::encoding::isbinary(data,dlen)); 48 47 rv = PyFloat_FromDouble(Rappture::encoding::isBinary(data,dlen)); 49 48 return rv; 50 49 } -
trunk/lang/tcl/src/RpEncodeTclInterface.cc
r1383 r1384 19 19 } 20 20 21 static Tcl_ObjCmdProc RpTclEncodingIs;22 static Tcl_ObjCmdProc RpTclEncodingEncode;23 static Tcl_ObjCmdProc RpTclEncodingDecode;21 static Tcl_ObjCmdProc IsCmd; 22 static Tcl_ObjCmdProc EncodeCmd; 23 static Tcl_ObjCmdProc DecodeCmd; 24 24 25 25 /**********************************************************************/ … … 37 37 RpEncoding_Init(Tcl_Interp *interp) 38 38 { 39 40 39 Tcl_CreateObjCommand(interp, "::Rappture::encoding::is", 41 RpTclEncodingIs, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);40 IsCmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 42 41 43 42 Tcl_CreateObjCommand(interp, "::Rappture::encoding::encode", 44 RpTclEncodingEncode, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);43 EncodeCmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 45 44 46 45 Tcl_CreateObjCommand(interp, "::Rappture::encoding::decode", 47 RpTclEncodingDecode, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 48 49 return TCL_OK; 50 } 51 52 /**********************************************************************/ 53 // FUNCTION: RpTclEncodingIs() 46 DecodeCmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 47 return TCL_OK; 48 } 49 50 /**********************************************************************/ 51 // FUNCTION: IsCmd() 54 52 /// Rappture::encoding::is checks to see if given string is binary. 55 53 /** … … 61 59 62 60 static int 63 RpTclEncodingIs (ClientData cdata, Tcl_Interp *interp, 64 int objc, Tcl_Obj *const objv[]) 61 IsCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 65 62 { 66 63 Tcl_ResetResult(interp); … … 79 76 const char *buf; 80 77 const char *string; 81 buf = (const char *)Tcl_GetByteArrayFromObj(objv[2], &bufLen);78 buf = (const char *)Tcl_GetByteArrayFromObj(objv[2], &bufLen); 82 79 const char *type = Tcl_GetString(objv[1]); 83 if (('b' == *type) && (strcmp(type,"binary") == 0)) { 84 bool isBinary; 85 86 isBinary = (Rappture::encoding::isbinary(buf,bufLen) != 0); 87 string = (isBinary) ? "yes" : "no" ; 80 if (('b' == *type) && (strcmp(type, "binary") == 0)) { 81 string = (Rappture::encoding::isBinary(buf, bufLen)) ? "yes" : "no"; 88 82 } else if (('e' == *type) && (strcmp(type,"encoded") == 0)) { 89 83 bool isEncoded; … … 101 95 102 96 /**********************************************************************/ 103 // FUNCTION: RpTclEncodingEncode()97 // FUNCTION: EncodeCmd -- 104 98 /// Rappture::encoding::encode function in Tcl, encodes provided string 105 99 /** … … 167 161 typedef struct { 168 162 unsigned int flags; 169 unsigned int noheader;170 163 } EncodeSwitches; 171 164 … … 174 167 {SWITCH_CUSTOM, "-as", "z|b64|zb64", 175 168 offsetof(EncodeSwitches, flags), 0, 0, &asSwitch}, 176 {SWITCH_ VALUE, "-no-header", "",177 offsetof(EncodeSwitches, noheader), 0, true},169 {SWITCH_BITMASK, "-noheader", "", 170 offsetof(EncodeSwitches, flags), 0, RPENC_RAW}, 178 171 {SWITCH_END} 179 172 }; 180 173 181 174 static int 182 RpTclEncodingEncode (ClientData cdata, Tcl_Interp *interp, int objc, 183 175 EncodeCmd(ClientData clientData, Tcl_Interp *interp, int objc, 176 Tcl_Obj *const *objv) 184 177 { 185 178 if (objc < 1) { 186 179 Tcl_AppendResult(interp, "wrong # args: should be \"", 187 180 Tcl_GetString(objv[0]), 188 " ?-as z|b64|zb64? ?-no -header? ?--? string\"", (char*)NULL);181 " ?-as z|b64|zb64? ?-noheader? ?--? string\"", (char*)NULL); 189 182 return TCL_ERROR; 190 183 } 191 184 EncodeSwitches switches; 192 185 switches.flags = 0; 193 switches.noheader = 0;194 186 int n; 195 187 n = Rp_ParseSwitches(interp, encodeSwitches, objc - 1, objv + 1, &switches, … … 203 195 Tcl_AppendResult(interp, "wrong # args: should be \"", 204 196 Tcl_GetString(objv[0]), 205 " ?-as z|b64|zb64? ?-no -header? ?--? string\"", (char*)NULL);197 " ?-as z|b64|zb64? ?-noheader? ?--? string\"", (char*)NULL); 206 198 return TCL_ERROR; 207 199 } … … 213 205 } 214 206 Rappture::Buffer buf(string, nBytes); 215 if (!switches.noheader) {216 switches.flags |= RPENC_HDR;217 }218 207 Rappture::Outcome status; 219 208 if (!Rappture::encoding::encode(status, buf, switches.flags)) { … … 227 216 228 217 /**********************************************************************/ 229 // FUNCTION: RpTclEncodingDecode()218 // FUNCTION: DecodeCmd() 230 219 /// Rappture::encoding::decode function in Tcl, decodes provided string 231 220 /** … … 236 225 * Full function call: 237 226 * ::Rappture::encoding::decode ?-as z|b64|zb64? <string> 227 * 228 * I'd rather the interface be 229 * 230 * decode -b64 -z string 238 231 */ 239 232 … … 246 239 {SWITCH_CUSTOM, "-as", "z|b64|zb64", 247 240 offsetof(DecodeSwitches, flags), 0, 0, &asSwitch}, 241 {SWITCH_BITMASK, "-raw", "", 242 offsetof(DecodeSwitches, flags), 0, RPENC_RAW}, 248 243 {SWITCH_END} 249 244 }; 250 245 251 246 static int 252 RpTclEncodingDecode(ClientData clientData, Tcl_Interp *interp, int objc, 253 247 DecodeCmd(ClientData clientData, Tcl_Interp *interp, int objc, 248 Tcl_Obj *const *objv) 254 249 { 255 250 if (objc < 1) {
Note: See TracChangeset
for help on using the changeset viewer.