mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-04 05:54:06 +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": [
|
||||
"_DEBUG",
|
||||
"DEBUG",
|
||||
"REGEXP_DEBUG",
|
||||
"PARSER_DEBUG",
|
||||
"LEXER_DEBUG",
|
||||
"DISCOVERY_DEBUG",
|
||||
"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) --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
|
||||
cmdline.o: cmdline.c cmdline.h boxes.h discovery.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
|
||||
discovery.o: discovery.c discovery.h boxes.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
|
||||
input.o: input.c boxes.h input.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
|
||||
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 logging.h shape.h tools.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 logging.h shape.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 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
|
||||
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
|
||||
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
|
||||
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h tools.h config.h | check_dir
|
||||
query.o: query.c query.h boxes.h list.h tools.h config.h | check_dir
|
||||
regulex.o: regulex.c regulex.h boxes.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
|
||||
shape.o: shape.c shape.h boxes.h bxstring.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
|
||||
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 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 logging.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 logging.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 logging.h tools.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
|
||||
|
||||
|
||||
|
50
src/boxes.c
50
src/boxes.c
@ -35,6 +35,7 @@
|
||||
#include "generate.h"
|
||||
#include "input.h"
|
||||
#include "list.h"
|
||||
#include "logging.h"
|
||||
#include "parsing.h"
|
||||
#include "query.h"
|
||||
#include "remove.h"
|
||||
@ -156,7 +157,7 @@ static int build_design(design_t **adesigns, const char *cld)
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||
return 1; /* never happens ;-) */
|
||||
return 1;
|
||||
}
|
||||
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[])
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Processing Command Line ...\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Processing Command Line ...\n");
|
||||
|
||||
opt_t *parsed_opts = process_commandline(argc, argv);
|
||||
if (parsed_opts == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -269,9 +269,8 @@ static void apply_expected_size()
|
||||
*/
|
||||
static void handle_input()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Reading all input ...\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Reading all input ...\n");
|
||||
|
||||
input_t *raw_input = NULL;
|
||||
if (opt.mend != 0) {
|
||||
raw_input = read_all_input();
|
||||
@ -287,10 +286,10 @@ static void handle_input()
|
||||
BFREE(raw_input);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Effective encoding: %s\n", encoding);
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "Effective encoding: %s\n", encoding);
|
||||
print_input_lines(NULL);
|
||||
#endif
|
||||
}
|
||||
if (input.num_lines == 0) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@ -362,9 +361,8 @@ static void adjust_size_and_padding()
|
||||
*/
|
||||
static void handle_generate_box()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Generating Box ...\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Generating Box ...\n");
|
||||
|
||||
sentry_t *thebox = (sentry_t *) calloc(NUM_SIDES, sizeof(sentry_t));
|
||||
if (thebox == NULL) {
|
||||
perror(PROJECT);
|
||||
@ -384,9 +382,8 @@ static void handle_generate_box()
|
||||
*/
|
||||
static void handle_remove_box()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Removing Box ...\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Removing Box ...\n");
|
||||
|
||||
if (opt.killblank == -1) {
|
||||
if (empty_side(opt.design->shape, BTOP) && empty_side(opt.design->shape, BBOT)) {
|
||||
opt.killblank = 0;
|
||||
@ -425,15 +422,16 @@ static int terminal_has_colors()
|
||||
result = 1;
|
||||
}
|
||||
#endif
|
||||
#if defined(DEBUG)
|
||||
|
||||
if (is_debug_logging(MAIN)) {
|
||||
#ifdef __MINGW32__
|
||||
int num_colors = 1;
|
||||
#else
|
||||
int num_colors = result ? tigetnum("colors") : 0;
|
||||
#endif
|
||||
fprintf(stderr, "Terminal \"%s\" %s colors (number of colors = %d).\n", termtype != NULL ? termtype : "(null)",
|
||||
result ? "has" : "does NOT have", num_colors);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Terminal \"%s\" %s colors (number of colors = %d).\n",
|
||||
termtype != NULL ? termtype : "(null)", result ? "has" : "does NOT have", num_colors);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -449,9 +447,7 @@ static int check_color_support(int opt_color)
|
||||
result = terminal_has_colors();
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
fprintf(stderr, "%s: Color support %sabled\n", PROJECT, result ? "\x1b[92mEN\x1b[0m" : "DIS");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Color support %sabled\n", result ? "\x1b[92mEN\x1b[0m" : "DIS");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -485,9 +481,7 @@ int main(int argc, char *argv[])
|
||||
int saved_designwidth; /* opt.design->minwith backup, used for mending */
|
||||
int saved_designheight; /* opt.design->minheight backup, used for mending */
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "BOXES STARTING ...\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "BOXES STARTING ...\n"); /* TODO This line will never execute, because debug not on yet */
|
||||
|
||||
/* Temporarily set the system encoding, for proper output of --help text etc. */
|
||||
activateSystemEncoding();
|
||||
@ -497,9 +491,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Store system character encoding */
|
||||
encoding = check_encoding(opt.encoding, locale_charset());
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Character Encoding = %s\n", encoding);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Character Encoding = %s\n", encoding);
|
||||
|
||||
color_output_enabled = check_color_support(opt.color);
|
||||
|
||||
|
@ -20,12 +20,6 @@
|
||||
#ifndef 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 <unitypes.h>
|
||||
|
||||
|
@ -731,14 +731,13 @@ static void print_debug_info(opt_t *result)
|
||||
|
||||
opt_t *process_commandline(int argc, char *argv[])
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "argc = %d\n", argc);
|
||||
fprintf(stderr, "argv = [");
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "argc = %d\n", argc);
|
||||
log_debug(__FILE__, MAIN, "argv = [");
|
||||
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();
|
||||
|
||||
|
84
src/detect.c
84
src/detect.c
@ -45,6 +45,7 @@
|
||||
|
||||
#include "boxes.h"
|
||||
#include "bxstring.h"
|
||||
#include "logging.h"
|
||||
#include "shape.h"
|
||||
#include "tools.h"
|
||||
#include "unicode.h"
|
||||
@ -67,9 +68,7 @@ int input_is_mono()
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Input is %s\n", result ? "mono" : "potentially colored");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Input is %s\n", result ? "mono" : "potentially colored");
|
||||
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++) {
|
||||
bxstr_t *shape_line = design->shape[scnt].mbcs[line_no];
|
||||
if (shape_line->num_chars_invisible > 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Design is potentially colored\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Design is potentially colored\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Design is mono\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Design is mono\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -121,10 +116,8 @@ static int *determine_empty_sides(design_t *current_design)
|
||||
for (size_t j = 0; j < NUM_SIDES; ++j) {
|
||||
result[j] = empty_side(current_design->shape, j);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
|
||||
log_debug(__FILE__, MAIN, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
|
||||
result[BTOP], result[BLEF], result[BBOT], result[BRIG]);
|
||||
#endif
|
||||
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,
|
||||
size_t *out_indent, size_t *out_trailing)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "prepare_comp_input(%d, %s, %s, %d, %p, %p)", (int) input_line_idx,
|
||||
log_debug(__FILE__, MAIN, "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);
|
||||
#endif
|
||||
|
||||
if (input_line_idx >= input.num_lines) {
|
||||
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);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, " -> (null)\n");
|
||||
#endif
|
||||
log_debug_cont(MAIN, " -> (null)\n");
|
||||
return NULL;
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
|
||||
if (is_debug_logging(MAIN)) {
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -296,9 +287,7 @@ static size_t find_west_corner(design_t *current_design, comparison_t comp_type,
|
||||
BFREE(shape_relevant);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) 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;
|
||||
if (empty[BRIG] || (empty[BTOP] && corner == NE) || (empty[BBOT] && corner == SE)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||
return hits;
|
||||
}
|
||||
|
||||
@ -349,9 +336,7 @@ static size_t find_east_corner(design_t *current_design, comparison_t comp_type,
|
||||
BFREE(shape_relevant);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %s corner produced %d hits.\n", shape_name[corner], (int) hits);
|
||||
return hits;
|
||||
}
|
||||
|
||||
@ -371,9 +356,7 @@ static size_t find_horizontal_shape(design_t *current_design, comparison_t comp_
|
||||
size_t hits = 0;
|
||||
if (empty[BTOP] || empty[BBOT]) {
|
||||
/* horizontal box part is empty */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
||||
return hits;
|
||||
}
|
||||
|
||||
@ -417,9 +400,7 @@ static size_t find_horizontal_shape(design_t *current_design, comparison_t comp_
|
||||
BFREE(shape_relevant);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[hshape], (int) hits);
|
||||
return hits;
|
||||
}
|
||||
|
||||
@ -468,9 +449,7 @@ static size_t find_vertical_west(design_t *current_design, comparison_t comp_typ
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
||||
return hits;
|
||||
}
|
||||
|
||||
@ -518,9 +497,7 @@ static size_t find_vertical_east(design_t *current_design, comparison_t comp_typ
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Checking %-3s shape produced %d hits.\n", shape_name[vshape], (int) hits);
|
||||
return hits;
|
||||
}
|
||||
|
||||
@ -581,21 +558,16 @@ design_t *autodetect_design()
|
||||
for (size_t dcnt = 0; ((int) dcnt) < num_designs; ++dcnt, ++current_design) {
|
||||
int mono_design = design_is_mono(current_design);
|
||||
if (!comp_type_is_viable(comp_type, mono_input, mono_design)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Design \"%s\" skipped for comparison type '%s' because mono_input=%d and "
|
||||
log_debug(__FILE__, MAIN, "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);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "CONSIDERING DESIGN ---- \"%s\" ---------------\n", current_design->name);
|
||||
fprintf(stderr, " comparison_type = %s\n", comparison_name[comp_type]);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "CONSIDERING DESIGN ---- \"%s\" ---------------\n", current_design->name);
|
||||
log_debug(__FILE__, MAIN, " comparison_type = %s\n", comparison_name[comp_type]);
|
||||
|
||||
long hits = match_design(current_design, comp_type);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Design \"%s\" scored %ld points\n", current_design->name, hits);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Design \"%s\" scored %ld points\n", current_design->name, hits);
|
||||
if (hits > maxhits) {
|
||||
maxhits = hits;
|
||||
result = current_design;
|
||||
@ -606,14 +578,14 @@ design_t *autodetect_design()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (is_debug_logging(MAIN)) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "boxes.h"
|
||||
#include "logging.h"
|
||||
#include "tools.h"
|
||||
#include "unicode.h"
|
||||
#include "discovery.h"
|
||||
@ -40,49 +41,38 @@
|
||||
|
||||
static int can_read_file(char *filename_utf8)
|
||||
{
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "can_read_file(%s) - enter\n", filename_utf8);
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_file(%s) - enter\n", filename_utf8);
|
||||
|
||||
struct stat statbuf;
|
||||
int result = 1;
|
||||
if (filename_utf8 == NULL || filename_utf8[0] == '\0') {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: can_read_file(): argument was NULL\n", PROJECT);
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_file(): argument was NULL\n");
|
||||
result = 0;
|
||||
}
|
||||
else {
|
||||
FILE *f = bx_fopen(filename_utf8, "r");
|
||||
if (f == NULL) {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: can_read_file(): File \"%s\" could not be opened for reading - %s\n",
|
||||
PROJECT, filename_utf8, strerror(errno));
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_file(): File \"%s\" could not be opened for reading - %s\n",
|
||||
filename_utf8, strerror(errno));
|
||||
result = 0;
|
||||
}
|
||||
else {
|
||||
fclose(f);
|
||||
|
||||
if (stat(filename_utf8, &statbuf) != 0) {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: can_read_file(): File \"%s\" not statable - %s\n",
|
||||
PROJECT, filename_utf8, strerror(errno));
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_file(): File \"%s\" not statable - %s\n",
|
||||
filename_utf8, strerror(errno));
|
||||
result = 0;
|
||||
}
|
||||
else if (S_ISDIR(statbuf.st_mode)) {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: can_read_file(): File \"%s\" is in fact a directory\n", PROJECT,
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_file(): File \"%s\" is in fact a directory\n",
|
||||
filename_utf8);
|
||||
#endif
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "can_read_file() - exit -> %s\n", result ? "true" : "false");
|
||||
#endif
|
||||
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_file() - exit -> %s\n", result ? "true" : "false");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -90,33 +80,26 @@ static int can_read_file(char *filename_utf8)
|
||||
|
||||
static int can_read_dir(const char *dirname_utf8)
|
||||
{
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "can_read_dir(%s) - enter\n", dirname_utf8);
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_dir(%s) - enter\n", dirname_utf8);
|
||||
|
||||
int result = 1;
|
||||
if (dirname_utf8 == NULL || dirname_utf8[0] == '\0') {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: can_read_dir(): argument was NULL\n", PROJECT);
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_dir(): argument was NULL\n");
|
||||
result = 0;
|
||||
}
|
||||
else {
|
||||
DIR *dir = opendir(dirname_utf8);
|
||||
if (dir == NULL) {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: can_read_dir(): Directory \"%s\" could not be opened for reading - %s\n",
|
||||
PROJECT, dirname_utf8, strerror(errno));
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_dir(): Directory \"%s\" could not be opened for reading - %s\n",
|
||||
dirname_utf8, strerror(errno));
|
||||
result = 0;
|
||||
}
|
||||
else {
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "can_read_dir() - exit -> %s\n", result ? "true" : "false");
|
||||
#endif
|
||||
|
||||
log_debug(__FILE__, DISCOVERY, "can_read_dir() - exit -> %s\n", result ? "true" : "false");
|
||||
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)) {
|
||||
result = locate_config_in_dir(path_utf8);
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
@ -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)
|
||||
{
|
||||
char *result = getenv(env_var);
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "%s: from_env_var(): getenv(\"%s\") --> %s\n", PROJECT, env_var, result);
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "from_env_var(): getenv(\"%s\") --> %s\n", env_var, result);
|
||||
if (result != NULL) {
|
||||
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)
|
||||
{
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "locate_config_common() - enter\n");
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "locate_config_common() - enter\n");
|
||||
|
||||
char *result = NULL;
|
||||
if (opt.f) {
|
||||
@ -207,9 +186,7 @@ static char *locate_config_common(int *error_printed)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "locate_config_common() - exit -> [%s]\n", result != NULL ? result : "(null)");
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "locate_config_common() - exit -> [%s]\n", result != NULL ? result : "(null)");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -218,16 +195,12 @@ static char *locate_config_common(int *error_printed)
|
||||
|
||||
static char *exe_to_cfg()
|
||||
{
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "exe_to_cfg() - enter\n");
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "exe_to_cfg() - enter\n");
|
||||
|
||||
const char *fallback = "C:\\boxes.cfg";
|
||||
char *exepath = (char *) malloc(256); /* for constructing config file path */
|
||||
if (GetModuleFileName(NULL, exepath, 255) != 0) {
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "exe_to_cfg() - Found executable at %s\n", exepath);
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "exe_to_cfg() - Found executable at %s\n", exepath);
|
||||
char *p = strrchr(exepath, '.') + 1;
|
||||
if (p) {
|
||||
/* 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 */
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -244,9 +217,8 @@ static char *exe_to_cfg()
|
||||
else {
|
||||
strcpy(exepath, fallback);
|
||||
}
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "exe_to_cfg() - exit -> [%s]\n", exepath);
|
||||
#endif
|
||||
|
||||
log_debug(__FILE__, DISCOVERY, "exe_to_cfg() - exit -> [%s]\n", exepath);
|
||||
return exepath;
|
||||
}
|
||||
|
||||
@ -269,9 +241,8 @@ static bxstr_t *utf8_to_bxs(char *utf8)
|
||||
|
||||
bxstr_t *discover_config_file(const int global_only)
|
||||
{
|
||||
#ifdef DISCOVERY_DEBUG
|
||||
fprintf(stderr, "discover_config_file(%s) - enter\n", global_only ? "true" : "false");
|
||||
#endif
|
||||
log_debug(__FILE__, DISCOVERY, "discover_config_file(%s) - enter\n", global_only ? "true" : "false");
|
||||
|
||||
int error_printed = 0;
|
||||
bxstr_t *result = NULL;
|
||||
if (!global_only) {
|
||||
@ -308,7 +279,7 @@ bxstr_t *discover_config_file(const int global_only)
|
||||
if (can_read_file(exepath)) {
|
||||
result = utf8_to_bxs(exepath);
|
||||
} 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;
|
||||
}
|
||||
BFREE(exepath);
|
||||
@ -328,11 +299,14 @@ bxstr_t *discover_config_file(const int global_only)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
149
src/generate.c
149
src/generate.c
@ -27,6 +27,7 @@
|
||||
|
||||
#include "shape.h"
|
||||
#include "boxes.h"
|
||||
#include "logging.h"
|
||||
#include "tools.h"
|
||||
#include "unicode.h"
|
||||
#include "generate.h"
|
||||
@ -92,12 +93,12 @@ static int horiz_precalc(const sentry_t *sarr,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "in horiz_precalc:\n ");
|
||||
fprintf (stderr, "opt.design->minwidth %d, input.maxline %d, target_width"
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "in horiz_precalc:\n");
|
||||
log_debug(__FILE__, MAIN, " opt.design->minwidth %d, input.maxline %d, target_width"
|
||||
" %d, tnumsh %d, bnumsh %d\n", (int) opt.design->minwidth,
|
||||
(int) input.maxline, (int) target_width, tnumsh, bnumsh);
|
||||
#endif
|
||||
}
|
||||
|
||||
twidth = 0;
|
||||
bwidth = 0;
|
||||
@ -212,7 +213,7 @@ static int horiz_precalc(const sentry_t *sarr,
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s: internal error in horiz_precalc()\n", PROJECT);
|
||||
bx_fprintf(stderr, "%s: internal error in horiz_precalc()\n", PROJECT);
|
||||
return 1;
|
||||
}
|
||||
} while (twidth != bwidth || twidth < target_width || bwidth < target_width);
|
||||
@ -396,7 +397,7 @@ static int vert_precalc(const sentry_t *sarr,
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s: internal error in vert_precalc()\n", PROJECT);
|
||||
bx_fprintf(stderr, "%s: internal error in vert_precalc()\n", PROJECT);
|
||||
return 1;
|
||||
}
|
||||
} 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(iltf_copy);
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "%s side required characters: %d\n", (side == north_side) ? "Top": "Bottom", (int) result);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "%s side required characters: %d\n",
|
||||
(side == north_side) ? "Top": "Bottom", (int) result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -584,20 +584,20 @@ static int horiz_generate(sentry_t *tresult, sentry_t *bresult)
|
||||
}
|
||||
bresult->width = tresult->width;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Top side box rect width %d, height %d.\n",
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "Top side box rect width %d, height %d.\n",
|
||||
(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[2]], (int) tiltf[1],
|
||||
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);
|
||||
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[2]], (int) biltf[1],
|
||||
shape_name[south_side[3]], (int) biltf[2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
tresult->chars = (char **) calloc(tresult->height, sizeof(char *));
|
||||
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;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
/*
|
||||
* Debugging code - Output horizontal sides of box
|
||||
*/
|
||||
/*
|
||||
* Debugging code - Output horizontal sides of box
|
||||
*/
|
||||
if (is_debug_logging(MAIN)) {
|
||||
size_t j;
|
||||
fprintf(stderr, "TOP SIDE:\n");
|
||||
log_debug(__FILE__, MAIN, "TOP SIDE:\n");
|
||||
for (j = 0; j < tresult->height; ++j) {
|
||||
fprintf(stderr, " %2d: \'%s\' - \'%s\'\n", (int) j,
|
||||
bxs_to_output(tresult->mbcs[j]), tresult->chars[j]);
|
||||
char *out_sl = bxs_to_output(tresult->mbcs[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) {
|
||||
fprintf(stderr, " %2d: \'%s\' - '%s'\n", (int) j,
|
||||
bxs_to_output(bresult->mbcs[j]), bresult->chars[j]);
|
||||
char *out_sl = bxs_to_output(bresult->mbcs[j]);
|
||||
log_debug(__FILE__, MAIN, " %2d: \'%s\' - '%s'\n", (int) j, out_sl, bresult->chars[j]);
|
||||
BFREE(out_sl);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0; /* all clear */
|
||||
}
|
||||
|
||||
@ -670,20 +669,20 @@ static int vert_generate(sentry_t *lresult, sentry_t *rresult)
|
||||
rresult->height = vspace +
|
||||
opt.design->shape[NE].height + opt.design->shape[SE].height;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Left side box rect width %d, height %d, vspace %d.\n",
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "Left side box rect width %d, height %d, vspace %d.\n",
|
||||
(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[2]], (int) leftiltf[1],
|
||||
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);
|
||||
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[2]], (int) rightiltf[1],
|
||||
shape_name[east_side[3]], (int) rightiltf[2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
lresult->chars = (char **) calloc(lresult->height, sizeof(char *));
|
||||
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, east_side, rightiltf, rresult);
|
||||
|
||||
#if defined(DEBUG) && 1
|
||||
{
|
||||
/*
|
||||
* Debugging code - Output left and right side of box
|
||||
*/
|
||||
size_t j;
|
||||
fprintf(stderr, "LEFT SIDE:\n");
|
||||
for (j = 0; j < lresult->height; ++j) {
|
||||
fprintf(stderr, " %2d: \'%s\' - \'%s\'\n", (int) j,
|
||||
bxs_to_output(lresult->mbcs[j]), lresult->chars[j]);
|
||||
}
|
||||
fprintf(stderr, "RIGHT SIDE:\n");
|
||||
for (j = 0; j < rresult->height; ++j) {
|
||||
fprintf(stderr, " %2d: \'%s\' - \'%s\'\n", (int) j,
|
||||
bxs_to_output(rresult->mbcs[j]), rresult->chars[j]);
|
||||
}
|
||||
/*
|
||||
* Debugging code - Output left and right side of box
|
||||
*/
|
||||
if (is_debug_logging(MAIN)) {
|
||||
size_t j;
|
||||
log_debug(__FILE__, MAIN, "LEFT SIDE:\n");
|
||||
for (j = 0; j < lresult->height; ++j) {
|
||||
char *out_sl = bxs_to_output(lresult->mbcs[j]);
|
||||
log_debug(__FILE__, MAIN, " %2d: \'%s\' - \'%s\'\n", (int) j, out_sl, lresult->chars[j]);
|
||||
BFREE(out_sl);
|
||||
}
|
||||
#endif
|
||||
|
||||
log_debug(__FILE__, MAIN, "RIGHT SIDE:\n");
|
||||
for (j = 0; j < rresult->height; ++j) {
|
||||
char *out_sl = bxs_to_output(rresult->mbcs[j]);
|
||||
log_debug(__FILE__, MAIN, " %2d: \'%s\' - \'%s\'\n", (int) j, out_sl, rresult->chars[j]);
|
||||
BFREE(out_sl);
|
||||
}
|
||||
}
|
||||
return 0; /* all clear */
|
||||
}
|
||||
|
||||
@ -788,13 +786,14 @@ static int justify_line(line_t *line, int skew)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(DEBUG) || 0
|
||||
if (is_debug_logging(MAIN)) {
|
||||
char *outtext = bxs_to_output(line->text);
|
||||
fprintf(stderr, "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,
|
||||
line->text->ascii, (int) line->text->num_chars_invisible, skew);
|
||||
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,
|
||||
line->text->ascii, (int) line->text->num_chars_invisible, skew);
|
||||
BFREE(outtext);
|
||||
#endif
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
size_t initial_space_size = line->text->indent;
|
||||
@ -837,13 +836,11 @@ static int justify_line(line_t *line, int skew)
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#if defined(DEBUG) || 0
|
||||
fprintf (stderr, " -> %d\n", result);
|
||||
#endif
|
||||
log_debug_cont(MAIN, " -> %d\n", 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 ntabs, nspcs; /* needed for unexpand of tabs */
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Padding used: left %d, top %d, right %d, bottom %d\n",
|
||||
opt.design->padding[BLEF], opt.design->padding[BTOP],
|
||||
opt.design->padding[BRIG], opt.design->padding[BBOT]);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Padding used: left %d, top %d, right %d, bottom %d\n",
|
||||
opt.design->padding[BLEF], opt.design->padding[BTOP],
|
||||
opt.design->padding[BRIG], opt.design->padding[BBOT]);
|
||||
|
||||
/*
|
||||
* 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(hfill2, hpr, char_nul);
|
||||
|
||||
#if defined(DEBUG)
|
||||
fprintf(stderr, "Alignment: hfill %d hpl %d hpr %d, vfill %d vfill1 %d vfill2 %d.\n",
|
||||
if (is_debug_logging(MAIN)) {
|
||||
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);
|
||||
fprintf(stderr, " hfill1 = \"%s\"; hfill2 = \"%s\"; indentspc = \"%s\";\n",
|
||||
u32_strconv_to_output(hfill1), u32_strconv_to_output(hfill2), u32_strconv_to_output(indentspc));
|
||||
#endif
|
||||
char *out_hfill1 = u32_strconv_to_output(hfill1);
|
||||
char *out_hfill2 = u32_strconv_to_output(hfill2);
|
||||
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
|
||||
@ -1008,10 +1009,8 @@ int output_box(const sentry_t *thebox)
|
||||
if (empty_side(opt.design->shape, BLEF)) {
|
||||
skip_left = opt.design->shape[NW].width;
|
||||
} /* could simply be 1, though */
|
||||
#if defined(DEBUG)
|
||||
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);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "skip_start = %d; skip_end = %d; skip_left = %d; nol = %d;\n",
|
||||
(int) skip_start, (int) skip_end, (int) skip_left, (int) nol);
|
||||
|
||||
/*
|
||||
* Generate actual output
|
||||
|
47
src/input.c
47
src/input.c
@ -26,6 +26,7 @@
|
||||
|
||||
#include "boxes.h"
|
||||
#include "input.h"
|
||||
#include "logging.h"
|
||||
#include "regulex.h"
|
||||
#include "tools.h"
|
||||
#include "unicode.h"
|
||||
@ -45,9 +46,7 @@ static int has_linebreak(const uint32_t *s, const int len)
|
||||
if (s != NULL && len > 0) {
|
||||
ucs4_t the_last = s[len - 1];
|
||||
result = u32_cmp(&char_cr, &the_last, 1) == 0 || u32_cmp(&char_newline, &the_last, 1) == 0;
|
||||
#if defined(DEBUG)
|
||||
fprintf(stderr, "has_linebreak: (%#010x) %d\n", (int) the_last, result);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "has_linebreak: (%#010x) %d\n", (int) the_last, 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 */
|
||||
|
||||
if (lines == NULL) {
|
||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||
bx_fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||
return -1;
|
||||
}
|
||||
if (lines_size == 0) {
|
||||
@ -112,16 +111,14 @@ int apply_substitutions(input_t *result, const int mode)
|
||||
rules = opt.design->revrules;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||
bx_fprintf(stderr, "%s: internal error\n", PROJECT);
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compile regular expressions
|
||||
*/
|
||||
#ifdef REGEXP_DEBUG
|
||||
fprintf(stderr, "Compiling %d %s rule patterns\n", (int) num_rules, mode ? "reversion" : "replacement");
|
||||
#endif
|
||||
log_debug(__FILE__, REGEXP, "Compiling %d %s rule patterns\n", (int) num_rules, mode ? "reversion" : "replacement");
|
||||
errno = 0;
|
||||
opt.design->current_rule = rules;
|
||||
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) {
|
||||
opt.design->current_rule = rules;
|
||||
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 *outrepstr = bxs_to_output(rules[j].repstr);
|
||||
fprintf(stderr, "regex_replace(0x%p, \"%s\", \"%s\", %d, \'%c\') == ", rules[j].prog, outrepstr,
|
||||
outtext, (int) result->lines[k].text->num_chars, rules[j].mode);
|
||||
log_debug(__FILE__, REGEXP, "regex_replace(0x%p, \"%s\", \"%s\", %d, \'%c\') == ", rules[j].prog,
|
||||
outrepstr, outtext, (int) result->lines[k].text->num_chars, rules[j].mode);
|
||||
BFREE(outtext);
|
||||
BFREE(outrepstr);
|
||||
#endif
|
||||
}
|
||||
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');
|
||||
#ifdef REGEXP_DEBUG
|
||||
if (is_debug_logging(REGEXP)) {
|
||||
char *outnewtext = newtext ? u32_strconv_to_output(newtext) : strdup("NULL");
|
||||
fprintf(stderr, "\"%s\"\n", outnewtext);
|
||||
log_debug_cont(REGEXP, "\"%s\"\n", outnewtext);
|
||||
BFREE(outnewtext);
|
||||
#endif
|
||||
}
|
||||
if (newtext == NULL) {
|
||||
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 */
|
||||
|
||||
#ifdef REGEXP_DEBUG
|
||||
if (is_debug_logging(REGEXP)) {
|
||||
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,
|
||||
outtext2);
|
||||
log_debug(__FILE__, REGEXP, "result->lines[%d] == {%d, \"%s\"}\n",
|
||||
(int) k, (int) result->lines[k].text->num_chars, outtext2);
|
||||
BFREE(outtext2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
opt.design->current_rule = NULL;
|
||||
}
|
||||
@ -321,15 +318,15 @@ int analyze_input(input_t *result)
|
||||
bxs_free(result->lines[i].text);
|
||||
result->lines[i].text = unindented;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (is_debug_logging(MAIN)) {
|
||||
char *outtext = bxs_to_output(result->lines[i].text);
|
||||
fprintf(stderr, "%2d: text = \"%s\" (%d chars, %d visible, %d invisible, %d columns)\n"
|
||||
" ascii = \"%s\"\n", (int) i, outtext,
|
||||
log_debug(__FILE__, MAIN, "%2d: text = \"%s\" (%d chars, %d visible, %d invisible, %d columns)\n",
|
||||
(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_invisible, (int) result->lines[i].text->num_columns,
|
||||
result->lines[i].text->ascii);
|
||||
(int) result->lines[i].text->num_chars_invisible, (int) result->lines[i].text->num_columns);
|
||||
log_debug(__FILE__, MAIN, " ascii = \"%s\"\n", result->lines[i].text->ascii);
|
||||
BFREE(outtext);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
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 "boxes.h"
|
||||
#include "logging.h"
|
||||
#include "shape.h"
|
||||
#include "tools.h"
|
||||
#include "parsing.h"
|
||||
@ -181,9 +182,7 @@ PFILENAME [^\r\n]+
|
||||
else if (*p == yyextra->sdel) {
|
||||
*p = '\0';
|
||||
yyless ((p - str) + 2 + qcnt); /* string plus quotes */
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, " STRING: \"%s\"\n", str);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, " STRING: \"%s\"\n", str);
|
||||
|
||||
uint32_t *utf8 = u32_strconv_from_arg(str, CONFIG_FILE_ENCODING);
|
||||
yylval->s = bxs_from_unicode(utf8);
|
||||
@ -293,9 +292,7 @@ PFILENAME [^\r\n]+
|
||||
|
||||
|
||||
<BOX>Tags {
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, " YTAGS: %s\n", yytext);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, " YTAGS: %s\n", yytext);
|
||||
return YTAGS;
|
||||
}
|
||||
|
||||
@ -368,9 +365,7 @@ PFILENAME [^\r\n]+
|
||||
/*
|
||||
* general key words
|
||||
*/
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, "KEYWORD: %s\n", yytext);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, "KEYWORD: %s\n", yytext);
|
||||
yylval->ascii = strdup(yytext);
|
||||
if (yylval->ascii == NULL) {
|
||||
perror (PROJECT);
|
||||
@ -398,9 +393,7 @@ PFILENAME [^\r\n]+
|
||||
perror (PROJECT);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, "ASCIIID: %s\n", yylval->ascii);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, "ASCIIID: %s\n", yylval->ascii);
|
||||
return ASCII_ID;
|
||||
}
|
||||
|
||||
@ -414,44 +407,38 @@ PFILENAME [^\r\n]+
|
||||
perror (PROJECT);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, " BXWORD: %s\n", u32_strconv_to_output(utf8));
|
||||
#endif
|
||||
if (is_debug_logging(LEXER)) {
|
||||
char *out_utf8 = u32_strconv_to_output(utf8);
|
||||
log_debug(__FILE__, LEXER, " BXWORD: %s\n", out_utf8);
|
||||
BFREE(out_utf8);
|
||||
}
|
||||
BFREE(utf8);
|
||||
return BXWORD;
|
||||
}
|
||||
|
||||
|
||||
<BOX>[\+-]?[0-9]+ {
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, "YNUMBER: %s\n", yytext);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, "YNUMBER: %s\n", yytext);
|
||||
yylval->num = atoi (yytext);
|
||||
return YNUMBER;
|
||||
}
|
||||
|
||||
|
||||
<BOX,SHAPES,ELASTIC>[,(){}] {
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, " SYMBOL: \'%c\'\n", yytext[0]);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, " SYMBOL: \'%c\'\n", yytext[0]);
|
||||
return yytext[0];
|
||||
}
|
||||
|
||||
|
||||
<INITIAL,BOX,SHAPES,ELASTIC>#.*$ {
|
||||
/* ignore comments */
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, "COMMENT: %s\n", yytext+1);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, "COMMENT: %s\n", yytext + 1);
|
||||
}
|
||||
|
||||
|
||||
<INITIAL,BOX,SHAPES,ELASTIC>. {
|
||||
/* a character that made no sense where it was encountered. Let the parser handle it. */
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf (stderr, " YUNREC: \'%c\'\n", yytext[0]);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, " YUNREC: \'%c\'\n", yytext[0]);
|
||||
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)
|
||||
{
|
||||
int lexerDebug = 0;
|
||||
#ifdef LEXER_DEBUG
|
||||
lexerDebug = 1;
|
||||
#endif
|
||||
if (lexerDebug) {
|
||||
fprintf(stderr, "%7s: %s -- STATE %s\n", symbol, text, expected_state_str);
|
||||
if (is_debug_logging(LEXER)) {
|
||||
size_t text_len = 0;
|
||||
if (text != NULL) {
|
||||
text_len = strlen(text);
|
||||
if (text_len > 0 && (text[text_len - 1] == '\r' || text[text_len - 1] == '\t')) {
|
||||
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;
|
||||
}
|
||||
|
||||
#ifdef LEXER_DEBUG
|
||||
fprintf(stderr, "YDELIMS: change_string_delimiters('%c', '%c')\n", delim_expr[0], delim_expr[1]);
|
||||
#endif
|
||||
log_debug(__FILE__, LEXER, "YDELIMS: change_string_delimiters('%c', '%c')\n", delim_expr[0], delim_expr[1]);
|
||||
extra->sesc = delim_expr[0];
|
||||
extra->sdel = delim_expr[1];
|
||||
|
||||
|
102
src/parsecode.c
102
src/parsecode.c
@ -27,6 +27,7 @@
|
||||
#include <unistr.h>
|
||||
|
||||
#include "discovery.h"
|
||||
#include "logging.h"
|
||||
#include "parsecode.h"
|
||||
#include "parsing.h"
|
||||
#include "query.h"
|
||||
@ -57,9 +58,7 @@ static int check_sizes(pass_to_bison *bison_args)
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: check_sizes()\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: check_sizes()\n");
|
||||
|
||||
for (i = 0; i < NUM_SIDES; ++i) {
|
||||
if (i == 0 || i == 2) {
|
||||
@ -125,9 +124,7 @@ static int corner_check(pass_to_bison *bison_args)
|
||||
{
|
||||
int c;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: corner_check()\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: corner_check()\n");
|
||||
|
||||
for (c = 0; c < NUM_CORNERS; ++c) {
|
||||
if (curdes.shape[corners[c]].elastic) {
|
||||
@ -145,9 +142,7 @@ static shape_t non_existent_elastics(pass_to_bison *bison_args)
|
||||
{
|
||||
shape_t i;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: non_existent_elastics()\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: non_existent_elastics()\n");
|
||||
|
||||
for (i = 0; i < NUM_SHAPES; ++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;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: insufficient_elasticity()\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: insufficient_elasticity()\n");
|
||||
|
||||
for (i = 0; i < NUM_SIDES; ++i) {
|
||||
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;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: adjoining_elastics()\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: adjoining_elastics()\n");
|
||||
|
||||
for (i = 0; i < NUM_SIDES; ++i) {
|
||||
ef = 0;
|
||||
@ -316,9 +307,7 @@ static int full_parse_required()
|
||||
if (!opt.design_choice_by_user) {
|
||||
result = opt.r || opt.l || (opt.query != NULL && !opt.qundoc);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, " Parser: full_parse_required() -> %s\n", result ? "true" : "false");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, " Parser: full_parse_required() -> %s\n", result ? "true" : "false");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -593,11 +582,9 @@ int action_finalize_shapes(pass_to_bison *bison_args)
|
||||
curdes.maxshapeheight = curdes.shape[i].height;
|
||||
}
|
||||
}
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: Minimum box dimensions: width %d height %d\n",
|
||||
log_debug(__FILE__, PARSER, " Parser: Minimum box dimensions: width %d height %d\n",
|
||||
(int) curdes.minwidth, (int) curdes.minheight);
|
||||
fprintf(stderr, " Parser: Maximum shape height: %d\n", (int) curdes.maxshapeheight);
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: Maximum shape height: %d\n", (int) curdes.maxshapeheight);
|
||||
|
||||
/*
|
||||
* 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)) {
|
||||
bison_args->speeding = 1;
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: Skipping to next design (lexer doesn't know!)\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: Skipping to next design (lexer doesn't know!)\n");
|
||||
return RC_ERROR; /* trigger the parser's `error` rule, which will skip to the next design */
|
||||
}
|
||||
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)
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: parent config file specified: [%s]\n", bxs_to_output(filepath));
|
||||
#endif
|
||||
if (is_debug_logging(PARSER)) {
|
||||
char *out_filepath = bxs_to_output(filepath);
|
||||
log_debug(__FILE__, PARSER, " Parser: parent config file specified: [%s]\n", out_filepath);
|
||||
BFREE(out_filepath);
|
||||
}
|
||||
|
||||
if (bxs_is_empty(filepath)) {
|
||||
bison_args->skipping = 1;
|
||||
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);
|
||||
}
|
||||
}
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: parent config file path resolved: [%s]\n", bxs_to_output(filepath));
|
||||
#endif
|
||||
if (is_debug_logging(PARSER)) {
|
||||
char *out_filepath = bxs_to_output(filepath);
|
||||
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);
|
||||
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->num_parent_configs);
|
||||
}
|
||||
else {
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: duplicate parent / cycle: [%s]\n", bxs_to_output(filepath));
|
||||
#endif
|
||||
else if (is_debug_logging(PARSER)) {
|
||||
char *out_filepath = bxs_to_output(filepath);
|
||||
log_debug(__FILE__, PARSER, " Parser: duplicate parent / cycle: [%s]\n", out_filepath);
|
||||
BFREE(out_filepath);
|
||||
}
|
||||
return RC_SUCCESS;
|
||||
}
|
||||
@ -699,9 +689,7 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
|
||||
{
|
||||
design_t *tmp;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, "--------- ADDING DESIGN \"%s\".\n", design_primary_name);
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, "--------- ADDING DESIGN \"%s\".\n", design_primary_name);
|
||||
|
||||
if (strcasecmp(design_primary_name, name_at_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)
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: entry rule fulfilled [%s = %s]\n", keyword, bxs_to_output(value));
|
||||
#endif
|
||||
if (is_debug_logging(PARSER)) {
|
||||
char *out_value = bxs_to_output(value);
|
||||
log_debug(__FILE__, PARSER, " Parser: entry rule fulfilled [%s = %s]\n", keyword, out_value);
|
||||
BFREE(out_value);
|
||||
}
|
||||
|
||||
size_t error_pos = 0;
|
||||
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;
|
||||
}
|
||||
if (alias_exists_in_child_configs(bison_args, alias_name)) {
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: alias already used by child config, dropping: %s\n", alias_name);
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: alias already used by child config, dropping: %s\n", alias_name);
|
||||
}
|
||||
else {
|
||||
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)
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, " Parser: SAMPLE block rule satisfied\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, " Parser: SAMPLE block rule satisfied\n");
|
||||
|
||||
if (curdes.sample) {
|
||||
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;
|
||||
|
||||
UNUSED(type); /* used only in PARSER_DEBUG mode */
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, "Adding %s rule: \"%s\" with \"%s\" (%c)\n",
|
||||
strcmp(type, "rep") == 0 ? "replacement" : "reversion",
|
||||
bxs_to_output(search), bxs_to_output(replace), mode);
|
||||
#endif
|
||||
if (is_debug_logging(PARSER)) {
|
||||
char *out_search = bxs_to_output(search);
|
||||
char *out_replace = bxs_to_output(replace);
|
||||
log_debug(__FILE__, PARSER, "Adding %s rule: \"%s\" with \"%s\" (%c)\n",
|
||||
strcmp(type, "rep") == 0 ? "replacement" : "reversion", out_search, out_replace, mode);
|
||||
BFREE(out_replace);
|
||||
BFREE(out_search);
|
||||
}
|
||||
|
||||
*rule_list = (reprule_t *) realloc(*rule_list, (n + 1) * sizeof(reprule_t));
|
||||
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;
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, "Initializing a shape entry with first line\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, "Initializing a shape entry with first line\n");
|
||||
|
||||
size_t error_pos = 0;
|
||||
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)
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf(stderr, "Extending a shape entry\n");
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, "Extending a shape entry\n");
|
||||
|
||||
size_t slen = line->num_columns;
|
||||
if (slen != shape->width) {
|
||||
|
35
src/parser.y
35
src/parser.y
@ -75,6 +75,7 @@ typedef struct {
|
||||
#include <stdlib.h>
|
||||
#include <unictype.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "shape.h"
|
||||
#include "tools.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
|
||||
{
|
||||
/* reset alias list, as those are collected even when speedmode is on */
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf (stderr, " Parser: Discarding token [skipping=%s, speeding=%s]\n",
|
||||
log_debug(__FILE__, PARSER, " Parser: Discarding token [skipping=%s, speeding=%s]\n",
|
||||
bison_args->skipping ? "true" : "false", bison_args->speeding ? "true" : "false");
|
||||
#endif
|
||||
if (curdes.aliases[0] != NULL) {
|
||||
BFREE(curdes.aliases);
|
||||
curdes.aliases = (char **) calloc(1, sizeof(char *));
|
||||
@ -268,10 +267,10 @@ entry: KEYWORD STRING
|
||||
yyerror(bison_args, "string expected");
|
||||
YYERROR;
|
||||
}
|
||||
else {
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf (stderr, " Parser: Discarding entry [%s = %s].\n", "parent", bxs_to_output(filename));
|
||||
#endif
|
||||
else if (is_debug_logging(PARSER)) {
|
||||
char *out_filename = bxs_to_output(filename);
|
||||
log_debug(__FILE__, PARSER, " Parser: Discarding entry [%s = %s].\n", "parent", out_filename);
|
||||
BFREE(out_filename);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,9 +283,11 @@ entry: KEYWORD STRING
|
||||
|
||||
| BXWORD STRING | ASCII_ID STRING
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf (stderr, " Parser: Discarding entry [%s = %s].\n", $1, bxs_to_output($2));
|
||||
#endif
|
||||
if (is_debug_logging(PARSER)) {
|
||||
char *out_string = bxs_to_output($2);
|
||||
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 '}'
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf (stderr, "Padding set to (l%d o%d r%d u%d)\n",
|
||||
log_debug(__FILE__, PARSER, "Padding set to (l%d o%d r%d u%d)\n",
|
||||
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
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf (stderr, "Marked \'%s\' shape as elastic\n", shape_name[(int) $1]);
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, "Marked \'%s\' shape as elastic\n", shape_name[(int) $1]);
|
||||
curdes.shape[$1].elastic = 1;
|
||||
}
|
||||
;
|
||||
@ -360,10 +357,8 @@ slist: slist slist_entry | slist_entry;
|
||||
|
||||
slist_entry: SHAPE shape_def
|
||||
{
|
||||
#ifdef PARSER_DEBUG
|
||||
fprintf (stderr, "Adding shape spec for \'%s\' (width %d "
|
||||
"height %d)\n", shape_name[$1], (int) $2.width, (int) $2.height);
|
||||
#endif
|
||||
log_debug(__FILE__, PARSER, "Adding shape spec for \'%s\' (width %d height %d)\n",
|
||||
shape_name[$1], (int) $2.width, (int) $2.height);
|
||||
|
||||
if (isempty (curdes.shape + $1)) {
|
||||
curdes.shape[$1] = $2;
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "boxes.h"
|
||||
#include "bxstring.h"
|
||||
#include "logging.h"
|
||||
#include "parsing.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)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Parsing Config File %s ...\n", bxs_to_output(config_file));
|
||||
#endif
|
||||
if (is_debug_logging(MAIN)) {
|
||||
char *out_config_file = bxs_to_output(config_file);
|
||||
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);
|
||||
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) {
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "yyparse() returned %d\n", rc);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "yyparse() returned %d\n", rc);
|
||||
return new_bison_args(config_file);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
*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 {
|
||||
pass_to_bison bison_args = parse_config_file(config_file, result, *r_num_designs);
|
||||
++parents_parsed;
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "bison_args returned: "
|
||||
log_debug(__FILE__, MAIN, "bison_args returned: "
|
||||
".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_designs, bison_args.designs);
|
||||
#endif
|
||||
|
||||
if (record_parent_config_files(&bison_args) != 0) {
|
||||
perror(PROJECT);
|
||||
@ -289,9 +288,7 @@ design_t *parse_config_files(bxstr_t *p_first_config_file, size_t *r_num_designs
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "design count raised to: %d\n", (int) *r_num_designs);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "design count raised to: %d\n", (int) *r_num_designs);
|
||||
if (parents_parsed < num_parent_configs) {
|
||||
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 "list.h"
|
||||
#include "logging.h"
|
||||
#include "tools.h"
|
||||
#include "query.h"
|
||||
|
||||
@ -118,12 +119,12 @@ char **parse_query(char *optarg)
|
||||
|
||||
static int filter_by_tag(char **tags)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "filter_by_tag(");
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "filter_by_tag(");
|
||||
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);
|
||||
if (opt.query != NULL) {
|
||||
@ -146,9 +147,7 @@ static int filter_by_tag(char **tags)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, ") -> %d\n", result);
|
||||
#endif
|
||||
log_debug_cont(MAIN, ") -> %d\n", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "boxes.h"
|
||||
#include "logging.h"
|
||||
#include "regulex.h"
|
||||
#include "tools.h"
|
||||
#include "unicode.h"
|
||||
@ -135,9 +136,7 @@ uint32_t *u32_regex_replace(pcre2_code *search, uint32_t *replace, uint32_t *inp
|
||||
done = 1;
|
||||
}
|
||||
else {
|
||||
#ifdef REGEXP_DEBUG
|
||||
fprintf(stderr, "Reallocating output buffer from %ld to %ld UTF-32 chars\n", bufsize, outlen);
|
||||
#endif
|
||||
log_debug(__FILE__, REGEXP, "Reallocating output buffer from %ld to %ld UTF-32 chars\n", bufsize, outlen);
|
||||
bufsize = outlen;
|
||||
output = (uint32_t *) realloc(output, sizeof(uint32_t) * bufsize);
|
||||
}
|
||||
|
169
src/remove.c
169
src/remove.c
@ -28,6 +28,7 @@
|
||||
|
||||
#include "boxes.h"
|
||||
#include "detect.h"
|
||||
#include "logging.h"
|
||||
#include "remove.h"
|
||||
#include "shape.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)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Remove Context %s:\n", heading);
|
||||
fprintf(stderr, " - empty_side[BTOP] = %s\n", ctx->empty_side[BTOP] ? "true" : "false");
|
||||
fprintf(stderr, " - empty_side[BRIG] = %s\n", ctx->empty_side[BRIG] ? "true" : "false");
|
||||
fprintf(stderr, " - empty_side[BBOT] = %s\n", ctx->empty_side[BBOT] ? "true" : "false");
|
||||
fprintf(stderr, " - empty_side[BLEF] = %s\n", ctx->empty_side[BLEF] ? "true" : "false");
|
||||
fprintf(stderr, " - design_is_mono = %s\n", ctx->design_is_mono ? "true" : "false");
|
||||
fprintf(stderr, " - input_is_mono = %s\n", ctx->input_is_mono ? "true" : "false");
|
||||
fprintf(stderr, " - top_start_idx = %d\n", (int) ctx->top_start_idx);
|
||||
fprintf(stderr, " - top_end_idx = %d\n", (int) ctx->top_end_idx);
|
||||
fprintf(stderr, " - bottom_start_idx = %d\n", (int) ctx->bottom_start_idx);
|
||||
fprintf(stderr, " - bottom_end_idx = %d\n", (int) ctx->bottom_end_idx);
|
||||
fprintf(stderr, " - comp_type = %s\n", comparison_name[ctx->comp_type]);
|
||||
fprintf(stderr, " - body (%d lines):\n", (int) ctx->body_num_lines);
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, "Remove Context %s:\n", heading);
|
||||
log_debug(__FILE__, MAIN, " - empty_side[BTOP] = %s\n", ctx->empty_side[BTOP] ? "true" : "false");
|
||||
log_debug(__FILE__, MAIN, " - empty_side[BRIG] = %s\n", ctx->empty_side[BRIG] ? "true" : "false");
|
||||
log_debug(__FILE__, MAIN, " - empty_side[BBOT] = %s\n", ctx->empty_side[BBOT] ? "true" : "false");
|
||||
log_debug(__FILE__, MAIN, " - empty_side[BLEF] = %s\n", ctx->empty_side[BLEF] ? "true" : "false");
|
||||
log_debug(__FILE__, MAIN, " - design_is_mono = %s\n", ctx->design_is_mono ? "true" : "false");
|
||||
log_debug(__FILE__, MAIN, " - input_is_mono = %s\n", ctx->input_is_mono ? "true" : "false");
|
||||
log_debug(__FILE__, MAIN, " - top_start_idx = %d\n", (int) ctx->top_start_idx);
|
||||
log_debug(__FILE__, MAIN, " - top_end_idx = %d\n", (int) ctx->top_end_idx);
|
||||
log_debug(__FILE__, MAIN, " - bottom_start_idx = %d\n", (int) ctx->bottom_start_idx);
|
||||
log_debug(__FILE__, MAIN, " - bottom_end_idx = %d\n", (int) ctx->bottom_end_idx);
|
||||
log_debug(__FILE__, MAIN, " - comp_type = %s\n", comparison_name[ctx->comp_type]);
|
||||
log_debug(__FILE__, MAIN, " - body (%d lines):\n", (int) ctx->body_num_lines);
|
||||
for (size_t i = 0; i < ctx->body_num_lines; i++) {
|
||||
if (ctx->body[i].input_line_used != NULL) {
|
||||
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));
|
||||
BFREE(out_input_line_used);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, " - lctx: (null)\n");
|
||||
log_debug(__FILE__, MAIN, " - lctx: (null)\n");
|
||||
}
|
||||
bxstr_t *orgline = input.lines[ctx->top_end_idx + i].text;
|
||||
if (orgline != NULL) {
|
||||
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);
|
||||
BFREE(out_orgline);
|
||||
}
|
||||
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].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)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, " shapes_relevant = {");
|
||||
if (is_debug_logging(MAIN)) {
|
||||
log_debug(__FILE__, MAIN, " shapes_relevant = {");
|
||||
for (size_t ds = 0; ds < SHAPES_PER_SIDE; ds++) {
|
||||
if (shapes_relevant[ds].empty) {
|
||||
fprintf(stderr, "-");
|
||||
log_debug_cont(MAIN, "-");
|
||||
}
|
||||
else {
|
||||
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" : "");
|
||||
BFREE(out_shp_text);
|
||||
}
|
||||
if (ds < SHAPES_PER_SIDE - 1) {
|
||||
fprintf(stderr, ", ");
|
||||
log_debug_cont(MAIN, ", ");
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "}\n");
|
||||
#else
|
||||
UNUSED(shapes_relevant);
|
||||
#endif
|
||||
log_debug_cont(MAIN, "}\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 anchored_right)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (is_debug_logging(MAIN)) {
|
||||
char *out_cur_pos = u32_strconv_to_output(cur_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");
|
||||
BFREE(out_cur_pos);
|
||||
BFREE(out_end_pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
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) {
|
||||
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);
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
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
|
||||
fprintf(stderr, "hmm() - exit, result = %d\n", result);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "hmm() - exit, result = %d\n", 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)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "match_horiz_line(ctx, %s, %d, %d)\n",
|
||||
log_debug(__FILE__, MAIN, "match_horiz_line(ctx, %s, %d, %d)\n",
|
||||
hside == BTOP ? "BTOP" : "BBOT", (int) input_line_idx, (int) shape_line_idx);
|
||||
#endif
|
||||
|
||||
int result = 0;
|
||||
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;
|
||||
}
|
||||
ctx->comp_type = comp_type;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, " Setting comparison type to: %s\n", comparison_name[comp_type]);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, " Setting comparison type to: %s\n", comparison_name[comp_type]);
|
||||
|
||||
shape_line_ctx_t *shapes_relevant = prepare_comp_shapes_horiz(hside, comp_type, shape_line_idx);
|
||||
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);
|
||||
bxs_append_spaces(input_prepped, opt.design->shape[NW].width + opt.design->shape[NE].width);
|
||||
bxs_free(input_prepped1);
|
||||
#ifdef DEBUG
|
||||
if (is_debug_logging(MAIN)) {
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t *cur_pos = input_prepped->memory;
|
||||
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;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (is_debug_logging(MAIN)) {
|
||||
char *out_cur_pos = u32_strconv_to_output(cur_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));
|
||||
fprintf(stderr, " end_pos = \"%s\" (index %d)\n", out_end_pos, (int) BMAX(end_pos - input_prepped->memory, 0));
|
||||
log_debug(__FILE__, MAIN, " cur_pos = \"%s\" (index %d)\n",
|
||||
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_end_pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
result = hmm(shapes_relevant, cur_pos, 1, end_pos, (mrl == NULL) || mrl->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);
|
||||
|
||||
if (result) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Matched %s side line using comp_type=%s and shape_line_idx=%d\n",
|
||||
log_debug(__FILE__, MAIN, "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);
|
||||
#endif
|
||||
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. */
|
||||
int sufficient = (max_quality == 0 && total_quality == 0)
|
||||
|| (max_quality > 0 && (total_quality > 0.5 * max_quality));
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "sufficient_body_quality() found body match quality of %d/%d (%s).\n",
|
||||
(int) total_quality, (int) max_quality, sufficient ? "sufficient" : "NOT sufficient");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "sufficient_body_quality() found body match quality of %d/%d (%s).\n",
|
||||
(int) total_quality, (int) max_quality, sufficient ? "sufficient" : "NOT sufficient");
|
||||
|
||||
return sufficient;
|
||||
}
|
||||
|
||||
@ -832,9 +822,7 @@ static void find_vertical_shapes(remove_ctx_t *ctx)
|
||||
continue;
|
||||
}
|
||||
ctx->comp_type = comp_type;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "find_vertical_shapes(): comp_type = %s\n", comparison_name[comp_type]);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "find_vertical_shapes(): comp_type = %s\n", comparison_name[comp_type]);
|
||||
reset_body(ctx);
|
||||
|
||||
shape_line_ctx_t **shape_lines_west = NULL;
|
||||
@ -883,20 +871,16 @@ static void detect_design_if_needed()
|
||||
design_t *tmp = autodetect_design();
|
||||
if (tmp) {
|
||||
opt.design = tmp;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Design autodetection: Removing box of design \"%s\".\n", opt.design->name);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Design autodetection: Removing box of design \"%s\".\n", opt.design->name);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s: Box design autodetection failed. Use -d option.\n", PROJECT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
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
|
||||
&& empty_line(input.lines + ctx->top_end_idx))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Killing leading blank line in box body.\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Killing leading blank line in box body.\n");
|
||||
++(ctx->top_end_idx);
|
||||
--(ctx->body_num_lines);
|
||||
++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
|
||||
&& empty_line(input.lines + ctx->bottom_start_idx - 1))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Killing trailing blank line in box body.\n");
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Killing trailing blank line in box body.\n");
|
||||
--(ctx->bottom_start_idx);
|
||||
--(ctx->body_num_lines);
|
||||
++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;
|
||||
size_t s_idx = calculate_start_idx(ctx, body_line_idx);
|
||||
size_t e_idx = calculate_end_idx(ctx, body_line_idx);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "remove_vertical_from_input(): body_line_idx=%d, input_line_idx=%d, s_idx=%d, e_idx=%d, "
|
||||
"input.indent=%d\n", (int) body_line_idx, (int) input_line_idx, (int) s_idx, (int) e_idx,
|
||||
(int) input.indent);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "remove_vertical_from_input(): body_line_idx=%d, input_line_idx=%d, s_idx=%d, "
|
||||
"e_idx=%d, input.indent=%d\n", (int) body_line_idx, (int) input_line_idx, (int) s_idx, (int) e_idx,
|
||||
(int) input.indent);
|
||||
|
||||
bxstr_t *temp2 = bxs_substr(org_line, s_idx, e_idx);
|
||||
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);
|
||||
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");
|
||||
fprintf(stderr, "Number of lines shrunk by %d.\n", (int) num_lines_removed);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "Number of lines shrunk by %d.\n", (int) num_lines_removed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1140,10 +1118,8 @@ int remove_box()
|
||||
ctx->empty_side[BRIG] = empty_side(opt.design->shape, BRIG);
|
||||
ctx->empty_side[BBOT] = empty_side(opt.design->shape, BBOT);
|
||||
ctx->empty_side[BLEF] = empty_side(opt.design->shape, BLEF);
|
||||
#ifdef DEBUG
|
||||
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]);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "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->design_is_mono = design_is_mono(opt.design);
|
||||
ctx->input_is_mono = input_is_mono();
|
||||
@ -1159,10 +1135,8 @@ int remove_box()
|
||||
else {
|
||||
ctx->top_end_idx = find_top_side(ctx);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ctx->top_start_idx = %d, ctx->top_end_idx = %d\n", (int) ctx->top_start_idx,
|
||||
(int) ctx->top_end_idx);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "ctx->top_start_idx = %d, ctx->top_end_idx = %d\n", (int) ctx->top_start_idx,
|
||||
(int) ctx->top_end_idx);
|
||||
|
||||
ctx->bottom_end_idx = find_last_line() + 1;
|
||||
if (ctx->empty_side[BBOT]) {
|
||||
@ -1171,10 +1145,8 @@ int remove_box()
|
||||
else {
|
||||
ctx->bottom_start_idx = find_bottom_side(ctx);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ctx->bottom_start_idx = %d, ctx->bottom_end_idx = %d\n", (int) ctx->bottom_start_idx,
|
||||
(int) ctx->bottom_end_idx);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "ctx->bottom_start_idx = %d, ctx->bottom_end_idx = %d\n", (int) ctx->bottom_start_idx,
|
||||
(int) ctx->bottom_end_idx);
|
||||
if (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;
|
||||
int ntabs, nspcs;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "output_input() - enter (trim_only=%d)\n", trim_only);
|
||||
#endif
|
||||
log_debug(__FILE__, MAIN, "output_input() - enter (trim_only=%d)\n", trim_only);
|
||||
|
||||
for (size_t j = 0; j < input.num_lines; ++j) {
|
||||
if (input.lines[j].text == NULL) {
|
||||
continue;
|
||||
|
59
src/shape.c
59
src/shape.c
@ -26,6 +26,7 @@
|
||||
|
||||
#include "boxes.h"
|
||||
#include "bxstring.h"
|
||||
#include "logging.h"
|
||||
#include "shape.h"
|
||||
#include "tools.h"
|
||||
|
||||
@ -248,10 +249,6 @@ size_t highest(const sentry_t *sarr, const int n, ...)
|
||||
int i;
|
||||
size_t max = 0; /* current maximum height */
|
||||
|
||||
#if defined(DEBUG) && 0
|
||||
fprintf (stderr, "highest (%d, ...)\n", n);
|
||||
#endif
|
||||
|
||||
va_start (ap, n);
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
@ -287,10 +284,6 @@ size_t widest(const sentry_t *sarr, const int n, ...)
|
||||
int i;
|
||||
size_t max = 0; /* current maximum width */
|
||||
|
||||
#if defined(DEBUG) && 0
|
||||
fprintf (stderr, "widest (%d, ...)\n", n);
|
||||
#endif
|
||||
|
||||
va_start (ap, n);
|
||||
|
||||
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)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (is_debug_logging(MAIN)) {
|
||||
if (shape == NULL) {
|
||||
fprintf(stderr, "NULL\n");
|
||||
log_debug(__FILE__, MAIN, "NULL\n");
|
||||
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");
|
||||
if (shape->blank_leftward == NULL) {
|
||||
fprintf(stderr, "NULL");
|
||||
log_debug_cont(MAIN, "NULL");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "[");
|
||||
log_debug_cont(MAIN, "[");
|
||||
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) ? ", " : "");
|
||||
}
|
||||
fprintf(stderr, "]");
|
||||
log_debug_cont(MAIN, "]");
|
||||
}
|
||||
fprintf(stderr, ", br=");
|
||||
log_debug_cont(MAIN, ", br=");
|
||||
if (shape->blank_rightward == NULL) {
|
||||
fprintf(stderr, "NULL");
|
||||
log_debug_cont(MAIN, "NULL");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "[");
|
||||
log_debug_cont(MAIN, "[");
|
||||
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) ? ", " : "");
|
||||
}
|
||||
fprintf(stderr, "]");
|
||||
log_debug_cont(MAIN, "]");
|
||||
}
|
||||
fprintf(stderr, ", ascii=");
|
||||
log_debug_cont(MAIN, ", ascii=");
|
||||
if (shape->chars == NULL) {
|
||||
fprintf(stderr, "NULL");
|
||||
log_debug_cont(MAIN, "NULL");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "[");
|
||||
log_debug_cont(MAIN, "[");
|
||||
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 ? ", " : "");
|
||||
}
|
||||
fprintf(stderr, "]");
|
||||
log_debug_cont(MAIN, "]");
|
||||
}
|
||||
fprintf(stderr, ", mbcs=");
|
||||
log_debug_cont(MAIN, ", mbcs=");
|
||||
if (shape->mbcs == NULL) {
|
||||
fprintf(stderr, "NULL");
|
||||
log_debug_cont(MAIN, "NULL");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "[");
|
||||
log_debug_cont(MAIN, "[");
|
||||
for (size_t i = 0; i < shape->height; 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) ? ", " : "");
|
||||
BFREE(out_mbcs);
|
||||
}
|
||||
fprintf(stderr, "]");
|
||||
log_debug_cont(MAIN, "]");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
#else
|
||||
UNUSED(shape);
|
||||
#endif
|
||||
log_debug_cont(MAIN, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
89
src/tools.c
89
src/tools.c
@ -32,6 +32,7 @@
|
||||
#include <uniwidth.h>
|
||||
|
||||
#include "boxes.h"
|
||||
#include "logging.h"
|
||||
#include "regulex.h"
|
||||
#include "shape.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
|
||||
* @param heading a heading to show for identification of the printed lines
|
||||
*/
|
||||
void print_input_lines(const char *heading)
|
||||
{
|
||||
fprintf(stderr, "%d Input Lines%s:\n", (int) input.num_lines, heading != NULL ? heading : "");
|
||||
fprintf(stderr, " [num_chars] \"real text\" [num_cols] \"ascii_text\"\n");
|
||||
for (size_t i = 0; i < input.num_lines; ++i) {
|
||||
char *outtext = bxs_to_output(input.lines[i].text);
|
||||
fprintf(stderr, "%4d [%02d] \"%s\" [%02d] \"%s\"", (int) i,
|
||||
(int) input.lines[i].text->num_chars, outtext,
|
||||
(int) input.lines[i].text->num_columns, input.lines[i].text->ascii);
|
||||
BFREE(outtext);
|
||||
fprintf(stderr, "\tTabs: [");
|
||||
if (input.lines[i].tabpos != NULL) {
|
||||
for (size_t j = 0; j < input.lines[i].tabpos_len; ++j) {
|
||||
fprintf(stderr, "%d", (int) input.lines[i].tabpos[j]);
|
||||
if (j < input.lines[i].tabpos_len - 1) {
|
||||
fprintf(stderr, ", ");
|
||||
if (is_debug_logging(MAIN)) {
|
||||
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) {
|
||||
char *outtext = bxs_to_output(input.lines[i].text);
|
||||
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_columns, input.lines[i].text->ascii);
|
||||
BFREE(outtext);
|
||||
log_debug_cont(MAIN, "\tTabs: [");
|
||||
if (input.lines[i].tabpos != NULL) {
|
||||
for (size_t j = 0; j < input.lines[i].tabpos_len; ++j) {
|
||||
log_debug_cont(MAIN, "%d", (int) input.lines[i].tabpos[j]);
|
||||
if (j < input.lines[i].tabpos_len - 1) {
|
||||
log_debug_cont(MAIN, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "] (%d)", (int) input.lines[i].tabpos_len);
|
||||
fprintf(stderr, "\tinvisible=%d\n", (int) input.lines[i].text->num_chars_invisible);
|
||||
log_debug_cont(MAIN, "] (%d)", (int) input.lines[i].tabpos_len);
|
||||
log_debug_cont(MAIN, "\tinvisible=%d\n", (int) input.lines[i].text->num_chars_invisible);
|
||||
|
||||
fprintf(stderr, " visible_char=");
|
||||
if (input.lines[i].text->visible_char != NULL) {
|
||||
fprintf(stderr, "[");
|
||||
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],
|
||||
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
||||
log_debug(__FILE__, MAIN, " visible_char=");
|
||||
if (input.lines[i].text->visible_char != NULL) {
|
||||
log_debug_cont(MAIN, "[");
|
||||
for (size_t j = 0; j < input.lines[i].text->num_chars_visible; j++) {
|
||||
log_debug_cont(MAIN, "%d%s", (int) input.lines[i].text->visible_char[j],
|
||||
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
||||
}
|
||||
log_debug_cont(MAIN, "]\n");
|
||||
}
|
||||
else {
|
||||
log_debug_cont(MAIN, "null\n");
|
||||
}
|
||||
fprintf(stderr, "]\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "null\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, " first_char=");
|
||||
if (input.lines[i].text->first_char != NULL) {
|
||||
fprintf(stderr, "[");
|
||||
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],
|
||||
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
||||
log_debug(__FILE__, MAIN, " first_char=");
|
||||
if (input.lines[i].text->first_char != NULL) {
|
||||
log_debug_cont(MAIN, "[");
|
||||
for (size_t j = 0; j < input.lines[i].text->num_chars_visible; j++) {
|
||||
log_debug_cont(MAIN, "%d%s", (int) input.lines[i].text->first_char[j],
|
||||
j == (input.lines[i].text->num_chars_visible - 1) ? "" : ", ");
|
||||
}
|
||||
log_debug_cont(MAIN, "]\n");
|
||||
}
|
||||
else {
|
||||
log_debug_cont(MAIN, "null\n");
|
||||
}
|
||||
fprintf(stderr, "]\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "null\n");
|
||||
}
|
||||
log_debug(__FILE__, MAIN, " Longest line: %d columns\n", (int) input.maxline);
|
||||
log_debug(__FILE__, MAIN, " Indentation: %2d spaces\n", (int) input.indent);
|
||||
log_debug(__FILE__, MAIN, "Final newline: %s\n", input.final_newline ? "yes" : "no");
|
||||
}
|
||||
fprintf(stderr, " Longest line: %d columns\n", (int) input.maxline);
|
||||
fprintf(stderr, " Indentation: %2d spaces\n", (int) input.indent);
|
||||
fprintf(stderr, "Final newline: %s\n", input.final_newline ? "yes" : "no");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user