View Ticket
Ticket UUID: 127ac40147407d703ee7ccd70c865c6a87c53c56
Title: Output C89 data from dir2c.tcl
Status: Open Type: Code Defect
Severity: Minor Priority: Low
Subsystem: KitDLL (The libTclkit Core) Resolution: Open
Last Modified: 2020-05-11 16:42:39
Version Found In: trunk
Description:
<div>Dear Sean,</div><div><br /></div><div>thank you for great C-VFS. I am trying to get it working by little steps.</div><div>There might be a wiki recipe on success for the medium programmer of this wizard program.<br /></div><div><br /></div><div>Just a note. TCL and Metakit is normally C89 clean. The output of dir2c.tcl is not, as it uses this style of initialization:</div><div><br /></div><div>&lt;verbatim&gt;</div><div>static struct cvfs_data cvfs_tcl_data[] = {<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Index 0 cannot be used because we use the value 0 to represent failure */<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .name&nbsp; = NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .index = 0,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .type&nbsp; = 0,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .size&nbsp; = 0,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .data&nbsp; = NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .free&nbsp; = 0,<br />&nbsp;&nbsp;&nbsp; },</div><div>&lt;/verbatim&gt;<br /></div><div><br /></div><div>Unfortunately, C89 does not allow to name the structure items.</div><div>The patch below transforms this output into:</div><div><br /></div><div>&lt;verbatim&gt;</div><div>static struct cvfs_data cvfs_tcl_data[] = {<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Index 0 cannot be used because we use the value 0 to represent failure */<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* name&nbsp; */ NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* index */ 0,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* type&nbsp; */ 0,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* size&nbsp; */ 0,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* data&nbsp; */ NULL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* free&nbsp; */ 0,<br />&nbsp;&nbsp;&nbsp; },<br /></div><div>&lt;/verbatim&gt;</div><div><br /></div><div>Here is the patch:</div><div><br /></div><div>&lt;verbatim&gt;</div><div>--- C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c_ori.tcl&nbsp;&nbsp;&nbsp; Wed Jan 22 20:53:52 2020<br />+++ C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl&nbsp;&nbsp;&nbsp; Fri Apr 17 10:20:20 2020<br />@@ -306,20 +306,20 @@<br />&nbsp;<br />&nbsp;#&nbsp; endif /* !LOADED_CVFS_COMMON */}<br />&nbsp;puts ""<br />&nbsp;<br />&nbsp;puts "static struct cvfs_data ${code_tag}_data\[\] = {"<br />&nbsp;puts "\t{"<br />&nbsp;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\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 />&nbsp;puts "\t},"<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 />@@ -345,20 +345,20 @@<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;&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\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;&nbsp; puts "\t},"<br />&nbsp;}<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)) {"&lt;/verbatim&gt;<br /></div><div><br /></div><div>Thank you and best regards,</div><div>Harald<br /></div>
User Comments:
anonymous (claiming to be oehhar) added on 2020-05-11 16:33:18: (text/x-fossil-wiki)
Sorry, the patch has the issue, that the two members "type" and "size" are mixed up.
Here is a corrected patch:

<verbatim>

--- C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c_ori.tcl    Wed Jan 22 20:53:52 2020
+++ C:/oehhar/elmicron/projekte/el1005_scanlink_dll/source/c-vfs/dir2c.tcl    Fri Apr 17 10:20:20 2020
@@ -306,20 +306,20 @@
 
 #  endif /* !LOADED_CVFS_COMMON */}
 puts ""
 
 puts "static struct cvfs_data ${code_tag}_data\[\] = {"
 puts "\t{"
 puts "\t\t/* Index 0 cannot be used because we use the value 0 to represent failure */"
-puts "\t\t.name  = NULL,"
-puts "\t\t.index = 0,"
-puts "\t\t.type  = 0,"
-puts "\t\t.size  = 0,"
-puts "\t\t.data  = NULL,"
-puts "\t\t.free  = 0,"
+puts "\t\t/* name  */ NULL,"
+puts "\t\t/* index */ 0,"
+puts "\t\t/* size  */ 0,"
+puts "\t\t/* type  */ 0,"
+puts "\t\t/* data  */ NULL,"
+puts "\t\t/* free  */ 0,"
 puts "\t},"
 for {set idx 1} {$idx < [llength $files]} {incr idx} {
     set file [lindex $files $idx]
     set shortfile [shorten_file $startdir $file]
 
     unset -nocomplain finfo type
     file stat $file finfo
@@ -345,20 +345,20 @@
             set type "CVFS_FILETYPE_DIR"
             set data "NULL"
             set size 0
         }
     }
 
     puts "\t{"
-    puts "\t\t.name  = \"$shortfile\","
-    puts "\t\t.index = $idx,"
-    puts "\t\t.type  = $type,"
-    puts "\t\t.size  = $size,"
-    puts "\t\t.data  = $data,"
-    puts "\t\t.free  = 0,"
+    puts "\t\t/* name  */ \"$shortfile\","
+    puts "\t\t/* index */ $idx,"
+    puts "\t\t/* size  */ $size,"
+    puts "\t\t/* type  */ $type,"
+    puts "\t\t/* data  */ $data,"
+    puts "\t\t/* free  */ 0,"
     puts "\t},"
 }
 puts "};"
 puts ""
 
 puts "static unsigned long ${code_tag}_lookup_index(const char *path) {"
 puts "\tswitch (cvfs_hash((unsigned char *) path)) {"

</verbatim>

rkeene added on 2020-05-11 16:42:39: (text/x-fossil-plain)
Thanks !  The replacement for C-VFS is called XVFS by the way:

https://chiselapp.com/user/rkeene/repository/xvfs/