File: globbing.c

package info (click to toggle)
zssh 1.5c.debian.1-3.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 468 kB
  • ctags: 260
  • sloc: ansic: 2,048; sh: 184; makefile: 151
file content (58 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 ** globbing.c for zssh
 ** 
 ** Made by Matthieu Lucotte
 ** Login   <gounter@users.sourceforge.net>
 ** 
 ** Started on  Thu Jun 29 19:09:55 2000 Matthieu Lucotte
 ** Last update Sun Oct  7 01:17:40 2001 Matthieu Lucotte
 */

#include "zssh.h"
#include <glob.h>

void	glob_args(ac,av)
int	*ac;
char	***av;
{
   int		i,j,flags;
   glob_t	glb;
   int		ac2;
   char		**av2;
   
   flags = 0;
#ifdef GLOB_BRACE
   flags |= GLOB_BRACE;
#endif
/*#ifdef GLOB_TILDE */
/*   flags |= GLOB_TILDE; */
/*#endif */
   av2 = smalloc(TAB_STEP * sizeof(char *));
   ac2 = 0; 
   for (i = 0; (*av)[i]; i++)
   {
      if (glob((*av)[i], flags, 0, &glb) != 0 || !glb.gl_pathc)
	 write_vector_word((*av)[i], &ac2, &av2);
      else
      {
	 for (j = 0; glb.gl_pathv[j]; j++)
	    write_vector_word(glb.gl_pathv[j], &ac2, &av2);
      }
      free((*av)[i]);
      globfree(&glb);
   }
   free(*av);
   av2[ac2++] = 0;
   *av = av2;
   *ac = ac2;
}

void	write_vector_word(str,argc,argv)
char	*str;
int	*argc;
char	***argv;
{
   (*argv)[(*argc)++] = strdup(str);
   if (!(*argc % TAB_STEP))
      pc_new_tab(argc,argv);
}