#!/bin/csh -f #(ie run the cshell on this but don't read the .cshrc) echo version = 3.14 of tc 2002 August 17 # 2002 Aug 17, 3.14: tc checks for gcc, allows gcc to be anywhere # 2002 Aug 17, 3.13: upgrade documentation # 2002 Apr 17, 3.11: upgrade output, make smarter # 2000 Oct 2, 3.10: no longer overwrite ~/.p2crc # 2000 Jul 24, 3.07: allow program or program.p as input name # Dr. Thomas D. Schneider # National Cancer Institute # Laboratory of Experimental and Computational Biology # Frederick, Maryland 21702-1201 # toms@ncifcrf.gov # permanent email: toms@alum.mit.edu # http://www.lecb.ncifcrf.gov/~toms/ echo Convert Pascal to C and compile using gcc if !($#argv == 1) then echo "The tc script converts Pascal programs to C" echo "and then complies them using gcc." echo "The tc script uses the p2c program. See:" echo "http://www.lecb.ncifcrf.gov/~toms/pascalp2c.html" echo "for further information." echo echo "It also uses the ver program:" echo "http://www.lecb.ncifcrf.gov/~toms/delila/ver.html" echo "You can comment out the call to ver, it is only used to" echo "tell you the version number of the program being worked on." endif # use these if you did a public installation of p2c: set INCLUDELOCATION = /usr/local/include set LIBLOCATION = /usr/local/lib # Use these if you installed somewhere else: # Make InstallLocation be the directory where you built p2c. # set InstallLocation = p2c # set INCLUDELOCATION = $InstallLocation/home # set LIBLOCATION = $InstallLocation/home if !(-d $INCLUDELOCATION) then echo $INCLUDELOCATION does not exist, it is needed for gcc exit endif if !(-d $LIBLOCATION/p2c) then echo $LIBLOCATION/p2c does not exist, it is needed for gcc echo "See:" echo "http://www.lecb.ncifcrf.gov/~toms/pascalp2c.html" exit endif if !(-d $LIBLOCATION) then echo $LIBLOCATION does not exist, it is needed for gcc exit endif # look for the gcc compiler set gcc = gcc # the last part of which should be gcc: set whichgcc = `which $gcc|tr "/" "\012"|tail -1` if ("$whichgcc" == "$gcc") then echo $gcc complier found else echo "**************************" echo "* $gcc complier NOT FOUND *" echo "**************************" exit endif # strip the .p off the end of the program name set program = `echo $1 | sed -e "s/\.p//"` echo converting $program from Pascal to C... if (-f $program.p) then echo $program.p exists echo "so we can delete $program and $program.c*" echo "REMOVING $program and $program.c*" rm -f $program $program.c* # you can use out the following line if you have ver set up: # ver <$program.p # otherwise just use the version line: grep "version = " $program.p | head -1 echo translating on host computer `hostname` if !(-f ~/.p2crc) then echo You do not have a .p2crc file in your home directory. echo Creating a ~/.p2crc file in your home directory... echo "LiteralFiles 2" > ~/.p2crc echo "NestedComments 2" >> ~/.p2crc echo "StructFiles 1" >> ~/.p2crc endif # translate: p2c -c ~/.p2crc $program.p # special changes to get around bugs in p2c: set tmp = /tmp/$program.c mv $program.c $tmp sed -e "s/P_getbits_%s/P_getbits_UB/g" < /tmp/$program.c > $program.c set changes = `diff $tmp $program.c | head -1` if ($changes != "") then echo "list of special changes:" echo "------------------------" diff $tmp $program.c echo "------------------------" endif rm -f $tmp echo compiling using gcc: gcc \ $program.c -o $program \ -I$INCLUDELOCATION -L$LIBLOCATION -lm -lp2c echo '{'$program' done}' else echo $program.p DOES NOT EXIST endif