Exemplo n.º 1
0
static int
change_ext(wchar_t *dest, const wchar_t *src, const wchar_t *ext)
{
    size_t src_len = wcsnlen_s(src, MAXPATHLEN+1);
    size_t i = src_len;
    if (i >= MAXPATHLEN+1)
        Py_FatalError("buffer overflow in getpathp.c's reduce()");

    while (i > 0 && src[i] != '.' && !is_sep(src[i]))
        --i;

    if (i == 0) {
        dest[0] = '\0';
        return -1;
    }

    if (is_sep(src[i]))
        i = src_len;

    if (wcsncpy_s(dest, MAXPATHLEN+1, src, i) ||
        wcscat_s(dest, MAXPATHLEN+1, ext)) {
        dest[0] = '\0';
        return -1;
    }

    return 0;
}
Exemplo n.º 2
0
static	int	stock_words(const char *str, const char *sep, char **tab)
{
  int		i;
  int		j;
  int		nb;

  nb = 0;
  i = 0;
  while (str[i])
    {
      while (str[i] && is_sep(sep, str[i]))
	i++;
      if (str[i] && !is_sep(sep, str[i]))
	{
	  j = 0;
	  while (str[i] && !is_sep(sep, str[i]))
	    {
	      j++;
	      i++;
	    }
	  if ((tab[nb] = malloc(sizeof(char) * (j + 1))) == NULL)
	    return (FAILURE);
	  strncpy(tab[nb++], &str[i - j], j);
	}
    }
  tab[nb] = NULL;
  return (SUCCESS);
}
Exemplo n.º 3
0
static bool rename(QCString & s, bool java, bool javasettings)
{
  static const struct {
    const char * o;
    const char * n;
    bool java_only;
  } T[] = {
    { "enumDecl", "enumPatternDecl", FALSE },
    { "set_EnumDecl", "set_EnumPatternDecl", FALSE },
    { "enumItemDecl", "enumPatternItemDecl", FALSE },
    { "set_EnumItemDecl", "set_EnumPatternItemDecl", FALSE },
    { "enumItemCase", "enumPatternItemCase", FALSE },
    { "set_EnumItemCase", "set_EnumPatternItemCase", FALSE },
    
    { "setJavaEnumDeclCmd", "setJavaEnumPatternDeclCmd", FALSE },
    { "setJavaEnumItemDeclCmd", "setJavaEnumPatternItemDeclCmd", FALSE },
    { "setJavaEnumItemCaseCmd", "setJavaEnumPatternItemCaseCmd", FALSE },
    
    { "_setJavaEnumDeclCmd", "_setJavaEnumPatternDeclCmd", TRUE },
    { "_setJavaEnumItemDeclCmd", "_setJavaEnumPatternItemDeclCmd", TRUE },
    { "_setJavaEnumItemCaseCmd", "_setJavaEnumPatternItemCaseCmd", TRUE },
    
    { "_enum_decl", "_enum_pattern_decl", FALSE },
    { "_enum_item_decl", "_enum_pattern_item_decl", FALSE },
    { "_enum_item_case", "_enum_pattern_item_case", FALSE }
  };
  int t_index;
  bool changed = FALSE;
  
  for (t_index = 0; t_index != sizeof(T)/sizeof(T[0]); t_index += 1) {
    if (!T[t_index].java_only || java) {
      QCString o = T[t_index].o;
      
      if (!javasettings)
	o = ((java) ? "JavaSettings." : "JavaSettings::") + o;
      
      int o_len = o.length();
      QCString n = T[t_index].n;
      
      if (!javasettings)
	n = ((java) ? "JavaSettings." : "JavaSettings::") + n;
      
      int n_len = n.length();
      int index = 0;
      
      while ((index = s.find(o, index)) != -1) {
	if (((index == 0) || is_sep(s[index - 1])) &&
	    is_sep(s[index + o_len])) {
	  s.replace(index, o_len, n);
	  index += n_len;
	  changed = TRUE;
	}
	else
	  index += 1;
      }
    }
  }

  return changed;
}
Exemplo n.º 4
0
/** Add a path component, by appending stuff to buffer.
    buffer must have at least MAXPATHLEN + 1 bytes allocated, and contain a
    NUL-terminated string with no more than MAXPATHLEN characters (not counting
    the trailing NUL).  It's a fatal error if it contains a string longer than
    that (callers must be careful!).  If these requirements are met, it's
    guaranteed that buffer will still be a NUL-terminated string with no more
    than MAXPATHLEN characters at exit.  If stuff is too long, only as much of
    stuff as fits will be appended.

    @param[in,out]    buffer    The path to be extended.
    @param[in]        stuff     The stuff to join onto the path.
*/
static void
joinpath(char *buffer, char *stuff)
{
  size_t n, k;

  k = 0;
  if (is_absolute(stuff) == 1) {
    n = 0;
  }
  else {
    n = strlen(buffer);
    if(n == 0) {
      strncpy(buffer, volume_name, MAXPATHLEN);
      n = strlen(buffer);
    }
    /* We must not use an else clause here because we want to test n again.
        volume_name may have been empty.
    */
    if (n > 0 && n < MAXPATHLEN) {
      if(!is_sep(buffer[n-1])) {
        buffer[n++] = SEP;
      }
      if(is_sep(stuff[0]))   ++stuff;
    }
  }
  if (n > MAXPATHLEN)
    Py_FatalError("buffer overflow in getpath.c's joinpath()");
  k = strlen(stuff);
  if (n + k > MAXPATHLEN)
    k = MAXPATHLEN - n;
  strncpy(buffer+n, stuff, k);
  buffer[n+k] = '\0';
}
Exemplo n.º 5
0
int	my_count_word(char *str, char *sep)
{
  int	i;
  int	count;

  i = -1;
  count = 0;
  while (str[++i])
    if (is_sep(str[i], sep) == 0 && (i == 0 || is_sep(str[i - 1], sep) == 1))
      count++;
  return (count);
}
Exemplo n.º 6
0
struct node *parse_statements(struct compiler *compiler)
{
    skip_seps(compiler);

