コード例 #1
0
void delvar(varnode **head, varnode **tail)
{
   varnode *temp;
   temp = findvar(*head);
   if (!temp)
      return;
   else if (temp == *head)
   {
      *head = (*head)->next;
      if (*head != NULL)
      {
         (*head)->prev = NULL;
      }
      free(temp);
   }
   else if (temp == *tail)
   {
      *tail = temp->prev;
      if (*tail != NULL)
         (*tail)->next = NULL;
      free(temp);
   }
   else
   {
      temp->prev->next = temp->next;
      temp->next->prev = temp->prev;
      free(temp);
   }
}
コード例 #2
0
ファイル: keyword.c プロジェクト: 2014-class/freerouter
void
parsefmt(const char *p, int user)
{
	char *tempstr, *tempstr1;

#define		FMTSEP	" \t,\n"
	tempstr1 = tempstr = strdup(p);
	while (tempstr && *tempstr) {
		char *cp, *hp;
		VAR *v;
		struct varent *vent;

		/*
		 * If an item contains an equals sign, it specifies a column
		 * header, may contain embedded separator characters and
		 * is always the last item.	
		 */
		if (tempstr[strcspn(tempstr, "="FMTSEP)] != '=')
			while ((cp = strsep(&tempstr, FMTSEP)) != NULL &&
			    *cp == '\0')
				/* void */;
		else {
			cp = tempstr;
			tempstr = NULL;
		}
		if (cp == NULL || !(v = findvar(cp, user, &hp)))
			continue;
		if (!user) {
			/*
			 * If the user is NOT adding this field manually,
			 * get on with our lives if this VAR is already
			 * represented in the list.
			 */
			vent = find_varentry(v);
			if (vent != NULL)
				continue;
		}
		if ((vent = malloc(sizeof(struct varent))) == NULL)
			errx(1, "malloc failed");
		vent->header = v->header;
		if (hp) {
			hp = strdup(hp);
			if (hp)
				vent->header = hp;
		}
		vent->var = malloc(sizeof(*vent->var));
		if (vent->var == NULL)
			errx(1, "malloc failed");
		memcpy(vent->var, v, sizeof(*vent->var));
		STAILQ_INSERT_TAIL(&varlist, vent, next_ve);
	}
	free(tempstr1);
	if (STAILQ_EMPTY(&varlist)) {
		warnx("no valid keywords; valid keywords:");
		showkey();
		exit(1);
	}
}
コード例 #3
0
ファイル: gen.c プロジェクト: stsquad/stonx
void settype (Type *t, Pattern *p, char id)
{		
	int i;
	switch(t->t_id)
	{
		case T_SI:
		case T_SI8:
		case T_SI16:
		case T_SI32:
			i=newvar(p);
			p->v[i].t=t; p->v[i].id=id; return;
	}
	p->v[findvar(p, id)].t=t;
}
コード例 #4
0
ファイル: for.c プロジェクト: n-t-roff/DWB3.3
void
forloop(char *var, double from, double to, int op, double by, char *str)
{
	if (++forp >= forstk+10)
		fatal("for loop nested too deep");

/* note: actually we here want to take a vector variable and construct its   */
/*	 values directly, then access them one at a time below; the current  */
/*	 version is a temporary concession to old pic's version of the 'for' */

	forp->sym = findvar(var, VARNAME);
	if (forp->sym->s_dim && forp->sym->s_val.a)
		free(forp->sym->s_val.a);
	forp->sym->s_dim = 0;
	forp->sym->s_val.f = from;
	forp->to = to;
	if (by == 0.)
		fatal("step size of 0 not allowed");

	/*  For additive or subtractive step, make sure step is positive.
	    Otherwise, make sure step is greater than 1 in absolute value. */
	if ((op == ' ' || op == '+') && by < 0.) {
		op = '-';
		by = -by;
	}
	else if (op == '-' && by < 0.) {
		op = '+';
		by = -by;
	}
	else if (op == '*' && fabs(by) < 1.) {
		op = '/';
		by = 1 / by;
	}
	else if (op == '/' && fabs(by) < 1.) {
		op = '*';
		by = 1 / by;
	}
	forp->op = op;
	forp->by = by;
	forp->str = str;
	nextfor();
	unput('\n');
}
コード例 #5
0
ファイル: ntpq-subs.c プロジェクト: Distrotech/ntp
/*
 * Decode an incoming data buffer and print a line in the peer list
 */
