home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
port-lpr
/
part01
/
vms-decnet.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-09
|
3KB
|
150 lines
/*
* lpr interface for VAX/VMS DECnet
*/
#include "common.h"
#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <lnmdef.h>
struct item_list {
unsigned short buffer_length;
unsigned short item_code;
char *buffer_address;
char *length_address;
};
struct descrip {
int length;
char *ptr;
};
/*
* Translate a VAX/VMS logical name, given the name we want to translate
* and the table name we want to search with.
*/
int
translate_logical_name (table, name, buf, size)
char *table; char *name; char *buf; int size;
{
struct descrip table_d;
struct descrip name_d;
struct item_list item_list[2];
int foo;
int status;
table_d.length = strlen (table);
table_d.ptr = table;
name_d.length = strlen (name);
name_d.ptr = name;
item_list[0].buffer_length = size - 1;
item_list[0].item_code = LNM$_STRING;
item_list[0].buffer_address = buf;
item_list[0].length_address = &foo;
item_list[1].buffer_length = 0;
item_list[1].item_code = 0;
item_list[1].buffer_address = 0;
item_list[1].length_address = 0;
status = SYS$TRNLNM (0, &table_d, &name_d, 0, item_list);
if ((status & 01) != 01)
lib$signal (status);
if (foo >= 0 && foo < size)
buf[foo] = '\0';
return ((status & 01) ? 0 : EOF);
}
/*
* Determine the DECnet node name by translating the system logical name
* SYS$NODE. We use this function rather than the getenv() function,
* just to make sure the user doesn't define his/her own SYS$NODE variable
* and pretend he/she is submitting the print job from somewhere else.
*/
int
get_decnet_node_name (buf, size)
char *buf; int size;
{
char *strrchr ();
if (!translate_logical_name ("LNM$SYSTEM_TABLE", "SYS$NODE", buf, size)) {
char *p;
while (p = strrchr (buf, ':'))
*p = '\0';
return 0;
}
return EOF;
}
#ifndef MAKE_EMAIL_ADDRESS
#define MAKE_EMAIL_ADDRESS(buf,user,dom) sprintf (buf, "%s@%s", user, dom)
#endif
void
sysdep()
{
struct passwd *pwd;
char *p;
struct hostent *hp;
char *getenv ();
char nodename[100];
get_decnet_node_name (nodename, sizeof(nodename));
strcpy (hostname, nodename);
/* get user name (will be in ALL CAPS - yikes!) */
cuserid (username);
MAKE_EMAIL_ADDRESS(email_address, username, hostname);
/* lower case host name and user name */
for (p = hostname; *p; ++p)
if (isupper (*p))
*p = tolower (*p);
for (p = username; *p; ++p)
if (isupper (*p))
*p = tolower (*p);
}
/*
* Open a DECnet connection to an lpd-server.
*/
int
open_lpd (server)
char *server;
{
int fd;
char buf[512];
if (server == NULL || *server == '\0') {
fprintf (stderr, "lpr: no printer server host is defined\n");
fprintf (stderr, " Either specify one using -S, or\n");
fprintf (stderr, " using the logical name LPD_SERVER.\n");
return EOF;
}
sprintf (buf, "%s::\"223=\"", server);
if ((fd = open (buf, 2)) < 0) {
fprintf (stderr, "cannot open remote DECnet object '%s'\n", buf);
perror ("");
}
max_net_read = max_net_write = 512;
return fd;
}
/*
* unlink() is not provided by the VMS C library (for reasons which have
* always eluded me). delete() does essentially the same thing, but
* doesn't return the same error codes as unlink. It is, however, sufficient
* for our purposes.
*/
int
unlink (filename)
char *filename;
{
return delete (filename);
}