File: vms.c

package info (click to toggle)
tin 981002-2
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 3,088 kB
  • ctags: 4,969
  • sloc: ansic: 46,800; sh: 1,655; makefile: 1,144; yacc: 699; perl: 103
file content (350 lines) | stat: -rw-r--r-- 6,809 bytes parent folder | download | duplicates (2)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
 *  Project   : tin - a Usenet reader
 *  Module    : vms.c
 *  Author    : Andrew Greer
 *  Created   : 19-06-95
 *  Updated   : 24-01-98  by Michael Stenns
 *  Notes     :
 *  Copyright : (c) Copyright 1991-95 by Iain Lea & Andrew Greer
 *              You may  freely  copy or  redistribute  this software,
 *              so  long as there is no profit made from its use, sale
 *              trade or  reproduction.  You may not change this copy-
 *              right notice, and it must be included in any copy made
 */

#ifdef VMS
#include <stdio.h>
#include <descrip.h>
#include <iodef.h>
#include <ssdef.h>
#include <uaidef.h>
#include <string.h>
#include <stdlib.h>
#include <sys/file.h>
#ifdef __GNUC__
#include <vms/sys$routines.h>
#else
#include <starlet.h>
#endif
#include "tin.h"

/* local prototypes */
char * lower (char * str);
static int vms_open_channel (char * device);

/* global variables for current module */
static int stdin_chan = 0;  /* vms channel to sys$input */
static int stdin_ef   = 0;  /* event flag for read from stdin_chan */

/* Get the name of current user */
char *
getlogin (void)
{
	char *p;

	if ((p = getenv ("USER")) == NULL) {
		return ( (char *) 0);
	}

	return (p);
}


/* return a pointer to string descriptor for zero terminated strings */
struct dsc$descriptor *desz(char *c$_str)
{
  static struct dsc$descriptor c$_tmpdesc;

  c$_tmpdesc.dsc$w_length = strlen(c$_str);
  c$_tmpdesc.dsc$b_dtype  = DSC$K_DTYPE_T;
  c$_tmpdesc.dsc$b_class  = DSC$K_CLASS_S;
  c$_tmpdesc.dsc$a_pointer= c$_str;
  return(&c$_tmpdesc);
}


/*
 * Author: unknown
 * Last edit: M. Stenns  (Oct 1997)
 * Comment:
 * returns the process owner (Owner field in uaf)
 */
char *get_uaf_fullname()
{
  static char uaf_owner[40];
  int i,status;

  struct item_list {
    short bl, ic;
    char *ba;
    short *rl;
  } getuai_itmlist[] = {
    {
      sizeof uaf_owner - 1,
      UAI$_OWNER,
      uaf_owner,
      0
    },
    { 0, 0, 0, 0}
  };

  memset (uaf_owner, '\0', sizeof uaf_owner);
  status = sys$getuai(0,0,desz(cuserid(NULL)),getuai_itmlist,0,0,0);
  if (!(status & 1)) strcpy (uaf_owner, cuserid(NULL));

  for (i=0;uaf_owner[i] && iscntrl(uaf_owner[i]);i++);
  return &uaf_owner[i];
}

/* Converts "TOD_MCQUILLIN" to "Tod McQuillin" */
char *fix_fullname(char *p)
{
  char *tmp;

  if (p && *p) {
    while ((tmp = strchr(p,'_'))) *tmp = ' ';
    tmp = lower(p);
    if (*tmp) *tmp = toupper (*tmp);
    while ((tmp = strchr(tmp,' '))) {
      tmp++;
      if (*tmp) *tmp = toupper (*tmp);
    }
    if ((tmp = strstr(p, "Mc"))) {
      tmp += 2;
      if (*tmp) *tmp = toupper (*tmp);
    }
    tmp = p + strlen(p) - 1;
    while ((tmp > p) && isspace(*tmp)) *tmp-- = '\0';
  }

  return p;
}

#ifndef INDEX_DAEMON

int tputs (char * str, int zzz, OutcPtr func)
{
	if (! str) {
		return(0);
	}
	if (func == outchar) {
		fputs (str, stdout);
	} else {
		while (*str) {
			if (*str == '\n') {
				func('\r');
			}
			func(*str++);
		}
	}
	return(0);
}

#endif

