Coverage Report

Created: 2023-09-25 06:26

/src/gdbm/tools/gdbmtool.h
Line
Count
Source (jump to first uncovered line)
1
/* This file is part of GDBM, the GNU data base manager.
2
   Copyright (C) 1990-2023 Free Software Foundation, Inc.
3
4
   GDBM is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
6
   the Free Software Foundation; either version 3, or (at your option)
7
   any later version.
8
9
   GDBM is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with GDBM. If not, see <http://www.gnu.org/licenses/>.    */
16
17
#include "autoconf.h"
18
#include "gdbmdefs.h"
19
#include "gdbm.h"
20
#include "gdbmapp.h"
21
#include <stdlib.h>
22
#include <stdio.h>
23
#include <stdarg.h>
24
#include <string.h>
25
#include <ctype.h>
26
#include <limits.h>
27
28
#ifndef GDBM_ARG_UNUSED
29
# define GDBM_ARG_UNUSED __attribute__ ((__unused__))
30
#endif
31
32
#ifndef GDBM_PRINTFLIKE
33
# define GDBM_PRINTFLIKE(fmt,narg) \
34
  __attribute__ ((__format__ (__printf__, fmt, narg)))
35
#endif
36
37
/* Position in input file */
38
struct point
39
{
40
  char *file;             /* file name */
41
  unsigned line;          /* line number */  
42
  unsigned col;           /* column number */ 
43
};
44
45
/* Location in input file */
46
struct locus
47
{
48
  struct point beg, end;
49
};
50
51
typedef struct locus gdbm_yyltype_t;
52
 
53
22.8k
#define YYLTYPE gdbm_yyltype_t 
54
55
#define YYLLOC_DEFAULT(Current, Rhs, N)           \
56
436k
  do                    \
57
436k
    {                   \
58
436k
      if (N)                 \
59
436k
  {                 \
60
391k
    (Current).beg = YYRHSLOC(Rhs, 1).beg;         \
61
391k
    (Current).end = YYRHSLOC(Rhs, N).end;         \
62
391k
  }                  \
63
436k
      else                  \
64
436k
  {                 \
65
45.3k
    (Current).beg = YYRHSLOC(Rhs, 0).end;         \
66
45.3k
    (Current).end = (Current).beg;          \
67
45.3k
  }                  \
68
436k
    }                   \
69
436k
  while (0)
70
71
1.85k
#define YY_LOCATION_PRINT(File, Loc) locus_print (File, &(Loc))
72
73
void locus_print (FILE *fp, struct locus const *loc);
74
void vlerror (struct locus *loc, const char *fmt, va_list ap);
75
void lerror (struct locus *loc, const char *fmt, ...)
76
     GDBM_PRINTFLIKE (2, 3);
77
78
void terror (const char *fmt, ...)
79
     GDBM_PRINTFLIKE (1, 2);
80
void dberror (char const *fmt, ...)
81
     GDBM_PRINTFLIKE (1, 2);
82
83
char *make_prompt (void);
84
85
#define GDBMTOOLRC ".gdbmtoolrc"
86
#define GDBMTOOL_DEFFILE "junk.gdbm"
87

