gwenhywfar 5.12.0
funcs.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Wed Feb 15 2022
3 copyright : (C) 2022 by Ralf Habacker
4 email : ralf.habacker@freenet.de
5
6 ***************************************************************************
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 * *
23 ***************************************************************************/
24
25#ifdef HAVE_CONFIG_H
26# include <config.h>
27#endif
28
29
30#include "funcs.h"
31
32#include <stdio.h>
33
35{
36 return func->func1!=NULL;
37}
38
40{
41 return func->func2!=NULL;
42}
43
45{
46 return func->func3!=NULL;
47}
48
50{
51 return func->func1();
52}
53
54int GWEN_Funcs_Call_Args(const GWEN_FUNCS *func, int argc, char **argv)
55{
56 return func->func2(argc, argv);
57}
58
59int GWEN_Funcs_Call_DB_NODE_Args(const GWEN_FUNCS *func, GWEN_DB_NODE *node, int argc, char **argv)
60{
61 return func->func3(node, argc, argv);
62}
63
67void GWEN_Funcs_Usage(const GWEN_FUNCS *funcs)
68{
69 const GWEN_FUNCS *p;
70
71 for (p=funcs; p->name; p++) {
72 fprintf(stderr, " %s", p->name);
73 if (p->description)
74 fprintf(stderr, " (%s)", p->description);
75 }
76 fprintf(stderr, "\n");
77}
78
83{
84 const GWEN_FUNCS *p;
85
86 for (p=funcs; p->name; p++) {
87 fprintf(stderr, " %s:\n %s\n\n", p->name, p->description ? p->description : "");
88 }
89}
90
95const GWEN_FUNCS* GWEN_Funcs_Find(const GWEN_FUNCS *funcs, const char *name)
96{
97 const GWEN_FUNCS *p;
98
99 for (p=funcs; p->name; p++) {
100 if (strcasecmp(name, p->name)==0)
101 return p;
102 }
103 return NULL;
104}
105
106
107
#define NULL
Definition binreloc.c:300
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
void GWEN_Funcs_Usage_With_Help(const GWEN_FUNCS *funcs)
Definition funcs.c:82
int GWEN_Funcs_Has_Call_DB_NODE_Args(const GWEN_FUNCS *func)
Definition funcs.c:44
const GWEN_FUNCS * GWEN_Funcs_Find(const GWEN_FUNCS *funcs, const char *name)
Definition funcs.c:95
int GWEN_Funcs_Has_Call(const GWEN_FUNCS *func)
Definition funcs.c:34
int GWEN_Funcs_Has_Call_Args(const GWEN_FUNCS *func)
Definition funcs.c:39
int GWEN_Funcs_Call_Args(const GWEN_FUNCS *func, int argc, char **argv)
Definition funcs.c:54
int GWEN_Funcs_Call(const GWEN_FUNCS *func)
Definition funcs.c:49
void GWEN_Funcs_Usage(const GWEN_FUNCS *funcs)
Definition funcs.c:67
int GWEN_Funcs_Call_DB_NODE_Args(const GWEN_FUNCS *func, GWEN_DB_NODE *node, int argc, char **argv)
Definition funcs.c:59
const char * description
Definition funcs.h:47
int(* func3)(GWEN_DB_NODE *, int, char **)
Definition funcs.h:46
int(* func2)(int, char **)
Definition funcs.h:45
const char * name
Definition funcs.h:43
int(* func1)(void)
Definition funcs.h:44