BRL-CAD
set_output_script.c
Go to the documentation of this file.
1 /* S E T _ O U T P U T _ S C R I P T . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * 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 this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libged/set_output_script.c
21  *
22  * The set_output_script command.
23  *
24  */
25 
26 #include "common.h"
27 #include <string.h>
28 #include "ged.h"
29 
30 /*
31  * Get/set the output handler script
32  *
33  * Usage:
34  * set_output_script [script]
35  *
36  */
37 int
38 ged_set_output_script(struct ged *gedp, int argc, const char *argv[])
39 {
40  static const char *usage = "[script]";
41 
43  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
44 
45  /* initialize result */
46  bu_vls_trunc(gedp->ged_result_str, 0);
47 
48  if (argc > 2) {
49  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
50  return GED_ERROR;
51  }
52 
53  /* Get the output handler script */
54  if (argc == 1) {
56  return GED_OK;
57  }
58 
59  /* We're now going to set the output handler script */
60  /* First, we zap any previous script */
61  if (gedp->ged_output_script != NULL) {
62  bu_free((void *)gedp->ged_output_script, "ged_set_output_script: zap");
63  gedp->ged_output_script = NULL;
64  }
65 
66  if (argv[1] != NULL && argv[1][0] != '\0')
67  gedp->ged_output_script = bu_strdup(argv[1]);
68 
69  return GED_OK;
70 }
71 
72 
73 /*
74  * Local Variables:
75  * tab-width: 8
76  * mode: C
77  * indent-tabs-mode: t
78  * c-file-style: "stroustrup"
79  * End:
80  * ex: shiftwidth=4 tabstop=8
81  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
struct bu_vls * ged_result_str
Definition: ged.h:357
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
char * ged_output_script
script for use by the outputHandler
Definition: ged.h:369
int ged_set_output_script(struct ged *gedp, int argc, const char *argv[])
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define bu_strdup(s)
Definition: str.h:71