properly handle default pipe names
This commit is contained in:
26
glava.c
26
glava.c
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
6
render.c
6
render.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user