|
Posted by Curtis on 10/13/67 11:34
ZeldorBlat <zeldorblat@gmail.com> wrote in message
news:1134490664.637820.269200@g49g2000cwa.googlegroups.com..
..
>
> Curtis wrote:
> > Any suggestions for a recursive algorithm that reads
text
> > file A line by line until it encounters a line directing
to
> > it read in a similar manner file B which might have
command
> > lines for reading files C and D, and so forth.
> >
> > It might look like so:
> >
> > A
> > A
> > A
> > A
> > A
> > READ B
> > B
> > B
> > READ C
> > C
> > C
> > B
> > B
> > A
> > A etc.
> >
> > The objective is to have one large array or string of
text
> > with the referenced files as includes. I think I can
manage
> > the recursive file opens, though I haven't tested code
yet.
> > Questions:
> >
> > Any limit to number of files? (Is file() the best
function
> > for this?)
> >
> > Best way to prevent circular references? (Place each
> > filename in an array with its calling file as a key
and...?)
> >
> > Guidance appreciated.
> If you just want to include files, why go through all that
trouble?
> Just use include_once() instead of include(), then nest
things
> appropriately. For example:
>
> In A.php, include_once("B.php");
> In B.php, include_once("C.php");
>
> Then, just include_once("A.php") and he will include B,
which will in
> turn include C. Using include_once() solves your circular
problem,
> since no file will ever be included more than once.
>
> Of course I could be totally misunderstanding your
problem, also.
I'll try to clarify, ZB.
We're completing a markup language similar to Textile, to be
used for forums and personal messaging like BBCode, and
more.
One feature we're including is the ability for advanced
users to issue a command to include other files, not unlike
the PHP include functions.
While we're writing the program IN PHP, it is *not* PHP. In
short, we have to parse file A to find directives to include
file B and C. And so on. That part is very easy.
What is more difficult is to preclude circular reference.
While it is unlikely to happen often, we would not consider
the application well-designed if it did not handle such
occurances gracefully and informatively.
Short circles like A calls B which calls A are trivial. The
problem becomes more difficult when A --> B --> C --> D -->
E --> B
The only way I can presently see to solve the problem is
with linked lists, and backwalk the link paths when, say, E
calls B. But I've never worked on this issue before, so
maybe there's a simpler algorithm that hasn't occurred to
me?
--
Curtis
Visit We the Thinking
www.wethethinking.com
An online magazine/forum
devoted to philosophical
thought.
>
[Back to original message]
|