preprocessFileLineNumbers: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\[\[Category:[ _]?Scripting[ _]Commands[ _]Arma[ _]2(\|.*)\]\]" to "{{GameCategory|arma2|Scripting Commands}}")
m (Text replacement - "{{Feature | Warning | " to "{{Feature|warning|")
 
(45 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma1 |Game name=
|game1= ofpe
|version1= 1.00


|1.00|Game version=
|game2= arma1
|version2= 1.00


|gr1= System |GROUP1=
|game3= arma2
____________________________________________________________________________________________
|version3= 1.00


| 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: <tt>#line 1 "aFilename"</tt><br><br>
|game4= arma2oa
|version4= 1.50
 
|game5= tkoh
|version5= 1.00
 
|game6= arma3
|version6= 0.50
 
|gr1= System
 
|descr= 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: {{hl|#line 1 "aFilename"}}<br><br>


The '''#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:<br>
The '''#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:<br>
<tt>'''#line''' <number> "<name>"</tt><br>
{{hl|'''#line''' <number> "<name>"}}<br>
followed 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:
followed 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:
<tt>File <filename>, line <linenumber></tt><br>
{{hl|File <filename>, line <linenumber>}}<br>
where <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.<br><br>
where <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.<br><br>
It 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.  
It 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.  
<br><br>
{{Feature|warning|If the file you are loading is not prepared using UTF-8 encoding and contains some characters [[toArray | with codes]] > 127, they might convert incorrectly}}
{{Warning | If the file you are loading is not prepared using UTF-8 encoding and contains some characters [[toArray | with codes]] > 127, they might convert incorrectly}}   |DESCRIPTION=


____________________________________________________________________________________________
|s1= [[preprocessFileLineNumbers]] fileName


| '''preprocessFileLineNumbers''' fileName |SYNTAX=
|p1= fileName: [[String]] - path to the file


|p1= fileName: [[String]] - path to the file |PARAMETER1=
|r1= [[String]] - file content containing {{hl|#line 1 "aFilename"}}


| [[String]] - file content containing <tt>#line 1 "aFilename"</tt> |RETURNVALUE=
|x1= <sqf>_string = preprocessFileLineNumbers "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"</sqf>
____________________________________________________________________________________________
 
|x1= <code>_string = [[preprocessFileLineNumbers]] "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"</code>  


Result is: <br>
Result is: <br>
  #line 1 "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"<br>
  #line 1 "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"<br>
  disableserialization;<br>
  disableserialization;<br>
  ........ |EXAMPLE1=
  ........
____________________________________________________________________________________________


| [[fileExists ]] [[preprocessFile]], [[loadFile]], [[Function]], [[SQF syntax]], [[call]], [[spawn]], [[execVM]], [[PreProcessor Commands]] |SEEALSO=
|seealso= [[fileExists]] [[preprocessFile]] [[loadFile]] [[Function]] [[SQF Syntax]] [[call]] [[spawn]] [[execVM]] [[PreProcessor Commands]]
}}


{{Note
|user= Killzone_Kid
|timestamp= 20131217134400
|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.<br>
[[File:PreprocessFile.jpg]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= code34
<!-- Note Section BEGIN -->
|timestamp= 20171104101600
<dd class="notedate">Posted on December 17, 2013
|text= The #line directive get's removed from the output.<br>
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]
<dd class="note">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.
 
[[Image:PreprocessFile.jpg]]
 
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|PREPROCESSFILELINENUMBERS]]
[[Category:Scripting Commands OFP Elite |PREPROCESSFILELINENUMBERS]]
{{GameCategory|arma1|Scripting Commands}}
{{GameCategory|arma2|Scripting Commands}}
{{GameCategory|arma3|Scripting Commands}}
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on November 4, 2017 - 10:16 (UTC)</dd>
<dt class="note">[[User:code34|code34]]</dt>
<dd class="note">
The #line directive get's removed from the output.<br>
So to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:<br>
So to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:<br>
''#define'' DEBUG(sharp,name) sharp##line 0 name<br>
''#define'' DEBUG(sharp,name) sharp##line 0 name<br>
Line 73: Line 64:


This way you can have custom filenames in error messages.
This way you can have custom filenames in error messages.
 
}}
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 21:46, 16 May 2024

Hover & click on the images for description

Description

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"

The #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:
#line <number> "<name>"
followed 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: File <filename>, line <linenumber>
where <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.

It 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.
If the file you are loading is not prepared using UTF-8 encoding and contains some characters with codes > 127, they might convert incorrectly
Groups:
System

Syntax

Syntax:
preprocessFileLineNumbers fileName
Parameters:
fileName: String - path to the file
Return Value:
String - file content containing #line 1 "aFilename"

Examples

Example 1:
_string = preprocessFileLineNumbers "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"
Result is:
#line 1 "A3\ui_f\scripts\IGUI\RscUnitInfo.sqf"
disableserialization;
........

Additional Information

See also:
fileExists preprocessFile loadFile Function SQF Syntax call spawn execVM PreProcessor Commands

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Killzone_Kid - c
Posted on Dec 17, 2013 - 13:44 (UTC)
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.
PreprocessFile.jpg
code34 - c
Posted on Nov 04, 2017 - 10:16 (UTC)
The #line directive get's removed from the output.
So to add a custom #line directive before while using preprocessFileLineNumbers, you have to use a preprocessor macro like this:
#define DEBUG(sharp,name) sharp##line 0 name
and add this at the right place in your code
DEBUG(#,"your filename"); This way you can have custom filenames in error messages.