99
1010def js_to_c_header (input_filename , output_filename ):
1111 try :
12- # Read JS file content
13- with open (input_filename , 'r' , encoding = 'utf-8' ) as file_js :
14- content = file_js .read ()
15- file_js .close ()
16-
1712 print (f"Converting '{ input_filename } ' to '{ output_filename } '..." )
1813
1914 # comment
@@ -27,8 +22,19 @@ def js_to_c_header(input_filename, output_filename):
2722 "// Canada.\n \n "
2823 )
2924
25+ # Read JS file content
26+ with open (input_filename , 'r' , encoding = 'utf-8' ) as file_js :
27+ content = file_js .read ()
28+ file_js .close ()
29+
30+ # Add comment to js
31+ new_content = comment + content
32+ with open (input_filename , 'w' ) as file_js :
33+ file_js .write (new_content )
34+ file_js .close ()
35+
3036 # Convert each character in JS content to its hexadecimal value
31- hex_values = ["0x{:02x}" .format (ord (char )) for char in content ]
37+ hex_values = ["0x{:02x}" .format (ord (char )) for char in new_content ]
3238
3339 # Prepare the content for the C header file
3440 header_content = (
@@ -49,12 +55,6 @@ def js_to_c_header(input_filename, output_filename):
4955 with open (output_filename , 'w' , encoding = 'utf-8' ) as file_h :
5056 file_h .write (header_content )
5157 file_h .close ()
52-
53- # Add comment to js
54- new_content = comment + content
55- with open (input_filename , 'w' ) as file_js :
56- file_js .write (new_content )
57- file_js .close ()
5858
5959 except FileNotFoundError :
6060 print (f"Error: File '{ input_filename } ' not found." )
0 commit comments