home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Archived / Updates / Flash / writeflash / !MakeFlash / c / action next >
Text File  |  2000-06-04  |  2KB  |  95 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. //
  5. #include "proto.h"
  6. #include "bucket.h"
  7. #include "main.h"
  8. #include "flash.h"
  9. #include "action.h"
  10.  
  11.  
  12. int action_read(ACTION *actionlist) {
  13.  
  14.   return 0;
  15. }
  16.  
  17.  
  18. int action_write(ACTION *actions, unsigned int entries) {
  19.  
  20.   U32 ptr;
  21.  
  22.   if (entries == 0)                               return 0;
  23.  
  24.   if (flush_bucket())                             return 1;
  25.   ptr = read_position(NULL);
  26.   if (write_ushort(0))                            return 1;
  27.  
  28.   if (action_write_list(actions, entries))        return 1;
  29.   return update_record_header(stagDoAction, ptr);
  30. }
  31.  
  32.  
  33.  
  34. int action_write_list(ACTION *actions, unsigned int n) {
  35.  
  36.   U32 i;
  37.  
  38.   for (i = 0; i < n; i++) {
  39.     if (write_ubyte(actions[i].action))                               return 1;
  40.     switch (actions[i].action) {
  41.     case ACTION_GOTOFRAME:
  42.       if (write_ushort(2))                                            return 1;
  43.       if (write_ushort(actions[i].data.gotoframe))                    return 1;
  44.       break;
  45.     case ACTION_GETURL:
  46.       {
  47.         U32 c;
  48.         if (write_ushort(strlen(actions[i].data.geturl.url)+1+
  49.                          strlen(actions[i].data.geturl.target)+1))    return 1;
  50.         c = 0;
  51.         while (actions[i].data.geturl.url[c])
  52.           if (write_ubyte(actions[i].data.geturl.url[c++]))           return 1;
  53.         if (write_ubyte(0))                                           return 1;
  54.         c = 0;
  55.         while (actions[i].data.geturl.target[c])
  56.           if (write_ubyte(actions[i].data.geturl.target[c++]))        return 1;
  57.         if (write_ubyte(0))                                           return 1;
  58.       }
  59.       break;
  60.     case ACTION_PLAY:
  61.     case ACTION_NEXTFRAME:
  62.     case ACTION_PREVIOUSFRAME:
  63.     case ACTION_STOP:
  64.     case ACTION_STOPSOUNDS:
  65.       break;
  66.     default:
  67.       return 1;
  68.       break;
  69.     }
  70.   }
  71.  
  72.   if (write_ubyte(ACTION_NULL))                   return 1;
  73.  
  74.   return 0;
  75. }
  76.  
  77.  
  78. int add_action(ACTION **list, unsigned int *count, ACTION *newaction) {
  79.  
  80.   if (!*list) {
  81.     *list = malloc(sizeof(ACTION));
  82.     if (!*list)                          return 1;
  83.   } else {
  84.     ACTION *newlist;
  85.     newlist = realloc(*list, (*count+1)*sizeof(ACTION));
  86.     if (!newlist)                       return 1;
  87.     *list = newlist;
  88.   }
  89.  
  90.   memcpy(*list+*count, newaction, sizeof(ACTION));
  91.   *count = *count+1;
  92.  
  93.   return 0;
  94. }
  95.