]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/testmime.c
2 * "$Id: testmime.c,v 1.1 2000/01/25 03:50:49 mike Exp $"
4 * MIME test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2000 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-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for the test program.
30 * Include necessary headers...
41 static void print_rules(mime_magic_t
*rules
);
45 * 'main()' - Main entry for the test program.
48 int /* O - Exit status */
49 main(int argc
, /* I - Number of command-line args */
50 char *argv
[]) /* I - Command-line arguments */
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 */
63 mime
= mimeLoad("../conf");
65 puts("MIME database types:");
66 for (i
= 0, types
= mime
->types
; i
< mime
->num_types
; i
++, types
++)
68 printf("\t%s/%s: ", (*types
)->super
, (*types
)->type
);
69 print_rules((*types
)->rules
);
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
);
87 fputs("Usage: testmime source-file [destination-type]\n", stderr
);
91 src
= mimeFileType(mime
, argv
[1]);
95 printf("%s: %s/%s\n", argv
[1], src
->super
, src
->type
);
100 printf("%s: unknown\n", argv
[1]);
105 src
= mimeFileType(mime
, argv
[1]);
107 sscanf(argv
[2], "%15[^/]/31%s", super
, type
);
108 dst
= mimeType(mime
, super
, type
);
110 filters
= mimeFilter(mime
, src
, dst
, &num_filters
);
114 printf("No filters to convert from %s to %s.\n", argv
[1], argv
[2]);
119 for (i
= 0; i
< num_filters
; i
++)
120 if (i
< (num_filters
- 1))
121 printf("%s | ", filters
[i
].filter
);
123 puts(filters
[i
].filter
);
132 * 'print_rules()' - Print the rules for a file type...
136 print_rules(mime_magic_t
*rules
) /* I - Rules to print */
138 char logic
; /* Logic separator */
144 if (rules
->parent
== NULL
||
145 rules
->parent
->op
== MIME_MAGIC_OR
)
150 while (rules
!= NULL
)
152 if (rules
->prev
!= NULL
)
157 case MIME_MAGIC_MATCH
:
158 printf("match(%s)", rules
->value
.matchv
);
160 case MIME_MAGIC_LOCALE
:
161 printf("locale(%s)", rules
->value
.localev
);
163 case MIME_MAGIC_ASCII
:
164 printf("ascii(%d,%d)", rules
->offset
, rules
->length
);
166 case MIME_MAGIC_PRINTABLE
:
167 printf("printable(%d,%d)", rules
->offset
, rules
->length
);
169 case MIME_MAGIC_STRING
:
170 printf("string(%d,%s)", rules
->offset
, rules
->value
.stringv
);
172 case MIME_MAGIC_CHAR
:
173 printf("char(%d,%d)", rules
->offset
, rules
->value
.charv
);
175 case MIME_MAGIC_SHORT
:
176 printf("short(%d,%d)", rules
->offset
, rules
->value
.shortv
);
178 case MIME_MAGIC_INT
:
179 printf("int(%d,%d)", rules
->offset
, rules
->value
.intv
);
182 if (rules
->child
!= NULL
)
185 print_rules(rules
->child
);
198 * End of "$Id: testmime.c,v 1.1 2000/01/25 03:50:49 mike Exp $".