| ... | ... | @@ -281,9 +281,6 @@ pub const ArgIteratorWasi = struct { |
| 281 | 281 | pub const ArgIteratorWindows = struct { |
| 282 | 282 | index: usize, |
| 283 | 283 | cmd_line: [*]const u8, |
| 284 | | in_quote: bool, |
| 285 | | quote_count: usize, |
| 286 | | seen_quote_count: usize, |
| 287 | 284 | |
| 288 | 285 | pub const NextError = error{OutOfMemory}; |
| 289 | 286 | |
| ... | ... | @@ -295,9 +292,6 @@ pub const ArgIteratorWindows = struct { |
| 295 | 292 | return ArgIteratorWindows{ |
| 296 | 293 | .index = 0, |
| 297 | 294 | .cmd_line = cmd_line, |
| 298 | | .in_quote = false, |
| 299 | | .quote_count = countQuotes(cmd_line), |
| 300 | | .seen_quote_count = 0, |
| 301 | 295 | }; |
| 302 | 296 | } |
| 303 | 297 | |
| ... | ... | @@ -328,6 +322,7 @@ pub const ArgIteratorWindows = struct { |
| 328 | 322 | } |
| 329 | 323 | |
| 330 | 324 | var backslash_count: usize = 0; |
| 325 | var in_quote = false; |
| 331 | 326 | while (true) : (self.index += 1) { |
| 332 | 327 | const byte = self.cmd_line[self.index]; |
| 333 | 328 | switch (byte) { |
| ... | ... | @@ -335,14 +330,14 @@ pub const ArgIteratorWindows = struct { |
| 335 | 330 | '"' => { |
| 336 | 331 | const quote_is_real = backslash_count % 2 == 0; |
| 337 | 332 | if (quote_is_real) { |
| 338 | | self.seen_quote_count += 1; |
| 333 | in_quote = !in_quote; |
| 339 | 334 | } |
| 340 | 335 | }, |
| 341 | 336 | '\\' => { |
| 342 | 337 | backslash_count += 1; |
| 343 | 338 | }, |
| 344 | 339 | ' ', '\t' => { |
| 345 | | if (self.seen_quote_count % 2 == 0 or self.seen_quote_count == self.quote_count) { |
| 340 | if (!in_quote) { |
| 346 | 341 | return true; |
| 347 | 342 | } |
| 348 | 343 | backslash_count = 0; |
| ... | ... | @@ -360,6 +355,7 @@ pub const ArgIteratorWindows = struct { |
| 360 | 355 | defer buf.deinit(); |
| 361 | 356 | |
| 362 | 357 | var backslash_count: usize = 0; |
| 358 | var in_quote = false; |
| 363 | 359 | while (true) : (self.index += 1) { |
| 364 | 360 | const byte = self.cmd_line[self.index]; |
| 365 | 361 | switch (byte) { |
| ... | ... | @@ -370,10 +366,7 @@ pub const ArgIteratorWindows = struct { |
| 370 | 366 | backslash_count = 0; |
| 371 | 367 | |
| 372 | 368 | if (quote_is_real) { |
| 373 | | self.seen_quote_count += 1; |
| 374 | | if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) { |
| 375 | | try buf.append('"'); |
| 376 | | } |
| 369 | in_quote = !in_quote; |
| 377 | 370 | } else { |
| 378 | 371 | try buf.append('"'); |
| 379 | 372 | } |
| ... | ... | @@ -384,7 +377,7 @@ pub const ArgIteratorWindows = struct { |
| 384 | 377 | ' ', '\t' => { |
| 385 | 378 | try self.emitBackslashes(&buf, backslash_count); |
| 386 | 379 | backslash_count = 0; |
| 387 | | if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) { |
| 380 | if (in_quote) { |
| 388 | 381 | try buf.append(byte); |
| 389 | 382 | } else { |
| 390 | 383 | return buf.toOwnedSlice(); |
| ... | ... | @@ -405,26 +398,6 @@ pub const ArgIteratorWindows = struct { |
| 405 | 398 | try buf.append('\\'); |
| 406 | 399 | } |
| 407 | 400 | } |
| 408 | | |
| 409 | | fn countQuotes(cmd_line: [*]const u8) usize { |
| 410 | | var result: usize = 0; |
| 411 | | var backslash_count: usize = 0; |
| 412 | | var index: usize = 0; |
| 413 | | while (true) : (index += 1) { |
| 414 | | const byte = cmd_line[index]; |
| 415 | | switch (byte) { |
| 416 | | 0 => return result, |
| 417 | | '\\' => backslash_count += 1, |
| 418 | | '"' => { |
| 419 | | result += 1 - (backslash_count % 2); |
| 420 | | backslash_count = 0; |
| 421 | | }, |
| 422 | | else => { |
| 423 | | backslash_count = 0; |
| 424 | | }, |
| 425 | | } |
| 426 | | } |
| 427 | | } |
| 428 | 401 | }; |
| 429 | 402 | |
| 430 | 403 | pub const ArgIterator = struct { |
| ... | ... | @@ -578,7 +551,7 @@ test "windows arg parsing" { |
| 578 | 551 | testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); |
| 579 | 552 | testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" }); |
| 580 | 553 | testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" }); |
| 581 | | testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" }); |
| 554 | testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "d f" }); |
| 582 | 555 | |
| 583 | 556 | testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{ |
| 584 | 557 | ".\\..\\zig-cache\\build", |