How to determine if a string is a valid PCI address? - pci

PCI addresses adhere to the BDF notation
What would be a good way to determine if a string contains a valid PCI address?
Any programming language would do.

So I came up with the following regex (javascript) to cover the basic BDF:
^([a-fA-F0-9]{2}|[a-fA-F0-9]{4}):[a-fA-F0-9]{2}\.[a-fA-F0-9]{1,2}$
extending it to cover the extended versions of BDF should not be that hard.

Related

History of EAFNOSUPPORT semantics?

I’m seeing three different “error strings” for the EAFNOSUPPORT / WSAEAFNOSUPPORT errno:
POSIX:
The implementation does not support the specified address family.
BSD (errno.h, _sys_errlist[]):
Address family not supported by protocol family
Windows®/Winsock2:
An address incompatible with the requested protocol was used
While the semantics of the latter two are pretty much identical, the former differs quite a bit (it does not reference a protocol family; rather, it states that the given address family is not supported in a particular place).
I’m assuming both interpretations are valid, especially given EPFNOSUPPORT (“Protocol family not supported”) is marked as nōn-POSIX in the BSD headers, but where does this difference come from? Incidentally, my back-of-the-head/historical(FSVO) understanding of this errno code matches the POSIX semantics more than the BSD/Winsock semantics…
I can imagine that the POSIX semantic is from older BSD sockets, and later EPFNOSUPPORT was added so EAFNOSUPPORT was redesignated in BSD sockets (and Winsock just took that), or POSIX is deliberately written in a different way.
Can anyone shed light on this, perhaps explain the histories (code heritage, etc)?

What is the occasion when we have to use the 'net' data type in systemverilog?

As I know, nowadays the 'reg' type in systemverilog can used in assign statement.
In old fashion, the assign statement does use the only the 'net' type.
So I want to know that what kind of the signals are should have to be the 'net' type in systemverilog?
Update1
From here, http://www.testbench.in/IF_01_INTERFACE.html
I can find a interface declaration.
interface intf #(parameter BW = 8)(input clk); 
logic read, enable; 
logic [BW -1 :0] addr,data; 
endinterface :intf 
At this here, I want to know that why the read and enable and addr and data signal are clared logic data type? Is there any reason? Why not used reg or wire?
A net is used when there are multiple drivers on a signal, usually in conjunction with a bi-directional port, and for designs at the switch level that require strength to operate. See http://go.mentor.com/wire-vs-reg for more details.
Regarding the usage of net Dave's answer pretty much covers it.
From the IEEE Std 1800-2012,
The keyword reg does not always accurately describe user intent, as it
could be perceived to imply a hardware register. The keyword logic is
a more descriptive term. logic and reg denote the same type.
More info on the usage of logic can be found in below links.
1) Morgans answer
2) Greg's answer

Where is the meaning of system constants such as _SIG_MAXSIG defined?

In FreeBSD we have the constant _SIG_MAXSIG defined in _sigset.h. I am wondering where the meaning of this constant is defined. Obviously, this is something like the maximal signal value. However, I am looking for a definite standard, the common ground that all developers should look at when interpreting that value. The same holds true for the meaning of other constants -- what is the definite source defining their meaning?
This won't answer your question directly, because I'm unaware of a standard that specifies _SIG_MAXSIG (I don't think it is standardized), but much of what you're looking for is defined by the Single Unix Specification. Note: you have to register with the site in order to download the specification.
Section XSH 2.4 explains the signal-related concepts. I don't see anything about the maximum number of signals though, other than SIGRTMIN and SIGRTMAX--which are for real-time signals.

Is there a widely used way to write "any IP address" as a string?

I've seen APIs that use "*" and "::" (for IPv6) to mean "any address" (i.e. INADDR_ANY) when binding a socket. I've also seen APIs that use "" or "0.0.0.0" to mean the same. Is there a widely use standard for writing "any address" as a string?
Those are the two ways. Sadly there isn't one that works for both IPv4 and IPv6. When binding a socket you should certainly use INADDR_ANY.
It's such a good idea, that there's more than one widely used way to write that. Isn't programming fun?

Get language of string

Let's say I have a title string, written in different languages.
Is there way to check which language is each string?
I have not played with it but you should look at NSLinguisticTagger and its - (NSOrthography *)orthographyAtIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveRange method. From the NSOrthography docs:
The NSOrthography class describes the linguistic content of a piece of
text, typically used for the purposes of spelling and grammar
checking.
An NSOrthography instance describes:
Which scripts the text contains. A dominant language and possibly
other languages for each of these scripts. A dominant script and
language for the text as a whole. Scripts are uniformly described by
standard four-letter tags (Latn, Grek, Cyrl, etc.) with the supertags
Jpan and Kore typically used for Japanese and Korean text, Hans and
Hant for Chinese text; the tag Zyyy is used if a specific script
cannot be identified. See Internationalization Programming Topics for
more information on internationalization.
Languages are uniformly described by BCP-47 tags , preferably in
canonical form; the tag und is used if a specific language cannot be
determined.
You can simply use the Google Transalate REST API to find the language.
And you can use something like RestKit to make the REST requests to the google servers.
You could use N-gram sampling frequencies techniques. I am not an expert, but they are rumored to work well in practice.
See netspeak and papers like this etc etc.
There's Google translation API available that allows language conversation. I am sure there must be something you will find that returns matched language for your string. See Google Translate APIs for details.