Beispiel #1
0
/*
 * get command line flags, initialize keywords & traps.
 * get values from environment.
 * set $pid, $cflag, $*
 * fabricate bootstrap code and start it (*=(argv);. /usr/lib/rcmain $*)
 * start interpreting code
 */
int
main(int argc, char *argv[])
{
	code bootstrap[32];
	char num[12], *rcmain;
	int i;
	
	/* needed for rcmain later */
	putenv("PLAN9", unsharp("#9"));
	argc = getflags(argc, argv, "ftjSsrdiIlxepvVc:1m:1[command]", 1);
	if(argc==-1)
		usage("[file [arg ...]]");
	if(argv[0][0]=='-')
		flag['l'] = flagset;
	if(flag['I'])
		flag['i'] = 0;
	else if(flag['i']==0 && argc==1 && Isatty(0)) flag['i'] = flagset;
	rcmain = flag['m'] ? flag['m'][0] : Rcmain();
	err = openfd(2);
	kinit();
	Trapinit();
	Vinit();
	inttoascii(num, mypid = getpid());
	pathinit();
	setvar("pid", newword(num, (word *)0));
	setvar("cflag", flag['c']?newword(flag['c'][0], (word *)0)
				:(word *)0);
	setvar("rcname", newword(argv[0], (word *)0));
	i = 0;
	bootstrap[i++].i = 1;
	bootstrap[i++].f = Xmark;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s="*";
	bootstrap[i++].f = Xassign;
	bootstrap[i++].f = Xmark;
	bootstrap[i++].f = Xmark;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s="*";
	bootstrap[i++].f = Xdol;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s = rcmain;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s=".";
	bootstrap[i++].f = Xsimple;
	bootstrap[i++].f = Xexit;
	bootstrap[i].i = 0;
	start(bootstrap, 1, (var *)0);
	/* prime bootstrap argv */
	pushlist();
	argv0 = strdup(argv[0]);
	for(i = argc-1;i!=0;--i) pushword(argv[i]);
	for(;;){
		if(flag['r'])
			pfnc(err, runq);
		runq->pc++;
		(*runq->code[runq->pc-1].f)();
		if(ntrap)
			dotrap();
	}
}
Beispiel #2
0
void upsdrv_initinfo(void)
{
	if (!upsc_commandlist()) {
		upslogx(LOG_ERR, "No contact with UPS, delaying init.");
		status = UPSC_STAT_NOTINIT;
		return;
	} else {
		status = 0;
	}

	upsc_getbaseinfo();
	if (can_upda) {
		upsc_flush_input();
		upscsend("UPDA");
	}
	if (can_upid) {
		upsc_getvalue("UPID", NULL, "ACID", "ups.id", NULL);
	}
	if (can_uppm) {
		check_uppm();
	}

	/* make sure we have some sensible defaults */
	setvar("ups.delay.shutdown", "10");
	setvar("ups.delay.reboot", "60");

	upsh.instcmd = instcmd;
	upsh.setvar = setvar;
}
Beispiel #3
0
void simple_upd(struct CSRMat *Mat, struct RHS *Rhs, double sol[ncell*nvar])
{
   int icell, ivar, idir;
   double *phi, *dep, *pgrd, *CelldblPnt, *dd_i;

   // Solution update -------------------
   // (all variables except pressure)
   for(icell=0;icell<ncell;icell++) {
      phi = setvar( icell);

      memcpy( &phi[Uvar], &sol[icell*nvar+Uvar], (nvar-1)*sizeof(double));
   }

   if ( eos == IFROZENP)
      return;

   // Not sure if these two instructions are relevant ...
   boundary();
   gradients( nvar, setvar( 0), PGrd, ndep, setdep( 0));

   // Velocity coefficients -------------
   calcdd( Mat);

   // Pressure equation resolution ------
   simple_peqn();

   // SIMPLE BC -------------------------
   simple_bc();

   // PresVel corrections ---------------
   for(icell=0;icell<ncell;icell++)  {
      phi        = setvar(icell);
      CelldblPnt = setdblcell(icell);
  
      //Pressure update P = P + p'
      phi[Pvar] += 0.5 * p_sol[icell];

      //Velocity update U = u* + u'
      dd_i = setsol( icell, ndir, dd);
      pgrd = setsol( icell, ndir, p_grd);

      for (idir=0;idir<ndir;idir++)
         phi[Uvar+idir] -= CelldblPnt[CellVol] * pgrd[idir] / dd_i[idir];

#if _DBG == 10
      // Adding P' and U' to CEI plot
      dep        = setdep(icell);
      dep[Ppdep] = p_sol[icell];
      for (idir=0;idir<ndir;idir++)
         dep[Updep+idir] = -CelldblPnt[CellVol] * pgrd[idir] / dd_i[idir];
#endif
   }

   // Memory release --------------------
   free(p_sol);
   free(p_grd);
   free(dd);
}
Beispiel #4
0
	void Client::Init()
	{
	    conoutf("[DEBUG] Client::Init");
		setvar("mainmenu", false);
		setvar("hidehud", 1);

		if(!connected)
			localconnect();
	}
