is there a way to choose the width of a pdf created from a txt file with cupsfilter - cups

i try to find a command line to convert files .txt to .pdf using a tool that most computer running on mac and linux have, like (i think) cupsfilter. but I can't seem to control the width of the output
I don't understand how cupsfilter choose the format it chould print, like how much characters define the width in the text file, it seems to be 80. But the output of 80 characters width on a A4 size page looks absurdely huge..
if my text looks like this :
|_| |_| | || |_ | | / . \ | |
_ _ _ _ _ _ _ _ _ _ _ _ _| || _|| |_ \ / | | |
/_ _ || |\_ _ \| ._ _| \ \ / /| || ( ] || | | _ \ / . \ | | |
/_ _ /|_|\_ _ \ \ _ _| \_/\_/ |_| \ _ _||_| |_| |_| \_ _/ |_ _|
the command cupsfilter file.txt > file.pdf will give me the same look, but in huge, in pdf format
however, if my text is longer it will look like this :
_ _ _ _
|_| |_| | || |_ | |
/ . \ | |
_ _ _ _ _ _ _ _ _ _ _ _ _| || _|| |_
\ / | | |
/_ _ || |\_ _ \| ._ _| \ \ / /| || ( ] || | | _ \
/ . \ | | |
/_ _ /|_|\_ _ \ \ _ _| \_/\_/ |_| \ _ _||_| |_| |_|
\_ _/ |_ _|
I would tel cupsfilter to consider a page width to be more than 80 characters long, or to use another tool to do that ?

Related

Solidity: How to represent bytes32 as string

