merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / pagein / pagein.c
blob7f00c86e8e6602336308748b046bf410bdfd9163
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pagein.c,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "file_image.h"
33 #include <unistd.h>
34 #include <errno.h>
35 #include <stdio.h>
36 #include <string.h>
38 /* do_pagein */
39 static int do_pagein (const char * filename, size_t * size)
41 int result;
42 file_image image = FILE_IMAGE_INITIALIZER;
44 if ((result = file_image_open (&image, filename)) != 0)
45 return (result);
47 if ((result = file_image_pagein (&image)) != 0)
49 fprintf (stderr, "file_image_pagein: %s\n", strerror(result));
50 goto cleanup_and_leave;
53 if (size)
55 *size = image.m_size;
58 cleanup_and_leave:
59 file_image_close (&image);
60 return (result);
63 /* main */
64 int main (int argc, char **argv)
66 int i, v = 0;
67 size_t nfiles = 0, nbytes = 0;
69 if (argc < 2)
71 fprintf (
72 stderr,
73 "%s: Usage: pagein [-v[v]] [-L<path>] [@]<filename> ...\n",
74 argv[0]);
75 return (1);
78 for (i = 1; i < argc; i++)
80 FILE * fp = 0;
81 size_t k = 0;
83 if (argv[i][0] == '-')
85 /* option */
86 int j = 1;
87 switch (argv[i][j])
89 case 'v':
90 /* verbosity level */
91 for (v += 1, j += 1; argv[i][j]; j++)
92 v += (argv[i][j] == 'v');
93 break;
94 case 'L':
95 /* search path */
96 if (chdir (&(argv[i][2])) == -1)
97 fprintf (stderr, "chdir: %s\n", strerror(errno));
98 break;
99 default:
100 /* ignored */
101 break;
104 /* next argv */
105 continue;
109 if ((argv[i][0] == '@') && ((fp = fopen (argv[i], "r")) == 0))
111 char path[1024];
112 if ((fp = fopen (&(argv[i][1]), "r")) == 0)
114 fprintf (stderr, "fopen: %s\n", strerror(errno));
115 continue;
117 while (fgets (path, sizeof(path), fp) != 0)
119 path[strlen(path) - 1] = '\0', k = 0;
120 if (do_pagein (path, &k) == 0)
122 /* accumulate total size */
123 nbytes += k;
126 if (v >= 2)
127 fprintf (stderr, "pagein(\"%s\") = %d bytes\n", path, (int) k);
128 nfiles += 1;
130 fclose (fp);
132 else
134 if (fp != 0)
135 fclose (fp);
137 if (do_pagein (argv[i], &k) == 0)
139 /* accumulate total size */
140 nbytes += k;
143 if (v >= 2)
144 fprintf (stderr, "pagein(\"%s\") = %d bytes\n", argv[i], (int) k);
145 nfiles += 1;
149 if (v >= 1)
150 fprintf (stderr, "Total: %d files (%d bytes)\n", (int) nfiles, (int) nbytes);
151 return (0);