aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Farina <tfransosi@gmail.com>2010-06-03 20:36:01 -0300
committerLinus Torvalds <torvalds@linux-foundation.org>2010-06-08 21:29:13 -0700
commit9489673a1b15b764d774cef4fa15e6e0222821e3 (patch)
tree257939d13f4233eb0ba5b1d7d2010801d4640cdf
parente32cecc843cb7f74e5ced292b29b756d46fc6a3d (diff)
downloaduemacs-9489673a1b15b764d774cef4fa15e6e0222821e3.tar.gz
uemacs: Add ARRAY_SIZE macro so we can get rid of some hard coded calculations.
Signed-off-by: Thiago Farina <thiago.farina@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--eval.c19
-rw-r--r--evar.h4
-rw-r--r--util.h6
3 files changed, 17 insertions, 12 deletions
diff --git a/eval.c b/eval.c
index fa25080..158c336 100644
--- a/eval.c
+++ b/eval.c
@@ -6,11 +6,12 @@
* modified by Petri Kutvonen
*/
-#include <stdio.h>
-#include "estruct.h"
-#include "edef.h"
+#include <stdio.h>
+#include "estruct.h"
+#include "edef.h"
#include "efunc.h"
-#include "evar.h"
+#include "evar.h"
+#include "util.h"
void varinit(void)
{ /* initialize the user variable list */
@@ -196,13 +197,13 @@ char *gtenv(char *vname)
int vnum; /* ordinal number of var refrenced */
/* scan the list, looking for the referenced name */
- for (vnum = 0; vnum < NEVARS; vnum++)
+ for (vnum = 0; vnum < ARRAY_SIZE(envars); vnum++)
if (strcmp(vname, envars[vnum]) == 0)
break;
/* return errorm on a bad reference */
- if (vnum == NEVARS)
-#if ENVFUNC
+ if (vnum == ARRAY_SIZE(envars))
+#if ENVFUNC
{
char *ename = getenv(vname);
@@ -453,11 +454,11 @@ void findvar(char *var, VDESC *vd, int size)
vnum = -1;
fvar:
- vtype = -1;
+ vtype = -1;
switch (var[0]) {
case '$': /* check for legal enviromnent var */
- for (vnum = 0; vnum < NEVARS; vnum++)
+ for (vnum = 0; vnum < ARRAY_SIZE(envars); vnum++)
if (strcmp(&var[1], envars[vnum]) == 0) {
vtype = TKENV;
break;
diff --git a/evar.h b/evar.h
index 9d9e9f7..3ad1a68 100644
--- a/evar.h
+++ b/evar.h
@@ -67,9 +67,7 @@ static char *envars[] = {
#endif
};
-#define NEVARS sizeof(envars) / sizeof(char *)
-
-/* and its preprocesor definitions */
+/* and its preprocesor definitions */
#define EVFILLCOL 0
#define EVPAGELEN 1
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..49f3649
--- /dev/null
+++ b/util.h
@@ -0,0 +1,6 @@
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+#endif /* UTIL_H_ */