Fossil SCM
Add text/csv to the mimetype table. Add additional code to verify that the mimetype table is well-ordered.
Commit
e4c420b4373cc7f7d37fdf1bdc2512320aba4edb
Parent
ef2db66199048db…
1 file changed
+18
-6
+18
-6
| --- src/doc.c | ||
| +++ src/doc.c | ||
| @@ -106,10 +106,11 @@ | ||
| 106 | 106 | { "com", 3, "application/x-msdos-program" }, |
| 107 | 107 | { "cpio", 4, "application/x-cpio" }, |
| 108 | 108 | { "cpt", 3, "application/mac-compactpro" }, |
| 109 | 109 | { "csh", 3, "application/x-csh" }, |
| 110 | 110 | { "css", 3, "text/css" }, |
| 111 | + { "csv", 3, "text/csv" }, | |
| 111 | 112 | { "dcr", 3, "application/x-director" }, |
| 112 | 113 | { "deb", 3, "application/x-debian-package" }, |
| 113 | 114 | { "dir", 3, "application/x-director" }, |
| 114 | 115 | { "dl", 2, "video/dl" }, |
| 115 | 116 | { "dms", 3, "application/octet-stream" }, |
| @@ -291,10 +292,24 @@ | ||
| 291 | 292 | { "xpm", 3, "image/x-xpixmap" }, |
| 292 | 293 | { "xwd", 3, "image/x-xwindowdump" }, |
| 293 | 294 | { "xyz", 3, "chemical/x-pdb" }, |
| 294 | 295 | { "zip", 3, "application/zip" }, |
| 295 | 296 | }; |
| 297 | + | |
| 298 | +/* | |
| 299 | +** Verify that all entries in the aMime[] table are in sorted order. | |
| 300 | +** Abort with a fatal error if any is out-of-order. | |
| 301 | +*/ | |
| 302 | +static void mimetype_verify(void){ | |
| 303 | + int i; | |
| 304 | + for(i=1; i<ArraySize(aMime); i++){ | |
| 305 | + if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ | |
| 306 | + fossil_fatal("mimetypes out of sequence: %s before %s", | |
| 307 | + aMime[i-1].zSuffix, aMime[i].zSuffix); | |
| 308 | + } | |
| 309 | + } | |
| 310 | +} | |
| 296 | 311 | |
| 297 | 312 | /* |
| 298 | 313 | ** Guess the mime-type of a document based on its name. |
| 299 | 314 | */ |
| 300 | 315 | const char *mimetype_from_name(const char *zName){ |
| @@ -308,16 +323,11 @@ | ||
| 308 | 323 | #ifdef FOSSIL_DEBUG |
| 309 | 324 | /* This is test code to make sure the table above is in the correct |
| 310 | 325 | ** order |
| 311 | 326 | */ |
| 312 | 327 | if( fossil_strcmp(zName, "mimetype-test")==0 ){ |
| 313 | - for(i=1; i<ArraySize(aMime); i++){ | |
| 314 | - if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ | |
| 315 | - fossil_fatal("mimetypes out of sequence: %s before %s", | |
| 316 | - aMime[i-1].zSuffix, aMime[i].zSuffix); | |
| 317 | - } | |
| 318 | - } | |
| 328 | + mimetype_verify(); | |
| 319 | 329 | return "ok"; |
| 320 | 330 | } |
| 321 | 331 | #endif |
| 322 | 332 | |
| 323 | 333 | z = zName; |
| @@ -356,10 +366,11 @@ | ||
| 356 | 366 | ** filename is special and verifies the integrity of the mimetype table. |
| 357 | 367 | ** It should return "ok". |
| 358 | 368 | */ |
| 359 | 369 | void mimetype_test_cmd(void){ |
| 360 | 370 | int i; |
| 371 | + mimetype_verify(); | |
| 361 | 372 | for(i=2; i<g.argc; i++){ |
| 362 | 373 | fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i])); |
| 363 | 374 | } |
| 364 | 375 | } |
| 365 | 376 | |
| @@ -369,10 +380,11 @@ | ||
| 369 | 380 | ** Show the built-in table used to guess embedded document mimetypes |
| 370 | 381 | ** from file suffixes. |
| 371 | 382 | */ |
| 372 | 383 | void mimetype_list_page(void){ |
| 373 | 384 | int i; |
| 385 | + mimetype_verify(); | |
| 374 | 386 | style_header("Mimetype List"); |
| 375 | 387 | @ <p>The Fossil <a href="%R/help?cmd=/doc">/doc</a> page uses filename |
| 376 | 388 | @ suffixes and the following table to guess at the appropriate mimetype |
| 377 | 389 | @ for each document.</p> |
| 378 | 390 | @ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'> |
| 379 | 391 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -106,10 +106,11 @@ | |
| 106 | { "com", 3, "application/x-msdos-program" }, |
| 107 | { "cpio", 4, "application/x-cpio" }, |
| 108 | { "cpt", 3, "application/mac-compactpro" }, |
| 109 | { "csh", 3, "application/x-csh" }, |
| 110 | { "css", 3, "text/css" }, |
| 111 | { "dcr", 3, "application/x-director" }, |
| 112 | { "deb", 3, "application/x-debian-package" }, |
| 113 | { "dir", 3, "application/x-director" }, |
| 114 | { "dl", 2, "video/dl" }, |
| 115 | { "dms", 3, "application/octet-stream" }, |
| @@ -291,10 +292,24 @@ | |
| 291 | { "xpm", 3, "image/x-xpixmap" }, |
| 292 | { "xwd", 3, "image/x-xwindowdump" }, |
| 293 | { "xyz", 3, "chemical/x-pdb" }, |
| 294 | { "zip", 3, "application/zip" }, |
| 295 | }; |
| 296 | |
| 297 | /* |
| 298 | ** Guess the mime-type of a document based on its name. |
| 299 | */ |
| 300 | const char *mimetype_from_name(const char *zName){ |
| @@ -308,16 +323,11 @@ | |
| 308 | #ifdef FOSSIL_DEBUG |
| 309 | /* This is test code to make sure the table above is in the correct |
| 310 | ** order |
| 311 | */ |
| 312 | if( fossil_strcmp(zName, "mimetype-test")==0 ){ |
| 313 | for(i=1; i<ArraySize(aMime); i++){ |
| 314 | if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ |
| 315 | fossil_fatal("mimetypes out of sequence: %s before %s", |
| 316 | aMime[i-1].zSuffix, aMime[i].zSuffix); |
| 317 | } |
| 318 | } |
| 319 | return "ok"; |
| 320 | } |
| 321 | #endif |
| 322 | |
| 323 | z = zName; |
| @@ -356,10 +366,11 @@ | |
| 356 | ** filename is special and verifies the integrity of the mimetype table. |
| 357 | ** It should return "ok". |
| 358 | */ |
| 359 | void mimetype_test_cmd(void){ |
| 360 | int i; |
| 361 | for(i=2; i<g.argc; i++){ |
| 362 | fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i])); |
| 363 | } |
| 364 | } |
| 365 | |
| @@ -369,10 +380,11 @@ | |
| 369 | ** Show the built-in table used to guess embedded document mimetypes |
| 370 | ** from file suffixes. |
| 371 | */ |
| 372 | void mimetype_list_page(void){ |
| 373 | int i; |
| 374 | style_header("Mimetype List"); |
| 375 | @ <p>The Fossil <a href="%R/help?cmd=/doc">/doc</a> page uses filename |
| 376 | @ suffixes and the following table to guess at the appropriate mimetype |
| 377 | @ for each document.</p> |
| 378 | @ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'> |
| 379 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -106,10 +106,11 @@ | |
| 106 | { "com", 3, "application/x-msdos-program" }, |
| 107 | { "cpio", 4, "application/x-cpio" }, |
| 108 | { "cpt", 3, "application/mac-compactpro" }, |
| 109 | { "csh", 3, "application/x-csh" }, |
| 110 | { "css", 3, "text/css" }, |
| 111 | { "csv", 3, "text/csv" }, |
| 112 | { "dcr", 3, "application/x-director" }, |
| 113 | { "deb", 3, "application/x-debian-package" }, |
| 114 | { "dir", 3, "application/x-director" }, |
| 115 | { "dl", 2, "video/dl" }, |
| 116 | { "dms", 3, "application/octet-stream" }, |
| @@ -291,10 +292,24 @@ | |
| 292 | { "xpm", 3, "image/x-xpixmap" }, |
| 293 | { "xwd", 3, "image/x-xwindowdump" }, |
| 294 | { "xyz", 3, "chemical/x-pdb" }, |
| 295 | { "zip", 3, "application/zip" }, |
| 296 | }; |
| 297 | |
| 298 | /* |
| 299 | ** Verify that all entries in the aMime[] table are in sorted order. |
| 300 | ** Abort with a fatal error if any is out-of-order. |
| 301 | */ |
| 302 | static void mimetype_verify(void){ |
| 303 | int i; |
| 304 | for(i=1; i<ArraySize(aMime); i++){ |
| 305 | if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ |
| 306 | fossil_fatal("mimetypes out of sequence: %s before %s", |
| 307 | aMime[i-1].zSuffix, aMime[i].zSuffix); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | ** Guess the mime-type of a document based on its name. |
| 314 | */ |
| 315 | const char *mimetype_from_name(const char *zName){ |
| @@ -308,16 +323,11 @@ | |
| 323 | #ifdef FOSSIL_DEBUG |
| 324 | /* This is test code to make sure the table above is in the correct |
| 325 | ** order |
| 326 | */ |
| 327 | if( fossil_strcmp(zName, "mimetype-test")==0 ){ |
| 328 | mimetype_verify(); |
| 329 | return "ok"; |
| 330 | } |
| 331 | #endif |
| 332 | |
| 333 | z = zName; |
| @@ -356,10 +366,11 @@ | |
| 366 | ** filename is special and verifies the integrity of the mimetype table. |
| 367 | ** It should return "ok". |
| 368 | */ |
| 369 | void mimetype_test_cmd(void){ |
| 370 | int i; |
| 371 | mimetype_verify(); |
| 372 | for(i=2; i<g.argc; i++){ |
| 373 | fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i])); |
| 374 | } |
| 375 | } |
| 376 | |
| @@ -369,10 +380,11 @@ | |
| 380 | ** Show the built-in table used to guess embedded document mimetypes |
| 381 | ** from file suffixes. |
| 382 | */ |
| 383 | void mimetype_list_page(void){ |
| 384 | int i; |
| 385 | mimetype_verify(); |
| 386 | style_header("Mimetype List"); |
| 387 | @ <p>The Fossil <a href="%R/help?cmd=/doc">/doc</a> page uses filename |
| 388 | @ suffixes and the following table to guess at the appropriate mimetype |
| 389 | @ for each document.</p> |
| 390 | @ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'> |
| 391 |