Changeset 4927:8fa254c85099 in roaraudio


Ignore:
Timestamp:
05/08/11 11:29:38 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added a pass mode to roarvio

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/man1/roarvio.1

    r4900 r4927  
    99.SH SYNOPSIS 
    1010 
    11 roarvio [OPTIONS]... FILE 
     11roarvio [OPTIONS]... FILE [FILE] 
    1212 
    1313.SH DESCRIPTION 
     
    3434 
    3535.TP 
     36\fB--pass\fR 
     37Pass mode (like 'cat infile > outfile'). 
     38 
     39.TP 
    3640\fB--explain\fR 
    3741Explain VIO object. This will report some information on the internal data structure of the VIO object. Use \fB--verbose\fR for more information. 
  • roarclients/roarvio.c

    r4886 r4927  
    3535 READ, 
    3636 WRITE, 
     37 PASS, 
    3738 EXPLAIN 
    3839}; 
     
    4041 
    4142void usage (const char * progname) { 
    42  fprintf(stderr, "Usage: %s [OPTIONS]... FILE\n", progname); 
     43 fprintf(stderr, "Usage: %s [OPTIONS]... FILE [FILE]\n", progname); 
    4344 
    4445 fprintf(stderr, "\nOptions:\n\n"); 
     
    4849                 "    --read         - Reading mode (like 'cat file').\n" 
    4950                 "    --write        - Writing mode (like 'cat > file').\n" 
     51                 "    --pass         - Passing mode (like 'cat infile > outfile').\n" 
    5052                 "    --explain      - Explain VIO object.\n"); 
    5153} 
     
    157159int main (int argc, char * argv[]) { 
    158160 struct roar_vio_defaults def; 
    159  struct roar_vio_calls vio; 
     161 struct roar_vio_calls vio0, vio1; 
    160162 enum action action = READ; 
    161163 int i; 
    162164 char * k; 
    163  char * file = NULL; 
     165 char * file0 = NULL; 
     166 char * file1 = NULL; 
    164167 int o_flags = -1; 
    165168 int ret = 0; 
     
    175178  } else if ( !strcmp(k, "--write") ) { 
    176179   action = WRITE; 
     180  } else if ( !strcmp(k, "--pass") ) { 
     181   action = PASS; 
    177182  } else if ( !strcmp(k, "--explain") ) { 
    178183   action = EXPLAIN; 
    179184  } else if ( !strcmp(k, "--verbose") ) { 
    180185   g_verbose++; 
    181   } else if ( file == NULL ) { 
    182    file = k; 
     186  } else if ( file0 == NULL ) { 
     187   file0 = k; 
     188  } else if ( file1 == NULL ) { 
     189   file1 = k; 
    183190  } else { 
    184191   ROAR_ERR("Too many parameters or unknown parameter: %s", k); 
     
    188195 } 
    189196 
    190  if ( file == NULL ) { 
     197 if ( file0 == NULL ) { 
     198  usage(argv[0]); 
     199  return 1; 
     200 } 
     201 
     202 if ( (file1 != NULL && action != PASS) || (action == PASS && file1 == NULL) ) { 
    191203  usage(argv[0]); 
    192204  return 1; 
     
    195207 switch (action) { 
    196208  case READ: 
     209  case PASS: 
    197210  case EXPLAIN: 
    198211    o_flags = O_RDONLY; 
     
    213226 } 
    214227 
    215  if ( roar_vio_open_dstr(&vio, file, &def, 1) == -1 ) { 
    216   ROAR_ERR("Can not open file: %s: %s", file, roar_error2str(roar_error)); 
    217   return 1; 
     228 if ( roar_vio_open_dstr(&vio0, file0, &def, 1) == -1 ) { 
     229  ROAR_ERR("Can not open file: %s: %s", file0, roar_error2str(roar_error)); 
     230  return 1; 
     231 } 
     232 
     233 if ( action == PASS ) { 
     234  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) { 
     235   ROAR_ERR("Can not init DSTR defaults. Bad."); 
     236   roar_vio_close(&vio0); 
     237   return 1; 
     238  } 
     239 
     240  if ( roar_vio_open_dstr(&vio1, file1, &def, 1) == -1 ) { 
     241   ROAR_ERR("Can not open file: %s: %s", file1, roar_error2str(roar_error)); 
     242   roar_vio_close(&vio0); 
     243   return 1; 
     244  } 
    218245 } 
    219246 
    220247 switch (action) { 
    221248  case READ: 
    222     roar_vio_copy_data(roar_stdout, &vio); 
     249    roar_vio_copy_data(roar_stdout, &vio0); 
    223250   break; 
    224251  case WRITE: 
    225     roar_vio_copy_data(&vio, roar_stdin); 
     252    roar_vio_copy_data(&vio0, roar_stdin); 
     253   break; 
     254  case PASS: 
     255    roar_vio_copy_data(&vio1, &vio0); 
    226256   break; 
    227257  case EXPLAIN: 
    228     if ( do_explain(&vio) == -1 ) 
     258    if ( do_explain(&vio0) == -1 ) 
    229259     ret = 4; 
    230260   break; 
     
    235265 } 
    236266 
    237  roar_vio_close(&vio); 
     267 roar_vio_close(&vio0); 
     268 if ( file1 != NULL ) 
     269  roar_vio_close(&vio1); 
    238270 
    239271 return ret; 
Note: See TracChangeset for help on using the changeset viewer.