/* $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 <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
#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]);
}
}
--- /dev/null
+#!/usr/bin/env perl
+# $Id$
+# To put LICENSE into the source code
+
+use IO::Handle;
+
+my $str = "";
+while(<STDIN>){
+ $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;