Skip to content

Commit

Permalink
Merge pull request #1049 from dheld/master
Browse files Browse the repository at this point in the history
Remove dead code in root.*, refactor redundant code
  • Loading branch information
WalterBright committed Aug 9, 2012
2 parents cef1bbf + 15d0705 commit 9cce561
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/doc.c
Expand Up @@ -233,7 +233,7 @@ void Module::gendocfile()
// Override with the ddoc macro files from the command line
for (size_t i = 0; i < global.params.ddocfiles->dim; i++)
{
FileName f((*global.params.ddocfiles)[i], 0);
FileName f((*global.params.ddocfiles)[i]);
File file(&f);
file.readv();
// BUG: convert file contents to UTF-8 before use
Expand Down
2 changes: 1 addition & 1 deletion src/libmscoff.c
Expand Up @@ -311,7 +311,7 @@ void LibMSCoff::addObject(const char *module_name, void *buf, size_t buflen)
int fromfile = 0;
if (!buf)
{ assert(module_name[0]);
FileName f((char *)module_name, 0);
FileName f((char *)module_name);
File file(&f);
file.readv();
buf = file.buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/libomf.c
Expand Up @@ -422,7 +422,7 @@ void LibOMF::addObject(const char *module_name, void *buf, size_t buflen)
#endif
if (!buf)
{ assert(module_name);
FileName f((char *)module_name, 0);
FileName f((char *)module_name);
File file(&f);
file.readv();
buf = file.buffer;
Expand Down
6 changes: 3 additions & 3 deletions src/module.c
Expand Up @@ -150,7 +150,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
#endif

if (global.params.objname)
objfilename = new FileName(argobj, 0);
objfilename = new FileName(argobj);
else
objfilename = FileName::forceExt(argobj, global.obj_ext);

Expand Down Expand Up @@ -188,7 +188,7 @@ void Module::setDocfile()
argdoc = FileName::combine(global.params.docdir, argdoc);
}
if (global.params.docname)
docfilename = new FileName(argdoc, 0);
docfilename = new FileName(argdoc);
else
docfilename = FileName::forceExt(argdoc, global.doc_ext);

Expand Down Expand Up @@ -216,7 +216,7 @@ void Module::setHdrfile()
arghdr = FileName::combine(global.params.hdrdir, arghdr);
}
if (global.params.hdrname)
hdrfilename = new FileName(arghdr, 0);
hdrfilename = new FileName(arghdr);
else
hdrfilename = FileName::forceExt(arghdr, global.hdr_ext);

Expand Down
10 changes: 7 additions & 3 deletions src/root/port.c
@@ -1,17 +1,19 @@

// Copyright (c) 1999-2011 by Digital Mars
// Copyright (c) 1999-2012 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com

#include "port.h"

#if __DMC__
#include <math.h>
#include <float.h>
#include <fp.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>

double Port::nan = NAN;
double Port::infinity = INFINITY;
Expand Down Expand Up @@ -127,6 +129,7 @@ char *Port::strupr(char *s)
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <wchar.h>
#include <stdlib.h>
#include <limits> // for std::numeric_limits

Expand Down Expand Up @@ -343,6 +346,7 @@ char *Port::strupr(char *s)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <wchar.h>
#include <float.h>
#include <assert.h>

Expand Down Expand Up @@ -510,7 +514,7 @@ char *Port::strupr(char *s)

#endif

#if __sun&&__SVR4
#if __sun && __SVR4

#define __C99FEATURES__ 1 // Needed on Solaris for NaN and more
#include <math.h>
Expand All @@ -520,6 +524,7 @@ char *Port::strupr(char *s)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <wchar.h>
#include <float.h>
#include <ieeefp.h>

Expand Down Expand Up @@ -648,4 +653,3 @@ char *Port::strupr(char *s)
}

#endif

17 changes: 6 additions & 11 deletions src/root/port.h
@@ -1,5 +1,5 @@

// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2012 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand All @@ -12,26 +12,21 @@

#include "longdouble.h"

#ifndef TYPEDEFS
#define TYPEDEFS

#include <wchar.h>

#if _MSC_VER
typedef __int64 longlong;
typedef unsigned __int64 ulonglong;

#include <float.h> // for _isnan
#include <malloc.h> // for alloca
// According to VC 8.0 docs, long double is the same as double
longdouble strtold(const char *p,char **endp);
#define strtof strtod
#define isnan _isnan

typedef __int64 longlong;
typedef unsigned __int64 ulonglong;
#else
typedef long long longlong;
typedef unsigned long long ulonglong;
#endif

