Coverage Report

Created: 2025-07-11 06:50

/src/libcue/rem.c
Line
Count
Source (jump to first uncovered line)
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
6.19k
{
37
6.19k
  Rem* new_rem = NULL;
38
39
6.19k
  Rem rem[] = {
40
6.19k
    {REM_DATE,      NULL},
41
6.19k
    {REM_REPLAYGAIN_ALBUM_GAIN, NULL},
42
6.19k
    {REM_REPLAYGAIN_ALBUM_PEAK, NULL},
43
6.19k
    {REM_REPLAYGAIN_TRACK_GAIN, NULL},
44
6.19k
    {REM_REPLAYGAIN_TRACK_PEAK, NULL},
45
6.19k
    {REM_END,     NULL}
46
6.19k
  };
47
48
  /* sizeof(rem) = number of elements in rem[] * sizeof(Rem) */
49
6.19k
  new_rem = (Rem*)calloc(sizeof(rem) / sizeof(Rem), sizeof(Rem));
50
6.19k
  if (new_rem == NULL)
51
0
    fprintf(stderr, "rem_new(): problem allocating memory\n");
52
6.19k
  else
53
6.19k
    memcpy(new_rem, rem, sizeof(rem));
54
55
6.19k
  return new_rem;
56
6.19k
}
57
58
void
59
rem_free( Rem* rem)
60
6.19k
{
61
6.19k
  if (rem == NULL)
62
0
    return;
63
64
6.19k
  Rem* ptr = rem;
65
66
6.19k
  do
67
30.9k
  {
68
30.9k
    free(ptr->value);
69
30.9k
  }
70
30.9k
  while ((++ptr)->cmt != REM_END);
71
72
6.19k
  free(rem);
73
6.19k
}
74
75
int
76
rem_is_emtpy( Rem* rem)
77
0
{
78
0
  if (rem == NULL)
79
0
    return 1;
80
81
0
  do
82
0
  {
83
0
    if (rem->value != NULL)
84
0
      return 0;
85
0
  } while ((++rem)->cmt != REM_END);
86
87
0
  return 1;
88
0
}
89
90
void
91
rem_set(  unsigned int cmt,
92
    char* value,
93
    Rem* rem)
94
300
{
95
300
  if (rem == NULL || value == NULL)
96
0
    return;
97
98
300
  do
99
300
  {
100
300
    if (rem->cmt == cmt)
101
300
    {
102
300
      free(rem->value);
103
300
      rem->value = strdup(value);
104
300
      return;
105
300
    }
106
300
  } while ((++rem)->cmt != REM_END);
107
300
}
108
109
const char*
110
rem_get(  RemType cmt,
111
    Rem* rem)
112
0
{
113
0
  if (rem == NULL)
114
0
    return NULL;
115
116
0
  do
117
0
  {
118
0
    if (rem->cmt == cmt)
119
0
    {
120
0
      if (rem->value != NULL)
121
0
        return rem->value;
122
0
      else
123
0
        return NULL;
124
0
    }
125
0
  } while ((++rem)->cmt != REM_END);
126
127
0
  return NULL;
128
0
}
129
130
void
131
rem_dump( Rem* rem)
132
0
{
133
0
  if (rem == NULL)
134
0
    return;
135
136
0
  do
137
0
  {
138
0
    printf("REM %u: %s\n", rem->cmt, rem->value);
139
0
  } while ((++rem)->cmt != REM_END);
140
0
}