Index: trunk/doc/TODO =================================================================== --- trunk/doc/TODO (revision 24849) +++ trunk/doc/TODO (revision 24850) @@ -14,7 +14,6 @@ - CLEANUP: remove pcb_attribute_dialog() and the label argument from the DAD API [report: igor2] - CLEANUP/BUG: The 'As Drawn' polygon contour is not displayed if the polygon is totally clipped out of existence even though it still exists in the layout. [report: Ade] -> need a new rtree that holds the polygons that have ->clipped == NULL for this purpose -- CLEANUP: pcb_layer_to_file_name() dest should be gds_t to avoid potential buffer overflow - CLEANUP: remove hid_flag.h - probably merge the function into a menu related .h - CLEANUP: DAD: centralize the coordinate input spinbox: hid_dad_spin - remove per hid implementation, get DAD macros to build spinboxes (maybe in brave mode first) Index: trunk/src/hid_cam.c =================================================================== --- trunk/src/hid_cam.c (revision 24849) +++ trunk/src/hid_cam.c (revision 24850) @@ -43,7 +43,7 @@ htsp_t *pcb_cam_vars = NULL; /* substitute %% variables from this hash */ -char *pcb_layer_to_file_name(char *dest, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, pcb_file_name_style_t style) +char *pcb_layer_to_file_name(gds_t *dest, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, pcb_file_name_style_t style) { const pcb_virt_layer_t *v; pcb_layergrp_id_t group; @@ -53,6 +53,8 @@ if (flags == 0) flags = pcb_layer_flags(PCB, lid); + dest->used = 0; + if (style == PCB_FNS_pcb_rnd) { const char *sloc, *styp; group = pcb_layer_get_group(PCB, lid); @@ -62,16 +64,16 @@ if (styp == NULL) styp = "none"; if (purpose == NULL) purpose = "none"; if (group < 0) { - sprintf(dest, "%s.%s.%s.none", sloc, styp, purpose); + pcb_append_printf(dest, "%s.%s.%s.none", sloc, styp, purpose); } else - sprintf(dest, "%s.%s.%s.%ld", sloc, styp, purpose, group); - return dest; + pcb_append_printf(dest, "%s.%s.%s.%ld", sloc, styp, purpose, group); + return dest->array; } if (flags & PCB_LYT_BOUNDARY) { - strcpy(dest, "outline"); - return dest; + gds_append_str(dest, "outline"); + return dest->array; } /* NOTE: long term only PCB_FNS_pcb_rnd will be supported and the rest, @@ -78,8 +80,8 @@ below, will be removed */ v = pcb_vlayer_get_first(flags, purpose, purpi); if (v != NULL) { - strcpy(dest, v->name); - return dest; + gds_append_str(dest, v->name); + return dest->array; } @@ -120,8 +122,8 @@ } assert(res != NULL); - strcpy(dest, res); - return dest; + gds_append_str(dest, res); + return dest->array; } Index: trunk/src/hid_cam.h =================================================================== --- trunk/src/hid_cam.h (revision 24849) +++ trunk/src/hid_cam.h (revision 24850) @@ -3,6 +3,7 @@ #include "layer.h" #include "hid_attrib.h" +#include /*** CAM plugin side API ***/ typedef struct pcb_cam_s { @@ -79,8 +80,9 @@ PCB_FNS_first } pcb_file_name_style_t; -/* Returns a filename base that can be used to output the layer. */ -char *pcb_layer_to_file_name(char *dest, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, pcb_file_name_style_t style); +/* Returns a filename base that can be used to output the layer. The file + name is built in dest, the returned pointer is pointing to the array of dest. */ +char *pcb_layer_to_file_name(gds_t *dest, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, pcb_file_name_style_t style); /* Returns a filename base that can be used to output the layer; if flags is 0, look it up. Copies result in dest (which should be at least PCB_DERIVE_FN_SUFF_LEN bytes wide). */ Index: trunk/src_plugins/export_gcode/gcode.c =================================================================== --- trunk/src_plugins/export_gcode/gcode.c (revision 24849) +++ trunk/src_plugins/export_gcode/gcode.c (revision 24850) @@ -411,10 +411,12 @@ for (i = 0; i < PCB_MAX_LAYERGRP; i++) { if (gcode_export_group[i]) { - char tmp_ln[PCB_PATH_MAX]; - const char *name = pcb_layer_to_file_name(tmp_ln, -1, pcb_layergrp_flags(PCB, i), PCB->LayerGroups.grp[i].purpose, PCB->LayerGroups.grp[i].purpi, PCB_FNS_fixed); + gds_t tmp_ln; + const char *name; gcode_cur_group = i; + gds_init(&tmp_ln); + name = pcb_layer_to_file_name(&tmp_ln, -1, pcb_layergrp_flags(PCB, i), PCB->LayerGroups.grp[i].purpose, PCB->LayerGroups.grp[i].purpi, PCB_FNS_fixed); /* magic */ idx = (i >= 0 && i < pcb_max_group(PCB)) ? PCB->LayerGroups.grp[i].lid[0] : i; printf("idx=%d %s\n", idx, name); @@ -452,6 +454,7 @@ gcode_f2 = pcb_fopen(filename, "wb"); if (!gcode_f2) { perror(filename); + gds_uninit(&tmp_ln); return; } fprintf(gcode_f2, "(Created by G-code exporter)\n"); @@ -474,6 +477,7 @@ r = bm_to_pathlist(bm, &plist, ¶m_default); if (r) { fprintf(stderr, "ERROR: pathlist function failed\n"); + gds_uninit(&tmp_ln); return; } /* generate best polygon and write vertices in g-code format */ @@ -480,6 +484,7 @@ d = process_path(plist, ¶m_default, bm, gcode_f2, metric ? 25.4 / gcode_dpi : 1.0 / gcode_dpi); if (d < 0) { fprintf(stderr, "ERROR: path process function failed\n"); + gds_uninit(&tmp_ln); return; } if (metric) @@ -497,6 +502,7 @@ gcode_f2 = pcb_fopen(filename, "wb"); if (!gcode_f2) { perror(filename); + gds_uninit(&tmp_ln); return; } fprintf(gcode_f2, "(Created by G-code exporter)\n"); @@ -540,6 +546,7 @@ /* ******************* end gcode conversion **************************** */ gcode_finish_png(); + gds_uninit(&tmp_ln); } } } Index: trunk/src_plugins/export_gerber/gerber.c =================================================================== --- trunk/src_plugins/export_gerber/gerber.c (revision 24849) +++ trunk/src_plugins/export_gerber/gerber.c (revision 24850) @@ -480,7 +480,7 @@ #undef fmatch -static void assign_file_suffix(char *dest, pcb_layergrp_id_t gid, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, int drill, int *merge_same) +static int assign_file_suffix_(gds_t *dest, char *direct, pcb_layergrp_id_t gid, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, int drill, int *merge_same) { int fns_style; const char *sext = ".gbr"; @@ -502,25 +502,40 @@ fns_style = PCB_FNS_first; break; case NAME_STYLE_EAGLE: - assign_eagle_file_suffix(dest, lid, flags, purpi); + assign_eagle_file_suffix(direct, lid, flags, purpi); if (merge_same != NULL) *merge_same = 1; - return; + return 1; case NAME_STYLE_HACKVANA: - assign_hackvana_file_suffix(dest, lid, flags, purpi); + assign_hackvana_file_suffix(direct, lid, flags, purpi); if (merge_same != NULL) *merge_same = 1; - return; + return 1; case NAME_STYLE_UNIVERSAL: - assign_universal_file_suffix(dest, gid, flags, purpi); + assign_universal_file_suffix(direct, gid, flags, purpi); if (merge_same != NULL) *merge_same = 1; - return; + return 1; } if (drill && PCB_LAYER_IS_DRILL(flags, purpi)) sext = ".cnc"; pcb_layer_to_file_name(dest, lid, flags, purpose, purpi, fns_style); - strcat(dest, sext); + gds_append_str(dest, sext); + return 0; } +TODO("Once file naming styles are gone, this should be gone too and we should use the gds version only, without fixed length file buffers") +static void assign_file_suffix(char *dest, pcb_layergrp_id_t gid, pcb_layer_id_t lid, unsigned int flags, const char *purpose, int purpi, int drill, int *merge_same) +{ + gds_t tmp; + + gds_init(&tmp); + if (assign_file_suffix_(&tmp, dest, gid, lid, flags, purpose, purpi, drill, merge_same)) { + gds_uninit(&tmp); + return; + } + strncpy(dest, tmp.array, SUFF_LEN); + gds_uninit(&tmp); +} + static void gerber_do_export(pcb_hid_attr_val_t * options) { const char *fnbase; Index: trunk/src_plugins/export_ps/eps.c =================================================================== --- trunk/src_plugins/export_ps/eps.c (revision 24849) +++ trunk/src_plugins/export_ps/eps.c (revision 24850) @@ -385,7 +385,7 @@ static int eps_set_layer_group(pcb_layergrp_id_t group, const char *purpose, int purpi, pcb_layer_id_t layer, unsigned int flags, int is_empty, pcb_xform_t **xform) { - char tmp_ln[PCB_PATH_MAX]; + gds_t tmp_ln; const char *name; if (flags & PCB_LYT_UI) @@ -420,12 +420,14 @@ if (is_mask || is_paste) return 0; - name = pcb_layer_to_file_name(tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); + gds_init(&tmp_ln); + name = pcb_layer_to_file_name(&tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); #if 0 printf("Layer %s group %d drill %d mask %d\n", name, group, is_drill, is_mask); #endif fprintf(f, "%% Layer %s group %ld drill %d mask %d\n", name, group, is_drill, is_mask); + gds_uninit(&tmp_ln); if (as_shown) { if (PCB_LAYERFLG_ON_VISIBLE_SIDE(flags)) Index: trunk/src_plugins/export_ps/ps.c =================================================================== --- trunk/src_plugins/export_ps/ps.c (revision 24849) +++ trunk/src_plugins/export_ps/ps.c (revision 24850) @@ -693,8 +693,7 @@ static int ps_set_layer_group(pcb_layergrp_id_t group, const char *purpose, int purpi, pcb_layer_id_t layer, unsigned int flags, int is_empty, pcb_xform_t **xform) { - char tmp_fn[PCB_PATH_MAX]; - char tmp_ln[PCB_PATH_MAX]; + gds_t tmp_ln; static int lastgroup = -1; time_t currenttime; const char *name; @@ -729,7 +728,8 @@ } - name = pcb_layer_to_file_name(tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); + gds_init(&tmp_ln); + name = pcb_layer_to_file_name(&tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); global.is_drill = PCB_LAYER_IS_DRILL(flags, purpi); global.is_mask = !!(flags & PCB_LYT_MASK); @@ -759,6 +759,7 @@ fprintf(global.f, "(%d.) tocp\n", global.single_page ? 2 : global.pagecount); } fprintf(global.f, "(%s) toc\n", name); + gds_uninit(&tmp_ln); return 0; } @@ -778,14 +779,21 @@ } global.pagecount++; if ((!ps_cam.active && global.multi_file) || (ps_cam.active && ps_cam.fn_changed)) { - const char *fn = ps_cam.active ? ps_cam.fn : pcb_layer_to_file_name(tmp_fn, layer, flags, purpose, purpi, PCB_FNS_fixed); + const char *fn; + gds_t tmp; + + gds_init(&tmp); + fn = ps_cam.active ? ps_cam.fn : pcb_layer_to_file_name(&tmp, layer, flags, purpose, purpi, PCB_FNS_fixed); if (global.f) { ps_end_file(global.f); fclose(global.f); } global.f = psopen(ps_cam.active ? fn : global.filename, fn); + gds_uninit(&tmp); + if (!global.f) { perror(global.filename); + gds_uninit(&tmp_ln); return 0; } @@ -800,7 +808,12 @@ * ordinal page number must reflect the position of that page in * the body of the PostScript file and must start with 1, not 0. */ - fprintf(global.f, "%%%%Page: %s %d\n", pcb_layer_to_file_name(tmp_fn, layer, flags, purpose, purpi, PCB_FNS_fixed), global.pagecount); + { + gds_t tmp; + gds_init(&tmp); + fprintf(global.f, "%%%%Page: %s %d\n", pcb_layer_to_file_name(&tmp, layer, flags, purpose, purpi, PCB_FNS_fixed), global.pagecount); + gds_uninit(&tmp); + } if (global.mirror) mirror_this = !mirror_this; @@ -809,11 +822,16 @@ fprintf(global.f, "/Helvetica findfont 10 scalefont setfont\n"); if (global.legend) { + gds_t tmp; fprintf(global.f, "30 30 moveto (%s) show\n", pcb_hid_export_fn(PCB->Filename)); + + gds_init(&tmp); if (PCB->Name) - fprintf(global.f, "30 41 moveto (%s, %s) show\n", PCB->Name, pcb_layer_to_file_name(tmp_fn, layer, flags, purpose, purpi, PCB_FNS_fixed)); + fprintf(global.f, "30 41 moveto (%s, %s) show\n", PCB->Name, pcb_layer_to_file_name(&tmp, layer, flags, purpose, purpi, PCB_FNS_fixed)); else - fprintf(global.f, "30 41 moveto (%s) show\n", pcb_layer_to_file_name(tmp_fn, layer, flags, purpose, purpi, PCB_FNS_fixed)); + fprintf(global.f, "30 41 moveto (%s) show\n", pcb_layer_to_file_name(&tmp, layer, flags, purpose, purpi, PCB_FNS_fixed)); + gds_uninit(&tmp); + if (mirror_this) fprintf(global.f, "( \\(mirrored\\)) show\n"); @@ -919,6 +937,7 @@ global.is_drill = save_drill; } + gds_uninit(&tmp_ln); return 1; } Index: trunk/src_plugins/export_svg/svg.c =================================================================== --- trunk/src_plugins/export_svg/svg.c (revision 24849) +++ trunk/src_plugins/export_svg/svg.c (revision 24850) @@ -417,9 +417,12 @@ } { - char tmp_ln[PCB_PATH_MAX]; - const char *name = name = pcb_layer_to_file_name(tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); + gds_t tmp_ln; + const char *name; + gds_init(&tmp_ln); + name = pcb_layer_to_file_name(&tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); fprintf(f, "