3383ee9a4e7f78bda48c31ee7917d18d2d81f1ad
[debian/gzip] / vms / vms.c
1 /* vms.c -- target dependent functions for VMS
2  * This is free software; you can redistribute it and/or modify it under the
3  * terms of the GNU General Public License, see the file COPYING.
4  *
5  * This file was written by Karl-Jose Filler <pla_jfi@pki-nbg.philips.de>
6  * and updated by Jean-loup Gailly.
7  */
8
9 #include <config.h>
10 #include <stdio.h>
11
12 static char **vms_argv = NULL;
13
14 static int max_files = 10000;
15
16 struct  Str_desc {
17     int     length;
18     char    *addr;
19 };
20
21 vms_expand_args(old_argc, argv)
22     int *old_argc;
23     char **argv[];
24 {
25     int     i;
26     int     new_argc = 0;
27     int     context, status;
28     char    buf[255], *p;
29
30     vms_argv = xmalloc((max_files+1)*sizeof(char*));
31
32     vms_argv[new_argc++] = **argv;
33
34     for (i=1; i < *old_argc; i++) {
35         if (*argv[0][i] == '-') {   /* switches */
36             if (new_argc < max_files) {
37                 vms_argv[new_argc++] = argv[0][i];
38             }
39         } else {                    /* Files */
40             context = 0;
41             if (find_file_c(argv[0][i], buf, sizeof(buf), &context) & 1 != 1) {
42                 /*
43                  * Wrong file ?
44                  * forward it to gzip
45                  */
46                 if (new_argc < max_files) {
47                     vms_argv[new_argc++] = argv[0][i];
48                 }
49             } else {
50                 p = xmalloc(strlen(buf)+1);
51                 strcpy(p, buf);
52                 if (new_argc < max_files) {
53                     vms_argv[new_argc++] = p;
54                 }
55                 while (find_file_c(argv[0][i], buf,
56                        sizeof(buf), &context) & 1 == 1) {
57                     p = xmalloc(strlen(buf)+1);
58                     strcpy(p, buf);
59                     if (new_argc < max_files) {
60                         vms_argv[new_argc++] = p;
61                     }
62                 }
63             }
64         }
65     }
66     if (new_argc <= max_files) {
67         *old_argc = new_argc;
68         vms_argv[new_argc] = NULL;
69         *argv = vms_argv;
70     } else {
71         free(vms_argv); /* the expanded file names should also be freed ... */
72         vms_argv = NULL;
73         max_files = new_argc + 1;
74         vms_expand_args(old_argc, argv);
75     }
76 }
77
78 int find_file_c(in,out,out_len,context)
79     char *in;
80     char *out;
81     int   out_len;
82     int  *context;
83 {
84     struct      Str_desc in_desc,out_desc;
85     int         status;
86     char        *p;
87
88     in_desc.addr = in;
89     in_desc.length = strlen(in);
90
91     out_desc.addr = out;
92     out_desc.length = out_len;
93
94     status = lib$find_file(&in_desc,&out_desc,context);
95
96     p   = out_desc.addr;
97     while(*p != ' ') {
98         p++;
99     }
100     *p = 0;
101
102     return status;
103 }