Exemple #1
0
void init() {
    read_mapping();
    read_table();
    read_rules();
    assert(num_rules<MAX_RULES);
    assert(num_symbols<MAX_SYMBOLS);
    assert(num_states<MAX_STATES);
}
Exemple #2
0
spocp_result_t 
get_rules( srv_t *srv )
{
	spocp_result_t  rc = SPOCP_SUCCESS;
	int		nrules = 0, r;
	dbcmd_t         dbc;
	struct timeval  start, end;

	memset( &dbc, 0, sizeof( dbcmd_t ));
	dbc.dback = srv->dback;

	if (srv->dback) {
		/*
		 * does the persistent database store need any initialization
		 * ?? * if( srv.dback->init ) srv.dback->init( dbcmd_t *dbc )
		 * ; 
		 */

		if ((nrules = dback_read_rules(&dbc, srv, &rc)) < 0)
			return rc;
	}

	if (nrules == 0) {
		if (srv->rulefile) {
			LOG(SPOCP_INFO)
				traceLog(LOG_INFO, "Opening rules file \"%s\"",
				    srv->rulefile);

			if (0)
				gettimeofday(&start, NULL);

			/*
			dbc.dback = srv->dback;
			dbc.handle = 0;
			*/

			r = read_rules(srv, srv->rulefile, &dbc) ;
			if( r == -1 ) {
	 			LOG(SPOCP_ERR)
					traceLog(LOG_ERR,"Error while reading rules");
				rc = SPOCP_OPERATIONSERROR;
			}
			if (0) {
				gettimeofday(&end, NULL);
				print_elapsed("readrule time:", start, end);
			}
		}
		else
			LOG(SPOCP_INFO)
				traceLog(LOG_INFO, "No rule file to start with");
	} else {
		LOG(SPOCP_INFO)
		    traceLog(LOG_INFO,
			"Got the rules from the persistent store, will not read the rulefile");
	}

	return rc;
}
Exemple #3
0
int main(int argc, char** argv)
{
	struct timeval start, end;

	if (argc < 4)
	{
		fprintf(stderr, "Wrong usage!\n");
		fprintf(stderr, "%s <transactions_filename> <rules_filename> <output_filename>\n", argv[0]);
		exit(0);
	}

	START_CHRONO;
		work_queue.index = 0;
		pthread_mutex_init(&(work_queue.mutex), NULL);
		pthread_mutex_init(&output_mutex, NULL);

		#pragma omp parallel sections
		{
			#pragma omp section
			{
				n_transactions = read_transanctions(argv[1]);
			}

			#pragma omp section
			{
				n_rules = read_rules(argv[2]);
			}
		}

		output_fd = fopen(argv[3], "w");

		sort_rules();

		#ifdef DEBUG_PRINT
			fprintf(stderr, "\n");
		#endif
		/*/
		show_transactions(n_transactions);
		show_rules(n_rules);
		/*/

		/* match_naive(); */
		/* match_bounded_search(); */

		bounded_search_match();

		fclose(output_fd);
	STOP_CHRONO;

	#ifdef TIME_MEASURES
		fprintf(stderr, "\n[Bounded] Took %ld ms to match %d transactions (%.2lf transactions per second)!\n", GET_CHRONO, n_transactions, n_transactions * 1000 / (GET_CHRONO + 0.001));
	#endif

	return 0;
}
Exemple #4
0
int main(const int argc, const char *argv[]) {

    const std::string rules_file = (argc >1)? argv[1] : "rules.txt";

    const std::vector<rule_t> rules = read_rules(rules_file);
    if (rules.empty()) {
        std::cerr << "No rules read freom " << rules_file << std::endl;
        return 1;
    }

    for (unsigned n = 0; n < 10000; n++)
        tell(rules, std::to_string(n));
}
Exemple #5
0
pp_knowledge *pp_knowledge_open(const char *path)
{
  /* read knowledge from disk into pp_knowledge */
  FILE *f = dictopen(path, "r");
  pp_knowledge *k = (pp_knowledge *) xalloc (sizeof(pp_knowledge));
  if (!f)
  {
    prt_error("Fatal Error: Couldn't find post-process knowledge file %s", path);
    exit(1);
  }
  k->lt = pp_lexer_open(f);
  fclose(f);
  k->string_set = string_set_create();
  k->path = string_set_add(path, k->string_set);
  read_starting_link_table(k);
  read_link_sets(k);
  read_rules(k);
  initialize_set_of_links_starting_bounded_domain(k);
  return k;
}
Exemple #6
0
int RDFParser::load_from_stream(std::stringstream & ss) {
	int ret;
	rdfg = new RDFGraph();
	graph = rdfg->graph;
	string rdfname;
        read_str(ss, "rdf");
        ss >> rdfname;
        rdfg->graph->set_name(rdfname);
	ret = read_graph(ss, rdfg->graph);
	
	if (ret < 0)
		return ret;
	ret = read_rules(ss);
	if (ret < 0)
		return ret;
	ret = read_main(ss);
	if (ret == 0)
		cout << "RDF is loaded successfully.\n";
	else 
		cout << "cannot load the RDF.\n";
	return ret;
}
Exemple #7
0
pp_knowledge *pp_knowledge_open(const char *path)
{
  /* read knowledge from disk into pp_knowledge */
  FILE *f = dictopen(path, "r");
  if (NULL == f)
  {
    prt_error("Error: Couldn't find post-process knowledge file %s\n", path);
    return NULL;
  }
  pp_knowledge *k = (pp_knowledge *) malloc (sizeof(pp_knowledge));
  *k = (pp_knowledge){0};
  k->lt = pp_lexer_open(f);
  fclose(f);
  if (NULL == k->lt) goto failure;
  k->string_set = string_set_create();
  k->path = string_set_add(path, k->string_set);
  if (!read_starting_link_table(k)) goto failure;

  if (!read_link_sets(k)) goto failure;
  if (!read_rules(k)) goto failure;
  initialize_set_of_links_starting_bounded_domain(k);

  /* If the knowledge file was empty, do nothing at all. */
  if (0 == k->nStartingLinks)
  {
    pp_knowledge_close(k);
    return NULL;
  }

  return k;

failure:
  prt_error("Error: Unable to open knowledge file %s.\n", path);
  pp_knowledge_close(k);
  return NULL;
}
Exemple #8
0
int changepars(void)
{
    extern int use_rxvt;
    extern int cluster;
    extern int shortqsonr;
    extern int searchflg;
    extern int demode;
    extern int contest;
    extern int announcefilter;
    extern int showscore_flag;
    extern int zonedisplay;
    extern int trxmode;
    extern char hiscall[];
    extern int rit;
    extern int trx_control;
    extern int editor;
    extern int packetinterface;
    extern int nopacket;
    extern int cqdelay;
    extern int ctcomp;
    extern SCREEN *mainscreen;
    extern char *config_file;
    extern int miniterm;
    extern char buffer[];

#ifdef HAVE_LIBHAMLIB
    extern freq_t outfreq;
#else
    extern int outfreq;
#endif

    extern int simulator;
    extern int keyerport;
    extern char synclogfile[];
    extern char sc_volume[];
    extern int cwstart;

    char parameterstring[20];
    char parameters[51][19];
    char cmdstring[80];
    int i, k, x, nopar = 0;
    int maxpar = 50;
    int volumebuffer;
    int currentmode = 0;
    int rc;

    strcpy(parameters[0], "SPOT");
    strcpy(parameters[1], "MAP");
    strcpy(parameters[2], "CLOFF");
    strcpy(parameters[3], "CLUSTER");
    strcpy(parameters[4], "SHORT");
    strcpy(parameters[5], "LONG");
    strcpy(parameters[6], "MESSAGE");
    strcpy(parameters[7], "LIST");
    strcpy(parameters[8], "CHECK");
    strcpy(parameters[9], "NOCHECK");
    strcpy(parameters[10], "TONE");
    strcpy(parameters[11], "EDIT");
    strcpy(parameters[12], "VIEW");
    strcpy(parameters[13], "HELP");
    strcpy(parameters[14], "DEMODE");
    strcpy(parameters[15], "CONTEST");
    strcpy(parameters[16], "FILTER");
    strcpy(parameters[17], "SCORE");
    strcpy(parameters[18], "WRITE");
    strcpy(parameters[19], "EXIT");
    strcpy(parameters[20], "TXFILE");
    strcpy(parameters[21], "ZONES");
    strcpy(parameters[22], "CTY");
    strcpy(parameters[23], "MODE");
    strcpy(parameters[24], "SET");
    strcpy(parameters[25], "MULTI");
    strcpy(parameters[26], "PROP");
    strcpy(parameters[27], "RITCLEAR");
    strcpy(parameters[28], "TRXCONTROL");
    strcpy(parameters[29], "CFG");
    //strcpy(parameters[30],  "CWMODE");
    strcpy(parameters[30], "CW");
    strcpy(parameters[31], "SSBMODE");
    strcpy(parameters[32], "DIGIMODE");
    strcpy(parameters[33], "PACKET");
    strcpy(parameters[34], "SIMULATOR");
    strcpy(parameters[35], "INFO");
    strcpy(parameters[36], "FREQ");
    strcpy(parameters[37], "RECONNECT");
    strcpy(parameters[38], "QUIT");
    strcpy(parameters[39], "CQDELAY");
    strcpy(parameters[40], "ADIF");
    strcpy(parameters[41], "SYNC");
    strcpy(parameters[42], "RESCORE");
    strcpy(parameters[43], "SCVOLUME");
    strcpy(parameters[44], "SCAN");
    strcpy(parameters[45], "DEBUG");
    strcpy(parameters[46], "MINITERM");
    strcpy(parameters[47], "RTTY");
    strcpy(parameters[48], "SOUND");
    strcpy(parameters[49], "CWMODE");
    strcpy(parameters[50], "CHARS");

    nopar = 0;

    attroff(A_STANDOUT);
    attron(COLOR_PAIR(C_HEADER));
    mvprintw(12, 29, "PARAMETER?  ");
    refreshp();

    mvprintw(12, 29, "            ");
    mvprintw(12, 29, "");
    refreshp();

    echo();
    getstr(parameterstring);
    noecho();

    for (k = 0; parameterstring[k]; k++)
	parameterstring[k] = toupper(parameterstring[k]);

    for (i = 0; i <= maxpar; i++) {
	if (strncmp(parameterstring, parameters[i], 3) == 0) {
	    break;
	}
    }

    switch (i) {
    case 0:			/* SPOTS) */
	{
	    /* SPOTS not supported anymore
	     * - default to MAP*/
	    cluster = MAP;
	    break;
	}
    case 1:			/* BANDMAP */
	{
	    cluster = MAP;
	    break;
	}
    case 2:			/* CLOFF  */
	{
	    cluster = NOCLUSTER;
	    break;
	}
    case 3:			/* CLUSTER  */
	{
	    cluster = CLUSTER;
	    announcefilter = FILTER_ALL;
	    break;
	}
    case 4:			/* SHORTNR  */
	{
	    shortqsonr = SHORTCW;
	    break;
	}
    case 5:			/* LONGNR  */
	{
	    shortqsonr = LONGCW;
	    break;
	}
    case 6:			/* MESSAGE  */
	{
	    message_change(i);
	    break;
	}

    case 7:			/* LIST  */
	{
	    listmessages();
	    break;
	}
    case 8:			/* CHECK  */
	{
	    searchflg = SEARCHWINDOW;
	    break;
	}
    case 9:			/* NOCHECK  */
	{
	    searchflg = 0;
	    break;
	}
    case 10:			/*  TONE   */
	{
	    set_tone();
	    break;
	}
    case 11:			/*  EDIT   */
	{
	    logedit();
	    break;
	}
    case 12:			/*  VIEW   */
	{
	    logview();
	    break;
	}
    case 13:			/*  HELP   */
	{
	    show_help();
	    break;
	}
    case 14:			/*  DEMODE   */
	{
	    if (demode == SEND_DE)
		demode = 0;
	    else
		demode = SEND_DE;
	    mvprintw(13, 29, "DE-mode is %d", demode);
	    refreshp();
	    sleep(1);

	    break;
	}
    case 15:			/*  CONTEST   */
	{
	    if (contest == CONTEST)
		contest = 0;
	    else {
		contest = CONTEST;
		searchflg = SEARCHWINDOW;
	    }
	    mvprintw(13, 29, "CONTEST-mode is %d", contest);
	    refreshp();
	    sleep(1);

	    break;
	}
    case 16:			/*  FILTER   */
	{
	    announcefilter++;
	    if (announcefilter > 3)
		announcefilter = 0;
	    mvprintw(13, 29, "FILTER-mode is %d", announcefilter);
	    refreshp();
	    sleep(1);

	    break;
	}
    case 17:			/*  SCORE   */
	{
	    if (showscore_flag == 0)
		showscore_flag = 1;
	    else {
		showscore_flag = 0;

	    }
	    mvprintw(13, 29, "Show score-mode is %d", showscore_flag);
	    refreshp();
	    sleep(1);

	    break;
	}
    case 18:			/*  WRITE CABRILLO FILE   */
	{
	    int old_cluster = cluster;
	    cluster = NOCLUSTER;

	    write_cabrillo();

	    cluster = old_cluster;


	    break;
	}
    case 19:			/* EXIT */
	{
	    writeparas();
	    clear();
	    cleanup_telnet();
	    endwin();
	    puts("\n\nThanks for using TLF.. 73\n");
	    exit(0);
	    break;
	}
    case 20:			/*  TXFILE   */
	{
	    break;
	}
    case 21:			/*  ZONES   */
	{
	    if (zonedisplay == 0)
		zonedisplay = 1;
	    else {
		zonedisplay = 0;

	    }

	    break;
	}
    case 22:			/* COUNTRIES */
	{
	    show_mults();
	    refreshp();
	    sleep(1);

	    break;
	}
    case 23:			/*  MODE   */
	{
	    if (trxmode == CWMODE)
		trxmode = SSBMODE;
	    else if (trxmode == SSBMODE)
		trxmode = DIGIMODE;
	    else
		trxmode = CWMODE;

	    if (trxmode == CWMODE) {
		mvprintw(13, 29, "TRXMODE = CW");
	    } else if (trxmode == SSBMODE)
		mvprintw(13, 29, "TRXMODE = SSB");
	    else
		mvprintw(13, 29, "TRXMODE = DIG");
	    refreshp();
	    sleep(1);

	    break;
	}
    case 24:			/* SET PARAMETERS */
    case 29:			/* CFG PARAMETERS */
	{
	    clear();
	    if (editor == EDITOR_JOE) {
		strcpy(cmdstring, "joe ");
	    } else if (editor == EDITOR_VI) {
		strcpy(cmdstring, "vi ");
	    } else if (editor == EDITOR_MC) {
		strcpy(cmdstring, "mcedit ");
	    } else {
		strcpy(cmdstring, "e3 ");
	    }

	    strcat(cmdstring, config_file);
	    rc = system(cmdstring);

	    read_logcfg();
	    read_rules();	/* also reread rules file */
	    writeparas();
	    mvprintw(24, 0, "Logcfg.dat loaded, parameters written..");
	    refreshp();
	    clear_display();
	    break;
	}
    case 25:			/*  MULTI   */
	{
	    multiplierinfo();

	    break;
	}
    case 26:			/* PROPAGATION */
	{
	    muf();
	    clear_display();
	    break;
	}
    case 27:			/*  RITCLEAR   */
	{
	    if (rit == RITCLEAR)
		rit = 0;
	    else {
		rit = RITCLEAR;

	    }
	    if (rit == RITCLEAR) {
		mvprintw(13, 29, "RIT clear on");
	    } else {
		mvprintw(13, 29, "RIT clear off");
	    }
	    refreshp();
	    sleep(1);

	    break;
	}
    case 28:			/*  trx ctl   */
	{
	    if (trx_control == 1)
		trx_control = 0;
	    else {
		trx_control = 1;

	    }
	    if (trx_control == 1) {
		mvprintw(13, 29, "TRX control on");
	    } else {
		mvprintw(13, 29, "TRX control off");
	    }
	    refreshp();
	    sleep(1);

	    break;
	}
    case 30:			/* CW  */
    case 49:
	{
	    if (keyerport == MFJ1278_KEYER) {
		strcpy(buffer, "MODE CW,30");
		buffer[7] = '\015';
		buffer[8] = 'K';
		buffer[9] = '\015';
		buffer[10] = '\0';
		sendbuf();
	    }
	    trxmode = CWMODE;

	    if (trx_control == 1)
		outfreq = SETCWMODE;
	    break;
	}
    case 31:			/* SSBMODE  */
	{
	    trxmode = SSBMODE;
	    outfreq = SETSSBMODE;
	    break;
	}
    case 32:			/* DIGIMODE  */
	{
	    trxmode = DIGIMODE;
	    break;
	}
    case 33:			/* PACKET  */
	{
	    if ((nopacket == 0) && (packetinterface > 0))
		packet();
	    break;
	}
    case 34:			/* SIMULATOR  */
	{
	    if (simulator == 0) {
		simulator = 1;
		if (ctcomp == 1) {
		    mvprintw(13, 19,
			     "The simulator only works in TRmode. Switching to TRmode");
		    ctcomp = 0;
		} else
		    mvprintw(13, 29, "Simulator on");

		refreshp();

		if (keyerport == NET_KEYER) {

		    if (netkeyer(K_WORDMODE, NULL) < 0) {
			mvprintw(24, 0,
				 "keyer not active; switching to SSB");
			trxmode = SSBMODE;
			clear_display();
		    }
		}
	    } else {
		simulator = 0;
		mvprintw(13, 29, "Simulator off");
		refreshp();

		if (keyerport == NET_KEYER) {

		    if (netkeyer(K_RESET, NULL) < 0) {
			mvprintw(24, 0,
				 "keyer not active; switching to SSB");
			trxmode = SSBMODE;
			clear_display();
		    }
		}

	    }
	    break;
	}
    case 35:			/* INFO  */
	{
	    int currentterm = miniterm;
	    miniterm = 0;
	    networkinfo();
	    miniterm = currentterm;

	    if (currentmode == DIGIMODE)
		trxmode = DIGIMODE;
	    break;
	}
    case 36:			/* CLOFF  */
	{
	    cluster = FREQWINDOW;
	    break;
	}

    case 37:			/* RECONNECT  */
	{
	    if ((nopacket == 0) && (packetinterface > 0)) {
		cleanup_telnet();
		init_packet();
		packet();
	    }
	    break;
	}

    case 38:			/* EXIT=QUIT */
	{
	    writeparas();
	    cleanup_telnet();
	    endwin();
	    puts("\n\nThanks for using TLF.. 73\n");
	    exit(0);
	    break;
	}
    case 39:			/* CQDELAY */
	{
	    mvprintw(12, 29, "CQD: pgup/dwn", cqdelay);
	    refreshp();

	    x = 1;
	    while (x) {
		x = onechar();

		switch (x) {
		case 156:{
			if (cqdelay <= 60) {
			    cqdelay++;
			    attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
			    mvprintw(0, 19, "  ");
			    mvprintw(0, 19, "%i", cqdelay);
			    break;

			}
		    }
		case 157:{
			if (cqdelay >= 1) {
			    cqdelay--;
			    attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);

			    mvprintw(0, 19, "  ");
			    mvprintw(0, 19, "%i", cqdelay);
			    break;

			}
		default:
			x = 0;
		    }

		}
	    }

	    if (use_rxvt == 0)
		attron(COLOR_PAIR(NORMCOLOR) | A_BOLD);
	    else
		attron(COLOR_PAIR(NORMCOLOR));

	    mvprintw(12, 29 + strlen(hiscall), "");
	    break;

	}
    case 40:			/* ADIF */
	{
	    write_adif();

	    break;
	}
    case 41:			/* SYNC */
	{
	    if (strlen(synclogfile) > 0)
		synclog(synclogfile);
	    scroll_log();
	    /** \todo register return value */
	    readcalls();
	    clear_display();
	    break;
	}
    case 42:			/* RESCORE */
	{
	    /** \todo register return value */
	    readcalls();
	    clear_display();
	    break;
	}
    case 43:			/* SCVOLUME - set soundcard volume */
	{
	    volumebuffer = atoi(sc_volume);
	    mvprintw(12, 29, "Vol: pgup/dwn");
	    refreshp();
	    usleep(500000);
	    mvprintw(12, 29, "Vol:         ");
	    mvprintw(12, 29, "Vol: %d", volumebuffer);

	    x = 1;
	    while (x) {
		x = onechar();

		switch (x) {
		case 156:{
			if (volumebuffer < 95)
			    volumebuffer += 5;

			break;
		    }
		case 157:{
			if (volumebuffer >= 5)
			    volumebuffer -= 5;

			break;
		    }
		default:
			x = 0;

		}

		attron(COLOR_PAIR(COLOR_GREEN) | A_STANDOUT);
		mvprintw(12, 34, "  ");
		mvprintw(12, 34, "%d", volumebuffer);

		if (volumebuffer >= 0 && volumebuffer <= 99)
		    sprintf(sc_volume, "%d", volumebuffer);

		netkeyer(K_STVOLUME, sc_volume);
	    }

	    clear_display();
	    break;
	}
    case 44:			/* SCAN */
	{
	    int currentterm = miniterm;
	    miniterm = 0;
	    testaudio();
	    clear_display();
	    miniterm = currentterm;
	    break;
	}
    case 45:			/* DEBUG */
	{
	    debug_tty();
	    clear_display();
	    break;
	}
    case 46:			/* MINITERM ON/OFF */
	{
	    if (miniterm == 1)
		miniterm = 0;
	    else
		miniterm = 1;
	    break;
	}
    case 47:			/* RTTY Initialize mode (MFJ1278B controller) */
	{
	    strcpy(buffer, "MODE VB");
	    buffer[7] = '\015';
	    buffer[8] = 'K';
	    buffer[9] = '\015';
	    buffer[10] = '\0';
	    sendbuf();
	    trxmode = DIGIMODE;

	    break;
	}
    case 48:			/* SOUND */
	{
	    clear_display();
	    record();
	    clear_display();
	    break;
	}
    case 50:			/* CHARS */
	{
	    mvprintw(13, 29, "Autosend: (0 (off), 2..5 chars) ?");
	    refreshp();
	    x = 1;

	    /* wait for correct input or ESC */
	    while ((x != 0) && ((x < 2) || (x > 5)) ) {
		x = onechar();
		if (x == 27)
		    break;
		x = x - '0';
	    }

	    /* remember new setting */
	    if (x != 27)
		cwstart = x;

	    if (cwstart)
		mvprintw(13,29, "Autosend now: %1d                 ",
			cwstart);
	    else
		mvprintw(13,29, "Autosend now: OFF                ");

	    refreshp();
	    break;

	}
    default:
	{
	    nopar = 1;
	}
    }

    if (nopar != 1) {
	mvprintw(12, 29, "OK !        ");
	writeparas();
    } else {
	if ((nopacket ==0) && (packetinterface > 0))
	    packet();
    }

    refreshp();

    if (use_rxvt == 0)
	attron(COLOR_PAIR(NORMCOLOR) | A_BOLD);
    else
	attron(COLOR_PAIR(NORMCOLOR));

    mvprintw(12, 29, "            ");
    mvprintw(12, 29, "");
    refreshp();
    hiscall[0] = '\0';

    return (0);
}
Exemple #9
0
/*
 * This is the worker bee which creates the manifest based upon the command
 * line options supplied by the user.
 *
 * NOTE: create_manifest() eventually outputs data to a pipe, which is read in
 * by the child process.  The child process is running output_manifest(), which
 * is responsible for generating sorted output.
 */
