Commit d1f4e0ff authored by rswindell's avatar rswindell
Browse files

New wrapper module targeted specifically at general/string RTL functions.

Will replace smbwrap.*/wrappers.c/sbbswrap.h at some point.
parent 389451b4
/* genwrap.c */
/* General cross-platform development wrappers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* 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 2 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include <string.h> /* strlen() */
#include "genwrap.h" /* Verify prototypes */
/****************************************************************************/
/* Convert ASCIIZ string to upper case */
/****************************************************************************/
#ifdef __unix__
char* SMBCALL strupr(char* str)
{
char* p=str;
while(*p) {
*p=toupper(*p);
p++;
}
return(str);
}
/****************************************************************************/
/* Convert ASCIIZ string to lower case */
/****************************************************************************/
char* SMBCALL strlwr(char* str)
{
char* p=str;
while(*p) {
*p=tolower(*p);
p++;
}
return(str);
}
/****************************************************************************/
/* Reverse characters of a string (provided by amcleod) */
/****************************************************************************/
char* strrev(char* str)
{
char t, *i=str, *j=str+strlen(str);
while (i<j) {
t=*i; *(i++)=*(--j); *j=t;
}
return str;
}
#endif
/****************************************************************************/
/* Generate a tone at specified frequency for specified milliseconds */
/* Thanks to Casey Martin for this code */
/****************************************************************************/
#ifdef __unix__
void DLLCALL xp_beep(int freq, int dur)
{
static int console_fd=-1;
if(console_fd == -1)
console_fd = open("/dev/console", O_NOCTTY);
if(console_fd != -1) {
ioctl(console_fd, KIOCSOUND, (int) (1193180 / freq));
mswait(dur);
ioctl(console_fd, KIOCSOUND, 0); /* turn off tone */
}
}
#endif
/****************************************************************************/
/* Return random number between 0 and n-1 */
/****************************************************************************/
#ifndef __BORLANDC__
int DLLCALL xp_random(int n)
{
float f;
if(n<2)
return(0);
f=(float)rand()/(float)RAND_MAX;
return((int)(n*f));
}
#endif
/* genwrap.h */
/* General cross-platform development wrappers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* 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 2 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef _GENWRAP_H
#define _GENWRAP_H
#include <stdio.h> /* sprintf */
#include "gen_defs.h" /* ulong */
#ifdef DLLEXPORT
#undef DLLEXPORT
#endif
#ifdef DLLCALL
#undef DLLCALL
#endif
#ifdef _WIN32
#ifdef WRAPPER_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#ifdef __BORLANDC__
#define DLLCALL __stdcall
#else
#define DLLCALL
#endif
#else /* !_WIN32 */
#define DLLEXPORT
#define DLLCALL
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*********************/
/* Compiler-specific */
/*********************/
/* Compiler Description */
#if defined(__BORLANDC__)
#define COMPILER_DESC(str) sprintf(str,"BCC %X.%02X" \
,__BORLANDC__>>8,__BORLANDC__&0xff);
#elif defined(_MSC_VER)
#define COMPILER_DESC(str) sprintf(str,"MSC %u", _MSC_VER);
/***
#elif defined(__GNUC__) && defined(__GLIBC__)
#define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u (GLIBC %u.%u)" \
,__GNUC__,__GNUC_MINOR__,__GLIBC__,__GLIBC_MINOR__);
***/
#elif defined(__GNUC__)
#define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u" \
,__GNUC__,__GNUC_MINOR__);
#else /* Unknown compiler */
#define COMPILER_DESC(str) strcpy(str,"UNKNOWN COMPILER");
#endif
/**********/
/* Macros */
/**********/
/* Target Platform Description */
#if defined(_WIN64)
#define PLATFORM_DESC "Win64"
#elif defined(_WIN32)
#define PLATFORM_DESC "Win32"
#elif defined(__OS2__)
#define PLATFORM_DESC "OS/2"
#elif defined(__MSDOS__)
#define PLATFORM_DESC "DOS"
#elif defined(__linux__)
#define PLATFORM_DESC "Linux"
#elif defined(__FreeBSD__)
#define PLATFORM_DESC "FreeBSD"
#elif defined(BSD)
#define PLATFORM_DESC "BSD"
#elif defined(__unix__)
#define PLATFORM_DESC "Unix"
#else
#warning "Need to describe target platform"
#define PLATFORM_DESC "UNKNOWN"
#endif
/*********************/
/* String Functionss */
/*********************/
#if defined(_MSC_VER) || defined(__MINGW32__)
#define snprintf _snprintf
#endif
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
DLLEXPORT char* DLLCALL ultoa(ulong, char*, int radix);
#endif
#if defined(__unix__)
DLLEXPORT char* DLLCALL strupr(char* str);
DLLEXPORT char* DLLCALL strlwr(char* str);
DLLEXPORT char* DLLCALL strrev(char* str);
#if !defined(stricmp)
#define stricmp(x,y) strcasecmp(x,y)
#define strnicmp(x,y,z) strncasecmp(x,y,z)
#endif
#endif
/****************************/
/* Common Utility Functions */
/****************************/
#if defined(_WIN32)
#define xp_beep(freq,dur) Beep(freq,dur)
#define mswait(x) Sleep(x)
#elif defined(__OS2__)
#define xp_beep(freq,dur) DosBeep(freq,dur)
#define mswait(x) DosSleep(x)
#elif defined(__unix__)
#define mswait(x) usleep(x*1000)
DLLEXPORT void DLLCALL xp_beep(int freq, int dur);
#else /* Unsupported OS */
#warning "Unsupported Target: Need some macros or function prototypes here."
#endif
#ifdef __cplusplus
}
#endif
#endif /* Don't add anything after this line */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment