Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "file_image.h"
21 : #include "pagein.h"
22 :
23 : #include <unistd.h>
24 : #include <errno.h>
25 : #include <stdio.h>
26 : #include <string.h>
27 :
28 : /* do_pagein */
29 3402 : static void do_pagein (const char * filename)
30 : {
31 : int result;
32 3402 : file_image image = FILE_IMAGE_INITIALIZER;
33 :
34 3402 : if (file_image_open (&image, filename) != 0)
35 3402 : return;
36 :
37 3402 : if ((result = file_image_pagein (&image)) != 0)
38 : {
39 0 : fprintf (stderr, "file_image_pagein %s: %s\n", filename, strerror(result));
40 : }
41 :
42 3402 : file_image_close (&image);
43 : }
44 :
45 63 : void pagein_execute(char const * path, char const * file)
46 : {
47 : char fullpath[4096];
48 63 : char *p = NULL;
49 63 : FILE * fp = 0;
50 63 : memset(fullpath, 0, sizeof(fullpath));
51 63 : strncpy (fullpath, path, 3000);
52 63 : if (!(p = strrchr (fullpath, '/')))
53 0 : p = fullpath;
54 : else
55 63 : p++;
56 63 : strncpy(p, file, 1024);
57 63 : p[strlen(p)] = '\0';
58 63 : if ((fp = fopen (fullpath, "r")) == 0)
59 : {
60 :
61 0 : fprintf (stderr, "fopen %s: %s\n", fullpath, strerror(errno));
62 63 : return;
63 : }
64 3528 : while (fgets (p, 1024, fp) != 0)
65 : {
66 3402 : p[strlen(p) - 1] = '\0';
67 :
68 : /* paths relative to the location of the pagein file */
69 3402 : do_pagein (fullpath);
70 : }
71 63 : fclose (fp);
72 : }
73 :
74 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|