static int
create_manifest_rule(char *reloc_root, FILE *rule_fp)
{
	struct rule	*root;
	int		ret_status = EXIT;
	uint_t		flags;

	if (compute_chksum)
		flags = ATTR_CONTENTS;
	else
		flags = 0;
	ret_status = read_rules(rule_fp, reloc_root, flags, 1);

	/* Loop through every single subtree */
	for (root = get_first_subtree(); root != NULL;
	    root = get_next_subtree(root)) {

		/*
		 * This subtree has already been traversed by a
		 * previous stanza, i.e. this rule is a subset of a
		 * previous rule.
		 *
		 * Subtree has already been handled so move on!
		 */
		if (root->traversed)
			continue;

		/*
		 * Check to see if this subtree should have contents
		 * checking turned on or off.
		 *
		 * NOTE: The 'compute_chksum' and 'parent_vfs'
		 * are a necessary hack: the variables are used in
		 * walker(), both directly and indirectly.  Since
		 * the parameters to walker() are defined by nftw(),
		 * the globals are really a backdoor mechanism.
		 */
		ret_status = statvfs(root->subtree, &parent_vfs);
		if (ret_status < 0) {
			perror(root->subtree);
			continue;
		}

		/*
		 * Walk the subtree and invoke the callback function
		 * walker()
		 */
		subtree_root = root;
		(void) nftw64(root->subtree, &walker, 20, FTW_PHYS);
		root->traversed = B_TRUE;

		/*
		 * Ugly but necessary:
		 *
		 * walker() must return 0, or the tree walk will stop,
		 * so warning flags must be set through a global.
		 */
		if (eval_err == WARNING_EXIT)
			ret_status = WARNING_EXIT;

	}
	return (ret_status);
}
Exemple #10
0
int main(int argc, char *argv[]) {
    int c;
    const char **arguments;
    int argumentcount;
    int status;

    if( argc <= 1 )
        usage(TESTTOOL_ERROR_EXIT);

    opterr = 0;
    while( (c = getopt_long(argc, argv, "+hvseariCD:o:d::", longopts, NULL)) != -1 ) {
        if( c == 'd' ) {
            use_debugger = true;
            if( optarg != NULL ) {
                debugger = strdup(optarg);
                if( debugger == NULL ) {
                    fputs("Out of memory!\n", stderr);
                    exit(TESTTOOL_ERROR_EXIT);
                }
            } else
                debugger = NULL;
            break;
        }
        switch( c ) {
        case '?':
            fprintf(stderr,
                    "%s: Unexpected option '%c'!\n",
                    program_invocation_short_name, optopt);
            exit(TESTTOOL_ERROR_EXIT);
        case 'h':
            usage(EXIT_SUCCESS);
        case 'v':
            printf("%s version %s\n", PACKAGE, VERSION);
            exit(EXIT_SUCCESS);
        case 's':
            silent = true;
            break;
        case 'e':
            echo = true;
            break;
        case 'a':
            annotate = true;
            break;
        case 'r':
            readrules = true;
            break;
        case 'o':
            free(outfile);
            outfile = strdup(optarg);
            if( outfile == NULL ) {
                fputs("Out of memory!\n", stderr);
                exit(TESTTOOL_ERROR_EXIT);
            }
            break;
        case 'C':
            outexpect.ignoreunknown = false;
            break;
        case 'i':
            ignoreunexpected = true;
            break;
        case 'D':
            if( optarg[0] < 'a' || optarg[0] > 'z' ) {
                fprintf(stderr,
                        "%s: No variable-name found in '%s'!\n",
                        program_invocation_short_name, optarg);
                exit(TESTTOOL_ERROR_EXIT);
            }
            if( optarg[1] != '=' ) {
                fprintf(stderr,
                        "%s: Missing '=' in '%s'!\n",
                        program_invocation_short_name, optarg);
                exit(TESTTOOL_ERROR_EXIT);
            }
            variables[optarg[0]-'a'+1] = atoi(optarg+2);
            break;
        default:
            fprintf(stderr,
                    "%s: Unexpected getopt_long return '%c'!\n",
                    program_invocation_short_name, c);
            exit(TESTTOOL_ERROR_EXIT);
        }
    }

    if( optind >= argc ) {
        fprintf(stderr, "%s: no program to start specified!\n",
                program_invocation_short_name);
        free(debugger);
        free(outfile);
        exit(TESTTOOL_ERROR_EXIT);
    }

    if( readrules ) {
        if( !read_rules() ) {
            free(debugger);
            free(outfile);
            exit(TESTTOOL_ERROR_EXIT);
        }
    }

    if( outfile != NULL ) {
        outfile_fd = open(outfile, O_CREAT|O_TRUNC|O_NOFOLLOW|O_WRONLY, 0666);
        if( outfile_fd < 0 ) {
            fprintf(stderr,"%s: Error opening file %s: %s\n",
                    program_invocation_short_name,
                    outfile, strerror(errno));
            free(debugger);
            free(outfile);
            exit(TESTTOOL_ERROR_EXIT);
        }
    }

    arguments = createarguments(&argumentcount, argv+optind, argc-optind);

    if( echo ) {
        int i;
        for( i = 0; i+1 < argumentcount; i++,putchar(' ') ) {
            putchar('\'');
            assert(arguments[i] != NULL);
            fputs(arguments[i], stdout);
            putchar('\'');
        }
        putchar('\n');
    }

    status = start(arguments);

    if( outfile_fd >= 0 )
        close(outfile_fd);

    free(arguments);
    free(debugger);
    free(outfile);
    return status;
}
Exemple #11
0
/** load all databases
 *
 * \return EXIT_FAILURE if not successful */
