preprocessFile: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "[[Image:" to "[[File:")
 
(99 intermediate revisions by 18 users not shown)
Line 1: Line 1:
[[Category:Scripting Commands|P]]
{{RV|type=command
[[Category:Scripting Commands OFP 1.97|P]]
[[Category:Scripting Commands ArmA|P]]


back to [[Scripting_Reference#P|COMREF]]
|game1= ofp
|version1= 1.85


<h2 style="color:#000066">'''preprocessFile ''filename'''''</h2>
|game2= ofpe
|version2= 1.00


|game3= arma1
|version3= 1.00


'''Operand types:'''
|game4= arma2
|version4= 1.00


'''filename:''' [[String]]
|game5= arma2oa
|version5= 1.50


'''Type of returned value:'''
|game6= tkoh
|version6= 1.00


[[String]]
|game7= arma3
|version7= 0.50


'''Compatibility:'''
|gr1= System


Added in version '''1.82'''
|descr= Reads and processes the content of the specified file. Preprocessor is C-like, supports comments using {{hl|//}} or {{hl|/*}} and {{hl|*/}} and [[PreProcessor Commands]].
Due to the hard-drive access this command executes and the lack of caching this command should not be used in time-critical script loops.
{{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.}}


'''Description:'''
|s1= [[preprocessFile]] fileName


Return preprocessed content of given file.
|p1= fileName: [[String]] - path to the file and name of the file


Preprocessor is C-like, supports comments using '''//''' or '''/*''' and '''*/''' and macros defined with '''#define'''.
|r1= [[String]]


|x1= <sqf>_content = preprocessFile "myFunction.sqf";</sqf>


'''Example:'''
|seealso= [[fileExists]] [[preprocessFileLineNumbers]] [[loadFile]] [[Function]] [[SQF Syntax]] [[call]] [[spawn]] [[execVM]] [[PreProcessor Commands]]
}}


'''preprocessFile''' "myFunction.sqf"
{{Note
|user= Alef
|timestamp= 20080304223500
|text= File path is always relative to mission directory. If script dir\a.sqf includes dir\b.sqf, use "dir\b.sqf" and not "b.sqf".
}}
 
{{Note
|user= Kju
|timestamp= 20110708105900
|text= Use [[preprocessFileLineNumbers]] instead as it provides more context information on error.
}}
 
{{Note
|user= Killzone_Kid
|timestamp= 20131217134400
|text= [[File:PreprocessFile.jpg|right]]The main difference between [[preprocessFile]] and [[preprocessFileLineNumbers]] is that the latter adds #line directive to the target file, which allows to log the {{hl|__LINE__}} error happened at and the {{hl|__FILE__}} error happened in.
}}
 
{{Note
|user= BrotherhoodOfHam
|timestamp= 20140725184300
|text= Essentially what the preprocessFile command does is it refers to the contents of a file as a string:<br>
Example 1:<br>
boop.html:
<syntaxhighlight lang="html"><t align = 'center' valign = 'middle' shadow = '0' size = '2'>structured text</t></syntaxhighlight>
init.sqf:
<sqf>
_text = parseText preprocessFile "boop.html";
hint _text;
</sqf>
This is especially useful for long strings, and it works on files with any file extension as long as they can be edited with a text editor.<br>
Example 2:<br>
init.sqf:
<sqf>
hint preprocessFile "description.ext";
copyToClipboard preprocessFile "mission.sqm";
</sqf>
The above is all valid. However, using *.jpg or any other files saved in an image format is not possible.
}}

Latest revision as of 23:10, 20 November 2023

Hover & click on the images for description

Description

Description:
Reads and processes the content of the specified file. Preprocessor is C-like, supports comments using // or /* and */ and PreProcessor Commands. Due to the hard-drive access this command executes and the lack of caching this command should not be used in time-critical script loops.
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:
preprocessFile fileName
Parameters:
fileName: String - path to the file and name of the file
Return Value:
String

Examples

Example 1:
_content = preprocessFile "myFunction.sqf";

Additional Information

See also:
fileExists preprocessFileLineNumbers 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
Alef - c
Posted on Mar 04, 2008 - 22:35 (UTC)
File path is always relative to mission directory. If script dir\a.sqf includes dir\b.sqf, use "dir\b.sqf" and not "b.sqf".
Kju - c
Posted on Jul 08, 2011 - 10:59 (UTC)
Use preprocessFileLineNumbers instead as it provides more context information on error.
Killzone_Kid - c
Posted on Dec 17, 2013 - 13:44 (UTC)
PreprocessFile.jpg
The main difference between preprocessFile and preprocessFileLineNumbers is that the latter adds #line directive to the target file, which allows to log the __LINE__ error happened at and the __FILE__ error happened in.
BrotherhoodOfHam - c
Posted on Jul 25, 2014 - 18:43 (UTC)
Essentially what the preprocessFile command does is it refers to the contents of a file as a string:
Example 1:
boop.html:
<t align = 'center' valign = 'middle' shadow = '0' size = '2'>structured text</t>

init.sqf:

_text = parseText preprocessFile "boop.html"; hint _text;
This is especially useful for long strings, and it works on files with any file extension as long as they can be edited with a text editor.
Example 2:
init.sqf:
hint preprocessFile "description.ext"; copyToClipboard preprocessFile "mission.sqm";
The above is all valid. However, using *.jpg or any other files saved in an image format is not possible.