]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/testmime.c
4 * MIME test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for the test program.
30 * Include necessary headers...
35 #include <cups/string.h>
43 static void print_rules(mime_magic_t
*rules
);
47 * 'main()' - Main entry for the test program.
50 int /* O - Exit status */
51 main(int argc
, /* I - Number of command-line args */
52 char *argv
[]) /* I - Command-line arguments */
54 int i
, j
; /* Looping vars */
55 const char *filter_path
; /* Filter path */
56 char super
[MIME_MAX_SUPER
], /* Super-type name */
57 type
[MIME_MAX_TYPE
]; /* Type name */
58 int compression
; /* Compression of file */
59 mime_t
*mime
; /* MIME database */
60 mime_type_t
*src
, /* Source type */
61 *dst
, /* Destination type */
62 **types
; /* File type array pointer */
63 mime_filter_t
*filters
; /* Filters for the file */
64 int num_filters
; /* Number of filters for the file */
70 filter_path
= "../filter";
72 for (i
= 1; i
< argc
; i
++)
73 if (strcmp(argv
[i
], "-d") == 0)
78 mime
= mimeLoad(argv
[i
], filter_path
);
80 else if (strcmp(argv
[i
], "-f") == 0)
85 filter_path
= argv
[i
];
90 mime
= mimeLoad("../conf", filter_path
);
92 src
= mimeFileType(mime
, argv
[i
], &compression
);
95 printf("%s: %s/%s%s\n", argv
[i
], src
->super
, src
->type
,
96 compression
? " (gzipped)" : "");
99 printf("%s: unknown\n", argv
[i
]);
107 sscanf(argv
[i
], "%15[^/]/%31s", super
, type
);
108 dst
= mimeType(mime
, super
, type
);
110 filters
= mimeFilter(mime
, src
, dst
, &num_filters
, 10);
114 printf("No filters to convert from %s/%s to %s.\n", src
->super
,
119 for (j
= 0; j
< num_filters
; j
++)
120 if (j
< (num_filters
- 1))
121 printf("%s | ", filters
[j
].filter
);
123 puts(filters
[j
].filter
);
130 mime
= mimeLoad("../conf", filter_path
);
134 puts("MIME database types:");
135 for (i
= 0, types
= mime
->types
; i
< mime
->num_types
; i
++, types
++)
137 printf("\t%s/%s:\n", (*types
)->super
, (*types
)->type
);
138 print_rules((*types
)->rules
);
144 puts("MIME database filters:");
145 for (i
= 0, filters
= mime
->filters
; i
< mime
->num_filters
; i
++, filters
++)
146 printf("\t%s/%s to %s/%s: %s (%d)\n",
147 filters
->src
->super
, filters
->src
->type
,
148 filters
->dst
->super
, filters
->dst
->type
,
149 filters
->filter
, filters
->cost
);
157 * 'print_rules()' - Print the rules for a file type...
161 print_rules(mime_magic_t
*rules
) /* I - Rules to print */
163 int i
; /* Looping var */
164 static char indent
[255] = "\t"; /* Indentation for rules */
170 while (rules
!= NULL
)
172 printf("%s[%p] ", indent
, rules
);
179 case MIME_MAGIC_MATCH
:
180 printf("match(%s)", rules
->value
.matchv
);
182 case MIME_MAGIC_LOCALE
:
183 printf("locale(%s)", rules
->value
.localev
);
185 case MIME_MAGIC_ASCII
:
186 printf("ascii(%d,%d)", rules
->offset
, rules
->length
);
188 case MIME_MAGIC_PRINTABLE
:
189 printf("printable(%d,%d)", rules
->offset
, rules
->length
);
191 case MIME_MAGIC_STRING
:
192 printf("string(%d,", rules
->offset
);
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
]);
198 putchar(rules
->value
.stringv
[i
]);
201 case MIME_MAGIC_CHAR
:
202 printf("char(%d,%d)", rules
->offset
, rules
->value
.charv
);
204 case MIME_MAGIC_SHORT
:
205 printf("short(%d,%d)", rules
->offset
, rules
->value
.shortv
);
207 case MIME_MAGIC_INT
:
208 printf("int(%d,%d)", rules
->offset
, rules
->value
.intv
);
210 case MIME_MAGIC_CONTAINS
:
211 printf("contains(%d,%d,", rules
->offset
, rules
->region
);
212 for (i
= 0; i
< rules
->length
; i
++)
213 if (rules
->value
.stringv
[i
] < ' ' ||
214 rules
->value
.stringv
[i
] > 126)
215 printf("<%02X>", rules
->value
.stringv
[i
]);
217 putchar(rules
->value
.stringv
[i
]);
224 if (rules
->child
!= NULL
)
226 if (rules
->op
== MIME_MAGIC_OR
)
231 strcat(indent
, "\t");
232 print_rules(rules
->child
);
233 indent
[strlen(indent
) - 1] = '\0';
234 printf("%s)\n", indent
);