libcdio  2.1.0
About: GNU libcdio is a library for CD-ROM and CD image access.
  Fossies Dox: libcdio-2.1.0.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

cdtext.c File Reference
#include <cdio/cdtext.h>
#include <cdio/logging.h>
#include "cdtext_private.h"
#include <cdio/utf8.h>
Include dependency graph for cdtext.c:

Go to the source code of this file.

Macros

#define _CDTEXT_DBCC
 
#define MAX_CDTEXT_GENRE_CODE   28
 
#define MAX_CDTEXT_LANGUAGE_CODE   127
 
#define CDTEXT_COMPARE_CHAR(buf, c, db)   ((buf)[0] == c && (! db || (buf)[1] == c) )
 

Functions

const char * cdtext_field2str (cdtext_field_t i)
 
const char * cdtext_genre2str (cdtext_genre_t i)
 
const char * cdtext_lang2str (cdtext_lang_t i)
 
void cdtext_destroy (cdtext_t *p_cdtext)
 
char * cdtext_get (const cdtext_t *p_cdtext, cdtext_field_t field, track_t track)
 
const char * cdtext_get_const (const cdtext_t *p_cdtext, cdtext_field_t field, track_t track)
 
cdtext_genre_t cdtext_get_genre (const cdtext_t *p_cdtext)
 
cdtext_lang_t cdtext_get_language (const cdtext_t *p_cdtext)
 
track_t cdtext_get_first_track (const cdtext_t *p_cdtext)
 
track_t cdtext_get_last_track (const cdtext_t *p_cdtext)
 
cdtext_lang_tcdtext_list_languages (const cdtext_t *p_cdtext)
 
cdtext_lang_tcdtext_list_languages_v2 (cdtext_t *p_cdtext)
 
bool cdtext_set_language_index (cdtext_t *p_cdtext, int idx)
 
bool cdtext_select_language (cdtext_t *p_cdtext, cdtext_lang_t language)
 
cdtext_tcdtext_init (void)
 
cdtext_field_t cdtext_is_field (const char *key)
 
cdtext_lang_t cdtext_str2lang (const char *lang)
 
void cdtext_set (cdtext_t *p_cdtext, cdtext_field_t key, const uint8_t *value, track_t track, const char *charset)
 
int cdtext_data_init (cdtext_t *p_cdtext, uint8_t *wdata, size_t i_data)
 
int cdtext_read_pack (cdtext_pack_t *p_pack, const uint8_t *p_data)
 

Variables

const char * cdtext_field [MAX_CDTEXT_FIELDS]
 
const char * cdtext_genre [28]
 
const char * cdtext_language [127+1]
 

Macro Definition Documentation

◆ _CDTEXT_DBCC

#define _CDTEXT_DBCC

Definition at line 39 of file cdtext.c.

◆ CDTEXT_COMPARE_CHAR

#define CDTEXT_COMPARE_CHAR (   buf,
  c,
  db 
)    ((buf)[0] == c && (! db || (buf)[1] == c) )

Definition at line 589 of file cdtext.c.

◆ MAX_CDTEXT_GENRE_CODE

#define MAX_CDTEXT_GENRE_CODE   28

Definition at line 40 of file cdtext.c.

◆ MAX_CDTEXT_LANGUAGE_CODE

#define MAX_CDTEXT_LANGUAGE_CODE   127

Definition at line 41 of file cdtext.c.

Function Documentation

◆ cdtext_data_init()

int cdtext_data_init ( cdtext_t p_cdtext,
uint8_t *  wdata,
size_t  i_data 
)

Read a binary CD-TEXT and fill a cdtext struct.

Parameters
p_cdtextthe CD-TEXT object
wdatathe data
i_datasize of wdata
Returns
0 on success, non-zero on failure

Definition at line 601 of file cdtext.c.

