wcalc  2.5
About: Wcalc is a natural-expression command-line calculator.
  Fossies Dox: wcalc-2.5.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

main.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/mman.h>
#include <assert.h>
#include <stdarg.h>
#include "number.h"
#include "calculator.h"
#include "conversion.h"
#include "y.tab.h"
#include "variables.h"
#include "files.h"
#include "historyManager.h"
#include "list.h"
#include "iscmd.h"
#include "isconst.h"
#include "isfunc.h"
#include "output.h"
#include "evalvar.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define TRUEFALSE   (!strcmp(value, "yes") || !strcmp(value, "true") || !strcmp(value, "1"))
 
#define BIG_STRING   4096
 
#define VERSION   PACKAGE_VERSION
 
#define EXIT_EARLY(code)
 
#define CHECK_COLOR(x)   else if (!strcasecmp(str, # x)) { return x; }
 
#define HANDLECOLOR(x)   else if (!strcasecmp(key, # x "]")) { uiselect[x] = str2color(value); }
 
#define DP_YESNO(x)   ((x) ? "yes" : "no")
 

Enumerations

enum  ui_colors {
  NONE, RESET, BLACK, RED,
  GREEN, YELLOW, BLUE, MAGENTA,
  CYAN, WHITE, BOLDBLACK, BOLDRED,
  BOLDGREEN, BOLDYELLOW, BOLDBLUE, BOLDMAGENTA,
  BOLDCYAN, BOLDWHITE
}
 
enum  ui_pieces {
  PROMPT, CONV_CAT, CONV_UNIT, APPROX_ANSWER,
  EXACT_ANSWER, ERR_LOCATION, ERR_TEXT, PREF_NAME,
  PREF_VAL, PREF_CMD, STATUS, VAR_NAME,
  VAR_DESC, SUBVAR_NAME, EXPLANATION, UNCOLOR
}
 

Functions

static int read_prefs (void)
 
static int read_preload (void)
 
static void display_and_clear_errstring (void)
 
int yyparse (void)
 
int yy_scan_string (const char *)
 
static void PrintConversionUnitCategory (int nCategory)
 
void show_answer (char *err, int uncertain, char *answer)
 
int main (int argc, char *argv[])
 
static enum ui_colors str2color (const char *str)
 
static int assign_color_prefs (const char *key, const char *value)
 
static int set_pref (const char *key, const char *value)
 
static void config_error (const char *format,...)
 
static size_t copy_string (char *d, const char *s, size_t dmax, size_t smax)
 
static void prefline (const char *name, const char *val, const char *cmd)
 
void display_prefs (void)
 
void display_status (const char *format,...)
 
void display_output_format (int format)
 
void display_val (const char *name)
 
void display_var (variable_t *v, unsigned count, unsigned digits)
 
void display_expvar_explanation (const char *str, const char *exp, List subvars, const char *desc)
 
void display_valvar_explanation (const char *str, Number *val, const char *desc)
 
void display_explanation (const char *exp,...)
 
void display_stateline (const char *buf)
 
void display_consts (void)
 

Variables

static int exit_on_err = 0
 
const char *const colors []
 
int black_and_white_ui []
 
int color_ui []
 
int * uiselect = black_and_white_ui
 

Macro Definition Documentation

◆ BIG_STRING

#define BIG_STRING   4096

Definition at line 71 of file main.c.

◆ CHECK_COLOR

#define CHECK_COLOR (   x)    else if (!strcasecmp(str, # x)) { return x; }

Definition at line 1126 of file main.c.

◆ DP_YESNO

#define DP_YESNO (   x)    ((x) ? "yes" : "no")

Definition at line 1465 of file main.c.

◆ EXIT_EARLY

#define EXIT_EARLY (   code)
Value:
do { \
clearHistory(); \
cleanupvar(); \
num_free(last_answer); \
lists_cleanup(); \
fflush(NULL); \
exit(code); \
} while (0)

Definition at line 73 of file main.c.

◆ HANDLECOLOR

#define HANDLECOLOR (   x)    else if (!strcasecmp(key, # x "]")) { uiselect[x] = str2color(value); }

Definition at line 1156 of file main.c.

◆ TRUEFALSE

#define TRUEFALSE   (!strcmp(value, "yes") || !strcmp(value, "true") || !strcmp(value, "1"))

Definition at line 70 of file main.c.

◆ VERSION

#define VERSION   PACKAGE_VERSION

Definition at line 72 of file main.c.

Enumeration Type Documentation

◆ ui_colors

enum ui_colors
Enumerator
NONE 
RESET 
BLACK 
RED 
GREEN 
YELLOW 
BLUE 
MAGENTA 
CYAN 
WHITE 
BOLDBLACK 
BOLDRED 
BOLDGREEN 
BOLDYELLOW 
BOLDBLUE 
BOLDMAGENTA 
BOLDCYAN 
BOLDWHITE 

Definition at line 354 of file main.c.

◆ ui_pieces

enum ui_pieces
Enumerator
PROMPT 
CONV_CAT 
CONV_UNIT 
APPROX_ANSWER 
EXACT_ANSWER 
ERR_LOCATION 
ERR_TEXT 
PREF_NAME 
PREF_VAL 
PREF_CMD 
STATUS 
VAR_NAME 
VAR_DESC 
SUBVAR_NAME 
EXPLANATION 
UNCOLOR 

Definition at line 395 of file main.c.

Function Documentation

