commit
907f27d251
@ -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
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* args.cxx
|
||||
*
|
||||
* Copyright 2011 Micke Nordin <micke@hal>
|
||||
*
|
||||
* 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 <iostream>
|
||||
#include <fstream>
|
||||
#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;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* args.cxx
|
||||
*
|
||||
* Copyright 2011 Micke Nordin <micke@hal>
|
||||
*
|
||||
* 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 <iostream>
|
||||
#include <fstream>
|
||||
|
||||
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
|
||||
|
Binary file not shown.
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* begin.cxx
|
||||
*
|
||||
* Copyright 2011 Micke Nordin <micke@hal>
|
||||
*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* begin.hpp
|
||||
*
|
||||
* Copyright 2011 Micke Nordin <micke@hal>
|
||||
*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void begin(string needle);
|
||||
string tolower(string str);
|
||||
|
||||
#endif
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* main.cxx
|
||||
*
|
||||
* Copyright 2011 Micke Nordin <micke@hal>
|
||||
*
|
||||
* 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 <iostream>
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in new issue