Back to index

tetex-bin  3.0
Defines | Functions | Variables
htex.c File Reference
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "system.h"
#include "mem.h"
#include "mfileio.h"
#include "dvi.h"
#include "htex.h"
#include "pdfparse.h"
#include "pdfdoc.h"

Go to the source code of this file.

Defines

#define ANCHOR   0
#define IMAGE   1
#define BASE   2
#define END_ANCHOR   3
#define HREF   1
#define NAME   2

Functions

static int is_htex_special (char **start, char *end)
static void downcase (char *s)
static int parse_html_tag (char **start, char *end)
static void html_make_link_dict (char *name)
void html_make_dest (char *name)
void html_start_anchor (char *key, char *value)
void html_end_anchor (void)
void html_set_base (char *value)
int htex_parse_special (char *buffer, UNSIGNED_QUAD size)

Variables

static char * tags [] = {"a", "img", "base" }
static pdf_objlink_dict = NULL
static unsigned pending_type = 0
char * base_value = NULL

Define Documentation

#define ANCHOR   0

Definition at line 57 of file htex.c.

#define BASE   2

Definition at line 59 of file htex.c.

#define END_ANCHOR   3

Definition at line 60 of file htex.c.

#define HREF   1

Definition at line 96 of file htex.c.

#define IMAGE   1

Definition at line 58 of file htex.c.

#define NAME   2

Definition at line 97 of file htex.c.


Function Documentation

static void downcase ( char *  s) [static]

Definition at line 47 of file htex.c.

{
  while (*s != 0) {
    if (*s >= 'A' && *s <= 'Z')
      *s = (*s-'A')+'a';
    s += 1;
  }
}

Here is the caller graph for this function:

int htex_parse_special ( char *  buffer,
UNSIGNED_QUAD  size 
)

Definition at line 209 of file htex.c.

{
  int result = 0;
  char *key, *value;
  char *save = buffer;
  char *end = buffer + size;
  int htmltag;
  skip_white (&buffer, end);
  if (is_htex_special(&buffer, end)) {
    result = 1; /* Must be html special (doesn't mean it will succeed) */
    skip_white (&buffer, end);
    if (buffer < end && *(buffer++) == '<' ) {
      htmltag = parse_html_tag(&buffer, end);
      switch (htmltag) {
      case ANCHOR:
       parse_key_val (&buffer, end, &key, &value);
       if (key && value)
         html_start_anchor (key, value);
       break;
      case IMAGE:
       fprintf (stderr, "\nImage html tag not yet implemented\n");
       parse_key_val (&buffer, end, &key, &value);
       if (key) RELEASE (key);
       if (value) RELEASE (value);
       break;
      case BASE:
       parse_key_val (&buffer, end, &key, &value);
       if (key && value)
         html_set_base (value);
       if (key)
         RELEASE (key);
       break;
      case END_ANCHOR:
       html_end_anchor ();
       break;
      default:
       fprintf (stderr, "Invalid tag\n");
       dump (save, end);
      }
    }
    skip_white(&buffer, end);
    if (buffer >= end || *buffer != '>') {
      fprintf (stderr, "\nBadly terminated tag..\n");
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 181 of file htex.c.

{
  switch (pending_type) {
  case HREF:
    if (link_dict) {
      pdf_doc_end_annot ();
      pdf_release_obj (link_dict);
      link_dict = NULL;
      pending_type = 0;
    } else {
      fprintf (stderr, "\nhtml_end_anchor:  Ending anchor tag without starting tag!\n");
    }
    break;
  case NAME:
    pending_type = 0;
    break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void html_make_dest ( char *  name)

Definition at line 144 of file htex.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void html_make_link_dict ( char *  name) [static]

Definition at line 102 of file htex.c.

{
  pdf_obj *color;
  if (!link_dict) {
    link_dict = pdf_new_dict();
    pdf_add_dict(link_dict, pdf_new_name("Type"), pdf_new_name ("Annot"));
    pdf_add_dict(link_dict, pdf_new_name("Subtype"), pdf_new_name ("Link"));
    color = pdf_new_array ();
    pdf_add_array (color, pdf_new_number (0));
    pdf_add_array (color, pdf_new_number (1));
    pdf_add_array (color, pdf_new_number (1));
    pdf_add_dict(link_dict, pdf_new_name("C"), color);
    if (name && *name == '#' && !(base_value)) {
      pdf_add_dict (link_dict, pdf_new_name("Dest"), pdf_new_string(name+1,strlen(name+1)));
    } else if (name) {    /* Assume its a URL */
      char *url;
      int len;
      pdf_obj *action;
      len = strlen(name)+1;
      if (base_value)
       len+=strlen(base_value);
      url = NEW (len, char);
      if (base_value)
       strcpy (url, base_value);
      else
       url[0] = 0;
      strcat (url, name);
      action = pdf_new_dict();
      pdf_add_dict (action, pdf_new_name ("Type"), pdf_new_name ("Action"));
      pdf_add_dict (action, pdf_new_name ("S"), pdf_new_name ("URI"));
      pdf_add_dict (action, pdf_new_name ("URI"),
                  pdf_new_string (url, len));
      pdf_add_dict (link_dict, pdf_new_name ("A"), pdf_ref_obj (action));
      pdf_release_obj (action);
      RELEASE (url);
    }
    pdf_doc_begin_annot (link_dict);
  } else {
    fprintf (stderr, "\nAttempt to nest links\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void html_set_base ( char *  value)

Definition at line 200 of file htex.c.

Here is the caller graph for this function:

void html_start_anchor ( char *  key,
char *  value 
)

Definition at line 157 of file htex.c.

{
  if (pending_type <= 0 && !link_dict) {
    downcase (key);
    if (!strcmp (key, "href")) {
      html_make_link_dict (value);
      pending_type = HREF;
    } else if (!strcmp (key, "name")) {
      html_make_dest (value);
      pending_type = NAME;
    } else {
      fprintf (stderr, "\nUnrecognized keyword in anchor tag: %s\n",
              key);
    }
  } else {
    fprintf (stderr, "\nWarning: Nested html anchors\n");
  }
  if (key)
    RELEASE (key);
  if (value) {
    RELEASE (value);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int is_htex_special ( char **  start,
char *  end 
) [static]

Definition at line 36 of file htex.c.

{
  skip_white(start, end);
  if (end-*start >= strlen ("html:") &&
      !strncmp (*start, "html:", strlen("html:"))) {
    *start += strlen("html:");
    return 1;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int parse_html_tag ( char **  start,
char *  end 
) [static]

Definition at line 64 of file htex.c.

{
  int result = -1;
  char *token = NULL;
  int closing = 0;
  skip_white(start, end);
  if (*start < end) {
    if (**start == '/') {
      (*start)++;
      closing = 1;
    }
    if (*start < end && (token = parse_ident (start, end))) {
      downcase (token);
      {
       int i;
       for (i=0; i<sizeof(tags)/sizeof(tags[0]); i++) {
         if (!strcmp (token, tags[i])) {
           result = i;
           if (closing) 
             result += sizeof(tags)/sizeof(tags[0]);
         }
         break;
       }
       if (i>=sizeof(tags)/sizeof(tags[0]))
         result = -1;
      }
      RELEASE (token);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* base_value = NULL

Definition at line 101 of file htex.c.

pdf_obj* link_dict = NULL [static]

Definition at line 98 of file htex.c.

unsigned pending_type = 0 [static]

Definition at line 99 of file htex.c.

char* tags[] = {"a", "img", "base" } [static]

Definition at line 62 of file htex.c.