Exemplo n.º 1
0
int exec_check
(
    string const * command,
    LIST * * pShell,
    int * error_length,
    int * error_max_length
)
{
    /* Default shell does nothing when triggered with an empty or a
     * whitespace-only command so we simply skip running it in that case. We
     * still pass them on to non-default shells as we do not really know what
     * they are going to do with such commands.
     */
    if ( list_empty( *pShell ) )
    {
        char const * s = command->value;
        while ( isspace( *s ) ) ++s;
        if ( !*s )
            return EXEC_CHECK_NOOP;
    }

    /* Check prerequisites for executing raw commands. */
    if ( is_raw_command_request( *pShell ) )
    {
        int const raw_cmd_length = raw_command_length( command->value );
        if ( raw_cmd_length < 0 )
        {
            /* Invalid characters detected - fallback to default shell. */
            list_free( *pShell );
            *pShell = L0;
        }
        else if ( raw_cmd_length > MAX_RAW_COMMAND_LENGTH )
        {
            *error_length = raw_cmd_length;
            *error_max_length = MAX_RAW_COMMAND_LENGTH;
            return EXEC_CHECK_TOO_LONG;
        }
        else
            return raw_cmd_length ? EXEC_CHECK_OK : EXEC_CHECK_NOOP;
    }

    /* Now we know we are using an external shell. Note that there is no need to
     * check for too long command strings when using an external shell since we
     * use a command file and assume no one is going to set up a JAMSHELL format
     * string longer than a few hundred bytes at most which should be well under
     * the total command string limit. Should someone actually construct such a
     * JAMSHELL value it will get reported as an 'invalid parameter'
     * CreateProcessA() Windows API failure which seems like a good enough
     * result for such intentional mischief.
     */

    /* Check for too long command lines. */
    return check_cmd_for_too_long_lines( command->value, maxline(),
        error_length, error_max_length );
}
Exemplo n.º 2
0
static int  message(int x1,int y1,char* txt1)
{  char     txt[STRSIZ];
   int      mess, marg, i=0, x2, y2;
   void *      dump;
   int         xold, yold;
   char * c;   

     strcpy(txt,txt1);
     c=txt;
     xold = where_x();
     yold = where_y();  
     x2 = x1 + maxline(&y2,txt) /*+4*/;
     y2 = y1 + y2 + 1;
     get_text(x1,y1,x2,y2,&dump); 
     chepbox(x1,y1,x2,y2);     
     be_be();
     c=strtok(txt,"\n");
     
     while(c)
     {
        ++(i);
        marg = (x2 - x1 - strlen(c)) / 2;
        if (y1+i == y2) 
        {  goto_xy(x1+1+marg ,y1 + i);
           print("%s",c);
        }else
        {  char buff[STRSIZ];
           memset(buff,' ',x2-x1 -1);
           memcpy(buff+marg,c,strlen(c));
           buff[x2-x1-1]=0;
           goto_xy(x1+1,y1+i);
           print(buff);
        }
        c=strtok(NULL,"\n");   
     }
ret_:
     if (blind) mess='Y' ; else  do{mess = inkey();} while (mess == KB_SIZE);
/* mouse filter */
     if (mess == KB_MOUSE)
     {
        if (  (mouse_info.but1 !=2) ||
              (mouse_info.row < y1) || (mouse_info.row > y2) ||
              (mouse_info.col < x1) || (mouse_info.col > x2)   ) goto ret_;
        if (mouse_info.row == y2 )
        {  if (mouse_info.col < (x1+x2)/2 /* -1*/ ) mess='Y';
           if (mouse_info.col > (x1+x2)/2 /*+1 */) mess='N';
        }       
     }   
/* end of filter */         
     put_text(&dump); 
     goto_xy(xold,yold);     
     return mess;
}   /* message */
Exemplo n.º 3
0
void execnt_unit_test()
{
#if !defined( NDEBUG )
    /* vc6 preprocessor is broken, so assert with these strings gets confused.
     * Use a table instead.
     */
    {
        typedef struct test { char * command; int result; } test;
        test tests[] = {
            { "", 0 },
            { "  ", 0 },
            { "x", 1 },
            { "\nx", 1 },
            { "x\n", 1 },
            { "\nx\n", 1 },
            { "\nx \n", 2 },
            { "\nx \n ", 2 },
            { " \n\t\t\v\r\r\n \t  x  \v \t\t\r\n\n\n   \n\n\v\t", 8 },
            { "x\ny", -1 },
            { "x\n\n y", -1 },
            { "echo x > foo.bar", -1 },
            { "echo x < foo.bar", -1 },
            { "echo x | foo.bar", -1 },
            { "echo x \">\" foo.bar", 18 },
            { "echo x '<' foo.bar", 18 },
            { "echo x \"|\" foo.bar", 18 },
            { "echo x \\\">\\\" foo.bar", -1 },
            { "echo x \\\"<\\\" foo.bar", -1 },
            { "echo x \\\"|\\\" foo.bar", -1 },
            { "\"echo x > foo.bar\"", 18 },
            { "echo x \"'\"<' foo.bar", -1 },
            { "echo x \\\\\"<\\\\\" foo.bar", 22 },
            { "echo x \\x\\\"<\\\\\" foo.bar", -1 },
            { 0 } };
        test const * t;
        for ( t = tests; t->command; ++t )
            assert( raw_command_length( t->command ) == t->result );
    }

    {
        int const length = maxline() + 9;
        char * const cmd = (char *)BJAM_MALLOC_ATOMIC( length + 1 );
        memset( cmd, 'x', length );
        cmd[ length ] = 0;
        assert( raw_command_length( cmd ) == length );
        BJAM_FREE( cmd );
    }
#endif
}
//Gauss消元法
void gauss(double lambda)
{
    double **a;
    double *X;
    double m, sigma, t;
    int i, j, k, n = 10;
    X = (double *)malloc(10 * sizeof(double));
    initMat(a);

    for (i = 0; i<n; i++) {
        a[i][i] -= lambda;
        a[i][10] = 0;
    }

    for (k = 0; k<n - 1; k++) {
        maxline(a, n, k);
        for (i = k + 1; i<n; i++) {
            m = a[i][k] / a[k][k];
            for (j = k; j<n + 1; j++)
                a[i][j] = a[i][j] - m*a[k][j];
        }
    }

    X[n - 1] = 1;    
    t = 0;
    for (k = n - 2; k >= 0; k--) {
        sigma = 0;
        for (j = k + 1; j<n; j++)
            sigma += a[k][j] * X[j];
        X[k] = (a[k][n] - sigma) / a[k][k];
    }
    for (i = 0; i<n; i++)
        t += X[i] * X[i];
    t = sqrt(t);
    printf("eigenvector = ( ");
    for (i = 0; i<n; i++)
        printf("%.12e ", X[i]/t);
    printf(")\n");
    for (i = 0; i<10; i++)
        free(a[i]);
    free(a);
    free(X);
}