home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume23
/
mlpd
/
mlp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-08
|
4KB
|
155 lines
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Riverside.
*
* NOTE : That's Riverside. Not Berkeley, not Santa Cruz, not even
* Irvine. Riverside. Ri - ver - side.
*
* The name of the University may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* MLPD -- Multiple Line Printer Daemon (Version 1.3)
* SCCS keywords: @(#)mlp.c 1.3 12/1/90
*/
#include "config.h"
char *LP_SPOOL_DIRECTORY;
int TIMEOUT;
int errno;
/*
// main() -- The main program.
//
// This will start off looking to create the printer structure,
// initialize the process so that it is running as a daemon,
// find the total number of printers to check, and start up a
// select/test loop that looks for print jobs in the main queue
// and moves/prints the new files in new queues.
//
// Arguments : None
*/
int main(argc, argv)
int argc;
char *argv[];
{
int count, clt, nready, pready, no_of_printers;
struct timeval timeout;
printerstruct *printers;
#ifndef lint
FILE *myfp, *fopen();
#endif
int fprintf();
int write();
void exit();
/*
// First, initialize the printer structure.
*/
#ifdef lint
printers = NULL;
#else
printers = (printerstruct *) malloc(sizeof(printerstruct));
#endif
/*
// Next, parse through all of the arguments to find information
// that we need, and set all variables necessary.
*/
no_of_printers = parse_arguments(argc, argv, printers);
/*
// Set the timeout values for the select process to be 2 seconds,
// which keeps the CPU usage down.
*/
timeout.tv_sec = 2;
timeout.tv_usec = 0;
count = 0;
while(TRUE)
{
/*
// Do a select() for about 2 seconds on nothing, so that
// all we do is a time wait without causing a lot of CPU
// usage. I'm hoping that this isn't too much bother for
// the users.
*/
if (count == 0)
{
(void)restart_all_printers(no_of_printers, printers);
/*
// (15 * 2 seconds) + 2 seconds;
*/
count = 16;
}
--count;
if ((nready = select((int) 0, (fd_set *) NULL, (fd_set *) NULL,
(fd_set *) NULL, (struct timeval *) &timeout)) < 0)
{
if (errno != EINTR)
{
bomb("select");
}
else
{
nready = 0;
}
}
/*
// Well, from here, we want to go through the printers
// to make sure we either don't have anything to print,
// or all of the printers are busy. We check the base
// printer (Which ever one that is), and see if it has
// any files to print. If it does, then we want to print
// out the file to one of the other printers, if any
// of them are available.
*/
pready = 0;
while ((nready == 0) &&
(check_base_printer() > 0) &&
(pready == 0))
{
debug("Found a file to print.\n");
/*
// Begin to check through the list of printers
// and see if we have one free. If we do, print
// to that printer, otherwise, skip it. We do
// NOT want to queue files on printers...We want
// to maintain one queue. (See README).
*/
for (clt = 0; clt < no_of_printers; ++clt)
{
/*
// This checks to see if the printer is
// available to print on.
*/
if ((pready = check_prs(printers, clt)) < 0)
{
bomb("check_prs");
}
else if (pready == 0)
{
debug("I can print out a file.\n");
/*
// If we get here, we can print
// out a file on this printer.
*/
if (print_file(printers, clt) < 0)
{
bomb("print_file");
}
clt = no_of_printers;
}
}
}
}
}