\input pstricks.tex
\input pst-node.tex
\input multido.tex
\nopagenumbers
\SpecialCoor
\edef\TheAtCode{\the\catcode`\@}\catcode`\@=11
%Note: this is a proof of concept only
% with no attempt at optimization.
% It is not suitable for a package

%The b-spline control points B0, B1,... are defined here
\edef\myargs{(0,1)(2,0)(5,2)(6,4)(4,5)(2,4)}% for example

\newcount\numargs
\def\my@def(#1){%
\expandafter\def\csname mycoor@\the\numargs\endcsname{(#1)}
}
%This is the loop where the arguments are counted and assigned one by one to the 
% command names defined in \my@def
\def\countargs{\@ifnextchar({\nextPointa}{}}
\def\nextPointa(#1){%
\my@def(#1)
\advance\numargs by 1 
\countargs}
\expandafter\countargs\myargs % action


% In this example, \numargs=6, and the macros \mycoor@0,...\mycoor@5 have been set to 
% (0,1), (2,0), (5,2), (6,4), (4,5), (2,4) respectively
\psset{unit=.75in}
\pspicture[showgrid=true](-.5,-.5)(6,5)
%Now we are within the pspicture environment,
% \pnodes are defined at each location, with names B0, B1,...
\multido{\i=0+1}{\numargs}{\edef\mycs{mycoor@\i}%
\edef\mycsb{\csname \mycs  \endcsname}
\expandafter\pnode\mycsb{B\i}}
% Define the left and right bezier control points in each interval. These are 
% denoted R0, L1, R1, L2, R2, etc
\pnode(B0){S0}
\advance\numargs by -1
%The next line seems silly, but you can't just say \pnode(B\numargs){S\numargs}
\multido{\i=\numargs+1}{1}{\pnode(B\i){S\i}}
\psset{linestyle=none}
\multido{\ia=0+1,\ib=1+1}{\numargs}{\ncline{*-*}{B\ia}{B\ib}\ncput[npos=.3333]{\pnode{R\ia}}\ncput[npos=.6667]{\pnode{L\ib}}}
%Finally, define the bezier endpoints for each interval
\advance\numargs by -1
\psset{linestyle=solid,linecolor=red}
\mmultido{\ia=0+1}{\numargs}{\ncline{*-*}{L\ia}{R\ia}\ncput[npos=.5]{\pnode{S\ia}}\psdot[linecolor=red](S\ia)}
%Now draw in the framework
\psset{linestyle=dashed,linecolor=gray}
\expandafter\psline\myargs
\psset{linestyle=solid,linecolor=blue}
\advance\numargs by 1
%the pieces of bezier curve
\multido{\ia=0+1,\ib=1+1}{\numargs}{\psbezier(S\ia)(R\ia)(L\ib)(S\ib)}
\multido{\i=0+1}{\numargs}{\uput[20](B\i){B\i}}
\uput[90](B5){B5}
\uput[90](S1){S1}
\uput[90](S2){S2}
\uput[180](S3){S3}
\uput[270](S4){S4}
\uput[-45](R1){R1}
\uput[-45](L2){L2}
\psdot[linecolor=red](R0)
\psdot[linecolor=red](L5)

\endpspicture
\catcode`\@=\TheAtCode\relax
\bye