| 
									
										
										
										
											2021-02-28 04:19:09 +06:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											2016-12-21 04:07:24 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if len(sys.argv) < 4: | 
					
						
							| 
									
										
										
										
											2020-11-17 15:07:09 +00:00
										 |  |  |     print("Usage: {0} <filename> <variable> <output>") | 
					
						
							| 
									
										
										
										
											2016-12-21 04:07:24 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-28 04:19:09 +06:00
										 |  |  | with open(sys.argv[1], "r", encoding="utf-8", errors="backslashreplace") as f: | 
					
						
							|  |  |  |     in_data = f.read() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:07:09 +00:00
										 |  |  | b = [r"\x{:02x}".format(ord(c)) for c in in_data] | 
					
						
							| 
									
										
										
										
											2016-12-21 04:07:24 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:07:09 +00:00
										 |  |  | out_data = 'const char {0}[] = "'.format(sys.argv[2]) | 
					
						
							| 
									
										
										
										
											2021-07-02 14:10:51 +02:00
										 |  |  | out_data += "".join(b) + '";\n' | 
					
						
							| 
									
										
										
										
											2016-12-21 04:07:24 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:07:09 +00:00
										 |  |  | with open(sys.argv[3], "w") as f: | 
					
						
							| 
									
										
										
										
											2016-12-21 04:07:24 +05:30
										 |  |  |     f.write(out_data) |