btparser/cparser/tests/exp_lex/InspectorWithMP4DateTime.bt

117 lines
3.5 KiB
Plaintext

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18: RequiresVersion ( 4 . 0 ) ;
19:
20:
21:
22:
23: local int64 position ;
24: if ( GetSelSize ( ) > 0 )
25: position = GetSelStart ( ) ;
26: else
27: position = GetCursorPos ( ) ;
28:
29:
30: int leap ( int year )
31: {
32: return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) ;
33: }
34:
35: int daysInYear ( int year ) { return 365 + leap ( year ) ; }
36:
37:
38: typedef uint MP4_Time < read = MP4_TimeRead , write = MP4_TimeWrite > ;
39:
40: string MP4_TimeRead ( MP4_Time secs )
41: {
42:
43:
44: int days = secs / 86400 ;
45: secs = secs % 86400 ;
46:
47: int year = 1904 ;
48: int month = 1 ;
49:
50: int daysInMonth [ 13 ] = { - 1 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
51: int extraDay [ 13 ] = { - 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
52:
53: while ( days > daysInYear ( year ) )
54: {
55: days -= daysInYear ( year ) ;
56: year ++ ;
57: }
58:
59: while ( days > daysInMonth [ month ] + leap ( year ) * extraDay [ month ] )
60: {
61: days -= daysInMonth [ month ] + leap ( year ) * extraDay [ month ] ;
62: month ++ ;
63: }
64:
65: int day = ++ days ;
66:
67: int hours = secs / 3600 ;
68: secs = secs % 3600 ;
69: int mins = secs / 60 ;
70: secs = secs % 60 ;
71:
72: string s ;
73: SPrintf ( s , "%02d.%02d.%4d %02d:%02d:%02d" , day , month , year , hours , mins , secs ) ;
74: return s ;
75: }
76:
77: void MP4_TimeWrite ( MP4_Time & secs , string dateTime )
78: {
79: int daysInMonth [ 13 ] = { - 1 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
80: int extraDay [ 13 ] = { - 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
81:
82: int day , month , year , hour , min , sec ;
83: SScanf ( dateTime , "%d.%d.%d %d:%d:%d" , day , month , year , hour , min , sec ) ;
84:
85: int days = day - 1 ;
86: int months , hours , mins , y , m ;
87:
88: for ( y = 1904 ; y < year ; ++ y )
89: days += daysInYear ( y ) ;
90:
91: for ( m = 1 ; m < month ; ++ m )
92: days += daysInMonth [ m ] + leap ( year ) * extraDay [ m ] ;
93:
94: secs = days * 86400 + hour * 3600 + min * 60 + sec ;
95: }
96:
97:
98: FSeek ( position ) ; MP4_Time _mp4t < name = "MP4 time" > ;
99: FSeek ( position ) ; byte _si8 < name = "Signed Byte" > ;
100: FSeek ( position ) ; ubyte _ui8 < name = "Unsigned Byte" > ;
101: FSeek ( position ) ; short _si16 < name = "Signed Short" > ;
102: FSeek ( position ) ; ushort _ui16 < name = "Unsigned Short" > ;
103: FSeek ( position ) ; int _si32 < name = "Signed Int" > ;
104: FSeek ( position ) ; uint _ui32 < name = "Unsigned Int" > ;
105: FSeek ( position ) ; int64 _si64 < name = "Signed Int64" > ;
106: FSeek ( position ) ; uint64 _ui64 < name = "Unsigned Int64" > ;
107: FSeek ( position ) ; float _f < name = "Float" > ;
108: FSeek ( position ) ; double _d < name = "Double" > ;
109: FSeek ( position ) ; hfloat _hf < name = "Half Float" > ;
110: FSeek ( position ) ; char _s [ ReadStringLength ( position , 256 ) ] < name = "String" > ;
111: FSeek ( position ) ; wchar_t _ws [ ReadWStringLength ( position , 256 ) ] < name = "Unicode" > ;
112: FSeek ( position ) ; DOSDATE _dd < name = "DOS Date" > ;
113: FSeek ( position ) ; DOSTIME _dt < name = "DOS Time" > ;
114: FSeek ( position ) ; FILETIME _ft < name = "FILETIME" > ;
115: FSeek ( position ) ; OLETIME _ot < name = "OLETIME" > ;
116: FSeek ( position ) ; time_t _tt < name = "time_t" > ;
117: tok_eof