Diff

Differences From Artifact [28f9b94a91]:

To Artifact [903b20a63c]:


     1      1   #! /usr/bin/env tclsh
     2      2   
     3      3   if {[llength $argv] != 2} {
     4         -	puts stderr "Usage: kitdll <hashkey> <startdir>"
            4  +	puts stderr "Usage: dir2c.tcl <hashkey> <startdir>"
     5      5   
     6      6   	exit 1
     7      7   }
     8      8   
     9      9   set hashkey [lindex $argv 0]
    10     10   set startdir [lindex $argv 1]
    11     11   
................................................................................
    72     72   
    73     73   	set ret "\"$ret\""
    74     74   
    75     75   	return $ret
    76     76   }
    77     77   
    78     78   # This function must be kept in-sync with the generated C function below
    79         -proc kitdll_hash {path} {
           79  +proc cvfs_hash {path} {
    80     80   	set h 0
    81     81   	set g 0
    82     82   
    83     83   	for {set idx 0} {$idx < [string length $path]} {incr idx} {
    84     84   		binary scan [string index $path $idx] H* char
    85     85   		set char "0x$char"
    86     86   
................................................................................
    99     99   # Generate list of files to include in output
   100    100   set files [recursive_glob $startdir]
   101    101   
   102    102   # Insert dummy entry cooresponding to C dummy entry
   103    103   set files [linsert $files 0 "__DUMMY__"]
   104    104   
   105    105   # Produce C89 compatible header
   106         -set cpp_tag "KITDLL_[string toupper $hashkey]"
   107         -set code_tag "kitdll_[string tolower $hashkey]"
          106  +set cpp_tag "CVFS_[string toupper $hashkey]"
          107  +set code_tag "cvfs_[string tolower $hashkey]"
   108    108   set hashkey [string tolower $hashkey]
   109    109   
   110    110   puts "#ifndef $cpp_tag"
   111    111   puts "#  define $cpp_tag 1"
   112    112   puts {
   113    113   #  ifdef HAVE_STDC
   114    114   #    ifndef HAVE_UNISTD_H
................................................................................
   121    121   #  ifdef HAVE_UNISTD_H
   122    122   #    include <unistd.h>
   123    123   #  endif
   124    124   #  ifdef HAVE_STRING_H
   125    125   #    include <string.h>
   126    126   #  endif
   127    127   
   128         -#  ifndef LOADED_KITDLL_COMMON
   129         -#    define LOADED_KITDLL_COMMON 1
          128  +#  ifndef LOADED_CVFS_COMMON
          129  +#    define LOADED_CVFS_COMMON 1
   130    130   
   131    131   typedef enum {
   132         -	KITDLL_FILETYPE_FILE,
   133         -	KITDLL_FILETYPE_DIR
   134         -} kitdll_filetype_t;
          132  +	CVFS_FILETYPE_FILE,
          133  +	CVFS_FILETYPE_DIR
          134  +} cvfs_filetype_t;
   135    135   
   136         -struct kitdll_data {
          136  +struct cvfs_data {
   137    137   	const char *             name;
   138    138   	unsigned long            index;
   139    139   	unsigned long            size;
   140         -	kitdll_filetype_t        type;
          140  +	cvfs_filetype_t          type;
   141    141   	const unsigned char *    data;
   142    142   };
   143    143   
   144         -static unsigned long kitdll_hash(const unsigned char *path) {
          144  +static unsigned long cvfs_hash(const unsigned char *path) {
   145    145   	unsigned long i, h = 0, g = 0;
   146    146   
   147    147   	for (i = 0; path[i]; i++) {
   148    148   		h = (h << 4) + path[i];
   149    149   		g = h & 0xf0000000;
   150    150   		if (g) {
   151    151   			h ^= (g >> 24);
................................................................................
   152    152   		}
   153    153   		h &= ((~g) & 0xffffffffLU);
   154    154   	}
   155    155           
   156    156           return(h);
   157    157   }
   158    158   
   159         -#  endif /* !LOADED_KITDLL_COMMON */}
          159  +#  endif /* !LOADED_CVFS_COMMON */}
   160    160   puts ""
   161    161   
   162         -puts "static struct kitdll_data ${code_tag}_data\[\] = {"
          162  +puts "static struct cvfs_data ${code_tag}_data\[\] = {"
   163    163   puts "\t{"
   164    164   puts "\t\t.name  = NULL,"
   165    165   puts "\t\t.index = 0,"
   166    166   puts "\t\t.type  = 0,"
   167    167   puts "\t\t.size  = 0,"
   168    168   puts "\t\t.data  = NULL,"
   169    169   puts "\t},"
................................................................................
   172    172   	set shortfile [shorten_file $startdir $file]
   173    173   
   174    174   	unset -nocomplain finfo type
   175    175   	file stat $file finfo
   176    176   
   177    177   	switch -- $finfo(type) {
   178    178   		"file" {
   179         -			set type "KITDLL_FILETYPE_FILE"
          179  +			set type "CVFS_FILETYPE_FILE"
   180    180   			set size $finfo(size)
   181    181   
   182    182   			set fd [open $file]
   183    183   			fconfigure $fd -translation binary
   184    184   			set data [read $fd]
   185    185   			close $fd
   186    186   
   187    187   			set data "(unsigned char *) [stringify $data]"
   188    188   		}
   189    189   		"directory" {
   190         -			set type "KITDLL_FILETYPE_DIR"
          190  +			set type "CVFS_FILETYPE_DIR"
   191    191   			set data "NULL"
   192    192   			set size 0
   193    193   		}
   194    194   	}
   195    195   
   196    196   	puts "\t{"
   197    197   	puts "\t\t.name  = \"$shortfile\","
................................................................................
   201    201   	puts "\t\t.data  = $data,"
   202    202   	puts "\t},"
   203    203   }
   204    204   puts "};"
   205    205   puts ""
   206    206   
   207    207   puts "static unsigned long ${code_tag}_lookup_index(const char *path) {"
   208         -puts "\tswitch (kitdll_hash((unsigned char *) path)) {"
          208  +puts "\tswitch (cvfs_hash((unsigned char *) path)) {"
   209    209   
   210    210   for {set idx 1} {$idx < [llength $files]} {incr idx} {
   211    211   	set file [lindex $files $idx]
   212    212   	set shortfile [shorten_file $startdir $file]
   213         -	set hash [kitdll_hash $shortfile]
          213  +	set hash [cvfs_hash $shortfile]
   214    214   
   215    215   	lappend indexes_per_hash($hash) [list $shortfile $idx]
   216    216   }
   217    217   
   218    218   foreach {hash idx_list} [array get indexes_per_hash] {
   219    219   	puts "\t\tcase $hash:"
   220    220   
................................................................................
   234    234   }
   235    235   
   236    236   puts "\t}"
   237    237   puts "\treturn(0);"
   238    238   puts "}"
   239    239   puts ""
   240    240   
   241         -puts "static struct kitdll_data *${code_tag}_getData(const char *path, unsigned long index) {"
          241  +puts "static struct cvfs_data *${code_tag}_getData(const char *path, unsigned long index) {"
   242    242   puts "\tif (path != NULL) {"
   243    243   puts "\t\tindex = ${code_tag}_lookup_index(path);"
   244    244   puts "\t}"
   245    245   puts ""
   246    246   puts "\tif (index == 0) {"
   247    247   puts "\t\treturn(NULL);"
   248    248   puts "\t}"
................................................................................
   262    262   puts "\tunsigned long num_children = 0;"
   263    263   puts ""
   264    264   puts "\tindex = ${code_tag}_lookup_index(path);"
   265    265   puts "\tif (index == 0) {"
   266    266   puts "\t\treturn(0);"
   267    267   puts "\t}"
   268    268   puts ""
   269         -puts "\tif (${code_tag}_data\[index\].type != KITDLL_FILETYPE_DIR) {"
          269  +puts "\tif (${code_tag}_data\[index\].type != CVFS_FILETYPE_DIR) {"
   270    270   puts "\t\treturn(0);"
   271    271   puts "\t}"
   272    272   puts ""
   273    273   puts "\tif (strcmp(path, ${code_tag}_data\[index\].name) != 0) {"
   274    274   puts "\t\treturn(0);"
   275    275   puts "\t}"
   276    276   puts ""
................................................................................
   347    347   
   348    348   puts "\t}"
   349    349   puts ""
   350    350   puts "\treturn(num_children);"
   351    351   puts "}"
   352    352   puts ""
   353    353   
   354         -puts "#  ifdef KITDLL_MAKE_LOADABLE"
          354  +puts "#  ifdef CVFS_MAKE_LOADABLE"
   355    355   
   356         -set fd [open "vfs_kitdll_data.c"]
          356  +set fd [open "cvfs_data.c"]
   357    357   puts [read $fd]
   358    358   close $fd
   359    359   
   360    360   
   361    361   puts "static cmd_getData_t *getCmdData(const char *hashkey) {"
   362    362   puts "\treturn(${code_tag}_getData);"
   363    363   puts "}"
   364    364   puts ""
   365    365   puts "static cmd_getChildren_t *getCmdChildren(const char *hashkey) {"
   366    366   puts "\treturn(${code_tag}_getChildren);"
   367    367   puts "}"
   368    368   puts ""
   369    369   
   370         -puts "int Vfs_kitdll_data_${hashkey}_Init(Tcl_Interp *interp) {"
          370  +puts "int Cvfs_data_${hashkey}_Init(Tcl_Interp *interp) {"
   371    371   puts "\tTcl_Command tclCreatComm_ret;"
   372    372   puts "\tint tclPkgProv_ret;"
   373    373   puts ""
   374         -puts "\ttclCreatComm_ret = Tcl_CreateObjCommand(interp, \"::vfs::kitdll::data::${hashkey}::getMetadata\", getMetadata, NULL, NULL);"
          374  +puts "\ttclCreatComm_ret = Tcl_CreateObjCommand(interp, \"::vfs::cvfs::data::${hashkey}::getMetadata\", getMetadata, NULL, NULL);"
          375  +puts "\tif (!tclCreatComm_ret) {"
          376  +puts "\t\treturn(TCL_ERROR);"
          377  +puts "\t}"
          378  +puts ""
          379  +puts "\ttclCreatComm_ret = Tcl_CreateObjCommand(interp, \"::vfs::cvfs::data::${hashkey}::getData\", getData, NULL, NULL);"
   375    380   puts "\tif (!tclCreatComm_ret) {"
   376    381   puts "\t\treturn(TCL_ERROR);"
   377    382   puts "\t}"
   378    383   puts ""
   379         -puts "\ttclCreatComm_ret = Tcl_CreateObjCommand(interp, \"::vfs::kitdll::data::${hashkey}::getData\", getData, NULL, NULL);"
          384  +puts "\ttclCreatComm_ret = Tcl_CreateObjCommand(interp, \"::vfs::cvfs::data::${hashkey}::getChildren\", getChildren, NULL, NULL);"
   380    385   puts "\tif (!tclCreatComm_ret) {"
   381    386   puts "\t\treturn(TCL_ERROR);"
   382    387   puts "\t}"
   383    388   puts ""
   384         -puts "\ttclCreatComm_ret = Tcl_CreateObjCommand(interp, \"::vfs::kitdll::data::${hashkey}::getChildren\", getChildren, NULL, NULL);"
   385         -puts "\tif (!tclCreatComm_ret) {"
   386         -puts "\t\treturn(TCL_ERROR);"
   387         -puts "\t}"
   388         -puts ""
   389         -puts "\ttclPkgProv_ret = Tcl_PkgProvide(interp, \"vfs::kitdll::data::${hashkey}\", \"1.0\");"
          389  +puts "\ttclPkgProv_ret = Tcl_PkgProvide(interp, \"vfs::cvfs::data::${hashkey}\", \"1.0\");"
   390    390   puts ""
   391    391   puts "\treturn(tclPkgProv_ret);"
   392    392   puts "\t}"
   393         -puts "#  endif /* KITDLL_MAKE_LOADABLE */"
          393  +puts "#  endif /* CVFS_MAKE_LOADABLE */"
   394    394   
   395    395   puts "#endif /* !$cpp_tag */"