src/lib/tree.c
TREE_NODE *insert_tree_node(char *path, char *fname, int type,
                            TREE_ROOT *root, TREE_NODE *parent)
{
   char *p, *q;
   int path_len = strlen(path);
   TREE_NODE *node;

   Dmsg1(100, "insert_tree_node: %s\n", path);
   /*
    * If trailing slash on path, strip it
    */
   if (path_len > 0) {
      q = path + path_len - 1;
      if (IsPathSeparator(*q)) {
         *q = 0;                      /* strip trailing slash */
      } else {
         q = NULL;                    /* no trailing slash */
      }
   } else {
      q = NULL;                       /* no trailing slash */
   }
   /* If no filename, strip last component of path as "filename" */
   if (*fname == 0) {
      p = (char *)last_path_separator(path);  /* separate path and filename */
      if (p) {
         fname = p + 1;               /* set new filename */
         *p = '\0';                   /* terminate new path */
      }
   } else {
      p = NULL;
   }
   if (*fname) {
      if (!parent) {                  /* if no parent, we need to make one */
         Dmsg1(100, "make_tree_path for %s\n", path);
         path_len = strlen(path);     /* get new length */
         if (path_len == root->cached_path_len &&
             strcmp(path, root->cached_path) == 0) {
            parent = root->cached_parent;
         } else {
            root->cached_path_len = path_len;
            pm_strcpy(&root->cached_path, path);
            parent = make_tree_path(path, root);
            root->cached_parent = parent;
         }
         Dmsg1(100, "parent=%s\n", parent->fname);
      }
   } else {
      fname = path;
      if (!parent) {
         parent = (TREE_NODE *)root;
         type = TN_DIR_NLS;
      }
      Dmsg1(100, "No / found: %s\n", path);
   }

   node = search_and_insert_tree_node(fname, 0, root, parent);
   if (q) {                           /* if trailing slash on entry */
      *q = '/';                       /*  restore it */
   }
   if (p) {                           /* if slash in path trashed */
      *p = '/';                       /* restore full path */
   }
   return node;
}
/*
 * Insert a node in the tree. This is the main subroutine
 *   called when building a tree.
 *
 */
Insert a node in the tree. This is the main subroutine
called when building a tree.
Insert a node in the tree . This is the main subroutine called when building a tree .
TREE_NODE *insert_tree_node(char *path, char *fname, int type,
                            TREE_ROOT *root, TREE_NODE *parent)
{
   char *p, *q;
   int path_len = strlen(path);
   TREE_NODE *node;
   Dmsg1(100, "insert_tree_node: %s\n", path);
   if (path_len > 0) {
      q = path + path_len - 1;
      if (IsPathSeparator(*q)) {
         *q = 0;                      
      } else {
         q = NULL;                    
      }
   } else {
      q = NULL;                       
   }
   if (*fname == 0) {
      p = (char *)last_path_separator(path);  
      if (p) {
         fname = p + 1;               
         *p = '\0';                   
      }
   } else {
      p = NULL;
   }
   if (*fname) {
      if (!parent) {                  
         Dmsg1(100, "make_tree_path for %s\n", path);
         path_len = strlen(path);     
         if (path_len == root->cached_path_len &&
             strcmp(path, root->cached_path) == 0) {
            parent = root->cached_parent;
         } else {
            root->cached_path_len = path_len;
            pm_strcpy(&root->cached_path, path);
            parent = make_tree_path(path, root);
            root->cached_parent = parent;
         }
         Dmsg1(100, "parent=%s\n", parent->fname);
      }
   } else {
      fname = path;
      if (!parent) {
         parent = (TREE_NODE *)root;
         type = TN_DIR_NLS;
      }
      Dmsg1(100, "No / found: %s\n", path);
   }
   node = search_and_insert_tree_node(fname, 0, root, parent);
   if (q) {                           
      *q = '/';                       
   }
   if (p) {                           
      *p = '/';                       
   }
   return node;
}
TREE_NODE * insert_tree_node ( char * path , char * fname , int type , TREE_ROOT * root , TREE_NODE * parent ) { char * p , * q ; int path_len = strlen ( path ) ; TREE_NODE * node ; Dmsg1 ( 100 , " \n " , path ) ; if ( path_len > 0 ) { q = path + path_len - 1 ; if ( IsPathSeparator ( * q ) ) { * q = 0 ; } else { q = NULL ; } } else { q = NULL ; } if ( * fname == 0 ) { p = ( char * ) last_path_separator ( path ) ; if ( p ) { fname = p + 1 ; * p = ' \0 ' ; } } else { p = NULL ; } if ( * fname ) { if ( ! parent ) { Dmsg1 ( 100 , " \n " , path ) ; path_len = strlen ( path ) ; if ( path_len == root -> cached_path_len && strcmp ( path , root -> cached_path ) == 0 ) { parent = root -> cached_parent ; } else { root -> cached_path_len = path_len ; pm_strcpy ( & root -> cached_path , path ) ; parent = make_tree_path ( path , root ) ; root -> cached_parent = parent ; } Dmsg1 ( 100 , " \n " , parent -> fname ) ; } } else { fname = path ; if ( ! parent ) { parent = ( TREE_NODE * ) root ; type = TN_DIR_NLS ; } Dmsg1 ( 100 , " \n " , path ) ; } node = search_and_insert_tree_node ( fname , 0 , root , parent ) ; if ( q ) { * q = ' ' ; } if ( p ) { * p = ' ' ; } return node ; }
Insert a node in the tree.
Insert a node in the tree .
/*
    * If trailing slash on path, strip it
    */ /* strip trailing slash */ /* no trailing slash */ /* no trailing slash */ /* If no filename, strip last component of path as "filename" */ /* separate path and filename */ /* set new filename */ /* terminate new path */ /* if no parent, we need to make one */ /* get new length */ /* if trailing slash on entry */ /*  restore it */ /* if slash in path trashed */ /* restore full path */