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.

common.c 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/lists.h>
  18. #include <exec/memory.h>
  19. #include <clib/exec_protos.h>
  20. #ifdef USE_PRAGMAS
  21. #include <proto/exec.h>
  22. #endif
  23. #include <string.h>
  24. #include "common.h"
  25. char *copy_of(char *s)
  26. {
  27. char *result;
  28. if ((result = AllocVec(strlen(s) + 1, MEMF_PUBLIC)) != NULL)
  29. strcpy(result, s);
  30. return result;
  31. }
  32. void for_all(struct List *l, void (*f)(void *))
  33. {
  34. struct Node *n, *next;
  35. /* This form of iteration allows f() to free nodes */
  36. for (n = l->lh_Head; (next = n->ln_Succ) != NULL; n = next)
  37. (*f)(n);
  38. }
  39. Bool is_in_list(struct List *l, struct Node *node)
  40. {
  41. struct Node *n;
  42. for (n = l->lh_Head; n->ln_Succ != NULL; n = n->ln_Succ)
  43. if (n == node)
  44. return YES;
  45. return NO;
  46. }
  47. struct Node *node_at(struct List *l, int i)
  48. {
  49. struct Node *n;
  50. for (n = l->lh_Head; n->ln_Succ != NULL; n = n->ln_Succ) {
  51. if (i == 0)
  52. return n;
  53. --i;
  54. }
  55. return NULL;
  56. }
  57. int length_of(struct List *l)
  58. {
  59. struct Node *n;
  60. int result = 0;
  61. for (n = l->lh_Head; n->ln_Succ != NULL; n = n->ln_Succ)
  62. ++result;
  63. return result;
  64. }
  65. void delete_port(struct MsgPort *port)
  66. {
  67. struct Message *msg;
  68. if (port != NULL) {
  69. while ((msg = GetMsg(port)) != NULL)
  70. ReplyMsg(msg);
  71. DeleteMsgPort(port);
  72. }
  73. }