mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-20 08:40:57 +03:00
tried to parse string functions using constexpr in C++
This commit is contained in:
@@ -31,23 +31,23 @@ typedef struct{
|
||||
|
||||
static glob_pars G = {.headerfile = "hash.h", .sourcefile = "hash.c"};
|
||||
static int help = 0;
|
||||
static myoption cmdlnopts[] = {
|
||||
static sl_option_t cmdlnopts[] = {
|
||||
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), "show this help"},
|
||||
{"dict", NEED_ARG, NULL, 'd', arg_string, APTR(&G.dict), "dictionary file"},
|
||||
{"header", NEED_ARG, NULL, 'H', arg_string, APTR(&G.headerfile),"output header filename"},
|
||||
{"source", NEED_ARG, NULL, 'S', arg_string, APTR(&G.sourcefile),"output source filename"},
|
||||
{"genfunc", NO_ARGS, NULL, 'F', arg_int, APTR(&G.genfunc), "generate function bodys"},
|
||||
{"genfunc", NO_ARGS, NULL, 'F', arg_int, APTR(&G.genfunc), "generate function bodies"},
|
||||
end_option
|
||||
};
|
||||
static void parse_args(int argc, char **argv){
|
||||
parseargs(&argc, &argv, cmdlnopts);
|
||||
if(help) showhelp(-1, cmdlnopts);
|
||||
sl_parseargs(&argc, &argv, cmdlnopts);
|
||||
if(help) sl_showhelp(-1, cmdlnopts);
|
||||
if(argc > 0){
|
||||
red("Unused arguments:\n");
|
||||
for(int i = 0; i < argc; ++i)
|
||||
printf("%s ", argv[i]);
|
||||
printf("\n");
|
||||
showhelp(-1, cmdlnopts);
|
||||
sl_showhelp(-1, cmdlnopts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,10 @@ static const char *fns =
|
||||
"int fn_%s(uint32_t _U_ hash, char _U_ *args) WAL; // \"%s\" (%u)\n\n"
|
||||
;
|
||||
static const char *headercontent =
|
||||
"#ifndef _U_\n\
|
||||
"// Generated by HASHGEN (https://github.com/eddyem/eddys_snippets/tree/master/stringHash4MCU_)\n\
|
||||
// Licensed by GPLv3\n\
|
||||
#pragma once\n\
|
||||
#ifndef _U_\n\
|
||||
#define _U_ __attribute__((__unused__))\n\
|
||||
#endif\n\n\
|
||||
#define CMD_MAXLEN (32)\n\n\
|
||||
@@ -259,12 +262,12 @@ static void build(strhash *H, int hno, int hlen){
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
initial_setup();
|
||||
sl_init();
|
||||
parse_args(argc, argv);
|
||||
if(!G.dict) ERRX("point dictionary file");
|
||||
if(!G.headerfile) ERRX("point header source file");
|
||||
if(!G.sourcefile) ERRX("point c source file");
|
||||
mmapbuf *b = My_mmap(G.dict);
|
||||
sl_mmapbuf_t *b = sl_mmap(G.dict);
|
||||
if(!b) ERRX("Can't open %s", G.dict);
|
||||
char *word = b->data;
|
||||
strhash *H = MALLOC(strhash, ALLOCSZ);
|
||||
@@ -320,6 +323,6 @@ int main(int argc, char **argv){
|
||||
}
|
||||
if(hno == HASHFNO) WARNX("Can't find proper hash function");
|
||||
FREE(H);
|
||||
My_munmap(b);
|
||||
sl_munmap(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user