DIE TABS, DIE!!!!!!!1

pull/58/head
Koncord 8 years ago
parent 9abd4e5a16
commit 64b5638d40

@ -643,7 +643,7 @@ static TCHAR *amx_strval(TCHAR buffer[], long value, int format, int width)
/* swap the string, and we are done */ /* swap the string, and we are done */
reverse(buffer+start,stop-start); reverse(buffer+start,stop-start);
return buffer; return buffer;
} }
#if defined FIXEDPOINT #if defined FIXEDPOINT
#define FIXEDMULT 1000 #define FIXEDMULT 1000

@ -1,4 +1,5 @@
#ifndef AMXCONS_H_INCLUDED #ifndef AMXCONS_H_INCLUDED
#ifndef AMXCONS_H_INCLUDED
#define AMXCONS_H_INCLUDED #define AMXCONS_H_INCLUDED
typedef struct tagFMTINFO { typedef struct tagFMTINFO {

@ -1151,8 +1151,8 @@ int main(int argc, char **argv)
test(1, "a`x", "a``x"); test(1, "a`x", "a``x");
test(1, "*`?", "`*```?"); test(1, "*`?", "`*```?");
test(1, "a*x", "a`*x"); test(1, "a*x", "a`*x");
test(1, "a", "a`80"); test(1, "a<EFBFBD>", "a`80");
test(0, "a", "a`8"); test(0, "a<EFBFBD>", "a`8");
#if defined FPAT_DELIM #if defined FPAT_DELIM
test(0, "", "/"); test(0, "", "/");

@ -127,7 +127,7 @@
* david.tribble@beasys.com * david.tribble@beasys.com
* dtribble@flash.net * dtribble@flash.net
* *
* Copyright ©1997 by David R. Tribble, all rights reserved. * Copyright <EFBFBD>1997 by David R. Tribble, all rights reserved.
*/ */

@ -14,10 +14,11 @@
#define __BINRELOC_C__ #define __BINRELOC_C__
#ifdef ENABLE_BINRELOC #ifdef ENABLE_BINRELOC
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#endif /* ENABLE_BINRELOC */ #endif /* ENABLE_BINRELOC */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
@ -29,14 +30,13 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/** @internal /** @internal
* Find the canonical filename of the executable. Returns the filename * Find the canonical filename of the executable. Returns the filename
* (which must be freed) or NULL on error. If the parameter 'error' is * (which must be freed) or NULL on error. If the parameter 'error' is
* not NULL, the error code will be stored there, if an error occured. * not NULL, the error code will be stored there, if an error occured.
*/ */
static char * static char *
_br_find_exe (BrInitError *error) _br_find_exe(BrInitError *error)
{ {
#ifndef ENABLE_BINRELOC #ifndef ENABLE_BINRELOC
if (error) if (error)
@ -175,14 +175,14 @@ _br_find_exe (BrInitError *error)
* Returns a filename which must be freed, or NULL on error. * Returns a filename which must be freed, or NULL on error.
*/ */
static char * static char *
_br_find_exe_for_symbol (const void *symbol, BrInitError *error) _br_find_exe_for_symbol(const void *symbol, BrInitError *error)
{ {
#ifndef ENABLE_BINRELOC #ifndef ENABLE_BINRELOC
if (error) if (error)
*error = BR_INIT_ERROR_DISABLED; *error = BR_INIT_ERROR_DISABLED;
return (char *) NULL; return (char *) NULL;
#else #else
#define SIZE PATH_MAX + 100 #define SIZE PATH_MAX + 100
FILE *f; FILE *f;
size_t address_string_len; size_t address_string_len;
char *address_string, line[SIZE], *found; char *address_string, line[SIZE], *found;
@ -279,8 +279,8 @@ _br_find_exe_for_symbol (const void *symbol, BrInitError *error)
#ifndef BINRELOC_RUNNING_DOXYGEN #ifndef BINRELOC_RUNNING_DOXYGEN
#undef NULL #undef NULL
#define NULL ((void *) 0) /* typecasted as char* for C++ type safeness */ #define NULL ((void *) 0) /* typecasted as char* for C++ type safeness */
#endif #endif
static char *exe = (char *) NULL; static char *exe = (char *) NULL;
@ -301,9 +301,9 @@ static char *exe = (char *) NULL;
* @returns 1 on success, 0 if BinReloc failed to initialize. * @returns 1 on success, 0 if BinReloc failed to initialize.
*/ */
int int
br_init (BrInitError *error) br_init(BrInitError *error)
{ {
exe = _br_find_exe (error); exe = _br_find_exe(error);
return exe != NULL; return exe != NULL;
} }
@ -323,9 +323,9 @@ br_init (BrInitError *error)
* @returns 1 on success, 0 if a filename cannot be found. * @returns 1 on success, 0 if a filename cannot be found.
*/ */
int int
br_init_lib (BrInitError *error) br_init_lib(BrInitError *error)
{ {
exe = _br_find_exe_for_symbol ((const void *) "", error); exe = _br_find_exe_for_symbol((const void *) "", error);
return exe != NULL; return exe != NULL;
} }
@ -340,16 +340,17 @@ br_init_lib (BrInitError *error)
* NULL will be returned. * NULL will be returned.
*/ */
char * char *
br_find_exe (const char *default_exe) br_find_exe(const char *default_exe)
{ {
if (exe == (char *) NULL) { if (exe == (char *) NULL)
{
/* BinReloc is not initialized. */ /* BinReloc is not initialized. */
if (default_exe != (const char *) NULL) if (default_exe != (const char *) NULL)
return strdup (default_exe); return strdup(default_exe);
else else
return (char *) NULL; return (char *) NULL;
} }
return strdup (exe); return strdup(exe);
} }
@ -368,17 +369,18 @@ br_find_exe (const char *default_exe)
* returned. * returned.
*/ */
char * char *
br_find_exe_dir (const char *default_dir) br_find_exe_dir(const char *default_dir)
{ {
if (exe == NULL) { if (exe == NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_dir != NULL) if (default_dir != NULL)
return strdup (default_dir); return strdup(default_dir);
else else
return NULL; return NULL;
} }
return br_dirname (exe); return br_dirname(exe);
} }
@ -396,21 +398,22 @@ br_find_exe_dir (const char *default_dir)
* will be returned. If default_prefix is NULL, then NULL will be returned. * will be returned. If default_prefix is NULL, then NULL will be returned.
*/ */
char * char *
br_find_prefix (const char *default_prefix) br_find_prefix(const char *default_prefix)
{ {
char *dir1, *dir2; char *dir1, *dir2;
if (exe == (char *) NULL) { if (exe == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_prefix != (const char *) NULL) if (default_prefix != (const char *) NULL)
return strdup (default_prefix); return strdup(default_prefix);
else else
return (char *) NULL; return (char *) NULL;
} }
dir1 = br_dirname (exe); dir1 = br_dirname(exe);
dir2 = br_dirname (dir1); dir2 = br_dirname(dir1);
free (dir1); free(dir1);
return dir2; return dir2;
} }
@ -429,21 +432,22 @@ br_find_prefix (const char *default_prefix)
* be returned. If default_bin_dir is NULL, then NULL will be returned. * be returned. If default_bin_dir is NULL, then NULL will be returned.
*/ */
char * char *
br_find_bin_dir (const char *default_bin_dir) br_find_bin_dir(const char *default_bin_dir)
{ {
char *prefix, *dir; char *prefix, *dir;
prefix = br_find_prefix ((const char *) NULL); prefix = br_find_prefix((const char *) NULL);
if (prefix == (char *) NULL) { if (prefix == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_bin_dir != (const char *) NULL) if (default_bin_dir != (const char *) NULL)
return strdup (default_bin_dir); return strdup(default_bin_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (prefix, "bin"); dir = br_build_path(prefix, "bin");
free (prefix); free(prefix);
return dir; return dir;
} }
@ -462,21 +466,22 @@ br_find_bin_dir (const char *default_bin_dir)
* be returned. If default_bin_dir is NULL, then NULL will be returned. * be returned. If default_bin_dir is NULL, then NULL will be returned.
*/ */
char * char *
br_find_sbin_dir (const char *default_sbin_dir) br_find_sbin_dir(const char *default_sbin_dir)
{ {
char *prefix, *dir; char *prefix, *dir;
prefix = br_find_prefix ((const char *) NULL); prefix = br_find_prefix((const char *) NULL);
if (prefix == (char *) NULL) { if (prefix == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_sbin_dir != (const char *) NULL) if (default_sbin_dir != (const char *) NULL)
return strdup (default_sbin_dir); return strdup(default_sbin_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (prefix, "sbin"); dir = br_build_path(prefix, "sbin");
free (prefix); free(prefix);
return dir; return dir;
} }
@ -496,21 +501,22 @@ br_find_sbin_dir (const char *default_sbin_dir)
* returned. * returned.
*/ */
char * char *
br_find_data_dir (const char *default_data_dir) br_find_data_dir(const char *default_data_dir)
{ {
char *prefix, *dir; char *prefix, *dir;
prefix = br_find_prefix ((const char *) NULL); prefix = br_find_prefix((const char *) NULL);
if (prefix == (char *) NULL) { if (prefix == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_data_dir != (const char *) NULL) if (default_data_dir != (const char *) NULL)
return strdup (default_data_dir); return strdup(default_data_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (prefix, "share"); dir = br_build_path(prefix, "share");
free (prefix); free(prefix);
return dir; return dir;
} }
@ -529,21 +535,22 @@ br_find_data_dir (const char *default_data_dir)
* If default_locale_dir is NULL, then NULL will be returned. * If default_locale_dir is NULL, then NULL will be returned.
*/ */
char * char *
br_find_locale_dir (const char *default_locale_dir) br_find_locale_dir(const char *default_locale_dir)
{ {
char *data_dir, *dir; char *data_dir, *dir;
data_dir = br_find_data_dir ((const char *) NULL); data_dir = br_find_data_dir((const char *) NULL);
if (data_dir == (char *) NULL) { if (data_dir == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_locale_dir != (const char *) NULL) if (default_locale_dir != (const char *) NULL)
return strdup (default_locale_dir); return strdup(default_locale_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (data_dir, "locale"); dir = br_build_path(data_dir, "locale");
free (data_dir); free(data_dir);
return dir; return dir;
} }
@ -562,21 +569,22 @@ br_find_locale_dir (const char *default_locale_dir)
* If default_lib_dir is NULL, then NULL will be returned. * If default_lib_dir is NULL, then NULL will be returned.
*/ */
char * char *
br_find_lib_dir (const char *default_lib_dir) br_find_lib_dir(const char *default_lib_dir)
{ {
char *prefix, *dir; char *prefix, *dir;
prefix = br_find_prefix ((const char *) NULL); prefix = br_find_prefix((const char *) NULL);
if (prefix == (char *) NULL) { if (prefix == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_lib_dir != (const char *) NULL) if (default_lib_dir != (const char *) NULL)
return strdup (default_lib_dir); return strdup(default_lib_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (prefix, "lib"); dir = br_build_path(prefix, "lib");
free (prefix); free(prefix);
return dir; return dir;
} }
@ -595,21 +603,22 @@ br_find_lib_dir (const char *default_lib_dir)
* If default_libexec_dir is NULL, then NULL will be returned. * If default_libexec_dir is NULL, then NULL will be returned.
*/ */
char * char *
br_find_libexec_dir (const char *default_libexec_dir) br_find_libexec_dir(const char *default_libexec_dir)
{ {
char *prefix, *dir; char *prefix, *dir;
prefix = br_find_prefix ((const char *) NULL); prefix = br_find_prefix((const char *) NULL);
if (prefix == (char *) NULL) { if (prefix == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_libexec_dir != (const char *) NULL) if (default_libexec_dir != (const char *) NULL)
return strdup (default_libexec_dir); return strdup(default_libexec_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (prefix, "libexec"); dir = br_build_path(prefix, "libexec");
free (prefix); free(prefix);
return dir; return dir;
} }
@ -628,21 +637,22 @@ br_find_libexec_dir (const char *default_libexec_dir)
* If default_etc_dir is NULL, then NULL will be returned. * If default_etc_dir is NULL, then NULL will be returned.
*/ */
char * char *
br_find_etc_dir (const char *default_etc_dir) br_find_etc_dir(const char *default_etc_dir)
{ {
char *prefix, *dir; char *prefix, *dir;
prefix = br_find_prefix ((const char *) NULL); prefix = br_find_prefix((const char *) NULL);
if (prefix == (char *) NULL) { if (prefix == (char *) NULL)
{
/* BinReloc not initialized. */ /* BinReloc not initialized. */
if (default_etc_dir != (const char *) NULL) if (default_etc_dir != (const char *) NULL)
return strdup (default_etc_dir); return strdup(default_etc_dir);
else else
return (char *) NULL; return (char *) NULL;
} }
dir = br_build_path (prefix, "etc"); dir = br_build_path(prefix, "etc");
free (prefix); free(prefix);
return dir; return dir;
} }
@ -658,7 +668,7 @@ br_find_etc_dir (const char *default_etc_dir)
* @returns A newly-allocated string. This string should be freed when no longer needed. * @returns A newly-allocated string. This string should be freed when no longer needed.
*/ */
char * char *
br_strcat (const char *str1, const char *str2) br_strcat(const char *str1, const char *str2)
{ {
char *result; char *result;
size_t len1, len2; size_t len1, len2;
@ -668,12 +678,12 @@ br_strcat (const char *str1, const char *str2)
if (str2 == NULL) if (str2 == NULL)
str2 = ""; str2 = "";
len1 = strlen (str1); len1 = strlen(str1);
len2 = strlen (str2); len2 = strlen(str2);
result = (char *) malloc (len1 + len2 + 1); result = (char *) malloc(len1 + len2 + 1);
memcpy (result, str1, len1); memcpy(result, str1, len1);
memcpy (result + len1, str2, len2); memcpy(result + len1, str2, len2);
result[len1 + len2] = '\0'; result[len1 + len2] = '\0';
return result; return result;
@ -681,29 +691,30 @@ br_strcat (const char *str1, const char *str2)
char * char *
br_build_path (const char *dir, const char *file) br_build_path(const char *dir, const char *file)
{ {
char *dir2, *result; char *dir2, *result;
size_t len; size_t len;
int must_free = 0; int must_free = 0;
len = strlen (dir); len = strlen(dir);
if (len > 0 && dir[len - 1] != '/') { if (len > 0 && dir[len - 1] != '/')
dir2 = br_strcat (dir, "/"); {
dir2 = br_strcat(dir, "/");
must_free = 1; must_free = 1;
} else } else
dir2 = (char *) dir; dir2 = (char *) dir;
result = br_strcat (dir2, file); result = br_strcat(dir2, file);
if (must_free) if (must_free)
free (dir2); free(dir2);
return result; return result;
} }
/* Emulates glibc's strndup() */ /* Emulates glibc's strndup() */
static char * static char *
br_strndup (const char *str, size_t size) br_strndup(const char *str, size_t size)
{ {
char *result = (char *) NULL; char *result = (char *) NULL;
size_t len; size_t len;
@ -711,14 +722,14 @@ br_strndup (const char *str, size_t size)
if (str == (const char *) NULL) if (str == (const char *) NULL)
return (char *) NULL; return (char *) NULL;
len = strlen (str); len = strlen(str);
if (len == 0) if (len == 0)
return strdup (""); return strdup("");
if (size > len) if (size > len)
size = len; size = len;
result = (char *) malloc (len + 1); result = (char *) malloc(len + 1);
memcpy (result, str, size); memcpy(result, str, size);
result[size] = '\0'; result[size] = '\0';
return result; return result;
} }
@ -737,23 +748,24 @@ br_strndup (const char *str, size_t size)
* @returns A directory name. This string should be freed when no longer needed. * @returns A directory name. This string should be freed when no longer needed.
*/ */
char * char *
br_dirname (const char *path) br_dirname(const char *path)
{ {
char *end, *result; char *end, *result;
if (path == (const char *) NULL) if (path == (const char *) NULL)
return (char *) NULL; return (char *) NULL;
end = strrchr (path, '/'); end = strrchr(path, '/');
if (end == (const char *) NULL) if (end == (const char *) NULL)
return strdup ("."); return strdup(".");
while (end > path && *end == '/') while (end > path && *end == '/')
end--; end--;
result = br_strndup (path, end - path + 1); result = br_strndup(path, end - path + 1);
if (result[0] == 0) { if (result[0] == 0)
free (result); {
return strdup ("/"); free(result);
return strdup("/");
} else } else
return result; return result;
} }

Loading…
Cancel
Save