References cdtext_pack_s::block, cdtext_s::block, cdtext_s::block_i, buffer, cdio_warn(), CDTEXT_CHARCODE_ASCII, CDTEXT_CHARCODE_ISO_8859_1, CDTEXT_CHARCODE_SHIFT_JIS, CDTEXT_COMPARE_CHAR, CDTEXT_FIELD_ARRANGER, CDTEXT_FIELD_COMPOSER, CDTEXT_FIELD_DISCID, CDTEXT_FIELD_GENRE, CDTEXT_FIELD_ISRC, CDTEXT_FIELD_MESSAGE, CDTEXT_FIELD_PERFORMER, CDTEXT_FIELD_SONGWRITER, CDTEXT_FIELD_TITLE, CDTEXT_FIELD_UPC_EAN, CDTEXT_GENRE_UNUSED, CDTEXT_GET_LEN16, CDTEXT_LANGUAGE_AMHARIC, CDTEXT_LANGUAGE_INVALID, CDTEXT_LANGUAGE_WALLON, CDTEXT_LANGUAGE_ZULU, CDTEXT_LEN_BLOCKSIZE, CDTEXT_LEN_PACK, CDTEXT_LEN_TEXTDATA, CDTEXT_NUM_BLOCKS_MAX, CDTEXT_PACK_ARRANGER, CDTEXT_PACK_BLOCKSIZE, CDTEXT_PACK_COMPOSER, CDTEXT_PACK_DISCID, CDTEXT_PACK_GENRE, CDTEXT_PACK_MESSAGE, CDTEXT_PACK_PERFORMER, CDTEXT_PACK_SONGWRITER, CDTEXT_PACK_TITLE, CDTEXT_PACK_UPC, cdtext_read_pack(), cdtext_set(), cdtext_blocksize_s::charcode, cdtext_blocksize_s::copyright, cdtext_block_s::copyright, cdtext_pack_s::db_chars, cdtext_block_s::first_track, cdtext_block_s::genre_code, i, i_data, cdtext_blocksize_s::i_first_track, cdtext_blocksize_s::i_last_track, cdtext_blocksize_s::i_packs, cdtext_pack_s::i_track, j, cdtext_blocksize_s::langcode, cdtext_block_s::language_code, cdtext_block_s::last_track, cdtext_blocksize_s::lastseq, NULL, cdtext_pack_s::seq, cdtext_pack_s::text, and cdtext_pack_s::type.

Referenced by get_cdtext_generic(), parse_cuefile(), and parse_nrg().

◆ cdtext_destroy()

void cdtext_destroy ( cdtext_t p_cdtext)

Free memory associated with the given cdtext_t object.

Parameters
p_cdtextthe CD-TEXT object

Definition at line 242 of file cdtext.c.

References cdtext_s::block, CDTEXT_NUM_BLOCKS_MAX, CDTEXT_NUM_TRACKS_MAX, cdtext_track_s::field, i, j, MAX_CDTEXT_FIELDS, NULL, and cdtext_block_s::track.

Referenced by _free_image(), cdio_generic_free(), get_cdtext_generic(), parse_nrg(), and CdioCDText::~CdioCDText().

◆ cdtext_field2str()

const char* cdtext_field2str ( cdtext_field_t  i)

Return string representation of given field type.

Definition at line 203 of file cdtext.c.

References cdtext_field, i, and MAX_CDTEXT_FIELDS.

Referenced by field2str(), and print_cdtext_track_info().

◆ cdtext_genre2str()

const char* cdtext_genre2str ( cdtext_genre_t  i)

Return string representation of the given genre code.

Definition at line 215 of file cdtext.c.

References cdtext_genre, i, and MAX_CDTEXT_GENRE_CODE.

Referenced by genre2str(), and print_cdtext_info().

◆ cdtext_get()

char* cdtext_get ( const cdtext_t p_cdtext,
cdtext_field_t  field,
track_t  track 
)

Returns a copy of the return value of cdtext_get_const or NULL.

Must be freed using cdio_free() when done.

See also
cdtext_get_const

Definition at line 269 of file cdtext.c.

References cdtext_get_const(), and NULL.

Referenced by get().

◆ cdtext_get_const()

const char* cdtext_get_const ( const cdtext_t p_cdtext,
cdtext_field_t  field,
track_t  track 
)

Returns value of the given field.

NULL is returned if key is CDTEXT_INVALID or the field is not set. Strings are encoded in UTF-8.

Parameters
p_cdtextthe CD-TEXT object
fieldtype of the field to return
trackspecifies the track, 0 stands for disc

Definition at line 289 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, CDIO_CD_MAX_TRACKS, CDTEXT_FIELD_INVALID, cdtext_track_s::field, NULL, and cdtext_block_s::track.

