summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--src/lib/file.cpp23
-rw-r--r--src/lib/file.h13
-rw-r--r--src/lib/note.cpp39
-rw-r--r--src/lib/note.h8
-rw-r--r--src/lib/note_list.cpp20
-rw-r--r--src/lib/note_list.h5
-rw-r--r--src/lib/path.cpp53
-rw-r--r--src/lib/path.h22
-rw-r--r--src/main.cpp2
10 files changed, 127 insertions, 71 deletions
diff --git a/Makefile b/Makefile
index 3e305ba..afc28cc 100644
--- a/Makefile
+++ b/Makefile
@@ -5,11 +5,14 @@ obj = obj/
all:
if [[ ! -d obj ]]; then mkdir obj; fi
- g++ $(debug) -c $(libs)file.cpp -o $(obj)/file.o
- g++ $(debug) -c $(libs)config.cpp -o $(obj)/config.o
- g++ $(debug) -c $(libs)note.cpp -o $(obj)/note.o
- g++ $(debug) -c $(libs)note_list.cpp -o $(obj)/note_list.o
- g++ $(debug) src/main.cpp $(obj)/*.o -o $(out)
+ g++ $(debug) -c $(libs)path.cpp -o $(obj)path.o
+ g++ $(debug) -c $(libs)config.cpp -o $(obj)config.o
+ g++ $(debug) -c $(libs)note.cpp -o $(obj)note.o
+ g++ $(debug) -c $(libs)note_list.cpp -o $(obj)note_list.o
+ g++ $(debug) src/main.cpp $(obj)*.o -o $(out)
debug:
make all debug="-g"
+
+clean:
+ rm -rvf $(obj)*.o
diff --git a/src/lib/file.cpp b/src/lib/file.cpp
deleted file mode 100644
index 6b18277..0000000
--- a/src/lib/file.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "file.h"
-
-file::file( string p ) {
- // Parse path into parent dir array and filename
- long cur_dir_begin = 0;
- for( int i = 0; i < p.length(); i++ ) {
- int cur_char = p[i];
- int delim = '/';
- // Parse the directories out of the path
- // Skip the first if it's an absolute path
- if( i == 0 && cur_char == delim ) {
- // Do nothing
- } else if( cur_char == delim ) {
- // Check if we've hit a path delimiter (/ or \)
- dirs.push_back( p.substr( cur_dir_begin, i - cur_dir_begin ) );
- // Skip the slash since we don't need it
- i++;
- cur_dir_begin = i;
- }
- }
- // Annnnnd output the filename...for now
- name = p.substr( cur_dir_begin, p.length() - cur_dir_begin );
-}
diff --git a/src/lib/file.h b/src/lib/file.h
deleted file mode 100644
index 85c8852..0000000
--- a/src/lib/file.h
+++ /dev/null
@@ -1,13 +0,0 @@
-using namespace std;
-
-#include <string>
-#include <vector>
-#include <iostream>
-
-class file {
- public:
- string name;
- vector<string> dirs;
-
- file( string );
-};
diff --git a/src/lib/note.cpp b/src/lib/note.cpp
index b50038d..dbffa04 100644
--- a/src/lib/note.cpp
+++ b/src/lib/note.cpp
@@ -19,17 +19,28 @@
/**
* Opens a new note object
*/
-note::note( string p, string filename ) {
- name = filename;
- path = p;
- extension = get_extension();
+// note::note( string p ) {
+// //name = filename;
+// _path = p;
+// extension = get_extension();
+// }
+
+/**
+ * Creates a new empty note object since no filename was specified.
+ */
+note::note( path p ) {
+ _path = p;
+ name = _path.filename;
}
/**
* Creates a new empty note object since no filename was specified.
*/
-note::note( string path ) {
- name = get_current_date_time();
+note::note( string p ) {
+ path tmp_path( p );
+ _path = tmp_path;
+ name = _path.filename;
+ //name = get_current_date_time();
}
/**
@@ -42,7 +53,7 @@ note::note( string path ) {
int note::edit( string editor ) {
string cmd = editor;
cmd += " ";
- cmd += path + name;
+ cmd += _path.out();
system( cmd.c_str() );
}
@@ -108,11 +119,11 @@ void note::read() {
// Don't do this unless body hasn't already been read
if( body.size() == 0 ) {
// Open the file
- ifstream fs( name.c_str() );
+ ifstream fs( _path.out().c_str() );
// Verify the file handle opened sucessfully
if( ! fs.is_open() ) {
- cout << "Could not open file at " << name << "." << endl;
+ cout << "Could not open file at " << _path.out() << "." << endl;
exit( 1 );
}
@@ -201,11 +212,11 @@ string note::friendly_name() {
/**
* TODO
*/
-string note::get_fqp() {
- string fqp = path;
- fqp += "/" + name;
- return fqp;
-}
+// string note::get_fqp() {
+// string fqp = path;
+// fqp += "/" + name;
+// return fqp;
+// }
/**
* TODO
diff --git a/src/lib/note.h b/src/lib/note.h
index 2643eaa..4ba4c1b 100644
--- a/src/lib/note.h
+++ b/src/lib/note.h
@@ -21,6 +21,7 @@ using namespace std;
#include <time.h>
#include <string>
#include <vector>
+#include "path.h"
#ifndef LIB_NOTE_H
#define LIB_NOTE_H
class note {
@@ -29,16 +30,17 @@ class note {
const char itoc( int );
string get_extension();
bool line_matches( string, string );
+ path _path;
public:
// Variables
- string name;
- string path;
string extension;
+ string name;
vector<string> body;
// Methods
- note( string, string);
+ //note( string, string);
+ note( path );
note( string );
int edit( string );
void read();
diff --git a/src/lib/note_list.cpp b/src/lib/note_list.cpp
index 73f20b9..ab058cb 100644
--- a/src/lib/note_list.cpp
+++ b/src/lib/note_list.cpp
@@ -19,12 +19,12 @@
/**
* Constructor
*
- * @param string p Path to the treasure... er... notes
+ * @param string dirname Path to the treasure... er... notes
* @param string ext Extension of the notes to pay attention to
*/
-note_list::note_list( string p, string ext ) {
- path = p;
- get_notes( p, ext );
+note_list::note_list( string dirname, string ext ) {
+ _dirname = dirname;
+ get_notes( _dirname, ext );
}
void note_list::get_notes( string base, string ext ) {
@@ -48,17 +48,17 @@ void note_list::get_notes( string base, string ext ) {
if( name != "."
&& name != ".."
&& name != ".git" ) {
- string fqp = base + "/" + name;
+ path p = base + "/" + name;
// Stat the item
struct stat sb;
- stat( fqp.c_str(), &sb );
+ stat( p.out().c_str(), &sb );
// Check if it's a file or a folder
if( sb.st_mode == is_folder ) {
// Recurse through nested dirs
- get_notes( fqp, ext );
+ get_notes( p.out(), ext );
} else {
- add( fqp );
+ add( p );
}
}
}
@@ -74,8 +74,8 @@ void note_list::get_notes( string base, string ext ) {
*
* @return 0
*/
-int note_list::add( string name ) {
- note n( path, name );
+int note_list::add( path p ) {
+ note n( p );
notes.push_back( n );
return 0;
}
diff --git a/src/lib/note_list.h b/src/lib/note_list.h
index fd2fb4b..615eeb1 100644
--- a/src/lib/note_list.h
+++ b/src/lib/note_list.h
@@ -21,6 +21,7 @@ using namespace std;
#include <vector>
#include <sys/stat.h>
#include "note.h"
+#include "path.h"
#ifndef LIB_NOTE_COLLECTION_H
#define LIB_NOTE_COLLECTION_H
@@ -28,14 +29,14 @@ class note_list {
private:
// Properties
vector<note> notes;
- string path;
+ string _dirname;
// Methods
void get_notes( string, string );
public:
// Methods
note_list( string, string );
- int add( string );
+ int add( path );
void edit( string, string );
vector<string> enum_names();
vector<string> find( bool, string );
diff --git a/src/lib/path.cpp b/src/lib/path.cpp
new file mode 100644
index 0000000..b478ab8
--- /dev/null
+++ b/src/lib/path.cpp
@@ -0,0 +1,53 @@
+#include "path.h"
+
+path::path() {}
+
+path::path( string p ) {
+ value = p;
+ // Parse path into parent dir array and filename
+ long cur_dir_begin = 0;
+ for( int i = 0; i < p.length(); i++ ) {
+ // Setting this to a variable so we can handle Windows in the future
+ char delim = '/';
+ // Parse the directories out of the path
+ // Skip the first if it's an absolute path
+ if( i == 0 && p[i] == delim ) { continue; }
+ if( p[i] == delim ) {
+ // Check if we've hit a path delimiter (/ or \)
+ dirs.push_back( p.substr( cur_dir_begin, i - cur_dir_begin ) );
+ // Skip the slash since we don't need it
+ i++;
+ cur_dir_begin = i;
+ }
+ }
+ // Advance one further so we don't catch the last delimiter
+ cur_dir_begin++;
+ // Annnnnd output the filename...for now
+ filename = p.substr( cur_dir_begin, p.length() - cur_dir_begin );
+ // Add the filename to the end of the array (might remove this later)
+ dirs.push_back( p.substr( cur_dir_begin + 1, p.length() - cur_dir_begin ) );
+}
+
+
+/**
+ * Checks if a particular file exists by attempting to open a file handle.
+ *
+ * @return bool File exists (true) or not (false)
+ */
+bool path::exists() {
+ // Attempt to open a file handle
+ ifstream fs( value.c_str() );
+
+ // Verify the file handle opened sucessfully
+ if( ! fs.is_open() ) {
+ return false;
+ }
+
+ // Looks like it opened, so close and return true
+ fs.close();
+ return true;
+}
+
+string path::out() {
+ return value;
+}
diff --git a/src/lib/path.h b/src/lib/path.h
new file mode 100644
index 0000000..ba18b64
--- /dev/null
+++ b/src/lib/path.h
@@ -0,0 +1,22 @@
+using namespace std;
+
+#include <string>
+#include <vector>
+#include <iostream>
+#include <fstream>
+#ifndef LIB_PATH_H
+#define LIB_PATH_H
+
+class path {
+ public:
+ string value;
+ string filename;
+ vector<string> dirs;
+
+ path();
+ path( string );
+ bool exists();
+ string out();
+};
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
index ee8dbee..7772a76 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,7 +21,7 @@ using namespace std;
#include "lib/config.h"
#include "lib/note.h"
#include "lib/note_list.h"
-#include "lib/file.h"
+#include "lib/path.h"
void get_help() {
string out = "Noteless provides a simple command line interface for note"

Generated by cgit