~ubuntu-branches/ubuntu/utopic/gettext/utopic

« back to all changes in this revision

Viewing changes to gettext-tools/src/open-catalog.c

  • Committer: Colin Watson
  • Date: 2010-08-01 21:36:08 UTC
  • mfrom: (2.1.10 sid)
  • Revision ID: cjwatson@canonical.com-20100801213608-yy7vkm8lpatep3ci
merge from Debian 0.18.1.1-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* open-po - search for .po file along search path list and open for reading
2
 
   Copyright (C) 1995-1996, 2000-2003, 2005-2007 Free Software Foundation, Inc.
 
2
   Copyright (C) 1995-1996, 2000-2003, 2005-2009 Free Software Foundation, Inc.
3
3
   Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
4
4
 
5
5
   This program is free software: you can redistribute it and/or modify
30
30
 
31
31
#include "dir-list.h"
32
32
#include "filename.h"
 
33
#include "concat-filename.h"
33
34
#include "xalloc.h"
34
35
#include "xvasprintf.h"
35
36
#include "po-xerror.h"
37
38
 
38
39
#define _(str) gettext (str)
39
40
 
40
 
/* This macro is used to determine the number of elements in an erray.  */
 
41
/* This macro is used to determine the number of elements in an array.  */
41
42
#define SIZEOF(a) (sizeof(a)/sizeof(a[0]))
42
43
 
43
44
static FILE *
61
62
  if (IS_ABSOLUTE_PATH (input_name))
62
63
    {
63
64
      for (k = 0; k < SIZEOF (extension); ++k)
64
 
        {
65
 
          file_name = concatenated_filename ("", input_name, extension[k]);
66
 
 
67
 
          ret_val = fopen (file_name, "r");
68
 
          if (ret_val != NULL || errno != ENOENT)
69
 
            {
70
 
              /* We found the file.  */
71
 
              *real_file_name_p = file_name;
72
 
              return ret_val;
73
 
            }
74
 
 
75
 
          free (file_name);
76
 
        }
 
65
        {
 
66
          file_name = xconcatenated_filename ("", input_name, extension[k]);
 
67
 
 
68
          ret_val = fopen (file_name, "r");
 
69
          if (ret_val != NULL || errno != ENOENT)
 
70
            {
 
71
              /* We found the file.  */
 
72
              *real_file_name_p = file_name;
 
73
              return ret_val;
 
74
            }
 
75
 
 
76
          free (file_name);
 
77
        }
77
78
    }
78
79
  else
79
80
    {
80
81
      /* For relative file names, look through the directory search list,
81
 
         trying the various extensions.  If no directory search list is
82
 
         specified, the current directory is used.  */
 
82
         trying the various extensions.  If no directory search list is
 
83
         specified, the current directory is used.  */
83
84
      for (j = 0; (dir = dir_list_nth (j)) != NULL; ++j)
84
 
        for (k = 0; k < SIZEOF (extension); ++k)
85
 
          {
86
 
            file_name = concatenated_filename (dir, input_name, extension[k]);
87
 
 
88
 
            ret_val = fopen (file_name, "r");
89
 
            if (ret_val != NULL || errno != ENOENT)
90
 
              {
91
 
                *real_file_name_p = file_name;
92
 
                return ret_val;
93
 
              }
94
 
 
95
 
            free (file_name);
96
 
          }
 
85
        for (k = 0; k < SIZEOF (extension); ++k)
 
86
          {
 
87
            file_name = xconcatenated_filename (dir, input_name, extension[k]);
 
88
 
 
89
            ret_val = fopen (file_name, "r");
 
90
            if (ret_val != NULL || errno != ENOENT)
 
91
              {
 
92
                *real_file_name_p = file_name;
 
93
                return ret_val;
 
94
              }
 
95
 
 
96
            free (file_name);
 
97
          }
97
98
    }
98
99
 
99
100
  /* File does not exist.  */
109
110
   purposes.  */
110
111
FILE *
111
112
open_catalog_file (const char *input_name, char **real_file_name_p,
112
 
                   bool exit_on_error)
 
113
                   bool exit_on_error)
113
114
{
114
115
  FILE *fp = try_open_catalog_file (input_name, real_file_name_p);
115
116
 
117
118
    {
118
119
      const char *errno_description = strerror (errno);
119
120
      po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
120
 
                 xasprintf ("%s: %s",
121
 
                            xasprintf (_("error while opening \"%s\" for reading"),
122
 
                                       *real_file_name_p),
123
 
                            errno_description));
 
121
                 xasprintf ("%s: %s",
 
122
                            xasprintf (_("error while opening \"%s\" for reading"),
 
123
                                       *real_file_name_p),
 
124
                            errno_description));
124
125
    }
125
126
 
126
127
  return fp;