Ticket Change Details
Overview

Artifact ID: 4eaaa9b664fe5ca116577e81a6bd17bf4344f219
Ticket: bd6188edd4290bfdcff4a8ef9355f5280496eda5
dir2c: Output data as character array and not as string
User & Date: anonymous on 2020-04-20 16:03:24
Changes

  1. Change comment to:
    <div>Dear Roy,</div><div><br /></div><div>thank 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 /></div><div>The 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 /></div><div>The patch below changes dir2c.tcl to output each file within one character array named&nbsp; cvfs_data_$idx as follows:</div><div><br /></div><div>&lt;verbatim&gt;</div><div>/* 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 />...</div><div>static struct cvfs_data cvfs_tcl_data[] = {<br /></div><div>...<br /></div><div>&nbsp;&nbsp;&nbsp; {<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 />&lt;/verbatim&gt;<br /></div><div><br /></div><div>The patch allows to use this for all files or files larger than the character length limit.</div><div><br /></div><div>I may miss another disadvantage of this method. I suppose, it only avoids the implicite trailing zero byte.<br /></div><div><br /></div><div>Thank you,</div><div>Harald</div><div><br /></div><div>Patch:</div><div>&lt;verbatim&gt;</div><div>--- C:/Users/oehhar/AppData/Local/Temp/dir2c.tcl-revBASE.svn001.tmp.tcl&nbsp;&nbsp;&nbsp; Fri Apr 17 17:29:24 2020<br />+++ C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl&nbsp;&nbsp;&nbsp; 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 "\\x${char}"<br />&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 "\"\n\""<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; set ret [string trim $ret "\n\""]<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; set ret "\"$ret\""<br />&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 "\{\n\t"<br />+&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 "\n\t"<br />+&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 "\n\}"<br />+<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 ${code_tag}_data\[\] = {"<br />-puts "\t{"<br />-puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */"<br />-puts "\t\t/* name&nbsp; */ NULL,"<br />-puts "\t\t/* index */ 0,"<br />-puts "\t\t/* type&nbsp; */ 0,"<br />-puts "\t\t/* size&nbsp; */ 0,"<br />-puts "\t\t/* data&nbsp; */ NULL,"<br />-puts "\t\t/* 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 ${variable_name}\[\] =\<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 "\t\t/* name&nbsp; */ \"$shortfile\","<br />-&nbsp;&nbsp;&nbsp; puts "\t\t/* index */ $idx,"<br />-&nbsp;&nbsp;&nbsp; puts "\t\t/* type&nbsp; */ $type,"<br />-&nbsp;&nbsp;&nbsp; puts "\t\t/* size&nbsp; */ $size,"<br />-&nbsp;&nbsp;&nbsp; puts "\t\t/* data&nbsp; */ $data,"<br />-&nbsp;&nbsp;&nbsp; puts "\t\t/* free&nbsp; */ 0,"<br />-&nbsp;&nbsp;&nbsp; puts "\t},"<br />+&nbsp;&nbsp;&nbsp; append struct_data "\t{\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t\t/* name&nbsp; */ \"$shortfile\",\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t\t/* index */ $idx,\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t\t/* type&nbsp; */ $type,\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t\t/* size&nbsp; */ $size,\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t\t/* data&nbsp; */ $data,\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t\t/* free&nbsp; */ 0,\n"\<br />+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "\t},\n"<br />&nbsp;}<br />+puts ""<br />+puts "static struct cvfs_data ${code_tag}_data\[\] = {"<br />+puts "\t{"<br />+puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */"<br />+puts "\t\t/* name&nbsp; */ NULL,"<br />+puts "\t\t/* index */ 0,"<br />+puts "\t\t/* type&nbsp; */ 0,"<br />+puts "\t\t/* size&nbsp; */ 0,"<br />+puts "\t\t/* data&nbsp; */ NULL,"<br />+puts "\t\t/* 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 /></div><div>&lt;/verbatim&gt;<br /></div>
    
  2. Change foundin to "trunk"
  3. Change login to "anonymous"
  4. Change private_contact to "0f366eb3e9e2fcab52b8ebacd197db9047186a5f"
  5. Change severity to "Minor"
  6. Change status to "Open"
  7. Change title to:
    dir2c: Output data as character array and not as string
    
  8. Change type to "Feature Request"