save
This commit is contained in:
18
configure
vendored
18
configure
vendored
@@ -23,20 +23,22 @@ CFLAGS="-Wall -Wextra -O2"
|
|||||||
LDFLAGS=
|
LDFLAGS=
|
||||||
CC=
|
CC=
|
||||||
|
|
||||||
for arg ; do
|
|
||||||
case "$arg" in
|
|
||||||
--help|h) usage ;;
|
|
||||||
CFLAGS=*) CFLAGS=${arg#*=} ;;
|
|
||||||
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
printf "checking for C compiler... "
|
printf "checking for C compiler... "
|
||||||
trycc gcc
|
trycc gcc
|
||||||
trycc cc
|
trycc cc
|
||||||
trycc clang
|
trycc clang
|
||||||
printf "%s\n" "$CC"
|
printf "%s\n" "$CC"
|
||||||
|
|
||||||
|
for arg ; do
|
||||||
|
case "$arg" in
|
||||||
|
--help|h) usage ;;
|
||||||
|
CFLAGS=*) CFLAGS=${arg#*=} ;;
|
||||||
|
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
|
||||||
|
CC=*) CC=${arg#*=} ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
printf "checking weather C compiler works... "
|
printf "checking weather C compiler works... "
|
||||||
status="fail"
|
status="fail"
|
||||||
tmpc="$(mktemp -d)/test.c"
|
tmpc="$(mktemp -d)/test.c"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
int
|
int
|
||||||
parse_standard_options (void (*usage) (int), int argc, char **argv)
|
parse_standard_options (void (*usage) (int), int argc, char **argv)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (strcmp (argv[i], "--help") == 0)
|
if (strcmp (argv[i], "--help") == 0)
|
||||||
{
|
{
|
||||||
@@ -25,3 +25,11 @@ parse_standard_options (void (*usage) (int), int argc, char **argv)
|
|||||||
}
|
}
|
||||||
return HELP_REQUESTED;
|
return HELP_REQUESTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
initialize_main (int *argc, char ***argv)
|
||||||
|
{
|
||||||
|
(*argc)--;
|
||||||
|
(*argv)++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,4 +10,12 @@
|
|||||||
*/
|
*/
|
||||||
int parse_standard_options(void (*usage_func)(), int argc, char **argv);
|
int parse_standard_options(void (*usage_func)(), int argc, char **argv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the program
|
||||||
|
* @param argc Argument count
|
||||||
|
* @param argv Argument vector
|
||||||
|
* @return 0 on success, 1 if something fails
|
||||||
|
*/
|
||||||
|
int initialize_main(int *, char ***);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
70
yait/main.c
70
yait/main.c
@@ -2,13 +2,13 @@
|
|||||||
#include "../core/file.h"
|
#include "../core/file.h"
|
||||||
#include "../core/print.h"
|
#include "../core/print.h"
|
||||||
#include "../core/standard.h"
|
#include "../core/standard.h"
|
||||||
|
#include "contents.h"
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "contents.h"
|
|
||||||
|
|
||||||
/* Constants for program behavior */
|
/* Constants for program behavior */
|
||||||
#define DEFAULT_USER_NAME "unknown"
|
#define DEFAULT_USER_NAME "unknown"
|
||||||
@@ -63,16 +63,17 @@ main (int argc, char **argv)
|
|||||||
printfn ("error: not enough arguments.");
|
printfn ("error: not enough arguments.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int status = parse_standard_options (usage, argc, argv);
|
int status = initialize_main (&argc, &argv);
|
||||||
|
status = parse_standard_options (usage, argc, argv);
|
||||||
if (status && status != HELP_REQUESTED)
|
if (status && status != HELP_REQUESTED)
|
||||||
{
|
{
|
||||||
printfn ("error: %s", strerror (status));
|
printfn ("error: %s", strerror (status));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
format_t conf;
|
format_t conf;
|
||||||
conf.project = argv[1];
|
conf.project = argv[0];
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
conf.name = argv[2];
|
conf.name = argv[1];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct passwd *pw = getpwuid (getuid ());
|
struct passwd *pw = getpwuid (getuid ());
|
||||||
@@ -115,13 +116,9 @@ create_project (format_t fmt)
|
|||||||
}
|
}
|
||||||
if (!fmt.name)
|
if (!fmt.name)
|
||||||
fmt.name = DEFAULT_USER_NAME;
|
fmt.name = DEFAULT_USER_NAME;
|
||||||
create_file_with_content (
|
create_file_with_content ("README", readme_template,
|
||||||
"README",
|
|
||||||
readme_template,
|
|
||||||
fmt.project ? fmt.project : DEFAULT_PROJECT_NAME);
|
fmt.project ? fmt.project : DEFAULT_PROJECT_NAME);
|
||||||
create_file_with_content (
|
create_file_with_content ("configure", configure_template);
|
||||||
"configure",
|
|
||||||
configure_template);
|
|
||||||
int status = system ("chmod +x configure");
|
int status = system ("chmod +x configure");
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
@@ -129,68 +126,59 @@ create_project (format_t fmt)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
// Create a safe uppercase version of the project name for Makefile variables
|
// Create a safe uppercase version of the project name for Makefile variables
|
||||||
char *mkfile_name = strdup (fmt.project);
|
char *makefile_name = strdup (fmt.project);
|
||||||
if (!mkfile_name)
|
if (!makefile_name)
|
||||||
{
|
{
|
||||||
printfn ("fatal: out of memory");
|
printfn ("fatal: out of memory");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Convert to uppercase safely, only for ASCII characters
|
// Convert to uppercase safely, only for ASCII characters
|
||||||
for (char *p = mkfile_name; *p; ++p)
|
for (char *p = makefile_name; *p; ++p)
|
||||||
{
|
{
|
||||||
if (*p >= 'a' && *p <= 'z')
|
if (*p >= 'a' && *p <= 'z')
|
||||||
*p = *p - 'a' + 'A';
|
*p = *p - 'a' + 'A';
|
||||||
}
|
}
|
||||||
create_file_with_content (
|
create_file_with_content ("Makefile", makefile_template, makefile_name,
|
||||||
"Makefile",
|
makefile_name, makefile_name, makefile_name,
|
||||||
makefile_template,
|
makefile_name, makefile_name, fmt.project,
|
||||||
mkfile_name, mkfile_name, mkfile_name, mkfile_name, mkfile_name,
|
makefile_name, makefile_name);
|
||||||
fmt.project, mkfile_name, mkfile_name, mkfile_name);
|
free (makefile_name);
|
||||||
free (mkfile_name);
|
|
||||||
if (fmt.flag.clang_format)
|
if (fmt.flag.clang_format)
|
||||||
create_file_with_content (".clang-format", clang_format_template);
|
create_file_with_content (".clang-format", clang_format_template);
|
||||||
char *license_line = "";
|
char *license_line = "";
|
||||||
switch (fmt.licence)
|
switch (fmt.licence)
|
||||||
{
|
{
|
||||||
case BSD3:
|
case BSD3:
|
||||||
license_line = "License BSD-3-Clause: BSD-3-Clause <https://opensource.org/licence/bsd-3-clause>";
|
license_line = "License BSD-3-Clause: BSD-3-Clause "
|
||||||
create_file_with_content (
|
"<https://opensource.org/licence/bsd-3-clause>";
|
||||||
"COPYING",
|
create_file_with_content ("COPYING", bsd3_license_template, YEAR,
|
||||||
bsd3_license_template,
|
fmt.name);
|
||||||
YEAR, fmt.name);
|
|
||||||
break;
|
break;
|
||||||
case GPLv3:
|
case GPLv3:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
create_file_with_content ("config.h",
|
create_file_with_content ("config.h", config_h_template, fmt.project,
|
||||||
config_h_template,
|
license_line, fmt.name, YEAR);
|
||||||
fmt.project, license_line, fmt.name, YEAR);
|
|
||||||
create_and_enter_directory (fmt.project);
|
create_and_enter_directory (fmt.project);
|
||||||
if (!fmt.flag.GNU)
|
if (!fmt.flag.GNU)
|
||||||
{
|
{
|
||||||
create_file_with_content (
|
create_file_with_content ("main.c", main_c_template,
|
||||||
"main.c",
|
fmt.project ? fmt.project
|
||||||
main_c_template,
|
: DEFAULT_PROJECT_NAME,
|
||||||
fmt.project ? fmt.project : DEFAULT_PROJECT_NAME,
|
|
||||||
fmt.name ? fmt.name : "World");
|
fmt.name ? fmt.name : "World");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
create_file_with_content (
|
create_file_with_content ("main.c", main_c_gnu_template, fmt.project,
|
||||||
"main.c",
|
fmt.project ? fmt.project
|
||||||
main_c_gnu_template,
|
: DEFAULT_PROJECT_NAME,
|
||||||
fmt.project, fmt.project ? fmt.project : DEFAULT_PROJECT_NAME,
|
|
||||||
fmt.name ? fmt.name : "World");
|
fmt.name ? fmt.name : "World");
|
||||||
}
|
}
|
||||||
if (fmt.flag.GNU)
|
if (fmt.flag.GNU)
|
||||||
{
|
{
|
||||||
create_file_with_content (
|
create_file_with_content ("standard.c", standard_c_template);
|
||||||
"standard.c",
|
create_file_with_content ("standard.h", standard_h_template);
|
||||||
standard_c_template);
|
|
||||||
create_file_with_content (
|
|
||||||
"standard.h",
|
|
||||||
standard_h_template);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user