Index: trunk/src/obj_pstk.h =================================================================== --- trunk/src/obj_pstk.h (revision 20428) +++ trunk/src/obj_pstk.h (revision 20429) @@ -252,6 +252,14 @@ /* Overwrite all fields of a proto in-place; returns the id or INVALID on error */ pcb_cardinal_t pcb_pstk_proto_replace(pcb_data_t *data, pcb_cardinal_t proto_id, const pcb_pstk_proto_t *src); +/* Cycle through all (first level) padstacks of data and count how many times + each prototype is referenced by them. The result is returned as an array + of counts per prototype ID; the array is as large as data's prototype array. + len_out is always filled with the length of the array. If the length is 0, + NULL is returned. The caller needs to call free() on the returned array. */ +pcb_cardinal_t *pcb_pstk_proto_used_all(pcb_data_t *data, pcb_cardinal_t *len_out); + + /*** layer info ***/ typedef struct pcb_proto_layer_s { const char *name; Index: trunk/src/obj_pstk_proto.c =================================================================== --- trunk/src/obj_pstk_proto.c (revision 20428) +++ trunk/src/obj_pstk_proto.c (revision 20429) @@ -1135,7 +1135,27 @@ pcb_pstk_proto_del_shape_idx(proto, idx); } +pcb_cardinal_t *pcb_pstk_proto_used_all(pcb_data_t *data, pcb_cardinal_t *len_out) +{ + pcb_cardinal_t len, n, *res; + pcb_pstk_t *ps; + len = data->ps_protos.used; + if (len == 0) { + *len_out = 0; + return NULL; + } + + res = calloc(sizeof(pcb_cardinal_t), len); + for(ps = padstacklist_first(&data->padstack); ps != NULL; ps = padstacklist_next(ps)) { + if ((ps->proto >= 0) && (ps->proto < len)) + res[ps->proto]++; + } + + *len_out = len; + return res; +} + /*** hash ***/ static unsigned int pcb_pstk_shape_hash(const pcb_pstk_shape_t *sh) {