1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "file_image.h"
28 static int do_pagein (const char * filename
, size_t * size
)
31 file_image image
= FILE_IMAGE_INITIALIZER
;
33 if ((result
= file_image_open (&image
, filename
)) != 0)
36 if ((result
= file_image_pagein (&image
)) != 0)
38 fprintf (stderr
, "file_image_pagein %s: %s\n", filename
, strerror(result
));
39 goto cleanup_and_leave
;
48 file_image_close (&image
);
52 extern int pagein_execute (int argc
, char **argv
);
55 int pagein_execute (int argc
, char **argv
)
58 size_t nfiles
= 0, nbytes
= 0;
64 "%s: Usage: pagein [-v[v]] [-L<path>] [@]<filename> ...\n",
69 for (i
= 1; i
< argc
; i
++)
74 if (argv
[i
][0] == '-')
82 for (v
+= 1, j
+= 1; argv
[i
][j
]; j
++)
83 v
+= (argv
[i
][j
] == 'v');
87 if (chdir (&(argv
[i
][2])) == -1)
88 fprintf (stderr
, "chdir %s: %s\n", &(argv
[i
][2]), strerror(errno
));
99 if ((argv
[i
][0] == '@') && ((fp
= fopen (argv
[i
], "r")) == 0))
103 memset(fullpath
, 0, sizeof(fullpath
));
104 strncpy (fullpath
, argv
[i
] + 1, 3000);
105 if (!(path
= strrchr (fullpath
, '/')))
110 if ((fp
= fopen (&(argv
[i
][1]), "r")) == 0)
112 fprintf (stderr
, "fopen %s: %s\n", &(argv
[i
][1]), strerror(errno
));
115 while (fgets (path
, 1024, fp
) != 0)
117 path
[strlen(path
) - 1] = '\0', k
= 0;
119 /* paths relative to the location of the pagein file */
120 if (do_pagein (fullpath
, &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
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */