mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-04 22:11:07 +01:00
Migrate preprocessor-based debug statements to our logging module
This commit is contained in:
parent
083fc37b12
commit
17013e60e7
5
.vscode/c_cpp_properties.json
vendored
5
.vscode/c_cpp_properties.json
vendored
@ -12,11 +12,6 @@
|
|||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
"DEBUG",
|
|
||||||
"REGEXP_DEBUG",
|
|
||||||
"PARSER_DEBUG",
|
|
||||||
"LEXER_DEBUG",
|
|
||||||
"DISCOVERY_DEBUG",
|
|
||||||
"UNICODE",
|
"UNICODE",
|
||||||
"_UNICODE"
|
"_UNICODE"
|
||||||
],
|
],
|
||||||
|
30
src/Makefile
30
src/Makefile
@ -107,24 +107,24 @@ parser.c parser.h: parser.y lex.yy.h | check_dir
|
|||||||
lex.yy.c lex.yy.h: lexer.l | check_dir
|
lex.yy.c lex.yy.h: lexer.l | check_dir
|
||||||
$(LEX) --header-file=lex.yy.h $<
|
$(LEX) --header-file=lex.yy.h $<
|
||||||
|
|
||||||
boxes.o: boxes.c boxes.h cmdline.h discovery.h generate.h input.h list.h parsing.h query.h remove.h shape.h tools.h unicode.h config.h | check_dir
|
boxes.o: boxes.c boxes.h cmdline.h discovery.h generate.h input.h list.h logging.h parsing.h query.h remove.h shape.h tools.h unicode.h config.h | check_dir
|
||||||
bxstring.o: bxstring.c bxstring.h tools.h unicode.h config.h | check_dir
|
bxstring.o: bxstring.c bxstring.h tools.h unicode.h config.h | check_dir
|
||||||
cmdline.o: cmdline.c cmdline.h boxes.h discovery.h query.h tools.h config.h | check_dir
|
cmdline.o: cmdline.c cmdline.h boxes.h discovery.h logging.h query.h tools.h config.h | check_dir
|
||||||
detect.o: detect.c detect.h boxes.h bxstring.h shape.h tools.h config.h | check_dir
|
detect.o: detect.c detect.h boxes.h bxstring.h logging.h shape.h tools.h config.h | check_dir
|
||||||
discovery.o: discovery.c discovery.h boxes.h tools.h unicode.h config.h | check_dir
|
discovery.o: discovery.c discovery.h boxes.h logging.h tools.h unicode.h config.h | check_dir
|
||||||
generate.o: generate.c generate.h boxes.h shape.h tools.h unicode.h config.h | check_dir
|
generate.o: generate.c generate.h boxes.h logging.h shape.h tools.h unicode.h config.h | check_dir
|
||||||
input.o: input.c boxes.h input.h regulex.h tools.h unicode.h config.h | check_dir
|
input.o: input.c boxes.h input.h logging.h regulex.h tools.h unicode.h config.h | check_dir
|
||||||
lex.yy.o: lex.yy.c parser.h boxes.h parsing.h tools.h shape.h unicode.h config.h | check_dir
|
lex.yy.o: lex.yy.c parser.h boxes.h logging.h parsing.h tools.h shape.h unicode.h config.h | check_dir
|
||||||
list.o: list.c list.h boxes.h bxstring.h parsing.h query.h shape.h tools.h unicode.h config.h | check_dir
|
list.o: list.c list.h boxes.h bxstring.h parsing.h query.h shape.h tools.h unicode.h config.h | check_dir
|
||||||
logging.o: logging.c logging.h tools.h config.h | check_dir
|
logging.o: logging.c logging.h tools.h config.h | check_dir
|
||||||
parsecode.o: parsecode.c parsecode.h discovery.h lex.yy.h parsing.h parser.h query.h regulex.h shape.h tools.h unicode.h config.h | check_dir
|
parsecode.o: parsecode.c parsecode.h discovery.h lex.yy.h logging.h parsing.h parser.h query.h regulex.h shape.h tools.h unicode.h config.h | check_dir
|
||||||
parser.o: parser.c boxes.h bxstring.h lex.yy.h parsecode.h parser.h parsing.h shape.h tools.h unicode.h config.h | check_dir
|
parser.o: parser.c boxes.h bxstring.h lex.yy.h logging.h parsecode.h parser.h parsing.h shape.h tools.h unicode.h config.h | check_dir
|
||||||
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h tools.h config.h | check_dir
|
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h logging.h tools.h config.h | check_dir
|
||||||
query.o: query.c query.h boxes.h list.h tools.h config.h | check_dir
|
query.o: query.c query.h boxes.h list.h logging.h tools.h config.h | check_dir
|
||||||
regulex.o: regulex.c regulex.h boxes.h tools.h unicode.h config.h | check_dir
|
regulex.o: regulex.c regulex.h boxes.h logging.h tools.h unicode.h config.h | check_dir
|
||||||
remove.o: remove.c remove.h boxes.h detect.h shape.h tools.h unicode.h config.h | check_dir
|
remove.o: remove.c remove.h boxes.h detect.h logging.h shape.h tools.h unicode.h config.h | check_dir
|
||||||
shape.o: shape.c shape.h boxes.h bxstring.h tools.h config.h | check_dir
|
shape.o: shape.c shape.h boxes.h bxstring.h logging.h tools.h config.h | check_dir
|
||||||
tools.o: tools.c tools.h boxes.h regulex.h shape.h unicode.h config.h | check_dir
|
tools.o: tools.c tools.h boxes.h logging.h regulex.h shape.h unicode.h config.h | check_dir
|
||||||
unicode.o: unicode.c unicode.h boxes.h tools.h config.h | check_dir
|
unicode.o: unicode.c unicode.h boxes.h tools.h config.h | check_dir
|
||||||
|
|
||||||
|
|
||||||
|
50
src/boxes.c
50
src/boxes.c
@ -35,6 +35,7 @@
|
|||||||
#include "generate.h"
|
#include "generate.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "remove.h"
|
#include "remove.h"
|
||||||
@ -156,7 +157,7 @@ static int build_design(design_t **adesigns, const char *cld)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||||
return 1; /* never happens ;-) */
|
return 1;
|
||||||
}
|
}
|
||||||
c->name = i;
|
c->name = i;
|
||||||
|
|
||||||
@ -180,9 +181,8 @@ static int build_design(design_t **adesigns, const char *cld)
|
|||||||
*/
|
*/
|
||||||
static void handle_command_line(int argc, char *argv[])
|
static void handle_command_line(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Processing Command Line ...\n");
|
||||||
fprintf (stderr, "Processing Command Line ...\n");
|
|
||||||
#endif
|
|
||||||
opt_t *parsed_opts = process_commandline(argc, argv);
|
opt_t *parsed_opts = process_commandline(argc, argv);
|
||||||
if (parsed_opts == NULL) {
|
if (parsed_opts == NULL) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -269,9 +269,8 @@ static void apply_expected_size()
|
|||||||
*/
|
*/
|
||||||
static void handle_input()
|
static void handle_input()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Reading all input ...\n");
|
||||||
fprintf (stderr, "Reading all input ...\n");
|
|
||||||
#endif
|
|
||||||
input_t *raw_input = NULL;
|
input_t *raw_input = NULL;
|
||||||
if (opt.mend != 0) {
|
if (opt.mend != 0) {
|
||||||
raw_input = read_all_input();
|
raw_input = read_all_input();
|
||||||
@ -287,10 +286,10 @@ static void handle_input()
|
|||||||
BFREE(raw_input);
|
BFREE(raw_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, "Effective encoding: %s\n", encoding);
|
log_debug(__FILE__, MAIN, "Effective encoding: %s\n", encoding);
|
||||||
print_input_lines(NULL);
|
print_input_lines(NULL);
|
||||||
#endif
|
}
|
||||||
if (input.num_lines == 0) {
|
if (input.num_lines == 0) {
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -362,9 +361,8 @@ static void adjust_size_and_padding()
|
|||||||
*/
|
*/
|
||||||
static void handle_generate_box()
|
static void handle_generate_box()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Generating Box ...\n");
|
||||||
fprintf (stderr, "Generating Box ...\n");
|
|
||||||
#endif
|
|
||||||
sentry_t *thebox = (sentry_t *) calloc(NUM_SIDES, sizeof(sentry_t));
|
sentry_t *thebox = (sentry_t *) calloc(NUM_SIDES, sizeof(sentry_t));
|
||||||
if (thebox == NULL) {
|
if (thebox == NULL) {
|
||||||
perror(PROJECT);
|
perror(PROJECT);
|
||||||
@ -384,9 +382,8 @@ static void handle_generate_box()
|
|||||||
*/
|
*/
|
||||||
static void handle_remove_box()
|
static void handle_remove_box()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Removing Box ...\n");
|
||||||
fprintf (stderr, "Removing Box ...\n");
|
|
||||||
#endif
|
|
||||||
if (opt.killblank == -1) {
|
if (opt.killblank == -1) {
|
||||||
if (empty_side(opt.design->shape, BTOP) && empty_side(opt.design->shape, BBOT)) {
|
if (empty_side(opt.design->shape, BTOP) && empty_side(opt.design->shape, BBOT)) {
|
||||||
opt.killblank = 0;
|
opt.killblank = 0;
|
||||||
@ -425,15 +422,16 @@ static int terminal_has_colors()
|
|||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(DEBUG)
|
|
||||||
|
if (is_debug_logging(MAIN)) {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
int num_colors = 1;
|
int num_colors = 1;
|
||||||
#else
|
#else
|
||||||
int num_colors = result ? tigetnum("colors") : 0;
|
int num_colors = result ? tigetnum("colors") : 0;
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr, "Terminal \"%s\" %s colors (number of colors = %d).\n", termtype != NULL ? termtype : "(null)",
|
log_debug(__FILE__, MAIN, "Terminal \"%s\" %s colors (number of colors = %d).\n",
|
||||||
result ? "has" : "does NOT have", num_colors);
|
termtype != NULL ? termtype : "(null)", result ? "has" : "does NOT have", num_colors);
|
||||||
#endif
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,9 +447,7 @@ static int check_color_support(int opt_color)
|
|||||||
result = terminal_has_colors();
|
result = terminal_has_colors();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG)
|
log_debug(__FILE__, MAIN, "Color support %sabled\n", result ? "\x1b[92mEN\x1b[0m" : "DIS");
|
||||||
fprintf(stderr, "%s: Color support %sabled\n", PROJECT, result ? "\x1b[92mEN\x1b[0m" : "DIS");
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,9 +481,7 @@ int main(int argc, char *argv[])
|
|||||||
int saved_designwidth; /* opt.design->minwith backup, used for mending */
|
int saved_designwidth; /* opt.design->minwith backup, used for mending */
|
||||||
int saved_designheight; /* opt.design->minheight backup, used for mending */
|
int saved_designheight; /* opt.design->minheight backup, used for mending */
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "BOXES STARTING ...\n"); /* TODO This line will never execute, because debug not on yet */
|
||||||
fprintf (stderr, "BOXES STARTING ...\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Temporarily set the system encoding, for proper output of --help text etc. */
|
/* Temporarily set the system encoding, for proper output of --help text etc. */
|
||||||
activateSystemEncoding();
|
activateSystemEncoding();
|
||||||
@ -497,9 +491,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Store system character encoding */
|
/* Store system character encoding */
|
||||||
encoding = check_encoding(opt.encoding, locale_charset());
|
encoding = check_encoding(opt.encoding, locale_charset());
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Character Encoding = %s\n", encoding);
|
||||||
fprintf (stderr, "Character Encoding = %s\n", encoding);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
color_output_enabled = check_color_support(opt.color);
|
color_output_enabled = check_color_support(opt.color);
|
||||||
|
|
||||||
|
@ -20,12 +20,6 @@
|
|||||||
#ifndef BOXES_H
|
#ifndef BOXES_H
|
||||||
#define BOXES_H
|
#define BOXES_H
|
||||||
|
|
||||||
/* #define DEBUG 1 */
|
|
||||||
/* #define REGEXP_DEBUG 1 */
|
|
||||||
/* #define PARSER_DEBUG 1 */
|
|
||||||
/* #define LEXER_DEBUG 1 */
|
|
||||||
/* #define DISCOVERY_DEBUG 1 */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unitypes.h>
|
#include <unitypes.h>
|
||||||
|
|
||||||
|
@ -731,14 +731,13 @@ static void print_debug_info(opt_t *result)
|
|||||||
|
|
||||||
opt_t *process_commandline(int argc, char *argv[])
|
opt_t *process_commandline(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, "argc = %d\n", argc);
|
log_debug(__FILE__, MAIN, "argc = %d\n", argc);
|
||||||
fprintf(stderr, "argv = [");
|
log_debug(__FILE__, MAIN, "argv = [");
|
||||||
for(int i=0; i<=argc; i++) {
|
for(int i=0; i<=argc; i++) {
|
||||||
fprintf(stderr, "%s%s", argv[i], i < argc ? ", " : "");
|
log_debug_cont(MAIN, "%s%s", argv[i], i < argc ? ", " : "]\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
opt_t *result = create_new_opt();
|
opt_t *result = create_new_opt();
|
||||||
|
|
||||||
|
84
src/detect.c
84
src/detect.c
@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
#include "bxstring.h"
|
#include "bxstring.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
@ -67,9 +68,7 @@ int input_is_mono()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Input is %s\n", result ? "mono" : "potentially colored");
|
||||||
fprintf(stderr, "Input is %s\n", result ? "mono" : "potentially colored");
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,16 +83,12 @@ int design_is_mono(design_t *design)
|
|||||||
for (size_t line_no = 0; line_no < design->shape[scnt].height; line_no++) {
|
for (size_t line_no = 0; line_no < design->shape[scnt].height; line_no++) {
|
||||||
bxstr_t *shape_line = design->shape[scnt].mbcs[line_no];
|
bxstr_t *shape_line = design->shape[scnt].mbcs[line_no];
|
||||||
if (shape_line->num_chars_invisible > 0) {
|
if (shape_line->num_chars_invisible > 0) {
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Design is potentially colored\n");
|
||||||
fprintf(stderr, "Design is potentially colored\n");
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Design is mono\n");
|
||||||
fprintf(stderr, "Design is mono\n");
|
|
||||||
#endif
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +116,8 @@ static int *determine_empty_sides(design_t *current_design)
|
|||||||
for (size_t j = 0; j < NUM_SIDES; ++j) {
|
for (size_t j = 0; j < NUM_SIDES; ++j) {
|
||||||
result[j] = empty_side(current_design->shape, j);
|
result[j] = empty_side(current_design->shape, j);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
|
||||||
fprintf (stderr, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
|
|
||||||
result[BTOP], result[BLEF], result[BBOT], result[BRIG]);
|
result[BTOP], result[BLEF], result[BBOT], result[BRIG]);
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,16 +178,13 @@ uint32_t *prepare_comp_shape(
|
|||||||
uint32_t *prepare_comp_input(size_t input_line_idx, int trim_left, comparison_t comp_type, size_t offset_right,
|
uint32_t *prepare_comp_input(size_t input_line_idx, int trim_left, comparison_t comp_type, size_t offset_right,
|
||||||
size_t *out_indent, size_t *out_trailing)
|
size_t *out_indent, size_t *out_trailing)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "prepare_comp_input(%d, %s, %s, %d, %p, %p)", (int) input_line_idx,
|
||||||
fprintf(stderr, "prepare_comp_input(%d, %s, %s, %d, %p, %p)", (int) input_line_idx,
|
|
||||||
trim_left ? "true" : "false", comparison_name[comp_type], (int) offset_right, out_indent, out_trailing);
|
trim_left ? "true" : "false", comparison_name[comp_type], (int) offset_right, out_indent, out_trailing);
|
||||||
#endif
|
|
||||||
if (input_line_idx >= input.num_lines) {
|
if (input_line_idx >= input.num_lines) {
|
||||||
bx_fprintf(stderr, "%s: prepare_comp_input(%d, %d, %s, %d): Index out of bounds\n", PROJECT,
|
bx_fprintf(stderr, "%s: prepare_comp_input(%d, %d, %s, %d): Index out of bounds\n", PROJECT,
|
||||||
(int) input_line_idx, trim_left, comparison_name[comp_type], (int) offset_right);
|
(int) input_line_idx, trim_left, comparison_name[comp_type], (int) offset_right);
|
||||||
#ifdef DEBUG
|
log_debug_cont(MAIN, " -> (null)\n");
|
||||||
fprintf(stderr, " -> (null)\n");
|
|
||||||
#endif
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bxstr_t *input_line = input.lines[input_line_idx].text;
|
bxstr_t *input_line = input.lines[input_line_idx].text;
|
||||||
@ -244,11 +234,12 @@ uint32_t *prepare_comp_input(size_t input_line_idx, int trim_left, comparison_t
|
|||||||
- input_line->first_char[input_line->num_chars_visible - input_line->trailing];
|
- input_line->first_char[input_line->num_chars_visible - input_line->trailing];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
|
||||||
|
if (is_debug_logging(MAIN)) {
|
||||||
char *out_result = u32_strconv_to_output(result);
|
char *out_result = u32_strconv_to_output(result);
|
||||||
fprintf(stderr, " -> \"%s\"\n", out_result);
|
log_debug_cont(MAIN, " -> \"%s\"\n", out_result);
|
||||||
BFREE(out_result);
|
BFREE(out_result);
|
||||||
#endif
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,9 +287,7 @@ static size_t find_west_corner(design_t *current_design, comparison_t comp_type,
|
|||||||
BFREE(shape_relevant);
|
BFREE(shape_relevant);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||||
fprintf(stderr, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,9 +306,7 @@ static size_t find_east_corner(design_t *current_design, comparison_t comp_type,
|
|||||||
{
|
{
|
||||||
size_t hits = 0;
|
size_t hits = 0;
|
||||||
if (empty[BRIG] || (empty[BTOP] && corner == NE) || (empty[BBOT] && corner == SE)) {
|
if (empty[BRIG] || (empty[BTOP] && corner == NE) || (empty[BBOT] && corner == SE)) {
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||||
fprintf(stderr, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,9 +336,7 @@ static size_t find_east_corner(design_t *current_design, comparison_t comp_type,
|
|||||||
BFREE(shape_relevant);
|
BFREE(shape_relevant);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||||
fprintf(stderr, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,9 +356,7 @@ static size_t find_horizontal_shape(design_t *current_design, comparison_t comp_
|
|||||||
size_t hits = 0;
|
size_t hits = 0;
|
||||||
if (empty[BTOP] || empty[BBOT]) {
|
if (empty[BTOP] || empty[BBOT]) {
|
||||||
/* horizontal box part is empty */
|
/* horizontal box part is empty */
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
||||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,9 +400,7 @@ static size_t find_horizontal_shape(design_t *current_design, comparison_t comp_
|
|||||||
BFREE(shape_relevant);
|
BFREE(shape_relevant);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
||||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,9 +449,7 @@ static size_t find_vertical_west(design_t *current_design, comparison_t comp_typ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
||||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,9 +497,7 @@ static size_t find_vertical_east(design_t *current_design, comparison_t comp_typ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
||||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
|
||||||
#endif
|
|
||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,21 +558,16 @@ design_t *autodetect_design()
|
|||||||
for (size_t dcnt = 0; ((int) dcnt) < num_designs; ++dcnt, ++current_design) {
|
for (size_t dcnt = 0; ((int) dcnt) < num_designs; ++dcnt, ++current_design) {
|
||||||
int mono_design = design_is_mono(current_design);
|
int mono_design = design_is_mono(current_design);
|
||||||
if (!comp_type_is_viable(comp_type, mono_input, mono_design)) {
|
if (!comp_type_is_viable(comp_type, mono_input, mono_design)) {
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Design \"%s\" skipped for comparison type '%s' because mono_input=%d and "
|
||||||
fprintf(stderr, "Design \"%s\" skipped for comparison type '%s' because mono_input=%d and "
|
|
||||||
"mono_design=%d\n", current_design->name, comparison_name[comp_type], mono_input, mono_design);
|
"mono_design=%d\n", current_design->name, comparison_name[comp_type], mono_input, mono_design);
|
||||||
#endif
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "CONSIDERING DESIGN ---- \"%s\" ---------------\n", current_design->name);
|
||||||
fprintf(stderr, "CONSIDERING DESIGN ---- \"%s\" ---------------\n", current_design->name);
|
log_debug(__FILE__, MAIN, " comparison_type = %s\n", comparison_name[comp_type]);
|
||||||
fprintf(stderr, " comparison_type = %s\n", comparison_name[comp_type]);
|
|
||||||
#endif
|
|
||||||
long hits = match_design(current_design, comp_type);
|
long hits = match_design(current_design, comp_type);
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Design \"%s\" scored %ld points\n", current_design->name, hits);
|
||||||
fprintf(stderr, "Design \"%s\" scored %ld points\n", current_design->name, hits);
|
|
||||||
#endif
|
|
||||||
if (hits > maxhits) {
|
if (hits > maxhits) {
|
||||||
maxhits = hits;
|
maxhits = hits;
|
||||||
result = current_design;
|
result = current_design;
|
||||||
@ -606,14 +578,14 @@ design_t *autodetect_design()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "CHOOSING \"%s\" design (%ld hits).\n", result->name, maxhits);
|
log_debug(__FILE__, MAIN, "CHOOSING \"%s\" design (%ld hits).\n", result->name, maxhits);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "NO DESIGN FOUND WITH EVEN ONE HIT POINT!\n");
|
log_debug(__FILE__, MAIN, "NO DESIGN FOUND WITH EVEN ONE HIT POINT!\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "discovery.h"
|
#include "discovery.h"
|
||||||
@ -40,49 +41,38 @@
|
|||||||
|
|
||||||
static int can_read_file(char *filename_utf8)
|
static int can_read_file(char *filename_utf8)
|
||||||
{
|
{
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_file(%s) - enter\n", filename_utf8);
|
||||||
fprintf(stderr, "can_read_file(%s) - enter\n", filename_utf8);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
if (filename_utf8 == NULL || filename_utf8[0] == '\0') {
|
if (filename_utf8 == NULL || filename_utf8[0] == '\0') {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_file(): argument was NULL\n");
|
||||||
fprintf(stderr, "%s: can_read_file(): argument was NULL\n", PROJECT);
|
|
||||||
#endif
|
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FILE *f = bx_fopen(filename_utf8, "r");
|
FILE *f = bx_fopen(filename_utf8, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_file(): File \"%s\" could not be opened for reading - %s\n",
|
||||||
fprintf(stderr, "%s: can_read_file(): File \"%s\" could not be opened for reading - %s\n",
|
filename_utf8, strerror(errno));
|
||||||
PROJECT, filename_utf8, strerror(errno));
|
|
||||||
#endif
|
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (stat(filename_utf8, &statbuf) != 0) {
|
if (stat(filename_utf8, &statbuf) != 0) {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_file(): File \"%s\" not statable - %s\n",
|
||||||
fprintf(stderr, "%s: can_read_file(): File \"%s\" not statable - %s\n",
|
filename_utf8, strerror(errno));
|
||||||
PROJECT, filename_utf8, strerror(errno));
|
|
||||||
#endif
|
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else if (S_ISDIR(statbuf.st_mode)) {
|
else if (S_ISDIR(statbuf.st_mode)) {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_file(): File \"%s\" is in fact a directory\n",
|
||||||
fprintf(stderr, "%s: can_read_file(): File \"%s\" is in fact a directory\n", PROJECT,
|
|
||||||
filename_utf8);
|
filename_utf8);
|
||||||
#endif
|
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DISCOVERY_DEBUG
|
|
||||||
fprintf(stderr, "can_read_file() - exit -> %s\n", result ? "true" : "false");
|
log_debug(__FILE__, DISCOVERY, "can_read_file() - exit -> %s\n", result ? "true" : "false");
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,33 +80,26 @@ static int can_read_file(char *filename_utf8)
|
|||||||
|
|
||||||
static int can_read_dir(const char *dirname_utf8)
|
static int can_read_dir(const char *dirname_utf8)
|
||||||
{
|
{
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_dir(%s) - enter\n", dirname_utf8);
|
||||||
fprintf(stderr, "can_read_dir(%s) - enter\n", dirname_utf8);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
if (dirname_utf8 == NULL || dirname_utf8[0] == '\0') {
|
if (dirname_utf8 == NULL || dirname_utf8[0] == '\0') {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_dir(): argument was NULL\n");
|
||||||
fprintf(stderr, "%s: can_read_dir(): argument was NULL\n", PROJECT);
|
|
||||||
#endif
|
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DIR *dir = opendir(dirname_utf8);
|
DIR *dir = opendir(dirname_utf8);
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "can_read_dir(): Directory \"%s\" could not be opened for reading - %s\n",
|
||||||
fprintf(stderr, "%s: can_read_dir(): Directory \"%s\" could not be opened for reading - %s\n",
|
dirname_utf8, strerror(errno));
|
||||||
PROJECT, dirname_utf8, strerror(errno));
|
|
||||||
#endif
|
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DISCOVERY_DEBUG
|
|
||||||
fprintf(stderr, "can_read_dir() - exit -> %s\n", result ? "true" : "false");
|
log_debug(__FILE__, DISCOVERY, "can_read_dir() - exit -> %s\n", result ? "true" : "false");
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,11 +145,11 @@ static char *locate_config_file_or_dir(char *path_utf8, const char *ext_msg)
|
|||||||
else if (can_read_dir(path_utf8)) {
|
else if (can_read_dir(path_utf8)) {
|
||||||
result = locate_config_in_dir(path_utf8);
|
result = locate_config_in_dir(path_utf8);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
fprintf(stderr, "%s: Couldn\'t find config file in directory \'%s\'%s\n", PROJECT, path_utf8, ext_msg);
|
bx_fprintf(stderr, "%s: Couldn\'t find config file in directory \'%s\'%s\n", PROJECT, path_utf8, ext_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: Couldn\'t find config file at \'%s\'%s\n", PROJECT, path_utf8, ext_msg);
|
bx_fprintf(stderr, "%s: Couldn\'t find config file at \'%s\'%s\n", PROJECT, path_utf8, ext_msg);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -176,9 +159,7 @@ static char *locate_config_file_or_dir(char *path_utf8, const char *ext_msg)
|
|||||||
static char *from_env_var(const char *env_var, const char *postfix)
|
static char *from_env_var(const char *env_var, const char *postfix)
|
||||||
{
|
{
|
||||||
char *result = getenv(env_var);
|
char *result = getenv(env_var);
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "from_env_var(): getenv(\"%s\") --> %s\n", env_var, result);
|
||||||
fprintf(stderr, "%s: from_env_var(): getenv(\"%s\") --> %s\n", PROJECT, env_var, result);
|
|
||||||
#endif
|
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
result = concat_strings_alloc(2, result, postfix);
|
result = concat_strings_alloc(2, result, postfix);
|
||||||
}
|
}
|
||||||
@ -189,9 +170,7 @@ static char *from_env_var(const char *env_var, const char *postfix)
|
|||||||
|
|
||||||
static char *locate_config_common(int *error_printed)
|
static char *locate_config_common(int *error_printed)
|
||||||
{
|
{
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "locate_config_common() - enter\n");
|
||||||
fprintf(stderr, "locate_config_common() - enter\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
if (opt.f) {
|
if (opt.f) {
|
||||||
@ -207,9 +186,7 @@ static char *locate_config_common(int *error_printed)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "locate_config_common() - exit -> [%s]\n", result != NULL ? result : "(null)");
|
||||||
fprintf(stderr, "locate_config_common() - exit -> [%s]\n", result != NULL ? result : "(null)");
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,16 +195,12 @@ static char *locate_config_common(int *error_printed)
|
|||||||
|
|
||||||
static char *exe_to_cfg()
|
static char *exe_to_cfg()
|
||||||
{
|
{
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "exe_to_cfg() - enter\n");
|
||||||
fprintf(stderr, "exe_to_cfg() - enter\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char *fallback = "C:\\boxes.cfg";
|
const char *fallback = "C:\\boxes.cfg";
|
||||||
char *exepath = (char *) malloc(256); /* for constructing config file path */
|
char *exepath = (char *) malloc(256); /* for constructing config file path */
|
||||||
if (GetModuleFileName(NULL, exepath, 255) != 0) {
|
if (GetModuleFileName(NULL, exepath, 255) != 0) {
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "exe_to_cfg() - Found executable at %s\n", exepath);
|
||||||
fprintf(stderr, "exe_to_cfg() - Found executable at %s\n", exepath);
|
|
||||||
#endif
|
|
||||||
char *p = strrchr(exepath, '.') + 1;
|
char *p = strrchr(exepath, '.') + 1;
|
||||||
if (p) {
|
if (p) {
|
||||||
/* p is always != NULL, because we get the full path */
|
/* p is always != NULL, because we get the full path */
|
||||||
@ -236,7 +209,7 @@ static char *exe_to_cfg()
|
|||||||
strcat(exepath, "cfg"); /* c:\blah\boxes.cfg */
|
strcat(exepath, "cfg"); /* c:\blah\boxes.cfg */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: path too long. Using %s.\n", PROJECT, fallback);
|
bx_fprintf(stderr, "%s: path too long. Using %s.\n", PROJECT, fallback);
|
||||||
strcpy(exepath, fallback);
|
strcpy(exepath, fallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,9 +217,8 @@ static char *exe_to_cfg()
|
|||||||
else {
|
else {
|
||||||
strcpy(exepath, fallback);
|
strcpy(exepath, fallback);
|
||||||
}
|
}
|
||||||
#ifdef DISCOVERY_DEBUG
|
|
||||||
fprintf(stderr, "exe_to_cfg() - exit -> [%s]\n", exepath);
|
log_debug(__FILE__, DISCOVERY, "exe_to_cfg() - exit -> [%s]\n", exepath);
|
||||||
#endif
|
|
||||||
return exepath;
|
return exepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,9 +241,8 @@ static bxstr_t *utf8_to_bxs(char *utf8)
|
|||||||
|
|
||||||
bxstr_t *discover_config_file(const int global_only)
|
bxstr_t *discover_config_file(const int global_only)
|
||||||
{
|
{
|
||||||
#ifdef DISCOVERY_DEBUG
|
log_debug(__FILE__, DISCOVERY, "discover_config_file(%s) - enter\n", global_only ? "true" : "false");
|
||||||
fprintf(stderr, "discover_config_file(%s) - enter\n", global_only ? "true" : "false");
|
|
||||||
#endif
|
|
||||||
int error_printed = 0;
|
int error_printed = 0;
|
||||||
bxstr_t *result = NULL;
|
bxstr_t *result = NULL;
|
||||||
if (!global_only) {
|
if (!global_only) {
|
||||||
@ -308,7 +279,7 @@ bxstr_t *discover_config_file(const int global_only)
|
|||||||
if (can_read_file(exepath)) {
|
if (can_read_file(exepath)) {
|
||||||
result = utf8_to_bxs(exepath);
|
result = utf8_to_bxs(exepath);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: Couldn\'t find config file at \'%s\'\n", PROJECT, exepath);
|
bx_fprintf(stderr, "%s: Couldn\'t find config file at \'%s\'\n", PROJECT, exepath);
|
||||||
error_printed = 1;
|
error_printed = 1;
|
||||||
}
|
}
|
||||||
BFREE(exepath);
|
BFREE(exepath);
|
||||||
@ -328,11 +299,14 @@ bxstr_t *discover_config_file(const int global_only)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result == NULL && !error_printed) {
|
if (result == NULL && !error_printed) {
|
||||||
fprintf(stderr, "%s: Can't find config file.\n", PROJECT);
|
bx_fprintf(stderr, "%s: Can't find config file.\n", PROJECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_debug_logging(DISCOVERY)) {
|
||||||
|
char *out_result = bxs_to_output(result);
|
||||||
|
log_debug(__FILE__, DISCOVERY, "discover_config_file() - exit -> [%s]\n", out_result);
|
||||||
|
BFREE(out_result);
|
||||||
}
|
}
|
||||||
#ifdef DISCOVERY_DEBUG
|
|
||||||
fprintf(stderr, "discover_config_file() - exit -> [%s]\n", bxs_to_output(result));
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
117
src/generate.c
117
src/generate.c
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "generate.h"
|
#include "generate.h"
|
||||||
@ -92,12 +93,12 @@ static int horiz_precalc(const sentry_t *sarr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf (stderr, "in horiz_precalc:\n ");
|
log_debug(__FILE__, MAIN, "in horiz_precalc:\n");
|
||||||
fprintf (stderr, "opt.design->minwidth %d, input.maxline %d, target_width"
|
log_debug(__FILE__, MAIN, " opt.design->minwidth %d, input.maxline %d, target_width"
|
||||||
" %d, tnumsh %d, bnumsh %d\n", (int) opt.design->minwidth,
|
" %d, tnumsh %d, bnumsh %d\n", (int) opt.design->minwidth,
|
||||||
(int) input.maxline, (int) target_width, tnumsh, bnumsh);
|
(int) input.maxline, (int) target_width, tnumsh, bnumsh);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
twidth = 0;
|
twidth = 0;
|
||||||
bwidth = 0;
|
bwidth = 0;
|
||||||
@ -212,7 +213,7 @@ static int horiz_precalc(const sentry_t *sarr,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: internal error in horiz_precalc()\n", PROJECT);
|
bx_fprintf(stderr, "%s: internal error in horiz_precalc()\n", PROJECT);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} while (twidth != bwidth || twidth < target_width || bwidth < target_width);
|
} while (twidth != bwidth || twidth < target_width || bwidth < target_width);
|
||||||
@ -396,7 +397,7 @@ static int vert_precalc(const sentry_t *sarr,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: internal error in vert_precalc()\n", PROJECT);
|
bx_fprintf(stderr, "%s: internal error in vert_precalc()\n", PROJECT);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} while (lheight != rheight || lheight < target_height || rheight < target_height);
|
} while (lheight != rheight || lheight < target_height || rheight < target_height);
|
||||||
@ -446,9 +447,8 @@ static size_t horiz_chars_required(const sentry_t *sarr, const shape_t *side, si
|
|||||||
|
|
||||||
BFREE(lens);
|
BFREE(lens);
|
||||||
BFREE(iltf_copy);
|
BFREE(iltf_copy);
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "%s side required characters: %d\n",
|
||||||
fprintf (stderr, "%s side required characters: %d\n", (side == north_side) ? "Top": "Bottom", (int) result);
|
(side == north_side) ? "Top": "Bottom", (int) result);
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,20 +584,20 @@ static int horiz_generate(sentry_t *tresult, sentry_t *bresult)
|
|||||||
}
|
}
|
||||||
bresult->width = tresult->width;
|
bresult->width = tresult->width;
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf (stderr, "Top side box rect width %d, height %d.\n",
|
log_debug(__FILE__, MAIN, "Top side box rect width %d, height %d.\n",
|
||||||
(int) tresult->width, (int) tresult->height);
|
(int) tresult->width, (int) tresult->height);
|
||||||
fprintf (stderr, "Top columns to fill: %s %d, %s %d, %s %d.\n",
|
log_debug(__FILE__, MAIN, "Top columns to fill: %s %d, %s %d, %s %d.\n",
|
||||||
shape_name[north_side[1]], (int) tiltf[0],
|
shape_name[north_side[1]], (int) tiltf[0],
|
||||||
shape_name[north_side[2]], (int) tiltf[1],
|
shape_name[north_side[2]], (int) tiltf[1],
|
||||||
shape_name[north_side[3]], (int) tiltf[2]);
|
shape_name[north_side[3]], (int) tiltf[2]);
|
||||||
fprintf (stderr, "Bottom side box rect width %d, height %d.\n",
|
log_debug(__FILE__, MAIN, "Bottom side box rect width %d, height %d.\n",
|
||||||
(int) bresult->width, (int) bresult->height);
|
(int) bresult->width, (int) bresult->height);
|
||||||
fprintf (stderr, "Bottom columns to fill: %s %d, %s %d, %s %d.\n",
|
log_debug(__FILE__, MAIN, "Bottom columns to fill: %s %d, %s %d, %s %d.\n",
|
||||||
shape_name[south_side[1]], (int) biltf[0],
|
shape_name[south_side[1]], (int) biltf[0],
|
||||||
shape_name[south_side[2]], (int) biltf[1],
|
shape_name[south_side[2]], (int) biltf[1],
|
||||||
shape_name[south_side[3]], (int) biltf[2]);
|
shape_name[south_side[3]], (int) biltf[2]);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
tresult->chars = (char **) calloc(tresult->height, sizeof(char *));
|
tresult->chars = (char **) calloc(tresult->height, sizeof(char *));
|
||||||
tresult->mbcs = (bxstr_t **) calloc(tresult->height, sizeof(bxstr_t *));
|
tresult->mbcs = (bxstr_t **) calloc(tresult->height, sizeof(bxstr_t *));
|
||||||
@ -616,25 +616,24 @@ static int horiz_generate(sentry_t *tresult, sentry_t *bresult)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Debugging code - Output horizontal sides of box
|
* Debugging code - Output horizontal sides of box
|
||||||
*/
|
*/
|
||||||
|
if (is_debug_logging(MAIN)) {
|
||||||
size_t j;
|
size_t j;
|
||||||
fprintf(stderr, "TOP SIDE:\n");
|
log_debug(__FILE__, MAIN, "TOP SIDE:\n");
|
||||||
for (j = 0; j < tresult->height; ++j) {
|
for (j = 0; j < tresult->height; ++j) {
|
||||||
fprintf(stderr, " %2d: \'%s\' - \'%s\'\n", (int) j,
|
char *out_sl = bxs_to_output(tresult->mbcs[j]);
|
||||||
bxs_to_output(tresult->mbcs[j]), tresult->chars[j]);
|
log_debug(__FILE__, MAIN, " %2d: \'%s\' - \'%s\'\n", (int) j, out_sl, tresult->chars[j]);
|
||||||
|
BFREE(out_sl);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "BOTTOM SIDE:\n");
|
log_debug(__FILE__, MAIN, "BOTTOM SIDE:\n");
|
||||||
for (j = 0; j < bresult->height; ++j) {
|
for (j = 0; j < bresult->height; ++j) {
|
||||||
fprintf(stderr, " %2d: \'%s\' - '%s'\n", (int) j,
|
char *out_sl = bxs_to_output(bresult->mbcs[j]);
|
||||||
bxs_to_output(bresult->mbcs[j]), bresult->chars[j]);
|
log_debug(__FILE__, MAIN, " %2d: \'%s\' - '%s'\n", (int) j, out_sl, bresult->chars[j]);
|
||||||
|
BFREE(out_sl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0; /* all clear */
|
return 0; /* all clear */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -670,20 +669,20 @@ static int vert_generate(sentry_t *lresult, sentry_t *rresult)
|
|||||||
rresult->height = vspace +
|
rresult->height = vspace +
|
||||||
opt.design->shape[NE].height + opt.design->shape[SE].height;
|
opt.design->shape[NE].height + opt.design->shape[SE].height;
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, "Left side box rect width %d, height %d, vspace %d.\n",
|
log_debug(__FILE__, MAIN, "Left side box rect width %d, height %d, vspace %d.\n",
|
||||||
(int) lresult->width, (int) lresult->height, (int) vspace);
|
(int) lresult->width, (int) lresult->height, (int) vspace);
|
||||||
fprintf(stderr, "Left lines to fill: %s %d, %s %d, %s %d.\n",
|
log_debug(__FILE__, MAIN, "Left lines to fill: %s %d, %s %d, %s %d.\n",
|
||||||
shape_name[west_side[1]], (int) leftiltf[0],
|
shape_name[west_side[1]], (int) leftiltf[0],
|
||||||
shape_name[west_side[2]], (int) leftiltf[1],
|
shape_name[west_side[2]], (int) leftiltf[1],
|
||||||
shape_name[west_side[3]], (int) leftiltf[2]);
|
shape_name[west_side[3]], (int) leftiltf[2]);
|
||||||
fprintf(stderr, "Right side box rect width %d, height %d, vspace %d.\n",
|
log_debug(__FILE__, MAIN, "Right side box rect width %d, height %d, vspace %d.\n",
|
||||||
(int) rresult->width, (int) rresult->height, (int) vspace);
|
(int) rresult->width, (int) rresult->height, (int) vspace);
|
||||||
fprintf(stderr, "Right lines to fill: %s %d, %s %d, %s %d.\n",
|
log_debug(__FILE__, MAIN, "Right lines to fill: %s %d, %s %d, %s %d.\n",
|
||||||
shape_name[east_side[1]], (int) rightiltf[0],
|
shape_name[east_side[1]], (int) rightiltf[0],
|
||||||
shape_name[east_side[2]], (int) rightiltf[1],
|
shape_name[east_side[2]], (int) rightiltf[1],
|
||||||
shape_name[east_side[3]], (int) rightiltf[2]);
|
shape_name[east_side[3]], (int) rightiltf[2]);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
lresult->chars = (char **) calloc(lresult->height, sizeof(char *));
|
lresult->chars = (char **) calloc(lresult->height, sizeof(char *));
|
||||||
if (lresult->chars == NULL) {
|
if (lresult->chars == NULL) {
|
||||||
@ -705,25 +704,24 @@ static int vert_generate(sentry_t *lresult, sentry_t *rresult)
|
|||||||
horiz_assemble(opt.design->shape, west_side, leftiltf, lresult);
|
horiz_assemble(opt.design->shape, west_side, leftiltf, lresult);
|
||||||
horiz_assemble(opt.design->shape, east_side, rightiltf, rresult);
|
horiz_assemble(opt.design->shape, east_side, rightiltf, rresult);
|
||||||
|
|
||||||
#if defined(DEBUG) && 1
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Debugging code - Output left and right side of box
|
* Debugging code - Output left and right side of box
|
||||||
*/
|
*/
|
||||||
|
if (is_debug_logging(MAIN)) {
|
||||||
size_t j;
|
size_t j;
|
||||||
fprintf(stderr, "LEFT SIDE:\n");
|
log_debug(__FILE__, MAIN, "LEFT SIDE:\n");
|
||||||
for (j = 0; j < lresult->height; ++j) {
|
for (j = 0; j < lresult->height; ++j) {
|
||||||
fprintf(stderr, " %2d: \'%s\' - \'%s\'\n", (int) j,
|
char *out_sl = bxs_to_output(lresult->mbcs[j]);
|
||||||
bxs_to_output(lresult->mbcs[j]), lresult->chars[j]);
|
log_debug(__FILE__, MAIN, " %2d: \'%s\' - \'%s\'\n", (int) j, out_sl, lresult->chars[j]);
|
||||||
|
BFREE(out_sl);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "RIGHT SIDE:\n");
|
log_debug(__FILE__, MAIN, "RIGHT SIDE:\n");
|
||||||
for (j = 0; j < rresult->height; ++j) {
|
for (j = 0; j < rresult->height; ++j) {
|
||||||
fprintf(stderr, " %2d: \'%s\' - \'%s\'\n", (int) j,
|
char *out_sl = bxs_to_output(rresult->mbcs[j]);
|
||||||
bxs_to_output(rresult->mbcs[j]), rresult->chars[j]);
|
log_debug(__FILE__, MAIN, " %2d: \'%s\' - \'%s\'\n", (int) j, out_sl, rresult->chars[j]);
|
||||||
|
BFREE(out_sl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0; /* all clear */
|
return 0; /* all clear */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,13 +786,14 @@ static int justify_line(line_t *line, int skew)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG) || 0
|
if (is_debug_logging(MAIN)) {
|
||||||
char *outtext = bxs_to_output(line->text);
|
char *outtext = bxs_to_output(line->text);
|
||||||
fprintf(stderr, "justify_line(%c): Input: real: (%02d) \"%s\", text: (%02d) \"%s\", invisible=%d, skew=%d",
|
log_debug(__FILE__, MAIN,
|
||||||
|
"justify_line(%c): Input: real: (%02d) \"%s\", text: (%02d) \"%s\", invisible=%d, skew=%d",
|
||||||
opt.justify ? opt.justify : '0', (int) line->text->num_chars, outtext, (int) line->text->num_columns,
|
opt.justify ? opt.justify : '0', (int) line->text->num_chars, outtext, (int) line->text->num_columns,
|
||||||
line->text->ascii, (int) line->text->num_chars_invisible, skew);
|
line->text->ascii, (int) line->text->num_chars_invisible, skew);
|
||||||
BFREE(outtext);
|
BFREE(outtext);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
size_t initial_space_size = line->text->indent;
|
size_t initial_space_size = line->text->indent;
|
||||||
@ -837,13 +836,11 @@ static int justify_line(line_t *line, int skew)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: internal error (unknown justify option: %c)\n", PROJECT, opt.justify);
|
bx_fprintf(stderr, "%s: internal error (unknown justify option: %c)\n", PROJECT, opt.justify);
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG) || 0
|
log_debug_cont(MAIN, " -> %d\n", result);
|
||||||
fprintf (stderr, " -> %d\n", result);
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,11 +870,9 @@ int output_box(const sentry_t *thebox)
|
|||||||
size_t skip_left; /* true if left box part is to be skipped */
|
size_t skip_left; /* true if left box part is to be skipped */
|
||||||
size_t ntabs, nspcs; /* needed for unexpand of tabs */
|
size_t ntabs, nspcs; /* needed for unexpand of tabs */
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Padding used: left %d, top %d, right %d, bottom %d\n",
|
||||||
fprintf (stderr, "Padding used: left %d, top %d, right %d, bottom %d\n",
|
|
||||||
opt.design->padding[BLEF], opt.design->padding[BTOP],
|
opt.design->padding[BLEF], opt.design->padding[BTOP],
|
||||||
opt.design->padding[BRIG], opt.design->padding[BBOT]);
|
opt.design->padding[BRIG], opt.design->padding[BBOT]);
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create string of spaces for indentation
|
* Create string of spaces for indentation
|
||||||
@ -985,12 +980,18 @@ int output_box(const sentry_t *thebox)
|
|||||||
set_char_at(hfill1, hpl, char_nul);
|
set_char_at(hfill1, hpl, char_nul);
|
||||||
set_char_at(hfill2, hpr, char_nul);
|
set_char_at(hfill2, hpr, char_nul);
|
||||||
|
|
||||||
#if defined(DEBUG)
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, "Alignment: hfill %d hpl %d hpr %d, vfill %d vfill1 %d vfill2 %d.\n",
|
log_debug(__FILE__, MAIN, "Alignment: hfill %d hpl %d hpr %d, vfill %d vfill1 %d vfill2 %d.\n",
|
||||||
(int) hfill, (int) hpl, (int) hpr, (int) vfill, (int) vfill1, (int) vfill2);
|
(int) hfill, (int) hpl, (int) hpr, (int) vfill, (int) vfill1, (int) vfill2);
|
||||||
fprintf(stderr, " hfill1 = \"%s\"; hfill2 = \"%s\"; indentspc = \"%s\";\n",
|
char *out_hfill1 = u32_strconv_to_output(hfill1);
|
||||||
u32_strconv_to_output(hfill1), u32_strconv_to_output(hfill2), u32_strconv_to_output(indentspc));
|
char *out_hfill2 = u32_strconv_to_output(hfill2);
|
||||||
#endif
|
char *out_indentspc = u32_strconv_to_output(indentspc);
|
||||||
|
log_debug(__FILE__, MAIN, " hfill1 = \"%s\"; hfill2 = \"%s\"; indentspc = \"%s\";\n",
|
||||||
|
out_hfill1, out_hfill2, out_indentspc);
|
||||||
|
BFREE(out_indentspc);
|
||||||
|
BFREE(out_hfill2);
|
||||||
|
BFREE(out_hfill1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find out if and how many leading or trailing blank lines must be
|
* Find out if and how many leading or trailing blank lines must be
|
||||||
@ -1008,10 +1009,8 @@ int output_box(const sentry_t *thebox)
|
|||||||
if (empty_side(opt.design->shape, BLEF)) {
|
if (empty_side(opt.design->shape, BLEF)) {
|
||||||
skip_left = opt.design->shape[NW].width;
|
skip_left = opt.design->shape[NW].width;
|
||||||
} /* could simply be 1, though */
|
} /* could simply be 1, though */
|
||||||
#if defined(DEBUG)
|
log_debug(__FILE__, MAIN, "skip_start = %d; skip_end = %d; skip_left = %d; nol = %d;\n",
|
||||||
fprintf(stderr, "skip_start = %d; skip_end = %d; skip_left = %d; nol = %d;\n",
|
|
||||||
(int) skip_start, (int) skip_end, (int) skip_left, (int) nol);
|
(int) skip_start, (int) skip_end, (int) skip_left, (int) nol);
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate actual output
|
* Generate actual output
|
||||||
|
47
src/input.c
47
src/input.c
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "regulex.h"
|
#include "regulex.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
@ -45,9 +46,7 @@ static int has_linebreak(const uint32_t *s, const int len)
|
|||||||
if (s != NULL && len > 0) {
|
if (s != NULL && len > 0) {
|
||||||
ucs4_t the_last = s[len - 1];
|
ucs4_t the_last = s[len - 1];
|
||||||
result = u32_cmp(&char_cr, &the_last, 1) == 0 || u32_cmp(&char_newline, &the_last, 1) == 0;
|
result = u32_cmp(&char_cr, &the_last, 1) == 0 || u32_cmp(&char_newline, &the_last, 1) == 0;
|
||||||
#if defined(DEBUG)
|
log_debug(__FILE__, MAIN, "has_linebreak: (%#010x) %d\n", (int) the_last, result);
|
||||||
fprintf(stderr, "has_linebreak: (%#010x) %d\n", (int) the_last, result);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -66,7 +65,7 @@ static int get_indent(const line_t *lines, const size_t lines_size)
|
|||||||
int nonblank = 0; /* true if one non-blank line found */
|
int nonblank = 0; /* true if one non-blank line found */
|
||||||
|
|
||||||
if (lines == NULL) {
|
if (lines == NULL) {
|
||||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
bx_fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (lines_size == 0) {
|
if (lines_size == 0) {
|
||||||
@ -112,16 +111,14 @@ int apply_substitutions(input_t *result, const int mode)
|
|||||||
rules = opt.design->revrules;
|
rules = opt.design->revrules;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
bx_fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compile regular expressions
|
* Compile regular expressions
|
||||||
*/
|
*/
|
||||||
#ifdef REGEXP_DEBUG
|
log_debug(__FILE__, REGEXP, "Compiling %d %s rule patterns\n", (int) num_rules, mode ? "reversion" : "replacement");
|
||||||
fprintf(stderr, "Compiling %d %s rule patterns\n", (int) num_rules, mode ? "reversion" : "replacement");
|
|
||||||
#endif
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
opt.design->current_rule = rules;
|
opt.design->current_rule = rules;
|
||||||
for (j = 0; j < num_rules; ++j, ++(opt.design->current_rule)) {
|
for (j = 0; j < num_rules; ++j, ++(opt.design->current_rule)) {
|
||||||
@ -141,21 +138,21 @@ int apply_substitutions(input_t *result, const int mode)
|
|||||||
for (k = 0; k < result->num_lines; ++k) {
|
for (k = 0; k < result->num_lines; ++k) {
|
||||||
opt.design->current_rule = rules;
|
opt.design->current_rule = rules;
|
||||||
for (j = 0; j < num_rules; ++j, ++(opt.design->current_rule)) {
|
for (j = 0; j < num_rules; ++j, ++(opt.design->current_rule)) {
|
||||||
#ifdef REGEXP_DEBUG
|
if (is_debug_logging(REGEXP)) {
|
||||||
char *outtext = bxs_to_output(result->lines[k].text);
|
char *outtext = bxs_to_output(result->lines[k].text);
|
||||||
char *outrepstr = bxs_to_output(rules[j].repstr);
|
char *outrepstr = bxs_to_output(rules[j].repstr);
|
||||||
fprintf(stderr, "regex_replace(0x%p, \"%s\", \"%s\", %d, \'%c\') == ", rules[j].prog, outrepstr,
|
log_debug(__FILE__, REGEXP, "regex_replace(0x%p, \"%s\", \"%s\", %d, \'%c\') == ", rules[j].prog,
|
||||||
outtext, (int) result->lines[k].text->num_chars, rules[j].mode);
|
outrepstr, outtext, (int) result->lines[k].text->num_chars, rules[j].mode);
|
||||||
BFREE(outtext);
|
BFREE(outtext);
|
||||||
BFREE(outrepstr);
|
BFREE(outrepstr);
|
||||||
#endif
|
}
|
||||||
uint32_t *newtext = u32_regex_replace(rules[j].prog, rules[j].repstr->memory, result->lines[k].text->memory,
|
uint32_t *newtext = u32_regex_replace(rules[j].prog, rules[j].repstr->memory, result->lines[k].text->memory,
|
||||||
result->lines[k].text->num_chars, rules[j].mode == 'g');
|
result->lines[k].text->num_chars, rules[j].mode == 'g');
|
||||||
#ifdef REGEXP_DEBUG
|
if (is_debug_logging(REGEXP)) {
|
||||||
char *outnewtext = newtext ? u32_strconv_to_output(newtext) : strdup("NULL");
|
char *outnewtext = newtext ? u32_strconv_to_output(newtext) : strdup("NULL");
|
||||||
fprintf(stderr, "\"%s\"\n", outnewtext);
|
log_debug_cont(REGEXP, "\"%s\"\n", outnewtext);
|
||||||
BFREE(outnewtext);
|
BFREE(outnewtext);
|
||||||
#endif
|
}
|
||||||
if (newtext == NULL) {
|
if (newtext == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -165,12 +162,12 @@ int apply_substitutions(input_t *result, const int mode)
|
|||||||
|
|
||||||
analyze_line_ascii(result, result->lines + k); /* update maxline value */
|
analyze_line_ascii(result, result->lines + k); /* update maxline value */
|
||||||
|
|
||||||
#ifdef REGEXP_DEBUG
|
if (is_debug_logging(REGEXP)) {
|
||||||
char *outtext2 = bxs_to_output(result->lines[k].text);
|
char *outtext2 = bxs_to_output(result->lines[k].text);
|
||||||
fprintf(stderr, "result->lines[%d] == {%d, \"%s\"}\n", (int) k, (int) result->lines[k].text->num_chars,
|
log_debug(__FILE__, REGEXP, "result->lines[%d] == {%d, \"%s\"}\n",
|
||||||
outtext2);
|
(int) k, (int) result->lines[k].text->num_chars, outtext2);
|
||||||
BFREE(outtext2);
|
BFREE(outtext2);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
opt.design->current_rule = NULL;
|
opt.design->current_rule = NULL;
|
||||||
}
|
}
|
||||||
@ -321,15 +318,15 @@ int analyze_input(input_t *result)
|
|||||||
bxs_free(result->lines[i].text);
|
bxs_free(result->lines[i].text);
|
||||||
result->lines[i].text = unindented;
|
result->lines[i].text = unindented;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
char *outtext = bxs_to_output(result->lines[i].text);
|
char *outtext = bxs_to_output(result->lines[i].text);
|
||||||
fprintf(stderr, "%2d: text = \"%s\" (%d chars, %d visible, %d invisible, %d columns)\n"
|
log_debug(__FILE__, MAIN, "%2d: text = \"%s\" (%d chars, %d visible, %d invisible, %d columns)\n",
|
||||||
" ascii = \"%s\"\n", (int) i, outtext,
|
(int) i, outtext,
|
||||||
(int) result->lines[i].text->num_chars, (int) result->lines[i].text->num_chars_visible,
|
(int) result->lines[i].text->num_chars, (int) result->lines[i].text->num_chars_visible,
|
||||||
(int) result->lines[i].text->num_chars_invisible, (int) result->lines[i].text->num_columns,
|
(int) result->lines[i].text->num_chars_invisible, (int) result->lines[i].text->num_columns);
|
||||||
result->lines[i].text->ascii);
|
log_debug(__FILE__, MAIN, " ascii = \"%s\"\n", result->lines[i].text->ascii);
|
||||||
BFREE(outtext);
|
BFREE(outtext);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
result->maxline -= result->indent;
|
result->maxline -= result->indent;
|
||||||
}
|
}
|
||||||
|
60
src/lexer.l
60
src/lexer.l
@ -61,6 +61,7 @@ void inflate_inbuf(void *yyscanner, const bxstr_t *configfile);
|
|||||||
#include <unitypes.h>
|
#include <unitypes.h>
|
||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
@ -181,9 +182,7 @@ PFILENAME [^\r\n]+
|
|||||||
else if (*p == yyextra->sdel) {
|
else if (*p == yyextra->sdel) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
yyless ((p - str) + 2 + qcnt); /* string plus quotes */
|
yyless ((p - str) + 2 + qcnt); /* string plus quotes */
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, " STRING: \"%s\"\n", str);
|
||||||
fprintf (stderr, " STRING: \"%s\"\n", str);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint32_t *utf8 = u32_strconv_from_arg(str, CONFIG_FILE_ENCODING);
|
uint32_t *utf8 = u32_strconv_from_arg(str, CONFIG_FILE_ENCODING);
|
||||||
yylval->s = bxs_from_unicode(utf8);
|
yylval->s = bxs_from_unicode(utf8);
|
||||||
@ -293,9 +292,7 @@ PFILENAME [^\r\n]+
|
|||||||
|
|
||||||
|
|
||||||
<BOX>Tags {
|
<BOX>Tags {
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, " YTAGS: %s\n", yytext);
|
||||||
fprintf (stderr, " YTAGS: %s\n", yytext);
|
|
||||||
#endif
|
|
||||||
return YTAGS;
|
return YTAGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,9 +365,7 @@ PFILENAME [^\r\n]+
|
|||||||
/*
|
/*
|
||||||
* general key words
|
* general key words
|
||||||
*/
|
*/
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, "KEYWORD: %s\n", yytext);
|
||||||
fprintf (stderr, "KEYWORD: %s\n", yytext);
|
|
||||||
#endif
|
|
||||||
yylval->ascii = strdup(yytext);
|
yylval->ascii = strdup(yytext);
|
||||||
if (yylval->ascii == NULL) {
|
if (yylval->ascii == NULL) {
|
||||||
perror (PROJECT);
|
perror (PROJECT);
|
||||||
@ -398,9 +393,7 @@ PFILENAME [^\r\n]+
|
|||||||
perror (PROJECT);
|
perror (PROJECT);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, "ASCIIID: %s\n", yylval->ascii);
|
||||||
fprintf (stderr, "ASCIIID: %s\n", yylval->ascii);
|
|
||||||
#endif
|
|
||||||
return ASCII_ID;
|
return ASCII_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,44 +407,38 @@ PFILENAME [^\r\n]+
|
|||||||
perror (PROJECT);
|
perror (PROJECT);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#ifdef LEXER_DEBUG
|
if (is_debug_logging(LEXER)) {
|
||||||
fprintf (stderr, " BXWORD: %s\n", u32_strconv_to_output(utf8));
|
char *out_utf8 = u32_strconv_to_output(utf8);
|
||||||
#endif
|
log_debug(__FILE__, LEXER, " BXWORD: %s\n", out_utf8);
|
||||||
|
BFREE(out_utf8);
|
||||||
|
}
|
||||||
BFREE(utf8);
|
BFREE(utf8);
|
||||||
return BXWORD;
|
return BXWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<BOX>[\+-]?[0-9]+ {
|
<BOX>[\+-]?[0-9]+ {
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, "YNUMBER: %s\n", yytext);
|
||||||
fprintf (stderr, "YNUMBER: %s\n", yytext);
|
|
||||||
#endif
|
|
||||||
yylval->num = atoi (yytext);
|
yylval->num = atoi (yytext);
|
||||||
return YNUMBER;
|
return YNUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<BOX,SHAPES,ELASTIC>[,(){}] {
|
<BOX,SHAPES,ELASTIC>[,(){}] {
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, " SYMBOL: \'%c\'\n", yytext[0]);
|
||||||
fprintf (stderr, " SYMBOL: \'%c\'\n", yytext[0]);
|
|
||||||
#endif
|
|
||||||
return yytext[0];
|
return yytext[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<INITIAL,BOX,SHAPES,ELASTIC>#.*$ {
|
<INITIAL,BOX,SHAPES,ELASTIC>#.*$ {
|
||||||
/* ignore comments */
|
/* ignore comments */
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, "COMMENT: %s\n", yytext + 1);
|
||||||
fprintf (stderr, "COMMENT: %s\n", yytext+1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<INITIAL,BOX,SHAPES,ELASTIC>. {
|
<INITIAL,BOX,SHAPES,ELASTIC>. {
|
||||||
/* a character that made no sense where it was encountered. Let the parser handle it. */
|
/* a character that made no sense where it was encountered. Let the parser handle it. */
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, " YUNREC: \'%c\'\n", yytext[0]);
|
||||||
fprintf (stderr, " YUNREC: \'%c\'\n", yytext[0]);
|
|
||||||
#endif
|
|
||||||
return YUNREC;
|
return YUNREC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,12 +477,15 @@ static void report_state_char(char *symbol, char c, char *expected_state_str)
|
|||||||
|
|
||||||
static void report_state(char *symbol, char *text, char *expected_state_str)
|
static void report_state(char *symbol, char *text, char *expected_state_str)
|
||||||
{
|
{
|
||||||
int lexerDebug = 0;
|
if (is_debug_logging(LEXER)) {
|
||||||
#ifdef LEXER_DEBUG
|
size_t text_len = 0;
|
||||||
lexerDebug = 1;
|
if (text != NULL) {
|
||||||
#endif
|
text_len = strlen(text);
|
||||||
if (lexerDebug) {
|
if (text_len > 0 && (text[text_len - 1] == '\r' || text[text_len - 1] == '\t')) {
|
||||||
fprintf(stderr, "%7s: %s -- STATE %s\n", symbol, text, expected_state_str);
|
text[text_len - 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_debug(__FILE__, LEXER, "%7s: %s (%d) -- STATE %s\n", symbol, text, text_len, expected_state_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,9 +506,7 @@ static int change_string_delimiters(pass_to_flex *extra, char *delim_expr)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LEXER_DEBUG
|
log_debug(__FILE__, LEXER, "YDELIMS: change_string_delimiters('%c', '%c')\n", delim_expr[0], delim_expr[1]);
|
||||||
fprintf(stderr, "YDELIMS: change_string_delimiters('%c', '%c')\n", delim_expr[0], delim_expr[1]);
|
|
||||||
#endif
|
|
||||||
extra->sesc = delim_expr[0];
|
extra->sesc = delim_expr[0];
|
||||||
extra->sdel = delim_expr[1];
|
extra->sdel = delim_expr[1];
|
||||||
|
|
||||||
|
102
src/parsecode.c
102
src/parsecode.c
@ -27,6 +27,7 @@
|
|||||||
#include <unistr.h>
|
#include <unistr.h>
|
||||||
|
|
||||||
#include "discovery.h"
|
#include "discovery.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "parsecode.h"
|
#include "parsecode.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
@ -57,9 +58,7 @@ static int check_sizes(pass_to_bison *bison_args)
|
|||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: check_sizes()\n");
|
||||||
fprintf(stderr, " Parser: check_sizes()\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_SIDES; ++i) {
|
for (i = 0; i < NUM_SIDES; ++i) {
|
||||||
if (i == 0 || i == 2) {
|
if (i == 0 || i == 2) {
|
||||||
@ -125,9 +124,7 @@ static int corner_check(pass_to_bison *bison_args)
|
|||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: corner_check()\n");
|
||||||
fprintf(stderr, " Parser: corner_check()\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (c = 0; c < NUM_CORNERS; ++c) {
|
for (c = 0; c < NUM_CORNERS; ++c) {
|
||||||
if (curdes.shape[corners[c]].elastic) {
|
if (curdes.shape[corners[c]].elastic) {
|
||||||
@ -145,9 +142,7 @@ static shape_t non_existent_elastics(pass_to_bison *bison_args)
|
|||||||
{
|
{
|
||||||
shape_t i;
|
shape_t i;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: non_existent_elastics()\n");
|
||||||
fprintf(stderr, " Parser: non_existent_elastics()\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_SHAPES; ++i) {
|
for (i = 0; i < NUM_SHAPES; ++i) {
|
||||||
if (curdes.shape[i].elastic && isempty(curdes.shape + i)) {
|
if (curdes.shape[i].elastic && isempty(curdes.shape + i)) {
|
||||||
@ -164,9 +159,7 @@ static int insufficient_elasticity(pass_to_bison *bison_args)
|
|||||||
{
|
{
|
||||||
int i, j, ef;
|
int i, j, ef;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: insufficient_elasticity()\n");
|
||||||
fprintf(stderr, " Parser: insufficient_elasticity()\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_SIDES; ++i) {
|
for (i = 0; i < NUM_SIDES; ++i) {
|
||||||
for (j = 1, ef = 0; j < 4; ++j) {
|
for (j = 1, ef = 0; j < 4; ++j) {
|
||||||
@ -188,9 +181,7 @@ static int adjoining_elastics(pass_to_bison *bison_args)
|
|||||||
{
|
{
|
||||||
int i, j, ef;
|
int i, j, ef;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: adjoining_elastics()\n");
|
||||||
fprintf(stderr, " Parser: adjoining_elastics()\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_SIDES; ++i) {
|
for (i = 0; i < NUM_SIDES; ++i) {
|
||||||
ef = 0;
|
ef = 0;
|
||||||
@ -316,9 +307,7 @@ static int full_parse_required()
|
|||||||
if (!opt.design_choice_by_user) {
|
if (!opt.design_choice_by_user) {
|
||||||
result = opt.r || opt.l || (opt.query != NULL && !opt.qundoc);
|
result = opt.r || opt.l || (opt.query != NULL && !opt.qundoc);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, " Parser: full_parse_required() -> %s\n", result ? "true" : "false");
|
||||||
fprintf(stderr, " Parser: full_parse_required() -> %s\n", result ? "true" : "false");
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,11 +582,9 @@ int action_finalize_shapes(pass_to_bison *bison_args)
|
|||||||
curdes.maxshapeheight = curdes.shape[i].height;
|
curdes.maxshapeheight = curdes.shape[i].height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: Minimum box dimensions: width %d height %d\n",
|
||||||
fprintf(stderr, " Parser: Minimum box dimensions: width %d height %d\n",
|
|
||||||
(int) curdes.minwidth, (int) curdes.minheight);
|
(int) curdes.minwidth, (int) curdes.minheight);
|
||||||
fprintf(stderr, " Parser: Maximum shape height: %d\n", (int) curdes.maxshapeheight);
|
log_debug(__FILE__, PARSER, " Parser: Maximum shape height: %d\n", (int) curdes.maxshapeheight);
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set name of each shape
|
* Set name of each shape
|
||||||
@ -631,9 +618,7 @@ int action_start_parsing_design(pass_to_bison *bison_args, char *design_name)
|
|||||||
|
|
||||||
if (!design_needed(bison_args)) {
|
if (!design_needed(bison_args)) {
|
||||||
bison_args->speeding = 1;
|
bison_args->speeding = 1;
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: Skipping to next design (lexer doesn't know!)\n");
|
||||||
fprintf(stderr, " Parser: Skipping to next design (lexer doesn't know!)\n");
|
|
||||||
#endif
|
|
||||||
return RC_ERROR; /* trigger the parser's `error` rule, which will skip to the next design */
|
return RC_ERROR; /* trigger the parser's `error` rule, which will skip to the next design */
|
||||||
}
|
}
|
||||||
return RC_SUCCESS;
|
return RC_SUCCESS;
|
||||||
@ -643,9 +628,12 @@ int action_start_parsing_design(pass_to_bison *bison_args, char *design_name)
|
|||||||
|
|
||||||
int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
|
int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
if (is_debug_logging(PARSER)) {
|
||||||
fprintf(stderr, " Parser: parent config file specified: [%s]\n", bxs_to_output(filepath));
|
char *out_filepath = bxs_to_output(filepath);
|
||||||
#endif
|
log_debug(__FILE__, PARSER, " Parser: parent config file specified: [%s]\n", out_filepath);
|
||||||
|
BFREE(out_filepath);
|
||||||
|
}
|
||||||
|
|
||||||
if (bxs_is_empty(filepath)) {
|
if (bxs_is_empty(filepath)) {
|
||||||
bison_args->skipping = 1;
|
bison_args->skipping = 1;
|
||||||
yyerror(bison_args, "parent reference is empty");
|
yyerror(bison_args, "parent reference is empty");
|
||||||
@ -674,9 +662,11 @@ int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef PARSER_DEBUG
|
if (is_debug_logging(PARSER)) {
|
||||||
fprintf(stderr, " Parser: parent config file path resolved: [%s]\n", bxs_to_output(filepath));
|
char *out_filepath = bxs_to_output(filepath);
|
||||||
#endif
|
log_debug(__FILE__, PARSER, " Parser: parent config file path resolved: [%s]\n", out_filepath);
|
||||||
|
BFREE(out_filepath);
|
||||||
|
}
|
||||||
|
|
||||||
int is_new = !array_contains_bxs(bison_args->parent_configs, bison_args->num_parent_configs, filepath);
|
int is_new = !array_contains_bxs(bison_args->parent_configs, bison_args->num_parent_configs, filepath);
|
||||||
if (is_new) {
|
if (is_new) {
|
||||||
@ -685,10 +675,10 @@ int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
|
|||||||
bison_args->parent_configs[bison_args->num_parent_configs] = filepath;
|
bison_args->parent_configs[bison_args->num_parent_configs] = filepath;
|
||||||
++(bison_args->num_parent_configs);
|
++(bison_args->num_parent_configs);
|
||||||
}
|
}
|
||||||
else {
|
else if (is_debug_logging(PARSER)) {
|
||||||
#ifdef PARSER_DEBUG
|
char *out_filepath = bxs_to_output(filepath);
|
||||||
fprintf(stderr, " Parser: duplicate parent / cycle: [%s]\n", bxs_to_output(filepath));
|
log_debug(__FILE__, PARSER, " Parser: duplicate parent / cycle: [%s]\n", out_filepath);
|
||||||
#endif
|
BFREE(out_filepath);
|
||||||
}
|
}
|
||||||
return RC_SUCCESS;
|
return RC_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -699,9 +689,7 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
|
|||||||
{
|
{
|
||||||
design_t *tmp;
|
design_t *tmp;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, "--------- ADDING DESIGN \"%s\".\n", design_primary_name);
|
||||||
fprintf(stderr, "--------- ADDING DESIGN \"%s\".\n", design_primary_name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (strcasecmp(design_primary_name, name_at_end)) {
|
if (strcasecmp(design_primary_name, name_at_end)) {
|
||||||
yyerror(bison_args, "box design name differs at BOX and END");
|
yyerror(bison_args, "box design name differs at BOX and END");
|
||||||
@ -747,9 +735,11 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
|
|||||||
|
|
||||||
int action_record_keyword(pass_to_bison *bison_args, char *keyword, bxstr_t *value)
|
int action_record_keyword(pass_to_bison *bison_args, char *keyword, bxstr_t *value)
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
if (is_debug_logging(PARSER)) {
|
||||||
fprintf(stderr, " Parser: entry rule fulfilled [%s = %s]\n", keyword, bxs_to_output(value));
|
char *out_value = bxs_to_output(value);
|
||||||
#endif
|
log_debug(__FILE__, PARSER, " Parser: entry rule fulfilled [%s = %s]\n", keyword, out_value);
|
||||||
|
BFREE(out_value);
|
||||||
|
}
|
||||||
|
|
||||||
size_t error_pos = 0;
|
size_t error_pos = 0;
|
||||||
if (!bxs_valid_in_kv_string(value, &error_pos)) {
|
if (!bxs_valid_in_kv_string(value, &error_pos)) {
|
||||||
@ -856,9 +846,7 @@ int action_add_alias(pass_to_bison *bison_args, char *alias_name)
|
|||||||
return RC_ERROR;
|
return RC_ERROR;
|
||||||
}
|
}
|
||||||
if (alias_exists_in_child_configs(bison_args, alias_name)) {
|
if (alias_exists_in_child_configs(bison_args, alias_name)) {
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: alias already used by child config, dropping: %s\n", alias_name);
|
||||||
fprintf(stderr, " Parser: alias already used by child config, dropping: %s\n", alias_name);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
size_t num_aliases = array_count0(curdes.aliases);
|
size_t num_aliases = array_count0(curdes.aliases);
|
||||||
@ -906,9 +894,7 @@ static uint32_t *find_first_nonblank_line(bxstr_t *sample)
|
|||||||
|
|
||||||
int action_sample_block(pass_to_bison *bison_args, bxstr_t *sample)
|
int action_sample_block(pass_to_bison *bison_args, bxstr_t *sample)
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: SAMPLE block rule satisfied\n");
|
||||||
fprintf(stderr, " Parser: SAMPLE block rule satisfied\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (curdes.sample) {
|
if (curdes.sample) {
|
||||||
yyerror(bison_args, "duplicate SAMPLE block");
|
yyerror(bison_args, "duplicate SAMPLE block");
|
||||||
@ -944,12 +930,14 @@ int action_add_regex_rule(pass_to_bison *bison_args, char *type, reprule_t **rul
|
|||||||
{
|
{
|
||||||
size_t n = *rule_list_len;
|
size_t n = *rule_list_len;
|
||||||
|
|
||||||
UNUSED(type); /* used only in PARSER_DEBUG mode */
|
if (is_debug_logging(PARSER)) {
|
||||||
#ifdef PARSER_DEBUG
|
char *out_search = bxs_to_output(search);
|
||||||
fprintf(stderr, "Adding %s rule: \"%s\" with \"%s\" (%c)\n",
|
char *out_replace = bxs_to_output(replace);
|
||||||
strcmp(type, "rep") == 0 ? "replacement" : "reversion",
|
log_debug(__FILE__, PARSER, "Adding %s rule: \"%s\" with \"%s\" (%c)\n",
|
||||||
bxs_to_output(search), bxs_to_output(replace), mode);
|
strcmp(type, "rep") == 0 ? "replacement" : "reversion", out_search, out_replace, mode);
|
||||||
#endif
|
BFREE(out_replace);
|
||||||
|
BFREE(out_search);
|
||||||
|
}
|
||||||
|
|
||||||
*rule_list = (reprule_t *) realloc(*rule_list, (n + 1) * sizeof(reprule_t));
|
*rule_list = (reprule_t *) realloc(*rule_list, (n + 1) * sizeof(reprule_t));
|
||||||
if (*rule_list == NULL) {
|
if (*rule_list == NULL) {
|
||||||
@ -975,9 +963,7 @@ int action_first_shape_line(pass_to_bison *bison_args, bxstr_t *line, sentry_t *
|
|||||||
{
|
{
|
||||||
sentry_t rval = SENTRY_INITIALIZER;
|
sentry_t rval = SENTRY_INITIALIZER;
|
||||||
|
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, "Initializing a shape entry with first line\n");
|
||||||
fprintf(stderr, "Initializing a shape entry with first line\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t error_pos = 0;
|
size_t error_pos = 0;
|
||||||
if (!bxs_valid_in_shape(line, &error_pos)) {
|
if (!bxs_valid_in_shape(line, &error_pos)) {
|
||||||
@ -1018,9 +1004,7 @@ int action_first_shape_line(pass_to_bison *bison_args, bxstr_t *line, sentry_t *
|
|||||||
|
|
||||||
int action_add_shape_line(pass_to_bison *bison_args, sentry_t *shape, bxstr_t *line)
|
int action_add_shape_line(pass_to_bison *bison_args, sentry_t *shape, bxstr_t *line)
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, "Extending a shape entry\n");
|
||||||
fprintf(stderr, "Extending a shape entry\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t slen = line->num_columns;
|
size_t slen = line->num_columns;
|
||||||
if (slen != shape->width) {
|
if (slen != shape->width) {
|
||||||
|
35
src/parser.y
35
src/parser.y
@ -75,6 +75,7 @@ typedef struct {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unictype.h>
|
#include <unictype.h>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
@ -199,10 +200,8 @@ config_file: config_file design_or_error | design_or_error | config_file parent_
|
|||||||
design_or_error: design | error
|
design_or_error: design | error
|
||||||
{
|
{
|
||||||
/* reset alias list, as those are collected even when speedmode is on */
|
/* reset alias list, as those are collected even when speedmode is on */
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, " Parser: Discarding token [skipping=%s, speeding=%s]\n",
|
||||||
fprintf (stderr, " Parser: Discarding token [skipping=%s, speeding=%s]\n",
|
|
||||||
bison_args->skipping ? "true" : "false", bison_args->speeding ? "true" : "false");
|
bison_args->skipping ? "true" : "false", bison_args->speeding ? "true" : "false");
|
||||||
#endif
|
|
||||||
if (curdes.aliases[0] != NULL) {
|
if (curdes.aliases[0] != NULL) {
|
||||||
BFREE(curdes.aliases);
|
BFREE(curdes.aliases);
|
||||||
curdes.aliases = (char **) calloc(1, sizeof(char *));
|
curdes.aliases = (char **) calloc(1, sizeof(char *));
|
||||||
@ -268,10 +267,10 @@ entry: KEYWORD STRING
|
|||||||
yyerror(bison_args, "string expected");
|
yyerror(bison_args, "string expected");
|
||||||
YYERROR;
|
YYERROR;
|
||||||
}
|
}
|
||||||
else {
|
else if (is_debug_logging(PARSER)) {
|
||||||
#ifdef PARSER_DEBUG
|
char *out_filename = bxs_to_output(filename);
|
||||||
fprintf (stderr, " Parser: Discarding entry [%s = %s].\n", "parent", bxs_to_output(filename));
|
log_debug(__FILE__, PARSER, " Parser: Discarding entry [%s = %s].\n", "parent", out_filename);
|
||||||
#endif
|
BFREE(out_filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,9 +283,11 @@ entry: KEYWORD STRING
|
|||||||
|
|
||||||
| BXWORD STRING | ASCII_ID STRING
|
| BXWORD STRING | ASCII_ID STRING
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
if (is_debug_logging(PARSER)) {
|
||||||
fprintf (stderr, " Parser: Discarding entry [%s = %s].\n", $1, bxs_to_output($2));
|
char *out_string = bxs_to_output($2);
|
||||||
#endif
|
log_debug(__FILE__, PARSER, " Parser: Discarding entry [%s = %s].\n", $1, out_string);
|
||||||
|
BFREE(out_string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -323,10 +324,8 @@ block: YSAMPLE STRING YENDSAMPLE
|
|||||||
|
|
||||||
| YPADDING '{' wlist '}'
|
| YPADDING '{' wlist '}'
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, "Padding set to (l%d o%d r%d u%d)\n",
|
||||||
fprintf (stderr, "Padding set to (l%d o%d r%d u%d)\n",
|
|
||||||
curdes.padding[BLEF], curdes.padding[BTOP], curdes.padding[BRIG], curdes.padding[BBOT]);
|
curdes.padding[BLEF], curdes.padding[BTOP], curdes.padding[BRIG], curdes.padding[BBOT]);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -347,9 +346,7 @@ elist: elist ',' elist_entry | elist_entry;
|
|||||||
|
|
||||||
elist_entry: SHAPE
|
elist_entry: SHAPE
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, "Marked \'%s\' shape as elastic\n", shape_name[(int) $1]);
|
||||||
fprintf (stderr, "Marked \'%s\' shape as elastic\n", shape_name[(int) $1]);
|
|
||||||
#endif
|
|
||||||
curdes.shape[$1].elastic = 1;
|
curdes.shape[$1].elastic = 1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@ -360,10 +357,8 @@ slist: slist slist_entry | slist_entry;
|
|||||||
|
|
||||||
slist_entry: SHAPE shape_def
|
slist_entry: SHAPE shape_def
|
||||||
{
|
{
|
||||||
#ifdef PARSER_DEBUG
|
log_debug(__FILE__, PARSER, "Adding shape spec for \'%s\' (width %d height %d)\n",
|
||||||
fprintf (stderr, "Adding shape spec for \'%s\' (width %d "
|
shape_name[$1], (int) $2.width, (int) $2.height);
|
||||||
"height %d)\n", shape_name[$1], (int) $2.width, (int) $2.height);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (isempty (curdes.shape + $1)) {
|
if (isempty (curdes.shape + $1)) {
|
||||||
curdes.shape[$1] = $2;
|
curdes.shape[$1] = $2;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
#include "bxstring.h"
|
#include "bxstring.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
@ -161,9 +162,11 @@ static pass_to_flex new_flex_extra_data()
|
|||||||
|
|
||||||
static pass_to_bison parse_config_file(bxstr_t *config_file, design_t *child_configs, size_t num_child_configs)
|
static pass_to_bison parse_config_file(bxstr_t *config_file, design_t *child_configs, size_t num_child_configs)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf (stderr, "Parsing Config File %s ...\n", bxs_to_output(config_file));
|
char *out_config_file = bxs_to_output(config_file);
|
||||||
#endif
|
log_debug(__FILE__, MAIN, "Parsing Config File %s ...\n", out_config_file);
|
||||||
|
BFREE(out_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
pass_to_bison bison_args = new_bison_args(config_file);
|
pass_to_bison bison_args = new_bison_args(config_file);
|
||||||
bison_args.child_configs = child_configs;
|
bison_args.child_configs = child_configs;
|
||||||
@ -187,9 +190,7 @@ static pass_to_bison parse_config_file(bxstr_t *config_file, design_t *child_con
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "yyparse() returned %d\n", rc);
|
||||||
fprintf (stderr, "yyparse() returned %d\n", rc);
|
|
||||||
#endif
|
|
||||||
return new_bison_args(config_file);
|
return new_bison_args(config_file);
|
||||||
}
|
}
|
||||||
return bison_args;
|
return bison_args;
|
||||||
@ -264,7 +265,7 @@ static int copy_designs(pass_to_bison *bison_args, design_t **r_result, size_t *
|
|||||||
|
|
||||||
design_t *parse_config_files(bxstr_t *p_first_config_file, size_t *r_num_designs)
|
design_t *parse_config_files(bxstr_t *p_first_config_file, size_t *r_num_designs)
|
||||||
{
|
{
|
||||||
size_t parents_parsed = -1; /** how many parent config files have already been parsed */
|
size_t parents_parsed = -1; /* how many parent config files have already been parsed */
|
||||||
|
|
||||||
design_t *result = NULL;
|
design_t *result = NULL;
|
||||||
*r_num_designs = 0;
|
*r_num_designs = 0;
|
||||||
@ -274,12 +275,10 @@ design_t *parse_config_files(bxstr_t *p_first_config_file, size_t *r_num_designs
|
|||||||
do {
|
do {
|
||||||
pass_to_bison bison_args = parse_config_file(config_file, result, *r_num_designs);
|
pass_to_bison bison_args = parse_config_file(config_file, result, *r_num_designs);
|
||||||
++parents_parsed;
|
++parents_parsed;
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "bison_args returned: "
|
||||||
fprintf (stderr, "bison_args returned: "
|
|
||||||
".num_parent_configs=%d, .parent_configs=%p, .num_designs=%d, .designs=%p\n",
|
".num_parent_configs=%d, .parent_configs=%p, .num_designs=%d, .designs=%p\n",
|
||||||
(int) bison_args.num_parent_configs, bison_args.parent_configs,
|
(int) bison_args.num_parent_configs, bison_args.parent_configs,
|
||||||
(int) bison_args.num_designs, bison_args.designs);
|
(int) bison_args.num_designs, bison_args.designs);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (record_parent_config_files(&bison_args) != 0) {
|
if (record_parent_config_files(&bison_args) != 0) {
|
||||||
perror(PROJECT);
|
perror(PROJECT);
|
||||||
@ -289,9 +288,7 @@ design_t *parse_config_files(bxstr_t *p_first_config_file, size_t *r_num_designs
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "design count raised to: %d\n", (int) *r_num_designs);
|
||||||
fprintf (stderr, "design count raised to: %d\n", (int) *r_num_designs);
|
|
||||||
#endif
|
|
||||||
if (parents_parsed < num_parent_configs) {
|
if (parents_parsed < num_parent_configs) {
|
||||||
config_file = parent_configs[parents_parsed];
|
config_file = parent_configs[parents_parsed];
|
||||||
}
|
}
|
||||||
@ -312,4 +309,4 @@ design_t *parse_config_files(bxstr_t *p_first_config_file, size_t *r_num_designs
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*EOF*/ /* vim: set sw=4: */
|
/* vim: set sw=4: */
|
||||||
|
13
src/query.c
13
src/query.c
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
|
||||||
@ -118,12 +119,12 @@ char **parse_query(char *optarg)
|
|||||||
|
|
||||||
static int filter_by_tag(char **tags)
|
static int filter_by_tag(char **tags)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, "filter_by_tag(");
|
log_debug(__FILE__, MAIN, "filter_by_tag(");
|
||||||
for (size_t tidx = 0; tags[tidx] != NULL; ++tidx) {
|
for (size_t tidx = 0; tags[tidx] != NULL; ++tidx) {
|
||||||
fprintf(stderr, "%s%s", tidx > 0 ? ", " : "", tags[tidx]);
|
log_debug_cont(MAIN, "%s%s", tidx > 0 ? ", " : "", tags[tidx]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int result = array_contains0(opt.query, QUERY_ALL);
|
int result = array_contains0(opt.query, QUERY_ALL);
|
||||||
if (opt.query != NULL) {
|
if (opt.query != NULL) {
|
||||||
@ -146,9 +147,7 @@ static int filter_by_tag(char **tags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug_cont(MAIN, ") -> %d\n", result);
|
||||||
fprintf(stderr, ") -> %d\n", result);
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "regulex.h"
|
#include "regulex.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
@ -135,9 +136,7 @@ uint32_t *u32_regex_replace(pcre2_code *search, uint32_t *replace, uint32_t *inp
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef REGEXP_DEBUG
|
log_debug(__FILE__, REGEXP, "Reallocating output buffer from %ld to %ld UTF-32 chars\n", bufsize, outlen);
|
||||||
fprintf(stderr, "Reallocating output buffer from %ld to %ld UTF-32 chars\n", bufsize, outlen);
|
|
||||||
#endif
|
|
||||||
bufsize = outlen;
|
bufsize = outlen;
|
||||||
output = (uint32_t *) realloc(output, sizeof(uint32_t) * bufsize);
|
output = (uint32_t *) realloc(output, sizeof(uint32_t) * bufsize);
|
||||||
}
|
}
|
||||||
|
159
src/remove.c
159
src/remove.c
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
#include "detect.h"
|
#include "detect.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "remove.h"
|
#include "remove.h"
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
@ -101,74 +102,69 @@ typedef struct _remove_ctx_t {
|
|||||||
|
|
||||||
static void debug_print_remove_ctx(remove_ctx_t *ctx, char *heading)
|
static void debug_print_remove_ctx(remove_ctx_t *ctx, char *heading)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, "Remove Context %s:\n", heading);
|
log_debug(__FILE__, MAIN, "Remove Context %s:\n", heading);
|
||||||
fprintf(stderr, " - empty_side[BTOP] = %s\n", ctx->empty_side[BTOP] ? "true" : "false");
|
log_debug(__FILE__, MAIN, " - empty_side[BTOP] = %s\n", ctx->empty_side[BTOP] ? "true" : "false");
|
||||||
fprintf(stderr, " - empty_side[BRIG] = %s\n", ctx->empty_side[BRIG] ? "true" : "false");
|
log_debug(__FILE__, MAIN, " - empty_side[BRIG] = %s\n", ctx->empty_side[BRIG] ? "true" : "false");
|
||||||
fprintf(stderr, " - empty_side[BBOT] = %s\n", ctx->empty_side[BBOT] ? "true" : "false");
|
log_debug(__FILE__, MAIN, " - empty_side[BBOT] = %s\n", ctx->empty_side[BBOT] ? "true" : "false");
|
||||||
fprintf(stderr, " - empty_side[BLEF] = %s\n", ctx->empty_side[BLEF] ? "true" : "false");
|
log_debug(__FILE__, MAIN, " - empty_side[BLEF] = %s\n", ctx->empty_side[BLEF] ? "true" : "false");
|
||||||
fprintf(stderr, " - design_is_mono = %s\n", ctx->design_is_mono ? "true" : "false");
|
log_debug(__FILE__, MAIN, " - design_is_mono = %s\n", ctx->design_is_mono ? "true" : "false");
|
||||||
fprintf(stderr, " - input_is_mono = %s\n", ctx->input_is_mono ? "true" : "false");
|
log_debug(__FILE__, MAIN, " - input_is_mono = %s\n", ctx->input_is_mono ? "true" : "false");
|
||||||
fprintf(stderr, " - top_start_idx = %d\n", (int) ctx->top_start_idx);
|
log_debug(__FILE__, MAIN, " - top_start_idx = %d\n", (int) ctx->top_start_idx);
|
||||||
fprintf(stderr, " - top_end_idx = %d\n", (int) ctx->top_end_idx);
|
log_debug(__FILE__, MAIN, " - top_end_idx = %d\n", (int) ctx->top_end_idx);
|
||||||
fprintf(stderr, " - bottom_start_idx = %d\n", (int) ctx->bottom_start_idx);
|
log_debug(__FILE__, MAIN, " - bottom_start_idx = %d\n", (int) ctx->bottom_start_idx);
|
||||||
fprintf(stderr, " - bottom_end_idx = %d\n", (int) ctx->bottom_end_idx);
|
log_debug(__FILE__, MAIN, " - bottom_end_idx = %d\n", (int) ctx->bottom_end_idx);
|
||||||
fprintf(stderr, " - comp_type = %s\n", comparison_name[ctx->comp_type]);
|
log_debug(__FILE__, MAIN, " - comp_type = %s\n", comparison_name[ctx->comp_type]);
|
||||||
fprintf(stderr, " - body (%d lines):\n", (int) ctx->body_num_lines);
|
log_debug(__FILE__, MAIN, " - body (%d lines):\n", (int) ctx->body_num_lines);
|
||||||
for (size_t i = 0; i < ctx->body_num_lines; i++) {
|
for (size_t i = 0; i < ctx->body_num_lines; i++) {
|
||||||
if (ctx->body[i].input_line_used != NULL) {
|
if (ctx->body[i].input_line_used != NULL) {
|
||||||
char *out_input_line_used = u32_strconv_to_output(ctx->body[i].input_line_used);
|
char *out_input_line_used = u32_strconv_to_output(ctx->body[i].input_line_used);
|
||||||
fprintf(stderr, " - lctx: \"%s\" (%d characters)\n", out_input_line_used,
|
log_debug(__FILE__, MAIN, " - lctx: \"%s\" (%d characters)\n", out_input_line_used,
|
||||||
(int) u32_strlen(ctx->body[i].input_line_used));
|
(int) u32_strlen(ctx->body[i].input_line_used));
|
||||||
BFREE(out_input_line_used);
|
BFREE(out_input_line_used);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, " - lctx: (null)\n");
|
log_debug(__FILE__, MAIN, " - lctx: (null)\n");
|
||||||
}
|
}
|
||||||
bxstr_t *orgline = input.lines[ctx->top_end_idx + i].text;
|
bxstr_t *orgline = input.lines[ctx->top_end_idx + i].text;
|
||||||
if (orgline != NULL) {
|
if (orgline != NULL) {
|
||||||
char *out_orgline = bxs_to_output(orgline);
|
char *out_orgline = bxs_to_output(orgline);
|
||||||
fprintf(stderr, " orgl: \"%s\" (%d characters, %d columns)\n", out_orgline,
|
log_debug(__FILE__, MAIN, " orgl: \"%s\" (%d characters, %d columns)\n", out_orgline,
|
||||||
(int) orgline->num_chars, (int) orgline->num_columns);
|
(int) orgline->num_chars, (int) orgline->num_columns);
|
||||||
BFREE(out_orgline);
|
BFREE(out_orgline);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, " orgl: (null)\n");
|
log_debug(__FILE__, MAIN, " orgl: (null)\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, " west: %d-%d (quality: %d), east: %d-%d (quality: %d)\n",
|
log_debug(__FILE__, MAIN, " west: %d-%d (quality: %d), east: %d-%d (quality: %d)\n",
|
||||||
(int) ctx->body[i].west_start, (int) ctx->body[i].west_end, (int) ctx->body[i].west_quality,
|
(int) ctx->body[i].west_start, (int) ctx->body[i].west_end, (int) ctx->body[i].west_quality,
|
||||||
(int) ctx->body[i].east_start, (int) ctx->body[i].east_end, (int) ctx->body[i].east_quality);
|
(int) ctx->body[i].east_start, (int) ctx->body[i].east_end, (int) ctx->body[i].east_quality);
|
||||||
}
|
}
|
||||||
#else
|
}
|
||||||
UNUSED(ctx);
|
|
||||||
UNUSED(heading);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void debug_print_shapes_relevant(shape_line_ctx_t *shapes_relevant)
|
static void debug_print_shapes_relevant(shape_line_ctx_t *shapes_relevant)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, " shapes_relevant = {");
|
log_debug(__FILE__, MAIN, " shapes_relevant = {");
|
||||||
for (size_t ds = 0; ds < SHAPES_PER_SIDE; ds++) {
|
for (size_t ds = 0; ds < SHAPES_PER_SIDE; ds++) {
|
||||||
if (shapes_relevant[ds].empty) {
|
if (shapes_relevant[ds].empty) {
|
||||||
fprintf(stderr, "-");
|
log_debug_cont(MAIN, "-");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *out_shp_text = bxs_to_output(shapes_relevant[ds].text);
|
char *out_shp_text = bxs_to_output(shapes_relevant[ds].text);
|
||||||
fprintf(stderr, "\"%s\"(%d%s)", out_shp_text, (int) shapes_relevant[ds].text->num_chars,
|
log_debug_cont(MAIN, "\"%s\"(%d%s)", out_shp_text, (int) shapes_relevant[ds].text->num_chars,
|
||||||
shapes_relevant[ds].elastic ? "E" : "");
|
shapes_relevant[ds].elastic ? "E" : "");
|
||||||
BFREE(out_shp_text);
|
BFREE(out_shp_text);
|
||||||
}
|
}
|
||||||
if (ds < SHAPES_PER_SIDE - 1) {
|
if (ds < SHAPES_PER_SIDE - 1) {
|
||||||
fprintf(stderr, ", ");
|
log_debug_cont(MAIN, ", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "}\n");
|
log_debug_cont(MAIN, "}\n");
|
||||||
#else
|
}
|
||||||
UNUSED(shapes_relevant);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -315,14 +311,14 @@ static int hmm_shiftable(shape_line_ctx_t *shapes_relevant, uint32_t *cur_pos, s
|
|||||||
int hmm(shape_line_ctx_t *shapes_relevant, uint32_t *cur_pos, size_t shape_idx, uint32_t *end_pos, int anchored_left,
|
int hmm(shape_line_ctx_t *shapes_relevant, uint32_t *cur_pos, size_t shape_idx, uint32_t *end_pos, int anchored_left,
|
||||||
int anchored_right)
|
int anchored_right)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
char *out_cur_pos = u32_strconv_to_output(cur_pos);
|
char *out_cur_pos = u32_strconv_to_output(cur_pos);
|
||||||
char *out_end_pos = u32_strconv_to_output(end_pos);
|
char *out_end_pos = u32_strconv_to_output(end_pos);
|
||||||
fprintf(stderr, "hmm(shapes_relevant, \"%s\", %d, \"%s\", %s, %s) - enter\n", out_cur_pos,
|
log_debug(__FILE__, MAIN, "hmm(shapes_relevant, \"%s\", %d, \"%s\", %s, %s) - enter\n", out_cur_pos,
|
||||||
(int) shape_idx, out_end_pos, anchored_left ? "true" : "false", anchored_right ? "true" : "false");
|
(int) shape_idx, out_end_pos, anchored_left ? "true" : "false", anchored_right ? "true" : "false");
|
||||||
BFREE(out_cur_pos);
|
BFREE(out_cur_pos);
|
||||||
BFREE(out_end_pos);
|
BFREE(out_end_pos);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (!anchored_left) {
|
if (!anchored_left) {
|
||||||
@ -371,11 +367,12 @@ int hmm(shape_line_ctx_t *shapes_relevant, uint32_t *cur_pos, size_t shape_idx,
|
|||||||
}
|
}
|
||||||
else if (!anchored_right) {
|
else if (!anchored_right) {
|
||||||
shape_line = shorten(shapes_relevant + shape_idx, &quality, 0, 0, 1);
|
shape_line = shorten(shapes_relevant + shape_idx, &quality, 0, 0, 1);
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
char *out_shape_line = u32_strconv_to_output(shape_line);
|
char *out_shape_line = u32_strconv_to_output(shape_line);
|
||||||
fprintf(stderr, "hmm() - shape_line shortened to %d (\"%s\")\n", (int) quality, out_shape_line);
|
log_debug(__FILE__, MAIN, "hmm() - shape_line shortened to %d (\"%s\")\n",
|
||||||
|
(int) quality, out_shape_line);
|
||||||
BFREE(out_shape_line);
|
BFREE(out_shape_line);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BFREE(shape_line);
|
BFREE(shape_line);
|
||||||
@ -383,9 +380,7 @@ int hmm(shape_line_ctx_t *shapes_relevant, uint32_t *cur_pos, size_t shape_idx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "hmm() - exit, result = %d\n", result);
|
||||||
fprintf(stderr, "hmm() - exit, result = %d\n", result);
|
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,10 +515,8 @@ match_result_t *match_outer_shape(int vside, bxstr_t *input_line, bxstr_t *shape
|
|||||||
|
|
||||||
static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx, size_t shape_line_idx)
|
static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx, size_t shape_line_idx)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "match_horiz_line(ctx, %s, %d, %d)\n",
|
||||||
fprintf(stderr, "match_horiz_line(ctx, %s, %d, %d)\n",
|
|
||||||
hside == BTOP ? "BTOP" : "BBOT", (int) input_line_idx, (int) shape_line_idx);
|
hside == BTOP ? "BTOP" : "BBOT", (int) input_line_idx, (int) shape_line_idx);
|
||||||
#endif
|
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (comparison_t comp_type = 0; comp_type < NUM_COMPARISON_TYPES; comp_type++) {
|
for (comparison_t comp_type = 0; comp_type < NUM_COMPARISON_TYPES; comp_type++) {
|
||||||
@ -531,9 +524,7 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ctx->comp_type = comp_type;
|
ctx->comp_type = comp_type;
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, " Setting comparison type to: %s\n", comparison_name[comp_type]);
|
||||||
fprintf(stderr, " Setting comparison type to: %s\n", comparison_name[comp_type]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
shape_line_ctx_t *shapes_relevant = prepare_comp_shapes_horiz(hside, comp_type, shape_line_idx);
|
shape_line_ctx_t *shapes_relevant = prepare_comp_shapes_horiz(hside, comp_type, shape_line_idx);
|
||||||
debug_print_shapes_relevant(shapes_relevant);
|
debug_print_shapes_relevant(shapes_relevant);
|
||||||
@ -542,11 +533,11 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx,
|
|||||||
bxstr_t *input_prepped = bxs_rtrim(input_prepped1);
|
bxstr_t *input_prepped = bxs_rtrim(input_prepped1);
|
||||||
bxs_append_spaces(input_prepped, opt.design->shape[NW].width + opt.design->shape[NE].width);
|
bxs_append_spaces(input_prepped, opt.design->shape[NW].width + opt.design->shape[NE].width);
|
||||||
bxs_free(input_prepped1);
|
bxs_free(input_prepped1);
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
char *out_input_prepped = bxs_to_output(input_prepped);
|
char *out_input_prepped = bxs_to_output(input_prepped);
|
||||||
fprintf(stderr, " input_prepped = \"%s\"\n", out_input_prepped);
|
log_debug(__FILE__, MAIN, " input_prepped = \"%s\"\n", out_input_prepped);
|
||||||
BFREE(out_input_prepped);
|
BFREE(out_input_prepped);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
uint32_t *cur_pos = input_prepped->memory;
|
uint32_t *cur_pos = input_prepped->memory;
|
||||||
match_result_t *mrl = NULL;
|
match_result_t *mrl = NULL;
|
||||||
@ -565,14 +556,16 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx,
|
|||||||
end_pos = mrr->p;
|
end_pos = mrr->p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
char *out_cur_pos = u32_strconv_to_output(cur_pos);
|
char *out_cur_pos = u32_strconv_to_output(cur_pos);
|
||||||
char *out_end_pos = u32_strconv_to_output(end_pos);
|
char *out_end_pos = u32_strconv_to_output(end_pos);
|
||||||
fprintf(stderr, " cur_pos = \"%s\" (index %d)\n", out_cur_pos, (int) BMAX(cur_pos - input_prepped->memory, 0));
|
log_debug(__FILE__, MAIN, " cur_pos = \"%s\" (index %d)\n",
|
||||||
fprintf(stderr, " end_pos = \"%s\" (index %d)\n", out_end_pos, (int) BMAX(end_pos - input_prepped->memory, 0));
|
out_cur_pos, (int) BMAX(cur_pos - input_prepped->memory, 0));
|
||||||
|
log_debug(__FILE__, MAIN, " end_pos = \"%s\" (index %d)\n",
|
||||||
|
out_end_pos, (int) BMAX(end_pos - input_prepped->memory, 0));
|
||||||
BFREE(out_cur_pos);
|
BFREE(out_cur_pos);
|
||||||
BFREE(out_end_pos);
|
BFREE(out_end_pos);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
result = hmm(shapes_relevant, cur_pos, 1, end_pos, (mrl == NULL) || mrl->shiftable ? 0 : 1,
|
result = hmm(shapes_relevant, cur_pos, 1, end_pos, (mrl == NULL) || mrl->shiftable ? 0 : 1,
|
||||||
(mrr == NULL) || mrr->shiftable ? 0 : 1);
|
(mrr == NULL) || mrr->shiftable ? 0 : 1);
|
||||||
@ -585,10 +578,8 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx,
|
|||||||
BFREE(shapes_relevant);
|
BFREE(shapes_relevant);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Matched %s side line using comp_type=%s and shape_line_idx=%d\n",
|
||||||
fprintf(stderr, "Matched %s side line using comp_type=%s and shape_line_idx=%d\n",
|
|
||||||
hside == BTOP ? "top" : "bottom", comparison_name[comp_type], (int) shape_line_idx);
|
hside == BTOP ? "top" : "bottom", comparison_name[comp_type], (int) shape_line_idx);
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -798,10 +789,9 @@ static int sufficient_body_quality(remove_ctx_t *ctx)
|
|||||||
/* If we manage to match 50%, then it is unlikely to improve with a different comparison mode. */
|
/* If we manage to match 50%, then it is unlikely to improve with a different comparison mode. */
|
||||||
int sufficient = (max_quality == 0 && total_quality == 0)
|
int sufficient = (max_quality == 0 && total_quality == 0)
|
||||||
|| (max_quality > 0 && (total_quality > 0.5 * max_quality));
|
|| (max_quality > 0 && (total_quality > 0.5 * max_quality));
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "sufficient_body_quality() found body match quality of %d/%d (%s).\n",
|
||||||
fprintf(stderr, "sufficient_body_quality() found body match quality of %d/%d (%s).\n",
|
|
||||||
(int) total_quality, (int) max_quality, sufficient ? "sufficient" : "NOT sufficient");
|
(int) total_quality, (int) max_quality, sufficient ? "sufficient" : "NOT sufficient");
|
||||||
#endif
|
|
||||||
return sufficient;
|
return sufficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,9 +822,7 @@ static void find_vertical_shapes(remove_ctx_t *ctx)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ctx->comp_type = comp_type;
|
ctx->comp_type = comp_type;
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "find_vertical_shapes(): comp_type = %s\n", comparison_name[comp_type]);
|
||||||
fprintf(stderr, "find_vertical_shapes(): comp_type = %s\n", comparison_name[comp_type]);
|
|
||||||
#endif
|
|
||||||
reset_body(ctx);
|
reset_body(ctx);
|
||||||
|
|
||||||
shape_line_ctx_t **shape_lines_west = NULL;
|
shape_line_ctx_t **shape_lines_west = NULL;
|
||||||
@ -883,20 +871,16 @@ static void detect_design_if_needed()
|
|||||||
design_t *tmp = autodetect_design();
|
design_t *tmp = autodetect_design();
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
opt.design = tmp;
|
opt.design = tmp;
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Design autodetection: Removing box of design \"%s\".\n", opt.design->name);
|
||||||
fprintf(stderr, "Design autodetection: Removing box of design \"%s\".\n", opt.design->name);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: Box design autodetection failed. Use -d option.\n", PROJECT);
|
fprintf(stderr, "%s: Box design autodetection failed. Use -d option.\n", PROJECT);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Design was chosen by user: %s\n", opt.design->name);
|
log_debug(__FILE__, MAIN, "Design was chosen by user: %s\n", opt.design->name);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -926,9 +910,7 @@ static void killblank(remove_ctx_t *ctx)
|
|||||||
while (ctx->top_end_idx < ctx->bottom_start_idx && lines_removed < max_lines_removable
|
while (ctx->top_end_idx < ctx->bottom_start_idx && lines_removed < max_lines_removable
|
||||||
&& empty_line(input.lines + ctx->top_end_idx))
|
&& empty_line(input.lines + ctx->top_end_idx))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Killing leading blank line in box body.\n");
|
||||||
fprintf(stderr, "Killing leading blank line in box body.\n");
|
|
||||||
#endif
|
|
||||||
++(ctx->top_end_idx);
|
++(ctx->top_end_idx);
|
||||||
--(ctx->body_num_lines);
|
--(ctx->body_num_lines);
|
||||||
++lines_removed;
|
++lines_removed;
|
||||||
@ -939,9 +921,7 @@ static void killblank(remove_ctx_t *ctx)
|
|||||||
while (ctx->bottom_start_idx > ctx->top_end_idx && lines_removed < max_lines_removable
|
while (ctx->bottom_start_idx > ctx->top_end_idx && lines_removed < max_lines_removable
|
||||||
&& empty_line(input.lines + ctx->bottom_start_idx - 1))
|
&& empty_line(input.lines + ctx->bottom_start_idx - 1))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Killing trailing blank line in box body.\n");
|
||||||
fprintf(stderr, "Killing trailing blank line in box body.\n");
|
|
||||||
#endif
|
|
||||||
--(ctx->bottom_start_idx);
|
--(ctx->bottom_start_idx);
|
||||||
--(ctx->body_num_lines);
|
--(ctx->body_num_lines);
|
||||||
++lines_removed;
|
++lines_removed;
|
||||||
@ -1038,11 +1018,9 @@ static void remove_vertical_from_input(remove_ctx_t *ctx)
|
|||||||
bxstr_t *org_line = input.lines[input_line_idx].text;
|
bxstr_t *org_line = input.lines[input_line_idx].text;
|
||||||
size_t s_idx = calculate_start_idx(ctx, body_line_idx);
|
size_t s_idx = calculate_start_idx(ctx, body_line_idx);
|
||||||
size_t e_idx = calculate_end_idx(ctx, body_line_idx);
|
size_t e_idx = calculate_end_idx(ctx, body_line_idx);
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "remove_vertical_from_input(): body_line_idx=%d, input_line_idx=%d, s_idx=%d, "
|
||||||
fprintf(stderr, "remove_vertical_from_input(): body_line_idx=%d, input_line_idx=%d, s_idx=%d, e_idx=%d, "
|
"e_idx=%d, input.indent=%d\n", (int) body_line_idx, (int) input_line_idx, (int) s_idx, (int) e_idx,
|
||||||
"input.indent=%d\n", (int) body_line_idx, (int) input_line_idx, (int) s_idx, (int) e_idx,
|
|
||||||
(int) input.indent);
|
(int) input.indent);
|
||||||
#endif
|
|
||||||
|
|
||||||
bxstr_t *temp2 = bxs_substr(org_line, s_idx, e_idx);
|
bxstr_t *temp2 = bxs_substr(org_line, s_idx, e_idx);
|
||||||
if (opt.indentmode == 'b' || opt.indentmode == '\0') {
|
if (opt.indentmode == 'b' || opt.indentmode == '\0') {
|
||||||
@ -1123,10 +1101,10 @@ static void apply_results_to_input(remove_ctx_t *ctx)
|
|||||||
+ BMAX(ctx->bottom_end_idx - ctx->bottom_start_idx, (size_t) 0);
|
+ BMAX(ctx->bottom_end_idx - ctx->bottom_start_idx, (size_t) 0);
|
||||||
memset(input.lines + input.num_lines, 0, num_lines_removed * sizeof(line_t));
|
memset(input.lines + input.num_lines, 0, num_lines_removed * sizeof(line_t));
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
print_input_lines(" (remove_box) after box removal");
|
print_input_lines(" (remove_box) after box removal");
|
||||||
fprintf(stderr, "Number of lines shrunk by %d.\n", (int) num_lines_removed);
|
log_debug(__FILE__, MAIN, "Number of lines shrunk by %d.\n", (int) num_lines_removed);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1140,10 +1118,8 @@ int remove_box()
|
|||||||
ctx->empty_side[BRIG] = empty_side(opt.design->shape, BRIG);
|
ctx->empty_side[BRIG] = empty_side(opt.design->shape, BRIG);
|
||||||
ctx->empty_side[BBOT] = empty_side(opt.design->shape, BBOT);
|
ctx->empty_side[BBOT] = empty_side(opt.design->shape, BBOT);
|
||||||
ctx->empty_side[BLEF] = empty_side(opt.design->shape, BLEF);
|
ctx->empty_side[BLEF] = empty_side(opt.design->shape, BLEF);
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "Empty sides? Top: %d, Right: %d, Bottom: %d, Left: %d\n",
|
||||||
fprintf(stderr, "Empty sides? Top: %d, Right: %d, Bottom: %d, Left: %d\n",
|
|
||||||
ctx->empty_side[BTOP], ctx->empty_side[BRIG], ctx->empty_side[BBOT], ctx->empty_side[BLEF]);
|
ctx->empty_side[BTOP], ctx->empty_side[BRIG], ctx->empty_side[BBOT], ctx->empty_side[BLEF]);
|
||||||
#endif
|
|
||||||
|
|
||||||
ctx->design_is_mono = design_is_mono(opt.design);
|
ctx->design_is_mono = design_is_mono(opt.design);
|
||||||
ctx->input_is_mono = input_is_mono();
|
ctx->input_is_mono = input_is_mono();
|
||||||
@ -1159,10 +1135,8 @@ int remove_box()
|
|||||||
else {
|
else {
|
||||||
ctx->top_end_idx = find_top_side(ctx);
|
ctx->top_end_idx = find_top_side(ctx);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "ctx->top_start_idx = %d, ctx->top_end_idx = %d\n", (int) ctx->top_start_idx,
|
||||||
fprintf(stderr, "ctx->top_start_idx = %d, ctx->top_end_idx = %d\n", (int) ctx->top_start_idx,
|
|
||||||
(int) ctx->top_end_idx);
|
(int) ctx->top_end_idx);
|
||||||
#endif
|
|
||||||
|
|
||||||
ctx->bottom_end_idx = find_last_line() + 1;
|
ctx->bottom_end_idx = find_last_line() + 1;
|
||||||
if (ctx->empty_side[BBOT]) {
|
if (ctx->empty_side[BBOT]) {
|
||||||
@ -1171,10 +1145,8 @@ int remove_box()
|
|||||||
else {
|
else {
|
||||||
ctx->bottom_start_idx = find_bottom_side(ctx);
|
ctx->bottom_start_idx = find_bottom_side(ctx);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "ctx->bottom_start_idx = %d, ctx->bottom_end_idx = %d\n", (int) ctx->bottom_start_idx,
|
||||||
fprintf(stderr, "ctx->bottom_start_idx = %d, ctx->bottom_end_idx = %d\n", (int) ctx->bottom_start_idx,
|
|
||||||
(int) ctx->bottom_end_idx);
|
(int) ctx->bottom_end_idx);
|
||||||
#endif
|
|
||||||
if (ctx->bottom_start_idx > ctx->top_end_idx) {
|
if (ctx->bottom_start_idx > ctx->top_end_idx) {
|
||||||
ctx->body_num_lines = ctx->bottom_start_idx - ctx->top_end_idx;
|
ctx->body_num_lines = ctx->bottom_start_idx - ctx->top_end_idx;
|
||||||
}
|
}
|
||||||
@ -1204,9 +1176,8 @@ void output_input(const int trim_only)
|
|||||||
size_t indent;
|
size_t indent;
|
||||||
int ntabs, nspcs;
|
int ntabs, nspcs;
|
||||||
|
|
||||||
#ifdef DEBUG
|
log_debug(__FILE__, MAIN, "output_input() - enter (trim_only=%d)\n", trim_only);
|
||||||
fprintf(stderr, "output_input() - enter (trim_only=%d)\n", trim_only);
|
|
||||||
#endif
|
|
||||||
for (size_t j = 0; j < input.num_lines; ++j) {
|
for (size_t j = 0; j < input.num_lines; ++j) {
|
||||||
if (input.lines[j].text == NULL) {
|
if (input.lines[j].text == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
59
src/shape.c
59
src/shape.c
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
#include "bxstring.h"
|
#include "bxstring.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
@ -248,10 +249,6 @@ size_t highest(const sentry_t *sarr, const int n, ...)
|
|||||||
int i;
|
int i;
|
||||||
size_t max = 0; /* current maximum height */
|
size_t max = 0; /* current maximum height */
|
||||||
|
|
||||||
#if defined(DEBUG) && 0
|
|
||||||
fprintf (stderr, "highest (%d, ...)\n", n);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
va_start (ap, n);
|
va_start (ap, n);
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
@ -287,10 +284,6 @@ size_t widest(const sentry_t *sarr, const int n, ...)
|
|||||||
int i;
|
int i;
|
||||||
size_t max = 0; /* current maximum width */
|
size_t max = 0; /* current maximum width */
|
||||||
|
|
||||||
#if defined(DEBUG) && 0
|
|
||||||
fprintf (stderr, "widest (%d, ...)\n", n);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
va_start (ap, n);
|
va_start (ap, n);
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
@ -470,66 +463,64 @@ int is_blankward(design_t *current_design, const shape_t shape, const size_t sha
|
|||||||
|
|
||||||
void debug_print_shape(sentry_t *shape)
|
void debug_print_shape(sentry_t *shape)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (is_debug_logging(MAIN)) {
|
||||||
if (shape == NULL) {
|
if (shape == NULL) {
|
||||||
fprintf(stderr, "NULL\n");
|
log_debug(__FILE__, MAIN, "NULL\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Shape %3s (%dx%d): elastic=%s, bl=",
|
log_debug(__FILE__, MAIN, "Shape %3s (%dx%d): elastic=%s, bl=",
|
||||||
shape_name[shape->name], (int) shape->width, (int) shape->height, shape->elastic ? "true" : "false");
|
shape_name[shape->name], (int) shape->width, (int) shape->height, shape->elastic ? "true" : "false");
|
||||||
if (shape->blank_leftward == NULL) {
|
if (shape->blank_leftward == NULL) {
|
||||||
fprintf(stderr, "NULL");
|
log_debug_cont(MAIN, "NULL");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "[");
|
log_debug_cont(MAIN, "[");
|
||||||
for (size_t i = 0; i < shape->height; i++) {
|
for (size_t i = 0; i < shape->height; i++) {
|
||||||
fprintf(stderr, "%d%s", shape->blank_leftward[i],
|
log_debug_cont(MAIN, "%d%s", shape->blank_leftward[i],
|
||||||
shape->height > 0 && i < (shape->height - 1) ? ", " : "");
|
shape->height > 0 && i < (shape->height - 1) ? ", " : "");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]");
|
log_debug_cont(MAIN, "]");
|
||||||
}
|
}
|
||||||
fprintf(stderr, ", br=");
|
log_debug_cont(MAIN, ", br=");
|
||||||
if (shape->blank_rightward == NULL) {
|
if (shape->blank_rightward == NULL) {
|
||||||
fprintf(stderr, "NULL");
|
log_debug_cont(MAIN, "NULL");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "[");
|
log_debug_cont(MAIN, "[");
|
||||||
for (size_t i = 0; i < shape->height; i++) {
|
for (size_t i = 0; i < shape->height; i++) {
|
||||||
fprintf(stderr, "%d%s", shape->blank_rightward[i],
|
log_debug_cont(MAIN, "%d%s", shape->blank_rightward[i],
|
||||||
shape->height > 0 && i < (shape->height - 1) ? ", " : "");
|
shape->height > 0 && i < (shape->height - 1) ? ", " : "");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]");
|
log_debug_cont(MAIN, "]");
|
||||||
}
|
}
|
||||||
fprintf(stderr, ", ascii=");
|
log_debug_cont(MAIN, ", ascii=");
|
||||||
if (shape->chars == NULL) {
|
if (shape->chars == NULL) {
|
||||||
fprintf(stderr, "NULL");
|
log_debug_cont(MAIN, "NULL");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "[");
|
log_debug_cont(MAIN, "[");
|
||||||
for (size_t i = 0; i < shape->height; i++) {
|
for (size_t i = 0; i < shape->height; i++) {
|
||||||
fprintf(stderr, "%s%s%s%s", shape->chars[i] != NULL ? "\"" : "", shape->chars[i],
|
log_debug_cont(MAIN, "%s%s%s%s", shape->chars[i] != NULL ? "\"" : "", shape->chars[i],
|
||||||
shape->chars[i] != NULL ? "\"" : "", (int) i < ((int) shape->height) - 1 ? ", " : "");
|
shape->chars[i] != NULL ? "\"" : "", (int) i < ((int) shape->height) - 1 ? ", " : "");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]");
|
log_debug_cont(MAIN, "]");
|
||||||
}
|
}
|
||||||
fprintf(stderr, ", mbcs=");
|
log_debug_cont(MAIN, ", mbcs=");
|
||||||
if (shape->mbcs == NULL) {
|
if (shape->mbcs == NULL) {
|
||||||
fprintf(stderr, "NULL");
|
log_debug_cont(MAIN, "NULL");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "[");
|
log_debug_cont(MAIN, "[");
|
||||||
for (size_t i = 0; i < shape->height; i++) {
|
for (size_t i = 0; i < shape->height; i++) {
|
||||||
char *out_mbcs = bxs_to_output(shape->mbcs[i]);
|
char *out_mbcs = bxs_to_output(shape->mbcs[i]);
|
||||||
fprintf(stderr, "%s%s%s%s", shape->mbcs[i] != NULL ? "\"" : "", out_mbcs,
|
log_debug_cont(MAIN, "%s%s%s%s", shape->mbcs[i] != NULL ? "\"" : "", out_mbcs,
|
||||||
shape->mbcs[i] != NULL ? "\"" : "", shape->height > 0 && i < (shape->height - 1) ? ", " : "");
|
shape->mbcs[i] != NULL ? "\"" : "", shape->height > 0 && i < (shape->height - 1) ? ", " : "");
|
||||||
BFREE(out_mbcs);
|
BFREE(out_mbcs);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]");
|
log_debug_cont(MAIN, "]");
|
||||||
|
}
|
||||||
|
log_debug_cont(MAIN, "\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
|
||||||
#else
|
|
||||||
UNUSED(shape);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
49
src/tools.c
49
src/tools.c
@ -32,6 +32,7 @@
|
|||||||
#include <uniwidth.h>
|
#include <uniwidth.h>
|
||||||
|
|
||||||
#include "boxes.h"
|
#include "boxes.h"
|
||||||
|
#include "logging.h"
|
||||||
#include "regulex.h"
|
#include "regulex.h"
|
||||||
#include "shape.h"
|
#include "shape.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
@ -409,67 +410,65 @@ char *nspaces(const size_t n)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(DEBUG) || 0
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debugging Code: Display contents of input structure
|
* Debugging Code: Display contents of input structure
|
||||||
* @param heading a heading to show for identification of the printed lines
|
* @param heading a heading to show for identification of the printed lines
|
||||||
*/
|
*/
|
||||||
void print_input_lines(const char *heading)
|
void print_input_lines(const char *heading)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%d Input Lines%s:\n", (int) input.num_lines, heading != NULL ? heading : "");
|
if (is_debug_logging(MAIN)) {
|
||||||
fprintf(stderr, " [num_chars] \"real text\" [num_cols] \"ascii_text\"\n");
|
log_debug(__FILE__, MAIN, "%d Input Lines%s:\n", (int) input.num_lines, heading != NULL ? heading : "");
|
||||||
|
log_debug(__FILE__, MAIN, " [num_chars] \"real text\" [num_cols] \"ascii_text\"\n");
|
||||||
for (size_t i = 0; i < input.num_lines; ++i) {
|
for (size_t i = 0; i < input.num_lines; ++i) {
|
||||||
char *outtext = bxs_to_output(input.lines[i].text);
|
char *outtext = bxs_to_output(input.lines[i].text);
|
||||||
fprintf(stderr, "%4d [%02d] \"%s\" [%02d] \"%s\"", (int) i,
|
log_debug(__FILE__, MAIN, "%4d [%02d] \"%s\" [%02d] \"%s\"", (int) i,
|
||||||
(int) input.lines[i].text->num_chars, outtext,
|
(int) input.lines[i].text->num_chars, outtext,
|
||||||
(int) input.lines[i].text->num_columns, input.lines[i].text->ascii);
|
(int) input.lines[i].text->num_columns, input.lines[i].text->ascii);
|
||||||
BFREE(outtext);
|
BFREE(outtext);
|
||||||
fprintf(stderr, "\tTabs: [");
|
log_debug_cont(MAIN, "\tTabs: [");
|
||||||
if (input.lines[i].tabpos != NULL) {
|
if (input.lines[i].tabpos != NULL) {
|
||||||
for (size_t j = 0; j < input.lines[i].tabpos_len; ++j) {
|
for (size_t j = 0; j < input.lines[i].tabpos_len; ++j) {
|
||||||
fprintf(stderr, "%d", (int) input.lines[i].tabpos[j]);
|
log_debug_cont(MAIN, "%d", (int) input.lines[i].tabpos[j]);
|
||||||
if (j < input.lines[i].tabpos_len - 1) {
|
if (j < input.lines[i].tabpos_len - 1) {
|
||||||
fprintf(stderr, ", ");
|
log_debug_cont(MAIN, ", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "] (%d)", (int) input.lines[i].tabpos_len);
|
log_debug_cont(MAIN, "] (%d)", (int) input.lines[i].tabpos_len);
|
||||||
fprintf(stderr, "\tinvisible=%d\n", (int) input.lines[i].text->num_chars_invisible);
|
log_debug_cont(MAIN, "\tinvisible=%d\n", (int) input.lines[i].text->num_chars_invisible);
|
||||||
|
|
||||||
fprintf(stderr, " visible_char=");
|
log_debug(__FILE__, MAIN, " visible_char=");
|
||||||
if (input.lines[i].text->visible_char != NULL) {
|
if (input.lines[i].text->visible_char != NULL) {
|
||||||
fprintf(stderr, "[");
|
log_debug_cont(MAIN, "[");
|
||||||
for (size_t j = 0; j < input.lines[i].text->num_chars_visible; j++) {
|
for (size_t j = 0; j < input.lines[i].text->num_chars_visible; j++) {
|
||||||
fprintf(stderr, "%d%s", (int) input.lines[i].text->visible_char[j],
|
log_debug_cont(MAIN, "%d%s", (int) input.lines[i].text->visible_char[j],
|
||||||
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]\n");
|
log_debug_cont(MAIN, "]\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "null\n");
|
log_debug_cont(MAIN, "null\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, " first_char=");
|
log_debug(__FILE__, MAIN, " first_char=");
|
||||||
if (input.lines[i].text->first_char != NULL) {
|
if (input.lines[i].text->first_char != NULL) {
|
||||||
fprintf(stderr, "[");
|
log_debug_cont(MAIN, "[");
|
||||||
for (size_t j = 0; j < input.lines[i].text->num_chars_visible; j++) {
|
for (size_t j = 0; j < input.lines[i].text->num_chars_visible; j++) {
|
||||||
fprintf(stderr, "%d%s", (int) input.lines[i].text->first_char[j],
|
log_debug_cont(MAIN, "%d%s", (int) input.lines[i].text->first_char[j],
|
||||||
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "]\n");
|
log_debug_cont(MAIN, "]\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "null\n");
|
log_debug_cont(MAIN, "null\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, " Longest line: %d columns\n", (int) input.maxline);
|
log_debug(__FILE__, MAIN, " Longest line: %d columns\n", (int) input.maxline);
|
||||||
fprintf(stderr, " Indentation: %2d spaces\n", (int) input.indent);
|
log_debug(__FILE__, MAIN, " Indentation: %2d spaces\n", (int) input.indent);
|
||||||
fprintf(stderr, "Final newline: %s\n", input.final_newline ? "yes" : "no");
|
log_debug(__FILE__, MAIN, "Final newline: %s\n", input.final_newline ? "yes" : "no");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user