From e7402d874965679dec0db3a74cbf4e44afe3ee92 Mon Sep 17 00:00:00 2001 From: CismonX Date: Tue, 11 Apr 2023 10:08:18 +0800 Subject: [PATCH] chore: clean up --- include/ctlseqs.h | 28 ++++++++++++++-------------- man/ctlseqs_reader_free.3 | 2 +- src/ctlseqs.c | 18 +++++++++--------- tests/Makefile.am | 12 ++++++++---- tests/{init.exp => lib/ctlseqs.exp} | 0 5 files changed, 32 insertions(+), 28 deletions(-) rename tests/{init.exp => lib/ctlseqs.exp} (100%) diff --git a/include/ctlseqs.h b/include/ctlseqs.h index cedfa3f..cb44522 100644 --- a/include/ctlseqs.h +++ b/include/ctlseqs.h @@ -250,12 +250,12 @@ #define CTLSEQS_SU(n) CTLSEQS_CSI n "S" // Set or request graphics attribute #define CTLSEQS_XTSMGRAPHICS(i1, i2, is) \ - CTLSEQS_CSI "?" i1 ";" i2 ";" is "S" + CTLSEQS_CSI "?" i1 ";" i2 ";" is "S" // Scroll Down $n Line(s) #define CTLSEQS_SD(n) CTLSEQS_CSI n "T" // Initiate highlight mouse tracking #define CTLSEQS_XTHIMOUSE(f, x, y, fr, lr) \ - CTLSEQS_CSI f ";" x ";" y ";" fr ";" lr "T" + CTLSEQS_CSI f ";" x ";" y ";" fr ";" lr "T" // Reset title mode features to default value #define CTLSEQS_XTRMTITLE(is) CTLSEQS_CSI ">" is "T" // Erase $n Character(s) @@ -328,7 +328,7 @@ #define CTLSEQS_XTRESTORE(is) CTLSEQS_CSI "?" is "r" // Change Attributes in Rectangular Area #define CTLSEQS_DECCARA(t, l, b, r, is) \ - CTLSEQS_CSI t ";" l ";" b ";" r ";" is "$r" + CTLSEQS_CSI t ";" l ";" b ";" r ";" is "$r" // Save cursor #define CTLSEQS_SCOSC() CTLSEQS_CSI "s" // Set left and right margins @@ -343,46 +343,46 @@ #define CTLSEQS_DECSWBV(i) CTLSEQS_CSI i " t" // Reverse Attributes in Rectangular Area #define CTLSEQS_DECRARA(t, l, b, r, is) \ - CTLSEQS_CSI t ";" l ";" b ";" r ";" is "$t" + CTLSEQS_CSI t ";" l ";" b ";" r ";" is "$t" // Restore cursor #define CTLSEQS_SCORC() CTLSEQS_CSI "u" // Set margin-bell volume #define CTLSEQS_DECSMBV(i) CTLSEQS_CSI i " u" // Copy Rectangular Area #define CTLSEQS_DECCRA(t, l, b, r, sp, dt, dl, dp) \ - CTLSEQS_CSI t ";" l ";" b ";" r ";" sp ";" dt ";" dl ";" dp "$v" + CTLSEQS_CSI t ";" l ";" b ";" r ";" sp ";" dt ";" dl ";" dp "$v" // Request presentation state report #define CTLSEQS_DECRQPSR(i) CTLSEQS_CSI i "$w" // Enable Filter Rectangle #define CTLSEQS_DECEFR(t, l, b, r) \ - CTLSEQS_CSI t ";" l ";" b ";" r "'w" + CTLSEQS_CSI t ";" l ";" b ";" r "'w" // Request Terminal Parameters #define CTLSEQS_DECREQTPARM(i) CTLSEQS_CSI i "x" // Select Attribute Change Extent #define CTLSEQS_DECSACE(i) CTLSEQS_CSI i "*x" // Fill Rectangular Area #define CTLSEQS_DECFRA(c, t, l, b, r) \ - CTLSEQS_CSI c ";" t ";" l ";" b ";" r "$x" + CTLSEQS_CSI c ";" t ";" l ";" b ";" r "$x" // Select checksum extension #define CTLSEQS_XTCHECKSUM(i) CTLSEQS_CSI i "#y" // Request Checksum of Rectangular Area #define CTLSEQS_DECRQCRA(id, p, t, l, b, r) \ - CTLSEQS_CSI id ";" p ";" t ";" l ";" b ";" r "*y" + CTLSEQS_CSI id ";" p ";" t ";" l ";" b ";" r "*y" // Enable Locator Reporting #define CTLSEQS_DECELR(i1, i2) CTLSEQS_CSI i1 ";" i2 "'z" // Erase Rectangular Area #define CTLSEQS_DECERA(t, l, b, r) \ - CTLSEQS_CSI t ";" l ";" b ";" r "$z" + CTLSEQS_CSI t ";" l ";" b ";" r "$z" // Select Locator Events #define CTLSEQS_DECSLE(is) CTLSEQS_CSI is "'{" // Push video attributes onto stack #define CTLSEQS_XTPUSHSGR(is) CTLSEQS_CSI is "#{" // Selective Erase Rectangular Area #define CTLSEQS_DECSERA(t, l, b, r) \ - CTLSEQS_CSI t ";" l ";" b ";" r "${" + CTLSEQS_CSI t ";" l ";" b ";" r "${" // Report selected graphic rendition #define CTLSEQS_XTREPORTSGR(t, l, b, r) \ - CTLSEQS_CSI t ";" l ";" b ";" r "$|" + CTLSEQS_CSI t ";" l ";" b ";" r "$|" // Select columns per page #define CTLSEQS_DECSCPP(i) CTLSEQS_CSI i "$|" // Request Locator Position @@ -413,7 +413,7 @@ #define CTLSEQS_RESP_PRIMARY_DA(ns) CTLSEQS_CSI "?" ns "c" // Secondary DA response message #define CTLSEQS_RESP_SECONDARY_DA(n1, n2, n3) \ - CTLSEQS_CSI ">" n1 ";" n2 ";" n3 "c" + CTLSEQS_CSI ">" n1 ";" n2 ";" n3 "c" // DECLRP response message #define CTLSEQS_RESP_DECXCPR(n1, n2) CTLSEQS_CSI "?" n1 ";" n2 "R" // DSR response message @@ -432,10 +432,10 @@ #define CTLSEQS_RESP_DECRQCRA(n, s) CTLSEQS_DCS n "!~" s CTLSEQS_ST // DECRQLP response message #define CTLSEQS_RESP_DECRQLP(e, b, row, col, p) \ - CTLSEQS_CSI e ";" b ";" row ";" col ";" p "&w" + CTLSEQS_CSI e ";" b ";" row ";" col ";" p "&w" // Mouse response in SGR mouse mode #define CTLSEQS_RESP_SGR_MOUSE(n, col, row, c) \ - CTLSEQS_CSI "<" n ";" col ";" row c + CTLSEQS_CSI "<" n ";" col ";" row c /// PC-Style Function Keys diff --git a/man/ctlseqs_reader_free.3 b/man/ctlseqs_reader_free.3 index df20193..b14779c 100644 --- a/man/ctlseqs_reader_free.3 +++ b/man/ctlseqs_reader_free.3 @@ -1,4 +1,4 @@ -.TH CTLSEQS_MATCHER_FREE 3 "Sep 01, 2020" 0.1.0 ctlseqs +.TH CTLSEQS_READER_FREE 3 "Sep 01, 2020" 0.1.0 ctlseqs . .SH NAME ctlseqs_reader_free - free control sequence reader diff --git a/src/ctlseqs.c b/src/ctlseqs.c index aa6c042..ec22ea2 100644 --- a/src/ctlseqs.c +++ b/src/ctlseqs.c @@ -158,7 +158,7 @@ struct ctlseqs_reader { bool save_matched; }; -ctlseqs_hot static inline int +static inline int ctlseqs_hot ctlseqs_poll( struct pollfd *pollfd, int timeout @@ -184,7 +184,7 @@ ctlseqs_poll( } } -ctlseqs_hot static inline int +static inline int ctlseqs_hot ctlseqs_do_read( struct ctlseqs_reader *reader ) { @@ -211,7 +211,7 @@ ctlseqs_do_read( } } -ctlseqs_hot static enum ctlseqs_state +static enum ctlseqs_state ctlseqs_hot ctlseqs_state_transition( enum ctlseqs_state state, char ch @@ -294,7 +294,7 @@ ctlseqs_state_transition( } } -ctlseqs_hot static char const * +static char const * ctlseqs_hot ctlseqs_fetch_value( char const *seq, int type, @@ -342,7 +342,7 @@ ctlseqs_fetch_value( } } -ctlseqs_hot static ssize_t +static ssize_t ctlseqs_hot ctlseqs_match_pattern( struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args const *args @@ -399,7 +399,7 @@ ctlseqs_match_pattern( return CTLSEQS_NOMATCH; } -ctlseqs_hot static inline ssize_t +static inline ssize_t ctlseqs_hot ctlseqs_do_match( struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args *args @@ -435,7 +435,7 @@ ctlseqs_do_match( return retval; } -ctlseqs_hot static ssize_t +static ssize_t ctlseqs_hot ctlseqs_reader_match( struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matcher @@ -634,7 +634,7 @@ ctlseqs_reader_config( return CTLSEQS_ERROR; } char *rbuf = realloc(reader->rbuf, readlen); - if (rbuf == NULL) { + if (ctlseqs_unlikely(rbuf == NULL)) { return CTLSEQS_NOMEM; } reader->readlen = readlen; @@ -698,7 +698,7 @@ ctlseqs_purge( reader->state = ctlseqs_state_none; } -ctlseqs_cold void +void ctlseqs_cold ctlseqs_reader_free( struct ctlseqs_reader *reader ) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 54ed9b9..3b5a00e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,12 +7,16 @@ # AUTOMAKE_OPTIONS = dejagnu -EXTRA_DIST = ctlseqs/*.exp init.exp +EXTRA_DIST = lib/ctlseqs.exp \ + ctlseqs/8bitchar.exp \ + ctlseqs/match.exp \ + ctlseqs/nomem.exp \ + ctlseqs/partial.exp \ + ctlseqs/timeout.exp -noinst_PROGRAMS = tcsgrep +check_PROGRAMS = tcsgrep tcsgrep_CPPFLAGS = -I$(top_srcdir)/include tcsgrep_SOURCES = tcsgrep.c tcsgrep_LDADD = $(top_builddir)/src/libctlseqs.la -RUNTESTFLAGS = TCSGREP_BIN=$(builddir)/tcsgrep -EXTRA_DEJAGNU_SITE_CONFIG = $(srcdir)/init.exp +RUNTESTFLAGS = TCSGREP_BIN=$(builddir)/tcsgrep diff --git a/tests/init.exp b/tests/lib/ctlseqs.exp similarity index 100% rename from tests/init.exp rename to tests/lib/ctlseqs.exp