/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)keywords.c 1.5 (Berkeley) %G%";
* Keyword and alias management.
private String reserved
[] ={
"alias", "and", "assign", "at", "call", "catch", "cont",
"debug", "delete", "div", "down", "dump", "edit", "file", "func",
"gripe", "help", "if", "ignore", "in",
"list", "mod", "next", "nexti", "nil", "not", "or",
"print", "psym", "quit", "rerun", "return", "run",
"sh", "skip", "source", "status", "step", "stepi",
"stop", "stopi", "trace", "tracei", "up",
"use", "whatis", "when", "where", "whereis", "which",
"INT", "REAL", "NAME", "STRING",
"LFORMER", "RFORMER", "#^", "->"
* The keyword table is a traditional hash table with collisions
typedef unsigned int Hashvalue
;
private Keyword hashtab
[KEYWORDHASH
];
#define keyhash(n) ((((unsigned) n) >> 2) mod KEYWORDHASH)
* The alias table is virtually the same, just
* replace the token id with a string to which
private Alias aliashashtab
[ALIASHASH
];
#define aliashash(n) ((((unsigned) n) >> 2) mod ALIASHASH)
* Enter all the reserved words into the keyword table.
for (i
= ALIAS
; i
<= WHICH
; i
++)
keyword(reserved
[ord(i
) - ord(ALIAS
)], i
);
alias(identname("c", true), identname(keywdstring(CONT
), true));
alias(identname("d", true), identname(keywdstring(DELETE
), true));
alias(identname("h", true), identname(keywdstring(HELP
), true));
alias(identname("e", true), identname(keywdstring(EDIT
), true));
alias(identname("l", true), identname(keywdstring(LIST
), true));
alias(identname("n", true), identname(keywdstring(NEXT
), true));
alias(identname("p", true), identname(keywdstring(PRINT
), true));
alias(identname("q", true), identname(keywdstring(QUIT
), true));
alias(identname("r", true), identname(keywdstring(RUN
), true));
alias(identname("s", true), identname(keywdstring(STEP
), true));
alias(identname("st", true), identname(keywdstring(STOP
), true));
alias(identname("j", true), identname(keywdstring(STATUS
), true));
alias(identname("t", true), identname(keywdstring(WHERE
), true));
* Deallocate the keyword and alias tables.
register Keyword k
, nextk
;
for (i
= 0; i
< KEYWORDHASH
; i
++) {
for (k
= hashtab
[i
]; k
!= nil
; k
= nextk
) {
for (i
= 0; i
< ALIASHASH
; i
++) {
for (a
= aliashashtab
[i
]; a
!= nil
; a
= nexta
) {
* Enter a keyword into the name table.
* It is assumed to not be there already.
* The string is assumed to be statically allocated.
* Return the string associated with a token corresponding to a keyword.
public String
keywdstring(t
)
return reserved
[ord(t
) - ord(ALIAS
)];
* Return the token associated with a given keyword string.
* We assume that tokens cannot legitimately be nil (0).
public Token
findkeyword(n
)
for (k
= hashtab
[keyhash(n
)]; k
!= nil
&& k
->name
!= n
; k
= k
->chain
)
return (k
== nil
? nil
: k
->toknum
);
public String
findalias(n
)
for (a
= aliashashtab
[aliashash(n
)]; a
!= nil
&& a
->name
!= n
; a
= a
->chain
)
return (a
== nil
? nil
: ident(a
->expansion
));
public enter_alias(cmd
, p
)
error("\"%s\" can't redefine a command", ident(cmd
));
n
= identname(p
->value
.scon
, true);
n
= identname(ident(p
->value
.name
), true);
for (a
= aliashashtab
[h
]; a
!= nil
&& a
->name
!= cmd
; a
= a
->chain
)
a
->chain
= aliashashtab
[h
];
printf(s
== nil
? "\n" : "%s\n", s
);
for (i
= 0; i
< ALIASHASH
; i
++) {
for (a
= aliashashtab
[i
]; a
!= nil
; a
= a
->chain
) {
printf("%s\t%s\n", ident(a
->name
), ident(a
->expansion
));