Referenced by cdtext_get(), getConst(), and print_cdtext_track_info().

◆ cdtext_get_first_track()

track_t cdtext_get_first_track ( const cdtext_t p_cdtext)

Returns the first track number.

Parameters
p_cdtextthe CD-TEXT object

Definition at line 331 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, cdtext_block_s::first_track, and NULL.

◆ cdtext_get_genre()

cdtext_genre_t cdtext_get_genre ( const cdtext_t p_cdtext)

Returns the discs genre code.

Parameters
p_cdtextthe CD-TEXT object

Definition at line 305 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, CDTEXT_GENRE_UNUSED, cdtext_block_s::genre_code, and NULL.

Referenced by print_cdtext_info().

◆ cdtext_get_language()

cdtext_lang_t cdtext_get_language ( const cdtext_t p_cdtext)

Returns the currently active language.

Parameters
p_cdtextthe CD-TEXT object

Definition at line 318 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, CDTEXT_LANGUAGE_BLOCK_UNUSED, cdtext_block_s::language_code, and NULL.

Referenced by getLanguage().

◆ cdtext_get_last_track()

track_t cdtext_get_last_track ( const cdtext_t p_cdtext)

Returns the last track number.

Parameters
p_cdtextthe CD-TEXT object

Definition at line 344 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, cdtext_block_s::last_track, and NULL.

◆ cdtext_init()

cdtext_t* cdtext_init ( void  )

◆ cdtext_is_field()

cdtext_field_t cdtext_is_field ( const char *  key)

Returns associated cdtext_field_t if field is a CD-TEXT keyword.

Internal function.

Parameters
keykey to test
Returns
CDTEXT_INVALID if the given keyword is invalid

Definition at line 520 of file cdtext.c.

References cdtext_field, CDTEXT_FIELD_INVALID, i, and MAX_CDTEXT_FIELDS.

Referenced by parse_cuefile(), and parse_tocfile().

◆ cdtext_lang2str()

const char* cdtext_lang2str ( cdtext_lang_t  i)

Return string representation of the given language code.

Definition at line 227 of file cdtext.c.

References cdtext_language, CDTEXT_LANGUAGE_AMHARIC, CDTEXT_LANGUAGE_WALLON, CDTEXT_LANGUAGE_ZULU, and i.

Referenced by lang2str(), and print_cdtext_info().

◆ cdtext_list_languages()

cdtext_lang_t* cdtext_list_languages ( const cdtext_t p_cdtext)
Deprecated:
Use cdtext_list_languages_v2()

Returns a list of available languages or NULL.

WARNING: The indices in the returned array do not match the indexing as expected by cdtext_set_language_index(). Use cdtext_select_language with the values of array elements.

Internally the list is stored in a static array.

Parameters
p_cdtextthe CD-TEXT object
Returns
NULL if p_cdtext is NULL. Else an array of 8 cdtext_lang_t elements: CDTEXT_LANGUAGE_UNKNOWN not only marks language code 0x00 but also invalid language codes and invalid language blocks.

Definition at line 369 of file cdtext.c.

References cdtext_s::block, CDTEXT_LANGUAGE_BLOCK_UNUSED, CDTEXT_LANGUAGE_INVALID, CDTEXT_LANGUAGE_UNKNOWN, CDTEXT_NUM_BLOCKS_MAX, i, j, cdtext_block_s::language_code, and NULL.

Referenced by listLanguages().

◆ cdtext_list_languages_v2()

cdtext_lang_t* cdtext_list_languages_v2 ( cdtext_t p_cdtext)

Returns an array of available languages or NULL. The index of an array element may be used to select the corresponding language block by call cdtext_set_language_index().

The return value is a pointer into the memory range of *p_cdtext. Do not use it after having freed that memory range.

Parameters
p_cdtextthe CD-TEXT object
Returns
NULL if p_cdtext is NULL, or an array of 8 cdtext_lang_t elements.

If an enumeration is CDTEXT_LANGUAGE_INVALID, then the language block has an invalid language code.

If an enumeration is CDTEXT_LANGUAGE_BLOCK_UNUSED, then the block does not exist on CD or could not be read in CD-TEXT for some reason.

Otherwise, the enumeration of element will be a value in CDTEXT_LANGUAGE_UNKNOWN to CDTEXT_LANGUAGE_AMHARIC, and is a block in that language.

