Browse code

fix last minute change

git-svn: trunk@850

Trog authored on 2004/09/13 19:56:26
Showing 1 changed files
... ...
@@ -362,7 +362,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
362 362
 	tag_arguments_t tag_args;
363 363
 	quoted_state quoted;
364 364
 	unsigned long length;
365
-	file_buff_t file_buff_o1, file_buff_o2,  file_buff_script;
365
+	file_buff_t *file_buff_o1, *file_buff_o2, *file_buff_script;
366 366
 	
367 367
 	if (!m_area) {
368 368
 		if (fd < 0) {
... ...
@@ -382,36 +382,49 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
382 382
 	}
383 383
 	
384 384
 	if (dirname) {
385
+		file_buff_o1 = (file_buff_t *) cli_malloc(sizeof(file_buff_t));
386
+		file_buff_o2 = (file_buff_t *) cli_malloc(sizeof(file_buff_t));
387
+		file_buff_script = (file_buff_t *) cli_malloc(sizeof(file_buff_t));
388
+		
385 389
 		snprintf(filename, 1024, "%s/comment.html", dirname);
386
-		file_buff_o1.fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
387
-		if (!file_buff_o1.fd) {
390
+		file_buff_o1->fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
391
+		if (!file_buff_o1->fd) {
388 392
 			cli_dbgmsg("open failed: %s\n", filename);
389 393
 			fclose(stream_in);
394
+			free(file_buff_o1);
395
+			free(file_buff_o2);
396
+			free(file_buff_script);
390 397
 			return FALSE;
391 398
 		}
392 399
 
393 400
 		snprintf(filename, 1024, "%s/nocomment.html", dirname);
394
-		file_buff_o2.fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
395
-		if (!file_buff_o2.fd) {
401
+		file_buff_o2->fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
402
+		if (!file_buff_o2->fd) {
396 403
 			cli_dbgmsg("open failed: %s\n", filename);
397
-			close(file_buff_o1.fd);
404
+			close(file_buff_o1->fd);
398 405
 			fclose(stream_in);
406
+			free(file_buff_o1);
407
+			free(file_buff_o2);
408
+			free(file_buff_script);
399 409
 			return FALSE;
400 410
 		}
401 411
 
402 412
 		snprintf(filename, 1024, "%s/script.html", dirname);
403
-		file_buff_script.fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
404
-		if (!file_buff_script.fd) {
413
+		file_buff_script->fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
414
+		if (!file_buff_script->fd) {
405 415
 			cli_dbgmsg("open failed: %s\n", filename);
406
-			close(file_buff_o1.fd);
407
-			close(file_buff_o2.fd);
416
+			close(file_buff_o1->fd);
417
+			close(file_buff_o2->fd);
408 418
 			fclose(stream_in);
419
+			free(file_buff_o1);
420
+			free(file_buff_o2);
421
+			free(file_buff_script);
409 422
 			return FALSE;
410 423
 		}
411 424
 
412
-		file_buff_o1.length = 0;
413
-		file_buff_o2.length = 0;
414
-		file_buff_script.length = 0;
425
+		file_buff_o1->length = 0;
426
+		file_buff_o2->length = 0;
427
+		file_buff_script->length = 0;
415 428
 	} else {
416 429
 		file_buff_o1 = NULL;
417 430
 		file_buff_o2 = NULL;
... ...
@@ -430,11 +443,11 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
430 430
 		while (*ptr) {
431 431
 			if (*ptr == '\n') {
432 432
 				if (state == HTML_COMMENT) {
433
-					html_output_c(&file_buff_o1, NULL, ' ');
433
+					html_output_c(file_buff_o1, NULL, ' ');
434 434
 				} else if ((state != HTML_SKIP_WS) && 
435 435
 						(state != HTML_TRIM_WS) &&
436 436
 						(state != HTML_PROCESS_TAG)) {
437
-					html_output_c(&file_buff_o1, &file_buff_o2, ' ');
437
+					html_output_c(file_buff_o1, file_buff_o2, ' ');
438 438
 				}
439 439
 				ptr++;
440 440
 				continue;
... ...
@@ -467,16 +480,16 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
467 467
 				if (isspace(*ptr)) {
468 468
 					ptr++;
469 469
 				} else {
470
-					html_output_c(&file_buff_o1, &file_buff_o2, ' ');
470
+					html_output_c(file_buff_o1, file_buff_o2, ' ');
471 471
 					state = next_state;
472 472
 					next_state = HTML_BAD_STATE;
473 473
 				}
474 474
 				break;
475 475
 			case HTML_NORM:
476 476
 				if (*ptr == '<') {
477
-					html_output_c(&file_buff_o1, &file_buff_o2, '<');
477
+					html_output_c(file_buff_o1, file_buff_o2, '<');
478 478
 					if (in_script) {
479
-						html_output_c(&file_buff_script, NULL, '<');
479
+						html_output_c(file_buff_script, NULL, '<');
480 480
 					}
481 481
 					ptr++;
482 482
 					state = HTML_SKIP_WS;
... ...
@@ -490,9 +503,9 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
490 490
 					next_state = HTML_NORM;
491 491
 					ptr++;
492 492
 				} else {
493
-					html_output_c(&file_buff_o1, &file_buff_o2, tolower(*ptr));
493
+					html_output_c(file_buff_o1, file_buff_o2, tolower(*ptr));
494 494
 					if (in_script) {
495
-						html_output_c(&file_buff_script, NULL, tolower(*ptr));
495
+						html_output_c(file_buff_script, NULL, tolower(*ptr));
496 496
 					}
497 497
 					ptr++;
498 498
 				}
... ...
@@ -500,30 +513,30 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
500 500
 			case HTML_TAG:
501 501
 				if ((tag_length == 0) && (*ptr == '!')) {
502 502
 					/* Comment */
503
-					html_output_c(&file_buff_o1, NULL, '!');
503
+					html_output_c(file_buff_o1, NULL, '!');
504 504
 					if (in_script) {
505
-						html_output_c(&file_buff_script, NULL, '!');
505
+						html_output_c(file_buff_script, NULL, '!');
506 506
 					}
507 507
 					/* Need to rewind in the no-comment output stream */
508
-					if (file_buff_o2.length > 0) {
509
-						file_buff_o2.length--;
508
+					if (file_buff_o2->length > 0) {
509
+						file_buff_o2->length--;
510 510
 					}
511 511
 					state = HTML_COMMENT;
512 512
 					next_state = HTML_BAD_STATE;
513 513
 					ptr++;
514 514
 				} else if (*ptr == '>') {
515
-					html_output_c(&file_buff_o1, &file_buff_o2, '>');
515
+					html_output_c(file_buff_o1, file_buff_o2, '>');
516 516
 					if (in_script) {
517
-						html_output_c(&file_buff_script, NULL, '>');
517
+						html_output_c(file_buff_script, NULL, '>');
518 518
 					}
519 519
 					ptr++;
520 520
 					tag[tag_length] = '\0';
521 521
 					state = HTML_SKIP_WS;
522 522
 					next_state = HTML_PROCESS_TAG;
523 523
 				} else if (!isspace(*ptr)) {
524
-					html_output_c(&file_buff_o1, &file_buff_o2, tolower(*ptr));
524
+					html_output_c(file_buff_o1, file_buff_o2, tolower(*ptr));
525 525
 					if (in_script) {
526
-						html_output_c(&file_buff_script, NULL, tolower(*ptr));
526
+						html_output_c(file_buff_script, NULL, tolower(*ptr));
527 527
 					}
528 528
 					if (tag_length < HTML_STR_LENGTH) {
529 529
 						tag[tag_length++] = tolower(*ptr);
... ...
@@ -538,7 +551,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
538 538
 				break;
539 539
 			case HTML_TAG_ARG:
540 540
 				if (*ptr == '=') {
541
-					html_output_c(&file_buff_o1, &file_buff_o2, '=');
541
+					html_output_c(file_buff_o1, file_buff_o2, '=');
542 542
 					tag_arg[tag_arg_length] = '\0';
543 543
 					ptr++;
544 544
 					state = HTML_SKIP_WS;
... ...
@@ -552,7 +565,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
552 552
 					state = HTML_SKIP_WS;
553 553
 					next_state = HTML_TAG_ARG_EQUAL;
554 554
 				} else if (*ptr == '>') {
555
-					html_output_c(&file_buff_o1, &file_buff_o2, '>');
555
+					html_output_c(file_buff_o1, file_buff_o2, '>');
556 556
 					if (tag_arg_length > 0) {
557 557
 						tag_arg[tag_arg_length] = '\0';
558 558
 						html_tag_arg_add(&tag_args, tag_arg, NULL);
... ...
@@ -563,9 +576,9 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
563 563
 				} else {
564 564
 					if (tag_arg_length == 0) {
565 565
 						/* Start of new tag - add space */
566
-						html_output_c(&file_buff_o1, &file_buff_o2,' ');
566
+						html_output_c(file_buff_o1, file_buff_o2,' ');
567 567
 					}
568
-					html_output_c(&file_buff_o1, &file_buff_o2, tolower(*ptr));
568
+					html_output_c(file_buff_o1, file_buff_o2, tolower(*ptr));
569 569
 					if (tag_arg_length < HTML_STR_LENGTH) {
570 570
 						tag_arg[tag_arg_length++] = tolower(*ptr);
571 571
 					}
... ...
@@ -574,7 +587,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
574 574
 				break;
575 575
 			case HTML_TAG_ARG_EQUAL:
576 576
 				if (*ptr == '=') {
577
-					html_output_c(&file_buff_o1, &file_buff_o2, '=');
577
+					html_output_c(file_buff_o1, file_buff_o2, '=');
578 578
 					ptr++;
579 579
 					state = HTML_SKIP_WS;
580 580
 					escape = FALSE;
... ...
@@ -599,14 +612,14 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
599 599
 				} else if (*ptr == '\'') {
600 600
 					if (tag_val_length == 0) {
601 601
 						quoted = SINGLE_QUOTED;
602
-						html_output_c(&file_buff_o1, &file_buff_o2, '"');
602
+						html_output_c(file_buff_o1, file_buff_o2, '"');
603 603
 						if (tag_val_length < HTML_STR_LENGTH) {
604 604
 							tag_val[tag_val_length++] = '"';
605 605
 						}
606 606
 						ptr++;
607 607
 					} else {
608 608
 						if (!escape && (quoted==SINGLE_QUOTED)) {
609
-							html_output_c(&file_buff_o1, &file_buff_o2, '"');
609
+							html_output_c(file_buff_o1, file_buff_o2, '"');
610 610
 							if (tag_val_length < HTML_STR_LENGTH) {
611 611
 								tag_val[tag_val_length++] = '"';
612 612
 							}
... ...
@@ -617,7 +630,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
617 617
 							tag_arg_length=0;
618 618
 							next_state = HTML_TAG_ARG;
619 619
 						} else {
620
-							html_output_c(&file_buff_o1, &file_buff_o2, '"');
620
+							html_output_c(file_buff_o1, file_buff_o2, '"');
621 621
 							if (tag_val_length < HTML_STR_LENGTH) {
622 622
 								tag_val[tag_val_length++] = '"';
623 623
 							}
... ...
@@ -627,14 +640,14 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
627 627
 				} else if (*ptr == '"') {
628 628
 					if (tag_val_length == 0) {
629 629
 						quoted = DOUBLE_QUOTED;
630
-						html_output_c(&file_buff_o1, &file_buff_o2, '"');
630
+						html_output_c(file_buff_o1, file_buff_o2, '"');
631 631
 						if (tag_val_length < HTML_STR_LENGTH) {
632 632
 							tag_val[tag_val_length++] = '"';
633 633
 						}
634 634
 						ptr++;
635 635
 					} else {
636 636
 						if (!escape && (quoted==DOUBLE_QUOTED)) {					
637
-							html_output_c(&file_buff_o1, &file_buff_o2, '"');
637
+							html_output_c(file_buff_o1, file_buff_o2, '"');
638 638
 							if (tag_val_length < HTML_STR_LENGTH) {
639 639
 								tag_val[tag_val_length++] = '"';
640 640
 							}
... ...
@@ -645,7 +658,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
645 645
 							tag_arg_length=0;
646 646
 							next_state = HTML_TAG_ARG;
647 647
 						} else {
648
-							html_output_c(&file_buff_o1, &file_buff_o2, '"');
648
+							html_output_c(file_buff_o1, file_buff_o2, '"');
649 649
 							if (tag_val_length < HTML_STR_LENGTH) {
650 650
 								tag_val[tag_val_length++] = '"';
651 651
 							}
... ...
@@ -660,7 +673,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
660 660
 						tag_arg_length=0;
661 661
 						next_state = HTML_TAG_ARG;
662 662
 					} else {
663
-						html_output_c(&file_buff_o1, &file_buff_o2, *ptr);
663
+						html_output_c(file_buff_o1, file_buff_o2, *ptr);
664 664
 						if (tag_val_length < HTML_STR_LENGTH) {
665 665
 							if (isspace(*ptr)) {
666 666
 								tag_val[tag_val_length++] = ' ';
... ...
@@ -675,7 +688,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
675 675
 						ptr++;
676 676
 					}
677 677
 				} else {
678
-					html_output_c(&file_buff_o1, &file_buff_o2, tolower(*ptr));
678
+					html_output_c(file_buff_o1, file_buff_o2, tolower(*ptr));
679 679
 					if (tag_val_length < HTML_STR_LENGTH) {
680 680
 						tag_val[tag_val_length++] = tolower(*ptr);
681 681
 					}
... ...
@@ -689,9 +702,9 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
689 689
 				}
690 690
 				break;
691 691
 			case HTML_COMMENT:
692
-				html_output_c(&file_buff_o1, NULL, tolower(*ptr));
692
+				html_output_c(file_buff_o1, NULL, tolower(*ptr));
693 693
 				if (in_script) {
694
-					html_output_c(&file_buff_script, NULL, tolower(*ptr));
694
+					html_output_c(file_buff_script, NULL, tolower(*ptr));
695 695
 				}
696 696
 				if (*ptr == '>') {
697 697
 					state = HTML_SKIP_WS;
... ...
@@ -710,7 +723,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
710 710
 					next_state = HTML_NORM;
711 711
 					if (strcmp(tag, "/script") == 0) {
712 712
 						in_script=FALSE;
713
-						html_output_c(&file_buff_script, NULL, '\n');
713
+						html_output_c(file_buff_script, NULL, '\n');
714 714
 					}
715 715
 				} else if (strcmp(tag, "script") == 0) {
716 716
 					arg_value = html_tag_arg_value(&tag_args, "language");
... ...
@@ -725,7 +738,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
725 725
 					} else {
726 726
 						in_script = TRUE;
727 727
 					}
728
-					html_output_tag(&file_buff_script, tag, &tag_args);
728
+					html_output_tag(file_buff_script, tag, &tag_args);
729 729
 				} else if (hrefs && strcmp(tag, "a") == 0) {
730 730
 					arg_value = html_tag_arg_value(&tag_args, "href");
731 731
 					if (strlen(arg_value) > 0) {
... ...
@@ -741,7 +754,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
741 741
 					state = HTML_CHAR_REF_DECODE;
742 742
 					ptr++;
743 743
 				} else {
744
-					html_output_c(&file_buff_o1, &file_buff_o2, '&');
744
+					html_output_c(file_buff_o1, file_buff_o2, '&');
745 745
 					state = next_state;
746 746
 					next_state = HTML_BAD_STATE;
747 747
 				}
... ...
@@ -751,7 +764,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
751 751
 					hex=TRUE;
752 752
 					ptr++;
753 753
 				} else if (*ptr == ';') {
754
-					html_output_c(&file_buff_o1, &file_buff_o2, value);
754
+					html_output_c(file_buff_o1, file_buff_o2, value);
755 755
 					state = next_state;
756 756
 					next_state = HTML_BAD_STATE;
757 757
 					ptr++;
... ...
@@ -768,7 +781,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
768 768
 					}
769 769
 					ptr++;
770 770
 				} else {
771
-					html_output_c(&file_buff_o1, &file_buff_o2, value);
771
+					html_output_c(file_buff_o1, file_buff_o2, value);
772 772
 					state = next_state;
773 773
 					next_state = HTML_BAD_STATE;
774 774
 				}
... ...
@@ -780,8 +793,8 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
780 780
 					state = HTML_JSDECODE_LENGTH;
781 781
 					next_state = HTML_BAD_STATE;
782 782
 				} else {
783
-					html_output_c(&file_buff_o1, &file_buff_o2, tolower(*ptr));
784
-					html_output_c(&file_buff_script, NULL, tolower(*ptr));
783
+					html_output_c(file_buff_o1, file_buff_o2, tolower(*ptr));
784
+					html_output_c(file_buff_script, NULL, tolower(*ptr));
785 785
 					ptr++;
786 786
 				}
787 787
 				break;
... ...
@@ -806,7 +819,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
806 806
 				break;
807 807
 			case HTML_JSDECODE_DECRYPT:
808 808
 				if (length == 0) {
809
-					html_output_str(&file_buff_script, "</script>\n", 10);
809
+					html_output_str(file_buff_script, "</script>\n", 10);
810 810
 					length = 12;
811 811
 					state = HTML_SKIP_LENGTH;
812 812
 					next_state = HTML_NORM;
... ...
@@ -823,29 +836,29 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
823 823
 							ptr--;
824 824
 							break;
825 825
 						case 0x21:
826
-							html_output_c(&file_buff_o1, &file_buff_o2, 0x3c);
827
-							html_output_c(&file_buff_script, NULL, 0x3c);
826
+							html_output_c(file_buff_o1, file_buff_o2, 0x3c);
827
+							html_output_c(file_buff_script, NULL, 0x3c);
828 828
 							break;
829 829
 						case 0x23:
830
-							html_output_c(&file_buff_o1, &file_buff_o2, 0x0d);
831
-							html_output_c(&file_buff_script, NULL, 0x0d);
830
+							html_output_c(file_buff_o1, file_buff_o2, 0x0d);
831
+							html_output_c(file_buff_script, NULL, 0x0d);
832 832
 							break;
833 833
 						case 0x24:
834
-							html_output_c(&file_buff_o1, &file_buff_o2, 0x40);
835
-							html_output_c(&file_buff_script, NULL, 0x40);
834
+							html_output_c(file_buff_o1, file_buff_o2, 0x40);
835
+							html_output_c(file_buff_script, NULL, 0x40);
836 836
 							break;				
837 837
 						case 0x26:
838
-							html_output_c(&file_buff_o1, &file_buff_o2, 0x0a);
839
-							html_output_c(&file_buff_script, NULL, 0x0a);
838
+							html_output_c(file_buff_o1, file_buff_o2, 0x0a);
839
+							html_output_c(file_buff_script, NULL, 0x0a);
840 840
 							break;
841 841
 						case 0x2a:
842
-							html_output_c(&file_buff_o1, &file_buff_o2, 0x3e);
843
-							html_output_c(&file_buff_script, NULL, 0x3e);
842
+							html_output_c(file_buff_o1, file_buff_o2, 0x3e);
843
+							html_output_c(file_buff_script, NULL, 0x3e);
844 844
 							break;
845 845
 						}
846 846
 					} else {
847
-						html_output_c(&file_buff_o1, &file_buff_o2, value);
848
-						html_output_c(&file_buff_script, NULL, tolower(value));
847
+						html_output_c(file_buff_o1, file_buff_o2, value);
848
+						html_output_c(file_buff_script, NULL, tolower(value));
849 849
 					}
850 850
 				}
851 851
 				table_pos = (table_pos + 1) % 64;
... ...
@@ -864,12 +877,15 @@ abort:
864 864
 	if (!m_area) {
865 865
 		fclose(stream_in);
866 866
 	}
867
-	html_output_flush(&file_buff_o1);
868
-	html_output_flush(&file_buff_o2);
869
-	html_output_flush(&file_buff_script);
870
-	close(file_buff_o1.fd);
871
-	close(file_buff_o2.fd);
872
-	close(file_buff_script.fd);
867
+	html_output_flush(file_buff_o1);
868
+	html_output_flush(file_buff_o2);
869
+	html_output_flush(file_buff_script);
870
+	close(file_buff_o1->fd);
871
+	close(file_buff_o2->fd);
872
+	close(file_buff_script->fd);
873
+	free(file_buff_o1);
874
+	free(file_buff_o2);
875
+	free(file_buff_script);
873 876
 	return retval;
874 877
 }
875 878