lfnetwork.com mark read register faq members calendar

Thread: Better va()...
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 09-10-2005, 09:52 PM   #1
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
Better va()...

Code:
char	* QDECL va2( char *format, ... ) {
	va_list		argptr;
	#define	MAX_VA_STRING	32000
	static char		temp_buffer[MAX_VA_STRING];
	static char		string[MAX_VA_STRING];	// in case va is called by nested functions
	static int		index = 0;
	char	*buf;
	int len;


	va_start (argptr, format);
	vsprintf (temp_buffer, format,argptr);
	va_end (argptr);

	if ((len = strlen(temp_buffer)) >= MAX_VA_STRING) {
		Com_Error( ERR_DROP, "Attempted to overrun string in call to va2()\n" );
	}

	if (len + index >= MAX_VA_STRING-1) {
		index = 0;
	}

	buf = &string[index];
	memcpy( buf, temp_buffer, len+1 );

	index += len + 1;

	return buf;
}
modified this to be a circular list, to further prevent stepping on/using
previous strings

dont overwrite the va in q_shared.c as its used by the engine and u cannot modify it


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 09-11-2005, 02:57 AM   #2
Tinny
 
Tinny's Avatar
 
Join Date: Apr 2002
Posts: 1,188
Thanks dude, have you noticed any problem's its fixed?


Redeemed!

An old school mod for jedi academy.
Tinny is offline   you may: quote & reply,
Old 09-12-2005, 08:52 PM   #3
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
haven't actually used it in q3, but it seems fine in q3.

i wouldnt exactly go around replacing all instances of va( ... ) to va2( ... ) though.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 09-14-2005, 12:07 PM   #4
stubert
 
Join Date: Aug 2002
Location: Philadelphia
Posts: 227
i invented a better wheel yesteday


soon i'll be famous
stubert is offline   you may: quote & reply,
Old 09-14-2005, 12:25 PM   #5
Astelraid
Rookie
 
Astelraid's Avatar
 
Join Date: Sep 2005
Posts: 27
its probrably stupid question but what is it for?
Astelraid is offline   you may: quote & reply,
Old 09-14-2005, 03:48 PM   #6
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,171
va is used as a general string parser for JKA. It's mainly for adding variable values to strings. For example, you'd use va to make the following....

"I have 10 health remaining!"


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > Better va()...

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:19 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.