source: roaraudio/roarclients/roarvio.c @ 4835:002e0a1371ed

Last change on this file since 4835:002e0a1371ed was 4835:002e0a1371ed, checked in by phi, 13 years ago

support reading and writing to a file via VIO

File size: 2.4 KB
Line 
1//roarvio.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27#include <errno.h>
28#include <string.h>
29
30enum action {
31 READ,
32 WRITE
33};
34
35void usage (const char * progname) {
36}
37
38int main (int argc, char * argv[]) {
39 struct roar_vio_defaults def;
40 struct roar_vio_calls vio;
41 enum action action = READ;
42 int i;
43 char * k;
44 char * file = NULL;
45 int o_flags = -1;
46
47 for (i = 1; i < argc; i++) {
48  k = argv[i];
49
50  if ( !strcmp(k, "-h") || !strcmp(k, "--help") ) {
51   usage(argv[0]);
52   return 0;
53  } else if ( !strcmp(k, "--read") ) {
54   action = READ;
55  } else if ( !strcmp(k, "--write") ) {
56   action = WRITE;
57  } else if ( file == NULL ) {
58   file = k;
59  } else {
60   ROAR_ERR("Too many parameters or unknown parameter: %s", k);
61   usage(argv[0]);
62   return 1;
63  }
64 }
65
66 if ( file == NULL ) {
67  usage(argv[0]);
68  return 1;
69 }
70
71 switch (action) {
72  case READ:
73    o_flags = O_RDONLY;
74   break;
75  case WRITE:
76    o_flags = O_WRONLY|O_CREAT|O_TRUNC;
77   break;
78 }
79
80 if ( o_flags == -1 ) {
81  ROAR_ERR("o_flags unset, very bad. This should never happen.");
82  return 1;
83 }
84
85 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, o_flags, 0644) == -1 ) {
86  ROAR_ERR("Can not init DSTR defaults. Bad.");
87  return 1;
88 }
89
90 if ( roar_vio_open_dstr(&vio, file, &def, 1) == -1 ) {
91  ROAR_ERR("Can not open file: %s: %s", file, strerror(errno));
92  return 1;
93 }
94
95 switch (action) {
96  case READ:
97    roar_vio_copy_data(roar_stdout, &vio);
98   break;
99  case WRITE:
100    roar_vio_copy_data(&vio, roar_stdin);
101   break;
102 }
103
104 roar_vio_close(&vio);
105
106 return 0;
107}
108
109//ll
Note: See TracBrowser for help on using the repository browser.