import less(1)
[unleashed/tickless.git] / usr / src / lib / libast / common / string / strtape.c
blob00d40b701a60a07250d22f776bbccbde117636d9
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
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
24 * local device pathname for portable tape unit specification is returned
25 * if e is non-null then it is set to the next unused char in s
27 * <unit><density>[<no-rewind>]
28 * {0-7}[l,m,h,u,c][n]
31 #include <ast.h>
33 char*
34 strtape(register const char* s, register char** e)
36 int mtunit = '0';
37 int mtdensity = 0;
38 char mtrewind[2];
39 char mtbehavior[2];
41 static char tapefile[sizeof("/dev/Xrmt/123456789")];
43 mtrewind[0] = mtrewind[1] = mtbehavior[0] = mtbehavior[1] = 0;
44 for (;;)
46 switch (*s)
48 case '0':
49 case '1':
50 case '2':
51 case '3':
52 case '4':
53 case '5':
54 case '6':
55 case '7':
56 mtunit = *s++;
57 continue;
58 case 'b':
59 case 'v':
60 mtbehavior[0] = *s++;
61 continue;
62 case 'l':
63 case 'm':
64 case 'h':
65 case 'u':
66 case 'c':
67 mtdensity = *s++;
68 continue;
69 case 'n':
70 mtrewind[0] = *s++;
71 continue;
73 break;
75 if (e) *e = (char*)s;
76 if (!access("/dev/rmt/.", F_OK))
79 * system V
82 if (!mtdensity) mtdensity = 'm';
83 sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt/ctape%c%s", mtunit, mtrewind);
84 if (!access(tapefile, F_OK)) return(tapefile);
85 for (;;)
87 sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt/%c%c%s%s", mtunit, mtdensity, mtbehavior, mtrewind);
88 if (!access(tapefile, F_OK)) return(tapefile);
89 if (!mtbehavior[0]) break;
90 mtbehavior[0] = 0;
93 else if (!access("/dev/nst0", F_OK))
96 * linux
99 sfsprintf(tapefile, sizeof(tapefile), "/dev/%sst%c", mtrewind, mtunit);
101 else if (!access("/dev/nrmt0", F_OK))
104 * 9th edition
107 switch (mtdensity)
109 case 'l':
110 mtunit = '0';
111 break;
112 case 'm':
113 mtunit = '1';
114 break;
115 case 'h':
116 mtunit = '2';
117 break;
119 sfsprintf(tapefile, sizeof(tapefile), "/dev/%srmt%c", mtrewind, mtunit);
121 else
124 * BSD
127 mtunit -= '0';
128 switch (mtdensity)
130 case 'l':
131 break;
132 case 'h':
133 mtunit |= 020;
134 break;
135 default:
136 mtunit |= 010;
137 break;
139 switch (mtrewind[0])
141 case 'n':
142 mtunit |= 040;
143 break;
145 sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt%d", mtunit);
147 return(tapefile);