88
typedef struct instream *instream_t;
89
90
struct instream
91
{
92
  char *in_name;           /* Input stream name */
93
  int in_inter;            /* True if this is an interactive stream */
94
  ssize_t (*in_read) (instream_t, char*, size_t);
95
                           /* Read from stream */
96
  void (*in_close) (instream_t);
97
                           /* Close the stream */
98
  int (*in_eq) (instream_t, instream_t);
99
                           /* Return true if both streams refer to the
100
            same input */
101
  int (*in_history_size) (instream_t);
102
                           /* Return size of the history buffer (entries) */
103
  const char *(*in_history_get) (instream_t, int);
104
                           /* Get Nth line from the history buffer */
105
};
106
107
static inline char const *
108
instream_name (instream_t in)
109
7.28k
{
110
7.28k
  return in->in_name;
111
7.28k
}
Unexecuted instantiation: gram.c:instream_name
lex.c:instream_name
Line
Count
Source
109
7.28k
{
110
7.28k
  return in->in_name;
111
7.28k
}
Unexecuted instantiation: gdbmshell.c:instream_name
Unexecuted instantiation: var.c:instream_name
Unexecuted instantiation: util.c:instream_name
Unexecuted instantiation: datconv.c:instream_name
Unexecuted instantiation: input-file.c:instream_name
Unexecuted instantiation: input-null.c:instream_name
112
113
static inline ssize_t
114
instream_read (instream_t in, char *buf, size_t size)
115
7.28k
{
116
7.28k
  return in->in_read (in, buf, size);
117
7.28k
}
Unexecuted instantiation: gram.c:instream_read
lex.c:instream_read
Line
Count
Source
115
7.28k
{
116
7.28k
  return in->in_read (in, buf, size);
117
7.28k
}
Unexecuted instantiation: gdbmshell.c:instream_read
Unexecuted instantiation: var.c:instream_read
Unexecuted instantiation: util.c:instream_read
Unexecuted instantiation: datconv.c:instream_read
Unexecuted instantiation: input-file.c:instream_read
Unexecuted instantiation: input-null.c:instream_read
118
119
static inline void
120
instream_close (instream_t in)
121
7.28k
{
122
7.28k
  in->in_close (in);
123
7.28k
}
Unexecuted instantiation: gram.c:instream_close
lex.c:instream_close
Line
Count
Source
121
7.28k
{
122
7.28k
  in->in_close (in);
123
7.28k
}
Unexecuted instantiation: gdbmshell.c:instream_close
Unexecuted instantiation: var.c:instream_close
Unexecuted instantiation: util.c:instream_close
Unexecuted instantiation: datconv.c:instream_close
Unexecuted instantiation: input-file.c:instream_close
Unexecuted instantiation: input-null.c:instream_close
124
125
static inline int
126
instream_interactive (instream_t in)
127
72.6k
{
128
72.6k
  return in->in_inter;
129
72.6k
}
Unexecuted instantiation: gram.c:instream_interactive
lex.c:instream_interactive
Line
Count
Source
127
68.0k
{
128
68.0k
  return in->in_inter;
129
68.0k
}
gdbmshell.c:instream_interactive
Line
Count
Source
127
4.57k
{
128
4.57k
  return in->in_inter;
129
4.57k
}
Unexecuted instantiation: var.c:instream_interactive
Unexecuted instantiation: util.c:instream_interactive
Unexecuted instantiation: datconv.c:instream_interactive
Unexecuted instantiation: input-file.c:instream_interactive
Unexecuted instantiation: input-null.c:instream_interactive
130
131
static inline int
132
instream_eq (instream_t a, instream_t b)
133
0
{
134
0
  return a->in_eq (a, b);
135
0
}
Unexecuted instantiation: gram.c:instream_eq
Unexecuted instantiation: lex.c:instream_eq
Unexecuted instantiation: gdbmshell.c:instream_eq
Unexecuted instantiation: var.c:instream_eq
Unexecuted instantiation: util.c:instream_eq
Unexecuted instantiation: datconv.c:instream_eq
Unexecuted instantiation: input-file.c:instream_eq
Unexecuted instantiation: input-null.c:instream_eq
136
137
static inline int
138
instream_history_size (instream_t in)
139
0
{
140
0
  return in->in_history_size ? in->in_history_size (in) : -1;
141
0
}
Unexecuted instantiation: gram.c:instream_history_size
Unexecuted instantiation: lex.c:instream_history_size
Unexecuted instantiation: gdbmshell.c:instream_history_size
Unexecuted instantiation: var.c:instream_history_size
Unexecuted instantiation: util.c:instream_history_size
Unexecuted instantiation: datconv.c:instream_history_size
Unexecuted instantiation: input-file.c:instream_history_size
Unexecuted instantiation: input-null.c:instream_history_size
142
143
static inline const char *
144
instream_history_get (instream_t in, int n)
145
0
{
146
0
  return in->in_history_get ? in->in_history_get (in, n) : NULL;
147
0
}
Unexecuted instantiation: gram.c:instream_history_get
Unexecuted instantiation: lex.c:instream_history_get
Unexecuted instantiation: gdbmshell.c:instream_history_get
Unexecuted instantiation: var.c:instream_history_get
Unexecuted instantiation: util.c:instream_history_get
Unexecuted instantiation: datconv.c:instream_history_get
Unexecuted instantiation: input-file.c:instream_history_get
Unexecuted instantiation: input-null.c:instream_history_get
148
149
instream_t instream_stdin_create (void);
150
instream_t instream_argv_create (int argc, char **argv);
151
instream_t instream_file_create (char const *name);
152
instream_t instream_null_create (void);
153
#ifdef WITH_READLINE
154
instream_t instream_readline_create (void);
155
#endif
156
157
int interactive (void);
158
int input_context_push (instream_t);
159
int input_context_pop (void);
160
void input_context_drain (void);
161
int input_history_size (void);
162
const char *input_history_get (int n);
163
const char *input_stream_name (void);
164
165

