Fossil SCM
Add the /mimetype_list page for use by documentation.
Commit
51751b00a96435fbdf70e1f495255e4b02349c67
Parent
ace8016f297a1d0…
1 file changed
+243
-219
+243
-219
| --- src/doc.c | ||
| +++ src/doc.c | ||
| @@ -65,17 +65,233 @@ | ||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | if( i>=n ){ |
| 68 | 68 | return 0; /* Plain text */ |
| 69 | 69 | } |
| 70 | - for(i=0; i<sizeof(aMime)/sizeof(aMime[0]); i++){ | |
| 70 | + for(i=0; i<ArraySize(aMime); i++){ | |
| 71 | 71 | if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){ |
| 72 | 72 | return aMime[i].zMimetype; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | return "unknown/unknown"; |
| 76 | 76 | } |
| 77 | + | |
| 78 | +/* A table of mimetypes based on file suffixes. | |
| 79 | +** Suffixes must be in sorted order so that we can do a binary | |
| 80 | +** search to find the mime-type | |
| 81 | +*/ | |
| 82 | +static const struct { | |
| 83 | + const char *zSuffix; /* The file suffix */ | |
| 84 | + int size; /* Length of the suffix */ | |
| 85 | + const char *zMimetype; /* The corresponding mimetype */ | |
| 86 | +} aMime[] = { | |
| 87 | + { "ai", 2, "application/postscript" }, | |
| 88 | + { "aif", 3, "audio/x-aiff" }, | |
| 89 | + { "aifc", 4, "audio/x-aiff" }, | |
| 90 | + { "aiff", 4, "audio/x-aiff" }, | |
| 91 | + { "arj", 3, "application/x-arj-compressed" }, | |
| 92 | + { "asc", 3, "text/plain" }, | |
| 93 | + { "asf", 3, "video/x-ms-asf" }, | |
| 94 | + { "asx", 3, "video/x-ms-asx" }, | |
| 95 | + { "au", 2, "audio/ulaw" }, | |
| 96 | + { "avi", 3, "video/x-msvideo" }, | |
| 97 | + { "bat", 3, "application/x-msdos-program" }, | |
| 98 | + { "bcpio", 5, "application/x-bcpio" }, | |
| 99 | + { "bin", 3, "application/octet-stream" }, | |
| 100 | + { "c", 1, "text/plain" }, | |
| 101 | + { "cc", 2, "text/plain" }, | |
| 102 | + { "ccad", 4, "application/clariscad" }, | |
| 103 | + { "cdf", 3, "application/x-netcdf" }, | |
| 104 | + { "class", 5, "application/octet-stream" }, | |
| 105 | + { "cod", 3, "application/vnd.rim.cod" }, | |
| 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" }, | |
| 116 | + { "doc", 3, "application/msword" }, | |
| 117 | + { "docx", 4, "application/vnd.openxmlformats-" | |
| 118 | + "officedocument.wordprocessingml.document"}, | |
| 119 | + { "dot", 3, "application/msword" }, | |
| 120 | + { "dotx", 4, "application/vnd.openxmlformats-" | |
| 121 | + "officedocument.wordprocessingml.template"}, | |
| 122 | + { "drw", 3, "application/drafting" }, | |
| 123 | + { "dvi", 3, "application/x-dvi" }, | |
| 124 | + { "dwg", 3, "application/acad" }, | |
| 125 | + { "dxf", 3, "application/dxf" }, | |
| 126 | + { "dxr", 3, "application/x-director" }, | |
| 127 | + { "eps", 3, "application/postscript" }, | |
| 128 | + { "etx", 3, "text/x-setext" }, | |
| 129 | + { "exe", 3, "application/octet-stream" }, | |
| 130 | + { "ez", 2, "application/andrew-inset" }, | |
| 131 | + { "f", 1, "text/plain" }, | |
| 132 | + { "f90", 3, "text/plain" }, | |
| 133 | + { "fli", 3, "video/fli" }, | |
| 134 | + { "flv", 3, "video/flv" }, | |
| 135 | + { "gif", 3, "image/gif" }, | |
| 136 | + { "gl", 2, "video/gl" }, | |
| 137 | + { "gtar", 4, "application/x-gtar" }, | |
| 138 | + { "gz", 2, "application/x-gzip" }, | |
| 139 | + { "h", 1, "text/plain" }, | |
| 140 | + { "hdf", 3, "application/x-hdf" }, | |
| 141 | + { "hh", 2, "text/plain" }, | |
| 142 | + { "hqx", 3, "application/mac-binhex40" }, | |
| 143 | + { "htm", 3, "text/html" }, | |
| 144 | + { "html", 4, "text/html" }, | |
| 145 | + { "ice", 3, "x-conference/x-cooltalk" }, | |
| 146 | + { "ief", 3, "image/ief" }, | |
| 147 | + { "iges", 4, "model/iges" }, | |
| 148 | + { "igs", 3, "model/iges" }, | |
| 149 | + { "ips", 3, "application/x-ipscript" }, | |
| 150 | + { "ipx", 3, "application/x-ipix" }, | |
| 151 | + { "jad", 3, "text/vnd.sun.j2me.app-descriptor" }, | |
| 152 | + { "jar", 3, "application/java-archive" }, | |
| 153 | + { "jpe", 3, "image/jpeg" }, | |
| 154 | + { "jpeg", 4, "image/jpeg" }, | |
| 155 | + { "jpg", 3, "image/jpeg" }, | |
| 156 | + { "js", 2, "application/x-javascript" }, | |
| 157 | + { "kar", 3, "audio/midi" }, | |
| 158 | + { "latex", 5, "application/x-latex" }, | |
| 159 | + { "lha", 3, "application/octet-stream" }, | |
| 160 | + { "lsp", 3, "application/x-lisp" }, | |
| 161 | + { "lzh", 3, "application/octet-stream" }, | |
| 162 | + { "m", 1, "text/plain" }, | |
| 163 | + { "m3u", 3, "audio/x-mpegurl" }, | |
| 164 | + { "man", 3, "application/x-troff-man" }, | |
| 165 | + { "markdown", 8, "text/x-markdown" }, | |
| 166 | + { "md", 2, "text/x-markdown" }, | |
| 167 | + { "me", 2, "application/x-troff-me" }, | |
| 168 | + { "mesh", 4, "model/mesh" }, | |
| 169 | + { "mid", 3, "audio/midi" }, | |
| 170 | + { "midi", 4, "audio/midi" }, | |
| 171 | + { "mif", 3, "application/x-mif" }, | |
| 172 | + { "mime", 4, "www/mime" }, | |
| 173 | + { "mkd", 3, "text/x-markdown" }, | |
| 174 | + { "mov", 3, "video/quicktime" }, | |
| 175 | + { "movie", 5, "video/x-sgi-movie" }, | |
| 176 | + { "mp2", 3, "audio/mpeg" }, | |
| 177 | + { "mp3", 3, "audio/mpeg" }, | |
| 178 | + { "mp4", 3, "video/mp4" }, | |
| 179 | + { "mpe", 3, "video/mpeg" }, | |
| 180 | + { "mpeg", 4, "video/mpeg" }, | |
| 181 | + { "mpg", 3, "video/mpeg" }, | |
| 182 | + { "mpga", 4, "audio/mpeg" }, | |
| 183 | + { "ms", 2, "application/x-troff-ms" }, | |
| 184 | + { "msh", 3, "model/mesh" }, | |
| 185 | + { "nc", 2, "application/x-netcdf" }, | |
| 186 | + { "oda", 3, "application/oda" }, | |
| 187 | + { "ogg", 3, "application/ogg" }, | |
| 188 | + { "ogm", 3, "application/ogg" }, | |
| 189 | + { "pbm", 3, "image/x-portable-bitmap" }, | |
| 190 | + { "pdb", 3, "chemical/x-pdb" }, | |
| 191 | + { "pdf", 3, "application/pdf" }, | |
| 192 | + { "pgm", 3, "image/x-portable-graymap" }, | |
| 193 | + { "pgn", 3, "application/x-chess-pgn" }, | |
| 194 | + { "pgp", 3, "application/pgp" }, | |
| 195 | + { "pl", 2, "application/x-perl" }, | |
| 196 | + { "pm", 2, "application/x-perl" }, | |
| 197 | + { "png", 3, "image/png" }, | |
| 198 | + { "pnm", 3, "image/x-portable-anymap" }, | |
| 199 | + { "pot", 3, "application/mspowerpoint" }, | |
| 200 | + { "potx", 4, "application/vnd.openxmlformats-" | |
| 201 | + "officedocument.presentationml.template"}, | |
| 202 | + { "ppm", 3, "image/x-portable-pixmap" }, | |
| 203 | + { "pps", 3, "application/mspowerpoint" }, | |
| 204 | + { "ppsx", 4, "application/vnd.openxmlformats-" | |
| 205 | + "officedocument.presentationml.slideshow"}, | |
| 206 | + { "ppt", 3, "application/mspowerpoint" }, | |
| 207 | + { "pptx", 4, "application/vnd.openxmlformats-" | |
| 208 | + "officedocument.presentationml.presentation"}, | |
| 209 | + { "ppz", 3, "application/mspowerpoint" }, | |
| 210 | + { "pre", 3, "application/x-freelance" }, | |
| 211 | + { "prt", 3, "application/pro_eng" }, | |
| 212 | + { "ps", 2, "application/postscript" }, | |
| 213 | + { "qt", 2, "video/quicktime" }, | |
| 214 | + { "ra", 2, "audio/x-realaudio" }, | |
| 215 | + { "ram", 3, "audio/x-pn-realaudio" }, | |
| 216 | + { "rar", 3, "application/x-rar-compressed" }, | |
| 217 | + { "ras", 3, "image/cmu-raster" }, | |
| 218 | + { "rgb", 3, "image/x-rgb" }, | |
| 219 | + { "rm", 2, "audio/x-pn-realaudio" }, | |
| 220 | + { "roff", 4, "application/x-troff" }, | |
| 221 | + { "rpm", 3, "audio/x-pn-realaudio-plugin" }, | |
| 222 | + { "rtf", 3, "text/rtf" }, | |
| 223 | + { "rtx", 3, "text/richtext" }, | |
| 224 | + { "scm", 3, "application/x-lotusscreencam" }, | |
| 225 | + { "set", 3, "application/set" }, | |
| 226 | + { "sgm", 3, "text/sgml" }, | |
| 227 | + { "sgml", 4, "text/sgml" }, | |
| 228 | + { "sh", 2, "application/x-sh" }, | |
| 229 | + { "shar", 4, "application/x-shar" }, | |
| 230 | + { "silo", 4, "model/mesh" }, | |
| 231 | + { "sit", 3, "application/x-stuffit" }, | |
| 232 | + { "skd", 3, "application/x-koan" }, | |
| 233 | + { "skm", 3, "application/x-koan" }, | |
| 234 | + { "skp", 3, "application/x-koan" }, | |
| 235 | + { "skt", 3, "application/x-koan" }, | |
| 236 | + { "smi", 3, "application/smil" }, | |
| 237 | + { "smil", 4, "application/smil" }, | |
| 238 | + { "snd", 3, "audio/basic" }, | |
| 239 | + { "sol", 3, "application/solids" }, | |
| 240 | + { "spl", 3, "application/x-futuresplash" }, | |
| 241 | + { "src", 3, "application/x-wais-source" }, | |
| 242 | + { "step", 4, "application/STEP" }, | |
| 243 | + { "stl", 3, "application/SLA" }, | |
| 244 | + { "stp", 3, "application/STEP" }, | |
| 245 | + { "sv4cpio", 7, "application/x-sv4cpio" }, | |
| 246 | + { "sv4crc", 6, "application/x-sv4crc" }, | |
| 247 | + { "svg", 3, "image/svg+xml" }, | |
| 248 | + { "swf", 3, "application/x-shockwave-flash" }, | |
| 249 | + { "t", 1, "application/x-troff" }, | |
| 250 | + { "tar", 3, "application/x-tar" }, | |
| 251 | + { "tcl", 3, "application/x-tcl" }, | |
| 252 | + { "tex", 3, "application/x-tex" }, | |
| 253 | + { "texi", 4, "application/x-texinfo" }, | |
| 254 | + { "texinfo", 7, "application/x-texinfo" }, | |
| 255 | + { "tgz", 3, "application/x-tar-gz" }, | |
| 256 | + { "th1", 3, "application/x-th1" }, | |
| 257 | + { "tif", 3, "image/tiff" }, | |
| 258 | + { "tiff", 4, "image/tiff" }, | |
| 259 | + { "tr", 2, "application/x-troff" }, | |
| 260 | + { "tsi", 3, "audio/TSP-audio" }, | |
| 261 | + { "tsp", 3, "application/dsptype" }, | |
| 262 | + { "tsv", 3, "text/tab-separated-values" }, | |
| 263 | + { "txt", 3, "text/plain" }, | |
| 264 | + { "unv", 3, "application/i-deas" }, | |
| 265 | + { "ustar", 5, "application/x-ustar" }, | |
| 266 | + { "vcd", 3, "application/x-cdlink" }, | |
| 267 | + { "vda", 3, "application/vda" }, | |
| 268 | + { "viv", 3, "video/vnd.vivo" }, | |
| 269 | + { "vivo", 4, "video/vnd.vivo" }, | |
| 270 | + { "vrml", 4, "model/vrml" }, | |
| 271 | + { "wav", 3, "audio/x-wav" }, | |
| 272 | + { "wax", 3, "audio/x-ms-wax" }, | |
| 273 | + { "wiki", 4, "text/x-fossil-wiki" }, | |
| 274 | + { "wma", 3, "audio/x-ms-wma" }, | |
| 275 | + { "wmv", 3, "video/x-ms-wmv" }, | |
| 276 | + { "wmx", 3, "video/x-ms-wmx" }, | |
| 277 | + { "wrl", 3, "model/vrml" }, | |
| 278 | + { "wvx", 3, "video/x-ms-wvx" }, | |
| 279 | + { "xbm", 3, "image/x-xbitmap" }, | |
| 280 | + { "xlc", 3, "application/vnd.ms-excel" }, | |
| 281 | + { "xll", 3, "application/vnd.ms-excel" }, | |
| 282 | + { "xlm", 3, "application/vnd.ms-excel" }, | |
| 283 | + { "xls", 3, "application/vnd.ms-excel" }, | |
| 284 | + { "xlsx", 4, "application/vnd.openxmlformats-" | |
| 285 | + "officedocument.spreadsheetml.sheet"}, | |
| 286 | + { "xlw", 3, "application/vnd.ms-excel" }, | |
| 287 | + { "xml", 3, "text/xml" }, | |
| 288 | + { "xpm", 3, "image/x-xpixmap" }, | |
| 289 | + { "xwd", 3, "image/x-xwindowdump" }, | |
| 290 | + { "xyz", 3, "chemical/x-pdb" }, | |
| 291 | + { "zip", 3, "application/zip" }, | |
| 292 | +}; | |
| 77 | 293 | |
| 78 | 294 | /* |
| 79 | 295 | ** Guess the mime-type of a document based on its name. |
| 80 | 296 | */ |
| 81 | 297 | const char *mimetype_from_name(const char *zName){ |
| @@ -83,232 +299,17 @@ | ||
| 83 | 299 | int i; |
| 84 | 300 | int first, last; |
| 85 | 301 | int len; |
| 86 | 302 | char zSuffix[20]; |
| 87 | 303 | |
| 88 | - /* A table of mimetypes based on file suffixes. | |
| 89 | - ** Suffixes must be in sorted order so that we can do a binary | |
| 90 | - ** search to find the mime-type | |
| 91 | - */ | |
| 92 | - static const struct { | |
| 93 | - const char *zSuffix; /* The file suffix */ | |
| 94 | - int size; /* Length of the suffix */ | |
| 95 | - const char *zMimetype; /* The corresponding mimetype */ | |
| 96 | - } aMime[] = { | |
| 97 | - { "ai", 2, "application/postscript" }, | |
| 98 | - { "aif", 3, "audio/x-aiff" }, | |
| 99 | - { "aifc", 4, "audio/x-aiff" }, | |
| 100 | - { "aiff", 4, "audio/x-aiff" }, | |
| 101 | - { "arj", 3, "application/x-arj-compressed" }, | |
| 102 | - { "asc", 3, "text/plain" }, | |
| 103 | - { "asf", 3, "video/x-ms-asf" }, | |
| 104 | - { "asx", 3, "video/x-ms-asx" }, | |
| 105 | - { "au", 2, "audio/ulaw" }, | |
| 106 | - { "avi", 3, "video/x-msvideo" }, | |
| 107 | - { "bat", 3, "application/x-msdos-program" }, | |
| 108 | - { "bcpio", 5, "application/x-bcpio" }, | |
| 109 | - { "bin", 3, "application/octet-stream" }, | |
| 110 | - { "c", 1, "text/plain" }, | |
| 111 | - { "cc", 2, "text/plain" }, | |
| 112 | - { "ccad", 4, "application/clariscad" }, | |
| 113 | - { "cdf", 3, "application/x-netcdf" }, | |
| 114 | - { "class", 5, "application/octet-stream" }, | |
| 115 | - { "cod", 3, "application/vnd.rim.cod" }, | |
| 116 | - { "com", 3, "application/x-msdos-program" }, | |
| 117 | - { "cpio", 4, "application/x-cpio" }, | |
| 118 | - { "cpt", 3, "application/mac-compactpro" }, | |
| 119 | - { "csh", 3, "application/x-csh" }, | |
| 120 | - { "css", 3, "text/css" }, | |
| 121 | - { "dcr", 3, "application/x-director" }, | |
| 122 | - { "deb", 3, "application/x-debian-package" }, | |
| 123 | - { "dir", 3, "application/x-director" }, | |
| 124 | - { "dl", 2, "video/dl" }, | |
| 125 | - { "dms", 3, "application/octet-stream" }, | |
| 126 | - { "doc", 3, "application/msword" }, | |
| 127 | - { "docx", 4, "application/vnd.openxmlformats-" | |
| 128 | - "officedocument.wordprocessingml.document"}, | |
| 129 | - { "dot", 3, "application/msword" }, | |
| 130 | - { "dotx", 4, "application/vnd.openxmlformats-" | |
| 131 | - "officedocument.wordprocessingml.template"}, | |
| 132 | - { "drw", 3, "application/drafting" }, | |
| 133 | - { "dvi", 3, "application/x-dvi" }, | |
| 134 | - { "dwg", 3, "application/acad" }, | |
| 135 | - { "dxf", 3, "application/dxf" }, | |
| 136 | - { "dxr", 3, "application/x-director" }, | |
| 137 | - { "eps", 3, "application/postscript" }, | |
| 138 | - { "etx", 3, "text/x-setext" }, | |
| 139 | - { "exe", 3, "application/octet-stream" }, | |
| 140 | - { "ez", 2, "application/andrew-inset" }, | |
| 141 | - { "f", 1, "text/plain" }, | |
| 142 | - { "f90", 3, "text/plain" }, | |
| 143 | - { "fli", 3, "video/fli" }, | |
| 144 | - { "flv", 3, "video/flv" }, | |
| 145 | - { "gif", 3, "image/gif" }, | |
| 146 | - { "gl", 2, "video/gl" }, | |
| 147 | - { "gtar", 4, "application/x-gtar" }, | |
| 148 | - { "gz", 2, "application/x-gzip" }, | |
| 149 | - { "h", 1, "text/plain" }, | |
| 150 | - { "hdf", 3, "application/x-hdf" }, | |
| 151 | - { "hh", 2, "text/plain" }, | |
| 152 | - { "hqx", 3, "application/mac-binhex40" }, | |
| 153 | - { "htm", 3, "text/html" }, | |
| 154 | - { "html", 4, "text/html" }, | |
| 155 | - { "ice", 3, "x-conference/x-cooltalk" }, | |
| 156 | - { "ief", 3, "image/ief" }, | |
| 157 | - { "iges", 4, "model/iges" }, | |
| 158 | - { "igs", 3, "model/iges" }, | |
| 159 | - { "ips", 3, "application/x-ipscript" }, | |
| 160 | - { "ipx", 3, "application/x-ipix" }, | |
| 161 | - { "jad", 3, "text/vnd.sun.j2me.app-descriptor" }, | |
| 162 | - { "jar", 3, "application/java-archive" }, | |
| 163 | - { "jpe", 3, "image/jpeg" }, | |
| 164 | - { "jpeg", 4, "image/jpeg" }, | |
| 165 | - { "jpg", 3, "image/jpeg" }, | |
| 166 | - { "js", 2, "application/x-javascript" }, | |
| 167 | - { "kar", 3, "audio/midi" }, | |
| 168 | - { "latex", 5, "application/x-latex" }, | |
| 169 | - { "lha", 3, "application/octet-stream" }, | |
| 170 | - { "lsp", 3, "application/x-lisp" }, | |
| 171 | - { "lzh", 3, "application/octet-stream" }, | |
| 172 | - { "m", 1, "text/plain" }, | |
| 173 | - { "m3u", 3, "audio/x-mpegurl" }, | |
| 174 | - { "man", 3, "application/x-troff-man" }, | |
| 175 | - { "markdown", 8, "text/x-markdown" }, | |
| 176 | - { "md", 2, "text/x-markdown" }, | |
| 177 | - { "me", 2, "application/x-troff-me" }, | |
| 178 | - { "mesh", 4, "model/mesh" }, | |
| 179 | - { "mid", 3, "audio/midi" }, | |
| 180 | - { "midi", 4, "audio/midi" }, | |
| 181 | - { "mif", 3, "application/x-mif" }, | |
| 182 | - { "mime", 4, "www/mime" }, | |
| 183 | - { "mkd", 3, "text/x-markdown" }, | |
| 184 | - { "mov", 3, "video/quicktime" }, | |
| 185 | - { "movie", 5, "video/x-sgi-movie" }, | |
| 186 | - { "mp2", 3, "audio/mpeg" }, | |
| 187 | - { "mp3", 3, "audio/mpeg" }, | |
| 188 | - { "mp4", 3, "video/mp4" }, | |
| 189 | - { "mpe", 3, "video/mpeg" }, | |
| 190 | - { "mpeg", 4, "video/mpeg" }, | |
| 191 | - { "mpg", 3, "video/mpeg" }, | |
| 192 | - { "mpga", 4, "audio/mpeg" }, | |
| 193 | - { "ms", 2, "application/x-troff-ms" }, | |
| 194 | - { "msh", 3, "model/mesh" }, | |
| 195 | - { "nc", 2, "application/x-netcdf" }, | |
| 196 | - { "oda", 3, "application/oda" }, | |
| 197 | - { "ogg", 3, "application/ogg" }, | |
| 198 | - { "ogm", 3, "application/ogg" }, | |
| 199 | - { "pbm", 3, "image/x-portable-bitmap" }, | |
| 200 | - { "pdb", 3, "chemical/x-pdb" }, | |
| 201 | - { "pdf", 3, "application/pdf" }, | |
| 202 | - { "pgm", 3, "image/x-portable-graymap" }, | |
| 203 | - { "pgn", 3, "application/x-chess-pgn" }, | |
| 204 | - { "pgp", 3, "application/pgp" }, | |
| 205 | - { "pl", 2, "application/x-perl" }, | |
| 206 | - { "pm", 2, "application/x-perl" }, | |
| 207 | - { "png", 3, "image/png" }, | |
| 208 | - { "pnm", 3, "image/x-portable-anymap" }, | |
| 209 | - { "pot", 3, "application/mspowerpoint" }, | |
| 210 | - { "potx", 4, "application/vnd.openxmlformats-" | |
| 211 | - "officedocument.presentationml.template"}, | |
| 212 | - { "ppm", 3, "image/x-portable-pixmap" }, | |
| 213 | - { "pps", 3, "application/mspowerpoint" }, | |
| 214 | - { "ppsx", 4, "application/vnd.openxmlformats-" | |
| 215 | - "officedocument.presentationml.slideshow"}, | |
| 216 | - { "ppt", 3, "application/mspowerpoint" }, | |
| 217 | - { "pptx", 4, "application/vnd.openxmlformats-" | |
| 218 | - "officedocument.presentationml.presentation"}, | |
| 219 | - { "ppz", 3, "application/mspowerpoint" }, | |
| 220 | - { "pre", 3, "application/x-freelance" }, | |
| 221 | - { "prt", 3, "application/pro_eng" }, | |
| 222 | - { "ps", 2, "application/postscript" }, | |
| 223 | - { "qt", 2, "video/quicktime" }, | |
| 224 | - { "ra", 2, "audio/x-realaudio" }, | |
| 225 | - { "ram", 3, "audio/x-pn-realaudio" }, | |
| 226 | - { "rar", 3, "application/x-rar-compressed" }, | |
| 227 | - { "ras", 3, "image/cmu-raster" }, | |
| 228 | - { "rgb", 3, "image/x-rgb" }, | |
| 229 | - { "rm", 2, "audio/x-pn-realaudio" }, | |
| 230 | - { "roff", 4, "application/x-troff" }, | |
| 231 | - { "rpm", 3, "audio/x-pn-realaudio-plugin" }, | |
| 232 | - { "rtf", 3, "text/rtf" }, | |
| 233 | - { "rtx", 3, "text/richtext" }, | |
| 234 | - { "scm", 3, "application/x-lotusscreencam" }, | |
| 235 | - { "set", 3, "application/set" }, | |
| 236 | - { "sgm", 3, "text/sgml" }, | |
| 237 | - { "sgml", 4, "text/sgml" }, | |
| 238 | - { "sh", 2, "application/x-sh" }, | |
| 239 | - { "shar", 4, "application/x-shar" }, | |
| 240 | - { "silo", 4, "model/mesh" }, | |
| 241 | - { "sit", 3, "application/x-stuffit" }, | |
| 242 | - { "skd", 3, "application/x-koan" }, | |
| 243 | - { "skm", 3, "application/x-koan" }, | |
| 244 | - { "skp", 3, "application/x-koan" }, | |
| 245 | - { "skt", 3, "application/x-koan" }, | |
| 246 | - { "smi", 3, "application/smil" }, | |
| 247 | - { "smil", 4, "application/smil" }, | |
| 248 | - { "snd", 3, "audio/basic" }, | |
| 249 | - { "sol", 3, "application/solids" }, | |
| 250 | - { "spl", 3, "application/x-futuresplash" }, | |
| 251 | - { "src", 3, "application/x-wais-source" }, | |
| 252 | - { "step", 4, "application/STEP" }, | |
| 253 | - { "stl", 3, "application/SLA" }, | |
| 254 | - { "stp", 3, "application/STEP" }, | |
| 255 | - { "sv4cpio", 7, "application/x-sv4cpio" }, | |
| 256 | - { "sv4crc", 6, "application/x-sv4crc" }, | |
| 257 | - { "svg", 3, "image/svg+xml" }, | |
| 258 | - { "swf", 3, "application/x-shockwave-flash" }, | |
| 259 | - { "t", 1, "application/x-troff" }, | |
| 260 | - { "tar", 3, "application/x-tar" }, | |
| 261 | - { "tcl", 3, "application/x-tcl" }, | |
| 262 | - { "tex", 3, "application/x-tex" }, | |
| 263 | - { "texi", 4, "application/x-texinfo" }, | |
| 264 | - { "texinfo", 7, "application/x-texinfo" }, | |
| 265 | - { "tgz", 3, "application/x-tar-gz" }, | |
| 266 | - { "th1", 3, "application/x-th1" }, | |
| 267 | - { "tif", 3, "image/tiff" }, | |
| 268 | - { "tiff", 4, "image/tiff" }, | |
| 269 | - { "tr", 2, "application/x-troff" }, | |
| 270 | - { "tsi", 3, "audio/TSP-audio" }, | |
| 271 | - { "tsp", 3, "application/dsptype" }, | |
| 272 | - { "tsv", 3, "text/tab-separated-values" }, | |
| 273 | - { "txt", 3, "text/plain" }, | |
| 274 | - { "unv", 3, "application/i-deas" }, | |
| 275 | - { "ustar", 5, "application/x-ustar" }, | |
| 276 | - { "vcd", 3, "application/x-cdlink" }, | |
| 277 | - { "vda", 3, "application/vda" }, | |
| 278 | - { "viv", 3, "video/vnd.vivo" }, | |
| 279 | - { "vivo", 4, "video/vnd.vivo" }, | |
| 280 | - { "vrml", 4, "model/vrml" }, | |
| 281 | - { "wav", 3, "audio/x-wav" }, | |
| 282 | - { "wax", 3, "audio/x-ms-wax" }, | |
| 283 | - { "wiki", 4, "text/x-fossil-wiki" }, | |
| 284 | - { "wma", 3, "audio/x-ms-wma" }, | |
| 285 | - { "wmv", 3, "video/x-ms-wmv" }, | |
| 286 | - { "wmx", 3, "video/x-ms-wmx" }, | |
| 287 | - { "wrl", 3, "model/vrml" }, | |
| 288 | - { "wvx", 3, "video/x-ms-wvx" }, | |
| 289 | - { "xbm", 3, "image/x-xbitmap" }, | |
| 290 | - { "xlc", 3, "application/vnd.ms-excel" }, | |
| 291 | - { "xll", 3, "application/vnd.ms-excel" }, | |
| 292 | - { "xlm", 3, "application/vnd.ms-excel" }, | |
| 293 | - { "xls", 3, "application/vnd.ms-excel" }, | |
| 294 | - { "xlsx", 4, "application/vnd.openxmlformats-" | |
| 295 | - "officedocument.spreadsheetml.sheet"}, | |
| 296 | - { "xlw", 3, "application/vnd.ms-excel" }, | |
| 297 | - { "xml", 3, "text/xml" }, | |
| 298 | - { "xpm", 3, "image/x-xpixmap" }, | |
| 299 | - { "xwd", 3, "image/x-xwindowdump" }, | |
| 300 | - { "xyz", 3, "chemical/x-pdb" }, | |
| 301 | - { "zip", 3, "application/zip" }, | |
| 302 | - }; | |
| 303 | 304 | |
| 304 | 305 | #ifdef FOSSIL_DEBUG |
| 305 | 306 | /* This is test code to make sure the table above is in the correct |
| 306 | 307 | ** order |
| 307 | 308 | */ |
| 308 | 309 | if( fossil_strcmp(zName, "mimetype-test")==0 ){ |
| 309 | - for(i=1; i<sizeof(aMime)/sizeof(aMime[0]); i++){ | |
| 310 | + for(i=1; i<ArraySize(aMime); i++){ | |
| 310 | 311 | if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ |
| 311 | 312 | fossil_fatal("mimetypes out of sequence: %s before %s", |
| 312 | 313 | aMime[i-1].zSuffix, aMime[i].zSuffix); |
| 313 | 314 | } |
| 314 | 315 | } |
| @@ -323,11 +324,11 @@ | ||
| 323 | 324 | len = strlen(z); |
| 324 | 325 | if( len<sizeof(zSuffix)-1 ){ |
| 325 | 326 | sqlite3_snprintf(sizeof(zSuffix), zSuffix, "%s", z); |
| 326 | 327 | for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]); |
| 327 | 328 | first = 0; |
| 328 | - last = sizeof(aMime)/sizeof(aMime[0]) - 1; | |
| 329 | + last = ArraySize(aMime) - 1; | |
| 329 | 330 | while( first<=last ){ |
| 330 | 331 | int c; |
| 331 | 332 | i = (first+last)/2; |
| 332 | 333 | c = fossil_strcmp(zSuffix, aMime[i].zSuffix); |
| 333 | 334 | if( c==0 ) return aMime[i].zMimetype; |
| @@ -357,11 +358,34 @@ | ||
| 357 | 358 | for(i=2; i<g.argc; i++){ |
| 358 | 359 | fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i])); |
| 359 | 360 | } |
| 360 | 361 | } |
| 361 | 362 | |
| 362 | - | |
| 363 | +/* | |
| 364 | +** WEBPAGE: mimetype_list | |
| 365 | +** | |
| 366 | +** Show the built-in table used to guess embedded document mimetypes | |
| 367 | +** from file suffixes. | |
| 368 | +*/ | |
| 369 | +void mimetype_list_page(void){ | |
| 370 | + int i; | |
| 371 | + style_header("Mimetype List"); | |
| 372 | + @ <p>The Fossil <a href="%R/help?cmd=/doc">/doc</a> page uses filename | |
| 373 | + @ suffixes and the following table to guess at the appropriate mimetype | |
| 374 | + @ for each document.</p> | |
| 375 | + @ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'> | |
| 376 | + @ <thead> | |
| 377 | + @ <tr><th>Suffix<th>Mimetype | |
| 378 | + @ </thead> | |
| 379 | + @ <tbody> | |
| 380 | + for(i=0; i<ArraySize(aMime); i++){ | |
| 381 | + @ <tr><td>%h(aMime[i].zSuffix)<td>%h(aMime[i].zMimetype)</tr> | |
| 382 | + } | |
| 383 | + @ </tbody></table> | |
| 384 | + output_table_sorting_javascript("mimeTable","tt",1); | |
| 385 | + style_footer(); | |
| 386 | +} | |
| 363 | 387 | |
| 364 | 388 | /* |
| 365 | 389 | ** Check to see if the file in the pContent blob is "embedded HTML". Return |
| 366 | 390 | ** true if it is, and fill pTitle with the document title. |
| 367 | 391 | ** |
| 368 | 392 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -65,17 +65,233 @@ | |
| 65 | } |
| 66 | } |
| 67 | if( i>=n ){ |
| 68 | return 0; /* Plain text */ |
| 69 | } |
| 70 | for(i=0; i<sizeof(aMime)/sizeof(aMime[0]); i++){ |
| 71 | if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){ |
| 72 | return aMime[i].zMimetype; |
| 73 | } |
| 74 | } |
| 75 | return "unknown/unknown"; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | ** Guess the mime-type of a document based on its name. |
| 80 | */ |
| 81 | const char *mimetype_from_name(const char *zName){ |
| @@ -83,232 +299,17 @@ | |
| 83 | int i; |
| 84 | int first, last; |
| 85 | int len; |
| 86 | char zSuffix[20]; |
| 87 | |
| 88 | /* A table of mimetypes based on file suffixes. |
| 89 | ** Suffixes must be in sorted order so that we can do a binary |
| 90 | ** search to find the mime-type |
| 91 | */ |
| 92 | static const struct { |
| 93 | const char *zSuffix; /* The file suffix */ |
| 94 | int size; /* Length of the suffix */ |
| 95 | const char *zMimetype; /* The corresponding mimetype */ |
| 96 | } aMime[] = { |
| 97 | { "ai", 2, "application/postscript" }, |
| 98 | { "aif", 3, "audio/x-aiff" }, |
| 99 | { "aifc", 4, "audio/x-aiff" }, |
| 100 | { "aiff", 4, "audio/x-aiff" }, |
| 101 | { "arj", 3, "application/x-arj-compressed" }, |
| 102 | { "asc", 3, "text/plain" }, |
| 103 | { "asf", 3, "video/x-ms-asf" }, |
| 104 | { "asx", 3, "video/x-ms-asx" }, |
| 105 | { "au", 2, "audio/ulaw" }, |
| 106 | { "avi", 3, "video/x-msvideo" }, |
| 107 | { "bat", 3, "application/x-msdos-program" }, |
| 108 | { "bcpio", 5, "application/x-bcpio" }, |
| 109 | { "bin", 3, "application/octet-stream" }, |
| 110 | { "c", 1, "text/plain" }, |
| 111 | { "cc", 2, "text/plain" }, |
| 112 | { "ccad", 4, "application/clariscad" }, |
| 113 | { "cdf", 3, "application/x-netcdf" }, |
| 114 | { "class", 5, "application/octet-stream" }, |
| 115 | { "cod", 3, "application/vnd.rim.cod" }, |
| 116 | { "com", 3, "application/x-msdos-program" }, |
| 117 | { "cpio", 4, "application/x-cpio" }, |
| 118 | { "cpt", 3, "application/mac-compactpro" }, |
| 119 | { "csh", 3, "application/x-csh" }, |
| 120 | { "css", 3, "text/css" }, |
| 121 | { "dcr", 3, "application/x-director" }, |
| 122 | { "deb", 3, "application/x-debian-package" }, |
| 123 | { "dir", 3, "application/x-director" }, |
| 124 | { "dl", 2, "video/dl" }, |
| 125 | { "dms", 3, "application/octet-stream" }, |
| 126 | { "doc", 3, "application/msword" }, |
| 127 | { "docx", 4, "application/vnd.openxmlformats-" |
| 128 | "officedocument.wordprocessingml.document"}, |
| 129 | { "dot", 3, "application/msword" }, |
| 130 | { "dotx", 4, "application/vnd.openxmlformats-" |
| 131 | "officedocument.wordprocessingml.template"}, |
| 132 | { "drw", 3, "application/drafting" }, |
| 133 | { "dvi", 3, "application/x-dvi" }, |
| 134 | { "dwg", 3, "application/acad" }, |
| 135 | { "dxf", 3, "application/dxf" }, |
| 136 | { "dxr", 3, "application/x-director" }, |
| 137 | { "eps", 3, "application/postscript" }, |
| 138 | { "etx", 3, "text/x-setext" }, |
| 139 | { "exe", 3, "application/octet-stream" }, |
| 140 | { "ez", 2, "application/andrew-inset" }, |
| 141 | { "f", 1, "text/plain" }, |
| 142 | { "f90", 3, "text/plain" }, |
| 143 | { "fli", 3, "video/fli" }, |
| 144 | { "flv", 3, "video/flv" }, |
| 145 | { "gif", 3, "image/gif" }, |
| 146 | { "gl", 2, "video/gl" }, |
| 147 | { "gtar", 4, "application/x-gtar" }, |
| 148 | { "gz", 2, "application/x-gzip" }, |
| 149 | { "h", 1, "text/plain" }, |
| 150 | { "hdf", 3, "application/x-hdf" }, |
| 151 | { "hh", 2, "text/plain" }, |
| 152 | { "hqx", 3, "application/mac-binhex40" }, |
| 153 | { "htm", 3, "text/html" }, |
| 154 | { "html", 4, "text/html" }, |
| 155 | { "ice", 3, "x-conference/x-cooltalk" }, |
| 156 | { "ief", 3, "image/ief" }, |
| 157 | { "iges", 4, "model/iges" }, |
| 158 | { "igs", 3, "model/iges" }, |
| 159 | { "ips", 3, "application/x-ipscript" }, |
| 160 | { "ipx", 3, "application/x-ipix" }, |
| 161 | { "jad", 3, "text/vnd.sun.j2me.app-descriptor" }, |
| 162 | { "jar", 3, "application/java-archive" }, |
| 163 | { "jpe", 3, "image/jpeg" }, |
| 164 | { "jpeg", 4, "image/jpeg" }, |
| 165 | { "jpg", 3, "image/jpeg" }, |
| 166 | { "js", 2, "application/x-javascript" }, |
| 167 | { "kar", 3, "audio/midi" }, |
| 168 | { "latex", 5, "application/x-latex" }, |
| 169 | { "lha", 3, "application/octet-stream" }, |
| 170 | { "lsp", 3, "application/x-lisp" }, |
| 171 | { "lzh", 3, "application/octet-stream" }, |
| 172 | { "m", 1, "text/plain" }, |
| 173 | { "m3u", 3, "audio/x-mpegurl" }, |
| 174 | { "man", 3, "application/x-troff-man" }, |
| 175 | { "markdown", 8, "text/x-markdown" }, |
| 176 | { "md", 2, "text/x-markdown" }, |
| 177 | { "me", 2, "application/x-troff-me" }, |
| 178 | { "mesh", 4, "model/mesh" }, |
| 179 | { "mid", 3, "audio/midi" }, |
| 180 | { "midi", 4, "audio/midi" }, |
| 181 | { "mif", 3, "application/x-mif" }, |
| 182 | { "mime", 4, "www/mime" }, |
| 183 | { "mkd", 3, "text/x-markdown" }, |
| 184 | { "mov", 3, "video/quicktime" }, |
| 185 | { "movie", 5, "video/x-sgi-movie" }, |
| 186 | { "mp2", 3, "audio/mpeg" }, |
| 187 | { "mp3", 3, "audio/mpeg" }, |
| 188 | { "mp4", 3, "video/mp4" }, |
| 189 | { "mpe", 3, "video/mpeg" }, |
| 190 | { "mpeg", 4, "video/mpeg" }, |
| 191 | { "mpg", 3, "video/mpeg" }, |
| 192 | { "mpga", 4, "audio/mpeg" }, |
| 193 | { "ms", 2, "application/x-troff-ms" }, |
| 194 | { "msh", 3, "model/mesh" }, |
| 195 | { "nc", 2, "application/x-netcdf" }, |
| 196 | { "oda", 3, "application/oda" }, |
| 197 | { "ogg", 3, "application/ogg" }, |
| 198 | { "ogm", 3, "application/ogg" }, |
| 199 | { "pbm", 3, "image/x-portable-bitmap" }, |
| 200 | { "pdb", 3, "chemical/x-pdb" }, |
| 201 | { "pdf", 3, "application/pdf" }, |
| 202 | { "pgm", 3, "image/x-portable-graymap" }, |
| 203 | { "pgn", 3, "application/x-chess-pgn" }, |
| 204 | { "pgp", 3, "application/pgp" }, |
| 205 | { "pl", 2, "application/x-perl" }, |
| 206 | { "pm", 2, "application/x-perl" }, |
| 207 | { "png", 3, "image/png" }, |
| 208 | { "pnm", 3, "image/x-portable-anymap" }, |
| 209 | { "pot", 3, "application/mspowerpoint" }, |
| 210 | { "potx", 4, "application/vnd.openxmlformats-" |
| 211 | "officedocument.presentationml.template"}, |
| 212 | { "ppm", 3, "image/x-portable-pixmap" }, |
| 213 | { "pps", 3, "application/mspowerpoint" }, |
| 214 | { "ppsx", 4, "application/vnd.openxmlformats-" |
| 215 | "officedocument.presentationml.slideshow"}, |
| 216 | { "ppt", 3, "application/mspowerpoint" }, |
| 217 | { "pptx", 4, "application/vnd.openxmlformats-" |
| 218 | "officedocument.presentationml.presentation"}, |
| 219 | { "ppz", 3, "application/mspowerpoint" }, |
| 220 | { "pre", 3, "application/x-freelance" }, |
| 221 | { "prt", 3, "application/pro_eng" }, |
| 222 | { "ps", 2, "application/postscript" }, |
| 223 | { "qt", 2, "video/quicktime" }, |
| 224 | { "ra", 2, "audio/x-realaudio" }, |
| 225 | { "ram", 3, "audio/x-pn-realaudio" }, |
| 226 | { "rar", 3, "application/x-rar-compressed" }, |
| 227 | { "ras", 3, "image/cmu-raster" }, |
| 228 | { "rgb", 3, "image/x-rgb" }, |
| 229 | { "rm", 2, "audio/x-pn-realaudio" }, |
| 230 | { "roff", 4, "application/x-troff" }, |
| 231 | { "rpm", 3, "audio/x-pn-realaudio-plugin" }, |
| 232 | { "rtf", 3, "text/rtf" }, |
| 233 | { "rtx", 3, "text/richtext" }, |
| 234 | { "scm", 3, "application/x-lotusscreencam" }, |
| 235 | { "set", 3, "application/set" }, |
| 236 | { "sgm", 3, "text/sgml" }, |
| 237 | { "sgml", 4, "text/sgml" }, |
| 238 | { "sh", 2, "application/x-sh" }, |
| 239 | { "shar", 4, "application/x-shar" }, |
| 240 | { "silo", 4, "model/mesh" }, |
| 241 | { "sit", 3, "application/x-stuffit" }, |
| 242 | { "skd", 3, "application/x-koan" }, |
| 243 | { "skm", 3, "application/x-koan" }, |
| 244 | { "skp", 3, "application/x-koan" }, |
| 245 | { "skt", 3, "application/x-koan" }, |
| 246 | { "smi", 3, "application/smil" }, |
| 247 | { "smil", 4, "application/smil" }, |
| 248 | { "snd", 3, "audio/basic" }, |
| 249 | { "sol", 3, "application/solids" }, |
| 250 | { "spl", 3, "application/x-futuresplash" }, |
| 251 | { "src", 3, "application/x-wais-source" }, |
| 252 | { "step", 4, "application/STEP" }, |
| 253 | { "stl", 3, "application/SLA" }, |
| 254 | { "stp", 3, "application/STEP" }, |
| 255 | { "sv4cpio", 7, "application/x-sv4cpio" }, |
| 256 | { "sv4crc", 6, "application/x-sv4crc" }, |
| 257 | { "svg", 3, "image/svg+xml" }, |
| 258 | { "swf", 3, "application/x-shockwave-flash" }, |
| 259 | { "t", 1, "application/x-troff" }, |
| 260 | { "tar", 3, "application/x-tar" }, |
| 261 | { "tcl", 3, "application/x-tcl" }, |
| 262 | { "tex", 3, "application/x-tex" }, |
| 263 | { "texi", 4, "application/x-texinfo" }, |
| 264 | { "texinfo", 7, "application/x-texinfo" }, |
| 265 | { "tgz", 3, "application/x-tar-gz" }, |
| 266 | { "th1", 3, "application/x-th1" }, |
| 267 | { "tif", 3, "image/tiff" }, |
| 268 | { "tiff", 4, "image/tiff" }, |
| 269 | { "tr", 2, "application/x-troff" }, |
| 270 | { "tsi", 3, "audio/TSP-audio" }, |
| 271 | { "tsp", 3, "application/dsptype" }, |
| 272 | { "tsv", 3, "text/tab-separated-values" }, |
| 273 | { "txt", 3, "text/plain" }, |
| 274 | { "unv", 3, "application/i-deas" }, |
| 275 | { "ustar", 5, "application/x-ustar" }, |
| 276 | { "vcd", 3, "application/x-cdlink" }, |
| 277 | { "vda", 3, "application/vda" }, |
| 278 | { "viv", 3, "video/vnd.vivo" }, |
| 279 | { "vivo", 4, "video/vnd.vivo" }, |
| 280 | { "vrml", 4, "model/vrml" }, |
| 281 | { "wav", 3, "audio/x-wav" }, |
| 282 | { "wax", 3, "audio/x-ms-wax" }, |
| 283 | { "wiki", 4, "text/x-fossil-wiki" }, |
| 284 | { "wma", 3, "audio/x-ms-wma" }, |
| 285 | { "wmv", 3, "video/x-ms-wmv" }, |
| 286 | { "wmx", 3, "video/x-ms-wmx" }, |
| 287 | { "wrl", 3, "model/vrml" }, |
| 288 | { "wvx", 3, "video/x-ms-wvx" }, |
| 289 | { "xbm", 3, "image/x-xbitmap" }, |
| 290 | { "xlc", 3, "application/vnd.ms-excel" }, |
| 291 | { "xll", 3, "application/vnd.ms-excel" }, |
| 292 | { "xlm", 3, "application/vnd.ms-excel" }, |
| 293 | { "xls", 3, "application/vnd.ms-excel" }, |
| 294 | { "xlsx", 4, "application/vnd.openxmlformats-" |
| 295 | "officedocument.spreadsheetml.sheet"}, |
| 296 | { "xlw", 3, "application/vnd.ms-excel" }, |
| 297 | { "xml", 3, "text/xml" }, |
| 298 | { "xpm", 3, "image/x-xpixmap" }, |
| 299 | { "xwd", 3, "image/x-xwindowdump" }, |
| 300 | { "xyz", 3, "chemical/x-pdb" }, |
| 301 | { "zip", 3, "application/zip" }, |
| 302 | }; |
| 303 | |
| 304 | #ifdef FOSSIL_DEBUG |
| 305 | /* This is test code to make sure the table above is in the correct |
| 306 | ** order |
| 307 | */ |
| 308 | if( fossil_strcmp(zName, "mimetype-test")==0 ){ |
| 309 | for(i=1; i<sizeof(aMime)/sizeof(aMime[0]); i++){ |
| 310 | if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ |
| 311 | fossil_fatal("mimetypes out of sequence: %s before %s", |
| 312 | aMime[i-1].zSuffix, aMime[i].zSuffix); |
| 313 | } |
| 314 | } |
| @@ -323,11 +324,11 @@ | |
| 323 | len = strlen(z); |
| 324 | if( len<sizeof(zSuffix)-1 ){ |
| 325 | sqlite3_snprintf(sizeof(zSuffix), zSuffix, "%s", z); |
| 326 | for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]); |
| 327 | first = 0; |
| 328 | last = sizeof(aMime)/sizeof(aMime[0]) - 1; |
| 329 | while( first<=last ){ |
| 330 | int c; |
| 331 | i = (first+last)/2; |
| 332 | c = fossil_strcmp(zSuffix, aMime[i].zSuffix); |
| 333 | if( c==0 ) return aMime[i].zMimetype; |
| @@ -357,11 +358,34 @@ | |
| 357 | for(i=2; i<g.argc; i++){ |
| 358 | fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i])); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | |
| 363 | |
| 364 | /* |
| 365 | ** Check to see if the file in the pContent blob is "embedded HTML". Return |
| 366 | ** true if it is, and fill pTitle with the document title. |
| 367 | ** |
| 368 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -65,17 +65,233 @@ | |
| 65 | } |
| 66 | } |
| 67 | if( i>=n ){ |
| 68 | return 0; /* Plain text */ |
| 69 | } |
| 70 | for(i=0; i<ArraySize(aMime); i++){ |
| 71 | if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){ |
| 72 | return aMime[i].zMimetype; |
| 73 | } |
| 74 | } |
| 75 | return "unknown/unknown"; |
| 76 | } |
| 77 | |
| 78 | /* A table of mimetypes based on file suffixes. |
| 79 | ** Suffixes must be in sorted order so that we can do a binary |
| 80 | ** search to find the mime-type |
| 81 | */ |
| 82 | static const struct { |
| 83 | const char *zSuffix; /* The file suffix */ |
| 84 | int size; /* Length of the suffix */ |
| 85 | const char *zMimetype; /* The corresponding mimetype */ |
| 86 | } aMime[] = { |
| 87 | { "ai", 2, "application/postscript" }, |
| 88 | { "aif", 3, "audio/x-aiff" }, |
| 89 | { "aifc", 4, "audio/x-aiff" }, |
| 90 | { "aiff", 4, "audio/x-aiff" }, |
| 91 | { "arj", 3, "application/x-arj-compressed" }, |
| 92 | { "asc", 3, "text/plain" }, |
| 93 | { "asf", 3, "video/x-ms-asf" }, |
| 94 | { "asx", 3, "video/x-ms-asx" }, |
| 95 | { "au", 2, "audio/ulaw" }, |
| 96 | { "avi", 3, "video/x-msvideo" }, |
| 97 | { "bat", 3, "application/x-msdos-program" }, |
| 98 | { "bcpio", 5, "application/x-bcpio" }, |
| 99 | { "bin", 3, "application/octet-stream" }, |
| 100 | { "c", 1, "text/plain" }, |
| 101 | { "cc", 2, "text/plain" }, |
| 102 | { "ccad", 4, "application/clariscad" }, |
| 103 | { "cdf", 3, "application/x-netcdf" }, |
| 104 | { "class", 5, "application/octet-stream" }, |
| 105 | { "cod", 3, "application/vnd.rim.cod" }, |
| 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" }, |
| 116 | { "doc", 3, "application/msword" }, |
| 117 | { "docx", 4, "application/vnd.openxmlformats-" |
| 118 | "officedocument.wordprocessingml.document"}, |
| 119 | { "dot", 3, "application/msword" }, |
| 120 | { "dotx", 4, "application/vnd.openxmlformats-" |
| 121 | "officedocument.wordprocessingml.template"}, |
| 122 | { "drw", 3, "application/drafting" }, |
| 123 | { "dvi", 3, "application/x-dvi" }, |
| 124 | { "dwg", 3, "application/acad" }, |
| 125 | { "dxf", 3, "application/dxf" }, |
| 126 | { "dxr", 3, "application/x-director" }, |
| 127 | { "eps", 3, "application/postscript" }, |
| 128 | { "etx", 3, "text/x-setext" }, |
| 129 | { "exe", 3, "application/octet-stream" }, |
| 130 | { "ez", 2, "application/andrew-inset" }, |
| 131 | { "f", 1, "text/plain" }, |
| 132 | { "f90", 3, "text/plain" }, |
| 133 | { "fli", 3, "video/fli" }, |
| 134 | { "flv", 3, "video/flv" }, |
| 135 | { "gif", 3, "image/gif" }, |
| 136 | { "gl", 2, "video/gl" }, |
| 137 | { "gtar", 4, "application/x-gtar" }, |
| 138 | { "gz", 2, "application/x-gzip" }, |
| 139 | { "h", 1, "text/plain" }, |
| 140 | { "hdf", 3, "application/x-hdf" }, |
| 141 | { "hh", 2, "text/plain" }, |
| 142 | { "hqx", 3, "application/mac-binhex40" }, |
| 143 | { "htm", 3, "text/html" }, |
| 144 | { "html", 4, "text/html" }, |
| 145 | { "ice", 3, "x-conference/x-cooltalk" }, |
| 146 | { "ief", 3, "image/ief" }, |
| 147 | { "iges", 4, "model/iges" }, |
| 148 | { "igs", 3, "model/iges" }, |
| 149 | { "ips", 3, "application/x-ipscript" }, |
| 150 | { "ipx", 3, "application/x-ipix" }, |
| 151 | { "jad", 3, "text/vnd.sun.j2me.app-descriptor" }, |
| 152 | { "jar", 3, "application/java-archive" }, |
| 153 | { "jpe", 3, "image/jpeg" }, |
| 154 | { "jpeg", 4, "image/jpeg" }, |
| 155 | { "jpg", 3, "image/jpeg" }, |
| 156 | { "js", 2, "application/x-javascript" }, |
| 157 | { "kar", 3, "audio/midi" }, |
| 158 | { "latex", 5, "application/x-latex" }, |
| 159 | { "lha", 3, "application/octet-stream" }, |
| 160 | { "lsp", 3, "application/x-lisp" }, |
| 161 | { "lzh", 3, "application/octet-stream" }, |
| 162 | { "m", 1, "text/plain" }, |
| 163 | { "m3u", 3, "audio/x-mpegurl" }, |
| 164 | { "man", 3, "application/x-troff-man" }, |
| 165 | { "markdown", 8, "text/x-markdown" }, |
| 166 | { "md", 2, "text/x-markdown" }, |
| 167 | { "me", 2, "application/x-troff-me" }, |
| 168 | { "mesh", 4, "model/mesh" }, |
| 169 | { "mid", 3, "audio/midi" }, |
| 170 | { "midi", 4, "audio/midi" }, |
| 171 | { "mif", 3, "application/x-mif" }, |
| 172 | { "mime", 4, "www/mime" }, |
| 173 | { "mkd", 3, "text/x-markdown" }, |
| 174 | { "mov", 3, "video/quicktime" }, |
| 175 | { "movie", 5, "video/x-sgi-movie" }, |
| 176 | { "mp2", 3, "audio/mpeg" }, |
| 177 | { "mp3", 3, "audio/mpeg" }, |
| 178 | { "mp4", 3, "video/mp4" }, |
| 179 | { "mpe", 3, "video/mpeg" }, |
| 180 | { "mpeg", 4, "video/mpeg" }, |
| 181 | { "mpg", 3, "video/mpeg" }, |
| 182 | { "mpga", 4, "audio/mpeg" }, |
| 183 | { "ms", 2, "application/x-troff-ms" }, |
| 184 | { "msh", 3, "model/mesh" }, |
| 185 | { "nc", 2, "application/x-netcdf" }, |
| 186 | { "oda", 3, "application/oda" }, |
| 187 | { "ogg", 3, "application/ogg" }, |
| 188 | { "ogm", 3, "application/ogg" }, |
| 189 | { "pbm", 3, "image/x-portable-bitmap" }, |
| 190 | { "pdb", 3, "chemical/x-pdb" }, |
| 191 | { "pdf", 3, "application/pdf" }, |
| 192 | { "pgm", 3, "image/x-portable-graymap" }, |
| 193 | { "pgn", 3, "application/x-chess-pgn" }, |
| 194 | { "pgp", 3, "application/pgp" }, |
| 195 | { "pl", 2, "application/x-perl" }, |
| 196 | { "pm", 2, "application/x-perl" }, |
| 197 | { "png", 3, "image/png" }, |
| 198 | { "pnm", 3, "image/x-portable-anymap" }, |
| 199 | { "pot", 3, "application/mspowerpoint" }, |
| 200 | { "potx", 4, "application/vnd.openxmlformats-" |
| 201 | "officedocument.presentationml.template"}, |
| 202 | { "ppm", 3, "image/x-portable-pixmap" }, |
| 203 | { "pps", 3, "application/mspowerpoint" }, |
| 204 | { "ppsx", 4, "application/vnd.openxmlformats-" |
| 205 | "officedocument.presentationml.slideshow"}, |
| 206 | { "ppt", 3, "application/mspowerpoint" }, |
| 207 | { "pptx", 4, "application/vnd.openxmlformats-" |
| 208 | "officedocument.presentationml.presentation"}, |
| 209 | { "ppz", 3, "application/mspowerpoint" }, |
| 210 | { "pre", 3, "application/x-freelance" }, |
| 211 | { "prt", 3, "application/pro_eng" }, |
| 212 | { "ps", 2, "application/postscript" }, |
| 213 | { "qt", 2, "video/quicktime" }, |
| 214 | { "ra", 2, "audio/x-realaudio" }, |
| 215 | { "ram", 3, "audio/x-pn-realaudio" }, |
| 216 | { "rar", 3, "application/x-rar-compressed" }, |
| 217 | { "ras", 3, "image/cmu-raster" }, |
| 218 | { "rgb", 3, "image/x-rgb" }, |
| 219 | { "rm", 2, "audio/x-pn-realaudio" }, |
| 220 | { "roff", 4, "application/x-troff" }, |
| 221 | { "rpm", 3, "audio/x-pn-realaudio-plugin" }, |
| 222 | { "rtf", 3, "text/rtf" }, |
| 223 | { "rtx", 3, "text/richtext" }, |
| 224 | { "scm", 3, "application/x-lotusscreencam" }, |
| 225 | { "set", 3, "application/set" }, |
| 226 | { "sgm", 3, "text/sgml" }, |
| 227 | { "sgml", 4, "text/sgml" }, |
| 228 | { "sh", 2, "application/x-sh" }, |
| 229 | { "shar", 4, "application/x-shar" }, |
| 230 | { "silo", 4, "model/mesh" }, |
| 231 | { "sit", 3, "application/x-stuffit" }, |
| 232 | { "skd", 3, "application/x-koan" }, |
| 233 | { "skm", 3, "application/x-koan" }, |
| 234 | { "skp", 3, "application/x-koan" }, |
| 235 | { "skt", 3, "application/x-koan" }, |
| 236 | { "smi", 3, "application/smil" }, |
| 237 | { "smil", 4, "application/smil" }, |
| 238 | { "snd", 3, "audio/basic" }, |
| 239 | { "sol", 3, "application/solids" }, |
| 240 | { "spl", 3, "application/x-futuresplash" }, |
| 241 | { "src", 3, "application/x-wais-source" }, |
| 242 | { "step", 4, "application/STEP" }, |
| 243 | { "stl", 3, "application/SLA" }, |
| 244 | { "stp", 3, "application/STEP" }, |
| 245 | { "sv4cpio", 7, "application/x-sv4cpio" }, |
| 246 | { "sv4crc", 6, "application/x-sv4crc" }, |
| 247 | { "svg", 3, "image/svg+xml" }, |
| 248 | { "swf", 3, "application/x-shockwave-flash" }, |
| 249 | { "t", 1, "application/x-troff" }, |
| 250 | { "tar", 3, "application/x-tar" }, |
| 251 | { "tcl", 3, "application/x-tcl" }, |
| 252 | { "tex", 3, "application/x-tex" }, |
| 253 | { "texi", 4, "application/x-texinfo" }, |
| 254 | { "texinfo", 7, "application/x-texinfo" }, |
| 255 | { "tgz", 3, "application/x-tar-gz" }, |
| 256 | { "th1", 3, "application/x-th1" }, |
| 257 | { "tif", 3, "image/tiff" }, |
| 258 | { "tiff", 4, "image/tiff" }, |
| 259 | { "tr", 2, "application/x-troff" }, |
| 260 | { "tsi", 3, "audio/TSP-audio" }, |
| 261 | { "tsp", 3, "application/dsptype" }, |
| 262 | { "tsv", 3, "text/tab-separated-values" }, |
| 263 | { "txt", 3, "text/plain" }, |
| 264 | { "unv", 3, "application/i-deas" }, |
| 265 | { "ustar", 5, "application/x-ustar" }, |
| 266 | { "vcd", 3, "application/x-cdlink" }, |
| 267 | { "vda", 3, "application/vda" }, |
| 268 | { "viv", 3, "video/vnd.vivo" }, |
| 269 | { "vivo", 4, "video/vnd.vivo" }, |
| 270 | { "vrml", 4, "model/vrml" }, |
| 271 | { "wav", 3, "audio/x-wav" }, |
| 272 | { "wax", 3, "audio/x-ms-wax" }, |
| 273 | { "wiki", 4, "text/x-fossil-wiki" }, |
| 274 | { "wma", 3, "audio/x-ms-wma" }, |
| 275 | { "wmv", 3, "video/x-ms-wmv" }, |
| 276 | { "wmx", 3, "video/x-ms-wmx" }, |
| 277 | { "wrl", 3, "model/vrml" }, |
| 278 | { "wvx", 3, "video/x-ms-wvx" }, |
| 279 | { "xbm", 3, "image/x-xbitmap" }, |
| 280 | { "xlc", 3, "application/vnd.ms-excel" }, |
| 281 | { "xll", 3, "application/vnd.ms-excel" }, |
| 282 | { "xlm", 3, "application/vnd.ms-excel" }, |
| 283 | { "xls", 3, "application/vnd.ms-excel" }, |
| 284 | { "xlsx", 4, "application/vnd.openxmlformats-" |
| 285 | "officedocument.spreadsheetml.sheet"}, |
| 286 | { "xlw", 3, "application/vnd.ms-excel" }, |
| 287 | { "xml", 3, "text/xml" }, |
| 288 | { "xpm", 3, "image/x-xpixmap" }, |
| 289 | { "xwd", 3, "image/x-xwindowdump" }, |
| 290 | { "xyz", 3, "chemical/x-pdb" }, |
| 291 | { "zip", 3, "application/zip" }, |
| 292 | }; |
| 293 | |
| 294 | /* |
| 295 | ** Guess the mime-type of a document based on its name. |
| 296 | */ |
| 297 | const char *mimetype_from_name(const char *zName){ |
| @@ -83,232 +299,17 @@ | |
| 299 | int i; |
| 300 | int first, last; |
| 301 | int len; |
| 302 | char zSuffix[20]; |
| 303 | |
| 304 | |
| 305 | #ifdef FOSSIL_DEBUG |
| 306 | /* This is test code to make sure the table above is in the correct |
| 307 | ** order |
| 308 | */ |
| 309 | if( fossil_strcmp(zName, "mimetype-test")==0 ){ |
| 310 | for(i=1; i<ArraySize(aMime); i++){ |
| 311 | if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){ |
| 312 | fossil_fatal("mimetypes out of sequence: %s before %s", |
| 313 | aMime[i-1].zSuffix, aMime[i].zSuffix); |
| 314 | } |
| 315 | } |
| @@ -323,11 +324,11 @@ | |
| 324 | len = strlen(z); |
| 325 | if( len<sizeof(zSuffix)-1 ){ |
| 326 | sqlite3_snprintf(sizeof(zSuffix), zSuffix, "%s", z); |
| 327 | for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]); |
| 328 | first = 0; |
| 329 | last = ArraySize(aMime) - 1; |
| 330 | while( first<=last ){ |
| 331 | int c; |
| 332 | i = (first+last)/2; |
| 333 | c = fossil_strcmp(zSuffix, aMime[i].zSuffix); |
| 334 | if( c==0 ) return aMime[i].zMimetype; |
| @@ -357,11 +358,34 @@ | |
| 358 | for(i=2; i<g.argc; i++){ |
| 359 | fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i])); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | ** WEBPAGE: mimetype_list |
| 365 | ** |
| 366 | ** Show the built-in table used to guess embedded document mimetypes |
| 367 | ** from file suffixes. |
| 368 | */ |
| 369 | void mimetype_list_page(void){ |
| 370 | int i; |
| 371 | style_header("Mimetype List"); |
| 372 | @ <p>The Fossil <a href="%R/help?cmd=/doc">/doc</a> page uses filename |
| 373 | @ suffixes and the following table to guess at the appropriate mimetype |
| 374 | @ for each document.</p> |
| 375 | @ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'> |
| 376 | @ <thead> |
| 377 | @ <tr><th>Suffix<th>Mimetype |
| 378 | @ </thead> |
| 379 | @ <tbody> |
| 380 | for(i=0; i<ArraySize(aMime); i++){ |
| 381 | @ <tr><td>%h(aMime[i].zSuffix)<td>%h(aMime[i].zMimetype)</tr> |
| 382 | } |
| 383 | @ </tbody></table> |
| 384 | output_table_sorting_javascript("mimeTable","tt",1); |
| 385 | style_footer(); |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | ** Check to see if the file in the pContent blob is "embedded HTML". Return |
| 390 | ** true if it is, and fill pTitle with the document title. |
| 391 | ** |
| 392 |