source: icGREP/icgrep-devel/icgrep/icgrep.cpp @ 4327

Last change on this file since 4327 was 4327, checked in by cameron, 5 years ago

Line numbering option

File size: 2.6 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <string>
8
9#include "icgrep.h"
10#include "utf_encoding.h"
11#include "compiler.h"
12#include "pablo/pablo_compiler.h"
13#include "do_grep.h"
14
15#include "llvm/Support/CommandLine.h"
16
17int main(int argc, char *argv[]) {
18    static cl::opt<std::string> regexp1(cl::Positional, cl::Required, cl::desc("<regexp>"));
19    static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
20   
21    static cl::opt<bool>CountOnly("c", cl::desc("Count and display the matching lines per file only."));
22    cl::alias CountOnlyLong("-count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
23   
24    static cl::opt<bool>ShowFileNames("H", cl::desc("Show the file name with each matching line."));
25    cl::alias ShowFileNamesLong("-with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
26   
27    static cl::opt<bool>ShowLineNumbers("n", cl::desc("Show the line number with each matching line."));
28    cl::alias ShowLineNumbersLong("-line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
29   
30    //cl::opt<std::string> RegexFilename("f", cl::desc("Take regular expressions (one per line) from a file"), cl::value_desc("<filename>"));
31 
32    // Does -b mean the byte offset of the line, or the byte offset of the match start within the line?
33    //static cl::opt<bool>ShowByteOffsets("b", cl::desc("Show the byte offset with each matching line."));
34    //cl::alias ShowByteOffsetsLong("-byte-offset", cl::desc("Alias for -b"), cl::aliasopt(ShowByteOffsets));
35
36    Encoding encoding(Encoding::Type::UTF_8, 8);
37
38    cl::ParseCommandLineOptions(argc, argv);
39
40    const auto llvm_codegen = icgrep::compile(encoding, regexp1, false, false);
41
42    if (llvm_codegen.process_block_fptr != 0) {
43        void (*FP)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output) = 
44           (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.process_block_fptr;
45        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
46        grepEngine.setCountOnlyOption(CountOnly);
47        grepEngine.setShowLineNumberOption(ShowLineNumbers);
48        if (inputFiles.size() > 1 || ShowFileNames) grepEngine.setShowFileNameOption();
49        for (unsigned i = 0; i != inputFiles.size(); ++i) {
50            grepEngine.doGrep(inputFiles[i].c_str());
51        }
52    }
53   
54    return 0;
55}
56
Note: See TracBrowser for help on using the repository browser.