mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
debug macros
This commit is contained in:
parent
6b6e83db8f
commit
475eeb8121
7 changed files with 178 additions and 18 deletions
10
include/psyc.h
Normal file
10
include/psyc.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PSYC_EPOCH 1440444041 // 2015-08-24 21:20:41 CET (Monday)
|
||||
|
||||
/** @brief Checks if short keyword string matches long keyword string
|
||||
*/
|
||||
int PSYC_matches(uint8_t* sho, unsigned int slen,
|
||||
uint8_t* lon, unsigned int llen);
|
||||
|
95
include/psyc/debug.h
Normal file
95
include/psyc/debug.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
#ifdef DEBUG
|
||||
# include <stdio.h>
|
||||
# define PP(args) printf args;
|
||||
#else
|
||||
# define PP(args)
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
# define PT(MSG) PP(MSG);
|
||||
# define DT(CODE) CODE
|
||||
#else
|
||||
# define PT(MSG)
|
||||
# define DT(CODE)
|
||||
#endif
|
||||
|
||||
/* simplified form of conditional compilation */
|
||||
|
||||
#ifndef DEBUG_FLAGS
|
||||
# ifdef DEBUG
|
||||
# if DEBUG == 1
|
||||
# define DEBUG_FLAGS 0x03
|
||||
# else
|
||||
# if DEBUG == 2
|
||||
# define DEBUG_FLAGS 0x07
|
||||
# else
|
||||
# if DEBUG == 3
|
||||
# define DEBUG_FLAGS 0x0f
|
||||
# else
|
||||
# if DEBUG == 4
|
||||
# define DEBUG_FLAGS 0x1f
|
||||
# else
|
||||
# define DEBUG_FLAGS 0x01
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# else
|
||||
# define DEBUG_FLAGS 0x00 /* no debugging */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if DEBUG_FLAGS & 0x01
|
||||
# define D0(CODE) CODE
|
||||
# define P0(MSG) PP(MSG);
|
||||
#else
|
||||
# define D0(CODE)
|
||||
# define P0(MSG)
|
||||
#endif
|
||||
|
||||
#if DEBUG_FLAGS & 0x02
|
||||
# define D1(CODE) CODE
|
||||
# define P1(MSG) PP(MSG);
|
||||
#else
|
||||
# define D1(CODE)
|
||||
# define P1(MSG)
|
||||
#endif
|
||||
|
||||
#if DEBUG_FLAGS & 0x04
|
||||
# define D2(CODE) CODE
|
||||
# define P2(MSG) PP(MSG);
|
||||
#else
|
||||
# define D2(CODE)
|
||||
# define P2(MSG)
|
||||
#endif
|
||||
|
||||
#if DEBUG_FLAGS & 0x08
|
||||
# define D3(CODE) CODE
|
||||
# define P3(MSG) PP(MSG);
|
||||
#else
|
||||
# define D3(CODE)
|
||||
# define P3(MSG)
|
||||
#endif
|
||||
|
||||
#if DEBUG_FLAGS & 0x10
|
||||
# define D4(CODE) CODE
|
||||
# define P4(MSG) PP(MSG);
|
||||
#else
|
||||
# define D4(CODE)
|
||||
# define P4(MSG)
|
||||
#endif
|
||||
|
||||
// ASSERT() unused as yet
|
||||
#if DEBUG > 0
|
||||
# ifdef STRICT
|
||||
# define ASSERT(NAME,COND,VALUE) { unless (COND) { \
|
||||
PP(("Assertion %s failed in %s: %s\n", NAME, ME, VALUE)); \
|
||||
raise_error("Assertion failed (strict mode).\n"); } }
|
||||
# else
|
||||
# define ASSERT(NAME,COND,VALUE) { unless (COND) \
|
||||
PP(("Assertion %s failed in %s: %s\n", NAME, ME, VALUE)); }
|
||||
# endif
|
||||
#else
|
||||
# define ASSERT(NAME,CONDITION,VALUE)
|
||||
#endif
|
||||
|
9
include/psyc/lib.h
Normal file
9
include/psyc/lib.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* this is needed to compile the library, not to use it */
|
||||
|
||||
#include "../psyc.h"
|
||||
#include "./debug.h"
|
||||
|
||||
/* perlisms for readability */
|
||||
#define unless(COND) if (!(COND))
|
||||
#define until(COND) while (!(COND))
|
||||
|
39
include/psyc/syntax.h
Normal file
39
include/psyc/syntax.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef PSYC_SYNTAX_H
|
||||
#define PSYC_SYNTAX_H
|
||||
|
||||
#ifndef PSYC_LIST_SIZE_LIMIT
|
||||
# define PSYC_LIST_SIZE_LIMIT 404
|
||||
#endif
|
||||
|
||||
/* beyond this a content length must be provided */
|
||||
#ifndef PSYC_CONTENT_SIZE_THRESHOLD
|
||||
# define PSYC_CONTENT_SIZE_THRESHOLD 444
|
||||
#endif
|
||||
|
||||
#define C_GLYPH_PACKET_DELIMITER '.'
|
||||
#define S_GLYPH_PACKET_DELIMITER "."
|
||||
|
||||
#define C_GLYPH_SEPARATOR_KEYWORD '_'
|
||||
#define S_GLYPH_SEPARATOR_KEYWORD "_"
|
||||
|
||||
#define C_GLYPH_MODIFIER_SET ':'
|
||||
#define S_GLYPH_MODIFIER_SET ":"
|
||||
|
||||
#define C_GLYPH_MODIFIER_ASSIGN '='
|
||||
#define S_GLYPH_MODIFIER_ASSIGN "="
|
||||
|
||||
#define C_GLYPH_MODIFIER_AUGMENT '+'
|
||||
#define S_GLYPH_MODIFIER_AUGMENT "+"
|
||||
|
||||
#define C_GLYPH_MODIFIER_DIMINISH '-'
|
||||
#define S_GLYPH_MODIFIER_DIMINISH "-"
|
||||
|
||||
#define C_GLYPH_MODIFIER_QUERY '?'
|
||||
#define S_GLYPH_MODIFIER_QUERY "?"
|
||||
|
||||
/* might move into routing.h or something */
|
||||
#define PSYC_ROUTING 1
|
||||
#define PSYC_ROUTING_MERGE 2
|
||||
#define PSYC_ROUTING_RENDER 4
|
||||
|
||||
#endif /* PSYC_SYNTAX_H */
|
17
src/Makefile
17
src/Makefile
|
@ -1,18 +1,21 @@
|
|||
CC=cc
|
||||
CC=cc -I../include
|
||||
# CC=clang
|
||||
|
||||
S=parser.c match.c
|
||||
O=parser.o match.o
|
||||
|
||||
default:
|
||||
@/bin/echo -e "Usage:\n\tmake diet - compile with diet libc\n\tmake lib - compile with normal gnu libc"
|
||||
|
||||
diet:
|
||||
/opt/diet/bin/diet ${CC} -static -c -Os parser.c -o libpsyc.o -DDEBUG
|
||||
/opt/diet/bin/diet ar rcs libpsyc.a libpsyc.o
|
||||
/opt/diet/bin/diet ${CC} -static -c -Os $S -DDEBUG
|
||||
/opt/diet/bin/diet ar rcs libpsyc.a $O
|
||||
|
||||
lib:
|
||||
${CC} -static -c -Os parser.c -lc -o libpsyc.o -DDEBUG -I../include
|
||||
ar rcs libpsyc.a libpsyc.o
|
||||
lib: $S
|
||||
${CC} -static -c -Os $S -lc -DDEBUG
|
||||
ar rcs libpsyc.a $O
|
||||
|
||||
match: match.c
|
||||
${CC} -o $@ -DTEST $<
|
||||
${CC} -o $@ -DDEBUG=2 -DCMDTOOL -DTEST $<
|
||||
|
||||
it: match
|
||||
|
|
14
src/match.c
14
src/match.c
|
@ -1,15 +1,7 @@
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef TEST
|
||||
# include <stdio.h>
|
||||
# define PT(args) printf args;
|
||||
#else
|
||||
# define PT(args)
|
||||
#endif
|
||||
#include "psyc/lib.h"
|
||||
|
||||
int PSYC_matches(uint8_t* sho, unsigned int slen,
|
||||
uint8_t* lon, unsigned int llen) {
|
||||
uint8_t* lon, unsigned int llen) {
|
||||
uint8_t *s, *l, *se, *le;
|
||||
|
||||
if (!slen) slen = strlen(sho);
|
||||
|
@ -66,7 +58,7 @@ failed:
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#ifdef CMDTOOL
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s <short> <long>\n\nExample: %s _failure_delivery _failure_unsuccessful_delivery_death\n", argv[0], argv[0]);
|
||||
|
|
12
src/tests/testMatch.c
Normal file
12
src/tests/testMatch.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include "../include/psyc/lib.h"
|
||||
|
||||
int main() {
|
||||
if (PSYC_matches("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -1;
|
||||
if (PSYC_matches("_failure_trash", 8, "_failure_unsuccessful_delivery_death", 0)) return -2;
|
||||
if (PSYC_matches("_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -3;
|
||||
if (PSYC_matches("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -4;
|
||||
unless (PSYC_matches("_truthahn", 0, "_failure_unsuccessful_delivery_death", 0)) return -5;
|
||||
|
||||
return 0; // passed all tests
|
||||
}
|
Loading…
Reference in a new issue