Mercurial > libdvdnav.hg
annotate remap.c @ 139:f7a26cd00c93 src
* only install the headers that really are intended for public use
* dvdnav.h has to include the headers differently if an application is using it
author | mroi |
---|---|
date | Sat, 29 Mar 2003 14:16:28 +0000 |
parents | b6834e6359cf |
children | 4e099155c968 |
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 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
17 * | |
18 * $Id$ | |
19 */ | |
20 | |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
21 #include <stdlib.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
22 #include <string.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
23 #include <stdio.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
24 #include <sys/param.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
25 #include <sys/fcntl.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
26 #include <assert.h> |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
27 #include "remap.h" |
114 | 28 #include "dvdnav_internal.h" |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
29 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
30 struct block_s { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
31 int domain; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
32 int title; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
33 int program; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
34 unsigned long start_block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
35 unsigned long end_block; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
36 }; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
37 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
38 struct remap_s { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
39 char *title; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
40 int maxblocks; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
41 int nblocks; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
42 int debug; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
43 struct block_s *blocks; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
44 }; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
45 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
46 remap_t* remap_new( char *title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
47 remap_t *map = malloc( sizeof(remap_t)); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
48 map->title = strdup(title); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
49 map->maxblocks = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
50 map->nblocks = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
51 map->blocks = NULL; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
52 map->debug = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
53 return map; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
54 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
55 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
56 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
|
57 /* 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
|
58 if (a->domain < b->domain) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
59 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
60 } else if (a->domain > b->domain) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
61 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
62 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
63 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
64 if (a->title < b->title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
65 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
66 } else if (a->title > b->title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
67 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
68 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
69 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
70 if (a->program < b->program) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
71 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
72 } else if (a->program > b->program) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
73 return 1; |
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 if (a->end_block < b->start_block) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
77 return -1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
78 } else if (a->start_block > b->end_block) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
79 /* |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
80 * if a->start_block == b->end_block then the two regions |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
81 * aren't strictly overlapping, but they should be merged |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
82 * anyway since there are zero blocks between them |
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 return 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
85 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
86 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
87 return 0; |
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 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
|
91 int lb = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
92 int ub = map->nblocks - 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
93 int mid; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
94 int res; |
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 while (lb <= ub) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
97 mid = lb + (ub - lb)/2; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
98 res = compare_block( key, &map->blocks[mid]); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
99 if (res < 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
100 ub = mid-1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
101 } else if (res > 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
102 lb = mid+1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
103 } else { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
104 return &map->blocks[mid]; |
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 NULL; |
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 void mergeblock( block_t *b, block_t tmp) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
111 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
|
112 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
|
113 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
114 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
115 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
|
116 block_t *b; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
117 int n; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
118 b = findblock( map, &block); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
119 if (b) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
120 /* overlaps an existing block */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
121 mergeblock( b, block); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
122 } else { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
123 /* new block */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
124 if (map->nblocks >= map->maxblocks) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
125 map->maxblocks += 20; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
126 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
|
127 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
128 n = map->nblocks++; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
129 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
|
130 map->blocks[ n] = map->blocks[ n-1]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
131 n--; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
132 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
133 map->blocks[ n] = block; |
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 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
136 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
137 int parseblock( |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
138 char *buf, int *dom, int *tt, int *pg, |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
139 unsigned long *start, unsigned long *end) |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
140 { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
141 long tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
142 char *tok; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
143 char *epos; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
144 char *marker[]={"domain", "title", "program", "start", "end"}; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
145 int st = 0; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
146 tok = strtok( buf, " "); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
147 while (st < 5) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
148 if (strcmp(tok, marker[st])) return -st-1000; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
149 tok = strtok( NULL, " "); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
150 if (!tok) return -st-2000; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
151 tmp = strtol( tok, &epos, 0); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
152 if (*epos != 0 && *epos != ',') return -st-3000; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
153 switch (st) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
154 case 0: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
155 *dom = (int)tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
156 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
157 case 1: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
158 *tt = (int)tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
159 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
160 case 2: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
161 *pg = (int)tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
162 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
163 case 3: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
164 *start = tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
165 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
166 case 4: |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
167 *end = tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
168 break; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
169 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
170 st++; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
171 tok = strtok( NULL, " "); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
172 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
173 return st; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
174 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
175 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
176 remap_t* remap_loadmap( char *title) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
177 char buf[160]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
178 char fname[MAXPATHLEN]; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
179 char *home; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
180 int res; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
181 FILE *fp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
182 block_t tmp; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
183 remap_t *map; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
184 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
185 /* Build the map filename */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
186 home = getenv("HOME"); assert(home); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
187 strncpy(fname, home, sizeof(fname)); |
114 | 188 strncat(fname, "/.dvdnav/", sizeof(fname)); |
96
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
189 strncat(fname, title, sizeof(fname)); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
190 strncat(fname, ".map", sizeof(fname)); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
191 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
192 /* Open the map file */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
193 fp = fopen( fname, "r"); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
194 if (!fp) { |
114 | 195 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
|
196 return NULL; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
197 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
198 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
199 /* Load the map file */ |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
200 map = remap_new( title); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
201 while (fgets( buf, sizeof(buf), fp) != NULL) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
202 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
|
203 if (strncasecmp( buf, "debug", 5) == 0) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
204 map->debug = 1; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
205 } else { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
206 res = parseblock( buf, |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
207 &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
|
208 if (res != 5) { |
114 | 209 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
|
210 continue; |
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 remap_add_node( map, tmp); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
213 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
214 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
215 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
216 if (map->nblocks == 0 && map->debug == 0) return NULL; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
217 return map; |
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 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
220 unsigned long remap_block( |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
221 remap_t *map, int domain, int title, int program, |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
222 unsigned long cblock, unsigned long offset) |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
223 { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
224 block_t key; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
225 block_t *b; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
226 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
227 if (map->debug) { |
114 | 228 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
|
229 map->title, domain, title, program, cblock, cblock+offset); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
230 } |
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 key.domain = domain; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
233 key.title = title; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
234 key.program = program; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
235 key.start_block = key.end_block = cblock + offset; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
236 b = findblock( map, &key); |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
237 |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
238 if (b) { |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
239 if (map->debug) { |
114 | 240 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
|
241 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
242 return b->end_block - cblock; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
243 } |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
244 return offset; |
2fcb4f228308
Adding "Personalizing DVD Viewing" files from <kevin_smathers@hp.com>
jcdutton
parents:
diff
changeset
|
245 } |