+/*
+ * Functions necessary to handle pandoc URLs.
+ * Copyright (C) 2014 Michael Goehler
+ *
+ * This file is part of mdp.
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
#include <stdlib.h>
#include <assert.h>
#include <string.h>
assert(tmp);
}
- tmp -> link_name = calloc(link_name_length, sizeof(char));
+ tmp -> link_name = calloc(link_name_length+1, sizeof(char));
assert(tmp->link_name);
strncpy(tmp->link_name, link_name, link_name_length);
+ tmp->link_name[link_name_length] = '\0';
- tmp->target = calloc(target_length, sizeof(char));
+ tmp->target = calloc(target_length+1, sizeof(char));
assert(tmp->target);
strncpy(tmp->target, target, target_length);
+ tmp->target[target_length] = '\0';
tmp->x = x;
tmp->y = y;
}
char * url_get_target(int index) {
+ if (!init_ok) return NULL;
+
url_t *tmp = list;
+ if (!tmp) return NULL;
+
while (index > 0 && tmp && tmp->next) {
tmp = tmp->next;
index--;
int url_get_amount(void) {
return index_max;
}
+
+int url_count_inline(const char *line) {
+ int count = 0;
+ const char *i = line;
+
+ for (; *i; i++) {
+ if (*i == '\\') {
+ i++;
+ } else if ( *i == '[' && *(i+1) != ']') {
+ while (*i && *i != ']') i++;
+ i++;
+ if (*i == '(' && strchr(i, ')')) {
+ count ++;
+ i = strchr(i, ')');
+ }
+ }
+ }
+
+ return count;
+}
+
+int url_len_inline(const char *text) {
+ int count = 0;
+ const char *i = text;
+
+ for (; *i; i++) {
+ if (*i == '\\') {
+ i++;
+ } else if ( *i == '[' && *(i+1) != ']') {
+ while (*i && *i != ']') i++;
+ i++;
+ if (*i == '(' && strchr(i, ')')) {
+ while (*i && *i != ')') {
+ count++;
+ i++;
+ }
+ }
+ }
+ }
+
+ return count;
+}