Changeset 2172 for trunk/src


Ignore:
Timestamp:
Dec 31, 2008, 1:03:02 AM (17 years ago)
Author:
bird
Message:

kmk: Added $(root ) to help out with checking for absolute paths on Windows and OS/2.

Location:
trunk/src/kmk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.am

    r2161 r2172  
    145145        -DCONFIG_WITH_STRING_FUNCTIONS \
    146146        -DCONFIG_WITH_LOOP_FUNCTIONS \
     147        -DCONFIG_WITH_ROOT_FUNC \
    147148        -DCONFIG_PRETTY_COMMAND_PRINTING \
    148149        -DCONFIG_WITH_PRINT_STATS_SWITCH \
  • trunk/src/kmk/Makefile.kmk

    r2161 r2172  
    171171        CONFIG_WITH_STRING_FUNCTIONS \
    172172        CONFIG_WITH_LOOP_FUNCTIONS \
     173        CONFIG_WITH_ROOT_FUNC \
    173174        CONFIG_PRETTY_COMMAND_PRINTING \
    174175        CONFIG_WITH_PRINT_STATS_SWITCH \
  • trunk/src/kmk/function.c

    r2163 r2172  
    808808}
    809809
     810#ifdef CONFIG_WITH_ROOT_FUNC
     811/*
     812 $(root path)
     813
     814 This is mainly for dealing with drive letters and UNC paths on Windows
     815 and OS/2.
     816 */
     817static char *
     818func_root (char *o, char **argv, const char *funcname UNUSED)
     819{
     820  const char  *paths = argv[0] ? argv[0] : "";
     821  int          doneany = 0;
     822  const char  *p;
     823  unsigned int len;
     824
     825  while ((p = find_next_token (&paths, &len)) != 0)
     826    {
     827      const char *p2 = p;
     828
     829#ifdef HAVE_DOS_PATHS
     830      if (   len >= 2
     831          && p2[1] == ':'
     832          && (   (p2[0] >= 'A' && p2[0] <= 'Z')
     833              || (p2[0] >= 'a' && p2[0] <= 'z')))
     834        {
     835          p2 += 2;
     836          len -= 2;
     837        }
     838      else if (len >= 4 && IS_PATHSEP(p2[0]) && IS_PATHSEP(p2[1])
     839               && !IS_PATHSEP(p2[2]))
     840        {
     841          /* Min recognized UNC: "//./" - find the next slash
     842             Typical root: "//srv/shr/" */
     843          /* XXX: Check if //./ needs special handling. */
     844
     845          p2 += 3;
     846          len -= 3;
     847          while (len > 0 && !IS_PATHSEP(*p2))
     848            p2++, len--;
     849
     850          if (len && IS_PATHSEP(p2[0]) && (len == 1 || !IS_PATHSEP(p2[1])))
     851            {
     852              p2++;
     853              len--;
     854
     855              if (len) /* optional share */
     856                while (len > 0 && !IS_PATHSEP(*p2))
     857                  p2++, len--;
     858            }
     859          else
     860            p2 = NULL;
     861        }
     862      else if (IS_PATHSEP(*p2))
     863        {
     864          p2++;
     865          len--;
     866        }
     867      else
     868        p2 = NULL;
     869
     870#elif defined (VMS) || defined (AMGIA)
     871      /* XXX: VMS and AMGIA */
     872      fatal (NILF, _("$(root ) is not implemented on this platform"));
     873#else
     874      if (IS_PATHSEP(*p2))
     875        {
     876          p2++;
     877          len--;
     878        }
     879      else
     880        p2 = NULL;
     881#endif
     882      if (p2 != NULL)
     883        {
     884          /* Include all subsequent path seperators. */
     885
     886          while (len > 0 && IS_PATHSEP(*p2))
     887            p2++, len--;
     888          o = variable_buffer_output (o, p, p2 - p);
     889          o = variable_buffer_output (o, " ", 1);
     890          doneany = 1;
     891        }
     892    }
     893
     894  if (doneany)
     895    /* Kill last space.  */
     896    --o;
     897
     898  return o;
     899}
     900#endif /* CONFIG_WITH_ROOT_FUNC */
     901
    810902static char *
    811903func_addsuffix_addprefix (char *o, char **argv, const char *funcname)
     
    49715063  { STRING_SIZE_TUPLE("dir"),           0,  1,  1,  func_basename_dir},
    49725064  { STRING_SIZE_TUPLE("notdir"),        0,  1,  1,  func_notdir_suffix},
     5065#ifdef CONFIG_WITH_ROOT_FUNC
     5066  { STRING_SIZE_TUPLE("root"),          0,  1,  1,  func_root},
     5067#endif
    49735068  { STRING_SIZE_TUPLE("subst"),         3,  3,  1,  func_subst},
    49745069  { STRING_SIZE_TUPLE("suffix"),        0,  1,  1,  func_notdir_suffix},
  • trunk/src/kmk/variable.c

    r2164 r2172  
    12071207  && defined (CONFIG_WITH_PRINTF) \
    12081208  && defined (CONFIG_WITH_LOOP_FUNCTIONS) \
     1209  && defined (CONFIG_WITH_ROOT_FUNC) \
    12091210  && defined (CONFIG_WITH_STRING_FUNCTIONS) \
    12101211  && defined (KMK_HELPERS)
     
    12321233                          " printf"
    12331234                          " for while"
     1235                          " root"
    12341236                          " length insert pos lastpos substr translate"
    12351237                          " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl "
     
    13011303  strcat (buf, " for while");
    13021304#  endif
     1305#  if defined (CONFIG_WITH_ROOT_FUNC)
     1306  strcat (buf, " root");
     1307#  endif
    13031308#  if defined (CONFIG_WITH_STRING_FUNCTIONS)
    13041309  strcat (buf, " length insert pos lastpos substr translate");
Note: See TracChangeset for help on using the changeset viewer.