    if(is_expression(compiler))
    {
        struct node *result = parse_statement(compiler);

        if (is_sep(compiler))
        {
            skip_seps(compiler);

            if(is_expression(compiler))
            {
                struct node *node = alloc_node(compiler, N_STATEMENTS);

                node->left = result;
                node->right = parse_statements(compiler);

                return node;
            }
        }

        return result;

    }
    else
        return &nil_node;
}
Exemplo n.º 7
0
void	ord_alphlong(t_list *list, char *str)
{
  int	i;
  int	cpos;
  int	ppos;

  cpos = -1;
  i = 0;
  while (i <= 0 || str[i - 1])
    {
      if (is_sep(str[i]))
	{
	  if (cpos >= 0 && i > cpos)
	    {
	      list->data = malloc(i - cpos + 1);
	      my_str_cpy((char *)list->data, str, cpos, i);
	      list = new_list(list);
	    }
	  cpos = - 1;
	}
      else if (cpos == -1)
	cpos = i;
      i = i + 1;
    }
}
Exemplo n.º 8
0
char			*skip_quotes_nb_arg(char *str, size_t *i, t_cmd *cmd)
{
	size_t		start;

	if (!verif_empty_quote(str, i))
	{
		return (NULL);
	}
	start = *i;
	while (str[*i] && !ft_isspace2(str[*i]) && !is_sep(i, str, 0, cmd))
	{
		if (is_redir(i, str, 0, cmd) && ft_isdigit(str[*i]))
		{
			break ;
		}
		if (!is_escaped_char(str, *i) && is_quote_open(str[*i]))
		{
			get_pos_after_quote(i, str);
		}
		(*i)++;
	}
	if (start != *i)
		return ((void*)1);
	return (NULL);
}
Exemplo n.º 9
0
static inline const char* file_name(const char* str)
{
    const char*       p;

    for (p = str + strlen(str) - 1; p >= str && !is_sep(*p); p--);
    return p + 1;
}
Exemplo n.º 10
0
/** Extracts the basename from a full file name.
 * Separators for directories and extensions are OS-specific.
 * @param filename full file name string.
 * @return pointer to basename
 */
char *ccp4_utils_basename(const char *filename)
{
  int i, indx1=-1, length;
  char *basename;

  for ( i = strlen(filename)-1; i >= 0; i-- ) {
    if (is_sep(filename[i])) {
      indx1 = i; 
      break;
    }
  }
  length = strlen(filename) - indx1;
  /* Search for extension separators must be performed backwards
     in case filename has multiple extension separators */
  for ( i = strlen(filename)-1; i >= (indx1 < 0 ? 0 : indx1) ; i-- ) {
    if (filename[i] == EXT_SEPARATOR) {
      length = i - indx1; 
      break;
    }
  }
  basename = ccp4_utils_malloc(length*sizeof(char));
  strncpy(basename,filename+indx1+1,length-1);
  basename[length-1]='\0';
  return basename;
}
Exemplo n.º 11
0
t_lex			*parser(t_lex *lex)
{
	t_lex		*cursor;
	t_detail	*det_error;
	t_lex		*sep_error;

	cursor = lex;
	det_error = NULL;
	sep_error = NULL;
	while (cursor && !det_error)
	{
		if (!is_sep(cursor->str))
		{
			if ((cursor->lst = str_to_lst(cursor->str)) == NULL)
				return (free_all(lex));
			det_error = check_cmd_syntax(cursor->lst);
			if (!det_error && !(det_error = check_redir(cursor->lst)))
				assign_redir(cursor->lst, NULL, &det_error);
		}
		else
			cursor->lst = NULL;
		cursor = cursor->next;
	}
	if (det_error)
		return (free_all(lex));
	sep_error = check_sep_syntax(lex);
	return (sep_error ? free_all(lex) : lex);
}
Exemplo n.º 12
0
static const char* skip_sep(const char str[])
{
    SkASSERT(str);
    while (is_sep(*str))
        str++;
    return str;
}
Exemplo n.º 13
0
/* Raw parsing */
static uint16_t hb_parse_character( hb_csv_file_t * file )
{
    int byte;
    uint16_t c = 0;
    int need_char = 1;

    if( file == NULL )
    {
        return CSV_CHAR_ERROR;
    }

    while( need_char )
    {
        byte = fgetc( file->fileref );
        if( feof( file->fileref ) )
        {
            return CSV_CHAR_EOF;
        }
        if( ferror( file->fileref ) )
        {
            return CSV_CHAR_ERROR;
        }

        if( file->parse_state == CSV_PARSE_SEEK && is_white(byte) )
        {
            continue;
        }
        else if( file->parse_state != CSV_PARSE_ESC && is_esc(byte) )
        {
            file->parse_state = CSV_PARSE_ESC;
            continue;
        }
        else if( file->parse_state != CSV_PARSE_ESC && is_sep(byte) )
        {
            file->parse_state = CSV_PARSE_SEEK;
            need_char = 0;
            c = CSV_CHAR_COLSEP;
        }
        else if( file->parse_state == CSV_PARSE_ESC )
        {
            file->parse_state = CSV_PARSE_NORMAL;
            need_char = 0;
            c = (uint16_t)byte;
        }
        else if( is_newline(byte) )
        {
            file->parse_state = CSV_PARSE_SEEK;
            need_char = 0;
            c = CSV_CHAR_ROWSEP;
        }
        else
        {
            file->parse_state = CSV_PARSE_NORMAL;
            need_char = 0;
            c = (uint16_t)byte;
        }
    }

    return c;
}
Exemplo n.º 14
0
/* assumes 'dir' null terminated in bounds.  Never writes
   beyond existing terminator.
*/
static void
reduce(wchar_t *dir)
{
    size_t i = wcslen(dir);
    while (i > 0 && !is_sep(dir[i]))
        --i;
    dir[i] = '\0';
}
Exemplo n.º 15
0
int		is_sep_space(char c)
{
	if (is_space(c))
		return (1);
	else if (is_sep(c))
		return (1);
	return (0);
}
Exemplo n.º 16
0
/** Reduce a path by its last element.

    The last element (everything to the right of the last separator character)
    in the path, dir, is removed from the path.  Parameter dir is modified in place.

    @param[in,out]    dir   Pointer to the path to modify.
**/
static void
reduce(char *dir)
{
    size_t i = strlen(dir);
    while (i > 0 && !is_sep(dir[i]))
        --i;
    dir[i] = '\0';
}
Exemplo n.º 17
0
/* Add a path component, by appending stuff to buffer.
   buffer must have at least MAXPATHLEN + 1 bytes allocated, and contain a
   NUL-terminated string with no more than MAXPATHLEN characters (not counting
   the trailing NUL).  It's a fatal error if it contains a string longer than
   that (callers must be careful!).  If these requirements are met, it's
   guaranteed that buffer will still be a NUL-terminated string with no more
   than MAXPATHLEN characters at exit.  If stuff is too long, only as much of
   stuff as fits will be appended.
*/
static void
join(char *buffer, char *stuff)
{
    size_t n, k;
    if (is_sep(stuff[0]))
        n = 0;
    else {
        n = strlen(buffer);
        if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
            buffer[n++] = SEP;
    }
    if (n > MAXPATHLEN)
        Py_FatalError("buffer overflow in getpathp.c's joinpath()");
    k = strlen(stuff);
    if (n + k > MAXPATHLEN)
        k = MAXPATHLEN - n;
    strncpy(buffer+n, stuff, k);
    buffer[n+k] = '\0';
}
Exemplo n.º 18
0
int SkParse::Count(const char str[]) 
{
    char c;
    int count = 0;
    goto skipLeading;
    do {
        count++;
        do {
            if ((c = *str++) == '\0')
                goto goHome;
        } while (is_sep(c) == false);
skipLeading:
        do {
            if ((c = *str++) == '\0')
                goto goHome;
        } while (is_sep(c));
    } while (true);
goHome:
    return count;
}
Exemplo n.º 19
0
/* assumes 'dir' null terminated in bounds.  Never writes
   beyond existing terminator.
*/
static void
reduce(wchar_t *dir)
{
    size_t i = wcsnlen_s(dir, MAXPATHLEN+1);
    if (i >= MAXPATHLEN+1)
        Py_FatalError("buffer overflow in getpathp.c's reduce()");

    while (i > 0 && !is_sep(dir[i]))
        --i;
    dir[i] = '\0';
}
Exemplo n.º 20
0
static int	count_words(const char *str, const char *sep)
{
  int		i;
  int		nb;

  nb = 0;
  i = 0;
  if (str == NULL || sep == NULL)
    return (FAILURE);
  while (str[i])
    {
      while (str[i] && is_sep(sep, str[i]))
	i++;
      if (str[i] && !is_sep(sep, str[i]))
	nb++;
      while (str[i] && !is_sep(sep, str[i]))
	i++;
    }
  return (nb);
}
Exemplo n.º 21
0
char	*my_epur_str(char *str)
{
  int	i;
  int	j;

  i = 0;
  j = 0;
  while (is_sep(str[i]))
    i++;
  while (str[i] != '\0')
    {
      while (is_sep(str[i]) && is_sep(str[i + 1]))
	i++;
      if (is_sep(str[i]))
	{
	  str[j++] = ' ';
	  i++;
	}
      while (!is_sep(str[i]) && str[i] != '\0')
	str[j++] = str[i++];
    }
  while (is_sep(str[j - 1]))
    j--;
  str[j] = '\0';
  return (str);
}
Exemplo n.º 22
0
/******************************************************************
 *		SymMatchFileName (DBGHELP.@)
 *
 */
