@ -3,6 +3,7 @@
# include <iostream>
# include <sstream>
# include "qrcodegen.hpp"
# include "QR.hpp"
# define UNUSED(var) (void) var;
@ -12,20 +13,40 @@ constexpr const char* VERSION = "@qr_VERSION@";
void printHelp ( ) {
std : : string helpText = R " EOF(
( C ) 2023 , MikO < miko @ massivedynamic . eu >
– a tool for generating QR codes –
Released under MIT license .
Usage :
- f - - format output file format . can be one of " cli, png, svg, jpg, bmp "
- h - - help show this help
- i - - input take data from this argument instead of stdin
- o - - output output file name without extension
- s - - size desired output file size in pixels
- t - - type output QR code type . can be one of " small, medium, large "
In pixel based renderers ( i . e . PNG ) , the output size may not be exactly as
specified but be the nearest multiple of the actual cell size for the QR code .
qr is a tool for generating QR codes from the commandline
Usage : qr [ OPTION ] . . . - - input " data to encapsulate "
* Caveats *
With no ` - - input ` parameter defined , read STDIN
In pixel based renderers ( i . e . PNG ) , the output code may not be exactly
centered , as the amount of segment may not correspond to the specified
output size .
Options :
- f - - format output file format . can be one of " cli, png, svg, jpg, bmp "
- h - - help show this help
- i - - input take data from this argument instead of stdin
- o - - output output file name without extension
- s - - size desired output file size in pixels
- t - - type output QR code type . can be one of " small, medium, large "
- v - - version shows version info
Examples :
qr - i " this is from parameter " - f png - s 512 - o my_qrcode_file
echo " this is from stdin " | qr - t small - f png - s 512 - o my_qrcode_file_with_low_ecc
Copyright :
( C ) 2023 , MikO < miko @ massivedynamic . eu >
* License *
Released under MIT license
Report bugs and issues at out issue tracker :
https : //git.mike-ochmann.de/MassiveDynamic/qr/issues
) EOF " ;
std : : cout < < " qr " < < VERSION ;
std : : cout < < helpText < < std : : endl ;
@ -37,26 +58,27 @@ int main(int argc, char* argv[]) {
exit ( 1 ) ;
}
const option options [ ] = {
{ " help " , no_argument , nullptr , ' h ' } ,
{ " input " , required_argument , nullptr , ' i ' } ,
{ " output " , required_argument , nullptr , ' o ' } ,
{ " size " , required_argument , nullptr , ' s ' } ,
{ " type " , required_argument , nullptr , ' t ' } ,
{ " format " , required_argument , nullptr , ' f ' } ,
{ " help " , no_argument , nullptr , ' h ' } ,
{ " input " , required_argument , nullptr , ' i ' } ,
{ " output " , required_argument , nullptr , ' o ' } ,
{ " size " , required_argument , nullptr , ' s ' } ,
{ " type " , required_argument , nullptr , ' t ' } ,
{ " format " , required_argument , nullptr , ' f ' } ,
{ " version " , no_argument , nullptr , ' v ' } ,
{ nullptr }
} ;
std : : string outputFile ;
std : : string paramData ;
size_t segmentSize = 0 ;
massivedynamic : : Type type = massivedynamic : : Type : : MEDIUM ;
massivedynamic : : Format format = massivedynamic : : Format : : CONSOLE ;
bool fromStdin = true ;
bool anyParameterSet = false ;
std : : string paramData = " " ;
qrcodegen : : QrCode : : Ecc type = qrcodegen : : QrCode : : Ecc : : LOW ;
massivedynamic : : Format format = massivedynamic : : Format : : CONSOLE ;
for ( ; ; ) {
int index = - 1 ;
int result = getopt_long ( argc , argv , " ho:s:t:f:i: " , options , & index ) ;
int result = getopt_long ( argc , argv , " v ho:s:t:f:i:" , options , & index ) ;
if ( result = = - 1 )
break ;
@ -77,12 +99,13 @@ int main(int argc, char* argv[]) {
case ' t ' : {
std : : string value = optarg ;
if ( value = = " small " )
type = massivedynamic : : Type : : SMALL ;
type = qrcodegen : : QrCode : : Ecc : : LOW ;
else if ( value = = " medium " )
type = massivedynamic : : Type : : MEDIUM ;
type = qrcodegen : : QrCode : : Ecc : : MEDIUM ;
else if ( value = = " large " )
type = massivedynamic : : Type : : LARGE ;
type = qrcodegen : : QrCode : : Ecc : : HIGH ;
else {
std : : cerr < < " ERROR: type (-t, --type) has to be one of 'small', 'medium' or 'large' " < < std : : endl ;
printHelp ( ) ;
return 1 ;
}
@ -112,6 +135,10 @@ int main(int argc, char* argv[]) {
paramData = optarg ;
break ;
}
case ' v ' : {
std : : cout < < " qr " < < VERSION < < std : : endl ;
exit ( 0 ) ;
}
case ' h ' :
default :
printHelp ( ) ;
@ -152,7 +179,8 @@ int main(int argc, char* argv[]) {
return 1 ;
}
std : : unique_ptr < massivedynamic : : QR > qr = std : : make_unique < massivedynamic : : QR > ( data . str ( ) , outputFile , segmentSize , type , format ) ;
std : : unique_ptr < massivedynamic : : QR > qr = std : : make_unique < massivedynamic : : QR > ( data . str ( ) , outputFile , segmentSize , type ) ;
qr - > render ( format ) ;
return 0 ;
}
}