VSCode Accessing Local Created Variable in Natvis [duplicate] - vscode-debugger

I am developing some debug visualizations for my custom classes in VSCode using Natvis.
Using CustomListItems with a simple example and I can't get it to work.
Basically, I think the following code should display 16 items all with value 1 but I get only the basic type of the class..
<Type Name="vq23_t">
<DisplayString>16 x q23 Array</DisplayString>
<Expand>
<CustomListItems>
<Size>16</Size>
<Variable Name="ind" InitialValue="0" />
<Loop Condition="ind < 16">
<Item Name="{ind}"> 1 </Item>
<exec> ++ind </exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
What I get:
pout: 16 x q23 Array
>[Raw View]: 0x56594b40 <xin>
Spent a lot of time trying various things out so I reduced the problem to this basic level and can't get it to work.

As described on MSDN you can activate logging for debugging natvis.
The solution for your case is to change the order of Size and Variable and to change exec to Exec.
<Type Name="vq23_t">
<DisplayString>16 x q23 Array</DisplayString>
<Expand>
<CustomListItems>
<Variable Name="ind" InitialValue="0" />
<Size>16</Size>
<Loop Condition="ind < 16">
<Item Name="{ind}"> 1 </Item>
<Exec> ++ind </Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>

Related

Find first occurence of node without traversing all of them using XPaths and elementpath library

I use elementpath to handle some XPath queries. I have an XML with linear structure which contains a unique id attribute.
<items>
<item id="1">...</item>
<item id="2">...</item>
<item id="3">...</item>
... 500k elements
<item id="500003">...</item>
</items>
I want the parser to find the first occurence without traversing all the nodes. For example, I want to select //items/item[#id = '3'] and stop after iterating over 3 nodes only (not over 500k of nodes). It would be a nice optimization for many cases.
An example using XSLT 3 streaming with a static parameter for the XPath, then using xsl:iterate with xsl:break to produce the "early exit" once the first item sought has been found would be
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:param name="path" static="yes" as="xs:string" select="'items/item[#id = ''3'']'"/>
<xsl:output method="xml"/>
<xsl:mode on-no-match="shallow-copy" streamable="yes"/>
<xsl:template match="/" name="xsl:initial-template">
<xsl:iterate _select="{$path}">
<xsl:if test="position() = 1">
<xsl:copy-of select="."/>
<xsl:break/>
</xsl:if>
</xsl:iterate>
</xsl:template>
</xsl:stylesheet>
You can run it with SaxonC EE (unfortunately streaming is only supported by EE) and Python with e.g.
import saxonc
with saxonc.PySaxonProcessor(license=True) as proc:
print("Test SaxonC on Python")
print(proc.version)
xslt30proc = proc.new_xslt30_processor()
xslt30proc.set_parameter('path', proc.make_string_value('/items/item[#id = "2"]'))
transformer = xslt30proc.compile_stylesheet(stylesheet_file='iterate-items-early-exit1.xsl')
xdm_result = transformer.apply_templates_returning_value(source_file='items-sample1.xml')
if transformer.exception_occurred:
print(transformer.error_message)
print(xdm_result)

Is there a way to find a specific string in an xml file and then replace the next string underneath it with a batch script?

Is this possible? I need to edit the following xml file. For every "BASerialKeyND", I need to replace the 987654321 right underneath it. Same thing for "BASerialKey" and 98-7654-321. I cannot count the lines in the file and assign it to a variable and then replace those specific lines because BASerialKeyND and BASerialKey occur on different lines in different files.
Thanks so much for your help!!!!!!!!!!
<?xml version="1.0" encoding="utf-8"?>
<SerializableDictionary>
<item>
<key>BASerialKeyND</key>
<value>987654321</value>
</item>
<item>
<key>BASerialKey</key>
<value>98-7654-321</value>
</item>
<item>
<key>MACHINETYPE</key>
<value>Max</value>
</item>
<item>
<key>PC1NAME</key>
<value>987654321PC1</value>
</item>
<item>
<key>PC2NAME</key>
<value>987654321PC2</value>
</item>
<item>
<key>REPORTPRINTER</key>
<value>None</value>
</item>
<item>
<key>PC1PRINTERS</key>
<value>Name=Microsoft XPS Document Writer
</SerializableDictionary>

Connect internal numbers on freeswitch

I would like to connect two internal numbers with one, I mean if I call 499 then two phones should ring for example 123, 127.
My .xml files in directory/default looks like this:
<include>
<user id="127" mailbox="127">
<params>
<param name="password" value="xxxx"/>
<param name="vm-password" value="127"/>
</params>
<variables>
<variable name="toll_allow" value="domestic,international,local"/>
<variable name="accountcode" value="127"/>
<variable name="user_context" value="default"/>
<variable name="effective_caller_id_name" value="Extension 127"/>
<variable name="effective_caller_id_number" value="127"/>
<variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
<variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
<variable name="callgroup" value="techsupport"/>
</variables>
similar for 123 and 499 numbers.
How can I change it to make two phones rings(123,127) when someone calls 499?
in your dialplan you should call the bridge application like this.
<extension name="Local_Extension">
<condition field="destination_number" expression="^(1001)$">
<action application="bridge" data="sofia/internal/1001%${server-domain-name},sofia/internal/1002%${server-domain-name},sofia/internal/1003%${server domain-name}"/>
</condition>
</extension>
So if you call to 1001 then it will ring to 1001,1002,1003

