Skip to content
Snippets Groups Projects
Select Git revision
  • 32a68a1ab439e29919b715a674a034fa15411076
  • jk default protected
2 results

osdd-to-string.h

Blame
  • osdd-to-string.h 5.09 KiB
    /*
     *	On-screen Display
     *
     *	(c) 2020--2021 Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
     */
    
    #include "osdd-set.h"
    #include "util.h"
    
    #define OSDD_TO_STRING_LONGOP \
    		{ "line-separator",		required_argument,	NULL,	'l' },\
    		{ "msq-separator",		required_argument,	NULL,	'm' },\
    		{ "time-separator",		required_argument,	NULL,	'T' },\
    	OSDD_TO_STRINGS_VECTOR_LONGOP
    
    #define OSDD_TO_STRINGS_VECTOR_LONGOP \
    		{ "color",		required_argument,	NULL,	'c' },\
    		{ "replace",		no_argument,	NULL,	'r' },\
    		{ "time",		required_argument,	NULL,	't' },\
    		{ "end",		required_argument,	NULL,	'e' },\
    		{ "end-time",		no_argument,	NULL,	'E' },\
    		{ "on-arrive",		required_argument,	NULL,	'a' },\
    		{ "on-arrive-do-not-que",		required_argument,	NULL,	'A' },\
    
    #define OSDD_TO_STRING_SHORTOP \
    	"l:m:T:" OSDD_TO_STRINGS_VECTOR_SHORTOP
    
    #define OSDD_TO_STRINGS_VECTOR_SHORTOP \
    	"c:rt:T:e:EaA"
    
    #define OSDD_TO_STRINGS_VECTOR_HELP \
    "-c, --color=<{}>\tSet how to print color of messages {no, rgbDEC, rgbHEX, rgbHEXHASHTAG, term, original}\n" \
    "-r, --replace\t\tReplace not alphabet and number in output to '?'\n"\
    "-t, --time=<{}>\t\tSet how to print actual time {no, unix, iso}\n"\
    "-e, --end-<s>\t\tPrint <s> on end of showing message\n"\
    "-E, --end-time\t\tPrint actual time on end messages (format from -t -T)\n"\
    "-a, --on-arrive\t\tPrint message just when arrive (not compatible with -e -E)\n"\
    "-A, --on-arrive\t\tPrint message just when arrive and do not insert it to message queue\n"\
    "\t\t\t\t(not compatible with -e -E)\n"
    
    #define OSDD_TO_STRING_HELP \
    "-c, --color=<{}>\tSet how to print color of messages {no, rgbDEC, rgbHEX, rgbHEXHASHTAG, term, original}\n" \
    "-l, --line-separator=<s>Separato of each line.\n"\
    "-m, --msq-separator=<s>\tSeparato of each message.\n"\
    "-r, --replace\t\tReplace not alphabet and number in output to '?'\n"\
    "-t, --time=<{}>\t\tSet how to print actual time {no, unix, iso}\n"\
    "-T, --time-separator=<s>Separator of time and message text\n"\
    "-e, --end-<s>\t\tPrint <s> on end of showing message\n"\
    "-E, --end-time\t\tPrint actual time on end messages (format from -t -T)\n"\
    "-a, --on-arrive\t\tPrint message just when arrive (not compatible with -e -E)\n"\
    "-A, --on-arrive\t\tPrint message just when arrive and do not insert it to message queue\n"\
    "\t\t\t\t(not compatible with -e -E)\n"
    
    
    struct osd_to_string_state
    {
    	char * line_separator;
    	char * msq_separator;
    	char * time_separator;
    	enum {
    		FILE_COLOR_NO,
    		FILE_COLOR_RGB_DEC,
    		FILE_COLOR_RGB_HEX,
    		FILE_COLOR_RGB_HASHTAG_HEX,
    		FILE_COLOR_TERM_RGB,
    		FILE_COLOR_ORIGINAL,
    	} color_mode;
    	enum {
    		FILE_TIME_NO,
    		FILE_TIME_UNIX,
    		FILE_TIME_ISO,
    	} time_mode;
    	bool replace_no_text;
    	char * end_of_mes_by;
    	bool end_of_mes_time;
    	bool on_arrive;
    	bool do_not_insert_msg_to_que;
    };
    
    char * expand_backslash(char * in);
    
    VECTOR(VECTOR(char)) osd_to_strings_vector(struct osd_to_string_state *state, struct osd_line * lines, int num_lines);
    VECTOR(char) osd_to_string(struct osd_to_string_state *state, struct osd_line * lines, int num_lines);
    
    VECTOR(char) osd_to_string_arrive_msq(struct osd_to_string_state *state, struct osd_line * lines, int num_lines);
    VECTOR(char) osd_to_string_show_msg(struct osd_to_string_state *state, struct osd_line * lines, int num_lines);
    VECTOR(char) osd_to_string_clear_msg(struct osd_to_string_state *state);
    
    VECTOR(VECTOR(char)) osd_to_strings_vector_arrive_msq(struct osd_to_string_state *state, struct osd_line * lines, int num_lines);
    VECTOR(VECTOR(char)) osd_to_strings_vector_show_msg(struct osd_to_string_state *state, struct osd_line * lines, int num_lines);
    VECTOR(VECTOR(char)) osd_to_strings_vector_clear_msg(struct osd_to_string_state *state);
    
    bool osd_to_string_parse_arg(struct osd_to_string_state *state, char arg);
    bool osd_to_strings_vector_parse_arg(struct osd_to_string_state *state, char arg);
    void osd_to_string_state_init(struct osd_to_string_state * state);
    
    #define CREATE_FUNC_USING_TO_STRING(NAME) \
    static \
    bool NAME ## _arrive(struct NAME ## _state *state, struct osd_line * lines, int num_lines) \
    { \
    	NAME ## _write(state,osd_to_string_arrive_msq(&state->to_string, lines, num_lines)); \
    	return state->to_string.do_not_insert_msg_to_que; \
    } \
     \
    static \
    void NAME ## _show(struct NAME ## _state *state, struct osd_line * lines, int num_lines) \
    { \
    	NAME ## _write(state,osd_to_string_show_msg(&state->to_string, lines, num_lines)); \
    } \
     \
    static \
    void NAME ## _clear(struct NAME ## _state *state) \
    { \
    	NAME ## _write(state,osd_to_string_clear_msg(&state->to_string)); \
    }
    
    #define CREATE_FUNC_USING_TO_STRINGS_VECTOR(NAME) \
    static \
    bool NAME ## _arrive(struct NAME ## _state *state, struct osd_line * lines, int num_lines) \
    { \
    	NAME ## _write(state,osd_to_strings_vector_arrive_msq(&state->to_string, lines, num_lines)); \
    	return state->to_string.do_not_insert_msg_to_que; \
    } \
     \
    static \
    void NAME ## _show(struct NAME ## _state *state, struct osd_line * lines, int num_lines) \
    { \
    	NAME ## _write(state,osd_to_strings_vector_show_msg(&state->to_string, lines, num_lines)); \
    } \
     \
    static \
    void NAME ## _clear(struct NAME ## _state *state) \
    { \
    	NAME ## _write(state,osd_to_strings_vector_clear_msg(&state->to_string)); \
    }