summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format43
-rw-r--r--.indent.pro38
-rw-r--r--smenu.c2674
3 files changed, 1385 insertions, 1370 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..77936dc
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,43 @@
+SortIncludes: 'false'
+BasedOnStyle: Mozilla
+AlignAfterOpenBracket: 'true'
+AlignConsecutiveAssignments: 'true'
+AlignConsecutiveDeclarations: 'true'
+AlignOperands: 'true'
+AlignEscapedNewlinesLeft: 'true'
+AlignOperands: 'true'
+AlignTrailingComments: 'true'
+ReflowComments: 'true'
+AllowAllParametersOfDeclarationOnNextLine: 'false'
+AllowShortBlocksOnASingleLine: 'false'
+AllowShortCaseLabelsOnASingleLine: 'false'
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: 'false'
+AllowShortLoopsOnASingleLine: 'false'
+AlwaysBreakBeforeMultilineStrings: 'true'
+BinPackArguments: 'true'
+BinPackParameters: 'true'
+BreakBeforeBraces: Allman
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeTernaryOperators: 'true'
+BreakConstructorInitializersBeforeComma: 'false'
+ColumnLimit: '80'
+ContinuationIndentWidth: '2'
+DerivePointerAlignment: 'false'
+IndentCaseLabels: 'true'
+IndentWidth: '2'
+KeepEmptyLinesAtTheStartOfBlocks: 'true'
+Language: Cpp
+MaxEmptyLinesToKeep: '1'
+PointerAlignment: Middle
+SpaceAfterCStyleCast: 'false'
+SpaceBeforeAssignmentOperators: 'true'
+SpaceBeforeParens: Never
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: 'false'
+SpacesBeforeTrailingComments: '1'
+SpacesInCStyleCastParentheses: 'false'
+SpacesInParentheses: 'false'
+SpacesInSquareBrackets: 'false'
+TabWidth: '2'
+UseTab: Never
diff --git a/.indent.pro b/.indent.pro
deleted file mode 100644
index 4632183..0000000
--- a/.indent.pro
+++ /dev/null
@@ -1,38 +0,0 @@
---blank-lines-after-commas
---declaration-comment-column 30
---brace-indent 0
---braces-after-if-line
---braces-after-struct-decl-line
---break-after-boolean-operator
---case-brace-indentation 0
---case-indentation 2
---continue-at-parentheses
---declaration-indentation 2
---dont-break-procedure-type
---dont-cuddle-do-while
---dont-cuddle-else
---dont-format-first-column-comments
---dont-space-special-semicolon
---honour-newlines
---indent-level 2
---leave-optional-blank-lines
---line-length 80
---no-blank-lines-before-block-comments
---no-comment-delimiters-on-blank-lines
---no-space-after-function-call-names
---no-space-after-parentheses
---no-tabs
---no-blank-lines-after-commas
---procnames-start-lines
---space-after-cast
---space-after-for
---space-after-if
---space-after-while
---struct-brace-indentation 0
---swallow-optional-blank-lines
---blank-lines-after-procedures
-//--blank-lines-after-declarations
---break-before-boolean-operator
---comment-indentation 30
---continue-at-parentheses
---comment-line-length 80
diff --git a/smenu.c b/smenu.c
index 56fb9c2..b9b5e32 100644
--- a/smenu.c
+++ b/smenu.c
@@ -47,18 +47,18 @@
/* ******** */
typedef struct charsetinfo_s charsetinfo_t;
-typedef struct langinfo_s langinfo_t;
-typedef struct ll_node_s ll_node_t;
-typedef struct ll_s ll_t;
-typedef struct term_s term_t;
-typedef struct tst_node_s tst_node_t;
-typedef struct toggle_s toggle_t;
-typedef struct win_s win_t;
-typedef struct word_s word_t;
-typedef struct txt_attr_s txt_attr_t;
-typedef struct limits_s limits_t;
-typedef struct sed_s sed_t;
-typedef struct interval_s interval_t;
+typedef struct langinfo_s langinfo_t;
+typedef struct ll_node_s ll_node_t;
+typedef struct ll_s ll_t;
+typedef struct term_s term_t;
+typedef struct tst_node_s tst_node_t;
+typedef struct toggle_s toggle_t;
+typedef struct win_s win_t;
+typedef struct word_s word_t;
+typedef struct txt_attr_s txt_attr_t;
+typedef struct limits_s limits_t;
+typedef struct sed_s sed_t;
+typedef struct interval_s interval_t;
/* ********** */
/* Prototypes */
@@ -68,77 +68,77 @@ static void help(win_t * win, term_t * term, int last_line);
static void short_usage(void);
static void usage(void);
-static void *xmalloc(size_t size);
-static void *xcalloc(size_t num, size_t size);
-static void *xrealloc(void *ptr, size_t size);
+static void * xmalloc(size_t size);
+static void * xcalloc(size_t num, size_t size);
+static void * xrealloc(void * ptr, size_t size);
-static interval_t *interval_new(void);
-static int interval_comp(void *a, void *b);
-static void interval_swap(void *a, void *b);
+static interval_t * interval_new(void);
+static int interval_comp(void * a, void * b);
+static void interval_swap(void * a, void * b);
-static int ll_append(ll_t * const list, void *const data);
-#if 0 /* here for coherency but not used. */
+static int ll_append(ll_t * const list, void * const data);
+#if 0 /* here for coherency but not used. */
static int ll_prepend(ll_t * const list, void *const data);
static void ll_insert_before(ll_t * const list, ll_node_t * node,
void *const data);
static void ll_insert_after(ll_t * const list, ll_node_t * node,
void *const data);
#endif
-static ll_node_t *ll_partition(ll_node_t * l, ll_node_t * h,
- int (*comp) (void *, void *),
- void (*swap) (void *, void *));
+static ll_node_t * ll_partition(ll_node_t * l, ll_node_t * h,
+ int (*comp)(void *, void *),
+ void (*swap)(void *, void *));
static void ll_quicksort(ll_node_t * l, ll_node_t * h,
- int (*comp) (void *, void *),
- void (*swap) (void *a, void *));
-static void ll_sort(ll_t * list, int (*comp) (void *, void *),
- void (*swap) (void *a, void *));
+ int (*comp)(void *, void *),
+ void (*swap)(void * a, void *));
+static void ll_sort(ll_t * list, int (*comp)(void *, void *),
+ void (*swap)(void * a, void *));
static int ll_delete(ll_t * const list, ll_node_t * node);
-static ll_node_t *ll_find(ll_t * const, void *const,
- int (*)(const void *, const void *));
+static ll_node_t * ll_find(ll_t * const, void * const,
+ int (*)(const void *, const void *));
static void ll_init(ll_t * list);
-static ll_node_t *ll_new_node(void);
-static ll_t *ll_new(void);
+static ll_node_t * ll_new_node(void);
+static ll_t * ll_new(void);
-static void ltrim(char *str, const char *trim);
-static void rtrim(char *str, const char *trim, size_t min_len);
-static int my_stricmp(const char *str1, const char *str2);
+static void ltrim(char * str, const char * trim);
+static void rtrim(char * str, const char * trim, size_t min_len);
+static int my_stricmp(const char * str1, const char * str2);
static int isprint7(int i);
static int isprint8(int i);
static int count_leading_set_bits(unsigned char c);
-static int get_cursor_position(int *const r, int *const c);
-static void get_terminal_size(int *const r, int *const c);
-static char *mb_strprefix(char *d, char *s, int n, int *pos);
-static int mb_strlen(char *str);
-static wchar_t *mb_strtowcs(char *s);
-static void *validate_mb(const void *str);
+static int get_cursor_position(int * const r, int * const c);
+static void get_terminal_size(int * const r, int * const c);
+static char * mb_strprefix(char * d, char * s, int n, int * pos);
+static int mb_strlen(char * str);
+static wchar_t * mb_strtowcs(char * s);
+static void * validate_mb(const void * str);
static int outch(int c);
static void restore_term(int const fd);
static void setup_term(int const fd);
-static void strip_ansi_color(char *s, toggle_t * toggle);
-static int strprefix(char *str1, char *str2);
+static void strip_ansi_color(char * s, toggle_t * toggle);
+static int strprefix(char * str1, char * str2);
-static int tst_cb(void *elem);
-static int tst_cb_cli(void *elem);
-#if 0 /* here for coherency but not used. */
+static int tst_cb(void * elem);
+static int tst_cb_cli(void * elem);
+#if 0 /* here for coherency but not used. */
static void tst_cleanup(tst_node_t * p);
#endif
-static tst_node_t *tst_insert(tst_node_t * p, wchar_t * w, void *data);
-static void *tst_prefix_search(tst_node_t * root, wchar_t * w,
- int (*callback) (void *));
-static void *tst_search(tst_node_t * root, wchar_t * w);
-static int tst_traverse(tst_node_t * p, int (*callback) (void *),
- int first_call);
-
-static int ini_load(const char *filename, win_t * win, term_t * term,
+static tst_node_t * tst_insert(tst_node_t * p, wchar_t * w, void * data);
+static void * tst_prefix_search(tst_node_t * root, wchar_t * w,
+ int (*callback)(void *));
+static void * tst_search(tst_node_t * root, wchar_t * w);
+static int tst_traverse(tst_node_t * p, int (*callback)(void *),
+ int first_call);
+
+static int ini_load(const char * filename, win_t * win, term_t * term,
limits_t * limits,
- int (*report) (win_t * win, term_t * term,
- limits_t * limits, const char *section,
- const char *name, char *value));
+ int (*report)(win_t * win, term_t * term, limits_t * limits,
+ const char * section, const char * name,
+ char * value));
static int ini_cb(win_t * win, term_t * term, limits_t * limits,
- const char *section, const char *name, char *value);
-static char *make_ini_path(char *name, char *base);
+ const char * section, const char * name, char * value);
+static char * make_ini_path(char * name, char * base);
static void set_foreground_color(term_t * term, int color);
static void set_background_color(term_t * term, int color);
@@ -147,85 +147,86 @@ static void set_win_start_end(win_t * win, int current, int last);
static int build_metadata(word_t * word_a, term_t * term, int count,
win_t * win);
static int disp_lines(word_t * word_a, win_t * win, toggle_t * toggle,
- int current, int count, int search_mode, char *search_buf,
- term_t * term, int last_line, char *tmp_max_word,
- langinfo_t * langinfo);
-static void get_message_lines(char *message, ll_t * message_lines_list,
- int *message_max_width, int *message_max_len);
+ int current, int count, int search_mode,
+ char * search_buf, term_t * term, int last_line,
+ char * tmp_max_word, langinfo_t * langinfo);
+static void get_message_lines(char * message, ll_t * message_lines_list,
+ int * message_max_width, int * message_max_len);
static int disp_message(ll_t * message_lines_list, int width, int max_len,
term_t * term, win_t * win);
-static void disp_word(word_t * word_a, int pos, int search_mode, char *buffer,
- term_t * term, win_t * win, char *tmp_max_word);
-static int egetopt(int nargc, char **nargv, char *ostr);
-static int expand(char *src, char *dest, langinfo_t * langinfo);
-static int get_bytes(FILE * input, char *mb_buffer, ll_t * word_delims_list,
+static void disp_word(word_t * word_a, int pos, int search_mode, char * buffer,
+ term_t * term, win_t * win, char * tmp_max_word);
+static int egetopt(int nargc, char ** nargv, char * ostr);
+static int expand(char * src, char * dest, langinfo_t * langinfo);
+static int get_bytes(FILE * input, char * mb_buffer, ll_t * word_delims_list,
toggle_t * toggle, langinfo_t * langinfo);
-static int get_scancode(unsigned char *s, int max);
-static char *get_word(FILE * input, ll_t * word_delims_list,
- ll_t * record_delims_list, char *mb_buffer,
- unsigned char *is_last, toggle_t * toggle,
- langinfo_t * langinfo, win_t * win, limits_t * limits);
-
-static void left_margin_putp(char *s, term_t * term, win_t * win);
-static void right_margin_putp(char *s1, char *s2, langinfo_t * langinfo,
+static int get_scancode(unsigned char * s, int max);
+static char * get_word(FILE * input, ll_t * word_delims_list,
+ ll_t * record_delims_list, char * mb_buffer,
+ unsigned char * is_last, toggle_t * toggle,
+ langinfo_t * langinfo, win_t * win, limits_t * limits);
+
+static void left_margin_putp(char * s, term_t * term, win_t * win);
+static void right_margin_putp(char * s1, char * s2, langinfo_t * langinfo,
term_t * term, win_t * win, int line, int offset);
-static int search_next(tst_node_t * tst, word_t * word_a, char *search_buf,
+static int search_next(tst_node_t * tst, word_t * word_a, char * search_buf,
int after_only);
static void sig_handler(int s);
static void set_new_first_column(win_t * win, term_t * term, word_t * word_a);
static int parse_sed_like_string(sed_t * sed);
-static int replace(char *orig, sed_t * sed, char *buf, size_t bufsiz);
+static int replace(char * orig, sed_t * sed, char * buf, size_t bufsiz);
-static int decode_txt_attr_toggles(char *s, txt_attr_t * attr);
-static int parse_txt_attr(char *str, txt_attr_t * attr, short max_color);
+static int decode_txt_attr_toggles(char * s, txt_attr_t * attr);
+static int parse_txt_attr(char * str, txt_attr_t * attr, short max_color);
static void apply_txt_attr(term_t * term, txt_attr_t attr);
-static int (*my_isprint) (int);
+static int (*my_isprint)(int);
-static int delims_cmp(const void *a, const void *b);
+static int delims_cmp(const void * a, const void * b);
/* **************** */
/* Global variables */
/* **************** */
-int dummy_rc;
-
-int count = 0; /* number of words read from stdin */
-int current; /* index the current selection *
- * (under the cursor) */
-int new_current; /* final current position, (used in *
- * search function) */
-int *line_nb_of_word_a; /* array containing the line number *
- * (from 0) of each word read */
-int *first_word_in_line_a; /* array containing the index of *
- * the first word of each lines */
-int search_mode = 0; /* 1 if in search mode else 0 */
-int help_mode = 0; /* 1 if help is display else 0 */
+int dummy_rc; /* temporary variable to silence *
+ * the compiler */
+
+int count = 0; /* number of words read from stdin */
+int current; /* index the current selection *
+ * (under the cursor) */
+int new_current; /* final current position, (used in *
+ * search function) */
+int * line_nb_of_word_a; /* array containing the line number *
+ * (from 0) of each word read */
+int * first_word_in_line_a; /* array containing the index of *
+ * the first word of each lines */
+int search_mode = 0; /* 1 if in search mode else 0 */
+int help_mode = 0; /* 1 if help is display else 0 */
/* UTF-8 useful symbols */
/* """"""""""""""""""""" */
-char *broken_line_sym = "\xc2\xa6"; /* broken_bar */
-char *shift_left_sym = "\xe2\x86\x90"; /* leftwards_arrow */
-char *shift_right_sym = "\xe2\x86\x92"; /* rightwards_arrow */
+char * broken_line_sym = "\xc2\xa6"; /* broken_bar */
+char * shift_left_sym = "\xe2\x86\x90"; /* leftwards_arrow */
+char * shift_right_sym = "\xe2\x86\x92"; /* rightwards_arrow */
-char *sbar_line = "\xe2\x94\x82"; /* box_drawings_light_vertical */
-char *sbar_top = "\xe2\x94\x90"; /* box_drawings_light_down_and_left */
-char *sbar_down = "\xe2\x94\x98"; /* box_drawings_light_up_and_left */
-char *sbar_curs = "\xe2\x95\x91"; /* box_drawings_double_vertical */
-char *sbar_arr_up = "\xe2\x96\xb2"; /* black_up_pointing_triangle */
-char *sbar_arr_down = "\xe2\x96\xbc"; /* black_down_pointing_triangle */
+char * sbar_line = "\xe2\x94\x82"; /* box_drawings_light_vertical */
+char * sbar_top = "\xe2\x94\x90"; /* box_drawings_light_down_and_left */
+char * sbar_down = "\xe2\x94\x98"; /* box_drawings_light_up_and_left */
+char * sbar_curs = "\xe2\x95\x91"; /* box_drawings_double_vertical */
+char * sbar_arr_up = "\xe2\x96\xb2"; /* black_up_pointing_triangle */
+char * sbar_arr_down = "\xe2\x96\xbc"; /* black_down_pointing_triangle */
-tst_node_t *root;
+tst_node_t * root;
/* Variables used in signal handlers */
/* """"""""""""""""""""""""""""""""" */
-volatile sig_atomic_t got_winch = 0;
-volatile sig_atomic_t got_winch_alrm = 0;
+volatile sig_atomic_t got_winch = 0;
+volatile sig_atomic_t got_winch_alrm = 0;
volatile sig_atomic_t got_search_alrm = 0;
-volatile sig_atomic_t got_help_alrm = 0;
+volatile sig_atomic_t got_help_alrm = 0;
/* ***************** */
/* emums and structs */
@@ -250,36 +251,36 @@ enum filter_infos
/* """"""""""""""""""" */
struct langinfo_s
{
- int utf8; /* charset is UTF-8 */
- size_t bits; /* number of bits in the charset */
+ int utf8; /* charset is UTF-8 */
+ size_t bits; /* number of bits in the charset */
};
struct charsetinfo_s
{
- char *name; /* canonical name of the allowed charset */
- size_t bits; /* number of bits in this charset */
+ char * name; /* canonical name of the allowed charset */
+ size_t bits; /* number of bits in this charset */
};
/* Various toggles which can be set with command line options */
/* """""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
struct toggle_s
{
- int del_line; /* 1 if the clean option is set (-d) else 0 */
- int enter_val_in_search; /* 1 if ENTER validates in search mode else 0 */
- int no_scrollbar; /* 1 to disable the scrollbar display else 0 */
- int blank_nonprintable; /* 1 to try to display non-blanks in *
- * symbolic form else 0 */
- int keep_spaces; /* 1 to keep the trailing spaces in columne *
- * and tabulate mode. */
+ int del_line; /* 1 if the clean option is set (-d) else 0 */
+ int enter_val_in_search; /* 1 if ENTER validates in search mode else 0 */
+ int no_scrollbar; /* 1 to disable the scrollbar display else 0 */
+ int blank_nonprintable; /* 1 to try to display non-blanks in *
+ * symbolic form else 0 */
+ int keep_spaces; /* 1 to keep the trailing spaces in columne *
+ * and tabulate mode. */
};
/* Structure to store the default or imposed smenu limits */
/* """""""""""""""""""""""""""""""""""""""""""""""""""""" */
struct limits_s
{
- int word_length;
- int words;
- int cols;
+ int word_length; /* maximum number of bytes in a word */
+ int words; /* maximum number of words */
+ int cols; /* maximum number of columns */
};
/* Terminal setting variables */
@@ -289,17 +290,18 @@ struct termios old_in_attrs;
/* Interval timers used */
/* """""""""""""""""""" */
-struct itimerval search_itv;
-struct itimerval hlp_itv;
-struct itimerval winch_itv;
+struct itimerval search_itv; /* used when searching */
+struct itimerval hlp_itv; /* used to remove the help line */
+struct itimerval winch_itv; /* used to delay the redisplay when *
+ * the terminal is resized */
/* Structure containing the attributes components */
/* """""""""""""""""""""""""""""""""""""""""""""" */
struct txt_attr_s
{
signed char is_set;
- short fg;
- short bg;
+ short fg;
+ short bg;
signed char bold;
signed char dim;
signed char reverse;
@@ -312,45 +314,45 @@ struct txt_attr_s
/* """""""""""""""""""""""""""""""""""""""""""""""""" */
struct term_s
{
- int ncolumns; /* number of columns */
- int nlines; /* number of lines */
- int curs_column; /* current cursor column */
- int curs_line; /* current cursor line */
- short colors; /* number of available colors */
- short color_method; /* color method (0=classic (0-7), 1=ANSI) */
-
- char has_cursor_up; /* has cuu1 terminfo capability */
- char has_cursor_down; /* has cud1 terminfo capability */
- char has_cursor_left; /* has cub1 terminfo capability */
- char has_cursor_right; /* has cuf1 terminfo capability */
- char has_save_cursor; /* has sc terminfo capability */
- char has_restore_cursor; /* has rc terminfo capability */
- char has_setf; /* has set_foreground terminfo capability */
- char has_setb; /* has set_background terminfo capability */
- char has_setaf; /* idem for set_a_foreground (ANSI) */
- char has_setab; /* idem for set_a_background (ANSI) */
- char has_hpa; /* has column_address terminfo capability */
- char has_bold; /* has bold mode */
- char has_reverse; /* has reverse mode */
- char has_underline; /* has underline mode */
- char has_standout; /* has standout mode */
+ int ncolumns; /* number of columns */
+ int nlines; /* number of lines */
+ int curs_column; /* current cursor column */
+ int curs_line; /* current cursor line */
+ short colors; /* number of available colors */
+ short color_method; /* color method (0=classic (0-7), 1=ANSI) */
+
+ char has_cursor_up; /* has cuu1 terminfo capability */
+ char has_cursor_down; /* has cud1 terminfo capability */
+ char has_cursor_left; /* has cub1 terminfo capability */
+ char has_cursor_right; /* has cuf1 terminfo capability */
+ char has_save_cursor; /* has sc terminfo capability */
+ char has_restore_cursor; /* has rc terminfo capability */
+ char has_setf; /* has set_foreground terminfo capability */
+ char has_setb; /* has set_background terminfo capability */
+ char has_setaf; /* idem for set_a_foreground (ANSI) */
+ char has_setab; /* idem for set_a_background (ANSI) */
+ char has_hpa; /* has column_address terminfo capability */
+ char has_bold; /* has bold mode */
+ char has_reverse; /* has reverse mode */
+ char has_underline; /* has underline mode */
+ char has_standout; /* has standout mode */
};
/* Structure describing a word */
/* """"""""""""""""""""""""""" */
struct word_s
{
- int start, end; /* start/end absolute horiz. word positions *
- * on the screen */
- size_t mbytes; /* number of multibytes to display */
- int special_level; /* can vary from 0 to 5; 0 meaning normal */
- char *str; /* display string associated with this word */
- size_t len; /* number of bytes of str (for trimming) */
- char *orig; /* NULL or original string if is had been *
- * shortened for being displayed or altered *
- * by is expansion. */
- unsigned char is_last; /* 1 if the word is the last of a line */
- unsigned char is_selectable; /* word is is_selectable */
+ int start, end; /* start/end absolute horiz. word positions *
+ * on the screen */
+ size_t mbytes; /* number of multibytes to display */
+ int special_level; /* can vary from 0 to 5; 0 meaning normal */
+ char * str; /* display string associated with this word */
+ size_t len; /* number of bytes of str (for trimming) */
+ char * orig; /* NULL or original string if is had been *
+ * shortened for being displayed or altered *
+ * by is expansion. */
+ unsigned char is_last; /* 1 if the word is the last of a line */
+ unsigned char is_selectable; /* word is is_selectable */
};
/* Structure describing the window in which the user */
@@ -358,45 +360,45 @@ struct word_s
/* """"""""""""""""""""""""""""""""""""""""""""""""" */
struct win_s
{
- int start, end; /* index of the first and last word */
- int first_column; /* number of the first character displayed */
- int cur_line; /* relative number of the cursor line (1+) */
- int asked_max_lines; /* requested number of lines in the window */
- int max_lines; /* effective number of lines in the window */
- int max_cols; /* max number of words in a sigle line */
- int max_width; /* max line length. In column, tab or line *
- * mode it can be greater than the *
- * terminal width */
- int offset; /* window offset user when centered */
-
- unsigned char tab_mode; /* -t */
- unsigned char col_mode; /* -c */
- unsigned char line_mode; /* -l */
- unsigned char col_sep; /* -g */
- unsigned char wide; /* -w */
- unsigned char center; /* -M */
-
- txt_attr_t cursor_attr; /* current cursor attributes */
- txt_attr_t bar_attr; /* scrollbar attributes */
- txt_attr_t shift_attr; /* shift indicator attributes */
- txt_attr_t search_field_attr; /* search mode field attributes */
- txt_attr_t search_text_attr; /* search mode text attributes */
- txt_attr_t exclude_attr; /* non-selectable words attributes */
- txt_attr_t special_attr[5]; /* special (-1,...) words attributes */
+ int start, end; /* index of the first and last word */
+ int first_column; /* number of the first character displayed */
+ int cur_line; /* relative number of the cursor line (1+) */
+ int asked_max_lines; /* requested number of lines in the window */
+ int max_lines; /* effective number of lines in the window */
+ int max_cols; /* max number of words in a sigle line */
+ int max_width; /* max line length. In column, tab or line *
+ * mode it can be greater than the *
+ * terminal width */
+ int offset; /* window offset user when centered */
+
+ unsigned char tab_mode; /* -t */
+ unsigned char col_mode; /* -c */
+ unsigned char line_mode; /* -l */
+ unsigned char col_sep; /* -g */
+ unsigned char wide; /* -w */
+ unsigned char center; /* -M */
+
+ txt_attr_t cursor_attr; /* current cursor attributes */
+ txt_attr_t bar_attr; /* scrollbar attributes */
+ txt_attr_t shift_attr; /* shift indicator attributes */
+ txt_attr_t search_field_attr; /* search mode field attributes */
+ txt_attr_t search_text_attr; /* search mode text attributes */
+ txt_attr_t exclude_attr; /* non-selectable words attributes */
+ txt_attr_t special_attr[5]; /* special (-1,...) words attributes */
};
/* Sed like node structure */
/* """"""""""""""""""""""" */
struct sed_s
{
- char *pattern; /* pattern to be matched */
- char *substitution; /* substitution string */
- unsigned char visual; /* Visual flag: alterations are only *
- * visual */
- unsigned char global; /* Global flag: alterations can *
- * occur more than once */
- unsigned char stop; /* Stop flag: only one alteration *
- * per word is allowed */
+ char * pattern; /* pattern to be matched */
+ char * substitution; /* substitution string */
+ unsigned char visual; /* Visual flag: alterations are only *
+ * visual */
+ unsigned char global; /* Global flag: alterations can *
+ * occur more than once */
+ unsigned char stop; /* Stop flag: only one alteration *
+ * per word is allowed */
regex_t re;
};
@@ -419,7 +421,7 @@ struct tst_node_s
wchar_t splitchar;
tst_node_t *lokid, *eqkid, *hikid;
- void *data;
+ void * data;
};
/* ******************************* */
@@ -430,18 +432,18 @@ struct tst_node_s
/* """""""""""""""""""""""""" */
struct ll_node_s
{
- void *data;
- struct ll_node_s *next;
- struct ll_node_s *prev;
+ void * data;
+ struct ll_node_s * next;
+ struct ll_node_s * prev;
};
/* Linked List structure */
/* """"""""""""""""""""" */
struct ll_s
{
- ll_node_t *head;
- ll_node_t *tail;
- size_t len;
+ ll_node_t * head;
+ ll_node_t * tail;
+ size_t len;
};
/* ************** */
@@ -488,42 +490,52 @@ usage(void)
fprintf(stderr, "The following options are available:\n\n");
fprintf(stderr, "-h displays this help.\n");
fprintf(stderr, "-n sets the number of lines in the selection window.\n");
- fprintf(stderr, "-t tabulates the items. The number of columns can be "
- "limited with\n");
+ fprintf(stderr,
+ "-t tabulates the items. The number of columns can be limited "
+ "with\n");
fprintf(stderr, " an optional number.\n");
- fprintf(stderr, "-k do not trim the space surrounding the output string "
- "if any.\n");
- fprintf(stderr, "-s sets the initial cursor position (read the manual for "
+ fprintf(stderr,
+ "-k do not trim the space surrounding the output string if any.\n");
+ fprintf(stderr,
+ "-s sets the initial cursor position (read the manual for "
"more details).\n");
fprintf(stderr, "-m displays a one-line message above the window\n");
- fprintf(stderr, "-w uses all the terminal width for the columns if "
- "their numbers is given.\n");
+ fprintf(stderr,
+ "-w uses all the terminal width for the columns if their numbers "
+ "is given.\n");
fprintf(stderr, "-d deletes the selection window on exit.\n");
fprintf(stderr, "-M centers the display if possible.\n");
- fprintf(stderr, "-c is like -t without argument "
- "but respects end of lines.\n");
+ fprintf(stderr,
+ "-c is like -t without argument but respects end of lines.\n");
fprintf(stderr, "-l is like -c without column alignments.\n");
- fprintf(stderr, "-r enables ENTER to validate the selection even "
- "in search mode.\n");
+ fprintf(stderr,
+ "-r enables ENTER to validate the selection even in "
+ "search mode.\n");
fprintf(stderr, "-b displays the non printable characters as space.\n");
- fprintf(stderr, "-i sets the regex input filter to match the "
- "selectable words.\n");
- fprintf(stderr, "-e sets the regex input filter to match the "
- "non-selectable words.\n");
+ fprintf(stderr,
+ "-i sets the regex input filter to match the selectable words.\n");
+ fprintf(stderr,
+ "-e sets the regex input filter to match the non-selectable "
+ "words.\n");
fprintf(stderr, "-C sets column restrictions for selections.\n");
fprintf(stderr, "-R sets rows restrictions for selections.\n");
- fprintf(stderr, "-S sets the post-processing action to apply to "
- "all words.\n");
- fprintf(stderr, "-I sets the post-processing action to apply to "
- "selectable words only.\n");
- fprintf(stderr, "-E sets the post-processing action to apply to "
- "non-selectable words only.\n");
- fprintf(stderr, "-A forces a class of words to be the first "
- "of the line they appear in.\n");
- fprintf(stderr, "-Z forces a class of words to be the latest "
- "of the line they appear in.\n");
- fprintf(stderr, "-1,-2,...,-5 gives specific colors to up to 5 "
- "classes of selectable words.\n");
+ fprintf(stderr,
+ "-S sets the post-processing action to apply to all words.\n");
+ fprintf(stderr,
+ "-I sets the post-processing action to apply to selectable "
+ "words only.\n");
+ fprintf(stderr,
+ "-E sets the post-processing action to apply to non-selectable "
+ "words only.\n");
+ fprintf(stderr,
+ "-A forces a class of words to be the first of the line they "
+ "appear in.\n");
+ fprintf(stderr,
+ "-Z forces a class of words to be the latest of the line they "
+ "appear in.\n");
+ fprintf(stderr,
+ "-1,-2,...,-5 gives specific colors to up to 5 classes of "
+ "selectable words.\n");
fprintf(stderr, "-g separates columns with '|' in tabulate mode.\n");
fprintf(stderr, "-q prevents the scrollbar display.\n");
fprintf(stderr, "-W sets the input words separators.\n");
@@ -541,8 +553,7 @@ usage(void)
fprintf(stderr, "The search key activates a timed search mode in which\n");
fprintf(stderr, "you can enter the first letters of the searched word.\n");
fprintf(stderr, "When entering this mode you have 7s to start typing\n");
- fprintf(stderr, "and each entered letter gives you 5 more seconds "
- "before\n");
+ fprintf(stderr, "and each entered letter gives you 5 more seconds before\n");
fprintf(stderr, "the timeout. After that the search mode is ended.\n\n");
fprintf(stderr, "Notes:\n");
fprintf(stderr, "- the timer can be cancelled by pressing ESC.\n");
@@ -559,60 +570,46 @@ usage(void)
void
help(win_t * win, term_t * term, int last_line)
{
- size_t index;
- int line = 0;
- int len = 0;
- int offset = 0;
+ size_t index; /* used to identify the objects int the help line */
+ int line = 0; /* number of windows lines used by the help line */
+ int len = 0; /* length of the help line */
+ int offset = 0;
struct entry_s
{
- char attr;
- char *str;
- int len;
+ char attr; /* r=reverse, n=normal, b=bold */
+ char * str; /* string to be displayed for un object in the help line */
+ int len; /* length of one of these objects */
};
struct entry_s entries[] = {
- {'r', "HLP", 3},
- {'n', " ", 1},
- {'n', "Move:", 5},
- {'b', "Arrows", 6},
- {'n', "|", 1},
- {'b', "h", 1},
- {'b', "j", 1},
- {'b', "k", 1},
- {'b', "l", 1},
- {'n', ",", 1},
- {'b', "PgUp", 4},
- {'n', "/", 1},
- {'b', "PgDn", 4},
- {'n', "/", 1},
- {'b', "Home", 4},
- {'n', "/", 1},
- {'b', "End", 3},
- {'n', " ", 1},
- {'n', "Cancel:", 7},
- {'b', "q", 1},
- {'n', " ", 1},
- {'n', "Confirm:", 8},
- {'b', "CR", 2},
- {'n', " ", 1},
- {'n', "Search:", 7},
- {'b', "/", 1},
- {'n', "|", 1},
- {'b', "^F", 2},
- {'n', "|", 1},
- {'b', "SP", 2},
- {'n', "|", 1},
- {'b', "n", 1},
- {(char) 0, NULL, 0}
+ { 'r', "HLP", 3 }, { 'n', " ", 1 }, { 'n', "Move:", 5 },
+ { 'b', "Arrows", 6 }, { 'n', "|", 1 }, { 'b', "h", 1 },
+ { 'b', "j", 1 }, { 'b', "k", 1 }, { 'b', "l", 1 },
+ { 'n', ",", 1 }, { 'b', "PgUp", 4 }, { 'n', "/", 1 },
+ { 'b', "PgDn", 4 }, { 'n', "/", 1 }, { 'b', "Home", 4 },
+ { 'n', "/", 1 }, { 'b', "End", 3 }, { 'n', " ", 1 },
+ { 'n', "Cancel:", 7 }, { 'b', "q", 1 }, { 'n', " ", 1 },
+ { 'n', "Confirm:", 8 }, { 'b', "CR", 2 }, { 'n', " ", 1 },
+ { 'n', "Search:", 7 }, { 'b', "/", 1 }, { 'n', "|", 1 },
+ { 'b', "^F", 2 }, { 'n', "|", 1 }, { 'b', "SP", 2 },
+ { 'n', "|", 1 }, { 'b', "n", 1 }, { (char)0, NULL, 0 }
};
- (void) tputs(save_cursor, 1, outch);
+ /* Save the position of the terminal cursor so that it can be */
+ /* put back there after printing of the help line */
+ /* """""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
+ (void)tputs(save_cursor, 1, outch);
+ /* Center the help line if the -M (Middle option is set. */
+ /* The 39 below must correspond to the length of the help line */
+ /* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
if (win->offset > 0)
if ((offset = win->offset + win->max_width / 2 - 39) > 0)
printf("%*s", offset, " ");
+ /* print the different objects forming the help line */
+ /* """"""""""""""""""""""""""""""""""""""""""""""""" */
for (index = 0; index < sizeof(entries) / sizeof(struct entry_s) - 1; index++)
{
if ((len += entries[index].len) >= term->ncolumns - 2)
@@ -623,31 +620,34 @@ help(win_t * win, term_t * term, int last_line)
break;
len = entries[index].len;
- (void) fputs("\n", stdout);
+ (void)fputs("\n", stdout);
}
switch (entries[index].attr)
{
case 'b':
if (term->has_bold)
- (void) tputs(enter_bold_mode, 1, outch);
+ (void)tputs(enter_bold_mode, 1, outch);
break;
case 'r':
if (term->has_reverse)
- (void) tputs(enter_reverse_mode, 1, outch);
+ (void)tputs(enter_reverse_mode, 1, outch);
else if (term->has_standout)
- (void) tputs(enter_standout_mode, 1, outch);
+ (void)tputs(enter_standout_mode, 1, outch);
break;
case 'n':
- (void) tputs(exit_attribute_mode, 1, outch);
+ (void)tputs(exit_attribute_mode, 1, outch);
break;
}
- (void) fputs(entries[index].str, stdout);
+ (void)fputs(entries[index].str, stdout);
}
- (void) tputs(exit_attribute_mode, 1, outch);
- (void) tputs(clr_eol, 1, outch);
- (void) tputs(restore_cursor, 1, outch);
+ (void)tputs(exit_attribute_mode, 1, outch);
+ (void)tputs(clr_eol, 1, outch);
+
+ /* Relocate the cursor to its saved position */
+ /* """"""""""""""""""""""""""""""""""""""""" */
+ (void)tputs(restore_cursor, 1, outch);
}
/* *************************** */
@@ -667,15 +667,16 @@ help(win_t * win, term_t * term, int last_line)
void *
xmalloc(size_t size)
{
- void *allocated;
+ void * allocated;
size_t real_size;
real_size = (size > 0) ? size : 1;
allocated = malloc(real_size);
if (allocated == NULL)
{
- fprintf(stderr, "Error: Insufficient memory "
- "(attempt to malloc %lu bytes)\n", (unsigned long int) size);
+ fprintf(stderr,
+ "Error: Insufficient memory (attempt to malloc %lu bytes)\n",
+ (unsigned long int)size);