1/*
2 * Copyright 1987, 1988 by MIT Student Information Processing Board
3 *
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose is hereby granted, provided that
6 * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7 * advertising or publicity pertaining to distribution of the software
8 * without specific, written prior permission.  M.I.T. and the
9 * M.I.T. S.I.P.B. make no representations about the suitability of
10 * this software for any purpose.  It is provided "as is" without
11 * express or implied warranty.
12 */
13
14#ifdef HAVE_ERRNO_H
15#include <errno.h>
16#endif
17
18#include "ss_internal.h"
19
20#define ssrt ss_request_table	/* for some readable code... */
21
22void ss_add_request_table(sci_idx, rqtbl_ptr, position, code_ptr)
23	int sci_idx;
24	ssrt *rqtbl_ptr;
25	int position;		/* 1 -> becomes second... */
26	int *code_ptr;
27{
28	register ss_data *info;
29	register int i, size;
30	ssrt **t;
31
32	info = ss_info(sci_idx);
33	for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
34		;
35	/* size == C subscript of NULL == #elements */
36	size += 2;		/* new element, and NULL */
37	t = (ssrt **)realloc(info->rqt_tables, (unsigned)size*sizeof(ssrt));
38	if (t == (ssrt **)NULL) {
39		*code_ptr = errno;
40		return;
41	}
42	info->rqt_tables = t;
43	if (position > size - 2)
44		position = size - 2;
45
46	if (size > 1)
47		for (i = size - 2; i >= position; i--)
48			info->rqt_tables[i+1] = info->rqt_tables[i];
49
50	info->rqt_tables[position] = rqtbl_ptr;
51	info->rqt_tables[size-1] = (ssrt *)NULL;
52	*code_ptr = 0;
53}
54
55void ss_delete_request_table(sci_idx, rqtbl_ptr, code_ptr)
56     int sci_idx;
57     ssrt *rqtbl_ptr;
58     int *code_ptr;
59{
60     register ss_data *info;
61     register ssrt **rt1, **rt2;
62
63     *code_ptr = SS_ET_TABLE_NOT_FOUND;
64     info = ss_info(sci_idx);
65     rt1 = info->rqt_tables;
66     for (rt2 = rt1; *rt1; rt1++) {
67	  if (*rt1 != rqtbl_ptr) {
68	       *rt2++ = *rt1;
69	       *code_ptr = 0;
70	  }
71     }
72     *rt2 = (ssrt *)NULL;
73     return;
74}
75