BOOL WINAPI SymMatchFileName(char* file, char* match,
                             char** filestop, char** matchstop)
{
    char*       fptr;
    char*       mptr;

    TRACE("(%s %s %p %p)\n", file, match, filestop, matchstop);

    fptr = file + strlen(file) - 1;
    mptr = match + strlen(match) - 1;

    while (fptr >= file && mptr >= match)
    {
        if (toupper(*fptr) != toupper(*mptr) && !(is_sep(*fptr) && is_sep(*mptr)))
            break;
        fptr--; mptr--;
    }
    if (filestop) *filestop = fptr;
    if (matchstop) *matchstop = mptr;

    return mptr == match - 1;
}
Exemplo n.º 23
0
/******************************************************************
 *		SymMatchFileName (DBGHELP.@)
 *
 */
BOOL WINAPI SymMatchFileName(PCSTR file, PCSTR match,
                             PSTR* filestop, PSTR* matchstop)
{
    PCSTR fptr;
    PCSTR mptr;

    TRACE("(%s %s %p %p)\n", debugstr_a(file), debugstr_a(match), filestop, matchstop);

    fptr = file + strlen(file) - 1;
    mptr = match + strlen(match) - 1;

    while (fptr >= file && mptr >= match)
    {
        if (toupper(*fptr) != toupper(*mptr) && !(is_sep(*fptr) && is_sep(*mptr)))
            break;
        fptr--; mptr--;
    }
    if (filestop) *filestop = (PSTR)fptr;
    if (matchstop) *matchstop = (PSTR)mptr;

    return mptr == match - 1;
}
Exemplo n.º 24
0
t_list		*my_str_to_wordlist(char *str, char *sep)
{
  t_list	*backup;
  t_list	*wordlist;
  int		i;

  i = -1;
  backup = NULL;
  wordlist = NULL;
  while (str[++i])
    if (is_sep(str[i], sep) == 0 && (i == 0 || is_sep(str[i - 1], sep) == 1))
      {
	if ((wordlist = my_put_in_list(str + i, wordlist)) == NULL)
	  {
	    my_free_list(backup);
	    return (NULL);
	  }
	backup = wordlist;
      }
    else if (is_sep(str[i], sep) == 1)
      str[i] = '\0';
  return (wordlist);
}
Exemplo n.º 25
0
size_t cmnroot(const char* path1, const char* path2)
{
	size_t last_sep = 0;
	size_t len = 0;
	if (path1 && *path1 && path2 && *path2)
	{
		while (path1[len] && path2[len])
		{
			char a = (char)tolower(path1[len]);
			char b = (char)tolower(path2[len]);

			if (a != b || is_sep(a) != is_sep(b))
				break;

			if (is_sep(a) || is_sep(b))
				last_sep = len;
			
			len++;
		}
	}

	return last_sep;
}
Exemplo n.º 26
0
/** Extracts the pathname from a full file name.
 * Separators for directories and extensions are OS-specific.
 * @param filename full file name string.
 * @return pointer to pathname with trailing separator.
 */
