BSD 4_3_Net_2 release
[unix-history] / usr / src / contrib / isode / dsap / common / audio.c
CommitLineData
f522e28b
C
1/* audio.c - play a sound */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/dsap/common/RCS/audio.c,v 7.3 91/02/22 09:18:33 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/dsap/common/RCS/audio.c,v 7.3 91/02/22 09:18:33 mrose Interim $
9 *
10 *
11 * $Log: audio.c,v $
12 * Revision 7.3 91/02/22 09:18:33 mrose
13 * Interim 6.8
14 *
15 * Revision 7.2 90/11/20 15:29:13 mrose
16 * cjr
17 *
18 * Revision 7.1 90/10/17 11:41:14 mrose
19 * sync
20 *
21 * Revision 7.0 90/08/08 08:35:36 mrose
22 * *** empty log message ***
23 *
24 */
25
26/*
27 * NOTICE
28 *
29 * Acquisition, use, and distribution of this module and related
30 * materials are subject to the restrictions of a license agreement.
31 * Consult the Preface in the User's Manual for the full terms of
32 * this agreement.
33 *
34 */
35
36
37/* LINTLIBRARY */
38
39#include <signal.h>
40#include "quipu/util.h"
41#include "quipu/attr.h"
42#include "psap.h"
43#include <errno.h>
44#ifdef BSD42
45#include <sys/wait.h>
46#endif
47
48#ifndef BINPATH
49#define BINPATH "/usr/local/bin/"
50#endif
51
52/* Assumes the 'play' routine from Mike (bauer@cns.ucalgary.ca) is
53 installed in BINPATH directory.
54*/
55
56/* Use the {FILE} mechanism to pull in the sound files */
57
58extern r_octprint();
59extern PE r_octenc();
60extern struct qbuf * r_octsdec();
61extern struct qbuf * r_octparse();
62extern struct qbuf * qb_cpy();
63extern qb_cmp();
64extern int file_attr_length;
65
66audio_print (ps,qb,format)
67PS ps;
68struct qbuf * qb;
69int format;
70{
71int pd[2];
72char buffer [LINESIZE];
73char execvector [LINESIZE];
74struct qbuf *p;
75
76int pid;
77int childpid;
78#ifndef BSD42
79int status;
80#else
81union wait status;
82#endif
83
84SFP pstat;
85
86
87 if (format != READOUT) {
88 for (p = qb -> qb_forw; p != qb; p = p -> qb_forw)
89 (void) ps_write (ps,(PElementData)p->qb_data,p->qb_len);
90 return;
91 }
92
93#ifndef sparc
94 ps_print (ps, "(No display process defined)");
95#else
96 if (pipe(pd) == -1) {
97 ps_print (ps,"ERROR: could not create pipe");
98 return;
99 }
100
101 pstat = signal (SIGPIPE, SIG_IGN);
102
103 switch (childpid = fork()) {
104
105 case -1:
106 (void) close (pd[1]);
107 (void) close (pd[0]);
108 (void) signal (SIGPIPE, pstat);
109 ps_print (ps,"ERROR: could not fork");
110 return;
111
112 case 0:
113 (void) signal (SIGPIPE, pstat);
114
115 if (dup2(pd[0], 0) == -1)
116 _exit (-1);
117 (void) close (pd[0]);
118 (void) close (pd[1]);
119
120 (void) sprintf (execvector,"%splay",BINPATH);
121
122 (void) execl (execvector,execvector,NULLCP);
123
124 while (read (0, buffer, sizeof buffer) > 0)
125 continue;
126 (void) printf ("ERROR: can't execute '%s'",execvector);
127
128 (void) fflush (stdout);
129 /* safety catch */
130 _exit (-1);
131 /* NOTREACHED */
132
133 default:
134 (void) close (pd[0]);
135 for (p = qb -> qb_forw; p != qb; p = p -> qb_forw) {
136 if (write (pd[1],p->qb_data,p->qb_len) != p->qb_len) {
137 (void) close (pd[1]);
138 (void) signal (SIGPIPE, pstat);
139 ps_print (ps,"ERROR: write error");
140 return;
141 }
142 }
143 (void) close (pd[1]);
144 ps_printf (ps,"%splay invoked",BINPATH);
145
146 while ((pid = wait (&status)) != NOTOK && childpid != pid)
147 continue;
148
149 (void) signal (SIGPIPE, pstat);
150
151 return;
152 }
153#endif
154}
155
156static struct qbuf *audio_parse (str)
157char *str;
158{
159 if (file_attr_length)
160 return str2qb (str, file_attr_length, 1);
161 else
162 return str2qb (str, strlen (str), 1);
163}
164
165audio_syntax ()
166{
167 (void) add_attribute_syntax ("audio",
168 (IFP)r_octenc, (IFP) r_octsdec,
169 (IFP)audio_parse, audio_print,
170 (IFP)qb_cpy, qb_cmp,
171 qb_free, NULLCP,
172 NULLIFP, TRUE);
173
174}