Ticket #4470: shell.patch

File shell.patch, 1.6 KB (added by codemonkey@…, 12 years ago)
  • builtins.c

    diff -r 1bb2d1cf49a5 -r 046cc0beef5b builtins.c
    a b  
    2525# include "variable.h"
    2626# include "timestamp.h"
    2727# include <ctype.h>
     28# include <sys/types.h>
     29# include <sys/wait.h>
    2830
    2931/*
    3032 * builtins.c - builtin jam rules
     
    17241726    #define pclose _pclose
    17251727#endif
    17261728
     1729static char * rtrim(char *s)
     1730{
     1731    char *p = s;
     1732    while(*p) ++p;
     1733    for(--p; p >= s && isspace(*p); *p-- = 0);
     1734    return s;
     1735}
     1736
    17271737LIST *builtin_shell( PARSE *parse, FRAME *frame )
    17281738{
    17291739    LIST* command = lol_get( frame->args, 0 );
     
    17351745    int exit_status = -1;
    17361746    int exit_status_opt = 0;
    17371747    int no_output_opt = 0;
     1748    int strip_eol_opt = 0;
    17381749   
    17391750    /* Process the variable args options. */
    17401751    {
     
    17501761            {
    17511762                no_output_opt = 1;
    17521763            }
     1764            else if ( strcmp("strip-eol", arg->string) == 0 )
     1765            {
     1766                strip_eol_opt = 1;
     1767            }
    17531768            arg = lol_get( frame->args, ++a );
    17541769        }
    17551770    }
     
    17671782        buffer[ret] = 0;
    17681783        if ( ! no_output_opt )
    17691784        {
     1785            if ( strip_eol_opt )
     1786                rtrim(buffer);
    17701787            string_append( &s, buffer );
    17711788        }
    17721789    }
     
    17801797    /* The command exit result next. */
    17811798    if ( exit_status_opt )
    17821799    {
     1800        if ( WIFEXITED(exit_status) )
     1801            exit_status = WEXITSTATUS(exit_status);
     1802        else
     1803            exit_status = -1;
    17831804        sprintf (buffer, "%d", exit_status);
    17841805        result = list_new( result, newstr( buffer ) );
    17851806    }