Skip to content

Commit

Permalink
remove rarely or unused global vars, build strings at compile time
Browse files Browse the repository at this point in the history
Microsoft is totally unused, purpose unknown, git blame doesn't go back far
enough

swap feature is MSDOS only, no need to collect it or set it

UseWinpath is often set, but never used except on a cygwin build, so
disable it on non-cygwin

_sv_op is unused in Bind_rules_to_targets, #if 0ed, reason unknown, disable
all other uses of _sv_op

avs var is unused on Win32, disable it on Win32

string "4.13" has 2 uses, Version() and Create_macro_vars, CPP constant
fold the version string together, the asm op to load string 4.13 onto C
stack and 2 bytes "%s" in fmt string is longer than the 4 bytes to inline
the version, also SSCID is used exactly once, CPP inline it, don't waste
image space on RW global var sccid, BUILDINFO is also used exactly once
in dmake, CPP inline it too, rest of the strings also are never used more
than once, so CPP cat them together, less machine code, less terminiating
null bytes in the string literals
  • Loading branch information
bulk88 authored and mohawk2 committed Mar 9, 2015
1 parent b12f2d8 commit 3c3ac2b
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dag.c
Expand Up @@ -674,7 +674,7 @@ char *rp;
case '-' : flag |= A_IGNORE; break;
case '+' : flag |= A_SHELL; break;
case '%' :
#if defined(MSDOS)
#if defined(MSDOS) && defined(REAL_MSDOS)
/* Ignore % in the non-MSDOS case. */
flag |= A_SWAP;
#endif
Expand Down
22 changes: 12 additions & 10 deletions dmake.c
Expand Up @@ -108,7 +108,7 @@ dbug/dbug/dbug.c, eg "-#d:F:L:t"
#endif
#define ARG(a,b) a b

static char *sccid = "Copyright (c) 1990,...,1997 by WTI Corp.";
#define SCCID "Copyright (c) 1990,...,1997 by WTI Corp."
static char _warn = TRUE; /* warnings on by default */

static void _do_VPATH();
Expand Down Expand Up @@ -175,9 +175,11 @@ char **argv;
Trace = FALSE;
Touch = FALSE;
Check = FALSE;
Microsoft = FALSE;
/* Microsoft = FALSE; */
Makemkf = FALSE;
#if defined(__CYGWIN__)
UseWinpath= FALSE;
#endif
No_exec = FALSE;
m_export = FALSE;
cmdmacs = NIL(char);
Expand Down Expand Up @@ -943,24 +945,24 @@ Version()
extern char **Rule_tab;
char **p;

printf("%s - Version %s (%s)\n", Pname, VERSION, BUILDINFO);
printf("%s\n\n", sccid);
printf("%s - Version " VERSION " (" BUILDINFO ")\n"
SCCID "\n\n"
"Default Configuration:\n"
, Pname);

puts("Default Configuration:");
for (p=Rule_tab; *p != NIL(char); p++)
printf("\t%s\n", *p);

printf("\n");

