{"name":"preprocessFileLineNumbers","operator":null,"title":"preprocessFileLineNumbers","type":"command","url":"https://community.bistudio.com/wiki/preprocessFileLineNumbers","revid":364516,"updated":"2024-05-16T20:46:22Z","groups":["System"],"status":"ok","replaced_by":[],"games":[{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Returns the preprocessed content of the given file. The preprocessor is C-like, it supports comments using /* */ and PreProcessor Commands. The preprocessor also adds a default debug entrypoint for compiler at the begining of script: `1. line 1 \"aFilename\"`\n\nThe **#line** keyword can be used in any script that are not preprocess, or with preprocess script with extra macro to protect reserverd sharp character. The format is:\n\n`**#line** <number> \"<name>\"`\n\nfollowed by new line. <number> could be only positive integer and <name> could be any name. This will be used only if an error occurs in the script. The error will contain the line:\n`File <filename>, line <linenumber>`\n\nwhere <filename> will be the <name> you set and <linenumber> will be <number> + how many lines it is from the **#line** line. If the error happened on the line right under **#line** it will add 0 to <number>, if on second line, it will add 1 etc.\n\nIt is possible to use more than one **#line** keywords, but it seems having just one at the top for little script is enough to pinpoint position of the error easily.\n\n> [!WARNING]\n> If the file you are loading is not prepared using UTF-8 encoding and contains some characters with codes > 127, they might convert incorrectly","syntaxes":[{"syntax":"preprocessFileLineNumbers fileName","since":null,"effect":null,"exec":null,"params":[{"name":"fileName","type":"String","optional":false,"default":null,"description":"path to the file","types":["String"],"since":null,"text":"fileName: String - path to the file"}],"returns":{"type":"String","types":["String"],"description":"file content containing `1. line 1 \"aFilename\"`","text":"String - file content containing `1. line 1 \"aFilename\"`"},"form":"unary","operator":null,"left":null,"right":{"text":"fileName","types":["String"]}}],"examples":[{"text":"```sqf\n_string = preprocessFileLineNumbers \"A3\\ui_f\\scripts\\IGUI\\RscUnitInfo.sqf\"\n```\n\nResult is:\n\n #line 1 \"A3\\ui_f\\scripts\\IGUI\\RscUnitInfo.sqf\"\n\n disableserialization;\n\n ........","code":["_string = preprocessFileLineNumbers \"A3\\ui_f\\scripts\\IGUI\\RscUnitInfo.sqf\""]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["fileExists","preprocessFile","loadFile","Function","SQF Syntax","call","spawn","execVM","PreProcessor Commands"],"notes":[{"user":"Killzone_Kid","date":"2013-12-17T13:44:00Z","text":"The main difference between preprocessFile and preprocessFileLineNumbers is that the latter adds #line keyword to the target file, which allows to log the __LINE__ error happened at and the __FILE__ error happened in."},{"user":"code34","date":"2017-11-04T10:16:00Z","text":"The #line directive get's removed from the output.\n\nSo to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:\n\n*#define* DEBUG(sharp,name) sharp##line 0 name\n\nand add this at the right place in your code\n\nDEBUG(#,\"your filename\");\n\nThis way you can have custom filenames in error messages."}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: System","Introduced with Operation Flashpoint: Elite version 1.00","Operation Flashpoint: Elite: New Scripting Commands","Operation Flashpoint: Elite: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}