2 * Functions necessary to handle pandoc URLs.
3 * Copyright (C) 2015 Michael Goehler
5 * This file is part of mdp.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 static void url_del_elem(url_t *elem);
30 static void url_print(url_t *u);
42 int url_add(const wchar_t *link_name, int link_name_length, const wchar_t *target, int target_length, int x, int y) {
43 if (!init_ok) return -1;
54 tmp->next = malloc(sizeof(url_t));
58 list = malloc(sizeof(url_t));
63 tmp -> link_name = calloc(link_name_length+1, sizeof(wchar_t));
64 assert(tmp->link_name);
65 wcsncpy(tmp->link_name, link_name, link_name_length);
66 tmp->link_name[link_name_length] = '\0';
68 tmp->target = calloc(target_length+1, sizeof(wchar_t));
70 wcsncpy(tmp->target, target, target_length);
71 tmp->target[target_length] = '\0';
82 wchar_t * url_get_target(int index) {
83 if (!init_ok) return NULL;
87 if (!tmp) return NULL;
89 while (index > 0 && tmp && tmp->next) {
99 wchar_t * url_get_name(int index) {
102 while (index > 0 && tmp && tmp->next) {
108 return tmp->link_name;
119 static void url_del_elem(url_t *elem) {
123 url_del_elem(elem->next);
132 if (elem->link_name) {
133 free(elem->link_name);
134 elem->link_name = NULL;
140 void url_dump(void) {
153 static void url_print(url_t *u) {
154 printf("url_t @ %p\n", u);
157 int url_get_amount(void) {
161 int url_count_inline(const wchar_t *line) {
163 const wchar_t *i = line;
168 } else if ( *i == '[' && *(i+1) != ']') {
169 while (*i && *i != ']') i++;
171 if (*i == '(' && wcschr(i, ')')) {
181 int url_len_inline(const wchar_t *value) {
183 const wchar_t *i = value;
188 } else if ( *i == '[' && *(i+1) != ']') {
189 while (*i && *i != ']') i++;
191 if (*i == '(' && wcschr(i, ')')) {
192 while (*i && *i != ')') {