force to new usefull_macros lib

This commit is contained in:
2025-06-23 16:35:29 +03:00
parent db2c0e2d9c
commit 89815e8981
28 changed files with 1717 additions and 88 deletions

View File

@@ -18,9 +18,7 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include <usefull_macros.h>
#include "cmdlnopts.h"
@@ -28,7 +26,6 @@
* here are global parameters initialisation
*/
int help;
static glob_pars G;
// default values for Gdefault & help
#define DEFAULT_PORT "12345"
@@ -36,7 +33,7 @@ static glob_pars G;
// DEFAULTS
// default global parameters
glob_pars const Gdefault = {
static glob_pars G = {
.device = NULL,
.port = DEFAULT_PORT,
.logfile = NULL,
@@ -52,7 +49,7 @@ glob_pars const Gdefault = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
myoption cmdlnopts[] = {
sl_option_t cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"device", NEED_ARG, NULL, 'd', arg_string, APTR(&G.device), _("serial device name (default: none)")},
@@ -73,19 +70,15 @@ myoption cmdlnopts[] = {
* @return allocated structure with global parameters
*/
glob_pars *parse_args(int argc, char **argv){
int i;
void *ptr;
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
// format of help: "Usage: progname [args]\n"
change_helpstring("Usage: %s [args]\n\n\tWhere args are:\n");
sl_helpstring("Usage: %s [args]\n\n\tWhere args are:\n");
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
if(argc > 0){
G.rest_pars_num = argc;
G.rest_pars = calloc(argc, sizeof(char*));
for (i = 0; i < argc; i++)
G.rest_pars[i] = strdup(argv[i]);
printf("Ignore flags:\n");
for(int i = 0; i < argc; i++)
printf("\t%s\n", argv[i]);
}
return &G;
}