1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile standards.h:
|
---|
4 | * some things that are always needed and never
|
---|
5 | * declared in a common place. Here you go.
|
---|
6 | *
|
---|
7 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
8 | * numbering.
|
---|
9 | *
|
---|
10 | *@@include #include "helpers\standards.h"
|
---|
11 | */
|
---|
12 |
|
---|
13 | /* Copyright (C) 2001 Ulrich Mller.
|
---|
14 | * This file is part of the "XWorkplace helpers" source package.
|
---|
15 | * This is free software; you can redistribute it and/or modify
|
---|
16 | * it under the terms of the GNU General Public License as published
|
---|
17 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
18 | * "COPYING" file of the XWorkplace main distribution.
|
---|
19 | * This program is distributed in the hope that it will be useful,
|
---|
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
22 | * GNU General Public License for more details.
|
---|
23 | */
|
---|
24 |
|
---|
25 | #ifndef STANDARDS_HEADER_INCLUDED
|
---|
26 | #define STANDARDS_HEADER_INCLUDED
|
---|
27 |
|
---|
28 | /*
|
---|
29 | *@@ NEW:
|
---|
30 | * wrapper around the typical malloc struct
|
---|
31 | * sequence.
|
---|
32 | *
|
---|
33 | * Usage:
|
---|
34 | *
|
---|
35 | + STRUCT *p = NEW(STRUCT);
|
---|
36 | *
|
---|
37 | * This expands to:
|
---|
38 | *
|
---|
39 | + STRUCT *p = (STRUCT *)malloc(sizeof(STRUCT));
|
---|
40 | *
|
---|
41 | *@@added V0.9.9 (2001-04-01) [umoeller]
|
---|
42 | */
|
---|
43 |
|
---|
44 | #define NEW(type) (type *)malloc(sizeof(type))
|
---|
45 |
|
---|
46 | /*
|
---|
47 | *@@ ZERO:
|
---|
48 | * wrapper around the typical zero-struct
|
---|
49 | * sequence.
|
---|
50 | *
|
---|
51 | * Usage:
|
---|
52 | *
|
---|
53 | + ZERO(p)
|
---|
54 | *
|
---|
55 | * This expands to:
|
---|
56 | *
|
---|
57 | + memset(p, 0, sizeof(*p));
|
---|
58 | *
|
---|
59 | *@@added V0.9.9 (2001-04-01) [umoeller]
|
---|
60 | */
|
---|
61 |
|
---|
62 | #define ZERO(ptr) memset(ptr, 0, sizeof(*ptr))
|
---|
63 |
|
---|
64 | /*
|
---|
65 | *@@ FREE:
|
---|
66 | * wrapper around the typical free() sequence.
|
---|
67 | *
|
---|
68 | * Usage:
|
---|
69 | *
|
---|
70 | + FREE(p)
|
---|
71 | *
|
---|
72 | * This expands to:
|
---|
73 | *
|
---|
74 | + if (p)
|
---|
75 | + {
|
---|
76 | + free(p);
|
---|
77 | + p = NULL;
|
---|
78 | + }
|
---|
79 | *
|
---|
80 | *@@added V0.9.16 (2001-12-08) [umoeller]
|
---|
81 | */
|
---|
82 |
|
---|
83 | #define FREE(ptr) { if ((ptr)) { free(ptr); ptr = NULL; } }
|
---|
84 |
|
---|
85 | /*
|
---|
86 | *@@ ARRAYITEMCOUNT:
|
---|
87 | * helpful macro to count the count of items
|
---|
88 | * in an array. Use this to avoid typos when
|
---|
89 | * having to pass the array item count to
|
---|
90 | * a function.
|
---|
91 | *
|
---|
92 | * ULONG aul[] = { 0, 1, 2, 3, 4 };
|
---|
93 | *
|
---|
94 | * ARRAYITEMCOUNT(aul) then expands to:
|
---|
95 | *
|
---|
96 | + sizeof(aul) / sizeof(aul[0])
|
---|
97 | *
|
---|
98 | * which should return 5. Note that the compiler
|
---|
99 | * should calculate this at compile-time, so that
|
---|
100 | * there is no run-time overhead... and this will
|
---|
101 | * never miscount the array item size.
|
---|
102 | *
|
---|
103 | *@@added V0.9.9 (2001-01-29) [umoeller]
|
---|
104 | */
|
---|
105 |
|
---|
106 | #define ARRAYITEMCOUNT(array) (sizeof(array) / sizeof(array[0]))
|
---|
107 |
|
---|
108 | /*
|
---|
109 | *@@ STRINGORNULL:
|
---|
110 | * helpful macro to avoid passing null strings
|
---|
111 | * to debugging printf calls.
|
---|
112 | *
|
---|
113 | *@@added V0.9.16 (2002-01-05) [umoeller]
|
---|
114 | */
|
---|
115 |
|
---|
116 | #define STRINGORNULL(s) (s) ? (s) : "NULL"
|
---|
117 |
|
---|
118 | #endif
|
---|
119 |
|
---|
120 |
|
---|