static int
doprintpeers(
	struct varlist *pvl,
	int associd,
	int rstatus,
	int datalen,
	const char *data,
	FILE *fp,
	int af
	)
{
	char *name;
	char *value = NULL;
	int i;
	int c;

	sockaddr_u srcadr;
	sockaddr_u dstadr;
	sockaddr_u refidadr;
	u_long srcport = 0;
	char *dstadr_refid = "0.0.0.0";
	char *serverlocal;
	size_t drlen;
	u_long stratum = 0;
	long ppoll = 0;
	long hpoll = 0;
	u_long reach = 0;
	l_fp estoffset;
	l_fp estdelay;
	l_fp estjitter;
	l_fp estdisp;
	l_fp reftime;
	l_fp rec;
	l_fp ts;
	u_char havevar[MAXHAVE];
	u_long poll_sec;
	char type = '?';
	char refid_string[10];
	char whenbuf[8], pollbuf[8];
	char clock_name[LENHOSTNAME];

	memset((char *)havevar, 0, sizeof(havevar));
	get_systime(&ts);
	
	ZERO_SOCK(&srcadr);
	ZERO_SOCK(&dstadr);

	/* Initialize by zeroing out estimate variables */
	memset((char *)&estoffset, 0, sizeof(l_fp));
	memset((char *)&estdelay, 0, sizeof(l_fp));
	memset((char *)&estjitter, 0, sizeof(l_fp));
	memset((char *)&estdisp, 0, sizeof(l_fp));

	while (nextvar(&datalen, &data, &name, &value)) {
		sockaddr_u dum_store;

		i = findvar(name, peer_var, 1);
		if (i == 0)
			continue;	/* don't know this one */
		switch (i) {
			case CP_SRCADR:
			if (decodenetnum(value, &srcadr)) {
				havevar[HAVE_SRCADR] = 1;
			}
			break;
			case CP_DSTADR:
			if (decodenetnum(value, &dum_store)) {
				type = decodeaddrtype(&dum_store);
				havevar[HAVE_DSTADR] = 1;
				dstadr = dum_store;
				if (pvl == opeervarlist) {
					dstadr_refid = trunc_left(stoa(&dstadr), 15);
				}
			}
			break;
			case CP_REFID:
			if (pvl == peervarlist) {
				havevar[HAVE_REFID] = 1;
				if (*value == '\0') {
					dstadr_refid = "";
				} else if (strlen(value) <= 4) {
					refid_string[0] = '.';
					(void) strcpy(&refid_string[1], value);
					i = strlen(refid_string);
					refid_string[i] = '.';
					refid_string[i+1] = '\0';
					dstadr_refid = refid_string;
				} else if (decodenetnum(value, &refidadr)) {
					if (SOCK_UNSPEC(&refidadr))
						dstadr_refid = "0.0.0.0";
					else if (ISREFCLOCKADR(&refidadr))
						dstadr_refid =
						    refnumtoa(&refidadr);
					else
						dstadr_refid =
						    stoa(&refidadr);
				} else {
					havevar[HAVE_REFID] = 0;
				}
			}
			break;
			case CP_STRATUM:
			if (decodeuint(value, &stratum))
				havevar[HAVE_STRATUM] = 1;
			break;
			case CP_HPOLL:
			if (decodeint(value, &hpoll)) {
				havevar[HAVE_HPOLL] = 1;
				if (hpoll < 0)
					hpoll = NTP_MINPOLL;
			}
			break;
			case CP_PPOLL:
			if (decodeint(value, &ppoll)) {
				havevar[HAVE_PPOLL] = 1;
				if (ppoll < 0)
					ppoll = NTP_MINPOLL;
			}
			break;
			case CP_REACH:
			if (decodeuint(value, &reach))
				havevar[HAVE_REACH] = 1;
			break;
			case CP_DELAY:
			if (decodetime(value, &estdelay))
				havevar[HAVE_DELAY] = 1;
			break;
			case CP_OFFSET:
			if (decodetime(value, &estoffset))
				havevar[HAVE_OFFSET] = 1;
			break;
			case CP_JITTER:
			if (pvl == peervarlist)
				if (decodetime(value, &estjitter))
					havevar[HAVE_JITTER] = 1;
			break;
			case CP_DISPERSION:
			if (decodetime(value, &estdisp))
				havevar[HAVE_DISPERSION] = 1;
			break;
			case CP_REC:
			if (decodets(value, &rec))
				havevar[HAVE_REC] = 1;
			break;
			case CP_SRCPORT:
			if (decodeuint(value, &srcport))
				havevar[HAVE_SRCPORT] = 1;
			break;
			case CP_REFTIME:
			havevar[HAVE_REFTIME] = 1;
			if (!decodets(value, &reftime))
				L_CLR(&reftime);
			break;
			default:
			break;
		}
	}

	/*
	 * Check to see if the srcport is NTP's port.  If not this probably
	 * isn't a valid peer association.
	 */
	if (havevar[HAVE_SRCPORT] && srcport != NTP_PORT)
		return (1);

	/*
	 * Got everything, format the line
	 */
	poll_sec = 1<<max(min3(ppoll, hpoll, NTP_MAXPOLL), NTP_MINPOLL);
	if (pktversion > NTP_OLDVERSION)
		c = flash3[CTL_PEER_STATVAL(rstatus) & 0x7];
	else
		c = flash2[CTL_PEER_STATVAL(rstatus) & 0x3];
	if (numhosts > 1) {
		if (peervarlist == pvl && havevar[HAVE_DSTADR]) {
			serverlocal = nntohost_col(&dstadr,
			    (size_t)min(LIB_BUFLENGTH - 1, maxhostlen),
			    TRUE);
		} else {
			if (currenthostisnum)
				serverlocal = trunc_left(currenthost,
							 maxhostlen);
			else
				serverlocal = currenthost;
		}
		fprintf(fp, "%-*s ", maxhostlen, serverlocal);
	}
	if (AF_UNSPEC == af || AF(&srcadr) == af) {
		strncpy(clock_name, nntohost(&srcadr), sizeof(clock_name));		
		fprintf(fp, "%c%-15.15s ", c, clock_name);
		drlen = strlen(dstadr_refid);
		makeascii(drlen, dstadr_refid, fp);
		while (drlen++ < 15)
			fputc(' ', fp);
		fprintf(fp,
			" %2ld %c %4.4s %4.4s  %3lo  %7.7s %8.7s %7.7s\n",
			stratum, type,
			prettyinterval(whenbuf, sizeof(whenbuf),
				       when(&ts, &rec, &reftime)),
			prettyinterval(pollbuf, sizeof(pollbuf), 
				       (int)poll_sec),
			reach, lfptoms(&estdelay, 3),
			lfptoms(&estoffset, 3),
			(havevar[HAVE_JITTER])
			    ? lfptoms(&estjitter, 3)
			    : lfptoms(&estdisp, 3));
		return (1);
	}
	else
		return(1);
}
コード例 #6
0
int ErrorThrow(int e) {
	*((float *)findvar("MM.ERRNO", V_FIND | V_NOFIND_ERR)) = e;
	if(e > 0 && e < NBRERRMSG && OptionErrorAbort) error((char *)FErrorMsg[e]);
	return e;
}	
コード例 #7
0
ファイル: docomm.c プロジェクト: dank101/4.2BSD
docommand() {
	register char	*p;
	register int	i;
	register ADDR	addr, bkaddr;
	struct proct 	*procp;
	char s[4];
	
	cntval = 1;
	adrflg = 0;
	errflg = 0;

	if (scallf) {
		doscall();
		setcur(1);
		lastcom = NOCOM;
		return;
	}
	
	if (reflag) {  /* search for regular expression */
		dore();
		lastcom = PRCOM;
		return;
	}
	
	if (cmd == '\0') {
		if (integ != 0 && var[0] != '\0') {
			error("Invalid command (1)");
			return;
		}
		if (integ != 0) { /* print line number */
			ffind(integ);
			fprint();
			lastcom = PRCOM;
			return;
		}
		if (var[0] != 0) {
			printf("Unexpected null command\n");
			return;
		}
	}
		
	switch (cmd) {
	
	case 'Y':
		debug = !debug;
		break;

	case 'V':
		version();
		break;

	case 'M':
		if (args[0]) {
			setmap(args);
		} else {
			printmap("? map", &txtmap);
			printmap("/ map", &datmap);
		}
		break;

	case 'x':
		printregs();
		break;

	case 'X':
		printpc();
		break;

	case 'a':
		if (integ) {
			cpstr(args, "l\n");
		} else if (proc[0]) {
			cpall(args, "T\n");
		} else {
			error("Bad arguments");
			break;
		}
		goto setbrk;
		break;	

	case 'l':
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case 'T':
		prfrx(1);
		lastcom = NOCOM;
		break;
		
	case 't':
		prframe();
		lastcom = NOCOM;
		break;
		
	case 'e':
		p = args;
		if (*p == '\0') {
#ifndef FLEXNAMES
			printf("%.16s() in \"%s\"\n",
				curproc()->pname, curfile);
#else
			printf("%s() in \"%s\"\n",
				curproc()->pname, curfile);
#endif
			break;
		}

		while (*p != '\0')
			if (*p++ == '.') goto l1;
		/* argument is procedure name */
		procp = findproc(args);
		if ((procp->pname[0] != '\0') && (procp->sfptr != badfile)) {
			finit(adrtofilep(procp->paddr)->sfilename);
			ffind(procp->lineno);
		}
		else printf("Can't find %s\n", args);
#ifndef FLEXNAMES
		printf("%.16s() in \"%s\"\n", curproc()->pname, curfile);
#else
		printf("%s() in \"%s\"\n", curproc()->pname, curfile);
#endif
		lastcom = PRCOM;
		break;
		
	l1:	/* argument is filename */
		finit(args);
		printf("\"%s\"\n", curfile);
		lastcom = PRCOM;
		break;
		
	case 'p':
		if (integ) ffind(integ);
		fprint();
		lastcom = PRCOM;
		break;
		
	case 'q':
		exit(0);
		
	case 'w':
		if (integ) ffind(integ);
		i = fline;
		fback(WINDOW/2);
		fprintn(WINDOW);
		ffind(i);
		lastcom = PRCOM;
		break;
		
	case 'Q':
		prdebug();
		break;

	case 'z':
		if (integ) ffind(integ);
		fprintn(WINDOW);
		lastcom = PRCOM;
		break;

	case '-':
		fback(integ ? integ : 1);
		fpargs();
		lastcom = PRCOM;
		break;

	case '+':
		fforward(integ ? integ : 1);
		fpargs();
		lastcom = PRCOM;
		break;

	case '\n':
		switch (lastcom) {
		case PRCOM:
			fforward(1);
			fprint();
			break;
		case DSCOM:
			oaddr += oincr ? oincr : typetosize(otype, WORDSIZE);
			printf("0x%x/ ", oaddr);
			dispf((ADDR) oaddr, odesc,
			    oclass == N_RSYM ? oclass : N_GSYM, otype, 0, 0, DSP);
			break;
		case DSICOM:
			dot += oincr;
			prisploc();
			dispi(dot, odesc, N_GSYM, 0, 0);
			break;
		}
		break;

	case '\004':
		if (!isatty(0))
			exit(0);
		switch (lastcom) {
		case PRCOM:
			fforward(1);
			printf("\b");
			fprintn(WINDOW);
			lastcom = PRCOM;
			break;
		case DSICOM:
			printf("\b");
			for (i=0; i<WINDOW; i++) {
				dot += oincr;
				prisploc();
				if (dispi(dot, odesc, N_GSYM, 0, 0) == -1)
					break;
			}
			break;
		case DSCOM:
			printf("\b");
			for (i=0; i<WINDOW; i++) {
				oaddr += oincr ?
					oincr : typetosize(otype, WORDSIZE);
				printf("0x%x/ ", oaddr);
				if (dispf((ADDR) oaddr, odesc,
					oclass == N_RSYM ? oclass :
					N_GSYM, otype, 0, 0, DSP) == -1)
					break;
			}
			break;
		default:
			printf("\n");
		}
		break;

	case 'r':
		if (args[0] == '\0') getargs();
	case 'R':
		signo = 0;
		cpstr(oldargs, args);
		if (debug) error("calling dopcs");
		if (integ) cntval = integ;
		if (!executing) {
			executing = TRUE;
			if (integ) cntval = integ;
			dopcs('r');
			executing = FALSE;
		}
		if (debug) error("exiting dopcs");
		bkaddr = -1;
		goto f1;

	case 'c':
		signo = 0;
	case 'C':
		if (proc[0] != '\0' || integ != 0) {
			setdot();
			if (dot == -1) {
				error("Cannot set temporary breakpoint");
				break;
			}
			dopcs('b');
			bkaddr = dot;
		} else
			bkaddr = -1;
		integ = atoi(args);

f1:		if (debug) error("calling dopcs");
		if (integ) cntval = integ;
		dopcs('c');
		if (debug) error("exiting dopcs");
		if (bkaddr != -1) {
			ADDR dotsave;
			dotsave = dot;
			dot = bkaddr;
			dopcs('d');
			dot = dotsave;
		}
		if (!signo) printf("Breakpoint");
		printf(" at\n");
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case 'S':
	case 's':
		signo = 0;
		integ = atoi(args);
		singstep(integ ? integ : 1, cmd);
		if (signo) printf("\n");
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case 'g':
		if (pid == 0  ||  signo) {
			error("Not stopped at breakpoint");
			break;
		}
		setdot();
		if (dot == -1) {
			error("Bad address");
			break;
		}
		adrflg = 1;
		integ = atoi(args);
		if (integ) cntval = integ;
		dopcs('c');
		if (!signo) printf("Breakpoint");
		printf(" at\n");
		setcur(1);
		lastcom = NOCOM;
		break;

	case 'k':
		if (scallx) {
	 		userpc = dot = *(ADDR *)(((ADDR)&u)+PC) = pcs;
	 		*(ADDR *)(((ADDR)&u)+FP) = fps;
	 		*(ADDR *)(((ADDR)&u)+AP) = aps;
			if (bkpts)
				bkpts->flag = flagss;
			scallx = 0;
			error("Procedure killed");
			longjmp(env, 0);
		} else {
			dopcs('k');
			printf("\n");
			lastcom = NOCOM;
			break;
		}

	case 'B':
		prbkpt();
		break;

	case 'b':
	setbrk:
		if (proc[0] == '\0' && integ == 0) {
			integ = fline;
		}
		setdot();
		if (dot == -1 || dot == 0) {
			error("Cannot set breakpoint");
			break;
		}
		dopcs('b');
		s[0] = ' ';
		s[1] = cmd;
		s[2] = '\n';
		s[3] = 0;
		s[1] = cmd;
		printbkpt(s, adrtoprocp(dot), dot);
		break;
		
	case 'd':
		if (proc[0] == '\0' && integ == 0) {
			idbkpt();
			break;
		}
		setdot();
		if (dot == -1) {
			error("Non existent breakpoint");
			break;
		}
		dopcs('d');
		break;
		
	case 'D':
		dabkpt();
		error("All breakpoints deleted");
		break;

	case 'm':
		addr = varaddr(proc[0] ? proc : curproc()->pname, var);
		printf("stopped with value %d\n", monex(addr, 'd'));
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case '?':
		if (!(var[0] == '.' && var[1] == '\0'))
			setdot();
		if (errflg) {
			error(errflg);
			break;
		}
		prisploc();
		dispi(dot, args[0] ? args : "i", N_GSYM, 0, 0);
		lastcom = DSICOM;
		break;

	case '/':
		if (var[0] == '.' && var[1] == '\0') {
			if (integ == 0) integ = oaddr;
			dispf((ADDR) integ, args[0] ? args : odesc,
			    oclass == N_RSYM ? oclass : N_GSYM, otype, 0, 0, DSP);
			oaddr = integ;
		} else
		if (integ && (var[0] == '\0')) {
			dispf((ADDR) integ, args, N_GSYM, 0, 0, 0, DSP);
			oaddr = integ;
			cpstr(odesc, args);
			oclass = N_GSYM;
			otype = 0;
		} else
			dispvar(proc, var, args);
		lastcom = DSCOM;
		break;
		
	case '=':
		if (var[0] == '\0') {
			if (proc[0]) {
				addr = getaddr(proc, integ);
				if (addr == -1) {
					error("Unknown address");
					break;
				}
			}
			else
				addr = integ;
			dispf(addr, args[0] ? args : "x", 0, -1, 0, 0, DSP);
		} else 
			findvar(proc, var, args[0] ? args : "x", 2);
		break;

	case '!':
		if (var[0] == '\0')
			addr = getaddr(proc, integ);
		else
			addr = varaddr(proc, var);
		if (addr == -1) 
			error("Unknown variable");
		else {
			if (number(args[0]) || eqany(args[0], ".-")) {
				char *p;
				double atof();
				union {
					struct{
						int w1, w2;
					} ww;
					double d;
				} dbl;

				p = (args[0] == '-') ? args+1 : args;
				for (; *p != '.' && *p != 'e'; p++) {
					if (!number(*p)) goto l2;
				}
				dbl.d = atof(args);
				putval(addr, 'd', dbl.ww.w1);
				if (typetodesc(sl_type,0)[0] == 'g')
					putval(addr+WORDSIZE, 'd', dbl.ww.w2);
				break;
			}
l2:			if (percentflag)
				*(ADDR *)(((ADDR)&u)+addr) = argvalue(args);
			else if (sl_class == N_RSYM && addr < 16)
				putreg(addr,typetodesc(sl_type,subflag)[0],
						argvalue(args));
			else
				putval(addr,typetodesc(sl_type,subflag)[0],
						argvalue(args));
		}
		lastcom = NOCOM;
		break;

	case '"':
		printf(args);
		break;
	}
}
コード例 #8
0
ファイル: read_mdl.c プロジェクト: jterning/MCSSMTools
static int  testLgrgn(algvertptr lgrgn)
{
  preres  m;
  int n;
/*  goto_xy(1,20); print("%d           ",nLine); */
  m = (preres) readExpression(lgrgn->comcoef,rd_pre, act_preF,NULL);
  if (rderrcode )
  {  errorMessage("Factor","*");
    return 0;
  }
  m->free=1;

  if (m->tp >rationtp)
  {  errorMessage("Factor","scalar expected");
    return 0;
  }

  if (m->maxp>0)
  {  errorMessage("Factor","moments p%d are not permitable here",m->maxp);
    return 0;
  }

  for (n = 0; n < vardef->nvar; n++)
  { int err;
    err=findvar(vardef->vars[n].name,NULL,NULL);
    if (err)
    {  errorMessage("Factor","unknown variable '%s'", vardef->vars[n].name);
      return 0;
    }
  }
  
  clearVars(vardef);

   
  m=(preres) readExpression(lgrgn->description,rd_pre,act_pre,NULL);
  if(rderrcode) {  errorMessage("Lorentz part","*"); return 0; }
  m->free=1;
 
  if (m->tp == rationtp)
  {  errorMessage("Lorentz part","division is not permited here");  return 0; }

  if( (m->tp == spintp) &&( prtclbase1[lgrgn->fields[0]].spin&1 !=1) 
                        &&( prtclbase1[lgrgn->fields[1]].spin&1 !=1)
                        &&( prtclbase1[lgrgn->fields[2]].spin&1 !=1) )
  {
    errorMessage("Lorentz part","Dirac gamma matrix not expected");
    return 0;
  }

  if ((m->maxp == 4)&&(lgrgn->fields[3] == 0))
  {  errorMessage("Lorentz part","p4 are not permited here");
    return 0;
  }


  for (n = 0; n < vardef->nvar; n++)
  {  int err;
    err=findvar (vardef->vars[n].name,NULL,NULL);
    if (err)
    {  errorMessage("Lorentz part","unknown variable '%s'",vardef->vars[n].name);
      return 0;
    }
  }

  clearVars(vardef);


  for (n = 0; n <= 3; n++)
  {  int  ind1,ind2,np ;
     
     ind1=0;
     np  = lgrgn->fields[n];
     if ( np != 0 )   switch  (prtclbase[np-1].spin)
     { case 2: 
       case 3: ind1=1; break;
       case 4: ind1=3;
     }     
     
     ind2=0;
     if( (1<<n)& m->indlist)     ind2 += 1;
     if( (1<<(n+4))& m->indlist) ind2 += 2;
     
     if (ind1 != ind2 )
     {  errorMessage("Lorentz part","index 'm%d'  unbalanced",n+1);
        return 0;
     }
  }
  
  return 1;
}
コード例 #9
0
ファイル: read_mdl.c プロジェクト: jterning/MCSSMTools
static int  readparticles(int  check, int ugForce )
{  char      *ss,*endstr;
   char      fullname[60], massname[60], imassname[60], p1[60], p2[60],numtxt[20];
   char      latex[STRSIZ], latex_[STRSIZ], s[60],c[60], chlp[40];
   int       itmp,i,j, errcode,np1,np2,nparticleLimit =128;

   linelist  ln=prtcls_tab.strings;

   tabName=prtcls_tab.headln;

   if(prtclbase) { cleardecaylist(); clearLatexNames(); free(prtclbase);}
 
   prtclbase=(prtcl_base*) malloc(nparticleLimit*sizeof(prtcl_base));
   prtclbase1=prtclbase-1;	
   nparticles = 0;

   for(i=nparticles;i<nparticleLimit;i++)
           {prtclbase[i].top=NULL;prtclbase[i].latex=NULL;}
   
   nLine=1;
   while (ln != NULL)
   {  ss=ln->line;
      if (nparticles >= nparticleLimit-16)
      {  nparticleLimit+=128;
         prtclbase=re_alloc(prtclbase,nparticleLimit*sizeof(prtcl_base));
         if(!prtclbase) 
         { errorMessage(" P ","too many particles");
	   return 0;
	 }
	 prtclbase1=prtclbase-1;
         for(i=nparticles;i<nparticleLimit;i++)
               {prtclbase[i].top=NULL;prtclbase[i].latex=NULL;} 
      }

      sscanf(ss,"%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]%*c%[^|]",
	    fullname,p1,p2,numtxt,s,massname,imassname,c,chlp,latex,latex_);
      trim(p1); trim(p2); trim(latex); trim(latex_); 
      {
         static char fldName[2][5]={" P "," aP"};
         char * pName[2];
         pName[0]=p1;
         pName[1]=p2;

         for ( i=0;i<=1;i++)
         {
            if (check && (! isPrtclName(pName[i])))
            {  errorMessage(fldName[i],"incorrect particle name '%s'",pName[i]);
               return 0;
            }

            if (check )
            {
               locateinbase(pName[i],&j);
               if (j != 0)
               {
                  errorMessage(fldName[i],"duplicate particle name '%s'",pName[i]);
                  return 0;
               }
            }
         }
      }
      nparticles++;
      strcpy(prtclbase[nparticles-1].name,p1);

            
      itmp=strtol(trim(s),&endstr,10);
      if(check)
      {
         if (s+strlen(s) != endstr)
         {  errorMessage("2*spin","number expected");
            return 0 ;
         }
         if((itmp!=0)&&(itmp!=1)&&(itmp!=2)&&(itmp!=3)&&(itmp!=4))
         {  errorMessage("2*spin","value out of range");
            return 0;
         }
      }
      prtclbase[nparticles-1].spin=itmp;
      if( 1!=sscanf(numtxt,"%ld",&prtclbase[nparticles-1].N))
      {    errorMessage("number","can't read MC numeration parameter");
            return 0;
      }
      trim(massname);
      if(strcmp(massname,"0")==0)
      { if(prtclbase[nparticles-1].spin==3 || prtclbase[nparticles-1].spin==4)
         errorMessage("mass","spin 3/2 and spin 2 particles should be massive");
      }
      else 
      {  int pos;
         errcode=findvar(massname,NULL,&pos);
         if (check && (errcode != 0))
         {
            errorMessage("mass","unknown variable %s",massname);
            return 0;
         }else 
         {  if(pos>nCommonVars) nCommonVars=pos;

         } 
      }
      strcpy(prtclbase[nparticles-1].massidnt,massname);

      trim(imassname);
      
      if( check && strcmp(imassname,"0")&& !strcmp(massname,"0")) 
      {  errorMessage("width","non zero width for zero mass particle '%s'", 
            prtclbase[nparticles-1].name);
         return 0;
      }
                                       
      if(strcmp(imassname,"0") != 0)
      { 
         errcode=findvar(imassname,NULL,NULL);
         
         if(errcode)  
         {  if(imassname[0]=='!') 
            {  imassname[0]=' ';  
               trim(imassname);
               if(check && (!isVarName(imassname)) )
               {  errorMessage("width","incorrect name '%s'",imassname);
                  return 0;
               }
               if(check && (!isOriginName(imassname)) )                            
               { errorMessage("width","this identifier  '%s' already was used",imassname);
                 return 0;
               }
               { varlist mvars=modelvars+1+nmodelvar; 
                  nmodelvar++;
                  strcpy(mvars->varname,imassname);
                  mvars->func = NULL;
                  mvars->varvalue = 0.;
                  mvars->need=0;
                  mvars->hidden=0;
                  mvars->pwidth=nparticles;
               }                                                     
            }else 
            { 
               errorMessage("width","unknown variable %s",imassname);
               return 0;
            }
         }
      }
      strcpy(prtclbase[nparticles-1].imassidnt,imassname);

      itmp=strtol(trim(c),&endstr,10);
      if(check)
      {
         if (c+strlen(c) != endstr)
         {  errorMessage("color","number expected");
            return 0;
         }
         if (((itmp!=1)&&(itmp!=3)&&(itmp!=8))||((itmp==3)&&(strcmp(p1,p2)==0))  )
         {  errorMessage("color","value out of range");
            return 0;
         }
      }
      prtclbase[nparticles-1].cdim=itmp;
      trim(chlp);
      if (strcmp(chlp,"") == 0) strcpy(chlp," ");
      prtclbase[nparticles-1].hlp = toupper(chlp[0]);
      if(check)
      {  int ner;
         ner=1;
         switch(prtclbase[nparticles-1].hlp)
         {
            case ' ':if(prtclbase[nparticles-1].spin==2 &&
                        !strcmp(prtclbase[nparticles-1].massidnt,"0")
                       )
              {  errorMessage("aux","Massless vector boson must\n"
                                     " be a gauge particle");                  
                 return 0;
              }
              break;
            case 'L':
            case 'R':
              if ((prtclbase[nparticles-1].spin !=1)
               ||((prtclbase[nparticles-1].massidnt[0])!='0')
               ||(strcmp(p1,p2)==0))  ner=0;
              break;

            case '*':
              if(prtclbase[nparticles-1].massidnt[0]=='0')   ner=0;
              else if(prtclbase[nparticles-1].imassidnt[0]!='0')
              { errorMessage("aux","for aux='*' zero width is  expected"); return 0;}
              break;
            case 'G':
              if(prtclbase[nparticles-1].spin!=2)   ner=0;
              break;
            default: ner=0;
         }
         if(!ner){ errorMessage("aux","unexpeted character"); return 0;}
         if(prtclbase[nparticles-1].N==0 && prtclbase[nparticles-1].hlp!='*')
         { errorMessage("number","Zero PDG code."); return 0;}  
      }
      prtclbase[nparticles-1].latex=malloc(1+strlen(latex));
      strcpy(prtclbase[nparticles-1].latex,latex);
      
      np1 = ghostaddition();
      if (strcmp(p1,p2) == 0) prtclbase[np1-1].anti = np1;
      else
      {
        ++(nparticles);
        prtclbase[nparticles-1] = prtclbase[np1-1];
        prtclbase[nparticles-1].N *=(-1);
        strcpy(prtclbase[nparticles-1].name,p2);
        prtclbase[nparticles-1].latex=malloc(1+strlen(latex_));
        strcpy(prtclbase[nparticles-1].latex,latex_);
        if (prtclbase[np1-1].cdim == 3) prtclbase[nparticles-1].cdim = -3;
        np2=ghostaddition();
        prtclbase[np1-1].anti = np2;
        prtclbase[np2-1].anti = np1; 
      }
      ln=ln->next;
      nLine++;
   }

   for (i = 1; i <= nparticles; i++)
   {  prtcl_base *with1 = &prtclbase[i-1];
      with1->top = NULL;
      
      if (strchr("fcCtT",with1->hlp) != NULL)
      {  
         sprintf(with1->name+strlen(with1->name),".%c",with1->hlp); 
         switch (with1->hlp)
         {
            case 'c':                        
               with1->anti = prtclbase[i-1 - 1].anti +2;
               break;
            case 'C':
               with1->anti = prtclbase[i-1 - 2].anti +1;
               break;
            case 'f':
               with1->anti = prtclbase[i-1 - 3].anti +3;
               break;
            case 't':
               with1->anti = prtclbase[i-1 + 1].anti -1;
               break;               
            case 'T':
               with1->anti = prtclbase[i-1 + 2].anti -2;
               break;               
         }
      }
   }
   
   if(ugForce)for(i=1; i <= nparticles; i++) 
               if(gaugep(i) && (!zeromass(i))) prtclbase[i-1].hlp=' ';

  for(i=1;i<=nmodelvar;i++)
  if(modelvars[i].pwidth) modelvars[i].pwidth=ghostmother(modelvars[i].pwidth);
   
   return 1;
}
コード例 #10
0
ファイル: eval.c プロジェクト: ChunHungLiu/uemacs
/*
 * set a variable
 *
 * int f;		default flag
 * int n;		numeric arg (can overide prompted value)
 */
