#ifndef PATHSTUFF_H
#define PATHSTUFF_H

#include <string>
#include <vector>
using namespace std;

#include <rpn.h>



/* Process path queries. */
class pathstuff
{
public:

  static string const root;
  static string const fwdsep;
  static string const parent;

  /* Convert a path between string and a vector of strings. */
  void convert(string& s, vector<string> const & path) const;
  void convert(vector<string>& v, string const & path) const;
  /* Convert a path between program and a vector of strings. */
  void convert(rpnprogram& p, vector<string> const & path) const;
  void convert(vector<string>& path, rpnprogram const & p) const;

  /* Does the path contain the targ string? */
  void contains(bool& res, vector<string> const & path, string const & targ);

  /* Search for a program relative to the current directory. */
  void findrelativetree
  (
    bool& found,
    rpnprogram*& prog,
    rpnprogram* const current,
    vector<string> const & pathtree
  );

  /* Search for a program relative to the current directory. 
   * The programs path - that is each of its parents in in an ordered list.
   * This is used for scoping in cd, where each program is pushed onto the stack. */
  void findrelativetree
  (
    bool& found,
    deque<rpnprogram*>& programlist,
    rpnprogram* const current,
    vector<string> const & pathtree
  );


  /* String maipulation: .. resolved, ~/.. is illegal. */
  void resolveparent
  ( 
    bool& valid, 
    vector<string>& path, 
    vector<string> const & path0
  );

  /* Current directory. */
  void pwd(vector<string>& v);

  /* Searches for the program described by the path. */
  void findpath
  (
    bool& found,
    rpnprogram*& prog,
    vector<string> const & path
  );

  void findpath
  (
    bool& found,
    deque<rpnprogram*>& programlist,
    vector<string> const & path
  );

  /* Gets the absolute path. eg .. realized and path from ~ . */
  void absolute
  (
    bool& found,
    vector<string>& pathfromhome,
    vector<string> const & path
  );

  /* No root or parent nodes. */
  bool const ispurerelative( vector<string> const & path );

};





#endif



