request_tbl.c revision e46c187aa6ee1ad6f38f0fb9c39da5e2bb6ceeb9
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#include "config.h"
15#ifdef HAVE_ERRNO_H
16#include <errno.h>
17#endif
18
19#include "ss_internal.h"
20
21#define ssrt ss_request_table	/* for some readable code... */
22
23void ss_add_request_table(sci_idx, rqtbl_ptr, position, code_ptr)
24	int sci_idx;
25	ssrt *rqtbl_ptr;
26	int position;		/* 1 -> becomes second... */
27	int *code_ptr;
28{
29	register ss_data *info;
30	register int i, size;
31	ssrt **t;
32
33	info = ss_info(sci_idx);
34	for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
35		;
36	/* size == C subscript of NULL == #elements */
37	size += 2;		/* new element, and NULL */
38	t = (ssrt **)realloc(info->rqt_tables, (unsigned)size*sizeof(ssrt *));
39	if (t == (ssrt **)NULL) {
40		*code_ptr = errno;
41		return;
42	}
43	info->rqt_tables = t;
44	if (position > size - 2)
45		position = size - 2;
46
47	if (size > 1)
48		for (i = size - 2; i >= position; i--)
49			info->rqt_tables[i+1] = info->rqt_tables[i];
50
51	info->rqt_tables[position] = rqtbl_ptr;
52	info->rqt_tables[size-1] = (ssrt *)NULL;
53	*code_ptr = 0;
54}
55
56void ss_delete_request_table(sci_idx, rqtbl_ptr, code_ptr)
57     int sci_idx;
58     ssrt *rqtbl_ptr;
59     int *code_ptr;
60{
61     register ss_data *info;
62     register ssrt **rt1, **rt2;
63
64     *code_ptr = SS_ET_TABLE_NOT_FOUND;
65     info = ss_info(sci_idx);
66     rt1 = info->rqt_tables;
67     for (rt2 = rt1; *rt1; rt1++) {
68	  if (*rt1 != rqtbl_ptr) {
69	       *rt2++ = *rt1;
70	       *code_ptr = 0;
71	  }
72     }
73     *rt2 = (ssrt *)NULL;
74     return;
75}
76