Author: rhs
Date: Fri Oct 12 01:09:34 2012
New Revision: 1397409
URL: http://svn.apache.org/viewvc?rev=1397409&view=rev
Log:
removed dead code
Modified:
qpid/proton/trunk/proton-c/src/codec/codec.c
Modified: qpid/proton/trunk/proton-c/src/codec/codec.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/codec/codec.c?rev=1397409&r1=1397408&r2=1397409&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/codec/codec.c (original)
+++ qpid/proton/trunk/proton-c/src/codec/codec.c Fri Oct 12 01:09:34 2012
@@ -50,13 +50,6 @@ int pn_print_atoms(const pn_atoms_t *ato
ssize_t pn_format_atoms(char *buf, size_t n, pn_atoms_t atoms);
int pn_format_atom(pn_bytes_t *bytes, pn_atom_t atom);
-int pn_fill_atoms(pn_atoms_t *atoms, const char *fmt, ...);
-int pn_vfill_atoms(pn_atoms_t *atoms, const char *fmt, va_list ap);
-int pn_ifill_atoms(pn_atoms_t *atoms, const char *fmt, ...);
-int pn_vifill_atoms(pn_atoms_t *atoms, const char *fmt, va_list ap);
-int pn_scan_atoms(const pn_atoms_t *atoms, const char *fmt, ...);
-int pn_vscan_atoms(const pn_atoms_t *atoms, const char *fmt, va_list ap);
-
typedef union {
uint32_t i;
uint32_t a[2];
@@ -1053,765 +1046,6 @@ int pn_decode_atom(pn_bytes_t *bytes, pn
return 0;
}
-int pn_fill_one(pn_atoms_t *atoms, const char *fmt, ...);
-
-int pn_vfill_one(pn_atoms_t *atoms, const char **fmt, va_list *ap, bool skip,
int *nvals)
-{
- int err, count;
- char code = **fmt;
- if (!code) return PN_ARG_ERR;
- if (!skip && !atoms->size) return PN_OVERFLOW;
- pn_atom_t skipped;
- pn_atom_t *atom;
- if (skip) {
- atom = &skipped;
- } else {
- atom = atoms->start;
- pn_atoms_ltrim(atoms, 1);
- }
- (*fmt)++;
-
- switch (code) {
- case 'n':
- *atom = (pn_atom_t) {PN_NULL, {0}};
- (*nvals)++;
- return 0;
- case 'o':
- atom->type = PN_BOOL;
- atom->u.as_bool = va_arg(*ap, int);
- (*nvals)++;
- return 0;
- case 'B':
- atom->type = PN_UBYTE;
- atom->u.as_ubyte = va_arg(*ap, unsigned int);
- (*nvals)++;
- return 0;
- case 'b':
- atom->type = PN_BYTE;
- atom->u.as_byte = va_arg(*ap, int);
- (*nvals)++;
- return 0;
- case 'H':
- atom->type = PN_USHORT;
- atom->u.as_ushort = va_arg(*ap, unsigned int);
- (*nvals)++;
- return 0;
- case 'h':
- atom->type = PN_SHORT;
- atom->u.as_short = va_arg(*ap, int);
- (*nvals)++;
- return 0;
- case 'I':
- atom->type = PN_UINT;
- atom->u.as_uint = va_arg(*ap, uint32_t);
- (*nvals)++;
- return 0;
- case 'i':
- atom->type = PN_INT;
- atom->u.as_int = va_arg(*ap, int32_t);
- (*nvals)++;
- return 0;
- case 'c':
- atom->type = PN_CHAR;
- atom->u.as_char = va_arg(*ap, pn_char_t);
- (*nvals)++;
- return 0;
- case 'L':
- atom->type = PN_ULONG;
- atom->u.as_ulong = va_arg(*ap, uint64_t);
- (*nvals)++;
- return 0;
- case 'l':
- atom->type = PN_LONG;
- atom->u.as_long = va_arg(*ap, int64_t);
- (*nvals)++;
- return 0;
- case 't':
- atom->type = PN_TIMESTAMP;
- atom->u.as_timestamp = va_arg(*ap, pn_timestamp_t);
- (*nvals)++;
- return 0;
- case 'f':
- atom->type = PN_FLOAT;
- atom->u.as_float = va_arg(*ap, double);
- (*nvals)++;
- return 0;
- case 'd':
- atom->type = PN_DOUBLE;
- atom->u.as_double = va_arg(*ap, double);
- (*nvals)++;
- return 0;
- case 'z':
- atom->type = PN_BINARY;
- atom->u.as_binary.size = va_arg(*ap, size_t);
- atom->u.as_binary.start = va_arg(*ap, char *);
- if (!atom->u.as_binary.start)
- *atom = (pn_atom_t) {PN_NULL, {0}};
- (*nvals)++;
- return 0;
- case 'S':
- atom->type = PN_STRING;
- atom->u.as_string.start = va_arg(*ap, char *);
- if (atom->u.as_string.start)
- atom->u.as_string.size = strlen(atom->u.as_string.start);
- else
- *atom = (pn_atom_t) {PN_NULL, {0}};
- (*nvals)++;
- return 0;
- case 's':
- atom->type = PN_SYMBOL;
- atom->u.as_symbol.start = va_arg(*ap, char *);
- if (atom->u.as_symbol.start)
- atom->u.as_symbol.size = strlen(atom->u.as_symbol.start);
- else
- *atom = (pn_atom_t) {PN_NULL, {0}};
- (*nvals)++;
- return 0;
- case 'D':
- *atom = (pn_atom_t) {PN_DESCRIPTOR, {0}};
- count = 0;
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- if (count != 1) return PN_ARG_ERR;
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- if (count != 2) return PN_ARG_ERR;
- (*nvals)++;
- return 0;
- case 'T':
- atom->type = PN_TYPE;
- atom->u.type = va_arg(*ap, int);
- (*nvals)++;
- return 0;
- case '@':
- atom->type = PN_ARRAY;
- count = 0;
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- if (count != 1 || atoms->start[-1].type != PN_TYPE) {
- fprintf(stderr, "expected a single PN_TYPE, got %i atoms ending in %s\n",
- count, pn_type_str(atoms->start[-1].type));
- return PN_ARG_ERR;
- }
- if (**fmt != '[') {
- fprintf(stderr, "expected '['\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- count = 0;
- while (**fmt && **fmt != ']') {
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- }
- if (**fmt != ']') {
- fprintf(stderr, "expected ']'\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- atom->u.count = count;
- (*nvals)++;
- return 0;
- case '[':
- atom->type = PN_LIST;
- count = 0;
- while (**fmt && **fmt != ']') {
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- }
- if (**fmt != ']') {
- fprintf(stderr, "expected ']'\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- atom->u.count = count;
- (*nvals)++;
- return 0;
- case '{':
- atom->type = PN_MAP;
- count = 0;
- while (**fmt && **fmt != '}') {
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- }
- if (**fmt != '}') {
- fprintf(stderr, "expected '}'\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- atom->u.count = count;
- (*nvals)++;
- return 0;
- case '?':
- count = 0;
- if (va_arg(*ap, int)) {
- // rewind atoms by one
- if (!skip) {
- atoms->start--;
- atoms->size++;
- }
- err = pn_vfill_one(atoms, fmt, ap, skip, &count);
- if (err) return err;
- } else {
- *atom = (pn_atom_t) {PN_NULL, {0}};
- err = pn_vfill_one(NULL, fmt, ap, true, &count);
- if (err) return err;
- }
- (*nvals)++;
- return 0;
- case '*':
- {
- int count = va_arg(*ap, int);
- void *ptr = va_arg(*ap, void *);
- // rewind atoms by one
- if (!skip) {
- atoms->start--;
- atoms->size++;
- }
-
- char c = **fmt;
- (*fmt)++;
-
- switch (c)
- {
- case 's':
- {
- char **sptr = ptr;
- for (int i = 0; i < count; i++)
- {
- char *sym = *(sptr++);
- err = pn_fill_one(atoms, "s", sym);
- if (err) return err;
- (*nvals)++;
- }
- }
- break;
- default:
- fprintf(stderr, "unrecognized * code: 0x%.2X '%c'\n", code, code);
- return PN_ARG_ERR;
- }
-
- return 0;
- }
- default:
- fprintf(stderr, "unrecognized fill code: 0x%.2X '%c'\n", code, code);
- return PN_ARG_ERR;
- }
-}
-
-int pn_fill_one(pn_atoms_t *atoms, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- int count = 0;
- int err = pn_vfill_one(atoms, &fmt, &ap, false, &count);
- va_end(ap);
- return err;
-}
-
-int pn_vfill_atoms(pn_atoms_t *atoms, const char *fmt, va_list ap)
-{
- const char *pos = fmt;
- pn_atoms_t copy = *atoms;
- int count = 0;
- va_list cp;
- va_copy(cp, ap);
-
- while (*pos) {
- int err = pn_vfill_one(©, &pos, &cp, false, &count);
- if (err) {
- va_end(cp);
- return err;
- }
- }
-
- va_end(cp);
-
- atoms->size -= copy.size;
- return 0;
-}
-
-int pn_fill_atoms(pn_atoms_t *atoms, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- int n = pn_vfill_atoms(atoms, fmt, ap);
- va_end(ap);
- return n;
-}
-
-int pn_vifill_atoms(pn_atoms_t *atoms, const char *fmt, va_list ap)
-{
- pn_atoms_t copy = *atoms;
- int err = pn_vfill_atoms(©, fmt, ap);
- if (err) return err;
- atoms->start = copy.start + copy.size;
- atoms->size -= copy.size;
- return 0;
-}
-
-int pn_ifill_atoms(pn_atoms_t *atoms, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- int err = pn_vifill_atoms(atoms, fmt, ap);
- va_end(ap);
- return err;
-}
-
-int pn_skip(pn_atoms_t *atoms, size_t n)
-{
- for (int i = 0; i < n; i++) {
- if (!atoms->size) return PN_UNDERFLOW;
- pn_atom_t *atom = atoms->start;
- pn_atoms_ltrim(atoms, 1);
- int err;
-
- switch (atom->type)
- {
- case PN_DESCRIPTOR:
- err = pn_skip(atoms, 2);
- if (err) return err;
- break;
- case PN_ARRAY:
- err = pn_skip(atoms, 1);
- if (err) return err;
- err = pn_skip(atoms, atom->u.count);
- if (err) return err;
- break;
- case PN_LIST:
- case PN_MAP:
- err = pn_skip(atoms, atom->u.count);
- if (err) return err;
- break;
- default:
- break;
- }
- }
-
- return 0;
-}
-
-int pn_scan_one(pn_atoms_t *atoms, const char **fmt, va_list *ap, bool
*scanned)
-{
- char code = **fmt;
- pn_atom_t *atom = atoms ? atoms->start : NULL;
- (*fmt)++;
- size_t count;
- int err;
-
- switch (code) {
- case 'n':
- if (atom && atom->type == PN_NULL) {
- *scanned = true;
- } else {
- *scanned = false;
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'o':
- {
- bool *value = va_arg(*ap, bool *);
- if (atom && atom->type == PN_BOOL) {
- *value = atom->u.as_bool;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'B':
- {
- uint8_t *value = va_arg(*ap, uint8_t *);
- if (atom && atom->type == PN_UBYTE) {
- *value = atom->u.as_ubyte;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'b':
- {
- int8_t *value = va_arg(*ap, int8_t *);
- if (atom && atom->type == PN_BYTE) {
- *value = atom->u.as_byte;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'H':
- {
- uint16_t *value = va_arg(*ap, uint16_t *);
- if (atom && atom->type == PN_USHORT) {
- *value = atom->u.as_ushort;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'h':
- {
- int16_t *value = va_arg(*ap, int16_t *);
- if (atom && atom->type == PN_SHORT) {
- *value = atom->u.as_short;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'I':
- {
- uint32_t *value = va_arg(*ap, uint32_t *);
- if (atom && atom->type == PN_UINT) {
- *value = atom->u.as_uint;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'i':
- {
- int32_t *value = va_arg(*ap, int32_t *);
- if (atom && atom->type == PN_INT) {
- *value = atom->u.as_int;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'c':
- {
- uint32_t *value = va_arg(*ap, pn_char_t *);
- if (atom && atom->type == PN_CHAR) {
- *value = atom->u.as_char;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'L':
- {
- uint64_t *value = va_arg(*ap, uint64_t *);
- if (atom && atom->type == PN_ULONG) {
- *value = atom->u.as_ulong;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'l':
- {
- int64_t *value = va_arg(*ap, int64_t *);
- if (atom && atom->type == PN_LONG) {
- *value = atom->u.as_long;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 't':
- {
- pn_timestamp_t *value = va_arg(*ap, pn_timestamp_t *);
- if (atom && atom->type == PN_TIMESTAMP) {
- *value = atom->u.as_timestamp;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'f':
- {
- float *value = va_arg(*ap, float *);
- if (atom && atom->type == PN_FLOAT) {
- *value = atom->u.as_float;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'd':
- {
- double *value = va_arg(*ap, double *);
- if (atom && atom->type == PN_DOUBLE) {
- *value = atom->u.as_double;
- *scanned = true;
- } else {
- *value = 0;
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'z':
- {
- pn_bytes_t *bytes = va_arg(*ap, pn_bytes_t *);
- if (atom && atom->type == PN_BINARY) {
- *bytes = atom->u.as_binary;
- *scanned = true;
- } else {
- *bytes = (pn_bytes_t) {0, 0};
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'S':
- {
- pn_bytes_t *bytes = va_arg(*ap, pn_bytes_t *);
- if (atom && atom->type == PN_STRING) {
- *bytes = atom->u.as_string;
- *scanned = true;
- } else {
- *bytes = (pn_bytes_t) {0, 0};
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 's':
- {
- pn_bytes_t *bytes = va_arg(*ap, pn_bytes_t *);
- if (atom && atom->type == PN_SYMBOL) {
- *bytes = atom->u.as_symbol;
- *scanned = true;
- } else {
- *bytes = (pn_bytes_t) {0, 0};
- *scanned = false;
- }
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case 'D':
- {
- if (atoms) pn_atoms_ltrim(atoms, 1);
- bool scd, scv;
- pn_atoms_t *ratoms;
- if (atom && atom->type == PN_DESCRIPTOR) {
- ratoms = atoms;
- } else {
- ratoms = NULL;
- }
- if (!**fmt) {
- fprintf(stderr, "expecting descriptor\n");
- return PN_ARG_ERR;
- }
- err = pn_scan_one(ratoms, fmt, ap, &scd);
- if (err) return err;
- if (!**fmt) {
- fprintf(stderr, "expecting described value\n");
- return PN_ARG_ERR;
- }
- err = pn_scan_one(ratoms, fmt, ap, &scv);
- if (err) return err;
- *scanned = scd && scv;
- }
- return 0;
- case 'T':
- if (atom && atom->type == PN_TYPE) {
- pn_type_t *type = va_arg(*ap, pn_type_t *);
- *type = atom->u.type;
- *scanned = true;
- } else {
- *scanned = false;
- }
- if (atoms) pn_atoms_ltrim(atoms, 1);
- return 0;
- case '@':
- if (atoms) pn_atoms_ltrim(atoms, 1);
- if (atom && atom->type == PN_ARRAY) {
- bool sc;
- if (!**fmt) {
- fprintf(stderr, "type must follow array\n");
- return PN_ARG_ERR;
- }
- err = pn_scan_one(atoms, fmt, ap, &sc);
- if (err) return err;
- if (**fmt != '[') {
- fprintf(stderr, "expected '['\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- count = 0;
- while (**fmt && **fmt != ']') {
- bool sce;
- if (count < atom->u.count) {
- err = pn_scan_one(atoms, fmt, ap, &sce);
- if (err) return err;
- sc = sc && sce;
- } else {
- err = pn_scan_one(NULL, fmt, ap, &sce);
- if (err) return err;
- sc = sc && sce;
- }
- count++;
- }
- if (**fmt != ']') {
- fprintf(stderr, "expected ']'\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- if (count < atom->u.count) {
- err = pn_skip(atoms, atom->u.count - count);
- if (err) return err;
- }
- *scanned = (atom->u.count == count) && sc;
- } else {
- *scanned = false;
- }
- return 0;
- case '[':
- {
- if (atoms) pn_atoms_ltrim(atoms, 1);
- pn_atoms_t *ratoms = atom && atom->type == PN_LIST ? atoms : NULL;
- count = 0;
- bool sc = true;
- while (**fmt && **fmt != ']') {
- bool sce;
- if (atom && count < atom->u.count) {
- err = pn_scan_one(ratoms, fmt, ap, &sce);
- if (err) return err;
- sc = sc && sce;
- } else {
- err = pn_scan_one(NULL, fmt, ap, &sce);
- if (err) return err;
- sc = sc && sce;
- }
- count++;
- }
- if (**fmt != ']') {
- fprintf(stderr, "expected ']'\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- if (atom && count < atom->u.count) {
- err = pn_skip(ratoms, atom->u.count - count);
- if (err) return err;
- }
- *scanned = (atom && atom->u.count == count) && sc;
- }
- return 0;
- case '{':
- if (atoms) pn_atoms_ltrim(atoms, 1);
- if (atom && atom->type == PN_MAP) {
- count = 0;
- bool sc = true;
- while (**fmt && **fmt != '}') {
- bool sce;
- if (count < atom->u.count) {
- err = pn_scan_one(atoms, fmt, ap, &sce);
- if (err) return err;
- sc = sc && sce;
- } else {
- err = pn_scan_one(NULL, fmt, ap, &sce);
- if (err) return err;
- sc = sc && sce;
- }
- count++;
- }
- if (**fmt != '}') {
- fprintf(stderr, "expected '}'\n");
- return PN_ARG_ERR;
- }
- (*fmt)++;
- if (count < atom->u.count) {
- err = pn_skip(atoms, atom->u.count - count);
- if (err) return err;
- }
- *scanned = (atom->u.count == count) && sc;
- } else {
- *scanned = false;
- }
- return 0;
- case '.':
- if (atoms) {
- err = pn_skip(atoms, 1);
- if (err) return err;
- }
- *scanned = true;
- return 0;
- case '?':
- {
- if (!**fmt) {
- fprintf(stderr, "codes must follow ?\n");
- return PN_ARG_ERR;
- }
- bool *sc = va_arg(*ap, bool *);
- err = pn_scan_one(atoms, fmt, ap, sc);
- if (err) return err;
- *scanned = true;
- }
- return 0;
- default:
- fprintf(stderr, "unrecognized scan code: 0x%.2X '%c'\n", code, code);
- return PN_ARG_ERR;
- }
-}
-
-int pn_scan_atoms(const pn_atoms_t *atoms, const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- int err = pn_vscan_atoms(atoms, fmt, ap);
- va_end(ap);
- return err;
-}
-
-int pn_vscan_atoms(const pn_atoms_t *atoms, const char *fmt, va_list ap)
-{
- pn_atoms_t copy = *atoms;
- const char *pos = fmt;
- bool scanned;
- va_list cp;
- va_copy(cp, ap);
-
- while (*pos) {
- int err = pn_scan_one(©, &pos, &cp, &scanned);
- if (err) {
- va_end(cp);
- return err;
- }
- }
-
- va_end(cp);
-
- return 0;
-}
-
// data
typedef struct {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]