POV-Ray : Newsgroups : povray.unofficial.patches : own set of keywords with WinPOV Server Time
3 Jul 2024 05:09:11 EDT (-0400)
  own set of keywords with WinPOV (Message 1 to 2 of 2)  
From: ABX
Subject: own set of keywords with WinPOV
Date: 25 Oct 2002 13:25:22
Message: <n1siruko7a49uccer4kplqkshtrngm1v1g@4ax.com>
Playing with docbook I looked for free, efficient XML/SGML editor.
At some point I realized I saw XML entry as one of supported filetypes in
WinPOV. So I tried it. It somehow works but with one defect - autocompletion
works with keywords from pov. It seems useless in XML. Then I started to dream
about custom list of available keywords. Investigation of codemax sources gave
me nothing. It was too complicated at that moment not talking about compiling
it with free borland I currently operate. But further reading gave me an idea
how to implement it to work easy. Below content can be considered as tutorial
about:
  - adding platform specific (windows) command line option
  - simple reading from text files with POVs clases.
  - operating over list of keywords for colored syntax and autocompletion

I have extended WinPOV with additional command line option. It can be used as
follow:
    pvengine .. /KEYWORDS [on|off] /KEYWORDS filename1 /KEYWORDS filename2 ..
  where:
  - switch is on | off and tells whether editor should use (or not use) 
    default set of keywords from POV
  - filename is text file with keywords listed line by line
Keywords can be whatever: fragment of SDL, favourite mails, html tags.
They are colored like POVs keywords and appear in autocompletion list.
This feature can confuse newbies becouse for example you can deliver list of
keywords with all internal functions with parameters. But then newbie can ask
why f_sphere is colored like keyword but not recognized by parser. Answering
could be simple but annoying when too often. So be careful using it.
Without modifing CODEMAX such feature is constant per instance. So keywords
are valid for every opened file in editor as long as POV no exited.

Here is list of changes I made (marked with #ifdefs)

First I have created switch in 'patches.h' to turn feature on.

  [patches.h]
  // platform specific patches
  #define CUSTOM_KEYWORDS_IN_WINPOV_PATCH
 
Then I have started enabling command line option reading. Reading of command
line options is realised in two levels - per whole instance and per
invocation. It is located in functions preparse_commandline() and
preparse_instance_commandline() in pvtext.c. We have to change
preparse_commandline() with "/KEYWORDS" option recognition.

  [pvtext.c ]

  #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
    #include "pov_mem.h"
    #include "file_pov.h"
    #include "povms.h"
  #endif

  ...

  char *preparse_commandline (char *s)
  {
    ...
    if (stricmp (commandstr, "NORESTORE") == 0 ...........
      {
        NoRestore = true ;
        while (*s == ' ')
          s++ ;
        continue ;
      }
    #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
      if (stricmp (commandstr, "KEYWORDS") == 0)
      {
        s = extract_file (filename, s) ;
        if (stricmp (filename, "OFF") == 0)
        {
          use_pov_keywords = false;
        }
        else if (stricmp (filename, "ON") == 0)
        {
          use_pov_keywords = true;
        }
        else
        {
          POV_ISTREAM *f;
          char bufline[512]; 
          if ((f=Locate_File(filename,POV_File_Text_User,NULL,false))==NULL)
          {
            PovMessageBox ("Cannot open file with custom keywords" ,
                           "Commandline processing error") ;
          }
          else
          {
            while (f->getline (bufline, 512))
            {
              int prev_length = 
                    additional_keywords ? strlen( additional_keywords ) : 0;
              int curr_length = strlen (bufline);

              char *lines = (char *) malloc (prev_length + curr_length + 2) ;

              if ( lines )
              {
                strcpy( lines , additional_keywords );
                strcat( lines , bufline );
                strcat( lines , "\n" );
                additional_keywords = strdup( lines );
                free( lines );
              }
              else
              {
                PovMessageBox ( "No memory for keywords", 
                                "Commandline processing error") ;
              }
            }
            POV_DELETE(f, POV_ISTREAM);
          }
        }
        while (*s == ' ')
          s++ ;
        continue ;
      }
    #endif
    sprintf (outstr, "Unrecognized command '%s' on commandline", commandstr) ;
    ....
  }

Ok. You probably noticed I used two additional global variables. '/KEYWORDS
on' and '/KEYWORDS off' control global variable 'use_pov_keywords'. '/KEYWORDS
filname' control global variable 'additional_keywords'. They have to be
defined and initialized. 

  [pvedit.h]
  #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
    extern bool use_pov_keywords;
    extern char *additional_keywords;
  #endif

  [pvedit.c]
  #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
    bool                  use_pov_keywords = true;
    char                  *additional_keywords = strdup( "#\n" );
  #endif

Now we have to only modify initialization list.

  [pvedit.c]
  HWND InitialiseEditor (HWND ParentWindow, HWND StatusWindow, char *HomePath)
  {
    ...
    if (!use_editors)
      return (NULL) ;
    #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
      s = Get_Reserved_Words (use_pov_keywords , additional_keywords ) ;
    #else
      s = Get_Reserved_Words ("#\n") ;
    #endif
    EditSetKeywords (s) ;
    ...
  }

As you can see I have modified definition of Get_Reserved_Words defined in
parse.cpp in povray core source. So let's modify it.

  [parse.h]
  char *Get_Reserved_Words ( 
                             #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
                               bool use_tokens,
                             #endif
                             const char *additional_words) ;

  [parse.cpp]
  char *Get_Reserved_Words (
                             #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
                               bool use_tokens,
                             #endif
                             const char *additional_words)
  {
    int length = 0 ;
    int i ;

    #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
    if (use_tokens)
    #endif
    for (i = 0; i < LAST_TOKEN; i++)
    {
      ...
    }

    ...

    #ifdef CUSTOM_KEYWORDS_IN_WINPOV_PATCH
    if (use_tokens)
    #endif
    for (i = 0 ; i < LAST_TOKEN ; i++)
    {
      ...
    }

    *--s = '\0' ;

    return (result) ;
  }

Experienced coders, please verify me if possible. 

This feature will be added to the next PoPOV probably.

ABX


Post a reply to this message

From: ABX
Subject: Re: own set of keywords with WinPOV
Date: 25 Oct 2002 13:38:57
Message: <700jruc49nv3kmp1rdfadlmgduto1ml59k@4ax.com>
On Fri, 25 Oct 2002 19:22:59 +0200, ABX <abx### [at] abxartpl> wrote:

>                free( lines );

BTW: I tried to use POV_MALLOC and other definitions as malloc and free but
for some reason they not worked (crash during start of POV). I think it was
becouse at moment of runing something from POV-Ray core was not initialized
but I've not investigated it hard enough. Any idea ?

ABX


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.