Subversion Repositories RepoView

Rev

Rev 11 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 1... Line 1...
1
/* $Id: modern.c 11 2024-08-21 04:31:55Z nishi $ */
1
/* $Id: modern.c 12 2024-08-21 05:05:19Z nishi $ */
2
 
2
 
3
#include "rv_query.h"
3
#include "rv_query.h"
4
 
4
 
5
#include "rv_util.h"
5
#include "rv_util.h"
6
#include "rv_version.h"
6
#include "rv_version.h"
Line 114... Line 114...
114
void list_files(const char* pathname) {
114
void list_files(const char* pathname) {
115
	if(fcounter == 0) {
115
	if(fcounter == 0) {
116
		add_data(&nav, "<li><a href=\"#filelist\">File List</a></li>\n");
116
		add_data(&nav, "<li><a href=\"#filelist\">File List</a></li>\n");
117
		add_data(&page, "<h2 id=\"filelist\">File List</h2>\n");
117
		add_data(&page, "<h2 id=\"filelist\">File List</h2>\n");
118
		add_data(&page, "<tr style=\"background-color: #D2E1F6;\"><th>Name</th><th>Size</th></tr>\n");
118
		add_data(&page, "<tr style=\"background-color: #D2E1F6;\"><th>Name</th><th>Size</th></tr>\n");
-
 
119
		char* path = rv_get_query("path");
-
 
120
		if(path == NULL) path = "/";
-
 
121
		if(strcmp(path, "/") != 0) {
-
 
122
			char* query = rv_strdup("?page=repo&reponame=");
-
 
123
			char* esc;
-
 
124
			esc = url_escape(rv_get_query("reponame"));
-
 
125
			add_data(&query, esc);
-
 
126
			free(esc);
-
 
127
			add_data(&query, "&username=");
-
 
128
			esc = url_escape(user);
-
 
129
			add_data(&query, esc);
-
 
130
			free(esc);
-
 
131
			add_data(&query, "&path=");
-
 
132
 
-
 
133
			char* urlpath = rv_strdup(path);
-
 
134
			int i;
-
 
135
			int counter = 0;
-
 
136
			int rep = urlpath[strlen(urlpath) - 1] == '/' ? 2 : 1;
-
 
137
			for(i = strlen(urlpath) - 1; i >= 0; i--) {
-
 
138
				char oldc = urlpath[i];
-
 
139
				urlpath[i] = 0;
-
 
140
				if(oldc == '/') {
-
 
141
					counter++;
-
 
142
					if(counter == 2) {
-
 
143
						break;
-
 
144
					}
-
 
145
				}
-
 
146
			}
-
 
147
 
-
 
148
			if(strlen(urlpath) == 0) {
-
 
149
				free(urlpath);
-
 
150
				urlpath = rv_strdup("/");
-
 
151
			}
-
 
152
 
-
 
153
			esc = url_escape(urlpath);
-
 
154
			add_data(&query, esc);
-
 
155
			free(esc);
-
 
156
 
-
 
157
			add_data(&page, "<tr><td><a href=\"");
-
 
158
			add_data(&page, query);
-
 
159
			add_data(&page, "\">../</a></td><td>&lt;DIR&gt;</td></tr>\n");
-
 
160
			fcounter++;
-
 
161
			free(query);
-
 
162
		}
119
	}
163
	}
120
	fcounter++;
164
	fcounter++;
121
	add_data(&page, "<tr style=\"background-color: #");
165
	add_data(&page, "<tr style=\"background-color: #");
122
	if((fcounter % 2) == 0) {
166
	if((fcounter % 2) == 0) {
123
		add_data(&page, "D2E1C0");
167
		add_data(&page, "D2E1C0");
Line 378... Line 422...
378
				if(isdir == 0) {
422
				if(isdir == 0) {
379
					add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
423
					add_data(&nav, "<li><a href=\"#filecontent\">Content</a></li>");
380
					add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
424
					add_data(&page, "<h2 id=\"filecontent\">Content</h2>\n");
381
					add_data(&page, "<pre class=\"codeblock\"><code>");
425
					add_data(&page, "<pre class=\"codeblock\"><code>");
382
					char* data = rv_read_file(repouser, path);
426
					char* data = rv_read_file(repouser, path);
-
 
427
					if(data != NULL) {
383
					char* esc = html_escape_nl_to_br(data);
428
						char* esc = html_escape_nl_to_br(data);
384
					add_data(&page, esc);
429
						add_data(&page, esc);
385
					free(esc);
430
						free(esc);
386
					free(data);
431
						free(data);
-
 
432
					} else {
-
 
433
						add_data(&page, "Cannot open the file.\n");
-
 
434
					}
387
					add_data(&page, "</code></pre>");
435
					add_data(&page, "</code></pre>");
388
				}
436
				}
389
			} else {
437
			} else {
390
				add_data(&page, "Repository does not exist.\n");
438
				add_data(&page, "Repository does not exist.\n");
391
			}
439
			}
Line 480... Line 528...
480
	add_data(&buffer, "	font-weight: bold;\n");
528
	add_data(&buffer, "	font-weight: bold;\n");
481
	add_data(&buffer, "}\n");
529
	add_data(&buffer, "}\n");
482
	add_data(&buffer, "pre {\n");
530
	add_data(&buffer, "pre {\n");
483
	add_data(&buffer, "	background-color: #dddddd;\n");
531
	add_data(&buffer, "	background-color: #dddddd;\n");
484
	add_data(&buffer, "	border: solid 2px #bbbbbb;\n");
532
	add_data(&buffer, "	border: solid 2px #bbbbbb;\n");
-
 
533
	add_data(&buffer, "	padding: 8px;\n");
-
 
534
	add_data(&buffer, "	overflow: scroll;\n");
485
	add_data(&buffer, "}\n");
535
	add_data(&buffer, "}\n");
486
	add_data(&buffer, "#index {\n");
536
	add_data(&buffer, "#index {\n");
487
	add_data(&buffer, "	list-style: none;\n");
537
	add_data(&buffer, "	list-style: none;\n");
488
	add_data(&buffer, "	line-height: normal;\n");
538
	add_data(&buffer, "	line-height: normal;\n");
489
	add_data(&buffer, "	margin: auto 0;\n");
539
	add_data(&buffer, "	margin: auto 0;\n");