]>
Commit | Line | Data |
---|---|---|
57555697 | 1 | /* |
71fe22b7 | 2 | * "$Id: testmime.c,v 1.8 2000/01/04 13:45:37 mike Exp $" |
57555697 | 3 | * |
3a193f5e | 4 | * MIME test program for the Common UNIX Printing System (CUPS). |
57555697 | 5 | * |
71fe22b7 | 6 | * Copyright 1997-2000 by Easy Software Products, all rights reserved. |
57555697 | 7 | * |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
8784b6a6 | 17 | * 44141 Airport View Drive, Suite 204 |
57555697 | 18 | * Hollywood, Maryland 20636-3111 USA |
19 | * | |
20 | * Voice: (301) 373-9603 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
0b74af7d | 26 | * main() - Main entry for the test program. |
57555697 | 27 | */ |
28 | ||
29 | /* | |
30 | * Include necessary headers... | |
31 | */ | |
32 | ||
3b960317 | 33 | #include <stdio.h> |
0b74af7d | 34 | #include "mime.h" |
35 | ||
36 | ||
37 | /* | |
38 | * Local functions... | |
39 | */ | |
40 | ||
41 | static void print_rules(mime_magic_t *rules); | |
42 | ||
43 | ||
44 | /* | |
45 | * 'main()' - Main entry for the test program. | |
46 | */ | |
47 | ||
3a193f5e | 48 | int /* O - Exit status */ |
0b74af7d | 49 | main(int argc, /* I - Number of command-line args */ |
50 | char *argv[]) /* I - Command-line arguments */ | |
51 | { | |
52 | int i; /* Looping var */ | |
53 | char super[MIME_MAX_SUPER], /* Super-type name */ | |
54 | type[MIME_MAX_TYPE]; /* Type name */ | |
55 | mime_t *mime; /* MIME database */ | |
56 | mime_type_t *src, /* Source type */ | |
57 | *dst, /* Destination type */ | |
58 | **types; /* File type array pointer */ | |
59 | mime_filter_t *filters; /* Filters for the file */ | |
60 | int num_filters; /* Number of filters for the file */ | |
61 | ||
62 | ||
3a193f5e | 63 | mime = mimeLoad("../conf"); |
0b74af7d | 64 | |
65 | puts("MIME database types:"); | |
66 | for (i = 0, types = mime->types; i < mime->num_types; i ++, types ++) | |
67 | { | |
68 | printf("\t%s/%s: ", (*types)->super, (*types)->type); | |
69 | print_rules((*types)->rules); | |
70 | puts(""); | |
e8fda7b9 | 71 | } |
0b74af7d | 72 | |
73 | puts(""); | |
74 | ||
75 | puts("MIME database filters:"); | |
76 | for (i = 0, filters = mime->filters; i < mime->num_filters; i ++, filters ++) | |
77 | printf("\t%s/%s to %s/%s: %s (%d)\n", | |
78 | filters->src->super, filters->src->type, | |
79 | filters->dst->super, filters->dst->type, | |
80 | filters->filter, filters->cost); | |
81 | ||
82 | puts(""); | |
83 | ||
84 | switch (argc) | |
85 | { | |
86 | default : | |
87 | fputs("Usage: testmime source-file [destination-type]\n", stderr); | |
88 | return (1); | |
89 | ||
90 | case 2 : | |
91 | src = mimeFileType(mime, argv[1]); | |
92 | ||
93 | if (src != NULL) | |
94 | { | |
95 | printf("%s: %s/%s\n", argv[1], src->super, src->type); | |
96 | return (0); | |
97 | } | |
98 | else | |
99 | { | |
100 | printf("%s: unknown\n", argv[1]); | |
101 | return (1); | |
e8fda7b9 | 102 | } |
0b74af7d | 103 | |
104 | case 3 : | |
105 | src = mimeFileType(mime, argv[1]); | |
106 | ||
04d61d56 | 107 | sscanf(argv[2], "%15[^/]/31%s", super, type); |
0b74af7d | 108 | dst = mimeType(mime, super, type); |
109 | ||
110 | filters = mimeFilter(mime, src, dst, &num_filters); | |
111 | ||
112 | if (filters == NULL) | |
113 | { | |
114 | printf("No filters to convert from %s to %s.\n", argv[1], argv[2]); | |
115 | return (1); | |
116 | } | |
117 | else | |
118 | { | |
119 | for (i = 0; i < num_filters; i ++) | |
120 | if (i < (num_filters - 1)) | |
121 | printf("%s | ", filters[i].filter); | |
122 | else | |
123 | puts(filters[i].filter); | |
124 | ||
125 | return (0); | |
e8fda7b9 | 126 | } |
127 | } | |
0b74af7d | 128 | } |
129 | ||
130 | ||
131 | /* | |
132 | * 'print_rules()' - Print the rules for a file type... | |
133 | */ | |
134 | ||
135 | static void | |
136 | print_rules(mime_magic_t *rules) /* I - Rules to print */ | |
137 | { | |
138 | char logic; /* Logic separator */ | |
139 | ||
140 | ||
141 | if (rules == NULL) | |
142 | return; | |
143 | ||
144 | if (rules->parent == NULL || | |
145 | rules->parent->op == MIME_MAGIC_OR) | |
146 | logic = ','; | |
147 | else | |
148 | logic = '+'; | |
149 | ||
150 | while (rules != NULL) | |
151 | { | |
152 | if (rules->prev != NULL) | |
153 | putchar(logic); | |
154 | ||
155 | switch (rules->op) | |
156 | { | |
157 | case MIME_MAGIC_MATCH : | |
158 | printf("match(%s)", rules->value.matchv); | |
159 | break; | |
160 | case MIME_MAGIC_LOCALE : | |
161 | printf("locale(%s)", rules->value.localev); | |
162 | break; | |
163 | case MIME_MAGIC_ASCII : | |
164 | printf("ascii(%d,%d)", rules->offset, rules->length); | |
165 | break; | |
166 | case MIME_MAGIC_PRINTABLE : | |
167 | printf("printable(%d,%d)", rules->offset, rules->length); | |
168 | break; | |
169 | case MIME_MAGIC_STRING : | |
170 | printf("string(%d,%s)", rules->offset, rules->value.stringv); | |
171 | break; | |
172 | case MIME_MAGIC_CHAR : | |
173 | printf("char(%d,%d)", rules->offset, rules->value.charv); | |
174 | break; | |
175 | case MIME_MAGIC_SHORT : | |
176 | printf("short(%d,%d)", rules->offset, rules->value.shortv); | |
177 | break; | |
178 | case MIME_MAGIC_INT : | |
179 | printf("int(%d,%d)", rules->offset, rules->value.intv); | |
180 | break; | |
181 | default : | |
182 | if (rules->child != NULL) | |
183 | { | |
184 | putchar('('); | |
185 | print_rules(rules->child); | |
186 | putchar(')'); | |
e8fda7b9 | 187 | } |
0b74af7d | 188 | break; |
e8fda7b9 | 189 | } |
0b74af7d | 190 | |
191 | rules = rules->next; | |
e8fda7b9 | 192 | } |
0b74af7d | 193 | } |
194 | ||
57555697 | 195 | |
196 | ||
197 | /* | |
71fe22b7 | 198 | * End of "$Id: testmime.c,v 1.8 2000/01/04 13:45:37 mike Exp $". |
57555697 | 199 | */ |