Ignore:
Timestamp:
Jul 1, 2020, 10:24:52 PM (5 years ago)
Author:
bird
Message:

kmk: Added version sort function: versort, rversort, versortfiles, rversortfiles, qversortfiles, qrversortfiles. Try get the real host version on windows by using RtlGetVersion.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/function.c

    r3389 r3394  
    9090#  include "kmkbuiltin/mscfakes.h"
    9191# endif
     92# include "version_compare.h"
    9293#endif
    9394
     
    17661767}
    17671768
     1769#ifdef KMK
     1770/* Compare strings *S1 and *S2.
     1771   Return negative if the first is less, positive if it is greater,
     1772   zero if they are equal.  */
     1773
     1774static int
     1775version_compare_wrapper (const void *v1, const void *v2)
     1776{
     1777  const char *s1 = *((char **)v1);
     1778  const char *s2 = *((char **)v2);
     1779  return version_compare (s1, s2);
     1780}
     1781#endif /* KMK */
    17681782
    17691783/*
     
    18061820
    18071821      /* Now sort the list of words.  */
     1822#ifdef KMK
     1823      if (funcname[0] == 'v' || funcname[1] == 'v')
     1824        qsort (words, wordi, sizeof (char *), version_compare_wrapper);
     1825      else
     1826        qsort (words, wordi, sizeof (char *), alpha_compare);
     1827#else
    18081828      qsort (words, wordi, sizeof (char *), alpha_compare);
     1829#endif
    18091830
    18101831      /* Now write the sorted list, uniquified.  */
    18111832#ifdef CONFIG_WITH_RSORT
    1812       if (strcmp (funcname, "rsort"))
     1833      if (*funcname != 'r')
    18131834        {
    18141835          /* sort */
     
    67826803
    67836804static char *common_sortfiles (char *o, char **argv, unsigned int style,
    6784                                int ascending)
     6805                               int ascending, int version)
    67856806{
    67866807  struct nameseq *chain = helper_parse_file_list (argv[0], style, 0);
     
    68406861{
    68416862  return common_sortfiles (o, argv, Q_IN_QUOTED | Q_RET_QUOTED | Q_SEP_SPACE,
    6842                            funcname[0] != 'r');
     6863                           funcname[0] != 'r',
     6864                           funcname[0] == 'v' || funcname[1] == 'v');
    68436865}
    68446866
     
    68516873{
    68526874  unsigned int const style = helper_file_quoting_style (argv[0], Q_QDEFAULT);
    6853   return common_sortfiles (o, &argv[1], style, funcname[1] != 'r');
     6875  return common_sortfiles (o, &argv[1], style, funcname[1] != 'r',
     6876                           funcname[1] == 'v' || funcname[2] == 'v');
    68546877}
    68556878
     
    68766899    {
    68776900      PATH_VAR (outbuf);
    6878       int doneany = 0;
    68796901      struct nameseq *chain = helper_parse_file_list (line, style, 0);
    68806902
     
    74087430#ifdef CONFIG_WITH_RSORT
    74097431  FT_ENTRY ("rsort",         0,  1,  1,  func_sort),
     7432# ifdef KMK
     7433  FT_ENTRY ("rversort",      0,  1,  1,  func_sort),
     7434# endif
    74107435#endif
    74117436  FT_ENTRY ("shell",         0,  1,  1,  func_shell),
    74127437  FT_ENTRY ("sort",          0,  1,  1,  func_sort),
     7438# ifdef KMK
     7439  FT_ENTRY ("versort",       0,  1,  1,  func_sort),
     7440# endif
    74137441  FT_ENTRY ("strip",         0,  1,  1,  func_strip),
    74147442#ifdef CONFIG_WITH_WHERE_FUNCTION
     
    75707598  FT_ENTRY ("foreachfile",   3,  3, 0, func_foreachfile),
    75717599  FT_ENTRY ("sortfiles",     0,  1, 1, func_sortfiles),
     7600  FT_ENTRY ("versortfiles",  0,  1, 1, func_sortfiles),
    75727601# ifdef CONFIG_WITH_RSORT
    75737602  FT_ENTRY ("rsortfiles",    0,  1, 1, func_sortfiles),
     7603  FT_ENTRY ("rversortfiles", 0,  1, 1, func_sortfiles),
    75747604# endif
    75757605  /* Function variants with preceding style argument and quoting by default. */
     
    75807610  FT_ENTRY ("qforeachfile", 1+3, 1+3, 0, func_q_foreachfile),
    75817611  FT_ENTRY ("qsortfiles",   1+0, 1+1, 1, func_q_sortfiles),
     7612  FT_ENTRY ("qversortfiles",1+0, 1+1, 1, func_q_sortfiles),
    75827613# ifdef CONFIG_WITH_RSORT
    75837614  FT_ENTRY ("qrsortfiles",  1+0, 1+1, 1, func_q_sortfiles),
     7615  FT_ENTRY ("qrversortfiles",1+0,1+1, 1, func_q_sortfiles),
    75847616# endif
    75857617  FT_ENTRY ("qabspath",     1+0, 1+1, 1, func_q_abspath),
Note: See TracChangeset for help on using the changeset viewer.