~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/qmake/vmsfunctions.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vmsfunctions.c */
 
2
 
 
3
#define KDEBUG 0
 
4
 
 
5
#include <stdio.h>
 
6
#include <ctype.h>
 
7
#include "make.h"
 
8
#ifdef __DECC
 
9
#include <starlet.h>
 
10
#endif
 
11
#include <descrip.h>
 
12
#include <rms.h>
 
13
#include <iodef.h>
 
14
#include <atrdef.h>
 
15
#include <fibdef.h>
 
16
#include "vmsdir.h"
 
17
 
 
18
#if __VMS_VER < 70000000
 
19
 
 
20
DIR *
 
21
opendir (dspec)
 
22
     char *dspec;
 
23
{
 
24
  static struct FAB *dfab;
 
25
  struct NAM *dnam;
 
26
  char *searchspec;
 
27
 
 
28
  dfab = (struct FAB *) xmalloc (sizeof (struct FAB));
 
29
  if (! dfab)
 
30
    {
 
31
      printf ("Error mallocing for FAB\n");
 
32
      return (NULL);
 
33
    }
 
34
 
 
35
  dnam = (struct NAM *) xmalloc (sizeof (struct NAM));
 
36
  if (! dnam)
 
37
    {
 
38
      printf ("Error mallocing for NAM\n");
 
39
      free (dfab);
 
40
      return (NULL);
 
41
    }
 
42
 
 
43
  searchspec = (char *) xmalloc (MAXNAMLEN + 1);
 
44
  if (! searchspec)
 
45
    {
 
46
      printf ("Error mallocing for searchspec\n");
 
47
      free (dfab);
 
48
      free (dnam);
 
49
      return (NULL);
 
50
    }
 
51
 
 
52
  sprintf (searchspec, "%s*.*;", dspec);
 
53
 
 
54
  *dfab = cc$rms_fab;
 
55
  dfab->fab$l_fna = searchspec;
 
56
  dfab->fab$b_fns = strlen (searchspec);
 
57
  dfab->fab$l_nam = dnam;
 
58
 
 
59
  *dnam = cc$rms_nam;
 
60
  dnam->nam$l_esa = searchspec;
 
61
  dnam->nam$b_ess = MAXNAMLEN;
 
62
 
 
63
  if (! (sys$parse (dfab) & 1))
 
64
    {
 
65
      free (dfab);
 
66
      free (dnam);
 
67
      free (searchspec);
 
68
      return (NULL);
 
69
    }
 
70
 
 
71
  return (dfab);
 
72
}
 
73
 
 
74
#define uppercasify(str) \
 
75
  do \
 
76
    { \
 
77
      char *tmp; \
 
78
      for (tmp = (str); *tmp != '\0'; tmp++) \
 
79
        if (islower (*tmp)) \
 
80
          *tmp = toupper (*tmp); \
 
81
    } \
 
82
  while (0)
 
83
 
 
84
struct direct *
 
85
readdir (dfd)
 
86
     DIR * dfd;
 
87
{
 
88
  static struct direct *dentry;
 
89
  static char resultspec[MAXNAMLEN + 1];
 
90
  int i;
 
91
 
 
92
  dentry = (struct direct *) xmalloc (sizeof (struct direct));
 
93
  if (! dentry)
 
94
    {
 
95
      printf ("Error mallocing for direct\n");
 
96
      return (NULL);
 
97
    }
 
98
 
 
99
  dfd->fab$l_nam->nam$l_rsa = resultspec;
 
100
  dfd->fab$l_nam->nam$b_rss = MAXNAMLEN;
 
101
 
 
102
  if (debug_flag)
 
103
    printf (".");
 
104
 
 
105
  if (!((i = sys$search (dfd)) & 1))
 
106
    {
 
107
      if (debug_flag)
 
108
        printf ("sys$search failed with %d\n", i);
 
109
      free (dentry);
 
110
      return (NULL);
 
111
    }
 
112
 
 
113
  dentry->d_off = 0;
 
114
  if (dfd->fab$l_nam->nam$w_fid == 0)
 
115
    dentry->d_fileno = 1;
 
116
  else
 
117
    dentry->d_fileno = dfd->fab$l_nam->nam$w_fid[0]
 
118
      + dfd->fab$l_nam->nam$w_fid[1] << 16;
 
119
  dentry->d_reclen = sizeof (struct direct);
 
120
#if 0
 
121
  if (!strcmp(dfd->fab$l_nam->nam$l_type, ".DIR"))
 
122
    dentry->d_namlen = dfd->fab$l_nam->nam$b_name;
 
123
  else
 
124
#endif
 
125
  dentry->d_namlen = dfd->fab$l_nam->nam$b_name + dfd->fab$l_nam->nam$b_type;
 
126
  strncpy (dentry->d_name, dfd->fab$l_nam->nam$l_name, dentry->d_namlen);
 
127
  dentry->d_name[dentry->d_namlen] = '\0';
 
128
  uppercasify (dentry->d_name);
 
129
#if 0
 
130
  uvUnFixRCSSeparator(dentry->d_name);
 
131
#endif
 
132
 
 
133
  return (dentry);
 
134
}
 
135
 
 
136
closedir (dfd)
 
137
     DIR *dfd;
 
138
{
 
139
  if (dfd)
 
140
    {
 
141
      if (dfd->fab$l_nam)
 
142
        free (dfd->fab$l_nam->nam$l_esa);
 
143
      free (dfd->fab$l_nam);
 
144
      free (dfd);
 
145
    }
 
146
}
 
