Hello community, here is the log from the commit of package dpic for openSUSE:Factory checked in at 2015-05-20 23:58:32 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/dpic (Old) and /work/SRC/openSUSE:Factory/.dpic.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "dpic" Changes: -------- --- /work/SRC/openSUSE:Factory/dpic/dpic.changes 2015-02-27 11:00:26.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.dpic.new/dpic.changes 2015-05-20 23:58:34.000000000 +0200 @@ -1,0 +2,8 @@ +Wed May 20 18:30:30 UTC 2015 - [email protected] + +- Update to version 2015.05.19 + * Bugfixes for nested if-statement and multiple pdf strings. + * Fix comment lines containing braces in macro and for bodies. + Revised messages for some errors. + +------------------------------------------------------------------- Old: ---- dpic-2015.02.16.tar.gz New: ---- dpic-2015.05.19.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ dpic.spec ++++++ --- /var/tmp/diff_new_pack.A4LH3G/_old 2015-05-20 23:58:34.000000000 +0200 +++ /var/tmp/diff_new_pack.A4LH3G/_new 2015-05-20 23:58:34.000000000 +0200 @@ -17,7 +17,7 @@ Name: dpic -Version: 2015.02.16 +Version: 2015.05.19 Release: 0 Summary: Pic language processor License: BSD-2-Clause and CC-BY-3.0 ++++++ dpic-2015.02.16.tar.gz -> dpic-2015.05.19.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/dpic/CHANGES new/dpic/CHANGES --- old/dpic/CHANGES 2015-02-16 17:26:17.000000000 +0100 +++ new/dpic/CHANGES 2015-05-19 20:14:24.000000000 +0200 @@ -2,6 +2,9 @@ those shown correspond to changes (usually of documentation) not involving functionality. +2015 05 19 Bugfixes for nested if-statement and multiple pdf strings. +2015 04 01 Fix comment lines containing braces in macro and for bodies. Revised + messages for some errors. 2015 02 13 Reworked the handling of backslashes in strings in macro arguments. 2015 02 04 PDF output. Built-in variable dpicopt and variables added for detecting command options. Linear objects reworked for consistent fill. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/dpic/doc/dpic.1 new/dpic/doc/dpic.1 --- old/dpic/doc/dpic.1 2015-02-16 17:26:17.000000000 +0100 +++ new/dpic/doc/dpic.1 2015-05-19 20:14:24.000000000 +0200 @@ -58,7 +58,7 @@ LaTeX drawing output (very limited font\(hybased drawing capability) .br .B \-d -PDF output +PDF output, basic strings .br .B \-e pict2e output @@ -845,6 +845,10 @@ .B " x :=" .I expr .P +or any assignment using an operator in the set +.P +.B " := += -= *= /= %=" +.P requires .B x to have been defined previously in the current block or an enclosing block. Files old/dpic/doc/dpicdoc.pdf and new/dpic/doc/dpicdoc.pdf differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/dpic/doc/quick.pic new/dpic/doc/quick.pic --- old/dpic/doc/quick.pic 2015-02-16 17:26:19.000000000 +0100 +++ new/dpic/doc/quick.pic 2015-05-19 20:14:25.000000000 +0200 @@ -1,7 +1,7 @@ .PS # Pic input begins with .PS -# cct_init Version 8.0: PSTricks m4 macro settings. +# cct_init Version 8.04: PSTricks m4 macro settings. - # gen_init Version 8.0: PSTricks m4 macro settings. + # gen_init Version 8.04: PSTricks m4 macro settings. define rpoint__ { @@ -28,7 +28,6 @@ # cct_init end # Read in macro definitions and set defaults - elen = 0.75 # Variables are allowed; default units are inches Origin: Here # Position names are capitalized line invis up elen diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/dpic/dpic.c new/dpic/dpic.c --- old/dpic/dpic.c 2015-02-16 17:26:17.000000000 +0100 +++ new/dpic/dpic.c 2015-05-19 20:14:23.000000000 +0200 @@ -60,7 +60,7 @@ /* Some PC versions of p2c crash on Pascal const declarations at low levels. All consts should be in dp0.x */ -/* Version= 'dpic version dpic version 2015.02.16'; p2c crashes on this */ +/* Version= 'dpic version dpic version 2015.05.19'; p2c crashes on this */ /* UMBX distmax = 1E25; XBMU */ #define distmax 3.40282347e+38 /* assumes at least IEEE single */ @@ -737,6 +737,7 @@ int errcount; /* becomes nonzero when errors found */ errmsginx errmp; /* index of error messages in errmsg */ int lineno; /* current input line number */ +int currprod; /* current production for error msgs */ /* Production variables */ attribute *attstack; @@ -3849,7 +3850,7 @@ (1L << ((long)PSfrag)) | (1L << ((long)SVG)))) != 0 && (lx == XLspline || lx == XLarrow || lx == XLline || lx == XLarc)); /* p2c: dpic1.p, line 1395: - * Note: Line breaker spent 0.0 seconds, 5000 tries on line 3404 [251] */ + * Note: Line breaker spent 0.0 seconds, 5000 tries on line 3405 [251] */ if (drawmode == SVG) hs = (hs || lx == XLstring); @@ -4715,8 +4716,10 @@ if (WITH->xval == 0.0) { attstack[newp + 1].lexval = XLBRACE; WITH->lexval = XLBRACE; - } else + } else { + currprod = elsehead1; skiptobrace(); + } break; /* for = forhead "lbrace" elementlist optnl */ @@ -4916,10 +4919,13 @@ if xval <> 0.0 then writeln(log,' true') else writeln(log,' false') end; D*/ if (WITH->xval != 0.0) { - for (i = 0; i <= 3; i++) + for (i = 1; i <= 3; i++) attstack[newp + i].lexval = XLBRACE; - } else + } else { + currprod = ifhead1; skiptobrace(); + } + WITH->lexval = XLBRACE; break; /* setlogic = "<EMPTY>" */ @@ -4986,6 +4992,7 @@ } else resetscale(WITH->xval, XEQ, envblock); + currprod = forhead1; if (WITH->length == 0) skiptobrace(); else { @@ -5162,14 +5169,15 @@ WITH5->carray[i] = chbuf[WITH->chbufx + i - 1]; WITH5->savedlen = WITH->length; WITH5->readx = WITH->length + 1; + currprod = p; readfor(macp->argbody, -WITH->length, &macp->argbody); /* append the body */ lastm = macp->argbody; while (lastm->nextb != NULL) lastm = lastm->nextb; lastm->carray[lastm->savedlen] = etxch; - /*D; if debuglevel > 1 then begin - writeln(log); write(log,'def','head1'); + /*D; if debuglevel > 1 then begin writeln(log); + if prod=defhead1 then write(log,'defhead1') else write(log,'defhead2'); lastm := macp^.argbody; while lastm<> nil do begin wrbuf(lastm,3,0); lastm := lastm^.nextb end end D*/ @@ -5190,7 +5198,7 @@ WITH2->UU.Ubox.boxradius = 0.0; newstr(&WITH2->textp); if (p == sprintf1) - nexprs = 0; /* no of expression args */ + nexprs = 0; /* no of expression arguments */ else nexprs = attstack[newp + 4].state; if (tmpbuf == NULL) @@ -8112,7 +8120,6 @@ switch (ptmp->ptype) { case XLbox: - case XBLOCK: case XLcircle: case XLellipse: north = Max(north, ptmp->aat.ypos + hight * 0.5); @@ -8121,6 +8128,15 @@ east = Max(east, ptmp->aat.xpos + wdth * 0.5); break; + case XBLOCK: + if (hight != 0 || wdth != 0) { + north = Max(north, ptmp->aat.ypos + hight * 0.5); + south = Min(south, ptmp->aat.ypos - hight * 0.5); + west = Min(west, ptmp->aat.xpos - wdth * 0.5); + east = Max(east, ptmp->aat.xpos + wdth * 0.5); + } + break; + case XLstring: neswstring(ptmp, hight, wdth); break; @@ -8278,7 +8294,7 @@ while (small > 0) { i = small; small = large % small; -/* p2c: dpic2.p, line 486: +/* p2c: dpic2.p, line 492: * Note: Using % for possibly-negative arguments [317] */ large = i; } @@ -8693,7 +8709,7 @@ writeln('Center'); writeln('Inches'); writeln(xfigres:1,' 2'); - writeln('# dpic version 2015.02.16 option -x for Fig 3.1') + writeln('# dpic version 2015.05.19 option -x for Fig 3.1') */ printf("#FIG 3.2\n"); @@ -8704,7 +8720,7 @@ printf("100.00\n"); printf("Single\n"); printf("-2\n"); - printf("# dpic version 2015.02.16 option -x for Fig 3.2\n"); + printf("# dpic version 2015.05.19 option -x for Fig 3.2\n"); printf("%ld 2\n", (long)xfigres); } @@ -9094,7 +9110,7 @@ printf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"); printf("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); - printf("<!-- Creator: dpic version 2015.02.16 option -v for SVG 1.1 -->\n"); + printf("<!-- Creator: dpic version 2015.05.19 option -v for SVG 1.1 -->\n"); hsize = (e - w + 2 * lth) / fsc; vsize = (n - s + 2 * lth) / fsc; printf("<!-- width=\"%d\" height=\"%d\" -->\n", @@ -9944,7 +9960,7 @@ wcoord(&output, w, s); wcoord(&output, e, n); printf("%%\n"); - printf("%% dpic version 2015.02.16 option -p for PSTricks 0.93a or later\n"); + printf("%% dpic version 2015.05.19 option -p for PSTricks 0.93a or later\n"); } @@ -10667,7 +10683,7 @@ wbrace(e / fsc); wbrace(s / fsc); wbrace(n / fsc); - printf("\n%% dpic version 2015.02.16 option -m for mfpic\n"); + printf("\n%% dpic version 2015.05.19 option -m for mfpic\n"); printf("\\dashlen=4bp\\dashspace=4bp\\dotspace=3bp\\pen{0.8bp}\n"); printf("\\def\\mfpdefaultcolor{black}\\drawcolor{\\mfpdefaultcolor}\n"); gslinethick = 0.8; @@ -11344,7 +11360,7 @@ { /* n,s,e,w: real */ printstate++; - printf("%% dpic version 2015.02.16 option -s for MetaPost\n"); + printf("%% dpic version 2015.05.19 option -s for MetaPost\n"); printf("beginfig(%d)\n", printstate); printf("def lcbutt=linecap:=butt enddef;\n"); printf("def lcsq=linecap:=squared enddef;\n"); @@ -11982,7 +11998,7 @@ { /* n,s,e,w: real */ printf("\\begin{tikzpicture}[scale=2.54]\n"); - printf("%% dpic version 2015.02.16 option -g for TikZ and PGF 1.01\n"); + printf("%% dpic version 2015.05.19 option -g for TikZ and PGF 1.01\n"); printf("\\ifx\\dpiclw\\undefined\\newdimen\\dpiclw\\fi\n"); printf("\\global\\def\\dpicdraw{\\draw[line width=\\dpiclw]}\n"); printf("\\global\\def\\dpicstop{;}\n"); @@ -12656,7 +12672,7 @@ pswfloat(&output, sx); pswfloat(&output, ex); pswfloat(&output, nx); - printf("\n%%%%Creator: dpic version 2015.02.16 option "); + printf("\n%%%%Creator: dpic version 2015.05.19 option "); switch (drawmode) { case PSfrag: @@ -13494,7 +13510,7 @@ pdfobjcount = 0; printf("%%PDF-1.4\n"); - printf("%% Creator: dpic version 2015.02.16 option -d for PDF\n"); + printf("%% Creator: dpic version 2015.05.19 option -d for PDF\n"); addbytes(62); /* pdfobjcount must be 1 here */ /* 123456789 123456789 123456789 123456789 123456789 123456789 12345*/ @@ -13802,9 +13818,11 @@ writeln(log,' textht=',textht:8:3,'[',textht/fsc:8:3,']', ' textwid=',textwid:8:3,'[',textwid/fsc:8:3,']') end; D*/ y += (nstr / 2.0 - 4.0 / 5) * textht; + nstr = 1; do { - if (textwid <= 0) + if (textwid <= 0 || nstr > 1) textwid = tp->len * textht * 0.6; + nstr++; checkjust(tp, &A, &B, &L, &R); pdfwln("BT", 2, &cx); pdfstream("/F1", 3, &cx); @@ -14431,7 +14449,7 @@ wcoord(&output, w, s); printf("\n\\thicklines\n"); } - printf("%% dpic version 2015.02.16 option "); + printf("%% dpic version 2015.05.19 option "); switch (drawmode) { case TeX: @@ -16271,7 +16289,30 @@ break; case 804: - fprintf(errout, "End of file while reading {...} contents\n"); + case 807: + fprintf(errout, "End of file while reading "); + if (emi == 807) + fprintf(errout, "string in "); + switch (currprod) { + + case elsehead1: + fprintf(errout, "else"); + break; + + case ifhead1: + fprintf(errout, "if"); + break; + + case forhead1: + fprintf(errout, "for"); + break; + + case defhead1: + case defhead2: + fprintf(errout, "define"); + break; + } + fprintf(errout, " {...} contents\n"); break; case 805: @@ -16376,8 +16417,6 @@ fprintf(errout, "String character generated at end of line\n"); break; - /* 902: writeln(errout, - 'Buffer size of 4096 characters exceeded while reading a string'); */ case 903: fprintf(errout, "Picture size adjusted to maxpswid value\n"); break; @@ -16647,7 +16686,7 @@ if lineno = i*10*linesignal then writeln(errout,'lineno ',lineno:1) end; if debuglevel > 1 then begin - writeln(log); write(log,'lineno ',lineno:1,':') end; D*/ + writeln(log); writeln(log,'lineno ',lineno:1,':') end; D*/ if (lexstate == 0 && !inputeof) { WITH = inbuf; @@ -16688,7 +16727,7 @@ write(log,'inchar['); if prevb<>nil then write(log,ordp(prevb):1); write(log,'<',ordp(inbuf):1,'>'); if nextb<>nil then write(log,ordp(nextb):1); - write(log,']: instr=',instr) end; D*/ + writeln(log,']: instr=',instr) end; D*/ bufend = (inbuf->readx >= inbuf->savedlen); while (bufend) { @@ -16701,12 +16740,19 @@ else if (instr) { if (WITH->savedlen < CHBUFSIZ) { WITH->savedlen++; - /* else if attrib > 0 then markerror(902) */ + WITH->carray[WITH->savedlen] = nlch; + } else if (WITH->attrib > 0) { + newbuf(&tp); + tp->attrib = inbuf->attrib; + tp->prevb = inbuf; + tp->savedlen = 1; + tp->carray[1] = nlch; + WITH->nextb = tp; } else { WITH->readx--; WITH->carray[WITH->readx] = bslch; + WITH->carray[WITH->savedlen] = nlch; } - WITH->carray[WITH->savedlen] = nlch; bufend = false; } } @@ -16751,9 +16797,10 @@ WITH->readx++; /*D; if debuglevel = 2 then with inbuf^ do begin - write(log,' savedlen=',savedlen:1,' readx=',readx:1); + write(log,' savedlen=',savedlen:1); if inputeof then write(log,' inputeof'); - write(log,' '); wrchar(ch); writeln(log) + write(log,' '); wrchar(ch); + writeln(log,' readx=',readx:1) end D*/ /* This is not a loop */ @@ -16950,7 +16997,7 @@ /*D if debuglevel > 0 then begin write(log, 'findarg('); if arlst = nil then write(log,'nil') else write(log,ordp(arlst):1); - write(log,',',k:1,'):') end; D*/ + write(log,',',k:0,'):') end; D*/ if (k > 0) ar = arlst; else @@ -16980,7 +17027,7 @@ fbuffer *abuf, *WITH; int FORLIM; - /*D if debuglevel > 0 then write(log,'readstring(',stringch,') '); D*/ + /*D if debuglevel > 0 then writeln(log,'readstring(',stringch,')'); D*/ j = -1; n = 0; instr = true; @@ -16989,6 +17036,9 @@ if (inputeof) instr = false; else if (ch == bslch) { + /*D if debuglevel > 0 then begin + write(log,' readstring3, instr=',instr,' '); + wrchar(ch); writeln(log) end; D*/ pushch(); if (ch == stringch) chbufi--; @@ -17001,32 +17051,34 @@ else if (j >= 0) { if (n > 0 && args != NULL) /* delete $nn */ chbufi = j; - ar = findarg(args, n); - if (ar != NULL) { - abuf = ar->argbody; - while (abuf != NULL) { - WITH = abuf; - FORLIM = WITH->savedlen; - for (n = WITH->readx; n <= FORLIM; n++) { - chbuf[chbufi] = WITH->carray[n]; - if (chbufi < CHBUFSIZ) - chbufi++; - else - fatal(4); + if (n > 0) { + ar = findarg(args, n); + if (ar != NULL) { + abuf = ar->argbody; + while (abuf != NULL) { + WITH = abuf; + FORLIM = WITH->savedlen; + for (n = WITH->readx; n <= FORLIM; n++) { + chbuf[chbufi] = WITH->carray[n]; + if (chbufi < CHBUFSIZ) + chbufi++; + else + fatal(4); + } + abuf = abuf->nextb; } - abuf = abuf->nextb; } + /*D if debuglevel > 0 then begin write(log,'arg(',n:1,')|'); + for n := j to chbufi-1 do write(log,chbuf^[n]); + write(log,'| ') end; D*/ } - /*D if debuglevel > 0 then begin write(log,'arg(',n:1,')|'); - for n := j to chbufi-1 do write(log,chbuf^[n]); - write(log,'| ') end; D*/ j = -1; n = 0; pushfl = false; } else if (ch == stringch) instr = false; /*D if debuglevel > 0 then begin - write(log,' readstring2, instr=',instr,' '); + write(log,' readstring2, instr=',instr,' j=',j:0,' pushfl=',pushfl); wrchar(ch); writeln(log) end;D*/ if (instr && pushfl) pushch(); @@ -17816,7 +17868,10 @@ break; if (inputeof) { bracelevel = 0; - markerror(804); + if (instring) + markerror(807); + else + markerror(804); } else { prevch = ch; inchar(); @@ -17837,7 +17892,7 @@ boolean instring; Char prevch; - /*D if debuglevel = 2 then begin + /*D if debuglevel > 0 then begin write(log,'readfor: attx('); if attx<0 then write(log,'-length)=') else write(log,'attstack idx)='); writeln(log,attx:5) @@ -17870,6 +17925,9 @@ if (instring) { /* do not check braces in strings */ if (ch == '"' && prevch != bslch) instring = false; + } else if (ch == '#') { + skiptoend(); + ch = nlch; } else if (ch == '{') bracelevel++; else if (ch == '}') @@ -17889,7 +17947,10 @@ if (bracelevel > 0) inchar(); if (inputeof) { - markerror(804); + if (instring) + markerror(807); + else + markerror(804); j = p1->savedlen; bracelevel = 0; } @@ -17899,7 +17960,7 @@ p1 = p1->prevb; backup(); /*D if debuglevel > 0 then begin - write(log,'For/macro buffer'); wrbuf(p1,3,0) end; D*/ + write(log,'readfor: for/macro buffer'); wrbuf(p1,3,0) end; D*/ *p2 = p1; } @@ -18311,7 +18372,7 @@ else if (cht >= '0') and (cht <= '9') then oflag := ord(cht)-ord('0') MHGUD*/ } else if (cht == 'h' || cht == '-') { - fprintf(errout, " *** dpic version 2015.02.16\n"); + fprintf(errout, " *** dpic version 2015.05.19\n"); fprintf(errout, " options:\n"); fprintf(errout, " (none) LaTeX picture output\n"); /* writeln(errout,' -d pdftex graphicx output'); */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/dpic/dpictools.pic new/dpic/dpictools.pic --- old/dpic/dpictools.pic 1970-01-01 01:00:00.000000000 +0100 +++ new/dpic/dpictools.pic 2015-05-19 18:04:45.000000000 +0200 @@ -0,0 +1,255 @@ +# dpictools.pic +# Some pic macros. Input this file using +# copy "HOMELIB_/dpictools.pic" when HOMELIB_ is defined or, generically, +# copy "<path>dpictools.pic" + +# Circuit_macros Version 8.04, copyright (c) 2015 J. D. Aplevich under # +# the LaTeX Project Public License. The files of this distribution may # +# be redistributed or modified provided that this copyright notice is # +# included and provided that modifications are clearly marked to # +# distinguish them from this distribution. There is no warranty # +# whatsoever for these files. # + +# findroot(function,left bound,right bound,tolerance,var name) +# Solve function(x)=0 by the method of bisection +# e.g. define parabola { $2 = ($1)^2 - 1 } +# findroot( parabola, 0, 2, 1e-8, x ) +define findroot {$5 = 0; [ x_m = $2; x_M = $3 + loop( $1(x_m,f_m);, abs(x_M-x_m)>$4,, + x_c = (x_m+x_M)/2 + $1(x_c,f_c) + if sign(f_c)==sign(f_m) then {x_m=x_c} else {x_M=x_c};) + $5 := (x_m+x_M)/2 ]; } + +# bisect(function,left bound,right bound, tolerance, var name) +# Like findroot but uses recursion +define bisect { x_m_$1 = $2; x_M_$1 = $3 + x_c_$1 = (x_m_$1+x_M_$1)/2 + if (abs(x_m_$1-x_M_$1) <= $4) then { $5 = x_c_$1 } else { + $1(x_m_$1,f_m_$1) + $1(x_c_$1,f_c_$1) + if (sign(f_c_$1)==sign(f_m_$1)) then { bisect($1,x_c_$1,x_M_$1,$4,$5) } \ + else { bisect($1,x_m_$1,x_c_$1,$4,$5) } } } + + +# testexpr(i, expr1, expr2, ... ) +# Set i to index of the first true alternative +# in a sequence of logical expressions, e.g., +# testexpr(i, 1>2, 1<2) returns 2 +define testexpr { $1 = -1; [for i=2 to $+ do { + exec sprintf("if $%g then {$1 := i-1; i=$+}",i); }]; } + +# Case statement: execute alternative i +# case(i, alt1, alt2, ... ), e.g., +# case(2, x = 5, x = 10, x = 15) sets x to 10 +define case { exec sprintf("$%g",floor($1+0.5)+1); } + +# loop(initial,test,loopend,statements) +# C-like loop. Commas in arg3 and arg4 must +# be in quotes or parentheses, e.g., +# loop(i=1,i<=3,i+=1,print i) prints 1, 2, 3 +ld__ = 0 +define loop {ld__+=1 + $1 + for lx__[ld__]=0 to 1 do { + if $2 then { lx__[ld__]=0; $4; $3; } else { lx__[ld__]=1 }} + ld__-=1; } + +# array(var,expr1,expr2,...) +# var[1]=expr1; var[2]=expr2,... +define array { + for i_array=2 to $+ do { exec sprintf("$1[%g] = $%g",i_array-1,i_array); }} + +# slantbox(wid,ht,xslant,yslant,lineattribs) +define slantbox { [ + if "$1"=="" then { w = boxwid } else { w = $1 } + if "$2"=="" then { h = boxht } else { h = $2 } + if "$3"=="" then { xs = 0 } else { xs = $3 } + if "$4"=="" then { ys = 0 } else { ys = $4 } + NE: (w+xs,h+ys)/2 ; SE: (w-xs,-h+ys)/2 + SW: (-w-xs,-h-ys)/2 ; NW: (-w+xs,h-ys)/2 + N: 0.5 between NW and NE ; E: 0.5 between NE and SE + S: 0.5 between SE and SW ; W: 0.5 between SW and NW + C: 0.5 between SW and NE + line $5 from N to NE then to SE then to SW then to NW then to N + ] } +# arraymax( data array, n, index name, value) +# Find the index in array[1:n] of the first +# occurrence of the max value. The value is +# assigned if arg4 is non-blank. eg., +# array(x,4,9,8,6); arraymax( x,4,i ) +# assigns 2 to i, and arraymax( x,4,i,m ) +# assigns 2 to i and 9 to m +define arraymax { { $3 = -1; if "$4" != "" then { $4 = 0 }; [ m_arrm = -1e25 + for i_arrm=1 to $2 do { if $1[i_arrm] > m_arrm then { + $3 := i_arrm; m_arrm = $1[i_arrm] }} + if "$4" != "" then { $4 := m_arrm } ] } } +# arraymin( data array, n, index name, value) +# Like arraymax +define arraymin { { $3 = -1; if "$4" != "" then { $4 = 0 }; [ m_arrm = 1e25 + for i_arrm=1 to $2 do { if $1[i_arrm] < m_arrm then { + $3 := i_arrm; m_arrm = $1[i_arrm] }} + if "$4" != "" then { $4 := m_arrm } ] } } + +# copythru(macro_name,"datafile") +# See the GNU pic manual +# Implements copy datafile thru macro_name +# for data separated by comma, spaces, or tabs +define copythru { + sh "sed -e 's/^[ ]*/$1(/' -e 's/[ ]*$/)/' -e 's/[, ][ ]*/,/g' $2 \ + > copy_tmp__" + copy "copy_tmp__" + sh "rm -f copy_tmp__";} + +# randn(array name,n,mean,stddev) +# Assign n Gaussian random numbers +# in array[1] ... array[n] +define randn { + if "$2"=="" then { n_randn = 1 } else { n_randn = $2 } + if "$3"=="" then { m_randn = 0 } else { m_randn = $3 } + if "$4"=="" then { s_randn = 1 } else { s_randn = $4 } + for i_randn=1 to n_randn by 2 do { + loop( t_randn=2, t_randn >= 1, u_randn = 2*rand()-1; v_randn = 2*rand()-1 + t_randn = u_randn^2+v_randn^2 ) + t_randn = sqrt( -2*loge(t_randn)/t_randn ) + $1[i_randn] = u_randn*t_randn*s_randn+m_randn + if i_randn < n_randn then { + $1[i_randn+1] = v_randn*t_randn*s_randn+m_randn } + } + } + +# histbins { data array name, n, [min], [max], +# nbins, bin array name ) +# Generate the distribution of n values in +# dataarray. If given, arg2 and arg3 specify +# maximum and minimum data values, otherwise they +# are calculated. Bins have index 0 to arg5-1 +define histbins { # dataarray, n, [min], [max], nbins, binarray +{ if "$3" == "" then { arraymin($1,$2,mn_histb,n_histb)} else { n_histb = $3 } + if "$4" == "" then { arraymax($1,$2,mx_histb,m_histb)} else { m_histb = $4 } + f_histb = ($5-0.001)/(m_histb-n_histb) + for i_histb=0 to $5-1 do { $6[i_histb] = 0 } + for i_histb=1 to $2 do { $6[floor(($1[i_histb]-n_histb)*f_histb)] += 1 } +} } + +# dpquicksort(a,lo,hi,ix) +# Given array a[lo:hi] and index +# array ix[lo:hi] = lo,lo+1,lo+2,...hi, sort +# a[lo:hi] and do identical exchanges on ix +define dpquicksort { [ if $3 > $2 then { + pivot = $1[($2+($3))/2] + loop(lo = $2; hi = $3, lo <= hi, + loop(,$1[lo] < pivot, lo = lo + 1) + loop(,$1[hi] > pivot, hi = hi - 1) + if lo < hi then { + tmp = $1[lo]; $1[lo] := $1[hi]; $1[hi] := tmp + tmp = $4[lo]; $4[lo] := $4[hi]; $4[hi] := tmp } + if lo <= hi then { lo = lo + 1; hi = hi - 1 } ) + if hi > $2 then { exec sprintf("dpquicksort($1,%g,%g,$4)",$2,hi) } + if lo < $3 then { exec sprintf("dpquicksort($1,%g,%g,$4)",lo,$3) } + } ] } + +# rgbtohsv(r,g,b,h,s,v) +# rgb color triple to hsv with h range 0 to 360 +define rgbtohsv { $4 = 0; $5 = 0; $6 = 0 + [r = $1; g = $2; b = $3 + maxc = max(max(r,g),b) + minc = min(min(r,g),b) + if maxc==minc then { $4 := 0 } \ + else {if maxc == r then { + $4 := pmod(60*((g-b)/(maxc-minc)),360) } \ + else {if maxc == g then { + $4 := 60*((b-r)/(maxc-minc)) + 120 } \ + else { $4 := 60*((r-g)/(maxc-minc)) + 240 }}} + if maxc == 0 then { $5 := 0 } else { $5 := 1 - (minc/maxc) } + $6 := maxc + ] } +# hsvtorgb(h,s,v,r,g,b) +# hsv color triple to rgb, h has range 0 to 360 +define hsvtorgb { $4 = 0; $5 = 0; $6 = 0 + [h = pmod($1,360)/60; s = $2; v = $3 + i = floor(h) + f = h-i + m = v*(1-s) + n = v*(1-s*f) + k = v*(1-s*(1-f)) + case(i+1, + $4 := v; $5 := k; $6 := m, + $4 := n; $5 := v; $6 := m, + $4 := m; $5 := v; $6 := k, + $4 := m; $5 := n; $6 := v, + $4 := k; $5 := m; $6 := v, + $4 := v; $5 := m; $6 := n) + ] } + +# cmyktorgb(c,m,y,k,r,g,b) +# cmyk colors in percent to rgb +define cmyktorgb { + $5 = 1-min(1,($1+$4)/100) + $6 = 1-min(1,($2+$4)/100) + $7 = 1-min(1,($3+$4)/100) + } +# rgbtocmyk(r,g,b,c,m,y,k) +# rgb to cmyk colors out of 100 +define rgbtocmyk { + $7 = min(1-$1,min(1-$2,1-$3))*100 + $4 = (1-$7-$1)/(1-$7)*100 + $5 = (1-$7-$2)/(1-$7)*100 + $6 = (1-$7-$3)/(1-$7)*100 } + +# ShadedObject(DrawRoutineName, n, colorseq) +# colorseq = 0,r0,g0,b0, frac1,r1,g1,b1, frac2,r2,g2,b2, ... 1,rn,gn,bn +# with 0 < frac1 < frac2 < ... < 1 +# calls DrawRoutine(frac,r,g,b) n times with interpolated args +# for frac = 1/n to 1 +define ShadedObject { [ nSteps = $2 + exec sprintf("nextP = $%g; nextR = $%g; nextG = $%g; nextB = $%g", 3,4,5,6) + nextarg = 7 + thisP = nextP + rgbtohsv(nextR^2,nextG^2,nextB^2,nextH,nextS,nextV) + if nextP*nSteps >= 1 then { nextP = 0 } + for stepnum = 1 to nSteps do { + if stepnum > nextP*nSteps then { + thisP = nextP; thisH = nextH; thisS = nextS; thisV = nextV + exec sprintf("nextP = $%g; nextR = $%g; nextG = $%g; nextB = $%g",\ + nextarg,nextarg+1,nextarg+2,nextarg+3); + nextarg +=4 } + if nextP != thisP then { + rgbtohsv(nextR^2,nextG^2,nextB^2,nextH,nextS,nextV) + if thisS == 0 then { thisH = nextH } + if nextS == 0 then { nextH = thisH } + if thisH-nextH > 180 then { nextH += 360 } \ + else { if nextH-thisH > 180 then { thisH +=360 } } } + if nextP > thisP then { + x = (stepnum/nSteps-thisP)/(nextP-thisP) + currP = thisP*(1-x) + nextP*x + currH = thisH*(1-x) + nextH*x + currS = thisS*(1-x) + nextS*x + currV = thisV*(1-x) + nextV*x + hsvtorgb(currH,currS,currV,cRsq,cGsq,cBsq) + $1(currP,sqrt(cRsq),sqrt(cGsq),sqrt(cBsq)) } + } + ] } + +# Useful for debugging: +# Print Pos:(Pos.x,Pos.y) +define prpos { { print sprintf("$1:(%g,%g)",($1).x,($1).y) } } + +define prval { print sprintf("$1=%g",$1) } +define prval2 { print sprintf("$1=%g, $2=%g",$1,$2) } +define prval3 { print sprintf("$1=%g, $2=%g, $3=%g",$1,$2,$3) } + +# prow(array name,lo,hi) +# print array[lo:hi] as a row +# eg array(x,6,4,5); prow(x,1,3) +define prow { + sh "echo -n \"print \\"\" > $1_xxx" + for i=$2 to $3-1 do { sh sprintf("echo -n \"%g \" >> $1_xxx",$1[i]) } + sh sprintf("echo \"%g\\"\" >> $1_xxx",$1[$3]) + copy "$1_xxx" + sh "rm $1_xxx" + } + +# print " *** dpic: dpictools.pic processed" +define dpictools {1} +# dpictools end
