コード例 #1
0
static void
dofile(		/* plot a file */
	int  optc,
	char  *optv[],
	char  *file
)
{
	char  stmp[256];
	int  i;
						/* start fresh */
	mgclearall();
						/* type options first */
	for (i = 0; i < optc; i++)
		if (istyp(optv[i])) {
			sprintf(stmp, "include=%s.plt", optv[i]+1);
			setmgvar(progname, stdin, stmp);
		} else
			i++;
						/* file next */
	mgload(file);
						/* variable options last */
	for (i = 0; i < optc; i++)
		if (isvar(optv[i])) {
			sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]);
			setmgvar(progname, stdin, stmp);
			i++;
		}
						/* graph it */
	mgraph();
}
コード例 #2
0
ファイル: dgraph.c プロジェクト: Pizookies/Radiance
void
dofile(		/* plot a file */
	int  optc,
	char  *optv[],
	char  *file
)
{
	int  width = 79;
	int  length = 21;
	char  stmp[256];
	int  i;
						/* start fresh */
	mgclearall();
						/* load file */
	mgload(file);
						/* do options */
	for (i = 0; i < optc; i += 2)
		if (optv[i][0] == '+') {
			sprintf(stmp, "%s=%s", optv[i]+1, optv[i+1]);
			setmgvar("command line", stdin, stmp);
		} else
			switch (optv[i][1]) {
			case 'w':
				width = atoi(optv[i+1]);
				break;
			case 'l':
				length = atoi(optv[i+1]);
				break;
			default:
				fprintf(stderr, "%s: unknown option: %s\n",
						progname, optv[i]);
				quit(1);
			}

						/* graph it */
	cgraph(width, length);
}
コード例 #3
0
void
setmgvar(		/* set a variable */
char  *fname,
FILE  *fp,
char  *string
)
{
	char  name[128];
	FILE  *fp2;
	register int  i;
	register char  *s;
	register VARIABLE  *vp;

	if (!strncmp(string, "include=", 8)) {	/* include file */
		if ((s = findfile(string+8, libpath)) == NULL) {
			fprintf(stderr, "%s\n", string);
			fprintf(stderr, "%s: %s: File not found: %s\n",
					progname, fname, string+8);
			quit(1);
		}
		strcpy(name, s);
		mgload(name);
		return;
	}
	s = string;
	i = 0;
	while (i < sizeof(name)-1 && isid(*s))
		name[i++] = *s++;
	name[i] = '\0';
	vp = vlookup(name);
	if (vp != NULL) {
		undefine(vp);
		switch (vp->type) {
		case REAL:
		case FUNCTION:
			if ((*s == '(') != (vp->type == FUNCTION)) {
				fprintf(stderr, "%s\n", string);
				fprintf(stderr,
					"%s: %s: Bad %s declaration: %s\n",
					progname, fname,
					vp->type == FUNCTION ?
					"function" : "variable",
					name);
				quit(1);
			}
			scompile(string, fname, 0);
			vp->v.dfn = savestr(string);
			break;
		case STRING:
			if (*s++ != '=') {
				fprintf(stderr, "%s\n", string);
				fprintf(stderr, "%s: %s: Missing '='\n",
						progname, fname);
				quit(1);
			}
			vp->v.s = savestr(s);
			break;
		case DATA:
			if (*s++ != '=') {
				fprintf(stderr, "%s\n", string);
				fprintf(stderr, "%s: %s: Missing '='\n",
						progname, fname);
				quit(1);
			}
			if (!*s) {
				loaddata(fname, fp, &vp->v.d);
			} else if (*s == '!') {
				if ((fp2 = popen(s+1, "r")) == NULL) {
					fprintf(stderr, "%s\n", string);
					fprintf(stderr,
					"%s: %s: Cannot execute: %s\n",
							progname, fname, s+1);
					quit(1);
				}
				loaddata(s, fp2, &vp->v.d);
				pclose(fp2);
			} else {
				if ((fp2 = fopen(s, "r")) == NULL) {
				    fprintf(stderr, "%s\n", string);
				    fprintf(stderr,
					    "%s: %s: Data file not found: %s\n",
					    progname, fname, s);
				    quit(1);
				}
				loaddata(s, fp2, &vp->v.d);
				fclose(fp2);
			}
			break;
		}
		vp->flags |= DEFINED;
	} else
		setivar(name, fname, string);		/* intermediate */
}