xref: /illumos-gate/usr/src/cmd/lp/model/lp.set.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #include "stdio.h"
31 
32 #include "lp.h"
33 #include "lp.set.h"
34 
35 extern char		*getenv();
36 
37 /**
38  ** main()
39  **/
40 
41 int
42 main(int argc, char *argv[])
43 {
44 	static char		not_set[10]	= "H V W L S";
45 
46 	int			exit_code;
47 
48 	char			*TERM		= getenv("TERM");
49 
50 
51 	if (!TERM || !*TERM || tidbit(TERM, (char *)0) == -1)
52 		exit (1);
53 
54 	/*
55 	 * Very simple calling sequence:
56 	 *
57 	 *	lpset horz-pitch vert-pitch width length char-set
58 	 *
59 	 * The first four can be scaled with 'i' (inches) or
60 	 * 'c' (centimeters). A pitch scaled with 'i' is same
61 	 * as an unscaled pitch.
62 	 * Blank arguments will skip the corresponding setting.
63 	 */
64 	if (argc != 6)
65 		exit (1);
66 
67 	exit_code = 0;
68 
69 	if (argv[1][0]) {
70 		switch (set_pitch(argv[1], 'H', 1)) {
71 		case E_SUCCESS:
72 			not_set[0] = ' ';
73 			break;
74 		case E_FAILURE:
75 			break;
76 		default:
77 			exit_code = 1;
78 			break;
79 		}
80 	} else
81 		not_set[0] = ' ';
82 
83 	if (argv[2][0]) {
84 		switch (set_pitch(argv[2], 'V', 1)) {
85 		case E_SUCCESS:
86 			not_set[2] = ' ';
87 			break;
88 		case E_FAILURE:
89 			break;
90 		default:
91 			exit_code = 1;
92 			break;
93 		}
94 	} else
95 		not_set[2] = ' ';
96 
97 	if (argv[3][0]) {
98 		switch (set_size(argv[3], 'W', 1)) {
99 		case E_SUCCESS:
100 			not_set[4] = ' ';
101 			break;
102 		case E_FAILURE:
103 			break;
104 		default:
105 			exit_code = 1;
106 			break;
107 		}
108 	} else
109 		not_set[4] = ' ';
110 
111 	if (argv[4][0]) {
112 		switch (set_size(argv[4], 'L', 1)) {
113 		case E_SUCCESS:
114 			not_set[6] = ' ';
115 			break;
116 		case E_FAILURE:
117 			break;
118 		default:
119 			exit_code = 1;
120 			break;
121 		}
122 	} else
123 		not_set[6] = ' ';
124 
125 	if (argv[5][0]) {
126 		switch (set_charset(argv[5], 1, TERM)) {
127 		case E_SUCCESS:
128 			not_set[8] = ' ';
129 			break;
130 		case E_FAILURE:
131 			break;
132 		default:
133 			exit_code = 1;
134 			break;
135 		}
136 	} else
137 		not_set[8] = ' ';
138 
139 	fprintf (stderr, "%s\n", not_set);
140 
141 	return (exit_code);
142 }
143