lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev proposal for LYK_SCRIPT and patch


From: Eduardo Chappa L.
Subject: lynx-dev proposal for LYK_SCRIPT and patch
Date: Wed, 30 Jun 1999 03:18:36 -0700 (PDT)

Hello 

  So here is the idea. Sometimes we find web pages where lynx is not able
to give us a good output or is not able to, say, send a form because there
a JavaScript button. Many of those problems arise because the person that
wrote the html code did not take care in that lynx users would not be able
to access their documents, and even when we complain, even a formal answer
is hard to find, less a change. So what I propose is that we give users the
ability to change the code, through a script. For example, if you happen to
find a table where you find the unhappy combination
<td><center></center></td>, this will break lynx output and the result will
be a mess. The solution is to eliminate the <center> </center> combination,
which could be easily done with, say sed, therefore if you can access the
code, apply a script to it, and redisplay the result, then you can read
better the page.

  This is possible to accomplish if we remember that we can cache the
source, so the trick is to be able to call the script, once the page has
been opened. This is what "LYK_SCRIPT" should do.

  The obvious advantage of this is that when users get here complaining
that lynx does not do something, instead of telling them, yes you are
right, wait until someone takes the painful task of writing the code, we
can give them a script that will solve their problem, while the real
problem of supportting javascript or fixing the output with tables is done,
and maybe who knows which new ones will appear in the future.

  I am sending a patch against lynx2-8-2.rel1 that does this. You have to
see it working to really be convinced that this is something useful. I have
shown it to a couple of people that have been impressed by how much the
output changes by pressing a few keys.

  The way the command works is as follows:

  You access the web page that you want to go to, and realize that a
change must be done, so you press the letter "S" to invoke a previously
written script. You are asked a question which you will probably want to
answer "yes" and then the script works on the /tmp file associated to the
web page. Once the script has made its work the new /tmp file associated to
the web page is displayed in the screen. The only bad thing I found about
it was that this made me change a reference like "http://"; in the visited
links to "file://localhost", which has some importance in the construction
of the script, rather than anywhere else. I found this problem to be minor
compared to the advantage of replacing the output ofr something nicer.

  How you set up the command to work is as follows:

  You write a script that will fix your page or make the transformation
that you want to the html code of the page and define in the external
section the following lines:

  EXTERNAL:http:/path/to/script %s:TRUE EXTERNAL:file:/path/to/script
%s:TRUE

  here %s is the URL of the currently opened web page. Additionaly the
script receives a second parameter (is not explicitly mentioned there
because the external command does not accept more than one parameter) which
is the name of the /tmp file associated to the currently opened URL. In
summary, the script has to receive two parameters "$1", the currently
opened URL and $2 the path to the /tmp file associated to $1.

  In my case the script is a menu of short scripts, from where I choose
which one rewrites $2.

  I had also the problem that when I accessed a document that I wanted to
apply a script to, but I pressed say the letter "o" twice, to see the
options menu and go back, the script got applied to the /tmp file
associated to the options menu instead of to the currently opened document
(is this a bug or did I misunderstand something?) In any case, I solved
this by reloading the file after pressing the second "o", this is also in
my patch, but I guess there is a better way to do it, which I don't know.
(This comment is valid for commands p,d,l,k,A,o.)

  I can send more explicit examples if you want me to, just ask.


 * Adds LYK_SCRIPT, which can only be used when the external command has
   been previously defined. It is also useful mostly if you cache the
   source. LYK_SCRIPT allows you to modify the source html code to get a
   better or useful display, which you would not get otherwise.
   Implementation at this time makes lynx to reload the source file after
   applying commands like printing, downloading, list of links, etc. This
   should be fixed in another version.

 * Add some features to the mouse (tested with SLANG). One can use the
   mouse to exit lynx (click on -Quit-), also clicking on an empty space
   makes the page to scroll up or down. The quantity of lines this is
   scrolled, dependent on the possition of the mouse, but is 2 lines in
   the center and half a page near the top and bottom. Also the middle
   buttom opens the bookmark file.
 


