Re: [PATCH RFC] ldattach: add --iflag command line option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 01.03.2010 11:17 schrieb Karel Zak:
> On Mon, Feb 22, 2010 at 01:00:10PM +0100, Tilman Schmidt wrote:
>> Add a command line option '-i' / '--iflag' for setting or clearing
>> input flags on the serial device before attaching the line discipline.
[...]
>  Good idea. Applied with some changes (see below). Thanks.

Your patch doesn't apply here. It looks like I'm missing one that has
to go before it, introducing struct ld_table and the lookup_table and
print_table functions. Could you send that one too, or better yet,
merge the two?

>  Note that I did a small refactoring in the ldattach to remove
>  duplicate code.

I'm fine with that.

> @@ -98,14 +119,39 @@ static void print_table(FILE *out, const struct ld_table *tab)
>      }
>  }
>  
> +static int parse_iflag(char *str, int *set_iflag, int *clr_iflag)
> +{
> +    int iflag;
> +    char *s, *end;
> +
> +    for (s = strtok(str, ","); s != NULL; s = strtok(NULL, ",")) {
> +	if (*s == '-')
> +	    s++;
> +        if ((iflag = lookup_table(ld_iflags, s)) < 0) {
> +	    iflag = strtol(s, &end, 0);
> +	    if (*end || iflag < 0)
> +	        errx(EXIT_FAILURE, _("invalid iflag: %s"), s);
> +	}
> +	if (s > str && *(s - 1) == '-')
> +	    *clr_iflag |= iflag;
> +	else
> +	    *set_iflag |= iflag;
> +    }

That looks awkward. How about doing it this way instead?

+static int parse_iflag(char *str, int *set_iflag, int *clr_iflag)
+{
+    int iflag;
+    char *s, *end;
+    int *op_iflag;
+
+    for (s = strtok(str, ","); s != NULL; s = strtok(NULL, ",")) {
+	if (*s == '-') {
+	    s++;
+	    op_iflag = clr_iflag;
+	} else
+	    op_iflag = set_iflag;
+        if ((iflag = lookup_table(ld_iflags, s)) < 0) {
+	    iflag = strtol(s, &end, 0);
+	    if (*end || iflag < 0)
+	        errx(EXIT_FAILURE, _("invalid iflag: %s"), s);
+	}
+	*op_iflag |= iflag;
+    }

> +
> +    dbg("iflag (set/clear): %d/%d", *set_iflag, *clr_iflag);
> +    return 0;
> +}

Thanks,
Tilman

-- 
Tilman Schmidt                    E-Mail: tilman@xxxxxxx
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux