Fixed AutoDoc indentation, spelling, grammar.
[AROS.git] / tools / toollib / toollib.c
blobd13069c9e1eebfeeea41a24fe97050ab19788c24
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <ctype.h>
9 #include <assert.h>
10 #include <toollib/toollib.h>
12 int verbose;
14 /* Functions */
15 char *
16 _xstrdup (const char * str, const char * file, int line)
18 char * nstr;
20 assert (str);
22 nstr = strdup (str);
24 if (!nstr)
26 fprintf (stderr, "Out of memory in %s:%d", file, line);
27 exit (20);
30 return nstr;
33 void *
34 _xmalloc (size_t size, const char * file, int line)
36 void * ptr;
38 ptr = malloc (size);
40 if (size && !ptr)
42 fprintf (stderr, "Out of memory in %s:%d", file, line);
43 exit (20);
46 return ptr;
49 void *
50 _xrealloc (void * optr, size_t size, const char * file, int line)
52 void * ptr;
54 ptr = realloc (optr, size);
56 if (size && !ptr)
58 fprintf (stderr, "Out of memory in %s:%d", file, line);
59 exit (20);
62 return ptr;
65 void
66 _xfree (void * ptr, const char * file, int line)
68 if (ptr)
69 free (ptr);
70 else
71 fprintf (stderr, "Illegal free(NULL) in %s:%d", file, line);
74 void *
75 _xcalloc (size_t number, size_t size, const char * file, int line)
77 void * ptr;
79 ptr = calloc (number, size);
81 if (size && !ptr)
83 fprintf (stderr, "Out of memory in %s:%d", file, line);
84 exit (20);
87 return ptr;
90 Node *
91 FindNode (const List * l, const char * name)
93 Node * n;
95 ForeachNode (l, n)
97 if (!strcmp (n->name, name))
98 return n;
101 return NULL;
104 Node *
105 FindNodeNC (const List * l, const char * name)
107 Node * n;
109 ForeachNode (l, n)
111 if (!strcasecmp (n->name, name))
112 return n;
115 return NULL;
118 void
119 printlist (const List * l)
121 Node * n;
123 ForeachNode (l,n)
125 printf (" \"%s\"\n", n->name);
130 execute (const char * cmd, const char * args,
131 const char * in, const char * out)
133 char buffer[4096];
134 int rc;
136 strcpy (buffer, cmd);
137 strcat (buffer, " ");
139 if (strcmp (in, "-"))
141 strcat (buffer, "<");
142 strcat (buffer, in);
143 strcat (buffer, " ");
146 if (strcmp (out, "-"))
148 strcat (buffer, ">");
149 strcat (buffer, out);
150 strcat (buffer, " ");
153 strcat (buffer, args);
155 if (verbose)
156 printf ("Executing %s...\n", buffer);
158 rc = system (buffer);
160 if (rc)
162 printf ("%s failed: %d\n", buffer, rc);
165 return !rc;
168 Node *
169 RemHead (List * l)
171 Node * node = GetHead (l);
173 Remove (node);
175 return node;