Exemplo n.º 1
0
static void
inform(char *cf, int rank)
{
	int fd, j;
	FILE *cfp = NULL;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	PRIV_START;
	fd = safe_open(cf, O_RDONLY|O_NOFOLLOW, 0);
	PRIV_END;
	if (fd < 0 || (cfp = fdopen(fd, "r")) == NULL) {
		if (fd >= 0)
			close(fd);
		return;
	}

	j = 0;
	while (getcfline(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, atoi(cf+3));
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				continue;
			if (j == 0 || strcmp(file, line+1) != 0)
				(void)strlcpy(file, line+1, sizeof(file));
			j++;
			continue;
		case 'N':
			show(line+1, file, j);
			file[0] = '\0';
			j = 0;
		}
	}
	fclose(cfp);
	if (!lflag) {
		blankfill(termwidth - (80 - SIZCOL));
		printf("%lld bytes\n", (long long)totsize);
		totsize = 0;
	}
}
Exemplo n.º 2
0
void
inform(const struct printer *pp, char *cf)
{
	int copycnt, jnum;
	char	 savedname[MAXPATHLEN+1];
	FILE	*cfp;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	PRIV_START
	if ((cfp = fopen(cf, "r")) == NULL)
		return;
	PRIV_END

	if (rank < 0)
		rank = 0;
	if (pp->remote || garbage || strcmp(cf, current))
		rank++;

	/*
	 * The cf-file may include commands to print more than one datafile
	 * from the user.  For each datafile, the cf-file contains at least
	 * one line which starts with some format-specifier ('a'-'z'), and
	 * a second line ('N'ame) which indicates the original name the user
	 * specified for that file.  There can be multiple format-spec lines
	 * for a single Name-line, if the user requested multiple copies of
	 * that file.  Standard lpr puts the format-spec line(s) before the
	 * Name-line, while lprNG puts the Name-line before the format-spec
	 * line(s).  This section needs to handle the lines in either order.
	 */
	copycnt = 0;
	file[0] = '\0';
	savedname[0] = '\0';
	jnum = calc_jobnum(cf, NULL);
	while (getline(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, jnum);
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				break;
			if (copycnt == 0 || strcmp(file, line+1) != 0) {
				strlcpy(file, line + 1, sizeof(file));
			}
			copycnt++;
			/*
			 * deliberately 'continue' to another getline(), so
			 * all format-spec lines for this datafile are read
			 * in and counted before calling show()
			 */
			continue;
		case 'N':
			strlcpy(savedname, line + 1, sizeof(savedname));
			break;
		}
		if ((file[0] != '\0') && (savedname[0] != '\0')) {
			show(savedname, file, copycnt);
			copycnt = 0;
			file[0] = '\0';
			savedname[0] = '\0';
		}
	}
	fclose(cfp);
	/* check for a file which hasn't been shown yet */
	if (file[0] != '\0') {
		if (savedname[0] == '\0') {
			/* a safeguard in case the N-ame line is missing */
			strlcpy(savedname, file, sizeof(savedname));
		}
		show(savedname, file, copycnt);
	}
	if (!lflag) {
		blankfill(SIZCOL);
		printf("%ld bytes\n", totsize);
		totsize = 0;
	}
}
Exemplo n.º 3
0
void
inform(const char *cf)
{
	int j;
	FILE *cfp;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	seteuid(euid);
	if ((cfp = fopen(cf, "r")) == NULL)
		return;
	seteuid(uid);

	if (rank < 0)
		rank = 0;
	if (remote || garbage || strcmp(cf, current))
		rank++;
	j = 0;
	while (get_line(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, atoi(cf+3));
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				continue;
			if (j == 0 || strcmp(fname, line+1) != 0) {
				(void)strlcpy(fname, line+1, sizeof(fname));
			}
			j++;
			continue;
		case 'N':
			show(line + 1, fname, j);
			fname[0] = '\0';
			j = 0;
		}
	}
	fclose(cfp);
	if (!lflag) {
		blankfill(SIZCOL);
		printf("%ld bytes\n", totsize);
		totsize = 0;
	}
}