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.
 
 
 
 
 
 

109 line
2.1 KiB

  1. /*
  2. * cueconvert.c -- convert between cue/toc formats
  3. *
  4. * Copyright (C) 2004 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 <unistd.h>
  11. #include "cuefile.h"
  12. char *progname;
  13. void usage (int status)
  14. {
  15. if (0 == status) {
  16. fprintf(stdout, "%s: usage: cueconvert [-h] [-i cue|toc] [-o cue|toc] [infile [outfile]]\n", progname);
  17. fputs("\
  18. \n\
  19. OPTIONS\n\
  20. -h print usage\n\
  21. -i cue|toc set format of input file\n\
  22. -o cue|toc set format of output file\n\
  23. ", stdout);
  24. } else {
  25. fprintf(stderr, "%s: syntax error\n", progname);
  26. fprintf(stderr, "run `%s -h' for usage\n", progname);
  27. }
  28. exit (status);
  29. }
  30. int convert (char *iname, int iformat, char *oname, int oformat)
  31. {
  32. Cd *cd = NULL;
  33. if (NULL == (cd = cf_parse(iname, &iformat))) {
  34. fprintf(stderr, "input file error\n");
  35. return -1;
  36. }
  37. if (UNKNOWN == oformat) {
  38. /* first use file suffix */
  39. if (UNKNOWN == (oformat = cf_format_from_suffix(oname))) {
  40. /* then use opposite of input format */
  41. switch(iformat) {
  42. case CUE:
  43. oformat = TOC;
  44. break;
  45. case TOC:
  46. oformat = CUE;
  47. break;
  48. }
  49. }
  50. }
  51. return cf_print(oname, &oformat, cd);
  52. }
  53. int main (int argc, char **argv)
  54. {
  55. int iformat = UNKNOWN;
  56. int oformat = UNKNOWN;
  57. /* option variables */
  58. char c;
  59. /* getopt() variables */
  60. extern char *optarg;
  61. extern int optind;
  62. progname = *argv;
  63. while (-1 != (c = getopt(argc, argv, "hi:o:"))) {
  64. switch (c) {
  65. case 'h':
  66. usage(0);
  67. break;
  68. case 'i':
  69. if (0 == strcmp("cue", optarg))
  70. iformat = CUE;
  71. else if (0 == strcmp("toc", optarg))
  72. iformat = TOC;
  73. break;
  74. case 'o':
  75. if (0 == strcmp("cue", optarg))
  76. oformat = CUE;
  77. else if (0 == strcmp("toc", optarg))
  78. oformat = TOC;
  79. break;
  80. default:
  81. usage(1);
  82. break;
  83. }
  84. }
  85. if (optind == argc) {
  86. convert("-", iformat, "-", oformat);
  87. } else if (optind == argc - 1) {
  88. convert(argv[optind], iformat, "-", oformat);
  89. } else if (optind == argc - 2) {
  90. convert(argv[optind], iformat, argv[optind + 1], oformat);
  91. } else {
  92. usage(1);
  93. }
  94. return 0;
  95. }