Add tools to the Workbench Tools menu
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.

args.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. ToolsMenu - Add tools to the Workbench Tools menu
  3. Copyright (C) 2015, 2018 Kim Fastrup Larsen
  4. This program is free software: you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation, either ver-
  7. sion 3 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be use-
  9. ful, but WITHOUT ANY WARRANTY; without even the implied war-
  10. ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public Li-
  13. cense along with this program. If not, see
  14. <http://www.gnu.org/licenses/>.
  15. The author can be contacted on <kimflarsen@hotmail.com>
  16. */
  17. #include <dos/dos.h>
  18. #include <dos/rdargs.h>
  19. #include <workbench/startup.h>
  20. #include <clib/alib_protos.h>
  21. #include <clib/dos_protos.h>
  22. #include <clib/exec_protos.h>
  23. #ifdef USE_PRAGMAS
  24. #include <proto/dos.h>
  25. #include <proto/exec.h>
  26. #endif
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "args.h"
  30. #define DEF_CX_PRIORITY 0
  31. #define DEF_CX_POPUP YES
  32. #define DEF_CX_POPKEY "control alt t"
  33. Args args;
  34. static UBYTE **tool_types;
  35. static struct RDArgs *rdargs;
  36. static void get_wb_args(char **argv)
  37. {
  38. struct WBArg *wb_arg = ((struct WBStartup *) argv)->sm_ArgList;
  39. args.exe.dir = wb_arg->wa_Lock;
  40. args.exe.filename = wb_arg->wa_Name;
  41. if ((tool_types = ArgArrayInit(0, argv)) == NULL)
  42. exit(RETURN_FAIL);
  43. args.cx_priority = ArgInt(tool_types, "CX_PRIORITY", DEF_CX_PRIORITY);
  44. args.cx_popup = strcmp(ArgString(tool_types, "CX_POPUP", DEF_CX_POPUP ?
  45. "YES" : "NO"), "NO") != 0;
  46. args.cx_popkey = ArgString(tool_types, "CX_POPKEY", DEF_CX_POPKEY);
  47. }
  48. static void get_shell_args(char **argv)
  49. {
  50. LONG sh_args[3];
  51. args.exe.dir = ((struct Process *) FindTask(NULL))->pr_CurrentDir;
  52. args.exe.filename = argv[0];
  53. sh_args[0] = DEF_CX_PRIORITY;
  54. sh_args[1] = (LONG) DEF_CX_POPKEY;
  55. sh_args[2] = DEF_CX_POPUP ? (LONG) "YES" : (LONG) "NO";
  56. if ((rdargs = ReadArgs(TEMPLATE, sh_args, NULL)) == NULL) {
  57. PrintFault(IoErr(), argv[0]);
  58. exit(RETURN_ERROR);
  59. }
  60. args.cx_priority = sh_args[0];
  61. args.cx_popkey = (STRPTR) sh_args[1];
  62. args.cx_popup = strcmp((char *) sh_args[2], "YES") == 0;
  63. }
  64. void args_set_up(int argc, char **argv)
  65. {
  66. if (argc == 0)
  67. get_wb_args(argv);
  68. else
  69. get_shell_args(argv);
  70. }
  71. void args_clean_up()
  72. {
  73. if (rdargs != NULL)
  74. FreeArgs(rdargs);
  75. if (tool_types != NULL)
  76. ArgArrayDone();
  77. }