home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / plugin / javap.c next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  164 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "npapi.h"
  20.  
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <stdarg.h>
  24. #include <string.h>
  25.  
  26. #if defined(__sun)
  27. # include "sunos4.h"
  28. #endif /* __sun */
  29.  
  30. #ifdef DEBUG
  31. extern int np_debug;
  32. static void
  33. nptrace (const char* message, ...)
  34. {
  35.     int len;
  36.     char buf[2048];
  37.     va_list stack;
  38.  
  39.     va_start (stack, message);
  40.     len = vsprintf (buf, message, stack);
  41.     va_end (stack);
  42.     len = strlen(buf);
  43.     fwrite("\t\tjp: ", 1, 6, stderr);
  44.     fwrite(buf, 1, len, stderr);
  45.     if (buf[len-1] != '\n')
  46.         fwrite("\n", 1, 1, stderr);
  47. }
  48. #define NPTRACE(l,t) { if(np_debug>l){nptrace t;}}
  49. #else
  50. #define NPTRACE(l,t) {}
  51. #endif
  52.  
  53. #include "npupp.h"
  54. extern NPNetscapeFuncs *np_nfuncs;
  55.  
  56. static int inum = 1;
  57.  
  58. static NPError
  59. javap_new(void *j, NPP npp, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
  60. {
  61.     if(mode==NP_EMBED) {
  62.         NPTRACE(0,("new embed"));
  63.     } else {
  64.         NPTRACE(0,("new full"));
  65.     }
  66.     return 0;
  67. }
  68.  
  69. static NPError
  70. javap_destroy(NPP instance, NPSavedData **save)
  71. {
  72.     NPTRACE(0,("destroy"));
  73.     return 0;
  74. }
  75.  
  76. static NPError
  77. javap_setwindow(NPP instance, NPWindow *window)
  78. {
  79.     NPTRACE(0,("setwindow x %d y %d w %d h %d", window->x, window->y, window->width, window->height));
  80.     return 0;
  81. }
  82.  
  83. static NPError
  84. javap_newstream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype)
  85. {
  86.     NPTRACE(0,("new stream"));
  87.  
  88.     switch(inum)
  89.     {
  90.             case 1:
  91.             {
  92.                 NPByteRange a, b;
  93.                 *stype = NP_SEEK;
  94.                 a.offset = 0;
  95.                 a.length = 60;
  96.                 b.offset = 252525;
  97.                 b.length = 10;
  98.                 a.next = &b;
  99.                 b.next = 0;
  100.                 np_nfuncs->requestread(stream, &a);
  101.             }
  102.             break;
  103.  
  104.             case 2:
  105.                 *stype = NP_ASFILE;
  106.                 break;
  107.  
  108.             case 3:
  109.                 {
  110.                     np_nfuncs->geturl(instance, "about:", "_current");
  111.                 }
  112.                 break;
  113.     }
  114.     inum++;
  115.         
  116.     np_nfuncs->status(instance, "wow");
  117.  
  118.     return 0;
  119. }
  120.  
  121. static int32
  122. javap_write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
  123. {
  124.     char buf[64];
  125.     NPTRACE(0,("got %d bytes at %d", len, offset));
  126.  
  127.     return 0;
  128.     strncpy(buf, (const char *)buffer, 63);
  129.     buf[63]=0;
  130.     NPTRACE(0,("\"%s\"", (char *)buf));
  131.     fwrite(buffer, len, 1, stream->pdata);
  132.     return 0;
  133. }
  134.  
  135. static NPError
  136. javap_closestream(NPP instance, NPStream *stream, NPError reason)
  137. {
  138.     NPTRACE(0,("sclose"));
  139.     pclose(stream->pdata);
  140.     return 0;
  141. }
  142.  
  143. static void
  144. javap_asfile(NPP instance, NPStream *stream, const char *fname)
  145. {
  146.     NPTRACE(0,("fname: \"%s\"", fname));
  147. }
  148.  
  149.  
  150. NPPluginFuncs javap_funcs = {
  151.     javap_new,
  152.     javap_destroy,
  153.     javap_setwindow,
  154.     javap_newstream,
  155.     javap_closestream,
  156.     javap_asfile,
  157.     NULL,
  158.     javap_write,
  159.     NULL,
  160.     NULL
  161. };
  162.  
  163. NPPluginFuncs *j_pfncs = &javap_funcs;
  164.