예제 #1
0
static void
read_foodgroup(struct fg_groups *g)
{
    const char *fgn = g->connection->name;
    const ip_subnet *lsn = &g->connection->spd.this.client;
    const struct lsw_conf_options *oco = lsw_init_options(); 
    size_t plen = strlen(oco->policies_dir) + 2 + strlen(fgn) + 1;
    struct file_lex_position flp_space;

    if (plen > fg_path_space)
    {
	pfreeany(fg_path);
	fg_path_space = plen + 10;
	fg_path = alloc_bytes(fg_path_space, "policy group path");
    }
    snprintf(fg_path, fg_path_space, "%s/%s", oco->policies_dir, fgn);
    if (!lexopen(&flp_space, fg_path, TRUE))
    {

	DBG(DBG_CONTROL,
	    char cwd[PATH_MAX];
	    DBG_log("no group file \"%s\" (pwd:%s)"
		      , fg_path
		      , getcwd(cwd, sizeof(cwd))));
    }
예제 #2
0
파일: main.c 프로젝트: kalopa/dbow
/*
 * It all starts here...
 */
int
main(int argc, char *argv[])
{
	int i;
	char tmpfname[256], *cp, *ifile;

	opterr = nflag = mflag = 0;
	active = NULL;
	fofile = hofile = NULL;
	/*
	 * Deal with the command-line options.
	 */
	while ((i = getopt(argc, argv, "h:t:o:xNmv")) != -1) {
		switch (i) {
		case 'h':
			hofile = optarg;
			break;

		case 't':
			if ((active = findtype(optarg)) == NULL) {
				fprintf(stderr, "dbow: unsupported code type: %s\n", optarg); 
				exit(1);
			}
			break;

		case 'o':
			fofile = optarg;
			break;
#ifdef YYDEBUG
		case 'x':
			yydebug = 1;
			break;
#endif
		case 'm':
			mflag = 1;
			break;

		case 'N':
			nflag = 1;
			break;

		case 'v':
			printf("DBOW version %s\n", DBOW_VERSION);
			exit(0);
			break;

		default:
			usage();
			break;
		}
	}
	/*
	 * The default generator is for C code.
	 */
	if (active == NULL && (active = findtype("c")) == NULL) {
		fprintf(stderr, "dbow: can't find default generator type.\n");
		exit(1);
	}
	/*
	 * Make sure we have an input file, and call the lexical
	 * analyzer to open it.  Report an error if that doesn't work.
	 */
	if ((argc - optind) != 1)
		usage();
	ifile = strdup(argv[optind]);
	if (lexopen(ifile) < 0) {
		fprintf(stderr, "dbow: ");
		perror(ifile);
		exit(1);
	}
	/*
	 * If no output file has been specified, then carve an
	 * output file by changing the <file>.d to <file>.<fext>
	 * where 'fext' is the generators file extension.
	 */
	if (fofile == NULL) {
		strncpy(tmpfname, ifile, sizeof(tmpfname) - 5);
		if ((cp = strrchr(tmpfname, '.')) != NULL &&
					cp[1] == 'd' && cp[2] == '\0') {
			*cp = '\0';
		} else
			cp = strchr(tmpfname, '\0');
		*cp++ = '.';
		if (mflag)
			strcpy(cp, "m4");
		else
			strcpy(cp, active->fext);
		if ((cp = strrchr(tmpfname, '/')) != NULL)
			cp++;
		else
			cp = tmpfname;
		fofile = strdup(cp);
	}
	/*
	 * Open the pipe to the M4 command.
	 * XXX - don't use M4 when generating SQL (for now!).
	 */
	if (mflag || active->cdtype == CDT_DBASE) {
		if (strcmp(fofile, "-") == 0)
			fofp = stdout;
		else if ((fofp = fopen(fofile, "w")) == NULL) {
			fprintf(stderr, "dbow: cannot open file for writing: ");
			perror(fofile);
			exit(1);
		}
		hofile = NULL;
	} else
		fofp = m4open(fofile, active);
	linesync(ifile, 1, fofp);
	if (hofile == NULL)
		hofp = fofp;
	else {
		hofp = m4open(hofile, active);
		linesync(ifile, 1, hofp);
	}
	tofp = NULL;
	/*
	 * Parse the input file using YACC and close the input stream.
	 * If there are no errors, call each table generator.
	 */
	nerrors = 0;
	yyparse();
	lexclose();
	if (nerrors == 0) {
		/*
		 * Perform function optimizations and check all
		 * tables to make sure they have the basic quorum
		 * of functions.
		 */
		functioncleanup();
		/*
		 * If we've diverted the prolog to a separate file, then
		 * we'll need to include it in the main file.
		 */
		if (fofp != hofp)
			fileinc(hofile, fofp);
		doproto(ifile, 0);
		docode(NULL, 0);
		/*
		 * Emit the epilog code.
		 */
		genepilog(fofp);
		if (hofp != fofp)
			genepilog(hofp);
		if (tofp != NULL) {
			fclose(tofp);
			if ((tofp = fopen(tofile, "r")) != NULL) {
				while ((i = fgetc(tofp)) != EOF)
					fputc(i, fofp);
				fclose(tofp);
			}
			unlink(tofile);
		}
	}
	/*
	 * Close out the output file (and delete it if it's bad),
	 * then exit.
	 */
	pclose(fofp);
	if (hofp != fofp)
		pclose(hofp);
	exit(nerrors > 0 ? 1 : 0);
}