1 /****************************************************************************
2 * Copyright (C) 2008 by Matteo Franchin *
3 * *
4 * This file is part of Box. *
5 * *
6 * Box is free software: you can redistribute it and/or modify it *
7 * under the terms of the GNU Lesser General Public License as published *
8 * by the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * Box is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with Box. If not, see <http://www.gnu.org/licenses/>. *
18 ****************************************************************************/
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "pointlist.h"
25
26 struct params_for_pointlist_print {
27 BoxInt num_points;
28 FILE *out;
29 };
30
_pointlist_print(BoxInt index,char * name,void * object,void * data)31 static BoxTask _pointlist_print(BoxInt index, char *name,
32 void *object, void *data)
33 {
34 struct params_for_pointlist_print *params =
35 (struct params_for_pointlist_print *) data;
36 BoxPoint *p = (BoxPoint *) object;
37 if (name != (char *) NULL)
38 fprintf(params->out, "\"%s\", ("SReal", "SReal")", name, p->x, p->y);
39 else
40 fprintf(params->out, "("SReal", "SReal")", p->x, p->y);
41 if (index < params->num_points) fprintf(params->out, ", ");
42 return BOXTASK_OK;
43 }
44
pointlist_print(PointList * pl,FILE * out)45 void pointlist_print(PointList *pl, FILE *out) {
46 struct params_for_pointlist_print params;
47 params.out = out;
48 params.num_points = pointlist_num(pl);
49 fprintf(out, "PointList[");
50 (void) pointlist_iter(pl, _pointlist_print, & params);
51 fprintf(out, "]");
52 }
53