#include <h/mts.h>
#include <h/utils.h>
-/*
- * maximum number of names
- */
-#define NVEC 50
-
-static struct swit switches[] = {
-#define ALIASW 0
- { "alias aliasfile", 0 },
-#define NALIASW 1
- { "noalias", -7 },
-#define LISTSW 2
- { "list", 0 },
-#define NLISTSW 3
- { "nolist", 0 },
-#define NORMSW 4
- { "normalize", 0 },
-#define NNORMSW 5
- { "nonormalize", 0 },
-#define USERSW 6
- { "user", 0 },
-#define NUSERSW 7
- { "nouser", 0 },
-#define VERSIONSW 8
- { "version", 0 },
-#define HELPSW 9
- { "help", 0 },
- { NULL, 0 }
-};
+#define ALI_SWITCHES \
+ X("alias aliasfile", 0, ALIASW) \
+ X("noalias", -7, NALIASW) \
+ X("list", 0, LISTSW) \
+ X("nolist", 0, NLISTSW) \
+ X("normalize", 0, NORMSW) \
+ X("nonormalize", 0, NNORMSW) \
+ X("user", 0, USERSW) \
+ X("nouser", 0, NUSERSW) \
+ X("version", 0, VERSIONSW) \
+ X("help", 0, HELPSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(ALI);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(ALI, switches);
+#undef X
static int pos = 1;
int i, vecp = 0, inverted = 0, list = 0;
int noalias = 0, normalize = AD_NHST;
char *cp, **ap, **argp, buf[BUFSIZ];
- char *vec[NVEC], **arguments;
+ /* Really only need to allocate for argc-1, but must allocate at least 1,
+ so go ahead and allocate for argc char pointers. */
+ char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments;
struct aka *ak;
#ifdef LOCALE
continue;
}
}
- vec[vecp++] = cp;
+
+ if (vecp < argc) {
+ vec[vecp++] = cp;
+ } else {
+ /* Should never happen, but try to protect against code changes
+ that could allow it. */
+ adios (NULL, "too many arguments");
+ }
}
if (!noalias) {
for (i = 0; i < vecp; i++)
print_usr (vec[i], list, normalize);
-
- done (0);
- }
-
- if (vecp) {
- /* print specified aliases */
- for (i = 0; i < vecp; i++)
- print_aka (akvalue (vec[i]), list, 0);
} else {
- /* print them all */
- for (ak = akahead; ak; ak = ak->ak_next) {
- printf ("%s: ", ak->ak_name);
- pos += strlen (ak->ak_name) + 1;
- print_aka (akresult (ak), list, pos);
+ if (vecp) {
+ /* print specified aliases */
+ for (i = 0; i < vecp; i++)
+ print_aka (akvalue (vec[i]), list, 0);
+ } else {
+ /* print them all */
+ for (ak = akahead; ak; ak = ak->ak_next) {
+ printf ("%s: ", ak->ak_name);
+ pos += strlen (ak->ak_name) + 1;
+ print_aka (akresult (ak), list, pos);
+ }
}
}
+ free (vec);
done (0);
return 1;
}
}
mnfree (mp);
-#if 0
- printf ("%s: ", s);
- print_aka (vp ? vp : s, list, pos += strlen (s) + 1);
-#else
print_aka (vp ? vp : s, list, 0);
-#endif
if (vp)
free (vp);