idek
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
/* tcpl.h: global header for the tcpl project.
|
||||
Copyright (C) vxclutch 2026
|
||||
|
||||
Written by vxclutch
|
||||
|
||||
This file is part of tcpl
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE. */
|
||||
#ifndef TCPL_TCPL_H
|
||||
#define TCPL_TCPL_H
|
||||
/*
|
||||
* This is a header file to be included into every source file that comprises
|
||||
* this project.
|
||||
* Do #include <tcpl/tcpl.h>
|
||||
*/
|
||||
/* This is a header file to be included into every source file that comprises
|
||||
this project.
|
||||
Do #include <tcpl/tcpl.h> */
|
||||
|
||||
#define unused (void)
|
||||
|
||||
|
||||
34
lib/print.c
34
lib/print.c
@@ -1,10 +1,38 @@
|
||||
/* print.c: print functions for tcpl.
|
||||
Copyright (C) vxclutch 2026
|
||||
|
||||
Written by vxclutch
|
||||
|
||||
This file is part of tcpl
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include "print.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <tcpl/tcpl.h>
|
||||
|
||||
char *arg0 = "";
|
||||
char* arg0 = "";
|
||||
|
||||
int tcpl_print(char* s)
|
||||
int tcpl_print(char* fmt, ...)
|
||||
{
|
||||
return printf("%s: %s\n", arg0, s);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
printf("%s: ", arg0);
|
||||
int ln = vprintf(fmt, ap);
|
||||
putc('\n', stdout);
|
||||
|
||||
va_end(ap);
|
||||
return ln;
|
||||
}
|
||||
|
||||
22
lib/print.h
22
lib/print.h
@@ -1,10 +1,28 @@
|
||||
/* print.h: print functions for tcpl.
|
||||
Copyright (C) vxclutch 2026
|
||||
|
||||
Written by vxclutch
|
||||
|
||||
This file is part of tcpl
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE. */
|
||||
#ifndef TCPL_PRINT_H
|
||||
#define TCPL_PRINT_H
|
||||
/*
|
||||
* Define the print functions for this project
|
||||
*/
|
||||
|
||||
extern char *arg0;
|
||||
int tcpl_print(char* s);
|
||||
extern char* arg0;
|
||||
int tcpl_print(char* fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
13
src/main.c
13
src/main.c
@@ -1,5 +1,5 @@
|
||||
/* main.c: defines the entry point for tcpl.
|
||||
Copyright (C) vxclutch
|
||||
Copyright (C) vxclutch 2026
|
||||
|
||||
Written by vxclutch
|
||||
|
||||
@@ -22,9 +22,14 @@ PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
unused argc;
|
||||
|
||||
arg0 = basename(argv[0]);
|
||||
tcpl_print("Hello, World!");
|
||||
|
||||
if (argc < 2)
|
||||
tcpl_print("Hello, World!");
|
||||
else {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
tcpl_print("Hello, %s!", argv[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
7
t/basic
Executable file
7
t/basic
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
. t/lib.sh
|
||||
|
||||
check "" "tcpl: Hello, World!"
|
||||
check "foo" "tcpl: Hello, foo!"
|
||||
check "oo" "tcpl: Hello, foo!"
|
||||
55
t/lib.sh
Normal file → Executable file
55
t/lib.sh
Normal file → Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
|
||||
scriptversion="1"
|
||||
me=$(basename "$0")
|
||||
version="$me/vxc v$scriptversion
|
||||
Copyright (C) 2026 vxc.
|
||||
This is free software; you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law."
|
||||
|
||||
usage="Usage: $me [OPTION]... <arg1> <arg2>
|
||||
Does a thing
|
||||
|
||||
Options:
|
||||
--help print this help and exit
|
||||
--version output version information"
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--help) echo "$usage"; exit 0 ;;
|
||||
--version) echo "$version"; exit 0 ;;
|
||||
-*) echo "$me: Unknown option '$1'." >&2; exit 1 ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
width=$(tput cols 2>/dev/null || echo 80)
|
||||
|
||||
INFO="\e[0;34m"
|
||||
RESET="\e[0m"
|
||||
OK="\e[0;32m"
|
||||
BAD="\e[0;31m"
|
||||
|
||||
good() {
|
||||
printf "%$((${width}))s\r%s...\n" "$(echo -e "$INFO[ ${OK}ok $INFO]$RESET")" "$1"
|
||||
}
|
||||
|
||||
fail() {
|
||||
printf "%$((${width}))s\r%s...\n" "$(echo -e "$INFO[${BAD}fail$INFO]$RESET")" "$1"
|
||||
}
|
||||
|
||||
make -s
|
||||
|
||||
check() {
|
||||
expected=$2
|
||||
output=$(./tcpl $1) || { fail "$1 (execution failed)"; return 1; }
|
||||
|
||||
if [ "$output" = "$expected" ]; then
|
||||
good "./tcpl $1"
|
||||
return 0
|
||||
else
|
||||
fail "./tcpl $1: unexpected: $output; wanted: $expected"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user