File: dtou.sh

package info (click to toggle)
allegro4.4 2:4.4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,744 kB
  • sloc: ansic: 164,458; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,107; python: 676; pascal: 179; makefile: 55; perl: 29; lisp: 1
file content (47 lines) | stat: -rwxr-xr-x 910 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#
# Convert CR/LF line endings to LF line endings, preserving timestamps and
# permissions on the file.
#

with_unix_tools() {
   for file in "$@"
   do
      echo "$file"

      tmpfile=`dirname "$file"`/__dtou_tmp.$RANDOM || exit 1
      trap 'rm -f "$tmpfile"' 1 2 3 13 15

      # We go through a slightly convoluted sequence of commands in order to
      # preserve both the timestamp and permissions on the file.
      {
         tr -d '\015' < "$file" > "$tmpfile" &&
         touch -r "$file" "$tmpfile" &&
         cat "$tmpfile" > "$file" &&
         touch -r "$tmpfile" "$file" &&
         rm -f "$tmpfile"
      } || exit 1
   done
}

with_cygwin() {
   for file in "$@"
   do
      dos2unix $file || exit 1
   done
}

if test -z "$1"
then
   echo "$0 filename"
   exit
fi

if test "$ALLEGRO_USE_CYGWIN" = "1"
then
   with_cygwin "$@"
else
   with_unix_tools "$@"
fi

# vi: sts=3 sw=3 et