Quartus: Add dependencies from external file - fpga

I have lots of FPGA projects and some generic components shared among them. I’m searching for a way to add these components through an external file, so I can easily add new components to all my projects.
I’ve moved all the
set_global_assignment -name VHDL_FILE x.vhd
set_global_assignment -name VHDL_FILE y.vhd
statements from the QSF to a separate TCL file and included it using
set_global_assignment -name SOURCE_TCL_SCRIPT_FILE library.tcl
This is almost what I want, but when modifying the file list from the GUI all components from this TCL script are added to the QSF file again. Is there a way to prevent this?

Could you do something like use TCL in the QSF to create a series of statements programatically from a manifest file that contains a list of files you need:
proc readData {filename} {
set f [open $filename r]
foreach line [split [read $f] \n] {
set_global_assignment -name VHDL_FILE $line
}
}

Related

making text files containing list of files in different directories with random name in bash

I have a script which makes some files in pair (all the resulting files have either R1 OR R2 in the file name) and then put each pair in a separate directory with random name (every time will be different and I cannot predict). for example if I have 6 files, 3 files would be file_R1.txt or file_R2.txt but in pair like this example:
s1_R1.txt and s1_R2.txt
s2_R1.txt and s2_R2.txt
s3_R1.txt and s3_R2.txt
In this example I will have 3 directories (one per pair of files). I want to make 2 text file (d1.txt and. d2.txt) containing above file names. In fact, d1.txt will have all the files with R1 and d2.txt will contain all the files with R2. To do so, I made the following short bash code but it does not return what I want. Do you know how to fix it?
For file in /./*R*.txt;
do;
touch "s1.txt"
touch "s2.txt"
echo "${fastq}" >> "s1.txt"
done
Weird question, not sure I get it, but for your d1 and d2 files:
#!/bin/bash
find . -type f -name "*R1*" -print >d1.txt
find . -type f -name "*R2*" -print >d2.txt
find is used since you have files under different sub-directories.
Using > ensures the text files are emptied out if they already exist.
Note the code you put in your question is not valid bash.

How to loop through the result of find in bash and perform operations on each of them

I am very new to bash scripting. I need to perform same operation on 300 files. I have tried the following so far:
empty_files=$(find ./ -type f -empty)
echo "$empty_files"
Now I have the full path to all the 300 files, stored in variable empty_files.
Now what I want to do is, for each file in the result
go to it's parent's parent directory,
then go to the other child (sibling of earlier file's parent directory) and find a file by name 'abc.js' inside it
Now, inside abc.js, find a particular word (object property) "user"
now on the new line, insert a line of js code. (exact same code for all files)
Please let me know if it's possible from mac command line.
Thanks
You can use a for loop:
for file in "${empty_files[#]}"
do
... code that uses "$file"
done
You could also pipe directly from find into the loop:
find . -type f -empty | while read -r file
do
... code that uses "$file"
done
This version should work for any filenames that don't contain newline.

Why is my bash randomly selecting files and renaming?

On my Mac I am terminal scripting an increment rename of some files in a folder. The files have a number at the end but from a top down approach they are in order:
foobar101.png
foobar107.png
foobar115.png
foobar121.png
foobar127.png
foobar133.png
foobar141.png
foobar145.png
foobar151.png
foobar155.png
When I create and run my loop it works:
DIR="/customlocation/on/mac"
add=1;
for thefile in $(find $DIR -name "*.png" ); do
cd $DIR
mv -v "${thefile}" foobar"${add}".png
((add++))
done
However, when it runs the increment it's not as expected:
foobar101.png -> need foobar1.png but is foobar10.png
foobar107.png -> need foobar2.png but is foobar3.png
foobar115.png -> need foobar3.png but is foobar4.png
foobar121.png -> need foobar4.png but is foobar2.png
foobar127.png -> need foobar5.png but is foobar9.png
foobar133.png -> need foobar6.png but is foobar6.png
foobar141.png -> need foobar7.png but is foobar1.png
foobar145.png -> need foobar8.png but is foobar5.png
foobar151.png -> need foobar9.png but is foobar8.png
foobar155.png -> need foobar10.png but is foobar7.png
Ive tried searching on SO, Linux/Unix, Ask Ubuntu, and SuperUser but I don't see any questions that solve the issue of controlling the increment and I dont know if it's something in particular I should be looking at. So how can I control the increment from the lowest number/filename instead of the Mac possibly randomly renaming with an increment so I get the desired output?
EDIT:
After a comment from Etan I was looking into the numerical values at the end and some of the files are named foobarXXXX and that is the issue. The below answer, while awesome and a new approach I will look into still produces the same outcome because of some other files. If I remove all files that are foobarXXXX and only leave files with values of foobarXXX my code and the code in fedorqui's answer work. Is there a way then I can target this while in the loop process or do I have to target all names and test to see the length of values and adjust accordingly?
You cannot rely on the order of a find command, which uses the order that the VFS gives them to it in.
You may, instead, want to sort it:
DIR="/customlocation/on/mac"
add=1;
while IFS= read -r thefile; do
cd $DIR
mv -v "${thefile}" foobar"${add}".png
((add++))
done < <(find $DIR -name "*.png" | sort)
#-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note this uses process substitution, which feed the while loop:
Process substitution is a form of redirection where the input or
output of a process (some sequence of commands) appear as a temporary
file.

Formatting multiple json files recursively

This is a theoretical question about minimizing side effects in bash scripting.
I recently used a simple mechanism for formatting a bunch of json files, in a nested directory structure...
for f in `find ./ -name *json`; do echo $f ; python -mjson.tool $f > /tmp/1 && cp /tmp/1 $f ; done.
The mechanism is simply to
format each file using python's mjson.tool,
write it to a tmp location, and
then rewrite it back in place.
Is there a way to do this which is more elegant, i.e. with minimal side effects? I'm assuming bash experts have a better way of doing this sort of thing .
Unix tools working on a streaming basis -- they don't store all of the contents of the files in memory at once. Therefore, you have to use an intermediary location since you would be overwriting a file that is currently being read from.
You may consider that your snippet isn't fault tolerant. If you make a mistake, you would have just overwritten all your data. You should store the output in a new location, verify, then move to overwrite. :)
Using Eclipse IDE we can achieve formatting for multiple JSON files
Import the files into eclipse and select the files (you wish to format) or folder(for all the files) and right click -> source -> format
I was looking for something similar and just noticed I can select all JSON files I have in my VSCode file panel and CTRL + Click > "Format". Works like magic for a one-off operation, it's formatting the files in-place.
VSCode format in action

How to add a new mime-type to the 'file' command

I use the following command to create a list of files and their mime-type's, to be used in a script to generate a content.opf file for an epub (OSX 10.6.8).
find * -type f -exec file {} --mime-type \;
The result is as follows:
...
OEBPS/cover.xhtml: application/xml
OEBPS/css/style.css: text/x-c
OEBPS/img/cover.png: image/png
...
The second item is not what I expected: it should list as:
OEBPS/css/style.css: text/css
The file man page says the value is read from definitions in /usr/share/file/magic and indeed there is no css definition there. Does anyone know how I can add one myself? I cannot find a manual to write these.
Before this approach I used a grep pattern to write the mime type, but I thought this would be a 'nicer' way of doing things...

Resources