Beispiel #5
0
void AgiEngine::selectItems(int n) {
	int fsel = 0;
	bool exit_select = false;

	while (!exit_select && !(shouldQuit() || _restartGame)) {
		if (n > 0)
			printItem(fsel, STATUS_BG, STATUS_FG);

		switch (waitAnyKey()) {
		case KEY_ENTER:
			setvar(vSelItem, _intobj[fsel]);
			exit_select = true;
			break;
		case KEY_ESCAPE:
			setvar(vSelItem, 0xff);
			exit_select = true;
			break;
		case KEY_UP:
			if (fsel >= 2)
				fsel -= 2;
			break;
		case KEY_DOWN:
			if (fsel + 2 < n)
				fsel += 2;
			break;
		case KEY_LEFT:
			if (fsel % 2 == 1)
				fsel--;
			break;
		case KEY_RIGHT:
			if (fsel % 2 == 0 && fsel + 1 < n)
				fsel++;
			break;
		case BUTTON_LEFT:{
				int i = findItem();
				if (i >= 0 && i < n) {
					setvar(vSelItem, _intobj[fsel = i]);
					debugC(6, kDebugLevelInventory, "item found: %d", fsel);
					showItems();
					printItem(fsel, STATUS_BG, STATUS_FG);
					_gfx->doUpdate();
					exit_select = true;
				}
				break;
			}
		default:
			break;
		}

		if (!exit_select) {
			showItems();
			_gfx->doUpdate();
		}
	}

	debugC(6, kDebugLevelInventory, "selected: %d", fsel);
}
Beispiel #6
0
/** handle one line of the read command.
 *  more fields than variables -> remainder shall be part of last variable.
 *  less fields than variables -> remaining variables unset.
 *
 *  @param line complete line of input
 *  @param ap argument (variable) list
 *  @param len length of line including trailing '\0'
 */
