Debian Codegraph @

rptp/rptp.c

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 /* $Id: rptp.c,v 1.6 1999/03/21 00:45:08 boyns Exp $ */
2
3 /*
4 * Copyright (C) 1993-99 Mark R. Boyns <[email protected]>
5 *
6 * This file is part of rplay.
7 *
8 * rplay is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * rplay is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with rplay; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 #include "version.h"
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <stdio.h>
31 #ifdef HAVE_STRING_H
32 #include <string.h>
33 #endif
34 #ifdef HAVE_LIBREADLINE
35 #include <readline/readline.h>
36 #include <readline/history.h>
37 #endif /* HAVE_LIBREADLINE */
38 #include "rplay.h"
39 #include "getopt.h"
•40 #include <ctype.h>
41 #include <unistd.h>
42
43 typedef struct
44 {
45 char *name;
46 int min_args;
47 int max_args;
48 char *usage;
49 #ifdef __STDC__
50 void (*func) (int argc, char **argv);
51 #else
52 void (*func) ();
53 #endif
54 }
55 COMMAND;
56
57 #ifdef __STDC__
58 void command_open(int argc, char **argv);
59 void command_close(int argc, char **argv);
60 void command_play(int argc, char **argv);
61 void command_help(int argc, char **argv);
62 void command_list(int argc, char **argv);
63 void command_quit(int argc, char **argv);
64 void command_put(int argc, char **argv);
65 void command_get(int argc, char **argv);
66 void command_unknown(int argc, char **argv);
67 void command_set(int argc, char **argv);
68 void command_status(int argc, char **argv);
69 void command_generic(int argc, char **argv);
70 void command_volume(int argc, char **argv);
71 void command_skip(int argc, char **argv);
72 void command_set(int argc, char **argv);
73 void command_monitor(int argc, char **argv);
74 void argv_to_command(char **argv);
75 int connected();
76 void done(int exit_value);
77 void usage();
78 void do_application();
79 void do_error(char *repsonse);
80 #else
81 void command_open( /* int argc, char **argv */ );
82 void command_close( /* int argc, char **argv */ );
83 void command_play( /* int argc, char **argv */ );
84 void command_help( /* int argc, char **argv */ );
85 void command_list( /* int argc, char **argv */ );
86 void command_quit( /* int argc, char **argv */ );
87 void command_put( /* int argc, char **argv */ );
88 void command_get( /* int argc, char **argv */ );
89 void command_unknown( /* int argc, char **argv */ );
90 void command_status( /* int argc, char **argv */ );
91 void command_generic( /* int argc, char **argv */ );
92 void command_volume( /* int argc, char **argv */ );
93 void command_skip( /* int argc, char **argv */ );
94 void command_set( /* int argc, char **argv */ );
95 void command_monitor( /* int argc, char **argv */ );
96 void argv_to_command( /* char **argv */ );
97 int connected();
98 void done( /* int exit_value */ );
99 void usage();
100 void do_application();
101 void do_error( /* char *repsonse */ );
102 #endif
103
104 COMMAND commands[] =
105 {
106 "access", 0, 0, "", command_generic,
107 "close", 0, 0, "", command_close,
108 "continue", 1, -1, "#id|sound ...", command_play,
109 "find", 1, 1, "sound", command_generic,
110 "get", 1, 2, "sound [filename]", command_get,
111 "help", 0, 1, "[command]", command_help,
112 "info", 1, 1, "sound", command_generic,
113 "list", 0, 1, "[connections|hosts|servers|spool|sounds]", command_list,
114 "monitor", 0, 0, "", command_monitor,
115 "open", 1, 2, "hostname [port]", command_open,
116 "pause", 1, -1, "#id|sound ...", command_play,
117 "play", 1, -1, "[options] sound ...", command_play,
118 "put", 1, 1, "sound", command_put,
119 "quit", 0, 0, "", command_quit,
120 "reset", 0, 0, "", command_generic,
121 "set", 1, -1, "name=value", command_set,
122 "skip", 0, 2, "[#id] [[+|-]count]", command_skip,
123 "status", 0, 0, "", command_status,
124 "stop", 1, -1, "#id|sound ...", command_play,
125 "version", 0, 0, "", command_generic,
126 "volume", 0, 1, "[[+|-]volume]", command_volume,
127 "wait", 1, -1, "#id|command|event-list", command_generic,
128 };
129
130 #define NCOMMANDS (sizeof(commands)/sizeof(COMMAND))
131
132 static struct option longopts[] =
133 {
134 {"help", no_argument, NULL, 1},
135 {"host", required_argument, NULL, 'h'},
136 {"port", required_argument, NULL, 'p'},
137 {"prompt", required_argument, NULL, 2},
138 {"raw", no_argument, NULL, 'r'},
139 {"version", no_argument, NULL, 'v'},
140 {NULL, 0, NULL, 0}
141 };
142
143 int rptp_fd = -1;
144 char rptp_buf[4096];
145 char command[RPTP_MAX_LINE];
146 char response[RPTP_MAX_LINE];
147 char *prompt = "rptp> ";
148 int interactive = 1;
149 int raw = 0;
150
151 extern int optind;
152 extern char *optarg;
153
154 #ifdef __STDC__
•155 int main(int argc, char **argv)
156 #else
•157 int main(argc, argv)
158 int argc;
159 char **argv;
160 #endif
161 {
162 char buf[256];
163 int i;
164 int port = RPTP_PORT;
165 int c;
166 char *av[RPTP_MAX_ARGS], *p, *host = NULL;
167 int ac, first;
168 char numeric_string[128];
169
170 while ((c = getopt_long(argc, argv, "+h:p:rv", longopts, 0)) != -1)
171 {
172 switch (c)
173 {
174 case 0:
175 /* getopt has processed a long-named option -- do nothing */
176 break;
177
178 case 1: /* --help */
179 usage();
180 done(0);
181
182 case 2: /* --prompt */
183 prompt = optarg;
184 break;
185
186 case 'h':
187 host = optarg;
188 break;
189
190 case 'p':
191 port = atoi(optarg);
192 break;
193
194 case 'r':
195 raw++;
196 break;
197
198 case 'v':
199 printf("rplay %s\n", RPLAY_VERSION);
200 done(0);
201
202 default:
203 fprintf(stderr, "Try `rptp --help' for more information.\n");
204 exit(1);
205 }
206 }
207
208 if (optind != argc)
209 {
210 interactive = 0;
211 }
212
213 if (host == NULL)
214 {
215 host = rplay_default_host();
216 }
217
218 rptp_fd = rptp_open(host, port, response, sizeof(response));
219 if (rptp_fd < 0)
220 {
221 rptp_perror("open");
222 }
223 else if (interactive)
224 {
225 if (raw)
226 {
227 printf("%s\n", response);
228 }
229 else
230 {
231 if (strchr(response, '='))
232 {
233 rptp_parse(response, 0);
234 printf("%s rplayd %s connected\n",
235 rptp_parse(0, "host"),
236 rptp_parse(0, "version"));
237 }
238 else
239 {
240 printf("Connected to %s port %d.\n", host, port);
241 printf("%s\n", response + 1);
242 }
243 }
244 }
245
246 do_application();
247
248 do
249 {
250 if (interactive)
251 {
252 if (!raw)
253 {
254 #ifdef HAVE_LIBREADLINE
255 p = readline(prompt);
256 if (!p)
257 {
258 done(0);
259 }
260 add_history(p);
261 strcpy(buf, p);
262 #else
263 printf(prompt);
264 fflush(stdout);
265 #endif
266 }
267
268 #ifndef HAVE_LIBREADLINE
269 if (fgets(buf, sizeof(buf), stdin) == NULL)
270 {
271 done(0);
272 }
273 #endif
274 first = 1;
275 ac = 0;
276 while ((p = strtok(first ? buf : NULL, " \t\r\n")))
277 {
278 av[ac++] = p;
279 first = 0;
280 }
281 av[ac] = NULL;
282 }
283 else
284 {
285 int i;
286
287 ac = 0;
288 for (i = optind; i < argc; i++)
289 {
290 av[ac++] = argv[i];
291 }
292 av[ac] = NULL;
293 }
294
295 if (av[0] == NULL)
296 {
297 continue;
298 }
299
300 for (i = 0; i < NCOMMANDS; i++)
301 {
302 if (strcasecmp(commands[i].name, av[0]) == 0)
303 {
304 if ((commands[i].min_args >= 0 && ac - 1 < commands[i].min_args)
305 || (commands[i].max_args >= 0 && ac - 1 > commands[i].max_args))
306 {
307 printf("Usage: %s %s\n", commands[i].name, commands[i].usage);
308 }
309 else
310 {
311 (*commands[i].func) (ac, av);
312 }
313 break;
314 }
315 }
316 if (i == NCOMMANDS)
317 {
318 command_unknown(ac, av);
319 }
320 }
321 while (interactive);
322
323 done(0);
324 }
325
326 #ifdef __STDC__
327 void
328 argv_to_command(char **argv)
329 #else
330 void
331 argv_to_command(argv)
332 char **argv;
333 #endif
334 {
335 command[0] = '\0';
336 for (; *argv; argv++)
337 {
338 strcat(command, *argv);
339 if (*(argv + 1))
340 {
341 strcat(command, " ");
342 }
343 }
344 }
345
346 int
347 connected()
348 {
349 if (rptp_fd != -1)
350 {
351 return 1;
352 }
353 else
354 {
355 printf("You're not connected, use `open' first.\n");
356 return 0;
357 }
358 }
359
360 #ifdef __STDC__
361 void
362 command_open(int argc, char **argv)
363 #else
364 void
365 command_open(argc, argv)
366 int argc;
367 char **argv;
368 #endif
369 {
370 int port;
371
372 if (rptp_fd != -1)
373 {
374 printf("You're already connected, use `close' first.\n");
375 }
376 else
377 {
378 port = argc == 3 ? atoi(argv[2]) : RPTP_PORT;
379 rptp_fd = rptp_open(argv[1], port, response, sizeof(response));
380 if (rptp_fd < 0)
381 {
382 rptp_perror("open");
383 }
384 else
385 {
386 if (raw)
387 {
388 printf("%s\n", response);
389 }
390 else
391 {
392 if (strchr(response, '='))
393 {
394 printf("%s rplayd %s connected\n",
395 rptp_parse(response, "host"),
396 rptp_parse(0, "version"));
397 }
398 else
399 {
400 printf("Connected to %s port %d.\n", argv[1], port);
401 printf("%s\n", response + 1);
402 }
403 }
404 do_application();
405 }
406 }
407 }
408
409 #ifdef __STDC__
410 void
411 command_close(int argc, char **argv)
412 #else
413 void
414 command_close(argc, argv)
415 int argc;
416 char **argv;
417 #endif
418 {
419 if (connected())
420 {
421 rptp_close(rptp_fd);
422 rptp_fd = -1;
423 if (interactive)
424 {
425 printf("Connection closed.\n");
426 }
427 }
428 }
429
430 #ifdef __STDC__
431 void
432 command_play(int argc, char **argv)
433 #else
434 void
435 command_play(argc, argv)
436 int argc;
437 char **argv;
438 #endif
439 {
440 argv_to_command(argv);
441
442 if (!connected())
443 {
444 return;
445 }
446
447 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
448 {
449 case -1:
450 rptp_perror(argv[0]);
451 command_close(argc, argv);
452 return;
453
454 case 1:
455 do_error(response);
456 return;
457
458 case 0:
459 break;
460 }
461
462 if (raw)
463 {
464 printf("%s\n", response);
465 }
466 }
467
468 #ifdef __STDC__
469 void
470 command_generic(int argc, char **argv)
471 #else
472 void
473 command_generic(argc, argv)
474 int argc;
475 char **argv;
476 #endif
477 {
478 argv_to_command(argv);
479
480 if (!connected())
481 {
482 return;
483 }
484
485 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
486 {
487 case -1:
488 rptp_perror(argv[0]);
489 command_close(argc, argv);
490 return;
491
492 case 1:
493 do_error(response);
494 return;
495
496 case 0:
497 break;
498 }
499
500 printf("%s\n", raw ? response : response + 1);
501 }
502
503 #ifdef __STDC__
504 void
505 command_help(int argc, char **argv)
506 #else
507 void
508 command_help(argc, argv)
509 int argc;
510 char **argv;
511 #endif
512 {
513 int i;
514
515 if (argc == 2)
516 {
517 for (i = 0; i < NCOMMANDS; i++)
518 {
519 if (strcasecmp(commands[i].name, argv[1]) == 0)
520 {
521 printf("Usage: %s %s\n", commands[i].name, commands[i].usage);
522 return;
523 }
524 }
525 command_unknown(argc, argv);
526 }
527 else
528 {
529 printf("access Display remote access permissions.\n");
530 printf("close Close the current server connection.\n");
531 printf("continue Continue paused sounds.\n");
532 printf("find Search for a sound.\n");
533 printf("get Retrieve a sound.\n");
534 printf("help Display help information.\n");
535 printf("info Display sound information.\n");
536 printf("list Display various server information.\n");
•537 printf("monitor Monitor the audio output of rplayd.\n");
538 printf(" Requires \"m\" permission in rplay.hosts\n");
539 printf("open Connect to a server.\n");
540 printf("pause Pause sounds that are playing.\n");
541 printf("play Play sounds\n");
542 printf("put Send a sound.\n");
543 printf("quit Terminate the rptp session.\n");
544 printf("reset Tell the server to reset itself.\n");
545 printf("set Change server settings.\n");
546 printf("skip Skip sounds in a sound list.\n");
547 printf("status Display server statistics.\n");
548 printf("stop Stop sounds that are playing.\n");
549 printf("version Display the version of the server.\n");
550 printf("volume Get and set the volume of the audio device.\n");
551 printf("wait Wait for a spool id, volume change, or command execution.\n");
552 }
553 }
554
555 #ifdef __STDC__
556 void
557 command_list(int argc, char **argv)
558 #else
559 void
560 command_list(argc, argv)
561 int argc;
562 char **argv;
563 #endif
564 {
565 int n;
566
567 if (!connected())
568 {
569 return;
570 }
571
572 argv_to_command(argv);
573
574 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
575 {
576 case -1:
577 rptp_perror(argv[0]);
578 command_close(argc, argv);
579 return;
580
581 case 1:
582 do_error(response);
583 return;
584
585 case 0:
586 if (raw)
587 {
588 printf("%s\n", response);
589 }
590 break;
591 }
592
593 for (;;)
594 {
595 n = rptp_getline(rptp_fd, rptp_buf, sizeof(rptp_buf));
596 if (n < 0)
597 {
598 rptp_perror("list");
599 command_close(argc, argv);
600 break;
601 }
602 if (strcmp(rptp_buf, ".") == 0)
603 {
604 if (raw)
605 {
606 printf("%s\n", rptp_buf);
607 }
608 break;
609 }
610 printf("%s\n", rptp_buf);
611 }
612 }
613
614 #ifdef __STDC__
615 void
616 command_quit(int argc, char **argv)
617 #else
618 void
619 command_quit(argc, argv)
620 int argc;
621 char **argv;
622 #endif
623 {
624 if (rptp_fd != -1)
625 {
626 rptp_close(rptp_fd);
627 printf("Connection closed.\n");
628 }
629 done(0);
630 }
631
632 #ifdef __STDC__
633 void
634 command_put(int argc, char **argv)
635 #else
636 void
637 command_put(argc, argv)
638 int argc;
639 char **argv;
640 #endif
641 {
642 FILE *fp;
643 int size, n, nwritten;
644 struct stat st;
645 char line[RPTP_MAX_LINE];
646 int total_size;
647
648 if (!connected())
649 {
650 return;
651 }
652
653 if (stat(argv[1], &st) < 0)
654 {
655 perror(argv[1]);
656 return;
657 }
658 fp = fopen(argv[1], "r");
659 if (fp == NULL)
660 {
661 perror(argv[1]);
662 return;
663 }
664 size = st.st_size;
665
666 sprintf(line, "put sound=%s size=%d", argv[1], size);
667
668 switch (rptp_command(rptp_fd, line, response, sizeof(response)))
669 {
670 case -1:
671 rptp_perror(argv[0]);
672 command_close(argc, argv);
673 return;
674
675 case 1:
676 do_error(response);
677 return;
678
679 case 0:
680 break;
681 }
682
683 if (raw)
684 {
685 printf("%s\n", response);
686 }
687
688 total_size = size;
689 while (size > 0)
690 {
691 n = fread(rptp_buf, 1, sizeof(rptp_buf), fp);
692 nwritten = rptp_write(rptp_fd, rptp_buf, n);
693 if (nwritten != n)
694 {
695 rptp_perror("put");
696 command_close(argc, argv);
697 break;
698 }
699 size -= nwritten;
700
701 sprintf(line, "\r%s %d/%d %d%%", argv[1],
702 total_size - size, total_size,
703 (int)(((float)(total_size-size)/total_size)*100));
704 write(2, line, strlen(line));
705 }
706 write(2, "\n", 1);
707 fclose(fp);
708 }
709
710 #ifdef __STDC__
711 void
712 command_get(int argc, char **argv)
713 #else
714 void
715 command_get(argc, argv)
716 int argc;
717 char **argv;
718 #endif
719 {
720 FILE *fp;
721 char *filename;
722 char *p;
723 int size, n, nread, total_size;
724 char line[RPTP_MAX_LINE];
725
726 if (!connected())
727 {
728 return;
729 }
730
731 if (argc == 3)
732 {
733 filename = argv[2];
734 argv[2] = NULL;
735 }
736 else
737 {
738 filename = argv[1];
739 }
740
741 sprintf(line, "get sound=%s", argv[1]);
742
743 switch (rptp_command(rptp_fd, line, response, sizeof(response)))
744 {
745 case -1:
746 rptp_perror(argv[0]);
747 command_close(argc, argv);
748 return;
749
750 case 1:
751 do_error(response);
752 return;
753
754 case 0:
755 break;
756 }
757
758 if (raw)
759 printf("%s\n", response);
760
761 fp = fopen(filename, "w");
762 if (fp == NULL)
763 {
764 perror(filename);
765 return;
766 }
767
768 if (strchr(response, '='))
769 {
770 size = atoi(rptp_parse(response, "size"));
771 }
772 else
773 {
774 p = strtok(response + 1, " ");
775 size = atoi(strtok(NULL, "\r\n"));
776 }
777
778 total_size = size;
779 while (size > 0)
780 {
781 n = MIN(sizeof(rptp_buf), size);
782 nread = rptp_read(rptp_fd, rptp_buf, n);
783 if (nread != n)
784 {
785 rptp_perror("get");
786 break;
787 }
788 fwrite(rptp_buf, 1, n, fp);
789 size -= n;
•790
791 sprintf(line, "\r%s %d/%d %d%%", filename,
792 total_size - size, total_size,
793 (int)(((float)(total_size-size)/total_size)*100));
794 write(2, line, strlen(line));
795 }
796 write(2, "\n", 1);
797 fclose(fp);
798 }
799
800 #ifdef __STDC__
801 void
802 command_unknown(int argc, char **argv)
803 #else
804 void
805 command_unknown(argc, argv)
806 int argc;
807 char **argv;
808 #endif
809 {
810 printf("unknown command `%s'.\n", argv[0]);
811 }
812
813 #ifdef __STDC__
814 void
815 command_status(int argc, char **argv)
816 #else
817 void
818 command_status(argc, argv)
819 int argc;
820 char **argv;
821 #endif
822 {
823 argv_to_command(argv);
824
825 if (!connected())
826 {
827 return;
828 }
829
830 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
831 {
832 case -1:
833 rptp_perror(argv[0]);
834 command_close(argc, argv);
835 return;
836
837 case 1:
838 do_error(response);
839 return;
840
841 case 0:
842 break;
843 }
844
845 if (raw)
846 {
847 printf("%s\n", response);
848 }
849 else
850 {
851 int first = 1;
852 char *name, *value;
853
854 while (name = rptp_parse(first ? response : 0, 0))
855 {
856 first = 0;
857 value = rptp_parse(0, name);
858 printf("%s=%s\n", name, value);
859 }
860 }
861 }
862
863 #ifdef __STDC__
864 void
865 command_volume(int argc, char **argv)
866 #else
867 void
868 command_volume(argc, argv)
869 int argc;
870 char **argv;
871 #endif
872 {
873 char *volume;
874
875 if (!connected())
876 {
877 return;
878 }
879
880 if (argc == 2)
881 {
882 sprintf(command, "set volume=%s", argv[1]);
883 }
884 else
885 {
886 sprintf(command, "set volume");
887 }
888
889 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
890 {
891 case -1:
892 rptp_perror(argv[0]);
893 command_close(argc, argv);
894 return;
895
896 case 1:
897 do_error(response);
898 return;
899
900 case 0:
901 break;
902 }
903
904 volume = rptp_parse(response, "volume");
905 if (volume && *volume)
906 {
907 printf("volume=%s\n", volume);
908 }
909 else
910 {
911 printf("unknown response `%s'\n", response);
912 }
913 }
914
915 #ifdef __STDC__
916 void
917 command_skip(int argc, char **argv)
918 #else
919 void
920 command_skip(argc, argv)
921 int argc;
922 char **argv;
923 #endif
924 {
925 char *value;
926
927 if (!connected())
928 {
929 return;
930 }
931
932 if (strchr(command, '='))
933 {
934 /* Leave command alone. */
935 }
936 else if (argc == 3)
937 {
938 sprintf(command, "skip id=%s count=%s", argv[1], argv[2]);
939 }
940 else if (argc == 2)
941 {
942 sprintf(command, "skip id=%s count=1", argv[1]);
943 }
944 else
945 {
946 sprintf(command, "skip id=#0 count=1");
947 }
948
949 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
950 {
951 case -1:
952 rptp_perror(argv[0]);
953 command_close(argc, argv);
954 return;
955
956 case 1:
957 do_error(response);
958 return;
959
960 case 0:
961 break;
962 }
963
964 value = rptp_parse(response, "message");
965 if (value && *value)
966 {
967 printf("%s\n", value);
968 }
969 else
970 {
971 printf("unknown response `%s'\n", response);
972 }
973 }
974
975 #ifdef __STDC__
976 void
977 command_set(int argc, char **argv)
978 #else
979 void
980 command_set(argc, argv)
981 int argc;
982 char **argv;
983 #endif
984 {
985 char *value;
986
987 if (!connected())
988 {
989 return;
990 }
991
992 argv_to_command(argv);
993
994 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
995 {
996 case -1:
997 rptp_perror(argv[0]);
998 command_close(argc, argv);
999 return;
1000
1001 case 1:
1002 do_error(response);
1003 return;
1004
1005 case 0:
1006 break;
1007 }
1008 }
1009
1010 #ifdef __STDC__
1011 void
1012 command_monitor(int argc, char **argv)
1013 #else
1014 void
1015 command_monitor(argc, argv)
1016 int argc;
1017 char **argv;
1018 #endif
1019 {
1020 char *value, *p;
1021 char buf[8192];
1022 char line[80];
1023 int n, size;
1024 int sample_rate, precision, channels, sample_size;
•1025
1026 if (!connected())
1027 {
1028 return;
1029 }
1030
1031 sprintf(command, "monitor");
1032
1033 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
1034 {
1035 case -1:
1036 rptp_perror(argv[0]);
1037 command_close(argc, argv);
1038 return;
1039
1040 case 1:
1041 do_error(response);
1042 return;
1043
1044 case 0:
1045 break;
1046 }
1047
1048 p = strtok(rptp_parse(response, "audio-info"), ",");
1049 // input_format
1050
1051 p = strtok(NULL, ",");
1052 if (p) sample_rate = atoi(p);
1053
1054 p = strtok(NULL, ",");
1055 if (p) precision = atoi(p);
1056
1057 p = strtok(NULL, ",");
1058 if (p) channels = atoi(p);
1059
1060 sample_size = precision/8 * channels;
1061
1062 fprintf(stderr, "%dhz %dbit %s\n", sample_rate, precision,
1063 channels == 2 ? "stereo" : "mono");
1064
1065 while ((n = read(rptp_fd, buf, sizeof(buf))) > 0)
1066 {
1067 write(1, buf, n);
1068 size += n;
1069 }
1070 close(rptp_fd);
1071 }
1072
1073 void
1074 do_application()
1075 {
1076 sprintf(command, "set application=\"rptp %s\"", RPLAY_VERSION);
1077
1078 switch (rptp_command(rptp_fd, command, response, sizeof(response)))
1079 {
1080 case -1:
1081 rptp_perror("application");
1082 rptp_close(rptp_fd);
1083 rptp_fd = -1;
1084 return;
1085
1086 case 1:
1087 do_error(response);
1088 return;
1089
1090 case 0:
1091 break;
1092 }
1093 }
1094
1095 #ifdef __STDC__
1096 void
1097 do_error(char *response)
1098 #else
1099 void
1100 do_error(response)
1101 char *response;
1102 #endif
1103 {
1104 if (raw)
1105 {
1106 printf("%s\n", response);
1107 }
1108 else
1109 {
1110 char *error;
1111
1112 error = rptp_parse(response, "error");
1113 if (!error || !*error)
1114 {
1115 error = response;
1116 }
1117 printf("%s\n", error);
1118 }
1119 }
1120
1121 void
1122 usage()
1123 {
1124 printf("\nrplay %s\n\n", RPLAY_VERSION);
1125 printf("usage: rptp [options] [command]\n");
1126 printf("--help\n");
1127 printf("\tDisplay helpful information.\n");
1128 printf("\n");
1129
1130 printf("-h HOST, --host=HOST\n");
1131 printf("\tSpecify the RPTP host, default = %s.\n",
1132 rplay_default_host());
1133 printf("\n");
1134
1135 printf("-p PORT, --port=PORT\n");
1136 printf("\tUse PORT instead of the default RPTP port, default = %d.\n", RPTP_PORT);
1137 printf("\n");
1138
1139 printf("-r, --raw\n");
1140 printf("\tEnable raw RPTP mode.\n");
1141 printf("\n");
1142
1143 printf("-v, --version\n");
1144 printf("\tDisplay rplay version information.\n");
1145 }
1146
1147 #ifdef __STDC__
1148 void
1149 done(int exit_value)
1150 #else
1151 void
1152 done(exit_value)
1153 int exit_value;
1154 #endif
1155 {
1156 exit(exit_value);
1157 }