mail.c

来自「APUE(第二版)的随书源代码,与第一版的代码相比增加了一些章节的代码(详见第二」· C语言 代码 · 共 68 行

C
68
字号
#include	"lprps.h"static FILE	*mailfp;static char	temp_file[L_tmpnam];static void	open_mailfp(void);/* Called by proc_input_char() when it encounters characters * that are not message characters.  We have to send these * characters back to the user. */voidmail_char(int c){	static int	done_intro = 0;	if (in_job && (done_intro || c != '\n')) {		open_mailfp();		if (done_intro == 0) {			fputs("Your PostScript printer job "				  "produced the following output:\n", mailfp);			done_intro = 1;		}		putc(c, mailfp);	}}/* Called by proc_msg() when an "Error" or "OffendingCommand" key * is returned by the PostScript interpreter.  Send the key and * val to the user. */voidmail_line(const char *msg, const char *val){	if (in_job) {    	open_mailfp();  		fprintf(mailfp, msg, val);	}}/* Create and open a temporary mail file, if not already open. * Called by mail_char() and mail_line() above. */static voidopen_mailfp(void){	if (mailfp == NULL) {		if ( (mailfp = fopen(tmpnam(temp_file), "w")) == NULL)			log_sys("open_mailfp: fopen error");	}}/* Close the temporary mail file and send it to the user. * Registered to be called on exit() by atexit() in main(). */voidclose_mailfp(void){	char	command[1024];	if (mailfp != NULL) {		if (fclose(mailfp) == EOF)			log_sys("close_mailfp: fclose error");		sprintf(command, MAILCMD, loginname, hostname, temp_file);		system(command);		unlink(temp_file);	}}

⌨️ 快捷键说明

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