summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2015-02-25 11:02:18 -0700
committerAaron Ball <nullspoon@iohq.net>2015-02-25 11:02:18 -0700
commitde3ee4e2c472dfd032c7ee580fcf67721f74623e (patch)
tree7477051bf524e735c82ed79d052f72967d1b482e
parent3bbfd0f3882a3832fb2affaa6d2a8aff2fedc6ba (diff)
downloadnoteless-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).
-rw-r--r--src/main.c5
-rw-r--r--src/note.c51
-rw-r--r--src/note.h3
-rw-r--r--src/note_list.c33
-rw-r--r--src/note_list.h3
5 files changed, 58 insertions, 37 deletions
diff --git a/src/main.c b/src/main.c
index 6a2d170..06ad00a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 ) {
diff --git a/src/note.c b/src/note.c
index 93b76da..71f495f 100644
--- a/src/note.c
+++ b/src/note.c
@@ -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
diff --git a/src/note.h b/src/note.h
index 239ef0f..2627295 100644
--- a/src/note.h
+++ b/src/note.h
@@ -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(&note, path);
+ // Read in the note's contents
+ note_cat(&note);
+ } 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

Generated by cgit