Skip to content

Commit

Permalink
Clean up some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParksProjets committed Oct 4, 2018
1 parent edaf817 commit 3823d20
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions c-lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
/doubly-linked-list
/malloc-scan
/vector
/special.*
/config.file
11 changes: 8 additions & 3 deletions c-lib/src/config/conf-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ This project is under the MIT License
// Is the parsing error reported?
_Bool _ctyconf_error_reported;

// Terminal colors.
#define TTY_RESET "\033[0m"
#define TTY_BOLD "\033[1m"
#define TTY_MAGENTA "\033[35m"



// Print the error position.
static void print_pos()
{
fprintf(stderr, "\n %s\n ", _ctyconf_line);
fprintf(stderr, TTY_MAGENTA "\n %s\n ", _ctyconf_line);

char *p = _ctyconf_line;
for (; p < _ctyconf_lastp; p++)
Expand All @@ -49,13 +54,13 @@ void _ctyconf_error(const char *msg, ...)
va_list argp;
va_start(argp, msg);

fprintf(stderr, " line %d: ", _ctyconf_lineno);
fprintf(stderr, TTY_BOLD " line %d: " TTY_RESET, _ctyconf_lineno);
vfprintf(stderr, msg, argp);

if (_ctyconf_lastp < _ctyconf_linep)
print_pos();

fprintf(stderr, "\n\n");
fprintf(stderr, TTY_RESET "\n\n");
va_end(argp);

longjmp(_ctyconf_jmp, 1);
Expand Down
8 changes: 4 additions & 4 deletions c-lib/src/config/conf-lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ static void parse_string()
pos++;

if (*pos != '"')
_ctyconf_error("Unexpected end of string");
_ctyconf_error("unexpected end of string");
if (pos - start >= 50)
_ctyconf_error("String to long (more than 50 chars)");
_ctyconf_error("string to long (more than 50 chars)");

strncpy(_ctyconf_string, start, pos - start);
_ctyconf_string[pos - start] = '\0';
Expand Down Expand Up @@ -81,7 +81,7 @@ static enum _Cty_ConfTokens parse_word()
}

if (pos - start >= 40)
_ctyconf_error("Word to long (more than 40 chars)");
_ctyconf_error("word to long (more than 40 chars)");

strncpy(_ctyconf_word, start, pos - start);
_ctyconf_word[pos - start] = '\0';
Expand Down Expand Up @@ -111,5 +111,5 @@ enum _Cty_ConfTokens _ctyconf_next()
if (isalpha(*last))
return parse_word();

_ctyconf_error("Unexpected character '%c'", *last);
_ctyconf_error("unexpected character '%c'", *last);
}
21 changes: 10 additions & 11 deletions c-lib/src/errors/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,15 @@ const char *_ctycat_error_text(int error)



// Error colors
#define _CTYCOL_RESET "\033[0m"
#define _CTYCOL_BOLD "\033[1m"
#define _CTYCOL_BOLDMAGENTA _CTYCOL_BOLD "\033[35m\033[95m"
#define _CTYCOL_BOLDRED _CTYCOL_BOLD "\033[31m\033[91m"
#define _CTYCOL_RED _CTYCOL_RESET "\033[31m"
// Terminal colors.
#define TTY_RESET "\033[0m"
#define TTY_BOLD "\033[1m"
#define TTY_RED "\033[31m"
#define TTY_MAGENTA "\033[35m"

// Print and format an error
#define _ctycat_errf(msg, ...) fprintf(stderr, _CTYCOL_BOLDMAGENTA "!! " \
_CTYCOL_RESET msg _CTYCOL_RESET "\n", ## __VA_ARGS__)
// Print and format an error.
#define _ctycat_errf(msg, ...) fprintf(stderr, TTY_BOLD TTY_MAGENTA "!! " \
TTY_RESET msg TTY_RESET "\n", ## __VA_ARGS__)


// Report an error
Expand All @@ -83,8 +82,8 @@ int _ctycat_report_error(int error)
const char *strz = _ctycat_error_text(error);

fprintf(stderr, "\n");
_ctycat_errf(_CTYCOL_BOLDRED "ctycat: an error has occurred");
_ctycat_errf(_CTYCOL_RED " [" _CTYCOL_BOLD "%d" _CTYCOL_RED "] %s\n",
_ctycat_errf(TTY_BOLD TTY_RED "ctycat: an error has occurred" TTY_RESET);
_ctycat_errf(TTY_RED " [" TTY_BOLD "%d" TTY_RESET TTY_RED "] %s\n",
error & 0xFFFF, strz);

return _CTY_FATAL_ERROR;
Expand Down
1 change: 0 additions & 1 deletion c-lib/tests/special/typedef.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ int main()

c.c = 'A';


ctycat(a);
}
2 changes: 2 additions & 0 deletions gdb-c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore example objects
/examples/tree

0 comments on commit 3823d20

Please sign in to comment.