summaryrefslogtreecommitdiff
path: root/src/commands/ed.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-01 18:43:32 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-01 18:43:32 -0400
commit82e55dde69dc89fdf06e751b75449f35836282a1 (patch)
tree29e49ae19cba7f6a7c2987c381ebe4b253edc053 /src/commands/ed.c
parentmove back to c99 (diff)
downloadlazysphere-82e55dde69dc89fdf06e751b75449f35836282a1.tar.gz
lazysphere-82e55dde69dc89fdf06e751b75449f35836282a1.tar.bz2
lazysphere-82e55dde69dc89fdf06e751b75449f35836282a1.zip
refactor and xargs
Diffstat (limited to '')
-rw-r--r--src/commands/ed.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/commands/ed.c b/src/commands/ed.c
index ed4ce24..44f1a2c 100644
--- a/src/commands/ed.c
+++ b/src/commands/ed.c
@@ -141,21 +141,6 @@ static bool parse_regex_lines(char** end, struct LineAddress* address) {
}
}
- // for (; (dir == BEFORE ? i >= until : i < until); dir == BEFORE ? i-- : i++) {
- // int len;
- // if (re_matchp(regex, lines[i], &len) == -1) {
- // if (dir == BEFORE && i == 0) break;
- // continue;
- // }
- // if (cap == siz) {
- // cap *= 2;
- // buf = realloc(buf, cap * sizeof(unsigned long));
- // }
- // buf[siz] = i;
- // siz++;
- // if (dir == BEFORE && i == 0) break;
- // }
-
free_address(*address);
address->empty = false;
address->type = SET;
@@ -295,7 +280,7 @@ static void free_data(bool all) {
}
}
-static void load_empty() {
+static void load_empty(void) {
free_data(false);
line_capacity = 8;
@@ -579,7 +564,7 @@ static int substute_string(long int index, long int matches, re_t regex, char* s
return matches_found;
}
-static void prompt() {
+static void prompt(void) {
printf(": ");
fflush(stdout);
@@ -805,13 +790,13 @@ test:
}
-static void prompt_loop() {
+static void prompt_loop(void) {
while (true) {
prompt();
}
}
-static void help() {
+static void help(void) {
printf("Usage: ed [FILE]\n\n");
printf("Edit a given [FILE] or create a new text file\n\n");
printf("\t(.,.)\tnewline\t\tgo to address line and print\n");
@@ -832,15 +817,16 @@ static void help() {
printf("\t(.,.)\tw file\t\twrite contents of lines to file\n");
printf("\t(.,.)\twq file\t\twrite contents of lines to file then quit\n");
printf("\t(.,.)\tW file\t\tappend contents of line to file\n");
- exit(EXIT_SUCCESS);
+ printf("\t\t=\t\tprint current line number\n");
}
COMMAND(ed) {
+
+ parse_help(argc, argv, help);
+
if (argc < 1) {
load_empty();
prompt_loop();
- } else if (streql(argv[0], "--help")) {
- help();
} else {
FILE* file = get_file(argv[0], "r");
load_file(file);