static void
readcmd_handle_line(char *s, char **ap)
{
	struct arglist arglist;
	struct strlist *sl;
	char *backup;
	char *line;

	/* ifsbreakup will fiddle with stack region... */
	line = stackblock();
	s = grabstackstr(s);

	/* need a copy, so that delimiters aren't lost
	 * in case there are more fields than variables */
	backup = sstrdup(line);

	arglist.lastp = &arglist.list;
	
	ifsbreakup(s, &arglist);
	*arglist.lastp = NULL;
	ifsfree();

	sl = arglist.list;

	do {
		if (!sl) {
			/* nullify remaining arguments */
			do {
				setvar(*ap, nullstr, 0);
			} while (*++ap);

			return;
		}

		/* remaining fields present, but no variables left. */
		if (!ap[1] && sl->next) {
			size_t offset;
			char *remainder;

			/* FIXME little bit hacky, assuming that ifsbreakup 
			 * will not modify the length of the string */
			offset = sl->text - s;
			remainder = backup + offset;
			rmescapes(remainder);
			setvar(*ap, remainder, 0);

			return;
		}
		
		/* set variable to field */
		rmescapes(sl->text);
		setvar(*ap, sl->text, 0);
		sl = sl->next;
	} while (*++ap);
}
Beispiel #7
0
static void select_items(int n) {
	int fsel = 0;

	while (42) {
		if (n > 0)
			print_item(fsel, STATUS_BG, STATUS_FG);

		switch (wait_any_key()) {
		case KEY_ENTER:
			setvar(V_sel_item, intobj[fsel]);
			goto exit_select;
		case KEY_ESCAPE:
			setvar(V_sel_item, 0xff);
			goto exit_select;
		case KEY_UP:
			if (fsel >= 2)
				fsel -= 2;
			break;
		case KEY_DOWN:
			if (fsel + 2 < n)
				fsel += 2;
			break;
		case KEY_LEFT:
			if (fsel % 2 == 1)
				fsel--;
			break;
		case KEY_RIGHT:
			if (fsel % 2 == 0 && fsel + 1 < n)
				fsel++;
			break;
		case BUTTON_LEFT:{
				int i = find_item();
				if (i >= 0 && i < n) {
					setvar(V_sel_item, intobj[fsel = i]);
					debugC(6, kDebugLevelInventory, "item found: %d", fsel);
					show_items();
					print_item(fsel, STATUS_BG, STATUS_FG);
					do_update();
					goto exit_select;
				}
				break;
			}
		default:
			break;
		}

		show_items();
		do_update();
	}

 exit_select:
	debugC(6, kDebugLevelInventory, "selected: %d", fsel);
}
Beispiel #8
0
int TextMan::print(const char *p, int lin, int col, int len) {
	if (p == NULL)
		return 0;

	debugC(4, kDebugLevelText, "lin = %d, col = %d, len = %d", lin, col, len);

	if (col == 0 && lin == 0 && len == 0)
		lin = col = -1;

	if (len == 0)
		len = 30;

	blit_textbox(p, lin, col, len);

	if (getflag(F_output_mode)) {
		/* non-blocking window */
		setflag(F_output_mode, false);
		return 1;
	}

	/* blocking */

	if (game.vars[V_window_reset] == 0) {
		int k;
		setvar(V_key, 0);
		k = wait_key();
		close_window();
		return k;
	}

	/* timed window */

	debugC(3, kDebugLevelText, "f15==0, v21==%d => timed", getvar(21));
	game.msg_box_ticks = getvar(V_window_reset) * 10;
	setvar(V_key, 0);

	do {
		main_cycle();
		if (game.keypress == KEY_ENTER) {
			debugC(4, kDebugLevelText, "KEY_ENTER");
			setvar(V_window_reset, 0);
			game.keypress = 0;
			break;
		}
	} while (game.msg_box_ticks > 0);

	setvar(V_window_reset, 0);

	close_window();

	return 0;
}
Beispiel #9
0
	void Client::editMode(bool on)
	{
		if(on)
		{
			setvar("hidehud", 0);
			setvar("grabinput", 1);
		}
		else
		{
			setvar("hidehud", 1);
			setvar("grabinput", 0);
		}
	}
