error.c revision 72445
1285169Scy/* 2132451Sroberto * Copyright (c) 1997, 1998 Kungliga Tekniska H�gskolan 3285169Scy * (Royal Institute of Technology, Stockholm, Sweden). 4285169Scy * All rights reserved. 5132451Sroberto * 6132451Sroberto * Redistribution and use in source and binary forms, with or without 7132451Sroberto * modification, are permitted provided that the following conditions 8132451Sroberto * are met: 9132451Sroberto * 10132451Sroberto * 1. Redistributions of source code must retain the above copyright 11132451Sroberto * notice, this list of conditions and the following disclaimer. 12132451Sroberto * 13132451Sroberto * 2. Redistributions in binary form must reproduce the above copyright 14285169Scy * notice, this list of conditions and the following disclaimer in the 15200576Sroberto * documentation and/or other materials provided with the distribution. 16200576Sroberto * 17285169Scy * 3. Neither the name of the Institute nor the names of its contributors 18285169Scy * may be used to endorse or promote products derived from this software 19200576Sroberto * without specific prior written permission. 20200576Sroberto * 21285169Scy * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22200576Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23280849Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24280849Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25132451Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26280849Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27280849Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28280849Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29280849Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30132451Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31280849Scy * SUCH DAMAGE. 32280849Scy */ 33280849Scy 34280849Scy#ifdef HAVE_CONFIG_H 35280849Scy#include <config.h> 36132451SrobertoRCSID("$Id: error.c,v 1.14 1999/12/02 16:58:38 joda Exp $"); 37280849Scy#endif 38280849Scy#include <stdio.h> 39280849Scy#include <stdlib.h> 40280849Scy#include <string.h> 41280849Scy#include <com_right.h> 42280849Scy 43280849Scyconst char * 44280849Scycom_right(struct et_list *list, long code) 45280849Scy{ 46280849Scy struct et_list *p; 47280849Scy for (p = list; p; p = p->next) { 48280849Scy if (code >= p->table->base && code < p->table->base + p->table->n_msgs) 49280849Scy return p->table->msgs[code - p->table->base]; 50132451Sroberto } 51280849Scy return NULL; 52182007Sroberto} 53280849Scy 54280849Scystruct foobar { 55280849Scy struct et_list etl; 56280849Scy struct error_table et; 57280849Scy}; 58280849Scy 59280849Scyvoid 60280849Scyinitialize_error_table_r(struct et_list **list, 61280849Scy const char **messages, 62182007Sroberto int num_errors, 63280849Scy long base) 64182007Sroberto{ 65280849Scy struct et_list *et; 66280849Scy struct foobar *f; 67280849Scy for (et = *list; et; et = et->next) 68280849Scy if (et->table->msgs == messages) 69280849Scy return; 70280849Scy f = malloc(sizeof(*f)); 71280849Scy if (f == NULL) 72280849Scy return; 73280849Scy et = &f->etl; 74280849Scy et->table = &f->et; 75182007Sroberto et->table->msgs = messages; 76182007Sroberto et->table->n_msgs = num_errors; 77280849Scy et->table->base = base; 78280849Scy et->next = *list; 79280849Scy *list = et; 80280849Scy} 81280849Scy 82280849Scy 83280849Scyvoid 84182007Srobertofree_error_table(struct et_list *et) 85132451Sroberto{ 86132451Sroberto while(et){ 87280849Scy struct et_list *p = et; 88280849Scy et = et->next; 89280849Scy free(p); 90280849Scy } 91182007Sroberto} 92280849Scy