puts("\n"
#if defined(HAVE_SPAWN_H) || defined(__CYGWIN__)
/* Only systems that have spawn ar concerned whether spawn or fork/exec
* are used. */
#if ENABLE_SPAWN
printf("Subprocesses are executed using: spawn.\n\n");
"Subprocesses are executed using: spawn.\n\n"
#else
printf("Subprocesses are executed using: fork/exec.\n\n");
"Subprocesses are executed using: fork/exec.\n\n"
#endif
#endif

printf("Please read the NEWS file for the latest release notes.\n");
"Please read the NEWS file for the latest release notes.");
}
4 changes: 4 additions & 0 deletions function.c
Expand Up @@ -156,6 +156,7 @@ char *buf;
res = exec_normpath(eargs);
}
else if( mod_count == 1 ) {
#if defined(__CYGWIN__)
char *para = Expand(mod1);
int tmpUseWinpath = UseWinpath;

Expand All @@ -164,9 +165,12 @@ char *buf;
} else {
UseWinpath = TRUE;
}
#endif
res = exec_normpath(eargs);
#if defined(__CYGWIN__)
UseWinpath = tmpUseWinpath;
FREE(para);
#endif
}
else
Fatal( "One or no comma-separated arguments expected in [%s].\n", buf );
Expand Down
4 changes: 2 additions & 2 deletions getinp.c
Expand Up @@ -307,12 +307,12 @@ int keep;
cmnd = Expand(c+2);
cmnd[strlen(cmnd)-1] = '\0'; /* strip last newline */
Current_target = Root;
#if defined(MSDOS)
#if defined(MSDOS) && defined(REAL_MSDOS)
Swap_on_exec = TRUE;
#endif
Wait_for_completion = TRUE;
Do_cmnd(&cmnd, FALSE, TRUE, Current_target, A_DEFAULT, TRUE);
#if defined(MSDOS)
#if defined(MSDOS) && defined(REAL_MSDOS)
Swap_on_exec = FALSE;
#endif
Wait_for_completion = FALSE;
Expand Down
8 changes: 7 additions & 1 deletion make.c
Expand Up @@ -317,7 +317,9 @@ CELLPTR setdirroot;
/* Set the UseWinpath variable to reflect the (global/local) .WINPATH
* attribute. The variable is used by DO_WINPATH() and in some other
* places. */
#if defined(__CYGWIN__)
UseWinpath = (((cp->ce_attr|Glob_attr)&A_WINPATH) != 0);
#endif

/* m_at needs to be defined before going to a "stop_making_it" where
* a _drop_mac( m_at ) would try to free it. */
Expand Down Expand Up @@ -479,7 +481,9 @@ CELLPTR setdirroot;
if (m_at->ht_value == NIL(char)) {
/* This check effectively tests if Make() was run before because
* Make() frees all dynamic macro values at the end. */
#if defined(__CYGWIN__)
UseWinpath = (((cp->ce_attr|Glob_attr)&A_WINPATH) != 0);
#endif
m_at = Def_macro("@", DO_WINPATH(cp->ce_fname), M_MULTI);
}

Expand Down Expand Up @@ -646,7 +650,9 @@ CELLPTR setdirroot;
if (m_at->ht_value == NIL(char)) {
/* This check effectively tests if Make() was run before because
* Make() frees all dynamic macro values at the end. */
#if defined(__CYGWIN__)
UseWinpath = (((cp->ce_attr|Glob_attr)&A_WINPATH) != 0);
#endif
m_at = Def_macro("@", DO_WINPATH(cp->ce_fname), M_MULTI);
}

Expand Down Expand Up @@ -1389,7 +1395,7 @@ CELLPTR cp;
}
}

#if defined(MSDOS)
#if defined(MSDOS) && defined(REAL_MSDOS)
Swap_on_exec = ((l_attr & A_SWAP) != 0); /* Swapping for DOS only */
#endif
do_it = !Trace;
Expand Down
2 changes: 2 additions & 0 deletions msdos/borland/bcc30/config.h
Expand Up @@ -41,6 +41,8 @@ extern unsigned int coreleft();
# define MSDOS 1
#endif

#define REAL_MSDOS 1

/* a small problem with pointer to voids on some unix machines needs this */
#define DMPVOID void *

Expand Down
2 changes: 2 additions & 0 deletions msdos/borland/bcc40/config.h
Expand Up @@ -41,6 +41,8 @@ extern unsigned int coreleft();
# define MSDOS 1
#endif

#define REAL_MSDOS 1

/* a small problem with pointer to voids on some unix machines needs this */
#define DMPVOID void *

Expand Down
2 changes: 2 additions & 0 deletions msdos/borland/bcc45/config.h
Expand Up @@ -41,6 +41,8 @@ extern unsigned int coreleft();
# define MSDOS 1
#endif

#define REAL_MSDOS 1

/* a small problem with pointer to voids on some unix machines needs this */
#define DMPVOID void *

