Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

141 рядки
2.8 KiB

  1. /*
  2. * cueconvert.c -- convert between cue/toc formats
  3. *
  4. * Copyright (C) 2004, 2005, 2006 Svend Sorensen
  5. * For license terms, see the file COPYING in this distribution.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <getopt.h>
  11. #include "cuefile.h"
  12. #if HAVE_CONFIG_H
  13. #include "config.h"
  14. #else
  15. #define PACKAGE_STRING "cuebreakpoints"
  16. #endif
  17. char *progname;
  18. void usage (int status)
  19. {
  20. if (0 == status) {
  21. fprintf(stdout, "%s: usage: cueconvert [option...] [infile [outfile]]\n", progname);
  22. fputs("\
  23. \n\
  24. OPTIONS\n\
  25. -h, --help print usage\n\
  26. -i, --input-format cue|toc set format of input file\n\
  27. -o, --output-format cue|toc set format of output file\n\
  28. -V, --version print version information\n\
  29. ", stdout);
  30. } else {
  31. fprintf(stderr, "run `%s --help' for usage\n", progname);
  32. }
  33. exit (status);
  34. }
  35. void version ()
  36. {
  37. printf("%s\n", PACKAGE_STRING);
  38. exit(0);
  39. }
  40. int convert (char *iname, int iformat, char *oname, int oformat)
  41. {
  42. Cd *cd = NULL;
  43. if (NULL == (cd = cf_parse(iname, &iformat))) {
  44. fprintf(stderr, "input file error\n");
  45. return -1;
  46. }
  47. if (UNKNOWN == oformat) {
  48. /* first use file suffix */
  49. if (UNKNOWN == (oformat = cf_format_from_suffix(oname))) {
  50. /* then use opposite of input format */
  51. switch(iformat) {
  52. case CUE:
  53. oformat = TOC;
  54. break;
  55. case TOC:
  56. oformat = CUE;
  57. break;
  58. }
  59. }
  60. }
  61. return cf_print(oname, &oformat, cd);
  62. }
  63. int main (int argc, char **argv)
  64. {
  65. int iformat = UNKNOWN;
  66. int oformat = UNKNOWN;
  67. /* option variables */
  68. int c;
  69. /* getopt_long() variables */
  70. extern char *optarg;
  71. extern int optind;
  72. static struct option longopts[] = {
  73. {"help", no_argument, NULL, 'h'},
  74. {"input-format", required_argument, NULL, 'i'},
  75. {"output-format", required_argument, NULL, 'o'},
  76. {"version", no_argument, NULL, 'V'},
  77. {NULL, 0, NULL, 0}
  78. };
  79. progname = *argv;
  80. while (-1 != (c = getopt_long(argc, argv, "hi:o:V", longopts, NULL))) {
  81. switch (c) {
  82. case 'h':
  83. usage(0);
  84. break;
  85. case 'i':
  86. if (0 == strcmp("cue", optarg)) {
  87. iformat = CUE;
  88. } else if (0 == strcmp("toc", optarg)) {
  89. iformat = TOC;
  90. } else {
  91. fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
  92. usage(1);
  93. }
  94. break;
  95. case 'o':
  96. if (0 == strcmp("cue", optarg)) {
  97. oformat = CUE;
  98. } else if (0 == strcmp("toc", optarg)) {
  99. oformat = TOC;
  100. } else {
  101. fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
  102. usage(1);
  103. }
  104. break;
  105. case 'V':
  106. version();
  107. break;
  108. default:
  109. usage(1);
  110. break;
  111. }
  112. }
  113. if (optind == argc) {
  114. convert("-", iformat, "-", oformat);
  115. } else if (optind == argc - 1) {
  116. convert(argv[optind], iformat, "-", oformat);
  117. } else if (optind == argc - 2) {
  118. convert(argv[optind], iformat, argv[optind + 1], oformat);
  119. } else {
  120. usage(1);
  121. }
  122. return 0;
  123. }