diff options
Diffstat (limited to 'src/note.c')
-rw-r--r-- | src/note.c | 53 |
1 files changed, 14 insertions, 39 deletions
@@ -19,9 +19,9 @@ /** * Creates a new empty note object since no filename was specified. */ -void note_new(note_t* note, char* path) { - strcpy(note->path, path); - basename(path, note->name); +void note_new(note* n, char* path) { + strcpy(n->path, path); + basename(path, n->name); } @@ -32,24 +32,8 @@ void note_new(note_t* note, char* path) { * * @return int Success or failure of the command */ -int note_create(note_t* note, char* editor) { - return note_edit(note, editor); -} - - -/** - * Opens a note using the specified editor - * - * @param string editor Path to the editor binary to use for editing. - * - * @return int Success or failure of the command - */ -int note_edit(note_t* note, char* editor) { - char cmd[strlen(editor) + 3 + strlen(note->path)]; - strcpy(cmd, editor); - strcat(cmd, " "); - strcat(cmd, note->path); - return system(cmd); +int note_create(note* n, char* editor) { + return file_edit(n->path, editor); } @@ -60,8 +44,8 @@ int note_edit(note_t* note, char* editor) { * 0 Success * -1 File could not be opened */ -int note_cat(note_t* note) { - FILE* f = fopen(note->path, "r"); +int note_cat(note* n) { + FILE* f = fopen(n->path, "r"); // Return early if the file could not be opened if(!f) { return -1; } @@ -85,41 +69,32 @@ int note_cat(note_t* note) { * * @return int Success or failure */ -int note_rm(note_t* note) { +int note_rm(note* n) { // Verify file exists. - FILE* f = fopen(note->path, "r"); + FILE* f = fopen(n->path, "r"); if(f) { - return remove(note->path); + return remove(n->path); fclose(f); } else { return 1; } } -/** - * Gets the filename of the current note instance without its extension. - * - * @return string Note filename without extension - */ -// string note::friendly_name() { -// return name.substr( 0, name.length() - extension.length() - 1 ); -// } /** * TODO */ -int note_search(note_t* note, char* term, int case_insensitive) { - FILE* f = fopen(note->path, "r"); +int note_search(note* n, char* term, int case_insensitive) { + FILE* f = fopen(n->path, "r"); char buf[file_width]; - int line_num = 0; + int line_num = 1; while((fgets(buf, file_width, f)) != NULL) { if(str_contains(buf, term, case_insensitive) == 1) { - printf("%s: %02d: %s", note->name, line_num, buf); + printf("%s: % 4d: %s", n->name, line_num, buf); } line_num++; } fclose(f); return 0; } - |