summaryrefslogtreecommitdiff
path: root/src/vms_fab.c
blob: ec3cc23e0b4537e049d318674910dec458dd914e (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
     /*
   Copyright (C) 1992, 1997-2002, 2004-2010 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

        <vms_fab>

        This macro sets up the file access block and name block for VMS.
        It also does the initial parsing of the input string (resolving
        wildcards,
        if any) and finds all files matching the input pattern.
        The address of the first matching pattern is returned.

        Written by Phillip C. Brisco 8/98.
      */

#include <config.h>
#include "vms_fab.h"

void
vms_fab (int * argp, char **argvp[])
{
  extern int optind;
  int optout;

  fab = cc$rms_fab;
  nam = cc$rms_nam;

  optout = 0;
  strcpy (fna_buffer, *argvp[optind]);
  length_of_fna_buffer = NAM$C_MAXRSS;

  fab.fab$b_bid = FAB$C_BID;
  fab.fab$b_bln = FAB$C_BLN;
  fab.fab$l_fop = FAB$M_NAM;
  fab.fab$l_nam = &nam;
  fab.fab$l_fna = (char *)&fna_buffer;
  fab.fab$b_fns = length_of_fna_buffer;

  nam.nam$b_bid = NAM$C_BID;
  nam.nam$b_bln = NAM$C_BLN;
  nam.nam$l_esa = (char *)&expanded_name;
  nam.nam$b_ess = NAM$C_MAXRSS;
  nam.nam$l_rsa = (char *)&result_name;
  nam.nam$b_rss = NAM$C_MAXRSS;

  fab_stat = sys$parse (&fab);
  fab_stat = sys$search (&fab);

  if (fab_stat != 65537)
    {
      fprintf (stderr, "No Matches found.\n");
      exit (0);
    }

  /*
     While we find matching patterns, continue searching for more.
   */
  while (fab_stat == 65537)
    {
      /*
         Allocate memory for the filename
       */
      arr_ptr[optout] = alloca (max_file_path_size + 1);

      strcpy (arr_ptr[optout], result_name);

      /*
         If we don't tack on a null character at the end of the
         filename,
         we can get partial data which is still there from the last
         sys$search command.
       */
      arr_ptr[optout][nam.nam$b_dev +
		      nam.nam$b_dir +
		      nam.nam$b_name +
		      nam.nam$b_type +
		      nam.nam$b_ver] = '\0';

      fab_stat = sys$search (&fab);
      optout++;
    }

  optout--;

  /* Return a pointer to the beginning of memory that has the expanded
     filenames.
   */
  *argp = optout;
  *argvp = arr_ptr;

}