147
#endif /* compiled for OpenVMS prior to V7.x */
 
148
 
 
149
char *
 
150
getwd (cwd)
 
151
     char *cwd;
 
152
{
 
153
  static char buf[512];
 
154
 
 
155
  if (cwd)
 
156
    return (getcwd (cwd, 512));
 
157
  else
 
158
    return (getcwd (buf, 512));
 
159
}
 
160
 
 
161
int
 
162
vms_stat (name, buf)
 
163
     char *name;
 
164
     struct stat *buf;
 
165
{
 
166
  int status;
 
167
  int i;
 
168
 
 
169
  static struct FAB Fab;
 
170
  static struct NAM Nam;
 
171
  static struct fibdef Fib;     /* short fib */
 
172
  static struct dsc$descriptor FibDesc =
 
173
  { sizeof (Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *) &Fib };
 
174
  static struct dsc$descriptor_s DevDesc =
 
175
  { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1] };
 
176
  static char EName[NAM$C_MAXRSS];
 
177
  static char RName[NAM$C_MAXRSS];
 
178
  static struct dsc$descriptor_s FileName =
 
179
  { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
 
180
  static struct dsc$descriptor_s string =
 
181
  { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
 
182
  static unsigned long Rdate[2];
 
183
  static unsigned long Cdate[2];
 
184
  static struct atrdef Atr[] =
 
185
  {
 
186
#if defined(VAX)
 
187
    /* Revision date */
 
188
    { sizeof (Rdate), ATR$C_REVDATE, (unsigned int) &Rdate[0] },
 
189
    /* Creation date */
 
190
    { sizeof (Cdate), ATR$C_CREDATE, (unsigned int) &Cdate[0] },
 
191
#else
 
192
    /* Revision date */
 
193
    { sizeof (Rdate), ATR$C_REVDATE, &Rdate[0] },
 
194
    /* Creation date */
 
195
    { sizeof (Cdate), ATR$C_CREDATE, &Cdate[0]},
 
196
#endif
 
197
    { 0, 0, 0 }
 
198
  };
 
199
  static short int DevChan;
 
200
  static short int iosb[4];
 
201
 
 
202
  name = vmsify (name, 0);
 
203
 
 
204
  /* initialize RMS structures, we need a NAM to retrieve the FID */
 
205
  Fab = cc$rms_fab;
 
206
  Fab.fab$l_fna = name;         /* name of file */
 
207
  Fab.fab$b_fns = strlen (name);
 
208
  Fab.fab$l_nam = &Nam;         /* FAB has an associated NAM */
 
209
 
 
210
  Nam = cc$rms_nam;
 
211
  Nam.nam$l_esa = EName;        /* expanded filename */
 
212
  Nam.nam$b_ess = sizeof (EName);
 
213
  Nam.nam$l_rsa = RName;        /* resultant filename */
 
214
  Nam.nam$b_rss = sizeof (RName);
 
215
 
 
216
  /* do $PARSE and $SEARCH here */
 
217
  status = sys$parse (&Fab);
 
218
  if (!(status & 1))
 
219
    return -1;
 
220
 
 
221
  DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
 
222
  status = sys$assign (&DevDesc, &DevChan, 0, 0);
 
223
  if (!(status & 1))
 
224
    return -1;
 
225
 
 
226
  FileName.dsc$a_pointer = Nam.nam$l_name;
 
227
  FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;
 
228
 
 
229
  /* Initialize the FIB */
 
230
  for (i = 0; i < 3; i++)
 
231
    {
 
232
#if __DECC
 
233
      Fib.fib$w_fid[i] = Nam.nam$w_fid[i];
 
234
      Fib.fib$w_did[i] = Nam.nam$w_did[i];
 
235
#else
 
236
      Fib.fib$r_fid_overlay.fib$w_fid[i] = Nam.nam$w_fid[i];
 
237
      Fib.fib$r_did_overlay.fib$w_did[i] = Nam.nam$w_did[i];
 
238
#endif
 
239
    }
 
240
 
 
241
  status = sys$qiow (0, DevChan, IO$_ACCESS, &iosb, 0, 0,
 
242
                     &FibDesc, &FileName, 0, 0, &Atr, 0);
 
243
  sys$dassgn (DevChan);
 
244
  if (!(status & 1))
 
245
    return -1;
 
246
  status = iosb[0];
 
247
  if (!(status & 1))
 
248
    return -1;
 
249
 
 
250
  status = stat (name, buf);
 
251
  if (status)
 
252
    return -1;
 
253
 
 
254
  buf->st_mtime = ((Rdate[0] >> 24) & 0xff) + ((Rdate[1] << 8) & 0xffffff00);
 
255
  buf->st_ctime = ((Cdate[0] >> 24) & 0xff) + ((Cdate[1] << 8) & 0xffffff00);
 
256
 
 
257
  return 0;
 
258
}
 
259
 
 
260
char *
 
261
cvt_time (tval)
 
262
     unsigned long tval;
 
263
{
 
264
  static long int date[2];
 
265
  static char str[27];
 
266
  static struct dsc$descriptor date_str =
 
267
  { 26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str };
 
268
 
 
269
  date[0] = (tval & 0xff) << 24;
 
270
  date[1] = ((tval >> 8) & 0xffffff);
 
271
 
 
272
  if ((date[0] == 0) && (date[1] == 0))
 
273
    return ("never");
 
274
 
 
275
  sys$asctim (0, &date_str, date, 0);
 
276
  str[26] = '\0';
 
277
 
 
278
  return (str);
 
279
}