home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / System / Source / Buffers.c next >
C/C++ Source or Header  |  2002-10-31  |  2KB  |  106 lines

  1. #include "stdafx.h"
  2. #include "Plugin.h"
  3. #include "System.h"
  4. #include "Buffers.h"
  5.  
  6. typedef struct tagTempStack TempStack;
  7. typedef struct tagTempStack
  8. {
  9.     TempStack *Next;
  10.     char Data[0];
  11. } TempStack;
  12. TempStack *tempstack = NULL;
  13.  
  14. PLUGINFUNCTIONSHORT(Alloc)
  15. {
  16.     int size;
  17.     if ((size = popint()) == 0)
  18.     {
  19.         pushint(0);
  20.         return;
  21.     }
  22.     pushint((int) GlobalAlloc(GPTR, size));
  23. }
  24. PLUGINFUNCTIONEND
  25.  
  26. PLUGINFUNCTIONSHORT(Copy)
  27. {
  28.     int size = 0;
  29.     HANDLE source, dest;
  30.     char *str;
  31.     // Get the string
  32.     if ((str = popstring()) == NULL) return;
  33.  
  34.     // Check for size option
  35.     if (str[0] == '/')
  36.     {
  37.         size = (int) myatoi(str+1);
  38.         dest = (HANDLE) popint();
  39.     }
  40.     else dest = (HANDLE) myatoi(str+1);
  41.     source = (HANDLE) popint();
  42.  
  43.     // Ok, check the size
  44.     if (size == 0) size = (int) GlobalSize(source);
  45.     // and the destinantion
  46.     if ((int) dest == 0) dest = GlobalAlloc((GPTR), size);
  47.  
  48.     // COPY!
  49.     copymem(dest, source, size);
  50.  
  51.     GlobalFree(str);
  52. }
  53. PLUGINFUNCTIONEND
  54.  
  55. PLUGINFUNCTIONSHORT(Free)
  56. {
  57.     GlobalFree((HANDLE) popint());
  58. }
  59. PLUGINFUNCTIONEND
  60.  
  61. PLUGINFUNCTION(Store)
  62. {
  63.     TempStack *tmp;
  64.     int size = ((INST_R9+1)*g_stringsize);    
  65.  
  66.     char *command, *cmd = command = popstring();
  67.     while (*cmd != 0)
  68.     {
  69.         switch (*(cmd++))
  70.         {
  71.         case 's':
  72.         case 'S':
  73.             // Store the whole variables range
  74.             tmp = (TempStack*) GlobalAlloc(GPTR, sizeof(TempStack)+size);
  75.             tmp->Next = tempstack;
  76.             tempstack = tmp;
  77.  
  78.             // Fill with data
  79.             copymem(tempstack->Data, g_variables, size);
  80.             break;
  81.         case 'l':
  82.         case 'L':
  83.             // Fill with data
  84.             copymem(g_variables, tempstack->Data, size);
  85.  
  86.             // Restore stack
  87.             tmp = tempstack->Next;
  88.             GlobalFree((HANDLE) tempstack);
  89.             tempstack = tmp;
  90.             break;
  91.         case 'P':
  92.             *cmd += 10;
  93.         case 'p':
  94.             GlobalFree((HANDLE) pushstring(getuservariable(*(cmd++)-'0')));
  95.             break;
  96.         case 'R':
  97.             *cmd += 10;
  98.         case 'r':
  99.             GlobalFree((HANDLE) setuservariable(*(cmd++)-'0', popstring()));
  100.             break;
  101.         }
  102.     }
  103.  
  104.     GlobalFree((HANDLE) command);
  105. }
  106. PLUGINFUNCTIONEND