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

ported printf to MSC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.