Release notes for 1.9.1
[blerg.git] / common / app.c
1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2  * BSD-style license.  Please see the COPYING file for details.
3  */
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include "app.h"
8
9 int parse_url_info(const char *url, struct url_info *info) {
10         const char *c;
11         int len;
12         info->contents = 0;
13
14         c = strchr(url, '/');
15         if (c == NULL) {
16                 len = strlen(url);
17         } else {
18                 len = c - url;
19         }
20         if (len == 0)
21                 return 0;
22         if (len > MAX_TAG_LENGTH)
23                 len = MAX_TAG_LENGTH;
24         memcpy(info->name, url, len);
25         info->name[len] = 0;
26         info->contents |= URL_INFO_NAME;
27
28         if (c == NULL || c[1] == 0)
29                 return info->contents;
30
31         info->record = strtoull(c + 1, NULL, 10);
32         info->contents |= URL_INFO_RECORD;
33
34         c = strchr(c, '-');
35         if (c == NULL || c[1] == 0)
36                 return info->contents;
37
38         info->record_to = strtoull(c + 1, NULL, 10);
39         info->contents |= URL_INFO_RECORD_TO;
40
41         return info->contents;
42 }
43
44 uint64_t *make_sequential_list(uint64_t from, uint64_t to) {
45         uint64_t len = to - from + 1;
46         uint64_t *list = malloc(len * sizeof(uint64_t));
47         uint64_t i;
48
49         for (i = 0; i < len; i++) {
50                 list[i] = from + i;
51         }
52
53         return list;
54 }