NAME cin - C interpreter SYNOPSIS cin [ option ... ] [ file ... ] [ -- arg ... ] DESCRIPTION Cin interprets a C program comprising the file arguments as in cc(1). The special name '-' signifies standard input. When called with no file arguments, cin defaults to -i. Arguments arg are passed to the interpreted program as cin_argv[1], cin_argv[2], ... and cin_argc. Options -Dname=def, -Dname, -Lname, -Uname, -Iname, -lx, -oname, and -uname are as in cc. Options -O and -g are ignored. Other options are: -0name Pass name to the interpreted program as cin_argv[0]. -Cname Use name as the interpreter startup file (by default, the file The interpreter startup file is ignored by using -C/dev/null. -Fi:o:e Use file descriptors i,o,e as standard input, standard output, and standard error for the interpreter, as dis- tinct from the interpreted code (by default, 0, 1, and 2). -S Enable interactive mode after run-time errors. -Vname:n Declare function name to have a variable number of arguments, the first n of which are to be type-checked. -c Parse files but do not execute the program. -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. -r Prohibit multiply-declared global variables. -s Do not catch signals using signal(2) (by default, cin catches SIGBUS, SIGEMT, SIGFPE, SIGILL, SIGINT, SIGIOT, SIGSEGV, SIGSYS, SIGTRAP). -v Print the user and system times associated with loading files and executing the program, as in time(1). +option Turn off the specified option. The functions and variables listed below are predefined in cin and libcin.a. Their arguments are typed according to these conventions: char *func, *message, *mod, *name, *ref, *string; enode *code; int level, line; long (*after)(); unsigned long addr; void (*before)(), (*routine)(); This first group of functions and variables are the most commonly used. To use them load and include int cin_break(name, line, string) If string is (char *)0, place a cin_system in file name before line number line. Otherwise, place the C- language statement specified by string in file name before line number line. Thus, string is read and eval- uated within the prevailing context of the function without stopping execution. Return 0 if line number line cannot be found in file name. int cin_dump(name) Create an and place it in the file name. Return 0 if name cannot be created. void cin_info(string) Where string is: breakpoint Print cin's cin_breaks and cin_stopins. log Print cin's interactive mode log file name. memory Print cin's memory usage. spy Print cin's spies. symboltable Print cin's symbol table. undefined Print cin's undefined variables. usage Print cin's usage message. version Print cin's version number. view List the available views. The current view is starred (*). where Print a trace of function calls. wrapper Print cin's wrappers. int cin_load(string) Evaluate string as invocation arguments of cin. Return 0 if arguments are not valid. int cin_log(name) mv(1) the interactive mode session log to file name. Return 0 if name cannot be mved. void cin_make(string) If string is (char *)0, then re-load any file that is out of date. Otherwise, run $MAKE, passing string as arguments, and scan its standard output for lines that begin with pound sign (#). Characters following the pound sign are executed as a C-language statement. int cin_pp(func, level) Print the C-language for the function func. Where level is: 0 Print declaration. 1 Print declaration and body. Return 0 if func cannot be found. void cin_quit() Flush output and exit cin. If all else fails, use _exit(2). 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. void cin_return() Return from a call to cin_system. void cin_run(string) Set cin_argv[1], cin_argv[2], ... and cin_argc from string and then main(cin_argc, cin_argv). int cin_spy(func, name, mod, ref) Trace variable references and modifications. If mod is not (char *)0, place the C-language statement specified by mod after the variable name is modified in the func- tion func. If ref is not (char *)0, place the C- language statement specified by ref before the variable name is referenced in the function func. If function value func is (char *)0, search all functions. Return 0 if name cannot be found in func. void cin_step() Step over function calls to the next C-language state- ment in the current or previous function. void cin_stepin() Step into any function to the next C-language state- ment. void cin_stepout() Step out of the current function back to the next C- language statement in the previous function. int cin_stopin(func, string) If string is (char *)0, place a cin_system before the first executable line in the function func, either in the current view or wherever func can be found. Other- wise, place the C-language statement specified by string before the first executable line in the function func, either in the current view or wherever it can be found. Thus, string is read and evaluated within the prevailing context of the function without stopping execution. Return 0 if function func cannot be found. char *cin_sync(string) Where string is: filename Return the non-interactive C source file name being executed. lineno Return the non-interactive C source line number being executed. void cin_system() Start a cin_read-cin_eval-cin_print loop. int cin_unbreak(name, line, string) Clear a cin_break or a cin_stopin in file name before line number line with string string. Return 0 if cin_break or cin_stopin cannot be cleared. int cin_unload(name) Unload the object file name. Return 0 if name cannot be unloaded. int cin_unspy(func, name, mod, ref) Remove the C-language statement specified by mod after the variable name is modified, and the C-language statement specified by ref before the variable name is referenced in the function func. Return 0 if spy cannot be cleared. int cin_unstopin(func, string) Clear a cin_stopin or cin_break at the first executable line in the function func with string string in either the current view or wherever func can be found. Return 0 if the cin_stopin or cin_break cannot be cleared. int cin_unwrapper(func, before, after) Remove the call of function before before the function func is called. Remove the call of function after after the function func is called. Return 0 if func cannot be found. int cin_view(name) Change the current view to name. Return 0 if the view cannot be found. int cin_wrapper(func, before, after) If before is not (void (*)())0, call the function before with the arguments of function func before the function func is called. If after is not (long (*)())0, call the function after with the argument of the return value of function func after the function func is called. The return value of function after is substituted for the return value of function func. Return 0 if name cannot be found either in the current view or any other view. extern int cin_argc The number of elements passed to the interpreted pro- gram. extern char **cin_argv An array of the arguments passed to the interpreted program. extern char *cin_filename The current C source file name being executed. extern int cin_level The number of nested calls to cin_system. extern char *cin_libpath A colon (:) -separated list of libraries to search for undefined routines (by default, the libraries specified on the command line and extern int cin_lineno The current C source line number being executed. extern char *cin_prompt The interactive mode prompt (by default, the string ''cin> ''). These are some of the less frequently used functions and variables in cin. They are primarily used by cin library or language developers. enode *cin_compile(code) Analyze code and return an optimized program. Return (enode *)0 if code cannot be compiled. int cin_epp(func) Print the enodes for function func. Return 0 if func cannot be found. enode *cin_eprint(code) Print the code as enodes. Return the argument. char *cin_error_code_set(message, string) Where message is: dynamic error When 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 string. undefined function When cin detects an undefined function execute the C-language statement specified by string. undefined symbol When cin detects an undefined symbol execute the C-language statement specified by string. If string is (char *)0, execute cin_system(). Return the old string for message. enode *cin_eval(code) Execute the code as if it were present in the program where cin_eval is called. Return the resulting pro- gram. ident *cin_find_ident(name) If name is not (char *)0, return the identifier for the variable name either in the current view or wherever name can be found. If name is (char *)0, return the identifier for the previous non- (char *)0 value of the variable name in the next view where name can be found. Return (ident *)0 if name cannot be found. struct nlist *cin_find_nlist(addr) Return the loader symbol table entry for the external address addr. Return (struct nlist *)0 if addr cannot be found. void (*cin_info_set())(string, routine) Inform cin_info that it should call routine when it is passed string. Return the old routine for string. char *cin_ltof(line) Return the function name at line number line in the current view. Return (char *)0 if a function cannot be found for line. void cin_pop(level) Replace level interpreted function calls from the stack with cin_system. enode *cin_print(code, level) Print the code as C-language code. Where level is: 0 Print declaration. 1 Print declaration and body. Return the code argument. enode *cin_read(string) Read string and return a program. Return (enode *)0 if string cannot be parsed. char *cin_slashify(string) Return a pointer to storage obtained from malloc(3) and there create a character array from string by translat- ing backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, single quote, and double quote into \b, \f, \n, \r, \t, \v, \\, \', and \" respectively. Other non-printable characters are translated into \ddd octal notation. extern int cin_err_fd Cin's standard error file descriptor. extern int cin_in_fd Cin's standard input file descriptor. extern int cin_out_fd Cin's standard output file descriptor. extern stackelem *cin_stack The trace of function calls. extern view *cin_views The list of available views. EXAMPLES The world's shortest ''Hello world'' program. cin> printf("Hello world\n"); Hello world (int)12 Setting breakpoints and tracing function calls. $ 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(); $ FILES default interactive log various function and variable declarations various predefined functions interpreter startup file other files as in cc(1) SEE ALSO CIN(1) CIN(1) Cin User Manual Cin Reference Manual B. W. Kernighan and D. M. Ritchie, The C Programming Language, Prentice-Hall, 1978 lint(1), ar(1), cc(1) BUGS The addresses of etext, edata, and end are not meaningful with incrementally loaded code.