Check-in [a85a20ac7a]
Overview
Comment:Implemented vfs::kitdll::data::getData

Fixed references to Tcl_SetResult() to use TCL_STATIC as freeProc

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a85a20ac7a66d0dc7a02b8fdd8a00fb244d9a919
User & Date: rkeene on 2010-09-26 04:51:22
Other Links: manifest | tags
Context
2010-09-26
04:51
Removed Tcl implementation of getData check-in: 2e1961564b user: rkeene tags: trunk
04:51
Implemented vfs::kitdll::data::getData

Fixed references to Tcl_SetResult() to use TCL_STATIC as freeProc check-in: a85a20ac7a user: rkeene tags: trunk

04:51
Got KitDLL storage into workable state

Renamed some files for consistency

Added basic Makefile check-in: 424322801f user: rkeene tags: trunk

Changes

Modified kitdll/buildsrc/kitdll-0.0/vfs_kitdll_data.c from [fdbf11d0e3] to [7be7436122].

    33     33   	struct kitdll_data *finfo = NULL;
    34     34   	Tcl_Obj *ret_list, *ret_list_items[20];
    35     35   	unsigned long num_children;
    36     36   	const char *hashkey;
    37     37   	const char *file;
    38     38   
    39     39   	if (objc != 3) {
    40         -		Tcl_SetResult(interp, "wrong # args: should be \"getMetadata hashKey fileName\"", NULL);
           40  +		Tcl_SetResult(interp, "wrong # args: should be \"getMetadata hashKey fileName\"", TCL_STATIC);
    41     41   
    42     42   		return(TCL_ERROR);
    43     43   	}
    44     44   
    45     45   	hashkey = Tcl_GetString(objv[1]);
    46     46   	file = Tcl_GetString(objv[2]);
    47     47   
    48     48   	cmd_getData = getCmdData(hashkey);
    49     49   	cmd_getChildren = getCmdChildren(hashkey);
    50     50   
    51     51   	if (cmd_getData == NULL || cmd_getChildren == NULL) {
    52         -		Tcl_SetResult(interp, "No such hashkey", NULL);
           52  +		Tcl_SetResult(interp, "No such hashkey", TCL_STATIC);
    53     53   
    54     54   		return(TCL_ERROR);
    55     55   	}
    56     56   
    57     57   	finfo = cmd_getData(file, 0);
    58     58   
    59     59   	if (finfo == NULL) {
    60         -		Tcl_SetResult(interp, "No such file or directory", NULL);
           60  +		Tcl_SetResult(interp, "No such file or directory", TCL_STATIC);
    61     61   
    62     62   		return(TCL_ERROR);
    63     63   	}
    64     64   
    65     65   	/* Values that can be derived from "finfo" */
    66     66   	ret_list_items[0] = Tcl_NewStringObj("type", 4);
    67     67   	ret_list_items[2] = Tcl_NewStringObj("mode", 4);
