~ubuntu-branches/debian/squeeze/ffcall/squeeze

« back to all changes in this revision

Viewing changes to src/m4/filecharset.m4

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2010-06-26 15:29:30 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100626152930-c09y01gk3szcnykn
Tags: 1.10+cvs20100619-2
Ship to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
dnl -*- Autoconf -*-
2
 
dnl Copyright (C) 1993-2004 Free Software Foundation, Inc.
3
 
dnl This file is free software, distributed under the terms of the GNU
4
 
dnl General Public License.  As a special exception to the GNU General
5
 
dnl Public License, this file may be distributed as part of a program
6
 
dnl that contains a configuration script generated by Autoconf, under
7
 
dnl the same distribution terms as the rest of that program.
8
 
 
9
 
dnl From Bruno Haible, Marcus Daniels, Sam Steingold.
10
 
 
11
 
AC_PREREQ(2.13)
12
 
 
13
 
AC_DEFUN([CL_FILECHARSET],
14
 
[AC_REQUIRE([AC_PROG_CC])dnl
15
 
AC_REQUIRE([CL_CLOSEDIR])dnl
16
 
AC_MSG_CHECKING(for the valid characters in filenames)
17
 
AC_CACHE_VAL(cl_cv_os_valid_filename_char,[
18
 
if test $cross_compiling = no; then
19
 
dnl Create the subdirectory the test program will use for its files.
20
 
mkdir conftestdir
21
 
cat > conftest.c <<EOF
22
 
#include "confdefs.h"
23
 
#include <sys/types.h>
24
 
#include <stdlib.h>
25
 
/* Declare chdir(). */
26
 
#ifdef HAVE_UNISTD_H
27
 
#include <unistd.h>
28
 
#endif
29
 
#include <string.h>
30
 
#include <stdio.h>
31
 
/* Declare open(). */
32
 
#include <fcntl.h>
33
 
#ifdef OPEN_NEEDS_SYS_FILE_H
34
 
#include <sys/file.h>
35
 
#endif
36
 
/* Declare opendir(), readdir(), closedir(). */
37
 
#include <$ac_header_dirent>
38
 
#ifdef DIRENT
39
 
#define SDIRENT struct dirent
40
 
#else
41
 
#define SDIRENT struct direct
42
 
#endif
43
 
changequote(,)dnl
44
 
/* A small program which checks for each character whether or not it is
45
 
 * valid in filenames. */
46
 
#define N 256
47
 
int main ()
48
 
{
49
 
#if defined(__CYGWIN32__) || defined(__MINGW32__)
50
 
  /* The test below would cause a dialog box to pop up (ch == ':'),
51
 
     and create files which cause "rm -rf conftest*" to hang
52
 
     (ch == '"') || (ch == '<') || (ch == '>') || (ch == 197) || (ch == 206).
53
 
     Also, it would make appear that (ch >= 'A') && (ch <= 'Z') doesn't work,
54
 
     because it would create files in lower case. But we don't want to forbid
55
 
     upper case letters in file names. */
56
 
  printf("(ch >= 1) && (ch <= 127) && (ch != 34) && (ch != 42) && (ch != 47) && (ch != 58) && (ch != 60) && (ch != 62) && (ch != 63) && (ch != 92) || (ch == 131) || (ch >= 160) && (ch != 197) && (ch != 206)\n");
57
 
#else
58
 
  char legal[N];
59
 
  char filename[4];
60
 
  int i;
61
 
  if (chdir("conftestdir") < 0) exit(1);
62
 
  for (i = 0; i < N; i++) legal[i] = 0;
63
 
  strcpy(filename,"a_z");
64
 
  for (i = 0; i < N; i++)
65
 
    if (i != '\0')
66
 
      { filename[1] = i;
67
 
        /* Determine whether the filename is valid: create a file
68
 
         * and check that it is present afterwards, under the same name. */
69
 
        { int fd = open(filename, O_CREAT | O_RDWR, 0644);
70
 
          if (fd >=0)
71
 
            { DIR* dirp = opendir(".");
72
 
              if (dirp != (DIR*)0)
73
 
                { SDIRENT* d;
74
 
                  while ((d = readdir(dirp)))
75
 
                    { if (!strcmp(d->d_name,".")) continue;
76
 
                      if (!strcmp(d->d_name,"..")) continue;
77
 
                      if (!strncmp(d->d_name,".nfs",4)) continue;
78
 
                      if (!strcmp(d->d_name,filename)) legal[i] = 1;
79
 
                      /* Remove the file even if its name is something else. */
80
 
                      unlink(d->d_name);
81
 
                    }
82
 
                  closedir(dirp);
83
 
                }
84
 
              close(fd);
85
 
      } }   }
86
 
  /* Output a boolean expression equivalent to legal[ch] (0 <= ch < N). */
87
 
  { int need_or = 0;
88
 
    int z;
89
 
    for (z = 0; z < N; )
90
 
      { int x, y;
91
 
        if (! legal[z]) { z++; continue; }
92
 
        x = z;
93
 
        if (need_or) printf(" || ");
94
 
        z++;
95
 
        if ((z < N) && legal[z])
96
 
          { do { do { z++; } while ((z < N) && legal[z]);
97
 
                 y = z-1;
98
 
                 z++;
99
 
               } while ((z < N) && legal[z]);
100
 
            { int premises = 0;
101
 
              if (x > 0) premises++;
102
 
              if (y < N-1) premises++;
103
 
              for (i = x; i <= y; i++)
104
 
                if (! legal[i])
105
 
                  premises++;
106
 
              if (premises > 1) printf("(");
107
 
              { int need_and = 0;
108
 
                if (x > 0) { printf("(ch >= %d)",x); need_and = 1; }
109
 
                if (y < N-1)
110
 
                  { if (need_and) printf(" && ");
111
 
                    printf("(ch <= %d)",y);
112
 
                    need_and = 1;
113
 
                  }
114
 
                for (i = x; i <= y; i++)
115
 
                  if (! legal[i])
116
 
                    { if (need_and) printf(" && ");
117
 
                      printf("(ch != %d)",i);
118
 
                      need_and = 1;
119
 
                    }
120
 
                if (!need_and) printf("1");
121
 
              }
122
 
              if (premises > 1) printf(")");
123
 
            }
124
 
            z = y+1;
125
 
          }
126
 
          else
127
 
          { printf("(ch == %d)",x); z++; }
128
 
        need_or = 1;
129
 
      }
130
 
    printf("\n");
131
 
  }
132
 
#endif
133
 
  exit(0);
134
 
}
135
 
changequote([,])dnl
136
 
EOF
137
 
AC_TRY_EVAL(ac_link)
138
 
cl_cv_os_valid_filename_char=`./conftest`
139
 
# Workaround a problem with NFS on Solaris 7, where unlink()ed files reappear
140
 
# immediately under a different name and disappear only after 1. the process
141
 
# doing readdir() has exited and 2. waiting a second or two.
142
 
# Even "rm -rf conftestdir" goes into an endless loop, eating CPU time, under
143
 
# these conditions.
144
 
period=1
145
 
while test -n "`ls conftestdir/.nfs* 2>/dev/null`"; do
146
 
  echo "waiting for NFS..."
147
 
  rm -f conftestdir/.nfs* 2>/dev/null
148
 
  sleep $period
149
 
  period=`expr 2 '*' $period`
150
 
done
151
 
# Now it's safe to do "rm -rf conftestdir".
152
 
fi
153
 
rm -rf conftest*
154
 
])
155
 
if test -z "$cl_cv_os_valid_filename_char"; then
156
 
  cl_cv_os_valid_filename_charset="guessing 7-bit"
157
 
else
158
 
  if test "$cl_cv_os_valid_filename_char" = '((ch >= 1) && (ch != 47))'; then
159
 
    cl_cv_os_valid_filename_charset="8-bit"
160
 
  else
161
 
    cl_cv_os_valid_filename_charset="7-bit"
162
 
  fi
163
 
fi
164
 
AC_MSG_RESULT($cl_cv_os_valid_filename_charset)
165
 
if test -n "$cl_cv_os_valid_filename_char"; then
166
 
  AC_DEFINE_UNQUOTED(VALID_FILENAME_CHAR,$cl_cv_os_valid_filename_char,[expression in ch which is true if ch is a valid character in filenames])
167
 
fi
168
 
])