char *ccp4_utils_pathname(const char *filename)
{
  int i, indx1=-1, length;
  char *pathname;

  for ( i = strlen(filename)-1; i >= 0; i-- ) {
    if (is_sep(filename[i])) {
      indx1 = i; 
      break;
    }
  }
  length = indx1+2;
  pathname = ccp4_utils_malloc(length*sizeof(char));
  strncpy(pathname,filename,length-1);
  pathname[length-1]='\0';
  return pathname;
}
Exemplo n.º 27
0
/** Copy p into path, ensuring that the result is an absolute path.

    copy_absolute requires that path be allocated at least
    MAXPATHLEN + 1 bytes and that p be no more than MAXPATHLEN bytes.

    @param[out]     path    Destination to receive the absolute path.
    @param[in]      p       Path to be tested and possibly converted.
**/
static void
copy_absolute(char *path, char *p)
{
  if (is_absolute(p) == 1)
        strcpy(path, p);
  else {
    if (!getcwd(path, MAXPATHLEN)) {
      /* unable to get the current directory */
      if(volume_name[0] != 0) {
        strcpy(path, volume_name);
        joinpath(path, p);
      }
      else
        strcpy(path, p);
      return;
    }
    if (p[0] == '.' && is_sep(p[1]))
        p += 2;
    joinpath(path, p);
  }
}
Exemplo n.º 28
0
/** Extracts the extension from a full file name.
 * Separators for directories and extensions are OS-specific.
 * @param filename full file name string.
 * @return pointer to extension
 */