int databases_load() {
    int status;

    showmsg("reading country data");
    readctydata();		/* read ctydb.dat */

    showmsg("reading configuration data");
    status = read_logcfg(); 	/* read the configuration file */
    status |= read_rules();	/* read the additional contest rules
				   in "rules/contestname" */
    if (status != PARSE_OK) {
	showmsg("Problems in logcfg.dat or rule file detected! Continue Y/(N)?");
	if (toupper(key_get()) != 'Y') {
	    showmsg("73...");
	    return EXIT_FAILURE;
	}
    }

    if (*call == '\0') {
	showmsg
	("WARNING: No callsign defined in logcfg.dat! exiting...\n\n\n");
	return EXIT_FAILURE;
    }


    if (multlist == 1) {
	showmsg("reading multiplier data      ");
	if (strlen(multsfile) == 0) {
	    mvprintw(9, 0, "No multiplier file specified, exiting.. !!\n");
	    refreshp();
	    sleep(5);
	    exit(1);
	}
    }
    init_and_load_multipliers();

    showmsg("reading callmaster data");
    load_callmaster();

    if (*exchange_list != '\0') {
	showmsg("reading initial exchange file");
	main_ie_list = make_ie_list(exchange_list);

	if (main_ie_list == NULL) {
	    showmsg("Problems in initial exchange file detected! Continue Y/(N)?");
	    if (toupper(key_get()) != 'Y') {
		showmsg("73...");
		return EXIT_FAILURE;
	    }
	}
    }

    /* make sure logfile is there and has the right format */
    if (checklogfile_new(logfile) != 0) {
	showmsg("Can not access logfile. Giving up");
	return EXIT_FAILURE;
    }

    if (qtcdirection > 0) {
	if (checkqtclogfile() != 0) {
	    showmsg("QTC's giving up");
	    return EXIT_FAILURE;
	}
	readqtccalls();
    }
    // unset QTC_RECV_LAZY if mode is DIGIMODE
    if (trxmode == DIGIMODE) {
	qtc_recv_lazy = 0;
    }
    return 0;
}
Exemple #12
0
int main(int argc, char *argv[])
{
    char *title;
    FILE *srcfp;
    struct GModule *module;
    struct
    {
	struct Option *input, *output, *title, *rules;
	struct Flag *a, *d;
    } parm;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("recode categories"));
    G_add_keyword(_("reclassification"));
    module->description = _("Recodes categorical raster maps.");

    parm.input = G_define_standard_option(G_OPT_R_INPUT);
    parm.input->description = _("Name of raster map to be recoded");
    
    parm.output = G_define_standard_option(G_OPT_R_OUTPUT);

    parm.rules = G_define_standard_option(G_OPT_F_INPUT);
    parm.rules->key = "rules";
    parm.rules->label = _("File containing recode rules");
    parm.rules->description = _("'-' for standard input");
    
    parm.title = G_define_option();
    parm.title->key = "title";
    parm.title->required = NO;
    parm.title->type = TYPE_STRING;
    parm.title->description = _("Title for output raster map");
    
    parm.a = G_define_flag();
    parm.a->key = 'a';
    parm.a->description = _("Align the current region to the input raster map");

    parm.d = G_define_flag();
    parm.d->key = 'd';
    parm.d->description = _("Force output to 'double' raster map type (DCELL)");
    
    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    name = parm.input->answer;
    result = parm.output->answer;
    title = parm.title->answer;
    align_wind = parm.a->answer;
    make_dcell = parm.d->answer;

    srcfp = stdin;
    if (strcmp(parm.rules->answer, "-") != 0) {
	srcfp = fopen(parm.rules->answer, "r");
	if (!srcfp)
	    G_fatal_error(_("Unable to open file <%s>"),
			  parm.rules->answer);
    }

    if (!read_rules(srcfp)) {
	if (isatty(fileno(srcfp)))
	    G_fatal_error(_("No rules specified. Raster map <%s> not created."),
			  result);
	else
	    G_fatal_error(_("No rules specified"));
    }

    no_mask = 0;

    do_recode();

    if(title)
	Rast_put_cell_title(result, title);

    exit(EXIT_SUCCESS);
}
Exemple #13
0
Fichier : main.c Projet : patlc/tlf
int main(int argc, char *argv[])
{
    int j;
    pthread_t thrd1, thrd2;
    int ret;
    int retval;
    char keyerbuff[3];
    char tlfversion[80] = "";
    int status;

    while ((argc > 1) && (argv[1][0] == '-')) {
	switch (argv[1][1]) {
	    /* verbose option */
	case 'f':
	    if (strlen(argv[1] + 2) > 0) {
		if ((*(argv[1] + 2) == '~') && (*(argv[1] + 3) == '/')) {
		    /* tilde expansion */
		    config_file = g_strconcat( g_get_home_dir(),
			    argv[1] + 3, NULL);
		}
	    	else {
		    config_file = g_strdup(argv[1] + 2);
		}
	    }
	    break;
	case 's':
	    if (strlen(argv[1] + 2) > 0)
		strcpy(synclogfile, argv[1] + 2);
	    break;
	case 'd':		// debug rigctl
	    debugflag = 1;
	    break;
	case 'v':		// verbose startup
	    verbose = 1;
	    break;
	case 'V':		// output version
	    printf("Version: tlf-%s\n", VERSION);
	    exit(0);
	    break;
	case 'n':		// output version
	    nopacket = 1;
	    break;
	default:
	    printf("Use: tlf [-v] Verbose\n");
	    printf("         [-V] Version\n");
	    printf("         [-f] Configuration file\n");
	    printf("         [-d] Debug mode\n");
	    printf("         [-h] This message\n");
	    printf("         [-n] Start without cluster hookup\n");
	    exit(0);
	    break;
	}
	--argc;
	++argv;
    }

    buffer[0] = '\0';
    buffer[79] = '\0';
    bufloc = 0;

    strcat(logline0, backgrnd_str);
    strcat(logline1, backgrnd_str);
    strcat(logline2, backgrnd_str);
    strcat(logline3, backgrnd_str);
    strcat(logline4, backgrnd_str);

    strcat(terminal1, backgrnd_str);
    strcat(terminal2, backgrnd_str);
    strcat(terminal3, backgrnd_str);
    strcat(terminal4, backgrnd_str);

    termbuf[0] = '\0';
    hiscall[0] = '\0';

/* getting users terminal string and (if RXVT) setting rxvt colours on it */
/* LZ3NY hack :) */
    if (strcasecmp(getenv("TERM"), "rxvt") == 0) {
	use_rxvt = 1;
	printf("terminal is:%s", getenv("TERM"));
    } else if (strcasecmp(getenv("TERM"), "xterm") == 0) {
	use_xterm = 1;
	use_rxvt = 1;
    } else
	putenv("TERM=rxvt");	/*or going to native console linux driver */

    if ((mainscreen = newterm(NULL, stdout, stdin)) == NULL) {	/* activate ncurses terminal control */
	perror("initscr");
	printf
	    ("\n Sorry, wrong terminal type !!!!! \nTry a  linux text terminal or set TERM=linux !!!");
	sleep(5);

	exit(EXIT_FAILURE);
    }
//keypad(stdscr,TRUE);

    InitSearchPanel();	/* at least one panel has to be defined
				   for refreshp() to work */

    getmaxyx(stdscr, ymax, xmax);
    if ((ymax < 25) || (xmax < 80)) {
	char c;

	showmsg( "!! TLF needs at least 25 lines and 80 columns !!");
	showmsg( "   Continue anyway? Y/(N)" );
	c = toupper( getch() );
	if (c != 'Y') {
	    showmsg( "73 es cuagn" );
	    sleep(1);
	    endwin();
	    exit(1);
	}
	showmsg("");
    }

    noecho();
    crmode();

    strcpy(sp_return, message[12]);
    strcpy(cq_return, message[13]);

    refreshp();

    if (has_colors()) {
	if (start_color() == ERR) {
	    perror("start_color");
	    endwin();
	    printf
		("\n Sorry, wrong terminal type !!!!! \n\nTry a linux text terminal or set TERM=linux !!!");
	    sleep(5);
	    exit(EXIT_FAILURE);
	}

	sprintf(tlfversion,
		"        Welcome to tlf-%s by PA0R!!" , VERSION);
	showmsg(tlfversion);
	showmsg("");

	showmsg("reading country data");
	readctydata();		/* read ctydb.dat */

	showmsg("reading configuration data");

	status = read_logcfg(); /* read the configuration file */
	status |= read_rules();	/* read the additional contest rules in "rules/contestname"  LZ3NY */

	if (status != PARSE_OK) {
	    showmsg( "Problems in logcfg.dat or rule file detected! Continue Y/(N)?");
	    if (toupper( getchar() ) != 'Y') {
		endwin();
		exit(1);
	    }
	}

	/* make sure logfile is there and has the right format */
	if (checklogfile_new(logfile) != 0) {
	    showmsg( "Giving up" );
	    sleep(2);
	    endwin();
	    exit(1);
	}

//              if (strlen(synclogfile) > 0)
//                      synclog(synclogfile);

	if (*call == '\0') {
	    showmsg
		("WARNING: No callsign defined in logcfg.dat! exiting...\n\n\n");
	    exit(1);
	}

	if (use_rxvt == 1) {	// use rxvt colours
	    init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_RED);
	    if (use_xterm == 1) {
		init_pair(C_HEADER, COLOR_GREEN, COLOR_BLUE);
		init_pair(COLOR_RED, COLOR_WHITE, 8);
		init_pair(C_WINDOW, COLOR_CYAN, COLOR_MAGENTA);
		init_pair(C_DUPE, COLOR_WHITE, COLOR_MAGENTA);
		init_pair(C_INPUT, COLOR_BLUE, COLOR_WHITE);
	    } else {
		init_pair(C_HEADER, COLOR_GREEN, COLOR_YELLOW);
		init_pair(COLOR_RED, COLOR_WHITE, COLOR_RED);
		init_pair(C_WINDOW, COLOR_CYAN, COLOR_RED);
		init_pair(C_DUPE, COLOR_RED, COLOR_MAGENTA);
		init_pair(C_INPUT, COLOR_BLUE, COLOR_YELLOW);
	    }
	    init_pair(C_LOG, COLOR_WHITE, COLOR_BLACK);
	    init_pair(C_BORDER, COLOR_CYAN, COLOR_YELLOW);
	} else {
	    // use linux console colours
	    init_pair(COLOR_BLACK, tlfcolors[0][0], tlfcolors[0][1]); // b/w
	    init_pair(C_HEADER, tlfcolors[1][0], tlfcolors[1][1]);    // Gn/Ye
	    init_pair(COLOR_RED, tlfcolors[2][0], tlfcolors[2][1]);   // W/R
	    init_pair(C_WINDOW, tlfcolors[3][0], tlfcolors[3][1]);    // Cy/W
	    init_pair(C_LOG, tlfcolors[4][0], tlfcolors[4][1]);       // W/B
	    init_pair(C_DUPE, tlfcolors[5][0], tlfcolors[5][1]);      // W/Mag
	    init_pair(C_INPUT, tlfcolors[6][0], tlfcolors[6][1]);     // Bl/Y
	    init_pair(C_BORDER, tlfcolors[7][0], tlfcolors[7][1]);    // W/B
	}

	mults_possible = g_ptr_array_new();

	if (multlist == 1) {
	    showmsg("reading multiplier data      ");
	    load_multipliers();

	}

	attron(COLOR_PAIR(COLOR_BLACK));
	showmsg("reading callmaster data");

	nr_callmastercalls = load_callmaster();

	if (*exchange_list != '\0') {
	    // read initial exchange file
	    main_ie_list = make_ie_list(exchange_list);
	    if (main_ie_list == NULL) {
		showmsg( "Problems in initial exchange file detected! Continue Y/(N)?");
		if (toupper( getchar() ) != 'Y') {
		    endwin();
		    exit(1);
		}
		else {
		    showmsg( "Initial exchange data not loaded! Continuing ...");
		    sleep(2);
		}
	    }
	}

#ifdef HAVE_LIBHAMLIB		// Code for hamlib interface

	showmsg("HAMLIB defined");

	if (trx_control != 0) {

	    shownr("Rignumber is", (int) myrig_model);
	    shownr("Rig speed is", serial_rate);

	    showmsg("Trying to start rig ctrl");

	    /** \todo fix exclusion of newer hamlib models */
	    if ((int) myrig_model > 1999)
		status = init_native_rig();
	    else
		status = init_tlf_rig();
	}
#else
	if (trx_control != 0) {
//                      trx_control = 0;
	    showmsg("No Hamlib library, using native driver");
	    shownr("Rignumber is", rignumber);
	    shownr("Rig speed is", serial_rate);
	    status = init_native_rig();
	    sleep(1);
	}
#endif				// end code for hamlib interface

	if (status  != 0) {
	    showmsg( "Continue without rig control Y/(N)?");
	    if (toupper( getchar() ) != 'Y') {
		endwin();
		exit(1);
	    }
	    trx_control = 0;
	    showmsg( "Disabling rig control!");
	    sleep(1);
	}


	if (keyerport == NET_KEYER) {
	    showmsg("Keyer is cwdaemon");
	}
	if (keyerport == MFJ1278_KEYER || keyerport == GMFSK) {
	    init_controller();
	}

	if (lan_active == 1) {
	    retval = lanrecv_init();

	    if (retval < 0)	/* set up the network */
		shownr("LAN receive  init failed", retval);
	    else
		showmsg("LAN receive  initialized");

	    if (lan_send_init() < 0)
		showmsg("LAN send init failed");
	    else
		showmsg("LAN send initialized");
	}

	checkparameters();	/* check .paras file */

	clear();
	mvprintw(0, 0, "        Welcome to tlf-%s by PA0R!!\n\n" , VERSION);
	refreshp();
	getmessages();		/* read .paras file */

	if (nopacket == 1)
	    packetinterface = 0;

	set_term(mainscreen);

	refreshp();

	if ((nopacket == 0) && (packetinterface != 0)) {

	    if (init_packet() == 0)
		packet();
	    else
		cleanup_telnet();

	}

	if (keyerport == NET_KEYER) {
	    if (netkeyer_init() < 0) {
		mvprintw(24, 0, "Cannot open NET keyer daemon ");
		refreshp();
		sleep(1);

	    } else {
		netkeyer(K_RESET, "0");

		sprintf(weightbuf, "%d", weight);

		write_tone();

		snprintf(keyerbuff, 3, "%2d", GetCWSpeed());
		netkeyer(K_SPEED, keyerbuff);		// set speed

		netkeyer(K_WEIGHT, weightbuf);		// set weight

		if (*keyer_device != '\0')
		    netkeyer(K_DEVICE, keyer_device);	// set device

		sprintf(keyerbuff, "%d", txdelay);
		netkeyer(K_TOD, keyerbuff);		// set TOD

		if (sc_sidetone != 0)			// set soundcard output
		    netkeyer(K_SIDETONE, "");

		if (*sc_volume != '\0')			// set soundcard volume
			netkeyer(K_STVOLUME, sc_volume);
	    }

	    if (keyerport != NET_KEYER)
		write_tone();
	}

	getwwv();		/* get the latest wwv info from packet */

	scroll_log();		/* read the last 5  log lines and set the qso number */

	nr_qsos = readcalls();	/* read the logfile for score and dupe */

	clear_display();	/* tidy up the display */

	qrb();

	attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

	for (j = 13; j <= 23; j++) {	/* wipe lower window */
	    mvprintw(j, 0, backgrnd_str);
	}

	bm_init();			/* initialize bandmap */

	/* Create the first thread */
	ret = pthread_create(&thrd1, NULL, (void *) logit, NULL);
	if (ret) {
	    perror("pthread_create: logit");
	    endwin();
	    exit(EXIT_FAILURE);
	}

	/* Create the second thread */
	ret =
	    pthread_create(&thrd2, NULL, (void *) background_process,
			   NULL);
	if (ret) {
	    perror("pthread_create: backgound_process");
	    endwin();
	    exit(EXIT_FAILURE);
	}

	pthread_join(thrd2, NULL);
	pthread_join(thrd1, NULL);
	endwin();
	exit(EXIT_SUCCESS);

    } else {
	printf("Terminal does not support color\n");
	printf("\nTry TERM=linux  or use a text console !!\n");
	refreshp();
	sleep(2);
    }
    cleanup_telnet();

    if (trxmode == CWMODE && keyerport == NET_KEYER)
	netkeyer_close();
    else
	close(cfd);		/* close keyer */

    endwin();

    return (0);
}
Exemple #14
0
/*
 * routine:
 *	main
 *
 * purpose:
 *	argument processing and primary dispatch
 *
 * returns:
 *	error codes per filesync.1 (ERR_* in filesync.h)
 *
 * notes:
 *	read filesync.1 in order to understand the argument processing
 *
 *	most of the command line options just set some opt_ global
 *	variable that is later looked at by the code that actually
 *	implements the features.  Only file names are really processed
 *	in this routine.
 */
