mirror of
https://github.com/simtactics/niotso.git
synced 2025-03-15 00:01:21 +00:00
Fixed the update-libraries script (thanks to Anderson Souza) and added a basic Linux daemon for the server
This commit is contained in:
parent
bb904c4698
commit
5444c9aea6
19 changed files with 260 additions and 84 deletions
|
@ -11,7 +11,7 @@ if(WIN32)
|
|||
Graphics/Font.cpp
|
||||
Graphics/Startup.cpp
|
||||
Graphics/Viewport.cpp
|
||||
resources/Resource.rc
|
||||
Resources/Resource.rc
|
||||
Scene/LoginScreen/LoginScreen.cpp
|
||||
System/System.cpp
|
||||
Window/Window.cpp
|
||||
|
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
libfar.c - Copyright (c) 2011 Niotso Project <http://niotso.org/>
|
||||
far.c - Copyright (c) 2011-2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
|
@ -72,21 +72,18 @@ int far_identify(const uint8_t * Buffer, unsigned FileSize)
|
|||
return FAR_TYPE_INVALID;
|
||||
|
||||
#ifdef FAR_SUPPORT_FAR
|
||||
if(FileSize >= MINSIZE_FAR)
|
||||
if(!memcmp(Buffer, Header_FAR, 8))
|
||||
return FAR_TYPE_FAR;
|
||||
if(FileSize >= MINSIZE_FAR && !memcmp(Buffer, Header_FAR, 8))
|
||||
return FAR_TYPE_FAR;
|
||||
#endif
|
||||
|
||||
#ifdef FAR_SUPPORT_DBPF
|
||||
if(FileSize >= MINSIZE_DBPF)
|
||||
if(!memcmp(Buffer, Header_DBPF, 4))
|
||||
return FAR_TYPE_DBPF;
|
||||
if(FileSize >= MINSIZE_DBPF && !memcmp(Buffer, Header_DBPF, 4))
|
||||
return FAR_TYPE_DBPF;
|
||||
#endif
|
||||
|
||||
#ifdef FAR_SUPPORT_PERSIST
|
||||
if(FileSize >= MINSIZE_PERSIST)
|
||||
if(Buffer[0] == 0x01)
|
||||
return FAR_TYPE_PERSIST;
|
||||
if(FileSize >= MINSIZE_PERSIST && Buffer[0] == 0x01)
|
||||
return FAR_TYPE_PERSIST;
|
||||
#endif
|
||||
|
||||
return FAR_TYPE_INVALID;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
libfar.h - Copyright (c) 2011 Niotso Project <http://niotso.org/>
|
||||
far.h - Copyright (c) 2011 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "config.h"
|
||||
#include "far.h"
|
||||
|
||||
enum {
|
||||
|
|
|
@ -159,5 +159,5 @@ int RefPackDecompress(const uint8_t *__restrict CompressedData, size_t Compresse
|
|||
}
|
||||
}
|
||||
|
||||
return (!stopflag || CompressedSize || DecompressedSize) ? 0 : 1;
|
||||
return (stopflag && !CompressedSize && !DecompressedSize);
|
||||
}
|
|
@ -102,18 +102,16 @@ void (* const iff_free_function[])(void*) = {
|
|||
** API public functions
|
||||
*/
|
||||
|
||||
IFFFile * iff_create()
|
||||
int iff_create(IFFFile * IFFFileInfo)
|
||||
{
|
||||
IFFFile *ptr = calloc(1, sizeof(IFFFile));
|
||||
if(ptr == NULL) return NULL;
|
||||
memset(IFFFileInfo, 0, sizeof(IFFFile));
|
||||
|
||||
ptr->Chunks = calloc(1, sizeof(IFFChunk));
|
||||
if(ptr->Chunks == NULL){
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
ptr->SizeAllocated = sizeof(IFFChunk);
|
||||
return ptr;
|
||||
IFFFileInfo->Chunks = calloc(1, sizeof(IFFChunk));
|
||||
if(IFFFileInfo->Chunks == NULL)
|
||||
return 0;
|
||||
IFFFileInfo->SizeAllocated = sizeof(IFFChunk);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int iff_read_header(IFFFile * IFFFileInfo, const uint8_t * Buffer, unsigned FileSize)
|
||||
|
@ -250,7 +248,4 @@ void iff_delete(IFFFile * IFFFileInfo){
|
|||
free(IFFFileInfo->ResourceMap->FormattedData);
|
||||
free(IFFFileInfo->ResourceMap);
|
||||
}
|
||||
|
||||
free(IFFFileInfo);
|
||||
IFFFileInfo = NULL;
|
||||
}
|
|
@ -345,7 +345,7 @@ extern "C" {
|
|||
** IFF file functions
|
||||
*/
|
||||
|
||||
IFFFile * iff_create();
|
||||
int iff_create(IFFFile * IFFFileInfo);
|
||||
int iff_read_header(IFFFile * IFFFileInfo, const uint8_t * Buffer, unsigned FileSize);
|
||||
|
||||
IFFChunk * iff_add_chunk(IFFFile * IFFFileInfo);
|
||||
|
|
|
@ -40,7 +40,7 @@ int main(int argc, char *argv[]){
|
|||
clock_t BeginningTime;
|
||||
unsigned chunkcount, chunk;
|
||||
unsigned exported = 0;
|
||||
IFFFile * IFFFileInfo;
|
||||
IFFFile IFFFileInfo;
|
||||
IFFChunk * ChunkData;
|
||||
|
||||
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
|
||||
|
@ -95,12 +95,11 @@ int main(int argc, char *argv[]){
|
|||
** Load header information
|
||||
*/
|
||||
|
||||
IFFFileInfo = iff_create();
|
||||
if(IFFFileInfo == NULL){
|
||||
if(!iff_create(&IFFFileInfo)){
|
||||
printf("%sMemory for this file could not be allocated.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
if(!iff_read_header(IFFFileInfo, IFFData, FileSize)){
|
||||
if(!iff_read_header(&IFFFileInfo, IFFData, FileSize)){
|
||||
printf("%sNot a valid IFF file.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
@ -109,19 +108,19 @@ int main(int argc, char *argv[]){
|
|||
** Load entry information
|
||||
*/
|
||||
|
||||
if(!iff_enumerate_chunks(IFFFileInfo, IFFData+64, FileSize-64)){
|
||||
if(!iff_enumerate_chunks(&IFFFileInfo, IFFData+64, FileSize-64)){
|
||||
printf("%sChunk data is corrupt.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
chunkcount = IFFFileInfo->ChunkCount;
|
||||
chunkcount = IFFFileInfo.ChunkCount;
|
||||
printf("This IFF file contains %u chunks.\n\nExporting\n", chunkcount);
|
||||
BeginningTime = clock();
|
||||
|
||||
/****
|
||||
** Extract each entry
|
||||
*/
|
||||
for(chunk = 1, ChunkData = IFFFileInfo->Chunks; chunk <= chunkcount; chunk++, ChunkData++){
|
||||
for(chunk = 1, ChunkData = IFFFileInfo.Chunks; chunk <= chunkcount; chunk++, ChunkData++){
|
||||
char name[256], destination[256];
|
||||
char filter[] = "\\/:*?\"<>|";
|
||||
int i;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project(NiotsoServer)
|
||||
|
||||
if(WIN32)
|
||||
else()
|
||||
set(NIOTSOSERVER_SOURCES
|
||||
Server.cpp
|
||||
)
|
||||
add_executable(niotsod-vanilla ${NIOTSOSERVER_SOURCES})
|
||||
target_link_libraries(niotsod-vanilla)
|
||||
endif()
|
|
@ -16,4 +16,161 @@
|
|||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include "Server.hpp"
|
||||
|
||||
#define SHUTDOWN(X) do { syslog(LOG_INFO, "<info> Could not recover from errors. Shutting down."); \
|
||||
exitval = EXIT_FAILURE; goto X; } while(0)
|
||||
#define SHUTDOWN_M(X, Y) do { syslog(LOG_ERR, "<error> %s (%s)", X, strerror(errno)); \
|
||||
SHUTDOWN(Y); } while(0)
|
||||
|
||||
//IPV6_V6ONLY
|
||||
|
||||
static void term(int)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
const pid_t pid = fork();
|
||||
if(pid < 0){
|
||||
const char *msg1 = "<error> Failed to create child process (%s).", *msg2 = strerror(errno);
|
||||
openlog(SERVER_NAME, 0, LOG_DAEMON);
|
||||
syslog(LOG_ERR, msg1, msg2);
|
||||
closelog();
|
||||
fprintf(stderr, msg1, msg2);
|
||||
fprintf(stderr, "\n");
|
||||
return EXIT_FAILURE;
|
||||
}else if(pid > 0)
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
int exitval = EXIT_SUCCESS, sockfd, epollfd;
|
||||
{ //New scope required for error handling
|
||||
int ret;
|
||||
FILE * fd;
|
||||
|
||||
umask(0);
|
||||
|
||||
openlog(SERVER_NAME, LOG_PID, LOG_DAEMON);
|
||||
|
||||
if(setsid() < 0)
|
||||
SHUTDOWN_M("Failed to create session", close_msg);
|
||||
|
||||
if(chdir(CONFIG_DIR) < 0)
|
||||
SHUTDOWN_M("Failed to change into \""CONFIG_DIR"\"", close_msg);
|
||||
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
||||
struct sigaction sigact;
|
||||
sigact.sa_handler = term;
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigact.sa_flags = 0;
|
||||
sigaction(SIGTERM, &sigact, NULL);
|
||||
sigaction(SIGINT, &sigact, NULL);
|
||||
|
||||
syslog(LOG_INFO, "<info> "SERVER_NAME" (version "VERSIONSTR") is starting...");
|
||||
|
||||
fd = fopen("network.conf", "r");
|
||||
if(!fd)
|
||||
SHUTDOWN_M("Failed to open \""CONFIG_DIR"/network.conf\"", close_msg);
|
||||
unsigned int port = 0;
|
||||
ret = fscanf(fd, "%u", &port);
|
||||
fclose(fd);
|
||||
if(ret < 0)
|
||||
SHUTDOWN_M("Failed to read \""CONFIG_DIR"/network.conf\"", close_msg);
|
||||
if(port > 65535){
|
||||
syslog(LOG_ERR, "<error> Invalid port '%u' specified in \""CONFIG_DIR"/network.conf\".", port);
|
||||
SHUTDOWN(close_msg);
|
||||
}
|
||||
|
||||
sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if(sockfd < 0)
|
||||
SHUTDOWN_M("Failed to open socket", close_msg);
|
||||
|
||||
int flags = fcntl(sockfd, F_GETFL, 0);
|
||||
if(flags < 0)
|
||||
SHUTDOWN_M("Failed to read socket flags", close_socket);
|
||||
if(fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) < 0)
|
||||
SHUTDOWN_M("Failed to set socket flags", close_socket);
|
||||
|
||||
sockaddr_in6 server_addr, client_addr;
|
||||
memset(&server_addr, 0, sizeof(sockaddr_in6));
|
||||
memset(&client_addr, 0, sizeof(sockaddr_in6));
|
||||
server_addr.sin6_family = AF_INET6;
|
||||
server_addr.sin6_port = htons((uint16_t) port);
|
||||
server_addr.sin6_addr = in6addr_any;
|
||||
client_addr.sin6_family = AF_INET6;
|
||||
client_addr.sin6_addr = in6addr_any;
|
||||
|
||||
if(bind(sockfd, (const sockaddr*) &server_addr, sizeof(sockaddr_in6)) < 0)
|
||||
SHUTDOWN_M("Failed to bind to socket", close_socket);
|
||||
|
||||
epollfd = epoll_create(1);
|
||||
if(epollfd < 0)
|
||||
SHUTDOWN_M("Failed to create an epoll handle", close_socket);
|
||||
|
||||
epoll_event epev[1];
|
||||
epev[0].events = EPOLLIN | EPOLLPRI;
|
||||
epev[0].data.fd = sockfd;
|
||||
if(epoll_ctl(epollfd, EPOLL_CTL_ADD, sockfd, epev) < 0)
|
||||
SHUTDOWN_M("Failed to register the socket to the epoll handle", close_epoll);
|
||||
|
||||
//Now that we're running, stop being terminate-on-failure-happy
|
||||
syslog(LOG_INFO, "<info> Running.");
|
||||
|
||||
/****
|
||||
** Listen loop
|
||||
*/
|
||||
|
||||
int eventcount;
|
||||
while((eventcount = epoll_wait(epollfd, epev, 1, -1)) >= 0){
|
||||
if(eventcount == 0)
|
||||
continue;
|
||||
else if(epev[0].events & EPOLLERR)
|
||||
SHUTDOWN_M("Socket closed unexpectedly with EPOLLERR", close_epoll);
|
||||
else if(epev[0].events & EPOLLHUP)
|
||||
SHUTDOWN_M("Socket closed unexpectedly with EPOLLHUP", close_epoll);
|
||||
else if(!(epev[0].events & EPOLLIN) && !(epev[0].events & EPOLLPRI))
|
||||
continue;
|
||||
|
||||
uint8_t packetdata[1500];
|
||||
socklen_t addrlen = sizeof(sockaddr_in6);
|
||||
ssize_t packetsize = recvfrom(epev[0].data.fd, packetdata, 1500, 0, (sockaddr*) &client_addr, &addrlen);
|
||||
if(packetsize < 0){
|
||||
if(errno == EINTR || errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT)
|
||||
continue;
|
||||
|
||||
SHUTDOWN_M("Socket closed unexpectedly on call to recvfrom", close_epoll);
|
||||
}
|
||||
|
||||
//Pass the packet down (even zero-length packets might be meaningful in the protocol)
|
||||
//...
|
||||
}
|
||||
|
||||
/****
|
||||
** Shutdown
|
||||
*/
|
||||
|
||||
}
|
||||
close_epoll: close(epollfd);
|
||||
close_socket: close(sockfd);
|
||||
close_msg: syslog(LOG_INFO, "<info> Shut down gracefully.");
|
||||
closelog();
|
||||
|
||||
return exitval;
|
||||
}
|
||||
|
|
24
Server/Server.hpp
Normal file
24
Server/Server.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
Niotso Server - Niotso daemon based on PostgreSQL
|
||||
Server.hpp
|
||||
Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define SERVER_NAME "niotsod-vanilla"
|
||||
#define CONFIG_DIR "/etc/"SERVER_NAME
|
||||
|
||||
#define VERSIONSTR "0.0.0"
|
|
@ -60,7 +60,7 @@ int main(int argc, char *argv[]){
|
|||
struct MD5Context md5c;
|
||||
unsigned char digest[16];
|
||||
uint8_t * IFFData;
|
||||
IFFFile * IFFFileInfo;
|
||||
IFFFile IFFFileInfo;
|
||||
IFFChunk * ChunkData;
|
||||
|
||||
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
|
||||
|
@ -139,12 +139,11 @@ int main(int argc, char *argv[]){
|
|||
** Load header information
|
||||
*/
|
||||
|
||||
IFFFileInfo = iff_create();
|
||||
if(IFFFileInfo == NULL){
|
||||
if(!iff_create(&IFFFileInfo)){
|
||||
printf("%sMemory for this file could not be allocated.", "iff2html: error: ");
|
||||
return -1;
|
||||
}
|
||||
if(!iff_read_header(IFFFileInfo, IFFData, FileSize)){
|
||||
if(!iff_read_header(&IFFFileInfo, IFFData, FileSize)){
|
||||
printf("%sNot a valid IFF file.", "iff2html: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
@ -153,7 +152,7 @@ int main(int argc, char *argv[]){
|
|||
** Load entry information
|
||||
*/
|
||||
|
||||
if(!iff_enumerate_chunks(IFFFileInfo, IFFData+64, FileSize-64)){
|
||||
if(!iff_enumerate_chunks(&IFFFileInfo, IFFData+64, FileSize-64)){
|
||||
printf("%sChunk data is corrupt.", "iff2html: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
@ -164,7 +163,7 @@ int main(int argc, char *argv[]){
|
|||
MD5Final(digest, &md5c);
|
||||
free(IFFData);
|
||||
|
||||
for(c = 0, ChunkData = IFFFileInfo->Chunks; c < IFFFileInfo->ChunkCount; c++, ChunkData++)
|
||||
for(c = 0, ChunkData = IFFFileInfo.Chunks; c < IFFFileInfo.ChunkCount; c++, ChunkData++)
|
||||
iff_parse_chunk(ChunkData, ChunkData->Data);
|
||||
|
||||
/****
|
||||
|
@ -292,9 +291,9 @@ int main(int argc, char *argv[]){
|
|||
fprintf(hFile, "</div>\n");
|
||||
fprintf(hFile, "<div>Dumped by iff2html.</div></div>\n");
|
||||
fprintf(hFile, "\n");
|
||||
fprintf(hFile, "<div id=\"toc\"><div><b>Contents</b> – %u chunks</div>\n", IFFFileInfo->ChunkCount);
|
||||
fprintf(hFile, "<div id=\"toc\"><div><b>Contents</b> – %u chunks</div>\n", IFFFileInfo.ChunkCount);
|
||||
fprintf(hFile, "<ul>\n");
|
||||
for(c=1, ChunkData = IFFFileInfo->Chunks; c <= IFFFileInfo->ChunkCount; c++, ChunkData++)
|
||||
for(c=1, ChunkData = IFFFileInfo.Chunks; c <= IFFFileInfo.ChunkCount; c++, ChunkData++)
|
||||
fprintf(hFile, "<li><a href=\"#chunk%u_%.4x\">%u [%s] (%.4X)%s%s</a></li>\n",
|
||||
c, ChunkData->ChunkID, c, ChunkData->Type, ChunkData->ChunkID,
|
||||
(ChunkData->Label[0] != 0x00) ? " – " : "", ChunkData->Label);
|
||||
|
@ -302,7 +301,7 @@ int main(int argc, char *argv[]){
|
|||
fprintf(hFile, "</div>\n");
|
||||
fprintf(hFile, "\n");
|
||||
|
||||
for(c=0, ChunkData = IFFFileInfo->Chunks; c < IFFFileInfo->ChunkCount; c++, ChunkData++){
|
||||
for(c=0, ChunkData = IFFFileInfo.Chunks; c < IFFFileInfo.ChunkCount; c++, ChunkData++){
|
||||
fprintf(hFile, "<h2 id=\"chunk%u_%.4x\">%u [%s] (%.4X)%s%s <a href=\"#chunk%u_%.4x\">(Jump)</a></h2>\n",
|
||||
c+1, ChunkData->ChunkID, c+1, ChunkData->Type, ChunkData->ChunkID,
|
||||
(ChunkData->Label[0] != 0x00) ? " – " : "", ChunkData->Label,
|
||||
|
@ -555,9 +554,9 @@ int main(int argc, char *argv[]){
|
|||
fprintf(hFile, "</table>\n");
|
||||
|
||||
if(SpriteList->PaletteID < 0xFFFF){
|
||||
Palette = iff_find_chunk(IFFFileInfo, "PALT", SpriteList->PaletteID);
|
||||
if(!Palette || !Palette->FormattedData) Palette = iff_find_chunk(IFFFileInfo, "PALT", ChunkData->ChunkID);
|
||||
if(!Palette || !Palette->FormattedData) Palette = iff_find_chunk(IFFFileInfo, "PALT", -1);
|
||||
Palette = iff_find_chunk(&IFFFileInfo, "PALT", SpriteList->PaletteID);
|
||||
if(!Palette || !Palette->FormattedData) Palette = iff_find_chunk(&IFFFileInfo, "PALT", ChunkData->ChunkID);
|
||||
if(!Palette || !Palette->FormattedData) Palette = iff_find_chunk(&IFFFileInfo, "PALT", -1);
|
||||
}
|
||||
if(!Palette || !Palette->FormattedData){
|
||||
memset(&BlankPalette, 0, sizeof(IFFPalette));
|
||||
|
@ -697,7 +696,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
fprintf(hFile, "</div>\n\n");
|
||||
}
|
||||
iff_delete(IFFFileInfo);
|
||||
iff_delete(&IFFFileInfo);
|
||||
|
||||
fprintf(hFile,
|
||||
"<div id=\"footer\">This page was generated by the use of <a href=\"http://www.niotso.org/\">iff2html</a>.\n");
|
||||
|
|
|
@ -21,11 +21,9 @@
|
|||
#include <iff/iff.h>
|
||||
#include "tsoscan.h"
|
||||
|
||||
IFFStats* stats_create(){
|
||||
IFFStats *stats = calloc(1, sizeof(IFFStats));
|
||||
if (stats == NULL) return NULL;
|
||||
int stats_create(IFFStats *stats){
|
||||
stats->AverageChunkCount = -1;
|
||||
return stats;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stats_version_increment(IFFStats *stats, char *type, unsigned version){
|
||||
|
@ -107,5 +105,4 @@ void stats_delete(IFFStats *stats){
|
|||
free(stats->ChunkTypes[i].Versions);
|
||||
free(stats->ChunkTypes);
|
||||
}
|
||||
free(stats);
|
||||
}
|
|
@ -39,10 +39,10 @@ int main(int argc, char *argv[]){
|
|||
CommandLineArgs *CmdArgs;
|
||||
unsigned i, version, FileCount = 0;
|
||||
char **Files = NULL;
|
||||
IFFStats *Stats = stats_create();
|
||||
IFFStats Stats;
|
||||
FILE *OutFile;
|
||||
|
||||
if(Stats == NULL){
|
||||
if(!stats_create(&Stats)){
|
||||
printf("%sUnable to allocate enough memory.\n", TSOSCAN_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
@ -114,13 +114,11 @@ int main(int argc, char *argv[]){
|
|||
** Load and parse IFF files
|
||||
*/
|
||||
|
||||
Stats->AverageChunkCount = -1;
|
||||
|
||||
for(i=0; i<FileCount; i++){
|
||||
FILE *file;
|
||||
size_t FileSize;
|
||||
uint8_t *data;
|
||||
IFFFile *iff;
|
||||
IFFFile iff;
|
||||
IFFChunk *ChunkData;
|
||||
unsigned ChunkIndex;
|
||||
|
||||
|
@ -148,34 +146,33 @@ int main(int argc, char *argv[]){
|
|||
}
|
||||
fclose(file);
|
||||
|
||||
iff = iff_create();
|
||||
if(iff == NULL){
|
||||
if(!iff_create(&iff)){
|
||||
printf("%sUnable to allocate memory for the specified files.\n", TSOSCAN_ERROR);
|
||||
return -1;
|
||||
}
|
||||
if(!iff_read_header(iff, data, FileSize) || !iff_enumerate_chunks(iff, data+64, FileSize-64)){
|
||||
if(!iff_read_header(&iff, data, FileSize) || !iff_enumerate_chunks(&iff, data+64, FileSize-64)){
|
||||
/* Skip non-IFF files silently */
|
||||
free(data);
|
||||
continue;
|
||||
}
|
||||
free(data);
|
||||
|
||||
Stats->FileCount++;
|
||||
if(Stats->AverageChunkCount == -1){
|
||||
Stats->AverageChunkCount = iff->ChunkCount;
|
||||
Stats.FileCount++;
|
||||
if(Stats.AverageChunkCount == -1){
|
||||
Stats.AverageChunkCount = iff.ChunkCount;
|
||||
}else{
|
||||
Stats->AverageChunkCount += iff->ChunkCount;
|
||||
Stats->AverageChunkCount /= 2;
|
||||
Stats.AverageChunkCount += iff.ChunkCount;
|
||||
Stats.AverageChunkCount /= 2;
|
||||
}
|
||||
|
||||
for(ChunkIndex = 0, ChunkData = iff->Chunks; ChunkIndex < iff->ChunkCount; ChunkIndex++, ChunkData++){
|
||||
for(ChunkIndex = 0, ChunkData = iff.Chunks; ChunkIndex < iff.ChunkCount; ChunkIndex++, ChunkData++){
|
||||
unsigned version = stats_get_version(ChunkData->Type, ChunkData->Data);
|
||||
if(!stats_version_increment(Stats, ChunkData->Type, version)){
|
||||
if(!stats_version_increment(&Stats, ChunkData->Type, version)){
|
||||
printf("%sUnable to allocate enough memory.\n", TSOSCAN_ERROR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
iff_delete(iff);
|
||||
iff_delete(&iff);
|
||||
}
|
||||
|
||||
/****
|
||||
|
@ -274,23 +271,23 @@ int main(int argc, char *argv[]){
|
|||
fprintf(OutFile, "<h1>IFF Chunk Statistics (tsostats)</h1>\n");
|
||||
fprintf(OutFile, "<div id=\"attributes\">\n");
|
||||
fprintf(OutFile, "<table>\n");
|
||||
fprintf(OutFile, "<tr><td>Number of IFF files:</td><td>%u</td></tr>\n", Stats->FileCount);
|
||||
fprintf(OutFile, "<tr><td>Average chunk count:</td><td>%.1f</td></tr>\n", Stats->AverageChunkCount);
|
||||
fprintf(OutFile, "<tr><td>Number of IFF files:</td><td>%u</td></tr>\n", Stats.FileCount);
|
||||
fprintf(OutFile, "<tr><td>Average chunk count:</td><td>%.1f</td></tr>\n", Stats.AverageChunkCount);
|
||||
fprintf(OutFile, "</table>\n");
|
||||
fprintf(OutFile, "</div>\n");
|
||||
|
||||
fprintf(OutFile, "<div id=\"toc\"><div><b>Contents</b> – %u chunk types</div>\n", Stats->ChunkTypeCount);
|
||||
fprintf(OutFile, "<div id=\"toc\"><div><b>Contents</b> – %u chunk types</div>\n", Stats.ChunkTypeCount);
|
||||
fprintf(OutFile, "<ul>\n");
|
||||
for(i=0; i<Stats->ChunkTypeCount; i++)
|
||||
fprintf(OutFile, "<li><a href=\"#type%u\">%u %s</a></li>\n", i, i+1, Stats->ChunkTypes[i].Type);
|
||||
for(i=0; i<Stats.ChunkTypeCount; i++)
|
||||
fprintf(OutFile, "<li><a href=\"#type%u\">%u %s</a></li>\n", i, i+1, Stats.ChunkTypes[i].Type);
|
||||
fprintf(OutFile, "</ul>\n");
|
||||
fprintf(OutFile, "</div>\n");
|
||||
fprintf(OutFile, "\n");
|
||||
|
||||
for(i=0; i<Stats->ChunkTypeCount; i++){
|
||||
ChunkStats *chunk = Stats->ChunkTypes+i;
|
||||
for(i=0; i<Stats.ChunkTypeCount; i++){
|
||||
ChunkStats *chunk = Stats.ChunkTypes+i;
|
||||
|
||||
fprintf(OutFile, "<h2 id=\"type%u\">%u %s <a href=\"#type%u\">(Jump)</a></h2>\n", i, i+1, Stats->ChunkTypes[i].Type, i);
|
||||
fprintf(OutFile, "<h2 id=\"type%u\">%u %s <a href=\"#type%u\">(Jump)</a></h2>\n", i, i+1, Stats.ChunkTypes[i].Type, i);
|
||||
fprintf(OutFile, "<div>\n");
|
||||
|
||||
fprintf(OutFile, "<table>\n");
|
||||
|
@ -324,8 +321,8 @@ int main(int argc, char *argv[]){
|
|||
fprintf(OutFile, "</html>");
|
||||
fclose(OutFile);
|
||||
|
||||
printf("Generated statistics based on %u IFF files.\n", Stats->FileCount);
|
||||
printf("Generated statistics based on %u IFF files.\n", Stats.FileCount);
|
||||
cmd_delete(CmdArgs);
|
||||
stats_delete(Stats);
|
||||
stats_delete(&Stats);
|
||||
return 0;
|
||||
}
|
|
@ -59,7 +59,7 @@ typedef struct IFFStats_s
|
|||
CommandLineArgs* cmd_parse_args(int argc, char *argv[]);
|
||||
void cmd_delete(CommandLineArgs *args);
|
||||
|
||||
IFFStats* stats_create();
|
||||
int stats_create(IFFStats *stats);
|
||||
int stats_version_increment(IFFStats *stats, char *type, unsigned version);
|
||||
unsigned stats_get_version(char *type, uint8_t *data);
|
||||
void stats_delete(IFFStats *stats);
|
|
@ -1,8 +1,9 @@
|
|||
LIBS = freetype libjpeg-turbo libmpg123 libpng libpq zlib
|
||||
all: .PHONY ../_deps/$(LIBS)
|
||||
all: .PHONY $(addprefix ../_deps/, $(LIBS))
|
||||
.PHONY: $(LIBS)
|
||||
wget -N http://niotso.org/pub/environment/windows/lib/$<.tar.xz
|
||||
../_deps/%: %.tar.xz
|
||||
$(LIBS):
|
||||
wget -N http://niotso.org/pub/environment/windows/lib/$@.tar.xz
|
||||
../_deps/%: ../_deps/%.tar.xz
|
||||
ifdef CMD
|
||||
del /F /S /Q "$@"
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue