Mercurial > libdvdnav.hg
annotate remap.c @ 389:d3c273ced49c src
Use consistent license headers everywhere: Fix wrong FSF address.
author | diego |
---|---|
date | Sun, 14 Sep 2008 15:40:51 +0000 |
parents | 90ca650854e0 |
children | 0a5a6f03b029 |
rev | line source |
---|---|
114 | 1 /* |
2 * This file is part of libdvdnav, a DVD navigation library. | |
3 * | |
4 * libdvdnav is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * libdvdnav is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
389
d3c273ced49c
Use consistent license headers everywhere: Fix wrong FSF address.
diego
parents:
388
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
d3c273ced49c
Use consistent license headers everywhere: Fix wrong FSF address.
diego
parents:
388
diff
changeset
|
15 * with libdvdnav; if not, write to the Free Software Foundation, Inc., |
d3c273ced49c
Use consistent license headers everywhere: Fix wrong FSF address.
diego
parents:
388
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
114 | 17 * |
18 * $Id$ | |
19 */ | |
20 | |
287 | 21 #ifdef HAVE_CONFIG_H |
22 #include "config.h" | |
23 #endif | |
24 | |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
25 #include <stdlib.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
26 #include <string.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
27 #include <stdio.h> |
176 | 28 |
388 | 29 #ifndef _MSC_VER |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
30 #include <sys/param.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
31 #include <sys/fcntl.h> |
176 | 32 #else |
33 #ifndef MAXPATHLEN | |
34 #define MAXPATHLEN 255 | |
35 #endif | |
36 #endif /* _MSC_VER */ | |
37 | |
286
6fac6a613ea5
moved inclusion of inttypes.h from dvd_types.h to the including .c files
nicodvb
parents:
285
diff
changeset
|
38 #include <inttypes.h> |
294
2146ff691bcd
include limits.h; it was included in the previous dvdnav_internal.h and without it players segfault
nicodvb
parents:
290
diff
changeset
|
39 #include <limits.h> |
290 | 40 #include <sys/time.h> |
285
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
282
diff
changeset
|
41 #include "dvd_types.h" |
386 | 42 #include <dvdread/nav_types.h> |
43 #include <dvdread/ifo_types.h> | |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
44 #include "remap.h" |
285
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
282
diff
changeset
|
45 #include "vm/decoder.h" |
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
282
diff
changeset
|
46 #include "vm/vm.h" |
52877d182e96
moved all header inclusions from .h to .c files; my word, I've never seen such a horrible entanglement as in this mess
nicodvb
parents:
282
diff
changeset
|
47 #include "dvdnav.h" |
114 | 48 #include "dvdnav_internal.h" |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
49 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
50 struct block_s { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
51 int domain; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
52 int title; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
53 int program; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
54 unsigned long start_block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
55 unsigned long end_block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
56 }; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
57 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
58 struct remap_s { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
59 char *title; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
60 int maxblocks; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
61 int nblocks; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
62 int debug; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
63 struct block_s *blocks; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
64 }; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
65 |
212
6b67914ae021
port Daniel's changes to xine-lib cvs to minimize difference
mroi
parents:
176
diff
changeset
|
66 static remap_t* remap_new( char *title) { |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
67 remap_t *map = malloc( sizeof(remap_t)); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
68 map->title = strdup(title); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
69 map->maxblocks = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
70 map->nblocks = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
71 map->blocks = NULL; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
72 map->debug = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
73 return map; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
74 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
75 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
76 static int compare_block( block_t *a, block_t *b) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
77 /* returns -1 if a precedes b, 1 if a follows b, and 0 if a and b overlap */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
78 if (a->domain < b->domain) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
79 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
80 } else if (a->domain > b->domain) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
81 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
82 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
83 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
84 if (a->title < b->title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
85 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
86 } else if (a->title > b->title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
87 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
88 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
89 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
90 if (a->program < b->program) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
91 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
92 } else if (a->program > b->program) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
93 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
94 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
95 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
96 if (a->end_block < b->start_block) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
97 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
98 } else if (a->start_block > b->end_block) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
99 /* |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
100 * if a->start_block == b->end_block then the two regions |
388 | 101 * aren't strictly overlapping, but they should be merged |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
102 * anyway since there are zero blocks between them |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
103 */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
104 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
105 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
106 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
107 return 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
108 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
109 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
110 static block_t *findblock( remap_t *map, block_t *key) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
111 int lb = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
112 int ub = map->nblocks - 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
113 int mid; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
114 int res; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
115 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
116 while (lb <= ub) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
117 mid = lb + (ub - lb)/2; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
118 res = compare_block( key, &map->blocks[mid]); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
119 if (res < 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
120 ub = mid-1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
121 } else if (res > 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
122 lb = mid+1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
123 } else { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
124 return &map->blocks[mid]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
125 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
126 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
127 return NULL; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
128 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
129 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
130 static void mergeblock( block_t *b, block_t tmp) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
131 if (tmp.start_block < b->start_block) b->start_block = tmp.start_block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
132 if (tmp.end_block > b->end_block) b->end_block = tmp.end_block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
133 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
134 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
135 static void remap_add_node( remap_t *map, block_t block) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
136 block_t *b; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
137 int n; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
138 b = findblock( map, &block); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
139 if (b) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
140 /* overlaps an existing block */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
141 mergeblock( b, block); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
142 } else { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
143 /* new block */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
144 if (map->nblocks >= map->maxblocks) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
145 map->maxblocks += 20; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
146 map->blocks = realloc( map->blocks, sizeof( block_t)*map->maxblocks); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
147 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
148 n = map->nblocks++; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
149 while (n > 0 && compare_block( &block, &map->blocks[ n-1]) < 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
150 map->blocks[ n] = map->blocks[ n-1]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
151 n--; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
152 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
153 map->blocks[ n] = block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
154 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
155 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
156 |
388 | 157 static int parseblock(char *buf, int *dom, int *tt, int *pg, |
212
6b67914ae021
port Daniel's changes to xine-lib cvs to minimize difference
mroi
parents:
176
diff
changeset
|
158 unsigned long *start, unsigned long *end) { |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
159 long tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
160 char *tok; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
161 char *epos; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
162 char *marker[]={"domain", "title", "program", "start", "end"}; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
163 int st = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
164 tok = strtok( buf, " "); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
165 while (st < 5) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
166 if (strcmp(tok, marker[st])) return -st-1000; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
167 tok = strtok( NULL, " "); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
168 if (!tok) return -st-2000; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
169 tmp = strtol( tok, &epos, 0); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
170 if (*epos != 0 && *epos != ',') return -st-3000; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
171 switch (st) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
172 case 0: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
173 *dom = (int)tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
174 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
175 case 1: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
176 *tt = (int)tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
177 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
178 case 2: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
179 *pg = (int)tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
180 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
181 case 3: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
182 *start = tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
183 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
184 case 4: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
185 *end = tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
186 break; |
388 | 187 } |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
188 st++; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
189 tok = strtok( NULL, " "); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
190 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
191 return st; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
192 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
193 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
194 remap_t* remap_loadmap( char *title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
195 char buf[160]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
196 char fname[MAXPATHLEN]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
197 char *home; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
198 int res; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
199 FILE *fp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
200 block_t tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
201 remap_t *map; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
202 |
375
5820649e5aa2
in remap_loadmap() memzero tmp before using it; patch by Erik Hovland org
nicodvb
parents:
371
diff
changeset
|
203 memset(&tmp, 0, sizeof(tmp)); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
204 /* Build the map filename */ |
371
587353009f65
replace an assert(getenv("HOME)) with a return NULL in cases
nicodvb
parents:
342
diff
changeset
|
205 home = getenv("HOME"); |
587353009f65
replace an assert(getenv("HOME)) with a return NULL in cases
nicodvb
parents:
342
diff
changeset
|
206 if(!home) { |
587353009f65
replace an assert(getenv("HOME)) with a return NULL in cases
nicodvb
parents:
342
diff
changeset
|
207 fprintf(MSG_OUT, "libdvdnav: Unable to find home directory" ); |
587353009f65
replace an assert(getenv("HOME)) with a return NULL in cases
nicodvb
parents:
342
diff
changeset
|
208 return NULL; |
587353009f65
replace an assert(getenv("HOME)) with a return NULL in cases
nicodvb
parents:
342
diff
changeset
|
209 } |
282
918fe20358cb
replaced sequency of strncpy() and strncat() by 1 snprintf() and fixed off-by-1 possible buffer oveflow; patch by Diego Petteno'
nicodvb
parents:
212
diff
changeset
|
210 snprintf(fname, sizeof(fname), "%s/.dvdnav/%s.map", home, title); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
211 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
212 /* Open the map file */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
213 fp = fopen( fname, "r"); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
214 if (!fp) { |
114 | 215 fprintf(MSG_OUT, "libdvdnav: Unable to find map file '%s'\n", fname); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
216 return NULL; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
217 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
218 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
219 /* Load the map file */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
220 map = remap_new( title); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
221 while (fgets( buf, sizeof(buf), fp) != NULL) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
222 if (buf[0] == '\n' || buf[0] == '#' || buf[0] == 0) continue; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
223 if (strncasecmp( buf, "debug", 5) == 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
224 map->debug = 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
225 } else { |
388 | 226 res = parseblock( buf, |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
227 &tmp.domain, &tmp.title, &tmp.program, &tmp.start_block, &tmp.end_block); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
228 if (res != 5) { |
114 | 229 fprintf(MSG_OUT, "libdvdnav: Ignoring map line (%d): %s\n", res, buf); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
230 continue; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
231 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
232 remap_add_node( map, tmp); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
233 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
234 } |
342
83758bfacd4c
in remap_loadmap() close the file pointer before exiting ; patch by Erik Hovland - erik hovland org
nicodvb
parents:
341
diff
changeset
|
235 fclose(fp); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
236 |
341
090b808c421b
in remap_loadmap() free map before exiting in case of failure ; patch by Erik Hovland - erik hovland org
nicodvb
parents:
332
diff
changeset
|
237 if (map->nblocks == 0 && map->debug == 0) { |
090b808c421b
in remap_loadmap() free map before exiting in case of failure ; patch by Erik Hovland - erik hovland org
nicodvb
parents:
332
diff
changeset
|
238 free(map); |
090b808c421b
in remap_loadmap() free map before exiting in case of failure ; patch by Erik Hovland - erik hovland org
nicodvb
parents:
332
diff
changeset
|
239 return NULL; |
090b808c421b
in remap_loadmap() free map before exiting in case of failure ; patch by Erik Hovland - erik hovland org
nicodvb
parents:
332
diff
changeset
|
240 } |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
241 return map; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
242 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
243 |
388 | 244 unsigned long remap_block( |
245 remap_t *map, int domain, int title, int program, | |
246 unsigned long cblock, unsigned long offset) | |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
247 { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
248 block_t key; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
249 block_t *b; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
250 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
251 if (map->debug) { |
114 | 252 fprintf(MSG_OUT, "libdvdnav: %s: domain %d, title %d, program %d, start %lx, next %lx\n", |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
253 map->title, domain, title, program, cblock, cblock+offset); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
254 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
255 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
256 key.domain = domain; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
257 key.title = title; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
258 key.program = program; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
259 key.start_block = key.end_block = cblock + offset; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
260 b = findblock( map, &key); |
388 | 261 |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
262 if (b) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
263 if (map->debug) { |
114 | 264 fprintf(MSG_OUT, "libdvdnav: Redirected to %lx\n", b->end_block); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
265 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
266 return b->end_block - cblock; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
267 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
268 return offset; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
269 } |