Changeset 601 for trunk/src


Ignore:
Timestamp:
Nov 26, 2006, 1:19:19 AM (19 years ago)
Author:
bird
Message:

o Added rmdir as builtin and external command.
o Made mkdir not modify the argument strings.
o Made mkdir deal properly with DOS slashes on OS/2 and Windows.

Location:
trunk/src/gmake
Files:
5 edited

Legend:

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

    r591 r601  
    104104        kmkbuiltin/ln.c \
    105105        kmkbuiltin/rm.c \
     106        kmkbuiltin/rmdir.c \
    106107        \
    107108        kmkbuiltin/err.c \
     
    123124# Standalone kmkbuiltin commands.
    124125#
    125 PROGRAMS += kmk_append kmk_cp kmk_echo kmk_mkdir kmk_install kmk_ln kmk_rm
     126PROGRAMS += kmk_append kmk_cp kmk_echo kmk_mkdir kmk_install kmk_ln kmk_rm kmk_rmdir
    126127
    127128kmk_append_TEMPLATE = BIN
     
    218219kmk_rm_SOURCES += \
    219220        kmkbuiltin/mscfakes.c\
     221        getopt.c \
     222        getopt1.c
     223endif
     224
     225kmk_rmdir_TEMPLATE = BIN
     226kmk_rmdir_DEFS = kmk_builtin_rmdir=main
     227kmk_rmdir_SOURCES = \
     228        kmkbuiltin/rmdir.c \
     229        kmkbuiltin/err.c \
     230        kmkbuiltin/setmode.c
     231ifeq ($(filter-out win32 win64 win nt,$(BUILD_TARGET)),)
     232kmk_rmdir_INCS += $(PATH_TARGET) .
     233kmk_rmdir_DEFS += HAVE_CONFIG_H
     234kmk_rmdir_SOURCES += \
     235        kmkbuiltin/mscfakes.c \
    220236        getopt.c \
    221237        getopt1.c
  • trunk/src/gmake/kmkbuiltin.c

    r507 r601  
    196196    else if (!strcmp(pszCmd, "rm"))
    197197        rc = kmk_builtin_rm(argc, argv, environ);
    198     //else if (!strcmp(pszCmd, "rmdir"))
    199     //    rc = kmk_builtin_rmdir(argc, argv, environ);
     198    else if (!strcmp(pszCmd, "rmdir"))
     199        rc = kmk_builtin_rmdir(argc, argv, environ);
    200200    /* obsolete */
    201201    else if (!strcmp(pszCmd, "cp"))
  • trunk/src/gmake/kmkbuiltin/mkdir.c

    r557 r601  
    5858#else
    5959#include "mscfakes.h"
     60#include <malloc.h>
    6061#endif
    6162
     
    161162        char *p;
    162163
     164        const size_t len = strlen(path);
     165        p = alloca(len + 1);
     166        path = memcpy(p, path, len + 1);
     167
     168#if defined(_MSC_VER) || defined(__EMX__)
     169        p = strchr(path, '\\');
     170        while (p) {
     171                *p++ = '/';
     172                p = strchr(p, '\\');
     173        }
     174#endif
     175
    163176        p = path;
    164177        oumask = 0;
    165178        retval = 0;
    166179#if defined(_MSC_VER) || defined(__EMX__)
    167         if (    (    (p[0] >= 'A' && p[0] <= 'Z')
    168                  ||  (p[0] >= 'a' && p[0] <= 'z'))
    169             && p[1] == ':')
    170             p += 2;
    171         else if (   (p[0] == '/' || p[0] == '\\')
    172                  && (p[1] == '/' || p[1] == '\\')
    173                  && (p[2] != '/' && p[2] != '\\'))
    174         {
    175             char *p2;
    176             p += 2;
    177             p2 = strpbrk(p, "\\/");
    178             if (p2)
    179                 p = p2 + 1;
    180         }
     180        if (    (    (p[0] >= 'A' && p[0] <= 'Z')
     181                 ||  (p[0] >= 'a' && p[0] <= 'z'))
     182            && p[1] == ':')
     183                p += 2;
     184        else if (   p[0] == '/'
     185                 && p[1] == '/'
     186                 && p[2] != '/')
     187        {
     188                char *p2;
     189                p += 2;
     190                p2 = strchr(p, '/');
     191                if (p2)
     192                        p = p2 + 1;
     193        }
    181194#endif
    182195        if (p[0] == '/')                /* Skip leading '/'. */
  • trunk/src/gmake/kmkbuiltin/rmdir.c

    r598 r601  
    3939#endif /* not lint */
    4040#endif
     41#if 0
    4142#include <sys/cdefs.h>
    4243__FBSDID("$FreeBSD: src/bin/rmdir/rmdir.c,v 1.20 2005/01/26 06:51:28 ssouhlal Exp $");
     44#endif
    4345
    44 #include <err.h>
     46#include "err.h"
    4547#include <stdio.h>
    4648#include <stdlib.h>
    4749#include <string.h>
     50#ifndef _MSC_VER
    4851#include <unistd.h>
     52#else
     53#include <malloc.h>
     54#include "mscfakes.h"
     55#endif
    4956
    50 static int rm_path(char *);
    51 static void usage(void);
     57static int rm_path(const char *);
     58static int usage(void);
    5259
    5360static int pflag;
     
    5562
    5663int
    57 main(int argc, char *argv[])
     64kmk_builtin_rmdir(int argc, char *argv[])
    5865{
    5966        int ch, errors;
    6067
     68        /* reinitialize globals */
     69        vflag = 0;
     70       
     71        /* kmk: reset getopt and set progname */
     72        g_progname = argv[0];
     73        opterr = 1;
     74        optarg = NULL;
     75        optopt = 0;
     76#if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__)
     77        optreset = 1;
     78        optind = 1;
     79#else
     80        optind = 0; /* init */
     81#endif
    6182        while ((ch = getopt(argc, argv, "pv")) != -1)
    6283                switch(ch) {
     
    6990                case '?':
    7091                default:
    71                         usage();
     92                        return usage();
    7293                }
    7394        argc -= optind;
     
    7596
    7697        if (argc == 0)
    77                 usage();
     98                return usage();
    7899
    79100        for (errors = 0; *argv; argv++) {
     
    89110        }
    90111
    91         exit(errors);
     112        return errors;
    92113}
    93114
     
    96117{
    97118        char *p;
     119        const size_t len = strlen(path);
     120        p = alloca(len + 1);
     121        path = memcpy(p, path, len + 1);
    98122
    99         p = path + strlen(path);
     123#if defined(_MSC_VER) || defined(__EMX__)
     124        p = strchr(path, '\\');
     125        while (p) {
     126                *p++ = '/';
     127                p = strchr(p, '\\');
     128        }
     129#endif
     130
     131        p = path + len;
    100132        while (--p > path && *p == '/')
    101133                ;
     
    108140                if (p == path)
    109141                        break;
     142#if defined(_MSC_VER) || defined(__EMX__)
     143                if (p[-1] == ':' && p - 2 == path)
     144                        break;
     145#endif
    110146
    111147                if (rmdir(path) < 0) {
     
    120156}
    121157
    122 static void
     158static int
    123159usage(void)
    124160{
    125161
    126162        (void)fprintf(stderr, "usage: rmdir [-pv] directory ...\n");
    127         exit(1);
     163        return 1;
    128164}
  • trunk/src/gmake/variable.c

    r578 r601  
    10621062#ifdef CONFIG_WITH_KMK_BUILTIN
    10631063  /* The supported kMk Builtin commands. */
    1064   (void) define_variable ("KMK_BUILTIN", 11, "append cp echo install ln mkdir rm", o_default, 0);
     1064  (void) define_variable ("KMK_BUILTIN", 11, "append cp echo install ln mkdir rm rmdir", o_default, 0);
    10651065#endif
    10661066
Note: See TracChangeset for help on using the changeset viewer.