commit 907f27d251566139bac0df2d5abcc05ba4c0306c Author: Micke Nordin Date: Fri Dec 23 11:08:09 2011 +0100 first commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc19e4c --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CC=g++ +CFLAGS=-c -g -Wall +CCFLAGS=-g -Wall +begin : main.o begin.o args.o + $(CC) -o begin $(CCFLAGS) main.o begin.o args.o + +main.o: main.cxx begin.o + $(CC) $(CFLAGS) main.cxx + +begin.o: begin.cxx begin.hpp + $(CC) $(CFLAGS) begin.cxx + +args.o: args.cxx args.hpp + $(CC) $(CFLAGS) args.cxx + + +clean: + rm *.o begin diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/args.cxx b/args.cxx new file mode 100644 index 0000000..dfe2c4a --- /dev/null +++ b/args.cxx @@ -0,0 +1,65 @@ +/* + * args.cxx + * + * Copyright 2011 Micke Nordin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include +#include +#include "args.hpp" +using namespace std; + +args::args(int argc, char **argv) { + iscaseinsence = false; + isregex = false; + havefile = false; + filename = ""; + int c; + + while ((c = getopt (argc, argv, "efi:")) != -1) { + switch (c) { + case 'e': + isregex = true; + break; + case 'f': + filename = optarg; + havefile = true; + break; + case 'i': + iscaseinsence = true; + break; + case '?': + if (optopt == 'f') { + cerr << "Option -" << optopt << " requires an argument.\n"; + } + else if (isprint (optopt)) { + cerr << "Unknown option `-" << optopt << ".\n"; + } + else { + cerr << "Unknown option character `\\x" << optopt << ".\n"; + } +// default: +// abort (); + } + } +} + +void args::print() { + cout << "Case inscensitive: " << iscaseinsence << " Regex: " << isregex << " Have a file: " << havefile << " filename: " << filename; +} diff --git a/args.hpp b/args.hpp new file mode 100644 index 0000000..0fb2a35 --- /dev/null +++ b/args.hpp @@ -0,0 +1,41 @@ +/* + * args.cxx + * + * Copyright 2011 Micke Nordin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#ifndef args_h +#define args_h + +#include +#include + +using namespace std; + +class args { + public: + bool iscaseinsence; //-i + bool isregex; // -e + bool havefile; // -f + string filename; // filename + + args(int argc, char **argv); //Konstruktor + void print(); //Skriver ut objektet +}; + +#endif + diff --git a/args.hpp.gch b/args.hpp.gch new file mode 100644 index 0000000..43da5a0 Binary files /dev/null and b/args.hpp.gch differ diff --git a/args.o b/args.o new file mode 100644 index 0000000..4008d10 Binary files /dev/null and b/args.o differ diff --git a/begin b/begin new file mode 100755 index 0000000..7ad1877 Binary files /dev/null and b/begin differ diff --git a/begin.cxx b/begin.cxx new file mode 100644 index 0000000..2d5ce89 --- /dev/null +++ b/begin.cxx @@ -0,0 +1,51 @@ +/* + * begin.cxx + * + * Copyright 2011 Micke Nordin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include +#include + +using namespace std; + +void begin(string needle) +{ + string input; + + while(cin) { + getline(cin, input); + if (input.find(needle) != string::npos) { + cout << input << endl; + while(cin) { + getline(cin,input); + cout << input << endl; + } + } + } + +} + +string tolower(string str) { + for( unsigned int i = 0; i < str.length(); i++) { + str[i] = tolower(str[i]); + } + return str; +} + diff --git a/begin.hpp b/begin.hpp new file mode 100644 index 0000000..58a3521 --- /dev/null +++ b/begin.hpp @@ -0,0 +1,31 @@ +/* + * begin.hpp + * + * Copyright 2011 Micke Nordin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#ifndef begin_h +#define begin_h +#include +#include + +using namespace std; + +void begin(string needle); +string tolower(string str); + +#endif diff --git a/begin.o b/begin.o new file mode 100644 index 0000000..3dc757b Binary files /dev/null and b/begin.o differ diff --git a/main.cxx b/main.cxx new file mode 100644 index 0000000..36c05ca --- /dev/null +++ b/main.cxx @@ -0,0 +1,39 @@ +/* + * main.cxx + * + * Copyright 2011 Micke Nordin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include +#include "begin.hpp" +#include "args.hpp" +using namespace std; + +int main(int argc, char **argv) +{ + args myargs(argc, argv); + + myargs.print(); + + if( argc == 2) { + begin(argv[1]); + } + return 0; +} + diff --git a/main.o b/main.o new file mode 100644 index 0000000..74b766c Binary files /dev/null and b/main.o differ