選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

198 行
4.2 KiB

  1. /*
  2. * cuebreakpoints.c -- print track break points
  3. *
  4. * Copyright (C) 2004, 2005, 2006 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. #include "time.h"
  13. #if HAVE_CONFIG_H
  14. #include "config.h"
  15. #else /* not HAVE_CONFIG_H */
  16. #define PACKAGE_STRING "cuebreakpoints"
  17. #endif /* HAVE_CONFIG_H */
  18. char *progname;
  19. /*
  20. * pregap correction modes:
  21. * APPEND - append pregap to previous track (except for first track)
  22. * PREPEND - prefix pregap to current track
  23. * SPLIT - print breakpoints for beginning and end of pregap
  24. */
  25. enum GapMode {APPEND, PREPEND, SPLIT};
  26. void usage (int status)
  27. {
  28. if (0 == status) {
  29. printf("Usage: %s [option...] [file...]\n", progname);
  30. printf("Report track breakpoints from a CUE or TOC file.\n"
  31. "\n"
  32. "OPTIONS\n"
  33. "-h, --help print usage\n"
  34. "-i, --input-format cue|toc set format of file(s)\n"
  35. "--append-gaps append pregaps to previous track (default)\n"
  36. "--prepend-gaps prefix pregaps to track\n"
  37. "--split-gaps split at beginning and end of pregaps\n"
  38. "-V, --version print version information\n");
  39. } else {
  40. fprintf(stderr, "Try `%s --help' for more information.\n", progname);
  41. }
  42. exit (status);
  43. }
  44. void version ()
  45. {
  46. printf("%s\n", PACKAGE_STRING);
  47. exit(0);
  48. }
  49. void print_m_ss_ff (long frame)
  50. {
  51. int m, s, f;
  52. time_frame_to_msf(frame, &m, &s, &f);
  53. printf ("%d:%02d.%02d\n", m, s, f);
  54. }
  55. void print_breakpoint (long b)
  56. {
  57. /* Do not print zero breakpoints. */
  58. if (0 != b) {
  59. print_m_ss_ff(b);
  60. }
  61. }
  62. void print_breaks (Cd *cd, int gaps)
  63. {
  64. int i;
  65. long b;
  66. long pg;
  67. Track *track;
  68. for (i = 1; i <= cd_get_ntrack(cd); i++) {
  69. track = cd_get_track(cd, i);
  70. /*
  71. * When breakpoint is at:
  72. * index 0: gap is prepended to track
  73. * index 1: gap is appended to previous track
  74. */
  75. b = track_get_start(track);
  76. pg = track_get_index(track, 1) - track_get_zero_pre(track);
  77. if (gaps == PREPEND || gaps == SPLIT) {
  78. print_breakpoint(b);
  79. /*
  80. * There is no previous track to append the first track's
  81. * pregap to.
  82. */
  83. } else if (gaps == APPEND && 1 < i) {
  84. print_breakpoint(b + pg);
  85. }
  86. /* If pregap exists, print breakpoints (in split mode). */
  87. if (gaps == SPLIT && 0 < pg) {
  88. print_breakpoint(b + pg);
  89. }
  90. }
  91. }
  92. int breaks (char *name, int format, int gaps)
  93. {
  94. Cd *cd = NULL;
  95. if (NULL == (cd = cf_parse(name, &format))) {
  96. fprintf(stderr, "%s: error: unable to parse input file"
  97. " `%s'\n", progname, name);
  98. return -1;
  99. }
  100. print_breaks(cd, gaps);
  101. return 0;
  102. }
  103. int main (int argc, char **argv)
  104. {
  105. int format = UNKNOWN;
  106. int gaps = APPEND;
  107. int ret = 0; /* return value of breaks() */
  108. /* option variables */
  109. int c;
  110. /* getopt_long() variables */
  111. extern char *optarg;
  112. extern int optind;
  113. static struct option longopts[] = {
  114. {"help", no_argument, NULL, 'h'},
  115. {"input-format", required_argument, NULL, 'i'},
  116. {"append-gaps", no_argument, NULL, 'a'},
  117. {"prepend-gaps", no_argument, NULL, 'p'},
  118. {"split-gaps", no_argument, NULL, 's'},
  119. {"version", no_argument, NULL, 'V'},
  120. {NULL, 0, NULL, 0}
  121. };
  122. progname = argv[0];
  123. while (-1 != (c = getopt_long(argc, argv, "hi:V", longopts, NULL))) {
  124. switch (c) {
  125. case 'h':
  126. usage(0);
  127. break;
  128. case 'i':
  129. if (0 == strcmp("cue", optarg)) {
  130. format = CUE;
  131. } else if (0 == strcmp("toc", optarg)) {
  132. format = TOC;
  133. } else {
  134. fprintf(stderr, "%s: error: unknown input file"
  135. " format `%s'\n", progname, optarg);
  136. usage(1);
  137. }
  138. break;
  139. case 'a':
  140. gaps = APPEND;
  141. break;
  142. case 'p':
  143. gaps = PREPEND;
  144. break;
  145. case 's':
  146. gaps = SPLIT;
  147. break;
  148. case 'V':
  149. version();
  150. break;
  151. default:
  152. usage(1);
  153. break;
  154. }
  155. }
  156. /* What we do depends on the number of operands. */
  157. if (optind == argc) {
  158. /* No operands: report breakpoints of stdin. */
  159. ret = breaks("-", format, gaps);
  160. } else {
  161. /* Report track breakpoints for each operand. */
  162. for (; optind < argc; optind++) {
  163. ret = breaks(argv[optind], format, gaps);
  164. /* Exit if breaks() returns nonzero. */
  165. if (!ret) {
  166. break;
  167. }
  168. }
  169. }
  170. return ret;
  171. }