Coverage Report

Created: 2025-10-10 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libcue/rem.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2009, 2010 Jochen Keil
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions are met:
6
 *     * Redistributions of source code must retain the above copyright
7
 *       notice, this list of conditions and the following disclaimer.
8
 *     * Redistributions in binary form must reproduce the above copyright
9
 *       notice, this list of conditions and the following disclaimer in the
10
 *       documentation and/or other materials provided with the distribution.
11
 *
12
 * THIS SOFTWARE IS PROVIDED BY Jochen Keil ''AS IS'' AND ANY
13
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
 * DISCLAIMED. IN NO EVENT SHALL Jochen Keil BE LIABLE FOR ANY
16
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
 */
23
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <string.h>
27
#include "rem.h"
28
29
struct Rem {
30
  unsigned int cmt;
31
  char *value;
32
};
33
34
Rem*
35
rem_new(  void)
36
5.67k
{
37
5.67k
  Rem* new_rem = NULL;
38
39
5.67k
  Rem rem[] = {
40
5.67k
    {REM_DATE,      NULL},
41
5.67k
    {REM_REPLAYGAIN_ALBUM_GAIN, NULL},
42
5.67k
    {REM_REPLAYGAIN_ALBUM_PEAK, NULL},
43
5.67k
    {REM_REPLAYGAIN_TRACK_GAIN, NULL},
44
5.67k
    {REM_REPLAYGAIN_TRACK_PEAK, NULL},
45
5.67k
    {REM_COMMENT,     NULL},
46
5.67k
    {REM_DISCNUMBER,      NULL},
47
5.67k
    {REM_TOTALDISCS,      NULL},
48
5.67k
    {REM_END,     NULL}
49
5.67k
  };
50
51
  /* sizeof(rem) = number of elements in rem[] * sizeof(Rem) */
52
5.67k
  new_rem = (Rem*)calloc(sizeof(rem) / sizeof(Rem), sizeof(Rem));
53
5.67k
  if (new_rem == NULL)
54
0
    fprintf(stderr, "rem_new(): problem allocating memory\n");
55
5.67k
  else
56
5.67k
    memcpy(new_rem, rem, sizeof(rem));
57
58
5.67k
  return new_rem;
59
5.67k
}
60
61
void
62
rem_free( Rem* rem)
63
5.67k
{
64
5.67k
  if (rem == NULL)
65
0
    return;
66
67
5.67k
  Rem* ptr = rem;
68
69
5.67k
  do
70
45.3k
  {
71
45.3k
    free(ptr->value);
72
45.3k
  }
73
45.3k
  while ((++ptr)->cmt != REM_END);
74
75
5.67k
  free(rem);
76
5.67k
}
77
78
int
79
rem_is_empty( Rem* rem)
80
0
{
81
0
  if (rem == NULL)
82
0
    return 1;
83
84
0
  do
85
0
  {
86
0
    if (rem->value != NULL)
87
0
      return 0;
88
0
  } while ((++rem)->cmt != REM_END);
89
90
0
  return 1;
91
0
}
92
93
void
94
rem_set(  unsigned int cmt,
95
    char* value,
96
    Rem* rem)
97
198
{
98
198
  if (rem == NULL || value == NULL)
99
0
    return;
100
101
198
  do
102
198
  {
103
198
    if (rem->cmt == cmt)
104
198
    {
105
198
      free(rem->value);
106
198
      rem->value = strdup(value);
107
198
      return;
108
198
    }
109
198
  } while ((++rem)->cmt != REM_END);
110
198
}
111
112
const char*
113
rem_get(  RemType cmt,
114
    Rem* rem)
115
0
{
116
0
  if (rem == NULL)
117
0
    return NULL;
118
119
0
  do
120
0
  {
121
0
    if (rem->cmt == cmt)
122
0
    {
123
0
      if (rem->value != NULL)
124
0
        return rem->value;
125
0
      else
126
0
        return NULL;
127
0
    }
128
0
  } while ((++rem)->cmt != REM_END);
129
130
0
  return NULL;
131
0
}
132
133
void
134
rem_dump( Rem* rem)
135
0
{
136
0
  if (rem == NULL)
137
0
    return;
138
139
0
  do
140
0
  {
141
0
    printf("REM %u: %s\n", rem->cmt, rem->value);
142
0
  } while ((++rem)->cmt != REM_END);
143
0
}