1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 /*
7 * Copyright 1987, 1988 by MIT Student Information Processing Board
8 *
9 * For copyright information, see copyright.h.
10 */
11
12 #include "copyright.h"
13 #include "ss_internal.h"
14
15 #define ssrt ss_request_table /* for some readable code... */
16
17 void
ss_add_request_table(sci_idx,rqtbl_ptr,position,code_ptr)18 ss_add_request_table(sci_idx, rqtbl_ptr, position, code_ptr)
19 int sci_idx;
20 ssrt *rqtbl_ptr;
21 int position; /* 1 -> becomes second... */
22 int *code_ptr;
23 {
24 register ss_data *info;
25 register int i, size;
26
27 info = ss_info(sci_idx);
28 for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
29 ;
30 /* size == C subscript of NULL == #elements */
31 size += 2; /* new element, and NULL */
32 info->rqt_tables = (ssrt **)realloc(info->rqt_tables,
33 size*sizeof(ssrt));
34 if (info->rqt_tables == (ssrt **)NULL) {
35 *code_ptr = errno;
36 return;
37 }
38 if (position > size - 2)
39 position = size - 2;
40
41 if (size > 1)
42 for (i = size - 2; i >= position; i--)
43 info->rqt_tables[i+1] = info->rqt_tables[i];
44
45 info->rqt_tables[position] = rqtbl_ptr;
46 info->rqt_tables[size-1] = (ssrt *)NULL;
47 *code_ptr = 0;
48 }
49
50 void
ss_delete_request_table(sci_idx,rqtbl_ptr,code_ptr)51 ss_delete_request_table(sci_idx, rqtbl_ptr, code_ptr)
52 int sci_idx;
53 ssrt *rqtbl_ptr;
54 int *code_ptr;
55 {
56 register ss_data *info;
57 register ssrt **rt1, **rt2;
58
59 *code_ptr = SS_ET_TABLE_NOT_FOUND;
60 info = ss_info(sci_idx);
61 rt1 = info->rqt_tables;
62 for (rt2 = rt1; *rt1; rt1++) {
63 if (*rt1 != rqtbl_ptr) {
64 *rt2++ = *rt1;
65 *code_ptr = 0;
66 }
67 }
68 *rt2 = (ssrt *)NULL;
69 return;
70 }
71