author | Lars Hjemli <hjemli@gmail.com> | 2007-10-28 11:08:45 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-28 11:08:45 (UTC) |
commit | 6ec5f36f279a85f59db2851ab476d9acd0015770 (patch) (unidiff) | |
tree | 18aff69bb319bbbf7427a1f401d86063ee850824 | |
parent | 0c8dd9c4bcc7a1a7a49f4eca1f3eb869d0995ea2 (diff) | |
download | cgit-6ec5f36f279a85f59db2851ab476d9acd0015770.zip cgit-6ec5f36f279a85f59db2851ab476d9acd0015770.tar.gz cgit-6ec5f36f279a85f59db2851ab476d9acd0015770.tar.bz2 |
Add html_option() function
This is a generic function used to output html "option" tags.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | html.c | 12 |
2 files changed, 13 insertions, 0 deletions
@@ -183,48 +183,49 @@ extern char *trim_end(const char *str, char c); | |||
183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
185 | int flags, void *cb_data); | 185 | int flags, void *cb_data); |
186 | 186 | ||
187 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 187 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
188 | 188 | ||
189 | extern int cgit_diff_files(const unsigned char *old_sha1, | 189 | extern int cgit_diff_files(const unsigned char *old_sha1, |
190 | const unsigned char *new_sha1, | 190 | const unsigned char *new_sha1, |
191 | linediff_fn fn); | 191 | linediff_fn fn); |
192 | 192 | ||
193 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 193 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
194 | const unsigned char *new_sha1, | 194 | const unsigned char *new_sha1, |
195 | filepair_fn fn, const char *prefix); | 195 | filepair_fn fn, const char *prefix); |
196 | 196 | ||
197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
198 | 198 | ||
199 | extern char *fmt(const char *format,...); | 199 | extern char *fmt(const char *format,...); |
200 | 200 | ||
201 | extern void html(const char *txt); | 201 | extern void html(const char *txt); |
202 | extern void htmlf(const char *format,...); | 202 | extern void htmlf(const char *format,...); |
203 | extern void html_txt(char *txt); | 203 | extern void html_txt(char *txt); |
204 | extern void html_ntxt(int len, char *txt); | 204 | extern void html_ntxt(int len, char *txt); |
205 | extern void html_attr(char *txt); | 205 | extern void html_attr(char *txt); |
206 | extern void html_hidden(char *name, char *value); | 206 | extern void html_hidden(char *name, char *value); |
207 | extern void html_option(char *value, char *text, char *selected_value); | ||
207 | extern void html_link_open(char *url, char *title, char *class); | 208 | extern void html_link_open(char *url, char *title, char *class); |
208 | extern void html_link_close(void); | 209 | extern void html_link_close(void); |
209 | extern void html_filemode(unsigned short mode); | 210 | extern void html_filemode(unsigned short mode); |
210 | extern int html_include(const char *filename); | 211 | extern int html_include(const char *filename); |
211 | 212 | ||
212 | extern int cgit_read_config(const char *filename, configfn fn); | 213 | extern int cgit_read_config(const char *filename, configfn fn); |
213 | extern int cgit_parse_query(char *txt, configfn fn); | 214 | extern int cgit_parse_query(char *txt, configfn fn); |
214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 215 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 216 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
216 | extern void cgit_parse_url(const char *url); | 217 | extern void cgit_parse_url(const char *url); |
217 | 218 | ||
218 | extern char *cache_safe_filename(const char *unsafe); | 219 | extern char *cache_safe_filename(const char *unsafe); |
219 | extern int cache_lock(struct cacheitem *item); | 220 | extern int cache_lock(struct cacheitem *item); |
220 | extern int cache_unlock(struct cacheitem *item); | 221 | extern int cache_unlock(struct cacheitem *item); |
221 | extern int cache_cancel_lock(struct cacheitem *item); | 222 | extern int cache_cancel_lock(struct cacheitem *item); |
222 | extern int cache_exist(struct cacheitem *item); | 223 | extern int cache_exist(struct cacheitem *item); |
223 | extern int cache_expired(struct cacheitem *item); | 224 | extern int cache_expired(struct cacheitem *item); |
224 | 225 | ||
225 | extern char *cgit_repourl(const char *reponame); | 226 | extern char *cgit_repourl(const char *reponame); |
226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 227 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
227 | const char *filename, const char *query); | 228 | const char *filename, const char *query); |
228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 229 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
229 | const char *query); | 230 | const char *query); |
230 | 231 | ||
@@ -105,48 +105,60 @@ void html_attr(char *txt) | |||
105 | *t = c; | 105 | *t = c; |
106 | if (c=='>') | 106 | if (c=='>') |
107 | html(">"); | 107 | html(">"); |
108 | else if (c=='<') | 108 | else if (c=='<') |
109 | html("<"); | 109 | html("<"); |
110 | else if (c=='\'') | 110 | else if (c=='\'') |
111 | html(""e;"); | 111 | html(""e;"); |
112 | txt = t+1; | 112 | txt = t+1; |
113 | } | 113 | } |
114 | t++; | 114 | t++; |
115 | } | 115 | } |
116 | if (t!=txt) | 116 | if (t!=txt) |
117 | html(txt); | 117 | html(txt); |
118 | } | 118 | } |
119 | 119 | ||
120 | void html_hidden(char *name, char *value) | 120 | void html_hidden(char *name, char *value) |
121 | { | 121 | { |
122 | html("<input type='hidden' name='"); | 122 | html("<input type='hidden' name='"); |
123 | html_attr(name); | 123 | html_attr(name); |
124 | html("' value='"); | 124 | html("' value='"); |
125 | html_attr(value); | 125 | html_attr(value); |
126 | html("'/>"); | 126 | html("'/>"); |
127 | } | 127 | } |
128 | 128 | ||
129 | void html_option(char *value, char *text, char *selected_value) | ||
130 | { | ||
131 | html("<option value='"); | ||
132 | html_attr(value); | ||
133 | html("'"); | ||
134 | if (selected_value && !strcmp(selected_value, value)) | ||
135 | html(" selected"); | ||
136 | html(">"); | ||
137 | html_txt(text); | ||
138 | html("</option>\n"); | ||
139 | } | ||
140 | |||
129 | void html_link_open(char *url, char *title, char *class) | 141 | void html_link_open(char *url, char *title, char *class) |
130 | { | 142 | { |
131 | html("<a href='"); | 143 | html("<a href='"); |
132 | html_attr(url); | 144 | html_attr(url); |
133 | if (title) { | 145 | if (title) { |
134 | html("' title='"); | 146 | html("' title='"); |
135 | html_attr(title); | 147 | html_attr(title); |
136 | } | 148 | } |
137 | if (class) { | 149 | if (class) { |
138 | html("' class='"); | 150 | html("' class='"); |
139 | html_attr(class); | 151 | html_attr(class); |
140 | } | 152 | } |
141 | html("'>"); | 153 | html("'>"); |
142 | } | 154 | } |
143 | 155 | ||
144 | void html_link_close(void) | 156 | void html_link_close(void) |
145 | { | 157 | { |
146 | html("</a>"); | 158 | html("</a>"); |
147 | } | 159 | } |
148 | 160 | ||
149 | void html_fileperm(unsigned short mode) | 161 | void html_fileperm(unsigned short mode) |
150 | { | 162 | { |
151 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 163 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
152 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 164 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |