Only an answer based on percusse's fine solution but with some modifications for the styles. I try to get a lighter code. I added a scope
to use options for the labels. I removed pos=.5
because it's the value by default. I remove the style myline
and I placed the options in the scope. I used the possibility to draw several edges from the same vertex with one path.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[ %some style declarations
mynode/.style = {draw,inner sep=2mm},
scale=1.5]
% Placing the nodes: you have to place them, no way to know beforehand
\node[fill=red,
mynode] (n0) at (0,0) {faultstate};
\node[mynode] (n1) at (1,2) {vm\_map};
\node[mynode] (n2) at (1,5) {vm\_map\_entry};
\node[mynode] (n3) at (3.5,2) {vm\_object};
\node[mynode] (n4) at (5,0) {vm\_map\_object};
%Now the edges and labels
\begin{scope}[> = stealth, ->,blue,thick,
every node/.style = {black,right,align=center}]
\draw (n1) edge node {root\\header} (n2);
\draw (n0) edge [bend left] node {entry} (n2)
edge [bend left] node {map} (n1)
edge [bend right] node [pos=0.8,
below right] {first\_object \\object} (n3);
\draw (n4) edge [bend left] node [pos=0.8] {sub\_map} (n1)
edge [bend right] node {vm\_object} (n3);
\draw (n3) edge [loop right] node {backing\_object} (n3);
\draw (n2) edge [loop right,
min distance =1 cm,
out=10,
in=-10] node {prev\\next\\right\\left} (n2)
edge [looseness=1.8,
out=30,
in=20] node [below left] {object} (n4) ;
\end{scope}
\end{tikzpicture}
\end{document}
It's not really difficult with expl3
. I define a command \ReadFile
that takes two arguments
\ReadFile{\myarray}{somefile.dat}
The first argument is a control sequence name, the second is the file to read from. With this, the file will be read in and the command \myarray
defined so that
\myarray{2}
yields the second item; the special call \myarray{*}
will return the number of items. You can also call \myarray{-1}
to access the last item.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\ior_new:N \g_hringriin_file_stream
\NewDocumentCommand{\ReadFile}{mm}
{
\hringriin_read_file:nn { #1 } { #2 }
\cs_new:Npn #1 ##1
{
\str_if_eq:nnTF { ##1 } { * }
{ \seq_count:c { g_hringriin_file_ \cs_to_str:N #1 _seq } }
{ \seq_item:cn { g_hringriin_file_ \cs_to_str:N #1 _seq } { ##1 } }
}
}
\cs_new_protected:Nn \hringriin_read_file:nn
{
\ior_open:Nn \g_hringriin_file_stream { #2 }
\seq_gclear_new:c { g_hringriin_file_ \cs_to_str:N #1 _seq }
\ior_map_inline:Nn \g_hringriin_file_stream
{
\seq_gput_right:cx
{ g_hringriin_file_ \cs_to_str:N #1 _seq }
{ \tl_trim_spaces:n { ##1 } }
}
\ior_close:N \g_hringriin_file_stream
}
\ExplSyntaxOff
\begin{document}
\ReadFile{\myarray}{somearray.dat}
\myarray{*}
\myarray{1}
\myarray{2}
\myarray{3}
\myarray{-1}
\myarray{-2}
\myarray{-3}
\end{document}
If the file somearray.dat
is
And now for something completely different
1 2 3 4 5 6 7 8
a bc def ghij
(I used the same as Christian), the result will be
Best Answer
This should get you started....