LCOV - code coverage report
Current view: top level - desktop/unx/source - pagein.c (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 60 0.0 %
Date: 2012-08-25 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 41 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "file_image.h"
      30                 :            : 
      31                 :            : #include <unistd.h>
      32                 :            : #include <errno.h>
      33                 :            : #include <stdio.h>
      34                 :            : #include <string.h>
      35                 :            : 
      36                 :            : /* do_pagein */
      37                 :          0 : static int do_pagein (const char * filename, size_t * size)
      38                 :            : {
      39                 :            :     int result;
      40                 :          0 :     file_image image = FILE_IMAGE_INITIALIZER;
      41                 :            : 
      42         [ #  # ]:          0 :     if ((result = file_image_open (&image, filename)) != 0)
      43                 :          0 :         return (result);
      44                 :            : 
      45         [ #  # ]:          0 :     if ((result = file_image_pagein (&image)) != 0)
      46                 :            :     {
      47                 :          0 :         fprintf (stderr, "file_image_pagein %s: %s\n", filename, strerror(result));
      48                 :          0 :         goto cleanup_and_leave;
      49                 :            :     }
      50                 :            : 
      51         [ #  # ]:          0 :     if (size)
      52                 :            :     {
      53                 :          0 :         *size = image.m_size;
      54                 :            :     }
      55                 :            : 
      56                 :            : cleanup_and_leave:
      57                 :          0 :     file_image_close (&image);
      58                 :          0 :     return (result);
      59                 :            : }
      60                 :            : 
      61                 :            : extern int pagein_execute (int argc, char **argv);
      62                 :            : 
      63                 :            : /* main */
      64                 :          0 : int pagein_execute (int argc, char **argv)
      65                 :            : {
      66                 :          0 :     int    i, v = 0;
      67                 :          0 :     size_t nfiles = 0, nbytes = 0;
      68                 :            : 
      69         [ #  # ]:          0 :     if (argc < 2)
      70                 :            :     {
      71                 :          0 :         fprintf (
      72                 :            :             stderr,
      73                 :            :             "%s: Usage: pagein [-v[v]] [-L<path>] [@]<filename> ...\n",
      74                 :            :             argv[0]);
      75                 :          0 :         return (1);
      76                 :            :     }
      77                 :            : 
      78         [ #  # ]:          0 :     for (i = 1; i < argc; i++)
      79                 :            :     {
      80                 :          0 :         FILE   * fp = 0;
      81                 :          0 :         size_t   k  = 0;
      82                 :            : 
      83         [ #  # ]:          0 :         if (argv[i][0] == '-')
      84                 :            :         {
      85                 :            :             /* option */
      86                 :          0 :             int j = 1;
      87      [ #  #  # ]:          0 :             switch (argv[i][j])
      88                 :            :             {
      89                 :            :                 case 'v':
      90                 :            :                     /* verbosity level */
      91         [ #  # ]:          0 :                     for (v += 1, j += 1; argv[i][j]; j++)
      92                 :          0 :                         v += (argv[i][j] == 'v');
      93                 :          0 :                     break;
      94                 :            :                 case 'L':
      95                 :            :                     /* search path */
      96         [ #  # ]:          0 :                     if (chdir (&(argv[i][2])) == -1)
      97                 :          0 :                         fprintf (stderr, "chdir %s: %s\n", &(argv[i][2]), strerror(errno));
      98                 :          0 :                     break;
      99                 :            :                 default:
     100                 :            :                     /* ignored */
     101                 :          0 :                     break;
     102                 :            :             }
     103                 :            : 
     104                 :            :             /* next argv */
     105                 :          0 :             continue;
     106                 :            :         }
     107                 :            : 
     108 [ #  # ][ #  # ]:          0 :         if ((argv[i][0] == '@') && ((fp = fopen (argv[i], "r")) == 0))
     109                 :          0 :         {
     110                 :            :             char fullpath[4096];
     111                 :          0 :             char *path = NULL;
     112                 :          0 :             memset(fullpath, 0, sizeof(fullpath));
     113                 :          0 :             strncpy (fullpath, argv[i] + 1, 3000);
     114         [ #  # ]:          0 :             if (!(path = strrchr (fullpath, '/')))
     115                 :          0 :                 path = fullpath;
     116                 :            :             else
     117                 :          0 :                 path++;
     118                 :            : 
     119         [ #  # ]:          0 :             if ((fp = fopen (&(argv[i][1]), "r")) == 0)
     120                 :            :             {
     121                 :          0 :                 fprintf (stderr, "fopen %s: %s\n", &(argv[i][1]), strerror(errno));
     122                 :          0 :                 continue;
     123                 :            :             }
     124         [ #  # ]:          0 :             while (fgets (path, 1024, fp) != 0)
     125                 :            :             {
     126                 :          0 :                 path[strlen(path) - 1] = '\0', k = 0;
     127                 :            : 
     128                 :            :                 /* paths relative to the location of the pagein file */
     129         [ #  # ]:          0 :                 if (do_pagein (fullpath, &k) == 0)
     130                 :            :                 {
     131                 :            :                     /* accumulate total size */
     132                 :          0 :                     nbytes += k;
     133                 :            :                 }
     134                 :            : 
     135         [ #  # ]:          0 :                 if (v >= 2)
     136                 :          0 :                     fprintf (stderr, "pagein(\"%s\") = %d bytes\n", path, (int) k);
     137                 :          0 :                 nfiles += 1;
     138                 :            :             }
     139                 :          0 :             fclose (fp);
     140                 :            :         }
     141                 :            :         else
     142                 :            :         {
     143         [ #  # ]:          0 :             if (fp != 0)
     144                 :          0 :                 fclose (fp);
     145                 :            : 
     146         [ #  # ]:          0 :             if (do_pagein (argv[i], &k) == 0)
     147                 :            :             {
     148                 :            :                 /* accumulate total size */
     149                 :          0 :                 nbytes += k;
     150                 :            :             }
     151                 :            : 
     152         [ #  # ]:          0 :             if (v >= 2)
     153                 :          0 :                 fprintf (stderr, "pagein(\"%s\") = %d bytes\n", argv[i], (int) k);
     154                 :          0 :             nfiles += 1;
     155                 :            :         }
     156                 :            :     }
     157                 :            : 
     158         [ #  # ]:          0 :     if (v >= 1)
     159                 :          0 :         fprintf (stderr, "Total: %d files (%d bytes)\n", (int) nfiles, (int) nbytes);
     160                 :          0 :     return (0);
     161                 :            : }
     162                 :            : 
     163                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10