/* * Stringifies a dPoint and appends it to a string buffer. * * sb -- A previously initialized string buffer. * point -- The dPoint to append to sb. * */ static void sb_put_point(SB *sb, dPoint* point) { sb_putc(sb, '['); // [ sb_putf(sb, point->abs); // abs value sb_putc(sb, ','); // , sb_putf(sb, point->time); // time value sb_putc(sb, ']'); // ] }
/* * Stringifies a dField with the name and value, then appends it to a string buffer. * * sb -- A previously initialized string buffer. * field -- The dField to append to sb. * */ static void sb_put_nv_field(SB *sb, dField* field) { sb_putc(sb, '\"'); sb_puts(sb, field->name); // 'field name' sb_putc(sb, '\"'); sb_putc(sb, ':'); // : sb_putc(sb, '\"'); sb_puts(sb, field->value); // 'field value' sb_putc(sb, '\"'); }
/* * JSON serializes a collection of dSets. * * sets -- A collection of dSet objects. * count -- The number of dSets in sets. * */ char* json_serialize(dSet** sets, int count) { SB sb; sb_init(&sb); sb_putc(&sb, '['); int i; for (i = 0; i < count; i++) { sb_put_dset(&sb, sets[i]); if (i != count - 1) { sb_putc(&sb, ','); } } sb_putc(&sb, ']'); sb_finish(&sb); return sb.start; }
/* KM_GETC - return next command char from kbd macro being executed. ** This is < 0 if not executing kbd macro. Also responsible for ** gathering input for kbd macro. */ km_getc() { register int c; while (km_flag > 0) /* Executing macro? */ { c = sb_getc(((SBBUF *)km_buf)); /* Yes, get char */ if(c != EOF) return(c); /* and return as cmd */ if(--km_exp >= 0) /* Macro done. Repeat? */ ex_go((SBBUF *)km_buf, (chroff)0); /* Yes */ else km_flag = 0; /* No, stop execution */ } c = tgetc(); /* Get char from user (TTY) */ if(km_flag < 0) /* Save it if collecting macro */ { sb_putc(((SBBUF *)km_buf), c); } return(c); }
/* * Stringifies a dSet and appends it to a string buffer. * * sb -- A previously initialized string buffer. * set -- A pointer to a dSet to add to sb. * */ static void sb_put_dset(SB* sb, dSet* set) { sb_putc(sb, '{'); // standard fields sb_put_nv_field(sb, &set->name); sb_putc(sb, ','); sb_put_nv_field(sb, &set->collection_time); sb_putc(sb, ','); sb_put_nvu_field(sb, &set->wavelength); sb_putc(sb, ','); // data points sb_putc(sb, '\"'); sb_puts(sb, "points"); sb_putc(sb, '\"'); sb_putc(sb, ':'); sb_putc(sb, '['); int i; for (i = 0; i < set->num_points; i++) { sb_put_point(sb, set->points[i]); if (i != set->num_points - 1) { sb_putc(sb, ','); } } sb_putc(sb, ']'); sb_putc(sb, ','); // metadata fields // TODO: this should really be a list, since we're just going to iterate over // the meta fields when we display them sb_putc(sb, '\"'); sb_puts(sb, "meta"); sb_putc(sb, '\"'); sb_putc(sb, ':'); sb_putc(sb, '['); sb_put_meta_field(sb, &set->operator_name); sb_putc(sb, ','); sb_put_meta_field(sb, &set->kinetics_version); sb_putc(sb, ','); sb_put_meta_field(sb, &set->param_list); sb_putc(sb, ','); sb_put_meta_field(sb, &set->instrument); sb_putc(sb, ','); sb_put_meta_field(sb, &set->instrument_version); sb_putc(sb, ','); sb_put_meta_field(sb, &set->ordinate_mode); sb_putc(sb, ','); sb_put_meta_field(sb, &set->sbw); sb_putc(sb, ','); sb_put_meta_field(sb, &set->ave_time); sb_putc(sb, ','); sb_put_meta_field(sb, &set->dwell_time); sb_putc(sb, ','); sb_put_meta_field(sb, &set->cycle_time); sb_putc(sb, ','); sb_put_meta_field(sb, &set->stop_time); sb_putc(sb, ']'); sb_putc(sb, '}'); }
/* * Stringifies a dField with the name, value, and units, then appends it to a string buffer. * * sb -- A previously initialized string buffer. * field -- The dField to append to sb. * */ static void sb_put_meta_field(SB *sb, dField* field) { sb_putc(sb, '{'); // { sb_putc(sb, '\"'); sb_puts(sb, "name"); // 'name' sb_putc(sb, '\"'); sb_putc(sb, ':'); // : sb_putc(sb, '\"'); sb_puts(sb, field->name); // 'field name' sb_putc(sb, '\"'); sb_putc(sb, ','); // , sb_putc(sb, '\"'); sb_puts(sb, "value"); // 'value' sb_putc(sb, '\"'); sb_putc(sb, ':'); // : sb_putc(sb, '\"'); sb_puts(sb, field->value); // 'field value' sb_putc(sb, '\"'); sb_putc(sb, ','); // , sb_putc(sb, '\"'); sb_puts(sb, "units"); // 'units' sb_putc(sb, '\"'); sb_putc(sb, ':'); // : sb_putc(sb, '\"'); sb_puts(sb, field->units); // 'field units' sb_putc(sb, '\"'); sb_putc(sb, '}'); // } }