Posted to tcl by mjanssen at Thu Sep 21 11:48:24 GMT 2006view raw

  1. #include <tcl.h>
  2.  
  3. typedef struct ShapeFile {
  4. Tcl_Obj * filename; /* the name of the shape filem */
  5. Tcl_Channel chan; /* the channel to the openend shape file */
  6. } ShapeFile;
  7.  
  8.  
  9. static int ShpObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])
  10. {
  11. ShapeFile *shp = (ShapeFile*)clientData;
  12. Tcl_SetObjResult(interp, shp->filename);
  13. return TCL_OK;
  14. }
  15. static int ShpShpCmd ( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
  16. {
  17. char *cmdName;
  18. ShapeFile *shp;
  19. shp = (ShapeFile*)Tcl_Alloc(sizeof(*shp));
  20. shp->chan = NULL;
  21. shp->filename = NULL;
  22. cmdName = Tcl_GetStringFromObj(objv[1], 0);
  23. shp->filename = Tcl_DuplicateObj(objv[2]);
  24. Tcl_CreateObjCommand(interp, cmdName, ShpObjCmd, shp, NULL);
  25. return TCL_OK;
  26. }
  27.  
  28.  
  29.  
  30. __declspec(dllexport) int Hello_Init(Tcl_Interp *interp)
  31. {
  32. /* we want to use stubs */
  33. if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
  34. return TCL_ERROR;
  35. }
  36. Tcl_CreateObjCommand(interp, "shp", ShpShpCmd, NULL, NULL);
  37. Tcl_PkgProvide(interp, "Hello", "1.0");
  38. return TCL_OK;
  39. }