r107 - trunk/tools
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sat Mar 19 17:16:09 EST 2005
Author: jonas
Date: 2005-03-19 17:16:09 -0500 (Sat, 19 Mar 2005)
New Revision: 107
Added:
trunk/tools/lvl2magick.c
Modified:
trunk/tools/Makefile
trunk/tools/slvextract.c
Log:
reorganized the directory structure...
Modified: trunk/tools/Makefile
===================================================================
--- trunk/tools/Makefile 2005-03-19 21:32:42 UTC (rev 106)
+++ trunk/tools/Makefile 2005-03-19 22:16:09 UTC (rev 107)
@@ -1,29 +1,31 @@
-CXX = g++
-CXX_FLAGS = -W -Wall -pedantic
-CXX_DEBUG = -g #-fno-inline
-CXX_OPT = -O2 -march=pentium4 -ffast-math
-CXX_GAME = -DSDL_MIXER -DSDL_IMAGE -DALPHA
-SDL = `sdl-config --cflags`
-SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image
+CC = gcc
+CC_FLAGS = -pedantic -W -Wall
+CC_DEBUG = -g #-fno-inline
+CC_OPT = -O2 -march=pentium4 -ffast-math
+CC_LVL = `Magick-config --ldflags --libs`
-OBJS = slvextract.o
-BIN = slvextract
+SLV = lvlextract
+SLV_OBJS = slvextract.o
+LVL = lvl2magick
+LVL_OBJS = lvl2magick.o
-default:
- $(MAKE) -C lvl_tools
- $(MAKE) $(BIN)
-
-$(BIN): $(OBJS)
- $(CXX) $(OBJS) $(SDL_LINK) -o $(BIN)
+default: $(SLV) $(LVL)
-%.o: %.cpp
- $(CXX) $(CXX_FLAGS) $(CXX_DEBUG) $(CXX_GAME) $(SDL) -c $< -o $@
+all: $(SLV) $(LVL)
+$(SLV): $(SLV_OBJS)
+ $(CC) $(SLV_OBJS) -o $(SLV)
+
+$(LVL): $(LVL_OBJS)
+ $(CC) $(CC_LVL) $(LVL_OBJS) -o $(LVL)
+
+%.o: %.c
+ $(CC) $(CC_FLAGS) $(CC_DEBUG) $(CC_OPT) -c $< -o $@
+
clean:
- rm -f *.o
- rm -f $(BIN)
- +$(MAKE) -C lvl_tools clean
+ rm -f $(SLV)
+ rm -f $(LVL)
+ rm -f *.o *.a
distclean: clean
rm -f *~
- +$(MAKE) -C lvl_tools distclean
Copied: trunk/tools/lvl2magick.c (from rev 106, trunk/tools/lvl_tools/lvl2magick.c)
Modified: trunk/tools/slvextract.c
===================================================================
--- trunk/tools/slvextract.c 2005-03-19 21:32:42 UTC (rev 106)
+++ trunk/tools/slvextract.c 2005-03-19 22:16:09 UTC (rev 107)
@@ -5,16 +5,19 @@
*/
#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <fcntl.h>
#include <unistd.h>
-void put_wav_header(int fd, int samp, int bits, int chans, int size)
-{
+void put_wav_header(int fd, int samp, int bit, int chans, int size) {
int bps = chans*samp;
char buf[44] = { 'R','I','F','F', 0,0,0,0, 'W','A','V','E',
- 'f','m','t',' ', 0,0,0,0,
- 1,0, 0,0, 0,0,0,0, 0,0,0,0, 0,0, 8,0,
- 'd','a','t','a', 0,0,0,0 };
+ 'f','m','t',' ', 0,0,0,0,
+ 1,0, 0,0, 0,0,0,0, 0,0,0,0, 0,0, 8,0,
+ 'd','a','t','a', 0,0,0,0 };
buf[4] = (size + 36);
buf[5] = (size + 36) >> 8;
@@ -50,153 +53,131 @@
write(fd, buf, 44);
}
-int read_entry(int fd_in)
-{
+int read_entry(int fd_in) {
int swapped = 0, size, samp, bits, chans;
char filename[14], buf[512];
- int fd_out, pos = 0, aligned;
+ int fd_out, pos = 0;
- printf("new entry at %x\n", lseek(fd_in, 0, SEEK_CUR));
+ printf("new entry at %x\n", (unsigned int)lseek(fd_in, 0, SEEK_CUR));
- // header
+ /* header */
read(fd_in, buf, 70);
- // byte swapped entry
- if (buf[3])
- swapped++;
+ /* byte swapped entry */
+ if (buf[3]) swapped++;
- // FIXME: size could be entries aswell? get some non-8bit samples
+ /* FIXME: size could be entries aswell? get some non-8bit samples */
- if (swapped)
- {
- size = (buf[0] << 16) | (buf[1] << 24) | (buf[2]) | (buf[3] << 8);
- samp = (buf[4] << 16) | (buf[5] << 24) | (buf[6]) | (buf[7] << 8);
- bits = (buf[8] << 16) | (buf[9 ] << 24) | (buf[10]) | (buf[11] << 8);
- chans = (buf[12] << 16)| (buf[13] << 24) | (buf[14]) | (buf[15] << 8);
+ if (swapped) {
+ size = (buf[0] << 16) | (buf[1] << 24) | (buf[2]) | (buf[3] << 8);
+ samp = (buf[4] << 16) | (buf[5] << 24) | (buf[6]) | (buf[7] << 8);
+ bits = (buf[8] << 16) | (buf[9 ] << 24) | (buf[10]) | (buf[11] << 8);
+ chans = (buf[12] << 16)| (buf[13] << 24) | (buf[14]) | (buf[15] << 8);
- size += 2;
+ size += 2;
- strncpy(&filename[0], &buf[52], 14);
- }
- else
- {
- size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
- samp = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
- bits = buf[8] | (buf[9] << 8) | (buf[10] << 16) | (buf[11] << 24);
- chans = buf[12] | (buf[13] << 8) | (buf[14] << 16) | (buf[15] << 24);
+ strncpy(&filename[0], &buf[52], 14);
+ } else {
+ size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+ samp = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
+ bits = buf[8] | (buf[9] << 8) | (buf[10] << 16) | (buf[11] << 24);
+ chans = buf[12] | (buf[13] << 8) | (buf[14] << 16) | (buf[15] << 24);
- strncpy(&filename[0], &buf[50], 14);
+ strncpy(&filename[0], &buf[50], 14);
}
- if (!size)
- return -1;
+ if (!size) return -1;
- printf("entry %x: %s size: %x %d/%d/%d\n",
- lseek(fd_in, 0, SEEK_CUR),
- filename, size, samp, bits, chans);
+ printf("entry %x: %s size: %x %d/%d/%d\n", (unsigned int)lseek(fd_in, 0, SEEK_CUR), filename, size, samp, bits, chans);
strncpy(buf, filename, 14);
- if (strrchr(buf, '.'))
- {
- char *loc = strrchr(buf, '.');
- strncpy(loc, ".wav", 5);
+ if (strrchr(buf, '.')) {
+ char *loc = strrchr(buf, '.');
+ strncpy(loc, ".wav", 5);
}
printf("Writing out %s...\n", buf);
fd_out = open(buf, O_WRONLY|O_CREAT, 0666);
put_wav_header(fd_out, samp, bits, chans, size);
- while(pos < size)
- {
- int ret = read(fd_in, buf, (size-pos > 512) ? 512 : size-pos);
-
- write(fd_out, buf, ret);
- pos += ret;
+ while(pos < size) {
+ int ret = read(fd_in, buf, (size-pos > 512) ? 512 : size-pos);
+
+ write(fd_out, buf, ret);
+ pos += ret;
}
close(fd_out);
- if (size % 4)
- {
- int aligned = size + (4 - (size % 4));
+ if (size % 4) {
+ int aligned = size + (4 - (size % 4));
- printf("aligned: %d, pos: %d, %d\n", aligned, pos, aligned-pos);
- lseek(fd_in, aligned-pos, SEEK_CUR);
-
- return 70 + size + aligned-pos;
+ printf("aligned: %d, pos: %d, %d\n", aligned, pos, aligned-pos);
+ lseek(fd_in, aligned-pos, SEEK_CUR);
+
+ return 70 + size + aligned-pos;
}
return 70 + size;
}
-int main(int argc, char *argv[])
-{
- int fd_in, fd_out;
+int main(int argc, char *argv[]) {
+ int fd_in;
char buf[16];
int size, pos = 0, counter = 0;
- if (argc < 2)
- {
- printf("Usage: %s input.slv [destination]\n", argv[0]);
- exit(1);
+ if (argc < 2) {
+ printf("Usage: %s input.slv [destination]\n", argv[0]);
+ exit(1);
}
fd_in = open(argv[1], O_RDONLY);
- if (fd_in < 0)
- {
- perror("error opening file");
- exit(1);
+ if (fd_in < 0) {
+ perror("error opening file");
+ exit(1);
}
read(fd_in, buf, 12);
if ((buf[0] != 'D') && (buf[1] != 'A') &&
- (buf[2] != 'T') && (buf[3] != 'A'))
- {
- printf("Invalid file\n");
- close(fd_in);
- exit(1);
+ (buf[2] != 'T') && (buf[3] != 'A')) {
+ printf("Invalid file\n");
+ close(fd_in);
+ exit(1);
}
size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
printf("size: %d\n", size);
- if (argc > 2)
- {
- mkdir(argv[2], 0777);
- chdir(argv[2]);
+ if (argc > 2) {
+ mkdir(argv[2], 0777);
+ chdir(argv[2]);
- printf("directory: %s\n", argv[2]);
- }
- else
- {
- // copy the filename
- if (strrchr(argv[1], '/'))
- strncpy(buf, strrchr(argv[1], '/')+1, 16);
- else
- strncpy(buf, argv[1], 16);
+ printf("directory: %s\n", argv[2]);
+ } else {
+ /* copy the filename */
+ if (strrchr(argv[1], '/')) strncpy(buf, strrchr(argv[1], '/')+1, 16);
+ else strncpy(buf, argv[1], 16);
- // truncate filename at .
- if (strrchr(buf, '.'))
- {
- char *loc = strrchr(buf, '.');
- *loc = 0;
- }
+ /* truncate filename at . */
+ if (strrchr(buf, '.')) {
+ char *loc = strrchr(buf, '.');
+ *loc = 0;
+ }
- mkdir(buf, 0777);
- chdir(buf);
+ mkdir(buf, 0777);
+ chdir(buf);
- printf("directory: %s\n", buf);
+ printf("directory: %s\n", buf);
}
- while(pos < size)
- {
- int tmp = read_entry(fd_in);
- if (tmp == -1)
- break;
- pos += tmp;
- counter++;
+ while(pos < size) {
+ int tmp = read_entry(fd_in);
+ if (tmp == -1) break;
+ pos += tmp;
+ counter++;
}
printf("extracted %d items\n", counter);
+ return 0;
}
More information about the lostpenguins-commits
mailing list