~emersion/annotatesh

59ec78bb887cdb314eccef610a6a7314e8cf222d — Simon Ser 10 months ago 9a63ff2
Move POSIX definitions to separate file
4 files changed, 213 insertions(+), 193 deletions(-)

A include/posix.h
M main.c
M meson.build
A posix.c
A include/posix.h => include/posix.h +16 -0
@@ 0,0 1,16 @@
#ifndef POSIX_H
#define POSIX_H

#include <stddef.h>

// The Open Group Base Specifications Issue 7, 2018 edition
#define POSIX_URL_BASE "http://pubs.opengroup.org/onlinepubs/9699919799"
#define POSIX_URL_UTILITY (POSIX_URL_BASE "/utilities")
#define POSIX_URL_SPECIAL_BUILTIN (POSIX_URL_BASE "/utilities/V3_chap02.html#")

extern const char *special_builtins[];
extern const size_t special_builtins_len;
extern const char *utilities[];
extern const size_t utilities_len;

#endif

M main.c => main.c +3 -192
@@ 5,194 5,7 @@
#include <string.h>
#include <unistd.h>

// The Open Group Base Specifications Issue 7, 2018 edition
#define POSIX_URL_BASE "http://pubs.opengroup.org/onlinepubs/9699919799"
#define POSIX_URL_UTILITY (POSIX_URL_BASE "/utilities")
#define POSIX_URL_SPECIAL_BUILTIN (POSIX_URL_BASE "/utilities/V3_chap02.html#")

// Retrieved from:
// http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
static const char *special_builtins[] = {
	"break",
	"colon",
	"continue",
	"dot",
	"eval",
	"exec",
	"exit",
	"export",
	"readonly",
	"return",
	"set",
	"shift",
	"trap",
	"unset",
};

// Retrieved from:
// http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html
static const char *utilities[] = {
	"admin",
	"alias",
	"ar",
	"asa",
	"at",
	"awk",
	"basename",
	"batch",
	"bc",
	"bg",
	"c99",
	"cal",
	"cat",
	"cd",
	"cflow",
	"chgrp",
	"chmod",
	"chown",
	"cksum",
	"cmp",
	"comm",
	"command",
	"compress",
	"cp",
	"crontab",
	"csplit",
	"ctags",
	"cut",
	"cxref",
	"date",
	"dd",
	"delta",
	"df",
	"diff",
	"dirname",
	"du",
	"echo",
	"ed",
	"env",
	"ex",
	"expand",
	"expr",
	"false",
	"fc",
	"fg",
	"file",
	"find",
	"fold",
	"fort77",
	"fuser",
	"gencat",
	"get",
	"getconf",
	"getopts",
	"grep",
	"hash",
	"head",
	"iconv",
	"id",
	"ipcrm",
	"ipcs",
	"jobs",
	"join",
	"kill",
	"lex",
	"link",
	"ln",
	"locale",
	"localedef",
	"logger",
	"logname",
	"lp",
	"ls",
	"m4",
	"mailx",
	"make",
	"man",
	"mesg",
	"mkdir",
	"mkfifo",
	"more",
	"mv",
	"newgrp",
	"nice",
	"nl",
	"nm",
	"nohup",
	"od",
	"paste",
	"patch",
	"pathchk",
	"pax",
	"pr",
	"printf",
	"prs",
	"ps",
	"pwd",
	"qalter",
	"qdel",
	"qhold",
	"qmove",
	"qmsg",
	"qrerun",
	"qrls",
	"qselect",
	"qsig",
	"qstat",
	"qsub",
	"read",
	"renice",
	"rm",
	"rmdel",
	"rmdir",
	"sact",
	"sccs",
	"sed",
	"sh",
	"sleep",
	"sort",
	"split",
	"strings",
	"strip",
	"stty",
	"tabs",
	"tail",
	"talk",
	"tee",
	"test",
	"time",
	"touch",
	"tput",
	"tr",
	"true",
	"tsort",
	"tty",
	"type",
	"ulimit",
	"umask",
	"unalias",
	"uname",
	"uncompress",
	"unexpand",
	"unget",
	"uniq",
	"unlink",
	"uucp",
	"uudecode",
	"uuencode",
	"uustat",
	"uux",
	"val",
	"vi",
	"wait",
	"wc",
	"what",
	"who",
	"write",
	"xargs",
	"yacc",
	"zcat",
};
#include "posix.h"

