summaryrefslogtreecommitdiff
path: root/command/ed.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-06-07 21:33:44 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-06-07 21:33:44 -0400
commit47e9c333620a0ca186efc00d2495b44fc887882f (patch)
treeb94c4d0238d186d0f8d3a7fb5485d0cf784714de /command/ed.c
parentslight refactor and start documenting (diff)
downloadlazysphere-47e9c333620a0ca186efc00d2495b44fc887882f.tar.gz
lazysphere-47e9c333620a0ca186efc00d2495b44fc887882f.tar.bz2
lazysphere-47e9c333620a0ca186efc00d2495b44fc887882f.zip
more documentation
Diffstat (limited to '')
-rw-r--r--command/ed.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/command/ed.c b/command/ed.c
index f839258..bdd69ab 100644
--- a/command/ed.c
+++ b/command/ed.c
@@ -53,7 +53,7 @@ static bool read_regex(char** end, re_t* regex, enum RegexDirection dir) {
while(true) {
c = *(index++);
if (c == '\0') {
- error_s("missing regex after %c\n", dir == BEFORE ? '?' : '/');
+ error_s("missing regex after %c", dir == BEFORE ? '?' : '/');
return false;
}
if (c == (dir == BEFORE ? '?' : '/')) {
@@ -186,7 +186,7 @@ static bool read_address(char** command, bool whitespace, struct LineAddress* a)
n_pre = -1;
} else {
if (n_pre < 0) {
- error_s("input cannot be negative\n");
+ error_s("input cannot be negative");
return false;
}
index = end_pre;
@@ -222,7 +222,7 @@ static bool read_address(char** command, bool whitespace, struct LineAddress* a)
}
if (address.data.index.i < 0) {
- error_s("line number %ld does not exist\n", address.data.index.i + 1);
+ error_s("line number %ld does not exist", address.data.index.i + 1);
return false;
}
@@ -236,7 +236,7 @@ static bool read_address(char** command, bool whitespace, struct LineAddress* a)
n = strtol(index, &end, 10) - 1;
if (n < 0) {
- error_s("input cannot be negative\n");
+ error_s("input cannot be negative");
return false;
}
if (index == end) {
@@ -245,7 +245,7 @@ static bool read_address(char** command, bool whitespace, struct LineAddress* a)
address.data.index.i = line_current + n;
}
if (address.data.index.i >= (long int) line_count) {
- error_s("line number %ld does not exist\n", address.data.index.i + 1);
+ error_s("line number %ld does not exist", address.data.index.i + 1);
return false;
}
break;
@@ -281,7 +281,7 @@ static bool read_address(char** command, bool whitespace, struct LineAddress* a)
address.data.index.i = n_pre;
}
if (address.data.index.i < 0 || address.data.index.i >= (long int) line_count) {
- error_s("line number %ld does not exist\n", address.data.index.i + 1);
+ error_s("line number %ld does not exist", address.data.index.i + 1);
return false;
}
}
@@ -437,7 +437,7 @@ static bool handle_append(struct LineAddress* address) {
unsigned long cap, size;
if (address->type != INDEX) {
- error_s("append command requires index addressing\n");
+ error_s("append command requires index addressing");
return false;
}
@@ -449,7 +449,7 @@ static bool handle_append(struct LineAddress* address) {
if (size > 0) {
append_lines(address->data.index.i + 1, buf, size);
- printf("ed: appened %lu lines\n", size);
+ output("appened %lu lines", size);
}
line_current += size;
@@ -459,22 +459,22 @@ static bool handle_append(struct LineAddress* address) {
static bool handle_delete(struct LineAddress* address) {
if (address->empty && address->data.index.i >= (long int) line_count) {
- error_s("line number %ld does not exist\n", address->data.index.i + 1);
+ error_s("line number %ld does not exist", address->data.index.i + 1);
return false;
}
if (address->type == INDEX) {
delete_lines(address->data.index.i, address->data.index.i);
- output("deleted line %ld\n", address->data.index.i+1);
+ output("deleted line %ld", address->data.index.i+1);
} else if (address->type == RANGE) {
delete_lines(address->data.range.a, address->data.range.b);
- output("deleted lines %ld-%ld\n", address->data.range.a+1, address->data.range.b+1);
+ output("deleted lines %ld-%ld", address->data.range.a+1, address->data.range.b+1);
} else if (address->type == SET) {
unsigned long i;
for (i = 0; i < address->data.set.s; i++) {
delete_lines(address->data.set.b[i], address->data.set.b[i]);
}
- output("deleted %lu lines\n", address->data.set.s);
+ output("deleted %lu lines", address->data.set.s);
}
return true;
@@ -485,7 +485,7 @@ static bool get_file_name(char** filename) {
if (len < 1 || (len == 1 && **filename == '\n')) {
if (default_filename == NULL) {
- error_s("no default filename specified\n");
+ error_s("no default filename specified");
return false;
}
*filename = default_filename;
@@ -510,7 +510,7 @@ static void write_file(char* filename, struct LineAddress* address, char* type)
int wrote;
if (line_count < 1) {
- error_s("cannot write empty file\n");
+ error_s("cannot write empty file");
return;
}
@@ -546,7 +546,7 @@ static void write_file(char* filename, struct LineAddress* address, char* type)
pending_writes = false;
fclose(file);
- output("wrote %d lines from %s\n", wrote, filename);
+ output("wrote %d lines from %s", wrote, filename);
}
static void read_file(char* filename) {
@@ -566,7 +566,7 @@ static void read_file(char* filename) {
if (size < 1) {
free(buf);
- error_s("attempted to read a empty file\n");
+ error_s("attempted to read a empty file");
return;
}
@@ -577,7 +577,7 @@ static void read_file(char* filename) {
append_lines(line, buf, size);
free(buf);
- output("read and appended %lu lines from %s\n", size, filename);
+ output("read and appended %lu lines from %s", size, filename);
}
static void expand_string(char** buf, int* capacity, int* size, char* text, int len) {
@@ -650,7 +650,7 @@ static void prompt(void) {
struct LineAddress address2;
if (address.type != INDEX) {
- error_s("comma range addressing requires two index addresses\n");
+ error_s("comma range addressing requires two index addresses");
free_address(address);
return;
}
@@ -663,7 +663,7 @@ static void prompt(void) {
}
if (address2.type != INDEX) {
- error_s("comma range addressing requires two index addresses\n");
+ error_s("comma range addressing requires two index addresses");
free_address(address);
free_address(address2);
return;
@@ -677,7 +677,7 @@ static void prompt(void) {
}
if (address.type == RANGE && address.data.range.a > address.data.range.b) {
- error_s("range addressing must be in ascending order\n");
+ error_s("range addressing must be in ascending order");
free_address(address);
return;
}
@@ -690,10 +690,10 @@ test:
case '\n':
if (address.empty) {
if (line_current == line_count) {
- error_s("line number %ld does not exist\n", line_current + 1);
+ error_s("line number %ld does not exist", line_current + 1);
break;
} else if (line_current + 1 == line_count) {
- error_s("line number %ld does not exist\n", line_current + 2);
+ error_s("line number %ld does not exist", line_current + 2);
break;
} else {
line_current++;
@@ -706,7 +706,7 @@ test:
} else if (address.type == RANGE) {
line_current = address.data.range.b;
} else if (address.type == SET) {
- error_s("unexpected range addressing\n");
+ error_s("unexpected range addressing");
break;
}
printf("%s", lines[line_current]);
@@ -728,7 +728,7 @@ test:
__attribute__((fallthrough));
case 'p':
if (address.empty && address.data.index.i >= (long int) line_count) {
- error_s("line number %ld does not exist\n", address.data.index.i + 1);
+ error_s("line number %ld does not exist", address.data.index.i + 1);
break;
}
if (address.type == INDEX) {
@@ -779,17 +779,17 @@ test:
skip_whitespace(&index);
if (*(index++) != '/') {
- error_s("unexpected character at start of regex\n");
+ error_s("unexpected character at start of regex");
break;
}
if (!parse_regex_lines(&index, &address)) { return; }
while(*index != '\0' && *index != '/') index++;
if (*index != '/') {
- error_s("/ missing after %c\n", *index);
+ error_s("/ missing after %c", *index);
break;
}
if (address.data.set.s < 1) {
- error_s("no matches found\n");
+ error_s("no matches found");
break;
}
*(index++) = '\0';
@@ -801,11 +801,11 @@ test:
char* end;
matches = strtol(index, &end, 10);
if (end == index) {
- error_s("invalid number: %s\n", index);
+ error_s("invalid number: %s", index);
break;
}
if (matches < 1) {
- error_s("matches cannot be less than 1\n");
+ error_s("matches cannot be less than 1");
break;
}
}
@@ -815,7 +815,7 @@ test:
for (i = 0; i < address.data.set.s; i++) {
matches_found += substute_string(address.data.set.b[i], matches, last_regex, replace, sub_len);
}
- output("replaced %ld matches over %ld lines\n", matches_found, address.data.set.s);
+ output("replaced %ld matches over %ld lines", matches_found, address.data.set.s);
pending_writes = true;
break;
}
@@ -865,7 +865,7 @@ test:
printf("%ld\n", line_current + 1);
break;
default:
- error_s("unimplemented command\n");
+ error_s("unimplemented command");
break;
}