File:  [Coherent Logic Development] / freem / src / mtok.c
Revision 1.3: download - view: text, annotated - select for diffs
Sun Mar 9 19:50:47 2025 UTC (3 weeks, 2 days ago) by snw
Branches: MAIN
CVS tags: v0-62-3, v0-62-2, v0-62-1, v0-62-0, HEAD
Second phase of REUSE compliance and header reformat

/*
 *   $Id: mtok.c,v 1.3 2025/03/09 19:50:47 snw Exp $
 *    Token lookup 
 *
 *  
 *   Author: Serena Willis <snw@coherent-logic.com>
 *    Copyright (C) 1998 MUG Deutschland
 *    Copyright (C) 2020, 2025 Coherent Logic Development LLC
 *
 *
 *   This file is part of FreeM.
 *
 *   FreeM is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   FreeM is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero Public License for more details.
 *
 *   You should have received a copy of the GNU Affero Public License
 *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
 *
 *   $Log: mtok.c,v $
 *   Revision 1.3  2025/03/09 19:50:47  snw
 *   Second phase of REUSE compliance and header reformat
 *
 *
 * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
 * SPDX-License-Identifier: AGPL-3.0-or-later
 **/

#include <stdlib.h>
#include <string.h>

#include "mpsdef.h"
#include "mtok.h"

tok_lut toktab[] = {
    {0, "ABLOCK"},
    {'a', "ASSIGN"},
    {1, "ASTART"},
    {2, "ASTOP"},
    {3, "AUNBLOCK"},
    {'b', "BREAK"},
    {'c', "CLOSE"},
    {'d', "DO"},
    {4, "DO"},
    {'e', "ELSE"},
    {5, "ESTART"},
    {6, "ESTOP"},
    {7, "ETRIGGER"},
    {'f', "FOR"},
    {'g', "GOTO"},
    {'h', "HA"},
    {8, "HALT"},
    {9, "HANG"},
    {'i', "IF"},
    {'j', "JOB"},
    {'k', "KILL"},
    {10, "KVALUE"},
    {11, "KSUBSCRIPTS"},
    {'l', "LOCK"},
    {'m', "MERGE"},
    {'n', "NEW"},
    {'o', "OPEN"},
    {'q', "QUIT"},
    {'r', "READ"},
    {12, "RLOAD"},
    {13, "RSAVE"},
    {'s', "SET"},
    {14, "TCOMMIT"},
    {15, "THEN"},
    {16, "TRESTART"},
    {17, "TROLLBACK"},
    {18, "TSTART"},
    {'u', "USE"},
    {'v', "VIEW"},
    {'w', "WRITE"},
    {'x', "XECUTE"},
    {'A', "ZALLOCATE"},
    {'B', "ZBREAK"},
    {'D', "ZDEALLOCATE"},
    {'G', "ZGO"},
    {'H', "ZHALT"},
    {'I', "ZINSERT"},
    {'J', "ZJOB"},
    {'L', "ZLOAD"},
    {'N', "ZNAMESPACE"},
    {'P', "ZPRINT"},
    {'Q', "ZQUIT"},
    {'R', "ZREMOVE"},
    {'S', "ZSAVE"},
    {'T', "ZTRAP"},
    {'W', "ZWRITE"},
    {20, "ZWATCH"},
    {21, "ZASSERT"},
    {SP, "PRIVATE"},
    {255, NULL}
};

int mtok_token_to_command (char *buf, int token)
{
    tok_lut *p;
    
    for (p = toktab; p->cmd_name != NULL; ++p) {

        if (p->tok == token) {
            strcpy (buf, p->cmd_name);            
            stcnv_c2m (buf);
            return 1;
        }

    }

    return -1;
}

int mtok_command_to_token (char *cmd_name)
{
    tok_lut *p;

    for (p = toktab; p->cmd_name != NULL; ++p) {

        if (strcmp (cmd_name, p->cmd_name) == 0) {
            return p->tok;
        }

    }

    return -1;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>