Skip to content

Commit

Permalink
Add new type lbool for boolean expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 14, 2023
1 parent 2f5faad commit 8992745
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 145 deletions.
14 changes: 7 additions & 7 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static int maxbufs = -1;
extern int autobuf;
extern int sigs;
extern int follow_mode;
extern int waiting_for_data;
extern lbool waiting_for_data;
extern constant char helpdata[];
extern constant int size_helpdata;
extern IFILE curr_ifile;
Expand All @@ -155,7 +155,7 @@ static int ch_get(void)
struct buf *bp;
struct bufnode *bn;
ssize_t n;
int read_again;
lbool read_again;
int h;
POSITION pos;
POSITION len;
Expand Down Expand Up @@ -384,7 +384,7 @@ public void ch_ungetchar(int c)
*/
public void end_logfile(void)
{
static int tried = FALSE;
static lbool tried = FALSE;

if (logfile < 0)
return;
Expand All @@ -411,7 +411,7 @@ public void sync_logfile(void)
{
struct buf *bp;
struct bufnode *bn;
int warned = FALSE;
lbool warned = FALSE;
BLOCKNUM block;
BLOCKNUM nblocks;

Expand All @@ -420,7 +420,7 @@ public void sync_logfile(void)
nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE;
for (block = 0; block < nblocks; block++)
{
int wrote = FALSE;
lbool wrote = FALSE;
FOR_BUFS(bn)
{
bp = bufnode_buf(bn);
Expand All @@ -445,7 +445,7 @@ public void sync_logfile(void)
/*
* Determine if a specific block is currently in one of the buffers.
*/
static int buffered(BLOCKNUM block)
static lbool buffered(BLOCKNUM block)
{
struct buf *bp;
struct bufnode *bn;
Expand Down Expand Up @@ -869,7 +869,7 @@ public void ch_init(int f, int flags)
*/
public void ch_close(void)
{
int keepstate = FALSE;
lbool keepstate = FALSE;

if (thisfile == NULL)
return;
Expand Down
28 changes: 14 additions & 14 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ static void ilocale(void)
/*
* Define the printing format for control (or binary utf) chars.
*/
public void setfmt(constant char *s, constant char **fmtvarptr, int *attrptr, constant char *default_fmt, int for_printf)
public void setfmt(constant char *s, constant char **fmtvarptr, int *attrptr, constant char *default_fmt, lbool for_printf)
{
if (s && utf_mode)
{
Expand Down Expand Up @@ -617,36 +617,36 @@ public int utf_len(unsigned char ch)
/*
* Does the parameter point to the lead byte of a well-formed UTF-8 character?
*/
public int is_utf8_well_formed(constant char *ss, int slen)
public lbool is_utf8_well_formed(constant char *ss, int slen)
{
int i;
int len;
constant unsigned char *s = (constant unsigned char *) ss;

if (IS_UTF8_INVALID(s[0]))
return (0);
return (FALSE);

len = utf_len(s[0]);
if (len > slen)
return (0);
return (FALSE);
if (len == 1)
return (1);
return (TRUE);
if (len == 2)
{
if (s[0] < 0xC2)
return (0);
return (FALSE);
} else
{
unsigned char mask;
mask = (~((1 << (8-len)) - 1)) & 0xFF;
if (s[0] == mask && (s[1] & mask) == 0x80)
return (0);
return (FALSE);
}

for (i = 1; i < len; i++)
if (!IS_UTF8_TRAIL(s[i]))
return (0);
return (1);
return (FALSE);
return (TRUE);
}

/*
Expand Down Expand Up @@ -843,7 +843,7 @@ static struct wchar_range comb_table[] = {
};


static int is_in_table(LWCHAR ch, struct wchar_range_table *table)
static lbool is_in_table(LWCHAR ch, struct wchar_range_table *table)
{
unsigned int hi;
unsigned int lo;
Expand All @@ -870,7 +870,7 @@ static int is_in_table(LWCHAR ch, struct wchar_range_table *table)
* Is a character a UTF-8 composing character?
* If a composing character follows any char, the two combine into one glyph.
*/
public int is_composing_char(LWCHAR ch)
public lbool is_composing_char(LWCHAR ch)
{
if (is_in_table(ch, &user_prt_table)) return FALSE;
return is_in_table(ch, &user_compose_table) ||
Expand All @@ -881,7 +881,7 @@ public int is_composing_char(LWCHAR ch)
/*
* Should this UTF-8 character be treated as binary?
*/
public int is_ubin_char(LWCHAR ch)
public lbool is_ubin_char(LWCHAR ch)
{
if (is_in_table(ch, &user_prt_table)) return FALSE;
return is_in_table(ch, &user_ubin_table) ||
Expand All @@ -892,7 +892,7 @@ public int is_ubin_char(LWCHAR ch)
/*
* Is this a double width UTF-8 character?
*/
public int is_wide_char(LWCHAR ch)
public lbool is_wide_char(LWCHAR ch)
{
return is_in_table(ch, &user_wide_table) ||
is_in_table(ch, &wide_table);
Expand All @@ -903,7 +903,7 @@ public int is_wide_char(LWCHAR ch)
* A combining char acts like an ordinary char, but if it follows
* a specific char (not any char), the two combine into one glyph.
*/
public int is_combining_char(LWCHAR ch1, LWCHAR ch2)
public lbool is_combining_char(LWCHAR ch1, LWCHAR ch2)
{
/* The table is small; use linear search. */
int i;
Expand Down
18 changes: 9 additions & 9 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int cmd_complete(int action);
/*
* These variables are statics used by cmd_complete.
*/
static int in_completion = FALSE;
static lbool in_completion = FALSE;
static char *tk_text;
static char *tk_original;
static constant char *tk_ipoint;
Expand Down Expand Up @@ -71,7 +71,7 @@ struct mlist
struct mlist *prev;
struct mlist *curr_mp;
char *string;
int modified;
lbool modified;
};

/*
Expand Down Expand Up @@ -709,7 +709,7 @@ static void ml_unlink(struct mlist *ml)
/*
* Add a string to an mlist.
*/
public void cmd_addhist(struct mlist *mlist, constant char *cmd, int modified)
public void cmd_addhist(struct mlist *mlist, constant char *cmd, lbool modified)
{
#if CMD_HISTORY
struct mlist *ml;
Expand Down Expand Up @@ -1284,7 +1284,7 @@ public LINENUM cmd_int(long *frac)
{
constant char *p;
LINENUM n = 0;
int err;
lbool err;

for (p = cmdbuf; *p >= '0' && *p <= '9'; p++)
{
Expand Down Expand Up @@ -1340,7 +1340,7 @@ static int mlist_size(struct mlist *ml)
/*
* Get the name of the history file.
*/
static char * histfile_find(int must_exist)
static char * histfile_find(lbool must_exist)
{
constant char *home = lgetenv("HOME");
char *name = NULL;
Expand All @@ -1367,7 +1367,7 @@ static char * histfile_find(int must_exist)
return (name);
}

static char * histfile_name(int must_exist)
static char * histfile_name(lbool must_exist)
{
constant char *name;
char *wname;
Expand Down Expand Up @@ -1465,7 +1465,7 @@ static void read_cmdhist2(void (*action)(void*,struct mlist*,constant char*), vo
fclose(f);
}

static void read_cmdhist(void (*action)(void*,struct mlist*,constant char*), void *uparam, int skip_search, int skip_shell)
static void read_cmdhist(void (*action)(void*,struct mlist*,constant char*), void *uparam, lbool skip_search, lbool skip_shell)
{
if (!secure_allow(SF_HISTORY))
return;
Expand Down Expand Up @@ -1589,7 +1589,7 @@ static void copy_hist(void *uparam, struct mlist *ml, constant char *string)
static void make_file_private(FILE *f)
{
#if HAVE_FCHMOD
int do_chmod = TRUE;
lbool do_chmod = TRUE;
#if HAVE_STAT
struct stat statbuf;
int r = fstat(fileno(f), &statbuf);
Expand All @@ -1606,7 +1606,7 @@ static void make_file_private(FILE *f)
* Does the history file need to be updated?
*/
#if CMD_HISTORY
static int histfile_modified(void)
static lbool histfile_modified(void)
{
if (mlist_search.modified)
return TRUE;
Expand Down
9 changes: 4 additions & 5 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static long fraction; /* The fractional part of the number */
static struct loption *curropt;
static int opt_lower;
static int optflag;
static int optgetname;
static lbool optgetname;
static POSITION bottompos;
static int save_hshift;
static int save_bs_mode;
Expand Down Expand Up @@ -397,7 +397,7 @@ static int mca_opt_nonfirst_char(LWCHAR c)
{
constant char *p;
constant char *oname;
int err;
lbool ambig;

if (curropt != NULL)
{
Expand All @@ -419,8 +419,7 @@ static int mca_opt_nonfirst_char(LWCHAR c)
if (p == NULL)
return (MCA_MORE);
opt_lower = ASCII_IS_LOWER(p[0]);
err = 0;
curropt = findopt_name(&p, &oname, &err);
curropt = findopt_name(&p, &oname, &ambig);
if (curropt != NULL)
{
/*
Expand All @@ -438,7 +437,7 @@ static int mca_opt_nonfirst_char(LWCHAR c)
if (cmd_char(c) != CC_OK)
return (MCA_DONE);
}
} else if (err != OPT_AMBIG)
} else if (!ambig)
{
bell();
}
Expand Down
32 changes: 16 additions & 16 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ extern int mousecap;
extern int sc_height;

/* "content" is lesskey source, never binary. */
static void add_content_table(int (*call_lesskey)(constant char *, int), constant char *envname, int sysvar);
static int add_hometable(int (*call_lesskey)(constant char *, int), constant char *envname, constant char *def_filename, int sysvar);
static void add_content_table(int (*call_lesskey)(constant char *, lbool), constant char *envname, lbool sysvar);
static int add_hometable(int (*call_lesskey)(constant char *, lbool), constant char *envname, constant char *def_filename, lbool sysvar);

#define SK(k) \
SK_SPECIAL_KEY, (k), 6, 1, 1, 1
Expand Down Expand Up @@ -336,7 +336,7 @@ public void init_cmds(void)
#if USERFILE
#ifdef BINDIR /* For backwards compatibility */
/* Try to add tables in the OLD system lesskey file. */
add_hometable(lesskey, NULL, BINDIR "/.sysless", 1);
add_hometable(lesskey, NULL, BINDIR "/.sysless", TRUE);
#endif
/*
* Try to load lesskey source file or binary file.
Expand All @@ -349,30 +349,30 @@ public void init_cmds(void)
* Try to add tables in system lesskey src file.
*/
#if HAVE_LESSKEYSRC
if (add_hometable(lesskey_src, "LESSKEYIN_SYSTEM", LESSKEYINFILE_SYS, 1) != 0)
if (add_hometable(lesskey_src, "LESSKEYIN_SYSTEM", LESSKEYINFILE_SYS, TRUE) != 0)
#endif
{
/*
* Try to add the tables in the system lesskey binary file.
*/
add_hometable(lesskey, "LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
add_hometable(lesskey, "LESSKEY_SYSTEM", LESSKEYFILE_SYS, TRUE);
}
/*
* Try to add tables in the lesskey src file "$HOME/.lesskey".
*/
#if HAVE_LESSKEYSRC
if (add_hometable(lesskey_src, "LESSKEYIN", DEF_LESSKEYINFILE, 0) != 0)
if (add_hometable(lesskey_src, "LESSKEYIN", DEF_LESSKEYINFILE, FALSE) != 0)
#endif
{
/*
* Try to add the tables in the standard lesskey binary file "$HOME/.less".
*/
add_hometable(lesskey, "LESSKEY", LESSKEYFILE, 0);
add_hometable(lesskey, "LESSKEY", LESSKEYFILE, FALSE);
}
#endif

add_content_table(lesskey_content, "LESSKEY_CONTENT_SYSTEM", 1);
add_content_table(lesskey_content, "LESSKEY_CONTENT", 0);
add_content_table(lesskey_content, "LESSKEY_CONTENT_SYSTEM", TRUE);
add_content_table(lesskey_content, "LESSKEY_CONTENT", FALSE);
}

/*
Expand Down Expand Up @@ -832,7 +832,7 @@ static int old_lesskey(unsigned char *buf, size_t len)
/*
* Process a new (post-v241) lesskey file.
*/
static int new_lesskey(unsigned char *buf, size_t len, int sysvar)
static int new_lesskey(unsigned char *buf, size_t len, lbool sysvar)
{
unsigned char *p;
unsigned char *end;
Expand Down Expand Up @@ -890,7 +890,7 @@ static int new_lesskey(unsigned char *buf, size_t len, int sysvar)
/*
* Set up a user command table, based on a "lesskey" file.
*/
public int lesskey(constant char *filename, int sysvar)
public int lesskey(constant char *filename, lbool sysvar)
{
unsigned char *buf;
POSITION len;
Expand Down Expand Up @@ -954,7 +954,7 @@ public int lesskey(constant char *filename, int sysvar)
}

#if HAVE_LESSKEYSRC
static int lesskey_text(constant char *filename, int sysvar, int content)
static int lesskey_text(constant char *filename, lbool sysvar, lbool content)
{
static struct lesskey_tables tables;
if (!secure_allow(SF_LESSKEY))
Expand All @@ -969,12 +969,12 @@ static int lesskey_text(constant char *filename, int sysvar, int content)
return (0);
}

public int lesskey_src(constant char *filename, int sysvar)
public int lesskey_src(constant char *filename, lbool sysvar)
{
return lesskey_text(filename, sysvar, FALSE);
}

public int lesskey_content(constant char *content, int sysvar)
public int lesskey_content(constant char *content, lbool sysvar)
{
return lesskey_text(content, sysvar, TRUE);
}
Expand All @@ -990,7 +990,7 @@ void lesskey_parse_error(char *s)
/*
* Add a lesskey file.
*/
static int add_hometable(int (*call_lesskey)(constant char *, int), constant char *envname, constant char *def_filename, int sysvar)
static int add_hometable(int (*call_lesskey)(constant char *, lbool), constant char *envname, constant char *def_filename, lbool sysvar)
{
char *filename = NULL;
constant char *efilename;
Expand Down Expand Up @@ -1029,7 +1029,7 @@ static int add_hometable(int (*call_lesskey)(constant char *, int), constant cha
/*
* Add the content of a lesskey source file.
*/
static void add_content_table(int (*call_lesskey)(constant char *, int), constant char *envname, int sysvar)
static void add_content_table(int (*call_lesskey)(constant char *, lbool), constant char *envname, lbool sysvar)
{
(void) call_lesskey; /* not used */
constant char *content = lgetenv(envname);
Expand Down

0 comments on commit 8992745

Please sign in to comment.