This may be simple in other languages but I can't figure out how to do it in Solidity.
I have a bytes32 like this 0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712.
I don't want to convert the bytes to a string, rather I just want to represent the whole thing as a string, like "0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712".
How can this be done in Solidity?
Update:
Why I need to do this: Basically I connect to an oracle, which does some work off-chain and finally uploads a file to IPFS. I need to get the content identifier into my contract from the oracle. The oracle can only send bytes32 as a response, so I convert it to a multihash and send only the digest as bytes32 from oracle to contract.
So far so good, I can recreate the multihash in my contract. The problem is that after this I create an ERC721 (NFT) token and I have to store some reference to the IPFS file in the metadata, which can only be in string format. This is where I'm stuck at the moment.
While the answer from #Burt looks correct (didn't test it though), there is a much more efficient way to solve the same task:
function toHex16 (bytes16 data) internal pure returns (bytes32 result) {
result = bytes32 (data) & 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000 |
(bytes32 (data) & 0x0000000000000000FFFFFFFFFFFFFFFF00000000000000000000000000000000) >> 64;
result = result & 0xFFFFFFFF000000000000000000000000FFFFFFFF000000000000000000000000 |
(result & 0x00000000FFFFFFFF000000000000000000000000FFFFFFFF0000000000000000) >> 32;
result = result & 0xFFFF000000000000FFFF000000000000FFFF000000000000FFFF000000000000 |
(result & 0x0000FFFF000000000000FFFF000000000000FFFF000000000000FFFF00000000) >> 16;
result = result & 0xFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000 |
(result & 0x00FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF0000) >> 8;
result = (result & 0xF000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000) >> 4 |
(result & 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00) >> 8;
result = bytes32 (0x3030303030303030303030303030303030303030303030303030303030303030 +
uint256 (result) +
(uint256 (result) + 0x0606060606060606060606060606060606060606060606060606060606060606 >> 4 &
0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F) * 7);
}
function toHex (bytes32 data) public pure returns (string memory) {
return string (abi.encodePacked ("0x", toHex16 (bytes16 (data)), toHex16 (bytes16 (data << 128))));
}
This code produces upper case output. For lower case output, just change 7 to 39 in the code.
Explanation
The idea is to process 16 bytes at once using binary operations.
The toHex16 function converts a sequence of 16 bytes represented as a bytes16 value into a sequence of 32 hexadecimal digits represented as a bytes32 value. The toHex function splits a bytes32 value into two bytes16 chunks, converts each chunk to hexadecimal representation via the toHex16 function, and finally concatenates the 0x prefix with the converted chunks using abi.encodePacked function.
The most sophisticated part is how the toHex16 function works. Let's explain it sentence by sentence.
The first sentence:
result = bytes32 (data) & 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000 |
(bytes32 (data) & 0x0000000000000000FFFFFFFFFFFFFFFF00000000000000000000000000000000) >> 64;
Here we shift the last 64 bits of the input to the right by 64 bits, basically doing:
0123456789abcdeffedcba9876543210
\______________/\______________/
| |
| +---------------+
______V_______ ______V_______
/ \ / \
0123456789abcdef0000000000000000fedcba9876543210
The second sentence:
result = result & 0xFFFFFFFF000000000000000000000000FFFFFFFF000000000000000000000000 |
(result & 0x00000000FFFFFFFF000000000000000000000000FFFFFFFF0000000000000000) >> 32;
Here we shift the last 32 bits of both 64-bit chunks to the right by 32 bits:
0123456789abcdef0000000000000000fedcba9876543210
\______/\______/ \______/\______/
| | | |
| +-------+ | +-------+
__V___ __V___ __V___ __V___
/ \ / \ / \ / \
012345670000000089abcdef00000000fedcba980000000076543210
The next sentence:
result = result & 0xFFFF000000000000FFFF000000000000FFFF000000000000FFFF000000000000 |
(result & 0x0000FFFF000000000000FFFF000000000000FFFF000000000000FFFF00000000) >> 16;
does:
012345670000000089abcdef00000000fedcba980000000076543210
\__/\__/ \__/\__/ \__/\__/ \__/\__/
| | | | | | | |
| +---+ | +---+ | +---+ | +---+
V_ V_ V_ V_ V_ V_ V_ V_
/ \ / \ / \ / \ / \ / \ / \ / \
012300004567000089ab0000cdef0000fedc0000ba980000765400003210
And the next one:
result = result & 0xFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000 |
(result & 0x00FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF0000) >> 8;
does:
012300004567000089ab0000cdef0000fedc0000ba980000765400003210
\/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/
| | | | | | | | | | | | | | | |
| +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+
V V V V V V V V V V V V V V V V
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
01002300450067008900ab00cd00ef00fe00dc00ba00980076005400320010
The final sentence in this series is a bit different:
result = (result & 0xF000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000) >> 4 |
(result & 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00) >> 8;
It shifts odd nibbles to the right by 4 bits, and even nibbles by 8 bits:
01002300450067008900ab00cd00ef00fe00dc00ba00980076005400320010
|\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\ |\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
000102030405060708090a0b0c0d0e0f0f0e0d0c0b0a09080706050403020100
So all the nibbles of the initial data are distributed one per byte.
Now with every byte x we need to do the following transformation:
x` = x < 10 ? '0' + x : 'A' + (x - 10)
Let's rewrite this formula a bit:
x` = ('0' + x) + (x < 10 ? 0 : 'A' - '0' - 10)
x` = ('0' + x) + (x < 10 ? 0 : 1) * ('A' - '0' - 10)
Note, that (x < 10 ? 0 : 1) could be calculated as ((x + 6) >> 4), thus we have:
x` = ('0' + x) + ((x + 6) >> 4) * ('A' - '0' - 10)
x` = (0x30 + x) + ((x + 0x06) >> 4) * 7
The final statement:
result = bytes32 (0x3030303030303030303030303030303030303030303030303030303030303030 +
uint256 (result) +
(uint256 (result) + 0x0606060606060606060606060606060606060606060606060606060606060606 >> 4 &
0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F) * 7);
Basically performs the above calculation for every byte. The
0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F
mask after the right shift is needed to zero out the bits "dropped" by the right shift in the original formula.
BTW, it would be better to ask questions like this one at https://ethereum.stackexchange.com/
Function bytes32ToString turns a bytes32 to hex string
function bytes32ToString(bytes32 _bytes32) public pure returns (string memory) {
uint8 i = 0;
bytes memory bytesArray = new bytes(64);
for (i = 0; i < bytesArray.length; i++) {
uint8 _f = uint8(_bytes32[i/2] & 0x0f);
uint8 _l = uint8(_bytes32[i/2] >> 4);
bytesArray[i] = toByte(_f);
i = i + 1;
bytesArray[i] = toByte(_l);
}
return string(bytesArray);
}
function toByte(uint8 _uint8) public pure returns (byte) {
if(_uint8 < 10) {
return byte(_uint8 + 48);
} else {
return byte(_uint8 + 87);
}
}

U-Boot with OpenSBI on HiFive Unleashed in QEMU: Store/AMO access fault

I've been trying to get U-Boot to work in QEMU for the sifive_u machine. I've tried using both the built in OpenSBI 'BIOS' and building my own OpenSBI, but I keep running into the same issue.
I'm building U-Boot using the riscv64 toolchain from the Arch repos:
➜ u-boot git:(0b0c6af387) riscv64-linux-gnu-gcc --version
riscv64-linux-gnu-gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
➜ u-boot git:(0b0c6af387) export CROSS_COMPILE=riscv64-linux-gnu-
➜ u-boot git:(0b0c6af387) export ARCH=riscv
➜ u-boot git:(0b0c6af387) make sifive_fu540_defconfig
...
➜ u-boot git:(0b0c6af387) make
I've tried to run this as follows:
➜ opensbi git:(master) ✗ qemu-system-riscv64 -M sifive_u -m 256M -bios default -display none -serial stdio -device loader,addr=0x80200000,file=../u-boot/u-boot.bin
OpenSBI v0.5 (Oct 9 2019 12:03:04)
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 5
Current Hart : 1
Firmware Base : 0x80000000
Firmware Size : 96 KB
Runtime SBI Version : 0.2
PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.01 (Jan 20 2020 - 18:14:27 +0000)
CPU: rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM: exception code: 7 , Store/AMO access fault , epc 8023cbdc , ra 8020c670
### ERROR ### Please RESET the board ###
I've also tried bundling U-Boot as a payload into my own build of OpenSBI:
➜ opensbi git:(master) ✗ export CROSS_COMPILE=riscv64-unknown-elf-
➜ opensbi git:(master) ✗ make PLATFORM=sifive/fu540 FW_PAYLOAD_PATH=../u-boot/u-boot.bin
➜ opensbi git:(master) ✗ qemu-system-riscv64 -M sifive_u -m 256M -bios none -display none -serial stdio -device loader,addr=0x80000000,file=./build/platform/sifive/fu540/firmware/fw_payload.bin
OpenSBI v0.5-32-gc0849cd
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 5
Current Hart : 1
Firmware Base : 0x80000000
Firmware Size : 100 KB
Runtime SBI Version : 0.2
PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.01 (Jan 20 2020 - 18:14:27 +0000)
CPU: rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM: exception code: 7 , Store/AMO access fault , epc 8023cbdc , ra 8020c670
### ERROR ### Please RESET the board ###
I've tried looking at the offending instruction (which I presume is at 0x8023cbdc) based on the error message:
➜ u-boot git:(0b0c6af387) riscv64-unknown-elf-objdump --start-address=0x8023cbdc -d ./u-boot | head -8
./u-boot: file format elf64-littleriscv
Disassembly of section .text_rest:
000000008023cbdc <memset+0x40>:
8023cbdc: fee7bc23 sd a4,-8(a5)
It's a store, so it's plausible that this is indeed accessing an invalid location; I'm trying to get GDB working so I can examine what's actually happening in more detail, but that's causing issues of its own...
Has anyone had any success with this?
UPDATE
I've managed to fix this specific error by changing the amount of memory with -M 2G; I presume the address it's trying to access lies outside the 256M range, but I'm not sure what it's doing that requires this much RAM.
Now I'm getting the following error:
➜ opensbi git:(master) ✗ qemu-system-riscv64 -M sifive_u -m 8G -bios default -display none -serial stdio -device loader,addr=0x80200000,file=../u-boot/u-boot-dtb.bin
OpenSBI v0.5 (Oct 9 2019 12:03:04)
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 5
Current Hart : 1
Firmware Base : 0x80000000
Firmware Size : 96 KB
Runtime SBI Version : 0.2
PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.01 (Jan 20 2020 - 21:40:02 +0000)
CPU: rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM: 8 GiB
MMC: exception code: 5 , Load access fault , epc fffadbd6 , ra fffadbd2
### ERROR ### Please RESET the board ###
qemu-system-riscv64: terminating on signal 2
Again it's similar (although a load this time); interestingly, the address fffadbd6 isn't part of U-Boot so I've no idea what's happening here; I very much doubt it's running off the end, because then I would expect undefined behaviour as opposed to consistently getting the same bad load.

BASH for loop with find, set variables from command output, then insert into mysql db

I have 256 directories, each with approximately 55,000 dicom files (these are NOT text files). Each file has meta data that I need to extract, set specified variables, then insert into mysql (actually MariaDB).
I need to keep the original files as is, so first I copy the files from one of the 256 directories from attached storage to a local directory, do another processing item, then go through the list and process each file. The copy and first process took about 20 minutes.
Afterwards I delete all the files locally, then go to the next directory.
Below is the part I think could be optimized, but I'm not sure how... if it was a one-liner process sure, but I think too much has to happen.
I set a variable (all-tags) by taking the output of the dcm2txt command against a file ($i), then set the variables that I need "re-echoing" for each. Is this the most efficient way? The test directory I just processed took a bit over 3 hours for about 55,000 files including 20 minutes to copy and first process, so this part took 2 hours 40 minutes. Only 255 directories to go....
logger -t "admin" "loc 2: Truncating files in $PROCESS_DIR"
find $PROCESS_DIR -type f -print0 | xargs -0 /usr/bin/truncate -s -512 {}
cd $PROCESS_DIR
for i in `find . -type f -printf '%f\n'`
do
all_tags=$(/home/admin/securecloud/dcm4che-2.0.29/bin/dcm2txt -w 150 $i)
VARsrc_aet=$(echo "$all_tags" | awk '/0002,0016/' | cut -d "[" -f2 | cut -d "]" -f1)
VARsop_cuid=$(echo "$all_tags" | awk '/0008,0016/' | cut -d "[" -f2 | cut -d "]" -f1)
VARsop_iuid=$(echo "$all_tags" | awk '/0008,0018/' | cut -d "[" -f2 | cut -d "]" -f1)
VARstudy_date=$(echo "$all_tags" | awk '/0008,0020/' | cut -d "[" -f2 | cut -d "]" -f1)
VARacquis_date=$(echo "$all_tags" | awk '/0008,0022/' | cut -d "[" -f2 | cut -d "]" -f1)
VARcontent_date=$(echo "$all_tags" | awk '/0008,0023/' | cut -d "[" -f2 | cut -d "]" -f1)
VARstudy_time=$(echo "$all_tags" | awk '/0008,0030/' | cut -d "[" -f2 | cut -d "]" -f1)
VARacqis_time=$(echo "$all_tags" | awk '/0008,0032/' | cut -d "[" -f2 | cut -d "]" -f1)
VARcontent_time=$(echo "$all_tags" | awk '/0008,0033/' | cut -d "[" -f2 | cut -d "]" -f1)
VARaccession_no=$(echo "$all_tags" | awk '/0008,0050/' | cut -d "[" -f2 | cut -d "]" -f1)
VARmodality=$(echo "$all_tags" | awk '/0008,0060/' | cut -d "[" -f2 | cut -d "]" -f1)
VARinstitution=$(echo "$all_tags" | awk '/0008,0080/' | cut -d "[" -f2 | cut -d "]" -f1)
VARseries_desc=$(echo "$all_tags" | awk '/0008,103E/' | cut -d "[" -f2 | cut -d "]" -f1)
VARops_name=$(echo "$all_tags" | awk '/0008,1070/' | cut -d "[" -f2 | cut -d "]" -f1)
VARmanu_model=$(echo "$all_tags" | awk '/0008,1090/' | cut -d "[" -f2 | cut -d "]" -f1)
VARpat_name=$(echo "$all_tags" | awk '/0010,0010/' | cut -d "[" -f2 | cut -d "]" -f1)
VARpat_id=$(echo "$all_tags" | awk '/0010,0020/' | cut -d "[" -f2 | cut -d "]" -f1)
VARpat_birthdate=$(echo "$all_tags" | awk '/0010,0030/' | cut -d "[" -f2 | cut -d "]" -f1)
VARpat_comments=$(echo "$all_tags" | awk '/0010,4000/' | cut -d "[" -f2 | cut -d "]" -f1)
VARstudy_iuid=$(echo "$all_tags" | awk '/0020,000D/' | cut -d "[" -f2 | cut -d "]" -f1)
VARseries_iuid=$(echo "$all_tags" | awk '/0020,000E/' | cut -d "[" -f2 | cut -d "]" -f1)
VARstudy_id=$(echo "$all_tags" | awk '/0020,0010/' | cut -d "[" -f2 | cut -d "]" -f1)
VARseries_no=$(echo "$all_tags" | awk '/0020,0011/' | cut -d "[" -f2 | cut -d "]" -f1)
VARinst_no=$(echo "$all_tags" | awk '/0020,0013/' | cut -d "[" -f2 | cut -d "]" -f1)
DB_NAME=ingestion_dir
TABLE=dicom_files
mysql -uname -ppassword $DB_NAME <<EOF
INSERT INTO $TABLE (src_aet,sop_cuid,sop_iuid,study_date,acquis_date,content_date,study_time,acqis_time,\
content_time,accession_no,modality,institution,series_desc,ops_name,manu_model,pat_name,\
pat_id,pat_birthdate,pat_comments,study_iuid,series_iuid,study_id,series_no,inst_no,filename) \
VALUES \
( "$VARsrc_aet", "$VARsop_cuid","$VARsop_iuid", "$VARstudy_date", "$VARacquis_date", "$VARcontent_date", "$VARstudy_time", "$VARacqis_time", \
"$VARcontent_time", "$VARaccession_no", "$VARmodality", "$VARinstitution", "$VARseries_desc", "$VARops_name", "$VARmanu_model", "$VARpat_name", \
"$VARpat_id", "$VARpat_birthdate", "$VARpat_comments", "$VARstudy_iuid", "$VARseries_iuid", "$VARstudy_id", "$VARseries_no", "$VARinst_no", "$i" );
EOF
done

How to create big style comment for HTML templates

If you look at the source code of some HTML sites, they use some giant alphabets to comment out or to provide their site name. Something where you write the word and it converts to to HTML like below:
<!--
------
-
---
-
------
!-->
anyone know how to create these types of comments?
Just Google "Big ASCII text art" and you'll find several online generators.
For example, here's one from bigtext.org:
_ _
/ \ __| | __ _ _ __ ___
/ _ \ / _` |/ _` | '_ ` _ \
/ ___ \ (_| | (_| | | | | | |
/_/ \_\__,_|\__,_|_| |_| |_|
Here's another website that lets you customize the font and a few other things. Example (using the font 'tinker-toy'):
O o
/ \ |
o---o o-O oo o-O-o
| || | | | | | |
o o o-o o-o-o o o

How can I create large ASCII text from a string?

Given a string, for example 'imgur', how can I generate large ASCII text like the following? Thanks.
_
(_)
_ _ __ ___ __ _ _ _ _ __
| | '_ ` _ \ / _` | | | | '__|
| | | | | | | (_| | |_| | |
|_|_| |_| |_|\__, |\__,_|_|
__/ |
|___/
You can use ASCII text generator like FIGlet which uses FIGlet fonts. TOIlet is like FIGlet and can use FIGlet fonts but as additional capabilities including Unicode handling, colour fonts, filters and various export formats. Specific logos may need to be created as their own font.
Here are some links:
FIGlet: http://www.figlet.org/
TOIlet: https://apps.ubuntu.com/cat/applications/toilet/
FIGlet fonts: http://www.figlet.org/fontdb.cgi
FIGlet web demo: http://www.kammerl.de/ascii/AsciiSignature.php