David Blume commited on 2015-11-07 22:13:58
Showing 16 changed files, with 359 additions and 0 deletions.
... | ... |
@@ -0,0 +1,21 @@ |
1 |
+SUBDIRS=my_lib product |
|
2 |
+LIBDIR=lib |
|
3 |
+ |
|
4 |
+.PHONY: clean subdirs $(SUBDIRS) |
|
5 |
+ |
|
6 |
+subdirs: $(SUBDIRS) |
|
7 |
+ |
|
8 |
+$(SUBDIRS): |
|
9 |
+ $(MAKE) -C $@ |
|
10 |
+ |
|
11 |
+all: $(LIBDIR) subdirs |
|
12 |
+ |
|
13 |
+product: my_lib |
|
14 |
+ |
|
15 |
+$(LIBDIR): |
|
16 |
+ mkdir $@ |
|
17 |
+ |
|
18 |
+clean: |
|
19 |
+ for dir in $(SUBDIRS); do \ |
|
20 |
+ $(MAKE) -C $$dir clean; \ |
|
21 |
+ done |
... | ... |
@@ -0,0 +1,25 @@ |
1 |
+#!/usr/bin/env python |
|
2 |
+# See http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12028 |
|
3 |
+ |
|
4 |
+import sys |
|
5 |
+import os.path |
|
6 |
+import re |
|
7 |
+ |
|
8 |
+cdir = "" |
|
9 |
+ |
|
10 |
+enter_re = re.compile(r"make\[[0-9]+\]: Entering directory\s+'(.*)'") |
|
11 |
+err_re = re.compile(r"(..[^:\n]*):([0-9]+:?[0-9]+?:? .*)$") |
|
12 |
+ |
|
13 |
+for line in iter(sys.stdin.readline, b''): |
|
14 |
+ err = re.match(err_re, line) |
|
15 |
+ if err: |
|
16 |
+ sys.stdout.write("{0}/{1}:{2}\n".format(cdir, err.group(1), |
|
17 |
+ err.group(2))) |
|
18 |
+ continue |
|
19 |
+ |
|
20 |
+ enter = re.match(enter_re, line) |
|
21 |
+ if enter: |
|
22 |
+ cdir = os.path.relpath(enter.group(1)) |
|
23 |
+ continue |
|
24 |
+ |
|
25 |
+ sys.stdout.write(line) |
... | ... |
@@ -0,0 +1,24 @@ |
1 |
+#/bin/bash |
|
2 |
+set -eu -o pipefail # See: https://sipb.mit.edu/doc/safe-shell/ |
|
3 |
+ |
|
4 |
+ctags -n --if0=yes --langmap=c++:+.inl --c++-kinds=+p --file-tags=yes -R --extra=fq \ |
|
5 |
+ --exclude='obj/*' \ |
|
6 |
+ --exclude='lib/*' \ |
|
7 |
+ --exclude='*generated/*' |
|
8 |
+ |
|
9 |
+find . -mindepth 1 \ |
|
10 |
+ '(' -path './include' ')' -prune \ |
|
11 |
+ -or '(' -path './lib' ')' -prune \ |
|
12 |
+ -or '(' -path '*/generated' ')' -prune \ |
|
13 |
+ -or '(' -type d ')' -print | while read i |
|
14 |
+do |
|
15 |
+ pushd "$i" 1> /dev/null |
|
16 |
+ ctags -n --if0=yes --langmap=c++:+.inl --c++-kinds=+p --file-tags=yes -R --extra=fq \ |
|
17 |
+ --exclude='obj/*' \ |
|
18 |
+ --exclude='lib/*' \ |
|
19 |
+ --exclude='*generated/*' |
|
20 |
+ popd 1> /dev/null |
|
21 |
+done |
|
22 |
+ |
|
23 |
+# Finally, there'll be empty tags files, unlink those |
|
24 |
+find . -name tags -size -2 -print | xargs rm |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+CXX=g++ |
|
2 |
+CPPFLAGS=-c -Wall -I../include |
|
3 |
+LDFLAGS= |
|
4 |
+OBJDIR=obj |
|
5 |
+LIBDIR=../lib |
|
6 |
+ |
|
7 |
+SOURCES=my_lib.cpp |
|
8 |
+# //OBJECTS=$(OBJDIR)$(SOURCES:.cpp=.o) |
|
9 |
+OBJECTS=$(foreach bname, $(basename $(SOURCES)), $(OBJDIR)/$(bname).o) |
|
10 |
+LIB=$(LIBDIR)/libmy_lib.a |
|
11 |
+ |
|
12 |
+all: $(LIB) |
|
13 |
+ |
|
14 |
+$(OBJDIR): |
|
15 |
+ mkdir $@ |
|
16 |
+ |
|
17 |
+$(LIBDIR): |
|
18 |
+ mkdir $@ |
|
19 |
+ |
|
20 |
+$(LIB): $(OBJECTS) $(LIBDIR) |
|
21 |
+ ar -rcs $@ $< |
|
22 |
+ |
|
23 |
+$(OBJDIR)/%.o: %.cpp $(OBJDIR) |
|
24 |
+ $(CXX) $(CPPFLAGS) $< -o $@ |
|
25 |
+ |
|
26 |
+clean: |
|
27 |
+ rm -f $(OBJECTS) $(LIB) |
|
28 |
+ |
... | ... |
@@ -0,0 +1,14 @@ |
1 |
+#include <iostream> |
|
2 |
+#include "../include/my_lib.hpp" |
|
3 |
+ |
|
4 |
+using namespace std; |
|
5 |
+ |
|
6 |
+int my_lib_fn() { |
|
7 |
+ cout << "The function my_lib_fn() was called." << endl; |
|
8 |
+ return 0; |
|
9 |
+} |
|
10 |
+ |
|
11 |
+int my_lib_fn(int x) { |
|
12 |
+ cout << "The function my_lib_fn with parameter " << x << " was called." << endl; |
|
13 |
+ return x+1; |
|
14 |
+} |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+CXX=g++ |
|
2 |
+CPPFLAGS=-c -Wall -std=c++0x -I../include |
|
3 |
+LIBDIR=../lib |
|
4 |
+LDFLAGS=-L $(LIBDIR) -lmy_lib |
|
5 |
+OBJDIR=obj |
|
6 |
+ |
|
7 |
+SOURCES=main.cpp main_helper.cpp ui/widget.cpp |
|
8 |
+# //OBJECTS=$(OBJDIR)$(SOURCES:.cpp=.o) |
|
9 |
+OBJECTS=$(foreach bname, $(basename $(SOURCES)), $(OBJDIR)/$(bname).o) |
|
10 |
+EXECUTABLE=main |
|
11 |
+ |
|
12 |
+all: $(EXECUTABLE) |
|
13 |
+ |
|
14 |
+$(OBJDIR): |
|
15 |
+ mkdir $@ |
|
16 |
+ |
|
17 |
+$(OBJDIR)/ui: |
|
18 |
+ mkdir $@ |
|
19 |
+ |
|
20 |
+$(EXECUTABLE): $(OBJECTS) $(LIBDIR)/libmy_lib.a |
|
21 |
+ $(CXX) $(OBJECTS) $(LDFLAGS) -o $@ |
|
22 |
+ |
|
23 |
+$(OBJDIR)/%.o: %.cpp ../include/my_lib.hpp $(OBJDIR) $(OBJDIR)/ui |
|
24 |
+ $(CXX) $(CPPFLAGS) $< -o $@ |
|
25 |
+ |
|
26 |
+clean: |
|
27 |
+ rm -f $(OBJECTS) $(EXECUTABLE) |
|
28 |
+ |
... | ... |
@@ -0,0 +1,95 @@ |
1 |
+#include <cmath> |
|
2 |
+#include <cstdio> |
|
3 |
+#include <vector> |
|
4 |
+#include <iostream> |
|
5 |
+#include <algorithm> |
|
6 |
+#include <memory> |
|
7 |
+#include "main_helper.hpp" |
|
8 |
+#include "ui/widget.hpp" |
|
9 |
+#include "../include/my_lib.hpp" |
|
10 |
+ |
|
11 |
+using namespace std; |
|
12 |
+ |
|
13 |
+int length_of_array; |
|
14 |
+ |
|
15 |
+ostream & operator << (ostream & ost, const int a[]) |
|
16 |
+{ |
|
17 |
+ // bad form: using global length_of_array |
|
18 |
+ for(int i = 0; i < length_of_array; ++i) { |
|
19 |
+ ost << a[i] << " "; |
|
20 |
+ } |
|
21 |
+ return ost; |
|
22 |
+} |
|
23 |
+ |
|
24 |
+// remove all instances of element n, return new length |
|
25 |
+int remove_element(int a[], int n, int elem) |
|
26 |
+{ |
|
27 |
+ int new_length = 0; |
|
28 |
+ for(int i = 0; i < n; ++i) { |
|
29 |
+ if(a[i] != elem) { |
|
30 |
+ if(i != new_length) { |
|
31 |
+ a[new_length] = a[i]; |
|
32 |
+ } |
|
33 |
+ ++new_length; |
|
34 |
+ } |
|
35 |
+ } |
|
36 |
+ return new_length; |
|
37 |
+} |
|
38 |
+ |
|
39 |
+// remove all duplicates of an element, return new length |
|
40 |
+int remove_duplicates(int a[], int n) |
|
41 |
+{ |
|
42 |
+ int last = 0; |
|
43 |
+ for(int i = 1; i < n; ++i) { |
|
44 |
+ if(a[last] != a[i]) { |
|
45 |
+ ++last; |
|
46 |
+ a[last] = a[i]; |
|
47 |
+ } |
|
48 |
+ } |
|
49 |
+ return last + 1; |
|
50 |
+} |
|
51 |
+ |
|
52 |
+int main() { |
|
53 |
+ length_of_array = 6; |
|
54 |
+ int a[6] = { 10, 20, 20, 30, 40, 40 }; |
|
55 |
+ int item_to_remove = 20; |
|
56 |
+ cout << "Removing " << item_to_remove << endl; |
|
57 |
+ length_of_array = remove_element(a, length_of_array, item_to_remove); |
|
58 |
+ cout << "a became " << a << endl; |
|
59 |
+ |
|
60 |
+ length_of_array = 6; |
|
61 |
+ int b[6] = { 10, 20, 20, 30, 40, 40 }; |
|
62 |
+ length_of_array = remove_duplicates(b, length_of_array); |
|
63 |
+ cout << "Removing duplicates yielded " << length_of_array << " items " << b << endl; |
|
64 |
+ |
|
65 |
+ main_helper_fn(); |
|
66 |
+ UI::widget_cb(); |
|
67 |
+ cout << "sizeof(int) is " << sizeof(int) << "." << endl; |
|
68 |
+ my_lib_fn(); |
|
69 |
+ my_lib_fn(5); |
|
70 |
+ |
|
71 |
+ { |
|
72 |
+ std::unique_ptr<int> up( new int() ); |
|
73 |
+ if (up) { |
|
74 |
+ cout << "unique_ptr passes if." << endl; |
|
75 |
+ } else { |
|
76 |
+ cout << "unique_ptr fails if." << endl; |
|
77 |
+ } |
|
78 |
+ up.release(); |
|
79 |
+ if (up) { |
|
80 |
+ cout << "unique_ptr 2 passes if." << endl; |
|
81 |
+ } else { |
|
82 |
+ cout << "unique_ptr 2 fails if." << endl; |
|
83 |
+ } |
|
84 |
+ if (up.get()) { |
|
85 |
+ cout << "unique_ptr 3 passes if." << endl; |
|
86 |
+ } else { |
|
87 |
+ cout << "unique_ptr 3 fails if." << endl; |
|
88 |
+ } |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ // This_function_is_not_defined(); |
|
92 |
+ |
|
93 |
+ cout << "Done." << endl; |
|
94 |
+ return 0; |
|
95 |
+} |
... | ... |
@@ -0,0 +1,21 @@ |
1 |
+#include <iostream> |
|
2 |
+#include <string> |
|
3 |
+#include <vector> |
|
4 |
+#include "main_helper.hpp" |
|
5 |
+ |
|
6 |
+using namespace std; |
|
7 |
+ |
|
8 |
+int read( std::string const &directory, const std::vector<unsigned char> &secret) |
|
9 |
+{ |
|
10 |
+// directory = directory + "aaa"; |
|
11 |
+ return directory.length(); |
|
12 |
+} |
|
13 |
+ |
|
14 |
+int main_helper_fn() { |
|
15 |
+ cout << "The function main_helper_fn was called." << endl; |
|
16 |
+ string my_string("Hello"); |
|
17 |
+ vector<unsigned char> secret; |
|
18 |
+ cout << "The length of hello is " << read(my_string, secret) << endl; |
|
19 |
+ return 0; |
|
20 |
+} |
|
21 |
+ |
... | ... |
@@ -0,0 +1,36 @@ |
1 |
+{ |
|
2 |
+ "folders": |
|
3 |
+ [ |
|
4 |
+ { |
|
5 |
+ "path": "include", |
|
6 |
+ "file_exclude_patterns": ["tags"] |
|
7 |
+ }, |
|
8 |
+ { |
|
9 |
+ "path": "my_lib", |
|
10 |
+ "folder_exclude_patterns": ["obj"], |
|
11 |
+ "file_exclude_patterns": ["tags"] |
|
12 |
+ }, |
|
13 |
+ { |
|
14 |
+ "path": "product", |
|
15 |
+ "folder_exclude_patterns": ["obj"], |
|
16 |
+ "file_exclude_patterns": ["tags"] |
|
17 |
+ } |
|
18 |
+ ], |
|
19 |
+ "build_systems": |
|
20 |
+ [ |
|
21 |
+ { |
|
22 |
+ "name": "Cygwin Make", |
|
23 |
+ "working_dir": "$project_path", |
|
24 |
+ "windows": { |
|
25 |
+ "shell_cmd": "C:/cygwin64/bin/bash --login $project_base_name/build" |
|
26 |
+ }, |
|
27 |
+ "osx": { |
|
28 |
+ "shell_cmd": "$project_base_name/build" |
|
29 |
+ }, |
|
30 |
+ "linux": { |
|
31 |
+ "shell_cmd": "$project_base_name/build" |
|
32 |
+ }, |
|
33 |
+ "file_regex": "^(...*?):([0-9]*):?([0-9]*)" |
|
34 |
+ } |
|
35 |
+ ] |
|
36 |
+} |
|
0 | 37 |