/* Include the CUPS header file */ #include int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping var */ int id; /* Job ID */ int num_files; /* Number of files */ const char *files[100]; /* Files to print */ char *name; /* Destination name */ char *instance; /* Instance name */ int num_dests; /* Number of destinations */ cups_dest_t *dests; /* Destinations */ cups_dest_t *dest; /* Current destination */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ /* Get the list of destinations */ num_dests = cupsGetDests(&dests); /* Get the default destination */ dest = cupsGetDest(NULL, NULL, num_dests, dests); /* Parse the command-line */ num_files = 0; num_options = 0; options = NULL; for (i = 1; i < argc; i ++) if (strncmp(argv[i], "-d", 2) == 0 || strncmp(argv[i], "-P", 2) == 0) { if (argv[i][2]) name = argv[i] + 2; else { i ++; if (i >= argc) { puts("ERROR: Expected destination name!"); cupsFreeDests(num_dests, dests); cupsFreeOptions(num_options, options); return (1); } else name = argv[i]; } if ((instance = strrchr(name, '/')) != NULL) *instance++ = '\0'; if ((dest = cupsGetDest(name, instance, num_dests, dests)) == NULL) { if (instance != NULL) printf("ERROR: %s/%s does not exist!\n", name, instance); else printf("ERROR: %s does not exist!\n", name); cupsFreeDests(num_dests, dests); cupsFreeOptions(num_options, options); return (1); } } else if (strncmp(argv[i], "-o", 2) == 0) { /* Add one or more options */ if (argv[i][2]) num_options = cupsParseOptions(argv[i] + 2, num_options, &options); else { i ++; if (i >= argc) { puts("ERROR: Expected option=value!"); cupsFreeDests(num_dests, dests); cupsFreeOptions(num_options, options); return (1); } num_options = cupsParseOptions(argv[i], num_options, &options); } } else if (num_files < 100) { /* Add a file to print */ files[num_files] = argv[i]; num_files ++; } /* See if we have any files to print... */ if (num_files == 0) { puts("ERROR: Expected print files!"); cupsFreeDests(num_dests, dests); cupsFreeOptions(num_options, options); return (1); } /* Merge the printer options */ for (i = 0; i < dest->num_options; i ++) if (cupsGetOption(dest->options[i].name, num_options, options) == NULL) num_options = cupsAddOption(dest->options[i].name, dest->options[i].value, num_options, &options); /* Print the file */ id = cupsPrintFiles(dest->name, num_files, files, files[0], num_options, options); /* Show the job ID or error */ if (id > 0) printf("Job ID is %d.\n", id); else printf("ERROR: Unable to print file - %s\n", ippErrorString(cupsLastError())); /* Return 1 on error or 0 on success */ return (id < 1); }