示例#1
0
文件: ANNOTlink.c 项目: ezura/Amaya
/*-----------------------------------------------------------------------
  LINK_GetAnnotationIndexFile 
  searches an entry in the main annot index file 
  The caller must free the returned string.
  -----------------------------------------------------------------------*/
char  *LINK_GetAnnotationIndexFile (char *source_url)
{
  int found;
  char *annot_dir;
  char *annot_main_index;
  char *annot_main_index_file;
  char *local_source_url;
  char url[MAX_LENGTH];
  char buffer[MAX_LENGTH];
  char *index_file;
  FILE *fp;

  if (!source_url)
    return NULL;

  annot_dir = GetAnnotDir ();
  annot_main_index = GetAnnotMainIndex ();
  annot_main_index_file = (char *)TtaGetMemory (strlen (annot_dir) 
                                                + strlen (annot_main_index) 
                                                + 10);
  sprintf (annot_main_index_file, "%s%c%s", 
           annot_dir, 
           DIR_SEP,  
           annot_main_index);
  local_source_url = TtaStrdup (source_url);
  WWWToLocal (local_source_url);

  if (TtaFileExist (annot_main_index_file))
    {
      index_file = (char *)TtaGetMemory (MAX_PATH);
      found = 0;
      if ((fp = TtaReadOpen (annot_main_index_file)))
        {
          while (fgets (buffer, MAX_LENGTH, fp))
            {
              sscanf (buffer, "%s %s\n", url, index_file);
              /* convert local URLs into local file system */
              WWWToLocal (url);
              WWWToLocal (index_file);
              if (!strcasecmp (local_source_url, url))
                {
                  found = 1;
                  break;
                }
            }
          TtaReadClose (fp);
        }
      if (!found)
        {
          TtaFreeMemory (index_file);
          index_file = NULL;
        }
    }
  else
    index_file = NULL;

  TtaFreeMemory (local_source_url);
  TtaFreeMemory (annot_main_index_file);

  return (index_file);
}
示例#2
0
文件: ANNOTlink.c 项目: ezura/Amaya
/*-----------------------------------------------------------------------
  LINK_LoadAnnotationIndex
  -----------------------------------------------------------------------
  Searches for an annotation index related to the document. If it exists,
  it parses it and then, if the variable mark_visible is set true, adds
  links to them from the source document.
  -----------------------------------------------------------------------*/
