1/*	$NetBSD$	*/
2
3     /*
4        <vms_fab>
5
6        This macro sets up the file access block and name block for VMS.
7        It also does the initial parsing of the input string (resolving
8        wildcards,
9        if any) and finds all files matching the input pattern.
10        The address of the first matching pattern is returned.
11
12        Written by Phillip C. Brisco 8/98.
13      */
14#include "vms_fab.h"
15
16void
17vms_fab (int * argp, char **argvp[])
18{
19  extern int optind;
20  int optout;
21
22  fab = cc$rms_fab;
23  nam = cc$rms_nam;
24
25  optout = 0;
26  strcpy (fna_buffer, *argvp[optind]);
27  length_of_fna_buffer = NAM$C_MAXRSS;
28
29  fab.fab$b_bid = FAB$C_BID;
30  fab.fab$b_bln = FAB$C_BLN;
31  fab.fab$l_fop = FAB$M_NAM;
32  fab.fab$l_nam = &nam;
33  fab.fab$l_fna = (char *)&fna_buffer;
34  fab.fab$b_fns = length_of_fna_buffer;
35
36  nam.nam$b_bid = NAM$C_BID;
37  nam.nam$b_bln = NAM$C_BLN;
38  nam.nam$l_esa = (char *)&expanded_name;
39  nam.nam$b_ess = NAM$C_MAXRSS;
40  nam.nam$l_rsa = (char *)&result_name;
41  nam.nam$b_rss = NAM$C_MAXRSS;
42
43  fab_stat = sys$parse (&fab);
44  fab_stat = sys$search (&fab);
45
46  if (fab_stat != 65537)
47    {
48      fprintf (stderr, "No Matches found.\n");
49      exit (0);
50    }
51
52  /*
53     While we find matching patterns, continue searching for more.
54   */
55  while (fab_stat == 65537)
56    {
57      /*
58         Allocate memory for the filename
59       */
60      arr_ptr[optout] = alloca (max_file_path_size + 1);
61
62      strcpy (arr_ptr[optout], result_name);
63
64      /*
65         If we don't tack on a null character at the end of the
66         filename,
67         we can get partial data which is still there from the last
68         sys$search command.
69       */
70      arr_ptr[optout][nam.nam$b_dev +
71		      nam.nam$b_dir +
72		      nam.nam$b_name +
73		      nam.nam$b_type +
74		      nam.nam$b_ver] = '\0';
75
76      fab_stat = sys$search (&fab);
77      optout++;
78    }
79
80  optout--;
81
82  /* Return a pointer to the beginning of memory that has the expanded
83     filenames.
84   */
85  *argp = optout;
86  *argvp = arr_ptr;
87
88}
89