author | Lars Hjemli <hjemli@gmail.com> | 2008-12-05 18:04:17 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-12-05 18:04:17 (UTC) |
commit | 7115f7d257b5e3fb5d5d7ad6299214506fb35042 (patch) (unidiff) | |
tree | 844631b9f2a6354fcd988a13dfb9b1d567cb6344 | |
parent | a5e899e4c786e2ed7f58874d66956bf196cef8df (diff) | |
download | cgit-7115f7d257b5e3fb5d5d7ad6299214506fb35042.zip cgit-7115f7d257b5e3fb5d5d7ad6299214506fb35042.tar.gz cgit-7115f7d257b5e3fb5d5d7ad6299214506fb35042.tar.bz2 |
ui-repolist: avoid build warning for strcasestr(3)
The non-standard function strcasestr is only defined if _GNU_SOURCE has
also been defined.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-repolist.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index c23232c..2324273 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,136 +1,140 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | /* This is needed for strcasestr to be defined by <string.h> */ | ||
10 | #define _GNU_SOURCE 1 | ||
11 | #include <string.h> | ||
12 | |||
9 | #include <time.h> | 13 | #include <time.h> |
10 | 14 | ||
11 | #include "cgit.h" | 15 | #include "cgit.h" |
12 | #include "html.h" | 16 | #include "html.h" |
13 | #include "ui-shared.h" | 17 | #include "ui-shared.h" |
14 | 18 | ||
15 | time_t read_agefile(char *path) | 19 | time_t read_agefile(char *path) |
16 | { | 20 | { |
17 | FILE *f; | 21 | FILE *f; |
18 | static char buf[64], buf2[64]; | 22 | static char buf[64], buf2[64]; |
19 | 23 | ||
20 | if (!(f = fopen(path, "r"))) | 24 | if (!(f = fopen(path, "r"))) |
21 | return -1; | 25 | return -1; |
22 | if (fgets(buf, sizeof(buf), f) == NULL) | 26 | if (fgets(buf, sizeof(buf), f) == NULL) |
23 | return -1; | 27 | return -1; |
24 | fclose(f); | 28 | fclose(f); |
25 | if (parse_date(buf, buf2, sizeof(buf2))) | 29 | if (parse_date(buf, buf2, sizeof(buf2))) |
26 | return strtoul(buf2, NULL, 10); | 30 | return strtoul(buf2, NULL, 10); |
27 | else | 31 | else |
28 | return 0; | 32 | return 0; |
29 | } | 33 | } |
30 | 34 | ||
31 | static void print_modtime(struct cgit_repo *repo) | 35 | static void print_modtime(struct cgit_repo *repo) |
32 | { | 36 | { |
33 | char *path; | 37 | char *path; |
34 | struct stat s; | 38 | struct stat s; |
35 | 39 | ||
36 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 40 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
37 | if (stat(path, &s) == 0) { | 41 | if (stat(path, &s) == 0) { |
38 | cgit_print_age(read_agefile(path), -1, NULL); | 42 | cgit_print_age(read_agefile(path), -1, NULL); |
39 | return; | 43 | return; |
40 | } | 44 | } |
41 | 45 | ||
42 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 46 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
43 | if (stat(path, &s) != 0) | 47 | if (stat(path, &s) != 0) |
44 | return; | 48 | return; |
45 | cgit_print_age(s.st_mtime, -1, NULL); | 49 | cgit_print_age(s.st_mtime, -1, NULL); |
46 | } | 50 | } |
47 | 51 | ||
48 | int is_match(struct cgit_repo *repo) | 52 | int is_match(struct cgit_repo *repo) |
49 | { | 53 | { |
50 | if (!ctx.qry.search) | 54 | if (!ctx.qry.search) |
51 | return 1; | 55 | return 1; |
52 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) | 56 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) |
53 | return 1; | 57 | return 1; |
54 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) | 58 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) |
55 | return 1; | 59 | return 1; |
56 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) | 60 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) |
57 | return 1; | 61 | return 1; |
58 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) | 62 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) |
59 | return 1; | 63 | return 1; |
60 | return 0; | 64 | return 0; |
61 | } | 65 | } |
62 | 66 | ||
63 | int is_in_url(struct cgit_repo *repo) | 67 | int is_in_url(struct cgit_repo *repo) |
64 | { | 68 | { |
65 | if (!ctx.qry.url) | 69 | if (!ctx.qry.url) |
66 | return 1; | 70 | return 1; |
67 | if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) | 71 | if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) |
68 | return 1; | 72 | return 1; |
69 | return 0; | 73 | return 0; |
70 | } | 74 | } |
71 | 75 | ||
72 | void print_header(int columns) | 76 | void print_header(int columns) |
73 | { | 77 | { |
74 | html("<tr class='nohover'>" | 78 | html("<tr class='nohover'>" |
75 | "<th class='left'>Name</th>" | 79 | "<th class='left'>Name</th>" |
76 | "<th class='left'>Description</th>" | 80 | "<th class='left'>Description</th>" |
77 | "<th class='left'>Owner</th>" | 81 | "<th class='left'>Owner</th>" |
78 | "<th class='left'>Idle</th>"); | 82 | "<th class='left'>Idle</th>"); |
79 | if (ctx.cfg.enable_index_links) | 83 | if (ctx.cfg.enable_index_links) |
80 | html("<th class='left'>Links</th>"); | 84 | html("<th class='left'>Links</th>"); |
81 | html("</tr>\n"); | 85 | html("</tr>\n"); |
82 | } | 86 | } |
83 | 87 | ||
84 | 88 | ||
85 | void print_pager(int items, int pagelen, char *search) | 89 | void print_pager(int items, int pagelen, char *search) |
86 | { | 90 | { |
87 | int i; | 91 | int i; |
88 | html("<div class='pager'>"); | 92 | html("<div class='pager'>"); |
89 | for(i = 0; i * pagelen < items; i++) | 93 | for(i = 0; i * pagelen < items; i++) |
90 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, | 94 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, |
91 | search, i * pagelen); | 95 | search, i * pagelen); |
92 | html("</div>"); | 96 | html("</div>"); |
93 | } | 97 | } |
94 | 98 | ||
95 | void cgit_print_repolist() | 99 | void cgit_print_repolist() |
96 | { | 100 | { |
97 | int i, columns = 4, hits = 0, header = 0; | 101 | int i, columns = 4, hits = 0, header = 0; |
98 | char *last_group = NULL; | 102 | char *last_group = NULL; |
99 | 103 | ||
100 | if (ctx.cfg.enable_index_links) | 104 | if (ctx.cfg.enable_index_links) |
101 | columns++; | 105 | columns++; |
102 | 106 | ||
103 | ctx.page.title = ctx.cfg.root_title; | 107 | ctx.page.title = ctx.cfg.root_title; |
104 | cgit_print_http_headers(&ctx); | 108 | cgit_print_http_headers(&ctx); |
105 | cgit_print_docstart(&ctx); | 109 | cgit_print_docstart(&ctx); |
106 | cgit_print_pageheader(&ctx); | 110 | cgit_print_pageheader(&ctx); |
107 | 111 | ||
108 | if (ctx.cfg.index_header) | 112 | if (ctx.cfg.index_header) |
109 | html_include(ctx.cfg.index_header); | 113 | html_include(ctx.cfg.index_header); |
110 | 114 | ||
111 | html("<table summary='repository list' class='list nowrap'>"); | 115 | html("<table summary='repository list' class='list nowrap'>"); |
112 | for (i=0; i<cgit_repolist.count; i++) { | 116 | for (i=0; i<cgit_repolist.count; i++) { |
113 | ctx.repo = &cgit_repolist.repos[i]; | 117 | ctx.repo = &cgit_repolist.repos[i]; |
114 | if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) | 118 | if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) |
115 | continue; | 119 | continue; |
116 | hits++; | 120 | hits++; |
117 | if (hits <= ctx.qry.ofs) | 121 | if (hits <= ctx.qry.ofs) |
118 | continue; | 122 | continue; |
119 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) | 123 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) |
120 | continue; | 124 | continue; |
121 | if (!header++) | 125 | if (!header++) |
122 | print_header(columns); | 126 | print_header(columns); |
123 | if ((last_group == NULL && ctx.repo->group != NULL) || | 127 | if ((last_group == NULL && ctx.repo->group != NULL) || |
124 | (last_group != NULL && ctx.repo->group == NULL) || | 128 | (last_group != NULL && ctx.repo->group == NULL) || |
125 | (last_group != NULL && ctx.repo->group != NULL && | 129 | (last_group != NULL && ctx.repo->group != NULL && |
126 | strcmp(ctx.repo->group, last_group))) { | 130 | strcmp(ctx.repo->group, last_group))) { |
127 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 131 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
128 | columns); | 132 | columns); |
129 | html_txt(ctx.repo->group); | 133 | html_txt(ctx.repo->group); |
130 | html("</td></tr>"); | 134 | html("</td></tr>"); |
131 | last_group = ctx.repo->group; | 135 | last_group = ctx.repo->group; |
132 | } | 136 | } |
133 | htmlf("<tr><td class='%s'>", | 137 | htmlf("<tr><td class='%s'>", |
134 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); | 138 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); |
135 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); | 139 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); |
136 | html("</td><td>"); | 140 | html("</td><td>"); |