1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pagein.c,v $
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"
39 static int do_pagein (const char * filename
, size_t * size
)
42 file_image image
= FILE_IMAGE_INITIALIZER
;
44 if ((result
= file_image_open (&image
, filename
)) != 0)
47 if ((result
= file_image_pagein (&image
)) != 0)
49 fprintf (stderr
, "file_image_pagein: %s\n", strerror(result
));
50 goto cleanup_and_leave
;
59 file_image_close (&image
);
64 int main (int argc
, char **argv
)
67 size_t nfiles
= 0, nbytes
= 0;
73 "%s: Usage: pagein [-v[v]] [-L<path>] [@]<filename> ...\n",
78 for (i
= 1; i
< argc
; i
++)
83 if (argv
[i
][0] == '-')
91 for (v
+= 1, j
+= 1; argv
[i
][j
]; j
++)
92 v
+= (argv
[i
][j
] == 'v');
96 if (chdir (&(argv
[i
][2])) == -1)
97 fprintf (stderr
, "chdir: %s\n", strerror(errno
));
109 if ((argv
[i
][0] == '@') && ((fp
= fopen (argv
[i
], "r")) == 0))
112 if ((fp
= fopen (&(argv
[i
][1]), "r")) == 0)
114 fprintf (stderr
, "fopen: %s\n", strerror(errno
));
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 */
127 fprintf (stderr
, "pagein(\"%s\") = %d bytes\n", path
, (int) k
);
137 if (do_pagein (argv
[i
], &k
) == 0)
139 /* accumulate total size */
144 fprintf (stderr
, "pagein(\"%s\") = %d bytes\n", argv
[i
], (int) k
);
150 fprintf (stderr
, "Total: %d files (%d bytes)\n", (int) nfiles
, (int) nbytes
);