................................................................................
   105    105   
   106    106   	Tcl_SetObjResult(interp, ret_list);
   107    107   
   108    108   	return(TCL_OK);
   109    109   }
   110    110   
   111    111   static int getData(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
          112  +	struct kitdll_data *finfo = NULL;
          113  +	cmd_getData_t *cmd_getData;
          114  +	const char *hashkey;
          115  +	const char *file;
          116  +	const char *end_str;
          117  +	Tcl_Obj *ret_str;
          118  +	long start = 0;
          119  +	long end = -1;
          120  +	int tclGetLFO_ret;
          121  +
   112    122   	if (objc < 3 || objc > 5) {
   113         -		Tcl_SetResult(interp, "wrong # args: should be \"getData hashKey fileName ?start? ?end?\"", NULL);
          123  +		Tcl_SetResult(interp, "wrong # args: should be \"getData hashKey fileName ?start? ?end?\"", TCL_STATIC);
          124  +
          125  +		return(TCL_ERROR);
          126  +	}
          127  +
          128  +	hashkey = Tcl_GetString(objv[1]);
          129  +	file = Tcl_GetString(objv[2]);
          130  +
          131  +	if (objc > 3) {
          132  +		tclGetLFO_ret = Tcl_GetLongFromObj(interp, objv[3], &start);
          133  +
          134  +		if (tclGetLFO_ret != TCL_OK) {
          135  +			return(tclGetLFO_ret);
          136  +		}
          137  +	}
          138  +
          139  +	if (objc > 4) {
          140  +		end_str = Tcl_GetString(objv[4]);
          141  +		if (strcmp(end_str, "end") == 0) {
          142  +			end = -1;
          143  +		} else {
          144  +			tclGetLFO_ret = Tcl_GetLongFromObj(interp, objv[4], &end);
          145  +
          146  +			if (tclGetLFO_ret != TCL_OK) {
          147  +				return(tclGetLFO_ret);
          148  +			}
          149  +		}
          150  +	}
          151  +
          152  +	cmd_getData = getCmdData(hashkey);
          153  +
          154  +	if (cmd_getData == NULL) {
          155  +		Tcl_SetResult(interp, "No such hashkey", TCL_STATIC);
          156  +
          157  +		return(TCL_ERROR);
          158  +	}
          159  +
          160  +	finfo = cmd_getData(file, 0);
          161  +
          162  +	if (finfo == NULL) {
          163  +		Tcl_SetResult(interp, "No such file or directory", TCL_STATIC);
          164  +
          165  +		return(TCL_ERROR);
          166  +	}
          167  +
          168  +	if (finfo->type != KITDLL_FILETYPE_FILE) {
          169  +		Tcl_SetResult(interp, "Not a file", TCL_STATIC);
          170  +
          171  +		return(TCL_ERROR);
          172  +	}
          173  +
          174  +	if (end == -1) {
          175  +		end = finfo->size;
          176  +	}
          177  +
          178  +	if (end > finfo->size) {
          179  +		end = finfo->size;
          180  +	}
          181  +
          182  +	if (start < 0) {
          183  +		start = 0;
          184  +	}
          185  +
          186  +	if (end < 0) {
          187  +		end = 0;
          188  +	}
          189  +
          190  +	if (end < start) {
          191  +		Tcl_SetResult(interp, "Invalid arguments, start must be less than end", TCL_STATIC);
   114    192   
   115    193   		return(TCL_ERROR);
   116    194   	}
   117         -	return(TCL_ERROR);
          195  +
          196  +	ret_str = Tcl_NewStringObj((const char *) finfo->data + start, (end - start));
          197  +
          198  +	Tcl_SetObjResult(interp, ret_str);
          199  +
          200  +	return(TCL_OK);
   118    201   }
   119    202   
   120    203   static int getChildren(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
          204  +	struct kitdll_data *finfo = NULL;
   121    205   	cmd_getChildren_t *cmd_getChildren;
   122    206   	cmd_getData_t *cmd_getData;
   123         -	struct kitdll_data *finfo = NULL;
   124    207   	unsigned long num_children, idx;
   125    208   	unsigned long *children;
   126    209   	const char *hashkey;
   127    210   	const char *file;
   128    211   	const char *child;
   129    212   	Tcl_Obj *ret_list, *ret_curr_obj;
   130    213   
   131    214   	if (objc != 3) {
   132         -		Tcl_SetResult(interp, "wrong # args: should be \"getChildren hashKey fileName\"", NULL);
          215  +		Tcl_SetResult(interp, "wrong # args: should be \"getChildren hashKey fileName\"", TCL_STATIC);
   133    216   
   134    217   		return(TCL_ERROR);
   135    218   	}
   136    219   
   137    220   	hashkey = Tcl_GetString(objv[1]);
   138    221   	file = Tcl_GetString(objv[2]);
   139    222   
   140    223   	cmd_getData = getCmdData(hashkey);
   141    224   	cmd_getChildren = getCmdChildren(hashkey);
   142    225   
   143    226   	if (cmd_getData == NULL || cmd_getChildren == NULL) {
   144         -		Tcl_SetResult(interp, "No such hashkey", NULL);
          227  +		Tcl_SetResult(interp, "No such hashkey", TCL_STATIC);
   145    228   
   146    229   		return(TCL_ERROR);
   147    230   	}
   148    231   
   149    232   	finfo = cmd_getData(file, 0);
   150    233   
   151    234   	if (finfo == NULL) {
   152         -		Tcl_SetResult(interp, "No such file or directory", NULL);
          235  +		Tcl_SetResult(interp, "No such file or directory", TCL_STATIC);
   153    236   
   154    237   		return(TCL_ERROR);
   155    238   	}
   156    239   
   157    240   	if (finfo->type != KITDLL_FILETYPE_DIR) {
   158         -		Tcl_SetResult(interp, "Not a directory", NULL);
          241  +		Tcl_SetResult(interp, "Not a directory", TCL_STATIC);
   159    242   
   160    243   		return(TCL_ERROR);
   161    244   	}
   162    245   
   163    246   	num_children = cmd_getChildren(file, NULL, 0);
   164    247   
   165    248   	if (num_children == 0) {
   166    249   		/* Return immediately if there are no children */
   167         -		Tcl_SetResult(interp, "", NULL);
          250  +		Tcl_SetResult(interp, "", TCL_STATIC);
   168    251   
   169    252   		return(TCL_OK);
   170    253   	}
   171    254   
   172    255   	ret_list = Tcl_NewObj();
   173    256   	if (ret_list == NULL) {
   174         -		Tcl_SetResult(interp, "Failed to allocate new object", NULL);
          257  +		Tcl_SetResult(interp, "Failed to allocate new object", TCL_STATIC);
   175    258   
   176    259   		return(TCL_ERROR);
   177    260   	}
   178    261   
   179    262   	children = malloc(sizeof(*children) * num_children);
   180    263   
   181    264   	num_children = cmd_getChildren(file, children, num_children);