mosquitto_sub now supports extra format specifiers.

These are for field width and precision for some parameters.
This commit is contained in:
Roger A. Light
2020-08-28 22:23:22 +01:00
parent 18e79eac22
commit bab8cc2a6b
6 changed files with 481 additions and 184 deletions
+2
View File
@@ -56,6 +56,8 @@ Clients:
of received messages to be printed.
- mosquitto_sub %j and %J timestamps are now in a ISO 8601 compatible format.
- mosquitto_pub now sends 0 length files without an error when using `-f`.
- mosquitto_sub now supports extra format specifiers for field width and
precision for some parameters.
1.6.9 - 20200227
+39
View File
@@ -55,6 +55,45 @@ static int check_format(const char *str)
fprintf(stderr, "Error: Incomplete format specifier.\n");
return 1;
}else{
if(str[i+1] == '0' || str[i+1] == '-'){
/* Flag characters */
i++;
if(i == len-1){
// error
fprintf(stderr, "Error: Incomplete format specifier.\n");
return 1;
}
}
/* Field width */
while(str[i+1] >= '0' && str[i+1] <= '9'){
i++;
if(i == len-1){
// error
fprintf(stderr, "Error: Incomplete format specifier.\n");
return 1;
}
}
if(str[i+1] == '.'){
/* Precision specifier */
i++;
if(i == len-1){
// error
fprintf(stderr, "Error: Incomplete format specifier.\n");
return 1;
}
/* Precision */
while(str[i+1] >= '0' && str[i+1] <= '9'){
i++;
if(i == len-1){
// error
fprintf(stderr, "Error: Incomplete format specifier.\n");
return 1;
}
}
}
if(str[i+1] == '%'){
// Print %, ignore
}else if(str[i+1] == 'A'){
+312 -167
View File
File diff suppressed because it is too large Load Diff
+59
View File
@@ -0,0 +1,59 @@
LD_LIBRARY_PATH=../lib ./mosquitto_sub \
-h test.mosquitto.org \
--retained-only \
--remove-retained \
-t FW/# \
-W 1>/dev/null 2>/dev/null
LD_LIBRARY_PATH=../lib ./mosquitto_pub \
-h test.mosquitto.org \
-D publish content-type "application/json" \
-D publish message-expiry-interval 360000 \
-D publish payload-format-indicator 1 \
-D publish response-topic response-topic \
-m ABCDEFGHIJKLMNOPQRSTUVWXYZ \
-q 2 \
-r \
-t FW/truncate \
-V 5
LD_LIBRARY_PATH=../lib ./mosquitto_pub \
-h test.mosquitto.org \
-D publish content-type "null" \
-D publish message-expiry-interval 3600 \
-D publish payload-format-indicator 1 \
-D publish response-topic r-t \
-m Off \
-q 2 \
-r \
-t FW/expire \
-V 5
LD_LIBRARY_PATH=../lib ./mosquitto_pub \
-h test.mosquitto.org \
-D publish payload-format-indicator 1 \
-D publish response-topic rt \
-m Offline \
-q 2 \
-r \
-t FW/1 \
-V 5
LD_LIBRARY_PATH=../lib ./mosquitto_sub \
-h test.mosquitto.org \
-C 3 \
-F "| %10t | %-10t | %7x | %-7x | %08x | %7X | %-7X | %08X | %8p | %-8p | %3m | %-3m | %03m | %3l | %-3l | %03l | %2F | %-2F | %02F | %5C | %-5C | %5E | %-5E | %05E | %5A | %5R | %-5R |" \
-q 2 \
-t 'FW/#' \
-V 5
echo
LD_LIBRARY_PATH=../lib ./mosquitto_sub \
-h test.mosquitto.org \
-C 3 \
-F "| %10.10t | %.5t | %-10.10t | %7x | %-7x | %08x | %7X | %-7X | %08X | %8p | %-8p | %3m | %-3m | %03m | %3l | %-3l | %03l | %2F | %-2F | %02F | %5C | %-5C | %5E | %-5E | %05E | %5.5A | %5.5R | %-5.5R |" \
-q 2 \
-t 'FW/#' \
-V 5
+16 -16
View File
@@ -50,32 +50,32 @@ uninstall :
-rm -f "${DESTDIR}${mandir}/man7/mosquitto-tls.7"
-rm -f "${DESTDIR}${mandir}/man3/libmosquitto.3"
mosquitto.8 : mosquitto.8.xml
$(XSLTPROC) $^
mosquitto.8 : mosquitto.8.xml manpage.xsl
$(XSLTPROC) $<
mosquitto.conf.5 : mosquitto.conf.5.xml manpage.xsl
$(XSLTPROC) $<
mosquitto_passwd.1 : mosquitto_passwd.1.xml
$(XSLTPROC) $^
mosquitto_passwd.1 : mosquitto_passwd.1.xml manpage.xsl
$(XSLTPROC) $<
mosquitto_pub.1 : mosquitto_pub.1.xml
$(XSLTPROC) $^
mosquitto_pub.1 : mosquitto_pub.1.xml manpage.xsl
$(XSLTPROC) $<
mosquitto_sub.1 : mosquitto_sub.1.xml
$(XSLTPROC) $^
mosquitto_sub.1 : mosquitto_sub.1.xml manpage.xsl
$(XSLTPROC) $<
mosquitto_rr.1 : mosquitto_rr.1.xml
$(XSLTPROC) $^
mosquitto_rr.1 : mosquitto_rr.1.xml manpage.xsl
$(XSLTPROC) $<
mqtt.7 : mqtt.7.xml
$(XSLTPROC) $^
mqtt.7 : mqtt.7.xml manpage.xsl
$(XSLTPROC) $<
mosquitto-tls.7 : mosquitto-tls.7.xml
$(XSLTPROC) $^
mosquitto-tls.7 : mosquitto-tls.7.xml manpage.xsl
$(XSLTPROC) $<
libmosquitto.3 : libmosquitto.3.xml
$(XSLTPROC) $^
libmosquitto.3 : libmosquitto.3.xml manpage.xsl
$(XSLTPROC) $<
html : *.xml
set -e; for m in *.xml; \
+53 -1
View File
@@ -790,7 +790,7 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained</programlisting>
</refsect1>
<refsect1 id='outputformat'>
<title>Output format</title>
<title>Output Format</title>
<para>There are three ways of formatting the output from mosquitto_sub.
In all cases a new-line character is appended for each message
received unless the <option>-N</option> argument is passed to
@@ -824,6 +824,58 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained</programlisting>
character is <option>\</option>, which is used to input some
characters that would otherwise be difficult to enter.</para>
<refsect2>
<title>Flag characters</title>
<para>The parameters %A, %C, %E, %F, %I, %l, %m, %p, %R, %S, %t, %x, and %X can have optional flags immediately after the % character.</para>
<variablelist>
<varlistentry>
<term><option>0</option></term>
<listitem><para>The value should be zero padded.
This applies to the parameters %A, %E, %F, %l, %m, %S, %X, and %x.
It will be ignored for other parameters. If used with the
<option>-</option> flag, the <option>0</option> flag will be
ignored.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-</option></term>
<listitem><para>The value will be left aligned to the field width,
padded with blanks. The default is right alignment, with either 0
or blank padding.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2>
<title>Field width</title>
<para>
Some of the MQTT related parameters can be formatted with an
option to set their field width in a similar way to regular
printf style formats, i.e. this sets the minimum width when
printing this parameter. This applies to the options %A, %C,
%E, %F, %I, %l, %m, %p, %R, %S, %t, %x, %X.
</para>
<para>
For example <option>%10t</option> would set the minimum topic
field width to 10 characters.
</para>
</refsect2>
<refsect2>
<title>Maximum width</title>
<para>
Some of the MQTT related parameters can be formatted with an
option to set a maximum field width in a similar way to regular
printf style formats. This applies to the options %C, %I, %R, %t.
</para>
<para>
For example <option>%10.10t</option> would set the minimum topic
field width to 10 characters, and the maximum topic width to
10 characters, i.e. the field will always be exactly 10
characters long.
</para>
</refsect2>
<refsect2>
<title>MQTT related parameters</title>
<itemizedlist mark="circle">