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.
 
 
 
 
 
 

123 lines
2.2 KiB

  1. /*
  2. * cuebreakpoints.c -- print track break points
  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 <getopt.h>
  11. #include "cuefile.h"
  12. #include "time.h"
  13. char *progname;
  14. void usage (int status)
  15. {
  16. if (0 == status) {
  17. fprintf(stdout, "%s: usage: cuebreakpoints [option...] [file...]\n", progname);
  18. fputs("\
  19. \n\
  20. OPTIONS\n\
  21. -h, --help print usage\n\
  22. -i, --input-format cue|toc set format of file(s)\n\
  23. ", stdout);
  24. } else {
  25. fprintf(stderr, "run `%s --help' for usage\n", progname);
  26. }
  27. exit (status);
  28. }
  29. void print_m_ss_ff (long frame)
  30. {
  31. int m, s, f;
  32. time_frame_to_msf(frame, &m, &s, &f);
  33. printf ("%d:%02d.%02d\n", m, s, f);
  34. }
  35. void print_breaks (Cd *cd)
  36. {
  37. int i;
  38. long b;
  39. Track *track;
  40. /* start on track 2 */
  41. for (i = 2; i <= cd_get_ntrack(cd); i++) {
  42. track = cd_get_track(cd, i);
  43. /* breakpoint is at index 1 */
  44. /* TODO: make option for breakpoint at index 0,
  45. * and option for breakpoints a index 0 and 1
  46. */
  47. b = track_get_start(track) + track_get_index(track, 1) - track_get_zero_pre(track);
  48. /* don't print zero indexes */
  49. if (0 != b)
  50. print_m_ss_ff(b);
  51. }
  52. }
  53. int breaks (char *name, int format)
  54. {
  55. Cd *cd = NULL;
  56. if (NULL == (cd = cf_parse(name, &format))) {
  57. fprintf(stderr, "%s: input file error\n", name);
  58. return -1;
  59. }
  60. print_breaks(cd);
  61. return 0;
  62. }
  63. int main (int argc, char **argv)
  64. {
  65. int format = UNKNOWN;
  66. /* option variables */
  67. char c;
  68. /* getopt_long() variables */
  69. extern char *optarg;
  70. extern int optind;
  71. static struct option longopts[] = {
  72. {"help", no_argument, NULL, 'h'},
  73. {"input-format", required_argument, NULL, 'i'},
  74. {NULL, 0, NULL, 0}
  75. };
  76. progname = *argv;
  77. while (-1 != (c = getopt_long(argc, argv, "hi:", longopts, NULL))) {
  78. switch (c) {
  79. case 'h':
  80. usage(0);
  81. break;
  82. case 'i':
  83. if (0 == strcmp("cue", optarg))
  84. format = CUE;
  85. else if (0 == strcmp("toc", optarg))
  86. format = TOC;
  87. else
  88. fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
  89. usage(1);
  90. break;
  91. default:
  92. usage(1);
  93. break;
  94. }
  95. }
  96. if (optind == argc) {
  97. breaks("-", format);
  98. } else {
  99. for (; optind < argc; optind++)
  100. breaks(argv[optind], format);
  101. }
  102. return 0;
  103. }