Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: try.c
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __STDC__
  11. #define __STDC__ 1
  12. #endif
  13. #include <string.h> /* String support. */
  14. #include <tcl.h>
  15. // #include "tcldllUtil.h" /* Our utility service definitions. */
  16. int
  17. TclExt_tryCmd(
  18. ClientData clientData,
  19. Tcl_Interp *interp,
  20. int argc,
  21. char *argv[])
  22. /*
  23. *
  24. * Function description:
  25. *
  26. * This is the main entry point for the Tcl try command.
  27. *
  28. *
  29. * Arguments:
  30. *
  31. * ClientData - Ignored.
  32. *
  33. * interp - The Tcl interpreter in force.
  34. *
  35. * argc - The number of arguments received.
  36. *
  37. * argv - The array of actual arguments.
  38. *
  39. *
  40. * Return value:
  41. *
  42. * TCL_OK - All went well
  43. * TCL_ERROR - An error was encountered, details in the return string.
  44. *
  45. *
  46. * Side effects:
  47. *
  48. * None.
  49. *
  50. */
  51. {
  52. /*
  53. * Local Variable Definitions: %local-vars%
  54. *
  55. Variable Description
  56. -------- --------------------------------------------*/
  57. char
  58. *tryCmd, /* The command to try. */
  59. *catchCmd, /* The command to do if tryCmd fails. */
  60. *varName; /* The name of the variable to receive the error string, if any. */
  61. int
  62. status; /* Status return code. */
  63. /*
  64. * try <commands> catch [<varName>] <errorCommands>
  65. */
  66. #ifdef CMD_TRACE
  67. int j;
  68. for (j = 0; j < argc; j += 1)
  69. (void)printf("{%s} ", argv[j]);
  70. (void)printf("\n");
  71. breakpoint;
  72. #endif
  73. if ((4 > argc) || (5 < argc))
  74. {
  75. Tcl_AppendResult(
  76. interp,
  77. "wrong number of args: should be \"",
  78. argv[0],
  79. " <command> catch [<varName>] <errorCommand>\"",
  80. NULL);
  81. status = TCL_ERROR;
  82. goto error_exit;
  83. }
  84. if (strcmp("catch", argv[2]))
  85. {
  86. Tcl_AppendResult(
  87. interp,
  88. "invalid args: should be \"",
  89. argv[0],
  90. " <command> catch [<varName>] <errorCommand>\"",
  91. NULL);
  92. status = TCL_ERROR;
  93. goto error_exit;
  94. }
  95. /*
  96. * Execute the first set of commands. If an error occurs, execute the
  97. * second set of commands, with the local variable errorString set to the
  98. * result of the first execution.
  99. */
  100. if (5 == argc)
  101. {
  102. varName = argv[3];
  103. catchCmd = argv[4];
  104. }
  105. else
  106. {
  107. varName = NULL;
  108. catchCmd = argv[3];
  109. }
  110. tryCmd = argv[1];
  111. if (TCL_ERROR == (status = Tcl_Eval(interp, tryCmd)))
  112. {
  113. if (NULL != varName)
  114. (void)Tcl_SetVar(interp, varName, interp->result, 0);
  115. status = Tcl_Eval(interp, catchCmd);
  116. }
  117. error_exit:
  118. return status;
  119. } /* end TclExt_tryCmd */
  120. /* end try.c */