Add license notifications to all source files
[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         memcpy(info->author, url, len);
23         info->author[len] = 0;
24         info->contents |= URL_INFO_AUTHOR;
25
26         if (c == NULL || c[1] == 0)
27                 return info->contents;
28
29         info->record = strtoull(c + 1, NULL, 10);
30         info->contents |= URL_INFO_RECORD;
31
32         c = strchr(c, '-');
33         if (c == NULL || c[1] == 0)
34                 return info->contents;
35
36         info->record_to = strtoull(c + 1, NULL, 10);
37         info->contents |= URL_INFO_RECORD_TO;
38
39         return info->contents;
40 }
41
42 uint64_t *make_sequential_list(uint64_t from, uint64_t to) {
43         uint64_t len = to - from + 1;
44         uint64_t *list = malloc(len * sizeof(uint64_t));
45         uint64_t i;
46
47         for (i = 0; i < len; i++) {
48                 list[i] = from + i;
49         }
50
51         return list;
52 }