150764Smarkm/* 2127804Snectar * Copyright (c) 1997, 1998, 2001 Kungliga Tekniska H�gskolan 350764Smarkm * (Royal Institute of Technology, Stockholm, Sweden). 450764Smarkm * All rights reserved. 550764Smarkm * 650764Smarkm * Redistribution and use in source and binary forms, with or without 750764Smarkm * modification, are permitted provided that the following conditions 850764Smarkm * are met: 950764Smarkm * 1050764Smarkm * 1. Redistributions of source code must retain the above copyright 1150764Smarkm * notice, this list of conditions and the following disclaimer. 1250764Smarkm * 1350764Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1450764Smarkm * notice, this list of conditions and the following disclaimer in the 1550764Smarkm * documentation and/or other materials provided with the distribution. 1650764Smarkm * 17127804Snectar * 3. Neither the name of the Institute nor the names of its contributors 1850764Smarkm * may be used to endorse or promote products derived from this software 1950764Smarkm * without specific prior written permission. 2050764Smarkm * 2150764Smarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2250764Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2350764Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2450764Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2550764Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2650764Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2750764Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2850764Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2950764Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3050764Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3150764Smarkm * SUCH DAMAGE. 3250764Smarkm */ 3350764Smarkm 3450764Smarkm#ifdef HAVE_CONFIG_H 3550764Smarkm#include <config.h> 36178843SdfrRCSID("$Id: error.c 9724 2001-02-28 20:00:13Z joda $"); 3750764Smarkm#endif 3850764Smarkm#include <stdio.h> 3950764Smarkm#include <stdlib.h> 4050764Smarkm#include <string.h> 4150764Smarkm#include <com_right.h> 4250764Smarkm 4350764Smarkmconst char * 4450764Smarkmcom_right(struct et_list *list, long code) 4550764Smarkm{ 4650764Smarkm struct et_list *p; 4750764Smarkm for (p = list; p; p = p->next) { 4850764Smarkm if (code >= p->table->base && code < p->table->base + p->table->n_msgs) 4950764Smarkm return p->table->msgs[code - p->table->base]; 5050764Smarkm } 5150764Smarkm return NULL; 5250764Smarkm} 5350764Smarkm 5450764Smarkmstruct foobar { 5550764Smarkm struct et_list etl; 5650764Smarkm struct error_table et; 5750764Smarkm}; 5850764Smarkm 5950764Smarkmvoid 6050764Smarkminitialize_error_table_r(struct et_list **list, 6150764Smarkm const char **messages, 6250764Smarkm int num_errors, 6350764Smarkm long base) 6450764Smarkm{ 65127804Snectar struct et_list *et, **end; 6650764Smarkm struct foobar *f; 67127804Snectar for (end = list, et = *list; et; end = &et->next, et = et->next) 6850764Smarkm if (et->table->msgs == messages) 6950764Smarkm return; 7050764Smarkm f = malloc(sizeof(*f)); 7150764Smarkm if (f == NULL) 7250764Smarkm return; 7350764Smarkm et = &f->etl; 7450764Smarkm et->table = &f->et; 7550764Smarkm et->table->msgs = messages; 7650764Smarkm et->table->n_msgs = num_errors; 7750764Smarkm et->table->base = base; 78127804Snectar et->next = NULL; 79127804Snectar *end = et; 8050764Smarkm} 8150764Smarkm 8250764Smarkm 8350764Smarkmvoid 8450764Smarkmfree_error_table(struct et_list *et) 8550764Smarkm{ 8650764Smarkm while(et){ 8750764Smarkm struct et_list *p = et; 8850764Smarkm et = et->next; 8950764Smarkm free(p); 9050764Smarkm } 9150764Smarkm} 92