int
main(int argc, char **argv)
{	int i;
	int c;
	errmask_t errs = ERR_OK;
	int do_prune = 0;
	char *srcname = 0;
	char *dstname = 0;
	struct base *bp;

	/* keep the error messages simple	*/
	argv[0] = "filesync";

	/* gather together all of the options	*/
	while ((c = getopt(argc, argv, "AaehmnqvyD:E:r:s:d:f:o:")) != EOF)
		switch (c) {
			case 'a':	/* always scan for acls	*/
				opt_acls = TRUE;
				break;
			case 'e':	/* everything agrees	*/
				opt_everything = TRUE;
				break;
			case 'h':	/* halt on error	*/
				opt_halt = TRUE;
				break;
			case 'm':	/* preserve modtimes	*/
				opt_mtime = TRUE;
				break;
			case 'n':	/* notouch		*/
				opt_notouch = TRUE;
				break;
			case 'q':	/* quiet		*/
				opt_quiet = TRUE;
				break;
			case 'v':	/* verbose		*/
				opt_verbose = TRUE;
				break;
			case 'y':	/* yes			*/
				opt_yes = TRUE;
				break;
			case 'D':	/* debug options	*/
				if (!isdigit(optarg[0])) {
					dbg_usage();
					exit(ERR_INVAL);
				}
				opt_debug |= strtol(optarg, (char **)NULL, 0);
				break;

			case 'E':	/* error simulation	*/
				if (dbg_set_error(optarg)) {
					err_usage();
					exit(ERR_INVAL);
				}
				opt_errors = TRUE;
				break;

			case 'f':	/* force conflict resolution	*/
				switch (optarg[0]) {
					case 's':
						opt_force = OPT_SRC;
						break;
					case 'd':
						opt_force = OPT_DST;
						break;
					case 'o':
						opt_force = OPT_OLD;
						break;
					case 'n':
						opt_force = OPT_NEW;
						break;
					default:
						fprintf(stderr,
							gettext(ERR_badopt),
							c, optarg);
						errs |= ERR_INVAL;
						break;
				}
				break;

			case 'o':	/* one way propagation		*/
				switch (optarg[0]) {
					case 's':
						opt_oneway = OPT_SRC;
						break;
					case 'd':
						opt_oneway = OPT_DST;
						break;
					default:
						fprintf(stderr,
							gettext(ERR_badopt),
							c, optarg);
						errs |= ERR_INVAL;
						break;
				}
				break;

			case 'r':	/* restricted reconciliation	*/
				if (num_restrs < MAX_RLIST)
					rlist[ num_restrs++ ] = optarg;
				else {
					fprintf(stderr, gettext(ERR_tomany),
						MAX_RLIST);
					errs |= ERR_INVAL;
				}
				break;

			case 's':
				if ((srcname = qualify(optarg)) == 0)
					errs |= ERR_MISSING;
				break;

			case 'd':
				if ((dstname = qualify(optarg)) == 0)
					errs |= ERR_MISSING;
				break;

			default:
			case '?':
				errs |= ERR_INVAL;
				break;
		}

	if (opt_debug & DBG_MISC)
		fprintf(stderr, "MISC: DBG=%s\n", showflags(dbgmap, opt_debug));

	/* if we have file names, we need a source and destination */
	if (optind < argc) {
		if (srcname == 0) {
			fprintf(stderr, gettext(ERR_nosrc));
			errs |= ERR_INVAL;
		}
		if (dstname == 0) {
			fprintf(stderr, gettext(ERR_nodst));
			errs |= ERR_INVAL;
		}
	}

	/* check for simple usage errors	*/
	if (errs & ERR_INVAL) {
		usage();
		exit(errs);
	}

	/* locate our baseline and rules files	*/
	if (c = findfiles())
		exit(c);

	/* figure out file creation defaults	*/
	whoami();

	/* read in our initial baseline		*/
	if (!new_baseline && (c = read_baseline(file_base)))
		errs |= c;

	/* read in the rules file if we need or have rules	*/
	if (optind >= argc && new_rules) {
		fprintf(stderr, ERR_nonames);
		errs |= ERR_INVAL;
	} else if (!new_rules)
		errs |= read_rules(file_rules);

	/* if anything has failed with our setup, go no further	*/
	if (errs) {
		cleanup(errs);
		exit(errs);
	}

	/*
	 * figure out whether or not we are willing to do a one-sided
	 * analysis (where we don't even look at the other side.  This
	 * is an "I'm just curious what has changed" query, and we are
	 * only willing to do it if:
	 *	we aren't actually going to do anything
	 *	we have a baseline we can compare against
	 * otherwise, we are going to insist on being able to access
	 * both the source and destination.
	 */
	if (opt_notouch && !new_baseline)
		opt_onesided = opt_oneway;

	/*
	 * there are two interested usage scenarios:
	 *	file names specified
	 *		create new rules for the specified files
	 *		evaulate and reconcile only the specified files
	 *	no file names specified
	 *		use already existing rules
	 *		consider restricting them to specified subdirs/files
	 */
	if (optind < argc) {
		/* figure out what base pair we're working on	*/
		bp = add_base(srcname, dstname);

		/* perverse default rules to avoid trouble	*/
		if (new_rules) {
			errs |= add_ignore(0, SUFX_RULES);
			errs |= add_ignore(0, SUFX_BASE);
		}

		/* create include rules for each file/dir arg	*/
		while (optind < argc)
			errs |= add_include(bp, argv[ optind++ ]);

		/*
		 * evaluate the specified base on each side,
		 * being careful to limit evaulation to new rules
		 */
		errs |= evaluate(bp, OPT_SRC, TRUE);
		errs |= evaluate(bp, OPT_DST, TRUE);
	} else {
		/* note any possible evaluation restrictions	*/
		for (i = 0; i < num_restrs; i++)
			errs |= add_restr(rlist[i]);

		/*
		 * we can only prune the baseline file if we have done
		 * a complete (unrestricted) analysis.
		 */
		if (i == 0)
			do_prune = 1;

		/* evaulate each base on each side		*/
		for (bp = bases; bp; bp = bp->b_next) {
			errs |= evaluate(bp, OPT_SRC, FALSE);
			errs |= evaluate(bp, OPT_DST, FALSE);
		}
	}

	/* if anything serious happened, skip reconciliation	*/
	if (errs & ERR_FATAL) {
		cleanup(errs);
		exit(errs);
	}

	/* analyze and deal with the differenecs		*/
	errs |= analyze();

	/* see if there is any dead-wood in the baseline	*/
	if (do_prune) {
		c = prune();

		if (c > 0 && opt_verbose)
			fprintf(stdout, V_prunes, c);
	}

	/* print out a final summary				*/
	summary();

	/* update the rules and baseline files (if needed)	*/
	(void) umask(my_umask);
	errs |= write_baseline(file_base);
	errs |= write_rules(file_rules);

	if (opt_debug & DBG_MISC)
		fprintf(stderr, "MISC: EXIT=%s\n", showflags(errmap, errs));

	/* just returning ERR_RESOLVABLE upsets some people	*/
	if (errs == ERR_RESOLVABLE && !opt_notouch)
		errs = 0;

	/* all done	*/
	cleanup(0);
	return (errs);
}
Exemple #15
0
int
read_rules(srv_t * srv, char *file, dbcmd_t * dbc)
{
	FILE           *fp;
	char           *sp, *tmp;
	int             n = 0, f = 0, r;
	octet_t         *op;
	octarr_t       *oa = 0;
	ruleset_t      *rs = 0, *trs, *prs;
	spocp_result_t  rc = SPOCP_SUCCESS;
	spocp_charbuf_t	*buf;
	spocp_chunk_t	*chunk = 0, *ck;
	spocp_chunkwrap_t   *cw;
	spocp_ruledef_t	rdef;
	struct stat	statbuf;

	if ((fp = fopen(file, "r")) == 0) {
		LOG(SPOCP_EMERG) traceLog(LOG_ERR,"couldn't open rule file \"%s\"",
					  file);
		op = oct_new( 256, NULL);
		sp = getcwd(op->val, op->size);
		traceLog(LOG_ERR,"I'm in \"%s\"", sp);
		oct_free(op);
		return -1;
	}

	stat( file, &statbuf);

	srv->mtime = statbuf.st_mtime;
 
	/*
	 * The default ruleset should already be set 
	 */

	if (srv->root == 0) {
		srv->root = rs = ruleset_new(0);
	} else
		rs = srv->root;

	if (rs->db == 0)
		rs->db = db_new();

	buf = charbuf_new( fp, BUFSIZ );

	if (get_more(buf) == 0) return 0;

	/*
	 * have to escape CR since fgets stops reading when it hits a newline
	 * NUL also has to be escaped since I have problem otherwise finding
	 * the length of the 'string'. '\' hex hex is probably going to be the 
	 * choice 
	 */
	while (rc == SPOCP_SUCCESS ) {
	    cw = get_object( buf, 0 );
	    if (cw->status == 0) {
	        Free(cw);
	        break;
	    }
	    else if (cw->status == -1) {
	        rc = SPOCP_LOCAL_ERROR;
            Free(cw);
            break;
        }
        else {
            chunk = cw->chunk;
            Free(cw);
        }
	    
		if (oct2strcmp(chunk->val, ";include ") == 0) {	/* include
								 * file */
			ck = chunk->next;
			tmp = oct2strdup( ck->val, 0 ) ;
			LOG(SPOCP_DEBUG) traceLog(LOG_DEBUG,"include directive \"%s\"",
						  tmp);
			if ((rc = read_rules(srv, tmp, dbc)) < 0) {
				traceLog(LOG_ERR,"Include problem");
			}
		}
		else if (*chunk->val->val == '/' || *chunk->val->val == '(') {
			trs = rs;
			if (*chunk->val->val == '/') {
#ifdef AVLUS
				oct_print(LOG_INFO,"ruleset", chunk->val);
#endif
				if ((trs = ruleset_find( chunk->val, rs)) == NULL) {
					octet_t oct;

					octln( &oct, chunk->val);
					rs = ruleset_create(chunk->val, rs);
					trs = ruleset_find(&oct, rs);
					trs->db = db_new();
				}

				ck = chunk->next;
			}
			else {
				ck = chunk;
			}

			ruledef_return( &rdef, ck ) ;
			if( rdef.rule ) {
				op = chunk2sexp( rdef.rule ) ;
				oa = octarr_add(oa, op) ;
				LOG(SPOCP_DEBUG) {
					traceLog(LOG_DEBUG,"We've got a rule");
				}
			}
			
			if( rdef.bcond) {
				op = chunk2sexp( rdef.bcond ) ;
				oa = octarr_add(oa, op) ;
				LOG(SPOCP_DEBUG) {
					traceLog(LOG_DEBUG,"We've got a boundary condition");
				}
			}