build: update gnulib submodule to latest
[gzip.git] / vms / vms.c
blob3ef8e4362ca4bdd362c4a7fc57790161bb999285
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.
5 * This file was written by Karl-Jose Filler <pla_jfi@pki-nbg.philips.de>
6 * and updated by Jean-loup Gailly.
7 */
9 #include <config.h>
10 #include <stdio.h>
12 static char **vms_argv = NULL;
14 static int max_files = 10000;
16 struct Str_desc {
17 int length;
18 char *addr;
21 vms_expand_args(old_argc, argv)
22 int *old_argc;
23 char **argv[];
25 int i;
26 int new_argc = 0;
27 int context, status;
28 char buf[255], *p;
30 vms_argv = xmalloc((max_files+1)*sizeof(char*));
32 vms_argv[new_argc++] = **argv;
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];
39 } else { /* Files */
40 context = 0;
41 if (find_file_c(argv[0][i], buf, sizeof(buf), &context) & 1 != 1) {
43 * Wrong file ?
44 * forward it to gzip
46 if (new_argc < max_files) {
47 vms_argv[new_argc++] = argv[0][i];
49 } else {
50 p = xmalloc(strlen(buf)+1);
51 strcpy(p, buf);
52 if (new_argc < max_files) {
53 vms_argv[new_argc++] = p;
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;
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);
78 int find_file_c(in,out,out_len,context)
79 char *in;
80 char *out;
81 int out_len;
82 int *context;
84 struct Str_desc in_desc,out_desc;
85 int status;
86 char *p;
88 in_desc.addr = in;
89 in_desc.length = strlen(in);
91 out_desc.addr = out;
92 out_desc.length = out_len;
94 status = lib$find_file(&in_desc,&out_desc,context);
96 p = out_desc.addr;
97 while(*p != ' ') {
98 p++;
100 *p = 0;
102 return status;