17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50a44ef6dSjacobs * Common Development and Distribution License (the "License").
60a44ef6dSjacobs * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
227c478bd9Sstevel@tonic-gate /* All Rights Reserved */
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
26d66fe9b8Swendyp * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
270a44ef6dSjacobs * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include "lpsched.h"
31d66fe9b8Swendyp #include <syslog.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate static int max_requests_needing_form_mounted ( FSTATUS * );
347c478bd9Sstevel@tonic-gate static int max_requests_needing_pwheel_mounted ( char * );
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate /**
377c478bd9Sstevel@tonic-gate ** queue_form() - ADD A REQUEST TO A FORM QUEUE
387c478bd9Sstevel@tonic-gate **/
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate void
queue_form(RSTATUS * prs,FSTATUS * pfs)410a44ef6dSjacobs queue_form(RSTATUS *prs, FSTATUS *pfs)
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate if ((prs->form = pfs) != NULL) {
447c478bd9Sstevel@tonic-gate prs->form->requests++;
457c478bd9Sstevel@tonic-gate if (prs->printer)
467c478bd9Sstevel@tonic-gate check_form_alert (prs->form, (_FORM *)0);
477c478bd9Sstevel@tonic-gate }
487c478bd9Sstevel@tonic-gate return;
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /**
527c478bd9Sstevel@tonic-gate ** unqueue_form() - REMOVE A REQUEST FROM A FORM QUEUE
537c478bd9Sstevel@tonic-gate **/
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate void
unqueue_form(RSTATUS * prs)560a44ef6dSjacobs unqueue_form(RSTATUS *prs)
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate FSTATUS * pfs = prs->form;
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate prs->form = 0;
617c478bd9Sstevel@tonic-gate if (pfs) {
627c478bd9Sstevel@tonic-gate pfs->requests--;
637c478bd9Sstevel@tonic-gate if (prs->printer)
647c478bd9Sstevel@tonic-gate check_form_alert (pfs, (_FORM *)0);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate return;
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate /**
707c478bd9Sstevel@tonic-gate ** queue_pwheel() - ADD A REQUEST TO A PRINT WHEEL QUEUE
717c478bd9Sstevel@tonic-gate **/
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate void
queue_pwheel(RSTATUS * prs,char * name)740a44ef6dSjacobs queue_pwheel(RSTATUS *prs, char *name)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate if (name) {
777c478bd9Sstevel@tonic-gate prs->pwheel_name = Strdup(name);
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * Don't bother queueing the request for
807c478bd9Sstevel@tonic-gate * a print wheel if this request is destined for
817c478bd9Sstevel@tonic-gate * only this printer and the printer doesn't take
827c478bd9Sstevel@tonic-gate * print wheels.
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate if (
857c478bd9Sstevel@tonic-gate !one_printer_with_charsets(prs)
860a44ef6dSjacobs && (prs->pwheel = search_pwstatus(name))
877c478bd9Sstevel@tonic-gate ) {
887c478bd9Sstevel@tonic-gate prs->pwheel->requests++;
897c478bd9Sstevel@tonic-gate check_pwheel_alert (prs->pwheel, (PWHEEL *)0);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate return;
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate /**
967c478bd9Sstevel@tonic-gate ** unqueue_pwheel() - REMOVE A REQUEST FROM A PRINT WHEEL QUEUE
977c478bd9Sstevel@tonic-gate **/
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate void
unqueue_pwheel(RSTATUS * prs)1000a44ef6dSjacobs unqueue_pwheel(RSTATUS *prs)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate PWSTATUS * ppws = prs->pwheel;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate prs->pwheel = 0;
1057c478bd9Sstevel@tonic-gate unload_str (&(prs->pwheel_name));
1067c478bd9Sstevel@tonic-gate if (ppws) {
1077c478bd9Sstevel@tonic-gate ppws->requests--;
1087c478bd9Sstevel@tonic-gate check_pwheel_alert (ppws, (PWHEEL *)0);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate return;
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate /**
1147c478bd9Sstevel@tonic-gate ** check_form_alert() - CHECK CHANGES TO MOUNT FORM ALERT
1157c478bd9Sstevel@tonic-gate **/
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate void
check_form_alert(FSTATUS * pfs,_FORM * pf)1180a44ef6dSjacobs check_form_alert(FSTATUS *pfs, _FORM *pf)
1197c478bd9Sstevel@tonic-gate {
1200a44ef6dSjacobs short trigger,
1217c478bd9Sstevel@tonic-gate fire_off_alert = 0;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate int requests_waiting;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate * Call this routine whenever a requests has been queued
1287c478bd9Sstevel@tonic-gate * or dequeued for a form, and whenever the form changes.
1297c478bd9Sstevel@tonic-gate * If a pointer to a new _FORM is passed, the FSTATUS
1307c478bd9Sstevel@tonic-gate * structure is updated with the changes. Use a second
1317c478bd9Sstevel@tonic-gate * argument of 0 if no change.
1327c478bd9Sstevel@tonic-gate *
1337c478bd9Sstevel@tonic-gate * WARNING: It is valid to call this routine when adding
1347c478bd9Sstevel@tonic-gate * a NEW form (not just changing it). Thus the members of
1357c478bd9Sstevel@tonic-gate * the structure "pfs->form" may not be set.
1367c478bd9Sstevel@tonic-gate * In this case, though, "pf" MUST be set, and there can
1377c478bd9Sstevel@tonic-gate * be NO alert active.
1387c478bd9Sstevel@tonic-gate */
1397c478bd9Sstevel@tonic-gate
140d66fe9b8Swendyp syslog(LOG_DEBUG, "check_form_alert:\n");
141*2a8bcb4eSToomas Soome if (pfs)
142d66fe9b8Swendyp syslog(LOG_DEBUG, "check_form_alert: pfs->name <%s>\n",
143d66fe9b8Swendyp (pfs->form->name != NULL) ? pfs->form->name : "null");
144d66fe9b8Swendyp if (pf)
145d66fe9b8Swendyp syslog(LOG_DEBUG, "check_form_alert: pf->name <%s>\n",
146d66fe9b8Swendyp (pf->name != NULL) ? pf->name : "null");
147d66fe9b8Swendyp
148d66fe9b8Swendyp
1497c478bd9Sstevel@tonic-gate if (pf) {
1507c478bd9Sstevel@tonic-gate if ((trigger = pf->alert.Q) <= 0)
1517c478bd9Sstevel@tonic-gate trigger = 1;
1527c478bd9Sstevel@tonic-gate } else
1537c478bd9Sstevel@tonic-gate trigger = pfs->trigger;
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate if (Starting)
1567c478bd9Sstevel@tonic-gate goto Return;
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate #define OALERT pfs->form->alert
1597c478bd9Sstevel@tonic-gate #define NALERT pf->alert
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate requests_waiting = max_requests_needing_form_mounted(pfs);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate * Cancel an active alert if the number of requests queued
1657c478bd9Sstevel@tonic-gate * has dropped below the threshold (or the threshold has been
1667c478bd9Sstevel@tonic-gate * raised), or if the alert command or period has changed.
1677c478bd9Sstevel@tonic-gate * In the latter case we'll reactive the alert later.
1687c478bd9Sstevel@tonic-gate */
1697c478bd9Sstevel@tonic-gate if (pfs->alert->active)
1707c478bd9Sstevel@tonic-gate if (!requests_waiting || requests_waiting < trigger)
1717c478bd9Sstevel@tonic-gate cancel_alert (A_FORM, pfs);
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate else if (
1747c478bd9Sstevel@tonic-gate pf
1757c478bd9Sstevel@tonic-gate && (
1767c478bd9Sstevel@tonic-gate !SAME(NALERT.shcmd, OALERT.shcmd)
1777c478bd9Sstevel@tonic-gate || NALERT.W != OALERT.W
1787c478bd9Sstevel@tonic-gate || NALERT.Q != OALERT.Q
1797c478bd9Sstevel@tonic-gate )
1807c478bd9Sstevel@tonic-gate )
1817c478bd9Sstevel@tonic-gate cancel_alert (A_FORM, pfs);
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate * If we still have the condition for an alert, we'll fire
1857c478bd9Sstevel@tonic-gate * one off. It is possible the alert is still running, but
1867c478bd9Sstevel@tonic-gate * that's okay. First, we may want to change the alert message;
1877c478bd9Sstevel@tonic-gate * second, the "alert()" routine doesn't execute an alert
1887c478bd9Sstevel@tonic-gate * if it is already running.
1897c478bd9Sstevel@tonic-gate */
1907c478bd9Sstevel@tonic-gate if (trigger > 0 && requests_waiting >= trigger)
1917c478bd9Sstevel@tonic-gate if ((pf && NALERT.shcmd) || OALERT.shcmd)
1927c478bd9Sstevel@tonic-gate fire_off_alert = 1;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate #undef OALERT
1957c478bd9Sstevel@tonic-gate #undef NALERT
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate Return: if (pf) {
1987c478bd9Sstevel@tonic-gate
199*2a8bcb4eSToomas Soome pfs->form = pf;
200d66fe9b8Swendyp
2017c478bd9Sstevel@tonic-gate pfs->trigger = trigger;
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * Have to do this after updating the changes.
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate if (fire_off_alert)
2087c478bd9Sstevel@tonic-gate alert (A_FORM, pfs);
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate return;
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate /**
2147c478bd9Sstevel@tonic-gate ** check_pwheel_alert() - CHECK CHANGES TO MOUNT PRINTWHEEL ALERT
2157c478bd9Sstevel@tonic-gate **/
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate void
check_pwheel_alert(PWSTATUS * ppws,PWHEEL * ppw)2180a44ef6dSjacobs check_pwheel_alert(PWSTATUS *ppws, PWHEEL *ppw)
2197c478bd9Sstevel@tonic-gate {
2200a44ef6dSjacobs short trigger,
2217c478bd9Sstevel@tonic-gate fire_off_alert = 0;
2227c478bd9Sstevel@tonic-gate int requests_waiting;
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate * Call this routine whenever a request has been queued
2277c478bd9Sstevel@tonic-gate * or dequeued for a print-wheel, and whenever the print-wheel
2287c478bd9Sstevel@tonic-gate * changes. If a pointer to a new PWHEEL is passed, the
2297c478bd9Sstevel@tonic-gate * PWSTATUS structure is updated with the changes. Use a
2307c478bd9Sstevel@tonic-gate * second argument of 0 if no change.
2317c478bd9Sstevel@tonic-gate *
2327c478bd9Sstevel@tonic-gate * WARNING: It is valid to call this routine when adding
2337c478bd9Sstevel@tonic-gate * a NEW print wheel (not just changing it). Thus the members
2347c478bd9Sstevel@tonic-gate * of the structure "ppws->pwheel" may not be set.
2357c478bd9Sstevel@tonic-gate * In this case, though, "ppw" MUST be set, and there can
2367c478bd9Sstevel@tonic-gate * be NO alert active.
2377c478bd9Sstevel@tonic-gate */
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate if (ppw) {
2407c478bd9Sstevel@tonic-gate if ((trigger = ppw->alert.Q) <= 0)
2417c478bd9Sstevel@tonic-gate trigger = 1;
2427c478bd9Sstevel@tonic-gate } else
2437c478bd9Sstevel@tonic-gate trigger = ppws->trigger;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate if (Starting)
2467c478bd9Sstevel@tonic-gate goto Return;
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate #define OALERT ppws->pwheel->alert
2497c478bd9Sstevel@tonic-gate #define NALERT ppw->alert
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate requests_waiting = max_requests_needing_pwheel_mounted(ppws->pwheel->name);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate /*
2547c478bd9Sstevel@tonic-gate * Cancel an active alert if the number of requests queued
2557c478bd9Sstevel@tonic-gate * has dropped below the threshold (or the threshold has been
2567c478bd9Sstevel@tonic-gate * raised), or if the alert command or period has changed.
2577c478bd9Sstevel@tonic-gate * In the latter case we'll reactive the alert later.
2587c478bd9Sstevel@tonic-gate */
2597c478bd9Sstevel@tonic-gate if (ppws->alert->active)
2607c478bd9Sstevel@tonic-gate if (!requests_waiting || requests_waiting < trigger)
2617c478bd9Sstevel@tonic-gate cancel_alert (A_PWHEEL, ppws);
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate else if (
2647c478bd9Sstevel@tonic-gate ppw
2657c478bd9Sstevel@tonic-gate && (
2667c478bd9Sstevel@tonic-gate !SAME(NALERT.shcmd, OALERT.shcmd)
2677c478bd9Sstevel@tonic-gate || NALERT.W != OALERT.W
2687c478bd9Sstevel@tonic-gate || NALERT.Q != OALERT.Q
2697c478bd9Sstevel@tonic-gate )
2707c478bd9Sstevel@tonic-gate )
2717c478bd9Sstevel@tonic-gate cancel_alert (A_PWHEEL, ppws);
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate * If we still have the condition for an alert, we'll fire
2757c478bd9Sstevel@tonic-gate * one off. It is possible the alert is still running, but
2767c478bd9Sstevel@tonic-gate * that's okay. First, we may want to change the alert message;
2777c478bd9Sstevel@tonic-gate * second, the "alert()" routine doesn't execute an alert
2787c478bd9Sstevel@tonic-gate * if it is already running.
2797c478bd9Sstevel@tonic-gate */
2807c478bd9Sstevel@tonic-gate if (trigger > 0 && requests_waiting >= trigger)
2817c478bd9Sstevel@tonic-gate if ((ppw && NALERT.shcmd) || OALERT.shcmd)
2827c478bd9Sstevel@tonic-gate fire_off_alert = 1;
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate #undef OALERT
2857c478bd9Sstevel@tonic-gate #undef NALERT
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate Return: if (ppw) {
2887c478bd9Sstevel@tonic-gate
289d66fe9b8Swendyp ppws->pwheel = ppw;
2907c478bd9Sstevel@tonic-gate ppws->trigger = trigger;
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate * Have to do this after updating the changes.
2957c478bd9Sstevel@tonic-gate */
2967c478bd9Sstevel@tonic-gate if (fire_off_alert)
2977c478bd9Sstevel@tonic-gate alert (A_PWHEEL, ppws);
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate return;
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate static int
trayWithForm(PSTATUS * pps,FSTATUS * pfs,int startingTray,int checkAvail)3037c478bd9Sstevel@tonic-gate trayWithForm(PSTATUS *pps, FSTATUS *pfs, int startingTray, int checkAvail)
3047c478bd9Sstevel@tonic-gate {
3057c478bd9Sstevel@tonic-gate int i;
3067c478bd9Sstevel@tonic-gate PFSTATUS *ppfs;
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate ppfs = pps->forms;
3097c478bd9Sstevel@tonic-gate if (startingTray < 0)
3107c478bd9Sstevel@tonic-gate startingTray = 0;
3117c478bd9Sstevel@tonic-gate
312*2a8bcb4eSToomas Soome if (ppfs) {
3137c478bd9Sstevel@tonic-gate for (i = startingTray; i < pps->numForms; i++)
314*2a8bcb4eSToomas Soome if ((!checkAvail || ppfs[i].isAvailable) &&
3157c478bd9Sstevel@tonic-gate (ppfs[i].form == pfs))
3167c478bd9Sstevel@tonic-gate return(i);
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate else if (!pfs)
3197c478bd9Sstevel@tonic-gate /* no form request matches no form mounted */
3207c478bd9Sstevel@tonic-gate return(0);
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate return(-1);
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate char *
allTraysWithForm(PSTATUS * pps,FSTATUS * pfs)3267c478bd9Sstevel@tonic-gate allTraysWithForm(PSTATUS *pps, FSTATUS *pfs)
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate int tray = 0;
3307c478bd9Sstevel@tonic-gate char *ptr, *p;
3317c478bd9Sstevel@tonic-gate char trayList[MAX_INPUT];
3327c478bd9Sstevel@tonic-gate int n;
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate ptr = trayList;
3357c478bd9Sstevel@tonic-gate if (pfs && pfs->form && pfs->form->paper)
3367c478bd9Sstevel@tonic-gate p = pfs->form->paper;
3377c478bd9Sstevel@tonic-gate else
3387c478bd9Sstevel@tonic-gate p = "";
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate n = sizeof (trayList);
3417c478bd9Sstevel@tonic-gate snprintf(ptr, n, "LP_TRAY_ARG=%s:", p);
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate ptr += strlen(ptr);
3447c478bd9Sstevel@tonic-gate n -= strlen(ptr);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate while ((tray = trayWithForm(pps, pfs, tray, 1)) > 0) {
3477c478bd9Sstevel@tonic-gate tray++;
3487c478bd9Sstevel@tonic-gate snprintf(ptr, n, "%d,", tray);
3497c478bd9Sstevel@tonic-gate ptr += strlen(ptr);
3507c478bd9Sstevel@tonic-gate n -= strlen(ptr);
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate if (*(ptr-1) == ',')
3537c478bd9Sstevel@tonic-gate *(ptr-1) = 0;
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate putenv(trayList);
3567c478bd9Sstevel@tonic-gate return(NULL);
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate int
isFormUsableOnPrinter(PSTATUS * pps,FSTATUS * pfs)3607c478bd9Sstevel@tonic-gate isFormUsableOnPrinter(PSTATUS *pps, FSTATUS *pfs)
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate return (trayWithForm(pps,pfs,0,1) >= 0 );
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate int
isFormMountedOnPrinter(PSTATUS * pps,FSTATUS * pfs)3657c478bd9Sstevel@tonic-gate isFormMountedOnPrinter(PSTATUS *pps, FSTATUS *pfs)
3667c478bd9Sstevel@tonic-gate {
3677c478bd9Sstevel@tonic-gate return (trayWithForm(pps,pfs,0,0) >= 0 );
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate /**
3717c478bd9Sstevel@tonic-gate ** max_requests_needing_form_mounted()
3727c478bd9Sstevel@tonic-gate ** max_requests_needing_pwheel_mounted()
3737c478bd9Sstevel@tonic-gate **/
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate static int
max_requests_needing_form_mounted(FSTATUS * pfs)3767c478bd9Sstevel@tonic-gate max_requests_needing_form_mounted(FSTATUS *pfs)
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate PSTATUS * pps;
3797c478bd9Sstevel@tonic-gate RSTATUS * prs;
3807c478bd9Sstevel@tonic-gate int max = 0;
3810a44ef6dSjacobs int i;
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate /*
3847c478bd9Sstevel@tonic-gate * For each printer that doesn't have this form mounted,
3857c478bd9Sstevel@tonic-gate * count the number of requests needing this form and
3867c478bd9Sstevel@tonic-gate * assigned to the printer. Find the maximum across all such
3877c478bd9Sstevel@tonic-gate * printers. Sorry, the code actually has a different loop
3887c478bd9Sstevel@tonic-gate * (it steps through the requests) but the description of what
3897c478bd9Sstevel@tonic-gate * happens below is easier to understand as given. (Looping
3907c478bd9Sstevel@tonic-gate * through the printers would result in #printers x #requests
3917c478bd9Sstevel@tonic-gate * steps, whereas this entails #requests steps.)
3927c478bd9Sstevel@tonic-gate */
3930a44ef6dSjacobs for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++)
3940a44ef6dSjacobs PStatus[i]->nrequests = 0;
3950a44ef6dSjacobs
3960a44ef6dSjacobs for (prs = Request_List; prs != NULL; prs = prs->next)
3970a44ef6dSjacobs if ((prs->form == pfs) && ((pps = prs->printer) != NULL) &&
3980a44ef6dSjacobs (!isFormMountedOnPrinter(pps,pfs)) &&
3990a44ef6dSjacobs (++pps->nrequests >= max))
4000a44ef6dSjacobs max = pps->nrequests;
4010a44ef6dSjacobs
4027c478bd9Sstevel@tonic-gate if (NewRequest)
4037c478bd9Sstevel@tonic-gate if (((pps = NewRequest->printer) != NULL) &&
4047c478bd9Sstevel@tonic-gate (!isFormMountedOnPrinter(pps,pfs)))
4057c478bd9Sstevel@tonic-gate if (++pps->nrequests >= max)
4067c478bd9Sstevel@tonic-gate max = pps->nrequests;
4077c478bd9Sstevel@tonic-gate return (max);
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate static int
max_requests_needing_pwheel_mounted(char * pwheel_name)4117c478bd9Sstevel@tonic-gate max_requests_needing_pwheel_mounted(char *pwheel_name)
4127c478bd9Sstevel@tonic-gate {
4137c478bd9Sstevel@tonic-gate PSTATUS * pps;
4147c478bd9Sstevel@tonic-gate RSTATUS * prs;
4157c478bd9Sstevel@tonic-gate int max = 0;
4160a44ef6dSjacobs int i;
4177c478bd9Sstevel@tonic-gate
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate /*
4207c478bd9Sstevel@tonic-gate * For each printer that doesn't have this print-wheel mounted,
4217c478bd9Sstevel@tonic-gate * count the number of requests needing this print-wheel and
4227c478bd9Sstevel@tonic-gate * assigned to the printer. Find the maximum across all such
4237c478bd9Sstevel@tonic-gate * printers. Sorry, the code actually has a different loop
4247c478bd9Sstevel@tonic-gate * (it steps through the requests) but the description of what
4257c478bd9Sstevel@tonic-gate * happens below is easier to understand as given. (Looping
4267c478bd9Sstevel@tonic-gate * through the printers would result in #printers x #requests
4277c478bd9Sstevel@tonic-gate * steps, whereas this entails #requests steps.)
4287c478bd9Sstevel@tonic-gate */
4290a44ef6dSjacobs for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++)
4300a44ef6dSjacobs PStatus[i]->nrequests = 0;
4310a44ef6dSjacobs
4320a44ef6dSjacobs for (prs = Request_List; prs != NULL; prs = prs->next)
4330a44ef6dSjacobs if ((prs->pwheel_name != NULL) &&
4340a44ef6dSjacobs (STREQU(prs->pwheel_name, pwheel_name)) &&
4350a44ef6dSjacobs ((pps = prs->printer) != NULL) && pps->printer->daisy &&
4360a44ef6dSjacobs (!SAME(pps->pwheel_name, pwheel_name)))
4377c478bd9Sstevel@tonic-gate if (++pps->nrequests >= max)
4387c478bd9Sstevel@tonic-gate max = pps->nrequests;
4390a44ef6dSjacobs
4407c478bd9Sstevel@tonic-gate if (NewRequest)
4417c478bd9Sstevel@tonic-gate if (
4427c478bd9Sstevel@tonic-gate ((pps = NewRequest->printer) != NULL)
4437c478bd9Sstevel@tonic-gate && pps->printer->daisy
4447c478bd9Sstevel@tonic-gate && !SAME(pps->pwheel_name, pwheel_name)
4457c478bd9Sstevel@tonic-gate )
4467c478bd9Sstevel@tonic-gate if (++pps->nrequests >= max)
4477c478bd9Sstevel@tonic-gate max = pps->nrequests;
4487c478bd9Sstevel@tonic-gate return (max);
4497c478bd9Sstevel@tonic-gate }
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate /**
452*2a8bcb4eSToomas Soome ** one_printer_with_charsets()
4537c478bd9Sstevel@tonic-gate **/
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate int
one_printer_with_charsets(RSTATUS * prs)4560a44ef6dSjacobs one_printer_with_charsets(RSTATUS *prs)
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate /*
4597c478bd9Sstevel@tonic-gate * This little function answers the question: Is a request
4607c478bd9Sstevel@tonic-gate * that needs a character set destined for a particular
4617c478bd9Sstevel@tonic-gate * printer that has selectable character sets instead of
4627c478bd9Sstevel@tonic-gate * mountable print wheels?
4637c478bd9Sstevel@tonic-gate */
4647c478bd9Sstevel@tonic-gate return (
4657c478bd9Sstevel@tonic-gate STREQU(prs->request->destination, prs->printer->printer->name)
4667c478bd9Sstevel@tonic-gate && !prs->printer->printer->daisy
4677c478bd9Sstevel@tonic-gate );
4687c478bd9Sstevel@tonic-gate }
469