Changeset 540


Ignore:
Timestamp:
Apr 24, 2011, 10:33:34 AM (6 years ago)
Author:
sam
Message:

tool: get rid of the specfile additions and implement a general purpose
SPEC file edition tool.

Location:
abuse/trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/.gitignore

    r161 r540  
    1616abuse.6
    1717src/abuse
     18src/abuse-tool
  • abuse/trunk/src/Makefile.am

    r509 r540  
    33SUBDIRS = lisp net imlib sdlport
    44
    5 bin_PROGRAMS = abuse
     5bin_PROGRAMS = abuse abuse-tool
    66
    77abuse_SOURCES = \
     
    6969abuse_DEPENDENCIES = $(EXTRALIBS)
    7070
     71abuse_tool_SOURCES = \
     72    tool/abuse-tool.cpp
     73abuse_tool_LDADD = imlib/libimlib.a
     74abuse_tool_DEPENDENCIES = $(abuse_tool_LDADD)
     75
    7176INCLUDES = -I$(srcdir) -I $(srcdir)/lisp -I$(srcdir)/imlib \
    7277           -I$(srcdir)/net $(SDL_CFLAGS)
  • abuse/trunk/src/imlib/specs.cpp

    r539 r540  
    2525#include "image.h"
    2626#include "palette.h"
    27 #include "pcxread.h"
    2827#include "specs.h"
    2928#include "dprint.h"
     
    963962}
    964963
    965 void spec_directory::extract(char const *name)
    966 {
    967     jFILE fp(name, "rb");
    968     if (fp.open_failure())
    969     {
    970         fprintf(stderr, "Spec: ERROR - could not open %s\n", name);
    971         return;
    972     }
    973 
    974     spec_directory dir(&fp);
    975     if (dir.total <= 0)
    976     {
    977         fprintf(stderr, "Spec: ERROR - no signature or no data in %s\n", name);
    978         return;
    979     }
    980 
    981     char const *out = "SPEC.DIR";
    982     mkdir(out, S_IRUSR | S_IWUSR | S_IXUSR);
    983     if (chdir(out))
    984     {
    985         fprintf(stderr, "Spec: ERROR - could not create or cd to %s\n", out);
    986         return;
    987     }
    988 
    989     palette *pal = NULL;
    990 
    991     for (int i = 0; i < dir.total; i++)
    992     {
    993         spec_entry *se = dir.entries[i];
    994 
    995         FILE *fp2 = fopen(se->name, "wb");
    996         if (!fp2)
    997         {
    998             fprintf(stderr, "Spec: ERROR - could not write to %s\n", se->name);
    999             continue;
    1000         }
    1001 
    1002         fp.seek(se->offset, SEEK_SET);
    1003         uint8_t buf[1024];
    1004         size_t todo = se->size;
    1005         while (todo > 0)
    1006         {
    1007             fp.read(buf, Min(todo, 1024));
    1008             fwrite(buf, Min(todo, 1024), 1, fp2);
    1009             todo -= Min(todo, 1024);
    1010         }
    1011         fclose(fp2);
    1012 
    1013         fprintf(stderr, "Spec: %s (type %i): %i bytes\n",
    1014                 se->name, se->type, (int)se->size);
    1015 
    1016         /* If it's a palette, keep it */
    1017         if (!pal && se->type == SPEC_PALETTE)
    1018             pal = new palette(se, &fp);
    1019     }
    1020 
    1021     /* If we have a palette, output all images */
    1022     for (int i = 0; pal && i < dir.total; i++)
    1023     {
    1024         char buf[1024];
    1025         spec_entry *se = dir.entries[i];
    1026 
    1027         switch (se->type)
    1028         {
    1029         case SPEC_IMAGE:
    1030         case SPEC_FORETILE:
    1031         case SPEC_BACKTILE:
    1032         case SPEC_CHARACTER:
    1033         case SPEC_CHARACTER2:
    1034             sprintf(buf, "%s-export.pcx", se->name);
    1035             image *im = new image(&fp, se);
    1036             write_PCX(im, pal, buf);
    1037             delete im;
    1038             fprintf(stderr, "Spec: %s is an image\n", buf);
    1039             break;
    1040         }
    1041     }
    1042 
    1043     /* Clean up */
    1044     delete pal;
    1045 }
    1046 
    1047964void note_open_fd(int fd, char const *str)
    1048965{
  • abuse/trunk/src/imlib/specs.h

    r539 r540  
    207207  void delete_entries();   // if the directory was created by hand instead of by file
    208208  ~spec_directory();
    209 
    210   static void extract(char const *name);
    211209} ;
    212210
  • abuse/trunk/src/sdlport/setup.cpp

    r539 r540  
    336336            }
    337337        }
    338         else if (ii + 1 < argc && !strcasecmp(argv[ii], "-export"))
    339         {
    340             spec_directory::extract(argv[++ii]);
    341             exit(0);
    342         }
    343338        else if( !strcasecmp( argv[ii], "-h" ) || !strcasecmp( argv[ii], "--help" ) )
    344339        {
Note: See TracChangeset for help on using the changeset viewer.