/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "signal.h"
#include "stdio.h"
#include "errno.h"
#include "lp.h"
#include "msgs.h"
#include "string.h"
void startup(),
cleanup(),
done();
extern char *getenv(),
*malloc(),
*realloc();
extern long atol();
extern int atoi();
static void wakeup();
extern char *optarg;
int optsw;
/*
* Some common postscript printer fault messages.
* These strings are here so that they get l10ned and then lpstat will
* be able to display them in the users language.
* This seemed like a good place for them, since lp.tell knows about
* postscript msgs.
*/
/**
** main()
**/
int
{
char *alert_text,
*bufPtr,
*printer,
*s_key;
int mtype,
short status;
int trayNum = 0;
int mode = 0;
int pagesPrinted = 0;
short mesgRetType;
void (*oldsignal)();
/*
* Run immune from typical interruptions, so that
* we stand a chance to get the fault message.
* EOF (or startup error) is the only way out.
*/
/*
* Do we have a key?
*/
if (
argc < 2
|| !*s_key
) {
printf( "Usage: lptell [-lodk] [-X String] printer\n");
printf("Options (where X is P,S,e,s, O or c )\n");
printf(" environment variable SPOOLER_KEY: must be defined and > 0\n");
printf(" printer: name of printer to give status for.\n");
printf(" -l: expect laser writer type messages (NeWSprint does)\n");
printf(" -o: send input to stdout\n");
printf(" -d: send additional debugging output to stdout\n");
printf(" -P String: string for prefix, default: '%%%%['\n");
printf(" -S String: string for suffix, default: ']%%%%'\n");
printf(" -e String: string to detect printer error,\n");
printf(" default: 'PrinterError:', send S_SEND_FAULT to lpsched\n");
" -c String: string to detect paper change in context of printer error,\n");
printf(" default: 'paper changed:', send S_PAPER_CHANGED to lpsched\n");
printf(" -s String: string to detect printer ok status, \n");
printf(" default: 'status:', send S_CLEAR_FAULT to lpsched\n");
printf(" -k: do not use the key for making status ok\n");
printf(" -O String: string sent as status message to lpsched,\n");
printf(" default: 'ready and printing:'\n");
exit (90);
}
doStdOut = 0;
doDebug = 0;
switch ( optsw ) {
case 'l':
break;
case 'P':
break;
case 'S':
break;
case 'e':
break;
case 's':
break;
case 'O':
break;
case 'c':
break;
case 'k':
clearKey = -1;
break;
case 'o':
doStdOut = 1;
break;
case 'd':
doDebug = 1;
break;
}
}
/*
* Which printer is this? Do we have a key?
*/
if (
|| !*printer
) {
exit (90);
}
if (doDebug) {
printf( "prefix (%s) suffix (%s) printerError (%s)\n",
printf( "paper_changed (%s) status (%s) key %d \n",
}
/*
* Wait for a message on the standard input. When a single line
* comes in, take a couple of more seconds to get any other lines
* that may be ready, then send them to the Spooler.
*/
if (useLaserWriterMessages) {
/* NeWSprint style processing (which simulates the LaserWriter
*There are four types of messages:
* 1) fault messages: printer error message from handler
* 2) clear fault messages: printer ok messages from handler
* 3) paper changed messages: printer handler detected paper change
* 4) server messages: xnews problems
*/
while (*bufPtr == ' ')
bufPtr++;
peLen) == 0) {
while (*bufPtr == ' ')
bufPtr++;
*ptr2 =0;
*ptr3= 0;
*ptr4= 0;
*ptr5= 0;
if (doDebug) {
printf("Paper changed: %s tray %d paper %s md %d pages %d\n",
}
startup ();
} else {
if ( doDebug ) {
}
startup ();
}
if ( doDebug ) {
bufPtr);
}
startup ();
} else {
if ( doDebug ) {
buf);
}
mesgRetType = 0;
}
} else {
*ptr1 = 0;
if (doDebug) {
printf("Server error: %s key %d (%s)\n",
}
mesgRetType = 0;
}
} else { /* not generic PostScript style messages */
alert_text = 0;
do {
if (alert_text)
);
else {
alert_text[0] = 0;
}
if (doStdOut) {
if ( doDebug ) {
}
else {
}
}
startup ();
} else {
startup ();
key, alert_text);
}
}
if (mesgRetType) {
done (91);
done (92);
/*
* check for R_CLEAR_FAULT here and 3 lines below
* because older lpsched doesn't pass S_CLEAR_FAULT
*/
if ((mtype != mesgRetType) &&
(mesgRetType != R_CLEAR_FAULT))
done (93);
done (94);
}
}
done (0);
return (0);
}
/**
** startup() - OPEN MESSAGE QUEUE TO SPOOLER
** cleanup() - CLOSE THE MESSAGE QUEUE TO THE SPOOLER
**/
static int have_contacted_spooler = 0;
void startup ()
{
void catch();
/*
* Open a message queue to the Spooler.
* An error is deadly.
*/
if (!have_contacted_spooler) {
if (mopen() == -1) {
switch (errno) {
case ENOMEM:
case ENOSPC:
break;
default:
break;
}
exit (1);
}
}
return;
}
void cleanup ()
{
mclose ();
return;
}
/**
** wakeup() - TRAP ALARM
**/
static void wakeup ()
{
return;
}
/**
** done() - CLEANUP AND EXIT
**/
int ec;
{
cleanup ();
}