Example #1
0
const char *stringvalue(const svalue_t & v)
{
	static char buffer[256];
	
	switch(v.type)
    {
	case svt_string:
		return v.string;
		
	case svt_mobj:
		// return the class name
		return (const char *)v.value.mobj->GetClass()->TypeName;
		
	case svt_fixed:
		{
			double val = v.value.f / 65536.;
			mysnprintf(buffer, countof(buffer), "%g", val);
			return buffer;
		}
		
	case svt_int:
	default:
        mysnprintf(buffer, countof(buffer), "%i", v.value.i);
		return buffer;	
    }
}
Example #2
0
const char *FBaseCVar::ToString (UCVarValue value, ECVarType type)
{
	switch (type)
	{
	case CVAR_Bool:
		return value.Bool ? truestr : falsestr;

	case CVAR_String:
		return value.String;

	case CVAR_Int:
		mysnprintf (cstrbuf, countof(cstrbuf), "%i", value.Int);
		break;

	case CVAR_Float:
		mysnprintf (cstrbuf, countof(cstrbuf), "%g", value.Float);
		break;

	case CVAR_GUID:
		FormatGUID (cstrbuf, countof(cstrbuf), *value.pGUID);
		break;

	default:
		strcpy (cstrbuf, "<huh?>");
		break;
	}
	return cstrbuf;
}
Example #3
0
void VMDumpConstants(FILE *out, const VMScriptFunction *func)
{
	char tmp[21];
	int i, j, k, kk;

	if (func->KonstD != NULL && func->NumKonstD != 0)
	{
		printf_wrapper(out, "\nConstant integers:\n");
		kk = (func->NumKonstD + 3) / 4;
		for (i = 0; i < kk; ++i)
		{
			for (j = 0, k = i; j < 4 && k < func->NumKonstD; j++, k += kk)
			{
				mysnprintf(tmp, countof(tmp), "%3d. %d", k, func->KonstD[k]);
				printf_wrapper(out, "%-20s", tmp);
			}
			printf_wrapper(out, "\n");
		}
	}
	if (func->KonstF != NULL && func->NumKonstF != 0)
	{
		printf_wrapper(out, "\nConstant floats:\n");
		kk = (func->NumKonstF + 3) / 4;
		for (i = 0; i < kk; ++i)
		{
			for (j = 0, k = i; j < 4 && k < func->NumKonstF; j++, k += kk)
			{
				mysnprintf(tmp, countof(tmp), "%3d. %.16f", k, func->KonstF[k]);
				printf_wrapper(out, "%-20s", tmp);
			}
			printf_wrapper(out, "\n");
		}
	}
	if (func->KonstA != NULL && func->NumKonstA != 0)
	{
		printf_wrapper(out, "\nConstant addresses:\n");
		kk = (func->NumKonstA + 3) / 4;
		for (i = 0; i < kk; ++i)
		{
			for (j = 0, k = i; j < 4 && k < func->NumKonstA; j++, k += kk)
			{
				mysnprintf(tmp, countof(tmp), "%3d. %p:%d", k, func->KonstA[k].v, func->KonstATags()[k]);
				printf_wrapper(out, "%-20s", tmp);
			}
			printf_wrapper(out, "\n");
		}
	}
	if (func->KonstS != NULL && func->NumKonstS != 0)
	{
		printf_wrapper(out, "\nConstant strings:\n");
		for (i = 0; i < func->NumKonstS; ++i)
		{
			printf_wrapper(out, "%3d. %s\n", i, func->KonstS[i].GetChars());
		}
	}
}
Example #4
0
static void DrawCoordinates(player_t * CPlayer)
{
	DVector3 pos;
	char coordstr[18];
	int h = SmallFont->GetHeight()+1;

	
	if (!map_point_coordinates || !automapactive) 
	{
		pos = CPlayer->mo->Pos();
	}
	else 
	{
		DVector2 apos = AM_GetPosition();
		double z = P_PointInSector(apos)->floorplane.ZatPoint(apos);
		pos = DVector3(apos, z);
	}

	int vwidth, vheight;
	if (active_con_scaletext() == 0)
	{
		vwidth = SCREENWIDTH / 2;
		vheight = SCREENHEIGHT / 2;
	}
	else
	{
		vwidth = SCREENWIDTH / active_con_scaletext();
		vheight = SCREENHEIGHT / active_con_scaletext();
	}

	int xpos = vwidth - SmallFont->StringWidth("X: -00000")-6;
	int ypos = 18;

	screen->DrawText(SmallFont, hudcolor_titl, vwidth - 6 - SmallFont->StringWidth(level.MapName), ypos, level.MapName,
		DTA_KeepRatio, true,
		DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);

	screen->DrawText(SmallFont, hudcolor_titl, vwidth - 6 - SmallFont->StringWidth(level.LevelName), ypos + h, level.LevelName,
		DTA_KeepRatio, true,
		DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);

	mysnprintf(coordstr, countof(coordstr), "X: %d", int(pos.X));
	screen->DrawText(SmallFont, hudcolor_xyco, xpos, ypos+2*h, coordstr,
		DTA_KeepRatio, true,
		DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);

	mysnprintf(coordstr, countof(coordstr), "Y: %d", int(pos.Y));
	screen->DrawText(SmallFont, hudcolor_xyco, xpos, ypos+3*h, coordstr,
		DTA_KeepRatio, true,
		DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);

	mysnprintf(coordstr, countof(coordstr), "Z: %d", int(pos.Z));
	screen->DrawText(SmallFont, hudcolor_xyco, xpos, ypos+4*h, coordstr,
		DTA_KeepRatio, true,
		DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
}
Example #5
0
static void OpenExprType(FLispString &out, EZCCExprType type)
{
	char buf[32];

	if (unsigned(type) < PEX_COUNT_OF)
	{
		mysnprintf(buf, countof(buf), "expr %d", type);
	}
	else
	{
		mysnprintf(buf, countof(buf), "bad-pex-%u", type);
	}
	out.Open(buf);
}
Example #6
0
	void AddInt(int i, bool un=false)
	{
		char buf[16];
		size_t len;
		if (!un)
		{
			len = mysnprintf(buf, countof(buf), "%d", i);
		}
		else
		{
			len = mysnprintf(buf, countof(buf), "%uu", i);
		}
		Add(buf, len);
	}
Example #7
0
static void example_read_html(
	struct arena* win, struct style* sty,
	struct actor* act, struct pinid* pin)
{
	int len = win->len;
	u8* buf = win->buf;

	len += mysnprintf(
		buf+len, 0x100000-len,
		"<div id=\"example\" style=\"width:50%%;height:100px;float:left;background-color:#82a977;\">"
	);
	len += mysnprintf(buf+len, 0x100000-len, "</div>\n");

	win->len = len;
}
Example #8
0
// Like DoGameSetup(), but for mod-specific cvars.
// Called after CVARINFO has been parsed.
void FGameConfigFile::DoModSetup(const char *gamename)
{
	mysnprintf(section, countof(section), "%s.Player.Mod", gamename);
	if (SetSection(section))
	{
		ReadCVars(CVAR_MOD|CVAR_USERINFO|CVAR_IGNORE);
	}
	mysnprintf(section, countof(section), "%s.LocalServerInfo.Mod", gamename);
	if (SetSection (section))
	{
		ReadCVars (CVAR_MOD|CVAR_SERVERINFO|CVAR_IGNORE);
	}
	// Signal that these sections should be rewritten when saving the config.
	bModSetup = true;
}
Example #9
0
FString level_info_t::LookupLevelName()
{
	if (flags & LEVEL_LOOKUPLEVELNAME)
	{
		const char *thename;
		const char *lookedup;

		lookedup = GStrings[LevelName];
		if (lookedup == NULL)
		{
			thename = LevelName;
		}
		else
		{
			char checkstring[32];

			// Strip out the header from the localized string
			if (MapName.Len() > 3 && MapName[0] == 'E' && MapName[2] == 'M')
			{
				mysnprintf (checkstring, countof(checkstring), "%s: ", MapName.GetChars());
			}
			else if (MapName.Len() > 3 && MapName[0] == 'M' && MapName[1] == 'A' && MapName[2] == 'P')
			{
				mysnprintf (checkstring, countof(checkstring), "%d: ", atoi(&MapName[3]));
			}
			else if (MapName.Len() > 5 && MapName[0] == 'L' && MapName[1] == 'E' && MapName[2] == 'V' && MapName[3] == 'E' && MapName[4] == 'L')
			{
				mysnprintf (checkstring, countof(checkstring), "%d: ", atoi(&MapName[5]));
			}
			else
			{
				// make sure nothing is stripped.
				checkstring[0] = '\0';
			}
			thename = strstr (lookedup, checkstring);
			if (thename == NULL)
			{
				thename = lookedup;
			}
			else
			{
				thename += strlen (checkstring);
			}
		}
		return thename;
	}
	else return LevelName;
}
Example #10
0
// Moved from DoGameSetup so that it can happen after wads are loaded
void FGameConfigFile::DoKeySetup(const char *gamename)
{
	static const struct { const char *label; FKeyBindings *bindings; } binders[] =
	{
		{ "Bindings", &Bindings },
		{ "DoubleBindings", &DoubleBindings },
		{ "AutomapBindings", &AutomapBindings },
		{ NULL, NULL }
	};
	const char *key, *value;

	sublen = countof(section) - 1 - mysnprintf(section, countof(section), "%s.", gamename);
	subsection = section + countof(section) - sublen - 1;
	section[countof(section) - 1] = '\0';

	C_SetDefaultBindings ();

	for (int i = 0; binders[i].label != NULL; ++i)
	{
		strncpy(subsection, binders[i].label, sublen);
		if (SetSection(section))
		{
			FKeyBindings *bindings = binders[i].bindings;
			bindings->UnbindAll();
			while (NextInSection(key, value))
			{
				bindings->DoBind(key, value);
			}
		}
	}
}
Example #11
0
static char* format_delay(ptpdt_t *dt, char *ptr, uint32_t sz)
{
    if(dt->s)
    {
        ptr += mysnprintf(ptr, sz, "%d", dt->s);
        *ptr++ = 's';
    }
    else
    {
        ptr += mysnprintf(ptr, sz, "%d", dt->ns);
        *ptr++ = 'n';
        *ptr++ = 's';
    }
    *ptr = 0;
    return ptr;
}
Example #12
0
int bd_send_button_text(const struct board_t *board, int button, const char *text) {
    char buffer[BUFFER_SIZE];
    int len = mysnprintf(buffer, BUFFER_SIZE, "#T%1.1x:%s" CRLF, button & 0xf, text);
    if (bd_send_command(board, buffer, len, BUFFER_SIZE) > 0)
        return is_ok(buffer);
    return -1;
}
Example #13
0
int bd_send_button_states(const struct board_t *board, int button) {
    char buffer[BUFFER_SIZE];
    int len = mysnprintf(buffer, BUFFER_SIZE, "#C%2.2x" CRLF, button & 0xff);
    if (bd_send_command(board, buffer, len, BUFFER_SIZE) > 0)
        return is_ok(buffer);
    return -1;
}
Example #14
0
int bd_send_line(const struct board_t *board, int line, const char* str) {
    char buffer[BUFFER_SIZE];
    int len = mysnprintf(buffer, BUFFER_SIZE, "#L%2.2x:%s" CRLF, line, str);
    if (bd_send_command(board, buffer, len, BUFFER_SIZE) > 0 )
        return is_ok(buffer);
    return -1;
}
Example #15
0
int bd_disconnect(const struct board_t *board) {
    char buffer[BUFFER_SIZE];
    int len = mysnprintf(buffer, BUFFER_SIZE, "#Q" CRLF);
    int res = bd_send_command(board, buffer, len, BUFFER_SIZE);
    close(board->socket);
    return res == 0;
}
Example #16
0
void FGameConfigFile::AddAutoexec (FArgs *list, const char *game)
{
	char section[64];
	const char *key;
	const char *value;

	mysnprintf (section, countof(section), "%s.AutoExec", game);

	// If <game>.AutoExec section does not exist, create it
	// with a default autoexec.cfg file present.
	CreateStandardAutoExec(section, false);
	// Run any files listed in the <game>.AutoExec section
	if (!SectionIsEmpty())
	{
		while (NextInSection (key, value))
		{
			if (stricmp (key, "Path") == 0 && *value != '\0')
			{
				FString expanded_path = ExpandEnvVars(value);
				if (FileExists(expanded_path))
				{
					list->AppendArg (ExpandEnvVars(value));
				}
			}
		}
	}
}
Example #17
0
UCVarValue FBaseCVar::FromFloat (float value, ECVarType type)
{
	UCVarValue ret;

	switch (type)
	{
	case CVAR_Bool:
		ret.Bool = value != 0.f;
		break;

	case CVAR_Int:
		ret.Int = (int)value;
		break;

	case CVAR_Float:
		ret.Float = value;
		break;

	case CVAR_String:
		mysnprintf (cstrbuf, countof(cstrbuf), "%g", value);
		ret.String = cstrbuf;
		break;

	case CVAR_GUID:
		ret.pGUID = NULL;
		break;

	default:
		break;
	}

	return ret;
}
Example #18
0
static void DrawHudNumber(FFont *font, int color, int num, int x, int y, int trans=0xc000)
{
	char text[15];

	mysnprintf(text, countof(text), "%d", num);
	DrawHudText(font, color, text, x, y, trans);
}
Example #19
0
/* write the current process id to the specified file */
static void create_pidfile(const char *filename)
{
  int fd;
  char buffer[20];
  if (filename != NULL)
  {
    mkdirname(filename);
    if ((fd = open(filename, O_RDWR | O_CREAT, 0644)) < 0)
    {
      log_log(LOG_ERR, "cannot create pid file (%s): %s",
              filename, strerror(errno));
      exit(EXIT_FAILURE);
    }
    if (lockf(fd, F_TLOCK, 0) < 0)
    {
      log_log(LOG_ERR, "cannot lock pid file (%s): %s",
              filename, strerror(errno));
      exit(EXIT_FAILURE);
    }
    if (ftruncate(fd, 0) < 0)
    {
      log_log(LOG_ERR, "cannot truncate pid file (%s): %s",
              filename, strerror(errno));
      exit(EXIT_FAILURE);
    }
    mysnprintf(buffer, sizeof(buffer), "%d\n", (int)getpid());
    if (write(fd, buffer, strlen(buffer)) != (int)strlen(buffer))
    {
      log_log(LOG_ERR, "error writing pid file (%s): %s",
              filename, strerror(errno));
      exit(EXIT_FAILURE);
    }
    /* we keep the pidfile open so the lock remains valid */
  }
}
Example #20
0
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveQuestItem)
{
	ACTION_PARAM_START(1);
	ACTION_PARAM_INT(questitem, 0);

	// Give one of these quest items to every player in the game
	for (int i = 0; i < MAXPLAYERS; ++i)
	{
		if (playeringame[i])
		{
			AInventory *item = static_cast<AInventory *>(Spawn (QuestItemClasses[questitem-1], 0,0,0, NO_REPLACE));
			if (!item->CallTryPickup (players[i].mo))
			{
				item->Destroy ();
			}
		}
	}

	char messageid[64];

	mysnprintf(messageid, countof(messageid), "TXT_QUEST_%d", questitem);
	const char * name = GStrings[messageid];

	if (name != NULL)
	{
		C_MidPrint (SmallFont, name);
	}
}
Example #21
0
void D_UserInfoChanged (FBaseCVar *cvar)
{
	UCVarValue val;
	FString escaped_val;
	char foo[256];

	if (cvar == &autoaim)
	{
		if (autoaim < 0.0f)
		{
			autoaim = 0.0f;
			return;
		}
		else if (autoaim > 5000.0f)
		{
			autoaim = 5000.f;
			return;
		}
	}

	val = cvar->GetGenericRep (CVAR_String);
	escaped_val = D_EscapeUserInfo(val.String);
	if (4 + strlen(cvar->GetName()) + escaped_val.Len() > 256)
		I_Error ("User info descriptor too big");

	mysnprintf (foo, countof(foo), "\\%s\\%s", cvar->GetName(), escaped_val.GetChars());

	Net_WriteByte (DEM_UINFCHANGED);
	Net_WriteString (foo);
}
Example #22
0
void FGameConfigFile::DoGameSetup (const char *gamename)
{
	const char *key;
	const char *value;

	sublen = countof(section) - 1 - mysnprintf (section, countof(section), "%s.", gamename);
	subsection = section + countof(section) - sublen - 1;
	section[countof(section) - 1] = '\0';
	
	strncpy (subsection, "UnknownConsoleVariables", sublen);
	if (SetSection (section))
	{
		ReadCVars (0);
	}

	strncpy (subsection, "ConsoleVariables", sublen);
	if (SetSection (section))
	{
		ReadCVars (0);
	}

	if (gameinfo.gametype & GAME_Raven)
	{
		SetRavenDefaults (gameinfo.gametype == GAME_Hexen);
	}

	// The NetServerInfo section will be read and override anything loaded
	// here when it's determined that a netgame is being played.
	strncpy (subsection, "LocalServerInfo", sublen);
	if (SetSection (section))
	{
		ReadCVars (0);
	}

	strncpy (subsection, "Player", sublen);
	if (SetSection (section))
	{
		ReadCVars (0);
	}

	strncpy (subsection, "ConsoleAliases", sublen);
	if (SetSection (section))
	{
		const char *name = NULL;
		while (NextInSection (key, value))
		{
			if (stricmp (key, "Name") == 0)
			{
				name = value;
			}
			else if (stricmp (key, "Command") == 0 && name != NULL)
			{
				C_SetAlias (name, value);
				name = NULL;
			}
		}
	}
	OkayToWrite = true;
}
Example #23
0
	void RenderViewport::SetViewport(FLevelLocals *Level, RenderThread *thread, int fullWidth, int fullHeight, float trueratio)
	{
		int virtheight, virtwidth, virtwidth2, virtheight2;

		if (!RenderingToCanvas)
		{ // Set r_viewsize cvar to reflect the current view size
			UCVarValue value;
			char temp[16];

			mysnprintf(temp, countof(temp), "%d x %d", viewwidth, viewheight);
			value.String = temp;
			r_viewsize.ForceSet(value, CVAR_String);
		}

		fuzzviewheight = viewheight - 2;	// Maximum row the fuzzer can draw to

		CenterX = viewwindow.centerx;
		CenterY = viewwindow.centery;

		virtwidth = virtwidth2 = fullWidth;
		virtheight = virtheight2 = fullHeight;

		if (AspectTallerThanWide(trueratio))
		{
			virtheight2 = virtheight2 * AspectMultiplier(trueratio) / 48;
		}
		else
		{
			virtwidth2 = virtwidth2 * AspectMultiplier(trueratio) / 48;
		}

		if (AspectTallerThanWide(viewwindow.WidescreenRatio))
		{
			virtheight = virtheight * AspectMultiplier(viewwindow.WidescreenRatio) / 48;
		}
		else
		{
			virtwidth = virtwidth * AspectMultiplier(viewwindow.WidescreenRatio) / 48;
		}

		double ypixelstretch = (Level->info) ? Level->info->pixelstretch : 1.2;

		BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2);
		YaspectMul = 320.0 * virtheight / (r_Yaspect * virtwidth) * ypixelstretch / 1.2;
		IYaspectMul = (double)virtwidth * r_Yaspect / 320.0 / virtheight;
		InvZtoScale = YaspectMul * CenterX;

		WallTMapScale2 = IYaspectMul / CenterX * 1.2 / ypixelstretch;

		// thing clipping
		fillshort(screenheightarray, viewwidth, (short)viewheight);

		InitTextureMapping();

		// Reset r_*Visibility vars
		thread->Light->SetVisibility(this, r_visibility, !!(Level->flags3 & LEVEL3_NOLIGHTFADE));

		SetupBuffer();
	}
