Setting up custom build environment - algorithm

I am trying to set up my custom build environment for Sublime Text 3 for competitive Programming.
My target is as follows :
Build the current source file
Run it and read inputs from a file input.in
Write output to a file output.out
diff expected output.out. expected file contains the expected output
This is how the window setup looks like
This is my json file for the build system
{
"cmd": ["g++ -std=c++11 ${file} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}<${file_path}/input.in>${file_path}/output.out && diff output.out expected"],
"shell":true
}
So far steps 1-3 are working as expected. But for last step 4, I am not able to get the result in proper suitable format. e.g. when files match there is no output (as diff generates nothing in case of match) and in case of non-match, this build system is generating output in non human-readable format.
5a6
> f
[Finished in 0.1s with exit code 1]
Can anyone suggest a better way to output the result or is there a way to use linux's notification utility

Related

How to redirect output from one folder to another?

I try to redirect the result of RNAfold external program that take input files from ./Desktop/Data and want to save execution to the folder ./Desktop/Results/Rfam.
I tried to use the following logic: command < input >> output. But nothing happens except creating files that didn't exist before with a NULL length.
RNAfold < ./Desktop/Data/RF*.fa >> ./Desktop/Results/Rfam/res.txt
None of errors appeared. I work on MAC OS X and it is first time I used bash, I looked manual and saw examples that I used, but nothing happened. RNAfold didn't execute, but when I try RNAfold < RF*.fa >> res.txt
all is going well - obtained results for input files, but they appeared at the same folder.
Default behaviour of RNAfold is to take input from standard input (or the files following RNAfold command)and output to standard out. To specify the input file you can also use -i or --infile=. Similarly for output file -o or --outfile=.
RNAfold -i ~/Desktop/Data/RF*.fa -o ~/Desktop/Results/Rfam/res.txt
or try
RNAfold ~/Desktop/Data/RF*.fa -o ~/Desktop/Results/Rfam/res.txt
Reference

Shell script to verify data packages

I need to make shell script to check my algorithms with loads of data(tests packages saved in .in files, every package contains folder with .in file and the other one with .out file where supposed to be correct result)
Sometimes It's about 1000 files in one packages so there's no point of doing it manually. I need some kind of loop which opens this .in file then redirect input of my c++ program and also redirect output of this program(save result to .out files) But the point is I can't get this language as quick as I need.
And I would like this script to compare results of my algorithm to .out files from packages
for f in ExternalIn/*.in; do//part of code which opens process with my algorithm and compare its .out file to .out file from package
Skipping checks for missing files, whitespace-safety, etc., you probably need something like:
for f in ExternalIn/*.in; do
# diff the result of my_cpp_app eating file.in with file.out
# and store the comparison result in file.diff
diff ${f/.in/.out} <(my_cpp_app <$f 2>/dev/null) > ${f/.in/.diff}
done
Although I would probably do it with find / xargs pipeline which is not only safer but also allows parallel execution.
Or even write a Makefile for this and use make, which after all is a tool for exactly this kind of work.

How to pass a file using Xcode in arguments

Sorry about my poor English, I hope you can understand what I'm describing
I know how to pass arguments, like -v, -c, etc
Edit Scheme > Run xxx > Arguments
In Termimal.app, when I type the following, it shows the correct result, as expected.
./C_Product < main.c
How should I do this in Xcode?
I tried to add argument < main.c, but it did not affect.
I already copied main.c file to
C_Productxxxxx -> Build -> Products -> Debug
with C_Product at the same place
I don't know of a way to get Xcode to pipe the contents of a file to std in automatically. However, you do have some other options. You could modify your program to take the filename as an argument, and then pass in the filename as an argument as you have above. So you could make -i <foo> be the name of the input file. (Or better yet, -input-file <foo>.)
Alternatively, you could modify your application to read from a file whose path is in an environment variable. So your app could call getenv("MY_INPUT_FILE"); and you could tell Xcode to set the value of "MY_INPUT_FILE" environment variable to the path of the input file in the scheme.

Error on say when output format is wave

I am trying to create wave files using mac's say command, however, I get the following error:
$ say "hello" -o hi.wav
Opening output file failed: fmt?
although,
$ say --file-format=?
WAVE WAVE (.wav) [lpcm,ulaw,alaw]
Is there some way I can get say to output a wave file?
It infers the file format from the file extension, but you need to specify the data format:
say -o hi.wav --data-format=LEF32#22050 "hello"

How can I set up an Xcode build rule with a variable output file list?

Build Rules are documented in the Xcode Build System Guide
They are well adapted to the common case where one input file is transformed into a fixed number (usually one) of output files.
The output files must be described in the "Output Files" area of the build rule definition; one line per output file. Typically the output files have the same name as the input file but have different extensions.
In my case, one single input file is transformed into a variable number of files with the same extensions. The number and the names of the output files depend on the content of the input file and are not known in advance.
The output files will have to be further processed later on (they are in this case C files to be compiled).
How can I set up a build rule for such a case?
Any suggestions welcome.
(I asked the same question on the Apple developer forum, but I figured it'd be a good idea to ask here too).
I dealt with this by, instead of generating multiple C files, just concatenating them all together into one file (e.g. "AUTOGENERATED.c"), and specifying that as the output file.
So long as your output files don't contain anything that will conflict (static functions with the same name, conflicting #defines etc.) this works well.
See this article on Cocoa With Love:
http://cocoawithlove.com/2010/02/custom-build-rules-generated-tables-and.html
This has an example of generating custom C code and using that as input to the normal build process. He's using ${} variable syntax in the output
The best way I found to add any number of files to my xcode project (and make some processing) is to write a little php script. The script can simply copy files into the bundle. The tricky part is the integration with xcode. It took me some time to find a clean way. (You can use the script language you like with this method).
First, use "Add Run Script" instead of "Add Copy File"
Shell parameter:
/bin/sh
Command parameter:
${SRCROOT}/your_script.php -s ${SRCROOT} -o ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
exit $?
(screenshot in xcode)
${SRCROOT} is your project directory.
${CONFIGURATION(...) is the bundle directory. Exactly what you need :)
This way, your script return code can stop xcode build (use die(0) for success and die(1) for failures) and the output of script will be visible in xcode's build log.
Your script will look like that: (don't forget chmod +x on it)
#!/usr/bin/php
<?php
error_reporting(E_ALL);
$options = getopt("s:o:");
$src_dir = $options["s"]."/";
$output_dir = $options["o"]."/";
// process_files (...)
die(0);
?>
BONUS: here my 'add_file' function.
Note the special treatment for PNG (use apple's png compression)
Note the filemtime/touch usage to prevent copy files each times.
l
define("COPY_PNG", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/copypng -compress");
function add_file_to_bundle($output_dir, $filepath) {
// split path
$path_info = pathinfo($filepath);
$output_filepath = $output_dir.$path_info['basename'];
// get file's dates of input and output
$input_date = filemtime($filepath);
$output_date = #filemtime($output_filepath);
if ($input_date === FALSE) { echo "can't get input file's modification date"; die(1); }
// skip unchanged files
if ($output_date === $input_date) {
//message("skip ".$path_info['basename']);
return 0;
}
// special copy for png with apple's png compression tool
if (strcasecmp($path_info['extension'], "png") == 0) {
//message($path_info['basename']." is a png");
passthru(COPY_PNG." ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var);
if ($return_var != 0) die($return_var);
}
// classic copy
else {
//message("copy ".$path_info['basename']);
passthru("cp ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var);
if ($return_var != 0) die($return_var);
}
// important: set output file date with input file date
touch($output_filepath, $input_date, $input_date);
return 1;
}

Resources