Posted to tcl by mjanssen at Fri May 04 09:33:14 GMT 2007view raw

  1. /*
  2. *----------------------------------------------------------------------
  3. *
  4. * Tcl_ModeObjCmd --
  5. *
  6. *----------------------------------------------------------------------
  7. */
  8.  
  9. /* ARGSUSED */
  10. int
  11. Tcl_ModeObjCmd(
  12. ClientData dummy, /* Not used. */
  13. Tcl_Interp *interp, /* Current interpreter. */
  14. int objc, /* Number of arguments. */
  15. Tcl_Obj *const objv[]) /* Argument objects. */
  16. {
  17. Tcl_Channel chan; /* The channel to puts on. */
  18. const char *channelId; /* Name of channel for puts. */
  19. int mode; /* Mode in which channel is opened. */
  20.  
  21. if (objc != 2) {
  22. Tcl_WrongNumArgs(interp, 1, objv, "channelId");
  23. return TCL_ERROR;
  24. }
  25.  
  26. channelId = Tcl_GetString(objv[1]);
  27.  
  28. chan = Tcl_GetChannel(interp, channelId, &mode);
  29. if (chan == (Tcl_Channel) NULL) {
  30. return TCL_ERROR;
  31. }
  32.  
  33. if ((mode & TCL_READABLE) != 0) {
  34. Tcl_AppendElement(interp, "r");
  35. }
  36.  
  37. if ((mode & TCL_WRITABLE) != 0) {
  38. Tcl_AppendElement(interp, "w");
  39. }
  40.  
  41. return TCL_OK;
  42.  
  43. }