]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/testmime.c
2 * "$Id: testmime.c 4970 2006-01-24 14:05:45Z mike $"
4 * MIME test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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
; /* 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 int cost
; /* Cost of filters */
60 mime_t
*mime
; /* MIME database */
61 mime_type_t
*src
, /* Source type */
62 *dst
; /* Destination type */
63 cups_array_t
*filters
; /* Filters for the file */
64 mime_filter_t
*filter
; /* Current filter */
70 filter_path
= "../filter:../pdftops";
72 for (i
= 1; i
< argc
; i
++)
73 if (!strcmp(argv
[i
], "-d"))
78 mime
= mimeLoad(argv
[i
], filter_path
);
80 else if (!strcmp(argv
[i
], "-f"))
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
, &cost
, 10);
114 printf("No filters to convert from %s/%s to %s.\n", src
->super
,
119 printf("Filter cost = %d\n", cost
);
121 filter
= (mime_filter_t
*)cupsArrayFirst(filters
);
122 fputs(filter
->filter
, stdout
);
124 for (filter
= (mime_filter_t
*)cupsArrayNext(filters
);
126 filter
= (mime_filter_t
*)cupsArrayNext(filters
))
127 printf(" | %s", filter
->filter
);
131 cupsArrayDelete(filters
);
136 mime
= mimeLoad("../conf", filter_path
);
140 puts("MIME database types:");
141 for (src
= mimeFirstType(mime
); src
; src
= mimeNextType(mime
))
143 printf("\t%s/%s:\n", src
->super
, src
->type
);
144 print_rules(src
->rules
);
150 puts("MIME database filters:");
151 for (filter
= mimeFirstFilter(mime
); filter
; filter
= mimeNextFilter(mime
))
152 printf("\t%s/%s to %s/%s: %s (%d)\n",
153 filter
->src
->super
, filter
->src
->type
,
154 filter
->dst
->super
, filter
->dst
->type
,
155 filter
->filter
, filter
->cost
);
163 * 'print_rules()' - Print the rules for a file type...
167 print_rules(mime_magic_t
*rules
) /* I - Rules to print */
169 int i
; /* Looping var */
170 static char indent
[255] = "\t"; /* Indentation for rules */
176 while (rules
!= NULL
)
178 printf("%s[%p] ", indent
, rules
);
185 case MIME_MAGIC_MATCH
:
186 printf("match(%s)", rules
->value
.matchv
);
188 case MIME_MAGIC_LOCALE
:
189 printf("locale(%s)", rules
->value
.localev
);
191 case MIME_MAGIC_ASCII
:
192 printf("ascii(%d,%d)", rules
->offset
, rules
->length
);
194 case MIME_MAGIC_PRINTABLE
:
195 printf("printable(%d,%d)", rules
->offset
, rules
->length
);
197 case MIME_MAGIC_STRING
:
198 printf("string(%d,", rules
->offset
);
199 for (i
= 0; i
< rules
->length
; i
++)
200 if (rules
->value
.stringv
[i
] < ' ' ||
201 rules
->value
.stringv
[i
] > 126)
202 printf("<%02X>", rules
->value
.stringv
[i
]);
204 putchar(rules
->value
.stringv
[i
]);
207 case MIME_MAGIC_CHAR
:
208 printf("char(%d,%d)", rules
->offset
, rules
->value
.charv
);
210 case MIME_MAGIC_SHORT
:
211 printf("short(%d,%d)", rules
->offset
, rules
->value
.shortv
);
213 case MIME_MAGIC_INT
:
214 printf("int(%d,%d)", rules
->offset
, rules
->value
.intv
);
216 case MIME_MAGIC_CONTAINS
:
217 printf("contains(%d,%d,", rules
->offset
, rules
->region
);
218 for (i
= 0; i
< rules
->length
; i
++)
219 if (rules
->value
.stringv
[i
] < ' ' ||
220 rules
->value
.stringv
[i
] > 126)
221 printf("<%02X>", rules
->value
.stringv
[i
]);
223 putchar(rules
->value
.stringv
[i
]);
230 if (rules
->child
!= NULL
)
232 if (rules
->op
== MIME_MAGIC_OR
)
237 strcat(indent
, "\t");
238 print_rules(rules
->child
);
239 indent
[strlen(indent
) - 1] = '\0';
240 printf("%s)\n", indent
);
251 * End of "$Id: testmime.c 4970 2006-01-24 14:05:45Z mike $".