示例#1
0
int hash_search(Fxstream& stream) {


    ReadPair pair;
    std::map<std::string, int>::iterator iter;
    while(stream.read(pair) == 0) {

        std::string * data = prepare_data(opts, pair.first);

        FILE * out = manager.find(*data);
        if(out != NULL) {
            if(! opts.v_flag) {
                if(on_match(out,  pair) == 1)
                {
                    // the l flag has been set, print the file name
                    printf("%s\n", stream.getFile1().c_str());
                    return 0;
                }
            }

        } else {
            // read one did not have a match check read 2 if it exists
            if(!pair.second.empty()) {
                data = prepare_data(opts, pair.second);
                FILE * out = manager.find(*data);
                if(out != NULL) {
                    if(on_match(out,  pair) == 1)
                    {
                        // the l flag has been set, print the file name
                        printf("%s\n", stream.getFile2().c_str());
                        return 0;
                    }
                } else if (opts.v_flag) {
                    on_match(stdout, pair);
                }
            } else if (opts.v_flag) {
                on_match(stdout, pair);
            }
        }
        pair.clear();
    }

    return 0;
}
示例#2
0
static int on_match2(int strnum, const char *textp, void const * context) {
    if(opts.v_flag) {
        return 1;
    }
    if(opts.l_flag)
    {
        return 1;
    }
    if(opts.c_flag) {
        ++matched_records;
        return 1;
    }
    ReadPair * pair = (ReadPair *) context;
    FILE * out = manager.find(pattv[strnum].ptr);
    pair->print(out);
    return  1;
}