Changeset 0d1a8fd in mainline
- Timestamp:
- 2012-06-24T18:44:34Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2da0bb
- Parents:
- 03b2b2c
- Location:
- uspace/app/bithenge
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/linux/os.h
r03b2b2c r0d1a8fd 85 85 } 86 86 87 static inline char *str_dup(const char *s) 88 { 89 return strdup(s); 90 } 91 87 92 static inline char *str_ndup(const char *s, size_t max_len) 88 93 { … … 100 105 } 101 106 107 static inline uint32_t uint32_t_be2host(uint32_t val) 108 { 109 return be32toh(val); 110 } 111 102 112 #endif -
uspace/app/bithenge/script.c
r03b2b2c r0d1a8fd 232 232 } 233 233 234 /** Find a transform by name. 234 /** Find a transform by name. A reference will be added to the transform. 235 235 * @return The found transform, or NULL if none was found. */ 236 236 static bithenge_transform_t *get_named_transform(state_t *state, 237 237 const char *name) 238 238 { 239 for (transform_list_t *e = state->transform_list; e; e = e->next) 240 if (!str_cmp(e->name, name)) 239 for (transform_list_t *e = state->transform_list; e; e = e->next) { 240 if (!str_cmp(e->name, name)) { 241 bithenge_transform_inc_ref(e->transform); 241 242 return e->transform; 243 } 244 } 245 for (int i = 0; bithenge_primitive_transforms[i].name; i++) { 246 if (!str_cmp(bithenge_primitive_transforms[i].name, name)) { 247 bithenge_transform_t *xform = 248 bithenge_primitive_transforms[i].transform; 249 bithenge_transform_inc_ref(xform); 250 return xform; 251 } 252 } 242 253 return NULL; 243 254 } -
uspace/app/bithenge/transform.c
r03b2b2c r0d1a8fd 35 35 */ 36 36 37 #include <assert.h> 37 38 #include <errno.h> 39 #include <stdlib.h> 38 40 #include "blob.h" 39 41 #include "transform.h" … … 41 43 static int transform_indestructible(bithenge_transform_t *xform) 42 44 { 43 return EINVAL; 45 assert(false); 46 return EOK; 44 47 } 45 48 … … 64 67 } 65 68 66 static int uint32le_prefix_length(bithenge_transform_t *xform, 67 bithenge_blob_t *blob, aoff64_t *out) 69 static int uint32be_apply(bithenge_transform_t *xform, bithenge_node_t *in, 70 bithenge_node_t **out) 71 { 72 int rc; 73 if (bithenge_node_type(in) != BITHENGE_NODE_BLOB) 74 return EINVAL; 75 bithenge_blob_t *blob = bithenge_node_as_blob(in); 76 77 // Try to read 5 bytes and fail if the blob is too long. 78 uint32_t val[2]; 79 aoff64_t size = sizeof(val[0]) + 1; 80 rc = bithenge_blob_read(blob, 0, (char *)val, &size); 81 if (rc != EOK) 82 return rc; 83 if (size != 4) 84 return EINVAL; 85 86 return bithenge_new_integer_node(out, uint32_t_be2host(val[0])); 87 } 88 89 static int prefix_length_4(bithenge_transform_t *xform, bithenge_blob_t *blob, 90 aoff64_t *out) 68 91 { 69 92 *out = 4; … … 73 96 static const bithenge_transform_ops_t uint32le_ops = { 74 97 .apply = uint32le_apply, 75 .prefix_length = uint32le_prefix_length,98 .prefix_length = prefix_length_4, 76 99 .destroy = transform_indestructible, 77 100 }; 78 101 79 static bithenge_transform_t uint32le_transform = { 102 static const bithenge_transform_ops_t uint32be_ops = { 103 .apply = uint32be_apply, 104 .prefix_length = prefix_length_4, 105 .destroy = transform_indestructible, 106 }; 107 108 /** The little-endian 32-bit unsigned integer transform. */ 109 bithenge_transform_t bithenge_uint32le_transform = { 80 110 &uint32le_ops, 1 81 111 }; 82 112 83 /** Create a little-endian 32-bit unsigned integer transform. 84 * @param out Holds the transform. 85 * @return EOK on success or an error code from errno.h. */ 86 int bithenge_uint32le_transform(bithenge_transform_t **out) 87 { 88 *out = &uint32le_transform; 89 return EOK; 90 } 113 /** The big-endian 32-bit unsigned integer transform. */ 114 bithenge_transform_t bithenge_uint32be_transform = { 115 &uint32be_ops, 1 116 }; 117 118 static bithenge_named_transform_t primitive_transforms[] = { 119 {"uint32le", &bithenge_uint32le_transform}, 120 {"uint32be", &bithenge_uint32be_transform}, 121 {NULL, NULL} 122 }; 123 124 /** An array of named built-in transforms. */ 125 bithenge_named_transform_t *bithenge_primitive_transforms = primitive_transforms; 91 126 92 127 /** @} -
uspace/app/bithenge/transform.h
r03b2b2c r0d1a8fd 117 117 } 118 118 119 int bithenge_uint32le_transform(bithenge_transform_t **out); 119 /** A transform with a name. */ 120 typedef struct { 121 const char *name; 122 bithenge_transform_t *transform; 123 } bithenge_named_transform_t; 124 125 extern bithenge_transform_t bithenge_uint32le_transform; 126 extern bithenge_transform_t bithenge_uint32be_transform; 127 extern bithenge_named_transform_t *bithenge_primitive_transforms; 120 128 121 129 #endif
Note:
See TracChangeset
for help on using the changeset viewer.