1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/tix/tix-vars.c
Jonas 'Sortie' Termansen 9588b0d3db Add ports to the Sortix repository.
This change imports the ports collection from the former porttix and srctix
repositories and converts them to port(5) files with metadata pointing to
the upstream release tarballs with patches checked into this repository.
Ports are now developed and versioned along with the operating system and
are automatically built per the PACKAGES environment variable. The patches
are licensed under the same license as the relevant ports.

Tix has gained support for the new port(5) format. tix-port(8) is the new
high level ports build even point that handles downloading pstream releases
into the new mirror cache directory, applying the patches, building the port
with the lower-level tix-build(8), and finally installing the binary
package. The new tix-vars(8) program parses port(5) files and the new
tix-rmdiff(8) program produces input for tix-rmpatch(8).

The old doc/ directory is discontinued in favor of manual pages documenting
the new ports system.

The obsolete porttix-create(8) and srctix-create(8) programs are removed.
2022-06-13 22:29:53 +02:00

91 lines
2.3 KiB
C

/*
* Copyright (c) 2022 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and 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.
*
* tix-vars.c
* Evaluate variables in port files.
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include "util.h"
int main(int argc, char* argv[])
{
const char* def = NULL;
bool test = false;
int opt;
while ( (opt = getopt(argc, argv, "d:t")) != -1 )
{
switch ( opt )
{
case 'd': def = optarg; break;
case 't': test = true; break;
default: return 1;
}
}
if ( optind == argc )
errx(2, "expected port file");
const char* path = argv[optind++];
string_array_t sa = string_array_make();
int status = !strcmp(path, "-") ?
variables_append_file(&sa, stdin) :
variables_append_file_path(&sa, path);
if ( status == -1 )
err(2, "%s", path);
else if ( status == -2 )
errx(2, "%s: Syntax error", path);
if ( optind == argc )
{
if ( test )
return 0;
for ( size_t i = 0; i < sa.length; i++ )
if ( puts(sa.strings[i]) < 0 )
err(2, "stdout");
}
else for ( int i = optind; i < argc; i++ )
{
const char* variable = argv[i];
const char* value = dictionary_get_def(&sa, variable, def);
if ( !value && test )
exit(1);
else if ( !value )
errx(1, "%s: Variable is unset: %s", path, variable);
if ( !test && puts(value) < 0 )
err(2, "stdout");
}
if ( ferror(stdout) || fflush(stdout) == EOF )
err(2, "stdout");
return 0;
}