.types parsing rules and syntax

Nik Svoboda nsvobo1 at lsu.edu
Wed Apr 1 08:18:24 PDT 2009


   From experiences with creating custom types rules for the 1.3.X line of CUPS, I believe I do not fully understand how the syntax and parsing works.

1) First as a note: From searching this list, I realize now that the ' ascending ordering' mentioned in the documentation is alphabetical order, not order read by the daemon. The mime.types file mentions this as, "Type names are sorted in ascending order, so if two types use the same rules to resolve a type (e.g. doc extension for two types), the returned type will be the first type in the sorted list." IMO, this should be mentioned using the term 'alphabetically ascending order.'

2) Why does the following crash the daemon at startup...:
*****************
application/postscript          !(contains(0,1024,"@PJL JOB") \
                                  contains(0,1024,"Mac font")) + \
                                (ai eps ps string(0,%!) string(0,<04>%!) \
                                 contains(0,128,<1B>%-12345X) + \
                                 (contains(0,4096,"LANGUAGE=POSTSCRIPT") \
                                  contains(0,4096,"LANGUAGE = Postscript") \
                                  contains(0,4096,"LANGUAGE = PostScript") \
                                  contains(0,4096,"LANGUAGE = POSTSCRIPT") \
                                  (contains(0,4096,<0a>%!) + \
                                   !contains(0,4096,"ENTER LANGUAGE"))))
*****************
   ...but this does not:
+++++++++++++++++
application/postscript          !(contains(0,1024,"@PJL JOB") \
                                  contains(0,1024,"Mac font")) && \
                                (ai eps ps string(0,%!) string(0,<04>%!) \
                                 contains(0,128,<1B>%-12345X) + \
                                 (contains(0,4096,"LANGUAGE=POSTSCRIPT") \
                                  contains(0,4096,"LANGUAGE = Postscript") \
                                  contains(0,4096,"LANGUAGE = PostScript") \
                                  contains(0,4096,"LANGUAGE = POSTSCRIPT") \
                                  (contains(0,4096,<0a>%!) + \
                                   !contains(0,4096,"ENTER LANGUAGE"))))
+++++++++++++++++
   The difference is the use of && instead of + as the AND operator. The use of && is also never documented officially on the cups site or in the files that i couls find. I noticed it from an IBM white paper on their cups setup.

3) Following up, what is the actual difference between && and + as the AND operator?

4) How is NOT (!) interpreted? I have noticed that any sections of NOT (!) rules must be in one contained expression and must be before the positive rules as in 2). For instance, the following will not seem to work as intended:
*****************
!contains(0,128,"Cheese") + \
!contains(0,128,"this is not postscript") + \
contains(0,128,"rules matching postscript")
*****************
contains(0,128,"rules matching postscript") + \
!contains(0,128,"this is not postscript")
*****************
   However, the following will work:
+++++++++++++++++
!(contains(0,128,"Cheese") \
contains(0,128,"this is not postscript")) && \
contains(0,128,"rules matching postscript")
+++++++++++++++++
!contains(0,128,"this is not postscript") + \
contains(0,128,"rules matching postscript")
+++++++++++++++++

5) Extra whitespace is not always interpreted correctly. For instance, this will be treated as an OR statement (whitespace shown as underscores):
*****************
application/specialpostscript___contains(0,1024,"a postscript rule")_+_\____
________________________________(ai_eps_ps_string(0,%!)_string(0,<04>%!)_\
*****************
  And this will correctly be treated as an AND statement:
+++++++++++++++++
application/specialpostscript___contains(0,1024,"a postscript rule")_+_\
________________________________(ai_eps_ps_string(0,%!)_string(0,<04>%!)_\
+++++++++++++++++
   Does anyone else see this problem?

Thanks for any help,
Nik





More information about the cups mailing list