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