int main(int argc, char **argv) { int fd; t_kitten kitten; if (argc != 2) return (1); fd = open(argv[1], O_RDONLY); kitten.line_nbr = 0; kitten.hex = xmalloc(512); kitten.offset = 0; while (kitten.line = get_next_line(fd)) { kitten.line_nbr++; kitten.i = 0; convert_line(&kitten); free(kitten.line); } close(fd); int i = 0; while (i < kitten.offset) printf("%#.2x,", kitten.hex[i++]); printf("\n"); free(kitten.hex); return (0); }
static void convert_lines(prescanner_t* prescanner) { // INCLUDE stuff regex_t match_include_directive; // It is enough with 2 regmatch_t sub_matching[2]; int code; if ((code = regcomp(&match_include_directive, INCLUDE_DIRECTIVE_REGEX, REG_EXTENDED | REG_ICASE)) != 0) { char error_message[120]; regerror(code, &match_include_directive, error_message, 120); internal_error("Error when compiling regular expression (%s)\n", error_message); } // This is a global variable with local scope static language_level next = LANG_TOP_LEVEL; line_t* iter = file_lines; while (iter != NULL) { if (regexec(&match_include_directive, iter->line, 2, sub_matching, 0) == 0) { handle_include_line(prescanner, iter, sub_matching); } else { next = convert_line(prescanner, next, &iter->line, iter->line_number); } iter = iter->next; } }
int _citrus_lookup_factory_convert(FILE *out, FILE *in) { struct _citrus_db_factory *df; struct _region r; char *line; size_t size; int ret; ret = _db_factory_create(&df, &_db_hash_std, NULL); if (ret) return (ret); while ((line = fgetln(in, &size)) != NULL) if ((ret = convert_line(df, line, size))) { _db_factory_free(df); return (ret); } ret = dump_db(df, &r); _db_factory_free(df); if (ret) return (ret); if (fwrite(_region_head(&r), _region_size(&r), 1, out) != 1) return (errno); return (0); }
static void query_vcf(args_t *args) { kstring_t str = {0,0,0}; if ( args->print_header ) { convert_header(args->convert,&str); fwrite(str.s, str.l, 1, args->out); } while ( bcf_sr_next_line(args->files) ) { if ( !bcf_sr_has_line(args->files,0) ) continue; bcf1_t *line = args->files->readers[0].buffer[0]; bcf_unpack(line, args->files->max_unpack); if ( args->filter ) { int pass = filter_test(args->filter, line, NULL); if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1; if ( !pass ) continue; } str.l = 0; convert_line(args->convert, line, &str); if ( str.l ) fwrite(str.s, str.l, 1, args->out); } if ( str.m ) free(str.s); }
static void deliver_by_pline (struct qtmsg *qt_msg) { long size; for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { (void) dlb_fgets(in_line, 80, msg_file); convert_line(); plines(out_line); } }
void convert_csv(CsvFloat * the_float,CsvData * the_data){ int i; Float_init(the_float,the_data); for (i=0;i<the_data->nheaders;i++){ copy_line((the_float->headers[i]),(the_data->headers[i])); } for (i=0;i<the_data->line_count;i++){ convert_line(*(the_float->data + i),(the_data->lines[i])); } }
static void deliver_by_pline(struct qtmsg *qt_msg) { long size; char in_line[81]; /* to match the fgets call below */ for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { dlb_fgets(in_line, 80, msg_file); const char *out_line = convert_line(in_line); pline("%s", out_line); } }
static void deliver_by_window (struct qtmsg *qt_msg, int how) { long size; winid datawin = create_nhwindow(how); for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { (void) dlb_fgets(in_line, 80, msg_file); convert_line(); putstr(datawin, 0, out_line); } display_nhwindow(datawin, true); destroy_nhwindow(datawin); }
static void deliver_by_window(struct qtmsg *qt_msg) { char in_line[81]; boolean new_para = TRUE; const char *msg = ""; int size; /* Don't show this in replay mode, because it would require a keystroke to dismiss. (The other uses of display_buffer are #verhistory and #license, both of which are zero-time; thus, this is the only way to produce an /uninteractible/ buffer, which is something we want to avoid.) */ if (program_state.followmode == FM_REPLAY) return; for (size = 0; size < qt_msg->size; size += (long)strlen(in_line)) { dlb_fgets(in_line, 80, msg_file); const char *out_line = convert_line(in_line); /* We want to strip lone newlines, but leave sequences intact, or special formatting. TODO: This is a huge kluge. Be better at this. */ if (!*out_line) { if (!new_para) msg = msgcat(msg, "\n \n"); new_para = TRUE; } else { if (out_line[0] == ' ' && !new_para) msg = msgkitten(msg, '\n'); else if (!new_para) msg = msgkitten(msg, ' '); new_para = FALSE; } msg = msgcat(msg, out_line); } display_buffer(msg, TRUE); }
static void convert(const char *filename) { struct stat stats; if (stat (filename, &stats) == -1) { print_info("File not exist!\n"); return; } FILE *tabfile; tabfile = fopen(filename,"r"); gchar *buffer = (gchar *)g_malloc (stats.st_size + 1); size_t readsize = fread (buffer, 1, stats.st_size, tabfile); fclose (tabfile); buffer[readsize] = '\0'; FILE *sqlfile; std::string sqlfilename = filename; sqlfilename += ".sql"; sqlfile = fopen(sqlfilename.c_str(), "wb"); char *p, *p1, *p2; p = buffer; while (TRUE) { p1 = strchr(p, '\n'); if (!p1) break; *p1 = '\0'; p2 = strchr(p, '\t'); if (!p2) { g_print("Error: no Tab.\n"); break; } *p2 = '\0'; p2++; convert_line(sqlfile, p, p2); p = p1 + 1; } fclose(sqlfile); }
// // handles the callback from the dime-library // bool dxfConverter::private_callback(const dimeState * const state, dimeEntity *entity) { if (entity->typeId() == dimeBase::dimePolylineType) { this->currentPolyline = entity; } if (state->getCurrentInsert()) { this->currentInsertColorIndex = getColorIndex((dimeEntity*)state->getCurrentInsert()); } else { this->currentInsertColorIndex = 7; } dxfLayerData *ld = getLayerData(entity); // fillmode on by default. entities which will not fill its polygons // should turn it off (layerData::addQuad() will create polygons, // not lines) // ld->setFillmode(true); switch (entity->typeId()) { case dimeBase::dime3DFaceType: convert_3dface(entity, state, ld, this); break; case dimeBase::dimeSolidType: convert_solid(entity, state, ld, this); break; case dimeBase::dimeTraceType: convert_solid(entity, state, ld, this); break; case dimeBase::dimeArcType: convert_arc(entity, state, ld, this); break; case dimeBase::dimeCircleType: convert_circle(entity, state, ld, this); break; case dimeBase::dimeEllipseType: convert_ellipse(entity, state, ld, this); break; case dimeBase::dimeInsertType: // handled in traverseEntities break; case dimeBase::dimeBlockType: // handled in traverseEntities break; case dimeBase::dimeLineType: convert_line(entity, state, ld, this); break; case dimeBase::dimeLWPolylineType: convert_lwpolyline(entity, state, ld, this); break; case dimeBase::dimePointType: convert_point(entity, state, ld, this); break; case dimeBase::dimePolylineType: convert_polyline(entity, state, ld, this); break; case dimeBase::dimeSplineType: // go for it Raphael! :-) break; default: break; } return true; }
static int decode_file (idn_resconf_t conf1, idn_resconf_t conf2, FILE * fp, int flags) { idn_result_t r; idnconv_strbuf_t buf1, buf2; idn_action_t actions1, actions2; int nl_trimmed; int local_ace_hack, idn_ace_hack; idn_converter_t conv; /* * See if the input codeset is an ACE. */ conv = idn_resconf_getidnconverter (conf1); if (conv != NULL && idn_converter_isasciicompatible (conv) && (flags & FLAG_SELECTIVE)) idn_ace_hack = 1; else idn_ace_hack = 0; if (conv != NULL) idn_converter_destroy (conv); conv = idn_resconf_getlocalconverter (conf1); if (conv != NULL && idn_converter_isasciicompatible (conv) && (flags & FLAG_SELECTIVE)) local_ace_hack = 1; else local_ace_hack = 0; if (conv != NULL) idn_converter_destroy (conv); actions1 = IDN_IDNCONV; if (local_ace_hack) { actions2 = IDN_IDNCONV; if (flags & FLAG_MAP) actions2 |= IDN_MAP; if (flags & FLAG_NORMALIZE) actions2 |= IDN_NORMALIZE; if (flags & FLAG_PROHIBITCHECK) actions2 |= IDN_PROHCHECK; if (flags & FLAG_UNASSIGNCHECK) actions2 |= IDN_UNASCHECK; if (flags & FLAG_BIDICHECK) actions2 |= IDN_BIDICHECK; if (flags & FLAG_ASCIICHECK) actions2 |= IDN_ASCCHECK; if (flags & FLAG_LENGTHCHECK) actions2 |= IDN_LENCHECK; } else { actions2 = IDN_LOCALCONV; } if (flags & FLAG_DELIMMAP) actions1 |= IDN_DELIMMAP; if (flags & FLAG_MAP) actions1 |= IDN_MAP; if (flags & FLAG_NORMALIZE) actions1 |= IDN_NORMALIZE; if (flags & FLAG_NORMALIZE) actions1 |= IDN_NORMALIZE; if (flags & FLAG_PROHIBITCHECK) actions1 |= IDN_PROHCHECK; if (flags & FLAG_UNASSIGNCHECK) actions1 |= IDN_UNASCHECK; if (flags & FLAG_BIDICHECK) actions1 |= IDN_BIDICHECK; if (flags & FLAG_ASCIICHECK) actions1 |= IDN_ASCCHECK; if (flags & FLAG_ROUNDTRIPCHECK) actions1 |= IDN_RTCHECK; strbuf_init (&buf1); strbuf_init (&buf2); line_number = 1; while (strbuf_getline (&buf1, fp) != NULL) { /* * Trim newline at the end. This is needed for * those ascii-comatible encodings such as UTF-5 or RACE * not to try converting newlines, which will result * in `invalid encoding' error. */ nl_trimmed = trim_newline (&buf1); /* * Treat input line as the string encoded in local * encoding and convert it to UTF-8 encoded string. */ if (local_ace_hack) { if (strbuf_copy (&buf2, strbuf_get (&buf1)) == NULL) r = idn_nomemory; else r = idn_success; } else { r = convert_line (&buf1, &buf2, conf1, IDN_LOCALCONV, 0); } if (r != idn_success) { errormsg ("conversion failed at line %d: %s\n", line_number, idn_result_tostring (r)); goto error; } /* * Convert internationalized domain names in the line. */ if (idn_ace_hack) { r = convert_line (&buf2, &buf1, conf1, actions1, FLAG_REVERSE | FLAG_SELECTIVE); } else { r = convert_line (&buf2, &buf1, conf1, actions1, FLAG_REVERSE); } if (r != idn_success) { errormsg ("conversion failed at line %d: %s\n", line_number, idn_result_tostring (r)); goto error; } if (!idn_utf8_isvalidstring (strbuf_get (&buf1))) { errormsg ("conversion to utf-8 failed at line %d\n", line_number); goto error; } /* * Perform round trip check and convert to the output * codeset. */ if (local_ace_hack) { r = convert_line (&buf1, &buf2, conf2, actions2, FLAG_SELECTIVE); } else { r = convert_line (&buf1, &buf2, conf1, actions2, FLAG_REVERSE); } if (r != idn_success) { errormsg ("error in nameprep or output conversion " "at line %d: %s\n", line_number, idn_result_tostring (r)); goto error; } fputs (strbuf_get (&buf2), stdout); if (nl_trimmed) putc ('\n', stdout); if (flush_every_line) fflush (stdout); line_number++; } strbuf_reset (&buf1); strbuf_reset (&buf2); return (0); error: strbuf_reset (&buf1); strbuf_reset (&buf2); return (1); }