Skip to content

Commit

Permalink
C generator: remove unneeded 'optind++' from positional parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknyquist committed Oct 27, 2023
1 parent 78285e3 commit 331d324
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 11 deletions.
6 changes: 5 additions & 1 deletion duckargs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ def _generate_c_getopt_code(processed_args, getopt_string, opts, positionals, ha
desc = f"Positional argument #{i + 1} ({arg.var_name})"
optarg = f"argv[optind]"
ret += '\n'.join([" " + x for x in _generate_c_opt_lines(arg, desc, optarg)])
ret += "\n optind++;\n\n"

if i < (len(positionals) - 1):
ret += "\n optind++;"

ret += "\n\n"

pass

Expand Down
1 change: 0 additions & 1 deletion tests/test_data/choices/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ int parse_args(int argc, char *argv[])
optind++;

pos2 = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/env_all/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ int parse_args(int argc, char *argv[])
optind++;

positional_arg2 = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/env_comment/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ int parse_args(int argc, char *argv[])
optind++;

positional_arg2 = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/env_print/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ int parse_args(int argc, char *argv[])
optind++;

positional_arg2 = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/many_opts/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ int parse_args(int argc, char *argv[])
optind++;

pos10 = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/negative_hex/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ int parse_args(int argc, char *argv[])
printf("Positional argument #1 (positional_arg0) requires an integer argument\n");
return -1;
}
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/negative_int/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ int parse_args(int argc, char *argv[])
printf("Positional argument #2 (positional_arg1) requires an integer argument\n");
return -1;
}
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/normalize_names/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ int parse_args(int argc, char *argv[])
optind++;

pos___3 = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/positional_values/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ int parse_args(int argc, char *argv[])
optind++;

hello = argv[optind];
optind++;

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/readme_example/expected_c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ int parse_args(int argc, char *argv[])
optind++;

positional_arg2 = argv[optind];
optind++;

return 0;
}
Expand Down

0 comments on commit 331d324

Please sign in to comment.