示例#1
0
文件: input.c 项目: aosm/graphviz
void dotneato_initialize(GVC_t *gvc, int argc, char** argv)
{
	char	*rest,c, *val;
	int	i,v,nfiles;

	/* establish if we are running in a CGI environment */
	HTTPServerEnVar=getenv("SERVER_NAME");

	/* establish Gvfilepath, if any */
	Gvfilepath = getenv("GV_FILE_PATH");

	aginit();
	nfiles = 0;
	for (i = 1; i < argc; i++)
		if (argv[i][0] != '-') nfiles++;
	Files = N_NEW(nfiles + 1, char *);
	nfiles = 0;
	if (!CmdName) setCmdName (argv[0]);
	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			rest = &(argv[i][2]);
			switch (c = argv[i][1]) {
				case 'G': 
					if (*rest) global_def(rest,agraphattr); 
					else {
						fprintf(stderr,"Missing argument for -G flag\n");
						dotneato_usage (1);
					}
					break;
				case 'N': 
					if (*rest) global_def(rest,agnodeattr);
					else {
						fprintf(stderr,"Missing argument for -N flag\n");
						dotneato_usage (1);
					}
					break;
				case 'E':
					if (*rest) global_def(rest,agedgeattr);
					else {
						fprintf(stderr,"Missing argument for -E flag\n");
						dotneato_usage (1);
					}
					break;
				case 'T': 
					val = getFlagOpt (argc, argv, &i);
					if (!val) {
						fprintf(stderr,"Missing argument for -T flag\n");
						dotneato_usage (1);
					}
					gvrender_output_langname_job(gvc, val);
					break;
				case 'V':
					fprintf(stderr,"%s version %s (%s)\n",
						gvc->info[0], gvc->info[1], gvc->info[2]);
					exit (0);
					break;
				case 'l':
					val = getFlagOpt (argc, argv, &i);
					if (!val) {
						fprintf(stderr,"Missing argument for -l flag\n");
						dotneato_usage (1);
					}
					use_library(val);
					break;
				case 'o':
					val = getFlagOpt (argc, argv, &i);
					gvrender_output_filename_job(gvc, val);
					break;
				case 'q':
					if (*rest) {
						v = atoi(rest);
						if (v <= 0) {
							fprintf (stderr, "Invalid parameter \"%s\" for -q flag - ignored\n", rest);
						}
						else if (v == 1) agseterr (AGERR);
						else agseterr (AGMAX);
					}
					else agseterr (AGERR);
					break;
				case 's':
					if (*rest) {
						PSinputscale = atof(rest);
						if (PSinputscale <= 0) {
							fprintf (stderr, "Invalid parameter \"%s\" for -s flag\n", rest);
							dotneato_usage (1);
						}
					}
					else PSinputscale = POINTS_PER_INCH;
					break;
				case 'v': 
                    Verbose = TRUE; 
                    if (isdigit(*rest)) Verbose = atoi (rest);
                    break;
				case 'y': y_invert = TRUE; break;
				case '?': dotneato_usage (0); break;
				default:
					fprintf(stderr, "%s: option -%c unrecognized\n\n",
	                  CmdName,c);
                    dotneato_usage (1);
			}
		}
		else
		Files[nfiles++] = argv[i];
	}

	/* if no -Txxx, then set default format */
	if (!gvc->jobs || !gvc->jobs->output_langname) {
		gvrender_output_langname_job(gvc, "dot");
	}

	/* need to set Output_lang now based on the first -Txxx,
	 * so that CodeGen->textsize picks up an appropriate routine
	 * otherwise node sizing can be wrong for any or all of the products.
	 */
