libmpdserver

Parser combinator library for MPD client commands

git clone https://git.8pit.net/libmpdserver.git

  1#include "fns.h"
  2#include "mpc.h"
  3
  4mpdf_fold(add, MPD_ARG_STRING)
  5
  6static mpc_parser_t *
  7mpd_add(void)
  8{
  9	return mpc_and(2, mpdf_add, mpc_string("add"), mpd_argument(mpd_uri()),
 10	               free);
 11}
 12
 13mpdf_fold(addid, MPD_ARG_STRING mpd_opt_arg(MPD_ARG_UINT))
 14
 15static mpc_parser_t *
 16mpd_addid(void)
 17{
 18	return mpc_and(3, mpdf_addid, mpc_string("addid"),
 19	               mpd_argument(mpd_uri()),
 20	               mpc_maybe(mpd_argument(mpd_uint())), free, free);
 21}
 22
 23static mpc_parser_t *
 24mpd_clear(void)
 25{
 26	return mpd_cmd_noarg("clear");
 27}
 28
 29mpdf_fold(deleteid, MPD_ARG_UINT)
 30
 31static mpc_parser_t *
 32mpd_deleteid(void)
 33{
 34	return mpc_and(2, mpdf_deleteid, mpc_string("deleteid"),
 35	               mpd_argument(mpd_uint()), free);
 36}
 37
 38mpdf_fold(delete, MPD_ARG_RANGE)
 39
 40static mpc_parser_t *
 41mpd_delete(void)
 42{
 43	return mpc_and(2, mpdf_delete, mpc_string("delete"),
 44	               mpd_argument(mpd_range_with_single()), free);
 45}
 46
 47mpdf_fold(move, MPD_ARG_RANGE MPD_ARG_INT)
 48
 49static mpc_parser_t *
 50mpd_move(void)
 51{
 52	return mpc_and(3, mpdf_move, mpc_string("move"),
 53	               mpd_argument(mpd_range_with_single()),
 54	               mpd_argument(mpd_int()), free, free);
 55}
 56
 57mpdf_fold(moveid, MPD_ARG_UINT MPD_ARG_INT)
 58
 59static mpc_parser_t *
 60mpd_moveid(void)
 61{
 62	return mpc_and(3, mpdf_moveid, mpc_string("moveid"),
 63	               mpd_argument(mpd_uint()), mpd_argument(mpd_int()), free,
 64	               free);
 65}
 66
 67mpdf_fold(playlistfind, MPD_ARG_STRING MPD_ARG_STRING)
 68
 69static mpc_parser_t *
 70mpd_playlistfind(void)
 71{
 72	return mpc_and(3, mpdf_playlistfind, mpc_string("playlistfind"),
 73	               mpd_argument(mpd_tag_name()), mpd_argument(mpd_string()),
 74	               free, free);
 75}
 76
 77mpdf_fold(playlistinfo, mpd_opt_arg(MPD_ARG_RANGE))
 78
 79static mpc_parser_t *
 80mpd_playlistinfo(void)
 81{
 82	return mpc_and(2, mpdf_playlistinfo, mpc_string("playlistinfo"),
 83	               mpc_maybe(mpd_argument(mpd_range_with_single())), free);
 84}
 85
 86mpdf_fold(plchanges, MPD_ARG_UINT mpd_opt_arg(MPD_ARG_RANGE))
 87
 88static mpc_parser_t *
 89mpd_plchanges(void)
 90{
 91	return mpc_and(3, mpdf_plchanges, mpc_string("plchanges"),
 92	               mpd_argument(mpd_uint()),
 93	               mpc_maybe(mpd_argument(mpd_range())), free, free);
 94}
 95
 96mpdf_fold(rangeid, MPD_ARG_UINT MPD_ARG_RANGE)
 97
 98static mpc_parser_t *
 99mpd_rangeid(void)
100{
101	return mpc_and(3, mpdf_rangeid, mpc_string("rangeid"),
102	               mpd_argument(mpd_uint()), mpd_argument(mpd_range()),
103	               free, free);
104}
105
106mpc_parser_t *
107mpd_queue_cmds(void)
108{
109	return mpc_or(11, mpd_add(), mpd_addid(), mpd_clear(), mpd_delete(),
110	              mpd_deleteid(), mpd_move(), mpd_moveid(),
111	              mpd_playlistfind(), mpd_playlistinfo(), mpd_plchanges(),
112	              mpd_rangeid());
113}