mirror of
https://github.com/sfall-team/sslc.git
synced 2026-07-27 16:52:49 -07:00
Edits to code style/formatting
* tabs for indentation, spaces for alignment. * remove trailing spaces and unnecessary keyword/declaration. * edit compile.c for VS2010 (for actual binary release in modderspack). * version number should follow sfall versioning.
This commit is contained in:
@@ -7,133 +7,133 @@
|
||||
// Need carefull review
|
||||
|
||||
int strcpy_s(char* dest, size_t destsz, const char* src) {
|
||||
if (!dest || !src || destsz == 0) return EINVAL;
|
||||
size_t len = strlen(src);
|
||||
if (len >= destsz) {
|
||||
dest[0] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
strcpy(dest, src);
|
||||
return 0;
|
||||
if (!dest || !src || destsz == 0) return EINVAL;
|
||||
size_t len = strlen(src);
|
||||
if (len >= destsz) {
|
||||
dest[0] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
strcpy(dest, src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int strcat_s(char *dest, size_t destsz, const char *src) {
|
||||
if (!dest || !src || destsz == 0) return EINVAL;
|
||||
if (!dest || !src || destsz == 0) return EINVAL;
|
||||
|
||||
size_t dest_len = strlen(dest);
|
||||
size_t src_len = strlen(src);
|
||||
size_t dest_len = strlen(dest);
|
||||
size_t src_len = strlen(src);
|
||||
|
||||
if (dest_len + src_len + 1 > destsz) {
|
||||
dest[0] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
if (dest_len + src_len + 1 > destsz) {
|
||||
dest[0] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
strcat(dest, src);
|
||||
return 0;
|
||||
strcat(dest, src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rand_s(unsigned int *randomValue) {
|
||||
if (!randomValue) return EINVAL;
|
||||
*randomValue = (unsigned int)rand();
|
||||
return 0;
|
||||
if (!randomValue) return EINVAL;
|
||||
*randomValue = (unsigned int)rand();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...) {
|
||||
if (!buffer || sizeOfBuffer == 0 || !format) return EINVAL;
|
||||
if (!buffer || sizeOfBuffer == 0 || !format) return EINVAL;
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int written = vsnprintf(buffer, sizeOfBuffer, format, args);
|
||||
va_end(args);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int written = vsnprintf(buffer, sizeOfBuffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (written < 0 || (size_t)written >= sizeOfBuffer) {
|
||||
buffer[0] = '\0'; // mimic Windows behavior
|
||||
return ERANGE;
|
||||
}
|
||||
if (written < 0 || (size_t)written >= sizeOfBuffer) {
|
||||
buffer[0] = '\0'; // mimic Windows behavior
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
intptr_t _findfirst(const char *pattern, struct _finddata_t *data) {
|
||||
_find_handle_t *handle = calloc(1, sizeof(_find_handle_t));
|
||||
if (!handle) return -1;
|
||||
_find_handle_t *handle = calloc(1, sizeof(_find_handle_t));
|
||||
if (!handle) return -1;
|
||||
|
||||
// Split pattern into directory path and wildcard
|
||||
const char *slash = strrchr(pattern, '/');
|
||||
if (slash) {
|
||||
size_t len = (size_t)(slash - pattern + 1);
|
||||
if (len >= sizeof(handle->path)) len = sizeof(handle->path) - 1;
|
||||
strncpy(handle->path, pattern, len);
|
||||
handle->path[len] = '\0';
|
||||
strncpy(handle->pattern, slash + 1, sizeof(handle->pattern) - 1);
|
||||
} else {
|
||||
strncpy(handle->path, "./", sizeof(handle->path) - 1);
|
||||
strncpy(handle->pattern, pattern, sizeof(handle->pattern) - 1);
|
||||
}
|
||||
// Split pattern into directory path and wildcard
|
||||
const char *slash = strrchr(pattern, '/');
|
||||
if (slash) {
|
||||
size_t len = (size_t)(slash - pattern + 1);
|
||||
if (len >= sizeof(handle->path)) len = sizeof(handle->path) - 1;
|
||||
strncpy(handle->path, pattern, len);
|
||||
handle->path[len] = '\0';
|
||||
strncpy(handle->pattern, slash + 1, sizeof(handle->pattern) - 1);
|
||||
} else {
|
||||
strncpy(handle->path, "./", sizeof(handle->path) - 1);
|
||||
strncpy(handle->pattern, pattern, sizeof(handle->pattern) - 1);
|
||||
}
|
||||
|
||||
handle->dir = opendir(handle->path);
|
||||
if (!handle->dir) {
|
||||
free(handle);
|
||||
return -1;
|
||||
}
|
||||
handle->dir = opendir(handle->path);
|
||||
if (!handle->dir) {
|
||||
free(handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(handle->dir)) != NULL) {
|
||||
if (fnmatch(handle->pattern, entry->d_name, 0) == 0) {
|
||||
struct stat st;
|
||||
char fullpath[PATH_MAX];
|
||||
snprintf(fullpath, sizeof(fullpath), "%s%s", handle->path, entry->d_name);
|
||||
if (stat(fullpath, &st) == 0) {
|
||||
strncpy(data->name, entry->d_name, sizeof(data->name) - 1);
|
||||
data->name[sizeof(data->name) - 1] = '\0';
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(handle->dir)) != NULL) {
|
||||
if (fnmatch(handle->pattern, entry->d_name, 0) == 0) {
|
||||
struct stat st;
|
||||
char fullpath[PATH_MAX];
|
||||
snprintf(fullpath, sizeof(fullpath), "%s%s", handle->path, entry->d_name);
|
||||
if (stat(fullpath, &st) == 0) {
|
||||
strncpy(data->name, entry->d_name, sizeof(data->name) - 1);
|
||||
data->name[sizeof(data->name) - 1] = '\0';
|
||||
|
||||
data->time_write = st.st_mtime;
|
||||
data->size = st.st_size;
|
||||
data->attrib = S_ISDIR(st.st_mode) ? _A_SUBDIR : _A_NORMAL;
|
||||
return (intptr_t)handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
data->time_write = st.st_mtime;
|
||||
data->size = st.st_size;
|
||||
data->attrib = S_ISDIR(st.st_mode) ? _A_SUBDIR : _A_NORMAL;
|
||||
return (intptr_t)handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(handle->dir);
|
||||
free(handle);
|
||||
return -1;
|
||||
closedir(handle->dir);
|
||||
free(handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _findnext(intptr_t h, struct _finddata_t *data) {
|
||||
_find_handle_t *handle = (_find_handle_t *)h;
|
||||
struct dirent *entry;
|
||||
_find_handle_t *handle = (_find_handle_t *)h;
|
||||
struct dirent *entry;
|
||||
|
||||
while ((entry = readdir(handle->dir)) != NULL) {
|
||||
if (fnmatch(handle->pattern, entry->d_name, 0) == 0) {
|
||||
struct stat st;
|
||||
char fullpath[PATH_MAX];
|
||||
snprintf(fullpath, sizeof(fullpath), "%s%s", handle->path, entry->d_name);
|
||||
if (stat(fullpath, &st) == 0) {
|
||||
strncpy(data->name, entry->d_name, sizeof(data->name) - 1);
|
||||
data->name[sizeof(data->name) - 1] = '\0';
|
||||
while ((entry = readdir(handle->dir)) != NULL) {
|
||||
if (fnmatch(handle->pattern, entry->d_name, 0) == 0) {
|
||||
struct stat st;
|
||||
char fullpath[PATH_MAX];
|
||||
snprintf(fullpath, sizeof(fullpath), "%s%s", handle->path, entry->d_name);
|
||||
if (stat(fullpath, &st) == 0) {
|
||||
strncpy(data->name, entry->d_name, sizeof(data->name) - 1);
|
||||
data->name[sizeof(data->name) - 1] = '\0';
|
||||
|
||||
data->time_write = st.st_mtime;
|
||||
data->size = st.st_size;
|
||||
data->attrib = S_ISDIR(st.st_mode) ? _A_SUBDIR : _A_NORMAL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
data->time_write = st.st_mtime;
|
||||
data->size = st.st_size;
|
||||
data->attrib = S_ISDIR(st.st_mode) ? _A_SUBDIR : _A_NORMAL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _findclose(intptr_t h) {
|
||||
_find_handle_t *handle = (_find_handle_t *)h;
|
||||
if (handle) {
|
||||
if (handle->dir) closedir(handle->dir);
|
||||
free(handle);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
_find_handle_t *handle = (_find_handle_t *)h;
|
||||
if (handle) {
|
||||
if (handle->dir) closedir(handle->dir);
|
||||
free(handle);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef _WIN32
|
||||
|
||||
|
||||
#ifndef _COMPAT_H_DEFINED
|
||||
#define _COMPAT_H_DEFINED
|
||||
|
||||
#define _COMPAT_H_DEFINED
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@@ -26,12 +26,12 @@
|
||||
#define _A_NORMAL 0x00
|
||||
#define _A_SUBDIR 0x10
|
||||
|
||||
#define _MSC_VER
|
||||
#define _MSC_VER
|
||||
|
||||
|
||||
int sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
|
||||
int rand_s(unsigned int *randomValue);
|
||||
|
||||
|
||||
int strcpy_s(char* dest, size_t destsz, const char* src);
|
||||
int strcat_s(char *dest, size_t destsz, const char *src);
|
||||
|
||||
@@ -51,16 +51,16 @@ typedef u_int32_t _fsize_t;
|
||||
|
||||
|
||||
struct _finddata_t {
|
||||
unsigned attrib;
|
||||
time_t time_write;
|
||||
size_t size;
|
||||
char name[PATH_MAX];
|
||||
unsigned attrib;
|
||||
time_t time_write;
|
||||
size_t size;
|
||||
char name[PATH_MAX];
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
DIR *dir;
|
||||
char pattern[PATH_MAX];
|
||||
char path[PATH_MAX];
|
||||
DIR *dir;
|
||||
char pattern[PATH_MAX];
|
||||
char path[PATH_MAX];
|
||||
} _find_handle_t;
|
||||
|
||||
|
||||
|
||||
@@ -65,9 +65,12 @@ int main(int argc, char **argv)
|
||||
char name[260], *c, *file;
|
||||
struct FINDDATA buf;
|
||||
FINDHANDLE handle;
|
||||
int nologo=0;
|
||||
int preprocess=0;
|
||||
int onlypreprocess=0;
|
||||
int nologo = 0;
|
||||
int preprocess = 0;
|
||||
int onlypreprocess = 0;
|
||||
#ifndef WIN2K
|
||||
char tmp_file_name[260] = {0};
|
||||
#endif
|
||||
|
||||
char* includeDir = NULL, *defMacro = NULL;
|
||||
|
||||
@@ -98,7 +101,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
while((argv[1] != NULL) && (argv[1][0] == '-')) {
|
||||
while ((argv[1] != NULL) && (argv[1][0] == '-')) {
|
||||
switch(argv[1][1]) {
|
||||
case 'w':
|
||||
case '-':
|
||||
@@ -158,19 +161,19 @@ int main(int argc, char **argv)
|
||||
argc--;
|
||||
}
|
||||
// disabled - Fakels
|
||||
/*if(backwardcompat&&(optimize||preprocess)) {
|
||||
/*if (backwardcompat&&(optimize||preprocess)) {
|
||||
parseOutput("Invalid option combination; cannot run preprocess or optimization passes in backward compatibility mode\n");
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
if(!nologo) PrintLogo();
|
||||
if (!nologo) PrintLogo();
|
||||
|
||||
compilerErrorTotal = 0;
|
||||
#ifndef WIN2K
|
||||
if (defMacro) parseOutput("Define macro: %s\n", defMacro);
|
||||
if (includeDir) parseOutput("Set include directory: %s\n", includeDir);
|
||||
#endif
|
||||
while(argv[1]) {
|
||||
while (argv[1]) {
|
||||
file = argv[1];
|
||||
argv++;
|
||||
argc--;
|
||||
@@ -186,9 +189,9 @@ int main(int argc, char **argv)
|
||||
|
||||
parseOutput("Compiling %s\n", buf.name);
|
||||
|
||||
if(argc>=2&&!strcmp(argv[1], "-o")) {
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
if (argc >= 2 && !strcmp(argv[1], "-o")) {
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
strcpy_s(name, 260, argv[0]);
|
||||
} else {
|
||||
strcpy_s(name, 260, buf.name);
|
||||
@@ -198,7 +201,7 @@ int main(int argc, char **argv)
|
||||
*c = 0;
|
||||
}
|
||||
|
||||
if(onlypreprocess) {
|
||||
if (onlypreprocess) {
|
||||
strcat_s(name, 260, ".preprocessed.ssl");
|
||||
|
||||
if (strcmp(name, buf.name) == 0) {
|
||||
@@ -219,37 +222,36 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
#ifndef WIN2K
|
||||
char tmp_file_name[260] = {0};
|
||||
if(preprocess) {
|
||||
if (preprocess) {
|
||||
FILE *newfile;
|
||||
unsigned int letters;
|
||||
|
||||
rand_s(&letters);
|
||||
if(onlypreprocess) {
|
||||
if (onlypreprocess) {
|
||||
strcpy_s(tmp_file_name, 260, name);
|
||||
newfile=fopen(tmp_file_name, "w+");
|
||||
newfile = fopen(tmp_file_name, "w+");
|
||||
} else {
|
||||
sprintf(tmp_file_name, "%d_%8x.tmp", GetCurrentProcessId(), letters);
|
||||
//#if _DEBUG
|
||||
// newfile=fopen(tmp_file_name, "w+");
|
||||
// newfile = fopen(tmp_file_name, "w+");
|
||||
//#else
|
||||
#ifdef WIN32
|
||||
newfile=fopen(tmp_file_name, "w+DT");
|
||||
newfile = fopen(tmp_file_name, "w+DT");
|
||||
#else
|
||||
newfile=fopen(tmp_file_name, "w+");
|
||||
newfile = fopen(tmp_file_name, "w+");
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
if(mcpp_lib_main(foo.file, newfile, buf.name, buf.name, defMacro, includeDir)) {
|
||||
if (mcpp_lib_main(foo.file, newfile, buf.name, buf.name, defMacro, includeDir)) {
|
||||
parseOutput("*** An error occured during preprocessing of %s ***\n", buf.name);
|
||||
return 1;
|
||||
}
|
||||
fclose(foo.file);
|
||||
rewind(newfile);
|
||||
foo.file=newfile;
|
||||
foo.file = newfile;
|
||||
}
|
||||
#endif
|
||||
if(!onlypreprocess) {
|
||||
if (!onlypreprocess) {
|
||||
parse(&foo, name);
|
||||
freeCurrentProgram();
|
||||
}
|
||||
@@ -280,7 +282,7 @@ int main(int argc, char **argv)
|
||||
|
||||
#ifdef BUILDING_DLL
|
||||
|
||||
static int inited=0;
|
||||
static int inited = 0;
|
||||
|
||||
int _stdcall parse_main(const char *filePath, const char* origPath, const char* dir/*, const char* def, const char* include_dir, int backMode*/) {
|
||||
InputStream foo;
|
||||
@@ -289,7 +291,7 @@ int _stdcall parse_main(const char *filePath, const char* origPath, const char*
|
||||
FILE *newfile;
|
||||
unsigned int letters;
|
||||
|
||||
if(inited) {
|
||||
if (inited) {
|
||||
freeCurrentProgram();
|
||||
FreeFileNames();
|
||||
inited=0;
|
||||
@@ -300,13 +302,13 @@ int _stdcall parse_main(const char *filePath, const char* origPath, const char*
|
||||
lexClear();
|
||||
}
|
||||
*/
|
||||
foo.name=AddFileName(origPath);
|
||||
foo.name = AddFileName(origPath);
|
||||
foo.file = fopen(filePath, "r");
|
||||
|
||||
rand_s(&letters);
|
||||
sprintf(tmpbuf, "%d_%8x.tmp", GetCurrentProcessId(), letters);
|
||||
newfile=fopen(tmpbuf, "w+DT");
|
||||
//newfile=fopen(tmpbuf, "w+");
|
||||
newfile = fopen(tmpbuf, "w+DT");
|
||||
//newfile = fopen(tmpbuf, "w+");
|
||||
parseroutput = fopen("errors.txt", "w");
|
||||
//GetCurrentDirectoryA(1024, cwd);
|
||||
//chdir(dir);
|
||||
@@ -325,11 +327,11 @@ int _stdcall parse_main(const char *filePath, const char* origPath, const char*
|
||||
fclose(foo.file);
|
||||
//fflush(newfile);
|
||||
rewind(newfile);
|
||||
foo.file=newfile;
|
||||
foo.file = newfile;
|
||||
parse(&foo, NULL);
|
||||
fclose(foo.file);
|
||||
|
||||
inited=1;
|
||||
inited = 1;
|
||||
if (parseroutput)
|
||||
fclose(parseroutput);
|
||||
|
||||
|
||||
+1
-1
@@ -348,7 +348,7 @@ There are several changes in this version of sslc which may result in problems f
|
||||
|
||||
### Changelog
|
||||
|
||||
**sfall 4.4.5:**
|
||||
**sfall 4.4.7:**
|
||||
- added Linux & WebAssembly builds
|
||||
|
||||
**sfall 4.4.4:**
|
||||
|
||||
@@ -871,7 +871,7 @@ static int writeStatement(NodeList *n, int i, FILE *f) {
|
||||
return i+1;
|
||||
}
|
||||
|
||||
extern int writeBlock(NodeList *n, int i, FILE *f) {
|
||||
int writeBlock(NodeList *n, int i, FILE *f) {
|
||||
if (n->nodes[i].token != T_BEGIN)
|
||||
parseError("begin expected");
|
||||
|
||||
|
||||
+2
-2
@@ -52,10 +52,10 @@
|
||||
#define S_ISREG( mode) (mode & S_IFREG)
|
||||
#define S_ISDIR( mode) (mode & S_IFDIR)
|
||||
#endif
|
||||
#if ! defined (S_IFREG)
|
||||
#if ! defined( S_IFREG)
|
||||
#define S_IFREG _S_IFREG
|
||||
#endif
|
||||
#if ! defined (S_IFDIR)
|
||||
#if ! defined( S_IFDIR)
|
||||
#define S_IFDIR _S_IFDIR
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "compat.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define Protect(a) if (_stricmp(c, a) == 0) return 1;
|
||||
|
||||
#define F_OP(token,op) case token: out->floatData = fd1 op fd2; break;
|
||||
|
||||
@@ -63,7 +63,6 @@ static void freeVariableList(VariableList *v);
|
||||
static void freeVariable(Variable *v);
|
||||
static void parseWhile(Procedure *p, NodeList *n);
|
||||
static int variable(VariableList *v, char **names, int type, char allowArrays, int allowMulti);
|
||||
extern int writeBlock(NodeList *n, int i, FILE *f);
|
||||
|
||||
extern FILE* parseroutput;
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
#define VERSION_BUILD 4
|
||||
#define VERSION_REV 0
|
||||
|
||||
#define VERSION_STRING "4.4.5"
|
||||
#define VERSION_STRING "4.4.7"
|
||||
|
||||
#ifdef BUILDING_DLL
|
||||
#define FILE_STRING "parser.dll"
|
||||
|
||||
Reference in New Issue
Block a user