FILE *
popen (
	char *command,
	char *mode)
{
	return ((FILE *) 0);
}


void
pclose (FILE *pipe)
{
	return;
}

void tzset(void)
{
	return;
}

void
make_post_cmd (cmd, name)
	char *cmd;
	char *name;
{
	char *p;

	if ((p = getenv (ENV_VAR_POSTER)) != (char *) 0) {
		sprintf (cmd, p, name);
	} else {
		sprintf (cmd, DEFAULT_POSTER, name);
	}
	return;
}


/*
 * vms_open_channel (char * device)
 *
 * Opens a channel to the device specified as argument.
 * Return value:
 *  VMS channel number
 */

static int vms_open_channel (char * device)
{
  int channel = 0;
  int status;

  status = sys$assign (desz(device), &channel,0,0);
  if ((status & 1) != 1)
  {
     perror ("cannot assgin channel to sys$input");
     exit (EXIT_FAILURE);
  }
  status = lib$get_ef (&stdin_ef);
  if ((status & 1) != 1)
  {
     perror ("cannot get event flag");
     exit (EXIT_FAILURE);
  }
  return channel;
}

/*
 * int vms_close_stdin (void)
 *
 * frees the resources used by ReadCh() and ReadChNowait()
 */
int vms_close_stdin (void)
{
  int status;

  status = sys$cancel (stdin_chan);
  if ((status & 1) != 1)
  {
     perror ("cannot cancel I/O request");
     return status;
  }

  status = sys$dassgn (stdin_chan);
  if ((status & 1) != 1)
  {
     perror ("cannot close channel");
     return status;
  }
  stdin_chan = 0;

  status = lib$free_ef (&stdin_ef);
  if ((status & 1) != 1)
  {
     perror ("cannot free event flag");
     exit (EXIT_FAILURE);
  }
  stdin_ef = 0;

  return status;
}

/*
 * Read character from termianl without echo
 * Return zero if no input hanging
 */
int ReadChNowait (void)
{
  static int tt_char = 0;
  static short int iosb[4] = {1,0,0,0};
  int character     = 0;
  int status = SS$_NORMAL;

  if (!stdin_chan) stdin_chan = vms_open_channel ("sys$input");

  if (iosb[0])  /* no qio pending */
  {
    if (iosb[0] == SS$_TIMEOUT)
      character = 0;
    else if (iosb[0] != SS$_NORMAL)
      character = EOF;
    else
      character = tt_char;

    status = sys$qio (stdin_ef, stdin_chan,
                     IO$_READVBLK|IO$M_NOFILTR|IO$M_NOECHO|IO$M_TIMED,
                     iosb,0,0,
                     &tt_char,1,1,0,0,0);
    if (status != SS$_NORMAL)
    {
      fprintf (stderr,"sys$qiow failed in ReadCh ()\n");
      exit (status);
    }
  }

  return character;
}


/*
 * Read character from termianl without echo
 */
int ReadCh (void)
{
  int character     = 0;
  int status = SS$_NORMAL;
  short int iosb[4];

  while ((status == SS$_NORMAL) && !character)
  {
    character = ReadChNowait();
    if (!character) status = sys$waitfr (stdin_ef);
  }
  return character;
}


/* ======================================================================== */
/* lower - convert string to lowercase */
/* ======================================================================== */
char * lower (char * str)
{
char * tmp;

 /* convert to lower */
 if (str)
 {
    for (tmp = str; *tmp; tmp++) *tmp = tolower (*tmp);
 }
 return str;
}


/******************************************************************************
 * vms_errmsg converts errno to an readable string
 * return values:
 *   the converted string
 *****************************************************************************/
char * vms_errmsg (int error_number)
{
  char * message;

  message = strerror(errno);
  if (!message) message = "unknown error code";
  return message;
}

/*
 *  setenv (char *name, char *value, int notused)
 */
int setenv (char *name, char *value, int notused)
{
  int status = 0;
  char command[LEN];

  if (name && value)
  {
    if (sprintf(command,"define/nolog/job %s \"%s\" ",name,value) > sizeof command)
    {
	fprintf (stderr, "FATAL buffer overflow in setenv");
	tin_done (EXIT_FAILURE);
    }
    status = system(command);
  }
  return status;
}


#endif /* VMS */