Index: examples/Makefile =================================================================== --- examples/Makefile (nonexistent) +++ examples/Makefile (revision 11180) @@ -0,0 +1,6 @@ +CFLAGS = -I../.. +CFLAGS += -Wall -g -ansi -pedantic + +dump_hpgl: dump_hpgl.o ../parse.o + +dump_hpgl.o: dump_hpgl.c Index: examples/dump_hpgl.c =================================================================== --- examples/dump_hpgl.c (nonexistent) +++ examples/dump_hpgl.c (revision 11180) @@ -0,0 +1,102 @@ +/* + libuhpgl - the micro HP-GL library + Copyright (C) 2017 Tibor 'Igor2' Palinkas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + + This library is part of pcb-rnd: http://repo.hu/projects/pcb-rnd +*/ + +#include +#include +#include +#include + + +static int dump_line(uhpgl_ctx_t *ctx, uhpgl_line_t *line) +{ + printf("line: %ld;%ld %ld;%ld\n", line->p1.x, line->p1.y, line->p2.x, line->p2.y); + return 0; +} + +static void dump_arc_(uhpgl_ctx_t *ctx, uhpgl_arc_t *arc, const char *type) +{ + printf("%s: %ld;%ld;%ld %f->%f (%f) (%ld;%ld->%ld;%ld)\n", type, + arc->center.x, arc->center.y, arc->r, + arc->starta, arc->enda, arc->deltaa, + arc->startp.x, arc->startp.y, arc->endp.x, arc->endp.y); +} + +static int dump_arc(uhpgl_ctx_t *ctx, uhpgl_arc_t *arc) +{ + dump_arc_(ctx, arc, "arc"); + return 0; +} + + +static int dump_circ(uhpgl_ctx_t *ctx, uhpgl_arc_t *circ) +{ + printf("circ: %ld;%ld;%ld\n", + circ->center.x, circ->center.y, circ->r); + return 0; +} + +static int dump_poly(uhpgl_ctx_t *ctx, uhpgl_poly_t *poly) +{ +#warning TODO + return 0; +} + +static int dump_wedge(uhpgl_ctx_t *ctx, uhpgl_wedge_t *wedge) +{ + dump_arc_(ctx, &wedge->arc, "wedge"); + return 0; +} + +static int dump_rect(uhpgl_ctx_t *ctx, uhpgl_rect_t *rect) +{ + printf("line: %ld;%ld %ld;%ld\n", rect->p1.x, rect->p1.y, rect->p2.x, rect->p2.y); + return 0; +} + +static int print_error(uhpgl_ctx_t *ctx) +{ + fprintf(stderr, "Error on stdin:%d.%d: %s\n", ctx->error.line, ctx->error.col, ctx->error.msg); + return -1; +} + +int main() +{ + uhpgl_ctx_t ctx; + + memset(&ctx, 0, sizeof(ctx)); + + ctx.conf.line = dump_line; + ctx.conf.arc = dump_arc; + ctx.conf.circ = dump_circ; + ctx.conf.poly = dump_poly; + ctx.conf.wedge = dump_wedge; + ctx.conf.rect = dump_rect; + + if (uhpgl_parse_open(&ctx) != 0) + return print_error(&ctx); + if (uhpgl_parse_file(&ctx, stdin) != 0) + return print_error(&ctx); + if (uhpgl_parse_close(&ctx) != 0) + return print_error(&ctx); + return 0; +} + Index: examples/rect.hpgl =================================================================== --- examples/rect.hpgl (nonexistent) +++ examples/rect.hpgl (revision 11180) @@ -0,0 +1,11 @@ +IN; + +PA0,0; + +PD; +PA200,0; +PA200,200; +PA0,200; +PA0,0; +PU; + Index: examples/rect_bound.hpgl =================================================================== --- examples/rect_bound.hpgl (nonexistent) +++ examples/rect_bound.hpgl (revision 11180) @@ -0,0 +1,13 @@ +IN; +IP0,0,4000,4000; +SC0,200,0,200; +SP1; +PA0,0; + +PD; +PA200,0; +PA200,200; +PA0,200; +PA0,0; +PU; +