MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / permute_args

Function permute_args

samples/common/getopt.c:153–183  ·  view source on GitHub ↗

* Exchange the block from nonopt_start to nonopt_end with the block * from nonopt_end to opt_end (keeping the same order of arguments * in each block). */

Source from the content-addressed store, hash-verified

151 * in each block).
152 */
153static void permute_args(int panonopt_start, int panonopt_end, int opt_end, char* const* nargv)
154{
155 int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
156 char* swap;
157
158 /*
159 * compute lengths of blocks and number and size of cycles
160 */
161 nnonopts = panonopt_end - panonopt_start;
162 nopts = opt_end - panonopt_end;
163 ncycle = gcd(nnonopts, nopts);
164 cyclelen = (opt_end - panonopt_start) / ncycle;
165
166 for (i = 0; i < ncycle; i++)
167 {
168 cstart = panonopt_end + i;
169 pos = cstart;
170 for (j = 0; j < cyclelen; j++)
171 {
172 if (pos >= panonopt_end)
173 pos -= nnonopts;
174 else
175 pos += nopts;
176 swap = nargv[pos];
177 /* LINTED const cast */
178 ((char**) nargv)[pos] = nargv[cstart];
179 /* LINTED const cast */
180 ((char**) nargv)[cstart] = swap;
181 }
182 }
183}
184
185/*
186 * parse_long_options --

Callers 1

getopt_internalFunction · 0.85

Calls 1

gcdFunction · 0.85

Tested by

no test coverage detected