//roarvio.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011 * * This file is part of roarclients a part of RoarAudio, * a cross-platform sound system for both, home and professional use. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include #include #include enum action { READ, WRITE }; void usage (const char * progname) { } int main (int argc, char * argv[]) { struct roar_vio_defaults def; struct roar_vio_calls vio; enum action action = READ; int i; char * k; char * file = NULL; int o_flags = -1; for (i = 1; i < argc; i++) { k = argv[i]; if ( !strcmp(k, "-h") || !strcmp(k, "--help") ) { usage(argv[0]); return 0; } else if ( !strcmp(k, "--read") ) { action = READ; } else if ( !strcmp(k, "--write") ) { action = WRITE; } else if ( file == NULL ) { file = k; } else { ROAR_ERR("Too many parameters or unknown parameter: %s", k); usage(argv[0]); return 1; } } if ( file == NULL ) { usage(argv[0]); return 1; } switch (action) { case READ: o_flags = O_RDONLY; break; case WRITE: o_flags = O_WRONLY|O_CREAT|O_TRUNC; break; } if ( o_flags == -1 ) { ROAR_ERR("o_flags unset, very bad. This should never happen."); return 1; } if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, o_flags, 0644) == -1 ) { ROAR_ERR("Can not init DSTR defaults. Bad."); return 1; } if ( roar_vio_open_dstr(&vio, file, &def, 1) == -1 ) { ROAR_ERR("Can not open file: %s: %s", file, strerror(errno)); return 1; } switch (action) { case READ: roar_vio_copy_data(roar_stdout, &vio); break; case WRITE: roar_vio_copy_data(&vio, roar_stdin); break; } roar_vio_close(&vio); return 0; } //ll