Example #1
0
ASL_alloc(int k)
#endif
{
	static int msize[5] = {
		sizeof(ASL_fg),
		sizeof(ASL_fg),
		sizeof(ASL_fgh),
		sizeof(ASL_pfg),
		sizeof(ASL_pfgh)
		};
	ASL *a;
	ASLhead *h;
	int n;

	if (!Stderr)
		Stderr_init_ASL();	/* set Stderr if necessary */
	Mach_ASL();
	if (k < 1 || k > 5)
		return 0;
	a = (ASL*) mymalloc(n = msize[k-1]);
	memcpy(a, &edagpars_ASL, sizeof(Edagpars));
	memset(&a->i, 0, n - sizeof(Edagpars));
	a->i.ASLtype = k;
	a->i.n_prob = 1;
	switch(k) {
	  case ASL_read_pfg:	((ASL_pfg*)a)->P.merge = 1; break;
	  case ASL_read_pfgh:	((ASL_pfgh*)a)->P.merge = 1;
	  }
	h = a->p.h.next = ASLhead_ASL.next;
	a->p.h.prev = h->prev;
	h->prev = ASLhead_ASL.next = &a->p.h;
	return cur_ASL = a;
	}
Example #2
0
 int
getopts_ASL(ASL *asl, char **argv, Option_Info *oi)
{
	char *s;

	if (!Stderr)
		Stderr_init_ASL();
	if (!(oi->asl = asl))
		badasl_ASL(asl,0,"getopts");
	if (!oi->option_echo)
		oi->option_echo = ASL_OI_echo;
	oi->option_echo &= ASL_OI_echo;
	oi->n_badopts = 0;

	if (oi->opname && (s = getenv(oi->opname)))
		while(*s)
			s = get_opt_ASL(oi, s);

	while((s = *argv++))
		do s = get_opt_ASL(oi, s);
			while(*s);

	need_nl = oi->nnl;
	if (oi->flags & ASL_OI_show_version)
		show_version_ASL(oi);
	fflush(stdout);
	return oi->n_badopts;
	}
Example #3
0
badasl_ASL(ASL *a, int n, char *who)
#endif
{
	if (!Stderr)
		Stderr_init_ASL();	/* set Stderr if necessary */
	if (a)
		fprintf(Stderr,
			"\n*** %s needs ASL_alloc(%d), not ASL_alloc(%d)\n",
			who, n, a->i.ASLtype);
	else if (n)
		fprintf(Stderr, "\n*** %s called before ASL_alloc(%d)\n",
			who, n);
	else
		fprintf(Stderr,
		 "\n*** %s called before ASL_alloc, jacdim, jac2dim, or jacpdim\n", who);
	exit(1);
	}
Example #4
0
File: misc.c Project: ampl/mp
 ASL *
ASL_alloc(int k)
{
	static int msize[5] = {
		sizeof(ASL_fg),
		sizeof(ASL_fg),
		sizeof(ASL_fgh),
		sizeof(ASL_pfg),
		sizeof(ASL_pfgh)
		};
	static int first = 1;
	ASL *a;
	ASLhead *h;
	int n;

	if (first) {
		first = 0;
		if (!Stderr)
			Stderr_init_ASL();	/* set Stderr if necessary */
		Mach_ASL();
#ifdef MULTIPLE_THREADS
		init_dtoa_locks();
		set_max_dtoa_threads(1);
#endif
		}
	if (k < 1 || k > 5)
		return 0;
	a = (ASL*) mymalloc(n = msize[k-1]);
	memcpy(a, &edagpars_ASL, sizeof(Edagpars));
	memset(&a->i, 0, n - sizeof(Edagpars));
	a->i.ASLtype = k;
	a->i.n_prob = 1;
	switch(k) {
	  case ASL_read_pfg:	((ASL_pfg*)a)->P.merge = 1; break;
	  case ASL_read_pfgh:	((ASL_pfgh*)a)->P.merge = 1;
	  }
	h = a->p.h.next = ASLhead_ASL.next;
	a->p.h.prev = h->prev;
	h->prev = ASLhead_ASL.next = &a->p.h;
	return cur_ASL = a;
	}
Example #5
0
 void
