/[m4]/m4/m4/path.c
ViewVC logotype

Diff of /m4/m4/path.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by gary, Fri Jun 20 15:43:20 2003 UTC revision 1.5 by gary, Tue Jul 29 15:57:34 2003 UTC
# Line 39  Line 39 
39  #include "m4module.h"  #include "m4module.h"
40  #include "m4private.h"  #include "m4private.h"
41    
42  static struct m4_search_path_info dirpath; /* the list of path directories */  static void search_path_add (m4__search_path_info *, const char *);
43    static void search_path_env_init (m4__search_path_info *, char *, boolean);
44    
45    
46  /*  /*
47   * General functions for search paths   * General functions for search paths
48   */   */
49    
50  struct m4_search_path_info *  static void
51  m4_search_path_info_new (void)  search_path_add (m4__search_path_info *info, const char *dir)
 {  
   struct m4_search_path_info *info;  
   
   info = (struct m4_search_path_info *)  
     xmalloc (sizeof (struct m4_search_path_info));  
   info->list = NULL;  
   info->list_end = NULL;  
   info->max_length = 0;  
   
   return info;  
 }  
   
 void  
 m4_search_path_add (struct m4_search_path_info *info, const char *dir)  
52  {  {
53    m4_search_path *path;    m4__search_path *path;
54    
55    if (*dir == '\0')    if (*dir == '\0')
56      dir = ".";      dir = ".";
57    
58    path = (struct m4_search_path *) xmalloc (sizeof (struct m4_search_path));    path = XMALLOC (m4__search_path, 1);
59    path->next = NULL;    path->next = NULL;
60    path->len = strlen (dir);    path->len = strlen (dir);
61    path->dir = xstrdup (dir);    path->dir = xstrdup (dir);
# Line 83  m4_search_path_add (struct m4_search_pat Line 70  m4_search_path_add (struct m4_search_pat
70    info->list_end = path;    info->list_end = path;
71  }  }
72    
73  void  static void
74  m4_search_path_env_init (struct m4_search_path_info *info, char *path,  search_path_env_init (m4__search_path_info *info, char *path, boolean isabs)
                          boolean isabs)  
75  {  {
76    char *path_end;    char *path_end;
77    
# Line 98  m4_search_path_env_init (struct m4_searc Line 84  m4_search_path_env_init (struct m4_searc
84        if (path_end)        if (path_end)
85          *path_end = '\0';          *path_end = '\0';
86        if (!isabs || *path == '/')        if (!isabs || *path == '/')
87          m4_search_path_add (info, path);          search_path_add (info, path);
88        path = path_end + 1;        path = path_end + 1;
89      }      }
90    while (path_end);    while (path_end);
91  }  }
92    
93    
 void  
 m4_include_init (void)  
 {  
   dirpath.list = NULL;  
   dirpath.list_end = NULL;  
   dirpath.max_length = 0;  
 }  
   
   
94  /* Functions for normal input path search */  /* Functions for normal input path search */
95    
96  void  void
# Line 122  m4_include_env_init (m4 *context) Line 99  m4_include_env_init (m4 *context)
99    if (m4_get_no_gnu_extensions_opt (context))    if (m4_get_no_gnu_extensions_opt (context))
100      return;      return;
101    
102    m4_search_path_env_init (&dirpath, getenv ("M4PATH"), FALSE);    search_path_env_init (m4__get_search_path (context),
103                            getenv ("M4PATH"), FALSE);
104  }  }
105    
106  void  void
# Line 131  m4_add_include_directory (m4 *context, c Line 109  m4_add_include_directory (m4 *context, c
109    if (m4_get_no_gnu_extensions_opt (context))    if (m4_get_no_gnu_extensions_opt (context))
110      return;      return;
111    
112    m4_search_path_add (&dirpath, dir);    search_path_add (m4__get_search_path (context), dir);
113    
114  #ifdef DEBUG_INCL  #ifdef DEBUG_INCL
115    fprintf (stderr, "add_include_directory (%s);\n", dir);    fprintf (stderr, "add_include_directory (%s);\n", dir);
# Line 142  FILE * Line 120  FILE *
120  m4_path_search (m4 *context, const char *dir, char **expanded_name)  m4_path_search (m4 *context, const char *dir, char **expanded_name)
121  {  {
122    FILE *fp;    FILE *fp;
123    struct m4_search_path *incl;    m4__search_path *incl;
124    char *name;                   /* buffer for constructed name */    char *name;                   /* buffer for constructed name */
125    
126    /* Look in current working directory first.  */    /* Look in current working directory first.  */
# Line 158  m4_path_search (m4 *context, const char Line 136  m4_path_search (m4 *context, const char
136    if (*dir == '/' || m4_get_no_gnu_extensions_opt (context))    if (*dir == '/' || m4_get_no_gnu_extensions_opt (context))
137      return NULL;      return NULL;
138    
139    name = (char *) xmalloc (dirpath.max_length + 1 + strlen (dir) + 1);    name = (char *) xmalloc (m4__get_search_path (context)->max_length + 1 + strlen (dir) + 1);
140    
141    for (incl = dirpath.list; incl != NULL; incl = incl->next)    for (incl = m4__get_search_path (context)->list; incl != NULL; incl = incl->next)
142      {      {
143        strncpy (name, incl->dir, incl->len);        strncpy (name, incl->dir, incl->len);
144        name[incl->len] = '/';        name[incl->len] = '/';
# Line 193  m4_path_search (m4 *context, const char Line 171  m4_path_search (m4 *context, const char
171  static void  static void
172  include_dump (void)  include_dump (void)
173  {  {
174    struct m4_search_path *incl;    m4__search_path *incl;
175    
176    fprintf (stderr, "include_dump:\n");    fprintf (stderr, "include_dump:\n");
177    for (incl = dirpath.list; incl != NULL; incl = incl->next)    for (incl = m4__get_search_path (context)->list; incl != NULL; incl = incl->next)
178      fprintf (stderr, "\t%s\n", incl->dir);      fprintf (stderr, "\t%s\n", incl->dir);
179  }  }
180    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26