]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/testmime.c
Copyright update...
[thirdparty/cups.git] / scheduler / testmime.c
CommitLineData
57555697 1/*
efb2f309 2 * "$Id: testmime.c,v 1.6 2002/01/02 17:59:18 mike Exp $"
57555697 3 *
3a193f5e 4 * MIME test program for the Common UNIX Printing System (CUPS).
57555697 5 *
efb2f309 6 * Copyright 1997-2002 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>
8cf6bc6e 34#include <string.h>
0b74af7d 35#include "mime.h"
36
37
38/*
39 * Local functions...
40 */
41
42static void print_rules(mime_magic_t *rules);
43
44
45/*
46 * 'main()' - Main entry for the test program.
47 */
48
3a193f5e 49int /* O - Exit status */
0b74af7d 50main(int argc, /* I - Number of command-line args */
51 char *argv[]) /* I - Command-line arguments */
52{
53 int i; /* Looping var */
54 char super[MIME_MAX_SUPER], /* Super-type name */
55 type[MIME_MAX_TYPE]; /* Type name */
56 mime_t *mime; /* MIME database */
57 mime_type_t *src, /* Source type */
58 *dst, /* Destination type */
59 **types; /* File type array pointer */
60 mime_filter_t *filters; /* Filters for the file */
61 int num_filters; /* Number of filters for the file */
62
63
3a193f5e 64 mime = mimeLoad("../conf");
0b74af7d 65
66 puts("MIME database types:");
67 for (i = 0, types = mime->types; i < mime->num_types; i ++, types ++)
68 {
8cf6bc6e 69 printf("\t%s/%s:\n", (*types)->super, (*types)->type);
0b74af7d 70 print_rules((*types)->rules);
71 puts("");
e8fda7b9 72 }
0b74af7d 73
74 puts("");
75
76 puts("MIME database filters:");
77 for (i = 0, filters = mime->filters; i < mime->num_filters; i ++, filters ++)
78 printf("\t%s/%s to %s/%s: %s (%d)\n",
79 filters->src->super, filters->src->type,
80 filters->dst->super, filters->dst->type,
81 filters->filter, filters->cost);
82
83 puts("");
84
85 switch (argc)
86 {
87 default :
88 fputs("Usage: testmime source-file [destination-type]\n", stderr);
4aca0e1b 89 mimeDelete(mime);
0b74af7d 90 return (1);
91
92 case 2 :
93 src = mimeFileType(mime, argv[1]);
94
95 if (src != NULL)
96 {
97 printf("%s: %s/%s\n", argv[1], src->super, src->type);
4aca0e1b 98 mimeDelete(mime);
0b74af7d 99 return (0);
100 }
101 else
102 {
103 printf("%s: unknown\n", argv[1]);
4aca0e1b 104 mimeDelete(mime);
0b74af7d 105 return (1);
e8fda7b9 106 }
0b74af7d 107
108 case 3 :
109 src = mimeFileType(mime, argv[1]);
110
dd0f599a 111 sscanf(argv[2], "%15[^/]/%31s", super, type);
0b74af7d 112 dst = mimeType(mime, super, type);
113
114 filters = mimeFilter(mime, src, dst, &num_filters);
115
116 if (filters == NULL)
117 {
118 printf("No filters to convert from %s to %s.\n", argv[1], argv[2]);
4aca0e1b 119 mimeDelete(mime);
0b74af7d 120 return (1);
121 }
122 else
123 {
124 for (i = 0; i < num_filters; i ++)
125 if (i < (num_filters - 1))
126 printf("%s | ", filters[i].filter);
127 else
128 puts(filters[i].filter);
129
4aca0e1b 130 mimeDelete(mime);
0b74af7d 131 return (0);
e8fda7b9 132 }
133 }
0b74af7d 134}
135
136
137/*
138 * 'print_rules()' - Print the rules for a file type...
139 */
140
141static void
142print_rules(mime_magic_t *rules) /* I - Rules to print */
143{
8cf6bc6e 144 int i; /* Looping var */
145 static char indent[255] = "\t"; /* Indentation for rules */
0b74af7d 146
147
148 if (rules == NULL)
149 return;
150
0b74af7d 151 while (rules != NULL)
152 {
8cf6bc6e 153 printf("%s[%p] ", indent, rules);
154
155 if (rules->invert)
156 printf("NOT ");
0b74af7d 157
158 switch (rules->op)
159 {
160 case MIME_MAGIC_MATCH :
161 printf("match(%s)", rules->value.matchv);
162 break;
163 case MIME_MAGIC_LOCALE :
164 printf("locale(%s)", rules->value.localev);
165 break;
166 case MIME_MAGIC_ASCII :
167 printf("ascii(%d,%d)", rules->offset, rules->length);
168 break;
169 case MIME_MAGIC_PRINTABLE :
170 printf("printable(%d,%d)", rules->offset, rules->length);
171 break;
172 case MIME_MAGIC_STRING :
8cf6bc6e 173 printf("string(%d,", rules->offset);
174 for (i = 0; i < rules->length; i ++)
175 if (rules->value.stringv[i] < ' ' ||
176 rules->value.stringv[i] > 126)
177 printf("<%02X>", rules->value.stringv[i]);
178 else
179 putchar(rules->value.stringv[i]);
180 putchar(')');
0b74af7d 181 break;
182 case MIME_MAGIC_CHAR :
183 printf("char(%d,%d)", rules->offset, rules->value.charv);
184 break;
185 case MIME_MAGIC_SHORT :
186 printf("short(%d,%d)", rules->offset, rules->value.shortv);
187 break;
188 case MIME_MAGIC_INT :
189 printf("int(%d,%d)", rules->offset, rules->value.intv);
190 break;
8cf6bc6e 191 case MIME_MAGIC_CONTAINS :
192 printf("contains(%d,%d,", rules->offset, rules->region);
193 for (i = 0; i < rules->length; i ++)
194 if (rules->value.stringv[i] < ' ' ||
195 rules->value.stringv[i] > 126)
196 printf("<%02X>", rules->value.stringv[i]);
197 else
198 putchar(rules->value.stringv[i]);
199 putchar(')');
200 break;
0b74af7d 201 default :
0b74af7d 202 break;
e8fda7b9 203 }
0b74af7d 204
8cf6bc6e 205 if (rules->child != NULL)
206 {
207 if (rules->op == MIME_MAGIC_OR)
208 puts("OR (");
209 else
210 puts("AND (");
211
212 strcat(indent, "\t");
213 print_rules(rules->child);
214 indent[strlen(indent) - 1] = '\0';
215 printf("%s)\n", indent);
216 }
217 else
218 putchar('\n');
219
0b74af7d 220 rules = rules->next;
e8fda7b9 221 }
0b74af7d 222}
223
57555697 224
225
226/*
efb2f309 227 * End of "$Id: testmime.c,v 1.6 2002/01/02 17:59:18 mike Exp $".
57555697 228 */