Example #24
0
static bool Cht_ChangeStartSpot (cheatseq_t *cheat)
{
	char cmd[64];

	mysnprintf (cmd, countof(cmd), "changemap %s %c", level.mapname, cheat->Args[0]);
	C_DoCommand (cmd);
	return true;
}
Example #25
0
const char *FFloatCVar::GetHumanString(int precision) const
{
	if (precision < 0)
	{
		precision = 6;
	}
	mysnprintf(cstrbuf, countof(cstrbuf), "%.*g", precision, Value);
	return cstrbuf;
}
Example #26
0
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid)
{
	mysnprintf (buffer, buffsize, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
		(uint32)guid.Data1, guid.Data2, guid.Data3,
		guid.Data4[0], guid.Data4[1],
		guid.Data4[2], guid.Data4[3],
		guid.Data4[4], guid.Data4[5],
		guid.Data4[6], guid.Data4[7]);
}
Example #27
0
int bd_read_key(const struct board_t *board) {
    char buffer[BUFFER_SIZE];
    int len = mysnprintf(buffer, BUFFER_SIZE, "#K" CRLF);
    if (bd_send_command(board, buffer, len, BUFFER_SIZE) > 0 && is_ok(buffer)) {
        if (buffer[3] != ':')
            return 0;
        return strtol(buffer + 4, NULL, 16);
    }
    return -1;
}
Example #28
0
static FStringProd *DoubleToString (FProduction *prod)
{
	char buf[128];
	FStringProd *newprod;

	mysnprintf (buf, countof(buf), "%g", static_cast<FDoubleProd *>(prod)->Value);
	newprod = NewStringProd (buf);
	M_Free (prod);
	return newprod;
}
Example #29
0
static const char *KeyName (int key)
{
	static char name[5];

	if (KeyNames[key])
		return KeyNames[key];

	mysnprintf (name, countof(name), "#%d", key);
	return name;
}
Example #30
0
static int mkfilter_rpc_byname(const char *name, char *buffer, size_t buflen)
{
  char safename[BUFLEN_SAFENAME];
  /* escape attribute */
  if (myldap_escape(name, safename, sizeof(safename)))
    return -1;
  /* build filter */
  return mysnprintf(buffer, buflen, "(&%s(%s=%s))",
                    rpc_filter, attmap_rpc_cn, safename);
}