Beispiel #10
0
static void uefirtvariable_env_cleanup(void)
{
	uint64_t status;
	uint8_t data[getvar_buf_size];
	uint64_t getdatasize = sizeof(data);
	uint32_t attributestest;

	long ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
	if (ioret != -1 && status == EFI_SUCCESS) {
		setvar(&gtestguid, attributes, sizeof(AuthVarDel), AuthVarDel, &status);
		setvar(&gtestguid, attributes, sizeof(AuthVarDelDiff), AuthVarDelDiff, &status);
	}
	return;
}
Beispiel #11
0
Datei: user.c Projekt: erukiti/ma
void	ulist_set(uint i,var_t *v)
{
	sion_sr("user",lpu(i,0));
	clrvar(v);
	sion_read(v);
/* varview(v);*/

	setvar("post"  ,lpu(ulist_getpost  (i),0),v);
	setvar("mpost" ,lpu(ulist_getmpost (i),0),v);
	setvar("login" ,lpu(ulist_getlogin (i),0),v);
	setvar("mlogin",lpu(ulist_getmlogin(i),0),v);
	setvar("wp"    ,lpu(ulist_getwp    (i),0),v);

	sion_write(NULL,v);
}
Beispiel #12
0
void connectserv(const char *servername, int serverport, const char *serverpassword)
{
    if(connpeer)
    {
        conoutf("aborting connection attempt");
        abortconnect();
    }

    if(serverport <= 0) serverport = server::serverport();

    ENetAddress address;
    address.port = serverport;

    if(servername)
    {
        if(strcmp(servername, connectname)) setsvar("connectname", servername);
        if(serverport != connectport) setvar("connectport", serverport);
        conoutf("attempting to connect to %s:%d", servername, serverport);
        if(!resolverwait(servername, &address))
        {
            conoutf("\f3could not resolve server %s", servername);
            return;
        }
    }
    else
    {
        setsvar("connectname", "");
        setvar("connectport", 0);
        conoutf("attempting to connect over LAN");
        address.host = ENET_HOST_BROADCAST;
    }

    if(!clienthost)
    {
        clienthost = enet_host_create(NULL, 2, server::numchannels(), rate*1024, rate*1024);
        if(!clienthost)
        {
            conoutf("\f3could not connect to server");
            return;
        }
        clienthost->duplicatePeers = 0;
    }

    connpeer = enet_host_connect(clienthost, &address, server::numchannels(), 0);
    enet_host_flush(clienthost);
    connmillis = totalmillis;
    connattempts = 0;
}
Beispiel #13
0
void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid) {

#ifdef TOOLS_ENABLED

	_edited = true;
#endif

	if (script_instance) {

		if (script_instance->set(p_name, p_value)) {
			if (r_valid)
				*r_valid = true;
			return;
		}
	}

	//try built-in setgetter
	{
		if (ClassDB::set_property(this, p_name, p_value, r_valid)) {
			/*
			if (r_valid)
				*r_valid=true;
			*/
			return;
		}
	}

	if (p_name == CoreStringNames::get_singleton()->_script) {
		set_script(p_value);
		if (r_valid)
			*r_valid = true;
		return;

	} else if (p_name == CoreStringNames::get_singleton()->_meta) {
		//set_meta(p_name,p_value);
		metadata = p_value;
		if (r_valid)
			*r_valid = true;
		return;
#ifdef TOOLS_ENABLED
	} else if (p_name == CoreStringNames::get_singleton()->_sections_unfolded) {
		Array arr = p_value;
		for (int i = 0; i < arr.size(); i++) {
			editor_section_folding.insert(arr[i]);
		}
		if (r_valid)
			*r_valid = true;
		return;
#endif
	} else {
		//something inside the object... :|
		bool success = _setv(p_name, p_value);
		if (success) {
			if (r_valid)
				*r_valid = true;
			return;
		}
		setvar(p_name, p_value, r_valid);
	}
}
Beispiel #14
0
static void
evalfor(union node *n, int flags)
{
	struct arglist arglist;
	union node *argp;
	int i;
	int status;

	emptyarglist(&arglist);
	for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
		oexitstatus = exitstatus;
		expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
	}

	loopnest++;
	status = 0;
	for (i = 0; i < arglist.count; i++) {
		setvar(n->nfor.var, arglist.args[i], 0);
		evaltree(n->nfor.body, flags);
		status = exitstatus;
		if (evalskip) {
			if (evalskip == SKIPCONT && --skipcount <= 0) {
				evalskip = 0;
				continue;
			}
			if (evalskip == SKIPBREAK && --skipcount <= 0)
				evalskip = 0;
			break;
		}
	}
	loopnest--;
	exitstatus = status;
}
Beispiel #15
0
/*
 * Set the created authenticated variable, AuthVarCreate,
 * and checking the data size and data.
 * expect EFI_SUCCESS returned.
 */
static int uefirtauthvar_test1(fwts_framework *fw)
{
	long ioret;

	uint8_t data[getvar_buf_size];
	uint64_t getdatasize = sizeof(data);
	uint64_t status;
	uint32_t attributestest;
	size_t i;

	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFICreateAuthVar",
			"Failed to create authenticated variable with UEFI "
			"runtime service.");

		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}

	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
	if (ioret == -1) {
		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFICreateAuthVar",
			"Failed to get authenticated variable with UEFI "
			"runtime service.");
		fwts_uefi_print_status_info(fw, status);
		return FWTS_ERROR;
	}
	if (getdatasize != sizeof(AuthVarCreateData)) {
		fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFICreateAuthVar",
			"Get authenticated variable data size is not the "
			"same as it set.");
		return FWTS_ERROR;
	}

	for (i = 0; i < sizeof(AuthVarCreateData); i++) {
		if (data[i] != AuthVarCreateData[i]) {
			fwts_failed(fw, LOG_LEVEL_HIGH,
			"UEFICreateAuthVar",
			"Get authenticated variable data are not the "
			"same as it set.");
			return FWTS_ERROR;
		}
	}

	data_exist |= E_AUTHVARCREATE;

	fwts_passed(fw, "Create authenticated variable test passed.");

	return FWTS_OK;
}
Beispiel #16
0
static int
subevalvar_misc(char *p, const char *var, int subtype, int startloc,
  int varflags)
{
	char *startp;
	struct nodelist *saveargbackq = argbackq;
	int amount;

	argstr(p, EXP_TILDE, NULL);
	STACKSTRNUL(expdest);
	argbackq = saveargbackq;
	startp = stackblock() + startloc;

	switch (subtype) {
	case VSASSIGN:
		setvar(var, startp, 0);
		amount = startp - expdest;
		STADJUST(amount, expdest);
		return 1;

	case VSQUESTION:
		if (*p != CTLENDVAR) {
			outfmt(out2, "%s\n", startp);
			error((char *)NULL);
		}
		error("%.*s: parameter %snot set", (int)(p - var - 1),
		      var, (varflags & VSNUL) ? "null or " : "");
		return 0;

	default:
		abort();
	}
}
Beispiel #17
0
/*
 * The authenticated variable is followed EFI_VARIABLE_AUTHENTICATION_2 descriptor,
 * set the authenticated variable with invalid
 * EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS instead of
 * EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute should
 * return EFI_SECURITY_VIOLATION.
 */
