forked from padi-g/bash-on-windows-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep.cpp
executable file
·57 lines (47 loc) · 1.26 KB
/
grep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "command.h"
#include "globals.h"
#include <QtCore>
#include<QTextStream>
using namespace std;
grep::grep(QString input){
cmd = input;
if(cmd.contains("-i"))
this->grep_i();
else
this->grep_n();
}
void grep::grep_n(){
user = cmd.mid(5);
subnum = user.indexOf(" ");
filename = user.mid(subnum+1);
substr = user.left(subnum);
QFile file(filename);
file.open(QIODevice::ReadOnly|QIODevice::Text);
putt_n = file.readAll();
file.close();
string s = substr.toStdString();
check = s.c_str();
if(putt_n.contains(check))
out << check << endl << "Found" << endl;
else
out << "Not Found" << endl;
}
void grep::grep_i(){
user = cmd.mid(8);
subnum = user.indexOf(" ");
filename = user.mid(subnum+1);
substr = user.left(subnum);
substr = substr.toLower();
//file read
QFile file(filename);
file.open(QIODevice::ReadOnly|QIODevice::Text);
putt = file.readAll();
//checking
string s = substr.toStdString();
check = s.c_str();
if(putt.contains(check))
out << check << endl << "Found" << endl;
else
out << "Not Found" <<endl;
file.close();
}