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.
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)
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.
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. */
25
#include <sys/types.h>
34
#include "libgettext.h"
36
#define _(str) gettext (str)
42
/* Prototypes for helper functions. */
43
extern char *xstrdup PARAMS ((const char *string));
45
/* This macro is used to determine the number of elements in an erray. */
46
#define SIZEOF(a) (sizeof(a)/sizeof(a[0]))
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. */
53
open_po_file (input_name, file_name)
54
const char *input_name;
57
static const char *extension[] = { "", ".po", ".pot", };
62
if (strcmp (input_name, "-") == 0 || strcmp (input_name, "/dev/stdin") == 0)
64
*file_name = xstrdup (_("<stdin>"));
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))
72
for (k = 0; k < SIZEOF (extension); ++k)
74
*file_name = concatenated_pathname ("", input_name, extension[k]);
76
ret_val = fopen (*file_name, "r");
77
if (ret_val != NULL || errno != ENOENT)
78
/* We found the file. */
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)
92
*file_name = concatenated_pathname (dir, input_name, extension[k]);
94
ret_val = fopen (*file_name, "r");
95
if (ret_val != NULL || errno != ENOENT)
102
/* File does not exist. */
103
*file_name = xstrdup (input_name);