Index: trunk/src/buffer.c =================================================================== --- trunk/src/buffer.c (revision 27331) +++ trunk/src/buffer.c (revision 27332) @@ -923,7 +923,7 @@ case F_Save: name = sbufnum; - pcb_save_buffer_subcs(name, fmt); + pcb_save_buffer_subcs(name, fmt, -1); break; case F_ToLayout: Index: trunk/src/file_act.c =================================================================== --- trunk/src/file_act.c (revision 27331) +++ trunk/src/file_act.c (revision 27332) @@ -223,7 +223,7 @@ case F_PasteBuffer: - PCB_ACT_IRES(pcb_save_buffer_subcs(name, fmt)); + PCB_ACT_IRES(pcb_save_buffer_subcs(name, fmt, -1)); return 0; /* shorthand kept only for compatibility reasons - do not use */ Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (revision 27331) +++ trunk/src/plug_io.c (revision 27332) @@ -374,14 +374,24 @@ } -int pcb_write_buffer(FILE *f, pcb_buffer_t *buff, const char *fmt, pcb_bool subc_only) +static int pcb_write_buffer(FILE *f, pcb_buffer_t *buff, const char *fmt, pcb_bool subc_only, long subc_idx) { int res/*, newfmt = 0*/; pcb_plug_io_t *p = find_writer(subc_only ? PCB_IOT_BUFFER_SUBC : PCB_IOT_BUFFER, fmt); if (p != NULL) { - if (subc_only) - res = p->write_buffer_subc(p, f, buff, 0); + if (subc_only) { + long avail = pcb_subclist_length(&buff->Data->subc); + if (subc_idx >= 0) { + if (subc_idx >= avail) { + pcb_message(PCB_MSG_ERROR, "pcb_write_buffer: subc index out of range"); + return -1; + } + + } +/* else*/ + res = p->write_buffer_subc(p, f, buff, 0); + } else res = p->write_buffer(p, f, buff); /*newfmt = 1;*/ @@ -588,7 +598,7 @@ } /* Write the pcb file, a footprint or a buffer */ -static int pcb_write_file(FILE *fp, pcb_bool thePcb, const char *old_path, const char *new_path, const char *fmt, pcb_bool emergency, pcb_bool subc_only) +static int pcb_write_file(FILE *fp, pcb_bool thePcb, const char *old_path, const char *new_path, const char *fmt, pcb_bool emergency, pcb_bool subc_only, long subc_idx) { if (thePcb) { if (PCB->is_footprint) @@ -595,12 +605,12 @@ return pcb_write_footprint_data(fp, PCB->Data, fmt); return pcb_write_pcb(fp, old_path, new_path, fmt, emergency); } - return pcb_write_buffer(fp, PCB_PASTEBUFFER, fmt, subc_only); + return pcb_write_buffer(fp, PCB_PASTEBUFFER, fmt, subc_only, subc_idx); } /* writes to pipe using the command defined by conf_core.rc.save_command %f are replaced by the passed filename */ -static int pcb_write_pipe(const char *Filename, pcb_bool thePcb, const char *fmt, pcb_bool subc_only) +static int pcb_write_pipe(const char *Filename, pcb_bool thePcb, const char *fmt, pcb_bool subc_only, long subc_idx) { FILE *fp; int result; @@ -609,7 +619,7 @@ const char *save_cmd; if (PCB_EMPTY_STRING_P(conf_core.rc.save_command)) - return pcb_write_pcb_file(Filename, thePcb, fmt, pcb_false, subc_only); + return pcb_write_pcb_file(Filename, thePcb, fmt, pcb_false, subc_only, subc_idx); save_cmd = conf_core.rc.save_command; /* setup commandline */ @@ -631,7 +641,7 @@ return (-1); } - result = pcb_write_file(fp, thePcb, NULL, NULL, fmt, pcb_false, subc_only); + result = pcb_write_file(fp, thePcb, NULL, NULL, fmt, pcb_false, subc_only, subc_idx); return (pcb_pclose(fp) ? (-1) : result); } @@ -642,13 +652,13 @@ #define F2S(OBJ, TYPE) pcb_strflg_f2s((OBJ)->Flags, TYPE) -int pcb_save_buffer_subcs(const char *Filename, const char *fmt) +int pcb_save_buffer_subcs(const char *Filename, const char *fmt, long subc_idx) { int result; if (conf_core.editor.show_solder_side) pcb_buffers_flip_side(PCB); - result = pcb_write_pipe(Filename, pcb_false, fmt, pcb_true); + result = pcb_write_pipe(Filename, pcb_false, fmt, pcb_true, subc_idx); if (conf_core.editor.show_solder_side) pcb_buffers_flip_side(PCB); return result; @@ -656,7 +666,7 @@ int pcb_save_buffer(const char *Filename, const char *fmt) { - return pcb_write_pipe(Filename, pcb_false, fmt, pcb_false); + return pcb_write_pipe(Filename, pcb_false, fmt, pcb_false, -1); } int pcb_save_pcb(const char *file, const char *fmt) @@ -667,7 +677,7 @@ if (conf_core.editor.io_incomp_popup) pcb_view_list_free_fields(&pcb_io_incompat_lst); - retcode = pcb_write_pipe(file, pcb_true, fmt, pcb_false); + retcode = pcb_write_pipe(file, pcb_true, fmt, pcb_false, -1); pcb_io_incompat_lst_enable = pcb_false; if (conf_core.editor.io_incomp_popup) { @@ -772,7 +782,7 @@ const char *fmt = conf_core.rc.emergency_format == NULL ? DEFAULT_EMERGENCY_FMT : conf_core.rc.emergency_format; sprintf(filename, conf_core.rc.emergency_name, (long int)pcb_getpid()); pcb_message(PCB_MSG_INFO, "Trying to save your layout in '%s'\n", filename); - pcb_write_pcb_file(filename, pcb_true, fmt, pcb_true, pcb_false); + pcb_write_pcb_file(filename, pcb_true, fmt, pcb_true, pcb_false, -1); } } @@ -843,13 +853,13 @@ fmt = conf_core.rc.backup_format; orig = PCB->Data->loader; - pcb_write_pcb_file(filename, pcb_true, fmt, pcb_true, pcb_false); + pcb_write_pcb_file(filename, pcb_true, fmt, pcb_true, pcb_false, -1); PCB->Data->loader = orig; free(filename); } -int pcb_write_pcb_file(const char *Filename, pcb_bool thePcb, const char *fmt, pcb_bool emergency, pcb_bool subc_only) +int pcb_write_pcb_file(const char *Filename, pcb_bool thePcb, const char *fmt, pcb_bool emergency, pcb_bool subc_only, long subc_idx) { FILE *fp; int result, overwrite; @@ -879,7 +889,7 @@ return (-1); } - result = pcb_write_file(fp, thePcb, fn_tmp, Filename, fmt, emergency, subc_only); + result = pcb_write_file(fp, thePcb, fn_tmp, Filename, fmt, emergency, subc_only, subc_idx); fclose(fp); if (fn_tmp != NULL) { Index: trunk/src/plug_io.h =================================================================== --- trunk/src/plug_io.h (revision 27331) +++ trunk/src/plug_io.h (revision 27332) @@ -126,7 +126,6 @@ int pcb_parse_pcb(pcb_board_t *Ptr, const char *Filename, const char *fmt, int load_settings, int ignore_missing); int pcb_parse_footprint(pcb_data_t *Ptr, const char *name, const char *fmt); int pcb_parse_font(pcb_font_t *Ptr, const char *Filename); -int pcb_write_buffer(FILE *f, pcb_buffer_t *buff, const char *fmt, pcb_bool subc_only); int pcb_write_footprint_data(FILE *f, pcb_data_t *e, const char *fmt); int pcb_write_font(pcb_font_t *Ptr, const char *Filename, const char *fmt); @@ -140,11 +139,11 @@ void pcb_emergency_save(void); void pcb_disable_emergency_save(void); int pcb_revert_pcb(void); -int pcb_save_buffer_subcs(const char *, const char *fmt); +int pcb_save_buffer_subcs(const char *, const char *fmt, long subc_idx); int pcb_save_buffer(const char *Filename, const char *fmt); void pcb_print_quoted_string_(FILE *, const char *); /* without wrapping in "" */ 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 subc_only); +int pcb_write_pcb_file(const char *Filename, pcb_bool thePcb, const char *fmt, pcb_bool emergency, pcb_bool subc_only, long subc_idx); 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); Index: trunk/src_plugins/io_pcb/file.c =================================================================== --- trunk/src_plugins/io_pcb/file.c (revision 27331) +++ trunk/src_plugins/io_pcb/file.c (revision 27332) @@ -1184,7 +1184,7 @@ void pcb_tmp_data_save(void) { char *fn = pcb_build_fn(&PCB->hidlib, conf_core.rc.emergency_name); - pcb_write_pcb_file(fn, pcb_true, NULL, pcb_true, pcb_false); + pcb_write_pcb_file(fn, pcb_true, NULL, pcb_true, pcb_false, -1); if (TMPFilename != NULL) free(TMPFilename); TMPFilename = fn;