diff options
author | Aaron Ball <nullspoon@iohq.net> | 2015-02-25 11:02:18 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@iohq.net> | 2015-02-25 11:02:18 -0700 |
commit | de3ee4e2c472dfd032c7ee580fcf67721f74623e (patch) | |
tree | 7477051bf524e735c82ed79d052f72967d1b482e /src | |
parent | 3bbfd0f3882a3832fb2affaa6d2a8aff2fedc6ba (diff) | |
download | noteless-de3ee4e2c472dfd032c7ee580fcf67721f74623e.tar.gz noteless-de3ee4e2c472dfd032c7ee580fcf67721f74623e.tar.xz |
Finished porting most of the cat functionality
Now we can cat notes. Still needs a little work on error messages when a note
doesn't exist (currently just exits with an error code).
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/note.c | 51 | ||||
-rw-r--r-- | src/note.h | 3 | ||||
-rw-r--r-- | src/note_list.c | 33 | ||||
-rw-r--r-- | src/note_list.h | 3 |
5 files changed, 58 insertions, 37 deletions
@@ -182,9 +182,8 @@ int main(int argc, char* argv[]) { // } else if( arg == "find" ) { // string term = argv[i + 1]; // return search_notes( list, term ); - // } else if( arg == "cat" ) { - // string name = argv[i + 1]; - // return cat_note( list, name ); + } else if(strcmp(argv[1], "cat") == 0) { + return note_list_cat_note(&list, argv[2]); } else if(strcmp(argv[1], "help") == 0) { get_help(); } else if(note_list_get_note_id(&list, argv[1]) != -1 ) { @@ -58,25 +58,36 @@ int note_edit(note_t* note, char* editor) { * * @return void */ -// void note::read() { -// // Don't do this unless body hasn't already been read -// if( body.size() == 0 ) { -// // Open the file -// ifstream fs( _path.out().c_str() ); -// -// // Verify the file handle opened sucessfully -// if( ! fs.is_open() ) { -// cout << "Could not open file at " << _path.out() << "." << endl; -// exit( 1 ); -// } -// -// string line; -// while( getline( fs, line ) ) { -// body.push_back( line ); -// } -// fs.close(); -// } -// } +int note_cat(note_t* note) { + FILE* f = fopen(note->path, "r"); + // Return early if the file could not be opened + if(!f) { return -1; } + + char c; + while((c = fgetc(f)) != EOF) { + printf("%c", c); + } + fclose(f); + printf("\n"); + //// Don't do this unless body hasn't already been read + //if( body.size() == 0 ) { + // // Open the file + // ifstream fs( _path.out().c_str() ); + + // // Verify the file handle opened sucessfully + // if( ! fs.is_open() ) { + // cout << "Could not open file at " << _path.out() << "." << endl; + // exit( 1 ); + // } + + // string line; + // while( getline( fs, line ) ) { + // body.push_back( line ); + // } + // fs.close(); + //} + return 0; +} /** @@ -173,4 +184,4 @@ int note_edit(note_t* note, char* editor) { // } // } // return false; -// } +// e @@ -35,6 +35,8 @@ int note_create(note_t*, char*); int note_edit(note_t*, char*); +int note_cat(note_t*); + int note_rm(note_t*); int line_matches(char*, char*); @@ -44,7 +46,6 @@ int line_matches(char*, char*); * C++ code */ //vector<string> body; -//void read(); //string friendly_name(); //string get_fqp(); //vector<string> find( bool, string ); diff --git a/src/note_list.c b/src/note_list.c index bcfd1e0..2e1740a 100644 --- a/src/note_list.c +++ b/src/note_list.c @@ -221,18 +221,27 @@ int note_list_get_note_id(note_list_t* list, char* note_name) { * * @return vector<string> Contents of the note, broken per line into a vector. */ -// int note_list::cat_note( string note_name, vector<string>* pbody ) { -// // Check for the requested note -// int id = find_note_id( note_name ); -// if( id != -1 ) { -// // Read in the note's contents -// notes[id].read(); -// *pbody = notes[id].body; -// } else { -// return 1; -// } -// return 0; -// } +int note_list_cat_note(note_list_t* list, char* note_name) { + // Check for the requested note + int id = note_list_get_note_id(list, note_name); + if(id != -1) { + // Construct the full note path + char path[strlen(list->path) + strlen(list->names[id]) + strlen(list->extension) + 3]; + strcpy(path, list->path); + strcat(path, "/"); + strcat(path, list->names[id]); + strcat(path, "."); + strcat(path, list->extension); + // TODO + note_t note; + note_new(¬e, path); + // Read in the note's contents + note_cat(¬e); + } else { + return 1; + } + return 0; +} /** * Deletes the specified note diff --git a/src/note_list.h b/src/note_list.h index 07a2676..11744a6 100644 --- a/src/note_list.h +++ b/src/note_list.h @@ -39,6 +39,8 @@ int note_list_edit(note_list_t*, char*, char*); int note_list_get_note_id(note_list_t*, char*); +int note_list_cat_note(note_list_t*, char*); + // void get_notes(note_list_t*); // note_list( string, string ); @@ -47,6 +49,5 @@ int note_list_get_note_id(note_list_t*, char*); // int rm( string ); // vector<string> enum_names(); // vector<string> find( bool, string ); -// int cat_note( string, vector<string>* ); #endif |