D 2020-04-20T16:03:24.642
J comment
Dear\sRoy,
thank\syou\sfor\sgreat\stcl2c.tcl\sand\sits\sframework.
I\sam\slearning\seach\sday\sand\sdigging\smiself\sthrough\sthe\smechanisms.
Sorry\sto\sbe\sa\snovice.
And\ssorry\sto\suse\sMicrosoft\scompilers.
The\scompiler\sMS-VC2015\s(VC9)\shas\sa\sstring\sconstant\ssize\slimit\sof\s65535\scharacters.
A\spossibility\sto\savoid\sthis\slimit\sis\sto\suse\san\sarray\sof\scharacters,\swhich\shave\sa\slimit\sof\ssize_z\s=\s0x7CFFFFFF.
The\spatch\sbelow\schanges\sdir2c.tcl\sto\soutput\seach\sfile\swithin\sone\scharacter\sarray\snamed \scvfs_data_$idx\sas\sfollows:
<verbatim>
/*\sData\sof\sboot.tcl\s*/
static\sunsigned\schar\scvfs_data_2[]\s=\s{
\s0x70,\s0x72,\s0x6f,\s0x63,\s0x20,\s0x74,\s0x63,\s0x6c,\s0x49,\s0x6e,\s0x69,\s0x74,\s0x20,\s0x7b,\s0x7d,\s0x20,\s
...
static\sstruct\scvfs_data\scvfs_tcl_data[]\s=\s{
...
\s{
\s \s/*\sname \s*/\s"boot.tcl",
\s \s/*\sindex\s*/\s2,
\s \s/*\stype \s*/\sCVFS_FILETYPE_FILE,
\s \s/*\ssize \s*/\s2887,
\s \s/*\sdata \s*/\scvfs_data_2,
\s \s/*\sfree \s*/\s0,
\s},
</verbatim>
The\spatch\sallows\sto\suse\sthis\sfor\sall\sfiles\sor\sfiles\slarger\sthan\sthe\scharacter\slength\slimit.
I\smay\smiss\sanother\sdisadvantage\sof\sthis\smethod.\sI\ssuppose,\sit\sonly\savoids\sthe\simplicite\strailing\szero\sbyte.
Thank\syou,
Harald
Patch:
<verbatim>
---\sC:/Users/oehhar/AppData/Local/Temp/dir2c.tcl-revBASE.svn001.tmp.tcl \sFri\sApr\s17\s17:29:24\s2020
+++\sC:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl \sMon\sApr\s20\s17:30:25\s2020
@@\s-66,26\s+66,44\s@@
proc\sstringify\s{data}\s{
\sset\sret\s"\\""
\sfor\s{set\sidx\s0}\s{$idx\s<\s[string\slength\s$data]}\s{incr\sidx}\s{
\s \sbinary\sscan\s[string\sindex\s$data\s$idx]\sH*\schar
\s \sappend\sret\s"\\\\x${char}"
- \s \sif\s{($idx\s%\s20)\s==\s0\s&&\s$idx\s!=\s0}\s{
+ \s \sif\s{(($idx+1)\s%\s20)\s==\s0}\s{
\s \s \sappend\sret\s"\\"\\n\\""
\s \s}
\s}
\sset\sret\s[string\strim\s$ret\s"\\n\\""]
\sset\sret\s"\\"$ret\\""
\sreturn\s$ret
}
+#\sConvert\sdata\sto\sa\scharacter\sarray
+proc\scharacter_array\s{data}\s{
+ \sset\sret\s"\\{\\n\\t"
+ \sfor\s{set\sidx\s0}\s{$idx\s<\s[string\slength\s$data]}\s{incr\sidx}\s{
+ \s \sbinary\sscan\s[string\sindex\s$data\s$idx]\sH*\schar
+ \s \sappend\sret\s"0x${char},\s"
+
+ \s \sif\s{(($idx+1)\s%\s16)\s==\s0\s}\s{
+ \s \s \sappend\sret\s"\\n\\t"
+ \s \s}
+ \s}
+ \sset\sret\s[string\strimright\s$ret\s"\\n,\s\\t"]
+
+ \sappend\sret\s"\\n\\}"
+
+ \sreturn\s$ret
+}
+
#\sEncrypt\sthe\sdata
proc\srandom_byte\s{}\s{
\sset\svalue\s[expr\s{int(256\s*\srand())}]
\sreturn\s$value
}
@@\s-303,64\s+321,80\s@@
\sreturn(0);
}
# \sendif\s/*\s!LOADED_CVFS_COMMON\s*/}
puts\s""
-puts\s"static\sstruct\scvfs_data\s${code_tag}_data\\[\\]\s=\s{"
-puts\s"\\t{"
-puts\s"\\t\\t/*\sIndex\s0\scannot\sbe\sused\sbecause\swe\suse\sthe\svalue\s0\sto\srepresent\sfailure\s*/"
-puts\s"\\t\\t/*\sname \s*/\sNULL,"
-puts\s"\\t\\t/*\sindex\s*/\s0,"
-puts\s"\\t\\t/*\stype \s*/\s0,"
-puts\s"\\t\\t/*\ssize \s*/\s0,"
-puts\s"\\t\\t/*\sdata \s*/\sNULL,"
-puts\s"\\t\\t/*\sfree \s*/\s0,"
-puts\s"\\t},"
+#\sC\sstruct\sdata\soutput\sbuffer\s(must\sbe\sdelayed\safter\sdefinition\sof\sfile\sdata)
+set\sstruct_data\s""
+
for\s{set\sidx\s1}\s{$idx\s<\s[llength\s$files]}\s{incr\sidx}\s{
\sset\sfile\s[lindex\s$files\s$idx]
\sset\sshortfile\s[shorten_file\s$startdir\s$file]
\sunset\s-nocomplain\sfinfo\stype
\sfile\sstat\s$file\sfinfo
\sswitch\s--\s$finfo(type)\s{
\s \s"file"\s{
\s \s \sset\ssize\s$finfo(size)
\s \s \sset\sfd\s[open\s$file]
\s \s \sfconfigure\s$fd\s-translation\sbinary
- \s \s \sset\sdata\s[read\s$fd]
+ \s \s \sset\sdata_in\s[read\s$fd]
\s \s \sclose\s$fd
\s \s \sif\s{$obsfucate}\s{
\s \s \s \sset\stype\s"CVFS_FILETYPE_ENCRYPTED_FILE"
- \s \s \s \sset\sdata\s"(unsigned\schar\s*)\s[stringify\s[encrypt\s$data\s$obsfucation_key]]"
+ \s \s \s \sset\sdata_in\s[encrypt\s$data\s$obsfucation_key]
\s \s \s}\selse\s{
\s \s \s \sset\stype\s"CVFS_FILETYPE_FILE"
- \s \s \s \sset\sdata\s"(unsigned\schar\s*)\s[stringify\s$data]"
\s \s \s}
+ \s \s \s#\sMicrosoft\sVC9\scompiler\shas\sa\sstring\slimit\sof\s65535\sbytes
+ \s \s \s#\sso\sput\sall\slarger\sfiles\sinto\san\sarray\swhich\shas\sa\shigher
+ \s \s \s#\sstring\slimit
+ \s \s \s#if\s{$size\s<=\s65535}\s{
+ \s \s \s# \sset\sdata\s"(unsigned\schar\s*)\s[stringify\s$data_in]"
+ \s \s \s#}\selse\s{
+ \s \s \s \sputs\s"/*\sData\sof\s$shortfile\s*/"
+ \s \s \s \sset\svariable_name\scvfs_data_$idx
+ \s \s \s \sset\sdata\s$variable_name
+ \s \s \s \sputs\s"static\sunsigned\schar\s${variable_name}\\[\\]\s=\\
+ \s \s \s \s \s \s[character_array\s$data_in];"
+ \s \s \s#}
\s \s}
\s \s"directory"\s{
\s \s \sset\stype\s"CVFS_FILETYPE_DIR"
\s \s \sset\sdata\s"NULL"
\s \s \sset\ssize\s0
\s \s}
\s}
- \sputs\s"\\t{"
- \sputs\s"\\t\\t/*\sname \s*/\s\\"$shortfile\\","
- \sputs\s"\\t\\t/*\sindex\s*/\s$idx,"
- \sputs\s"\\t\\t/*\stype \s*/\s$type,"
- \sputs\s"\\t\\t/*\ssize \s*/\s$size,"
- \sputs\s"\\t\\t/*\sdata \s*/\s$data,"
- \sputs\s"\\t\\t/*\sfree \s*/\s0,"
- \sputs\s"\\t},"
+ \sappend\sstruct_data\s"\\t{\\n"\\
+ \s \s \s"\\t\\t/*\sname \s*/\s\\"$shortfile\\",\\n"\\
+ \s \s \s"\\t\\t/*\sindex\s*/\s$idx,\\n"\\
+ \s \s \s"\\t\\t/*\stype \s*/\s$type,\\n"\\
+ \s \s \s"\\t\\t/*\ssize \s*/\s$size,\\n"\\
+ \s \s \s"\\t\\t/*\sdata \s*/\s$data,\\n"\\
+ \s \s \s"\\t\\t/*\sfree \s*/\s0,\\n"\\
+ \s \s \s"\\t},\\n"
}
+puts\s""
+puts\s"static\sstruct\scvfs_data\s${code_tag}_data\\[\\]\s=\s{"
+puts\s"\\t{"
+puts\s"\\t\\t/*\sIndex\s0\scannot\sbe\sused\sbecause\swe\suse\sthe\svalue\s0\sto\srepresent\sfailure\s*/"
+puts\s"\\t\\t/*\sname \s*/\sNULL,"
+puts\s"\\t\\t/*\sindex\s*/\s0,"
+puts\s"\\t\\t/*\stype \s*/\s0,"
+puts\s"\\t\\t/*\ssize \s*/\s0,"
+puts\s"\\t\\t/*\sdata \s*/\sNULL,"
+puts\s"\\t\\t/*\sfree \s*/\s0,"
+puts\s"\\t},"
+puts\s-nonewline\s$struct_data
puts\s"};"
puts\s""
puts\s"static\sunsigned\slong\s${code_tag}_lookup_index(const\schar\s*path)\s{"
puts\s"\\tswitch\s(cvfs_hash((unsigned\schar\s*)\spath))\s{"
for\s{set\sidx\s1}\s{$idx\s<\s[llength\s$files]}\s{incr\sidx}\s{
</verbatim>
J foundin trunk
J login anonymous
J private_contact 0f366eb3e9e2fcab52b8ebacd197db9047186a5f
J severity Minor
J status Open
J title dir2c:\sOutput\sdata\sas\scharacter\sarray\sand\snot\sas\sstring
J type Feature\sRequest
K bd6188edd4290bfdcff4a8ef9355f5280496eda5
U anonymous
Z abde5fc13982fa4229bd20c2de3c66b5