char *ccp4_utils_extension(const char *filename)
{
  int i, indx1=-1, length=1;
  char *extension;

  for ( i = strlen(filename)-1; i >= 0; i-- ) {
    if (filename[i] == EXT_SEPARATOR) {
      indx1 = i; 
      length = strlen(filename) - indx1;
      break;
    } else if (is_sep(filename[i])) {
      indx1 = i; 
      length = 1;
      break;
    }
  }
  extension = ccp4_utils_malloc(length*sizeof(char));
  strncpy(extension,filename+indx1+1,length-1);
  extension[length-1]='\0';
  return extension;
}
Exemplo n.º 29
0
static void		skip_quotes_replace_string(t_cmd *cmd, char **str, size_t *i)
{
	while ((*str)[*i] && !ft_isspace2((*str)[*i]) && !is_sep(i, *str, 0, cmd))
	{
		if ((*str)[*i] == '\\')
		{
			if ((*str)[*i + 1])
				*str = delete_char(*str, *i + 1);
		}
		else
		{
			if ((is_redir(i, *str, 0, cmd) || is_aggr(i, *str, 0)) &&
			ft_isdigit((*str)[*i]))
			{
				(*i)++;
				break ;
			}
			if (is_quote_open((*str)[*i]) && !is_escaped_char(*str, *i))
				join_inside_quote(i, str);
		}
		if ((*str)[*i])
			(*i)++;
	}
}
Exemplo n.º 30
0
static void
calculate_path(void)
{
    char argv0_path[MAXPATHLEN+1];
    char *buf;
    size_t bufsz;
    char *pythonhome = Py_GetPythonHome();
    char *envpath = Py_GETENV("PYTHONPATH");

#ifdef MS_WINDOWS
    int skiphome, skipdefault;
    char *machinepath = NULL;
    char *userpath = NULL;
    char zip_path[MAXPATHLEN+1];
    size_t len;
#endif

    get_progpath();
    /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
    strcpy(argv0_path, progpath);
    reduce(argv0_path);
    if (pythonhome == NULL || *pythonhome == '\0') {
        if (search_for_prefix(argv0_path, LANDMARK))
            pythonhome = prefix;
        else
            pythonhome = NULL;
    }
    else
        strncpy(prefix, pythonhome, MAXPATHLEN);

    if (envpath && *envpath == '\0')
        envpath = NULL;


#ifdef MS_WINDOWS
    /* Calculate zip archive path */
    if (dllpath[0])             /* use name of python DLL */
        strncpy(zip_path, dllpath, MAXPATHLEN);
    else                        /* use name of executable program */
        strncpy(zip_path, progpath, MAXPATHLEN);
    zip_path[MAXPATHLEN] = '\0';
    len = strlen(zip_path);
    if (len > 4) {
        zip_path[len-3] = 'z';          /* change ending to "zip" */
        zip_path[len-2] = 'i';
        zip_path[len-1] = 'p';
    }
    else {
        zip_path[0] = 0;
    }

    skiphome = pythonhome==NULL ? 0 : 1;
#ifdef Py_ENABLE_SHARED
    machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome);
    userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome);
#endif
    /* We only use the default relative PYTHONPATH if we havent
       anything better to use! */
    skipdefault = envpath!=NULL || pythonhome!=NULL || \
                  machinepath!=NULL || userpath!=NULL;
#endif

    /* We need to construct a path from the following parts.
       (1) the PYTHONPATH environment variable, if set;
       (2) for Win32, the zip archive file path;
       (3) for Win32, the machinepath and userpath, if set;
       (4) the PYTHONPATH config macro, with the leading "."
           of each component replaced with pythonhome, if set;
       (5) the directory containing the executable (argv0_path).
       The length calculation calculates #4 first.
       Extra rules:
       - If PYTHONHOME is set (in any way) item (3) is ignored.
       - If registry values are used, (4) and (5) are ignored.
    */

    /* Calculate size of return buffer */
    if (pythonhome != NULL) {
        char *p;
        bufsz = 1;
        for (p = PYTHONPATH; *p; p++) {
            if (*p == DELIM)
                bufsz++; /* number of DELIM plus one */
        }
        bufsz *= strlen(pythonhome);
    }
    else
        bufsz = 0;
    bufsz += strlen(PYTHONPATH) + 1;
    bufsz += strlen(argv0_path) + 1;
