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
|
. \" Copyright 1984,1985,1986,1987,1988,1989,1990 AT&T Bell Laboratories
.TH CIN 1
.CT 1 prog_c
.SH NAME
cin \- C interpreter
.SH SYNOPSIS
.B cin
[
.I option ...
]
[
.I file ...
]
[
.B --
.I arg ...
]
.SH DESCRIPTION
.I Cin
interprets a C program comprising the
.I file
arguments as in
.IR cc (1).
The special name
.L -
signifies standard input.
When called with no
.I file
arguments,
.I cin
defaults to
.BR -i .
Arguments
.I arg
are passed to the interpreted program as
.BR cin_argv[1] ,
.BR cin_argv[2] ,
\&...
and
.BR cin_argc .
.PP
Options
.BI -D name = def ,
.BI -D name ,
.BI -L name ,
.BI -U name ,
.BI -I name ,
.BI -l x ,
.BI -o name ,
and
.BI -u name
are as in
.IR cc .
Options
.B -O
and
.B -g
are ignored.
Other options are:
.TP
.BI -0 name
Pass
.I name
to the interpreted program as
.BR cin_argv[0] .
.TP
.BI -C name
Use
.I name
as the interpreter startup file
(by default, the file
.FR $HOME/.cin.c ).
The interpreter startup file is ignored by using
.BR -C/dev/null .
.TP
.BI -F i : o : e
Use file descriptors
.IR i , o , e
as standard input, standard output, and standard error for the
interpreter, as distinct from the interpreted code
(by default, 0, 1, and 2).
.TP
.B -S
Enable interactive mode after run-time errors.
.TP
.BI -V name : n
Declare function
.I name
to have a variable number of arguments, the first
.I n
of which are to be type-checked.
.TP
.B -c
Parse files but do not execute the program.
.TP
.B -i
Enable interactive interpretation.
C statements are evaluated immediately using local and global variables.
Non-void values are printed.
Function, variable, and C pre-processor declarations are stored
in the current `view'.
A function definition must include its return type.
Declarations and statements can appear in any order and
identifiers can be redeclared.
.TP
.B -r
Prohibit multiply-declared global variables.
.TP
.B -s
Do not catch signals using
.IR signal (2)
(by default,
.I cin
catches
.BR SIGBUS ,
.BR SIGEMT ,
.BR SIGFPE ,
.BR SIGILL ,
.BR SIGINT ,
.BR SIGIOT ,
.BR SIGSEGV ,
.BR SIGSYS ,
.BR SIGTRAP ).
.TP
.B -v
Print the user and system times associated with loading files and executing
the program, as in
.IR time (1).
.TP
.BI + option
Turn off the specified
.IR option .
.PP
The functions and variables listed below are predefined in
.I cin
and
.IR libcin.a .
Their arguments are typed according to these conventions:
.IP
.B char
.BI * func ,
.BI * message ,
.BI * mod ,
.BI * name ,
.BI * ref ,
.BI * string ;
.br
.B enode
.BI * code ;
.br
.B int
.IB level ,
.IB line ;
.br
.B long
.BI (* after )();
.br
.B unsigned
.B long
.IB addr ;
.br
.B void
.BI (* before )(),
.BI (* routine )();
.PP
This first group of functions and variables are the most commonly used.
To use them load
.F libcin.a
and include
.FR cin.h .
.PP
.HP
.BI "int cin_break(" name ,
.IB line ,
.IB string )
.br
If
.I string
is
.BR "(char *)0" ,
place a
.B cin_system
in file
.I name
before line number
.IR line .
Otherwise,
place the C-language statement specified by
.I string
in file
.I name
before line number
.IR line .
Thus,
.IR string
is read and evaluated
within the prevailing context of the function
without stopping execution.
Return 0 if line number
.I line
cannot be found in file
.IR name .
.TP
.BI "int cin_dump(" name )
Create an
.F a.out
and place it in the file
.IR name .
Return 0 if
.I name
cannot be created.
.TP
.BI "void cin_info(" string )
Where
.I string
is:
.RS
.TP
.B breakpoint
Print
.IR cin 's
.BR cin_break s
and
.BR cin_stopin s.
.TP
.B log
Print
.IR cin 's
interactive mode log file name.
.TP
.B memory
Print
.IR cin 's
memory usage.
.TP
.B spy
Print
.IR cin 's
spies.
.TP
.B symboltable
Print
.IR cin 's
symbol table.
.TP
.B undefined
Print
.IR cin 's
undefined variables.
.TP
.B usage
Print
.IR cin 's
usage message.
.TP
.B version
Print
.IR cin 's
version number.
.TP
.B view
List the available views.
The current view is starred
.RB ( * ).
.TP
.B where
Print a trace of function calls.
.TP
.B wrapper
Print
.IR cin 's
wrappers.
.RE
.TP
.BI "int cin_load(" string )
Evaluate
.I string
as invocation arguments of
.IR cin .
Return 0 if arguments are not valid.
.TP
.BI "int cin_log(" name )
.IR mv (1)
the interactive mode session log to file
.IR name .
Return 0 if
.I name
cannot be
.IR mv ed.
.TP
.BI "void cin_make(" string )
If
.I string
is
.BR "(char *)0" ,
then re-load any file that is out of date.
Otherwise,
run
.BR $MAKE ,
passing
.I string
as arguments, and scan
its standard output for lines that begin with pound sign
.RB ( # ).
Characters following the pound sign are executed as
a C-language statement.
.HP
.BI "int cin_pp(" func ,
.IB level )
.br
Print the C-language for the function
.IR func .
Where
.I level
is:
.RS
.TP
.B 0
Print declaration.
.TP
.B 1
Print declaration and body.
.PP
Return 0 if
.I func
cannot be found.
.RE
.TP
.B "void cin_quit()"
Flush output and exit
.IR cin .
If all else fails,
use
.IR _exit(2) .
.TP
.B "int cin_reset()"
Preserve function definitions,
zero bss variables,
and restore initialized data variables to their original values.
Return 0 if
state cannot be reset.
.TP
.B "void cin_return()"
Return from a call to
.BR cin_system .
.TP
.BI "void cin_run(" string )
Set
.BR cin_argv[1] ,
.BR cin_argv[2] ,
\&...
and
.B cin_argc
from
.I string
and then
.BR "main(cin_argc, cin_argv)" .
.HP
.BI "int cin_spy(" func ,
.IB name ,
.IB mod ,
.IB ref )
.br
Trace variable references and modifications.
If
.I mod
is not
.BR "(char *)0" ,
place the C-language statement specified by
.I mod
after the variable
.I name
is modified in the function
.IR func .
If
.I ref
is not
.BR "(char *)0" ,
place the C-language statement specified by
.I ref
before the variable
.I name
is referenced in the function
.IR func .
If function value
.I func
is
.BR "(char *)0" ,
search all functions.
Return 0 if
.I name
cannot be found in
.IR func .
.TP
.B "void cin_step()"
Step over function calls
to the next C-language statement in the current or previous function.
.TP
.B "void cin_stepin()"
Step into any function to the next C-language statement.
.TP
.B "void cin_stepout()"
Step out of the current function back to the next C-language statement
in the previous function.
.HP
.BI "int cin_stopin(" func ,
.IB string )
.br
If
.I string
is
.BR "(char *)0" ,
place a
.B cin_system
before the first
executable line in the function
.IR func ,
either in the current view or wherever
.I func
can be found.
Otherwise,
place the C-language statement specified by
.I string
before the first
executable line in the function
.IR func ,
either in the current view or wherever it can be found.
Thus,
.IR string
is read and evaluated
within the prevailing context of the function
without stopping execution.
Return 0 if function
.I func
cannot be found.
.TP
.BI "char *cin_sync(" string )
Where
.I string
is:
.RS
.TP
.B filename
Return the non-interactive C source file name being executed.
.TP
.B lineno
Return the non-interactive C source line number being executed.
.RE
.TP
.B "void cin_system()"
Start a
.BR cin_read - cin_eval - cin_print
loop.
.HP
.BI "int cin_unbreak(" name ,
.IB line ,
.IB string )
.br
Clear a
.B cin_break
or a
.B cin_stopin
in file
.I name
before line number
.I line
with string
.IR string .
Return 0 if
.B cin_break
or
.B cin_stopin
cannot be cleared.
.TP
.BI "int cin_unload(" name )
Unload the object file
.IR name .
Return 0 if
.I name
cannot be unloaded.
.HP
.BI "int cin_unspy(" func ,
.IB name ,
.IB mod ,
.IB ref )
.br
Remove the C-language statement specified by
.I mod
after the variable
.I name
is modified,
and the C-language statement specified by
.I ref
before the variable
.I name
is referenced in the function
.IR func .
Return 0 if spy cannot be cleared.
.HP
.BI "int cin_unstopin(" func ,
.IB string )
.br
Clear a
.B cin_stopin
or
.B cin_break
at the first
executable line in the function
.I func
with string
.I string
in either the current view or wherever
.I func
can be found.
Return 0 if the
.B cin_stopin
or
.B cin_break
cannot be cleared.
.HP
.BI "int cin_unwrapper(" func ,
.IB before ,
.IB after )
.br
Remove the call of function
.I before
before the function
.I func
is called.
Remove the call of function
.I after
after the function
.I func
is called.
Return 0 if
.I func
cannot be found.
.TP
.BI "int cin_view(" name )
Change the current view to
.IR name .
Return 0 if the view cannot be found.
.HP
.BI "int cin_wrapper(" func ,
.IB before ,
.IB after )
.br
If
.I before
is not
.BR "(void (*)())0" ,
call the function
.I before
with the arguments of function
.I func
before the function
.I func
is called.
If
.I after
is not
.BR "(long (*)())0" ,
call the function
.I after
with the argument of the return value of function
.I func
after the function
.I func
is called.
The return value of function
.I after
is substituted for the return value of function
.IR func .
Return 0 if
.I name
cannot be found either in the current view or any other view.
.TP
.B "extern int cin_argc"
The number of elements passed to the interpreted program.
.TP
.B "extern char **cin_argv"
An array of the arguments passed to the interpreted program.
.TP
.B "extern char *cin_filename"
The current C source file name being executed.
.TP
.B "extern int cin_level"
The number of nested calls to
.BR cin_system .
.TP
.B "extern char *cin_libpath"
A colon
.RB ( : )
-separated list of libraries to search for undefined routines
(by default,
the libraries specified on the command line and
.FR -lc ).
.TP
.B "extern int cin_lineno"
The current C source line number being executed.
.TP
.B "extern char *cin_prompt"
The interactive mode prompt (by default,
the string
.RB `` cin> " '')."
.PP
These are some of the less frequently used functions and variables in
.IR cin .
They are primarily used by
.I cin
library or language developers.
.TP
.BI "enode *cin_compile(" code )
Analyze
.I code
and return an optimized program.
Return
.B "(enode *)0"
if
.I code
cannot be compiled.
.TP
.BI "int cin_epp(" func )
Print the
.BR enode s
for function
.IR func .
Return 0 if
.I func
cannot be found.
.TP
.BI "enode *cin_eprint(" code )
Print the
.I code
as
.BR enode s.
Return the argument.
.HP
.BI "char *cin_error_code_set(" message ,
.IB string )
.br
Where
.I message
is:
.RS
.TP
.B dynamic error
When
.I cin
detects
a divide by zero,
a modulus by zero,
a null pointer access,
or
an abnormal signal
execute the C-language statement specified by
.IR string .
.TP
.B undefined function
When
.I cin
detects an undefined function execute the C-language statement specified by
.IR string .
.TP
.B undefined symbol
When
.I cin
detects
an undefined symbol execute the C-language statement specified by
.IR string .
.PP
If
.I string
is
.BR "(char *)0" ,
execute
.BR cin_system() .
Return the old
.I string
for
.IR message .
.RE
.TP
.BI "enode *cin_eval(" code )
Execute the
.I code
as if it were present in the program where
.B cin_eval
is called.
Return the resulting program.
.TP
.BI "ident *cin_find_ident(" name )
If
.I name
is not
.BR "(char *)0" ,
return the identifier for the variable
.I name
either in the current view or wherever
.I name
can be found.
If
.I name
is
.BR "(char *)0" ,
return the identifier for the previous non-
.B "(char *)0"
value of the variable
.I name
in the next view where
.I name
can be found.
Return
.B "(ident *)0"
if
.I name
cannot be found.
.TP
.BI "struct nlist *cin_find_nlist(" addr )
Return the loader symbol table entry for the external address
.IR addr .
Return
.B "(struct nlist *)0"
if
.I addr
cannot be found.
.HP
.BI "void (*cin_info_set())(" string ,
.IB routine )
.br
Inform
.B cin_info
that it should call
.I routine
when it is passed
.IR string .
Return the old
.I routine
for
.IR string .
.TP
.BI "char *cin_ltof(" line )
Return the function name at line number
.I line
in the current view.
Return
.B "(char *)0"
if a function cannot be found for
.IR line .
.TP
.BI "void cin_pop(" level )
Replace
.I level
interpreted function calls from the stack with
.BR cin_system .
.HP
.BI "enode *cin_print(" code ,
.IB level )
.br
Print the
.I code
as C-language code.
Where
.I level
is:
.RS
.TP
.B 0
Print declaration.
.TP
.B 1
Print declaration and body.
.PP
Return the
.I code
argument.
.RE
.TP
.BI "enode *cin_read(" string )
Read
.I string
and return a program.
Return
.B "(enode *)0"
if
.I string
cannot be parsed.
.TP
.BI "char *cin_slashify(" string )
Return a pointer to storage obtained from
.IR malloc (3)
and there create a character array from
.I string
by translating
backspace,
form feed,
newline,
carriage return,
horizontal tab,
vertical tab,
backslash,
single quote,
and double quote
into
.BR \eb ,
.BR \ef ,
.BR \en ,
.BR \er ,
.BR \et ,
.BR \ev ,
.BR \e\e ,
.BR \e' ,
and
.B \e"
respectively.
Other non-printable characters are translated into
.BI \e ddd
octal notation.
.TP
.B "extern int cin_err_fd"
.IR Cin 's
standard error file descriptor.
.TP
.B "extern int cin_in_fd"
.IR Cin 's
standard input file descriptor.
.TP
.B "extern int cin_out_fd"
.IR Cin 's
standard output file descriptor.
.TP
.B "extern stackelem *cin_stack"
The trace of function calls.
.TP
.B "extern view *cin_views"
The list of available views.
.SH EXAMPLES
.TP
The world's shortest ``Hello world'' program.
.EX
cin> printf("Hello world\en");
Hello world
(int)12
.EE
.TP
Setting breakpoints and tracing function calls.
.EX
$ cin -lcin
cin> int f(x) { return x <= 1 ? 1 : x * f(x - 1); }
extern int f();
cin> cin_stopin("f", (char*)0);
/tmp/cin006795: 1: f: set breakpoint: (char *)0
(int)1
cin> f(2);
/tmp/int006795: 1: f: stopped execution:
cin> cin_return();
/tmp/int006795: 1: f: stopped execution:
cin> (void)cin_info("where");
/tmp/cin006795: 5: cin_system: info: where: ()
/tmp/cin006795: 1: f: info: where: (x = (int)1)
/tmp/cin006795: 1: f: info: where: (x = (int)2)
/tmp/cin006795: 3: cin_system: info: where: ()
cin> x;
(int)1
cin> cin_return();
(int)2
cin> cin_quit();
$
.EE
.SH FILES
.TF /usr/include/cin.h
.TP
.F /tmp/cin*
default interactive log
.TP
.F /usr/include/cin.h
various function and variable declarations
.TP
.F /usr/lib/libcin.a
various predefined functions
.TP
.F $HOME/.cin.c
interpreter startup file
.HP
other files as in
.IR cc (1)
.SH "SEE ALSO"
.I "Cin User Manual"
.br
.I "Cin Reference Manual"
.br
B. W. Kernighan and D. M. Ritchie,
.IR "The C Programming Language" ,
Prentice-Hall,
1978
.br
.IR lint (1),
.IR ar (1),
.IR cc (1)
.SH BUGS
The addresses of
.IR etext ,
.IR edata ,
and
.I end
are not meaningful with incrementally loaded code.
|