Skip to content

Commit

Permalink
Merge pull request #318 from blackav/317-add-default_disabled-config-…
Browse files Browse the repository at this point in the history
…variable-to-language-section

317 add default disabled config variable to language section
  • Loading branch information
blackav committed May 9, 2024
2 parents c0abedd + ddff212 commit 63b0658
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 15 deletions.
9 changes: 9 additions & 0 deletions gen/prepare_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,8 @@ static struct meta_info_item meta_info_section_language_data_data[] =
[CNTSLANG_enable_custom] = { CNTSLANG_enable_custom, 'B', XSIZE(struct section_language_data, enable_custom), "enable_custom", XOFFSET(struct section_language_data, enable_custom) },
[CNTSLANG_enable_ejudge_env] = { CNTSLANG_enable_ejudge_env, 'B', XSIZE(struct section_language_data, enable_ejudge_env), "enable_ejudge_env", XOFFSET(struct section_language_data, enable_ejudge_env) },
[CNTSLANG_preserve_line_numbers] = { CNTSLANG_preserve_line_numbers, 'B', XSIZE(struct section_language_data, preserve_line_numbers), "preserve_line_numbers", XOFFSET(struct section_language_data, preserve_line_numbers) },
[CNTSLANG_default_disabled] = { CNTSLANG_default_disabled, 'B', XSIZE(struct section_language_data, default_disabled), "default_disabled", XOFFSET(struct section_language_data, default_disabled) },
[CNTSLANG_enabled] = { CNTSLANG_enabled, 'B', XSIZE(struct section_language_data, enabled), "enabled", XOFFSET(struct section_language_data, enabled) },
[CNTSLANG_max_vm_size] = { CNTSLANG_max_vm_size, 'E', XSIZE(struct section_language_data, max_vm_size), "max_vm_size", XOFFSET(struct section_language_data, max_vm_size) },
[CNTSLANG_max_stack_size] = { CNTSLANG_max_stack_size, 'E', XSIZE(struct section_language_data, max_stack_size), "max_stack_size", XOFFSET(struct section_language_data, max_stack_size) },
[CNTSLANG_max_file_size] = { CNTSLANG_max_file_size, 'E', XSIZE(struct section_language_data, max_file_size), "max_file_size", XOFFSET(struct section_language_data, max_file_size) },
Expand All @@ -2002,6 +2004,7 @@ static struct meta_info_item meta_info_section_language_data_data[] =
[CNTSLANG_clean_up_cmd] = { CNTSLANG_clean_up_cmd, 's', XSIZE(struct section_language_data, clean_up_cmd), "clean_up_cmd", XOFFSET(struct section_language_data, clean_up_cmd) },
[CNTSLANG_run_env_file] = { CNTSLANG_run_env_file, 's', XSIZE(struct section_language_data, run_env_file), "run_env_file", XOFFSET(struct section_language_data, run_env_file) },
[CNTSLANG_clean_up_env_file] = { CNTSLANG_clean_up_env_file, 's', XSIZE(struct section_language_data, clean_up_env_file), "clean_up_env_file", XOFFSET(struct section_language_data, clean_up_env_file) },
[CNTSLANG_version] = { CNTSLANG_version, 's', XSIZE(struct section_language_data, version), "version", XOFFSET(struct section_language_data, version) },
[CNTSLANG_unhandled_vars] = { CNTSLANG_unhandled_vars, 's', XSIZE(struct section_language_data, unhandled_vars), "unhandled_vars", XOFFSET(struct section_language_data, unhandled_vars) },
[CNTSLANG_disabled_by_config] = { CNTSLANG_disabled_by_config, 'i', XSIZE(struct section_language_data, disabled_by_config), NULL, XOFFSET(struct section_language_data, disabled_by_config) },
};
Expand Down Expand Up @@ -2090,6 +2093,8 @@ void cntslang_copy(struct section_language_data *dst, const struct section_langu
dst->enable_custom = src->enable_custom;
dst->enable_ejudge_env = src->enable_ejudge_env;
dst->preserve_line_numbers = src->preserve_line_numbers;
dst->default_disabled = src->default_disabled;
dst->enabled = src->enabled;
dst->max_vm_size = src->max_vm_size;
dst->max_stack_size = src->max_stack_size;
dst->max_file_size = src->max_file_size;
Expand Down Expand Up @@ -2138,6 +2143,9 @@ void cntslang_copy(struct section_language_data *dst, const struct section_langu
if (src->clean_up_env_file) {
dst->clean_up_env_file = strdup(src->clean_up_env_file);
}
if (src->version) {
dst->version = strdup(src->version);
}
if (src->unhandled_vars) {
dst->unhandled_vars = strdup(src->unhandled_vars);
}
Expand Down Expand Up @@ -2170,6 +2178,7 @@ void cntslang_free(struct section_language_data *ptr)
free(ptr->clean_up_cmd);
free(ptr->run_env_file);
free(ptr->clean_up_env_file);
free(ptr->version);
free(ptr->unhandled_vars);
// private disabled_by_config
}
Expand Down
3 changes: 3 additions & 0 deletions include/ejudge/meta/prepare_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ enum
CNTSLANG_enable_custom,
CNTSLANG_enable_ejudge_env,
CNTSLANG_preserve_line_numbers,
CNTSLANG_default_disabled,
CNTSLANG_enabled,
CNTSLANG_max_vm_size,
CNTSLANG_max_stack_size,
CNTSLANG_max_file_size,
Expand All @@ -646,6 +648,7 @@ enum
CNTSLANG_clean_up_cmd,
CNTSLANG_run_env_file,
CNTSLANG_clean_up_env_file,
CNTSLANG_version,
CNTSLANG_unhandled_vars,
CNTSLANG_disabled_by_config,

Expand Down
9 changes: 8 additions & 1 deletion include/ejudge/prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ struct section_problem_data
} xml META_ATTRIB((meta_hidden));
};

