mirror of https://github.com/krustur/IconSnap.git
refactored system code into seperate c-file, basic support to run from wb added
This commit is contained in:
parent
4d35d99004
commit
2b76e490f1
|
@ -25,7 +25,8 @@
|
|||
"dirent.h": "c",
|
||||
"unistd.h": "c",
|
||||
"intuition.h": "c",
|
||||
"signal.h": "c"
|
||||
"signal.h": "c",
|
||||
"exec_sysbase_pragmas.h": "c"
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
2
b.bat
2
b.bat
|
@ -1,4 +1,4 @@
|
|||
@REM echo off
|
||||
@REM -v for verbose
|
||||
vc src/main.c -v -stack-check -size -lamiga -lposix -IE:\Amiga\KrustWB3\Output\Dev\vbcc_posix\targets\m68k-amigaos\include -LE:\Amiga\KrustWB3\Output\Dev\vbcc_posix\targets\m68k-amigaos\lib -DBUILD_PLATFORM_WIN -o IconSnap
|
||||
vc src/main.c src/sys.c -v -stack-check -size -lamiga -lposix -IE:\Amiga\KrustWB3\Output\Dev\vbcc_posix\targets\m68k-amigaos\include -LE:\Amiga\KrustWB3\Output\Dev\vbcc_posix\targets\m68k-amigaos\lib -DBUILD_PLATFORM_WIN -o IconSnap
|
||||
copy IconSnap r
|
105
src/main.c
105
src/main.c
|
@ -17,35 +17,18 @@
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "sys.h"
|
||||
|
||||
// TODO: Scripted tests!
|
||||
|
||||
// C helpers
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
|
||||
// VBCC
|
||||
extern size_t __stack_usage;
|
||||
|
||||
// Version tag
|
||||
#define VERSTAG "\0$VER: IconSnap 0.3 (30.11.2018)"
|
||||
unsigned char versiontag[] = VERSTAG;
|
||||
|
||||
// Build Platform
|
||||
#ifdef BUILD_PLATFORM_AMIGA
|
||||
const char *BuildPlatform = "Amiga";
|
||||
#elif BUILD_PLATFORM_WIN
|
||||
const char *BuildPlatform = "Win";
|
||||
#else
|
||||
const char *BuildPlatform = "Unknown";
|
||||
#endif
|
||||
|
||||
// Libraries
|
||||
unsigned long DosVersion = 37L;
|
||||
struct Library *DosBase = NULL;
|
||||
unsigned long IconVersion = 37L;
|
||||
struct Library *IconBase = NULL;
|
||||
short iconLibraryV44Enabled = FALSE;
|
||||
|
||||
// Arguments
|
||||
unsigned char FILE_OPTION_POS = 0;
|
||||
unsigned char DIR_OPTION_POS = 1;
|
||||
|
@ -74,11 +57,6 @@ struct RDArgs *rdargs = NULL;
|
|||
// clean exit handling
|
||||
void CleanExit();
|
||||
|
||||
// Logging
|
||||
short verbose = FALSE;
|
||||
void Information(const char *fmt, ...);
|
||||
void Verbose(const char *fmt, ...);
|
||||
|
||||
// String/Path handling
|
||||
size_t maxPathTreshold = PATH_MAX - 2;
|
||||
short StringEndsWith(const char *str, const char *suffix);
|
||||
|
@ -105,34 +83,24 @@ int main(int argc, char **argv)
|
|||
{
|
||||
atexit(CleanExit);
|
||||
|
||||
short sysInitResult = SysInit(argc, argv);
|
||||
if (sysInitResult != RETURN_OK)
|
||||
{
|
||||
exit(sysInitResult);
|
||||
}
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
//Opened from WB
|
||||
Information("Started from Workbench\n");
|
||||
exit(RETURN_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("fignal\n");
|
||||
// signal(SIGINT, intHandler);
|
||||
Verbose("Started from CLI\n");
|
||||
}
|
||||
// Open libraries
|
||||
DosBase = OpenLibrary("dos.library", DosVersion);
|
||||
if (!DosBase)
|
||||
{
|
||||
Information("Failed to open dos.library %li\n", DosVersion);
|
||||
return RETURN_ERROR;
|
||||
}
|
||||
// Verbose("DosBase: %p\n", (void *)DosBase);
|
||||
|
||||
IconBase = OpenLibrary("icon.library", IconVersion);
|
||||
if (!IconBase)
|
||||
{
|
||||
Information("Failed to open icon.library %li\n", IconVersion);
|
||||
return RETURN_ERROR;
|
||||
}
|
||||
// Verbose("IconBase: %p\n", (void *)IconBase);
|
||||
|
||||
// check arguments
|
||||
|
||||
rdargs = ReadArgs(argumentString, argArray, NULL);
|
||||
|
||||
if (!rdargs)
|
||||
|
@ -141,21 +109,10 @@ int main(int argc, char **argv)
|
|||
return RETURN_ERROR;
|
||||
}
|
||||
|
||||
verbose = argArray[VERBOSE_OPTION_POS] == DOSTRUE;
|
||||
if (verbose)
|
||||
short verbose2 = argArray[VERBOSE_OPTION_POS] == DOSTRUE;
|
||||
if (verbose2)
|
||||
{
|
||||
Verbose(" VERBOSE logging active\n");
|
||||
}
|
||||
Verbose("Build platform: %s\n", BuildPlatform);
|
||||
Verbose("dos.library version %li\n", DosBase->lib_Version);
|
||||
Verbose("dos.library opencnt %li\n", DosBase->lib_OpenCnt);
|
||||
Verbose("icon.library version %li\n", IconBase->lib_Version);
|
||||
Verbose("icon.library opencnt %li\n", IconBase->lib_OpenCnt);
|
||||
|
||||
if (IconBase->lib_Version >= 45)
|
||||
{
|
||||
Verbose("Icon library V44 features enabled\n");
|
||||
iconLibraryV44Enabled = TRUE;
|
||||
SysSetVerboseEnabled(TRUE);
|
||||
}
|
||||
|
||||
unsigned char *fileOption = (unsigned char *)argArray[FILE_OPTION_POS];
|
||||
|
@ -250,8 +207,6 @@ int main(int argc, char **argv)
|
|||
// return RETURN_ERROR;
|
||||
// }
|
||||
|
||||
Verbose("Stack used: %lu\n", (unsigned long)__stack_usage);
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -278,36 +233,7 @@ void CleanExit()
|
|||
FreeArgs(rdargs);
|
||||
rdargs = NULL;
|
||||
}
|
||||
if (DosBase != NULL)
|
||||
{
|
||||
CloseLibrary(DosBase);
|
||||
DosBase = NULL;
|
||||
}
|
||||
if (IconBase != NULL)
|
||||
{
|
||||
CloseLibrary(IconBase);
|
||||
IconBase = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Logging
|
||||
void Verbose(const char *fmt, ...)
|
||||
{
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stdout, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Information(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stdout, fmt, args);
|
||||
va_end(args);
|
||||
SysCleanup();
|
||||
}
|
||||
|
||||
// String/Path handling
|
||||
|
@ -409,7 +335,6 @@ unsigned int AlignDir(unsigned char *dirName)
|
|||
return fixCount;
|
||||
}
|
||||
|
||||
|
||||
unsigned int AlignIcon(unsigned char *diskObjectName)
|
||||
{
|
||||
unsigned long diskObjectNameLen = strlen(diskObjectName);
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
#include <exec/types.h>
|
||||
// #include <dos/dos.h>
|
||||
#include <libraries/dos.h>
|
||||
// #include <workbench/workbench.h>
|
||||
// #include <workbench/startup.h>
|
||||
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
// #include <proto/icon.h>
|
||||
// #include <workbench/icon.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// Build Platform
|
||||
#ifdef BUILD_PLATFORM_AMIGA
|
||||
const char *BuildPlatform = "Amiga";
|
||||
#elif BUILD_PLATFORM_WIN
|
||||
const char *BuildPlatform = "Win";
|
||||
#else
|
||||
const char *BuildPlatform = "Unknown";
|
||||
#endif
|
||||
|
||||
// VBCC
|
||||
extern size_t __stack_usage;
|
||||
|
||||
// Library
|
||||
unsigned long DosReqVersion = 37L;
|
||||
struct Library *DosBase = NULL;
|
||||
unsigned long IconReqVersion = 37L;
|
||||
struct Library *IconBase = NULL;
|
||||
short iconLibraryV44Enabled = FALSE;
|
||||
|
||||
// Logging
|
||||
#define LOG_MAX (256)
|
||||
unsigned char *LogBuffer = NULL;
|
||||
short verbose = FALSE;
|
||||
BPTR wbcon = (BPTR)NULL;
|
||||
// FILE *outputFile = NULL;
|
||||
void Information(const char *fmt, ...);
|
||||
void Verbose(const char *fmt, ...);
|
||||
|
||||
short SysInit(int argc, char **argv)
|
||||
{
|
||||
// Open libraries
|
||||
DosBase = OpenLibrary(DOSNAME, DosReqVersion);
|
||||
if (!DosBase)
|
||||
{
|
||||
// Information("Failed to open dos.library %li\n", DosReqVersion);
|
||||
return RETURN_ERROR;
|
||||
}
|
||||
// Verbose("DosBase: %p\n", (void *)DosBase);
|
||||
|
||||
IconBase = OpenLibrary("icon.library", IconReqVersion);
|
||||
if (!IconBase)
|
||||
{
|
||||
// Information("Failed to open icon.library %li\n", IconReqVersion);
|
||||
return RETURN_ERROR;
|
||||
}
|
||||
// Verbose("IconBase: %p\n", (void *)IconBase);
|
||||
if (IconBase->lib_Version >= 45)
|
||||
{
|
||||
iconLibraryV44Enabled = TRUE;
|
||||
}
|
||||
|
||||
// Initialize logging
|
||||
LogBuffer = AllocVec(LOG_MAX, MEMF_ANY);
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
//Opened from WB
|
||||
wbcon = Open("CON:20/20/500/100/IconSnap", MODE_NEWFILE);
|
||||
SelectOutput(wbcon);
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void SysCleanup(void)
|
||||
{
|
||||
Verbose("Stack used: %lu\n", (unsigned long)__stack_usage);
|
||||
|
||||
if (LogBuffer != NULL)
|
||||
{
|
||||
FreeVec(LogBuffer);
|
||||
}
|
||||
if (wbcon != (BPTR)NULL)
|
||||
{
|
||||
Delay(100);
|
||||
Close(wbcon);
|
||||
}
|
||||
if (DosBase != NULL)
|
||||
{
|
||||
CloseLibrary(DosBase);
|
||||
DosBase = NULL;
|
||||
}
|
||||
if (IconBase != NULL)
|
||||
{
|
||||
CloseLibrary(IconBase);
|
||||
IconBase = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void SysSetVerboseEnabled(short enabled)
|
||||
{
|
||||
verbose = enabled;
|
||||
Verbose("Verbose logging active\n");
|
||||
Verbose("Build platform: %s\n", BuildPlatform);
|
||||
Verbose("dos.library version %li\n", DosBase->lib_Version);
|
||||
Verbose("dos.library opencnt %li\n", DosBase->lib_OpenCnt);
|
||||
Verbose("icon.library version %li\n", IconBase->lib_Version);
|
||||
Verbose("icon.library opencnt %li\n", IconBase->lib_OpenCnt);
|
||||
if (iconLibraryV44Enabled)
|
||||
{
|
||||
Verbose("Icon library V44 features enabled\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Logging
|
||||
void Verbose(const char *fmt, ...)
|
||||
{
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
// va_start(args, fmt);
|
||||
Information(fmt, args);
|
||||
// va_end(args);
|
||||
}
|
||||
|
||||
void Information(const char *fmt, ...)
|
||||
{
|
||||
if (LogBuffer == NULL)
|
||||
{
|
||||
Write(Output(), "Log error\n", 10);
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(LogBuffer, LOG_MAX-1, fmt, args);
|
||||
Write(Output(), LogBuffer, strlen(LogBuffer));
|
||||
va_end(args);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef SYS_H
|
||||
#define SYS_H
|
||||
|
||||
extern short iconLibraryV44Enabled;
|
||||
|
||||
short SysInit(int argc, char **argv);
|
||||
void SysCleanup(void);
|
||||
void SysSetVerboseEnabled(short enabled);
|
||||
|
||||
// Logging
|
||||
void Information(const char *fmt, ...);
|
||||
void Verbose(const char *fmt, ...);
|
||||
|
||||
#endif /* SYS_H */
|
Loading…
Reference in New Issue