How to design syntax for complex command line options? [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Suppose my command line utility can send messages with following structure
struct Message {
uint32_t ip;
string id;
}
User must be able to specify host(ipv4+port) and filters on ip and id per host
(allowed network addresses and ids to send). How can I design
clear syntax for such complex option?
The best what I invented is:
--msg-send="192.168.10.2:8080;ip_isin=10.0.0.0/8,172.16.0.1/16;id=one,two"
But something is wrong with it... for example sign = inside is
annoying... Does anybody knows "the silver bullet" for command line arguments with complex structure?
another variant is better:
--msg-send="192.168.10.2:8080{ip 10.0.0.0/8,172.168.0.0/16}{id one,two}"
UPD: msg-send is plural, user can set several hosts with different filters

There's no silver bullet, however, when interacting with humans you should try to follow human way of thinking. You're trying to make the user to compose a complex structure, somewhat resembling JSON format, by hand. Humans are bad at this. From your explanation I get that this structure has three components:
host+port
list of IPs (identified by subnets, CIDR notations,
rangers, whatever your program can handle)
list of string ids
Thus it might be logical to require the user to enter these parameters separately, for example
msg_util.exe --host 192.168.10.2:8080 --allowed_ips 10.0.0.0/8,172.16.0.1/16 --allowed_ids one,two
If you might have many hosts with corresponding allowed IPs and ids, then it'd be quite awkward to enter it from command line alone, and many network utilities (like dig) resort to consume input from files. For example you could have
msg_util.exe --file --host hosts_file --allowed_ips ips_file --allowed_ids ids_file
where each line of hosts_file has corrseponding options in ips_file and ids_file

Related

Issue with regular expressions while parsing source code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Im trying to get some information from a page source code.
For example, lets take this amazon product.
https://www.amazon.com/gp/product/B07PWCJZJ6?pf_rd_p=2d1ab404-3b11-4c97-b3db-48081e145e35&pf_rd_r=0PF9KX04Y9GAPGCXBDAP
We can check the source code with
view-source:https://www.amazon.com/gp/product/B07PWCJZJ6?pf_rd_p=2d1ab404-3b11-4c97-b3db-48081e145e35&pf_rd_r=0PF9KX04Y9GAPGCXBDAP
My objective is to get some data like the product descriptions (1366x768 LED display for example)
Im basically taking the whole source code and then using regular expressions to get the data I need.
Im doing something like this:
import requests
source = requests.get(someUrl)
data = re.findall(r'<span class=\"a-list-item\">(.*?)<\/span><\/li>', source.content)
Which should give me every product description, but I keep getting the TypeError: cannot use a string pattern on a bytes-like object
I don't know if my regex is wrong or source.content is not giving me the source code
As the diagnostic explains, the regex library wants a string input, not bytes.
The requests documentation is pretty clear:
... access the response body as bytes, for non-text requests:
>>> r.content
Given that you retrieved some HTML text
you will want to decode it,
or let the library decode it for you:
>>> source.content.decode(source.encoding)
or
>>> source.text
Both expressions return a Unicode string,
which would be the perfect input for that regex.
Separate item: make Soup, not Regexes -- bs4 is the more appropriate tool, here.

Statistica VB - Including an external macro [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm using Statistica 64 VB. I wrote a function "Public MyFunction()" in FileLibrary.svb (a collection of useful functions) that I want to be called by a function in FileDoStuff.svb (an analysis).
I tried to include FileLibrary.svb like this in FileDoStuff.svb:
'#Language "WWB-COM"
'#Uses "U:\TestSVB\FileLibrary.svb"
This is the result when I run Main() in FileDoStuff, and the result is the same even if I have FileLibrary open in the application.
"Script error in FileDoStuff.svb
Macro/module does not exist."
Statistica is on the E: drive. However, FileLibrary opens a spreadsheet on U: and has no problem with it. I am able to open FileLibrary from Statistica and test it.
Why would it work to open an external spreadsheet but not call an external macro? The FileLibrary is not saved within Statistica, but neither is the analysis in FileDoStuff. What am I doing wrong?
Also, what's the difference between an SVB and an SVX file?
You know what really helps, as I discovered after hours of trying everything?
Try spelling the entire path name and the entire file name correctly, including spaces, etc. And make sure the slashes go the right way, too. (In my real path/file there are spaces.)
As much as I'd like to delete this whole question, I'm leaving it here to remind us all that sometimes the answer is just that simple. Also, I want to draw more people out who are using Statistica VB because I know there will be more questions.

Create an invisible text file in C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Put simply, I have a browser widget I'm using in FLTK Gui toolkit which can be loaded using a file like so.
browser::load("textfile.txt");
The problem is I don't want to create a physical text file, just an invisible one so I can use it as an argument for browser::load above. I plan to use this invisible text file by loading it with the values I'm going to place in my browser....then use it like this.
browser::load("invisible_textfile.txt");
Is it possible to do this in C++?
I have already tried using ifstream::rdbuf() which probably has nothing to do with this. I'm not even sure what to call this so I'm just calling it an invisible textfile for now.
I'm using windows 7 64 bit. MinGW compiler.
Let's say what you want to add is equivalent of text file like this:
One
Two
Three
But you don't want to have the text file. So one piece of code which would do the same thing is this:
const char *lines[] = { "One", "Two", "Three", 0 };
for(int i = 0 ; lines[i] != 0 ; ++i)
browser.add(lines[i]);
Documentation link for that overload of add
Please refine your question, or perhaps ask a new question, if you want more help on how to get lines with your data.
It depends a lot on what browser::load() actually does internally, but let's assume that it will look for your filename and load it.
You probably already know how to read / write a standard file (e.g. http://www.cplusplus.com/doc/tutorial/files/). Now, if you just want to hide the file from the user, you can set OS specific hidden flags (e.g. windows). I'm assuming that's not what you actually want to accomplish here. (You could obviously also create a temporary file that you delete again, but it's not an elegant solution either.)
What you might want to use is a named pipe. Under Linux you can create these with mkfifo and then stream content through those file objects.
The general point is, though, unless the browser API allows you to pass it a complete string holding the text file or a stringstream, you will need a file object.
If your only target system is NTFS, there is a good answer on creating virtual files over here:
How to create a virtual file?
But in the end, you probably want to create an actual file (in your case probably a temporary one, though). I would recommend placing that file into the systems temporary path.

Running various c or cpp development tasks from vi "like running cpp program without exiting vi." [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have some questions regarding the use of VI while working on c or cpp programs, this can serve as a quick reference to people who are coming to vi for the first time.
How to run CPP programs from withing vi, without exiting it.
How to get type hierarchy in vi
How to get call hierarchy in vi
How to refactor code in vi, so that it will not only refactor on current file but also on all the other dependent files.
How to open declaration of a method defined in some other cpp file from the place where it is used.
How to search in different files for some keyword without exiting vi.
How to maintain indentation of programs in vi.
Thanks in advance.
disclaimer -- I am not a vi(m) user, rather I use emacs.
I suspect that much of what you want is not available in a default installation of vi(m), however some of the functionality can be gained via additional programs:
for your question 3 (and possibly 5 & 6) cscope may provide what you are looking for. See this link
for your question 4, see this stack-overflow thread.
for your questions 5 (and possibly 6), ctags may provide what you are looking for. See this link.
I ran in to several of the same problems using emacs, and wound up integrating similar third-party programs into emacs, thus my somewhat limited knowledge on this topic. Hope these pointers help.
I got some of the answer to question:
1 How to run CPP programs from withing vi, without exiting it.
Solution: Using bang (!) followed by the command to be run. For instance, if you're editing a file in Vim and want to find out how many words are in the file, run
:! wc %
We can also exit and go to shell by typing :shell or :sh while remaining within vi, the shell will open you can type in any no. of commands and when you are done you can just exit the shell and you will land into vi again at the same place.
6 How to search in different files for some keyword without exiting vi.
Solution: Using the same explained in answer 1. Using grep:
:! grep <keyword or regular expression>
All of the questions lumped together expose a point of view issue. From the point of view of the folks (starting with Bill Joy, the original author of vi) who created Unix and vi, the the shell prompt is the whole development environment. vi is just the editor part. make is the project builder. The file system along with ls, find, grep and a myriad other tools provides the file grouping and organizational tools.
This is why vi has a rich set of command line options that allow you to name multiple files to open, and where in each file to position the cursor. Along with the ctags tool, you can even ask vi to open the file holding a named function without typing the name of the file.
From within vi, you can always use the ! command to operate on text using an arbitrary program. !fmt is a quick and dirty way to do wrapped text, for instance. And, of course, the : command is your gateway into the wonderfully dangerous power of CLI based editing.
Underlying it all is a requirement that you really understand the commands that move the cursor and describe a span of text. The first step is to notice every time you find yourself repeating a command (like a simple movement command 'h', 'j', 'k' or 'l') until you reach the right spot and ask your self how you could have achieved that effect with less typing. Instead of 'lllll', say '5l' or perhaps 'w' or better 'fa' if the target was the next letter 'a' that just happened to be five characters over.
With the right mindset, and a good grasp of the larger universe of text processing filters, most of your questions boil down to identifying the right span of text and passing it to an external utility, in the context of a project already sensibly organized in folders and with ctags run from make to keep the tags database current.
There are lots of tutorials and quick references out there. This one seems to express the point of view I'm trying to convey here.

Howto manage XML recipes with c++ and Qt? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to write a software for managing recipes. The recipes are valid standalone xml files. They contain string and integer values and image data (in a base64 representation). The user should be able to create/open, edit and save recipes. Now I have concerns about file management and efficiency (speed and memory).
How should I manage all the recipes? I think I could either store them all as plain xml files in a folder, or have them all in one library file of some sort. The first approach might be faster on startup, as the recipes are loaded when the user clicks them, e.g. in a QTreeView. The second approach might be more efficient and fast because the whole library would be kept in memory, although it could be more complex to change its contents.
I want to use DOM for xml file handling - or would QXmlStreamReader/writer be a better choice here?
Either way, I would have to manage the recipe data using unique IDs, e.g. for several different "Cookies" recipes. When using the first approach from question 1., I would use file names based on such an ID. Are there any convenient ways to create unique IDs? Because when using incrementing integers I'd have to track which numbers are already in use.
I'm using XML files for transferring recipes in my recipe program. I have options to import and export using XML.
I am using a database to store the recipes. I do not use XML data files to store recipes. I'll leave data management to the database (I'm not wasting my time writing and debugging a database).
For data storage, there more efficient file formats than XML. Also, you may want to create "index tables" which allow for sorted and more efficient access to files than having to always parse an XML file.