properly handle default pipe names

This commit is contained in:
Jarcode
2019-03-15 00:32:33 -07:00
parent 315063eb9c
commit 706ec0fcd4
4 changed files with 54 additions and 40 deletions

26
glava.c
View File

@@ -182,15 +182,11 @@ static const char* help_str =
" appropriate backend will be used for the underlying windowing\n"
" system.\n"
"-a, --audio=BACKEND specifies an audio input backend to use.\n"
"-p, --pipe[=FORMAT] binds a value to be read from stdin. The input my be read using\n"
"-p, --pipe=BIND[:TYPE] binds a value to be read from stdin. The input my be read using\n"
" `@name` or `@name:default` syntax within shader sources.\n"
" A stream of inputs (each overriding the previous) must be\n"
" assigned with the `name = value` syntax and separated by\n"
" newline (\'\\n\') characters.\n"
"-i, --stdin[=OLDFORMAT] specifies a format for input to be read from stdin. The input\n"
" may be read from the STDIN macro from within shader sources.\n"
" A stream of inputs (each overriding the previous) must be\n"
" separated by newline (\'\\n\') characters.\n"
"-V, --version print application version and exit\n"
"\n"
"The REQUEST argument is evaluated identically to the \'#request\' preprocessor directive\n"
@@ -205,8 +201,10 @@ static const char* help_str =
"The BACKEND argument may be any of the following strings (for this particular build):\n"
"%s"
"\n"
"The OLDFORMAT argument must be a valid GLSL type. If `--stdin` is used without an argument,\n"
"the default type is `vec4` (type used for RGBA colors)\n"
"The BIND argument must a valid GLSL identifier."
"\n"
"The TYPE argument must be a valid GLSL type. If `--pipe` is used without a \n"
"type argument, the default type is `vec4` (type used for RGBA colors).\n"
"\n"
GLAVA_VERSION_STRING "\n";
@@ -296,6 +294,7 @@ int main(int argc, char** argv) {
if (stdin_type != STDIN_TYPE_NONE) goto conflict_error;
char* parsed_name = NULL;
const char* parsed_type = NULL;
if (optarg) {
size_t in_sz = strlen(optarg);
int sep = -1;
for (size_t t = 0; t < in_sz; ++t) {
@@ -310,11 +309,22 @@ int main(int argc, char** argv) {
optarg[sep] = '\0';
}
parsed_name = optarg;
} else parsed_name = PIPE_DEFAULT;
if (*parsed_name == '\0') {
fprintf(stderr, "Error: invalid pipe binding name: \"%s\"\n"
"Zero length names are not permitted.\n", parsed_name);
exit(EXIT_FAILURE);
}
for (char* c = parsed_name; *c != '\0'; ++c) {
switch (*c) {
case '0' ... '9':
if (c == parsed_name) {
fprintf(stderr, "Error: invalid pipe binding name: \"%s\" ('%c')\n"
"Valid names may not start with a number.\n", parsed_name, *c);
exit(EXIT_FAILURE);
}
case 'a' ... 'z':
case 'A' ... 'Z':
case '0' ... '9':
case '_': continue;
default:
fprintf(stderr, "Error: invalid pipe binding name: \"%s\" ('%c')\n"

View File

@@ -318,7 +318,7 @@ void ext_process(struct glsl_ext* ext, const char* f) {
bool quoted = false, arg_start, b_sep = false, b_spc = false;
int b_br = 0;
char cbuf[9];
char bbuf[128];
char bbuf[256];
char** args = malloc(sizeof(char*));
size_t args_sz = 0;

View File

@@ -1644,6 +1644,8 @@ bool rd_update(struct renderer* r, float* lb, float* rb, size_t bsz, bool modifi
if (c != EOF && c != '\n')
stdin_buf[stdin_idx++] = c;
else {
if (stdin_idx == 0)
goto reset;
stdin_buf[stdin_idx] = '\0';
stdin_select = gl->stdin_type;
@@ -1669,9 +1671,9 @@ bool rd_update(struct renderer* r, float* lb, float* rb, size_t bsz, bool modifi
break;
}
}
if (!valid && !v) {
if ((stdin_name && stdin_name[0] == '\0') || (!valid && !v)) {
/* no assignment, just a default value */
stdin_name = "";
stdin_name = PIPE_DEFAULT;
stdin_name_len = 0;
valid = true;
}

View File

@@ -15,6 +15,8 @@ extern const struct {
#define STDIN_TYPE_VEC3 5
#define STDIN_TYPE_VEC4 6
#define PIPE_DEFAULT "_"
struct gl_data;
typedef struct renderer {