aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-10-31 20:15:49 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-10-31 20:16:10 +0100
commitc5cc1dab1d5610c0d96f72dc36ac6d4b4476c8ed (patch)
treee17ad0370de82f619e6cb4f2e67248cf373519a2 /src
parenta0cbd4f04311392b785cf260abe52e2eb5695312 (diff)
Make -l the default and add -b
Diffstat (limited to 'src')
-rw-r--r--src/flags.h2
-rw-r--r--src/main.c10
-rw-r--r--src/work.c12
3 files changed, 12 insertions, 12 deletions
diff --git a/src/flags.h b/src/flags.h
index 8344205..306464c 100644
--- a/src/flags.h
+++ b/src/flags.h
@@ -2,9 +2,9 @@
#define GRAB_FLAGS_H
typedef struct {
+ bool b : 1;
bool c : 1;
bool i : 1;
- bool l : 1;
bool p : 1;
bool s : 1;
bool U : 1;
diff --git a/src/main.c b/src/main.c
index 439f353..e679839 100644
--- a/src/main.c
+++ b/src/main.c
@@ -74,10 +74,10 @@ main(int argc, char **argv)
optparser_t parser = mkoptparser(argv);
static const cli_opt_t opts[] = {
+ {'b', U8C("byte-offset"), CLI_NONE},
{'c', U8C("color"), CLI_NONE},
{'h', U8C("help"), CLI_NONE},
{'i', U8C("ignore-case"), CLI_NONE},
- {'l', U8C("line"), CLI_NONE},
{'p', U8C("predicate"), CLI_NONE},
{'s', U8C("strip-newline"), CLI_NONE},
{'U', U8C("no-unicode"), CLI_NONE},
@@ -89,6 +89,9 @@ main(int argc, char **argv)
if (opt == 0)
break;
switch (opt) {
+ case 'b':
+ flags.b = true;
+ break;
case 'c':
flags.c = true;
break;
@@ -98,9 +101,6 @@ main(int argc, char **argv)
case 'i':
flags.i = true;
break;
- case 'l':
- flags.l = true;
- break;
case 'p':
flags.p = true;
break;
@@ -137,7 +137,7 @@ main(int argc, char **argv)
if (argc == 0) {
usage:
- usage("[-p | -s | -z] [-cilU] pattern [file ...]", "-h");
+ usage("[-p | -s | -z] [-bciU] pattern [file ...]", "-h");
exit(EXIT_FATAL);
}
diff --git a/src/work.c b/src/work.c
index e6ab140..15c9ea4 100644
--- a/src/work.c
+++ b/src/work.c
@@ -369,7 +369,12 @@ write_match_to_buffer(u8view_t sv, u8view_t *hl)
char offset[/* len(INT64_MAX - 1) */ 19];
pos_state_t ps = {.buf = {baseptr, PTRDIFF_MAX}};
- if (flags.l) {
+ if (flags.b) {
+ offsetsz = sprintf(offset, "%td", sv.p - baseptr);
+ array_extend_sv(buf, COL_LN);
+ array_extend(buf, offset, offsetsz);
+ array_extend_sv(buf, COL_RS);
+ } else {
compute_pos(sv.p, &ps);
offsetsz = sprintf(offset, "%td", ps.row + 1);
@@ -385,11 +390,6 @@ write_match_to_buffer(u8view_t sv, u8view_t *hl)
array_extend_sv(buf, COL_LN);
array_extend(buf, offset, offsetsz);
array_extend_sv(buf, COL_RS);
- } else {
- offsetsz = sprintf(offset, "%td", sv.p - baseptr);
- array_extend_sv(buf, COL_LN);
- array_extend(buf, offset, offsetsz);
- array_extend_sv(buf, COL_RS);
}
array_extend_sv(buf, COL_SE);