From aa327c8e37e6bf6c16df0ba827fd6788d6b401c9 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 8 Jan 2015 09:12:53 -0300 Subject: [PATCH] slicer/Makefile, slicer.c: forgot to commit these files :-( --- slicer/Makefile | 25 ++++++++++++++++++++ slicer/slicer.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 slicer/Makefile create mode 100644 slicer/slicer.c diff --git a/slicer/Makefile b/slicer/Makefile new file mode 100644 index 0000000..f37eec2 --- /dev/null +++ b/slicer/Makefile @@ -0,0 +1,25 @@ +# +# slicer/Makefile - Build the mesh slicer +# +# Written 2015 by Werner Almesberger +# Copyright 2015 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + + +NAME = slicer + +OBJS = $(NAME).o slice.o stl.o + +CFLAGS = -g -Wall -Wshadow -Wmissing-prototypes -Wmissing-declarations\ + $(shell pkg-config --cflags glib-2.0) +LDLIBS = -lm $(shell pkg-config --libs glib-2.0) + +$(NAME): $(OBJS) + +clean: + rm -f $(OBJS) diff --git a/slicer/slicer.c b/slicer/slicer.c new file mode 100644 index 0000000..1b058e0 --- /dev/null +++ b/slicer/slicer.c @@ -0,0 +1,61 @@ +/* + * slicer.c - Generate slices + * + * Written 2015 by Werner Almesberger + * Copyright 2015 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include +#include +#include + +#include "slice.h" +#include "stl.h" + + +static void usage(const char *name) +{ + fprintf(stderr, "usage: %s [-b distance] [file.stl]\n", name); + exit(1); +} + + +int main(int argc, char **argv) +{ + float box = 0; + int c; + + slice_init(); + + while ((c = getopt(argc, argv, "b:")) != EOF) + switch (c) { + case 'b': + box = atof(optarg); + if (!box) + usage(*argv); + break; + default: + usage(*argv); + } + + switch (argc-optind) { + case 0: + stl_load_file(stdin, slice); + break; + case 1: + stl_load(argv[optind], slice); + break; + default: + usage(*argv); + } + + slice_dump(box); + + return 0; +}