From: nishi Date: Sun, 5 May 2024 04:26:03 +0000 (+0000) Subject: some progress X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=991271de9bc03fd52e2bac8732ae7e19c9ca83b9;p=clover.git some progress git-svn-id: file:///raid/svn-main/nishi-clover/trunk@3 cc13bd98-b292-b64a-ad22-c0789b689ca7 --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..53f287c --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +--- +# $Id$ +Language: Cpp +UseTab: Always +TabWidth: 8 +IndentWidth: 8 +PointerAlignment: Left +ColumnLimit: 1024 +AllowShortIfStatementsOnASingleLine: Always +AllowShortBlocksOnASingleLine: Never +AllowShortLoopsOnASingleLine: true +SpaceBeforeParens: Never diff --git a/HEADER b/HEADER new file mode 100644 index 0000000..19b6c52 --- /dev/null +++ b/HEADER @@ -0,0 +1 @@ +HTML 2.0 compliant static site generator diff --git a/Makefile b/Makefile index 117d9a3..f59851e 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LIBS = CLOVER_OBJS = clover.o -.PHONY: all +.PHONY: all clean format replace all: ./clover @@ -18,3 +18,19 @@ all: ./clover .c.o: $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f *.o ./clover + +FILES = `find . -name "*.c" -or -name "*.h"` + +replace: + for i in $(FILES); do \ + echo -n "$$i ... "; \ + perl replace.pl < $$i > $$i.new; \ + mv $$i.new $$i; \ + echo "done"; \ + done + +format: + clang-format -i $(FILES) diff --git a/clover.c b/clover.c index 4366fc3..72bb1f8 100644 --- a/clover.c +++ b/clover.c @@ -1,18 +1,96 @@ /* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#include #include #include +#include +#include +#include #define CLOVER_VERSION "0.00" -int parse_config(const char* path){ +char* concat_str(const char* str1, const char* str2) { + char* r = malloc(strlen(str1) + strlen(str2) + 1); + memcpy(r, str1, strlen(str1)); + memcpy(r + strlen(str1), str2, strlen(str2)); + r[strlen(str1) + strlen(str2)] = 0; + return r; +} + +int parse_config(const char* path) { FILE* f = fopen(path, "r"); - if(f == NULL) return 1; + if(f == NULL) { + fprintf(stderr, "%s: could not open the file\n", path); + return 1; + } + char* bf = malloc(2); + bf[1] = 0; + char* str = malloc(1); + str[0] = 0; + while(1) { + fread(bf, 1, 1, f); + if(feof(f)) break; + if(bf[0] == '\n') { + int i; + bool found = false; + for(i = 0; str[i] != 0; i++) { + if(str[i] == ' ') { + for(; str[i] != 0 && (str[i] == ' ' || str[i] == '\t'); i++) str[i] = 0; + found = true; + break; + } + } + if(strcmp(str, "output") == 0) { + if(found) { + mkdir(str + i, 0775); + chdir(str + i); + } + } + free(str); + str = malloc(1); + str[0] = 0; + } else if(bf[0] != '\r') { + char* tmp = str; + str = concat_str(tmp, bf); + free(tmp); + } + } + free(str); + free(bf); + fclose(f); + return 0; } -int main(int argc, char** argv){ - if(argv[1] == NULL){ +int main(int argc, char** argv) { + if(argv[1] == NULL) { return parse_config("clover.conf"); - }else{ + } else { return parse_config(argv[1]); } } diff --git a/replace.pl b/replace.pl new file mode 100755 index 0000000..98f6aab --- /dev/null +++ b/replace.pl @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +# $Id$ +# To put LICENSE into the source code + +use IO::Handle; + +my $str = ""; +while(){ + $str = $str . $_; +} + +my $rep = 74; + +my $repl = "/* " . ("-" x $rep) . " */\n"; + +my $io = IO::Handle->new(); + +if(open $io, '<', "HEADER"){ + my $len = 0; + while(<$io>){ + my @list = $_ =~ /.{1,$rep}/g; + for my $s (@list){ + if(length($s) > $len){ + $len = length($s); + } + } + } + $io->close; + open $io, '<', "HEADER"; + while(<$io>){ + my @list = $_ =~ /.{1,$rep}/g; + for my $s (@list){ + $repl = $repl . "/* " . (" " x ($rep - $len - 1)) . "$s" . (" " x ($len - length($s) + 1)) . " */\n"; + } + } + $repl = $repl . "/* " . ("-" x $rep) . " */\n"; +} + +$io = IO::Handle->new(); + +open $io, '<', "LICENSE" or die "$!"; + +while(<$io>){ + my @list = $_ =~ /.{1,$rep}/g; + for my $s (@list){ + $repl = $repl . "/* $s" . (" " x ($rep - length($s))) . " */\n"; + } +} + +$io->close; + +$repl = $repl . "/* " . ("-" x $rep) . " */\n"; + +$str =~ s/\/\* --- START LICENSE --- \*\/\n(.+\n)?\/\* --- END LICENSE --- \*\//\/\* --- START LICENSE --- \*\/\n$repl\/\* --- END LICENSE --- \*\//gs; +print $str;