emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: before- and after-string issues


From: martin rudalics
Subject: Re: before- and after-string issues
Date: Thu, 19 May 2005 18:51:09 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

If you can provide the appropriate overlay start and end positions via
entry1->start, entry1->end, entry2->start, and entry2->end - this should
be done in load_overlay_strings - the following could be a first
approximation.  But in general I don't write C.

/* Compare two overlay_entry structures E1 and E2.  Used as a comparison
   function for qsort in load_overlay_strings.  Overlay strings for the
   same position are sorted so that

1. after-strings from non-empty overlays come before before-strings from
   non-empty overlays and any strings from empty overlays,

2. before-strings from empty overlays come before after-strings from
   empty overlays,

3. strings from empty overlays come before before-strings from non-empty
   overlays,

4. within after-string groups formed according to rules 1..3 strings
   from overlays with higher priorities come first,

5. within before-string groups formed according to rules 1..3 strings
   from overlays with lower priorities come first.

   Value is analogous to strcmp.  */

static int
compare_overlay_entries (e1, e2)
     void *e1, *e2;
{
  struct overlay_entry *entry1 = (struct overlay_entry *) e1;
  struct overlay_entry *entry2 = (struct overlay_entry *) e2;
  int result;

  if entry1->end > entry1->start
    { /* entry1 non-empty */
      if entry2->end > entry2->start
        { /* both overlays non-empty */
          if entry1->after_string_p
            { /* entry1 is after-string */
              if entry2->after_string_p
                /* two non-empty after-strings => rule 4 */
                result = entry2->priority - entry1->priority;
              /* entry2 is before-string => rule 1 */
              else result = -1;
            }
          /* entry1 is before-string */
          else if entry2->after_string_p
            /* entry2 is after-string => rule 1 */
            result = 1;
          /* two non-empty before-strings => rule 5 */
          else result = entry1->priority - entry2->priority;
        }
      /* entry2 empty => rule 1 or 3 */
      else result = entry1->after-string_p ? -1 : 1;
    }
  /* entry1 empty */
  else if entry2->end > entry2->start
    /* entry2 non-empty => rule 1 or 3 */
    result = entry2->after_string_p ? 1 : -1;
  /* both overlays empty */
  else if entry1->after_string_p
    { /* entry1 is after-string */
      if entry2->after_string_p
        /* two empty after-strings => rule 4 */
        result = entry2->priority - entry1->priority;
      /* entry2 is before-string => rule 2 */
      else result = 1;
    }
  /* entry1 is before-string */
  else if entry2->after_string_p
    /* entry2 is after-string => rule 2 */
    result = -1;
    /* two empty before-strings => rule 5 */
  else result = entry1->priority - entry2->priority;

  return result;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]