diff -rc lynx2-8-2.real/LYMessages_en.h lynx2-8-2/LYMessages_en.h
*** lynx2-8-2.real/LYMessages_en.h      Tue May 25 10:13:02 1999
--- lynx2-8-2/LYMessages_en.h   Mon Jun 28 14:06:23 1999
***************
*** 31,36 ****
--- 31,37 ----
  #define WELCOME_MSG gettext("Welcome")
  #define REALLY_QUIT_Y gettext("Are you sure you want to quit?")
  #define REALLY_QUIT_N gettext("Are you sure you want to quit?")
+ #define CHANGE_CACHE gettext("Do you want to replace the cached memory file?")
  #ifdef VMS
  #define REALLY_EXIT_Y gettext("Really exit from Lynx?")
  #define REALLY_EXIT_N gettext("Really exit from Lynx?")

Only in lynx2-8-2.real: lynx2-8-2
diff -rc lynx2-8-2.real/src/GridText.c lynx2-8-2/src/GridText.c
*** lynx2-8-2.real/src/GridText.c       Fri May 28 07:04:01 1999
--- lynx2-8-2/src/GridText.c    Tue Jun 29 14:02:35 1999
***************
*** 1118,1127 ****
      }
      move(0, 0);
      clrtoeol();
      if (text->top_of_screen > 0 && HText_hasToolbar(text)) {
        addch('#');
      }
!     i = (LYcols - 1) - strlen(percent) - strlen(title);
      if (i > 0) {
        move(0, i);
      } else {
--- 1118,1133 ----
      }
      move(0, 0);
      clrtoeol();
+     if (LYUseMouse) {
+       addstr("-Quit-");
+     }
      if (text->top_of_screen > 0 && HText_hasToolbar(text)) {
        addch('#');
      }
!     if (LYUseMouse) {
!        i = (LYcols - 1) - strlen(percent) - strlen(title) - 6;}
!     else {
!        i = (LYcols - 1) - strlen(percent) - strlen(title); }
      if (i > 0) {
        move(0, i);
      } else {
***************
*** 1130,1137 ****
         *  account the possibility that multibyte
         *  characters might be present. - FM
         */
!       title[((LYcols - 2) - strlen(percent))] = '\0';
!       move(0, 1);
      }
      addstr(title);
      if (percent[0] != '\0')
--- 1136,1148 ----
         *  account the possibility that multibyte
         *  characters might be present. - FM
         */
!         if (LYUseMouse) {
!          title[((LYcols - 2) - strlen(percent) - 6)] = '\0';
!          move(0, 7);} 
!         else {
!          title[((LYcols - 2) - strlen(percent))] = '\0';
!          move(0, 1); }
! 
      }
      addstr(title);
      if (percent[0] != '\0')
diff -rc lynx2-8-2.real/src/LYExtern.c lynx2-8-2/src/LYExtern.c
*** lynx2-8-2.real/src/LYExtern.c       Tue Mar 30 09:10:37 1999
--- lynx2-8-2/src/LYExtern.c    Fri Jun 25 11:40:13 1999
***************
*** 24,29 ****
--- 24,30 ----
  #include <LYExtern.h>
  #include <LYLeaks.h>
  #include <LYCurses.h>
