| 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 "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 | *@@ ARRAYITEMCOUNT:
|
|---|
| 66 | * helpful macro to count the count of items
|
|---|
| 67 | * in an array. Use this to avoid typos when
|
|---|
| 68 | * having to pass the array item count to
|
|---|
| 69 | * a function.
|
|---|
| 70 | *
|
|---|
| 71 | * ULONG aul[] = { 0, 1, 2, 3, 4 };
|
|---|
| 72 | *
|
|---|
| 73 | * ARRAYITEMCOUNT(aul) then expands to:
|
|---|
| 74 | *
|
|---|
| 75 | + sizeof(aul) / sizeof(aul[0])
|
|---|
| 76 | *
|
|---|
| 77 | * which should return 5. Note that the compiler
|
|---|
| 78 | * should calculate this at compile-time, so that
|
|---|
| 79 | * there is no run-time overhead... and this will
|
|---|
| 80 | * never miscount the array item size.
|
|---|
| 81 | *
|
|---|
| 82 | *@@added V0.9.9 (2001-01-29) [umoeller]
|
|---|
| 83 | */
|
|---|
| 84 |
|
|---|
| 85 | #define ARRAYITEMCOUNT(array) sizeof(array) / sizeof(array[0])
|
|---|
| 86 |
|
|---|
| 87 | #endif
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|