xref: /titanic_51/usr/src/lib/libast/common/misc/fs3d.c (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Bell Laboratories
26  *
27  * 3d fs operations
28  * only active for non-shared 3d library
29  */
30 
31 #include <ast.h>
32 #include <fs3d.h>
33 
34 int
35 fs3d(register int op)
36 {
37 	register int	cur;
38 	register char*	v;
39 	char		val[sizeof(FS3D_off) + 8];
40 
41 	static int	fsview;
42 	static char	on[] = FS3D_on;
43 	static char	off[] = FS3D_off;
44 
45 	if (fsview < 0) return(0);
46 
47 	/*
48 	 * get the current setting
49 	 */
50 
51 	if (!fsview && mount("", "", 0, NiL))
52 		goto nope;
53 	if (FS3D_op(op) == FS3D_OP_INIT && mount(FS3D_init, NiL, FS3D_VIEW, NiL))
54 		goto nope;
55 	if (mount(on, val, FS3D_VIEW|FS3D_GET|FS3D_SIZE(sizeof(val)), NiL))
56 		goto nope;
57 	if (v = strchr(val, ' ')) v++;
58 	else v = val;
59 	if (!strcmp(v, on))
60 		cur = FS3D_ON;
61 	else if (!strncmp(v, off, sizeof(off) - 1) && v[sizeof(off)] == '=')
62 		cur = FS3D_LIMIT((int)strtol(v + sizeof(off) + 1, NiL, 0));
63 	else cur = FS3D_OFF;
64 	if (cur != op)
65 	{
66 		switch (FS3D_op(op))
67 		{
68 		case FS3D_OP_OFF:
69 			v = off;
70 			break;
71 		case FS3D_OP_ON:
72 			v = on;
73 			break;
74 		case FS3D_OP_LIMIT:
75 			sfsprintf(val, sizeof(val), "%s=%d", off, FS3D_arg(op));
76 			v = val;
77 			break;
78 		default:
79 			v = 0;
80 			break;
81 		}
82 		if (v && mount(v, NiL, FS3D_VIEW, NiL))
83 			goto nope;
84 	}
85 	fsview = 1;
86 	return(cur);
87  nope:
88 	fsview = -1;
89 	return(0);
90 }
91