MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / get_multi_line_statement

Function get_multi_line_statement

tools/cdb2sql/cdb2sql.cpp:1892–1924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1890}
1891
1892static char *get_multi_line_statement(char *line)
1893{
1894 char *stmt = NULL;
1895 int slen = 0;
1896 char *nl = (char *) ""; // new-line
1897 int n = 0; // len of nl
1898
1899 char tmp_prompt[sizeof(main_prompt) + 4];
1900 int spaces = strlen(dbname) - 3, dots = 3;
1901 if (spaces < 0) {
1902 dots += spaces;
1903 spaces = 0;
1904 }
1905 sprintf(tmp_prompt, "%.*s%.*s> ", spaces,
1906 " ",
1907 dots, "...");
1908 prompt = tmp_prompt;
1909 do {
1910 int len = strlen(line);
1911 int newlen = slen + len + n;
1912 stmt = (char *) realloc(stmt, newlen + 1);
1913 sprintf(&stmt[slen], "%s%s", nl, line);
1914 slen = newlen;
1915 if (stmt[slen - 2] == '$' && stmt[slen - 1] == '$') {
1916 stmt[slen - 2] = '\0';
1917 break;
1918 }
1919 nl = (char *) "\n";
1920 n = 1;
1921 } while ((line = read_line()) != NULL);
1922 prompt = main_prompt;
1923 return stmt;
1924}
1925
1926static inline int dbtype_valid(char *type)
1927{

Callers 1

mainFunction · 0.70

Calls 2

reallocFunction · 0.85
read_lineFunction · 0.70

Tested by

no test coverage detected