void LINK_LoadAnnotationIndex (Document doc, char *annotIndex, ThotBool mark_visible)
{
  View    view;
  Element body;
  List *annot_list, *list_ptr;
  AnnotMeta *annot;
  AnnotMeta *old_annot;
  DisplayMode dispMode;
  /* counts the number of orphan annotations in the document */
  int orphan_count = 0;
#ifdef ANNOT_ON_ANNOT
  Document doc_thread;
  AnnotThreadList *thread;
#endif /* ANNOT_ON_ANNOT */

  if (!annotIndex || !(TtaFileExist (annotIndex)))
    /* there are no annotations */
    return;
  
  annot_list = RDF_parseFile (annotIndex, &AnnotMetaData[doc].rdf_model);
  TtaFreeMemory (annotIndex);
  annotIndex = NULL;
  if (!annot_list)
    /* we didn't read any annotation */
    return;

  /* avoid refreshing the document while adding the annotation links */
  dispMode = TtaGetDisplayMode (doc);
  if (dispMode == DisplayImmediately)
    TtaSetDisplayMode (doc, DeferredDisplay);

  /* Insert the annotations in the body */
  view = TtaGetViewFromName (doc, "Formatted_view");
  body = SearchElementInDoc (doc, HTML_EL_BODY);
  
  list_ptr = annot_list;

  while (list_ptr)
    {
      char *url;
      AnnotMetaDataSearch searchType;

      annot = (AnnotMeta *) list_ptr->object;
      
      /* don't add an annotation if it's already on the list */
      /* @@ JK: later, Ralph will add code to delete the old one.
         We should remove the old annotations and preserve the newer
         ones. Take into account that an anotation window may be open
         and that we'll have to close it without saving... or just update
         the metadata... */
      
      if (IsW3Path (annot->annot_url))
        {
          url = annot->annot_url;
          searchType = AM_ANNOT_URL;
        }
      else
        {
          url = annot->body_url;
          searchType = AM_BODY_URL;
        }
      old_annot = AnnotList_searchAnnot (AnnotMetaData[doc].annotations,
                                         url, searchType);
#ifdef ANNOT_ON_ANNOT
      /* do the same thing to avoid duplicating the thread items */
      if (!old_annot && AnnotThread[doc].annotations)
        old_annot = AnnotList_searchAnnot (AnnotThread[doc].annotations,
                                           url, searchType);
#endif /* ANNOT_ON_ANNOT */

      if (!old_annot)
        {
          if (mark_visible)
            {
              /* create the reverse link name */
              LINK_CreateAName (annot);
              if (! LINK_AddLinkToSource (doc, annot))
                orphan_count++;
              annot->is_visible = TRUE;
              annot->show = TRUE;
            }
          else
            annot->is_visible = FALSE;
#ifdef ANNOT_ON_ANNOT
          if (annot->inReplyTo)
            {
              doc_thread = AnnotThread_searchRoot (annot->rootOfThread);
              /* if there's no other thread, then use the source doc as the
                 start of the thread */
              if (doc_thread ==  0)
                {
                  thread = NULL;
                  doc_thread = doc;
                }
              else
                thread = &AnnotThread[doc_thread];

              /* there was no thread. Create a new one if it's the same rootOfThread document */
              if (!thread && Annot_isSameURL (AnnotMetaData[doc].annot_url, annot->rootOfThread))
                {
                  /* add the root of thread (used by load index later on) */
                  AnnotThread[doc].rootOfThread = 
                    TtaStrdup (annot->rootOfThread);
                  AnnotThread[doc].references = 1;
                  thread = &AnnotThread[doc_thread];
                }

              /* add and show the thread item */
              if (thread)
                {
                  List_add (&(thread->annotations), (void *) annot);
                  if (!AnnotMetaData[doc].thread)
                    AnnotMetaData[doc].thread = thread;
                  annot->thread = thread;
                  /* ANNOT_AddThreadItem (doc_thread, annot); */
                }
              else
                Annot_free (annot);
            }
          else /* not a reply */
#endif /* ANNOT_ON_ANNOT */
            /* Verify that the annotates property really does point
               to this document and discard if not or if there is
               no annotates property. */
            if (Annot_isSameURL (annot->source_url, DocumentURLs[doc]))
              List_add (&AnnotMetaData[doc].annotations, (void *) annot);
            else
              Annot_free (annot);
        }
      else
        Annot_free (annot);
      List_delFirst (&list_ptr);
    }

#ifdef ANNOT_ON_ANNOT
  /* erase and redisplay the thread items */
  ANNOT_DeleteThread (doc);
  if (AnnotThread[doc].annotations)
    ANNOT_BuildThread (doc);
#endif /* ANNOT_ON_ANNOT */

  /* show the document */
  if (dispMode == DisplayImmediately)
    TtaSetDisplayMode (doc, dispMode);

  if (orphan_count)
    {
      /* warn the user there were some orphan annotations */
      InitInfo ("Annotation load", 
                "There were some orphan annotations. You may See them with the Links view.");
    }
}
示例#3
0
文件: ANNOTlink.c 项目: ezura/Amaya
/*-----------------------------------------------------------------------
  LINK_UpdateAnnotationIndexFile
  old_source_url and new_source_url must be complete URLs.
  -----------------------------------------------------------------------*/
void LINK_UpdateAnnotationIndexFile (char *old_source_url, char *new_source_url)
{
  char *annot_dir;
  char *annot_main_index;
  char *annot_main_index_file;
  char *annot_new_main_index_file;
  char url[MAX_LENGTH];
  char index_file[MAX_LENGTH];
  char buffer[MAX_LENGTH];
  char *tmp_url;
  char *tmp_index_file;
  FILE *fp_old, *fp_new;
  ThotBool move;

  annot_dir = GetAnnotDir ();
  annot_main_index = GetAnnotMainIndex ();
  annot_main_index_file = (char *)TtaGetMemory (strlen (annot_dir) 
                                                + strlen (annot_main_index) 
                                                + 10);
  sprintf (annot_main_index_file, "%s%c%s", 
           annot_dir, 
           DIR_SEP,  
           annot_main_index);
  annot_new_main_index_file = (char *)TtaGetMemory (strlen (annot_dir) 
                                                    + strlen (annot_main_index) 
                                                    + 11);
  sprintf (annot_new_main_index_file, "%s%ct%s", 
           annot_dir, 
           DIR_SEP,  
           annot_main_index);

  move = FALSE;
  if (TtaFileExist (annot_main_index_file))
    {
      if ((fp_old = TtaReadOpen (annot_main_index_file)))
        {
          if ((fp_new = TtaWriteOpen (annot_new_main_index_file)))
            {
              while (fgets (buffer, MAX_LENGTH, fp_old))
                {
                  sscanf (buffer, "%s %s\n", url, index_file);
                  /* convert local URLs into file: ones */
                  if (!IsFilePath (url) && !IsW3Path (url))
                    tmp_url = LocalToWWW (url);
                  else
                    tmp_url = url;
                  if (!IsFilePath (index_file) && !IsW3Path (index_file))
                    tmp_index_file = LocalToWWW (index_file);
                  else
                    tmp_index_file = index_file;
                  if (!strcasecmp (old_source_url, tmp_url))
                    fprintf (fp_new, "%s %s\n", new_source_url, tmp_index_file);
                  else
                    fprintf (fp_new, "%s %s\n", tmp_url, tmp_index_file);
                  if (tmp_url != url)
                    TtaFreeMemory (tmp_url);
                  if (tmp_index_file != index_file)
                    TtaFreeMemory (tmp_index_file);
                }
              TtaWriteClose (fp_new);
              move = TRUE;
            }
          TtaReadClose (fp_old);
        }
    }
  
  if (move)
    {
      TtaFileCopy (annot_new_main_index_file, annot_main_index_file);
      TtaFileUnlink (annot_new_main_index_file);
    }

  TtaFreeMemory (annot_main_index_file);
  TtaFreeMemory (annot_new_main_index_file);
}
示例#4
0
文件: css.c 项目: ArcScofield/Amaya
/*----------------------------------------------------------------------
  LoadStyleSheet loads the external Style Sheet found at the given url
  (in dialog charset).
  The parameter link gives the element which links the CSS or NULL.
  The parameter css gives the CSS context which imports this CSS file.
  The parameter urlRef gives the url used to resolve relative paths.
  The parameter media gives the application limits of the CSS.
  The parameter user is true when it's a User style sheet. It's false
  when it's an author style sheet
  ----------------------------------------------------------------------*/
