BRL-CAD
gdiff.c
Go to the documentation of this file.
1 /* G D I F F . C
2  * BRL-CAD
3  *
4  * Copyright (c) 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/gdiff.c
21  *
22  * The gdiff command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 #include "bu/getopt.h"
32 
33 #include "./ged_private.h"
34 
35 HIDDEN const char *
37 {
38  return NULL;
39 }
40 
41 int
42 ged_gdiff(struct ged *gedp, int argc, const char *argv[])
43 {
44  int left_dbip_specified = 0;
45  int right_dbip_specified = 0;
46  int c = 0;
47  struct bu_vls tmpstr = BU_VLS_INIT_ZERO;
49  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
50 
51  /* initialize result */
52  bu_vls_trunc(gedp->ged_result_str, 0);
53 
54  if (argc < 3) {
55  bu_vls_printf(gedp->ged_result_str, "Usage: %s", gdiff_usage());
56  return GED_ERROR;
57  }
58 
59  /* skip command name */
60  bu_optind = 1;
61  bu_opterr = 1;
62 
63  /* parse args */
64  while ((c=bu_getopt(argc, (char * const *)argv, "O:N:vh?")) != -1) {
65  if (bu_optopt == '?')
66  c='h';
67  switch (c) {
68  case 'O' :
69  left_dbip_specified = 1;
70  bu_vls_sprintf(&tmpstr, "%s", bu_optarg);
71  bu_log("Have origin database: %s", bu_vls_addr(&tmpstr));
72  break;
73  case 'N' :
74  right_dbip_specified = 1;
75  bu_vls_sprintf(&tmpstr, "%s", bu_optarg);
76  bu_log("Have new database: %s", bu_vls_addr(&tmpstr));
77  break;
78  case 'v' :
79  bu_log("Reporting mode is verbose");
80  break;
81  default:
82  bu_vls_printf(gedp->ged_result_str, "Usage: %s", gdiff_usage());
83  return GED_ERROR;
84  }
85  }
86 
87  /* There are possible convention-based interpretations of 1, 2, 3, 4 and n args
88  * beyond those used as options. For the shortest cases, the interpretation depends
89  * on whether one or two .g files are known:
90  *
91  * a) No .g file specified
92  * 1 - objname (error)
93  * 1 - file.g (error)
94  * 2 - file.g objname (error)
95  * 2 - obj1 obj2 (error)
96  * 3 - file.g obj1 obj2 (diff two objects in file.g)
97  *
98  * b) Current .g file known
99  * 1 - objname (error)
100  * 1 - file.g (diff full .g file contents)
101  * 2 - file.g objname (diff obj between current.g and file.g)
102  * 2 - obj1 obj2 (diff two objects in current .g)
103  * 3 - file.g obj1 obj2 (diff all listed objects between current.g and file.g)
104  *
105  * .g file args must always come first.
106  *
107  * A maximum of two .g files can be specified - any additional specification
108  * of .g files is an error.
109  *
110  * When only one environment is specified, all other args must define pairs of
111  * objects to compare.
112  *
113  * When two environments are known, all args will be compared by their instances
114  * in the first environment and the second, not against each other in either
115  * environment.
116  *
117  * When there is a current .g environment and two additional .g files are
118  * specified, the argv environments will override use of the "current" .g environment.
119  */
120  if ((argc - bu_optind) == 2) {
121  bu_log("left: %s", argv[bu_optind]);
122  bu_log("right: %s", argv[bu_optind+1]);
123  } else {
124  if ((argc - bu_optind) == 1) {
125  if (left_dbip_specified || right_dbip_specified)
126  bu_log("obj_name: %s", argv[bu_optind]);
127  } else {
128  bu_vls_printf(gedp->ged_result_str, "Usage: %s", gdiff_usage());
129  return GED_ERROR;
130  }
131  }
132 
133  return GED_OK;
134 }
135 
136 
137 /*
138  * Local Variables:
139  * tab-width: 8
140  * mode: C
141  * indent-tabs-mode: t
142  * c-file-style: "stroustrup"
143  * End:
144  * ex: shiftwidth=4 tabstop=8
145  */
#define GED_OK
Definition: ged.h:55
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
HIDDEN const char * gdiff_usage()
Definition: gdiff.c:36
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
char * bu_optarg
Definition: globals.c:91
Header file for the BRL-CAD common definitions.
int bu_optind
Definition: globals.c:89
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:43
#define GED_ERROR
Definition: ged.h:61
#define HIDDEN
Definition: common.h:86
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
int bu_optopt
Definition: globals.c:90
void bu_vls_sprintf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:707
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
struct bu_vls * ged_result_str
Definition: ged.h:357
int bu_opterr
Definition: globals.c:88
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
int ged_gdiff(struct ged *gedp, int argc, const char *argv[])
Definition: gdiff.c:42
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
Definition: vls.h:56