MCPcopy Create free account
hub / github.com/Kitware/CMake / kwsysSystem__ParseUnixCommand

Function kwsysSystem__ParseUnixCommand

Source/kwsys/System.c:95–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93#define KWSYSPE_LOCAL_BYTE_COUNT 1024
94#define KWSYSPE_LOCAL_ARGS_COUNT 32
95static char** kwsysSystem__ParseUnixCommand(char const* command, int flags)
96{
97 /* Create a buffer for argument pointers during parsing. */
98 char* local_pointers[KWSYSPE_LOCAL_ARGS_COUNT];
99 int pointers_size = KWSYSPE_LOCAL_ARGS_COUNT;
100 char** pointer_begin = local_pointers;
101 char** pointer_end = pointer_begin;
102
103 /* Create a buffer for argument strings during parsing. */
104 char local_buffer[KWSYSPE_LOCAL_BYTE_COUNT];
105 int buffer_size = KWSYSPE_LOCAL_BYTE_COUNT;
106 char* buffer_begin = local_buffer;
107 char* buffer_end = buffer_begin;
108
109 /* Parse the command string. Try to behave like a UNIX shell. */
110 char** newCommand = 0;
111 char const* c = command;
112 int in_argument = 0;
113 int in_escape = 0;
114 int in_single = 0;
115 int in_double = 0;
116 int failed = 0;
117 for (; *c; ++c) {
118 if (in_escape) {
119 /* This character is escaped so do no special handling. */
120 if (!in_argument) {
121 in_argument = 1;
122 }
123 if (!kwsysSystem__AppendByte(local_buffer, &buffer_begin, &buffer_end,
124 &buffer_size, *c)) {
125 failed = 1;
126 break;
127 }
128 in_escape = 0;
129 } else if (*c == '\\') {
130 /* The next character should be escaped. */
131 in_escape = 1;
132 } else if (*c == '\'' && !in_double) {
133 /* Enter or exit single-quote state. */
134 if (in_single) {
135 in_single = 0;
136 } else {
137 in_single = 1;
138 if (!in_argument) {
139 in_argument = 1;
140 }
141 }
142 } else if (*c == '"' && !in_single) {
143 /* Enter or exit double-quote state. */
144 if (in_double) {
145 in_double = 0;
146 } else {
147 in_double = 1;
148 if (!in_argument) {
149 in_argument = 1;
150 }
151 }
152 } else if (kwsysString_isspace(*c)) {

Callers 1

Calls 3

kwsysSystem__AppendByteFunction · 0.85
kwsysString_isspaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…