diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-13 02:27:56 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-13 02:28:01 +0200 |
commit | 6bc291c0fd3e1760ca4bfeaf33b38cbb4b21830c (patch) | |
tree | 887c41ec771a48d3323c9d2a2e0d7f6c86c36736 /client | |
parent | renamed files to prepare merge of code dirs (diff) |
merged app sources to single folder
Diffstat (limited to 'client')
-rw-r--r-- | client/dolmetschctl-client.c | 192 | ||||
-rw-r--r-- | client/midi_client.c | 242 | ||||
-rw-r--r-- | client/midi_client.h | 54 | ||||
-rw-r--r-- | client/osc_client.c | 123 | ||||
-rw-r--r-- | client/osc_client.h | 41 | ||||
-rw-r--r-- | client/slist.c | 123 | ||||
-rw-r--r-- | client/slist.h | 46 |
7 files changed, 0 insertions, 821 deletions
diff --git a/client/dolmetschctl-client.c b/client/dolmetschctl-client.c deleted file mode 100644 index 9815924..0000000 --- a/client/dolmetschctl-client.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <stdio.h> -#include <unistd.h> -#include <ctype.h> -#include <error.h> - -#include <lo/lo.h> -#include <alsa/asoundlib.h> - -#include "midi_client.h" -#include "osc_client.h" - - -void print_version() -{ - printf("%s\n", VERSION_STRING_0); -#if defined(__clang__) - printf("%s, using CLANG %s\n", VERSION_STRING_1, __clang_version__); -#elif defined(__GNUC__) - printf("%s, using GCC %d.%d.%d\n", VERSION_STRING_1, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -#else - printf("%s\n", VERSION_STRING_1); -#endif - - printf("linked against alsa-lib Version %s\n", snd_asoundlib_version()); - char verstr[32]; - lo_version(verstr, sizeof(verstr), 0, 0, 0, 0, 0, 0, 0); - printf("linked against liblo Version %s\n", verstr); -} - -void print_usage() -{ - printf("\ndolmetschctl-client <options>\n"); - printf(" -h print this and exit\n"); - printf(" -v print version information and exit\n"); - printf(" -m <dev> the MIDI control device name to use, i.e. hw:2,0,0\n"); - printf(" (use `amidi -l` to list all available devices)'\n"); - printf(" -o <host>:<port> the UDP host/port to send OSC messages to\n"); -} - -int main_loop(midi_t* m, osc_t* o) -{ - int ret = 0; - - printf("main_loop just started\n"); - - int midi_npfds_offset = 0; - int midi_npfds = midi_get_poll_fd_count(m); - assert(midi_npfds > 0); - - int osc_npfds_offset = midi_npfds_offset + midi_npfds; - int osc_npfds = osc_get_poll_fd_count(o); - assert(osc_npfds > 0); - - int npfds = midi_npfds + osc_npfds; - struct pollfd *pfds = alloca(npfds * sizeof(struct pollfd)); - if(!pfds) { - error(0, 0, "error while allocating poll fds - stack corrupted??"); - return -1; - } - - printf("main_loop running with %d pollfds...\n", npfds); - for (;;) { - midi_get_poll_fds(m, &(pfds[midi_npfds_offset]), midi_npfds); - osc_get_poll_fds(o, &(pfds[osc_npfds_offset]), osc_npfds); - - int err = poll(pfds, npfds, 200); - if(err < 0 && errno != EINTR) { - error(0, errno, "poll failed"); - break; - } - if(err <= 0) { - // timeout or EINTR - continue; - } - - ret = midi_handle_revents(m, &(pfds[midi_npfds_offset]), midi_npfds, o); - if(ret) - break; - -// ret = osc_handle_revents(o, &(pfds[osc_npfds_offset]), osc_npfds, m); - ret = osc_handle_revents(o, &(pfds[osc_npfds_offset]), osc_npfds); - if(ret) - break; - } - - return ret; -} - -int main(int argc, char* argv[]) -{ - int helpflag = 0; - int versionflag = 0; - char* midi_dev = NULL; - char* osc_target = NULL; - - int c; - opterr = 0; - while ((c = getopt (argc, argv, "vhm:o:")) != -1) { - switch (c) { - case 'h': - helpflag = 1; - break; - case 'v': - versionflag = 1; - break; - case 'm': - midi_dev = optarg; - break; - case 'o': - osc_target = optarg; - break; - case '?': - if (optopt == 'm' || optopt == 'o') - error(0, 0, "Option -%c requires an argument.\n", optopt); - else if (isprint (optopt)) - error(0, 0, "Unknown option `-%c'.\n", optopt); - else - error(0, 0, "Unknown option character `\\x%x'.\n", optopt); - return -1; - default: - return -1; - } - } - - if(helpflag) { - print_usage(); - return 0; - } - - if(versionflag) { - print_version(); - return 0; - } - - if(!midi_dev){ - error(0, 0, "MIDI device name must be set"); - print_usage(); - return -1; - } - - if(!osc_target){ - error(0, 0, "OSC target (host/port) name must be set"); - print_usage(); - return -1; - } - - char* port = osc_target; - char* host = strsep(&port, ":"); - char* remain = port; - strsep(&remain, ":"); - if(!host || !port || remain) { - error(0, 0, "'%s' is not a valid targets, must be in the format <host>:<port>", osc_target); - print_usage(); - return -1; - } - - midi_t m; - if(midi_init(&m, midi_dev)) - return -1; - - osc_t o; - if(osc_init(&o, &m, host, port)) - return -1; - - int ret = main_loop(&m, &o); - - return ret; -} diff --git a/client/midi_client.c b/client/midi_client.c deleted file mode 100644 index 456ec7d..0000000 --- a/client/midi_client.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <stdio.h> -#include <error.h> -#include <poll.h> -#include <assert.h> - -#include "midi_client.h" - -#define NOTE_EN 0x00 -#define NOTE_DE 0x01 -u_int8_t led_cmd_en[] = { 0xB0, NOTE_EN, 0x01, 0xB0, NOTE_DE, 0x00 }; -u_int8_t led_cmd_de[] = { 0xB0, NOTE_EN, 0x00, 0xB0, NOTE_DE, 0x01 }; - -static void free_cmd_entry(void* ptr) -{ - cmd_t* c = ptr; - assert(c); - free(c->buf_); - free(c); -} - -int midi_init(midi_t* m, const char* device) -{ - assert(m != NULL); - - m->input_ = NULL; - m->output_ = NULL; - memset(m->buf_, 0, sizeof(m->buf_)); - m->read_idx_ = 0; - slist_init(&(m->cmds_), free_cmd_entry); - - int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK); - if(ret < 0) { - error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret)); - return ret; - } - - return 0; -} - -int midi_enqueue_cmd(midi_t* m, const char* lang) -{ - assert(m && lang); - - int len; - const u_int8_t* src; - if(!strcmp(lang, "en")) { - len = sizeof(led_cmd_en); - src = led_cmd_en; - } - else if(!strcmp(lang, "de")) { - len = sizeof(led_cmd_de); - src = led_cmd_de; - } - else - return 0; - - cmd_t* cmd = malloc(sizeof(cmd_t)); - assert(cmd); - cmd->len_ = len; - assert((cmd->buf_ = malloc(cmd->len_))); - memcpy(cmd->buf_, src, cmd->len_); - cmd->write_idx_ = 0; - - slist_add(&(m->cmds_), cmd); - - return 0; -} - -int midi_get_poll_fd_count(midi_t* m) -{ - assert(m); - - m->in_pfds_cnt_ = snd_rawmidi_poll_descriptors_count(m->input_); - assert(m->in_pfds_cnt_ > 0); - m->out_pfds_cnt_ = snd_rawmidi_poll_descriptors_count(m->output_); - assert(m->out_pfds_cnt_ > 0); - - return (m->in_pfds_cnt_ + m->out_pfds_cnt_); -} - -int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds) -{ - assert(m && pfds && npfds); - - snd_rawmidi_poll_descriptors(m->input_, pfds, m->in_pfds_cnt_); - snd_rawmidi_poll_descriptors(m->output_, &(pfds[m->in_pfds_cnt_]), npfds - m->in_pfds_cnt_); - - if(!slist_length(&(m->cmds_))) { - int i; - for(i = m->in_pfds_cnt_; i < npfds; ++i) - pfds[i].events = 0; - } - return (m->in_pfds_cnt_ + m->out_pfds_cnt_); -} - -static int midi_enqueue_lang_switch(midi_t* m, osc_t* o, const char* lang) -{ - return osc_switch_lang(o, lang); -} - -static int midi_handle_note_on(midi_t* m, osc_t* o) -{ - int ret = 0; - switch(m->buf_[1]) { - case NOTE_EN: ret = midi_enqueue_lang_switch(m, o,"en"); break; - case NOTE_DE: ret = midi_enqueue_lang_switch(m, o, "de"); break; - default: printf("ignoring unknown note\n"); break; - } - return ret; -} - -static int midi_handle_note_off(midi_t* m, osc_t* o) -{ - return 0; -} - -static int midi_handle_message(midi_t* m, osc_t* o) -{ - /* int i; */ - /* printf("MIDI: "); */ - /* for (i = 0; i < sizeof(m->buf_); ++i) */ - /* printf("%02X%c", m->buf_[i], (i >= (sizeof(m->buf_)-1)) ? '\n' : ' '); */ - - int ret = 0; - switch(m->buf_[0]) { - case 0x90: ret = midi_handle_note_on(m, o); break; - case 0x80: ret = midi_handle_note_off(m, o); break; - default: printf("ignoring unknown midi command\n"); break; - } - - return ret; -} - -static int midi_handle_in_revents(midi_t* m, struct pollfd *pfds, int npfds, osc_t* o) -{ - int err; - unsigned short revents; - if((err = snd_rawmidi_poll_descriptors_revents(m->input_, pfds, npfds, &revents)) < 0) { - error(0, 0, "MIDI: cannot get poll events: %s", snd_strerror(errno)); - return -1; - } - if(pfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { - error(0, 0, "MIDI: got POLLERR, POLLHUP or POLLNVAL"); - return -1; - } - if(!(revents & POLLIN)) - return 0; - - int ret = snd_rawmidi_read(m->input_, &(m->buf_[m->read_idx_]), sizeof(m->buf_) - m->read_idx_); - if(ret == -EAGAIN) - return 0; - if(ret < 0) { - error(0, 0, "MIDI: cannot read from midi port: %s", snd_strerror(ret)); - return -1; - } - m->read_idx_ += ret; - if(m->read_idx_ >= sizeof(m->buf_)) { - ret = midi_handle_message(m, o); - memset(m->buf_, 0, sizeof(m->buf_)); - m->read_idx_ = 0; - return ret; - } - - return ret; -} - -static int midi_handle_out_revents(midi_t* m, struct pollfd *pfds, int npfds) -{ - int err; - unsigned short revents; - if((err = snd_rawmidi_poll_descriptors_revents(m->output_, pfds, npfds, &revents)) < 0) { - error(0, 0, "MIDI: cannot get poll events: %s", snd_strerror(errno)); - return -1; - } - if(pfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { - error(0, 0, "MIDI: got POLLERR, POLLHUP or POLLNVAL"); - return -1; - } - if(!(revents & POLLOUT)) - return 0; - - assert(m->cmds_.first_); - cmd_t* cmd = (cmd_t*)(m->cmds_.first_->data_); - assert(cmd); - assert(cmd->buf_); - - int ret = snd_rawmidi_write(m->output_, &(cmd->buf_[cmd->write_idx_]), cmd->len_ - cmd->write_idx_); - if(ret == -EAGAIN) - return 0; - if(ret < 0) { - error(0, 0, "MIDI: cannot write to port: %s", snd_strerror(ret)); - return -1; - } - cmd->write_idx_ += ret; - if(cmd->write_idx_ >= cmd->len_) { - if((err = snd_rawmidi_drain(m->output_)) < 0) { - error(0, 0, "MIDI: cannot drain output: %s", snd_strerror(err)); - return -1; - } - slist_remove(&(m->cmds_), cmd); - } - - return 0; -} - -int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, osc_t* o) -{ - assert(m); - - if(!m->input_ || !m->output_) - return 0; - - int ret = midi_handle_in_revents(m, pfds, m->in_pfds_cnt_, o); - if(ret) - return ret; - - return midi_handle_out_revents(m, &(pfds[m->in_pfds_cnt_]), m->out_pfds_cnt_); -} diff --git a/client/midi_client.h b/client/midi_client.h deleted file mode 100644 index 7ae65bd..0000000 --- a/client/midi_client.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef DOLMETSCHCTL_midi_h_INCLUDED -#define DOLMETSCHCTL_midi_h_INCLUDED - -#include <alsa/asoundlib.h> -#include <poll.h> - -#include "slist.h" -#include "osc_client.h" - -typedef struct { - u_int8_t* buf_; - int len_; - int write_idx_; -} cmd_t; - -typedef struct { - snd_rawmidi_t* input_; - int in_pfds_cnt_; - snd_rawmidi_t* output_; - int out_pfds_cnt_; - u_int8_t buf_[3]; - int read_idx_; - slist_t cmds_; -} midi_t; - -int midi_init(midi_t* m, const char* device); -int midi_enqueue_cmd(midi_t* m, const char* lang); -int midi_get_poll_fd_count(midi_t* m); -int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds); -int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, osc_t* o); - -#endif diff --git a/client/osc_client.c b/client/osc_client.c deleted file mode 100644 index a70eb67..0000000 --- a/client/osc_client.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <error.h> -#include <assert.h> - -#include "osc_client.h" -#include "midi_client.h" - - -static void print_error(int num, const char *msg, const char *path) -{ - error(0, 0, "liblo server error %d in path %s: %s", num, path, msg); -} - -static int lang_handler(const char *path, const char *types, lo_arg ** argv, - int argc, lo_message msg, void *user_data) -{ - osc_t* o = (osc_t*)user_data; - assert(o); - - if(argc != 1 || !lo_is_string_type((lo_type)types[0])) - return 1; - -// printf("got ack for: lang '%s'\n", &(argv[0]->s)); - midi_enqueue_cmd((midi_t*)o->m_, &(argv[0]->s)); - - return 0; -} - -int osc_init(osc_t* o, void* m, const char* host, const char* port) -{ - assert(o != NULL); - - o->server_ = NULL; - o->target_ = lo_address_new(host, port); - o->m_ = m; - - if(!port) - return 0; - - o->server_ = lo_server_new(NULL, print_error); - if(!o->server_) - return -1; - - if(!lo_server_add_method(o->server_, "/lang/ack", "s", lang_handler, (void*)o)) - return -1; - - return 0; -} - -int osc_switch_lang(osc_t* o, const char* lang) -{ - lo_send_from(o->target_, o->server_, LO_TT_IMMEDIATE, "/lang/switch", "s", lang); - return 0; -} - -int osc_get_poll_fd_count(osc_t* o) -{ - assert(o); - - if(!o->server_) - return 0; - - return 1; -} - -int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds) -{ - assert(o); - - if(!o->server_) - return 0; - - pfds[0].fd = lo_server_get_socket_fd(o->server_); - pfds[0].events = POLLIN; - pfds[0].revents = 0; - - return 0; -} - -int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds) -{ - assert(o); - - if(!o->server_) - return 0; - - if(pfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { - error(0, 0, "OSC: got POLLERR, POLLHUP or POLLNVAL"); - return -1; - } - if(!(pfds[0].revents & POLLIN)) - return 0; - - lo_server_recv_noblock(o->server_, 0); - - return 0; -} diff --git a/client/osc_client.h b/client/osc_client.h deleted file mode 100644 index 9d1ad94..0000000 --- a/client/osc_client.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef DOLMETSCHCTL_osc_h_INCLUDED -#define DOLMETSCHCTL_osc_h_INCLUDED - -#include "lo/lo.h" -#include <poll.h> - -typedef struct { - lo_server server_; - lo_address target_; - void* m_; // forward declarations of typedes are not possible -- this is a HACK! FIXME!!! -} osc_t; - -int osc_init(osc_t* o, void* m, const char* host, const char* port); -int osc_switch_lang(osc_t* o, const char* lang); -int osc_get_poll_fd_count(osc_t* o); -int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds); -int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds); - -#endif diff --git a/client/slist.c b/client/slist.c deleted file mode 100644 index b10aca7..0000000 --- a/client/slist.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <unistd.h> -#include <stdlib.h> -#include <assert.h> - -#include "slist.h" - -slist_element_t* slist_get_last(slist_element_t* first) -{ - if(!first) - return NULL; - - while(first->next_) - first = first->next_; - - return first; -} - -void slist_init(slist_t* lst, void (*delete_element)(void*)) -{ - assert(lst && delete_element); - - lst->delete_element = delete_element; - lst->first_ = NULL; -} - -slist_element_t* slist_add(slist_t* lst, void* data) -{ - if(!lst || !data) - return NULL; - - slist_element_t* new_element = malloc(sizeof(slist_element_t)); - if(!new_element) - return NULL; - - new_element->data_ = data; - new_element->next_ = NULL; - - if(!lst->first_) - lst->first_ = new_element; - else - slist_get_last(lst->first_)->next_ = new_element; - - return new_element; -} - -void slist_remove(slist_t* lst, void* data) -{ - if(!lst || !lst->first_ || !data) - return; - - slist_element_t* tmp = lst->first_->next_; - slist_element_t* prev = lst->first_; - if(lst->first_->data_ == data) { - lst->first_ = tmp; - lst->delete_element(prev->data_); - free(prev); - } - else { - while(tmp) { - if(tmp->data_ == data) { - prev->next_ = tmp->next_; - lst->delete_element(tmp->data_); - free(tmp); - return; - } - prev = tmp; - tmp = tmp->next_; - } - } -} - -void slist_clear(slist_t* lst) -{ - if(!lst || !lst->first_) - return; - - do { - slist_element_t* deletee = lst->first_; - lst->first_ = lst->first_->next_; - lst->delete_element(deletee->data_); - free(deletee); - } - while(lst->first_); - - lst->first_ = NULL; -} - -int slist_length(slist_t* lst) -{ - if(!lst || !lst->first_) - return 0; - - int len = 0; - slist_element_t* tmp; - for(tmp = lst->first_; tmp; tmp = tmp->next_) - len++; - - return len; -} diff --git a/client/slist.h b/client/slist.h deleted file mode 100644 index 70a81b5..0000000 --- a/client/slist.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * dolmetschctl - * - * - * Copyright (C) 2015 Christian Pointner <equinox@spreadspace.org> - * - * This file is part of dolmetschctl. - * - * dolmetschctl is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * dolmetschctl is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dolmetschctl. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef DOLMETSCHCTL_slist_h_INCLUDED -#define DOLMETSCHCTL_slist_h_INCLUDED - -struct slist_element_struct { - void* data_; - struct slist_element_struct* next_; -}; -typedef struct slist_element_struct slist_element_t; - -slist_element_t* slist_get_last(slist_element_t* first); - -struct slist_struct { - void (*delete_element)(void* element); - slist_element_t* first_; -}; -typedef struct slist_struct slist_t; - -void slist_init(slist_t* lst, void (*delete_element)(void*)); -slist_element_t* slist_add(slist_t* lst, void* data); -void slist_remove(slist_t* lst, void* data); -void slist_clear(slist_t* lst); -int slist_length(slist_t* lst); - -#endif |