dh-exec-install.c 2.09 KB
Newer Older
1
/* dh-exec-install.c -- Wrapper around dh-exec-install-magic.
Gergely Nagy's avatar
Gergely Nagy committed
2
 * Copyright (C) 2011-2015  Software Freedom Conservancy, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define _GNU_SOURCE

20 21
#include "config.h"

22
#include <fnmatch.h>
23
#include <string.h>
24 25 26 27
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

Gergely Nagy's avatar
Gergely Nagy committed
28
#include "dh-exec.lib.h"
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
static int
_match_extension (const char *src, const char *ext)
{
  char *glob;

  glob = malloc (strlen (ext) + 6);
  memcpy (glob, "*[./]", 5);
  memcpy (glob + 5, ext, strlen (ext) + 1);

  if (strcmp (src, ext) != 0 &&
      fnmatch (glob, src, 0) != 0)
    return 0;

  return 1;
}

46 47
static int
preamble(int argc, char *argv[])
48
{
49
  const char *src = dh_exec_source (argc, 1, argv);
50 51

  if (!src)
52 53 54 55
    {
      fprintf (stderr,
               "%s: Need an input file argument, stdin not acceptable!\n",
               argv[0]);
56
      return EXIT_FAILURE;
57 58
    }

59
  /* Handle cases where the source is not an .install file */
60 61
  if (!_match_extension (src, "install") &&
      !_match_extension (src, "manpages"))
62
    {
63 64
      /* Source is stdin, we're piped, ignore it. */
      if (argc < 2)
65
        return (dh_exec_ignore ());
66 67 68 69 70
      else
        {
          /* Source is from the command-line directly, raise an
             error. */
          fprintf (stderr,
71
                   "%s: Unsupported filename extension: %s\n",
72
                   argv[0], src);
73
          return EXIT_FAILURE;
74
        }
75 76
    }

77
  return 0;
78
}
79 80 81 82

#define dh_exec_simple_preamble preamble

#include "dh-exec.simple.c"