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.

main.c 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <exec/libraries.h>
  18. #include <clib/exec_protos.h>
  19. #ifdef USE_PRAGMAS
  20. #include <proto/exec.h>
  21. #endif
  22. #include <stdlib.h>
  23. #define CATCOMP_NUMBERS
  24. #include "args.h"
  25. #include "broker.h"
  26. #include "catalog.h"
  27. #include "error.h"
  28. #include "gui.h"
  29. #include "strings.h"
  30. #include "toolrun.h"
  31. #include "wb.h"
  32. #define OS_REQUIRED 37
  33. extern struct Library *SysBase;
  34. extern struct Library *DOSBase;
  35. char *version = "\0$VER: " TITLE " (" DATE ")";
  36. struct Library *CxBase;
  37. struct Library *GadToolsBase;
  38. struct Library *IconBase;
  39. struct Library *IntuitionBase;
  40. struct Library *LocaleBase;
  41. struct Library *WorkbenchBase;
  42. static ULONG signals = SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_F;
  43. static ULONG wb_signal, tr_signal, broker_signal, gui_signal;
  44. static void check_system_version(void)
  45. {
  46. if (SysBase->lib_Version<OS_REQUIRED||DOSBase->lib_Version<OS_REQUIRED)
  47. exit(RETURN_FAIL);
  48. }
  49. static struct Library *open_library(STRPTR name)
  50. {
  51. struct Library *base;
  52. if ((base = OpenLibrary(name, OS_REQUIRED)) == NULL) {
  53. error_message(get_string(MSG_ERR_OPEN), name);
  54. exit(RETURN_FAIL);
  55. }
  56. return base;
  57. }
  58. static void open_libraries(void)
  59. {
  60. IntuitionBase = open_library("intuition.library");
  61. IconBase = open_library("icon.library");
  62. CxBase = open_library("commodities.library");
  63. GadToolsBase = open_library("gadtools.library");
  64. WorkbenchBase = open_library("workbench.library");
  65. }
  66. static void set_up(int argc, char **argv)
  67. {
  68. LocaleBase = OpenLibrary("locale.library", 38);
  69. open_catalog(CATALOG);
  70. open_libraries();
  71. args_set_up(argc, argv);
  72. signals |= wb_signal = wb_set_up();
  73. signals |= tr_signal = tr_set_up();
  74. signals |= broker_signal = broker_set_up();
  75. signals |= gui_signal = gui_set_up();
  76. cx_set_up();
  77. }
  78. static void main_loop(void)
  79. {
  80. ULONG received;
  81. for (;;) {
  82. received = Wait(signals);
  83. if (received & wb_signal)
  84. wb_handle_signal();
  85. if (received & tr_signal)
  86. tr_handle_signal();
  87. if (received & broker_signal)
  88. broker_handle_signal();
  89. if (received & gui_signal)
  90. gui_handle_signal();
  91. if (received & SIGBREAKF_CTRL_C)
  92. cx_quit();
  93. if (received & SIGBREAKF_CTRL_F)
  94. cx_show();
  95. }
  96. }
  97. static void close_libraries(void)
  98. {
  99. CloseLibrary(WorkbenchBase);
  100. CloseLibrary(GadToolsBase);
  101. CloseLibrary(CxBase);
  102. CloseLibrary(IconBase);
  103. CloseLibrary(IntuitionBase);
  104. }
  105. /* Clean up as much as possible, then wait for the all tools started by us to
  106. quit before finishing up. */
  107. static void clean_up(void)
  108. {
  109. cx_clean_up();
  110. gui_clean_up();
  111. broker_clean_up();
  112. /* tr_clean_up() won't return until all tools have quit. */
  113. tr_clean_up();
  114. wb_clean_up();
  115. args_clean_up();
  116. close_libraries();
  117. close_catalog();
  118. CloseLibrary(LocaleBase);
  119. }
  120. int main(int argc, char **argv)
  121. {
  122. check_system_version();
  123. atexit(clean_up);
  124. set_up(argc, argv);
  125. if (args.cx_popup)
  126. cx_show();
  127. main_loop();
  128. }