Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/miscutils/dc.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/miscutils/dc.c

    r821 r1765  
    11/* vi: set sw=4 ts=4: */
    2 #include "busybox.h"
    3 #include <ctype.h>
    4 #include <stdio.h>
    5 #include <stdlib.h>
    6 #include <string.h>
    7 #include <unistd.h>
     2/*
     3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     4 */
     5
     6#include "libbb.h"
    87#include <math.h>
    98
    109/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
    1110
    12 static double stack[100];
     11enum { STACK_SIZE = COMMON_BUFSIZE / sizeof(double) };
     12
     13#define stack ((double*)&bb_common_bufsiz1)
    1314static unsigned int pointer;
    1415static unsigned char base;
     
    1617static void push(double a)
    1718{
    18     if (pointer >= (sizeof(stack) / sizeof(*stack)))
     19    if (pointer >= STACK_SIZE)
    1920        bb_error_msg_and_die("stack overflow");
    2021    stack[pointer++] = a;
     
    8889static void set_output_base(void)
    8990{
    90     base=(unsigned char)pop();
     91    base = (unsigned char)pop();
    9192    if ((base != 10) && (base != 16)) {
    92         fprintf(stderr, "Error: base = %d is not supported.\n", base);
    93         base=10;
     93        bb_error_msg("error, base %d is not supported", base);
     94        base = 10;
    9495    }
    9596}
     
    100101        printf("%x\n", (unsigned int)print);
    101102    else
    102     printf("%g\n", print);
     103        printf("%g\n", print);
    103104}
    104105
    105106static void print_stack_no_pop(void)
    106107{
    107     unsigned int i=pointer;
     108    unsigned int i = pointer;
    108109    while (i)
    109110        print_base(stack[--i]);
     
    116117
    117118struct op {
    118     const char *name;
     119    const char name[4];
    119120    void (*function) (void);
    120121};
     
    142143    {"f", print_stack_no_pop},
    143144    {"o", set_output_base},
    144     {0,    0}
     145    {"", 0}
    145146};
    146147
     
    161162    }
    162163
    163     while (o->name != 0) {
     164    while (o->name[0]) {
    164165        if (strcmp(o->name, argument) == 0) {
    165             (*(o->function)) ();
     166            o->function();
    166167            return;
    167168        }
    168169        o++;
    169170    }
    170     bb_error_msg_and_die("%s: syntax error.", argument);
     171    bb_error_msg_and_die("%s: syntax error", argument);
    171172}
    172173
     
    176177static char *get_token(char **buffer)
    177178{
    178     char *start   = NULL;
    179     char *current = *buffer;
    180 
    181     while (isspace(*current)) { current++; }
     179    char *start = NULL;
     180    char *current;
     181
     182    current = skip_whitespace(*buffer);
    182183    if (*current != 0) {
    183184        start = current;
    184         while (!isspace(*current) && *current != 0) { current++; }
     185        current = skip_non_whitespace(current);
    185186        *buffer = current;
    186187    }
     
    197198}
    198199
     200int dc_main(int argc, char **argv);
    199201int dc_main(int argc, char **argv)
    200202{
     
    205207        char *cursor = NULL;
    206208        char *token  = NULL;
    207         while ((line = bb_get_chomped_line_from_file(stdin))) {
     209        while ((line = xmalloc_getline(stdin))) {
    208210            cursor = line;
    209211            len = number_of_tokens(line);
     
    216218        }
    217219    } else {
    218         if (*argv[1]=='-')
     220        if (*argv[1] == '-')
    219221            bb_show_usage();
    220222        while (argc >= 2) {
Note: See TracChangeset for help on using the changeset viewer.