error.c revision 50764
11573Srgrimes/* 21573Srgrimes * Copyright (c) 1997, 1998 Kungliga Tekniska H�gskolan 31573Srgrimes * (Royal Institute of Technology, Stockholm, Sweden). 41573Srgrimes * All rights reserved. 51573Srgrimes * 61573Srgrimes * Redistribution and use in source and binary forms, with or without 71573Srgrimes * modification, are permitted provided that the following conditions 81573Srgrimes * are met: 91573Srgrimes * 101573Srgrimes * 1. Redistributions of source code must retain the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer. 121573Srgrimes * 131573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141573Srgrimes * notice, this list of conditions and the following disclaimer in the 151573Srgrimes * documentation and/or other materials provided with the distribution. 161573Srgrimes * 171573Srgrimes * 3. All advertising materials mentioning features or use of this software 181573Srgrimes * must display the following acknowledgement: 191573Srgrimes * This product includes software developed by Kungliga Tekniska 201573Srgrimes * H�gskolan and its contributors. 211573Srgrimes * 221573Srgrimes * 4. Neither the name of the Institute nor the names of its contributors 231573Srgrimes * may be used to endorse or promote products derived from this software 241573Srgrimes * without specific prior written permission. 251573Srgrimes * 261573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 271573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 301573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361573Srgrimes * SUCH DAMAGE. 3792986Sobrien */ 3892986Sobrien 391573Srgrimes#ifdef HAVE_CONFIG_H 401573Srgrimes#include <config.h> 411573SrgrimesRCSID("$Id: error.c,v 1.13 1998/02/17 21:19:44 bg Exp $"); 421573Srgrimes#endif 431573Srgrimes#include <stdio.h> 44154252Sjasone#include <stdlib.h> 451573Srgrimes#include <string.h> 46154252Sjasone#include <com_right.h> 471573Srgrimes 48154252Sjasoneconst char * 49154252Sjasonecom_right(struct et_list *list, long code) 50154252Sjasone{ 51154252Sjasone struct et_list *p; 521573Srgrimes for (p = list; p; p = p->next) { 53 if (code >= p->table->base && code < p->table->base + p->table->n_msgs) 54 return p->table->msgs[code - p->table->base]; 55 } 56 return NULL; 57} 58 59struct foobar { 60 struct et_list etl; 61 struct error_table et; 62}; 63 64void 65initialize_error_table_r(struct et_list **list, 66 const char **messages, 67 int num_errors, 68 long base) 69{ 70 struct et_list *et; 71 struct foobar *f; 72 for (et = *list; et; et = et->next) 73 if (et->table->msgs == messages) 74 return; 75 f = malloc(sizeof(*f)); 76 if (f == NULL) 77 return; 78 et = &f->etl; 79 et->table = &f->et; 80 et->table->msgs = messages; 81 et->table->n_msgs = num_errors; 82 et->table->base = base; 83 et->next = *list; 84 *list = et; 85} 86 87 88void 89free_error_table(struct et_list *et) 90{ 91 while(et){ 92 struct et_list *p = et; 93 et = et->next; 94 free(p); 95 } 96} 97