<div>Dear Roy,</div><div><br you for great tcl2c.tcl and its framework.</div><div>I am learning each day and digging miself through the mechanisms.</div><div>Sorry to be a novice.</div><div>And sorry to use Microsoft compilers.</div><div><br compiler MS-VC2015 (VC9) has a string constant size limit of 65535 characters.</div><div>A possibility to avoid this limit is to use an array of characters, which have a limit of size_z = 0x7CFFFFFF.</div><div><br patch below changes dir2c.tcl to output each file within one character array named&nbsp; cvfs_data_$idx as follows:</div><div><br Data of boot.tcl */<br />static unsigned char cvfs_data_2[] = {<br />&nbsp;&nbsp;&nbsp; 0x70, 0x72, 0x6f, 0x63, 0x20, 0x74, 0x63, 0x6c, 0x49, 0x6e, 0x69, 0x74, 0x20, 0x7b, 0x7d, 0x20, <br struct cvfs_data cvfs_tcl_data[] = {<br {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* name&nbsp; */ "boot.tcl",<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* index */ 2,<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* type&nbsp; */ CVFS_FILETYPE_FILE,<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* size&nbsp; */ 2887,<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* data&nbsp; */ cvfs_data_2,<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* free&nbsp; */ 0,<br />&nbsp;&nbsp;&nbsp; },<br patch allows to use this for all files or files larger than the character length limit.</div><div><br may miss another disadvantage of this method. I suppose, it only avoids the implicite trailing zero byte.<br Fri Apr 17 17:29:24 2020<br />+++ Mon Apr 20 17:30:25 2020<br />@@ -66,26 +66,44 @@<br />&nbsp;proc stringify {data} {<br />&nbsp;&nbsp;&nbsp;&nbsp; set ret "\""<br />&nbsp;&nbsp;&nbsp;&nbsp; for {set idx 0} {$idx &lt; [string length $data]} {incr idx} {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; binary scan [string index $data $idx] H* char<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; append ret />&nbsp;<br />-&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if {($idx % 20) == 0 &amp;&amp; $idx != 0} {<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if {(($idx+1) % 20) == 0} {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; append ret />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; set ret [string trim $ret />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; set ret />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; return $ret<br />&nbsp;}<br />&nbsp;<br />+# Convert data to a character array<br />+proc character_array {data} {<br />+&nbsp;&nbsp;&nbsp; set ret />+&nbsp;&nbsp;&nbsp; for {set idx 0} {$idx &lt; [string length $data]} {incr idx} {<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; binary scan [string index $data $idx] H* char<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; append ret "0x${char}, "<br />+<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if {(($idx+1) % 16) == 0 } {<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; append ret />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />+&nbsp;&nbsp;&nbsp; }<br />+&nbsp;&nbsp;&nbsp; set ret [string trimright $ret "\n, \t"]<br />+<br />+&nbsp;&nbsp;&nbsp; append ret />+<br />+&nbsp;&nbsp;&nbsp; return $ret<br />+}<br />+<br />&nbsp;# Encrypt the data<br />&nbsp;proc random_byte {} {<br />&nbsp;&nbsp;&nbsp;&nbsp; set value [expr {int(256 * rand())}]<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; return $value<br />&nbsp;}<br />&nbsp;<br />@@ -303,64 +321,80 @@<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; return(0);<br />&nbsp;}<br />&nbsp;<br />&nbsp;#&nbsp; endif /* !LOADED_CVFS_COMMON */}<br />&nbsp;puts ""<br />&nbsp;<br />-puts "static struct cvfs_data = {"<br />-puts "\t{"<br />-puts Index 0 cannot be used because we use the value 0 to represent failure */"<br />-puts name&nbsp; */ NULL,"<br />-puts index */ 0,"<br />-puts type&nbsp; */ 0,"<br />-puts size&nbsp; */ 0,"<br />-puts data&nbsp; */ NULL,"<br />-puts free&nbsp; */ 0,"<br />-puts "\t},"<br />+# C struct data output buffer (must be delayed after definition of file data)<br />+set struct_data ""<br />+<br />&nbsp;for {set idx 1} {$idx &lt; [llength $files]} {incr idx} {<br />&nbsp;&nbsp;&nbsp;&nbsp; set file [lindex $files $idx]<br />&nbsp;&nbsp;&nbsp;&nbsp; set shortfile [shorten_file $startdir $file]<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; unset -nocomplain finfo type<br />&nbsp;&nbsp;&nbsp;&nbsp; file stat $file finfo<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; switch -- $finfo(type) {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "file" {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set size $finfo(size)<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set fd [open $file]<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fconfigure $fd -translation binary<br />-&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data [read $fd]<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data_in [read $fd]<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close $fd<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if {$obsfucate} {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set type "CVFS_FILETYPE_ENCRYPTED_FILE"<br />-&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data "(unsigned char *) [stringify [encrypt $data $obsfucation_key]]"<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data_in [encrypt $data $obsfucation_key]<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set type "CVFS_FILETYPE_FILE"<br />-&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data "(unsigned char *) [stringify $data]"<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # Microsoft VC9 compiler has a string limit of 65535 bytes<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # so put all larger files into an array which has a higher<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # string limit<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #if {$size &lt;= 65535} {<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp; set data "(unsigned char *) [stringify $data_in]"<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #} else {<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; puts "/* Data of $shortfile */"<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set variable_name cvfs_data_$idx<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data $variable_name<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; puts "static unsigned char =\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [character_array $data_in];"<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #}<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "directory" {<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set type "CVFS_FILETYPE_DIR"<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set data "NULL"<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set size 0<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />-&nbsp;&nbsp;&nbsp; puts "\t{"<br />-&nbsp;&nbsp;&nbsp; puts name&nbsp; */ />-&nbsp;&nbsp;&nbsp; puts index */ $idx,"<br />-&nbsp;&nbsp;&nbsp; puts type&nbsp; */ $type,"<br />-&nbsp;&nbsp;&nbsp; puts size&nbsp; */ $size,"<br />-&nbsp;&nbsp;&nbsp; puts data&nbsp; */ $data,"<br />-&nbsp;&nbsp;&nbsp; puts free&nbsp; */ 0,"<br />-&nbsp;&nbsp;&nbsp; puts "\t},"<br />+&nbsp;&nbsp;&nbsp; append struct_data />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; name&nbsp; */ />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; index */ />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; type&nbsp; */ />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size&nbsp; */ />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; data&nbsp; */ />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; free&nbsp; */ />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; />&nbsp;}<br />+puts ""<br />+puts "static struct cvfs_data = {"<br />+puts "\t{"<br />+puts Index 0 cannot be used because we use the value 0 to represent failure */"<br />+puts name&nbsp; */ NULL,"<br />+puts index */ 0,"<br />+puts type&nbsp; */ 0,"<br />+puts size&nbsp; */ 0,"<br />+puts data&nbsp; */ NULL,"<br />+puts free&nbsp; */ 0,"<br />+puts "\t},"<br />+puts -nonewline $struct_data<br />&nbsp;puts "};"<br />&nbsp;puts ""<br />&nbsp;<br />&nbsp;puts "static unsigned long ${code_tag}_lookup_index(const char *path) {"<br />&nbsp;puts "\tswitch (cvfs_hash((unsigned char *) path)) {"<br />&nbsp;<br />&nbsp;for {set idx 1} {$idx &lt; [llength $files]} {incr idx} {<br /><br