Jump to content
Sign in to follow this  
Prod6112

Config Parser Script

Recommended Posts

Hello to all the BIS community.

New to SQF scripting, i would like to share my first script.

Description:

Parse a config class and print all sub-classes + entries in a C-Like text to the report file.

Installation:

Copy the file "ConfigParser.sqf" into your mission folder.

Parameters:

  • 0: <CONFIG> config entry to parse (must be a class)
  • 1: <BOOLEAN> (optional) if true: the output will be alphabetically sorted.

Usage examples:

  • [configFile >> "CfgVehicles", true] call compile preprocessFile "ConfigParser.sqf";
  • [configFile >> "CfgWeapons"] execVM "ConfigParser.sqf";

Link:

ConfigParser.sqf v1.1

Screenshots:

overview1.jpg (882 kB)

overview2.jpg (280 kB)

overview3.jpg (275 kB)

Toggle output to Clipboard/Report File

Recommandations:

  • Call it between startLoadingScreen and endLoadingScreen commands when using "call compile preprocessFile" for a full speed execution of the script.
  • I recommand notepad++ to open the arma3*.rpt file (Choose Language > C++ style).

Known Issues:

  • execVM command will stop the script if the passed config class is too big (configFile e.g.)
  • [sOLVED] Arrays are not printed with the correct C syntax.
  • [sOLVED] Due to the 1024 chars limit of the diag_log command, some arrays are not fully printed. Only solved in clipboard output mode (see the last screenshot)

Performances:

Used test code:

startLoadingScreen [""];

_a = diag_ticktime;
[configFile, true] call compile preprocessFileLineNumbers "ConfigParser.sqf";
_b = diag_ticktime;

endLoadingScreen;

diag_log str(_b - _a);

Arma3 Alpha v0.57.105125

Date: 2013/05/13 20:01:17

Processor speed: 3,4Ghz

Drive type: SSD

Loaded Addons:

dta\bin.pbo - unknown

dta\core.pbo - 0

dta\languagecore_f.pbo - 47191

addons\a3.pbo - unknown

addons\air_f.pbo - 46977

addons\animals_f.pbo - 44998

addons\anims_f.pbo - 45586

addons\anims_f_data.pbo - 45586

addons\armor_f.pbo - 43682

addons\baseconfig_f.pbo - 43414

addons\boat_f.pbo - 46977

addons\cargoposes_f.pbo - 45221

addons\characters_f.pbo - 46977

addons\data_f.pbo - 47269

addons\dubbing_f.pbo - 45172

addons\dubbing_radio_f.pbo - 47182

addons\dubbing_radio_f_data.pbo - 47182

addons\editor_f.pbo - 43414

addons\functions_f.pbo - 47120

addons\languagemissions.pbo - unknown

addons\languagemissions_f.pbo - 45944

addons\language_f.pbo - 46408

addons\map_data.pbo - 45088

addons\map_stratis.pbo - 47208

addons\map_stratis_data.pbo - 47208

addons\map_stratis_data_layers.pbo - 45088

addons\misc_f.pbo - 43845

addons\missions_f.pbo - 45943

addons\missions_f_data.pbo - 45944

addons\missions_f_video.pbo - 45944

addons\modules_f.pbo - 45214

addons\modules_f_data.pbo - 40648

addons\music_f.pbo - 43414

addons\music_f_music.pbo - unknown

addons\plants_f.pbo - 47219

addons\roads_f.pbo - 45868

addons\rocks_f.pbo - 44998

addons\signs_f.pbo - 44998

addons\soft_f.pbo - 46977

addons\sounds_f.pbo - 47000

addons\sounds_f_vehicles.pbo - 46977

addons\sounds_f_weapons.pbo - 46977

addons\static_f.pbo - 44998

addons\structures_f.pbo - 47268

addons\structures_f_data.pbo - 45088

addons\structures_f_households.pbo - 47268

addons\structures_f_ind.pbo - 47268

addons\structures_f_mil.pbo - 47268

addons\structures_f_wrecks.pbo - 47268

addons\uifonts_f.pbo - 43414

