void begin (int argc, const char * argv[]) { size_t infile; size_t n_fields; size_t field; size_t n_params; size_t param; const char * comment; infile = Infile ("-"); File_fix (infile, 1, 0); puts ("#: taql-0.1/text"); n_fields = N_fields (infile); for (field = 0; field < n_fields; ++field) { fputs ("# field ", stdout); Fprint (stdout, Field_name (infile, field)); fputs (" ", stdout); Fprint (stdout, Field_type (infile, field)); fputc ('\n', stdout); } n_params = N_params (infile); for (param = 0; param < n_params; ++param) { fputs ("# param ", stdout); Fprint (stdout, Param_name (infile, param)); fputs (" ", stdout); Fprint (stdout, Param_value (infile, param)); fputc ('\n', stdout); } comment = Comment (infile); if (!comment || !comment[0]) { fputs ("#.\n", stdout); } else { const char * c; fputs ("#-\n# ", stdout); for (c = comment; *c; ++c) { if (*c == '\n') fputs ("\n# ", stdout); else fputc (*c, stdout); } fputs ("\n#.\n", stdout); } while (N_ahead (infile)) { for (field = 0; field < n_fields; ++field) { if (field) fputc (' ', stdout); Fprint (stdout, Peek (infile, 0, field)); } fputc ('\n', stdout); Advance (infile, 1); } }
PyObject * Field_str ( Field * self ) { PyObject * pyobj, * string, * typeobj; if ( ! ( string = PyString_FromFormat ( "Field[" ) ) ) return 0; /* Output the field name - if present */ if ( self->field.flags & FUDGE_FIELD_HAS_NAME ) { PyObject * namestr, * nameobj = Field_name ( self ); if ( ! nameobj ) goto clear_string_and_fail; namestr = PyObject_Str ( nameobj ); Py_DECREF( nameobj ); if ( ! namestr ) goto clear_string_and_fail; PyString_ConcatAndDel ( &string, namestr ); if ( ! string ) return 0; } /* Separator between name and ordinal */ PyString_ConcatAndDel ( &string, PyString_FromString ( "|" ) ); if ( ! string ) return 0; /* Output the field ordinal - if present */ if ( self->field.flags & FUDGE_FIELD_HAS_ORDINAL ) { PyString_ConcatAndDel ( &string, PyString_FromFormat ( "%d", self->field.ordinal ) ); if ( ! string ) return 0; } /* Separator between ordinal and type name */ PyString_ConcatAndDel ( &string, PyString_FromString ( "|" ) ); if ( ! string ) return 0; /* Retrieve the type name from the lookup in the types module; if * unknown, display the type id */ if ( ! ( typeobj = PyInt_FromLong ( self->field.type ) ) ) goto clear_string_and_fail; pyobj = PyDict_GetItem ( s_typenamedict, typeobj ); Py_DECREF( typeobj ); if ( pyobj ) PyString_Concat ( &string, pyobj ); else PyString_ConcatAndDel ( &string, PyString_FromFormat ( "%d", self->field.type ) ); if ( ! string ) return 0; /* Separator between type name and the value */ PyString_ConcatAndDel ( &string, PyString_FromString ( ":" ) ); if ( ! string ) return 0; /* Output the stringized field value */ switch ( self->field.type ) { case FUDGE_TYPE_INDICATOR: break; /* For all non-byte array types, use the stringized Python value */ case FUDGE_TYPE_BOOLEAN: case FUDGE_TYPE_BYTE: case FUDGE_TYPE_SHORT: case FUDGE_TYPE_INT: case FUDGE_TYPE_LONG: case FUDGE_TYPE_FLOAT: case FUDGE_TYPE_DOUBLE: case FUDGE_TYPE_SHORT_ARRAY: case FUDGE_TYPE_INT_ARRAY: case FUDGE_TYPE_LONG_ARRAY: case FUDGE_TYPE_FLOAT_ARRAY: case FUDGE_TYPE_DOUBLE_ARRAY: case FUDGE_TYPE_STRING: case FUDGE_TYPE_FUDGE_MSG: case FUDGE_TYPE_DATE: case FUDGE_TYPE_TIME: case FUDGE_TYPE_DATETIME: if ( ! ( pyobj = Field_value ( self ) ) ) goto clear_string_and_fail; PyString_ConcatAndDel ( &string, PyObject_Str ( pyobj ) ); Py_DECREF( pyobj ); break; /* Assume everything else is just a bundle of (potentially * unprintable) bytes */ default: PyString_ConcatAndDel ( &string, PyString_FromFormat ( "<%d bytes>", self->field.numbytes ) ); break; } if ( string ) PyString_ConcatAndDel ( &string, PyString_FromString ( "]" ) ); return string; clear_string_and_fail: Py_XDECREF( string ); return 0; }
void begin (int argc, const char * argv[]) { size_t infile; size_t n_fields; size_t field; size_t n_params; size_t param; const char * comment; int mer_field[256] = {0, }; infile = Infile ("-"); File_fix (infile, 1, 0); puts ("#: taql-0.1/text"); n_fields = N_fields (infile); for (field = 0; field < n_fields; ++field) { Taql name; Taql type; fputs ("# field ", stdout); name = Field_name (infile, field); Fprint (stdout, name); fputs (" ", stdout); type = Field_type (infile, field); Fprint (stdout, type); fputc ('\n', stdout); if ( Eq (type, Sym ("uint64")) && ('m' == Sym_ref(name, 0)) && ('e' == Sym_ref(name, 1)) && ('r' == Sym_ref(name, 2)) && isdigit (Sym_ref(name, 3))) { mer_field[field] = 1; } } n_params = N_params (infile); for (param = 0; param < n_params; ++param) { fputs ("# param ", stdout); Fprint (stdout, Param_name (infile, param)); fputs (" ", stdout); Fprint (stdout, Param_value (infile, param)); fputc ('\n', stdout); } comment = Comment (infile); if (!comment || !comment[0]) { fputs ("#.\n", stdout); } else { const char * c; fputs ("#-\n# ", stdout); for (c = comment; *c; ++c) { if (*c == '\n') fputs ("\n# ", stdout); else fputc (*c, stdout); } fputs ("\n#.\n", stdout); } while (N_ahead (infile)) { for (field = 0; field < n_fields; ++field) { Taql value; if (field) fputc (' ', stdout); value = Peek (infile, 0, field); if (!mer_field [field]) { Fprint (stdout, value); } else { t_taql_uint64 mer; char in_ascii[17]; mer = as_uInt64 (value); mer_to_ascii (in_ascii, mer); fputs (in_ascii, stdout); } } fputc ('\n', stdout); Advance (infile, 1); } }