1 /*
2  * Common output functions for the regftools
3  *
4  * Copyright (C) 2009-2021, Joachim Metz <joachim.metz@gmail.com>
5  *
6  * Refer to AUTHORS for acknowledgements.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <common.h>
23 #include <file_stream.h>
24 #include <memory.h>
25 #include <types.h>
26 
27 #include "regftools_i18n.h"
28 #include "regftools_libbfio.h"
29 #include "regftools_libcerror.h"
30 #include "regftools_libclocale.h"
31 #include "regftools_libcnotify.h"
32 #include "regftools_libfdata.h"
33 #include "regftools_libfdatetime.h"
34 #include "regftools_libfwnt.h"
35 #include "regftools_libregf.h"
36 #include "regftools_libuna.h"
37 #include "regftools_output.h"
38 
39 /* Initializes output settings
40  * Returns 1 if successful or -1 on error
41  */
regftools_output_initialize(int stdio_mode,libcerror_error_t ** error)42 int regftools_output_initialize(
43      int stdio_mode,
44      libcerror_error_t **error )
45 {
46 	static char *function = "regftools_output_initialize";
47 
48 	if( ( stdio_mode != _IOFBF )
49 	 && ( stdio_mode != _IOLBF )
50 	 && ( stdio_mode != _IONBF ) )
51 	{
52 		libcerror_error_set(
53 		 error,
54 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
55 		 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
56 		 "%s: unsupported standard IO mode.",
57 		 function );
58 
59 		return( -1 );
60 	}
61 #if !defined( __BORLANDC__ )
62 	if( setvbuf(
63 	     stdout,
64 	     NULL,
65 	     stdio_mode,
66 	     0 ) != 0 )
67 	{
68 		libcerror_error_set(
69 		 error,
70 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
71 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
72 		 "%s: unable to set IO mode of stdout.",
73 		 function );
74 
75 		return( -1 );
76 	}
77 	if( setvbuf(
78 	     stderr,
79 	     NULL,
80 	     stdio_mode,
81 	     0 ) != 0 )
82 	{
83 		libcerror_error_set(
84 		 error,
85 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
86 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
87 		 "%s: unable to set IO mode of stderr.",
88 		 function );
89 
90 		return( -1 );
91 	}
92 #endif /* !defined( __BORLANDC__ ) */
93 
94 	return( 1 );
95 }
96 
97 /* Prints the copyright information
98  */
regftools_output_copyright_fprint(FILE * stream)99 void regftools_output_copyright_fprint(
100       FILE *stream )
101 {
102 	if( stream == NULL )
103 	{
104 		return;
105 	}
106 	/* TRANSLATORS: This is a proper name.
107 	 */
108 	fprintf(
109 	 stream,
110 	 _( "Copyright (C) 2009-2021, %s.\n" ),
111 	 _( "Joachim Metz" ) );
112 
113 	fprintf(
114 	 stream,
115 	 _( "This is free software; see the source for copying conditions. There is NO\n"
116 	    "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" ) );
117 
118 	/* TRANSLATORS: The placeholder indicates the bug-reporting address
119 	 * for this package.  Please add _another line_ saying
120 	 * "Report translation bugs to <...>\n" with the address for translation
121 	 * bugs (typically your translation team's web or email address).
122 	 */
123 	fprintf(
124 	 stream,
125 	 _( "Report bugs to <%s>.\n" ),
126 	 PACKAGE_BUGREPORT );
127 }
128 
129 /* Prints the version information
130  */
regftools_output_version_fprint(FILE * stream,const char * program)131 void regftools_output_version_fprint(
132       FILE *stream,
133       const char *program )
134 {
135 	if( stream == NULL )
136 	{
137 		return;
138 	}
139 	if( program == NULL )
140 	{
141 		return;
142 	}
143         fprintf(
144 	 stream,
145 	 "%s %s\n\n",
146          program,
147 	 LIBREGF_VERSION_STRING );
148 }
149 
150 /* Prints the detailed version information
151  */
regftools_output_version_detailed_fprint(FILE * stream,const char * program)152 void regftools_output_version_detailed_fprint(
153       FILE *stream,
154       const char *program )
155 {
156 	if( stream == NULL )
157 	{
158 		return;
159 	}
160 	if( program == NULL )
161 	{
162 		return;
163 	}
164         fprintf(
165 	 stream,
166 	 "%s %s (libregf %s",
167          program,
168 	 LIBREGF_VERSION_STRING,
169 	 LIBREGF_VERSION_STRING );
170 
171 	fprintf(
172 	 stream,
173 	 ", libuna %s",
174 	 LIBUNA_VERSION_STRING );
175 
176 	fprintf(
177 	 stream,
178 	 ", libbfio %s",
179 	 LIBBFIO_VERSION_STRING );
180 
181 	fprintf(
182 	 stream,
183 	 ", libfdata %s",
184 	 LIBFDATA_VERSION_STRING );
185 
186 	fprintf(
187 	 stream,
188 	 ", libfdatetime %s",
189 	 LIBFDATETIME_VERSION_STRING );
190 
191 	fprintf(
192 	 stream,
193 	 ", libfwnt %s",
194 	 LIBFWNT_VERSION_STRING );
195 
196         fprintf(
197 	 stream,
198 	 ")\n\n" );
199 }
200 
201