Changeset 775 for trunk/src


Ignore:
Timestamp:
Jan 19, 2007, 6:57:42 AM (19 years ago)
Author:
bird
Message:

ported printf to MSC.

Location:
trunk/src/gmake
Files:
6 edited

Legend:

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

    r763 r775  
    109109        kmkbuiltin/mv.c \
    110110        kmkbuiltin/ln.c \
     111        kmkbuiltin/printf.c \
    111112        kmkbuiltin/rm.c \
    112113        kmkbuiltin/rmdir.c \
     
    130131# Standalone kmkbuiltin commands.
    131132#
    132 PROGRAMS += kmk_append kmk_cat kmk_cp kmk_echo kmk_mkdir kmk_mv kmk_install kmk_ln kmk_rm kmk_rmdir
     133PROGRAMS += kmk_append kmk_cat kmk_cp kmk_echo kmk_mkdir kmk_mv kmk_install kmk_ln kmk_printf kmk_rm kmk_rmdir
    133134
    134135kmk_append_TEMPLATE = BIN
     
    238239kmk_mv_DEFS += HAVE_CONFIG_H
    239240kmk_mv_SOURCES += \
     241        kmkbuiltin/mscfakes.c \
     242        getopt.c \
     243        getopt1.c
     244endif
     245
     246kmk_printf_TEMPLATE = BIN
     247kmk_printf_DEFS = kmk_builtin_printf=main
     248kmk_printf_SOURCES = \
     249        kmkbuiltin/printf.c \
     250        kmkbuiltin/err.c
     251ifeq ($(filter-out win32 win64 win nt,$(BUILD_TARGET)),)
     252kmk_printf_INCS += $(PATH_TARGET) .
     253kmk_printf_DEFS += HAVE_CONFIG_H
     254kmk_printf_SOURCES += \
    240255        kmkbuiltin/mscfakes.c \
    241256        getopt.c \
  • trunk/src/gmake/kmkbuiltin.c

    r613 r775  
    3131#ifdef _MSC_VER
    3232# include <io.h>
    33 #endif 
     33#endif
    3434#include "kmkbuiltin/err.h"
    3535#include "kmkbuiltin.h"
     
    184184    if (!strcmp(pszCmd, "append"))
    185185        rc = kmk_builtin_append(argc, argv, environ);
     186    else if (!strcmp(pszCmd, "printf"))
     187        rc = kmk_builtin_printf(argc, argv, environ);
    186188    else if (!strcmp(pszCmd, "echo"))
    187189        rc = kmk_builtin_echo(argc, argv, environ);
  • trunk/src/gmake/kmkbuiltin.h

    r611 r775  
    3636extern int kmk_builtin_mkdir(int argc, char **argv, char **envp);
    3737extern int kmk_builtin_mv(int argc, char **argv, char **envp);
     38extern int kmk_builtin_printf(int argc, char **argv, char **envp);
    3839extern int kmk_builtin_rm(int argc, char **argv, char **envp);
    3940extern int kmk_builtin_rmdir(int argc, char **argv, char **envp);
  • trunk/src/gmake/kmkbuiltin/mscfakes.c

    r370 r775  
    3737
    3838char *dirname(char *path)
    39 {         
     39{
    4040    /** @todo later */
    4141    return path;
     
    127127    return cch;
    128128}
    129 #endif 
     129#endif
    130130
    131131
     
    151151}
    152152
     153
     154intmax_t strtoimax(const char *nptr, char **endptr, int base)
     155{
     156    return strtol(nptr, endptr, base); /** @todo fix this. */
     157}
     158
     159
     160uintmax_t strtoumax(const char *nptr, char **endptr, int base)
     161{
     162    return strtoul(nptr, endptr, base); /** @todo fix this. */
     163}
     164
     165
     166int asprintf(char **strp, const char *fmt, ...)
     167{
     168    int rc;
     169    va_list va;
     170    va_start(va, fmt);
     171    rc = vasprintf(strp, fmt, va);
     172    va_end(va);
     173    return rc;
     174}
     175
     176
     177int vasprintf(char **strp, const char *fmt, va_list va)
     178{
     179    int rc;
     180    char *psz;
     181    size_t cb = 1024;
     182
     183    *strp = NULL;
     184    for (;;)
     185    {
     186        va_list va2;
     187
     188        psz = malloc(cb);
     189        if (!psz)
     190            return -1;
     191
     192#ifdef va_copy
     193        va_copy(va2, va);
     194        rc = snprintf(psz, cb, fmt, va2);
     195        va_end(vaCopy);
     196#else
     197        va2 = va;
     198        rc = snprintf(psz, cb, fmt, va2);
     199#endif
     200        if (rc < 0 || (size_t)rc < cb)
     201            break;
     202        cb *= 2;
     203        free(psz);
     204    }
     205
     206    *strp = psz;
     207    return rc;
     208}
     209
  • trunk/src/gmake/kmkbuiltin/mscfakes.h

    r526 r775  
    3131#include <direct.h>
    3232#include <time.h>
     33#include <stdarg.h>
    3334#undef setmode
    3435#include "getopt.h"
     
    8687
    8788#ifndef timerisset
    88 struct timeval 
     89struct timeval
    8990{
    9091    long tv_sec;
    9192    long tv_usec;
    9293};
    93 #endif 
     94#endif
    9495
    95 struct iovec 
     96struct iovec
    9697{
    9798    char *iov_base;
     
    99100};
    100101
     102typedef __int64 intmax_t;
     103typedef unsigned __int64 uintmax_t;
    101104
    102105#define chown(path, uid, gid) 0         /** @todo implement fchmod! */
     
    118121#define readlink(link, buf, size) -1
    119122#define reallocf(old, size) realloc(old, size)
     123intmax_t strtoimax(const char *nptr, char **endptr, int base);
     124int asprintf(char **strp, const char *fmt, ...);
     125int vasprintf(char **strp, const char *fmt, va_list ap);
    120126#if _MSC_VER < 1400
    121127int snprintf(char *buf, size_t size, const char *fmt, ...);
    122128#else
    123129#define snprintf _snprintf
    124 #endif 
     130#endif
    125131size_t strlcpy(char *, const char *, size_t);
    126132int symlink(const char *pszDst, const char *pszLink);
     
    129135
    130136#endif /* _MSC_VER */
    131 #endif 
     137#endif
    132138
  • trunk/src/gmake/kmkbuiltin/printf.c

    r774 r775  
    3030 */
    3131
    32 #include <sys/cdefs.h>
     32/*#include <sys/cdefs.h>
    3333#ifndef lint
    3434#if !defined(BUILTIN) && !defined(SHELL)
     
    4444__RCSID("$NetBSD: printf.c,v 1.31 2005/03/22 23:55:46 dsl Exp $");
    4545#endif
    46 #endif /* not lint */
     46#endif*/ /* not lint */
    4747
    4848#include <sys/types.h>
    4949
    5050#include <ctype.h>
    51 #include <err.h>
     51#include "err.h"
    5252#include <errno.h>
     53#ifndef _MSC_VER
    5354#include <inttypes.h>
     55#endif
    5456#include <limits.h>
    5557#include <locale.h>
     
    5860#include <stdlib.h>
    5961#include <string.h>
     62#ifndef _MSC_VER
    6063#include <unistd.h>
     64#else
     65#include "mscfakes.h"
     66#endif
    6167
    6268#ifdef __GNUC__
     
    7783static char     *mklong(const char *, int);
    7884static void      check_conversion(const char *, const char *);
    79 static void      usage(void); 
     85static void      usage(void);
    8086
    8187static void     b_count(int);
     
    8894
    8995#ifdef BUILTIN          /* csh builtin */
    90 #define main progprintf
     96#define kmk_builtin_printf progprintf
    9197#endif
    9298
    9399#ifdef SHELL            /* sh (aka ash) builtin */
    94 #define main printfcmd
     100#define kmk_builtin_printf printfcmd
    95101#include "../../bin/sh/bltin/bltin.h"
    96102#endif /* SHELL */
     
    120126}
    121127
    122 int main(int, char **);
    123 int main(int argc, char *argv[])
     128int kmk_builtin_printf(int argc, char *argv[])
    124129{
    125130        char *fmt, *start;
     
    129134        int ch;
    130135
    131 #if !defined(SHELL) && !defined(BUILTIN)
     136        /* kmk: reinitialize globals */
     137        b_length = 0;
     138        b_fmt = NULL;
     139        rval = 0;
     140        gargv = NULL;
     141
     142        /* kmk: reset getopt and set progname */
     143        g_progname = argv[0];
     144        opterr = 1;
     145        optarg = NULL;
     146        optopt = 0;
     147#if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__)
     148        optreset = 1;
     149        optind = 1;
     150#else
     151        optind = 0; /* init */
     152#endif
     153
     154#if !defined(SHELL) && !defined(BUILTIN) && !defined(kmk_builtin_printf) /* kmk did this already. */
    132155        (void)setlocale (LC_ALL, "");
    133156#endif
     
    158181                 * Basic algorithm is to scan the format string for conversion
    159182                 * specifications -- once one is found, find out if the field
    160                  * width or precision is a '*'; if it is, gather up value. 
     183                 * width or precision is a '*'; if it is, gather up value.
    161184                 * Note, format strings are reused as necessary to use up the
    162                  * provided arguments, arguments of zero/null string are 
     185                 * provided arguments, arguments of zero/null string are
    163186                 * provided to use up the format string.
    164187                 */
     
    322345
    323346/*
    324  * Print SysV echo(1) style escape string 
     347 * Print SysV echo(1) style escape string
    325348 *      Halts processing string if a \c escape is encountered.
    326349 */
     
    345368                }
    346369
    347                 /* 
     370                /*
    348371                 * %b string octal constants are not like those in C.
    349                  * They start with a \0, and are followed by 0, 1, 2, 
    350                  * or 3 octal digits. 
     372                 * They start with a \0, and are followed by 0, 1, 2,
     373                 * or 3 octal digits.
    351374                 */
    352375                if (ch == '0') {
     
    390413
    391414/*
    392  * Print "standard" escape characters 
     415 * Print "standard" escape characters
    393416 */
    394417static char *
     
    519542{
    520543        static char copy[64];
    521         size_t len;     
     544        size_t len;
    522545
    523546        len = strlen(str) + 2;
     
    530553        copy[len - 2] = ch;
    531554        copy[len - 1] = '\0';
    532         return copy;   
     555        return copy;
    533556}
    534557
     
    659682usage(void)
    660683{
    661         (void)fprintf(stderr, "Usage: %s format [arg ...]\n", getprogname());
    662 }
     684        (void)fprintf(stderr, "Usage: %s format [arg ...]\n", g_progname);
     685}
Note: See TracChangeset for help on using the changeset viewer.