Message ID | 7f2139b27013d77993c6bc2b0a6c94fab01add98.1447773299.git.stillcompiling@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Nov 17, 2015 at 07:24:22AM -0800, Joshua Clayton wrote:
> Put input from string into its own function.
Again, why are we doing this? I'm having a hard time seeing what the
gain is, the amount of code being moved is tiny.
On Tuesday, November 17, 2015 05:43:33 PM Mark Brown wrote: > On Tue, Nov 17, 2015 at 07:24:22AM -0800, Joshua Clayton wrote: > > Put input from string into its own function. > > Again, why are we doing this? I'm having a hard time seeing what the > gain is, the amount of code being moved is tiny. It takes some clutter out of main() whose scope is limited to that little block of code, and because in the next patch we add another (larger)function to the if/else block. I don't know if it is valid to say "look at the next commit" for justification, but That is the reason.
On Tue, Nov 17, 2015 at 11:21:12AM -0800, Joshua Clayton wrote: Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to. > It takes some clutter out of main() whose scope is limited to that little block of code, > and because in the next patch we add another (larger)function to the if/else block. > I don't know if it is valid to say "look at the next commit" for justification, but > That is the reason. That's totally fine - just say that it's to support future changes in this area. It's good to split out mechanical changes like this from the more complex changes, you just need to say why they're happening.
diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index dfe8f47..1ed9110 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/spi/spidev_test.c @@ -249,12 +249,20 @@ static void parse_opts(int argc, char *argv[]) } } +static void transfer_escaped_string(int fd, char *str) +{ + size_t size = strlen(str + 1); + uint8_t *tx = malloc(size); + + size = unescape((char *)tx, str, size); + transfer(fd, tx, size); + free(tx); +} + int main(int argc, char *argv[]) { int ret = 0; int fd; - uint8_t *tx; - int size; parse_opts(argc, argv); @@ -299,15 +307,10 @@ int main(int argc, char *argv[]) printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); - if (input_tx) { - size = strlen(input_tx+1); - tx = malloc(size); - size = unescape((char *)tx, input_tx, size); - transfer(fd, tx, size); - free(tx); - } else { + if (input_tx) + transfer_escaped_string(fd, input_tx); + else transfer(fd, default_tx, sizeof(default_tx)); - } close(fd);
Put input from string into its own function. Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> --- Documentation/spi/spidev_test.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)