#ifdef MS_WINDOWS
    if (userpath)
        bufsz += strlen(userpath) + 1;
    if (machinepath)
        bufsz += strlen(machinepath) + 1;
    bufsz += strlen(zip_path) + 1;
#endif
    if (envpath != NULL)
        bufsz += strlen(envpath) + 1;

    module_search_path = buf = malloc(bufsz);
    if (buf == NULL) {
        /* We can't exit, so print a warning and limp along */
        fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
        if (envpath) {
            fprintf(stderr, "Using environment $PYTHONPATH.\n");
            module_search_path = envpath;
        }
        else {
            fprintf(stderr, "Using default static path.\n");
            module_search_path = PYTHONPATH;
        }
#ifdef MS_WINDOWS
        if (machinepath)
            free(machinepath);
        if (userpath)
            free(userpath);
#endif /* MS_WINDOWS */
        return;
    }

    if (envpath) {
        strcpy(buf, envpath);
        buf = strchr(buf, '\0');
        *buf++ = DELIM;
    }
#ifdef MS_WINDOWS
    if (zip_path[0]) {
        strcpy(buf, zip_path);
        buf = strchr(buf, '\0');
        *buf++ = DELIM;
    }
    if (userpath) {
        strcpy(buf, userpath);
        buf = strchr(buf, '\0');
        *buf++ = DELIM;
        free(userpath);
    }
    if (machinepath) {
        strcpy(buf, machinepath);
        buf = strchr(buf, '\0');
        *buf++ = DELIM;
        free(machinepath);
    }
    if (pythonhome == NULL) {
        if (!skipdefault) {
            strcpy(buf, PYTHONPATH);
            buf = strchr(buf, '\0');
        }
    }
#else
    if (pythonhome == NULL) {
        strcpy(buf, PYTHONPATH);
        buf = strchr(buf, '\0');
    }
#endif /* MS_WINDOWS */
    else {
        char *p = PYTHONPATH;
        char *q;
        size_t n;
        for (;;) {
            q = strchr(p, DELIM);
            if (q == NULL)
                n = strlen(p);
            else
                n = q-p;
            if (p[0] == '.' && is_sep(p[1])) {
                strcpy(buf, pythonhome);
                buf = strchr(buf, '\0');
                p++;
                n--;
            }
            strncpy(buf, p, n);
            buf += n;
            if (q == NULL)
                break;
            *buf++ = DELIM;
            p = q+1;
        }
    }
    if (argv0_path) {
        *buf++ = DELIM;
        strcpy(buf, argv0_path);
        buf = strchr(buf, '\0');
    }
    *buf = '\0';
    /* Now to pull one last hack/trick.  If sys.prefix is
       empty, then try and find it somewhere on the paths
       we calculated.  We scan backwards, as our general policy
       is that Python core directories are at the *end* of
       sys.path.  We assume that our "lib" directory is
       on the path, and that our 'prefix' directory is
       the parent of that.
    */
    if (*prefix=='\0') {
        char lookBuf[MAXPATHLEN+1];
        char *look = buf - 1; /* 'buf' is at the end of the buffer */
        while (1) {
            Py_ssize_t nchars;
            char *lookEnd = look;
            /* 'look' will end up one character before the
               start of the path in question - even if this
               is one character before the start of the buffer
            */
            while (look >= module_search_path && *look != DELIM)
                look--;
            nchars = lookEnd-look;
            strncpy(lookBuf, look+1, nchars);
            lookBuf[nchars] = '\0';
            /* Up one level to the parent */
            reduce(lookBuf);
            if (search_for_prefix(lookBuf, LANDMARK)) {
                break;
            }
            /* If we are out of paths to search - give up */
            if (look < module_search_path)
                break;
            look--;
        }
    }
}