Subversion Repositories Keine

Rev

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

Rev 6 Rev 7
Line 1... Line 1...
1
/* $Id: cgi.c 6 2024-09-11 15:45:32Z nishi $ */
1
/* $Id: cgi.c 7 2024-09-11 15:46:04Z nishi $ */
2
 
2
 
3
#include "../config.h"
3
#include "../config.h"
4
 
4
 
5
#include "kn_cgi.h"
5
#include "kn_cgi.h"
6
 
6
 
Line 48... Line 48...
48
			if(stat(path, &s) == 0) {
48
			if(stat(path, &s) == 0) {
49
				if(S_ISDIR(s.st_mode)) {
49
				if(S_ISDIR(s.st_mode)) {
50
					manpage_scan(path);
50
					manpage_scan(path);
51
				} else {
51
				} else {
52
					char* name = kn_strdup(nl[i]->d_name);
52
					char* name = kn_strdup(nl[i]->d_name);
53
					char* desc = kn_strdup("dadsandasndasdsadmadsadmsmdsmdmdksmdkamdkmdksmdsmdmskdmdmsakdsdmsakdmskdmsdmsadkmsakdmdsdmsdkamdkmdkamdksmdksamkdsmdkmadmsakdmsakdmmdakmdsm");
53
					char* desc = kn_strdup("<No description detected>");
54
 
54
 
55
					int incr = 0;
55
					int incr = 0;
56
					FILE* f = fopen(path, "r");
56
					FILE* f = fopen(path, "r");
57
					char* b = malloc(s.st_size + 1);
57
					char* b = malloc(s.st_size + 1);
58
					b[s.st_size] = 0;
58
					b[s.st_size] = 0;
59
					fread(b, s.st_size, 1, f);
59
					fread(b, s.st_size, 1, f);
60
					fclose(f);
60
					fclose(f);
61
 
61
 
62
					int j;
62
					int j;
63
					for(j = 0;; j++){
63
					for(j = 0;; j++) {
64
						if(b[j] == '\n' || b[j] == 0){
64
						if(b[j] == '\n' || b[j] == 0) {
65
							char* line = malloc(j - incr + 1);
65
							char* line = malloc(j - incr + 1);
66
							line[j - incr] = 0;
66
							line[j - incr] = 0;
67
							memcpy(line, b + incr, j - incr);
67
							memcpy(line, b + incr, j - incr);
68
 
68
 
69
							int k;
69
							int k;
70
							for(k = 0; line[k] != 0 && k < 4; k++){
70
							for(k = 0; line[k] != 0 && k < 4; k++) {
71
								if(line[k] == ' '){
71
								if(line[k] == ' ') {
72
									line[k] = 0;
72
									line[k] = 0;
73
									if(strcasecmp(line, ".Nd") == 0){
73
									if(strcasecmp(line, ".Nd") == 0) {
74
										free(desc);
74
										free(desc);
75
										desc = kn_strdup(line + k + 1);
75
										desc = kn_strdup(line + k + 1);
76
										int l;
76
										int l;
77
										for(l = 0; desc[l] != 0; l++){
77
										for(l = 0; desc[l] != 0; l++) {
78
											if(desc[l] == '\\'){
78
											if(desc[l] == '\\') {
79
												l++;
79
												l++;
80
												if(desc[l] == '"'){
80
												if(desc[l] == '"') {
81
													l--;
81
													l--;
82
													desc[l] = 0;
82
													desc[l] = 0;
83
													break;
83
													break;
84
												}
84
												}
85
											}
85
											}
Line 95... Line 95...
95
						}
95
						}
96
					}
96
					}
97
 
97
 
98
					free(b);
98
					free(b);
99
 
99
 
100
					if(strlen(desc) > 70){
100
					if(strlen(desc) > 70) {
101
						desc[70] = 0;
101
						desc[70] = 0;
102
						desc[69] = '.';
102
						desc[69] = '.';
103
						desc[68] = '.';
103
						desc[68] = '.';
104
						desc[67] = '.';
104
						desc[67] = '.';
105
					}
105
					}
Line 122... Line 122...
122
 
122
 
123
void list_manpages(void) {
123
void list_manpages(void) {
124
#ifdef MANPAGE_DIRS
124
#ifdef MANPAGE_DIRS
125
	int i;
125
	int i;
126
	const char* dirs[] = MANPAGE_DIRS;
126
	const char* dirs[] = MANPAGE_DIRS;
127
	for(i = 0; i < sizeof(dirs) / sizeof(*dirs); i++){
127
	for(i = 0; i < sizeof(dirs) / sizeof(*dirs); i++) {
128
		manpage_scan(dirs[i]);
128
		manpage_scan(dirs[i]);
129
	}
129
	}
130
#else
130
#else
131
	manpage_scan(MANPAGE_DIR);
131
	manpage_scan(MANPAGE_DIR);
132
#endif
132
#endif
Line 183... Line 183...
183
	} else {
183
	} else {
184
		bool cond = false;
184
		bool cond = false;
185
#ifdef MANPAGE_DIRS
185
#ifdef MANPAGE_DIRS
186
		int i;
186
		int i;
187
		const char* dirs[] = MANPAGE_DIRS;
187
		const char* dirs[] = MANPAGE_DIRS;
188
		for(i = 0; i < sizeof(dirs) / sizeof(*dirs); i++){
188
		for(i = 0; i < sizeof(dirs) / sizeof(*dirs); i++) {
189
			cond = (path = kn_find(dirs[i], kn_get_query("page"))) != NULL;
189
			cond = (path = kn_find(dirs[i], kn_get_query("page"))) != NULL;
190
			if(cond) break;
190
			if(cond) break;
191
		}
191
		}
192
#else
192
#else
193
		cond = (path = kn_find(MANPAGE_DIR, kn_get_query("page"))) != NULL;
193
		cond = (path = kn_find(MANPAGE_DIR, kn_get_query("page"))) != NULL;