static int uefirtauthvar_test11(fwts_framework *fw)
{
	long ioret;

	uint64_t status;
	uint32_t attr = FWTS_UEFI_VAR_NON_VOLATILE |
			FWTS_UEFI_VAR_BOOTSERVICE_ACCESS |
			FWTS_UEFI_VAR_RUNTIME_ACCESS |
			FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS;

	ioret = setvar(&gtestguid, attr, sizeof(AuthVarCreate), AuthVarCreate, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		if (status == EFI_SECURITY_VIOLATION) {
			fwts_passed(fw, "Set authenticated variable test with invalid attributes passed.");
			return FWTS_OK;
		}

		fwts_failed(fw, LOG_LEVEL_MEDIUM,
			"UEFISetAuthVarInvalidAttr",
			"Set authenticated variable fail");
			fwts_uefi_print_status_info(fw, status);
	}

	fwts_failed(fw, LOG_LEVEL_HIGH,
		"UEFISetAuthVarInvalidAttr",
		"Set authenticated variable expected fail but success");

	return FWTS_ERROR;
}
Beispiel #18
0
/*
 * Set the authenticated variable with different guid, expect
 * EFI_SECURITY_VIOLATION returned.
 */
static int uefirtauthvar_test10(fwts_framework *fw)
{
	long ioret;
	uint64_t status;
	EFI_GUID gtestguiddiff = TEST_GUID1;

	ioret = setvar(&gtestguiddiff, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		if (status == EFI_SECURITY_VIOLATION) {
			fwts_passed(fw, "Set authenticated variable test with different guid passed.");
			return FWTS_OK;
		}

		fwts_failed(fw, LOG_LEVEL_MEDIUM,
			"UEFISetAuthVarDiffGuid",
			"Set authenticated variable fail");
			fwts_uefi_print_status_info(fw, status);
	}

	fwts_failed(fw, LOG_LEVEL_HIGH,
		"UEFISetAuthVarDiffGuid",
		"Set authenticated variable expected fail but success");

	return FWTS_ERROR;
}
Beispiel #19
0
/*
 * Set the authenticated variable with invalid modified timestamp, expect
 * EFI_SECURITY_VIOLATION returned.
 */
static int uefirtauthvar_test9(fwts_framework *fw)
{
	long ioret;
	uint64_t status;

	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarModTime), AuthVarModTime, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		if (status == EFI_SECURITY_VIOLATION) {
			fwts_passed(fw, "Set authenticated variable test with invalid modified timestamp passed.");
			return FWTS_OK;
		}

		fwts_failed(fw, LOG_LEVEL_MEDIUM,
			"UEFISetAuthVarInvalidTime",
			"Set authenticated variable fail");
			fwts_uefi_print_status_info(fw, status);
	}

	fwts_failed(fw, LOG_LEVEL_HIGH,
		"UEFISetAuthVarInvalidTime",
		"Set authenticated variable expected fail but success");

	return FWTS_ERROR;
}
Beispiel #20
0
/*
 * After updated, set the old data and timestamp authenticated variable,
 * AuthVarCreate, expect EFI_SECURITY_VIOLATION returned.
 */
static int uefirtauthvar_test6(fwts_framework *fw)
{
	long ioret;
	uint64_t status;

	if (!(data_exist & E_AUTHVARUPDATE)) {
		fwts_skipped(fw,"The test variable, AuthVarUpdate, doesn't exist, skip the test.");
		return FWTS_SKIP;
	}

	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);

	if (ioret == -1) {
		int supcheck = check_fw_support(fw, status);

		if (supcheck != FWTS_OK)
			return supcheck;

		if (status == EFI_SECURITY_VIOLATION) {
			fwts_passed(fw, "Authenticated variable test with old authenticated variable passed.");
			return FWTS_OK;
		}

		fwts_failed(fw, LOG_LEVEL_MEDIUM,
			"UEFISetOldAuthVar",
			"Set authenticated variable fail");
			fwts_uefi_print_status_info(fw, status);
	}

	fwts_failed(fw, LOG_LEVEL_HIGH,
		"UEFISetOldAuthVar",
		"Set authenticated variable expected fail but success");

	return FWTS_ERROR;
}
Beispiel #21
0
void disconnect(bool async, bool cleanup)
{
    if(curpeer)
    {
        if(!discmillis)
        {
            enet_peer_disconnect(curpeer, DISC_NONE);
            enet_host_flush(clienthost);
            discmillis = totalmillis;
        }
        if(curpeer->state!=ENET_PEER_STATE_DISCONNECTED)
        {
            if(async) return;
            enet_peer_reset(curpeer);
        }
        curpeer = NULL;
        discmillis = 0;
        conoutf("disconnected");
        game::gamedisconnect(cleanup);
        setvar("mainmenu", 1);
    }
    if(!connpeer && clienthost)
    {
        enet_host_destroy(clienthost);
        clienthost = NULL;
    }
}
Beispiel #22
0
static void
setwakeup(void)
{
	register Seconds_t	t;
	register Seconds_t	now;
	int			level;

	now = CURSECS;
	if (!trap.alarms)
		t = 0;
	else if (trap.alarms->time <= now)
		t = 1;
	else
		t = trap.alarms->time - now;
	alarm(t);
	sfsprintf(tmpname, MAXNAME, "%lu", t ? (now + t) : t);
	setvar(internal.alarm->name, fmtelapsed(t, 1), 0);
	if (error_info.trace <= (level = (state.test & 0x00010000) ? 2 : CMDTRACE))
	{
		register Alarms_t*	a;

		if (a = trap.alarms)
		{
			error(level, "ALARM  TIME                 RULE");
			do
			{
				error(level, "%6s %s %s", fmtelapsed((a->time >= now) ? (a->time - now) : 0, 1), timestr(tmxsns(a->time, 0)), a->rule->name);
			} while (a = a->next);
		}
		else
			error(level, "ALARM -- NONE");
	}
}
Beispiel #23
0
static int set_variable (lua_State *L)
{
  const char* vname = luaL_checkstring(L, 1);
  const char* vvalue = luaL_checkstring(L, 2);
  setvar(vname, vvalue);
  return 0;
}
Beispiel #24
0
void
readenv(void)
{
	char **p, *s;
	Word *w;

	for(p = environ; *p; p++){
/* rsc 5/5/2004 -- This misparses fn#cd={whatever} 
		s = shname(*p);
		if(*s == '=') {
			*s = 0;
			w = newword(s+1);
		} else
			w = newword("");
*/
		s = strchr(*p, '=');
		if(s){
			*s = 0;
			w = newword(s+1);
		} else
			w = newword("");
		if (symlook(*p, S_INTERNAL, 0))
			continue;
		s = strdup(*p);
		setvar(s, (void *)w);
		symlook(s, S_EXPORTED, (void*)"")->u.ptr = "";
	}
}
Beispiel #25
0
int
unsetvar(shinstance *psh, const char *s, int unexport)
{
    struct var **vpp;
    struct var *vp;

    vp = find_var(psh, s, &vpp, NULL);
    if (vp == NULL)
        return 1;

    if (vp->flags & VREADONLY)
        return (1);

    INTOFF;
    if (unexport) {
        vp->flags &= ~VEXPORT;
    } else {
        if (vp->text[vp->name_len + 1] != '\0')
            setvar(psh, s, nullstr, 0);
        vp->flags &= ~VEXPORT;
        vp->flags |= VUNSET;
        if ((vp->flags & VSTRFIXED) == 0) {
            if ((vp->flags & VTEXTFIXED) == 0)
                ckfree(psh, vp->text);
            *vpp = vp->next;
            ckfree(psh, vp);
        }
    }
    INTON;
    return 0;
}
Beispiel #26
0
int
exportcmd(shinstance *psh, int argc, char **argv)
{
    struct var *vp;
    char *name;
    const char *p;
    int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
    int pflag;

    pflag = nextopt(psh, "p") == 'p' ? 3 : 0;
    if (argc <= 1 || pflag) {
        showvars(psh, pflag ? argv[0] : 0, flag, pflag );
        return 0;
    }

    while ((name = *psh->argptr++) != NULL) {
        if ((p = strchr(name, '=')) != NULL) {
            p++;
        } else {
            vp = find_var(psh, name, NULL, NULL);
            if (vp != NULL) {
                vp->flags |= flag;
                continue;
            }
        }
        setvar(psh, name, p, flag);
    }
    return 0;
}
Beispiel #27
0
static void
evalfor(union node *n, int flags)
{
	struct arglist arglist;
	union node *argp;
	struct strlist *sp;
	int status;

	arglist.lastp = &arglist.list;
	for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
		oexitstatus = exitstatus;
		expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
	}
	*arglist.lastp = NULL;

	loopnest++;
	status = 0;
	for (sp = arglist.list ; sp ; sp = sp->next) {
		setvar(n->nfor.var, sp->text, 0);
		evaltree(n->nfor.body, flags);
		status = exitstatus;
		if (evalskip) {
			if (evalskip == SKIPCONT && --skipcount <= 0) {
				evalskip = 0;
				continue;
			}
			if (evalskip == SKIPBREAK && --skipcount <= 0)
				evalskip = 0;
			break;
		}
	}
	loopnest--;
	exitstatus = status;
}
Beispiel #28
0
//Operations to perform before solving the system
void pv_adjustment(struct CSRMat *Mat, struct RHS *Rhs, double sol[ncell*nvar])
{
   int icell;
   double *phi;

   // Copying VAR to SOL
   phi = setvar( 0); 
   memcpy( sol, phi, ncell*nvar* sizeof(double));

   // Modifications due to alghorithms 
   switch (eos) {
   case ISIMPLE:
   case ISIMPLEC:
   case IPISO:
   case IFROZENP:
      for (icell=0;icell<ncell;icell++) 
         sol[icell*nvar+Pvar] = 0.0;
      break;
   case ICOUPLED:
      coupled_press( Mat, Rhs);
      break;
   case IDBIG:
      break;
   }
}
Beispiel #29
0
void connectserv(const char *name, int port, const char *password)
{
    abortconnect();
    if(!port) port = ENG_SERVER_PORT;

    ENetAddress address;
    address.port = port;

    setsvar("serveraddress", "");
    setvar("serverconport", 0);
    if(name && *name)
    {
        addserver(name, port);
        conoutft(CON_MESG, "\faattempting to connect to %s:[%d]", name, port);
        if(!resolverwait(name, &address))
        {
            conoutft(CON_MESG, "\frcould not resolve host %s", name);
            connectfail();
            return;
        }
        setsvar("serveraddress", name);
        setvar("serverconport", port);
    }
    else
    {
        conoutft(CON_MESG, "\faattempting to connect to a local server");
        address.host = ENET_HOST_BROADCAST;
    }

    if(!clienthost)
        clienthost = enet_host_create(NULL, 2, server::numchannels(), rate, rate);

    if(clienthost)
    {
        connpeer = enet_host_connect(clienthost, &address, server::numchannels(), 0);
        enet_host_flush(clienthost);
        connmillis = totalmillis;
        connattempts = 0;
        client::connectattempt(name ? name : "", port, password ? password : "", address);
        conoutft(CON_MESG, "\fgconnecting to %s:[%d]", name != NULL ? name : "local server", port);
    }
    else
    {
        conoutft(CON_MESG, "\frfailed creating client socket");
        connectfail();
    }
}
Beispiel #30
0
int settingsInit(){
	mpfr_t set;
	mpfr_init(set);
	mpfr_set_si( set, 20, MPFR_RNDN);
	if( setvar( "precision", set)){
		FREE;
		return 1;
	}
	mpfr_set_si( set, 10, MPFR_RNDN);
	if( setvar( "base", set)){
		FREE;
		return 1;
	}

	FREE;
	return 0;
}