/* sizeof(struct section_language_data) == 312/400 */
/* sizeof(struct section_language_data) == ?/472 */
struct section_language_data
{
struct generic_section_config g META_ATTRIB((meta_hidden));
Expand Down Expand Up @@ -1395,6 +1395,10 @@ struct section_language_data
ejintbool_t enable_ejudge_env;
/** to preserve the original line numbers in scripts */
ejintbool_t preserve_line_numbers;
/** disable this language by the default import */
ejintbool_t default_disabled;
/** enable this language (overrides default_disabled) */
ejintbool_t enabled;

/** max virtual size limit */
ej_size64_t max_vm_size;
Expand Down Expand Up @@ -1442,6 +1446,9 @@ struct section_language_data
/** additional clean_up environment in file */
unsigned char *clean_up_env_file;

/** compiler version */
unsigned char *version;

unsigned char *unhandled_vars;
/** disabled by configuration script */
int disabled_by_config META_ATTRIB((meta_private));
Expand Down
40 changes: 30 additions & 10 deletions lib/lang_config_vis.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- mode: c -*- */

/* Copyright (C) 2008-2023 Alexander Chernov <[email protected]> */
/* Copyright (C) 2008-2024 Alexander Chernov <[email protected]> */

/*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -496,6 +496,10 @@ update_language_script(
size_t in_z = 0, out_z = 0;
FILE *f = 0;
char buf[1024];
char old_path[PATH_MAX];
char lock_path[PATH_MAX];
char new_script_out[PATH_MAX];
__attribute__((unused)) int _;

// read the source file
if (!(f = fopen(script_in, "r"))) {
Expand All @@ -520,16 +524,30 @@ update_language_script(
fclose(f); f = 0;
if (!strcmp(out_t, in_t)) {
// no difference, but update the modtime
if (utime(script_out, 0) < 0) {
log_printf(err_f, win, "error: cannot change mod time for `%s'\n",
script_out);
// error
}
//if (utime(script_out, 0) < 0) {
// log_printf(err_f, win, "error: cannot change mod time for `%s'\n",
// script_out);
// // error
//}
goto cleanup;
}
xfree(out_t); out_t = 0;
}

// check the lock file
_ = snprintf(lock_path, sizeof(lock_path), "%s.lock", script_out);
if (access(lock_path, F_OK) >= 0) {
_ = snprintf(new_script_out, sizeof(new_script_out), "%s.new", script_out);
script_out = new_script_out;
} else {
// preserve the old output file
_ = snprintf(old_path, sizeof(old_path), "%s.old", script_out);
if (rename(script_out, old_path) < 0) {
log_printf(err_f, win, "error: cannot rename `%s'\n", script_out);
goto cleanup;
}
}

// write the output file
if (!(f = fopen(script_out, "w"))) {
log_printf(err_f, win, "error: cannot open `%s' for writing\n",
Expand Down Expand Up @@ -1189,11 +1207,10 @@ lang_config_generate_compile_cfg(
s = shellconfig_get(p->cfg, "long_name");
if (!s) s = "";
fprintf(f, "long_name = \"%s\"\n", s);
/*
s = shellconfig_get(p->cfg, "version");
if (!s) s = "";
fprintf(f, "%s\"\n", s);
*/
if (s && *s) {
fprintf(f, "version = \"%s\"\n", s);
}
if ((s = shellconfig_get(p->cfg, "src_sfx"))) {
fprintf(f, "src_sfx = \"%s\"\n", s);
}
Expand Down Expand Up @@ -1221,6 +1238,9 @@ lang_config_generate_compile_cfg(
if ((s = shellconfig_get(p->cfg, "enable_ejudge_env"))) {
fprintf(f, "enable_ejudge_env\n");
}
if ((s = shellconfig_get(p->cfg, "default_disabled"))) {
fprintf(f, "default_disabled\n");
}
if (!(s = shellconfig_get(p->cfg, "cmd"))) s = p->lang;
fprintf(f, "cmd = \"%s\"\n", s);
if ((s = shellconfig_get(p->cfg, "arch"))) {
Expand Down
3 changes: 3 additions & 0 deletions lib/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ static const struct config_parse_info section_language_params[] =
LANGUAGE_PARAM(enable_custom, "d"),
LANGUAGE_PARAM(enable_ejudge_env, "d"),
LANGUAGE_PARAM(preserve_line_numbers, "d"),
LANGUAGE_PARAM(default_disabled, "d"),
LANGUAGE_PARAM(enabled, "d"),
LANGUAGE_PARAM(max_vm_size, "E"),
LANGUAGE_PARAM(max_stack_size, "E"),
LANGUAGE_PARAM(max_file_size, "E"),
Expand All @@ -648,6 +650,7 @@ static const struct config_parse_info section_language_params[] =
LANGUAGE_PARAM(clean_up_cmd, "S"),
LANGUAGE_PARAM(run_env_file, "S"),
LANGUAGE_PARAM(clean_up_env_file, "S"),
LANGUAGE_PARAM(version, "S"),

{ 0, 0, 0, 0 }
};
Expand Down
7 changes: 7 additions & 0 deletions lib/prepare_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,10 @@ prepare_unparse_lang(
unparse_bool(f, "enable_ejudge_env", lang->enable_ejudge_env);
if (lang->preserve_line_numbers > 0)
unparse_bool(f, "preserve_line_numbers", lang->preserve_line_numbers);
if (lang->default_disabled > 0)
unparse_bool(f, "default_disabled", lang->default_disabled);
if (lang->enabled > 0)
unparse_bool(f, "enabled", lang->enabled);
if (lang->content_type && lang->content_type[0]) {
fprintf(f, "content_type = \"%s\"\n", CARMOR(lang->content_type));
}
Expand Down Expand Up @@ -992,6 +996,9 @@ prepare_unparse_lang(
if (lang->clean_up_env_file && *lang->clean_up_env_file) {
fprintf(f, "clean_up_env_file = \"%s\"\n", CARMOR(lang->clean_up_env_file));
}
if (lang->version && *lang->version) {
fprintf(f, "version = \"%s\"\n", CARMOR(lang->version));
}
fprintf(f, "\n");

if (lang->unhandled_vars) fprintf(f, "%s\n", lang->unhandled_vars);
Expand Down
3 changes: 2 additions & 1 deletion scripts/custom-version.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2023 Alexander Chernov <[email protected]>
# Copyright (c) 2023-2024 Alexander Chernov <[email protected]>

# compiler script interface is as follows
# <comp>-version [OPTION]
Expand All @@ -22,6 +22,7 @@ common_config() {
echo 'long_name="Custom"'
echo 'src_sfx=".txt"'
echo 'enable_custom=1'
echo 'default_disabled=1'
}

failure() {
Expand Down
2 changes: 0 additions & 2 deletions scripts/node.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ then
mv "$1" "${EJUDGE_SOLUTION_FILE}.js"
tar cfz "$2" .
echo '{ "is_archive": true, "start_cmd": "'${NODEPATH}'", "start_args": ["'${NODEPATH}'"'${extra_args}',"'${EJUDGE_START_FILE}'.js"] }' > "$3"
ls -l .
cat $3
exit 0
fi

Expand Down
3 changes: 2 additions & 1 deletion scripts/postgres-version.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash
# Copyright (c) 2023 Alexander Chernov <[email protected]>
# Copyright (c) 2023-2024 Alexander Chernov <[email protected]>

prefix="@prefix@"
exec_prefix="@exec_prefix@"
Expand All @@ -13,6 +13,7 @@ common_config() {
echo 'long_name="PostgreSQL"'
echo 'src_sfx=".sql"'
echo 'arch="linux-shared"'
echo 'default_disabled=1'
}

failure() {
Expand Down

0 comments on commit 63b0658

Please sign in to comment.