~ubuntu-branches/ubuntu/trusty/gettext/trusty

« back to all changes in this revision

Viewing changes to src/open-po.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2002-04-10 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20020410131742-npf89tsaygdolprj
Tags: upstream-0.10.40
ImportĀ upstreamĀ versionĀ 0.10.40

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* open-po - search for .po file along search path list and open for reading
 
2
   Copyright (C) 1995-1996, 2000, 2001 Free Software Foundation, Inc.
 
3
   Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
 
4
 
 
5
This program is free software; you can redistribute it and/or modify
 
6
it under the terms of the GNU General Public License as published by
 
7
the Free Software Foundation; either version 2, or (at your option)
 
8
any later version.
 
9
 
 
10
This program is distributed in the hope that it will be useful,
 
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
GNU General Public License for more details.
 
14
 
 
15
You should have received a copy of the GNU General Public License
 
16
along with this program; if not, write to the Free Software
 
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
# include <config.h>
 
21
#endif
 
22
 
 
23
#include <errno.h>
 
24
#include <stdio.h>
 
25
#include <sys/types.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
 
 
29
#include "open-po.h"
 
30
#include "dir-list.h"
 
31
#include "error.h"
 
32
#include "system.h"
 
33
 
 
34
#include "libgettext.h"
 
35
 
 
36
#define _(str) gettext (str)
 
37
 
 
38
#ifndef errno
 
39
extern int errno;
 
40
#endif
 
41
 
 
42
/* Prototypes for helper functions.  */
 
43
extern char *xstrdup PARAMS ((const char *string));
 
44
 
 
45
/* This macro is used to determine the number of elements in an erray.  */
 
46
#define SIZEOF(a) (sizeof(a)/sizeof(a[0]))
 
47
 
 
48
/* Open the input file with the name INPUT_NAME.  The ending .po is added
 
49
   if necessary.  If INPUT_NAME is not an absolute file name and the file is
 
50
   not found, the list of directories in "dir-list.h" is searched.  The
 
51
   file's pathname is returned in *FILE_NAME, for error message purposes.  */
 
52
FILE *
 
53
open_po_file (input_name, file_name)
 
54
     const char *input_name;
 
55
     char **file_name;
 
56
{
 
57
  static const char *extension[] = { "", ".po", ".pot", };
 
58
  FILE *ret_val;
 
59
  int j, k;
 
60
  const char *dir;
 
61
 
 
62
  if (strcmp (input_name, "-") == 0 || strcmp (input_name, "/dev/stdin") == 0)
 
63
    {
 
64
      *file_name = xstrdup (_("<stdin>"));
 
65
      return stdin;
 
66
    }
 
67
 
 
68
  /* We have a real name for the input file.  If the name is absolute,
 
69
     try the various extensions, but ignore the directory search list.  */
 
70
  if (IS_ABSOLUTE_PATH (input_name))
 
71
    {
 
72
      for (k = 0; k < SIZEOF (extension); ++k)
 
73
        {
 
74
          *file_name = concatenated_pathname ("", input_name, extension[k]);
 
75
 
 
76
          ret_val = fopen (*file_name, "r");
 
77
          if (ret_val != NULL || errno != ENOENT)
 
78
            /* We found the file.  */
 
79
            return ret_val;
 
80
 
 
81
          free (*file_name);
 
82
        }
 
83
    }
 
84
  else
 
85
    {
 
86
      /* For relative file names, look through the directory search list,
 
87
         trying the various extensions.  If no directory search list is
 
88
         specified, the current directory is used.  */
 
89
      for (j = 0; (dir = dir_list_nth (j)) != NULL; ++j)
 
90
        for (k = 0; k < SIZEOF (extension); ++k)
 
91
          {
 
92
            *file_name = concatenated_pathname (dir, input_name, extension[k]);
 
93
 
 
94
            ret_val = fopen (*file_name, "r");
 
95
            if (ret_val != NULL || errno != ENOENT)
 
96
              return ret_val;
 
97
 
 
98
            free (*file_name);
 
99
          }
 
100
    }
 
101
 
 
102
  /* File does not exist.  */
 
103
  *file_name = xstrdup (input_name);
 
104
  errno = ENOENT;
 
105
  return NULL;
 
106
}