libamxrt  0.4.2
Ambiorix Run Time Library
amxrt_user_output.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include <amxrt/amxrt.h>
#include "amxrt_priv.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

static void amxrt_cmd_line_arg (const char so, const char *lo, const char *args, const char *description)
 
static void amxrt_print_notes (void)
 
static void amxrt_print_config_example (void)
 
const char * get_color (uint32_t cc)
 
void amxrt_print_usage (void)
 Prints the usage information and all available options to stdout. More...
 
void amxrt_print_help (void)
 
void amxrt_print_configuration (void)
 
void amxrt_print_error (const char *fmt,...)
 
void amxrt_print_message (const char *fmt,...)
 
void amxrt_print_failure (amxo_parser_t *parser, const char *string)
 

Variables

static const char * colors []
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxrt_user_output.c.

Function Documentation

◆ amxrt_cmd_line_arg()

static void amxrt_cmd_line_arg ( const char  so,
const char *  lo,
const char *  args,
const char *  description 
)
static

Definition at line 78 of file amxrt_user_output.c.

81  {
82  int pre_length = 4 + 2 + 4 + strlen(lo);
83 
84  printf(" %s-%c%s %s--%s%s",
85  c(GREEN), so, c(RESET),
86  c(GREEN), lo, c(RESET));
87 
88  if(args != NULL) {
89  pre_length += 3 + strlen(args);
90  printf("%s %s %s ", c(BLUE), args, c(RESET));
91  }
92  for(int i = 39 - pre_length; i > 0; i--) {
93  printf(" ");
94  }
95  printf("%s%s%s\n", c(WHITE), description, c(RESET));
96 }
#define BLUE
Definition: amxrt_priv.h:89
#define WHITE
Definition: amxrt_priv.h:92
#define RESET
Definition: amxrt_priv.h:95
#define GREEN
Definition: amxrt_priv.h:90
#define c(x)
Definition: amxrt_priv.h:97

◆ amxrt_print_config_example()

static void amxrt_print_config_example ( void  )
static

Definition at line 114 of file amxrt_user_output.c.