+ #include <LYKeymap.h>

  void run_external ARGS1(char *, cmd)
  {
***************
*** 39,45 ****
                HTUserMsg(EXTERNALS_DISABLED);
            } else {

!               HTAddParam(&the_command, ext->command, 1, cmd);
                HTEndParam(&the_command, ext->command, 1);

                HTUserMsg(the_command);
--- 40,46 ----
                HTUserMsg(EXTERNALS_DISABLED);
            } else {

!               HTAddParam(&the_command, ext->command, 1, cmd); 
                HTEndParam(&the_command, ext->command, 1);

                HTUserMsg(the_command);
***************
*** 48,53 ****
--- 49,88 ----
                LYSystem(the_command);
                FREE(the_command);
                start_curses();
+           }
+ 
+           break;
+       }
+     }
+ 
+     return;
+ }
+ 
+ void run_script ARGS2(char *, cmd, char *, result)
+ {
+     char *the_command = 0;
+     lynx_html_item_type *ext = 0;
+     static CONST char SCRIPT_FMT[] = "%s %s";
+ 
+     for (ext = externals; ext != NULL; ext = ext->next) {
+ 
+       if (ext->command != 0
+       && !strncasecomp(ext->name, cmd, strlen(ext->name))) {
+ 
+           if (no_externals && !ext->always_enabled) {
+               HTUserMsg(EXTERNALS_DISABLED);
+           } else {
+ 
+             HTAddParam(&the_command, ext->command, 1, cmd); 
+           HTEndParam(&the_command, ext->command, 1);
+             HTAddParam(&the_command, SCRIPT_FMT, 2, result);
+             HTEndParam(&the_command, SCRIPT_FMT, 2);
+           HTUserMsg(the_command);
+             stop_curses();
+             LYSystem(the_command);
+             FREE(the_command);
+             start_curses();
+ 
            }

            break;
diff -rc lynx2-8-2.real/src/LYExtern.h lynx2-8-2/src/LYExtern.h
*** lynx2-8-2.real/src/LYExtern.h       Wed Mar 25 05:58:54 1998
--- lynx2-8-2/src/LYExtern.h    Fri Jun 25 10:24:30 1999
***************
*** 5,10 ****
  #include <LYStructs.h>
  #endif /* LYSTRUCTS_H */

! void run_external PARAMS((char * c));

  #endif /* EXTERNALS_H */
--- 5,12 ----
  #include <LYStructs.h>
  #endif /* LYSTRUCTS_H */

! void run_external PARAMS((char * cmd));
! 
! void run_script PARAMS((char * cmd, char * result));

  #endif /* EXTERNALS_H */
diff -rc lynx2-8-2.real/src/LYKeymap.c lynx2-8-2/src/LYKeymap.c
*** lynx2-8-2.real/src/LYKeymap.c       Fri Apr 23 07:56:35 1999
--- lynx2-8-2/src/LYKeymap.c    Mon Jun 14 12:07:20 1999
***************
*** 122,129 ****
--- 122,134 ----
  LYK_LIST,          LYK_MAIN_MENU,    LYK_NEXT,      LYK_OPTIONS,
  /* L */              /* M */         /* N */        /* O */

+ #ifndef USE_EXTERNALS
  LYK_PRINT,          LYK_ABORT,    LYK_DEL_BOOKMARK, LYK_INDEX_SEARCH,
  /* P */              /* Q */         /* R */        /* S */
+ #else
+ LYK_PRINT,          LYK_ABORT,    LYK_DEL_BOOKMARK, LYK_SCRIPT,
+ /* P */              /* Q */         /* R */        /* S */
+ #endif /* USE_EXTERNAL*/

  LYK_TAG_LINK,      LYK_PREV_DOC,    LYK_VLINKS,         0,
  /* T */              /* U */         /* V */        /* W */
***************
*** 716,721 ****
--- 721,727 ----
  { "EDITTEXTAREA",     "use an external editor to edit a form's textarea" },
  { "GROWTEXTAREA",     "add 5 new blank lines to the bottom of a textarea" },
  { "INSERTFILE",               "insert file into a textarea (just above 
cursorline)" },
+ { "SCRIPT",             "to make a script/program act on a web page"},
  #ifdef EXP_ADDRLIST_PAGE
  { "ADDRLIST",         "like LIST command, but always shows the links URL's" },
  #endif
diff -rc lynx2-8-2.real/src/LYKeymap.h lynx2-8-2/src/LYKeymap.h
*** lynx2-8-2.real/src/LYKeymap.h       Wed May 12 19:06:05 1999
--- lynx2-8-2/src/LYKeymap.h    Fri Jun 11 04:00:41 1999
***************
*** 121,126 ****
--- 121,127 ----
    , LYK_EDIT_TEXTAREA
    , LYK_GROW_TEXTAREA
    , LYK_INSERT_FILE
+   , LYK_SCRIPT

  #ifdef EXP_ADDRLIST_PAGE
    , LYK_ADDRLIST
diff -rc lynx2-8-2.real/src/LYMainLoop.c lynx2-8-2/src/LYMainLoop.c
*** lynx2-8-2.real/src/LYMainLoop.c     Fri May 28 07:04:01 1999
--- lynx2-8-2/src/LYMainLoop.c  Tue Jun 29 16:45:41 1999
***************
*** 263,268 ****
--- 263,270 ----
      unsigned int len;
      int i;
      int n;
+     extern LY_TEMP *ly_temp;
+     char *location;

  #ifdef DIRED_SUPPORT
      char *tp = NULL;
***************
*** 1210,1216 ****
                 */
                        /*  currently disabled ***
                HTUserMsg(gettext("Reparsing document under current 
settings..."));
!               cmd = LYK_RELOAD;
                goto new_cmd;
                        */
            }
--- 1212,1218 ----
                 */
                        /*  currently disabled ***
                HTUserMsg(gettext("Reparsing document under current 
settings..."));
!               cmd = LYK_PREV_DOC;
                goto new_cmd;
                        */
            }
***************
*** 2743,2750 ****
                if (LYValidate || check_realm) {
                    LYPermitURL = TRUE;
                }
                break;
!           } /* end if strncmp */
            /*
             *  Don't put break here so that if the backspace key
             *  is pressed in the history page, we fall though,
--- 2745,2755 ----
                if (LYValidate || check_realm) {
                    LYPermitURL = TRUE;
                }
+ #ifdef SOURCE_CACHE
+               HTuncache_current_document(); 
+ #endif /* SOURCE_CACHE */
                break;