void LoadStyleSheet (char *url, Document doc, Element link, CSSInfoPtr css,
                     char *urlRef, CSSmedia media, ThotBool user)
{
  CSSInfoPtr          refcss = NULL;
  PInfoPtr            pInfo;
  char                tempfile[MAX_LENGTH];
  char                tempURL[MAX_LENGTH];
  char               *tmpBuff;
  CSSCategory         category;
  ThotBool            import, printing;
  ThotBool            loadcss;

  /* check if we have to load CSS */
  TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
  printing = TtaIsPrinting ();

  if (!loadcss && !printing)
    return;
  import = (css != NULL);
  if (import)
    category = CSS_IMPORT;
  else if (user)
    category = CSS_USER_STYLE;
  else
    category = CSS_EXTERNAL_STYLE;
  refcss = css;

  /* get the absolute URI */
  if (import && urlRef == NULL)
    {
      if (css->url)
        urlRef = css->url;
      else
        urlRef = css->localName;
    }
  LoadRemoteStyleSheet (url, doc, link, urlRef, tempURL, tempfile);
  if (!TtaFileExist (tempfile))
    {
    // cannot load the style sheet
      TtaSetStatus (doc, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), tempURL);
      return;
    }
  css = SearchCSS (doc, tempURL, link, &pInfo);
  if (css == NULL ||
      (import && !css->import))
    {
      /* It's a new CSS file: allocate a new Presentation structure */
      /* or a @import CSS: add the CSS descriptor just before the main css */
      css = AddCSS (0, doc, category, media, tempURL, tempfile, link);
      pInfo = css->infos[doc];
    }
  else
    {
      if (pInfo && pInfo->PiCategory != category)
        /* this entry doesn't match */
        pInfo = NULL;
      if (pInfo == NULL)
        /* add a new entry at the end */
        pInfo = AddInfoCSS (doc, css, category, media, link);
    }

  /* look for the CSS descriptor that points to the extension schema */
  if (import)
    {
      while (refcss && refcss->import)
        refcss = refcss->NextCSS;
      if (refcss->infos[doc])
        link = refcss->infos[doc]->PiLink;
    }
  else
    refcss = css;
  /* now apply style rules */
  pInfo = refcss->infos[doc];
  if (tempfile[0] == EOS)
    /* cannot do more */
    return;
  else if (media == CSS_OTHER || css == NULL ||
           (!printing && media == CSS_PRINT) ||
           (printing && media == CSS_SCREEN) ||
           !pInfo->PiEnabled)
    /* nothing more to do */
    return;

  /* apply CSS rules in current Presentation structure (import) */
  if ( pInfo->PiSchemas == NULL || import)
    {
      /* load the resulting file in memory */
      tmpBuff = LoadACSSFile (tempfile);
      if (tmpBuff == NULL)
        {
          TtaSetStatus (doc, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), tempURL);
          return;
        }
      if (css)
        urlRef = css->url;
      ReadCSSRules (doc, refcss, tmpBuff, urlRef, 0, FALSE, link);
      TtaFreeMemory (tmpBuff);
    }
}