// 1. example.cfgtmpl:
../confetti -i example.cfgtmpl -n my_product -f my_product.cfg
// 2. h :
../confetti -i example.cfgtmpl -n my_product -h my_product_cfg.h
../confetti -i example.cfgtmpl -n my_product -c my_product_cfg.c
gcc -Wall -g -O0 -Werror -std=gnu99 -I. -c my_product_cfg.c
// 2. :
../confetti -i example.cfgtmpl -H prscfg.h
../confetti -i example.cfgtmpl -p prscfg.c
gcc -Wall -g -O0 -Werror -std=gnu99 -I. -c prscfg.c
// 4.
gcc -Wall -g -O0 -Werror -std=gnu99 -I. -c example.c
gcc -o example example.o my_product_cfg.o prscfg.o
CONFETTI=/usr/local/bin/confetti
NAME=tarantool_proxy
CFG=tarantool_proxy.cfgtmpl
test_OBJS=tarantool_proxy_cfg.o tnt_config.o prscfg.o
all: $(NAME).cfg test
.SUFFIXES: .oc
.co:
$(CC) $(CFLAGS) $(INCLUDE) -c $<
test: $(test_OBJS)
$(CC) -o $@ $(test_OBJS) $(LIB)
tarantool_proxy: $(test_OBJS)
$(CC) -o $@ $(test_OBJS) $(LIB)
$(NAME).cfg: $(CFG)
$(CONFETTI) -i $< -n $(NAME) -f $(NAME).cfg
$(CONFETTI) -i $< -n $(NAME) -h $(NAME)_cfg.h
$(CONFETTI) -i $< -n $(NAME) -c $(NAME)_cfg.c
prscfg.c: $(CFG)
$(CONFETTI) -i $< -p $@
prscfg.h: $(CFG)
$(CONFETTI) -i $< -H $@
prscfg.c: prscfg.h $(NAME)_cfg.h
$(NAME)_cfg.c: prscfg.h $(NAME)_cfg.h
clean:
rm -f $(NAME).cfg $(NAME)_cfg.c $(NAME)_cfg.h
rm -f prscfg.c prscfg.h
rm -f test
rm *.o
install:
cp $(NAME).def.cfg ../cfg/$(NAME).cfg
cp tarantool_proxy_cfg.o ..
cp prscfg.o ..
cp *.h ..
% {
#include <prscfg.h>
#include <tarantool_proxy_cfg.h>
void out_warning ( ConfettyError r, char * format, ... ) ;
% } :
confetti -i tarantool_proxy.cfgtmpl -n tarantool_proxy -f tarantool_proxy.cfg
pid = "/usr/local/var/tarantool_proxy.pid"
log = "/usr/local/var/log/tarantool_proxy.log"
daemon = 1
pool_size = 4096
# count of threads
threads = 4
#listen
host = "localhost"
port = 33013
# server connections
server = [
hostname = "localhost"
port = 33013
namespace = [
key = NULL , required
]
]
namespace = [
type = NULL , required
]
server [ 0 ] . hostname = "host2"
server [ 0 ] . port = 33013
server [ 1 ] . hostname = "host1"
server [ 1 ] . port = 33023
namespace [ 1 ] . type = "str"
namespace [ 0 ] . type = "int"
server [ 0 ] . namespace [ 0 ] . key = "345"
server [ 0 ] . namespace [ 1 ] . key = "abc"
server [ 1 ] . namespace [ 0 ] . key = "xyz"
server [ 1 ] . namespace [ 1 ] . key = "345"
./test
==========Accepted: 11; Skipped: 0===========
pid => '/usr/local/var/tarantool_proxy.pid'
log => '/usr/local/var/log/tarantool_proxy.log'
daemon => '1'
pool_size => '4096'
threads => '4'
host => 'localhost'
port => '33013'
server[0].hostname => 'localhost'
server[0].port => '33013'
server[0].namespace[0].key => '345'
server[0].namespace[1].key => 'abc'
server[1].hostname => 'tfn24'
server[1].port => '33023'
server[1].namespace[0].key => 'xyz'
server[1].namespace[1].key => '345'
namespace[0].type => 'int'
namespace[1].type => 'str'
==========DIRECT=========
pid=/usr/local/var/tarantool_proxy.pid
daemon=1
keys
==========Destroy=========
: ./test
==========Accepted: 11; Skipped: 0===========
pid => '/usr/local/var/tarantool_proxy.pid'
log => '/usr/local/var/log/tarantool_proxy.log'
daemon => '1'
pool_size => '4096'
threads => '4'
host => 'localhost'
port => '33013'
server[0].hostname => 'localhost'
server[0].port => '33013'
server[0].namespace[0].key => '345'
server[0].namespace[1].key => 'abc'
server[1].hostname => 'tfn24'
server[1].port => '33023'
server[1].namespace[0].key => 'xyz'
server[1].namespace[1].key => '345'
namespace[0].type => 'int'
namespace[1].type => 'str'
==========DIRECT=========
pid=/usr/local/var/tarantool_proxy.pid
daemon=1
keys
==========Destroy=========
./test
==========Accepted: 11; Skipped: 0===========
pid => '/usr/local/var/tarantool_proxy.pid'
log => '/usr/local/var/log/tarantool_proxy.log'
daemon => '1'
pool_size => '4096'
threads => '4'
host => 'localhost'
port => '33013'
server[0].hostname => 'localhost'
server[0].port => '33013'
server[0].namespace[0].key => '345'
server[0].namespace[1].key => 'abc'
server[1].hostname => 'tfn24'
server[1].port => '33023'
server[1].namespace[0].key => 'xyz'
server[1].namespace[1].key => '345'
namespace[0].type => 'int'
namespace[1].type => 'str'
==========DIRECT=========
pid=/usr/local/var/tarantool_proxy.pid
daemon=1
keys
==========Destroy=========
printf ( "========== DIRECT ========== \ n " ) ;
printf ( "pid =% s \ n " , cfg. pid ) ;
printf ( "daemon =% d \ n " , cfg. daemon ) ;
tarantool_proxy_namespace ** it = cfg. namespace ;
while ( * it ! = NULL ) {
printf ( "namespace type =% s \ n " , ( * it ) -> type ) ;
++ it ;
}
tarantool_proxy cfg ;
char * key , * value ;
fill_default_tarantool_proxy ( & cfg ) ;
int nAccepted , nSkipped ;
FILE * fh = fopen ( filename , "r" ) ;
if ( ! fh ) {
fprintf ( stderr , "Could not open file% s \ n " , argv [ 1 ] ) ;
return 1 ;
}
useStdout = 1 ;
parse_cfg_file_tarantool_proxy ( & cfg , fh , 1 , & nAccepted , & nSkipped ) ;
printf ( "========== Accepted:% d; Skipped:% d ============ \ n " , nAccepted , nSkipped ) ;
fclose ( fh ) ;
tarantool_proxy_iterator_t * i ;
i = tarantool_proxy_iterator_init ( ) ;
while ( ( key = tarantool_proxy_iterator_next ( i , & cfg , & value ) ) ! = NULL ) {
if ( value ) {
printf ( "% s => '% s' \ n " , key , value ) ;
free ( value ) ;
} else {
printf ( "% s => (null) \ n " , key ) ;
}
}
Source: https://habr.com/ru/post/127387/
All Articles