BRL-CAD
title.c
Go to the documentation of this file.
1 /* T I T L E . 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/title.c
21  *
22  * The title command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_title(struct ged *gedp, int argc, const char *argv[])
37 {
38  struct bu_vls title = BU_VLS_INIT_ZERO;
39 
41  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
42 
43  /* initialize result */
44  bu_vls_trunc(gedp->ged_result_str, 0);
45 
46  /* get title */
47  if (argc == 1) {
48  bu_vls_printf(gedp->ged_result_str, "%s", gedp->ged_wdbp->dbip->dbi_title);
49  return GED_OK;
50  }
51 
53 
54  /* set title */
55  bu_vls_from_argv(&title, argc-1, (const char **)argv+1);
56 
57  if (db_update_ident(gedp->ged_wdbp->dbip, bu_vls_addr(&title), gedp->ged_wdbp->dbip->dbi_local2base) < 0) {
58  bu_vls_free(&title);
59  bu_vls_printf(gedp->ged_result_str, "Error: unable to change database title");
60  return GED_ERROR;
61  }
62 
63  bu_vls_free(&title);
64  return GED_OK;
65 }
66 
67 
68 /*
69  * Local Variables:
70  * tab-width: 8
71  * mode: C
72  * indent-tabs-mode: t
73  * c-file-style: "stroustrup"
74  * End:
75  * ex: shiftwidth=4 tabstop=8
76  */
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
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
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
char * dbi_title
title from IDENT rec
Definition: raytrace.h:809
void bu_vls_from_argv(struct bu_vls *vp, int argc, const char *argv[])
Definition: vls.c:532
int db_update_ident(struct db_i *dbip, const char *title, double local2mm)
Definition: db_scan.c:367
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
int ged_title(struct ged *gedp, int argc, const char *argv[])
Definition: title.c:36
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
double dbi_local2base
local2mm
Definition: raytrace.h:807
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
Definition: vls.h:56