Definition at line 411 of file cdtext.c.

References cdtext_s::block, CDTEXT_NUM_BLOCKS_MAX, i, cdtext_block_s::language_code, cdtext_s::languages, and NULL.

Referenced by listLanguagesV2(), and print_cdtext_info().

◆ cdtext_read_pack()

int cdtext_read_pack ( cdtext_pack_t p_pack,
const uint8_t *  p_data 
)

Fills cdtext_pack_t with information read from p_data

Parameters
p_packout
p_datain

Definition at line 865 of file cdtext.c.

References cdtext_pack_s::block, cdtext_pack_s::char_pos, cdtext_pack_s::crc, cdtext_pack_s::db_chars, cdtext_pack_s::i_track, cdtext_pack_s::seq, cdtext_pack_s::text, and cdtext_pack_s::type.

Referenced by cdtext_data_init().

◆ cdtext_select_language()

bool cdtext_select_language ( cdtext_t p_cdtext,
cdtext_lang_t  language 
)

Try to select the given language. Select default language if specified is not available or invalid and return false.

Parameters
p_cdtextthe CD-TEXT object
languagelanguage identifier
Returns
true on success, false if language is not available

Definition at line 459 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, CDTEXT_LANGUAGE_BLOCK_UNUSED, CDTEXT_NUM_BLOCKS_MAX, i, cdtext_block_s::language_code, and NULL.

Referenced by selectLanguage().

◆ cdtext_set()

void cdtext_set ( cdtext_t p_cdtext,
cdtext_field_t  key,
const uint8_t *  value,
track_t  track,
const char *  charset 
)

Sets the given field at the given track to the given value.

Recodes to UTF-8 if charset is not NULL.

Parameters
p_cdtextthe CD-TEXT object
keyfield to set
valuevalue to set
tracktrack to work on
charsetcharset to convert from

Definition at line 568 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, CDIO_CD_MAX_TRACKS, cdio_charset_to_utf8(), CDTEXT_FIELD_INVALID, cdtext_track_s::field, NULL, and cdtext_block_s::track.

Referenced by cdtext_data_init(), parse_cuefile(), parse_tocfile(), and set().

◆ cdtext_set_language_index()

bool cdtext_set_language_index ( cdtext_t p_cdtext,
int  idx 
)

Select the given language by block index. See cdtext_list_languages_v2(). If the index is bad, or no language block with that index was read: select the default language at index 0 and return false.

Parameters
p_cdtextthe CD-TEXT object
idxthe desired index: 0 to 7.
Returns
true on success, false if no language block is associated to idx

Definition at line 435 of file cdtext.c.

References cdtext_s::block, cdtext_s::block_i, CDTEXT_LANGUAGE_BLOCK_UNUSED, cdtext_block_s::language_code, and NULL.

Referenced by print_cdtext_info(), and setLanguageIndex().

◆ cdtext_str2lang()

cdtext_lang_t cdtext_str2lang ( const char *  lang)

Return the language code of a given language string representation. This is the inverse of cdtext_lang2str().

Parameters
langlanguage to look up
Returns
if lang is among the possible results of cdtext_lang2str(): the cdtext_lang_t which is associated. else: CDTEXT_LANGUAGE_INVALID

Definition at line 542 of file cdtext.c.

References cdtext_language, CDTEXT_LANGUAGE_INVALID, i, and MAX_CDTEXT_LANGUAGE_CODE.

Variable Documentation

◆ cdtext_field

const char* cdtext_field[MAX_CDTEXT_FIELDS]
Initial value:
=
{
"TITLE",
"PERFORMER",
"SONGWRITER",
"COMPOSER",
"MESSAGE",
"ARRANGER",
"ISRC",
"UPC_EAN",
"GENRE",
"DISC_ID",
}

Definition at line 43 of file cdtext.c.

Referenced by cdtext_field2str(), and cdtext_is_field().

◆ cdtext_genre

const char* cdtext_genre[28]

Definition at line 57 of file cdtext.c.

Referenced by cdtext_genre2str().

◆ cdtext_language

const char* cdtext_language[127+1]

Definition at line 89 of file cdtext.c.

Referenced by cdtext_lang2str(), and cdtext_str2lang().