Commit | Line | Data |
---|---|---|
f522e28b C |
1 | /* audio.c - play a sound */ |
2 | ||
3 | #ifndef lint | |
4 | static 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 | ||
58 | extern r_octprint(); | |
59 | extern PE r_octenc(); | |
60 | extern struct qbuf * r_octsdec(); | |
61 | extern struct qbuf * r_octparse(); | |
62 | extern struct qbuf * qb_cpy(); | |
63 | extern qb_cmp(); | |
64 | extern int file_attr_length; | |
65 | ||
66 | audio_print (ps,qb,format) | |
67 | PS ps; | |
68 | struct qbuf * qb; | |
69 | int format; | |
70 | { | |
71 | int pd[2]; | |
72 | char buffer [LINESIZE]; | |
73 | char execvector [LINESIZE]; | |
74 | struct qbuf *p; | |
75 | ||
76 | int pid; | |
77 | int childpid; | |
78 | #ifndef BSD42 | |
79 | int status; | |
80 | #else | |
81 | union wait status; | |
82 | #endif | |
83 | ||
84 | SFP 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 | ||
156 | static struct qbuf *audio_parse (str) | |
157 | char *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 | ||
165 | audio_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 | } |