static int str_in_array_cmp(const void *e1, const void *e2) {
	const char *s1 = *(const char **)e1;


@@ 215,11 28,9 @@ static const char *posix_cmd_link(const char *name) {
		name = "test";
	}

	if (str_in_array(name, special_builtins,
			sizeof(special_builtins) / sizeof(special_builtins[0]))) {
	if (str_in_array(name, special_builtins, special_builtins_len)) {
		snprintf(link, sizeof(link), "%s%s", POSIX_URL_SPECIAL_BUILTIN, name);
	} else if (str_in_array(name, utilities,
			sizeof(utilities) / sizeof(utilities[0]))) {
	} else if (str_in_array(name, utilities, utilities_len)) {
		snprintf(link, sizeof(link), "%s/%s.html", POSIX_URL_UTILITY, name);
	} else {
		return NULL;

M meson.build => meson.build +4 -1
@@ 32,10 32,13 @@ else
	mrsh = dependency('mrsh')
endif

annotatesh_inc = include_directories('include')

annotatesh_exe = executable(
	'annotatesh',
	files('main.c'),
	files('main.c', 'posix.c'),
	dependencies: [jsonc, mrsh],
	include_directories: annotatesh_inc,
	install: true,
)


A posix.c => posix.c +190 -0
@@ 0,0 1,190 @@
#include "posix.h"

// Retrieved from:
// http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
const char *special_builtins[] = {
	"break",
	"colon",
	"continue",
	"dot",
	"eval",
	"exec",
	"exit",
	"export",
	"readonly",
	"return",
	"set",
	"shift",
	"trap",
	"unset",
};

const size_t special_builtins_len =
	sizeof(special_builtins) / sizeof(special_builtins[0]);

// Retrieved from:
// http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html
const char *utilities[] = {
	"admin",
	"alias",
	"ar",
	"asa",
	"at",
	"awk",
	"basename",
	"batch",
	"bc",
	"bg",
	"c99",
	"cal",
	"cat",
	"cd",
	"cflow",
	"chgrp",
	"chmod",
	"chown",
	"cksum",
	"cmp",
	"comm",
	"command",
	"compress",
	"cp",
	"crontab",
	"csplit",
	"ctags",
	"cut",
	"cxref",
	"date",
	"dd",
	"delta",
	"df",
	"diff",
	"dirname",
	"du",
	"echo",
	"ed",
	"env",
	"ex",
	"expand",
	"expr",
	"false",
	"fc",
	"fg",
	"file",
	"find",
	"fold",
	"fort77",
	"fuser",
	"gencat",
	"get",
	"getconf",
	"getopts",
	"grep",
	"hash",
	"head",
	"iconv",
	"id",
	"ipcrm",
	"ipcs",
	"jobs",
	"join",
	"kill",
	"lex",
	"link",
	"ln",
	"locale",
	"localedef",
	"logger",
	"logname",
	"lp",
	"ls",
	"m4",
	"mailx",
	"make",
	"man",
	"mesg",
	"mkdir",
	"mkfifo",
	"more",
	"mv",
	"newgrp",
	"nice",
	"nl",
	"nm",
	"nohup",
	"od",
	"paste",
	"patch",
	"pathchk",
	"pax",
	"pr",
	"printf",
	"prs",
	"ps",
	"pwd",
	"qalter",
	"qdel",
	"qhold",
	"qmove",
	"qmsg",
	"qrerun",
	"qrls",
	"qselect",
	"qsig",
	"qstat",
	"qsub",
	"read",
	"renice",
	"rm",
	"rmdel",
	"rmdir",
	"sact",
	"sccs",
	"sed",
	"sh",
	"sleep",
	"sort",
	"split",
	"strings",
	"strip",
	"stty",
	"tabs",
	"tail",
	"talk",
	"tee",
	"test",
	"time",
	"touch",
	"tput",
	"tr",
	"true",
	"tsort",
	"tty",
	"type",
	"ulimit",
	"umask",
	"unalias",
	"uname",
	"uncompress",
	"unexpand",
	"unget",
	"uniq",
	"unlink",
	"uucp",
	"uudecode",
	"uuencode",
	"uustat",
	"uux",
	"val",
	"vi",
	"wait",
	"wc",
	"what",
	"who",
	"write",
	"xargs",
	"yacc",
	"zcat",
};

const size_t utilities_len = sizeof(utilities) / sizeof(utilities[0]);