coreutils
[Top][All Lists]
Advanced

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

Re: uniq with sort-like "--key" support


From: Assaf Gordon
Subject: Re: uniq with sort-like "--key" support
Date: Wed, 13 Feb 2013 15:22:11 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Pádraig Brady wrote, On 02/13/2013 12:54 PM:
> On 02/13/2013 05:34 PM, Assaf Gordon wrote:
>>
>> What would be the recommended way to compartmentalize this functionality?
>> 1. put it in "src/key-spec-parsing.h", and have each program (e.g. uniq.c) 
>> do "#include" ?
>> or
>> 2. split it into "src/key-spec-parsing.h" and "src/key-spec-parsing.c" (with 
>> all the "src/local.mk" associated changes) - but removing the "static" from 
>> all the variables/functions?
> 
> 2 is more standard/flexible.
> 

Evidently, "leaning" towards option #1 was the wrong choice :)


This update splits the code into the two files (src/key-spec-parsing.{c,h}), 
and adds conditional compilation of supported keys, using per-file CFLAGS in 
local.mk:
    src_uniq_SOURCES = src/uniq.c src/key-spec-parsing.c
    src_uniq_CPPFLAGS = $(AM_CPPFLAGS)

Another program that needs all the keys might define:
    src_sort_SOURCES = src/sort.c src/key-spec-parsing.c
    src_sort_CPPFLAGS = -DKEY_SPEC_RANDOM -DKEY_SPEC_REVERSE -DKEY_SPEC_VERSION 
-DKEY_SPEC_HUMAN_NUMERIC $(AM_CPPFLAGS)

These are explained in 'src/key-spec-parsing.c':
  /* define the following to enable extra key options:
      KEY_SPEC_RANDOM       - sort by random order (-k1R,1)
      KEY_SPEC_REVERSE      - reverse sort order   (-k1r,1)
      KEY_SPEC_VERSION      - Version sort order   (-k1V,1)
      KEY_SPEC_HUMAN_NUMERIC- Human sizes order    (-k1h,1)

    If these are not defined, specifing them will generate an error.
  
    See 'set_ordering()' and 'key_to_opts()' in this file,
    and "src_uniq_CPPFLAGS" in "src/local.mk" for usage examples.
   */


-gordon

Attachment: uniq_key5.patch.xz
Description: application/xz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]