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.
 
 
 
 
 
 

110 lines
1.8 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 <unistd.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 [-h] [-i cue|toc] [file...]\n", progname);
  18. fputs("\
  19. \n\
  20. OPTIONS\n\
  21. -h print usage\n\
  22. -i cue|toc set format of file(s)\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. void print_m_ss_ff (long frame)
  31. {
  32. int m, s, f;
  33. time_frame_to_msf(frame, &m, &s, &f);
  34. printf ("%d:%02d.%02d\n", m, s, f);
  35. }
  36. void print_breaks (Cd *cd)
  37. {
  38. int i;
  39. long b;
  40. Track *track;
  41. for (i = 1; i <= cd_get_ntrack(cd); i++) {
  42. track = cd_get_track(cd, i);
  43. /* don't print zero indexes */
  44. b = track_get_start(track) + track_get_index(track, 1) - track_get_zero_pre(track);
  45. if (0 != b)
  46. print_m_ss_ff(b);
  47. }
  48. }
  49. int breaks (char *name, int format)
  50. {
  51. Cd *cd = NULL;
  52. if (NULL == (cd = cf_parse(name, &format))) {
  53. fprintf(stderr, "%s: input file error\n", name);
  54. return -1;
  55. }
  56. print_breaks(cd);
  57. return 0;
  58. }
  59. int main (int argc, char **argv)
  60. {
  61. int format = UNKNOWN;
  62. /* option variables */
  63. char c;
  64. /* getopt() variables */
  65. extern char *optarg;
  66. extern int optind;
  67. progname = *argv;
  68. while (-1 != (c = getopt(argc, argv, "hi:"))) {
  69. switch (c) {
  70. case 'h':
  71. usage(0);
  72. break;
  73. case 'i':
  74. if (0 == strcmp("cue", optarg))
  75. format = CUE;
  76. else if (0 == strcmp("toc", optarg))
  77. format = TOC;
  78. break;
  79. default:
  80. usage(1);
  81. break;
  82. }
  83. }
  84. if (optind == argc) {
  85. breaks("-", format);
  86. } else {
  87. for (; optind < argc; optind++)
  88. breaks(argv[optind], format);
  89. }
  90. return 0;
  91. }