166
void print_prompt_at_bol (void);
167
char *command_generator (const char *text, int state);
168
169

170
struct slist
171
{
172
  struct slist *next;
173
  char *str;
174
};
175
176
struct slist *slist_new (char const *s);
177
struct slist *slist_new_s (char *s);
178
struct slist *slist_new_l (char const *s, size_t l);
179
void slist_free (struct slist *);
180
void slist_insert (struct slist **where, struct slist *what);
181

182
54.3k
#define KV_STRING 0
183
0
#define KV_LIST   1
184
185
struct kvpair
186
{
187
  struct kvpair *next;
188
  int type;
189
  struct locus loc;
190
  char *key;
191
  union
192
  {
193
    char *s;
194
    struct slist *l;
195
  } val;
196
};
197
198
struct kvpair *kvpair_string (struct locus *loc, char *val);
199
struct kvpair *kvpair_list (struct locus *loc, struct slist *s);
200
struct kvpair *kvlist_find (struct kvpair *kv, char const *tag);
201
void kvlist_free (struct kvpair *kvp);
202
203

204
32.6k
#define GDBM_ARG_STRING 0
205
27.1k
#define GDBM_ARG_DATUM  1
206
0
#define GDBM_ARG_KVPAIR 2
207
#define GDBM_ARG_MAX    3
208
209
/* Argument to a command handler */
210
struct gdbmarg
211
{
212
  struct gdbmarg *next;
213
  int type;
214
  int ref;
215
  struct locus loc;
216
  union
217
  {
218
    char *string;
219
    datum dat;
220
    struct kvpair *kvpair;
221
  } v;
222
};
223
224
/* List of arguments */
225
struct gdbmarglist
226
{
227
  struct gdbmarg *head, *tail;
228
};
229
230
struct command_param
231
{
232
  size_t argc;
233
  size_t argmax;
234
  struct gdbmarg **argv;
235
  struct gdbmarg *vararg;
236
};
237
  
238
58.9k
#define HANDLER_PARAM_INITIALIZER { 0, 0, NULL, NULL }
239
240
0
#define PARAM_LOCPTR(p,n) (&(p)->argv[n]->loc)
241
2.71k
#define PARAM_STRING(p,n) ((p)->argv[n]->v.string)
242
13.5k
#define PARAM_DATUM(p,n)  ((p)->argv[n]->v.dat)
243
#define PARAM_KVPAIR(p,n) ((p)->argv[n]->v.kvpair)
244
245
void gdbmarglist_init (struct gdbmarglist *, struct gdbmarg *);
246
void gdbmarglist_add (struct gdbmarglist *, struct gdbmarg *);
247
void gdbmarglist_free (struct gdbmarglist *lst);
248
249
struct gdbmarg *gdbmarg_string (char *, struct locus *);
250
struct gdbmarg *gdbmarg_datum (datum *, struct locus *);
251
struct gdbmarg *gdbmarg_kvpair (struct kvpair *kvl, struct locus *);
252
253
int gdbmarg_free (struct gdbmarg *arg);
254
void gdbmarg_destroy (struct gdbmarg **parg);
255

256
struct command_environ
257
{
258
  FILE *fp;
259
  void *data;
260
};
261
262
58.9k
#define COMMAND_ENVIRON_INITIALIZER { NULL, NULL }
263

264
struct command;
265
int command_lookup (const char *str, struct locus *loc, struct command **pcmd);
266
267
int run_command (struct command *cmd, struct gdbmarglist *arglist);
268
int run_last_command (void);
269

270
struct xdatum;
271
void xd_expand (struct xdatum *xd, size_t size);
272
void xd_store (struct xdatum *xd, void *val, size_t size);
273
274

275
struct datadef
276
{
277
  char *name;
278
  int size;
279
  int (*format) (FILE *, void *ptr, int size);
280
  int (*scan) (struct xdatum *xd, char *str);
281
};
282
283
struct datadef *datadef_lookup (const char *name);
284
285
struct field
286
{
287
  struct datadef *type;
288
  int dim;
289
  char *name;
290
};
291
292
37.6k
#define FDEF_FLD 0
293
0
#define FDEF_OFF 1
294
0
#define FDEF_PAD 2
295
296
struct dsegm
297
{
298
  struct dsegm *next;
299
  int type;
300
  union
301
  {
302
    int n;
303
    struct field field;
304
  } v;
305
};
306
307
struct dsegm *dsegm_new (int type);
308
struct dsegm *dsegm_new_field (struct datadef *type, char *id, int dim);
309
void dsegm_list_free (struct dsegm *dp);
310
struct dsegm *dsegm_list_find (struct dsegm *dp, char const *name);
311
312
10.1k
#define DS_KEY     0
313
10.2k
#define DS_CONTENT 1
314
13.7k
#define DS_MAX     2
315
316
extern struct dsegm *dsdef[];
317