addons\uifonts_f_data.pbo - 43414

addons\ui_f.pbo - 47120

addons\ui_f_data.pbo - 45869

addons\weapons_f.pbo - 47117

Result:

Elapsed Time: 144.203s (17.826s without alphabetical sort)

Report File Size: 9,432,732 bytes

Lines: 226567

Classes printed: 32369

Can you let me know your positive/negative feedbacks and encountered bugs ? Thanks

Thanks:

.kju [PvPscene] for his very usefull tips.

Denis Usenko for a nice string concatenation algorithm in the dumpConfig (re-implemented for the script)

Killzone_Kid for the Notepad++ SQF syntax highlight.

All wiki members as always, keeping it up to date.

Edited by Prod6112

Share this post


Link to post
Share on other sites

salut Prod6112 :bounce3:

great show with such quality first submission!

Did you compare yours to these yet?

http://www.ofpec.com/forum/index.php?topic=33539.0

http://www.ofpec.com/forum/index.php?topic=35236.0

You might find this useful too:

https://dev-heaven.net/projects/alef-projects/wiki/DumpConfig

output will be alphabetically sorted

This would be extremely useful. Testing NOW :D

---------- Post added at 01:46 PM ---------- Previous post was at 01:34 PM ----------

PS:

A3 stable

// 31822 classes printed.

"145.484"

Intel Core i7 920 2.67GHz @ 3598.8 MHz

Samsung SSD 840 PRO

12,0 GB Dual-Channel DDR3 @ 799MHz (9-9-9-24) - 4 GB RAM drive

Share this post


Link to post
Share on other sites

Hi kju

Merci for your response ;)

Im going to try the dumpConfig script

Here are some details about the Alphabetical sort function i worked on:

Description:

Sort Alphabetically an array of strings

Features:

  • Any ASCII character is allowed due to the toArray command usage
  • Can be case sensitive or not by adding/removing the toLower command
  • Array can be a config data type (adding configName)
  • Array is passed by reference
  • Result can be reversed

I didn't find another way to sort alphabetically an array of strings (except the lbSort command which is faster but only works on listbox).

After a couple of time spent and tests, this is the fastest algorithm i found :

AlphabeticalSort =
{
if (count _this < 2) exitWith {};

private ["_array1", "_array2", "_tmp", "_isSorted"];

for "_inc" from 0 to (count _this -2) do
{
	for "_dec" from _inc to 0 step -1 do
	{
		_array1 = toArray(toLower(_this select _dec));
		_array2 = toArray(toLower(_this select _dec +1));
		_isSorted = false;

		for "_i" from 0 to (count _array1) do
		{
			if (_i >= count _array2 || {_array1 select _i > _array2 select _i}) exitWith
			{
				_tmp = _this select _dec;
				_this set [_dec, _this select _dec +1];
				_this set [_dec +1, _tmp]
			};
			if (_array1 select _i < _array2 select _i) exitWith {_isSorted = true}
		};

		if _isSorted exitWith {};
	};
};
};

I tested the code with the configNames of all the firsts configFile classes (742 elements)

The original code resulted in 4s. This one in 2.87s

Different implementations (not case sensitive):

- Array of strings (A to Z)

_AlphabeticalSort =
{
if (count _this < 2) exitWith {};

private ["_array1", "_array2", "_tmp", "_isSorted"];

for "_inc" from 0 to (count _this -2) do
{
	for "_dec" from _inc to 0 step -1 do
	{
		_array1 = toArray(toLower(_this select _dec));
		_array2 = toArray(toLower(_this select _dec +1));
		_isSorted = false;

		for "_i" from 0 to (count _array1) do
		{
			if (_i >= count _array2 || {_array1 select _i > _array2 select _i}) exitWith
			{
				_tmp = _this select _dec;
				_this set [_dec, _this select _dec +1];
				_this set [_dec +1, _tmp]
			};
			if (_array1 select _i < _array2 select _i) exitWith {_isSorted = true}
		};

		if _isSorted exitWith {};
	};
};
};

- Array of strings (Z to A)

