{"name":"preprocessFileLineNumbers","title":"preprocessFileLineNumbers","type":"command","url":"https://community.bistudio.com/wiki/preprocessFileLineNumbers","revid":364516,"updated":"2024-05-16T20:46:22Z","groups":["System"],"status":"ok","games":{"ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofpe 1.00","arma3_since":"0.50","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: `#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`#line <number> \"<name>\"`\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>`\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","params":[{"name":"fileName","type":"String","description":"path to the file","type_expr":"String"}],"returns":{"type":"String","type_expr":"String","description":"file content containing `#line 1 \"aFilename\"`"},"form":"unary","right":{"text":"fileName"}}],"examples":[{"text":"```sqf\n_string = preprocessFileLineNumbers \"A3\\ui_f\\scripts\\IGUI\\RscUnitInfo.sqf\"\n```\n\nResult is:\n\n```\n#line 1 \"A3\\ui_f\\scripts\\IGUI\\RscUnitInfo.sqf\"\n\ndisableserialization;\n\n........\n```","code":["_string = preprocessFileLineNumbers \"A3\\ui_f\\scripts\\IGUI\\RscUnitInfo.sqf\""]}],"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.\nSo to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:\n*#define* DEBUG(sharp,name) sharp##line 0 name\nand add this at the right place in your code\nDEBUG(#,\"your filename\");\n\nThis way you can have custom filenames in error messages."}]}