From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <3.0.5.32.20011213155655.019a72b0@mail.real.com> To: 9fans@cse.psu.edu From: Skip Tavakkolian In-Reply-To: <20011213215248.74D2F19A28@mail.cse.psu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Subject: [9fans] Pascal for Plan9: a HOWTO Date: Thu, 13 Dec 2001 15:56:55 -0800 Topicbox-Message-UUID: 360b8d22-eaca-11e9-9e20-41e7f4b1d025 Use p2c by Dave Gillespie (http://www.synaptics.com/people/daveg/). In some very early incarnations of TeX distribution for UNIX you needed p2c. I think it is this same one. I very hope you'll notice that what I've done below could have been done by a trained hairy monkey! ================================================= cpu% hget -o p2c-1.20.1.tar.gz 'http://www.synaptics.com/people/daveg/p2c-1.20.1.tar.gz' cpu% mkdir p2c cpu% cd p2c cpu% gunzip -c <../p2c-1.20.1.tar.gz | tar -xv x HP/import/asm.imp, 1332 bytes x HP/import/fs.imp, 4894 bytes x HP/import/general_0.imp, 940 bytes x HP/import/general_1.imp, 646 bytes x HP/import/general_2.imp, 911 bytes x HP/import/general_3.imp, 232 bytes x HP/import/general_4.imp, 1992 bytes x HP/import/hpib_0.imp, 775 bytes x HP/import/hpib_1.imp, 1359 bytes x HP/import/hpib_2.imp, 1489 bytes x HP/import/hpib_3.imp, 1178 bytes x HP/import/iodecl.imp, 11318 bytes x HP/import/misc.imp, 2478 bytes x HP/import/sysdevs.imp, 15631 bytes x HP/import/sysglobals.imp, 13046 bytes x HP/import/rnd.imp, 210 bytes x HP/include/asm.h, 1663 bytes x HP/include/hpib_0.h, 435 bytes x HP/include/hpib_1.h, 710 bytes x HP/include/fs.h, 4438 bytes x HP/include/general_0.h, 824 bytes x HP/include/general_1.h, 690 bytes x HP/include/general_2.h, 862 bytes x HP/include/general_3.h, 347 bytes x HP/include/general_4.h, 1497 bytes x HP/include/hpib_2.h, 934 bytes x HP/include/hpib_3.h, 658 bytes x HP/include/iodecl.h, 6087 bytes x HP/include/misc.h, 2815 bytes x HP/include/rnd.h, 160 bytes x HP/include/sysdevs.h, 12249 bytes x HP/include/sysglobals.h, 8748 bytes x Makefile, 1629 bytes x README, 5669 bytes x examples/fact.p, 299 bytes x examples/self.p, 1101 bytes x examples/c/basic.c, 52947 bytes x examples/c/cref.c, 7649 bytes x examples/c/e.c, 2640 bytes x examples/c/fact.c, 433 bytes x examples/c/self.c, 1554 bytes x examples/cref.p, 11280 bytes x examples/e.p, 2411 bytes x examples/p2crc, 822 bytes x examples/Makefile, 777 bytes x examples/README, 1463 bytes x examples/basic.p, 66611 bytes x examples/basic.doc, 11310 bytes x ftp.README, 1133 bytes x src/README, 3024 bytes x src/HISTORY, 26404 bytes x src/p2c.man, 47539 bytes x src/NOTES, 32785 bytes x src/COPYING, 12488 bytes x src/sys.p2crc, 78998 bytes x src/Makefile, 5449 bytes x src/trans.c, 40665 bytes x src/stuff.c, 13533 bytes x src/out.c, 35574 bytes x src/comment.c, 9620 bytes x src/lex.c, 87350 bytes x src/parse.c, 126397 bytes x src/decl.c, 144578 bytes x src/expr.c, 143339 bytes x src/pexpr.c, 109596 bytes x src/funcs.c, 144081 bytes x src/dir.c, 5264 bytes x src/hpmods.c, 3182 bytes x src/citmods.c, 31419 bytes x src/p2clib.c, 18218 bytes x src/loc.p2clib.c, 185 bytes x src/makeproto.c, 16398 bytes x src/p2c.h, 13483 bytes x src/trans.h, 79073 bytes x src/p2c.proto, 20013 bytes x src/p2c.hdrs, 32223 bytes x src/TAGS, 33605 bytes x src/p2c.cat, 84298 bytes x src/system.imp, 3784 bytes x src/system.m2, 803 bytes x src/turbo.imp, 9333 bytes x src/string.pas, 1802 bytes x src/loc.p2crc, 138 bytes x src/INSTALL, 5669 bytes cpu% ape/psh bind: /386/bin/pub: file does not exist $ echo $PATH /bin:. $ export PATH=/bin/ape:$PATH $ echo $PATH /bin/ape:/bin:. $ make Compiling p2c, installing in /usr/fst/p2c/home... cd src; make install cc makeproto.c -o makeproto ./makeproto -n -m -h -t16 -a35 -s1 -i trans.c stuff.c out.c comment.c lex.c parse.c decl.c expr.c pexpr.c funcs.c dir.c hpmods.c citmods.c -o p2c.proto ./makeproto -n -m -h -t16 -a35 -s0 -x trans.c stuff.c out.c comment.c lex.c parse.c decl.c expr.c pexpr.c funcs.c dir.c hpmods.c citmods.c -o p2c.hdrs if [ ! -d ../home ]; then mkdir ../home; fi if [ ! -d .. ]; then mkdir ..; fi if [ ! -d ../home ]; then mkdir ../home; fi if [ ! -d ../home ]; then mkdir ../home; fi if [ ! -d ../home/p2c ]; then mkdir ../home/p2c; fi cc -c -DHASDUMPS -DP2C_HOME=\"`cd ../home; pwd`\" trans.c cc -c stuff.c cc -c out.c cc -c comment.c cc -c lex.c cc -c parse.c cc -c decl.c cc -c expr.c cc -c pexpr.c cc -c funcs.c cc -c -DCUST1=hpmods -DCUST2=citmods dir.c cc -c hpmods.c cc -c citmods.c cc trans.o stuff.o out.o comment.o lex.o parse.o decl.o expr.o pexpr.o funcs.o dir.o hpmods.o citmods.o -o p2c cp p2c ../p2c cc -c p2clib.c cc -c loc.p2clib.c ar r libp2c.a p2clib.o loc.p2clib.o ar: creating libp2c.a cp libp2c.a ../home/libp2c.a if [ -f /usr/bin/ranlib -o -f /bin/ranlib ]; then ranlib ../home/libp2c.a; fi sed -e "s;--HOMEDIR--;`cd ../home; pwd`;" -e "s;--INCDIR--;`cd ../home/p2c; pwd`;" -e "s;--LIBDIR--;`cd ../home; pwd`;" p2c.man >p2c.man.inst if [ -f /usr/bin/nroff -o -f /bin/nroff ]; then nroff -man p2c.man.inst >p2c.cat; fi cp p2c.cat ../home/p2c.1 cp p2c.h ../home/p2c/p2c.h cp sys.p2crc ../home/p2crc cp loc.p2crc ../home/loc.p2crc cp system.imp ../home/system.imp cp system.m2 ../home/system.m2 cp turbo.imp ../home/turbo.imp cp string.pas ../home/string.pas Translating and compiling example files... cd examples; make comp ../p2c fact.p fact, factorials Translation completed. c89 -I../home fact.c ../home/libp2c.a -o fact ../p2c e.p initinteger, divide e.p, line 37: Note: Using % for possibly-negative arguments [317] , add, sub, e e.p, line 121: Note: Using % for possibly-negative arguments [317] e.p, line 122: Note: Using % for possibly-negative arguments [317] e.p, line 123: Note: Using % for possibly-negative arguments [317] Translation completed. c89 -I../home e.c ../home/libp2c.a -o e ../p2c self.p t, q, self Translation completed. c89 -I../home self.c ../home/libp2c.a -o self ../p2c cref.p lookup, kw, cref, traverse, crefprog cref.p, line 228: Note: Null character at end of sprintf control string [148] Translation completed. c89 -I../home cref.c ../home/libp2c.a -o cref ../p2c basic.p restoredata, clearloops, arraysize, clearvar, clearvars, numtostr basic.p, line 237: Note: Modification of string length may translate incorrectly [146] basic.p, line 248: Note: Modification of string length may translate incorrectly [146] , parse basic.p, line 309: Note: Modification of string length may translate incorrectly [146] basic.p, line 415: Note: Modification of string length may translate incorrectly [146] , listtokens, disposetokens, parseinput, errormsg, snerr, tmerr, badsubscr, realfactor, strfactor, stringfactor, intfactor, realexpr, strexpr, stringexpr, intexpr, require, skipparen, findvar, inot, ixor, factor basic.p, line 1029: Note: Range checking is OFF [216] basic.p, line 1032: Note: Range checking is ON [216] , upexpr, term basic.p, line 1078: Note: Using % for possibly-negative arguments [317] , sexpr, relexpr, andexpr, expr, checkextra, iseos, skiptoeos, findline, mustfindline, cmdend, cmdnew, cmdlist, cmdload, cmdrun, cmdsave, cmdbye, cmddel, cmdrenum, cmdprint, cmdinput, cmdlet, cmdgoto, cmdif, cmdelse, skiploop, cmdfor, cmdnext, cmdwhile, cmdwend, cmdgosub, cmdreturn, cmdread, cmddata, cmdrestore, cmdgotoxy, cmdon, cmddim, cmdpoke basic.p, line 2073: Note: Range checking is OFF [216] basic.p, line 2077: Note: Range checking is ON [216] , exec basic.p, line 2175/1552: Note: Line breaker spent 0.0 seconds, 5000 tries on line 1552 [251] basic.p, line 2175/1566: Note: Line breaker spent 0.0 seconds, 5000 tries on line 1566 [251] , basic Translation completed. c89 -I../home basic.c ../home/libp2c.a -lm -o basic Running the factorial example... examples/fact The factorial of 1 is 1 The factorial of 2 is 2 The factorial of 3 is 6 The factorial of 4 is 24 The factorial of 5 is 120 The factorial of 6 is 720 The factorial of 7 is 5040 The factorial of 8 is 40320 The factorial of 9 is 362880 The factorial of 10 is 3628800 Running the 'e' computation example... examples/e Series: 0.00% Series: 0.10% Series: 0.10% Series: 0.20% Series: 0.30% Series: 0.30% Series: 0.40% Series: 0.50% Series: 0.60% Series: 0.69% Series: 0.79% Series: 0.89% Series: 0.99% Series: 1.09% Series: 1.29% Series: 1.39% Series: 1.49% Series: 1.59% Series: 1.79% Series: 1.88% Series: 1.98% Series: 2.18% Series: 2.28% Series: 2.38% Series: 2.58% Series: 2.68% Series: 2.88% Series: 2.98% Series: 3.08% Series: 3.27% Series: 3.37% Series: 3.57% Series: 3.67% Series: 3.87% Series: 4.07% Series: 4.17% Series: 4.37% Series: 4.46% Series: 4.66% Series: 4.76% Series: 4.96% Series: 5.16% Series: 5.26% Series: 5.46% Series: 5.65% Series: 5.75% Series: 5.95% Series: 6.15% Series: 6.25% Series: 6.45% Series: 6.65% Series: 6.75% Series: 6.94% Series: 7.14% Series: 7.34% Series: 7.44% Series: 7.64% Series: 7.84% Series: 8.04% Series: 8.13% Series: 8.33% Series: 8.53% Series: 8.73% Series: 8.93% Series: 9.03% Series: 9.23% Series: 9.42% Series: 9.62% Series: 9.82% Series: 10.02% Series: 10.12% Series: 10.32% Series: 10.52% Series: 10.71% Series: 10.91% Series: 11.11% Series: 11.31% Series: 11.51% Series: 11.61% Series: 11.81% Series: 12.00% Series: 12.20% Series: 12.40% Series: 12.60% Series: 12.80% Series: 13.00% Series: 13.19% Series: 13.39% Series: 13.59% Series: 13.79% Series: 13.99% Series: 14.19% Series: 14.38% Series: 14.58% Series: 14.78% Series: 14.88% Series: 15.08% Series: 15.28% Series: 15.48% Series: 15.67% Series: 15.87% Series: 16.07% Series: 16.27% Series: 16.57% Series: 16.77% Series: 16.96% Series: 17.16% Series: 17.36% Series: 17.56% Series: 17.76% Series: 17.96% Series: 18.15% Series: 18.35% Series: 18.55% Series: 18.75% Series: 18.95% Series: 19.15% Series: 19.35% Series: 19.54% Series: 19.74% Series: 19.94% Series: 20.14% Series: 20.44% Series: 20.63% Series: 20.83% Series: 21.03% Series: 21.23% Series: 21.43% Series: 21.63% Series: 21.83% Series: 22.02% Series: 22.32% Series: 22.52% Series: 22.72% Series: 22.92% Series: 23.12% Series: 23.31% Series: 23.51% Series: 23.71% Series: 24.01% Series: 24.21% Series: 24.40% Series: 24.60% Series: 24.80% Series: 25.00% Series: 25.30% Series: 25.50% Series: 25.69% Series: 25.89% Series: 26.09% Series: 26.29% Series: 26.59% Series: 26.79% Series: 26.98% Series: 27.18% Series: 27.38% Series: 27.68% Series: 27.88% Series: 28.08% Series: 28.27% Series: 28.47% Series: 28.77% Series: 28.97% Series: 29.17% Series: 29.37% Series: 29.56% Series: 29.86% Series: 30.06% Series: 30.26% Series: 30.46% Series: 30.75% Series: 30.95% Series: 31.15% Series: 31.35% Series: 31.65% Series: 31.85% Series: 32.04% Series: 32.24% Series: 32.54% Series: 32.74% Series: 32.94% Series: 33.13% Series: 33.43% Series: 33.63% Series: 33.83% Series: 34.03% Series: 34.33% Series: 34.52% Series: 34.72% Series: 34.92% Series: 35.22% Series: 35.42% Series: 35.62% Series: 35.91% Series: 36.11% Series: 36.31% Series: 36.61% Series: 36.81% Series: 37.00% Series: 37.20% Series: 37.50% Series: 37.70% Series: 37.90% Series: 38.19% Series: 38.39% Series: 38.59% Series: 38.89% Series: 39.09% Series: 39.29% Series: 39.58% Series: 39.78% Series: 39.98% Series: 40.28% Series: 40.48% Series: 40.67% Series: 40.97% Series: 41.17% Series: 41.37% Series: 41.67% Series: 41.87% Series: 42.06% Series: 42.36% Series: 42.56% Series: 42.76% Series: 43.06% Series: 43.25% Series: 43.45% Series: 43.75% Series: 43.95% Series: 44.15% Series: 44.44% Series: 44.64% Series: 44.84% Series: 45.14% Series: 45.34% Series: 45.63% Series: 45.83% Series: 46.03% Series: 46.33% Series: 46.53% Series: 46.73% Series: 47.02% Series: 47.22% Series: 47.52% Series: 47.72% Series: 47.92% Series: 48.21% Series: 48.41% Series: 48.71% Series: 48.91% Series: 49.11% Series: 49.40% Series: 49.60% Series: 49.90% Series: 50.10% Series: 50.30% Series: 50.60% Series: 50.79% Series: 51.09% Series: 51.29% Series: 51.49% Series: 51.79% Series: 51.98% Series: 52.28% Series: 52.48% Series: 52.78% Series: 52.98% Series: 53.17% Series: 53.47% Series: 53.67% Series: 53.97% Series: 54.17% Series: 54.46% Series: 54.66% Series: 54.96% Series: 55.16% Series: 55.36% Series: 55.65% Series: 55.85% Series: 56.15% Series: 56.35% Series: 56.65% Series: 56.85% Series: 57.14% Series: 57.34% Series: 57.54% Series: 57.84% Series: 58.04% Series: 58.33% Series: 58.53% Series: 58.83% Series: 59.03% Series: 59.33% Series: 59.52% Series: 59.82% Series: 60.02% Series: 60.32% Series: 60.52% Series: 60.81% Series: 61.01% Series: 61.21% Series: 61.51% Series: 61.71% Series: 62.00% Series: 62.20% Series: 62.50% Series: 62.70% Series: 63.00% Series: 63.19% Series: 63.49% Series: 63.69% Series: 63.99% Series: 64.19% Series: 64.48% Series: 64.68% Series: 64.98% Series: 65.18% Series: 65.48% Series: 65.67% Series: 65.97% Series: 66.17% Series: 66.47% Series: 66.67% Series: 66.96% Series: 67.16% Series: 67.46% Series: 67.66% Series: 67.96% Series: 68.15% Series: 68.45% Series: 68.65% Series: 68.95% Series: 69.25% Series: 69.44% Series: 69.74% Series: 69.94% Series: 70.24% Series: 70.44% Series: 70.73% Series: 70.93% Series: 71.23% Series: 71.43% Series: 71.73% Series: 71.92% Series: 72.22% Series: 72.42% Series: 72.72% Series: 73.02% Series: 73.21% Series: 73.51% Series: 73.71% Series: 74.01% Series: 74.21% Series: 74.50% Series: 74.70% Series: 75.00% Series: 75.20% Series: 75.50% Series: 75.79% Series: 75.99% Series: 76.29% Series: 76.49% Series: 76.79% Series: 76.98% Series: 77.28% Series: 77.48% Series: 77.78% Series: 78.08% Series: 78.27% Series: 78.57% Series: 78.77% Series: 79.07% Series: 79.27% Series: 79.56% Series: 79.86% Series: 80.06% Series: 80.36% Series: 80.56% Series: 80.85% Series: 81.05% Series: 81.35% Series: 81.65% Series: 81.85% Series: 82.14% Series: 82.34% Series: 82.64% Series: 82.94% Series: 83.13% Series: 83.43% Series: 83.63% Series: 83.93% Series: 84.23% Series: 84.42% Series: 84.72% Series: 84.92% Series: 85.22% Series: 85.52% Series: 85.71% Series: 86.01% Series: 86.21% Series: 86.51% Series: 86.81% Series: 87.00% Series: 87.30% Series: 87.50% Series: 87.80% Series: 88.10% Series: 88.29% Series: 88.59% Series: 88.79% Series: 89.09% Series: 89.38% Series: 89.58% Series: 89.88% Series: 90.08% Series: 90.38% Series: 90.67% Series: 90.87% Series: 91.17% Series: 91.47% Series: 91.67% Series: 91.96% Series: 92.16% Series: 92.46% Series: 92.76% Series: 92.96% Series: 93.25% Series: 93.55% Series: 93.75% Series: 94.05% Series: 94.25% Series: 94.54% Series: 94.84% Series: 95.04% Series: 95.34% Series: 95.63% Series: 95.83% Series: 96.13% Series: 96.43% Series: 96.63% Series: 96.92% Series: 97.22% Series: 97.42% Series: 97.72% Series: 97.92% Series: 98.21% Series: 98.51% Series: 98.71% Series: 99.01% Series: 99.31% Series: 99.50% Series: 99.80% Series: 100.00% e = 2. 7182818284 5904523536 0287471352 6624977572 4709369995 9574966967 6277240766 3035354759 4571382178 5251664274 2746639193 2003059921 8174135966 2904357290 0334295260 5956307381 3232862794 3490763233 8298807531 9525101901 1573834187 9307021540 8914993488 4167509244 7614606680 8226480016 8477411853 7423454424 3710753907 7744992069 5517027618 3860626133 1384583000 7520449338 2656029760 6737113200 7093287091 2744374704 7230696977 2093101416 9283681902 5515108657 4637721112 5238978442 5056953696 7707854499 6996794686 4454905987 9316368892 3009879312 7736178215 4249992295 7635148220 8269895193 6680331825 2886939849 6465105820 9392398294 8879332036 2509443117 3012381970 6841614039 7019837679 3206832823 7646480429 5311802328 7825098194 5581530175 6717361332 0698112509 9618188159 3041690351 5988885193 4580727386 6738589422 8792284998 9208680582 5749279610 4841984443 6346324496 8487560233 6248270419 7862320900 2160990235 3043699418 4914631409 3431738143 6405462531 5209618369 0888707016 7683964243 7814059271 4563549061 3031072085 1038375051 0115747704 1718986106 8739696552 1267154688 9570350354 Final digits: 0212109 Running the self-printing Pascal example... examples/self >examples/self.out cat examples/self.out program self(input, output); type s = string[255]; n=integer; var a : array [1..100] of s; i,j : integer; function t(a:integer):integer; begin if a<7 then t:=a else t:=a+11 end; function q(a:s):s; var j:n;begin for j:=strlen(a)downto 1 do if a[j]=#39 then strinsert(#39,a,j);q:=a;end; begin a[1] := 'program self(input, output);'; a[2] := 'type s = string[255]; n=integer;'; a[3] := 'var a : array [1..100] of s; i,j : integer;'; a[4] := 'function t(a:integer):integer; begin if a<7 then t:=a else t:=a+11 end; function q(a:s):s;'; a[5] := ' var j:n;begin for j:=strlen(a)downto 1 do if a[j]=#39 then strinsert(#39,a,j);q:=a;end;'; a[6] := 'begin'; a[18] := ' for i := 1 to 11 do begin setstrlen(a[i+6], 0);'; a[19] := ' strwrite(a[i+6],1,j,'' a['',t(i):1,''] := '''''', q(a[t(i)]), '''''';'');'; a[20] := ' end;'; a[21] := ' for i := 1 to 22 do writeln(a[i]);'; a[22] := 'end.'; for i := 1 to 11 do begin setstrlen(a[i+6], 0); strwrite(a[i+6],1,j,' a[',t(i):1,'] := ''', q(a[t(i)]), ''';'); end; for i := 1 to 22 do writeln(a[i]); end. diff examples/self.p examples/self.out Also try 'cref' and 'basic' in the examples directory. $