* Given a C string, parse it into a qualified function or operator name * followed by a parenthesized list of type names. Reduce the * type names to an array of OIDs (returned into *nargs and *argtypes; * the argtypes array should be of size FUNC_MAX_ARGS). The function or * operator name is returned to *names as a List of Strings. * * If allowNone is true, accept "NONE" and return it as I
| 1922 | * for unary operators). |
| 1923 | */ |
| 1924 | static void |
| 1925 | parseNameAndArgTypes(const char *string, bool allowNone, List **names, |
| 1926 | int *nargs, Oid *argtypes) |
| 1927 | { |
| 1928 | char *rawname; |
| 1929 | char *ptr; |
| 1930 | char *ptr2; |
| 1931 | char *typename; |
| 1932 | bool in_quote; |
| 1933 | bool had_comma; |
| 1934 | int paren_count; |
| 1935 | Oid typeid; |
| 1936 | int32 typmod; |
| 1937 | |
| 1938 | /* We need a modifiable copy of the input string. */ |
| 1939 | rawname = pstrdup(string); |
| 1940 | |
| 1941 | /* Scan to find the expected left paren; mustn't be quoted */ |
| 1942 | in_quote = false; |
| 1943 | for (ptr = rawname; *ptr; ptr++) |
| 1944 | { |
| 1945 | if (*ptr == '"') |
| 1946 | in_quote = !in_quote; |
| 1947 | else if (*ptr == '(' && !in_quote) |
| 1948 | break; |
| 1949 | } |
| 1950 | if (*ptr == '\0') |
| 1951 | ereport(ERROR, |
| 1952 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 1953 | errmsg("expected a left parenthesis"))); |
| 1954 | |
| 1955 | /* Separate the name and parse it into a list */ |
| 1956 | *ptr++ = '\0'; |
| 1957 | *names = stringToQualifiedNameList(rawname); |
| 1958 | |
| 1959 | /* Check for the trailing right parenthesis and remove it */ |
| 1960 | ptr2 = ptr + strlen(ptr); |
| 1961 | while (--ptr2 > ptr) |
| 1962 | { |
| 1963 | if (!scanner_isspace(*ptr2)) |
| 1964 | break; |
| 1965 | } |
| 1966 | if (*ptr2 != ')') |
| 1967 | ereport(ERROR, |
| 1968 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 1969 | errmsg("expected a right parenthesis"))); |
| 1970 | |
| 1971 | *ptr2 = '\0'; |
| 1972 | |
| 1973 | /* Separate the remaining string into comma-separated type names */ |
| 1974 | *nargs = 0; |
| 1975 | had_comma = false; |
| 1976 | |
| 1977 | for (;;) |
| 1978 | { |
| 1979 | /* allow leading whitespace */ |
| 1980 | while (scanner_isspace(*ptr)) |
| 1981 | ptr++; |
no test coverage detected