!           }  /* end if strncmp */
            /*
             *  Don't put break here so that if the backspace key
             *  is pressed in the history page, we fall though,
***************
*** 3750,3755 ****
--- 3755,3763 ----
                newdoc.isHEAD = FALSE;
                newdoc.safe = FALSE;
                newdoc.internal_link = FALSE;
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            }
            break;

***************
*** 3961,3966 ****
--- 3969,3977 ----
                if (LYValidate || check_realm) {
                    LYPermitURL = TRUE;
                }
+ #ifdef SOURCE_CACHE
+               HTuncache_current_document(); 
+ #endif /* SOURCE_CACHE */
           } else {
                /*
                 *  If already in the options menu, get out.
***************
*** 4608,4613 ****
--- 4619,4627 ----
                if (check_realm)
                    LYPermitURL = TRUE;
                refresh_screen = TRUE;  /* redisplay */
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            }
            break;

***************
*** 4642,4647 ****
--- 4656,4664 ----
                LYPermitURL = TRUE;
                StrAllocCopy(lynxlistfile, newdoc.address);
            }
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            break;

  #ifdef EXP_ADDRLIST_PAGE
***************
*** 4676,4681 ****
--- 4693,4701 ----
                LYPermitURL = TRUE;
                StrAllocCopy(lynxlistfile, newdoc.address);
            }
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            break;
  #endif /* EXP_ADDRLIST_PAGE */

***************
*** 4708,4713 ****
--- 4728,4736 ----
                LYPermitURL = TRUE;
                StrAllocCopy(lynxlinksfile, newdoc.address);
            }
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            break;

        case LYK_TOOLBAR:  /* go to Toolbar or Banner in current document */
***************
*** 4875,4881 ****
                run_external(links[curdoc.link].lname);
                refresh_screen = TRUE;
            }