usage_ASL(Option_Info *oi, int rc)
{
	static const char *opts[] = {
		"-", "end of options",
		"=", "show name= possibilities",
		"?", "show usage",
#ifdef SYMANTEC
		"E", "force floating-point emulation (Symantec only)",
#endif
		"e", "suppress echoing of assignments",
		"ix","import user-defined functions from x; -i? gives details",
		"s", "write .sol file (without -AMPL)",
		"u", "just show available user-defined functions",
		"v", "just show version",
		0};
	char **o;
	const char *s, *s1;
	keyword *kw, *kwe;
	int i, L, L1, L2;
	FILE *f = stdout;

	if (rc) {
		if (!Stderr)
			Stderr_init_ASL();
		f = Stderr;
		}
	kw = kwe = 0;
	o = 0;
	s = 0;
	L = 2;
	if (oi) {
		s = oi->sname;
		o = oi->usage;
		L = kw_width(kw = oi->options, oi->n_options, &kwe);
		}
	fprintf(f, "usage: %s [options] stub [-AMPL] [<assignment> ...]\n",
		s ? s : basename(progname));
	if (o)
		while((s = *o++))
			fprintf(f, "%s\n", s);
	fprintf(f, "\nOptions:\n");
	o = (char**)opts;
	if (!oi || !(oi->flags && ASL_OI_want_funcadd))
		ofix(o, 4);
	else if (!ix_details_ASL[0])
		ofix(o, 2);
	s = *o;
	for(;;) {
		if (kw < kwe)
			i = s ? strcmp(s, kw->name): 1;
		else if (s)
			i = -1;
		else
			break;
		if (i < 0)
			fprintf(f, "\t-%-*s{%s}\n", L, s, o[1]);
		else {
			if ((s1 = kw->desc))
				if (*s1 == '=') {
					while(*++s1 > ' ');
					L1 = s1 - kw->desc;
					L2 = L - strlen(kw->name);
					if (*s1)
						s1++;
					fprintf(f, "\t-%s%-*.*s{%s}\n",
						kw->name, L2, L1, kw->desc,s1);
					}
				else
					fprintf(f, "\t-%-*s{%s}\n", L,
						kw->name, s1);
			else
				fprintf(f, "\t-%s\n", kw->name);
			++kw;
			}
		if (i <= 0) {
			o += 2;
			s = *o;
			}
		}
	exit(rc);
	}
Example #6
0
 char *
getstub_ASL(ASL *asl, char ***pargv, Option_Info *oi)
{
	char *s, *s1;
	keyword *kw, *okw;
	int i, options;
	char **argv = *pargv;

	progname = *argv;
	if (!Stderr)
		Stderr_init_ASL();	/* set Stderr if necessary */
	if (!asl)
		badasl_ASL(asl,0,"getstub");
	amplflag = 0;
	options = 1;
	okw = 0;
	if (oi) {
		oi->nnl = 0;
		oi->asl = asl;
		okw = oi->options;
		if ((s = getenv("solver_msg"))) {
			i = (int)strtol(s, &s1, 10);
			if (s1 > s && !*s1 && i >= 0 && !(i & 1))
				oi->option_echo = ASL_OI_never_echo;
			}
		oi->option_echo = (oi->option_echo & ASL_OI_never_echo)
			? ASL_OI_never_echo : ASL_OI_clopt | ASL_OI_echo;
		oi->n_badopts = 0;
		}

	while((s = *++argv)) {
		if (*s == '-' && options) {
			s1 = s + 1;
			if (okw
			 && (kw = (keyword*)b_search_ASL(okw,
					(int)sizeof(keyword), oi->n_options,
					&s1, &oi->eqsign))) {
				if (!*s1 && argv[1]) {
					s = (*kw->kf)(oi, kw, argv[1]);
					if (s != argv[1])
						argv++;
					continue;
					}
				(*kw->kf)(oi, kw, s1);
				continue;
				}
			if (!s1[1])
			    switch(*s1) {
				case '=':
					shownames(oi);
				case '?':
					usage_ASL(oi,0);
				case '-':
					options = 0;
					continue;
#ifdef SYMANTEC
				case 'E':
					_8087 = 0;
					continue;
#endif
				case 'e':
					if (oi)
						oi->option_echo &= ~ASL_OI_echo;
					continue;
				case 's':
					if (oi)
						oi->wantsol = 1;
					continue;
				case 'u':
					if (!oi || !(oi->flags && ASL_OI_want_funcadd))
						break;
					func_add(asl);
					show_funcs();
					exit(0);
				case 'v':
					if (oi)
						Ver_val_ASL(oi,0,0);
					continue;
				case 'i':
					if (ix_details_ASL[0]) {
						if ((s = argv[1])) {
							argv++;
							if (*s == '?' && !s[1])
								ix_usage();
							i_option_ASL = s;
							}
						continue;
						}
				}
			if (*s1 == 'i' && ix_details_ASL[0]) {
				if (s1[1] == '?' && !s1[2])
					ix_usage();
				i_option_ASL = s1 + 1;
				continue;
				}
			if (*s1 == '-') {
				if (!strcmp(++s1, "help")) {
					if (oi)
						usage_ASL(oi,0);
					}
				else if (!strcmp(s1, "version")) {
					if (oi) {
						Ver_val_ASL(oi,0,0);
						continue;
						}
					}
				}
			fprintf(Stderr, "%s: bad option %s\n", progname, s);
			usage_ASL(oi,1);
			}
		if (strchr(s,'='))
			break;
		if ((s1 = *++argv) && !strncmp(s1,"-AMPL",5)) {
			amplflag = 1;
			argv++;
			if (oi && oi->bsname
			 && !(oi->option_echo & ASL_OI_never_echo))
				need_nl = oi->nnl = printf("%s: ", oi->bsname);
			}
		i = strlen(s) - 3;
		if (i > 0 && !strcmp(s+i,".nl"))
			s[i] = 0;
		break;
		}
	if (oi && oi->n_badopts)	/* possiby set by kw->kf */
		exit(1);
	*pargv = argv;
	return s;
	}