static int find_alias __P((char *, int));
static int add_alias __P((char *, int));
static int more_aliases __P((size_t));
+static char *dotcat __P((char *, char *));
int yyerror(s)
char *s;
%}
%union {
- char string[MAXCOMMANDLENGTH+1];
+ char *string;
int tok;
}
%start file /* special start symbol */
%token <string> ALIAS /* an UPPERCASE alias name */
%token <string> NTWKADDR /* w.x.y.z */
-%token <string> NETGROUP /* +NAME */
+%token <string> NETGROUP /* a netgroup (+NAME) */
%token <string> COMMAND /* an absolute pathname + args */
%token <string> NAME /* a mixed-case name */
%token <tok> COMMENT /* comment and/or carriage return */
| NTWKADDR {
if (addr_matches($1))
host_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| NETGROUP {
if (netgr_matches($1, host, NULL))
host_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| NAME {
if (strcmp(host, $1) == 0)
host_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| ALIAS {
if (find_alias($1, HOST))
host_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| fqdn {
#ifdef HAVE_STRCASECMP
if (strcmp($1, host) == 0)
host_matches = TRUE;
#endif /* HAVE_STRCASECMP */
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
;
fqdn : NAME '.' NAME {
- (void) strcpy($$, $1);
- (void) strcat($$, ".");
- (void) strcat($$, $3);
+ $$ = dotcat($1, $3);
+ (void) free($1);
+ (void) free($3);
+ $1 = $3 = NULL; /* XXX */
}
| fqdn '.' NAME {
- (void) strcpy($$, $1);
- (void) strcat($$, ".");
- (void) strcat($$, $3);
+ $$ = dotcat($1, $3);
+ (void) free($3);
+ $3 = NULL; /* XXX */
}
;
| ALIAS {
if (find_alias($1, CMND))
cmnd_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| COMMAND {
if (path_matches(cmnd, $1))
cmnd_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
;
if (cmnd_matches == TRUE && !add_alias($1, CMND))
YYERROR;
pop;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
;
if (user_matches == TRUE && !add_alias($1, USER))
YYERROR;
pop;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
;
user : NAME {
if (strcmp($1, user) == 0)
user_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| NETGROUP {
if (netgr_matches($1, NULL, user))
user_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| ALIAS {
if (find_alias($1, USER))
user_matches = TRUE;
+ (void) free($1);
+ $1 = NULL; /* XXX */
}
| ALL {
user_matches = TRUE;
size_t naliases = 0;
size_t nslots = 0;
+
static int aliascmp(a1, a2)
const VOID *a1, *a2;
{
return(ok);
}
+
static int find_alias(alias, type)
char *alias;
int type;
sizeof(ai), aliascmp) != NULL);
}
+
static int more_aliases(nslots)
size_t nslots;
{
return(aip != NULL);
}
+
int dumpaliases()
{
size_t n;
}
}
+
void reset_aliases()
{
if (aliases)
(void) free(aliases);
naliases = nslots = 0;
}
+
+
+static char *dotcat(s1, s2)
+ char *s1;
+ char *s2;
+{
+ int len1; /* length of param 1 */
+ int fulllen; /* length of params 1, 2, '.' */
+ char *s; /* string to return */
+
+ /* how much space do we need? */
+ len1 = strlen(s1);
+ fulllen = len1 + 1 + strlen(s2);
+
+ /* allocate the space */
+ s = (char *) malloc(fulllen + 1);
+ if (s == NULL)
+ yyerror("unable to allocate memory");
+
+ /* cat s1.s2 -> s effeciently */
+ (void) strcpy(s, s1);
+ *(s + len1) = '.';
+ (void) strcpy(s + len1 + 1, s2);
+
+ return(s);
+}