#endif

typedef double d_time;

struct Port
Expand Down
107 changes: 10 additions & 97 deletions src/root/root.c
Expand Up @@ -56,68 +56,6 @@ extern "C" void __cdecl _assert(void *e, void *f, unsigned line)
#endif


/*************************************
* Convert wchar string to ascii string.
*/

char *wchar2ascii(wchar_t *us)
{
return wchar2ascii(us, wcslen(us));
}

char *wchar2ascii(wchar_t *us, unsigned len)
{
unsigned i;
char *p;

p = (char *)mem.malloc(len + 1);
for (i = 0; i <= len; i++)
p[i] = (char) us[i];
return p;
}

int wcharIsAscii(wchar_t *us)
{
return wcharIsAscii(us, wcslen(us));
}

int wcharIsAscii(wchar_t *us, unsigned len)
{
unsigned i;

for (i = 0; i <= len; i++)
{
if (us[i] & ~0xFF) // if high bits set
return 0; // it's not ascii
}
return 1;
}


/***********************************
* Compare length-prefixed strings (bstr).
*/

int bstrcmp(unsigned char *b1, unsigned char *b2)
{
return (*b1 == *b2 && memcmp(b1 + 1, b2 + 1, *b2) == 0) ? 0 : 1;
}

/***************************************
* Convert bstr into a malloc'd string.
*/

char *bstr2str(unsigned char *b)
{
char *s;
unsigned len;

len = *b;
s = (char *) mem.malloc(len + 1);
s[len] = 0;
return (char *)memcpy(s,b + 1,len);
}

/**************************************
* Print error message and exit.
*/
Expand All @@ -136,11 +74,6 @@ void error(const char *format, ...)
exit(EXIT_FAILURE);
}

void error_mem()
{
error("out of memory");
}

/**************************************
* Print warning message.
*/
Expand Down Expand Up @@ -200,10 +133,9 @@ void Object::mark()

/****************************** String ********************************/

String::String(char *str, int ref)
String::String(char *str)
: str(mem.strdup(str))
{
this->str = ref ? str : mem.strdup(str);
this->ref = ref;
}

String::~String()
Expand Down Expand Up @@ -291,8 +223,8 @@ void String::print()

/****************************** FileName ********************************/

FileName::FileName(char *str, int ref)
: String(str,ref)
FileName::FileName(char *str)
: String(str)
{
}

Expand Down Expand Up @@ -326,11 +258,6 @@ char *FileName::combine(const char *path, const char *name)
return f;
}

FileName::FileName(char *path, char *name)
: String(combine(path,name),1)
{
}

// Split a path into an Array of paths
Strings *FileName::splitPath(const char *path)
{
Expand Down Expand Up @@ -678,15 +605,15 @@ FileName *FileName::defaultExt(const char *name, const char *ext)

e = FileName::ext(name);
if (e) // if already has an extension
return new FileName((char *)name, 0);
return new FileName((char *)name);

len = strlen(name);
extlen = strlen(ext);
s = (char *)alloca(len + 1 + extlen + 1);
memcpy(s,name,len);
s[len] = '.';
memcpy(s + len + 1, ext, extlen + 1);
return new FileName(s, 0);
return new FileName(s);
}

/***************************
Expand All @@ -708,7 +635,7 @@ FileName *FileName::forceExt(const char *name, const char *ext)
s = (char *)alloca(len + extlen + 1);
memcpy(s,name,len);
memcpy(s + len, ext, extlen + 1);
return new FileName(s, 0);
return new FileName(s);
}
else
return defaultExt(name, ext); // doesn't have one
Expand Down Expand Up @@ -1008,7 +935,7 @@ File::File(char *n)
buffer = NULL;
len = 0;
touchtime = NULL;
name = new FileName(n, 0);
name = new FileName(n);
}

File::~File()
Expand Down Expand Up @@ -1418,7 +1345,7 @@ void File::remove()

Files *File::match(char *n)
{
return match(new FileName(n, 0));
return match(new FileName(n));
}

Files *File::match(FileName *n)
Expand Down Expand Up @@ -1866,6 +1793,7 @@ char *OutBuffer::toChars()
return (char *)data;
}

// TODO: Remove (only used by disabled GC)
/********************************* Bits ****************************/

Bits::Bits()
Expand Down Expand Up @@ -1958,18 +1886,3 @@ void Bits::sub(Bits *b)
for (u = 0; u < allocdim; u++)
data[u] &= ~b->data[u];
}















0 comments on commit 9cce561

Please sign in to comment.