Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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