: <- the first
character in the file is the string table name delimiter :strings1 this is a test\r\n this is a another test\r\n :strings2 this is a test\r\n this is a \"another\" test\r\n |
char strings1_0[]
PROGMEM = "this is a test\r\n"; char strings1_1[] PROGMEM = "this is a another test\r\n"; PGM_P strings1[] PROGMEM = { strings1_0, strings1_1 }; char strings2_0[] PROGMEM = "this is a test\r\n"; char strings2_1[] PROGMEM = "this is a \"another\" test\r\n"; PGM_P strings2[] PROGMEM = { strings2_0, strings2_1 }; |
Rebol[] if none? input_file: request-file/title "Choose string file" "" [ quit ] input_file: read/lines to-file input_file delimiter: input_file/1/1 if delimiter = #" " [ delimiter: #":" ] input_file: next input_file temp_file: "" table_name: none line_count: 0 create_table: func [ name count /local temp ] [ temp: rejoin [ "PGM_P " name "[] PROGMEM = { " #"^/" ] for i 0 count 1 [ insert tail temp rejoin [ " " name "_" i ] if i < count [ insert tail temp "," ] insert tail temp #"^/" ] insert tail temp "};" return temp ] create_string: func [ name count string ] [ return rejoin [ {char } name {_} count {[] PROGMEM = } {"} string {";} #"^/" ] ] foreach line input_file [ either line/1 = delimiter [ if not none? table_name [ insert tail temp_file create_table table_name (line_count - 1) insert tail temp_file #"^/" insert tail temp_file #"^/" line_count: 0 ] line: next line table_name: line ][ if not empty? line [ insert tail temp_file create_string table_name line_count line line_count: line_count + 1 ] ] ] if not none? table_name [ insert tail temp_file create_table table_name (line_count - 1) ] write/lines clipboard:// temp_file alert "String arrays and tables copied to clipboard" |