Commit 44ae83d0 44ae83d0d7776b365cee4cdc7f1d61e19513c951 by Sergey Poznyakoff

Switch mimeview to new locus and linetracker

* include/mailutils/locus.h (mu_stream_print_locus_point): New proto.
(mu_locus_range_copy): New proto.
* include/mailutils/yyloc.h (mu_file_print_locus_point)
(mu_file_print_locus_range): New protos.
(YY_LOCATION_PRINT): Redo using mu_file_print_locus_range.
* libmailutils/locus/filprloc.c: New file.
* libmailutils/locus/genprloc.c: New file.
* libmailutils/locus/strprloc.c: New file.
* libmailutils/locus/Makefile.am: Add new files.
* libmailutils/locus/debug.c (mu_stream_print_locus_range): Remove.
Declared elsewhere.
* libmailutils/locus/linetrack.c: use mu_locus_point_set_file,
instead of mu_locus_point_init.
* libmailutils/locus/locus.c: Likewise.
(mu_locus_range_copy)P: New function.
* mimeview/mimetypes.l: Provide rule for \n in ARGSTRING
Always print diagnostics before returning BOGUS
(lex_next_rule): Rewrite.  Print verbose diagnostics if app.trace6 is set.
(mimetypes_close): Deinitialize yylloc.
* mimeview/mimetypes.y: Catch the BOGUS token.
Adjust conflict expectation.
Properly reference assigned loci.
(mimetypes_parse): Return 1 if any errors detected.
* mimeview/mimeview.c: Use debug category app instead of mime.
* mimeview/tests/testsuite.at: Add new tests.
* libmailutils/stream/logstream.c (_log_done): Deinitialize
locus range.
1 parent 8ee676ca
...@@ -41,6 +41,8 @@ void mu_locus_point_deinit (struct mu_locus_point *pt); ...@@ -41,6 +41,8 @@ void mu_locus_point_deinit (struct mu_locus_point *pt);
41 int mu_locus_point_copy (struct mu_locus_point *dest, 41 int mu_locus_point_copy (struct mu_locus_point *dest,
42 struct mu_locus_point const *src); 42 struct mu_locus_point const *src);
43 43
44 int mu_locus_range_copy (struct mu_locus_range *dest,
45 struct mu_locus_range const *src);
44 void mu_locus_range_deinit (struct mu_locus_range *lr); 46 void mu_locus_range_deinit (struct mu_locus_range *lr);
45 47
46 static inline int 48 static inline int
...@@ -74,7 +76,8 @@ int mu_linetrack_locus (struct mu_linetrack *trk, struct mu_locus_point *lp); ...@@ -74,7 +76,8 @@ int mu_linetrack_locus (struct mu_linetrack *trk, struct mu_locus_point *lp);
74 int mu_linetrack_stat (mu_linetrack_t trk, struct mu_linetrack_stat *st); 76 int mu_linetrack_stat (mu_linetrack_t trk, struct mu_linetrack_stat *st);
75 int mu_linetrack_at_bol (struct mu_linetrack *trk); 77 int mu_linetrack_at_bol (struct mu_linetrack *trk);
76 78
77 79 void mu_stream_print_locus_point (mu_stream_t stream,
80 struct mu_locus_point const *lpt);
78 void mu_stream_print_locus_range (mu_stream_t stream, 81 void mu_stream_print_locus_range (mu_stream_t stream,
79 struct mu_locus_range const *loc); 82 struct mu_locus_range const *loc);
80 83
......
1 void mu_file_print_locus_point (FILE *,
2 struct mu_locus_point const *lpt);
3 void mu_file_print_locus_range (FILE *,
4 struct mu_locus_range const *loc);
5
1 #define YYLTYPE struct mu_locus_range 6 #define YYLTYPE struct mu_locus_range
2 #define YYLLOC_DEFAULT(Current, Rhs, N) \ 7 #define YYLLOC_DEFAULT(Current, Rhs, N) \
3 do \ 8 do \
...@@ -14,29 +19,7 @@ ...@@ -14,29 +19,7 @@
14 } \ 19 } \
15 } while (0) 20 } while (0)
16 #define YY_LOCATION_PRINT(File, Loc) \ 21 #define YY_LOCATION_PRINT(File, Loc) \
17 do \ 22 mu_file_print_locus_range (File, &(Loc))
18 { \
19 if (!mu_locus_point_same_file (&(Loc).beg, &(Loc).end)) \
20 fprintf (File, "%s:%u.%u-%s:%u.%u", \
21 (Loc).beg.mu_file, \
22 (Loc).beg.mu_line, (Loc).beg.mu_col, \
23 (Loc).end.mu_file, \
24 (Loc).end.mu_line, (Loc).end.mu_col); \
25 else if ((Loc).beg.mu_line != (Loc).end.mu_line) \
26 fprintf (File, "%s:%u.%u-%u.%u", \
27 (Loc).beg.mu_file, \
28 (Loc).beg.mu_line, (Loc).beg.mu_col, \
29 (Loc).end.mu_line, (Loc).end.mu_col); \
30 else if ((Loc).beg.mu_col != (Loc).end.mu_col) \
31 fprintf (File, "%s:%u.%u-%u", \
32 (Loc).beg.mu_file, \
33 (Loc).beg.mu_line, (Loc).beg.mu_col, \
34 (Loc).end.mu_col); \
35 else \
36 fprintf (File, "%s:%u.%u", \
37 (Loc).beg.mu_file, \
38 (Loc).beg.mu_line, (Loc).beg.mu_col); \
39 } while (0)
40 23
41 24
42 25
......
...@@ -21,7 +21,11 @@ liblocus_la_SOURCES = \ ...@@ -21,7 +21,11 @@ liblocus_la_SOURCES = \
21 ident.c\ 21 ident.c\
22 debug.c\ 22 debug.c\
23 linetrack.c\ 23 linetrack.c\
24 locus.c 24 locus.c\
25 filprloc.c\
26 strprloc.c
27
28 EXTRA_DIST = genprloc.c
25 29
26 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils 30 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
27 31
......
...@@ -9,50 +9,6 @@ ...@@ -9,50 +9,6 @@
9 #include <mailutils/stdstream.h> 9 #include <mailutils/stdstream.h>
10 10
11 void 11 void
12 mu_stream_print_locus_range (mu_stream_t stream,
13 struct mu_locus_range const *loc)
14 {
15 if (loc->beg.mu_col == 0)
16 {
17 if (loc->end.mu_file
18 && (!mu_locus_point_same_file (&loc->beg, &loc->end)
19 || loc->beg.mu_line != loc->end.mu_line))
20 mu_stream_printf (stream, "%s:%u-%u",
21 loc->beg.mu_file,
22 loc->beg.mu_line,
23 loc->end.mu_line);
24 else
25 mu_stream_printf (stream, "%s:%u",
26 loc->beg.mu_file,
27 loc->beg.mu_line);
28 }
29 else
30 {
31 if (loc->end.mu_file
32 && !mu_locus_point_same_file (&loc->beg, &loc->end))
33 mu_stream_printf (stream, "%s:%u.%u-%s:%u.%u",
34 loc->beg.mu_file,
35 loc->beg.mu_line, loc->beg.mu_col,
36 loc->end.mu_file,
37 loc->end.mu_line, loc->end.mu_col);
38 else if (loc->end.mu_file && loc->beg.mu_line != loc->end.mu_line)
39 mu_stream_printf (stream, "%s:%u.%u-%u.%u",
40 loc->beg.mu_file,
41 loc->beg.mu_line, loc->beg.mu_col,
42 loc->end.mu_line, loc->end.mu_col);
43 else if (loc->end.mu_file && loc->beg.mu_col != loc->end.mu_col)
44 mu_stream_printf (stream, "%s:%u.%u-%u",
45 loc->beg.mu_file,
46 loc->beg.mu_line, loc->beg.mu_col,
47 loc->end.mu_col);
48 else
49 mu_stream_printf (stream, "%s:%u.%u",
50 loc->beg.mu_file,
51 loc->beg.mu_line, loc->beg.mu_col);
52 }
53 }
54
55 void
56 mu_stream_vlprintf (mu_stream_t stream, 12 mu_stream_vlprintf (mu_stream_t stream,
57 struct mu_locus_range const *loc, 13 struct mu_locus_range const *loc,
58 char const *fmt, va_list ap) 14 char const *fmt, va_list ap)
......
1 #include <stdio.h>
2
3 #define STREAM_TYPE FILE*
4 #define STREAM_PRINTF fprintf
5 #define PRINT_LOCUS_POINT mu_file_print_locus_point
6 #define PRINT_LOCUS_RANGE mu_file_print_locus_range
7 #include "genprloc.c"
1 #ifndef STREAM_TYPE
2 # error "STREAM_TYPE not defined"
3 #endif
4 #ifndef PRINT_LOCUS_POINT
5 # error "PRINT_LOCUS_POINT not defined"
6 #endif
7 #ifndef PRINT_LOCUS_RANGE
8 # error "PRINT_LOCUS_RANGE not defined"
9 #endif
10 #ifndef STREAM_PRINTF
11 # error "STREAM_PRINTF not defined"
12 #endif
13
14 #include <mailutils/types.h>
15 #include <mailutils/locus.h>
16
17 void
18 PRINT_LOCUS_POINT (STREAM_TYPE stream, struct mu_locus_point const *lp)
19 {
20 if (lp->mu_file)
21 {
22 STREAM_PRINTF (stream, "%s:%u",
23 lp->mu_file, lp->mu_line);
24 if (lp->mu_col)
25 STREAM_PRINTF (stream, ".%u", lp->mu_col);
26 }
27 }
28
29 void
30 PRINT_LOCUS_RANGE (STREAM_TYPE stream, struct mu_locus_range const *loc)
31 {
32 PRINT_LOCUS_POINT (stream, &loc->beg);
33 if (loc->end.mu_file)
34 {
35 if (!mu_locus_point_same_file (&loc->beg, &loc->end))
36 {
37 STREAM_PRINTF (stream, "-");
38 PRINT_LOCUS_POINT (stream, &loc->end);
39 }
40 else if (loc->beg.mu_line != loc->end.mu_line)
41 {
42 STREAM_PRINTF (stream, "-");
43 STREAM_PRINTF (stream, "%u", loc->end.mu_line);
44 if (loc->end.mu_col)
45 STREAM_PRINTF (stream, ".%u", loc->end.mu_col);
46 }
47 else if (loc->beg.mu_col
48 && loc->beg.mu_col != loc->end.mu_col)
49 {
50 STREAM_PRINTF (stream, "-");
51 STREAM_PRINTF (stream, "%u", loc->end.mu_col);
52 }
53 }
54 }
...@@ -196,7 +196,7 @@ int ...@@ -196,7 +196,7 @@ int
196 mu_linetrack_locus (struct mu_linetrack *trk, struct mu_locus_point *lp) 196 mu_linetrack_locus (struct mu_linetrack *trk, struct mu_locus_point *lp)
197 { 197 {
198 lp->mu_line = trk->hline + trk->tos; 198 lp->mu_line = trk->hline + trk->tos;
199 return mu_locus_point_init (lp, trk->file_name); 199 return mu_locus_point_set_file (lp, trk->file_name);
200 } 200 }
201 201
202 int 202 int
......
...@@ -39,7 +39,26 @@ mu_locus_point_copy (struct mu_locus_point *dest, ...@@ -39,7 +39,26 @@ mu_locus_point_copy (struct mu_locus_point *dest,
39 { 39 {
40 dest->mu_col = src->mu_col; 40 dest->mu_col = src->mu_col;
41 dest->mu_line = src->mu_line; 41 dest->mu_line = src->mu_line;
42 return mu_locus_point_init (dest, src->mu_file); 42 return mu_locus_point_set_file (dest, src->mu_file);
43 }
44
45 int
46 mu_locus_range_copy (struct mu_locus_range *dest,
47 struct mu_locus_range const *src)
48 {
49 int rc;
50 struct mu_locus_range tmp = MU_LOCUS_RANGE_INITIALIZER;
51
52 rc = mu_locus_point_copy (&tmp.beg, &src->beg);
53 if (rc == 0)
54 {
55 rc = mu_locus_point_copy (&tmp.end, &src->end);
56 if (rc)
57 mu_locus_point_deinit (&tmp.beg);
58 else
59 *dest = tmp;
60 }
61 return rc;
43 } 62 }
44 63
45 void 64 void
......
1 #include <mailutils/types.h>
2 #include <mailutils/locus.h>
3 #include <mailutils/stream.h>
4
5 #define STREAM_TYPE mu_stream_t
6 #define STREAM_PRINTF mu_stream_printf
7 #define PRINT_LOCUS_POINT mu_stream_print_locus_point
8 #define PRINT_LOCUS_RANGE mu_stream_print_locus_range
9 #include "genprloc.c"
10
...@@ -305,6 +305,7 @@ static void ...@@ -305,6 +305,7 @@ static void
305 _log_done (struct _mu_stream *str) 305 _log_done (struct _mu_stream *str)
306 { 306 {
307 struct _mu_log_stream *sp = (struct _mu_log_stream *)str; 307 struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
308 mu_locus_range_deinit (&sp->locrange);
308 mu_stream_destroy (&sp->transport); 309 mu_stream_destroy (&sp->transport);
309 } 310 }
310 311
......
...@@ -43,6 +43,12 @@ digit_to_number (char c) ...@@ -43,6 +43,12 @@ digit_to_number (char c)
43 } 43 }
44 44
45 static void 45 static void
46 drop_string (void)
47 {
48 mu_opool_clear (pool);
49 }
50
51 static void
46 finish_string (void) 52 finish_string (void)
47 { 53 {
48 mu_opool_append_char (pool, 0); 54 mu_opool_append_char (pool, 0);
...@@ -100,6 +106,11 @@ WS [ \t][ \t]* ...@@ -100,6 +106,11 @@ WS [ \t][ \t]*
100 BEGIN (RULE); 106 BEGIN (RULE);
101 return TYPE; 107 return TYPE;
102 } 108 }
109
110 . {
111 mu_error (_("type/subtype is missing"));
112 return BOGUS;
113 }
103 } 114 }
104 115
105 <RULE>{ 116 <RULE>{
...@@ -147,8 +158,7 @@ WS [ \t][ \t]* ...@@ -147,8 +158,7 @@ WS [ \t][ \t]*
147 {WS} mu_error ("unexpected whitespace in argument list"); 158 {WS} mu_error ("unexpected whitespace in argument list");
148 \n { 159 \n {
149 mu_error ("unexpected newline in argument list"); 160 mu_error ("unexpected newline in argument list");
150 BEGIN (RULE); 161 return BOGUS;
151 return EOL;
152 } 162 }
153 . { 163 . {
154 mu_locus_point_copy (&string_beg, &yylloc.beg); 164 mu_locus_point_copy (&string_beg, &yylloc.beg);
...@@ -190,6 +200,12 @@ WS [ \t][ \t]* ...@@ -190,6 +200,12 @@ WS [ \t][ \t]*
190 mu_opool_append (pool, yytext, yyleng); 200 mu_opool_append (pool, yytext, yyleng);
191 } 201 }
192 202
203 \n {
204 mu_error ("unexpected newline in argument");
205 drop_string ();
206 return BOGUS;
207 }
208
193 . { 209 . {
194 mu_linetrack_retreat (trk, 1); 210 mu_linetrack_retreat (trk, 1);
195 yyless (0); 211 yyless (0);
...@@ -207,7 +223,7 @@ mimetypes_open (const char *name) ...@@ -207,7 +223,7 @@ mimetypes_open (const char *name)
207 int mode; 223 int mode;
208 char *filename; 224 char *filename;
209 225
210 yy_flex_debug = mu_debug_level_p (MU_DEBCAT_MIME, MU_DEBUG_TRACE4); 226 yy_flex_debug = mu_debug_level_p (MU_DEBCAT_APP, MU_DEBUG_TRACE4);
211 227
212 if (stat (name, &st)) 228 if (stat (name, &st))
213 { 229 {
...@@ -247,6 +263,7 @@ mimetypes_close () ...@@ -247,6 +263,7 @@ mimetypes_close ()
247 int mode; 263 int mode;
248 264
249 fclose (yyin); 265 fclose (yyin);
266 mu_locus_range_deinit (&yylloc);
250 mu_linetrack_destroy (&trk); 267 mu_linetrack_destroy (&trk);
251 mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, 268 mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
252 MU_IOCTL_LOGSTREAM_GET_MODE, &mode); 269 MU_IOCTL_LOGSTREAM_GET_MODE, &mode);
...@@ -290,8 +307,10 @@ void ...@@ -290,8 +307,10 @@ void
290 lex_next_rule (void) 307 lex_next_rule (void)
291 { 308 {
292 int c; 309 int c;
310 int dbg = yy_flex_debug
311 || mu_debug_level_p (MU_DEBCAT_APP, MU_DEBUG_TRACE6);
293 312
294 if (yy_flex_debug) 313 if (dbg)
295 { 314 {
296 YY_LOCATION_PRINT (stderr, yylloc); 315 YY_LOCATION_PRINT (stderr, yylloc);
297 fprintf (stderr, ": started error recovery\n"); 316 fprintf (stderr, ": started error recovery\n");
...@@ -299,19 +318,14 @@ lex_next_rule (void) ...@@ -299,19 +318,14 @@ lex_next_rule (void)
299 while ((c = input ()) != EOF) 318 while ((c = input ()) != EOF)
300 { 319 {
301 char ch = c; 320 char ch = c;
302 mu_linetrack_advance (trk, &yylloc, &ch, 1); 321 if (!mu_isspace (c) && mu_linetrack_at_bol (trk))
303 if (c == '\n')
304 { 322 {
305 continue;
306 }
307 else if (mu_linetrack_at_bol (trk) && !(c == ' ' || c == '\t'))
308 {
309 mu_linetrack_retreat (trk, 1);
310 unput (c); 323 unput (c);
311 break; 324 break;
312 } 325 }
326 mu_linetrack_advance (trk, &yylloc, &ch, 1);
313 } 327 }
314 if (yy_flex_debug) 328 if (dbg)
315 { 329 {
316 struct mu_locus_range lr = MU_LOCUS_RANGE_INITIALIZER; 330 struct mu_locus_range lr = MU_LOCUS_RANGE_INITIALIZER;
317 mu_linetrack_locus (trk, &lr.beg); 331 mu_linetrack_locus (trk, &lr.beg);
...@@ -321,4 +335,5 @@ lex_next_rule (void) ...@@ -321,4 +335,5 @@ lex_next_rule (void)
321 } 335 }
322 BEGIN (RULE); 336 BEGIN (RULE);
323 unput ('\n'); 337 unput ('\n');
338 mu_linetrack_retreat (trk, 1);
324 } 339 }
......
...@@ -122,10 +122,11 @@ struct rule_tab ...@@ -122,10 +122,11 @@ struct rule_tab
122 }; 122 };
123 123
124 static mu_list_t rule_list; 124 static mu_list_t rule_list;
125 static size_t errors;
125 %} 126 %}
126 127
127 %locations 128 %locations
128 %expect 12 129 %expect 15
129 130
130 %token <string> TYPE IDENT 131 %token <string> TYPE IDENT
131 %token <string> STRING 132 %token <string> STRING
...@@ -165,16 +166,21 @@ rule_line: /* empty */ ...@@ -165,16 +166,21 @@ rule_line: /* empty */
165 p->type = $1.ptr; 166 p->type = $1.ptr;
166 p->node = $2; 167 p->node = $2;
167 p->priority = $3; 168 p->priority = $3;
168 p->loc.beg = @1.beg; 169 mu_locus_point_copy (&p->loc.beg, &@1.beg);
169 p->loc.end = @3.end; 170 mu_locus_point_copy (&p->loc.end, &@3.end);
170 #if 0 171 #if 0
171 YY_LOCATION_PRINT (stderr, p->loc); 172 YY_LOCATION_PRINT (stderr, p->loc);
172 fprintf (stderr, ": rule %s\n", p->type); 173 fprintf (stderr, ": rule %s\n", p->type);
173 #endif 174 #endif
174 mu_list_append (rule_list, p); 175 mu_list_append (rule_list, p);
175 } 176 }
177 | BOGUS
178 {
179 YYERROR;
180 }
176 | error 181 | error
177 { 182 {
183 errors++;
178 if (arg_list) 184 if (arg_list)
179 mu_list_destroy (&arg_list); 185 mu_list_destroy (&arg_list);
180 arg_list = NULL; 186 arg_list = NULL;
...@@ -228,6 +234,10 @@ stmt : '!' stmt ...@@ -228,6 +234,10 @@ stmt : '!' stmt
228 $$ = make_suffix_node (&$1, &@1); 234 $$ = make_suffix_node (&$1, &@1);
229 } 235 }
230 | function 236 | function
237 | BOGUS
238 {
239 YYERROR;
240 }
231 ; 241 ;
232 242
233 priority : PRIORITY '(' arglist ')' 243 priority : PRIORITY '(' arglist ')'
...@@ -280,6 +290,10 @@ arglist : arg ...@@ -280,6 +290,10 @@ arglist : arg
280 ; 290 ;
281 291
282 arg : STRING 292 arg : STRING
293 | BOGUS
294 {
295 YYERROR;
296 }
283 ; 297 ;
284 298
285 %% 299 %%
...@@ -290,10 +304,10 @@ mimetypes_parse (const char *name) ...@@ -290,10 +304,10 @@ mimetypes_parse (const char *name)
290 int rc; 304 int rc;
291 if (mimetypes_open (name)) 305 if (mimetypes_open (name))
292 return 1; 306 return 1;
293 yydebug = mu_debug_level_p (MU_DEBCAT_MIME, MU_DEBUG_TRACE3); 307 yydebug = mu_debug_level_p (MU_DEBCAT_APP, MU_DEBUG_TRACE3);
294 rc = yyparse (); 308 rc = yyparse ();
295 mimetypes_close (); 309 mimetypes_close ();
296 return rc || rule_list == NULL; 310 return rc || errors;
297 } 311 }
298 312
299 static struct node * 313 static struct node *
...@@ -301,7 +315,7 @@ make_node (enum node_type type, struct mu_locus_range const *loc) ...@@ -301,7 +315,7 @@ make_node (enum node_type type, struct mu_locus_range const *loc)
301 { 315 {
302 struct node *p = mimetypes_malloc (sizeof *p); 316 struct node *p = mimetypes_malloc (sizeof *p);
303 p->type = type; 317 p->type = type;
304 p->loc = *loc; 318 mu_locus_range_copy (&p->loc, loc);
305 return p; 319 return p;
306 } 320 }
307 321
...@@ -759,7 +773,7 @@ check_suffix (char *suf) ...@@ -759,7 +773,7 @@ check_suffix (char *suf)
759 void 773 void
760 mime_debug (int lev, struct mu_locus_range const *loc, char const *fmt, ...) 774 mime_debug (int lev, struct mu_locus_range const *loc, char const *fmt, ...)
761 { 775 {
762 if (mu_debug_level_p (MU_DEBCAT_MIME, lev)) 776 if (mu_debug_level_p (MU_DEBCAT_APP, lev))
763 { 777 {
764 va_list ap; 778 va_list ap;
765 779
......
...@@ -66,7 +66,7 @@ cli_debug (struct mu_parseopt *po, struct mu_option *opt, ...@@ -66,7 +66,7 @@ cli_debug (struct mu_parseopt *po, struct mu_option *opt,
66 lev = MU_DEBUG_LEVEL_UPTO (MU_DEBUG_TRACE2); 66 lev = MU_DEBUG_LEVEL_UPTO (MU_DEBUG_TRACE2);
67 else 67 else
68 { 68 {
69 mu_debug_get_category_level (MU_DEBCAT_MIME, &lev); 69 mu_debug_get_category_level (MU_DEBCAT_APP, &lev);
70 for (; *arg; arg++) 70 for (; *arg; arg++)
71 { 71 {
72 switch (*arg) 72 switch (*arg)
...@@ -88,7 +88,7 @@ cli_debug (struct mu_parseopt *po, struct mu_option *opt, ...@@ -88,7 +88,7 @@ cli_debug (struct mu_parseopt *po, struct mu_option *opt,
88 } 88 }
89 } 89 }
90 } 90 }
91 mu_debug_set_category_level (MU_DEBCAT_MIME, lev); 91 mu_debug_set_category_level (MU_DEBCAT_APP, lev);
92 } 92 }
93 93
94 static void 94 static void
...@@ -222,11 +222,11 @@ display_file (const char *file, const char *type) ...@@ -222,11 +222,11 @@ display_file (const char *file, const char *type)
222 argv[5] = (char*) mimeview_file; 222 argv[5] = (char*) mimeview_file;
223 argv[6] = NULL; 223 argv[6] = NULL;
224 224
225 if (mu_debug_level_p (MU_DEBCAT_MIME, MU_DEBUG_TRACE0)) 225 if (mu_debug_level_p (MU_DEBCAT_APP, MU_DEBUG_TRACE0))
226 { 226 {
227 char *string; 227 char *string;
228 mu_argcv_string (6, argv, &string); 228 mu_argcv_string (6, argv, &string);
229 mu_debug (MU_DEBCAT_MIME, MU_DEBUG_TRACE0, 229 mu_debug (MU_DEBCAT_APP, MU_DEBUG_TRACE0,
230 (_("executing %s...\n"), string)); 230 (_("executing %s...\n"), string));
231 free (string); 231 free (string);
232 } 232 }
...@@ -247,7 +247,7 @@ display_file (const char *file, const char *type) ...@@ -247,7 +247,7 @@ display_file (const char *file, const char *type)
247 { 247 {
248 display_stream_mailcap (mimeview_file, mimeview_stream, hdr, 248 display_stream_mailcap (mimeview_file, mimeview_stream, hdr,
249 no_ask_types, interactive, dry_run, 249 no_ask_types, interactive, dry_run,
250 MU_DEBCAT_MIME); 250 MU_DEBCAT_APP);
251 mu_header_destroy (&hdr); 251 mu_header_destroy (&hdr);
252 } 252 }
253 } 253 }
...@@ -264,9 +264,9 @@ main (int argc, char **argv) ...@@ -264,9 +264,9 @@ main (int argc, char **argv)
264 if (dry_run) 264 if (dry_run)
265 { 265 {
266 mu_debug_level_t lev; 266 mu_debug_level_t lev;
267 mu_debug_get_category_level (MU_DEBCAT_MIME, &lev); 267 mu_debug_get_category_level (MU_DEBCAT_APP, &lev);
268 lev |= MU_DEBUG_LEVEL_UPTO (MU_DEBUG_TRACE2); 268 lev |= MU_DEBUG_LEVEL_UPTO (MU_DEBUG_TRACE2);
269 mu_debug_set_category_level (MU_DEBCAT_MIME, lev); 269 mu_debug_set_category_level (MU_DEBCAT_APP, lev);
270 } 270 }
271 271
272 if (argc == 0 && !lint) 272 if (argc == 0 && !lint)
......
...@@ -40,8 +40,8 @@ $2: $4 ...@@ -40,8 +40,8 @@ $2: $4
40 40
41 m4_pushdef([build_expect],[__build_expect([],m4_shift(m4_shift($@)))]) 41 m4_pushdef([build_expect],[__build_expect([],m4_shift(m4_shift($@)))])
42 42
43 # MIMETEST(NAME,TYPES,FILE,CONTENT,RES) 43 # MIMEIDENTIFY(NAME,TYPES,FILE,CONTENT,RES)
44 m4_pushdef([MIMETEST],[ 44 m4_pushdef([MIMEIDENTIFY],[
45 AT_SETUP([$1]) 45 AT_SETUP([$1])
46 AT_KEYWORDS([mimeview]) 46 AT_KEYWORDS([mimeview])
47 AT_CHECK([ 47 AT_CHECK([
...@@ -55,17 +55,29 @@ mimeview MIMEVIEW_OPTIONS --identify -f mime.types select_args($@) ...@@ -55,17 +55,29 @@ mimeview MIMEVIEW_OPTIONS --identify -f mime.types select_args($@)
55 AT_CLEANUP 55 AT_CLEANUP
56 ]) 56 ])
57 57
58 m4_pushdef([MIMETEST],[
59 AT_SETUP([$1])
60 AT_KEYWORDS([mimeview])
61 AT_CHECK([
62 AT_DATA([mime.types],[$2
63 ])
64 mimeview MIMEVIEW_OPTIONS --debug-level=app.=trace6 -t -f mime.types
65 ],
66 m4_shift(m4_shift($@)))
67 AT_CLEANUP
68 ])
69
58 dnl ------------------------------------------------------------ 70 dnl ------------------------------------------------------------
59 71
60 AT_INIT 72 AT_INIT
61 AT_TESTED([mimeview]) 73 AT_TESTED([mimeview])
62 MUT_VERSION([mimeview]) 74 MUT_VERSION([mimeview])
63 75
64 MIMETEST([default], 76 MIMEIDENTIFY([default],
65 [application/octet-stream], 77 [application/octet-stream],
66 [input], [], [application/octet-stream]) 78 [input], [], [application/octet-stream])
67 79
68 MIMETEST([suffixes], 80 MIMEIDENTIFY([suffixes],
69 [foo/x-bar bar baz 81 [foo/x-bar bar baz
70 foo/x-qux qux quux 82 foo/x-qux qux quux
71 ], 83 ],
...@@ -74,13 +86,13 @@ foo/x-qux qux quux ...@@ -74,13 +86,13 @@ foo/x-qux qux quux
74 [a.quux], [], [foo/x-qux], 86 [a.quux], [], [foo/x-qux],
75 [a.qx], [], [unknown]) 87 [a.qx], [], [unknown])
76 88
77 MIMETEST([default ordering], 89 MIMEIDENTIFY([default ordering],
78 [text/foo bar 90 [text/foo bar
79 text/bar bar 91 text/bar bar
80 ], 92 ],
81 [a.bar], [], [text/bar]) 93 [a.bar], [], [text/bar])
82 94
83 MIMETEST([priority], 95 MIMEIDENTIFY([priority],
84 [text/bar bar 96 [text/bar bar
85 text/foo bar priority(20) 97 text/foo bar priority(20)
86 ], 98 ],
...@@ -89,7 +101,7 @@ text/foo bar priority(20) ...@@ -89,7 +101,7 @@ text/foo bar priority(20)
89 AT_BANNER([Functions]) 101 AT_BANNER([Functions])
90 102
91 # match("pattern") Pattern match on filename 103 # match("pattern") Pattern match on filename
92 MIMETEST([match], 104 MIMEIDENTIFY([match],
93 [application/x-csource match(*.c) 105 [application/x-csource match(*.c)
94 ], 106 ],
95 [a.c],[],[application/x-csource], 107 [a.c],[],[application/x-csource],
...@@ -97,7 +109,7 @@ MIMETEST([match], ...@@ -97,7 +109,7 @@ MIMETEST([match],
97 109
98 # ascii(offset,length) True if bytes are valid printable ASCII 110 # ascii(offset,length) True if bytes are valid printable ASCII
99 # (CR, NL, TAB, BS, 32-126) 111 # (CR, NL, TAB, BS, 32-126)
100 MIMETEST([ascii], 112 MIMEIDENTIFY([ascii],
101 [application/x-bar ascii(16,6) 113 [application/x-bar ascii(16,6)
102 ], 114 ],
103 [one],[-seek 16 -string foobar -int 100],[application/x-bar], 115 [one],[-seek 16 -string foobar -int 100],[application/x-bar],
...@@ -105,7 +117,7 @@ MIMETEST([ascii], ...@@ -105,7 +117,7 @@ MIMETEST([ascii],
105 117
106 # printable(offset,length) True if bytes are printable 8-bit chars 118 # printable(offset,length) True if bytes are printable 8-bit chars
107 # (CR, NL, TAB, BS, 32-126, 128-254) 119 # (CR, NL, TAB, BS, 32-126, 128-254)
108 MIMETEST([printable], 120 MIMEIDENTIFY([printable],
109 [application/x-bar printable(16,6) 121 [application/x-bar printable(16,6)
110 ], 122 ],
111 [one],[-seek 16 -string foobar -int 100],[application/x-bar], 123 [one],[-seek 16 -string foobar -int 100],[application/x-bar],
...@@ -113,14 +125,14 @@ MIMETEST([printable], ...@@ -113,14 +125,14 @@ MIMETEST([printable],
113 [three],[-seek 16 -string fooba -byte 127],[unknown]) 125 [three],[-seek 16 -string fooba -byte 127],[unknown])
114 126
115 # regex(offset,"regex") True if bytes match regular expression 127 # regex(offset,"regex") True if bytes match regular expression
116 MIMETEST([regex], 128 MIMEIDENTIFY([regex],
117 [application/pdf regex(0,^[[\n\r]]*%PDF) 129 [application/pdf regex(0,^[[\n\r]]*%PDF)
118 ], 130 ],
119 [one],[-byte 10 -byte 10 -byte 13 -byte 10 -string %PDF],[application/pdf], 131 [one],[-byte 10 -byte 10 -byte 13 -byte 10 -string %PDF],[application/pdf],
120 [two],[-byte 10 -byte 10 -byte 13 -byte 7 -string %PDF],[unknown]) 132 [two],[-byte 10 -byte 10 -byte 13 -byte 7 -string %PDF],[unknown])
121 133
122 # string(offset,"string") True if bytes are identical to string 134 # string(offset,"string") True if bytes are identical to string
123 MIMETEST([string], 135 MIMEIDENTIFY([string],
124 [application/x-foo string(5,FOO) 136 [application/x-foo string(5,FOO)
125 ], 137 ],
126 [one],[-seek 5 -string FOO],[application/x-foo], 138 [one],[-seek 5 -string FOO],[application/x-foo],
...@@ -128,28 +140,28 @@ MIMETEST([string], ...@@ -128,28 +140,28 @@ MIMETEST([string],
128 140
129 # istring(offset,"string") True if bytes are identical to 141 # istring(offset,"string") True if bytes are identical to
130 # case-insensitive string 142 # case-insensitive string
131 MIMETEST([istring], 143 MIMEIDENTIFY([istring],
132 [application/x-foo istring(5,FOO) 144 [application/x-foo istring(5,FOO)
133 ], 145 ],
134 [one],[-seek 5 -string foO],[application/x-foo], 146 [one],[-seek 5 -string foO],[application/x-foo],
135 [two],[-seek 4 -string FOO],[unknown]) 147 [two],[-seek 4 -string FOO],[unknown])
136 148
137 # char(offset,value) True if byte is identical 149 # char(offset,value) True if byte is identical
138 MIMETEST([char], 150 MIMEIDENTIFY([char],
139 [application/x-foo char(5,15) 151 [application/x-foo char(5,15)
140 ], 152 ],
141 [one],[-seek 5 -byte 15],[application/x-foo], 153 [one],[-seek 5 -byte 15],[application/x-foo],
142 [two],[-seek 5 -byte 1],[unknown]) 154 [two],[-seek 5 -byte 1],[unknown])
143 155
144 # short(offset,value) True if 16-bit integer is identical 156 # short(offset,value) True if 16-bit integer is identical
145 MIMETEST([short], 157 MIMEIDENTIFY([short],
146 [application/x-foo short(5,1600) 158 [application/x-foo short(5,1600)
147 ], 159 ],
148 [one],[-seek 5 -short 1600],[application/x-foo], 160 [one],[-seek 5 -short 1600],[application/x-foo],
149 [two],[-seek 5 -short 1601],[unknown]) 161 [two],[-seek 5 -short 1601],[unknown])
150 162
151 # int(offset,value) True if 32-bit integer is identical 163 # int(offset,value) True if 32-bit integer is identical
152 MIMETEST([int], 164 MIMEIDENTIFY([int],
153 [application/x-foo int(5,16578) 165 [application/x-foo int(5,16578)
154 ], 166 ],
155 [one],[-seek 5 -int 16578],[application/x-foo], 167 [one],[-seek 5 -int 16578],[application/x-foo],
...@@ -159,13 +171,13 @@ MIMETEST([int], ...@@ -159,13 +171,13 @@ MIMETEST([int],
159 # FIXME 171 # FIXME
160 172
161 # contains(offset,range,"string") True if the range contains the string 173 # contains(offset,range,"string") True if the range contains the string
162 MIMETEST([contains], 174 MIMEIDENTIFY([contains],
163 [application/x-foo contains(10,1024,"TESTSTRING") 175 [application/x-foo contains(10,1024,"TESTSTRING")
164 ], 176 ],
165 [one],[-seek 512 -string TESTSTRING],[application/x-foo], 177 [one],[-seek 512 -string TESTSTRING],[application/x-foo],
166 [two],[-seek 512 -string TEST],[unknown]) 178 [two],[-seek 512 -string TEST],[unknown])
167 179
168 MIMETEST([argument strings], 180 MIMEIDENTIFY([argument strings],
169 [application/x-foo string(0,"FOO") 181 [application/x-foo string(0,"FOO")
170 application/x-bar string(0,'B A R') 182 application/x-bar string(0,'B A R')
171 application/x-baz string(0,"B A"Z<1B0103>BAZ) 183 application/x-baz string(0,"B A"Z<1B0103>BAZ)
...@@ -176,7 +188,7 @@ application/x-qux string(0,<1B>45" Q "<01>) ...@@ -176,7 +188,7 @@ application/x-qux string(0,<1B>45" Q "<01>)
176 [three],[-string "B AZ" -byte 0x1b -byte 0x01 -byte 0x03 -string BAZ],[application/x-baz], 188 [three],[-string "B AZ" -byte 0x1b -byte 0x01 -byte 0x03 -string BAZ],[application/x-baz],
177 [four],[-byte 0x1b -string '45 Q ' -byte 0x01],[application/x-qux]) 189 [four],[-byte 0x1b -string '45 Q ' -byte 0x01],[application/x-qux])
178 190
179 MIMETEST([logical or], 191 MIMEIDENTIFY([logical or],
180 [text/x-bar bar baz string(0,bar) printable(3,10) 192 [text/x-bar bar baz string(0,bar) printable(3,10)
181 ], 193 ],
182 [one.bar],[],[text/x-bar], 194 [one.bar],[],[text/x-bar],
...@@ -185,16 +197,53 @@ MIMETEST([logical or], ...@@ -185,16 +197,53 @@ MIMETEST([logical or],
185 [bar],[-seek 3 -string teststring],[text/x-bar], 197 [bar],[-seek 3 -string teststring],[text/x-bar],
186 [baz],[-seek 3 -string test -byte 0 -string tring],[unknown]) 198 [baz],[-seek 3 -string test -byte 0 -string tring],[unknown])
187 199
188 MIMETEST([logical and], 200 MIMEIDENTIFY([logical and],
189 [text/x-foo bar + string(0,bar<10>) + printable(4,10) 201 [text/x-foo bar + string(0,bar<10>) + printable(4,10)
190 ], 202 ],
191 [one.bar],[-string bar -byte 0x10 -string TESTSTRING],[text/x-foo], 203 [one.bar],[-string bar -byte 0x10 -string TESTSTRING],[text/x-foo],
192 [one],[-string bar -byte 0x10 -string TESTSTRING],[unknown], 204 [one],[-string bar -byte 0x10 -string TESTSTRING],[unknown],
193 [two.bar],[-string bar -byte 0x13 -byte 0x10 -string TEST],[unknown]) 205 [two.bar],[-string bar -byte 0x13 -byte 0x10 -string TEST],[unknown])
194 206
195 MIMETEST([grouping], 207 MIMEIDENTIFY([grouping],
196 [text/x-foo bar (string(0,bar) + printable(4,10)) 208 [text/x-foo bar (string(0,bar) + printable(4,10))
197 ], 209 ],
198 [one.bar],[-string foo],[text/x-foo], 210 [one.bar],[-string foo],[text/x-foo],
199 [two.baz],[-string bar -byte 0x10 -string TESTSTRING],[text/x-foo], 211 [two.baz],[-string bar -byte 0x10 -string TESTSTRING],[text/x-foo],
200 [three],[-string bar -byte 0x13 -byte 0x10 -string TESTSTRING],[unknown]) 212 [three],[-string bar -byte 0x13 -byte 0x10 -string TESTSTRING],[unknown])
213
214 MIMETEST([error recovery],
215 [text/x-foo bar (string(0,bar) + printable(4,10))
216 string(10,baz)
217 application/x-baz
218 ],
219 [1],
220 [],
221 [mimeview: mime.types:2.1: type/subtype is missing
222 mime.types:2.1: started error recovery
223 mime.types:3: finished error recovery
224 ])
225
226 MIMETEST([multiple error recovery],
227 [text/x-foo bar (string(0,bar) + printable(4,10))
228 string(10,baz)
229 application/x-baz baz
230 image/jpeg jpeg jpg jpe string(0,<FFD8FF>) &&\
231 (char(3,0xe0) char(3,0xe1) char(3,0xe2) char(3,0xe3)\
232 char(3,0xe4) char(3,0xe5) char(3,0xe6) char(3,0xe7)
233 char(3,0xe8) char(3,0xe9) char(3,0xea) char(3,0xeb)\
234 char(3,0xec) char(3,0xed) char(3,0xee) char(3,0xef))
235 image/tiff tiff tif string(0,MM<002A>) string(0,II<2A00>)
236 ],
237 [1],
238 [],
239 [mimeview: mime.types:2.1: type/subtype is missing
240 mime.types:2.1: started error recovery
241 mime.types:3: finished error recovery
242 mimeview: mime.types:6.63: syntax error
243 mime.types:6.63: started error recovery
244 mime.types:9: finished error recovery
245 ])
246
247
248 m4_popdef([MIMETEST])
249 m4_popdef([MIMEIDENTIFY])
...\ No newline at end of file ...\ No newline at end of file
......