Edinburgh Speech Tools  2.1-release
bcat_main.cc
Go to the documentation of this file.
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
6  /* All Rights Reserved. */
7  /* */
8  /* Permission is hereby granted, free of charge, to use and distribute */
9  /* this software and its documentation without restriction, including */
10  /* without limitation the rights to use, copy, modify, merge, publish, */
11  /* distribute, sublicense, and/or sell copies of this work, and to */
12  /* permit persons to whom this work is furnished to do so, subject to */
13  /* the following conditions: */
14  /* 1. The code must retain the above copyright notice, this list of */
15  /* conditions and the following disclaimer. */
16  /* 2. Any modifications must be clearly marked as such. */
17  /* 3. Original authors' names are not deleted. */
18  /* 4. The authors' names are not used to endorse or promote products */
19  /* derived from this software without specific prior written */
20  /* permission. */
21  /* */
22  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30  /* THIS SOFTWARE. */
31  /* */
32  /*************************************************************************/
33  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* Date: Thu Aug 14 1997 */
36  /* -------------------------------------------------------------------- */
37  /* A simple file concatenator which does everything in binary */
38  /* mode. For use in the tests on Windows etc. */
39  /* */
40  /*************************************************************************/
41 
42 
43 #include <cstdio>
44 #include "EST.h"
45 #include "EST_String.h"
46 #include "EST_error.h"
47 
48 using namespace std;
49 
50 #define BUFFER_SIZE (1024)
51 
52 int main(int argc, char *argv[])
53 {
54  EST_StrList files;
55  EST_Option settings, cmd_line;
56 
58  (argc, argv,
59  EST_String("-o [ofile] [files...]\n")+
60  "Summary; concatenate files in binary mode\n"+
61  "-o <ofile> Ouptut file of binary data\n",
62  files, cmd_line);
63 
64  EST_String out_file;
65 
66  if (cmd_line.present("-o"))
67  out_file = cmd_line.val("-o");
68  else
69  EST_error("No output file specified");
70 
71  FILE *dest;
72 
73  if ((dest=fopen(out_file, "wb")) == NULL) {
74  EST_sys_error("Can't create '%s'", (const char *)out_file);
75  return -1;
76  }
77 
78  EST_Litem *item;
79 
80  for(item=files.head(); item; item = item->next())
81  {
82  FILE *src;
83 
84  if ((src=fopen(files(item), "rb"))==NULL) {
85  EST_sys_error("can't read '%s'", (const char *)files(item));
86  return -1;
87  }
88 
89  unsigned int n;
90  char buf[BUFFER_SIZE];
91 
92  while((n=fread(buf, sizeof(char), BUFFER_SIZE, src)) >0)
93  if (fwrite(buf, sizeof(char), n, dest) < n)
94  EST_sys_error("write error");
95 
96  fclose(src);
97  }
98 
99  fclose(dest);
100 
101  return 0;
102 }
103 
104 
105 
106 
#define BUFFER_SIZE
Definition: bcat_main.cc:50
EST_UItem * next()
Definition: EST_UList.h:55
#define EST_sys_error
Definition: EST_error.h:108
NULL
Definition: EST_WFST.cc:55
#define EST_error
Definition: EST_error.h:104
int main(int argc, char *argv[])
Definition: bcat_main.cc:52
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
EST_UItem * head() const
Definition: EST_UList.h:97
EST_String
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
Definition: cmd_line.cc:101