How to highlite blocks of HTML code in c++ code?

I write web project on c++. In my c++ code has to insert html, for example such
void CPage::putBaseFooter() {
if(m_canRender) {
HTML(
<!++
</main>
<footer>
<f++ composePageFooter(); ++f>
</footer>
</body>
</html>
++!>);
}
}
That is the whole html code is between <!++ and ++!> (Code is processed before compiling its own preprocessor to string)
Just have your own macros preprocessor, such as for example
<f++ composeHead(); ++f>
<v++ ts.tm_year + 1900++v>
<paged_list++ [day_tasks_control] [/tasks/list] [taskListRenderer]>
...
<++paged_list>
<labeled_control++ [Description] [taskDescription]>
<textarea></textarea>
<++labeled_control>
Tell me please, how i can highlite html keywords and own macroses into qt-creator code editor? I tried to write a higlite-xml for Kate (with inheritance c++ highlite), but probably something I do not understand, since the backlight does not work.
Here are my sketches syntax highlighting
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
<!ENTITY space " ">
<!ENTITY separators ",;">
<!ENTITY ns_punctuators "!%&space;&()+-/.*<=>?[]{|}~^&separators;">
]>
<!--
Copyright (c) 2012 by Alex Turbov (i.zaufi#gmail.com)
-->
<language
name="C++"
section="Sources"
version="1.0"
kateversion="2.4"
indenter="cstyle"
style="C++"
mimetype="text/x-c++src;text/x-c++hdr;text/x-chdr"
extensions="*.c++;*.cxx;*.cpp;*.cc;*.C;*.h;*.hh;*.H;*.h++;*.hxx;*.hpp;*.hcc;*.moc"
author="Sheridan (gorlov.maxim#gmail.com)"
license="LGPL"
priority="11"
>
<highlighting>
<list name="InplaceHTML">
<item> form </item>
<item> table </item>
<item> div </item>
<item> td </item>
<item> tr </item>
<item> th </item>
<item> span </item>
<item> input </item>
<item> textarea </item>
<item> label </item>
<item> a </item>
<item> head </item>
<item> link </item>
<item> script </item>
</list>
<contexts>
<context attribute="Normal Text" lineEndContext="#stay" name="Normal">
<IncludeRules context="##C++" />
<IncludeRules context="DetectInplaceHTML" />
</context>
<context attribute="Normal Text" lineEndContext="#stay" name="DetectInplaceHTML">
<keyword attribute="Inplace HTML" context="#stay" String="InplaceHTML" />
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" />
<itemData name="Inplace HTML" defStyleNum="dsKeyword" color="#0095ff" selColor="#ffffff" bold="1" italic="0" spellChecking="false" />
</itemDatas>
</highlighting>
</language>
The Kate C++ highlighting is not used in Qt Creator, changing/extending the Kate configuration file won't have anny affect. You could try to register a separate mime type that's not recognized as C or C++ by Qt Creator and write a Kate highlighter for that, but I don't know whether this would work.
Actually you may have few highlighters for the same language, but w/ different priority!
Take a look to syntax files: there is ISO C++ and C++ (which is a pure C++ syntax plus Qt4 addons). Also here is alternative C++ highlighters where C++ is a pure C++ syntax and C++/Qt4 is a secondary. One may use configuration settings to change priority according needs. Personally I prefer to have a pure C++ over "default" C++/Qt4.
So you may try to add your own C++/Custom syntax and boost its priority. Take a look to C++/Qt4 to get an idea how to "reuse" pure C++ syntax.
And finally, considering your example syntax, you'd better to detect your extension before fall into inherited C++ contexts.

Xpath Cast node to number for mod

I have nodes that contain numbers that I would like to cast to a number and use mod. For example:
<item>
<num>1</num>
</item>
<item>
<num>2</num>
</item>
<item>
<num>3</num>
</item>
I've tried:
num mod 3 -- returns NaN
number(num) mod 3 -- returns NaN
number(string(num)) -- returns NaN
Any idea if this can be done? Even if there was a way to convert to ASCII, I would take it
Thanks in advance!
number(num) mod 3 should work. The following example files output 1 2 0 as expected.
XML
(saved as input.xml)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mod_test.xsl"?>
<items>
<item>
<num>1</num>
</item>
<item>
<num>2</num>
</item>
<item>
<num>3</num>
</item>
</items>
XSL
(saved as mod_text.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="//item">
<xsl:value-of select="number(num) mod 3"/>
</xsl:template>
</xsl:stylesheet>
Note: just num mod 3 in the select also works.
For reference, here is the relevant section in the documentation.
I've tried:
num mod 3 -- returns NaN
number(num) mod 3 -- returns NaN
number(string(num)) -- returns NaN
Any idea if this can be done?
As no complete XML document is provided, here are my two guesses:
The context node for the relative expressions has no num children. The solution is to assure that the context node is the correct one, or to use absolute XPath expression(s).
The not-shown XML document is in a default namespace. In this case the solution is to "register a namespace" (associate a string-prefix to the default namespace, say "x") and then replace in your expressio(s) num with x:num.

Resources