~ubuntu-branches/ubuntu/oneiric/gimp/oneiric-security

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/tinyscheme/scheme.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2010-07-12 15:08:08 UTC
  • mfrom: (1.1.23) (0.4.6 sid)
  • Revision ID: package-import@ubuntu.com-20100712150808-db9xqgtxrvpyl3g2
Tags: 2.6.10-1ubuntu1
Resync on Debian, dropping changes which are in the new version

Show diffs side-by-side

added added

removed removed

Lines of Context:
3507
3507
     return sc->T;
3508
3508
}
3509
3509
 
3510
 
static int is_list(scheme *sc, pointer a) {
3511
 
    pointer slow, fast;
3512
 
 
3513
 
    slow = fast = a;
3514
 
    while (1)
3515
 
    {
3516
 
        if (fast == sc->NIL)
3517
 
                return 1;
3518
 
        if (!is_pair(fast))
3519
 
                return 0;
3520
 
        fast = cdr(fast);
3521
 
        if (fast == sc->NIL)
3522
 
                return 1;
3523
 
        if (!is_pair(fast))
3524
 
                return 0;
3525
 
        fast = cdr(fast);
3526
 
 
3527
 
        slow = cdr(slow);
3528
 
        if (fast == slow)
3529
 
        {
3530
 
            /* the fast pointer has looped back around and caught up
3531
 
               with the slow pointer, hence the structure is circular,
3532
 
               not of finite length, and therefore not a list */
3533
 
            return 0;
3534
 
        }
3535
 
    }
3536
 
}
3537
 
 
 
3510
static int is_list(scheme *sc, pointer a)
 
3511
{ return list_length(sc,a) >= 0; }
 
3512
 
 
3513
/* Result is:
 
3514
   proper list: length
 
3515
   circular list: -1
 
3516
   not even a pair: -2
 
3517
   dotted list: -2 minus length before dot
 
3518
*/
3538
3519
int list_length(scheme *sc, pointer a) {
3539
3520
    int i=0;
3540
3521
    pointer slow, fast;
3545
3526
        if (fast == sc->NIL)
3546
3527
                return i;
3547
3528
        if (!is_pair(fast))
3548
 
                return i;
 
3529
                return -2 - i;
3549
3530
        fast = cdr(fast);
3550
3531
        ++i;
3551
3532
        if (fast == sc->NIL)
3552
3533
                return i;
3553
3534
        if (!is_pair(fast))
3554
 
                return i;
 
3535
                return -2 - i;
3555
3536
        ++i;
3556
3537
        fast = cdr(fast);
3557
3538
 
 
3539
    /* Safe because we would have already returned if `fast'
 
3540
       encountered a non-pair. */
3558
3541
        slow = cdr(slow);
3559
3542
        if (fast == slow)
3560
3543
        {
3645
3628
     case OP_PAIRP:       /* pair? */
3646
3629
          s_retbool(is_pair(car(sc->args)));
3647
3630
     case OP_LISTP:       /* list? */
3648
 
          s_retbool(is_list(sc, car(sc->args)));
 
3631
          s_retbool(list_length(sc, car(sc->args)) >= 0);
 
3632
 
3649
3633
     case OP_ENVP:        /* environment? */
3650
3634
          s_retbool(is_environment(car(sc->args)));
3651
3635
     case OP_VECTORP:     /* vector? */