SCTC
the soundcloud.com terminal client
Macros | Functions | Variables
jspf.c File Reference

Implements JSPF, a variation of the XSPF playlist format. More...

#include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h>
#include <yajl/yajl_tree.h>
#include "yajl_helper.h"
#include "track.h"
#include "log.h"
#include "helper.h"
#include "jspf.h"
Include dependency graph for jspf.c:

Macros

#define _XOPEN_SOURCE   500
 
#define YAJL_GEN_STRING(hand, str)   yajl_gen_string(hand, (unsigned char*)str, strlen(str))
 
#define YAJL_GEN_ENTRY(hand, title, content)
 
#define YAJL_GEN_ENTRY_INT(hand, title, value)
 
#define YAJL_GEN_SCOPED_ENTRY(hand, title, content)
 
#define YAJL_GEN_SCOPED_ENTRY_INT(hand, title, content)
 

Functions

bool jspf_write (char *file, struct track_list *list)
 Write a whole tracklist to file. More...
 
static void jspf_filewriter (void *ctx, const char *str, size_t len)
 YAJL print callback function for writing JSPF. More...
 
static void write_jspf_track (yajl_gen hand, struct track *track)
 Write a single track to file. More...
 
struct track_listjspf_read (char *file)
 Read a JSPF playlist to a track_list. More...
 
char * jspf_error ()
 Return a descriptive message for the error occured in the last call to jspf_*. More...
 

Variables

static char * last_error = NULL
 

Detailed Description

Implements JSPF, a variation of the XSPF playlist format.

XSPF and JSPF are two related, free and extensible formats for saving playlists. JSPF uses JSON as backing format.

See also
http://www.xspf.org/jspf/
http://json.org/

Macro Definition Documentation

#define _XOPEN_SOURCE   500
#define YAJL_GEN_ENTRY (   hand,
  title,
  content 
)
Value:
{ \
if(content) { \
YAJL_GEN_STRING(hand, title); \
YAJL_GEN_STRING(hand, content); \
} \
}
#define YAJL_GEN_STRING(hand, str)
Definition: jspf.c:56
#define YAJL_GEN_ENTRY_INT (   hand,
  title,
  value 
)
Value:
{ \
YAJL_GEN_STRING(hand, title); \
yajl_gen_integer(hand, value); \
}
#define YAJL_GEN_STRING(hand, str)
Definition: jspf.c:56
#define YAJL_GEN_SCOPED_ENTRY (   hand,
  title,
  content 
)
Value:
{ \
yajl_gen_map_open(hand); \
YAJL_GEN_ENTRY(hand, title, content) \
yajl_gen_map_close(hand); \
}
#define YAJL_GEN_ENTRY(hand, title, content)
Definition: jspf.c:58
#define YAJL_GEN_SCOPED_ENTRY_INT (   hand,
  title,
  content 
)
Value:
{ \
yajl_gen_map_open(hand); \
YAJL_GEN_ENTRY_INT(hand, title, content) \
yajl_gen_map_close(hand); \
}
#define YAJL_GEN_ENTRY_INT(hand, title, value)
Definition: jspf.c:65
#define YAJL_GEN_STRING (   hand,
  str 
)    yajl_gen_string(hand, (unsigned char*)str, strlen(str))

Function Documentation

char* jspf_error ( )

Return a descriptive message for the error occured in the last call to jspf_*.

The memory returned is allocated statically, it must not be free'd. This function may only be used directly after an error occured(!), calling another jspf_* function after the failing call and jspf_error() is undefined behaviour.

Returns
Pointer the message

Here is the caller graph for this function:

static void jspf_filewriter ( void *  ctx,
const char *  str,
size_t  len 
)
static

YAJL print callback function for writing JSPF.

Parameters
ctxA context, here: a FILE* receiving the JSPF
strThe string to write to file
lenThe length of str

Here is the caller graph for this function:

struct track_list* jspf_read ( char *  file)

Read a JSPF playlist to a track_list.

Parameters
fileThe file to read from
Returns
The track_list containing data from file (or an empty list in case of error)

Here is the call graph for this function:

Here is the caller graph for this function:

bool jspf_write ( char *  file,
struct track_list list 
)

Write a whole tracklist to file.

Parameters
fileThe name of the file to write to
listThe tracklist to be written to file
Returns
true in case of success, false otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_jspf_track ( yajl_gen  hand,
struct track track 
)
static

Write a single track to file.

Parameters
handA YAJL handle (represents the document)
trackThe track to be written to file

Here is the caller graph for this function:

Variable Documentation

char* last_error = NULL
static