Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2010, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
/* #define debug 1 */
37
38
#include <stdlib.h>
39
#include "openaxiom-c-macros.h"
40
#include <unistd.h>
41
#include <string.h>
42
#include <stdio.h>
43
#include <sys/types.h>
44
45
#include "edible.h"
46
47
#define HFT 0
48
#define SUN 1
49
#define DEC 2
50
#define control_to_alpha(x) (x + ('A' - 0x01))
51
#define alpha_to_control(x) (x - ('A' - 0x01))
52
53
int termId;
54
QueStruct *ring = NULL;
55
QueStruct *current = NULL;
56
int ring_size = 0;
57
int MAXRING = 64;
58
int prev_check = 10;
59
int curr_pntr;
60
int num_pntr;
61
int num_proc;
62
int had_tab;
63
int had_tab_last;
64
extern char buff[1024]; /* Buffers for collecting input and */
65
extern int buff_flag[1024]; /* flags for whether buff chars
66
are printing or non-printing */
67
int buff_pntr; /* present length of buff */
68
69
70
#include "edin.h"
71
#include "prt.h"
72
#include "wct.h"
73
#include "cursor.h"
74
#include "fnct_key.h"
75
76
77
78
void
79
init_reader(void)
80
{
81
char *termVal;
82
83
buff[50] = '\0'; /** initialize some stuff ***/
84
init_flag(buff_flag, MAXLINE);
85
buff_pntr = curr_pntr = 0;
86
87
had_tab = 0;
88
had_tab_last = 0;
89
termVal = (char *) getenv("TERM");
90
if (!strcmp("sun", termVal))
91
termId = SUN;
92
else if (!strcmp("xterm", termVal) || !strncmp("vt", termVal, 2))
93
termId = DEC;
94
else if (!strcmp("hft", termVal) || !strncmp("aixterm", termVal, 7))
95
termId = HFT;
96
}
97
98
99
void
100
do_reading(void)
101
{
102
int ttt_read;
103
int done_completely;
104
105
done_completely = 0;
106
num_proc = 0;
107
while (num_proc < num_read) {
108
if(in_buff[num_proc]== _ERASE) {
109
back_over_current_char();
110
num_proc++;
111
}
112
else {
113
switch (in_buff[num_proc]) {
114
/* lets start checking for different types of chars */
115
case _EOLN:
116
case _CR:
117
/* If I have read a complete line, so send it to the child */
118
send_line_to_child();
119
if (!PTY)
120
myputchar('\n');
121
break;
122
123
/*
124
* Use 0x7f as delete
125
*/
126
case _DEL:
127
/* Had a delete key */
128
delete_current_char();
129
break;
130
131
case _CNTRL_W:
132
move_back_word();
133
num_proc++;
134
break;
135
case _TAB:
136
had_tab = 1;
137
/* command completion stuff */
138
num_proc++;
139
if (had_tab_last)
140
rescan_wct();
141
else
142
find_wct();
143
break;
144
case _BELL:
145
insert_buff_nonprinting(1);
146
putchar(_BELL);
147
fflush(stdout);
148
break;
149
case _ESC:
150
151
/*
152
* get 2 characters more
153
*/
154
while (!(num_read - num_proc > 2)) {
155
ttt_read = read(0,
156
in_buff + num_read,
157
2 - (num_read - num_proc) + 1);
158
if (ttt_read > 0)
159
num_read = num_read + ttt_read;
160
}
161
if (in_buff[num_proc + 1] == _LBRACK) {
162
163
/* ESC [ */
164
165
switch (in_buff[num_proc + 2]) {
166
/* look for arrows */
167
case _A:
168
/* up arrow */
169
170
/*
171
* The first thing I plan to do is get rid of the present
172
* input **
173
*/
174
prev_buff();
175
curr_pntr = buff_pntr;
176
num_proc = num_proc + 3;
177
break;
178
case _B:
179
/* down arrow */
180
next_buff();
181
curr_pntr = buff_pntr;
182
num_proc = num_proc + 3;
183
break;
184
case _C:
185
/* right arrow */
186
move_ahead();
187
num_proc = num_proc + 3;
188
break;
189
case _D:
190
/* left arrow */
191
move_back();
192
num_proc = num_proc + 3;
193
break;
194
195
/*
196
* Use ^[[P as delete
197
*/
198
case _P:
199
/*** Had a delete key ****/
200
delete_current_char();
201
break;
202
case _H:
203
case 0:
204
move_home();
205
num_proc += 3;
206
break;
207
case _M:
208
case _Z:
209
insert_buff_nonprinting(3);
210
done_completely = 1;
211
num_proc += 3;
212
break;
213
case _x:
214
num_proc = num_read;
215
break;
216
case _1:
217
case _2:
218
case _0:
219
220
/*
221
* I have had a possible function key hit, look for the
222
* ones I want. check for ESC ] x ~
223
*/
224
while (!(num_read - num_proc > 3)) {
225
ttt_read = read(0,
226
in_buff + num_read,
227
3 - (num_read - num_proc) + 1);
228
if (ttt_read > 0)
229
num_read = num_read + ttt_read;
230
}
231
if (in_buff[num_proc + 3] == _twiddle) {
232
233
/*
234
* treat ESC ] x ~
235
*/
236
switch (in_buff[num_proc + 2]) {
237
case _2:
238
flip(INS_MODE);
239
if (INS_MODE)
240
Cursor_shape(5);
241
else
242
Cursor_shape(2);
243
reprint(curr_pntr);
244
num_proc += 4;
245
break;
246
default:
247
insert_buff_nonprinting(1);
248
break;
249
}
250
break;
251
}
252
/* check for ESC ] x y ~ */
253
while (!(num_read - num_proc > 4)) {
254
ttt_read = read(0,
255
in_buff + num_read,
256
4 - (num_read - num_proc) + 1);
257
if (ttt_read > 0)
258
num_read = num_read + ttt_read;
259
}
260
if (in_buff[num_proc + 4] == _twiddle) {
261
262
/*
263
* treat ESC ] x y ~
264
*/
265
insert_buff_nonprinting(1);
266
break;
267
}
268
269
/* check for ESC ] x y z [q|z] */
270
271
while (!(num_read - num_proc > 5)) {
272
ttt_read = read(0,
273
in_buff + num_read,
274
5 - (num_read - num_proc) + 1);
275
if (ttt_read > 0)
276
num_read = num_read + ttt_read;
277
}
278
if (insert_toggle(&in_buff[num_proc + 3])) {
279
flip(INS_MODE);
280
if (INS_MODE)
281
Cursor_shape(5);
282
else
283
Cursor_shape(2);
284
reprint(curr_pntr);
285
num_proc = num_proc + 6;
286
break;
287
}
288
else if (cntrl_end(&in_buff[num_proc + 3])) {
289
num_proc = num_proc + 6;
290
delete_to_end_of_line();
291
break;
292
}
293
else if (back_word(&in_buff[num_proc + 3])) {
294
move_back_word();
295
num_proc += 6;
296
break;
297
}
298
else if (fore_word(&in_buff[num_proc + 3])) {
299
move_fore_word();
300
num_proc += 6;
301
break;
302
}
303
else if (end_key(&in_buff[num_proc + 3])) {
304
move_end();
305
num_proc += 6;
306
break;
307
}
308
switch (in_buff[num_proc + 5]) {
309
case _q:
310
311
/*
312
* IBM function keys
313
*/
314
{
315
char num[3];
316
int key;
317
318
num[0] = in_buff[num_proc + 3];
319
num[1] = in_buff[num_proc + 4];
320
num[2] = '\0';
321
key = atoi(num);
322
if (key > 0 && key < 13) {
323
if (function_key[key].str != NULL) {
324
handle_function_key(key, contNum);
325
done_completely = 1;
326
}
327
else {
328
insert_buff_nonprinting(6);
329
done_completely = 1;
330
}
331
}
332
else {
333
insert_buff_nonprinting(6);
334
done_completely = 1;
335
}
336
break;
337
}
338
case _z:
339
340
/*
341
* Sun function keys
342
*/
343
{
344
char num[3];
345
int key;
346
347
num[0] = in_buff[num_proc + 3];
348
num[1] = in_buff[num_proc + 4];
349
num[2] = '\0';
350
key = atoi(num) - 23;
351
if (key > 0 && key < 13) {
352
if (function_key[key].str != NULL) {
353
handle_function_key(key, contNum);
354
done_completely = 1;
355
}
356
else {
357
insert_buff_nonprinting(6);
358
done_completely = 1;
359
}
360
}
361
else if (atoi(num) == 14) {
362
move_home();
363
num_proc += 6;
364
done_completely = 1;
365
}
366
else if (atoi(num) == 20) {
367
move_end();
368
num_proc += 6;
369
done_completely = 1;
370
}
371
else if (atoi(num) == 47) {
372
flip(INS_MODE);
373
if (INS_MODE)
374
Cursor_shape(5);
375
else
376
Cursor_shape(2);
377
reprint(curr_pntr);
378
num_proc = num_proc + 6;
379
done_completely = 1;
380
}
381
else {
382
insert_buff_nonprinting(6);
383
done_completely = 1;
384
}
385
386
break;
387
}
388
389
default:
390
insert_buff_nonprinting(1);
391
break;
392
}
393
default:
394
if (!done_completely)
395
insert_buff_nonprinting(1);
396
break;
397
}
398
} /* if */
399
else { /* ESC w/o [ */
400
insert_buff_nonprinting(1);
401
}
402
break;
403
404
case _BKSPC:
405
back_over_current_char();
406
num_proc++;
407
break;
408
default:
409
if (in_buff[num_proc] == _KILL) {
410
delete_line();
411
num_proc++;
412
}
413
else {
414
if ((in_buff[num_proc] == _INTR) || (in_buff[num_proc] == _QUIT)) {
415
write(contNum, &in_buff[num_proc], num_read - num_proc);
416
if (!PTY)
417
write(contNum, "\n", 1);
418
num_proc++;
419
}
420
else {
421
if (in_buff[num_proc] == _EOF) {
422
insert_buff_nonprinting(1);
423
if (!PTY)
424
write(contNum, "\n", 1);
425
426
/*comment out this bit
427
if (!buff_pntr) {
428
write(contNum, &in_buff[num_proc], 1);
429
if (!PTY)
430
write(contNum, "\n", 1);
431
}
432
else {
433
write(contNum, buff, buff_pntr);
434
}
435
*/
436
num_proc++;
437
}
438
else {
439
if (in_buff[num_proc] == _EOL) {
440
send_line_to_child();
441
if (!PTY)
442
write(contNum, "\n", 1);
443
}
444
else {
445
if (in_buff[num_proc] == _ERASE) {
446
back_over_current_char();
447
num_proc++;
448
}
449
else {
450
if (control_char(in_buff[num_proc]))
451
insert_buff_nonprinting(1);
452
else
453
insert_buff_printing(1);
454
}
455
}
456
}
457
}
458
} /* close the default case */
459
break;
460
} /* switch */
461
} /*else*/
462
if (had_tab) {
463
had_tab_last = 1;
464
had_tab = 0;
465
}
466
else
467
had_tab_last = 0;
468
469
} /* while */
470
}
471
472
473
474
void
475
send_line_to_child(void)
476
{
477
static char converted_buffer[MAXLINE];
478
int converted_num;
479
480
/* Takes care of sending a line to the child, and resetting the
481
buffer for new input */
482
483
back_it_up(curr_pntr);
484
485
/* start by putting the line into the command line ring ***/
486
if (buff_pntr)
487
insert_queue();
488
489
/* finish the line and send it to the child **/
490
buff[buff_pntr] = in_buff[num_proc];
491
buff_flag[buff_pntr++] = 1;
492
buff[buff_pntr] = '\0';
493
buff_flag[buff_pntr] = -1;
494
495
/*
496
* Instead of actually writing the Line, I have to substitute in the
497
* actual characters recieved
498
*/
499
converted_num =
500
convert_buffer(converted_buffer, buff, buff_flag, buff_pntr);
501
write(contNum, converted_buffer, converted_num);
502
503
/** reinitialize the buffer ***/
504
init_flag(buff_flag, buff_pntr);
505
init_buff(buff, buff_pntr);
506
/** reinitialize my buffer pointers **/
507
buff_pntr = curr_pntr = 0;
508
509
/** reset the ring pointer **/
510
current = NULL;
511
num_proc++;
512
return;
513
}
514
515
int
516
convert_buffer(char *target, char *source,int * source_flag, int num)
517
{
518
int i, j;
519
520
/*
521
* Until I get something wierd, just keep copying
522
*/
523
for (i = 0, j = 0; i < num; i++, j++) {
524
switch (source[i]) {
525
case _CARROT:
526
if (source_flag[i] == 1) {
527
target[j] = source[i];
528
}
529
else {
530
if (source[i + 1] == _LBRACK) {
531
target[j] = _ESC;
532
i++;
533
}
534
else if (source[i + 1] >= 'A' && source[i + 1] <= 'Z') {
535
target[j] = alpha_to_control(source[i + 1]);
536
i++;
537
}
538
}
539
break;
540
case '?':
541
default:
542
target[j] = source[i];
543
}
544
}
545
return j;
546
}
547
548
549
void
550
insert_buff_printing(int amount)
551
{
552
int count;
553
554
/* This procedure takes the character at in_buff[num_proc] and adds
555
it to the buffer. It first checks to see if we should be inserting
556
or overwriting, and then does the appropriate thing */
557
558
if ((buff_pntr + amount) > 1023) {
559
putchar(_BELL);
560
fflush(stdout);
561
num_proc += amount;
562
}
563
else {
564
565
if (INS_MODE) {
566
567
forwardcopy(&buff[curr_pntr + amount],
568
&buff[curr_pntr],
569
buff_pntr - curr_pntr);
570
forwardflag_cpy(&buff_flag[curr_pntr + amount],
571
&buff_flag[curr_pntr],
572
buff_pntr - curr_pntr);
573
for (count = 0; count < amount; count++) {
574
buff[curr_pntr + count] = in_buff[num_proc + count];
575
buff_flag[curr_pntr + count] = 1;
576
}
577
ins_print(curr_pntr, amount);
578
buff_pntr = buff_pntr + amount;
579
}
580
else {
581
for (count = 0; count < amount; count++) {
582
if (buff_flag[curr_pntr + count] == 2) {
583
myputchar(buff[curr_pntr + count]);
584
curr_pntr += count + 1;
585
delete_current_char();
586
/** fix num_proc affected by delete **/
587
num_proc -= 3;
588
curr_pntr -= count + 1;
589
myputchar(_BKSPC);
590
}
591
buff[curr_pntr + count] = in_buff[num_proc + count];
592
buff_flag[curr_pntr + count] = 1;
593
}
594
myputchar(in_buff[num_proc]);
595
if (curr_pntr == buff_pntr)
596
buff_pntr++;
597
}
598
num_proc = num_proc + amount;
599
curr_pntr = curr_pntr + amount;
600
fflush(stdout);
601
}
602
return;
603
604
}
605
606
void
607
insert_buff_nonprinting(int amount)
608
{
609
int count;
610
611
/* This procedure takes the character at in_buff[num_proc] and adds
612
it to the buffer. It first checks to see if we should be inserting
613
or overwriting, and then does the appropriate thing */
614
615
/* it takes care of the special case, when I have an esc character */
616
617
if ((buff_pntr + amount) > 1023) {
618
myputchar(_BELL);
619
fflush(stdout);
620
num_proc += amount;
621
}
622
else {
623
if (INS_MODE) {
624
forwardcopy(&buff[curr_pntr + amount + 1],
625
&buff[curr_pntr],
626
buff_pntr - curr_pntr);
627
forwardflag_cpy(&buff_flag[curr_pntr + amount + 1],
628
&buff_flag[curr_pntr],
629
buff_pntr - curr_pntr);
630
/** now insert the special character **/
631
switch (in_buff[num_proc]) {
632
case _ESC:
633
/** in this case I insert a '^[' into the string ***/
634
buff[curr_pntr] = _CARROT;
635
buff_flag[curr_pntr] = 2;
636
buff[curr_pntr + 1] = _LBRACK;
637
buff_flag[curr_pntr + 1] = 0;
638
break;
639
default:
640
if (control_char(in_buff[num_proc])) {
641
buff[curr_pntr] = _CARROT;
642
buff_flag[curr_pntr] = 2;
643
buff[curr_pntr + 1] = control_to_alpha(in_buff[num_proc]);
644
buff_flag[curr_pntr + 1] = 0;
645
}
646
else {
647
/** What do I have ? **/
648
buff[curr_pntr] = '?';
649
buff_flag[curr_pntr] = 2;
650
buff[curr_pntr + 1] = in_buff[num_proc];
651
buff_flag[curr_pntr] = 0;
652
break;
653
}
654
}
655
/** Now add the normal characters **/
656
for (count = 1; count < amount; count++) {
657
buff[curr_pntr + count + 1] = in_buff[num_proc + count];
658
buff_flag[curr_pntr + count + 1] = 1;
659
}
660
ins_print(curr_pntr, amount + 1);
661
buff_pntr = buff_pntr + amount + 1;
662
}
663
else {
664
/** I am in the overstrike mode **/
665
switch (in_buff[num_proc]) {
666
case _ESC:
667
/** in this case I insert a '^[' into the string ***/
668
buff[curr_pntr] = _CARROT;
669
buff_flag[curr_pntr] = 2;
670
buff[curr_pntr + 1] = _LBRACK;
671
buff_flag[curr_pntr + 1] = 0;
672
break;
673
default:
674
if (control_char(in_buff[num_proc])) {
675
buff[curr_pntr] = _CARROT;
676
buff_flag[curr_pntr] = 2;
677
buff[curr_pntr + 1] = control_to_alpha(in_buff[num_proc]);
678
buff_flag[curr_pntr + 1] = 0;
679
}
680
else {
681
/** What do I have ? **/
682
buff[curr_pntr] = '?';
683
buff_flag[curr_pntr] = 2;
684
buff[curr_pntr + 1] = in_buff[num_proc];
685
buff_flag[curr_pntr] = 0;
686
break;
687
}
688
}
689
for (count = 1; count < amount; count++) {
690
if (buff_flag[curr_pntr + count] == 2) {
691
curr_pntr += count + 1;
692
delete_current_char();
693
/** fix num. processed form delete **/
694
num_proc -= 3;
695
curr_pntr -= count + 1;
696
}
697
buff[curr_pntr + count + 1] = in_buff[num_proc + count];
698
buff_flag[curr_pntr + count + 1] = 1;
699
}
700
/** now print the characters I have put in **/
701
printbuff(curr_pntr, amount + 1);
702
}
703
num_proc = num_proc + amount;
704
curr_pntr = curr_pntr + amount + 1;
705
if (curr_pntr > buff_pntr)
706
buff_pntr = curr_pntr;
707
}
708
return;
709
710
}
711
712
void
713
prev_buff(void)
714
{
715
716
/*
717
* If the current command ring is NULL, then I should NOT clear the
718
* current line. Thus my business is already done
719
*/
720
if (ring == NULL)
721
return;
722
clear_buff();
723
init_buff(buff, buff_pntr);
724
init_flag(buff_flag, buff_pntr);
725
726
if (current == NULL) {
727
if (ring == NULL)
728
return;
729
current = ring;
730
}
731
else
732
current = current->prev;
733
strcpy(buff, current->buff);
734
flagcpy(buff_flag, current->flags);
735
736
/* first back up and blank the line */
737
fflush(stdout);
738
printbuff(0, strlen(buff));
739
curr_pntr = buff_pntr = strlen(buff);
740
fflush(stdout);
741
return ;
742
}
743
744
void
745
next_buff(void)
746
{
747
748
/*
749
* If the current command ring is NULL, then I should NOT clear the
750
* current line. Thus my business is already done
751
*/
752
if (ring == NULL)
753
return;
754
clear_buff();
755
init_buff(buff, buff_pntr);
756
init_flag(buff_flag, buff_pntr);
757
if (current == NULL) {
758
if (ring == NULL)
759
return;
760
current = ring->next;
761
}
762
else
763
current = current->next;
764
strcpy(buff, current->buff);
765
flagcpy(buff_flag, current->flags);
766
767
/* first back up and blank the line **/
768
fflush(stdout);
769
printbuff(0, strlen(buff));
770
curr_pntr = buff_pntr = strlen(buff);
771
fflush(stdout);
772
return ;
773
}
774
775
776
void
777
forwardcopy(char *buff1,char * buff2,int num)
778
{
779
int count;
780
781
for (count = num; count >= 0; count--)
782
buff1[count] = buff2[count];
783
}
784
785
786
void
787
forwardflag_cpy(int *buff1,int * buff2,int num)
788
{
789
int count;
790
791
for (count = num; count >= 0; count--)
792
buff1[count] = buff2[count];
793
}
794
795
void
796
flagcpy(int *s,int *t)
797
{
798
while (*t >= 0)
799
*s++ = *t++;
800
*s = *t;
801
}
802
803
void
804
flagncpy(int *s,int *t,int n)
805
{
806
while (n-- > 0)
807
*s++ = *t++;
808
}
809
810
void
811
insert_queue(void)
812
{
813
QueStruct *trace;
814
QueStruct *new_q;
815
int c;
816
817
if (!ECHOIT)
818
return;
819
if (ring != NULL && !strcmp(buff, ring->buff))
820
return;
821
for (c = 0, trace = ring; trace != NULL && c < (prev_check - 1);
822
c++, trace = trace->prev) {
823
if (!strcmp(buff, trace->buff)) {
824
825
/*
826
* throw this puppy at the end of the ring
827
*/
828
trace->next->prev = trace->prev;
829
trace->prev->next = trace->next;
830
trace->prev = ring;
831
trace->next = ring->next;
832
ring->next = trace;
833
trace->next->prev = trace;
834
ring = trace;
835
return;
836
}
837
}
838
839
/*
840
* simply places the buff command into the front of the queue
841
*/
842
if (ring_size < MAXRING) {
843
new_q = (QueStruct *) malloc(sizeof(struct que_struct));
844
if (new_q == NULL) {
845
fprintf(stderr, "Malloc Error: Ran out of memory\n");
846
exit(-1);
847
}
848
if (ring_size == 0) {
849
ring = new_q;
850
ring->prev = ring->next = new_q;
851
}
852
else {
853
new_q->next = ring->next;
854
new_q->prev = ring;
855
ring->next = new_q;
856
new_q->next->prev = new_q;
857
ring = new_q;
858
}
859
ring_size++;
860
}
861
else
862
ring = ring->next;
863
864
init_flag(ring->flags, MAXLINE);
865
init_buff(ring->buff, MAXLINE);
866
strcpy(ring->buff, buff);
867
flagncpy(ring->flags, buff_flag, buff_pntr);
868
(ring->buff)[buff_pntr] = '\0';
869
(ring->flags)[buff_pntr] = -1;
870
}
871
872
873
void
874
init_flag(int *flags, int num)
875
{
876
int i;
877
878
for (i = 0; i < num; i++)
879
flags[i] = -1;
880
}
881
882
void
883
init_buff(char *flags, int num)
884
{
885
int i;
886
887
for (i = 0; i < num; i++)
888
flags[i] = '\0';
889
}
890
891
892
void
893
send_function_to_child(void)
894
{
895
/* Takes care of sending a line to the child, and resetting the
896
buffer for new input */
897
898
back_it_up(curr_pntr);
899
/** start by putting the line into the command line ring ***/
900
if (buff_pntr)
901
insert_queue();
902
903
/** finish the line and send it to the child **/
904
buff[buff_pntr] = _EOLN;
905
906
buff_flag[buff_pntr++] = 1;
907
buff[buff_pntr] = '\0';
908
buff_flag[buff_pntr] = 0;
909
write(contNum, buff, buff_pntr);
910
911
/** reinitialize the buffer ***/
912
init_flag(buff_flag, buff_pntr);
913
init_buff(buff, buff_pntr);
914
/** reinitialize my buffer pointers **/
915
buff_pntr = curr_pntr = 0;
916
917
/** reset the ring pointer **/
918
current = NULL;
919
920
num_proc++;
921
return;
922
}
923
924
void
925
send_buff_to_child(int chann)
926
{
927
if (buff_pntr > 0)
928
write(chann, buff, buff_pntr);
929
num_proc += 6;
930
/** reinitialize the buffer ***/
931
init_flag(buff_flag, buff_pntr);
932
init_buff(buff, buff_pntr);
933
/** reinitialize my buffer pointers **/
934
buff_pntr = curr_pntr = 0;
935
/** reset the ring pointer **/
936
current = NULL;
937
return;
938
}
939
940
941