1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 #include <dos.h>
56 #include <ws.h>
57 #include <cat.h>
58 #include <ws_dcls.h>
59 #include <ws_error.h>
60 #include <ws_func.h>
61
62 #define NULL 0
63
64 cretinst (capability_name, entry_name, inbuff_length, outbuff_length, data_block_ptr, mcb_ptr)
65
66 char *capability_name;
67 int (*entry_name)();
68 int inbuff_length;
69 int outbuff_length;
70 char *data_block_ptr;
71 mcb **mcb_ptr;
72 {
73 int i;
74 int inbuff_size;
75 int outbuff_size;
76 int cap_num;
77 int code;
78 mcb *lmcb_ptr;
79 struct SREGS segregs;
80 struct allocstr *allocp;
81 struct cretinst_param_struct cips;
82
83 int pe_entry();
84
85 code = 0;
86
87
88
89 lmcb_ptr = (mcb *) malloc (sizeof (mcb));
90 if (lmcb_ptr == NULL)
91 return (WSCNTCRE);
92
93
94
95 cips.mcb_ptr = lmcb_ptr;
96 stccpy (lmcb_ptr -> capability_name, capability_name, CAPABILITY_NAME_LENGTH);
97 i = stccpy (cips.capability_name, capability_name, CAPABILITY_NAME_LENGTH);
98 for (i = i; i < CAPABILITY_NAME_LENGTH; i++)
99 { lmcb_ptr -> capability_name[i] = 0;
100 cips.capability_name[i] = 0;
101 }
102
103
104
105
106
107 lmcb_ptr -> data_block_ptr = data_block_ptr;
108 lmcb_ptr -> mcb_flag = 0;
109
110 if (!((int)(entry_name)))
111 { lmcb_ptr -> application_entry = NULL;
112 lmcb_ptr -> mcb_flag |= MCB_NULL_ROUTINE;
113 }
114 else
115 lmcb_ptr -> application_entry = entry_name;
116
117
118
119
120
121 if (inbuff_length < WSPAKSIZ)
122 inbuff_size = WSPAKSIZ;
123 else
124 inbuff_size = inbuff_length;
125
126 inbuff_size += (sizeof (struct allocstr))*2;
127 inbuff_size += (sizeof (struct linklst))*2;
128 inbuff_size += WSPAKSIZ;
129
130
131
132
133 lmcb_ptr -> inbuff_length = inbuff_length;
134 allocp = (struct allocstr *) malloc (inbuff_size);
135 if (allocp != NULL)
136 { lmcb_ptr -> inalloc = allocp;
137 allocp -> memory_used = 0;
138 allocp -> memory = (char *) ((int)allocp + sizeof (struct allocstr));
139 allocp -> m_allocp = NULL;
140 allocp -> memory_size = inbuff_size - sizeof (struct allocstr);
141 lmcb_ptr -> inbuff = NULL;
142 }
143 else
144 { free (lmcb_ptr);
145 *mcb_ptr = NULL;
146 return (WSINVBUF);
147 }
148
149
150
151
152
153 outbuff_size = 1 + outbuff_length / WSPAKSIZ;
154 outbuff_size = outbuff_size * (WSPAKSIZ + sizeof(struct linklst));
155 outbuff_size += sizeof (struct allocstr);
156
157
158
159
160 lmcb_ptr -> outbuff_length = outbuff_length;
161 allocp = (struct allocstr *) malloc (outbuff_size);
162 if (allocp != NULL) {
163 lmcb_ptr -> outalloc = allocp;
164 allocp -> memory_used = 0;
165 allocp -> memory = (char *) ((int)allocp + sizeof (struct allocstr));
166 allocp -> m_allocp = NULL;
167 allocp -> memory_size = outbuff_size - sizeof (struct allocstr);
168 lmcb_ptr -> outbuff = NULL;
169 }
170 else {
171 free (lmcb_ptr -> inalloc);
172 free (lmcb_ptr);
173 *mcb_ptr = NULL;
174 return (WSINVBUF);
175 }
176
177
178
179
180
181 segread(&segregs);
182 cips.cs_reg = segregs.cs;
183 cips.entry_pt = NULL;
184 if (!(lmcb_ptr -> mcb_flag & MCB_NULL_ROUTINE))
185 cips.entry_pt = pe_entry;
186
187
188
189
190 if (code = call_mowse_int (I$CRETINST, &cips, sizeof(cips)))
191 { if (lmcb_ptr -> inalloc != NULL)
192 free (lmcb_ptr -> inalloc);
193 if (lmcb_ptr -> outalloc != NULL)
194 free (lmcb_ptr -> outalloc);
195 free (lmcb_ptr);
196 *mcb_ptr = NULL;
197 }
198 else
199 { lmcb_ptr -> major_capability = cips.major_capability;
200 lmcb_ptr -> system_id = cips.system_id;
201 *mcb_ptr = lmcb_ptr;
202 }
203 return (code);
204 }