318
531k
#define VART_STRING 0
319
174k
#define VART_BOOL   1
320
142k
#define VART_INT    2
321
322
enum
323
  {
324
    VAR_OK,           /* operation succeeded */
325
    VAR_ERR_NOTSET,   /* Only for variable_get: variable is not set */ 
326
    VAR_ERR_NOTDEF,   /* no such variable */ 
327
    VAR_ERR_BADTYPE,  /* variable cannot be coerced to the requested type
328
       (software error) */
329
    VAR_ERR_BADVALUE, /* Only for variable_set: the value is not valid for
330
       this variable. */
331
    VAR_ERR_GDBM,     /* GDBM error */
332
  };
333
334
335
int variable_set (const char *name, int type, void *val);
336
int variable_get (const char *name, int type, void **val);
337
int variable_unset(const char *name);
338
int variable_is_set (const char *name);
339
int variable_is_true (const char *name);
340
void variable_print_all (FILE *fp);
341
static inline int
342
variable_has_errno (char *varname, int e)
343
48.1k
{
344
48.1k
  return variable_get (varname, VART_INT, (void**)&e) == VAR_OK && e == 1;
345
48.1k
}
gram.c:variable_has_errno
Line
Count
Source
343
25.3k
{
344
25.3k
  return variable_get (varname, VART_INT, (void**)&e) == VAR_OK && e == 1;
345
25.3k
}
Unexecuted instantiation: lex.c:variable_has_errno
gdbmshell.c:variable_has_errno
Line
Count
Source
343
22.7k
{
344
22.7k
  return variable_get (varname, VART_INT, (void**)&e) == VAR_OK && e == 1;
345
22.7k
}
Unexecuted instantiation: var.c:variable_has_errno
Unexecuted instantiation: util.c:variable_has_errno
Unexecuted instantiation: datconv.c:variable_has_errno
Unexecuted instantiation: input-file.c:variable_has_errno
Unexecuted instantiation: input-null.c:variable_has_errno
346
static inline int
347
gdbm_error_is_masked (int e)
348
30.5k
{
349
30.5k
  return variable_has_errno ("errormask", e);
350
30.5k
}
gram.c:gdbm_error_is_masked
Line
Count
Source
348
25.3k
{
349
25.3k
  return variable_has_errno ("errormask", e);
350
25.3k
}
Unexecuted instantiation: lex.c:gdbm_error_is_masked
gdbmshell.c:gdbm_error_is_masked
Line
Count
Source
348
5.15k
{
349
5.15k
  return variable_has_errno ("errormask", e);
350
5.15k
}
Unexecuted instantiation: var.c:gdbm_error_is_masked
Unexecuted instantiation: util.c:gdbm_error_is_masked
Unexecuted instantiation: datconv.c:gdbm_error_is_masked
Unexecuted instantiation: input-file.c:gdbm_error_is_masked
Unexecuted instantiation: input-null.c:gdbm_error_is_masked
351

352
int unescape (int c);
353
int escape (int c);
354
void begin_def (void);
355
void end_def (void);
356
357
int yylex (void);
358
int yylex_destroy (void);
359
void yyerror (char const *s);
360
#define YYERROR_IS_DECLARED 1
361
int yyparse (void);
362
363
void lex_trace (int n);
364
void gram_trace (int n);
365
366
void datum_format (FILE *fp, datum const *dat, struct dsegm *ds);
367
int datum_scan (datum *dat, struct dsegm *ds, struct kvpair *kv);
368
void dsprint (FILE *fp, int what, struct dsegm *ds);
369
370
char *mkfilename (const char *dir, const char *file, const char *suf);
371
char *tildexpand (char *s);
372
int vgetyn (const char *prompt, va_list ap);
373
int getyn (const char *prompt, ...) GDBM_PRINTFLIKE (1, 2);
374
375
int getnum (int *pnum, char *arg, char **endp);
376
377
int gdbmshell (instream_t input);
378
int gdbmshell_run (int (*init) (void *, instream_t *), void *data);
379
380
int gdbmshell_setopt (char *name, int opt, int val);
381
382
void variables_init (void);
383
void variables_free (void);
384