/js/src/ctypes/libffi/mdate-sh

http://github.com/zpao/v8monkey · Shell · 201 lines · 107 code · 18 blank · 76 comment · 3 complexity · ba25b8a8910b7416a09ad23611286acb MD5 · raw file

  1. #!/bin/sh
  2. # Get modification time of a file or directory and pretty-print it.
  3. scriptversion=2005-06-29.22
  4. # Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005 Free Software
  5. # Foundation, Inc.
  6. # written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software Foundation,
  20. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. # As a special exception to the GNU General Public License, if you
  22. # distribute this file as part of a program that contains a
  23. # configuration script generated by Autoconf, you may include it under
  24. # the same distribution terms that you use for the rest of that program.
  25. # This file is maintained in Automake, please report
  26. # bugs to <bug-automake@gnu.org> or send patches to
  27. # <automake-patches@gnu.org>.
  28. case $1 in
  29. '')
  30. echo "$0: No file. Try \`$0 --help' for more information." 1>&2
  31. exit 1;
  32. ;;
  33. -h | --h*)
  34. cat <<\EOF
  35. Usage: mdate-sh [--help] [--version] FILE
  36. Pretty-print the modification time of FILE.
  37. Report bugs to <bug-automake@gnu.org>.
  38. EOF
  39. exit $?
  40. ;;
  41. -v | --v*)
  42. echo "mdate-sh $scriptversion"
  43. exit $?
  44. ;;
  45. esac
  46. # Prevent date giving response in another language.
  47. LANG=C
  48. export LANG
  49. LC_ALL=C
  50. export LC_ALL
  51. LC_TIME=C
  52. export LC_TIME
  53. # GNU ls changes its time format in response to the TIME_STYLE
  54. # variable. Since we cannot assume `unset' works, revert this
  55. # variable to its documented default.
  56. if test "${TIME_STYLE+set}" = set; then
  57. TIME_STYLE=posix-long-iso
  58. export TIME_STYLE
  59. fi
  60. save_arg1=$1
  61. # Find out how to get the extended ls output of a file or directory.
  62. if ls -L /dev/null 1>/dev/null 2>&1; then
  63. ls_command='ls -L -l -d'
  64. else
  65. ls_command='ls -l -d'
  66. fi
  67. # A `ls -l' line looks as follows on OS/2.
  68. # drwxrwx--- 0 Aug 11 2001 foo
  69. # This differs from Unix, which adds ownership information.
  70. # drwxrwx--- 2 root root 4096 Aug 11 2001 foo
  71. #
  72. # To find the date, we split the line on spaces and iterate on words
  73. # until we find a month. This cannot work with files whose owner is a
  74. # user named `Jan', or `Feb', etc. However, it's unlikely that `/'
  75. # will be owned by a user whose name is a month. So we first look at
  76. # the extended ls output of the root directory to decide how many
  77. # words should be skipped to get the date.
  78. # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
  79. set x`ls -l -d /`
  80. # Find which argument is the month.
  81. month=
  82. command=
  83. until test $month
  84. do
  85. shift
  86. # Add another shift to the command.
  87. command="$command shift;"
  88. case $1 in
  89. Jan) month=January; nummonth=1;;
  90. Feb) month=February; nummonth=2;;
  91. Mar) month=March; nummonth=3;;
  92. Apr) month=April; nummonth=4;;
  93. May) month=May; nummonth=5;;
  94. Jun) month=June; nummonth=6;;
  95. Jul) month=July; nummonth=7;;
  96. Aug) month=August; nummonth=8;;
  97. Sep) month=September; nummonth=9;;
  98. Oct) month=October; nummonth=10;;
  99. Nov) month=November; nummonth=11;;
  100. Dec) month=December; nummonth=12;;
  101. esac
  102. done
  103. # Get the extended ls output of the file or directory.
  104. set dummy x`eval "$ls_command \"\$save_arg1\""`
  105. # Remove all preceding arguments
  106. eval $command
  107. # Because of the dummy argument above, month is in $2.
  108. #
  109. # On a POSIX system, we should have
  110. #
  111. # $# = 5
  112. # $1 = file size
  113. # $2 = month
  114. # $3 = day
  115. # $4 = year or time
  116. # $5 = filename
  117. #
  118. # On Darwin 7.7.0 and 7.6.0, we have
  119. #
  120. # $# = 4
  121. # $1 = day
  122. # $2 = month
  123. # $3 = year or time
  124. # $4 = filename
  125. # Get the month.
  126. case $2 in
  127. Jan) month=January; nummonth=1;;
  128. Feb) month=February; nummonth=2;;
  129. Mar) month=March; nummonth=3;;
  130. Apr) month=April; nummonth=4;;
  131. May) month=May; nummonth=5;;
  132. Jun) month=June; nummonth=6;;
  133. Jul) month=July; nummonth=7;;
  134. Aug) month=August; nummonth=8;;
  135. Sep) month=September; nummonth=9;;
  136. Oct) month=October; nummonth=10;;
  137. Nov) month=November; nummonth=11;;
  138. Dec) month=December; nummonth=12;;
  139. esac
  140. case $3 in
  141. ???*) day=$1;;
  142. *) day=$3; shift;;
  143. esac
  144. # Here we have to deal with the problem that the ls output gives either
  145. # the time of day or the year.
  146. case $3 in
  147. *:*) set `date`; eval year=\$$#
  148. case $2 in
  149. Jan) nummonthtod=1;;
  150. Feb) nummonthtod=2;;
  151. Mar) nummonthtod=3;;
  152. Apr) nummonthtod=4;;
  153. May) nummonthtod=5;;
  154. Jun) nummonthtod=6;;
  155. Jul) nummonthtod=7;;
  156. Aug) nummonthtod=8;;
  157. Sep) nummonthtod=9;;
  158. Oct) nummonthtod=10;;
  159. Nov) nummonthtod=11;;
  160. Dec) nummonthtod=12;;
  161. esac
  162. # For the first six month of the year the time notation can also
  163. # be used for files modified in the last year.
  164. if (expr $nummonth \> $nummonthtod) > /dev/null;
  165. then
  166. year=`expr $year - 1`
  167. fi;;
  168. *) year=$3;;
  169. esac
  170. # The result.
  171. echo $day $month $year
  172. # Local Variables:
  173. # mode: shell-script
  174. # sh-indentation: 2
  175. # eval: (add-hook 'write-file-hooks 'time-stamp)
  176. # time-stamp-start: "scriptversion="
  177. # time-stamp-format: "%:y-%02m-%02d.%02H"
  178. # time-stamp-end: "$"
  179. # End: