1999-03-19 18:51:19 +01:00
/*
2019-02-15 21:24:31 +01:00
* boxes - Command line filter to draw / remove ASCII boxes around text
2021-02-11 22:11:16 +01:00
* Copyright ( c ) 1999 - 2021 Thomas Jensen and the boxes contributors
1999-07-20 20:48:46 +02:00
*
2019-02-15 21:24:31 +01:00
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License , version 2 , as published
* by the Free Software Foundation .
2021-01-22 18:47:16 +01:00
*
2019-02-15 21:24:31 +01:00
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
* for more details .
2021-01-22 18:47:16 +01:00
*
2019-02-15 21:24:31 +01:00
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
1999-03-19 18:51:19 +01:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
1999-03-18 16:08:57 +01:00
2019-02-20 11:04:09 +01:00
/*
* Project - wide globals and data structures
*/
2019-02-15 21:24:31 +01:00
1999-03-18 16:08:57 +01:00
# ifndef BOXES_H
# define BOXES_H
2021-02-05 11:01:38 +01:00
/* #define DEBUG 1 */
2021-02-06 18:17:00 +01:00
/* #define REGEXP_DEBUG 1 */
2021-02-05 11:01:38 +01:00
/* #define PARSER_DEBUG 1 */
/* #define LEXER_DEBUG 1 */
1999-06-22 14:01:24 +02:00
2021-03-06 13:40:26 +01:00
# include <stdio.h>
2021-01-27 19:11:03 +01:00
# include <unitypes.h>
2021-02-05 11:01:38 +01:00
# include "regulex.h"
# include "shape.h"
1999-06-23 21:21:15 +02:00
1999-04-04 18:10:51 +02:00
1999-03-18 16:08:57 +01:00
# define PROJECT "boxes" /* name of program */
1999-08-22 01:37:23 +02:00
# define VERSION "--BVERSION--" /* current release of project */
# define GLOBALCONF "--GLOBALCONF--" /* name of system-wide config file */
1999-03-18 16:08:57 +01:00
1999-03-30 11:36:58 +02:00
2021-04-11 22:07:40 +02:00
# define DEF_INDENTMODE 'b' /* default indent mode of a design (indent box, not text) */
1999-04-04 18:10:51 +02:00
1999-06-22 14:01:24 +02:00
1999-06-30 14:19:12 +02:00
/*
2021-01-22 18:47:16 +01:00
* max . supported line length in bytes
1999-06-22 14:01:24 +02:00
* This is how many characters of a line will be read . Anything beyond
* will be discarded . The line feed character at the end does not count .
* ( This should have been done via sysconf ( ) , but I didn ' t do it in order
* to ease porting to non - unix platforms . )
1999-03-30 11:36:58 +02:00
*/
2021-01-22 18:49:54 +01:00
# if defined(LINE_MAX_BYTES) && (LINE_MAX_BYTES < 2048)
2021-01-22 18:47:16 +01:00
# undef LINE_MAX_BYTES
1999-06-22 14:01:24 +02:00
# endif
2021-01-22 18:47:16 +01:00
# ifndef LINE_MAX_BYTES
2021-03-04 21:42:00 +01:00
# define LINE_MAX_BYTES 16382
1999-06-22 14:01:24 +02:00
# endif
1999-03-30 11:36:58 +02:00
1999-03-19 18:51:19 +01:00
2021-04-11 22:07:40 +02:00
# define BTOP 0 /* for use with sides */
1999-03-30 11:36:58 +02:00
# define BRIG 1
# define BBOT 2
# define BLEF 3
1999-03-18 16:08:57 +01:00
1999-04-04 18:10:51 +02:00
typedef struct {
2021-02-05 11:01:38 +01:00
char * search ;
char * repstr ;
2021-04-11 22:07:40 +02:00
pcre2_code * prog ; /* compiled search pattern */
int line ; /* line of definition in config file */
char mode ; /* 'g' or 'o' */
1999-04-04 18:10:51 +02:00
} reprule_t ;
1999-03-18 16:08:57 +01:00
typedef struct {
1999-04-04 18:10:51 +02:00
char * name ;
2021-04-11 22:07:40 +02:00
char * * aliases ; /* zero-terminated array of alias names of the design */
char * author ; /* creator of the configuration file entry */
char * designer ; /* creator of the original ASCII artwork */
char * created ; /* date created, free format */
char * revision ; /* revision number of design */
char * revdate ; /* date of current revision */
1999-04-04 18:10:51 +02:00
char * sample ;
2021-04-11 22:07:40 +02:00
char indentmode ; /* 'b', 't', or 'n' */
2021-04-14 21:27:23 +02:00
sentry_t shape [ NUM_SHAPES ] ;
2021-04-11 22:07:40 +02:00
size_t maxshapeheight ; /* height of highest shape in design */
1999-04-04 18:10:51 +02:00
size_t minwidth ;
size_t minheight ;
2021-04-14 21:27:23 +02:00
int padding [ NUM_SIDES ] ;
2021-04-02 15:45:04 +02:00
char * * tags ;
2021-04-11 22:07:40 +02:00
char * defined_in ; /* path to config file where this was defined */
1999-06-14 14:11:54 +02:00
reprule_t * current_rule ;
2021-04-11 22:07:40 +02:00
reprule_t * reprules ; /* applied when drawing a box */
1999-04-04 18:10:51 +02:00
size_t anz_reprules ;
2021-04-11 22:07:40 +02:00
reprule_t * revrules ; /* applied upon removal of a box */
1999-06-14 14:11:54 +02:00
size_t anz_revrules ;
1999-03-18 16:08:57 +01:00
} design_t ;
extern design_t * designs ;
2021-04-16 20:45:21 +02:00
extern int num_designs ;
1999-06-22 14:01:24 +02:00
1999-06-23 14:33:49 +02:00
2021-04-11 22:07:40 +02:00
typedef struct { /* Command line options: */
char valign ; /** `-a`: text position inside box */
char halign ; /** `-a`: ( h[lcr]v[tcb] ) */
char justify ; /** `-a`: 'l', 'c', 'r', or '\0' */
char * cld ; /** `-c`: commandline design definition */
design_t * design ; /** `-d`: currently used box design */
int design_choice_by_user ; /** `-d`, `-c`: true if design was chosen by user */
char * eol ; /** `-e`: line break to use. Never NULL, default to "\n". */
int eol_overridden ; /** `-e`: 0: value in `eol` is the default; 1: value in `eol` specified via `-e` */
char * f ; /** `-f`: config file path */
int help ; /** `-h`: flags if help argument was specified */
char indentmode ; /** `-i`: 'b', 't', 'n', or '\0' */
int killblank ; /** `-k`: kill blank lines, -1 if not set */
int l ; /** `-l`: list available designs */
int mend ; /** `-m`: 1 if -m is given, 2 in 2nd loop */
char * encoding ; /** `-n`: character encoding override for input and output text */
2021-04-14 21:27:23 +02:00
int padding [ NUM_SIDES ] ; /** `-p`: in spaces or lines resp. */
2021-04-11 22:07:40 +02:00
char * * query ; /** `-q`: parsed tag query expression passed in via -q; also, special handling of web UI needs */
int r ; /** `-r`: remove box from input */
long reqwidth ; /** `-s`: requested box width */
long reqheight ; /** `-s`: requested box height */
int tabstop ; /** `-t`: tab stop distance */
char tabexp ; /** `-t`: tab expansion mode (for leading tabs) */
int version_requested ; /** `-v`: request to show version number */
FILE * infile ;
FILE * outfile ;
1999-06-22 14:01:24 +02:00
} opt_t ;
extern opt_t opt ;
1999-03-18 16:08:57 +01:00
1999-06-23 21:21:15 +02:00
typedef struct {
2021-04-11 22:07:40 +02:00
size_t len ; /* length of visible text in columns (visible character positions in a text terminal), which is the same as the length of the 'text' field */
char * text ; /* ASCII line content, tabs expanded, ansi escapes removed, multi-byte chars replaced with one or more 'x' */
size_t invis ; /* number of invisble columns/characters (part of an ansi sequence) */
2021-01-30 21:03:57 +01:00
2021-04-11 22:07:40 +02:00
uint32_t * mbtext ; /* multi-byte (original) line content, tabs expanded. We use UTF-32 in order to enable pointer arithmetic. */
size_t num_chars ; /* total number of characters in mbtext, visible + invisible */
uint32_t * mbtext_org ; /* mbtext as originally allocated, so that we can free it again */
2021-01-30 21:03:57 +01:00
2021-04-11 22:07:40 +02:00
size_t * tabpos ; /* tab positions in expanded work strings, or NULL if not needed */
size_t tabpos_len ; /* number of tabs in a line */
size_t * posmap ; /* for each character in `text`, position of corresponding char in `mbtext`. Needed for box removal. */
1999-06-23 21:21:15 +02:00
} line_t ;
typedef struct {
line_t * lines ;
2021-04-15 22:13:29 +02:00
size_t num_lines ; /* number of entries in input */
2021-04-11 22:07:40 +02:00
size_t maxline ; /* length of longest input line */
size_t indent ; /* number of leading spaces found */
int final_newline ; /* true if the last line of input ends with newline */
1999-06-23 21:21:15 +02:00
} input_t ;
extern input_t input ;
1999-03-18 16:08:57 +01:00
1999-06-23 21:21:15 +02:00
# endif /* BOXES_H */
2021-03-06 13:40:26 +01:00
/*EOF*/ /* vim: set cindent sw=4: */