⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmds.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *sccsid = "@(#)cmds.c	4.1      ULTRIX 7/2/90";#endif/************************************************************************ *									* *			Copyright (c) 1988 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * lpc -- line printer control program *//* SCCS history beginning * *************************************************************** *                -- Revision History -- * *************************************************************** *  * 1.1  01/11/83 -- sccs * date and time created 83/11/01 20:53:47 by sccs *  * *************************************************************** *  * 1.2  28/06/85 -- root * Comments taken from: /usr/src/usr.lib/lpr/SCCS/s.cmds.c: *                      1.2 85/06/24 08:54:13 williams 2 1	00005/00000/00739 * added initializtion file creation to startup command *  *  *  * *************************************************************** *  * 1.3  25/11/85 -- root * Comments taken from: /usr/src/usr.lib/lpr/SCCS/s.cmds.c: *                      1.3 85/11/13 16:17:25 williams 3 2	00001/00001/00743 * Added modes to init file open call. *  *  *  * *************************************************************** * * 1.4  11/07/88 -- thoms * Added copyright notice * *  * *************************************************************** * * 1.5 12/11/89 -- m irish * Restored 'all' option to  status() *  * *************************************************************** * SCCS history end */#include "lp.h"/* * kill an existing daemon and disable printing. */abort(argc, argv)	char *argv[];{	register int c, status;	register char *cp1, *cp2;	char prbuf[100];	if (argc == 1) {		printf("Usage: abort {all | printer ...}\n");		return;	}	if (argc == 2 && !strcmp(argv[1], "all")) {		printer = prbuf;		while (getprent(line) > 0) {			cp1 = prbuf;			cp2 = line;			while ((c = *cp2++) && c != '|' && c != ':')				*cp1++ = c;			*cp1 = '\0';			abortpr();		}		return;	}	while (--argc) {		printer = *++argv;		if ((status = pgetent(line, printer)) < 0) {			printf("cannot open printer description file\n");			continue;		} else if (status == 0) {			printf("unknown printer %s\n", printer);			continue;		}		abortpr();	}}abortpr(){	register FILE *fp;	struct stat stbuf;	int pid, fd;	bp = pbuf;	if ((SD = pgetstr("sd", &bp)) == NULL)		SD = DEFSPOOL;	if ((LO = pgetstr("lo", &bp)) == NULL)		LO = DEFLOCK;	(void) sprintf(line, "%s/%s", SD, LO);	printf("%s:\n", printer);	/*	 * Turn on the owner execute bit of the lock file to disable printing.	 */	if (stat(line, &stbuf) >= 0) {		if (chmod(line, (stbuf.st_mode & 0777) | 0100) < 0)			printf("\tcannot disable printing\n");		else			printf("\tprinting disabled\n");	} else if (errno == ENOENT) {		if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0)			printf("\tcannot create lock file\n");		else {			(void) close(fd);			printf("\tprinting disabled\n");			printf("\tno daemon to abort\n");		}		return;	} else {		printf("\tcannot stat lock file\n");		return;	}	/*	 * Kill the current daemon to stop printing now.	 */	if ((fp = fopen(line, "r")) == NULL) {		printf("\tcannot open lock file\n");		return;	}	if (!getline(fp) || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) {		(void) fclose(fp);	/* unlocks as well */		printf("\tno daemon to abort\n");		return;	}	(void) fclose(fp);	if (kill(pid = atoi(line), SIGINT) < 0)		printf("\tWarning: daemon (pid %d) not killed\n", pid);	else		printf("\tdaemon (pid %d) killed\n", pid);}/* * Remove all spool files and temporaries from the spooling area. */clean(argc, argv)	char *argv[];{	register int c, status;	register char *cp1, *cp2;	char prbuf[100];	if (argc == 1) {		printf("Usage: clean {all | printer ...}\n");		return;	}	if (argc == 2 && !strcmp(argv[1], "all")) {		printer = prbuf;		while (getprent(line) > 0) {			cp1 = prbuf;			cp2 = line;			while ((c = *cp2++) && c != '|' && c != ':')				*cp1++ = c;			*cp1 = '\0';			cleanpr();		}		return;	}	while (--argc) {		printer = *++argv;		if ((status = pgetent(line, printer)) < 0) {			printf("cannot open printer description file\n");			continue;		} else if (status == 0) {			printf("unknown printer %s\n", printer);			continue;		}		cleanpr();	}}cleanpr(){	register int c;	register DIR *dirp;	register struct direct *dp;	char *cp, *cp1;	bp = pbuf;	if ((SD = pgetstr("sd", &bp)) == NULL)		SD = DEFSPOOL;	for (cp = line, cp1 = SD; *cp++ = *cp1++; );	cp[-1] = '/';	printf("%s:\n", printer);	if ((dirp = opendir(SD)) == NULL) {		printf("\tcannot examine spool directory\n");		return;	}	while ((dp = readdir(dirp)) != NULL) {		c = dp->d_name[0];		if ((c == 'c' || c == 't' || c == 'd') && dp->d_name[1]=='f') {			strcpy(cp, dp->d_name);			if (unlink(line) < 0)				printf("\tcannot remove %s\n", line);			else				printf("\tremoved %s\n", line);		}	}	closedir(dirp);}/* * Enable queuing to the printer (allow lpr's). */enable(argc, argv)	char *argv[];{	register int c, status;	register char *cp1, *cp2;	char prbuf[100];	if (argc == 1) {		printf("Usage: enable {all | printer ...}\n");		return;	}	if (argc == 2 && !strcmp(argv[1], "all")) {		printer = prbuf;		while (getprent(line) > 0) {			cp1 = prbuf;			cp2 = line;			while ((c = *cp2++) && c != '|' && c != ':')				*cp1++ = c;			*cp1 = '\0';			enablepr();		}		return;	}	while (--argc) {		printer = *++argv;		if ((status = pgetent(line, printer)) < 0) {			printf("cannot open printer description file\n");			continue;		} else if (status == 0) {			printf("unknown printer %s\n", printer);			continue;		}		enablepr();	}}enablepr(){	struct stat stbuf;	bp = pbuf;	if ((SD = pgetstr("sd", &bp)) == NULL)		SD = DEFSPOOL;	if ((LO = pgetstr("lo", &bp)) == NULL)		LO = DEFLOCK;	(void) sprintf(line, "%s/%s", SD, LO);	printf("%s:\n", printer);	/*	 * Turn off the group execute bit of the lock file to enable queuing.	 */	if (stat(line, &stbuf) >= 0) {		if (chmod(line, stbuf.st_mode & 0767) < 0)			printf("\tcannot enable queuing\n");		else			printf("\tqueuing enabled\n");	}}/* * Disable queuing. */disable(argc, argv)	char *argv[];{	register int c, status;	register char *cp1, *cp2;	char prbuf[100];	if (argc == 1) {		printf("Usage: disable {all | printer ...}\n");		return;	}	if (argc == 2 && !strcmp(argv[1], "all")) {		printer = prbuf;		while (getprent(line) > 0) {			cp1 = prbuf;			cp2 = line;			while ((c = *cp2++) && c != '|' && c != ':')				*cp1++ = c;			*cp1 = '\0';			disablepr();		}		return;	}	while (--argc) {		printer = *++argv;		if ((status = pgetent(line, printer)) < 0) {			printf("cannot open printer description file\n");			continue;		} else if (status == 0) {			printf("unknown printer %s\n", printer);			continue;		}		disablepr();	}}disablepr(){	register int fd;	struct stat stbuf;	bp = pbuf;	if ((SD = pgetstr("sd", &bp)) == NULL)		SD = DEFSPOOL;	if ((LO = pgetstr("lo", &bp)) == NULL)		LO = DEFLOCK;	(void) sprintf(line, "%s/%s", SD, LO);	printf("%s:\n", printer);	/*	 * Turn on the group execute bit of the lock file to disable queuing.	 */	if (stat(line, &stbuf) >= 0) {		if (chmod(line, (stbuf.st_mode & 0777) | 010) < 0)			printf("\tcannot disable queuing\n");		else			printf("\tqueuing disabled\n");	} else if (errno == ENOENT) {		if ((fd = open(line, O_WRONLY|O_CREAT, 0670)) < 0)			printf("\tcannot create lock file\n");		else {			(void) close(fd);			printf("\tqueuing disabled\n");		}		return;	} else		printf("\tcannot stat lock file\n");}/* * Exit lpc */quit(argc, argv)	char *argv[];{	exit(0);}/* * Startup the daemon. */restart(argc, argv)	char *argv[];{	register int c, status;	register char *cp1, *cp2;	char prbuf[100];	if (argc == 1) {		printf("Usage: restart {all | printer ...}\n");		return;	}	gethostname(host, sizeof(host));	if (argc == 2 && !strcmp(argv[1], "all")) {		printer = prbuf;		while (getprent(line) > 0) {			cp1 = prbuf;			cp2 = line;			while ((c = *cp2++) && c != '|' && c != ':')				*cp1++ = c;			*cp1 = '\0';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -