You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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