~ubuntu-branches/ubuntu/utopic/dicelab/utopic

« back to all changes in this revision

Viewing changes to roll.tc

  • Committer: Bazaar Package Importer
  • Author(s): Robert Lemmen
  • Date: 2009-11-25 12:30:05 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091125123005-ylg50em2n998a232
Tags: 0.7-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
        for (i = 0; i < rv->count; i++) {
222
222
                s *= rv->values[i];
223
223
        }
 
224
        rv->count = 1;
 
225
        rv->values = (int*)realloc(rv->values, sizeof(int) * rv->count);
224
226
        rv->values[0] = s;
225
 
        rv->count = 1;
226
227
        return rv;
227
228
}
228
229
 
262
263
        return rv;
263
264
}
264
265
 
265
 
/* XXX first <-> last and high <-> low could be done in one method per pair */
266
266
roll(first) {
267
267
        struct roll_value *num = roll(this->expr1);
268
268
        struct roll_value *exp = roll(this->expr2);
336
336
        quicksort(slist, 0, exp->count -1);
337
337
        int p = 0, i, c = 0;
338
338
 
339
 
/*      printf("# (");
340
 
        for (i = 0; i < exp->count; i++) {
341
 
                printf("%i", exp->values[i]);
342
 
                if (i < (exp->count-1)) {
343
 
                        printf(", ");
344
 
                }
345
 
        }
346
 
        printf(") -> (");*/
347
 
 
348
339
        if (this->type == keep) {
349
340
                for (i = 0; (i < exp->count) && (c < num->values[0]); i++) {
350
341
                        int j, found = 0;
351
342
                        for (j = 0; j < num->values[0]; j++) {
352
 
                                if (exp->values[i] == slist[j]) {
 
343
                                if ((exp->values[i] == slist[j]) && (!mask[j])) {
353
344
                                        found = 1;
 
345
                    mask[j] = 1;
354
346
                                        break;
355
347
                                }
356
348
                        }
361
353
                }
362
354
        }
363
355
        else {
364
 
                // XXX something wrong here
365
356
                for (i = 0; (i < exp->count) && (c < (exp->count - num->values[0])); 
366
357
                        i++) {
367
358
                        int j, found = 0;
381
372
                }
382
373
        }
383
374
        exp->count = c;
384
 
/*      for (i = 0; i < exp->count; i++) {
385
 
                printf("%i", exp->values[i]);
386
 
                if (i < (exp->count-1)) {
387
 
                        printf(", ");
388
 
                }
389
 
        }
390
 
        printf(")\n");*/
 
375
        free_roll(num);
391
376
        free(slist);
392
377
        free(mask);
393
378
        return exp;
414
399
                for (i = 0; (i < exp->count) && (c < num->values[0]); i++) {
415
400
                        int j, found = 0;
416
401
                        for (j = exp->count - 1; j >= exp->count - num->values[0]; j--) {
417
 
                                if (exp->values[i] == slist[j]) {
 
402
                                if ((exp->values[i] == slist[j]) && (!mask[j])) {
418
403
                                        found = 1;
 
404
                    mask[j] = 1;
419
405
                                        break;
420
406
                                }
421
407
                        }
443
429
                }
444
430
        }
445
431
        exp->count = c;
 
432
        free_roll(num);
446
433
        free(slist);
447
434
        free(mask);
448
435
        return exp;