summaryrefslogtreecommitdiff
path: root/startmode.c
blob: ff209ebdcb41901e5b4508465d71d8bfe0be82a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "7ed.h"
#include "input.h"
#include "i_validation.h"
#include <stdint.h>

int ncat(char filename[]) {

    FILE *file;
    file = fopen(filename,"r");

    if (file == NULL) {
        fprintf(stderr, "Cannot open file. ncat\n");
        return 1;
    }

    char buffer[BUF_SZ_2];
    size_t bytes_read;
    while ((bytes_read = fread(buffer, 1, BUF_SZ_2, file)) > 0) {
        fwrite(buffer, 1, bytes_read, stdout);
    }
    fclose(file);
    return 0;
}

int display_name_linecount(char *filename) {

    uint64_t Flines;
    int returnval = count_lines_in_file(filename, &Flines); 
    if (returnval == 1) {
        return 1;
    }
    fprintf(stdout,"%s %ld lines\n", filename, Flines);

    return 0;
}

int startmode(char filename[]) {
    // The entry to the program. Count lines and display the count. Also show which file is being edited.
    int dnl = display_name_linecount(filename);
    if (dnl == 1) {
        return EXIT_FAILURE;
    }
    uint64_t focus = 1; // The focus variable. Which is the actual line number we have "selected"

    char *multiple;
    char single;
    int smode_input_ret = smode_input(&single, &multiple, focus);
    if (smode_input_ret == _SINGLE) {
        fprintf(stdout, "single\n");
        fprintf(stdout, "%c\n", single);
    }
    if (smode_input_ret == _MULTIPLE) {
        fprintf(stdout, "multiple\n");
        fprintf(stdout, "%s", multiple);
        free(multiple);
    }
    if (smode_input_ret == _FAIL) {
        fprintf(stdout, "?\n");
    }
    
    return EXIT_SUCCESS;
}