aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-04-29 15:42:42 -0400
committerShav Kinderlehrer <[email protected]>2023-05-01 18:13:13 -0400
commite4f517c02005ed20861c3f1f68f1c2a72bb690d3 (patch)
tree26b37413c1e48e06135540bf0d921686ef070755 /src/main.c
parent0f9a68c578a2c7ea0a4f1a8fc35320aad339b51e (diff)
downloadlat-e4f517c02005ed20861c3f1f68f1c2a72bb690d3.tar.gz
lat-e4f517c02005ed20861c3f1f68f1c2a72bb690d3.zip
Start implementing -e
- extensions
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 4afabc8..781ab41 100644
--- a/src/main.c
+++ b/src/main.c
@@ -83,11 +83,14 @@ void run(FILE *fp, char *filename, bool tty) {
int linecount = 1;
for (int i = 0; i < f.lc; i++) {
if (conf.lines) {
- char *padding = linepad(linecount, f.lc);
- fprintf(st, "%s%s%d│%s ", c.grey, padding, i + 1, c.reset);
+ { // line numbers
+ char *padding = linepad(linecount, f.lc);
+ fprintf(err, "%s%s%d│%s ", c.grey, padding, i + 1, c.reset);
+ free(padding);
+ }
+
fwrite(f.lines[i].buf, 1, f.lines[i].len, st);
fprintf(st, "\n");
- free(padding);
linecount++;
} else {
fprintf(st, "%s\n", f.lines[i].buf);
@@ -97,7 +100,8 @@ void run(FILE *fp, char *filename, bool tty) {
} else {
fwrite(f.buf, 1, f.buflen, st);
fflush(st);
- fwrite("\n", 1, 1, err);
+ if (tty)
+ fwrite("\n", 1, 1, err);
}
free(f.buf);
free(f.lines);
@@ -127,6 +131,7 @@ void initconf(void) {
conf.lines = true;
conf.name = NULL;
+ conf.extension = NULL;
}
void clearstdin(void) {
@@ -150,8 +155,13 @@ int main(int argc, char *argv[]) {
bool tty = isatty(STDOUT_FILENO);
+ int offset = parseargs(argc, argv);
+
+ conf.headers = conf.headers && tty;
+
+ printf("set extension to '%s'\n", conf.extension);
+
if (argc > 1) {
- int offset = parseargs(argc, argv);
tty = tty || conf.literal;