!           break;
  #endif /* USE_EXTERNALS */

        case LYK_ADD_BOOKMARK:  /* add link to bookmark file */
--- 4898,4921 ----
                run_external(links[curdoc.link].lname);
                refresh_screen = TRUE;
            }
!             break;
!         case LYK_SCRIPT: /* use external scripts on current web page */
! #ifdef SOURCE_CACHE
!               c = HTConfirmDefault(CHANGE_CACHE, YES);
!                 if (c == YES) {
!                    sprintf(location,"file://localhost%s",ly_temp->name);
!                  StrAllocCopy(newdoc.address, location); }
!                 else {
!                  StrAllocCopy(newdoc.address, curdoc.address); }
!               run_script(curdoc.address, ly_temp->name);
! #else
!               run_script(curdoc.address, NULL);
! #endif /* SOURCE_CACHE */
!               FREE(curdoc.address);
!               newdoc.line = curdoc.line;
!               newdoc.link = curdoc.link;
!               refresh_screen = TRUE;
!             break;
  #endif /* USE_EXTERNALS */

        case LYK_ADD_BOOKMARK:  /* add link to bookmark file */
***************
*** 5311,5316 ****
--- 5351,5359 ----
                old_c = real_c;
                HTUserMsg(NO_DOWNLOAD_CHOICE);
            }
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            break;

  #ifdef DIRED_SUPPORT
***************
*** 5340,5345 ****
--- 5383,5391 ----
                 */
                HTuncache_current_document();
             }
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            break;
  #endif /* DIRED_SUPPORT */

***************
*** 5606,5611 ****
--- 5652,5660 ----
                }
  #endif /* DIRED_SUPPORT && OK_OVERRIDE */
                LYforce_no_cache = TRUE;
+ #ifdef SOURCE_CACHE
+                 HTuncache_current_document();
+ #endif /* SOURCE_CACHE */
            }
            break;

diff -rc lynx2-8-2.real/src/LYStrings.c lynx2-8-2/src/LYStrings.c
*** lynx2-8-2.real/src/LYStrings.c      Fri May 28 07:04:01 1999
--- lynx2-8-2/src/LYStrings.c   Tue Jun 29 14:15:54 1999
***************
*** 213,224 ****

      if (y == (LYlines-1)) {
        mouse_link = -2;
!       if (x < left) c = LTARROW;
        else if (x > right) c = '\b';
        else c = PGDOWN;
      } else if (y == 0) {
        mouse_link = -2;
!       if (x < left) c = LTARROW;
        else if (x > right) c = '\b';
        else c = PGUP;
      } else {
--- 213,224 ----

      if (y == (LYlines-1)) {
        mouse_link = -2;
!       if (x < left) c = LYReverseKeymap (LYK_GOTO);
        else if (x > right) c = '\b';
        else c = PGDOWN;
      } else if (y == 0) {
        mouse_link = -2;
!       if (x < left) c = LYReverseKeymap (LYK_ABORT);
        else if (x > right) c = '\b';
        else c = PGUP;
      } else {
***************
*** 288,293 ****
--- 288,310 ----
            else if (mouse_err >= 0)
                c = lookup_keymap(LYK_CHANGE_LINK);
        }
+          else {
+                 if ((4*y < LYlines) && (y!=0))
+                  c = LYReverseKeymap (LYK_UP_HALF);
+                 else {
+                     if (2*y < LYlines)
+                       c = LYReverseKeymap (LYK_UP_TWO);
+                     else {
+                         if (4*y < 3*LYlines)
+                           c = LYReverseKeymap (LYK_DOWN_TWO);
+                         else {
+                             if (y!= LYlines - 1)
+                               c = LYReverseKeymap (LYK_DOWN_HALF);
+                              }
+                          }
+                       }
+               }
+ 
      }
      return c;
  }
***************
*** 537,542 ****
--- 554,562 ----
        if (button == 0)  /* left */
          return set_clicked_link (mouse_x, mouse_y, FOR_PANEL);

