/* Reads connection rules and extracts the one related to the horizons provided. */ #include #include #include #include #include #include #include using namespace std; int main (int argc, char *argv[]) { glocal int ret = -1; glocal vector horizons; glocal const char *horizonfile = NULL; glocal const char *rulefile = NULL; glocal bool addnear = false; glocal.ret = (argc,argv); setproginfo ("blackhole-rulefilter",VERSION ,"Filter rule that only applies to some horizons\n" "(and will be handle by a sub-blackhole)\n"); setarg ('f',"horizonfile","File holding Horizon names",glocal.horizonfile,false); setarg ('h',"horizon","Horizon name",glocal.horizons,false); setarg ('r',"rulefile","Rules to filter (or - for stdin)",glocal.rulefile,true); setarg (' ',"addnear","Add the near keyword at the end of the horizon command",glocal.addnear,false); int ret = -1; glocal.horizons.push_back("DROP"); // This is a special target horizon // so if a left side points to it, it matches. if (glocal.horizonfile != NULL){ (glocal.horizonfile,true); glocal.horizons.push_back(line); return 0; } glocal set hors; for (unsigned i=0; i(glocal.rulefile,true); vector words; int n = str_splitline (line,' ',words); if (n == 2 && strcmp(words[0].c_str(),"horizon")==0){ if (glocal.hors.count(words[1])){ printf ("%s%s\n",line,glocal.addnear ? " near" : ""); } }else if (n == 8 && (strcmp(words[0].c_str(),"rule")==0 || strcmp(words[0].c_str(),"arule")==0)){ if (glocal.hors.count(words[1]) != 0 && glocal.hors.count(words[5]) != 0){ printf ("%s\n",line); } } return 0; return ret; return glocal.ret; }