_AlphabeticalSortReversed =
{
if (count _this < 2) exitWith {};

private ["_array1", "_array2", "_tmp", "_isSorted"];

for "_inc" from 0 to (count _this -2) do
{
	for "_dec" from _inc to 0 step -1 do
	{
		_array1 = toArray(toLower(_this select _dec));
		_array2 = toArray(toLower(_this select _dec +1));
		_isSorted = false;

		for "_i" from 0 to (count _array2) do
		{
			if (_i >= count _array1 || {_array1 select _i < _array2 select _i}) exitWith
			{
				_tmp = _this select _dec;
				_this set [_dec, _this select _dec +1];
				_this set [_dec +1, _tmp]
			};
			if (_array1 select _i > _array2 select _i) exitWith {_isSorted = true}
		};

		if _isSorted exitWith {};
	};
};
};

- Array of configs (A to Z)

_AlphabeticalSort =
{
if (count _this < 2) exitWith {};

private ["_array1", "_array2", "_tmp", "_isSorted"];

for "_inc" from 0 to (count _this -2) do
{
	for "_dec" from _inc to 0 step -1 do
	{
		_array1 = toArray(toLower(configName(_this select _dec)));
		_array2 = toArray(toLower(configName(_this select _dec +1)));
		_isSorted = false;

		for "_i" from 0 to (count _array1) do
		{
			if (_i >= count _array2 || {_array1 select _i > _array2 select _i}) exitWith
			{
				_tmp = _this select _dec;
				_this set [_dec, _this select _dec +1];
				_this set [_dec +1, _tmp]
			};
			if (_array1 select _i < _array2 select _i) exitWith {_isSorted = true}
		};

		if _isSorted exitWith {};
	};
};
};

- Array of configs (Z to A)

_AlphabeticalSortReversed =
{
if (count _this < 2) exitWith {};

private ["_array1", "_array2", "_tmp", "_isSorted"];

for "_inc" from 0 to (count _this -2) do
{
	for "_dec" from _inc to 0 step -1 do
	{
		_array1 = toArray(toLower(configName(_this select _dec)));
		_array2 = toArray(toLower(configName(_this select _dec +1)));
		_isSorted = false;

		for "_i" from 0 to (count _array2) do
		{
			if (_i >= count _array1 || {_array1 select _i < _array2 select _i}) exitWith
			{
				_tmp = _this select _dec;
				_this set [_dec, _this select _dec +1];
				_this set [_dec +1, _tmp]
			};
			if (_array1 select _i > _array2 select _i) exitWith {_isSorted = true}
		};

		if _isSorted exitWith {};
	};
};
};

---------- Post added at 16:26 ---------- Previous post was at 14:58 ----------

Thx for the tip kju!

this dumpConfig took 9s versus 17s for mine (using clipboard copy instead of diag_log reduce the time and solve the 1024 chars limit problem)

I think im going to try the clipboard idea to see how many times it take with the alphabetical sort function.

Edited by Prod6112

Share this post


Link to post
Share on other sites

Here is another idea to consider:

I use arma2net to fetch the data put into the clipboard and save it to file with a small c# app.

However with skills like yours, you should be able to improve this approach considerably.

Like doing the sorting outside the game is probably way more efficient.

Ref:

http://forums.bistudio.com/showthread.php?131325-Arma2NET

http://community.bistudio.com/wiki/Extensions

Share this post


Link to post
Share on other sites

to remove...

Edited by Prod6112

Share this post


Link to post
Share on other sites

Updated to version 1.1

You can now switch the output destination to the clipboard to solve the character limits problem (see the first post)

;2394727']You might find this useful too:

https://dev-heaven.net/projects/alef-projects/wiki/DumpConfig

The new config parser take 6.682s with clipboard copy to output the entire configFile (not sorted)

However' date=' it seems that there is no difference with the Alphabetical sort function (still ~150s)

;2395223']Here is another idea to consider:

Like doing the sorting outside the game is probably way more efficient.

Ref:

http://forums.bistudio.com/showthread.php?131325-Arma2NET

http://community.bistudio.com/wiki/Extensions

Right kju!, the fastest way now is to do the sorting with an external library...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×