◆ assign_color_prefs()

static int assign_color_prefs ( const char *  key,
const char *  value 
)
static

◆ config_error()

static void config_error ( const char *  format,
  ... 
)
static

Definition at line 1285 of file main.c.

Referenced by read_prefs().

◆ copy_string()

static size_t copy_string ( char *  d,
const char *  s,
size_t  dmax,
size_t  smax 
)
static

Definition at line 1297 of file main.c.

Referenced by read_prefs().

◆ display_and_clear_errstring()

static void display_and_clear_errstring ( void  )
static

◆ display_consts()

void display_consts ( void  )

Definition at line 1665 of file main.c.

References consts, name_with_exp::explanation, and name_with_exp::names.

Referenced by explain().

◆ display_explanation()

void display_explanation ( const char *  exp,
  ... 
)

Definition at line 1644 of file main.c.

References colors, EXPLANATION, standard_output, uiselect, and UNCOLOR.

Referenced by explain(), explain_command(), and scan_exps().

◆ display_expvar_explanation()

void display_expvar_explanation ( const char *  str,
const char *  exp,
List  subvars,
const char *  desc 
)

◆ display_output_format()

void display_output_format ( int  format)

Definition at line 1518 of file main.c.

References BINARY_FORMAT, DECIMAL_FORMAT, display_status(), HEXADECIMAL_FORMAT, OCTAL_FORMAT, and standard_output.

Referenced by yyparse().

◆ display_prefs()

◆ display_stateline()

void display_stateline ( const char *  buf)

Definition at line 1659 of file main.c.

Referenced by loadStateFD().

◆ display_status()

void display_status ( const char *  format,
  ... 
)

Definition at line 1503 of file main.c.

References colors, standard_output, STATUS, uiselect, and UNCOLOR.

Referenced by display_output_format(), and yyparse().

◆ display_val()

void display_val ( const char *  name)

◆ display_valvar_explanation()

void display_valvar_explanation ( const char *  str,
Number val,
const char *  desc 
)

Definition at line 1631 of file main.c.

References colors, print_this_result(), uiselect, UNCOLOR, VAR_DESC, and VAR_NAME.

Referenced by explain_variable().

◆ display_var()

void display_var ( variable_t v,
unsigned  count,
unsigned  digits 
)

◆ main()

◆ prefline()

static void prefline ( const char *  name,
const char *  val,
const char *  cmd 
)
static

Definition at line 1436 of file main.c.

References colors, PREF_CMD, PREF_NAME, PREF_VAL, strchr, uiselect, and UNCOLOR.

Referenced by display_prefs().

◆ PrintConversionUnitCategory()

static void PrintConversionUnitCategory ( int  nCategory)
static

Definition at line 452 of file main.c.

References conversion::aka, colors, CONV_CAT, CONV_UNIT, conversion_names, conversions, conversion::name, uiselect, and UNCOLOR.

Referenced by main().

◆ read_prefs()

static int read_prefs ( void  )
static

Definition at line 1328 of file main.c.

References BIG_STRING, config_error(), copy_string(), openDotFile(), and set_pref().

Referenced by main().

◆ read_preload()

static int read_preload ( void  )
static

Definition at line 1096 of file main.c.

References loadStateFD(), and openDotFile().

Referenced by main().

◆ set_pref()

◆ show_answer()

void show_answer ( char *  err,
int  uncertain,
char *  answer 
)

◆ str2color()

static enum ui_colors str2color ( const char *  str)
static

◆ yy_scan_string()

int yy_scan_string ( const char *  )

◆ yyparse()

int yyparse ( void  )

Definition at line 1563 of file parser.c.

Variable Documentation

◆ black_and_white_ui

int black_and_white_ui[]
Initial value:

Definition at line 413 of file main.c.

Referenced by main(), and set_pref().

◆ color_ui

int color_ui[]
Initial value:

Definition at line 431 of file main.c.

Referenced by assign_color_prefs(), main(), and set_pref().

◆ colors

const char* const colors[]
Initial value:
= {
"",
"\033[0m",
"\033[30m",
"\033[31m",
"\033[32m",
"\033[33m",
"\033[34m",
"\033[35m",
"\033[36m",
"\033[37m",
"\033[1m\033[30m",
"\033[1m\033[31m",
"\033[1m\033[32m",
"\033[1m\033[33m",
"\033[1m\033[34m",
"\033[1m\033[35m",
"\033[1m\033[36m",
"\033[1m\033[37m",
}

Definition at line 374 of file main.c.

Referenced by display_and_clear_errstring(), display_explanation(), display_expvar_explanation(), display_status(), display_val(), display_valvar_explanation(), display_var(), main(), prefline(), PrintConversionUnitCategory(), and show_answer().

◆ exit_on_err

int exit_on_err = 0
static

Definition at line 95 of file main.c.

Referenced by display_and_clear_errstring(), and main().

◆ uiselect

GREEN
Definition: main.c:359
BOLDMAGENTA
Definition: main.c:370
BLUE
Definition: main.c:361
BOLDYELLOW
Definition: main.c:368
last_answer
Number last_answer
Definition: calculator.c:98
CYAN
Definition: main.c:363
RESET
Definition: main.c:356
BOLDRED
Definition: main.c:366
BOLDGREEN
Definition: main.c:367
NONE
Definition: main.c:355
YELLOW
Definition: main.c:360
BOLDCYAN
Definition: main.c:371