Projekt

Allgemein

Profil

Bug #256 » 0001-Add-GWEN_Funcs_xxx-functions.patch

rhabacker, 16.02.2022 09:43

Unterschiede anzeigen:

src/base/Makefile.am
buffer.h \
debug.h \
error.h \
funcs.h \
gwensignal.h \
i18n.h \
idlist64.h \
......
buffer.c \
debug.c \
error.c \
funcs.c \
gwensignal.c \
i18n.c \
idlist64.c \
src/base/funcs.c
/***************************************************************************
$RCSfile$
-------------------
cvs : $Id$
begin : Wed Feb 15 2022
copyright : (C) 2022 by Ralf Habacker
email : ralf.habacker@freenet.de
***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
* *
***************************************************************************/
typedef struct GWEN_DB_NODE GWEN_DB_NODE;
#include "funcs.h"
#include <stdio.h>
/**
* This function prints out a space separated list of all defined functions
*/
void GWEN_Funcs_Usage(const GWEN_FUNCS *funcs)
{
GWEN_FUNCS *p;
for(p = funcs; p->name; p++) {
fprintf(stderr, " %s", p->name);
if (p->description)
fprintf(stderr, " (%s)", p->description);
}
fprintf(stderr, "\n");
}
/**
* This function prints out list of all defined functions including the description
*/
void GWEN_Funcs_Usage_With_Help(const GWEN_FUNCS *funcs)
{
GWEN_FUNCS *p;
for(p = funcs; p->name; p++) {
fprintf(stderr, " %s:\n\n %s\n\n", p->name, p->description ? p->description : "");
}
}
/**
* This function returns a pointer to the function identified by \p name
* or NULL if function has not been found.
*/
const GWEN_FUNCS* GWEN_Funcs_Find(const GWEN_FUNCS *funcs, const char *name)
{
GWEN_FUNCS *p;
for(p = funcs; p->name; p++) {
if (strcasecmp(name, p->name)==0)
return p;
}
return NULL;
}
src/base/funcs.h
/***************************************************************************
$RCSfile$
-------------------
cvs : $Id$
begin : Wed Feb 15 2022
copyright : (C) 2022 by Ralf Habacker
email : ralf.habacker@freenet.de
***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
* *
***************************************************************************/
#ifndef GWENHYWFAR_Funcs_H
#define GWENHYWFAR_Funcs_H
#include <gwenhywfar/gwenhywfarapi.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* This is one of the very few structs inside Gwenhywfar whose
* contents are available for direct access to the the program.
* Developer's note: Please note that any change within this struct will
* make it necessary to increment the SO_VERSION of the library !
*/
typedef struct {
const char *name;
int (*func1)(void);
int (*func2)(int, char**);
int (*func3)(GWEN_DB_NODE*, int, char**);
const char *description;
} GWEN_FUNCS;
/* Defines a command without parameters but with description */
#define GWEN_Funcs_Entry_Help(a,b,c) { a, b, NULL, NULL, c }
/* Defines a command with argc/argv parameter and description */
#define GWEN_Funcs_Entry_Args_Help(a,b,c) { a, 0, b, NULL, c }
/* Defines a command with DB_NODE type and argc/argv parameter and description */
#define GWEN_Funcs_Entry_DB_NODE_Args_Help(a,b,c) { a, NULL, NULL, b, c }
/* Defines the end of the command table */
#define GWEN_Funcs_Entry_End() { NULL, NULL, NULL, NULL, NULL }
/* Defines one of the above commands without description */
#define GWEN_Funcs_Entry(a,b) { a, b, NULL, NULL, NULL }
#define GWEN_Funcs_Entry_Args(a,b) { a, 0, b, NULL, NULL }
#define GWEN_Funcs_Entry_DB_NODE_Args(a,b) { a, NULL, NULL, b, NULL }
/* Checks if a command variant exists */
#define GWEN_Funcs_Has_Call(func) (func)->func1
#define GWEN_Funcs_Has_Call_Args(func) (func)->func2
#define GWEN_Funcs_Has_Call_DB_NODE_Args(func) (func)->func3
/* Functions to call a specified command */
#define GWEN_Funcs_Call(func) (func->func1)()
#define GWEN_Funcs_Call_Args(func,a,b) (func->func2)(a,b)
#define GWEN_Funcs_Call_DB_NODE_Args(func,a,b,c) (func->func3)(a,b,c)
/**
* This function prints out a space separated list of all defined functions
* without description.
*/
GWENHYWFAR_API
void GWEN_Funcs_Usage(const GWEN_FUNCS* funcs);
/**
* This function outputs a list of all defined functions including the description
*/
GWENHYWFAR_API
void GWEN_Funcs_Usage_With_Help(const GWEN_FUNCS* funcs);
/**
* This function returns a pointer to the function described by \p name
* or NULL if the function was not found.
*/
GWENHYWFAR_API
const GWEN_FUNCS* GWEN_Funcs_Find(const GWEN_FUNCS* funcs, const char *name);
#ifdef __cplusplus
}
#endif
#endif /* GWENHYWFAR_Funcs_H */
(3-3/8)