Changeset 1850 for trunk/lang
- Timestamp:
- Jul 30, 2010, 8:34:57 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/tcl/src/RpEncodeTclInterface.cc
r1409 r1850 81 81 string = (Rappture::encoding::isBinary(buf, bufLen)) ? "yes" : "no"; 82 82 } else if (('e' == *type) && (strcmp(type,"encoded") == 0)) { 83 83 bool isEncoded; 84 84 85 85 isEncoded = (Rappture::encoding::headerFlags(buf, bufLen) != 0); 86 86 string = (isEncoded) ? "yes" : "no" ; 87 87 } else { 88 89 90 88 Tcl_AppendResult(interp, "bad option \"", type, 89 "\": should be binary or encoded", (char*)NULL); 90 return TCL_ERROR; 91 91 } 92 92 Tcl_SetResult(interp, (char *)string, TCL_STATIC); … … 114 114 * AsSwitch -- 115 115 * 116 * 117 * 116 * Convert a string represent a node number into its integer 117 * value. 118 118 * 119 119 * Results: 120 * 120 * The return value is a standard Tcl result. 121 121 * 122 122 *--------------------------------------------------------------------------- … … 125 125 static int 126 126 AsSwitch( 127 ClientData clientData, 128 Tcl_Interp *interp, 129 const char *switchName, 130 Tcl_Obj *objPtr, 131 char *record, 132 int offset, 133 int flags) 127 ClientData clientData, /* Not used. */ 128 Tcl_Interp *interp, /* Interpreter to send results back to */ 129 const char *switchName, /* Not used. */ 130 Tcl_Obj *objPtr, /* String representation */ 131 char *record, /* Structure record */ 132 int offset, /* Offset to field in structure */ 133 int flags) /* Not used. */ 134 134 { 135 135 int *flagsPtr = (int *)(record + offset); … … 140 140 c = string[0]; 141 141 if ((c == 'b') && (strcmp(string, "b64") == 0)) { 142 142 *flagsPtr = RPENC_B64; 143 143 } else if ((c == 'z') && (strcmp(string, "zb64") == 0)) { 144 144 *flagsPtr = RPENC_Z | RPENC_B64; 145 145 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 146 146 *flagsPtr = RPENC_Z; 147 147 } else { 148 149 150 148 Tcl_AppendResult(interp, "bad value \"", string, 149 "\": should be b64, zb64, or z", (char *)NULL); 150 return TCL_ERROR; 151 151 } 152 152 return TCL_OK; … … 165 165 { 166 166 {SWITCH_CUSTOM, "-as", "z|b64|zb64", 167 167 offsetof(EncodeSwitches, flags), 0, 0, &asSwitch}, 168 168 {SWITCH_BITMASK, "-noheader", "", 169 169 offsetof(EncodeSwitches, flags), 0, RPENC_RAW}, 170 170 {SWITCH_END} 171 171 }; … … 173 173 static int 174 174 EncodeCmd(ClientData clientData, Tcl_Interp *interp, int objc, 175 175 Tcl_Obj *const *objv) 176 176 { 177 177 if (objc < 1) { 178 178 Tcl_AppendResult(interp, "wrong # args: should be \"", 179 180 179 Tcl_GetString(objv[0]), 180 " ?-as z|b64|zb64? ?-noheader? ?--? string\"", (char*)NULL); 181 181 return TCL_ERROR; 182 182 } … … 185 185 int n; 186 186 n = Rp_ParseSwitches(interp, encodeSwitches, objc - 1, objv + 1, &switches, 187 187 SWITCH_OBJV_PARTIAL); 188 188 if (n < 0) { 189 189 return TCL_ERROR; 190 190 } 191 191 int last; … … 193 193 if ((objc - last) != 1) { 194 194 Tcl_AppendResult(interp, "wrong # args: should be \"", 195 196 195 Tcl_GetString(objv[0]), 196 " ?-as z|b64|zb64? ?-noheader? ?--? string\"", (char*)NULL); 197 197 return TCL_ERROR; 198 198 } … … 201 201 string = (const char*)Tcl_GetByteArrayFromObj(objv[last], &nBytes); 202 202 if (nBytes <= 0) { 203 return TCL_OK;// Nothing to encode.203 return TCL_OK; // Nothing to encode. 204 204 } 205 205 Rappture::Buffer buf(string, nBytes); … … 207 207 if (!Rappture::encoding::encode(status, buf, switches.flags)) { 208 208 Tcl_AppendResult(interp, status.remark(), "\n", status.context(), NULL); 209 209 return TCL_ERROR; 210 210 } 211 211 Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 212 212 (const unsigned char*)buf.bytes(), buf.size()); 213 213 return TCL_OK; 214 214 } … … 225 225 * ::Rappture::encoding::decode ?-as z|b64|zb64? <string> 226 226 * 227 * 228 * 229 * 227 * I'd rather the interface be 228 * 229 * decode -b64 -z string 230 230 */ 231 231 … … 237 237 { 238 238 {SWITCH_CUSTOM, "-as", "z|b64|zb64", 239 239 offsetof(DecodeSwitches, flags), 0, 0, &asSwitch}, 240 240 {SWITCH_BITMASK, "-noheader", "", 241 241 offsetof(DecodeSwitches, flags), 0, RPENC_RAW}, 242 242 {SWITCH_END} 243 243 }; … … 245 245 static int 246 246 DecodeCmd(ClientData clientData, Tcl_Interp *interp, int objc, 247 247 Tcl_Obj *const *objv) 248 248 { 249 249 if (objc < 1) { 250 250 Tcl_AppendResult(interp, "wrong # args: should be \"", 251 251 Tcl_GetString(objv[0]), 252 252 " ?-as z|b64|zb64? ?--? <string>\"", (char*)NULL); 253 253 return TCL_ERROR; … … 258 258 int n; 259 259 n = Rp_ParseSwitches(interp, decodeSwitches, objc - 1, objv + 1, &switches, 260 260 SWITCH_OBJV_PARTIAL); 261 261 if (n < 0) { 262 262 return TCL_ERROR; 263 263 } 264 264 int last; … … 266 266 if ((objc - last) != 1) { 267 267 Tcl_AppendResult(interp, "wrong # args: should be \"", 268 269 268 Tcl_GetString(objv[0]), 269 " ?-as z|b64|zb64? ?--? string\"", (char*)NULL); 270 270 return TCL_ERROR; 271 271 } … … 274 274 string = (const char*)Tcl_GetByteArrayFromObj(objv[last], &nBytes); 275 275 if (nBytes <= 0) { 276 return TCL_OK;// Nothing to decode.276 return TCL_OK; // Nothing to decode. 277 277 } 278 278 Rappture::Buffer buf(string, nBytes); … … 280 280 if (!Rappture::encoding::decode(status, buf, switches.flags)) { 281 281 Tcl_AppendResult(interp, status.remark(), "\n", status.context(), NULL); 282 282 return TCL_ERROR; 283 283 } 284 284 Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 285 286 return TCL_OK; 287 } 285 (const unsigned char*)buf.bytes(), buf.size()); 286 return TCL_OK; 287 }
Note: See TracChangeset
for help on using the changeset viewer.