Annotation of freem/src/iftab.c, revision 1.3

1.1       snw         1: /*
1.3     ! snw         2:  *   $Id$
1.1       snw         3:  *    implementation of the freem transactions-in-flight symbol table
                      4:  *
                      5:  *  
1.2       snw         6:  *   Author: Serena Willis <snw@coherent-logic.com>
1.1       snw         7:  *    Copyright (C) 1998 MUG Deutschland
1.3     ! snw         8:  *    Copyright (C) 2020, 2025 Coherent Logic Development LLC
1.1       snw         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:  *
1.3     ! snw        26:  *   $Log$
        !            27:  *
        !            28:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
        !            29:  * SPDX-License-Identifier: AGPL-3.0-or-later
1.1       snw        30:  **/
                     31: 
                     32: #include <stdlib.h>
                     33: #include "iftab.h"
                     34: #include "mpsdef.h"
                     35: #include "transact.h"
                     36: 
                     37: iftab *iftab_head;
                     38: 
                     39: iftab *iftab_insert(short action, char *key, char *data, int tlevel)
                     40: {
                     41:     iftab *t;
                     42: 
                     43:     for (t = iftab_head; t != NULL; t = t->next) {
                     44:         
                     45:         if (stcmp (t->key, key) == 0) {
                     46: 
                     47:             /* the key already exists. this is now an update. */
                     48:             free (t->data);
                     49:            
                     50:             t->data = malloc (stlen (data) + 1);
                     51:            NULLPTRCHK(t->data,"iftab_insert");
                     52:            
                     53:             stcpy (t->data, data);
                     54:             t->killed = FALSE;
                     55: 
                     56:             return t;
                     57:         }
                     58: 
                     59:     }
                     60: 
                     61:     /* key did not exist. this is now a true insert. */
                     62: 
                     63:     t = (iftab *) malloc (sizeof (iftab));
                     64:     NULLPTRCHK(t,"iftab_insert");
                     65:     
                     66:     t->key = malloc (stlen (key) + 1);
                     67:     NULLPTRCHK(t->key,"iftab_insert");
                     68:     
                     69:     t->data = malloc (stlen (data) + 1);
                     70:     NULLPTRCHK(t->data,"iftab_insert");
                     71: 
                     72:     stcpy (t->key, key);
                     73:     stcpy (t->data, data);
                     74: 
                     75:     t->killed = FALSE;
                     76:     t->tlevel = tlevel;
                     77:     t->action = action;
                     78: 
                     79:     t->next = iftab_head;
                     80:     iftab_head = t;
                     81: 
                     82:     return t;
                     83: }
                     84: 
                     85: iftab *iftab_retrieve(char *key, char *data)
                     86: {
                     87:     iftab *t;
                     88: 
                     89:     for (t = iftab_head; t != NULL; t = t->next) {
                     90:         if (stcmp (t->key, key) == 0) {
                     91:            
                     92:             data = (char *) malloc (stlen (t->data) + 1);
                     93:            NULLPTRCHK(data,"iftab_retrieve");
                     94:            
                     95:             stcpy (data, t->data);
                     96: 
                     97:             return t;
                     98:         }
                     99:     }
                    100: 
                    101:     return (iftab *) NULL;
                    102: }
                    103: 
                    104: void iftab_delete(char *key)
                    105: {
                    106:     iftab *t = iftab_head;
                    107:     iftab *p = NULL;
                    108: 
                    109: 
                    110:     if ((t != (iftab *) NULL) && (stcmp (t->key, key) == 0)) {
                    111:         iftab_head = t->next;
                    112: 
                    113:         free (t->key);
                    114:         free (t->data);
                    115:         free (t);
                    116:         return;
                    117:     }
                    118: 
                    119:     while ((t != NULL) && (stcmp (t->key, key) != 0)) {
                    120:         p = t;
                    121:         t = t->next;
                    122:     }
                    123: 
                    124:     if (t == NULL) return;
                    125: 
                    126:     p->next = t->next;
                    127:     free (t->key);
                    128:     free (t->data);
                    129:     free (t);
                    130: 
                    131:     return;
                    132: }
                    133: 
                    134: iftab *iftab_kill(char *key)
                    135: {
                    136:     iftab *t;
                    137: 
                    138:     for(t = iftab_head; t != NULL; t = t->next) {
                    139:         if (stcmp (t->key, key) == 0) {
                    140:             t->killed = TRUE;
                    141: 
                    142:             return t;
                    143:         }
                    144:     }
                    145: 
                    146:     t = iftab_insert (kill_sym, key, "\201", tp_level);
                    147:     t->killed = TRUE;
                    148: 
                    149:     return t;
                    150: }
                    151: 
                    152: void iftab_pop_tlevel(int tlevel)
                    153: {
                    154:     iftab *t;
                    155: 
                    156:     for (t = iftab_head; t != NULL; t = t->next) {
                    157:         if (t->tlevel == tlevel) iftab_delete (t->key);
                    158:     }
                    159: }

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