DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
A UNIX Path Name Library for C++ - Path(C++)

Implementation

We conclude this tutorial with a note regarding implementation. The function expand_wildcards might have been implemented as follows:

       void Path::expand_wildcards(List<Path> & ret) {
           const char *tmp = tmpnam();
           ostrstream o;
           o << "ls " << *this << " > " << tmp <<ends;
           system(o.str());
           ifstream f(tmp);
           String s;
           ret.make_empty();
           while (f >> s)
               ret.put(s);
       }

First the shell command ls pattern>tmp\fR is sent to the shell to perform the actual pattern expansion, then the file containing the results is read and the resulting list is constructed. This implementation has several problems:

To overcome these problems, the actual implementation of expand_wildcards steals code from the Korn shell. The resulting implementation is fast, reliable, and (of course) Korn shell-based.

Acknowledgement Special thanks to Dave Korn for his patient explanations of the inner workings of the Korn shell.


Previous topic: Wildcards

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005