int setvar(int f, int n)
{
	int status;	/* status return */
#if	DEBUGM
	char *sp;	/* temp string pointer */
	char *ep;	/* ptr to end of outline */
#endif
	struct variable_description vd;		/* variable num/type */
	char var[NVSIZE + 1];	/* name of variable to fetch */
	char value[NSTRING];	/* value to set variable to */

	/* first get the variable to set.. */
	if (clexec == FALSE) {
		status = mlreply("Variable to set: ", &var[0], NVSIZE);
		if (status != TRUE)
			return status;
	} else {		/* macro line argument */
		/* grab token and skip it */
		execstr = token(execstr, var, NVSIZE + 1);
	}

	/* check the legality and find the var */
	findvar(var, &vd, NVSIZE + 1);

	/* if its not legal....bitch */
	if (vd.v_type == -1) {
		mlwrite("%%No such variable as '%s'", var);
		return FALSE;
	}

	/* get the value for that variable */
	if (f == TRUE)
		strcpy(value, itoa(n));
	else {
		status = mlreply("Value: ", &value[0], NSTRING);
		if (status != TRUE)
			return status;
	}

	/* and set the appropriate value */
	status = svar(&vd, value);

#if	DEBUGM
	/* if $debug == TRUE, every assignment will echo a statment to
	   that effect here. */

	if (macbug) {
		strcpy(outline, "(((");

		/* assignment status */
		strcat(outline, ltos(status));
		strcat(outline, ":");

		/* variable name */
		strcat(outline, var);
		strcat(outline, ":");

		/* and lastly the value we tried to assign */
		strcat(outline, value);
		strcat(outline, ")))");

		/* expand '%' to "%%" so mlwrite wont bitch */
		sp = outline;
		while (*sp)
			if (*sp++ == '%') {
				/* advance to the end */
				ep = --sp;
				while (*ep++);
				/* null terminate the string one out */
				*(ep + 1) = 0;
				/* copy backwards */
				while (ep-- > sp)
					*(ep + 1) = *ep;

				/* and advance sp past the new % */
				sp += 2;
			}

		/* write out the debug line */
		mlforce(outline);
		update(TRUE);

		/* and get the keystroke to hold the output */
		if (get1key() == abortc) {
			mlforce("(Macro aborted)");
			status = FALSE;
		}
	}
#endif

	/* and return it */
	return status;
}