Browse Source

Replace broken log2 function; add a missing comment.

tags/v0.2
Ben 11 years ago
parent
commit
a689467577
2 changed files with 14 additions and 3 deletions
  1. +13
    -3
      mwparserfromhell/parser/tokenizer.c
  2. +1
    -0
      mwparserfromhell/parser/tokenizer.h

+ 13
- 3
mwparserfromhell/parser/tokenizer.c View File

@@ -23,9 +23,16 @@ SOFTWARE.

#include "tokenizer.h"

double log2(double n)
/*
Given a context, return the heading level encoded within it.
*/
static int heading_level_from_context(int n)
{
return log(n) / log(2);
int level;
n /= LC_HEADING_LEVEL_1;
for (level = 1; n > 1; n >>= 1)
level++;
return level;
}

static PyObject*
@@ -175,6 +182,9 @@ Tokenizer_push_textbuffer(Tokenizer* self)
return 0;
}

/*
Pop and deallocate the top token stack/context/textbuffer.
*/
static void
Tokenizer_delete_top_of_stack(Tokenizer* self)
{
@@ -858,7 +868,7 @@ Tokenizer_handle_heading_end(Tokenizer* self)
best++;
self->head++;
}
current = log2(self->topstack->context / LC_HEADING_LEVEL_1) + 1;
current = heading_level_from_context(self->topstack->context);
level = current > best ? (best > 6 ? 6 : best) :
(current > 6 ? 6 : current);
after = (HeadingData*) Tokenizer_parse(self, self->topstack->context);


+ 1
- 0
mwparserfromhell/parser/tokenizer.h View File

@@ -181,6 +181,7 @@ typedef struct {

/* Function prototypes: */

static int heading_level_from_context(int);
static PyObject* Tokenizer_new(PyTypeObject*, PyObject*, PyObject*);
static struct Textbuffer* Textbuffer_new(void);
static void Tokenizer_dealloc(Tokenizer*);


Loading…
Cancel
Save