This is somewhat similar to Reading the contents of a box, but with a specifically plain Latex example; I somewhat solved the question while writing the post, so I'll formulate the question like this: is the below all there is to it?
Basically, I have a situation, where I'd like to concatenate/append input text as box material; the below MWE demonstrates this concatenation "manually":
\documentclass{article}
\loggingoutput\scrollmode
\tracingonline=1 % shows just \box42=[] in terminal, unless \loggingoutput\scrollmode above is enabled!
% https://tex.stackexchange.com/questions/46480/setbox-vs-sbox-and-savebox-what-are-the-differences-i-need-to-know-about
\newsavebox{\mainbox}
\newsavebox{\firstchildbox}
\newsavebox{\secondchildbox}
\begin{document}
\savebox\mainbox{inner2 inner1 main}
\typeout{Mainbox with inline contents:}
\showbox\mainbox
% "Manual" concatenation/appending of box material
\setbox\secondchildbox\hbox{inner2}
% \box will clear the box register (\usebox or \copy will not erase it)
\savebox\firstchildbox{\box\secondchildbox inner1}
\setbox\mainbox\hbox{\usebox\firstchildbox main}
\typeout{Mainbox with nested contents:}
\showbox\mainbox
% unhbox via https://tex.stackexchange.com/questions/6183/reading-the-contents-of-a-box
\setbox\secondchildbox\hbox{inner2}
% \box will clear the box register (\usebox or \copy will not erase it)
\savebox\firstchildbox{\unhbox\secondchildbox\space inner1}
\setbox\mainbox\hbox{\unhbox\firstchildbox\space main}
\typeout{Mainbox with unnested contents:}
\showbox\mainbox
\end{document}
The MWE does not produce PDF output, all output is to the terminal/logfile. Basically, if I put a text like "inner2 inner1 main" directly into a \hbox inline, the box looks like this in the terminal output:
Mainbox with inline contents:
> \box26=
\hbox(6.67859+0.0)x82.83351
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 e
.\OT1/cmr/m/n/10 r
.\OT1/cmr/m/n/10 2
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 e
.\OT1/cmr/m/n/10 r
.\OT1/cmr/m/n/10 1
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 m
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
If I do the "manual" concatenation/appending, then I have:
Mainbox with nested contents:
> \box26=
\hbox(6.67859+0.0)x76.16685
.\hbox(6.67859+0.0)x54.50012
..\hbox(6.67859+0.0)x27.25006
...\OT1/cmr/m/n/10 i
...\OT1/cmr/m/n/10 n
...\OT1/cmr/m/n/10 n
...\OT1/cmr/m/n/10 e
...\OT1/cmr/m/n/10 r
...\OT1/cmr/m/n/10 2
..\OT1/cmr/m/n/10 i
..\OT1/cmr/m/n/10 n
..\OT1/cmr/m/n/10 n
..\OT1/cmr/m/n/10 e
..\OT1/cmr/m/n/10 r
..\OT1/cmr/m/n/10 1
.\OT1/cmr/m/n/10 m
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
So, the "concatenation" resulted with a nested hierarchy of boxes, with a parent/child relationship.
My original question was, how could I flatten the hierarchy and obtain spaces like in the "inline" version; then I saw Reading the contents of a box, and realized I could use \unhbox to "unpack" and thereby use the "first child" contents (immediate contents) of a given box; and adding \space ensures the same \glues are present in the box contents as in the "inline" case:
Mainbox with unnested contents:
> \box26=
\hbox(6.67859+0.0)x82.83351
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 e
.\OT1/cmr/m/n/10 r
.\OT1/cmr/m/n/10 2
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 n
.\OT1/cmr/m/n/10 e
.\OT1/cmr/m/n/10 r
.\OT1/cmr/m/n/10 1
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 m
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 i
.\OT1/cmr/m/n/10 n
This looks good enough to me - but is this all that there is to it?