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.
 
 
 
 
 
 

91 lines
1.5 KiB

  1. /*
  2. * cuefile.c -- cue/toc functions
  3. *
  4. * Copyright (C) 2004 Svend Sorensen
  5. * For license terms, see the file COPYING in this distribution.
  6. */
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "cuefile.h"
  10. #include "cue.h"
  11. #include "toc.h"
  12. Cd *cf_parse (char *name, int *format)
  13. {
  14. FILE *fp = NULL;
  15. Cd *cd = NULL;
  16. if (UNKNOWN == *format)
  17. if (UNKNOWN == (*format = cf_format_from_suffix(name))) {
  18. fprintf(stderr, "%s: unknown format\n", name);
  19. return NULL;
  20. }
  21. if (0 == strcmp("-", name)) {
  22. fp = stdin;
  23. } else if (NULL == (fp = fopen(name, "r"))) {
  24. fprintf(stderr, "%s: error opening file\n", name);
  25. return NULL;
  26. }
  27. switch (*format) {
  28. case CUE:
  29. cd = cue_parse(fp);
  30. break;
  31. case TOC:
  32. cd = toc_parse(fp);
  33. break;
  34. }
  35. if(stdin != fp)
  36. fclose(fp);
  37. return cd;
  38. }
  39. int cf_print (char *name, int *format, Cd *cd)
  40. {
  41. FILE *fp = NULL;
  42. if (UNKNOWN == *format)
  43. if (UNKNOWN == (*format = cf_format_from_suffix(name))) {
  44. fprintf(stderr, "%s: unknown format\n", name);
  45. return -1;
  46. }
  47. if (0 == strcmp("-", name)) {
  48. fp = stdout;
  49. } else if (NULL == (fp = fopen(name, "w"))) {
  50. fprintf(stderr, "%s: error opening file\n", name);
  51. return -1;
  52. }
  53. switch (*format) {
  54. case CUE:
  55. cue_print(fp, cd);
  56. break;
  57. case TOC:
  58. toc_print(fp, cd);
  59. break;
  60. }
  61. if(stdout != fp)
  62. fclose(fp);
  63. return 0;
  64. }
  65. int cf_format_from_suffix (char *name)
  66. {
  67. char *suffix;
  68. if (0 != (suffix = strrchr(name, '.'))) {
  69. if (0 == strcasecmp(".cue", suffix))
  70. return CUE;
  71. else if (0 == strcasecmp(".toc", suffix))
  72. return TOC;
  73. }
  74. return UNKNOWN;
  75. }