1: /*
2: * $Id: mtok.c,v 1.4 2025/04/02 03:02:42 snw Exp $
3: * Token lookup
4: *
5: *
6: * Author: Serena Willis <snw@coherent-logic.com>
7: * Copyright (C) 1998 MUG Deutschland
8: * Copyright (C) 2020, 2025 Coherent Logic Development LLC
9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
26: * $Log: mtok.c,v $
27: * Revision 1.4 2025/04/02 03:02:42 snw
28: * Stop requiring users to pass -e to fmadm when -u or -g are passed
29: *
30: * Revision 1.3 2025/03/09 19:50:47 snw
31: * Second phase of REUSE compliance and header reformat
32: *
33: *
34: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
35: * SPDX-License-Identifier: AGPL-3.0-or-later
36: **/
37:
38: #include <stdlib.h>
39: #include <string.h>
40:
41: #include "mpsdef.h"
42: #include "mtok.h"
43:
44: tok_lut toktab[] = {
45: {0, "ABLOCK"},
46: {'a', "ASSIGN"},
47: {1, "ASTART"},
48: {2, "ASTOP"},
49: {3, "AUNBLOCK"},
50: {'b', "BREAK"},
51: {'c', "CLOSE"},
52: {'d', "DO"},
53: {4, "DO"},
54: {'e', "ELSE"},
55: {5, "ESTART"},
56: {6, "ESTOP"},
57: {7, "ETRIGGER"},
58: {'f', "FOR"},
59: {'g', "GOTO"},
60: {'h', "HA"},
61: {8, "HALT"},
62: {9, "HANG"},
63: {'i', "IF"},
64: {'j', "JOB"},
65: {'k', "KILL"},
66: {10, "KVALUE"},
67: {11, "KSUBSCRIPTS"},
68: {'l', "LOCK"},
69: {'m', "MERGE"},
70: {'n', "NEW"},
71: {'o', "OPEN"},
72: {'q', "QUIT"},
73: {'r', "READ"},
74: {12, "RLOAD"},
75: {13, "RSAVE"},
76: {'s', "SET"},
77: {14, "TCOMMIT"},
78: {15, "THEN"},
79: {16, "TRESTART"},
80: {17, "TROLLBACK"},
81: {18, "TSTART"},
82: {'u', "USE"},
83: {'v', "VIEW"},
84: {'w', "WRITE"},
85: {'x', "XECUTE"},
86: {'B', "ZBREAK"},
87: {'G', "ZGO"},
88: {'H', "ZHALT"},
89: {'I', "ZINSERT"},
90: {'J', "ZJOB"},
91: {'L', "ZLOAD"},
92: {'N', "ZNAMESPACE"},
93: {'P', "ZPRINT"},
94: {'Q', "ZQUIT"},
95: {'R', "ZREMOVE"},
96: {'S', "ZSAVE"},
97: {'T', "ZTRAP"},
98: {'W', "ZWRITE"},
99: {20, "ZWATCH"},
100: {21, "ZASSERT"},
101: {SP, "PRIVATE"},
102: {255, NULL}
103: };
104:
105: int mtok_token_to_command (char *buf, int token)
106: {
107: tok_lut *p;
108:
109: for (p = toktab; p->cmd_name != NULL; ++p) {
110:
111: if (p->tok == token) {
112: strcpy (buf, p->cmd_name);
113: stcnv_c2m (buf);
114: return 1;
115: }
116:
117: }
118:
119: return -1;
120: }
121:
122: int mtok_command_to_token (char *cmd_name)
123: {
124: tok_lut *p;
125:
126: for (p = toktab; p->cmd_name != NULL; ++p) {
127:
128: if (strcmp (cmd_name, p->cmd_name) == 0) {
129: return p->tok;
130: }
131:
132: }
133:
134: return -1;
135: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>