fix compilation of token.c

(TOKEN_BUFFER still disabled)
also: made VP8TBufferClear() always visible

Change-Id: Iff353fe70b2f3c5b0ab4ef7f143e1d65b0ab2b0d
diff --git a/src/enc/token.c b/src/enc/token.c
index 03f4edf..0d8beaf 100644
--- a/src/enc/token.c
+++ b/src/enc/token.c
@@ -33,6 +33,10 @@
   VP8Tokens* next_;
 };
 
+//------------------------------------------------------------------------------
+
+#ifdef USE_TOKEN_BUFFER
+
 void VP8TBufferInit(VP8TBuffer* const b) {
   b->tokens_ = NULL;
   b->pages_ = NULL;
@@ -41,13 +45,9 @@
   b->error_ = 0;
 }
 
-//------------------------------------------------------------------------------
-
-#ifdef USE_TOKEN_BUFFER
-
 void VP8TBufferClear(VP8TBuffer* const b) {
   if (b != NULL) {
-    const VP8Tokens* p = b->rows_;
+    const VP8Tokens* p = b->pages_;
     while (p != NULL) {
       const VP8Tokens* const next = p->next_;
       free((void*)p);
@@ -63,7 +63,7 @@
     b->error_ = 1;
     return 0;
   }
-  *b->last_page__ = page;
+  *b->last_page_ = page;
   b->last_page_ = &page->next_;
   b->left_ = MAX_NUM_TOKEN;
   b->tokens_ = page->tokens_;
@@ -185,7 +185,7 @@
 }
 
 void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats) {
-  const VP8Tokens* p = b->rows_;
+  const VP8Tokens* p = b->pages_;
   while (p != NULL) {
     const int N = (p->next_ == NULL) ? b->left_ : 0;
     int n = MAX_NUM_TOKEN;
@@ -201,7 +201,8 @@
 
 int VP8EmitTokens(const VP8TBuffer* const b, VP8BitWriter* const bw,
                   const uint8_t* const probas, int final_pass) {
-  const VP8Tokens* p = b->rows_;
+  const VP8Tokens* p = b->pages_;
+  (void)final_pass;
   if (b->error_) return 0;
   while (p != NULL) {
     const VP8Tokens* const next = p->next_;
@@ -221,6 +222,14 @@
 }
 
 //------------------------------------------------------------------------------
+#else
+
+void VP8TBufferInit(VP8TBuffer* const b) {
+  (void)b;
+}
+void VP8TBufferClear(VP8TBuffer* const b) {
+  (void)b;
+}
 
 #endif    // USE_TOKEN_BUFFER
 
diff --git a/src/enc/vp8enci.h b/src/enc/vp8enci.h
index 21212ab..736602a 100644
--- a/src/enc/vp8enci.h
+++ b/src/enc/vp8enci.h
@@ -326,24 +326,25 @@
 //------------------------------------------------------------------------------
 // Paginated token buffer
 
-// WIP: #define USE_TOKEN_BUFFER
+// WIP:#define USE_TOKEN_BUFFER
 
 typedef struct VP8Tokens VP8Tokens;  // struct details in token.c
 
 typedef struct {
+#ifdef USE_TOKEN_BUFFER
   VP8Tokens* pages_;        // first page
   VP8Tokens** last_page_;   // last page
   uint16_t* tokens_;        // set to (*last_page_)->tokens_
   int left_;          // how many free tokens left before the page is full.
   int error_;         // true in case of malloc error
+#endif
 } VP8TBuffer;
 
 void VP8TBufferInit(VP8TBuffer* const b);    // initialize an empty buffer
+void VP8TBufferClear(VP8TBuffer* const b);   // de-allocate pages memory
 
 #ifdef USE_TOKEN_BUFFER
 
-void VP8TBufferClear(VP8TBuffer* const b);   // de-allocate pages memory
-
 int VP8EmitTokens(const VP8TBuffer* const b, VP8BitWriter* const bw,
                   const uint8_t* const probas, int final_pass);
 int VP8RecordCoeffTokens(int ctx, int first, int last,
@@ -378,9 +379,8 @@
 
   int percent_;                             // for progress
 
-#ifdef USE_TOKEN_BUFFER
+  int use_tokens_;                          // if true, use Token buffer
   VP8TBuffer tokens_;                       // token buffer
-#endif
 
   // transparency blob
   int has_alpha_;
@@ -475,7 +475,7 @@
 int VP8GetCostLuma16(VP8EncIterator* const it, const VP8ModeScore* const rd);
 int VP8GetCostLuma4(VP8EncIterator* const it, const int16_t levels[16]);
 int VP8GetCostUV(VP8EncIterator* const it, const VP8ModeScore* const rd);
-// Main stat / coding passes
+// Main coding calls
 int VP8EncLoop(VP8Encoder* const enc);
 int VP8StatLoop(VP8Encoder* const enc);