Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (revision 27318) +++ trunk/src/plug_io.c (revision 27319) @@ -706,6 +706,36 @@ return real_load_pcb(PCB->hidlib.filename, NULL, pcb_true, pcb_true, 1); } +int pcb_load_buffer(pcb_hidlib_t *hidlib, pcb_buffer_t *buff, const char *fn, const char *fmt) +{ + int res = -1, len, n; + pcb_find_io_t available[PCB_IO_MAX_FORMATS]; + int accepts[PCB_IO_MAX_FORMATS]; /* test-parse output */ + int accept_total = 0; + FILE *ft; + + ft = pcb_fopen(hidlib, fn, "r"); + len = pcb_test_parse_all(ft, fn, fmt, PCB_IOT_BUFFER, available, accepts, &accept_total, sizeof(available)/sizeof(available[0]), 0, 0); + if (ft != NULL) + fclose(ft); + if (len < 0) + return -1; + + /* try all plugins that said it could handle the file */ + for(n = 0; n < len; n++) { + if ((available[n].plug->parse_buffer == NULL) || (!accepts[n])) /* can't parse or doesn't want to parse this file */ + continue; + res = available[n].plug->parse_buffer(available[n].plug, buff, fn); + if (res == 0) + break; + } + + plug_io_err(hidlib, res, "load buffer", fn); + return res; + +} + + void pcb_print_quoted_string_(FILE * FP, const char *S) { const char *start; Index: trunk/src/plug_io.h =================================================================== --- trunk/src/plug_io.h (revision 27318) +++ trunk/src/plug_io.h (revision 27319) @@ -77,7 +77,10 @@ /* Attempt to load fonts from a file. Return 0 on success. */ int (*parse_font)(pcb_plug_io_t *ctx, pcb_font_t *Ptr, const char *Filename); + /* Attempt to load a complete buffer from a file. Return 0 on success. */ + int (*parse_buffer)(pcb_plug_io_t *ctx, pcb_buffer_t *buff, const char *filename); + /* Write the buffer to a file. Return 0 on success. */ int (*write_buffer)(pcb_plug_io_t *ctx, FILE *f, pcb_buffer_t *buff); @@ -143,6 +146,7 @@ void pcb_print_quoted_string(FILE *, const char *); /* with wrapping in "" */ int pcb_write_pcb_file(const char *Filename, pcb_bool thePcb, const char *fmt, pcb_bool emergency, pcb_bool elem_only); void pcb_set_design_dir(const char *fn); +int pcb_load_buffer(pcb_hidlib_t *hidlib, pcb_buffer_t *buff, const char *fn, const char *fmt); /********** helpers **********/