xeluxee / competitest.nvim

CompetiTest.nvim is a Neovim plugin for Competitive Programming: it can manage and check testcases, download problems and contests from online judges and much more
GNU Lesser General Public License v3.0
442 stars 21 forks source link

Whitespaces not compiled correctly. #42

Open mohammadrehan28 opened 1 year ago

mohammadrehan28 commented 1 year ago

when we use competitest to receives problem from codeforces and contest. the name shouldn't have whitespaces cause when I try to run the file with my own configuration (input.in, output.out) it's led to error. it's not a better idea to name the contest and problem with whitespaces.

Finally, thank you for this awesome plugin.

xeluxee commented 1 year ago

Please share your CompetiTest setup() and paste here the error you're getting

mohammadrehan28 commented 1 year ago

maybe you don't understand me. I mean that your plugin is works correctly 100% but if i need to run the program on cmd and show the input and output for my own test it's shown an error cause the name contain whitespaces. I solve it by edit the configuration of your plugin to name the contest and the problem without whitespace. but it can be nice to add a configuration that name the problem and contest without whitespaces and without a '(' , ')' characters, avoiding make a function to easiest on people beginner. this is my setup:

require('competitest').setup {
    save_current_file = true,
    save_all_files = true, --------------
    compile_directory = ".",
    compile_command = {
        c = { exec = "gcc", args = { "-Wall", "$(FNAME)", "-o", "$(FNOEXT)" } },
        cpp = { exec = "g++", args = { "-DLOCAL", "-DONLINE_JUDGE", "-std=c++17", "-Wall", "$(FNAME)", "-o", "$(FNOEXT)" } },
        rust = { exec = "rustc", args = { "$(FNAME)" } },
        java = { exec = "javac", args = { "$(FNAME)" } },
    },
    running_directory = ".",
    run_command = {
        c = { exec = "./$(FNOEXT)" },
        cpp = { exec = "./$(FNOEXT)" },
        rust = { exec = "./$(FNOEXT)" },
        python = { exec = "python", args = { "$(FNAME)" } },
        java = { exec = "java", args = { "$(FNOEXT)" } },
    },
    multiple_testing = -1,
    maximum_time = 5000,
    output_compare_method = "squish",
    view_output_diff = true,
    testcases_directory = ".",
    testcases_use_single_file = false,
    testcases_auto_detect_storage = true,
    testcases_single_file_format = "$(FNOEXT).testcases",
    testcases_input_file_format = "$(FNOEXT)_input$(TCNUM).txt",
    testcases_output_file_format = "$(FNOEXT)_output$(TCNUM).txt",
    companion_port = 27121,
    receive_print_message = true,
    template_file = {cpp = "/mnt/media/Code/Linux/Template/template.cpp"},
    evaluate_template_modifiers = false,
    date_format = "%c",
    received_files_extension = "cpp",
  received_problems_path = function(task, file_extension)
    local hyphen = string.find(task.group, " - ")
    local contest, problem, path
    if not hyphen then
      contest = "unknown_contest"
    else
      contest = string.sub(task.group, hyphen + 3)
    end
    contest = string.gsub(contest, "%s+", "")
    contest = string.gsub(contest, "%(", "-")
    contest = string.gsub(contest, "%)", "-")
    problem = string.gsub(task.name, "%s+", "")
    problem = string.gsub(problem, "%(", "-")
    problem = string.gsub(problem, "%)", "-")
    path = vim.fn.getcwd()
    return string.format("%s/%s/%s.%s", path, contest, problem, file_extension)
  end,
    --received_problems_path = "$(CWD)/$(PROBLEM)/$(PROBLEM).$(FEXT)",
    received_problems_prompt_path = true,
  received_contests_directory = function(task, file_extension)
    local hyphen = string.find(task.group, " - ")
    local contest, path
    if not hyphen then
      contest = "unknown_contest"
    else
      contest = string.sub(task.group, hyphen + 3)
    end
    contest = string.gsub(contest, "%s+", "")
    contest = string.gsub(contest, "%(", "-")
    contest = string.gsub(contest, "%)", "-")
    path = vim.fn.getcwd()
    return string.format("%s/%s", path, contest)
  end,
    --received_contests_directory = "$(CWD)/$(CONTEST)",
  received_contests_problems_path = function(task, file_extension)
    local problem
    problem = string.gsub(task.name, "%s+", "")
    problem = string.gsub(problem, "%(", "-")
    problem = string.gsub(problem, "%)", "-")
    return string.format("%s.%s", problem, file_extension)
  end,
    --received_contests_problems_path = "$(PROBLEM).$(FEXT)",
    received_contests_prompt_directory = true,
    received_contests_prompt_extension = true,
    open_received_problems = true,
    open_received_contests = true,
}
xeluxee commented 1 year ago

if i need to run the program on cmd and show the input and output for my own test it's shown an error cause the name contain whitespaces

If I understood correctly you want to compile and run the source code from command line. You can do it even if the filename contains whitespaces. You have two options.

  1. Surround filename with single quotes before launching command, or put backslash before spaces:

    # compile
    g++ 'A. Problem name.cpp' -o 'A. Problem name'
    g++ A.\ Problem\ name.cpp -o A.\ Problem\ name
    
    # run
    './A. Problem name'
    ./A.\ Problem\ name
  2. Change CompetiTest configuration to avoid whitespaces: As you already did you can tweak received_problems_path, received_contests_directory, received_contests_problems_path to remove whitespaces. If you want something simpler you can use $(JAVA_TASK_CLASS) modifier that, despite its name, works for every programming language. It is generated from problem name removing all non-alphabetic and non-numeric characters, including spaces and punctuation. Here's an example:

     received_problems_path = "$(HOME)/path/to/folder/$(JAVA_TASK_CLASS).$(FEXT)"
     received_contests_problems_path = "$(JAVA_TASK_CLASS).$(FEXT)"