Expand Down
2 changes: 2 additions & 0 deletions msdos/borland/bcc50/config.h
Expand Up @@ -41,6 +41,8 @@ extern unsigned int coreleft();
# define MSDOS 1
#endif

#define REAL_MSDOS 1

/* a small problem with pointer to voids on some unix machines needs this */
#define DMPVOID void *

Expand Down
2 changes: 2 additions & 0 deletions msdos/borland/tcc20/config.h
Expand Up @@ -41,6 +41,8 @@ extern unsigned int coreleft();
# define MSDOS 1
#endif

#define REAL_MSDOS 1

/* a small problem with pointer to voids on some unix machines needs this */
#define DMPVOID void *

Expand Down
2 changes: 2 additions & 0 deletions msdos/microsft/config.h
Expand Up @@ -70,6 +70,8 @@
# define MSDOS 1
#endif

#define REAL_MSDOS 1

/* a small problem with pointer to voids on some unix machines needs this */
#define DMPVOID void *

Expand Down
6 changes: 6 additions & 0 deletions rulparse.c
Expand Up @@ -55,7 +55,10 @@ static LINKPTR _sv_ind_prq = NIL(LINK); /* indirect prerequisites for % cel
static int _sp_target = FALSE;
static t_attr _sv_attr;
static int _sv_flag;
/* unused in Bind_rules_to_targets */
#if 0
static int _sv_op;
#endif
static char *_sv_setdir;
static char _sv_globprq_only = 0;

Expand Down Expand Up @@ -341,7 +344,10 @@ int *state;

/* Save these prior to calling _do_targets, since _build_graph needs the
* _sv_setdir value for matching edges. */
#if 0
/* unused in Bind_rules_to_targets */
_sv_op = op;
#endif
_sv_setdir = set_dir;

if( special )
Expand Down
4 changes: 4 additions & 0 deletions sysintf.c
Expand Up @@ -325,13 +325,17 @@ int shell;
char **cmd; /* Simulate a reference to *cmd. */
{
static char **av = NIL(char *);
#if !defined(USE_CREATEPROCESS)
static int avs = 0;
#endif
int i = 0;
char *s; /* Temporary string pointer. */

if( av == NIL(char *) ) {
TALLOC(av, MINARGV, char*);
#if !defined(USE_CREATEPROCESS)
avs = MINARGV;
#endif
}
av[0] = NIL(char);

Expand Down
6 changes: 3 additions & 3 deletions vextern.h
Expand Up @@ -74,9 +74,9 @@ EXTERN int Def_targets; /* TRUE if defining targets - Only used *
* in Def_cell(). */
EXTERN int Skip_to_eof; /* TRUE if asked to skip to eof on input */
EXTERN int NameMax; /* The value of NAMEMAX */
#if __CYGWIN__
EXTERN int UseWinpath; /* True if .WINPATH is set for currently *
* made target. */
#if __CYGWIN__
EXTERN char* CygDrvPre; /* Drive prefix used by cygwin */
EXTERN int CygDrvPreLen; /* Drive prefix length used by cygwin */
#endif
Expand All @@ -94,7 +94,7 @@ EXTERN int zerofd; /* File descriptor for /dev/null */
EXTERN int Doing_bang; /* TRUE if target timestamp needs not to be
* updated immediately. */
EXTERN int Packed_shell; /* TRUE if packed args to use a shell */
#if defined(MSDOS)
#if defined(MSDOS) && defined(REAL_MSDOS)
EXTERN int Swap_on_exec; /* TRUE if going to swap on exec call */
#endif
EXTERN int State; /* parser state */
Expand All @@ -116,7 +116,7 @@ EXTERN int Touch; /* -t */
EXTERN int Check; /* -q */
EXTERN uint16 Verbose; /* -v */
EXTERN uint16 Measure; /* -m */
EXTERN int Microsoft; /* -M */
/*EXTERN int Microsoft; /* -M */
EXTERN int Transitive; /* -T */
EXTERN int No_exec; /* -X */

Expand Down

0 comments on commit 3c3ac2b

Please sign in to comment.