Subversion Repositories Tewi

Rev

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

Rev 255 Rev 257
Line 1... Line 1...
1
/* $Id: config.c 255 2024-10-04 04:08:58Z nishi $ */
1
/* $Id: config.c 257 2024-10-04 05:34:27Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_config.h"
5
#include "tw_config.h"
6
#include "tw_module.h"
6
#include "tw_module.h"
7
 
7
 
8
#include <stdio.h>
8
#include <stdio.h>
9
#include <stdint.h>
9
#include <stdint.h>
10
#include <stdlib.h>
10
#include <stdlib.h>
11
#include <string.h>
11
#include <string.h>
-
 
12
#include <sys/stat.h>
12
 
13
 
13
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
14
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
14
#include <unistd.h>
15
#include <unistd.h>
15
#endif
16
#endif
16
 
17
 
Line 402... Line 403...
402
						} else {
403
						} else {
403
							struct tw_mime_entry* e = &current->mimes[current->mime_count++];
404
							struct tw_mime_entry* e = &current->mimes[current->mime_count++];
404
							e->ext = cm_strdup(r[1]);
405
							e->ext = cm_strdup(r[1]);
405
							e->mime = cm_strdup(r[2]);
406
							e->mime = cm_strdup(r[2]);
406
						}
407
						}
-
 
408
					} else if(cm_strcaseequ(r[0], "MIMEFile")) {
-
 
409
						if(r[1] == NULL) {
-
 
410
							cm_log("Config", "Missing path at line %d", ln);
-
 
411
							stop = 1;
-
 
412
						} else {
-
 
413
							FILE* mimefile = fopen(r[1], "r");
-
 
414
							if(mimefile == NULL) {
-
 
415
								cm_log("Config", "Could not load the file at line %d", ln);
-
 
416
								stop = 1;
-
 
417
							} else {
-
 
418
								char* line = malloc(1);
-
 
419
								int i;
-
 
420
								struct stat st;
-
 
421
								char* buf;
-
 
422
								int incr = 0;
-
 
423
								stat(r[1], &st);
-
 
424
 
-
 
425
								buf = malloc(st.st_size + 1);
-
 
426
								fread(buf, st.st_size, 1, mimefile);
-
 
427
 
-
 
428
								for(i = 0;; i++) {
-
 
429
									if(buf[i] == '\n' || buf[i] == 0) {
-
 
430
										char oldc = buf[i];
-
 
431
										char* line;
-
 
432
										buf[i] = 0;
-
 
433
 
-
 
434
										line = buf + incr;
-
 
435
 
-
 
436
										if(strlen(line) > 0 && line[0] != '#') {
-
 
437
											int j;
-
 
438
											for(j = 0; line[j] != 0; j++) {
-
 
439
												if(line[j] == ' ' || line[j] == '\t') {
-
 
440
													line[j] = 0;
-
 
441
													j++;
-
 
442
													for(; line[j] != 0; j++) {
-
 
443
														if(line[j] != ' ' && line[j] != '\t') {
-
 
444
															char* name = line;
-
 
445
															char* mimes = line + j;
-
 
446
															int k = 0;
-
 
447
															int incr2 = 0;
-
 
448
															for(k = 0;; k++) {
-
 
449
																if(mimes[k] == ' ' || mimes[k] == 0) {
-
 
450
																	char oldc2 = mimes[k];
-
 
451
																	struct tw_mime_entry* e;
-
 
452
																	mimes[k] = 0;
-
 
453
 
-
 
454
																	e = &current->mimes[current->mime_count++];
-
 
455
																	e->ext = cm_strcat(".", mimes + incr2);
-
 
456
																	e->mime = cm_strdup(name);
-
 
457
																	if(current->mime_count == MAX_MIME) {
-
 
458
																		cm_log("Config", "Too many MIME types, cannot handle");
-
 
459
																		stop = 1;
-
 
460
																		break;
-
 
461
																	}
-
 
462
 
-
 
463
																	incr2 = k + 1;
-
 
464
																	if(oldc2 == 0) break;
-
 
465
																}
-
 
466
															}
-
 
467
															break;
-
 
468
														}
-
 
469
													}
-
 
470
													break;
-
 
471
												}
-
 
472
												if(stop) break;
-
 
473
											}
-
 
474
										}
-
 
475
 
-
 
476
										incr = i + 1;
-
 
477
										if(oldc == 0) break;
-
 
478
									}
-
 
479
								}
-
 
480
 
-
 
481
								free(buf);
-
 
482
 
-
 
483
								fclose(mimefile);
-
 
484
							}
-
 
485
						}
407
					} else if(cm_strcaseequ(r[0], "Icon")) {
486
					} else if(cm_strcaseequ(r[0], "Icon")) {
408
						if(r[1] == NULL) {
487
						if(r[1] == NULL) {
409
							cm_log("Config", "Missing MIME at line %d", ln);
488
							cm_log("Config", "Missing MIME at line %d", ln);
410
							stop = 1;
489
							stop = 1;
411
						} else if(r[2] == NULL) {
490
						} else if(r[2] == NULL) {