+         if (button == 1)  /* middle */
+           return LYReverseKeymap (LYK_VIEW_BOOKMARK);
+  
        if (button == 2)   /* right */
          {
             /* Right button: go back to prev document.
diff -rc lynx2-8-2.real/src/LYUtils.c lynx2-8-2/src/LYUtils.c
*** lynx2-8-2.real/src/LYUtils.c        Sat May 29 20:27:26 1999
--- lynx2-8-2/src/LYUtils.c     Fri Jun 25 13:03:02 1999
***************
*** 90,95 ****
--- 90,96 ----

  #define COPY_COMMAND "%s %s %s"

+ char *cache_file = NULL;
  extern HTkcode kanji_code;
  extern BOOLEAN LYHaveCJKCharacterSet;
  extern HTCJKlang HTCJK;
***************
*** 3380,3386 ****
  /*
   * Construct a temporary-filename.  Assumes result is LY_MAXPATH chars long.
   */
! PRIVATE int fmt_tempname ARGS3(
        char *,         result,
        CONST char *,   prefix,
        CONST char *,   suffix)
--- 3381,3387 ----
  /*
   * Construct a temporary-filename.  Assumes result is LY_MAXPATH chars long.
   */
! PUBLIC int fmt_tempname ARGS3(
        char *,         result,
        CONST char *,   prefix,
        CONST char *,   suffix)
***************
*** 3424,3429 ****
--- 3425,3431 ----
        sprintf(result, "%.*s", LY_MAXPATH-1, leaf);
        code = FALSE;
      }
+     cache_file = result;
      CTRACE(tfp, "-> '%s'\n", result);
      return (code);
  }
***************
*** 3512,3517 ****
--- 3514,3520 ----
  #ifdef USE_EXTERNALS
         "externals" ,
  #endif
+        "scripts" ,
         (char *) 0     };

        /* restrict_name and restrict_flag structure order
***************
*** 5799,5812 ****
  /*
   * Maintain a list of all of the temp-files we create so that we can remove
   * them during the cleanup.
   */
- typedef struct _LYTemp {
-     struct _LYTemp *next;
-     char *name;
-     FILE *file;
- } LY_TEMP;

! static LY_TEMP *ly_temp;

  /*
   * Open a temp-file, ensuring that it is unique, and not readable by other
--- 5802,5816 ----
  /*
   * Maintain a list of all of the temp-files we create so that we can remove
   * them during the cleanup.
+  *
+  * typedef struct _LYTemp {
+  *   struct _LYTemp *next;
+  *   char *name;
+  *   FILE *file;
+  *} LY_TEMP;
   */

! LY_TEMP *ly_temp;

  /*
   * Open a temp-file, ensuring that it is unique, and not readable by other
diff -rc lynx2-8-2.real/src/LYUtils.h lynx2-8-2/src/LYUtils.h
*** lynx2-8-2.real/src/LYUtils.h        Sat May 29 20:27:26 1999
--- lynx2-8-2/src/LYUtils.h     Fri Jun 25 13:01:45 1999
***************
*** 48,53 ****
--- 48,59 ----
      (!strcmp((name), LIST_PAGE_TITLE))
  #endif

+ typedef struct _LYTemp {struct _LYTemp *next;
+     char *name;
+     FILE *file;  
+ } LY_TEMP;
+ 
+ 
  #define LYIsHtmlSep(ch) ((ch) == '/')

  #define TABLESIZE(v) (sizeof(v)/sizeof(v[0]))
***************
*** 129,134 ****
--- 135,141 ----
  #if ! HAVE_PUTENV
  extern int putenv PARAMS((CONST char *string));
  #endif /* HAVE_PUTENV */
+ 

  #ifdef UNIX
  extern void LYRelaxFilePermissions PARAMS((CONST char * name));
Only in lynx2-8-2/src: lop

Eduardo
http://www.math.washington.edu/~chappa/personal.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]