Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!think.com!sdd.hp.com!usc!apple!olivea!oliveb!isc-br!ewu!ttork From: ttork@ewu.UUCP (Terry Torkelson) Newsgroups: comp.sys.transputer Subject: Unix Occam Compiler (part 4 of 4) Keywords: Occam Message-ID: <1340@ewu.UUCP> Date: 14 Nov 90 19:42:09 GMT Distribution: usa Organization: Eastern Washington Univ. Cheney WA Lines: 1153 ----------tools.shar---------- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # tools # This archive created: Thu Apr 19 16:54:45 1990 export PATH; PATH=/bin:$PATH if test ! -d 'tools' then mkdir 'tools' fi cd 'tools' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else cat << \SHAR_EOF > 'Makefile' # configurable definitions: ################################################################################ CC=/bin/cc CNAME=cc AS=/bin/as ASNAME=as CPP=/lib/cpp CPPNAME=cpp SRCDIR=.. DESTDIR=/m/usr/gil/occam # OCCDIR and BINDIR should exist OCCDIR=$(DESTDIR)/lib BINDIR=$(DESTDIR)/bin OCP=$(OCCDIR)/ocp OCPNAME=ocp LIB=$(OCCDIR)/lsim.a LIBNAME=lsim.a OCCNAME=occ OCC=$(BINDIR)/occ ################################################################################ CFLAGS= \ -DCC=\"$(CC)\" -DCNAME=\"$(CNAME)\" -DAS=\"$(AS)\" \ -DASNAME=\"$(ASNAME)\" -DCPP=\"$(CPP)\" -DCPPNAME=\"$(CPPNAME)\" \ -DOCCDIR=\"$(OCCDIR)\" -DOCP=\"$(OCP)\" -DOCPNAME=\"$(OCPNAME)\" \ -DLIB=\"$(LIB)\" -DLIBNAME=\"$(LIBNAME)\" $(OCCNAME): occ.c Makefile $(CC) $(CFLAGS) -o $(OCCNAME) occ.c # installation of $(OCC), $(OCP), $(LIB). # $(OCP) and $(LIB) should be prepared in the source directories # $(SRCDIR)/{comp,sim} install: $(OCCNAME) $(SRCDIR)/comp/$(OCPNAME) $(SRCDIR)/sim/$(LIBNAME) @echo installing $(OCCNAME) $(OCPNAME) $(LIBNAME) -install $(OCCNAME) $(OCC) -install $(SRCDIR)/comp/$(OCPNAME) $(OCP) -install $(SRCDIR)/sim/$(LIBNAME) $(LIB) ranlib $(LIB) SHAR_EOF fi # end of overwriting check if test -f 'ocp.1' then echo shar: will not over-write existing file "'ocp.1'" else cat << \SHAR_EOF > 'ocp.1' .TH OCP 1N "15 November 1986" .UC 4 .SH NAME ocp \- .B Occam language system .SH SYNOPSIS .B ocp [ .I \-S ] [ .I \-L ] [ .I \-C ] [ .I \-T ] [ .I \-c ] [ .B cc .I flags ] [ .I files.. ] .sp .B [ .I \-s ] [ .I \-i ] [ .I \-r ] [ .I \-d ] [ .I \-t [opts] ] [ .I \-q ] [ .I \-f [] ] .SH DESCRIPTION .PP Ocp is an .B OCCAM compiler. .B OCCAM is a computer language which supports parallel execution of program parts, It is used on the .I Transputer parallel computer. The Ocp system provides a compiler and a runtime library used to run .B Occam programs on the UNIX/VAX system. .PP The occam compiler accepts a list of arguments, interpreted as follows: .PP Arguments whose names end with .B `.oc' are taken to be occam source programs. They are compiled, and an object file with the suffix `.o' substituting `.oc' is left, for further linking. .PP Other file names are taken to be acceptable arguments to .B cc(1) and passed unchanged to the C-compiler (see below). .PP The following options are interpreted by .IR ocp : .TP 3 .B \-L Produce program listing for the named .B OCCAM programs on the corresponding files suffixed '.lst'. .TP 3 .B -C Do not generate code for run-time commands counting. .TP 3 .B -T By default, the compiler generates code for automatic stack expansion when the current stack is exhausted. When this option is raised, the above code is not produced by the compiler. Resulting a more efficient code. .TP 3 .B \-c Suppress the loading phase of the compilation, and force an object file to be produced even if only one program is compiled. .TP 3 .B \-S Compile the named .B OCCAM programs, and leave the assembler-language output on corresponding files suffixed `.s'. This option suppresses the loading phase. .PP The loading phase is done by the C-compiler .IR (cc(1)) including the loading of the runtime library, compilation of other files (as mentioned above) and interpretation of all other flags. .SH Language Additions .PP In addition to the standard .B OCCAM language the .B Ocp system provides the following extensions: .PP As mentioned above, separate compilation of partial .B OCCAM programs is supported by the system. The linking of the produced object files with any other UNIX object file is done by the standard loader .IR ld(1). The naming convention for global data agrees with that of the C-compiler (i.e. names are prefixed with '_'). The loading phase includes the loading of the C-library (libc), which includes interface to system calls and a buffered-io library. .PP A cross files (and possibly cross languages) variable-sharing is provided by an external declaration. .br syntax: .br .nf \fIextern\fR .fi The object declared external via this statement is linked with the original object (declared normally, in a different file/part), and may be used normally throughout the program. .PP Recursion is allowed in programs. Note should be taken of the stack size consideration made by the compiler and the runtime library. The user should use carefully the -T, -s, and -r options in order to tune his program memory/cpu usage. .PP Strings are heavily supported by the compiler: calls of the form: .br .nf foo("hello world") .fi .br when `foo' is a declared procedure are allowed. .br Passing of strings through channels is also supported, as in: .br .nf OUTPUT ! "hello world*n" .fi .br The C-language string convention is supported (using `\\' as escape character). .PP .SH Channel behavior .PP Special channels are supported in three forms: .TP 3 VAX/VMS\-OCCAM compatible special channels. The VAX/VMS special channels are used to connect .B OCCAM programs with UNIX files and special files (terminal, keyboard, etc.), in a compatible manner with the INMOS VAX/VMS-OCCAM special channels. .TP 3 Special channels for I/O. The special I/O channels are used to connect .B OCCAM programs to UNIX files. In this form, the channels are used as one-way data streams (to a file or from it). One special function is called to attach a channel to a file: .br .nf \fBchassign\fR(, , ) .fi .br .I Chassign associates the channel named `chname' with the file descriptor `fd' obtained from .I open, dup, creat, or .IR pipe(2). The mode `mode' must agree with the mode of the open file: .br 0 - for read only .br 1 - for write only .br 2 - for read & write .br Further access to the channel is in the usual way. .br Two special channels are automatically declared upon invoking of the compiler: INPUT & OUTPUT. They can further be assigned to any file-descriptor. .TP 3 Special VAX/VMS\-OCCAM compatible TIME channel. The special time channel provides a different, VAX/VMS compatible, interface for the local clock. Thus, the local clock can be accessed in two equivalent ways: .br `TIME ? ' :: ` := NOW'. .br `TIME ? AFTER ' :: `WAIT NOW AFTER '. .PP Channel messages of different sizes are prohibited by the system. When read and write requests of different sizes are encountered on a channel, the systems panics and quits. .SH Runtime Library .PP The runtime library provides a virtual parallel machine interface which matches the abstract .B OCCAM machine to which the compiler is designed. The library simulates the .B OCCAM primitives for parallel processes and channel operations. It provides a scheduler and timer for parallel processes, and a connected channeled message passing. .PP The parallelism simulation is done by the scheduler; At a pre-defined interval (user tunable, see below) a context-switching between running processes is performed, thus sharing the sequential time (more or less) equally between the processes. Memory is allocated for each process, separately, for the local data, and its size is pre-defined (user-tunable, see below). .br Stacks are expanded when stack bottom is reached. When a process' stack is exhausted, an additional stack is allocated for it. This stack is automatically freed on return from the routine in which stack overflow has occurred. If the user program uses a known fixed stack size, it should be run with the \-T option to gain performance improvement. .PP All the runtime routines are loaded in the linking phase. The execution of any .B OCCAM program starts in a proto-type routine that acts as a father process to all processes. The `proto' routine accepts the following options: .TP 3 .B \-s Determine the local-data size for all processes. Default is 8Kb. .TP 3 .B \-r Determine the reservation stack space, this size is used as a minimal reservation space when generating code for automatic stack expansion. see the -T compiler option. .TP 3 .B \-i Specify the interval for context-switching. 'n' is the number per cpu-second switches. Default is 25. .TP 3 .B \-d .br Run in debug mode. In this mode the library routines print out messages for debugging. .TP 3 .B \-t[options..] .br Turn on trace flags according to `options': .br .RS 3 .TP 6 \fB`c'\fR \- trace context switching. .TP 6 \fB`f'\fR \- trace forks (creation of new processes). .TP 6 \fB`s'\fR \- same as `f'. .TP 6 \fB`b'\fR \- trace blocking/unblocking of processes on events. .TP 6 \fB`i'\fR \- trace i/o events. .RE .IP Empty `options' implies all trace flags. .TP 3 .B \-f[filename] .br By default, tracing messages are sent to \fIstderr\fP. When this option is given tracing messages are sent to \fIfilename\fP. If \fIfilename\fP is not given \fIstdout\fP is used. .TP 3 .B \-q .br Quiet mode. Without this flag the program will print out counting of the parallel and sequential instruction-count .B (OCCAM instruction level) upon termination. .SH Not Supported The special .B OCCAM configuration directives PRI ALT, PRI PAR, PLACED PAR, ALLOCATE, are not supported since they do not have a meaningful semantics in the system. .SH ERRORS The system will panic with an error message on the following events: .sp .IP "no more channels -" Channels pool has been exhausted. .IP "select channel disappeared -" Internal error. Shouldn't happen. .IP "noncompatible receive-send request on channel -" Requests for sending/receiving messages of different sizes on a channel. .IP "noncompatible sizes in receive-send -" Requests for sending/receiving operands of different types on channel. .IP "alloc stack failed -" Stack memory have been exhausted. .IP "no more process -" Processes pool has been exhausted. .IP "deadlock -" Deadlock situation. .IP "non word messages are not allowed in Vms -" Attempt to send operand of compound type on VMS special channel. .IP "vms select not implemented yet -" Attempt to use ALT on VMS channels. .IP "vms: can't read from closed file -" Attempt to read from a VMS special channel connected to a closed file. .IP "vms: file not open for reading -" attempt to read from a write-only file-connected VMS special channel. .IP "try to write on a closed file -" Attempt to write to a VMS special channel connected to a closed file. .IP "flushing a closed file -" Attempt to flush a VMX channel connected to a closed file. .IP "bad request -" Bad request code on VMS special channel. .IP "trying to close a closed file -" Attempt to close a VMS channel connected to a closed file. .SH FILES .SH SEE ALSO "OCCAM programming manual", INMOS Limited, Prentice Hall International. .br "Occam programming system, VAX/VMS host manual", INMOS Limited. .br "A UNIX Occam system", TR, Hebrew Uni. Jerusalem. .IR cc(1), .IR ld(1), .IR open(2), .IR creat(2), .IR dup(2) .SH BUGS The stack handling mechanism is very subtle and should be tuned carefully for each program. There is no syntax-error handling yet. The compiler will produce lexical & semantical error messages. In case of syntax error only the line number will be printed out. .sp 1 Please report any other bugs via electronic mail to: .br .ti 1i csnet: dalia@huji .br .ti 1i bitnet: dalia@hujics .br .ti 1i uucp: decvax!huji!dalia .SH AUTHOR Dalia Malki & Gil Shwed, Hebrew University, Jerusalem. SHAR_EOF fi # end of overwriting check if test -f 'ocp.n' then echo shar: will not over-write existing file "'ocp.n'" else cat << \SHAR_EOF > 'ocp.n' OCP(1N) UNIX Programmer's Manual OCP(1N) NAME ocp - Occam language system SYNOPSIS ocp [ -_S ] [ -_L ] [ -_C ] [ -_T ] [ -_c ] [ cc _f_l_a_g_s ] [ _f_i_l_e_s.. ] [ -_s ] [ -_i ] [ -_r ] [ -_d ] [ -_t [opts] ] [ -_q ] [ -_f [] ] DESCRIPTION Ocp is an OCCAM compiler. OCCAM is a computer language which supports parallel execution of program parts, It is used on the _T_r_a_n_s_p_ u_t_e_r paral- lel computer. The Ocp system provides a compiler and a runtime library used to run Occam programs on the UNIX/VAX system. The occam compiler accepts a list of arguments, interpreted as follows: Arguments whose names end with `.oc' are taken to be occam source pro- grams. They are compiled, and an object file with the suffix `.o' sub- stituting `.oc' is left, for further linking. Other file names are taken to be acceptable arguments to cc(1) and passed unchanged to the C-compiler (see below). The following options are interpreted by _o_c_p: -L Produce program listing for the named OCCAM programs on the corresponding files suffixed '.lst'. -C Do not generate code for run-time commands counting. -T By default, the compiler generates code for automatic stack expansion when the current stack is exhausted. When this option is raised, the above code is not produced by the compiler. Resulting a more effi- cient code. -c Suppress the loading phase of the compilation, and force an object file to be produced even if only one program is compiled. -S Compile the named OCCAM programs, and leave the assembler-language output on corresponding files suffixed `.s'. This option suppresses the loading phase. The loading phase is done by the C-compiler (_c_c(_1)) including the lo ad- ing of the runtime library, compilation of other files (as mentioned above) and interpretation of all other flags. Language Additions In addition to the standard OCCAM language the Ocp system provides the following extensions: As mentioned above, separate compilation of partial OCCAM programs is supported by the system. The linking of the produced object files with any other UNIX object file is done by the standard loader _l_d(_1). Th e naming convention for global data agrees with that of the C-compiler (i.e. names are prefixed with '_'). The loading phase includes the loading of the C-library (libc), which includes interface to system calls and a buffered-io library. A cross files (and possibly cross languages) variable-sharing is pro- vided by an external declaration. syntax: _e_x_t_e_r_n The object declared external via this statement is linked with the ori- ginal object (declared normally, in a different file/part), and may be used normally throughout the program. Recursion is allowed in programs. Note should be taken of the stack size consideration made by the compiler and the runtime library. The user should use carefully the -T, -s, and -r options in order to tune his program memory/cpu usage. Printed 11/20/86 15 November 1986 1 OCP(1N) UNIX Programmer's Manual OCP(1N) Strings are heavily supported by the compiler: calls of the form: foo("hello world") when `foo' is a declared procedure are allowed. Passing of strings through channels is also supported, as in: OUTPUT ! "hello world*n" The C-language string convention is supported (using `\' as escape char- acter). Channel behavior Special channels are supported in three forms: VAX/VMS-OCCAM compatible special channels. The VAX/VMS special channels are used to connect OCCAM programs with UNIX files and special files (terminal, keyboard, etc.), in a compa- tible manner with the INMOS VAX/VMS-OCCAM special channels. Special channels for I/O. The special I/O channels are used to connect OCCAM programs to UNIX files. In this form, the channels are used as one-way data streams (to a file or from it). One special function is called to attach a channel to a file: chassign(, , ) _C_h_a_s_s_i_g_n associates the channel named `chname' with the file descrip- tor `fd' obtained from _o_p_e_n, _d_u_p, _c_r_e_a_t, or _p _i_p_e(_2). The mode `mode' must agree with the mode of the open file: 0 - for read only 1 - for write only 2 - for read & write Further access to the channel is in the usual way. Two special channels are automatically declared upon invoking of the compiler: INPUT & OUTPUT. They can further be assigned to any file- descriptor. Special VAX/VMS-OCCAM compatible TIME channel. The special time channel provides a different, VAX/VMS compatible, interface for the local clock. Thus, the local clock can be accessed in two equivalent ways: `TIME ? ' :: ` := NOW'. `TIME ? AFTER ' :: `WAIT NOW AFTER '. Channel messages of different sizes are prohibited by the system. When read and write requests of different sizes are encountered on a channel, the systems panics and quits. Runtime Library The runtime library provides a virtual parallel machine interface which matches the abstract OCCAM machine to which the compiler is designed. The library simulates the OCCAM primitives for parallel processes and channel operations. It provides a scheduler and timer for parallel processes, and a connected channeled message passing. The parallelism simulation is done by the scheduler; At a pre-defined interval (user tunable, see below) a context-switching between running processes is performed, thus sharing the sequential time (more or less) equally between the processes. Memory is allocated for each process, separately, for the local data, and its size is pre-defined (user- tunable, see below). Stacks are expanded when stack bottom is reached. When a process' stack is exhausted, an additional stack is allocated for it. This stack is automatically freed on return from the routine in which stack overflow has occurred. If the user program uses a known fixed stack size, it should be run with the -T option to gain performance improvement. All the runtime routines are loaded in the linking phase. The execution of any OCCAM program starts in a proto-type routine that acts as a father process to all processes. The `proto' routine accepts the fol- lowing options: -s Determine the local-data size for all processes. Default is 8Kb. -r Printed 11/20/86 15 November 1986 2 OCP(1N) UNIX Programmer's Manual OCP(1N) Determine the reservation stack space, this size is used as a minimal reservation space when generating code for automatic stack expansion. see the -T compiler option. -i Specify the interval for context-switching. 'n' is the number per cpu-second switches. Default is 25. -d Run in debug mode. In this mode the library routines print out mes- sages for debugging. -t[options..] Turn on trace flags according to `options': `c' - trace context switching. `f' - trace forks (creation of new processes). `s' - same as `f'. `b' - trace blocking/unblocking of processes on events. `i' - trace i/o events. Empty `options' implies all trace flags. -f[filename] By default, tracing messages are sent to _s_t_d_e_r_r. When this option is given tracing messages are sent to _f_i_l_e_n_a_m_e. If _f_i _l_e_n_a_m_e is not given _s_t_d_o_u_t is used. -q Quiet mode. Without this flag the program will print out counting of the parallel and sequential instruction-count (OCCAM instruction level) upon termination. Not Supported The special OCCAM configuration directives PRI ALT, PRI PAR, PLACED PAR, ALLOCATE, are not supported since they do not have a meaningful seman- tics in the system. ERRORS The system will panic with an error message on the following events: no more channels - Channels pool has been exhausted. select channel disappeared - Internal error. Shouldn't happen. noncompatible receive-send request on channel - Requests for sending/receiving messages of different sizes on a channel. noncompatible sizes in receive-send - Requests for sending/receiving operands of different types on channel. alloc stack failed - Stack memory have been exhausted. no more process - Processes pool has been exhausted. deadlock - Deadlock situation. non word messages are not allowed in Vms - Attempt to send operand of compound type on VMS special channel. Printed 11/20/86 15 November 1986 3 OCP(1N) UNIX Programmer's Manual OCP(1N) vms select not implemented yet - Attempt to use ALT on VMS channels. vms: can't read from closed file - Attempt to read from a VMS special channel connected to a closed file. vms: file not open for reading - attempt to read from a write-only file-connected VMS special chan- nel. try to write on a closed file - Attempt to write to a VMS special channel connected to a closed file. flushing a closed file - Attempt to flush a VMX channel connected to a closed file. bad request - Bad request code on VMS special channel. trying to close a closed file - Attempt to close a VMS channel connected to a closed file. FILES SEE ALSO "OCCAM programming manual", INMOS Limited, Prentice Hall International. "Occam programming system, VAX/VMS host manual", INMOS Limited. "A UNIX Occam system", TR, Hebrew Uni. Jerusalem. _c_c(_1), _l_d(_1 ), _o_p_e_n(_2), _c_r_e_a_t(_2), _d_u_p(_2) BUGS The stack handling mechanism is very subtle and should be tuned care- fully for each program. There is no syntax-error handling yet. The com- piler will produce lexical & semantical error messages. In case of syn- tax error only the line number will be printed out. Please report any other bugs via electronic mail to: csnet: dalia@huji bitnet: dalia@hujics uucp: decvax!huji!dalia AUTHOR Dalia Malki & Gil Shwed, Hebrew University, Jerusalem. Printed 11/20/86 15 November 1986 4 SHAR_EOF fi # end of overwriting check if test -f 'reserve' then echo shar: will not over-write existing file "'reserve'" else cat << \SHAR_EOF > 'reserve' #! /bin/csh -f set words = reserved_words sort $words : \ awk 'BEGIN {\ printf "#include \n#include \"all.h\"\n\nstruct reswords ReservedWords[ ] = {\n"; }\ /^#/ { next }\ { if(NF == 3) type = $3; else type = "reserved"; \ printf "\t%-16s,%-16s,%s,\n", $1, $2, type }\ END { printf "};\nint nreserved = sizeof(ReservedWords)/sizeof(struct reswords) ;\n" }\ ' > reserved_words.c SHAR_EOF fi # end of overwriting check if test -f 'makeerrs' then echo shar: will not over-write existing file "'makeerrs'" else cat << \SHAR_EOF > 'makeerrs' #! /bin/sh awk ' BEGIN { printf "#define ERR_LIST\n"; printf "#include \"error.h\"\n"; printf "struct error_list Err_list[] = {\n"; printf " WARNING, \"No Error\",\n"; FS=":"; } { n++; printf " %s, \"%s\",\n#define %s %d\n", $1, $3, $2, n; } END { printf"};\n"; }' < ../comp/err_types > ../comp/error_list.c grep "^#define" < ../comp/error_list.c > ../comp/h/errors.h SHAR_EOF fi # end of overwriting check if test -f 'occ.c' then echo shar: will not over-write existing file "'occ.c'" else cat << \SHAR_EOF > 'occ.c' #include #define MAXARGS 128 #define load_occam() (!cflag && !Sflag) char *malloc(), *strcpy(), *rindex(); char *mktemp(); static char *pname; static char *args[MAXARGS]; static int args_cnt; static char ocpflags[20], ocpn = 1; static int Sflag; /* leave assembler files */ static int cflag; /* separate compilation: leave .o files */ static int Lflag; /* listing flag; passed to ocp (ONLY) */ static int Cflag; /* no counter flag; passed to ocp (ONLY) */ static int Tflag; /* don't generate code for automatic stack : expansion */ int vflg; char *Occdir; char *tflags(), *setsuf(), *getenv(); main(ac, av) char **av; { register i; register char *p; int ccflag; int was_error = 0; if(Occdir == NULL && (Occdir = getenv("OCCDIR")) == NULL) Occdir = OCCDIR; pname = av[0]; args[args_cnt++] = CNAME; for(i = 1; i < ac; i++) { if (av[i][0] == '-') av[i] = tflags(&av[i][1]); } for(i = 1; i < ac; i++) { if (occam_suffix(av[i])) { if (cpp_suffix(av[i]) && pass_cpp(av[i])) was_error = 1; else if (occam_comp(av[i]) == 0) { if (load_occam()) { args[args_cnt++] = setsuf(av[i],"o"); } } else was_error = 1; } else if (av[i][0]) args[args_cnt++] = av[i]; } ccflag = 0; for (i = 1; i < args_cnt; i++) if (args[args_cnt][0] != '-') ccflag++; if (ccflag) { char buf[128]; sprintf(buf, "%s/%s", Occdir, LIBNAME); args[args_cnt++] = buf; args[args_cnt] = (char *)0; if (execute(CC, args) != 0) was_error = 1; } exit(was_error); } execute(prog, argv) char *prog, **argv; { int f; int s; char buf[128]; if(prog[0] != '/') { sprintf(buf, "%s/%s", Occdir, prog); prog = buf; } if(vflg) { char **av; printf("exec %s: ", prog); for(av = argv; *av; av++) printf("%s ", *av); printf("\n"); } fflush(stdout); if ((f = fork()) > 0) { wait(&s); return s; } else if (f == 0) { int i; execv(prog, argv); Prerror("Cannot execute %s: ", prog); perror(NULL); exit(1); } else Prerror("cannot fork\n"); } Prerror(fmt, a, b, c, d, e) char *fmt; { fprintf(stderr, "%s: ", pname); fprintf(stderr, fmt, a, b, c, d, e); } char *tflags(options) char *options; { register char *p; char *nopts; /* new option string, stripped from : the local options */ register char *np; np = nopts = malloc(strlen(options)+2); /* at most */ *np++ = '-'; for (p = options; *p; p++) switch(*p) { case 'S': if (!Sflag) { /* first time.. */ *np++ = 'S'; } Sflag = 1; break; case 'c': if (!cflag) { *np++ = 'c'; } cflag = 1; break; case 'L': if (!Lflag) { ocpflags[ocpn++] = 'L'; } Lflag = 1; break; case 'C': if(!Cflag) { ocpflags[ocpn++] = 'C'; } Cflag = 1; break; case 'T': if(!Tflag) { ocpflags[ocpn++] = 'T'; } Tflag = 1; break; case 'v': vflg++; break; default: /* maybe a c-flag? */ *np++ = *p; break; } if (np-nopts == 1) nopts[0] = '\0'; /* avoid just '-' */ *np = '\0'; return nopts; } occam_suffix(name) char *name; { register l; l = strlen(name); if(l < 4) return 0; if (strcmp(&name[l-3], ".oc") == 0 :: strcmp(&name[l-4], ".occ") == 0) return 1; return 0; } cpp_suffix(name) char *name; { register l; l = strlen(name); if(l < 4) return 0; if (strcmp(&name[l-4], ".occ") == 0) return 1; return 0; } static char *TMPS = "/tmp/ocsXXXXXX"; static char template[30]; /* big enough to hold /tmp/... */ occam_comp(prog) char *prog; { char *sname; char *oname; register i; char *ocp_args[5]; int s; /* first - activate the code generator 'ocp' */ if (Sflag) sname = setsuf(prog, "s"); else { strcpy(template, TMPS); sname = mktemp(template); } i = 0; ocp_args[i++] = OCPNAME; if (ocpn > 1) { ocpflags[0] = '-'; ocp_args[i++] = ocpflags; } ocp_args[i++] = prog; ocp_args[i++] = sname; ocp_args[i] = (char *)0; if ((s = execute(OCP, ocp_args)) != 0 :: Sflag) goto remove; /* now - if everytihing is fine, activate the assembler */ oname = setsuf(prog, "o"); i = 0; ocp_args[i++] = ASNAME; ocp_args[i++] = "-o"; ocp_args[i++] = oname; ocp_args[i++] = sname; ocp_args[i] = '\0'; s = execute(AS, ocp_args); remove: if (!Sflag) unlink(sname); return s; } char *setsuf(name, suf) char *name, *suf; { char *c, *p; c = strcpy(malloc(strlen(name)), name); if ((p = rindex(c, '.')) == NULL) { Prerror("setsuf - name %s has no suffix"); return NULL; } strcpy(p+1, suf); return c; } pass_cpp(s) char *s; { register l = strlen(s); char buf[128], *args[4]; strcpy(buf, s); s[l-1] = '\0'; args[0] = CPPNAME; args[1] = buf; args[2] = s; args[3] = NULL; return execute(CPP, args); } SHAR_EOF fi # end of overwriting check cd .. # End of shell archive exit 0 ----------end of tools.shar---------- -- - - Terry Torkelson Internet: ttork%ewu@uunet.uu.net - Eastern Washington University uucp: uunet!isc-br!ewu!ttork - tellynet: 509-359-6016