feat: FASM target
This commit is contained in:
@@ -6,51 +6,80 @@
|
||||
* <https://opensource.org/licence/bsd-3-clause>
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../include/yait.h"
|
||||
#include "util.h"
|
||||
#include "contents.h"
|
||||
|
||||
char buffer[BUFSIZ];
|
||||
#define emit_progress_file \
|
||||
fprintf(stderr, "Created files %d\r", a); \
|
||||
a++
|
||||
|
||||
int create_project(manifest_t manifest)
|
||||
{
|
||||
mkdir_p(manifest.project);
|
||||
chdir(manifest.project);
|
||||
int status, a = 1;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
if (manifest.style == SIMPLE) {
|
||||
/* This only works if the source
|
||||
files's root name is the same as the target on all of the Makefile becuase of how it checks for files. */
|
||||
status = mkdir_p(manifest.project);
|
||||
if (status)
|
||||
return 1;
|
||||
|
||||
status = chdir(manifest.project);
|
||||
if (status)
|
||||
return 1;
|
||||
|
||||
switch (manifest.style) {
|
||||
case SIMPLE:
|
||||
cfprintf(
|
||||
"Makefile",
|
||||
".POSIX:\nCC ::= gcc\nCFLAGS ::= -Wall --std=c23 -Wpedantic\n\nall: %s",
|
||||
manifest.project);
|
||||
fprintf(stderr, "Created files 1\r");
|
||||
emit_progress_file;
|
||||
cfprintf("README", "%s", manifest.project);
|
||||
fprintf(stderr, "Created files 2\r");
|
||||
emit_progress_file;
|
||||
|
||||
snprintf(buffer, BUFSIZ, "%s.c", manifest.project);
|
||||
cfprintf(buffer, "");
|
||||
fputs("Created files 3, done.\n", stderr);
|
||||
/* We exit early because the simple flag is an overridding flag. */
|
||||
return 0;
|
||||
fprintf(stderr, "Created files %d, done.\n", a);
|
||||
break;
|
||||
|
||||
case POSIX:
|
||||
cfprintf("Makefile", "");
|
||||
cfprintf("configure", configure);
|
||||
cfprintf(".clang-format", "");
|
||||
cfprintf("README", readme, manifest.name);
|
||||
cfprintf("src/main.c", "");
|
||||
|
||||
snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project);
|
||||
cfprintf(buffer, "");
|
||||
|
||||
snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project);
|
||||
cfprintf(buffer, ".\\\" %s.1 - Manual page for %s",
|
||||
manifest.project, manifest.project);
|
||||
|
||||
cfprintf("doc/WHATNEXT", what_next);
|
||||
break;
|
||||
case FASM:
|
||||
snprintf(buffer, BUFSIZ, "%s.txt", manifest.project);
|
||||
for (int i = 0; buffer[i] != '\0'; ++i)
|
||||
buffer[i] = toupper((unsigned char)buffer[i]);
|
||||
cfprintf(
|
||||
buffer,
|
||||
"<https://github.com/tgrysztar/fasm/blob/master/FASM.TXT>");
|
||||
cfprintf(
|
||||
"SOURCE/main.c",
|
||||
"#include <stdio.h>\n\nint main() {\n\tputs(\"Hei!\");\n\treturn 0;\n}");
|
||||
cfprintf("TOOLS/build.sh",
|
||||
"#!/bin/sh\n\ncc SOURCE/main.c -o %s",
|
||||
manifest.project);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
cfprintf("Makefile", "");
|
||||
cfprintf("configure", configure);
|
||||
cfprintf(".clang-format", "");
|
||||
cfprintf("README", readme, manifest.name);
|
||||
cfprintf("src/main.c", "");
|
||||
|
||||
snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project);
|
||||
cfprintf(buffer, "");
|
||||
|
||||
snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project);
|
||||
cfprintf(buffer, "");
|
||||
|
||||
cfprintf("doc/WHATNEXT", what_next);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
src/main.c
31
src/main.c
@@ -24,15 +24,6 @@
|
||||
#define print_option(option, description) \
|
||||
printf(" %-20s %-20s\n", option, description)
|
||||
|
||||
char *str_dup(char *s)
|
||||
{
|
||||
char *new = malloc(strlen(s) + 1);
|
||||
if (!new)
|
||||
return NULL;
|
||||
strcpy(new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
static void usage(int status)
|
||||
{
|
||||
if (status != 0) {
|
||||
@@ -46,8 +37,10 @@ static void usage(int status)
|
||||
puts("Mandatory arguments to long options are mandatory for short options too");
|
||||
print_option("--no-git", "Do not inititize git reposity");
|
||||
print_option("--clang", "Add clang-format files and tooling");
|
||||
print_option("-L <licence>", "Set licence");
|
||||
print_option("-l <library>", "Add a library");
|
||||
print_option("-L <licence>",
|
||||
"Set licence. This list can be found by passing 'list'");
|
||||
print_option("-l <library>",
|
||||
"Add a library. This list can be found by passing 'list'");
|
||||
print_option("-n <name>", "Set the name of the project");
|
||||
print_option(
|
||||
"--style=<style>",
|
||||
@@ -68,14 +61,16 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
||||
{ 0, 0, 0, 0 } };
|
||||
// clang-format on
|
||||
|
||||
// TODO(vx-clutch): lL
|
||||
while ((opt = getopt_long(argc, argv, "s:gcn", long_opts, NULL)) !=
|
||||
// TODO(vx-clutch): libraries
|
||||
while ((opt = getopt_long(argc, argv, "s:gcn:L:", long_opts, NULL)) !=
|
||||
-1) {
|
||||
switch (opt) {
|
||||
case 's':
|
||||
if (strcmp(optarg, "list") == 0) {
|
||||
fputs("", stderr);
|
||||
puts("posix\nsimple\nGNU\nlib\nfasm");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
conf->style = TOstyle(optarg);
|
||||
break;
|
||||
case 'g':
|
||||
conf->flags.git = false;
|
||||
@@ -86,6 +81,9 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
||||
case 'n':
|
||||
conf->name = str_dup(optarg);
|
||||
break;
|
||||
case 'L':
|
||||
conf->licence = TOlicence(optarg);
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
@@ -161,6 +159,11 @@ int main(int argc, char **argv)
|
||||
get_name(&manifest.name);
|
||||
status = create_project(manifest);
|
||||
|
||||
if (status) {
|
||||
fprintf(stderr, "%s\n", strerror(status));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
char buffer[PATH_MAX];
|
||||
getcwd(buffer, PATH_MAX);
|
||||
fprintf(stderr, "Created %s at\n %s\n", manifest.project, buffer);
|
||||
|
||||
33
src/util.c
33
src/util.c
@@ -1,21 +1,46 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "../include/yait.h"
|
||||
|
||||
licence_t TOlicence(const char *s)
|
||||
licence_t TOlicence(char *s)
|
||||
{
|
||||
if (strcmp(s, "mit"))
|
||||
if (!strcmp(s, "mit"))
|
||||
return MIT;
|
||||
if (strcmp(s, "gpl"))
|
||||
if (!strcmp(s, "gpl"))
|
||||
return GPL;
|
||||
if (strcmp(s, "bsd"))
|
||||
if (!strcmp(s, "bsd"))
|
||||
return BSD;
|
||||
return UNL;
|
||||
}
|
||||
|
||||
style_t TOstyle(char *s)
|
||||
{
|
||||
if (!strcmp(s, "posix"))
|
||||
return POSIX;
|
||||
if (!strcmp(s, "simple"))
|
||||
return SIMPLE;
|
||||
if (!strcmp(s, "GNU"))
|
||||
return GNU;
|
||||
if (!strcmp(s, "lib"))
|
||||
return LIBRARY;
|
||||
if (!strcmp(s, "fasm"))
|
||||
return FASM;
|
||||
return SIMPLE;
|
||||
}
|
||||
|
||||
char *str_dup(char *s)
|
||||
{
|
||||
char *new = malloc(strlen(s) + 1);
|
||||
if (!new)
|
||||
return NULL;
|
||||
strcpy(new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
static char *nextchar;
|
||||
|
||||
int getopt_long(int argc, char *const argv[], const char *optstring,
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
|
||||
#include "../include/yait.h"
|
||||
|
||||
licence_t TOlicence(const char *s);
|
||||
licence_t TOlicence(char *s);
|
||||
style_t TOstyle(char *s);
|
||||
|
||||
int getopt_long(int argc, char *const argv[], const char *optstring,
|
||||
const struct option *longopts, int *longindex);
|
||||
|
||||
char *str_dup(char *s);
|
||||
|
||||
int mkdir_p(const char *path);
|
||||
int cfprintf(const char *path, const char *format, ...);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user