]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cupsfilter.c
Import CUPS v2.0b1
[thirdparty/cups.git] / scheduler / cupsfilter.c
index 4102277a232263c59353ad74ec480dbc469d8848..75300fb9a8d91cab7145b6340c3dc63391d4adc6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cupsfilter.c 11772 2014-03-28 15:08:30Z msweet $"
+ * "$Id: cupsfilter.c 11770 2014-03-28 14:49:58Z msweet $"
  *
  * Filtering program for CUPS.
  *
@@ -95,7 +95,8 @@ int                                   /* O - Exit status */
 main(int  argc,                                /* I - Number of command-line args */
      char *argv[])                     /* I - Command-line arguments */
 {
-  int          i;                      /* Looping vars */
+  int          i,                      /* Looping vars */
+               list_filters = 0;       /* Just list the filters? */
   const char   *command,               /* Command name */
                *opt,                   /* Current option */
                *printer;               /* Printer name */
@@ -164,168 +165,175 @@ main(int  argc,                         /* I - Number of command-line args */
   _cupsSetLocale(argv);
 
   for (i = 1; i < argc; i ++)
+  {
     if (argv[i][0] == '-')
     {
-      for (opt = argv[i] + 1; *opt; opt ++)
-        switch (*opt)
+      if (!strcmp(argv[i], "--list-filters"))
+      {
+        list_filters = 1;
+      }
+      else if (!strcmp(argv[i], "--"))
+      {
+       i ++;
+       if (i < argc && !infile)
+         infile = argv[i];
+       else
+         usage(opt);
+      }
+      else
+      {
+       for (opt = argv[i] + 1; *opt; opt ++)
        {
-         case '-' : /* Next argument is a filename... */
-             i ++;
-             if (i < argc && !infile)
-               infile = argv[i];
-             else
-               usage(opt);
-             break;
-
-          case 'a' : /* Specify option... */
-             i ++;
-             if (i < argc)
-               num_options = cupsParseOptions(argv[i], num_options, &options);
-             else
-               usage(opt);
-             break;
-
-          case 'c' : /* Specify cups-files.conf file location... */
-             i ++;
-             if (i < argc)
-             {
-               if (!strcmp(command, "convert"))
-                 num_options = cupsAddOption("copies", argv[i], num_options,
-                                             &options);
+         switch (*opt)
+         {
+           case 'a' : /* Specify option... */
+               i ++;
+               if (i < argc)
+                 num_options = cupsParseOptions(argv[i], num_options, &options);
                else
-                 strlcpy(cupsfilesconf, argv[i], sizeof(cupsfilesconf));
-             }
-             else
-               usage(opt);
-             break;
-
-          case 'd' : /* Specify the real printer name */
-             i ++;
-             if (i < argc)
-               printer = argv[i];
-             else
-               usage(opt);
-             break;
-
-         case 'D' : /* Delete input file after conversion */
-             removeinfile = 1;
-             break;
-
-          case 'e' : /* Use every filter from the PPD file */
-             all_filters = 1;
-             break;
-
-          case 'f' : /* Specify input file... */
-             i ++;
-             if (i < argc && !infile)
-               infile = argv[i];
-             else
-               usage(opt);
-             break;
-
-          case 'i' : /* Specify source MIME type... */
-             i ++;
-             if (i < argc)
-             {
-               if (sscanf(argv[i], "%15[^/]/%255s", super, type) != 2)
                  usage(opt);
+               break;
 
-                srctype = argv[i];
-             }
-             else
-               usage(opt);
-             break;
+           case 'c' : /* Specify cups-files.conf file location... */
+               i ++;
+               if (i < argc)
+               {
+                 if (!strcmp(command, "convert"))
+                   num_options = cupsAddOption("copies", argv[i], num_options, &options);
+                 else
+                   strlcpy(cupsfilesconf, argv[i], sizeof(cupsfilesconf));
+               }
+               else
+                 usage(opt);
+               break;
 
-          case 'j' : /* Get job file or specify destination MIME type... */
-              if (strcmp(command, "convert"))
-             {
-               i ++;
+           case 'd' : /* Specify the real printer name */
+               i ++;
+               if (i < argc)
+                 printer = argv[i];
+               else
+                 usage(opt);
+               break;
+
+           case 'D' : /* Delete input file after conversion */
+               removeinfile = 1;
+               break;
+
+           case 'e' : /* Use every filter from the PPD file */
+               all_filters = 1;
+               break;
+
+           case 'f' : /* Specify input file... */
+               i ++;
+               if (i < argc && !infile)
+                 infile = argv[i];
+               else
+                 usage(opt);
+               break;
+
+           case 'i' : /* Specify source MIME type... */
+               i ++;
                if (i < argc)
                {
-                 get_job_file(argv[i]);
-                 infile = TempFile;
+                 if (sscanf(argv[i], "%15[^/]/%255s", super, type) != 2)
+                   usage(opt);
+
+                 srctype = argv[i];
                }
                else
                  usage(opt);
+               break;
+
+           case 'j' : /* Get job file or specify destination MIME type... */
+               if (strcmp(command, "convert"))
+               {
+                 i ++;
+                 if (i < argc)
+                 {
+                   get_job_file(argv[i]);
+                   infile = TempFile;
+                 }
+                 else
+                   usage(opt);
 
-                break;
-             }
+                 break;
+               }
 
-          case 'm' : /* Specify destination MIME type... */
-             i ++;
-             if (i < argc)
-             {
-               if (sscanf(argv[i], "%15[^/]/%255s", super, type) != 2)
+           case 'm' : /* Specify destination MIME type... */
+               i ++;
+               if (i < argc)
+               {
+                 if (sscanf(argv[i], "%15[^/]/%255s", super, type) != 2)
+                   usage(opt);
+
+                 dsttype = argv[i];
+               }
+               else
                  usage(opt);
+               break;
 
-                dsttype = argv[i];
-             }
-             else
-               usage(opt);
-             break;
-
-          case 'n' : /* Specify number of copies... */
-             i ++;
-             if (i < argc)
-               num_options = cupsAddOption("copies", argv[i], num_options,
-                                           &options);
-             else
-               usage(opt);
-             break;
-
-          case 'o' : /* Specify option(s) or output filename */
-             i ++;
-             if (i < argc)
-             {
-               if (!strcmp(command, "convert"))
+           case 'n' : /* Specify number of copies... */
+               i ++;
+               if (i < argc)
+                 num_options = cupsAddOption("copies", argv[i], num_options, &options);
+               else
+                 usage(opt);
+               break;
+
+           case 'o' : /* Specify option(s) or output filename */
+               i ++;
+               if (i < argc)
                {
-                 if (outfile)
-                   usage(NULL);
+                 if (!strcmp(command, "convert"))
+                 {
+                   if (outfile)
+                     usage(NULL);
+                   else
+                     outfile = argv[i];
+                 }
                  else
-                   outfile = argv[i];
+                   num_options = cupsParseOptions(argv[i], num_options, &options);
                }
                else
-                 num_options = cupsParseOptions(argv[i], num_options,
-                                                &options);
-             }
-             else
-               usage(opt);
-             break;
-
-          case 'p' : /* Specify PPD file... */
-          case 'P' : /* Specify PPD file... */
-             i ++;
-             if (i < argc)
-               ppdfile = argv[i];
-             else
-               usage(opt);
-             break;
-
-          case 't' : /* Specify title... */
-          case 'J' : /* Specify title... */
-             i ++;
-             if (i < argc)
-               title = argv[i];
-             else
-               usage(opt);
-             break;
-
-         case 'u' : /* Delete PPD file after conversion */
-             removeppd = 1;
-             break;
-
-          case 'U' : /* Specify username... */
-             i ++;
-             if (i < argc)
-               user = argv[i];
-             else
-               usage(opt);
-             break;
-
-         default : /* Something we don't understand... */
-             usage(opt);
-             break;
+                 usage(opt);
+               break;
+
+           case 'p' : /* Specify PPD file... */
+           case 'P' : /* Specify PPD file... */
+               i ++;
+               if (i < argc)
+                 ppdfile = argv[i];
+               else
+                 usage(opt);
+               break;
+
+           case 't' : /* Specify title... */
+           case 'J' : /* Specify title... */
+               i ++;
+               if (i < argc)
+                 title = argv[i];
+               else
+                 usage(opt);
+               break;
+
+           case 'u' : /* Delete PPD file after conversion */
+               removeppd = 1;
+               break;
+
+           case 'U' : /* Specify username... */
+               i ++;
+               if (i < argc)
+                 user = argv[i];
+               else
+                 usage(opt);
+               break;
+
+           default : /* Something we don't understand... */
+               usage(opt);
+               break;
+         }
        }
+      }
     }
     else if (!infile)
     {
@@ -340,6 +348,7 @@ main(int  argc,                             /* I - Number of command-line args */
                     _("cupsfilter: Only one filename can be specified."));
       usage(NULL);
     }
+  }
 
   if (!infile && !srctype)
     usage(NULL);
@@ -473,12 +482,31 @@ main(int  argc,                           /* I - Number of command-line args */
     filters = prefilters;
   }
 
- /*
-  * Do it!
-  */
+  if (list_filters)
+  {
+   /*
+    * List filters...
+    */
+
+    mime_filter_t      *filter;        /* Current filter */
+
+    for (filter = (mime_filter_t *)cupsArrayFirst(filters);
+        filter;
+        filter = (mime_filter_t *)cupsArrayNext(filters))
+      if (strcmp(filter->filter, "-"))
+        _cupsLangPuts(stdout, filter->filter);
 
-  status = exec_filters(src, filters, infile, outfile, ppdfile, printer, user,
-                        title, num_options, options);
+    status = 0;
+  }
+  else
+  {
+   /*
+    * Run filters...
+    */
+
+    status = exec_filters(src, filters, infile, outfile, ppdfile, printer, user,
+                         title, num_options, options);
+  }
 
  /*
   * Remove files as needed, then exit...
@@ -558,7 +586,7 @@ add_printer_filter(
   {
     char       *ptr;                   /* Pointer into maxsize(nnnn) program */
 
-    maxsize = strtoll(program + 8, &ptr, 10);
+    maxsize = (size_t)strtoll(program + 8, &ptr, 10);
 
     if (*ptr != ')')
     {
@@ -727,7 +755,7 @@ escape_options(
 {
   int          i;                      /* Looping var */
   cups_option_t        *option;                /* Current option */
-  int          bytes;                  /* Number of bytes needed */
+  size_t       bytes;                  /* Number of bytes needed */
   char         *s,                     /* Option string */
                *sptr,                  /* Pointer into string */
                *vptr;                  /* Pointer into value */
@@ -755,7 +783,7 @@ escape_options(
     if (sptr > s)
       *sptr++ = ' ';
 
-    strlcpy(sptr, option->name, bytes - (sptr - s));
+    strlcpy(sptr, option->name, bytes - (size_t)(sptr - s));
     sptr += strlen(sptr);
     *sptr++ = '=';
 
@@ -1396,9 +1424,7 @@ read_cups_files_conf(
     cupsFileClose(fp);
   }
 
-  snprintf(line, sizeof(line),
-           "%s/filter:" CUPS_BINDIR ":" CUPS_SBINDIR ":/bin:/usr/bin",
-          ServerBin);
+  snprintf(line, sizeof(line), "%s/filter:" CUPS_BINDIR ":" CUPS_SBINDIR ":/bin:/usr/bin", ServerBin);
   set_string(&Path, line);
 
   return (0);
@@ -1450,38 +1476,30 @@ static void
 usage(const char *opt)                 /* I - Incorrect option, if any */
 {
   if (opt)
-    _cupsLangPrintf(stderr, _("%s: Unknown option \"%c\"."), "cupsfilter",
-                    *opt);
+    _cupsLangPrintf(stderr, _("%s: Unknown option \"%c\"."), "cupsfilter", *opt);
 
-  _cupsLangPuts(stdout, _("Usage: cupsfilter [ options ] filename"));
+  _cupsLangPuts(stdout, _("Usage: cupsfilter [ options ] [ -- ] filename"));
   _cupsLangPuts(stdout, _("Options:"));
-  _cupsLangPuts(stdout, _("  -D                      Remove the input file "
-                         "when finished."));
+  _cupsLangPuts(stdout, _("  --list-filters          List filters that will be used."));
+  _cupsLangPuts(stdout, _("  -D                      Remove the input file when finished."));
   _cupsLangPuts(stdout, _("  -P filename.ppd         Set PPD file."));
   _cupsLangPuts(stdout, _("  -U username             Specify username."));
-  _cupsLangPuts(stdout, _("  -c cups-files.conf      Set cups-files.conf file to "
-                         "use."));
-  _cupsLangPuts(stdout, _("  -d printer              Use the named "
-                         "printer."));
-  _cupsLangPuts(stdout, _("  -e                      Use every filter from "
-                         "the PPD file."));
-  _cupsLangPuts(stdout, _("  -i mime/type            Set input MIME type "
-                         "(otherwise auto-typed)."));
-  _cupsLangPuts(stdout, _("  -j job-id[,N]           Filter file N from the "
-                         "specified job (default is file 1)."));
-  _cupsLangPuts(stdout, _("  -m mime/type            Set output MIME type "
-                         "(otherwise application/pdf)."));
+  _cupsLangPuts(stdout, _("  -c cups-files.conf      Set cups-files.conf file to use."));
+  _cupsLangPuts(stdout, _("  -d printer              Use the named printer."));
+  _cupsLangPuts(stdout, _("  -e                      Use every filter from the PPD file."));
+  _cupsLangPuts(stdout, _("  -i mime/type            Set input MIME type (otherwise auto-typed)."));
+  _cupsLangPuts(stdout, _("  -j job-id[,N]           Filter file N from the specified job (default is file 1)."));
+  _cupsLangPuts(stdout, _("  -m mime/type            Set output MIME type (otherwise application/pdf)."));
   _cupsLangPuts(stdout, _("  -n copies               Set number of copies."));
   _cupsLangPuts(stdout, _("  -o name=value           Set option(s)."));
   _cupsLangPuts(stdout, _("  -p filename.ppd         Set PPD file."));
   _cupsLangPuts(stdout, _("  -t title                Set title."));
-  _cupsLangPuts(stdout, _("  -u                      Remove the PPD file "
-                         "when finished."));
+  _cupsLangPuts(stdout, _("  -u                      Remove the PPD file when finished."));
 
   exit(1);
 }
 
 
 /*
- * End of "$Id: cupsfilter.c 11772 2014-03-28 15:08:30Z msweet $".
+ * End of "$Id: cupsfilter.c 11770 2014-03-28 14:49:58Z msweet $".
  */