xref: /aoo41x/main/registry/tools/regview.cxx (revision 51134e9e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_registry.hxx"
26 
27 #include "registry/registry.h"
28 #include "fileurl.hxx"
29 
30 #include "rtl/ustring.hxx"
31 
32 #include <stdio.h>
33 #include <string.h>
34 
35 using rtl::OUString;
36 using namespace registry::tools;
37 
38 #if (defined UNX) || (defined OS2)
main(int argc,char * argv[])39 int main( int argc, char * argv[] )
40 #else
41 int _cdecl main( int argc, char * argv[] )
42 #endif
43 {
44 	RegHandle 		hReg;
45 	RegKeyHandle	hRootKey, hKey;
46 
47 	if (argc < 2 || argc > 3)
48 	{
49 		fprintf(stderr, "using: regview registryfile [keyName]\n");
50 		exit(1);
51 	}
52 
53 	OUString regName( convertToFileUrl(argv[1], strlen(argv[1])) );
54 	if (reg_openRegistry(regName.pData, &hReg, REG_READONLY))
55 	{
56 		fprintf(stderr, "open registry \"%s\" failed\n", argv[1]);
57 		exit(1);
58 	}
59 
60 	if (!reg_openRootKey(hReg, &hRootKey))
61 	{
62 		if (argc == 3)
63 		{
64 			OUString keyName( OUString::createFromAscii(argv[2]) );
65 			if (!reg_openKey(hRootKey, keyName.pData, &hKey))
66 			{
67 				if (reg_dumpRegistry(hKey))
68 				{
69 					fprintf(stderr, "dumping registry \"%s\" failed\n", argv[1]);
70 				}
71 
72 				if (reg_closeKey(hKey))
73 				{
74 					fprintf(stderr, "closing key \"%s\" of registry \"%s\" failed\n",
75 							argv[2], argv[1]);
76 				}
77 			}
78             else
79 			{
80 				fprintf(stderr, "key \"%s\" not exists in registry \"%s\"\n",
81 						argv[2], argv[1]);
82 			}
83 		}
84         else
85 		{
86 			if (reg_dumpRegistry(hRootKey))
87 			{
88 				fprintf(stderr, "dumping registry \"%s\" failed\n", argv[1]);
89 			}
90 		}
91 
92 		if (reg_closeKey(hRootKey))
93 		{
94 			fprintf(stderr, "closing root key of registry \"%s\" failed\n", argv[1]);
95 		}
96 	}
97     else
98 	{
99 		fprintf(stderr, "open root key of registry \"%s\" failed\n", argv[1]);
100 	}
101 
102 	if (reg_closeRegistry(hReg))
103 	{
104 		fprintf(stderr, "closing registry \"%s\" failed\n", argv[1]);
105 		exit(1);
106 	}
107 
108 	return(0);
109 }
110 
111 
112