1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-out-gzip1.c:
4  *
5  * Copyright (C) 2002-2003-2006 Jody Goldberg (jody@gnome.org)
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2.1 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21 
22 #include <gsf/gsf-utils.h>
23 #include <gsf/gsf-output-stdio.h>
24 #include <gsf/gsf-output-gzip.h>
25 
26 #include <stdio.h>
27 
28 static int
test(int argc,char * argv[])29 test (int argc, char *argv[])
30 {
31 	GsfOutput *output;
32 	GsfOutput *gzout;
33 	GError   *err = NULL;
34 
35 	if (argc != 2) {
36 		fprintf (stderr, "Usage : %s outfile\n", argv[0]);
37 		return 1;
38 	}
39 
40 	output = gsf_output_stdio_new (argv[1], &err);
41 	if (output == NULL) {
42 		g_return_val_if_fail (err != NULL, 1);
43 
44 		g_warning ("'%s' error: %s", argv[1], err->message);
45 		g_error_free (err);
46 		return 1;
47 	}
48 
49 	gzout = gsf_output_gzip_new (output, &err);
50 	if (gzout == NULL) {
51 		g_return_val_if_fail (err != NULL, 1);
52 
53 		g_warning ("'%s' error: %s", "gzip output", err->message);
54 		g_error_free (err);
55 		return 1;
56 	}
57 
58 	if (!gsf_output_printf (gzout,
59 				"The %s sat on the %s.\n", "cat", "mat"))
60 		return 1;
61 	if (!gsf_output_printf (gzout, "%d %ss sat on the %s.\n",
62 				2, "cat", "mat"))
63 		return 1;
64 	if (!gsf_output_puts (gzout,
65 			      "The quick brown fox is afraid of the cats.\n"))
66 		return 1;
67 	if (!gsf_output_close (gzout))
68 		return 1;
69 	if (!gsf_output_close (output))
70 		return 1;
71 	g_object_unref (G_OBJECT (gzout));
72 	g_object_unref (G_OBJECT (output));
73 
74 	return 0;
75 }
76 
77 int
main(int argc,char * argv[])78 main (int argc, char *argv[])
79 {
80 	int res;
81 
82 	gsf_init ();
83 	res = test (argc, argv);
84 	gsf_shutdown ();
85 
86 	return res;
87 }
88