/* FIXME */
	Output_lang = lang_select(gvc, gvc->jobs->output_langname, 0);

	/* set persistent attributes here (if not already set from command line options) */ 
	if (! (agfindattr(agprotograph()->proto->n, "label")))
		agnodeattr(NULL,"label",NODENAME_ESC);
}
示例#2
0
文件: input.c 项目: ekoontz/graphviz
void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv)
{
    char *rest, c, *val;
    int i, v, nfiles;

    /* establish if we are running in a CGI environment */
    HTTPServerEnVar = getenv("SERVER_NAME");

    /* establish Gvfilepath, if any */
    Gvfilepath = getenv("GV_FILE_PATH");

    /* configure for available plugins and codegens */
    gvconfig(gvc, gvc->common.config);
    if (gvc->common.config)
	exit (0);

    gvc->common.cmdname = dotneato_basename(argv[0]);
    i = gvlayout_select(gvc, gvc->common.cmdname);
    if (i == NO_SUPPORT)
	gvlayout_select(gvc, "dot");

    /* feed the globals */
    Verbose = gvc->common.verbose;
    CmdName = gvc->common.cmdname;

    aginit();
    nfiles = 0;
    for (i = 1; i < argc; i++)
	if (argv[i] && argv[i][0] != '-')
	    nfiles++;
    gvc->input_filenames = N_NEW(nfiles + 1, char *);
    nfiles = 0;
    for (i = 1; i < argc; i++) {
	if (argv[i] && argv[i][0] == '-') {
	    rest = &(argv[i][2]);
	    switch (c = argv[i][1]) {
	    case 'G':
		if (*rest)
		    global_def(rest, agraphattr);
		else {
		    fprintf(stderr, "Missing argument for -G flag\n");
		    dotneato_usage(1);
		}
		break;
	    case 'N':
		if (*rest)
		    global_def(rest, agnodeattr);
		else {
		    fprintf(stderr, "Missing argument for -N flag\n");
		    dotneato_usage(1);
		}
		break;
	    case 'E':
		if (*rest)
		    global_def(rest, agedgeattr);
		else {
		    fprintf(stderr, "Missing argument for -E flag\n");
		    dotneato_usage(1);
		}
		break;
	    case 'T':
		val = getFlagOpt(argc, argv, &i);
		if (!val) {
		    fprintf(stderr, "Missing argument for -T flag\n");
		    dotneato_usage(1);
		    exit(1);
		}
		v = gvjobs_output_langname(gvc, val);
		if (!v) {
		    fprintf(stderr, "Format: \"%s\" not recognized. Use one of:%s\n",
			val, gvplugin_list(gvc, API_device, val));
		    exit(1);
		}
		break;
	    case 'K':
		val = getFlagOpt(argc, argv, &i);
		if (!val) {
                    fprintf(stderr, "Missing argument for -K flag\n");
                    dotneato_usage(1);
                    exit(1);
                }
                v = gvlayout_select(gvc, val);
                if (v == NO_SUPPORT) {
                    fprintf(stderr, "Layout type: \"%s\" not recognized. Use one of:%s\n",
                        val, gvplugin_list(gvc, API_layout, val));
                    exit(1);
                }
		break;
	    case 'V':
		fprintf(stderr, "%s - %s version %s (%s)\n",
			gvc->common.cmdname, gvc->common.info[0], 
			gvc->common.info[1], gvc->common.info[2]);
		exit(0);
		break;
	    case 'l':
		val = getFlagOpt(argc, argv, &i);
		if (!val) {
		    fprintf(stderr, "Missing argument for -l flag\n");
		    dotneato_usage(1);
		}
		use_library(gvc, val);
		break;
	    case 'o':
		val = getFlagOpt(argc, argv, &i);
		if (! gvc->common.auto_outfile_names)
		    gvjobs_output_filename(gvc, val);
		break;
	    case 'q':
		if (*rest) {
		    v = atoi(rest);
		    if (v <= 0) {
			fprintf(stderr,
				"Invalid parameter \"%s\" for -q flag - ignored\n",
				rest);
		    } else if (v == 1)
			agseterr(AGERR);
		    else
			agseterr(AGMAX);
		} else
		    agseterr(AGERR);
		break;
	    case 's':
		if (*rest) {
		    PSinputscale = atof(rest);
		    if (PSinputscale <= 0) {
			fprintf(stderr,
				"Invalid parameter \"%s\" for -s flag\n",
				rest);
			dotneato_usage(1);
		    }
		} else
		    PSinputscale = POINTS_PER_INCH;
		break;
	    case 'x':
		Reduce = TRUE;
		break;
	    case 'y':
		Y_invert = TRUE;
		break;
	    case '?':
		dotneato_usage(0);
		break;
	    default:
		fprintf(stderr, "%s: option -%c unrecognized\n\n", gvc->common.cmdname,
			c);
		dotneato_usage(1);
	    }
	} else if (argv[i])
	    gvc->input_filenames[nfiles++] = argv[i];
    }

    /* if no -Txxx, then set default format */
    if (!gvc->jobs || !gvc->jobs->output_langname) {
	v = gvjobs_output_langname(gvc, "dot");
	assert(v);  /* "dot" should always be available as an output format */
    }

    /* set persistent attributes here (if not already set from command line options) */
    if (!(agfindattr(agprotograph()->proto->n, "label")))
	agnodeattr(NULL, "label", NODENAME_ESC);
}