View Ticket
Ticket Hash: 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:
Dear Sean,

thank you for great C-VFS. I am trying to get it working by little steps.
There might be a wiki recipe on success for the medium programmer of this wizard program.

Just a note. TCL and Metakit is normally C89 clean. The output of dir2c.tcl is not, as it uses this style of initialization:

<verbatim>
static struct cvfs_data cvfs_tcl_data[] = {
    {
        /* Index 0 cannot be used because we use the value 0 to represent failure */
        .name  = NULL,
        .index = 0,
        .type  = 0,
        .size  = 0,
        .data  = NULL,
        .free  = 0,
    },
</verbatim>

Unfortunately, C89 does not allow to name the structure items.
The patch below transforms this output into:

<verbatim>
static struct cvfs_data cvfs_tcl_data[] = {
    {
        /* Index 0 cannot be used because we use the value 0 to represent failure */
        /* name  */ NULL,
        /* index */ 0,
        /* type  */ 0,
        /* size  */ 0,
        /* data  */ NULL,
        /* free  */ 0,
    },
</verbatim>

Here is the 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/* type  */ 0,"
+puts "\t\t/* size  */ 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/* type  */ $type,"
+    puts "\t\t/* size  */ $size,"
+    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>

Thank you and best regards,
Harald
User Comments:
anonymous (claiming to be oehhar) added on 2020-05-11 16:33:18:

Sorry, the patch has the issue, that the two members "type" and "size" are mixed up. Here is a corrected patch:


--- 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)) {"


rkeene added on 2020-05-11 16:42:39:
Thanks !  The replacement for C-VFS is called XVFS by the way:

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