%\tracingassigns=1%
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{pgfextra}
\usepackage{newfile} 

\newlength\xtemp
\newlength\ytemp
\newcommand*{\GetCoordinate}[1]{%
  \getcoordinate{#1}{\xtemp}{\ytemp}%
}

\makeatletter
\newcommand{\tb@APPEND}[2]{%
  \edef\@tempa{#2}%
  \ifx\@tempa\@empty%
    \edef#2{#1}%
  \else%
    \edef#2{\@tempa,#1}%
  \fi%
}
\newcommand{\tb@CONS}[2]{%
  \edef\@tempa{#2}%
  \ifx\@tempa\@empty%
    \edef#2{#1}%
  \else%
    \edef#2{#1,\@tempa}%
  \fi%
}
\def\keyList{}
% A macro printing a list 
\newcommand{\debug}[1]{%
  \@for\@unevar:=#1\do{%
    \@unevar ;\space% = [\csname show\@unevar\endcsname] ; %
  }
}
\newcommand{\puttofile}[1]{%
%   \@bsphack
%   \let\do\@makeother\dospecials
%   \catcode`\^^M\active
%   \verbatim@startline
%   \verbatim@addtoline
%   \verbatim@finish
%  \def\verbatim@processline{%
\immediate\write\@nameuse{keysoutstre@m}{#1}%}%
%   \verbatim@start
%   #1
%   \@esphack
}

\def\pgfkeyssetvalue#1#2{%
  %\puttofile{#1}%
  \tb@APPEND{#1}{\keyList}%
  \pgfkeys@temptoks{#2}%
  \expandafter\edef\csname pgfk@#1\endcsname{\the\pgfkeys@temptoks}%
}
\def\pgfkeyslet#1#2{%
  %\puttofile{#1}%
  \tb@APPEND{#1}{\keyList}%
  \expandafter\let\csname pgfk@#1\endcsname#2%
}
\newtoks\pgfextra@pathtoks
\newcommand{\pgfextra@cons@pathtoks}[1]{%
  \expandafter\def\expandafter\pgfextra@tempa\expandafter{\the\pgfextra@pathtoks}%
  \ifx\pgfextra@tempa\@empty%
    \pgfextra@pathtoks{#1}%
  \else%
    \edef\pgfextra@tempa{#1,\pgfextra@tempa}%
    \expandafter\pgfextra@pathtoks\expandafter{\pgfextra@tempa}%
  \fi%
}
\newcommand{\pgfextra@append@pathtoks}[1]{%
  \expandafter\def\expandafter\pgfextra@tempa\expandafter{\the\pgfextra@pathtoks}%
  \ifx\pgfextra@tempa\@empty%
    \pgfextra@pathtoks{#1}%
  \else%
    \edef\pgfextra@tempa{\pgfextra@tempa#1}%
    \expandafter\pgfextra@pathtoks\expandafter{\pgfextra@tempa}%
  \fi%
}
\newcommand{\pgfextraSplitPath}[1]{%
%  \def\nameList{}%
  \pgfextra@pathtoks{}%
  \pgfextra@splitter#1\relax%
%  Components: \debug{\nameList}
  Components: \debug{\the\pgfextra@pathtoks}%
}
\def\pgfextra@slash{/}
\def\pgfextra@splitter/#1/#2\relax{%
  \def\pgfkeys@temp{#1}%
  \ifx\pgfkeys@temp\pgfkeys@empty%
  \else%
    \pgfextra@append@pathtoks{,#1}%
%    \tb@APPEND{#1}{\nameList}%
  \fi%
  \def\pgfkeys@temp{#2}%
  \ifx\pgfkeys@temp\pgfextra@slash%
  \else%
    \pgfextra@splitter/#2/\relax%
  \fi%
}

\newcommand{\pgfextra@APPEND}[2]{%
  \edef\@tempa{#1}%
  \ifx\@tempa\@empty%
    \edef#1{#2}%
  \else%
    \edef#1{\@tempa,#2}%
  \fi%
}
\newcommand{\pgfextraRegisterPath}[1]{%
  \pgfextra@pathtoks{}%
  \pgfextra@register#1/\relax%
}
\def\pgfextra@define@path#1{%
  \edef\pgfextra@temp@name{#1}%
  \expandafter\def\csname\pgfextra@temp@name\endcsname{}%
}
\def\pgfextra@register/#1/#2\relax{%
  \def\pgfextra@temp{#1}%
  \ifx\pgfextra@temp\@empty%
  \else%
    % Is current path already defined? (always true?)
    \edef\pgfextra@name{pgfextra@keys\the\pgfextra@pathtoks}%
    \ifcsname\pgfextra@name\endcsname%
    \else%
      % define path
      \pgfextra@define@path{\pgfextra@name}
    \fi%
    % Is the subpath already defined?
    \ifcsname\pgfextra@name @#1\endcsname%
    \else%
      % register subpath and define it
      \expandafter\pgfextra@APPEND\expandafter{\csname\pgfextra@name\endcsname}{#1}%
      \pgfextra@define@path{\pgfextra@name @#1}%
    \fi%
    % if the last of the path is empty, that's the end brother
    \def\pgfextra@temp{#2}%
    \ifx\pgfextra@temp\@empty%
      % indicates its #1 is a key (by defining macro \pgfextra@key<path>@#1)
      \expandafter\def\csname pgfextra@key\the\pgfextra@pathtoks @#1\endcsname{}% 
    \else%
      % extends path for future calls
      \pgfextra@append@pathtoks{@#1}%
      \pgfextra@register/#2\relax%
    \fi%
  \fi%
}
% taken from pgf (modified to expand the list)
\def\foreach#1in#2{%
  \def\pgffor@var{#1}%
  \edef\pgffor@values{#2, \noexpand\pgffor@stop,}%
  \ifx\pgffor@values\pgffor@emptyvalues
    \def\pgffor@values{\pgffor@stop,}%
  \fi%
  \let\pgffor@body\@empty%
  \global\pgffor@continuetrue%
  \pgffor@collectbody}

% \def\drawChildren#1#2{%
%   child foreach \csname#1\endcsname in {\csname#2\endcsname} {node {\csname#1\endcsname}%
%       \drawChildren{#1l}{#2@\csname#1\endcsname}}%
% }
\newcommand{\buildTree}{%
  \ifx\pgfextra@keys\relax%
    \begin{tikzpicture}
      \pgfkeys{/buildTree/current x/.initial=0}
      \pgfkeys{/buildTree/current y/.initial=0}
      \@for\@unevar:=\pgfextra@keys\do{%
        \draw (\pgfkeys{/buildTree/current x},\pgfkeys{/buildTree/current y}) node (\@unevar) {\@unevar}; %
      }
    \end{tikzpicture} 
  \else%
  \fi%
}

% \newcommand{\buildTree}{%
%   \ifcsname pgfextra@keys\endcsname%
%     \begin{tikzpicture}[
%       level distance=20mm,
% %      every node/.style={right},
%       level 1/.style={sibling distance=20mm}, 
%       level 2/.style={sibling distance=10mm}, 
%       level 3/.style={sibling distance=5mm}]
%       \node {/} [grow=right] child [red] foreach \name in {\pgfextra@keys} {%\drawChildren{\name}{\pgfextra@keys}
%         node {\name} child[blue] foreach \namebis in {\expandafter\csname\expandafter pgfextra@keys@\name\endcsname} {node{\namebis}}%
%       } ;
%     \end{tikzpicture} 
%   \else%
%   \fi%
% }

\makeatother

\begin{document}

\newoutputstream{keys} 
\openoutputfile{\jobname.keys}{keys}



% \pgfextraSplitPath{/chemin1/chemin2/chemin3}
% \pgfextraSplitPath{/chemin 1/chemin 2/chemin 3}
% \pgfextraSplitPath{/chemin 1/chemin 2/.@chemin 3}


% \pgfextraRegisterPath{/chemin1/chemin2/chemin3}

% \pgfextraRegisterPath{/chemin1/chemin2/toto}
% \pgfextraRegisterPath{/chemin1/chemin2/titi}
% \pgfextraRegisterPath{/fd}
% \pgfextraRegisterPath{/chemin1/chemin2}
%\drawChildren{name}{pgfextra@keys}


%\tracingmacros=1
% \tracingassigns=1%
%\buildTree
% \tracingassigns=0%
%\tracingmacros=0

%current name:\pgfkeyscurrentname

%current path:\pgfkeyscurrentpath

\section{Reinit test}

\pgfextraNewCounter{aCounter}{0}
\newcommand{\fortest}[1]{#1 is \pgfkeys{/fd/#1}}
\newcommand{\myinitfun}[1]{\countinitfun{aCounter}{#1}}
\newcommand{\myotherinitfun}[1]{\def#1{112}}

\pgfqkeys{/fd/tututu}{.initfun=\myinitfun}
\pgfqkeys{/fd/tititi}{.initval=112}

after init \fortest{tututu} and \fortest{tititi}

\pgfkeys{/fd/tututu=tutu,/fd/tititi=titi}
after \verb+\pgfkeys{/fd/tututu=tutu,/fd/tititi=titi}+, \fortest{tututu} and \fortest{tititi}.

\pgfkeys{/fd/tututu/.reinit} 
after \verb+\pgfkeys{/fd/tututu/.reinit}+, \fortest{tututu} and \fortest{tititi}.

again, \fortest{tututu} and \fortest{tititi}.

again, \fortest{tututu} and \fortest{tititi}.

\pgfkeys{/fd/tititi/.@init} 

\tracingmacros=1
\tracingassigns=1%
\pgfkeys{/fd/tititi/.reinit} 
\tracingmacros=0
\tracingassigns=0%
after \verb+\pgfkeys{/fd/tititi/.reinit}+, \fortest{tututu} and \fortest{tititi}.

\pgfkeys{/fd/tututu/.reinit} 
after \verb+\pgfkeys{/fd/tututu/.reinit}+, \fortest{tututu} and \fortest{tititi}.

\pgfkeys{/fd/tututu/.reinit} 
after \verb+\pgfkeys{/fd/tututu/.reinit}+, \fortest{tututu} and \fortest{tititi}.


%must raise error no init function
%\pgfkeys{/fd/tututa/.reinit} 

\pgfkeys{/fd/tututu=tutu,/fd/tititi=titi}
after \verb+\pgfkeys{/fd/tututu=tutu,/fd/tititi=titi}+, \fortest{tututu} and \fortest{tititi}.


\reinit{/fd}{tututu,tititi} after the for, \fortest{tututu} and \fortest{tititi}.

{
\pgfkeys{/fd/tututu=test,/fd/tititi=1024}
after in the group, \fortest{tututu} and \fortest{tititi}.
}

after ouside the group, \fortest{tututu} and \fortest{tititi}.


\expandafter\def\expandafter\name\expandafter{\csname mon nom\endcsname}
%\show\name
\expandafter\def\name{3}
\csname mon nom\endcsname

\def\temp{1}
before \temp

\pgfkeys{/fd/testglob/.initial=1024}
before \pgfkeys{/fd/testglob}

{
  \def\temp{2}
  in the group \temp

  \pgfkeys{/fd/testglob=toto}
  in the group \pgfkeys{/fd/testglob}

  \makeGlobal{\temp}

  \makeKeyGlobal{/fd/testglob}
%  \makeGlobal{/fd/testglob}
%   \let\forglobal\temp
%   \expandafter\gdef\expandafter\temp\expandafter{\forglobal}
}

after \temp

after \pgfkeys{/fd/testglob}

List of defined keys: \debug{\keyList}


\closeoutputstream{keys} 
% font with init
% \pgfkeys{/fd/tututu/.code=tututu avec #1.}
% \pgfkeys{/fd/tututu}
% \pgfkeys{/fd/tututu=18}
% \pgfqkeys{/fd/test/font}{.init=\pgfkeysnovalue}
% 1:[{\pgfkeys{/fd/test/font}test}]
% \pgfkeys{/fd/test/font/.add={}{\itshape}}
% 2:[{\pgfkeys{/fd/test/font}test}]
% \pgfkeys{/fd/test/font/.add={\bfseries}{}}
% 3:[{\pgfkeys{/fd/test/font}test}]
% \pgfkeys{/fd/test/font/.reinit}
% after:[{\pgfkeys{/fd/test/font}test}]
%\pgfkeys{/fd/test/font/.reinit=12}


% \countinitfun{aCounter}{\myvalI}
% => (\myvalI).
% \countinitfun{aCounter}{\myvalII}
% => (\myvalI,\myvalII).
% \countinitfun{aCounter}{\myvalIII}

% enfin (\myvalI,\myvalII,\myvalIII).

% \section{pgfkeys de base}
% \subsection{Basic add}
% \pgfqkeys{/stereotype}{.initial=\pgfkeysnovalue}
% 1:[\pgfkeys{/stereotype]

% \pgfkeys{/stereotype=toto}
% 2:[\pgfkeys{/stereotype}]

% \pgfkeys{/stereotype/.add={tutu\\}{\\titi}}
% 3:[\pgfkeys{/stereotype}]

% \subsection{Basic add if empty}
% \pgfqkeys{/fd/stereotype}{.initial=\pgfkeysnovalue}
% 1:[\pgfkeys{/fd/stereotype]

% \pgfkeys{/fd/stereotype/.add if non empty={tutu->}{->titi}}
% 2:[\pgfkeys{/fd/stereotype}]

% \pgfkeys{/fd/stereotype/.add before if empty={empty}{non empty ->}}
% 2bis:[\pgfkeys{/fd/stereotype}]

% \pgfkeys{/fd/stereotype=toto}
% 3:[\pgfkeys{/fd/stereotype}]

% \pgfkeys{/fd/stereotype/.add before if empty={empty}{non empty ->}}
% 3bis:[\pgfkeys{/fd/stereotype}]

% \pgfkeys{/fd/test/.initial=contenu de test}
% \pgfqkeys{/fd}{test=modif,test/.get=\testVal,stereotype/.add if non empty={tutu->}{\testVal}}
% 4:[\pgfkeys{/fd/stereotype}]

% \pgfqkeys{/fd}{test=modif 2,stereotype/.add if non empty={tutu->}{->\pgfkeysvalueof{/fd/test}}}
% 5:[\pgfkeys{/fd/stereotype}]

% \subsection{Basic font}
% \pgfqkeys{/fd/font}{.initial=\pgfkeysnovalue}
% 1:[{\pgfkeys{/fd/font}test}]

% \pgfkeys{/fd/font/.add={}{\itshape}}
% 2:[{\pgfkeys{/fd/font}test}]

% \pgfkeys{/fd/font/.add={\bfseries}{}}
% 3:[{\pgfkeys{/fd/font}test}]

% \section{counter testing}

% \pgfextraNewCounter{yeti}{0}
% \pgfextraNewCounter{yeto}{100}

% \pgfextraGetCounter{yeti},
% \pgfextraGetCounter{yeto},
% \pgfextraGetCounter{yeti}

% \pgfextraIncrCounter{yeto}\pgfextraIncrCounter{yeti}\pgfextraIncrCounter{yeti}\pgfextraIncrCounter{yeti}

% \pgfextraGetCounter{yeti},
% \pgfextraGetCounter{yeto},
% \pgfextraGetCounter{yeti}

% \pgfextraIncrCounter{yeti}\pgfextraIncrCounter{yeto}\pgfextraIncrCounter{yeti}\pgfextraIncrCounter{yeto}

% \pgfextraGetCounter{yeti},
% \pgfextraGetCounter{yeto},
% \pgfextraGetCounter{yeti}


% \section{Fonts}
% \texttt{Normal and \textbf{bold Type-Writer} and \textit{italic} and \textbf{\textit{bold italic}}}

% \section{Tikz}
% \newcommand*{\myline}{|-}
% \begin{tikzpicture}
%   \draw (0,0) node (n1) {n1};
%   \draw (2,2) node (n2) {n2};
%   \draw (n1) \myline (n2);
%   \renewcommand*{\myline}{-|}
%   \draw (n1) \myline (n2);
% \end{tikzpicture}

% \newcommand*{\mydraw}[3]{
%   \draw (#1) #2 (#3);
% }
% \section{suite}
% \begin{tikzpicture}
%   \draw (0,0) node (n1) {n1};
%   \draw (2,2) node (n2) {n2};
%   \mydraw{n1}{|-}{n2}
%   \GetCoordinate{[xshift=1cm]n1.north}
%   \draw (\xtemp,\ytemp) node {[]};
% \end{tikzpicture}




\end{document}
  

% LocalWords:  subpath pathtoks
