Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / mmdb / src / restore.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: restore.C /main/2 1996/11/11 11:10:03 drk $
24  *
25  * (c) Copyright 1996 Digital Equipment Corporation.
26  * (c) Copyright 1996 Hewlett-Packard Company.
27  * (c) Copyright 1996 International Business Machines Corp.
28  * (c) Copyright 1996 Sun Microsystems, Inc.
29  * (c) Copyright 1996 Novell, Inc. 
30  * (c) Copyright 1996 FUJITSU LIMITED.
31  * (c) Copyright 1996 Hitachi.
32  */
33
34 #include <fstream.h>
35 #include <strstream.h>
36
37 #include "utility/const.h"
38 #include "utility/randomize.h"
39
40 main(int argc, char** argv)
41 {
42   if (argc < 2) {
43     cerr << "usage: " << *argv << " filename\n" << flush;
44     return 1;
45   }
46
47   char schema_header[LBUFSIZ];
48   fstream fstr(*(argv+1), ios::in);
49
50   fstr.getline(schema_header, 1024);
51
52   int sz = bytes(fstr) - strlen(schema_header) - 1;
53
54   char* buf = new char[sz];
55
56   if ( !fstr.read(buf, sz) )
57     return 0;
58
59   fstr.close();
60
61   buffer orig(0);
62   orig.set_chunk(buf, sz);
63   orig.set_content_sz(sz);
64
65   randomize rd(233);
66   rd.restore(orig);
67
68   cout << buf << flush;
69 }
70