114  {
115  printf("\n");
116  printf("%sExample config section:%s\n", c(CYAN), c(RESET));
117  printf("\n");
118  printf("%s%%config%s {\n", c(GREEN), c(RESET));
119  printf(" %suris%s = %s\"pcb:/var/run/pcb_sys,ubus:/var/run/ubus/ubus.sock\"%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
120  printf(" %sbackends%s = %s\"/usr/bin/mods/amxb/mod-amxb-pcb.so,/usr/bin/mods/amxb/mod-amxb-ubus.so\"%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
121  printf(" %sauto-detect%s = %strue%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
122  printf(" %sauto-connect%s = %strue%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
123  printf(" %sinclude-dirs%s = %s\".\"%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
124  printf(" %simport-dirs%s = %s\".\"%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
125  printf(" %sdaemon%s = %sfalse%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
126  printf(" %spriority%s = %s0%s;\n", c(BLUE), c(RESET), c(CYAN), c(RESET));
127  printf("}\n");
128 }
#define CYAN
Definition: amxrt_priv.h:93

◆ amxrt_print_configuration()

void amxrt_print_configuration ( void  )

Definition at line 166 of file amxrt_user_output.c.

166  {
167  amxrt_t* rt = amxrt_get();
168 
169  fprintf(stderr, "\n%sConfiguration:%s\n", c(GREEN), c(RESET));
170  fflush(stderr);
171  amxc_var_dump(&rt->parser.config, STDERR_FILENO);
172 }
static amxrt_t rt
Definition: amxrt.c:74
PRIVATE amxrt_t * amxrt_get(void)
Definition: amxrt.c:297
amxo_parser_t parser
Definition: amxrt_priv.h:101

◆ amxrt_print_error()

void amxrt_print_error ( const char *  fmt,
  ... 
)

Definition at line 174 of file amxrt_user_output.c.

174  {
175  amxc_var_t* config = amxrt_get_config();
176  va_list args;
177 
178  if(GET_BOOL(config, AMXRT_COPT_LOG)) {
179  va_start(args, fmt);
180  vsyslog(LOG_USER | LOG_ERR, fmt, args);
181  va_end(args);
182  } else {
183  fprintf(stderr, "%sERROR%s -- %s", c(RED), c(RESET), c(WHITE));
184 
185  va_start(args, fmt);
186  vfprintf(stderr, fmt, args);
187  va_end(args);
188 
189  fprintf(stderr, "%s\n", c(RESET));
190  }
191 }
#define AMXRT_COPT_LOG
Definition: amxrt.h:98
#define RED
Definition: amxrt_priv.h:91
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
Definition: amxrt.c:301
config
Definition: test.odl:54

◆ amxrt_print_failure()

void amxrt_print_failure ( amxo_parser_t *  parser,
const char *  string 
)

Definition at line 213 of file amxrt_user_output.c.

213  {
214  amxc_var_t* config = amxrt_get_config();
215  const char* msg = amxo_parser_get_message(parser);
216 
217  if(GET_BOOL(config, AMXRT_COPT_LOG)) {
218  syslog(LOG_USER | LOG_CRIT, "Failed parsing - %s", string == NULL ? "###" : string);
219  syslog(LOG_USER | LOG_CRIT, "Reason - %s", msg == NULL ? "###" : msg);
220  } else {
221  fprintf(stderr, "%sERROR%s -- Failed parsing %s%s%s\n",
222  c(RED), c(RESET),
223  c(CYAN), string == NULL ? "###" : string, c(RESET));
224 
225  fprintf(stderr, "%sREASON%s -- %s%s%s\n",
226  c(BLUE), c(RESET),
227  c(CYAN), msg == NULL ? "###" : msg, c(RESET));
228  }
229 }

◆ amxrt_print_help()

void amxrt_print_help ( void  )

Definition at line 160 of file amxrt_user_output.c.

160  {
164 }
static void amxrt_print_config_example(void)
static void amxrt_print_notes(void)
void amxrt_print_usage(void)
Prints the usage information and all available options to stdout.

◆ amxrt_print_message()

void amxrt_print_message ( const char *  fmt,
  ... 
)

Definition at line 193 of file amxrt_user_output.c.

193  {
194  amxc_var_t* config = amxrt_get_config();
195  va_list args;
196 
197  if(GET_BOOL(config, AMXRT_COPT_LOG)) {
198  va_start(args, fmt);
199  vsyslog(LOG_USER | LOG_NOTICE, "%s", args);
200  va_end(args);
201  } else {
202  fprintf(stderr, "%sINFO%s -- %s", c(YELLOW), c(RESET), c(WHITE));
203 
204  va_start(args, fmt);
205  vfprintf(stderr, fmt, args);
206  va_end(args);
207 
208  fprintf(stderr, "%s\n", c(RESET));
209  }
210 }
#define YELLOW
Definition: amxrt_priv.h:94

◆ amxrt_print_notes()

static void amxrt_print_notes ( void  )
static

Definition at line 98 of file amxrt_user_output.c.

98  {
99  printf("\n");
100  printf("%sNotes:%s\n", c(CYAN), c(RESET));
101  printf(" %s*%s Short and long options take the same arguments\n", c(YELLOW), c(RESET));
102  printf("\n");
103  printf(" %s*%s At least one odl file or odl string must be specified\n", c(YELLOW), c(RESET));
104  printf("\n");
105  printf(" %s*%s Each bus backend can only be specified once\n", c(YELLOW), c(RESET));
106  printf("\n");
107  printf(" %s*%s The process daemizes (-D) after the entry points are called, but before\n", c(YELLOW), c(RESET));
108  printf(" the data model is registered to the busses.\n");
109  printf("\n");
110  printf(" %s*%s All command line options can be put in the config section of one\n", c(YELLOW), c(RESET));
111  printf(" of the main odls.\n");
112 }

◆ get_color()

const char* get_color ( uint32_t  cc)

Definition at line 130 of file amxrt_user_output.c.

130  {
131  if(cc < RESET) {
132  return colors[cc];
133  }
134  return colors[RESET];
135 }
static const char * colors[]

Variable Documentation

◆ colors

const char* colors[]
static
Initial value:
= {
}
#define COLOR_BRIGHT_RED
Definition: amxrt_priv.h:79
#define COLOR_RESET
Definition: amxrt_priv.h:87
#define COLOR_BRIGHT_YELLOW
Definition: amxrt_priv.h:81
#define COLOR_BRIGHT_GREEN
Definition: amxrt_priv.h:80
#define COLOR_BRIGHT_WHITE
Definition: amxrt_priv.h:85
#define COLOR_BRIGHT_CYAN
Definition: amxrt_priv.h:84
#define COLOR_BRIGHT_BLUE
Definition: amxrt_priv.h:82

Definition at line 68 of file amxrt_user_output.c.