comparison src/rangetab.c @ 408:501cfd01ee6d r21-2-34

Import from CVS: tag r21-2-34
author cvs
date Mon, 13 Aug 2007 11:18:11 +0200
parents a86b2b5e0111
children 697ef44129c6
comparison
equal deleted inserted replaced
407:ed6218a7d4d3 408:501cfd01ee6d
441 } 441 }
442 442
443 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /* 443 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /*
444 Map FUNCTION over entries in TABLE, calling it with three args, 444 Map FUNCTION over entries in TABLE, calling it with three args,
445 the beginning and end of the range and the corresponding value. 445 the beginning and end of the range and the corresponding value.
446
447 Results are guaranteed to be correct (i.e. each entry processed
448 exactly once) if FUNCTION modifies or deletes the current entry
449 (i.e. passes the current range to `put-range-table' or
450 `remove-range-table'), but not otherwise.
446 */ 451 */
447 (function, table)) 452 (function, table))
448 { 453 {
449 error ("not yet implemented"); 454 Lisp_Range_Table *rt;
455 int i;
456
457 CHECK_RANGE_TABLE (table);
458 CHECK_FUNCTION (function);
459
460 rt = XRANGE_TABLE (table);
461
462 /* Do not "optimize" by pulling out the length computation below!
463 FUNCTION may have changed the table. */
464 for (i = 0; i < Dynarr_length (rt->entries); i++)
465 {
466 struct range_table_entry *entry = Dynarr_atp (rt->entries, i);
467 EMACS_INT first, last;
468 Lisp_Object args[4];
469 int oldlen;
470
471 again:
472 first = entry->first;
473 last = entry->last;
474 oldlen = Dynarr_length (rt->entries);
475 args[0] = function;
476 args[1] = make_int (first);
477 args[2] = make_int (last);
478 args[3] = entry->val;
479 Ffuncall (countof (args), args);
480 /* Has FUNCTION removed the entry? */
481 if (oldlen > Dynarr_length (rt->entries)
482 && i < Dynarr_length (rt->entries)
483 && (first != entry->first || last != entry->last))
484 goto again;
485 }
486
450 return Qnil; 487 return Qnil;
451 } 488 }
452 489
453 490
454 /************************************************************************/ 491 /************************************************************************/