summaryrefslogtreecommitdiff
path: root/process_multiples.c
diff options
context:
space:
mode:
Diffstat (limited to 'process_multiples.c')
-rw-r--r--process_multiples.c156
1 files changed, 146 insertions, 10 deletions
diff --git a/process_multiples.c b/process_multiples.c
index b99b74d..af164c8 100644
--- a/process_multiples.c
+++ b/process_multiples.c
@@ -266,41 +266,177 @@ uint64_t call_N(char *multiple, uint64_t focus, uint64_t Flines, char *filename)
return 0;
}
+int call_X_plus_continue(char *multiple, uint64_t focus, char *filename, uint64_t Flines) { // NOT DONE!! IT IS A COPY OF call_N_plus_continue !!!
+
+ char new_multiple[32] = { '\0' };
+
+ int i = 0;
+ int j = 2;
+ for( ; multiple[j] != '\n' ; i++, j++) {
+ new_multiple[i] = multiple[j];
+ }
+
+ char *endptr;
+ uint64_t amount_of_lines_to_remove = strtol(new_multiple, &endptr, 10);
+ errno = 0;
+ if (errno == ERANGE) {
+ return -1;
+ }
+ if (endptr == new_multiple) {
+ return -1;
+ }
+
+ if(check_L_linecount(Flines, focus+(amount_of_lines_to_remove-1) /*-1 because we are not doing currentline + amount of lines. That would be 1 too much*/, MODE_L) == _INVALID) {
+ return -1;
+ }
+
+ if (choice() == 1) { return -1; }
+
+ for(uint64_t count = 0 ; count < amount_of_lines_to_remove ; count++) { // This is very inefficient if you are adding thousands of lines but why would you wanna do that anyway?
+ remove_line_contents(filename, focus+count);
+ }
+
+ return 0;
+}
+
+int call_X_immediate(char *multiple, uint64_t Flines, char *filename) {
+
+ char new_multiple[32] = { '\0' };
+
+ int i = 0;
+ int j = 1;
+ for( ; multiple[j] != '\n' ; i++, j++) {
+ new_multiple[i] = multiple[j];
+ }
+
+ char *endptr;
+ uint64_t remove_line_contents_position = strtol(new_multiple, &endptr, 10);
+ errno = 0;
+ if (errno == ERANGE) {
+ return 0;
+ }
+ if (endptr == new_multiple) {
+ return 0;
+ }
+
+ if(check_L_linecount(Flines, remove_line_contents_position, MODE_L) == _INVALID) {
+ return -1;
+ }
+
+ if (choice() == 1) { return -1; }
+
+ remove_line_contents(filename, remove_line_contents_position);
+
+ return 0;
+}
+
int call_X(char *multiple, uint64_t focus, uint64_t Flines, char *filename) {
int imm = _IMM_NUMBER;
if (multiple[1] == '\n') { // X Will remove current line
imm = _NA;
- remove_line_contents(filename, focus);
+
+ if(choice() == 0) {
+ remove_line_contents(filename, focus);
+ }
return 0;
}
- if (multiple[1] == '+') { // X+ Will..... idk
+ if (multiple[1] == '+') {
imm = _NA;
if (multiple[2] == '\n') {
- // Will have to really think about this
+ if(choice() == 0) {
+ remove_line_contents(filename, focus);
+ }
return 0;
}
-
- // X plus continue. Still figuring out how this is gonna work.
+ call_X_plus_continue(multiple, focus, filename, Flines);
return 0;
}
if (imm == _IMM_NUMBER) {
- // X immediate, process immediates
-
+ call_X_immediate(multiple, Flines, filename);
return 0;
}
- fprintf(stdout, "%s %ld\n", multiple, Flines);
return 0;
}
-int call_D(char *multiple) {
+uint64_t call_D_plus_continue(char *multiple, uint64_t focus, uint64_t Flines, char *filename) {
+
+ char new_multiple[32] = { '\0' };
+
+ int i = 0;
+ int j = 2;
+ for( ; multiple[j] != '\n' ; i++, j++) {
+ new_multiple[i] = multiple[j];
+ }
+
+ char *endptr;
+ uint64_t lines_and_newlines_to_remove = strtol(new_multiple, &endptr, 10);
+ errno = 0;
+ if (errno == ERANGE) {
+ return -1;
+ }
+ if (endptr == new_multiple) {
+ return -1;
+ }
+
+ if(check_L_linecount(Flines, focus+(lines_and_newlines_to_remove-1) /*-1 because we are not doing currentline + amount of lines. That would be 1 too much*/, MODE_L) == _INVALID) {
+ return -1;
+ }
+
+ if (choice() == 1) { return -1; }
+
+ for(uint64_t count = 0 ; count < lines_and_newlines_to_remove ; count++) { // This is very inefficient if you are adding thousands of lines but why would you wanna do that anyway?
+ remove_line_contents_and_newline(filename, focus);
+ }
- fprintf(stdout, "%s\n", multiple);
+ return 0;
+
+}
+
+uint64_t call_D(char *multiple, uint64_t focus, uint64_t Flines, char *filename) {
+
+ int imm = _IMM_NUMBER;
+
+ if (multiple[1] == '\n') { // D Will remove current line
+ imm = _NA;
+
+ if(choice() == 0) {
+ remove_line_contents_and_newline(filename, focus);
+ if (focus == 1) { return 1; }
+ return focus-1;
+ } else {
+ return focus;
+ }
+
+ }
+
+ if (multiple[1] == '+') {
+ imm = _NA;
+ if (multiple[2] == '\n') {
+ if(choice() == 0) {
+ remove_line_contents_and_newline(filename, focus);
+ if (focus == 1) { return 1; }
+ return focus-1;
+ } else {
+ return focus;
+ }
+ }
+ // call_D_plus_continue
+
+ return 0;
+ }
+
+ if (imm == _IMM_NUMBER) {
+ //call_D_immediate(multiple, Flines, filename);
+ return 0;
+ }
+
+ fprintf(stdout, "%s %ld\n", multiple, Flines);
return 0;
}