wip: large changes

This commit is contained in:
2025-11-04 13:58:37 -05:00
parent 684cf7fb53
commit b4665675ad
24 changed files with 646 additions and 487 deletions

View File

@@ -1,38 +1,4 @@
/*
* yait.licence - Contains licence source texts
*
*
* LICENSE: BSD-3-Clause
*
* Copyright (c) 2025 GCK
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software 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, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// SPDX-License-Identifier: BSD-3-Clause
#ifndef LICENCES_H
#define LICENCES_H
@@ -782,5 +748,3 @@ For more information, please refer to <https://unlicense.org/>\
";
#endif
/* end of licence.h */

62
src/shell.c Normal file
View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: BSD-3-Clause
#include <errno.h>
#include <lib/err.h>
#include <lib/fs.h>
#include <sys/stat.h>
int write_shell(char *package, char *license, int year, char *author, char *m)
{
fs_write(package, "\
#!/bin/sh\n\
# SPDX-License-Identifier: %s\n\
#\n\
# %s\n\
\n\
me=$0\n\
scriptversion=\"1.0.0\"\n\
\n\
version=\"$me $scriptversion\n\
\n\
Copyright (C) %d %s\n\
This is free software; you are free to change and redistribute it.\n\
There is NO WARRANTY, to the textent permitted by law.\"\n\
\n\
usage=\"\\\n\
Usage: $me [OPTION]...\n\
%s\n\
\n\
Options:\n\
\n\
--help print this help and exit\n\
--version output version information\"\n\
\n\
while [ $# -gt 0 ]; do\n\
case $1 in\n\
--help) echo \"$usage\"; exit 0;;\n\
--version) echo \"$version\"; exit 0;;\n\
-*)\n\
echo \"$0: Unknwon option '$1'.\" >&2\n\
echo \"$0: Try '--help' for more information.\" >&2\n\
exit 1 ;;\n\
esac\n\
shift\n\
done\n\
\n\
echo \"$0: done.\"\n\
\n\
# End: %s\
",
license, m, year, author, m, package);
struct stat st;
if (stat(package, &st) != 0) {
fatalfa(errno);
}
mode_t mode = st.st_mode | S_IXUSR;
if (chmod(package, mode) != 0) {
fatalfa(errno);
}
return 0;
}

7
src/shell.h Normal file
View File

@@ -0,0 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHELL_H
#define SHELL_H
int write_shell(char *package, char *license, int year, char *author, char *m);
#endif

View File

@@ -1,6 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Generate C project
*
/*
* Copyright (C) 2025, GCK.
* Written by vx-clutch (vx-clutch)
*/
@@ -9,7 +8,6 @@
#include <errno.h>
#include <getopt.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -23,6 +21,7 @@
#include <lib/say.h>
#include <lib/textc.h>
#include "shell.h"
#include "license.h"
typedef enum { MIT, GPL, BSD, UNL } license_t;
@@ -166,61 +165,19 @@ int main(int argc, char **argv)
package = str_dup(argv[optind]);
if (shell) {
fs_write(package, "\
#!/bin/sh\n\
# SPDX-License-Identifier: %s\n\
#\n\
# %s\n\
\n\
me=$0\n\
scriptversion=\"1.0.0\"\n\
\n\
version=\"$me $scriptversion\n\
\n\
Copyright (C) %d %s\n\
This is free software; you are free to change and redistribute it.\n\
There is NO WARRANTY, to the textent permitted by law.\"\n\
\n\
usage=\"\\\n\
Usage: $me [OPTION]...\n\
%s\n\
\n\
Options:\n\
\n\
--help print this help and exit\n\
--version output version information\"\n\
\n\
while [ $# -gt 0 ]; do\n\
case $1 in\n\
--help) echo \"$usage\"; exit 0;;\n\
--version) echo \"$version\"; exit 0;;\n\
-*)\n\
echo \"$0: Unknwon option '$1'.\" >&2\n\
echo \"$0: Try '--help' for more information.\" >&2\n\
exit 1 ;;\n\
esac\n\
shift\n\
done\n\
\n\
echo \"$0: done.\"\n\
\n\
# End: %s\
",
license_str, m, year, author, m, package);
struct stat st;
if (shell)
return write_shell(package, license_str, year, author, m);
if (stat(package, &st) != 0) {
fatalfa(errno);
}
char *project_dir;
asprintf(&project_dir, "%s/", package);
mode_t mode = st.st_mode | S_IXUSR;
fs_new(project_dir);
if (chdir(project_dir))
fatalfa(errno);
if (chmod(package, mode) != 0) {
fatalfa(errno);
}
return exit_status;
}
fs_write("README", templ_README, author, package, package, m, year,
author, author, package);
fs_write("README-dev", templ_README_dev, year, author);
return exit_status;
}
@@ -238,8 +195,9 @@ Generates an opinionated C project.\n",
stdout);
puts("");
fputs("\
--author=NAME Set the program author (default git username|system username)\n\
--license=LICENSE Set the program license (default BSD)\n",
-m DESC Set the program description (default \"Does a thing\")\n\
--author NAME Set the program author (default git username|system username)\n\
--license LICENSE Set the program license (default BSD)\n",
stdout);
exit(exit_status);
}
@@ -254,5 +212,3 @@ static void print_version()
puts("There is NO WARRANTY, to the extent permitted by law.");
exit(exit_status);
}
/* end of file yait.c */