Skip to content

Commit

Permalink
wmake: do handling command line more stricter
Browse files Browse the repository at this point in the history
on UNIX systems only dash option character is enabled, slash character no more possible
'=' character as macro name separator possible only, '#' character no more possible
  • Loading branch information
jmalak committed Mar 18, 2024
1 parent e58bd4c commit fd415b5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 45 deletions.
73 changes: 54 additions & 19 deletions bld/wmake/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@
#include "clibext.h"


#ifdef __UNIX__
#define CHECK_OPTION(p) ( p[0] == '-' )
#else
#define CHECK_OPTION(p) ( p[0] == '-' || p[0] == Glob.swchar )
#endif
#define CHECK_STDIN(p) ( p[0] == '-' && p[1] == NULLCHAR )

STATIC TLIST *mustTargs; /* targets we must update */
STATIC TLIST *firstTargFound; /* first targets we ever found */
STATIC NODE *filesToDo; /* pointers into argv to -f files */

static void parseString( const char *s )
/**************************************/
{
TLIST *tlist;

Expand Down Expand Up @@ -107,7 +115,9 @@ STATIC void doBuiltIns( const char *makeopts )
suffices = SuffixList;
builtins = NULL;
}
// suffixes must be parsed before builtins
/*
* suffixes must be parsed before builtins
*/
if( suffices != NULL ) {
FmtStr( cpy, "%F", suffices );
parseString( cpy );
Expand All @@ -134,10 +144,29 @@ static void setFirstTarget( TLIST *potential_first )
}
return;
}
/* Note all first targets must not have attribute explicit */
/*
* Note all first targets must not have attribute explicit
*/
firstTargFound = potential_first;
}

STATIC bool checkMacroDefn( const char *buf )
/*******************************************/
{
char *p;

assert( buf != NULL );

p = strchr( buf, '=' );
if( p == NULL )
return( false );
if( p == buf )
return( false );
// if( p[1] == '\0' )
// return( false );
return( true );
}

STATIC void handleMacroDefn( const char *buf )
/*********************************************
* Can't use Parse() at this point because we need readonly macros, so we
Expand All @@ -151,13 +180,12 @@ STATIC void handleMacroDefn( const char *buf )

assert( buf != NULL );

q = StrDupSafe( buf ); /* we need our own copy */
q = StrDupSafe( buf ); /* we need our own copy */

p = strpbrk( q, "#=" );
p = strpbrk( q, "=" );
assert( p != NULL );
*p = '='; /* lex doesn't recognize '#' */

InsString( q, false ); /* put arg into stream */
InsString( q, false ); /* put arg into stream */
while( LexToken( LEX_PARSER ) != TOK_END ) {
/* NOP - eat all the characters */
}
Expand Down Expand Up @@ -223,7 +251,7 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
#define CHK_OPTION(o) options[(unsigned char)(o)]

if( (p = argv[1]) != NULL ) {
if( strcmp( p, "?" ) == 0 || ((p[0] == '-' || p[0] == Glob.swchar) && strcmp( p + 1, "?" ) == 0) ) {
if( strcmp( p, "?" ) == 0 || (CHECK_OPTION( p ) && strcmp( p + 1, "?" ) == 0) ) {
Usage();
// never return
}
Expand All @@ -234,8 +262,11 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
checkCtrl( p );
select = p[0];
option = ctolower( p[1] );
if( select == '-' || select == Glob.swchar ) {
if( CHECK_OPTION( p ) ) {
if( option != NULLCHAR && p[2] == NULLCHAR ) {
/*
* single character options processing
*/
switch( option ) {
case '?':
Usage();
Expand Down Expand Up @@ -266,7 +297,9 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
#endif
case 'y': Glob.show_offenders = true; break;
case 'z': Glob.hold = true; break;
/* these options require a filename */
/*
* following options require a filename
*/
case 'f':
case 'l':
if( (p = *++argv) == NULL ) {
Expand All @@ -276,9 +309,9 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
}
checkCtrl( p );
if( option == 'f' ) {
if( (p[0] == '-') && (p[1] == NULLCHAR) ) {
if( CHECK_STDIN( p ) ) {
// stdin
} else if( (p[0] == '-') || (p[0] == Glob.swchar) ) {
} else if( CHECK_OPTION( p ) ) {
PrtMsg( ERR | INVALID_FILE_OPTION, select, option );
Usage();
// never return
Expand All @@ -287,8 +320,9 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
new->name = (char *)p;
new->next = filesToDo;
filesToDo = new;
} else
} else {
*log_name = p;
}
break;
default:
PrtMsg( ERR | INVALID_OPTION, select, option );
Expand All @@ -300,6 +334,9 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
continue;
}
if( p[3] == NULLCHAR ) {
/*
* two character options processing
*/
#if defined( __DOS__ )
if( option == 'e' && ctolower( p[2] ) == 'r' ) {
Glob.redir_err = true;
Expand Down Expand Up @@ -329,9 +366,9 @@ STATIC char *procFlags( char const * const *argv, const char **log_name )
}
}
}
if( strpbrk( p, "=#" ) != NULL ) { /* is macro=defn */
if( checkMacroDefn( p ) ) { /* is macro=defn */
handleMacroDefn( p );
} else { /* is a target */
} else { /* is a target */
handleTarg( p );
}
} // while( *++argv != NULL )
Expand Down Expand Up @@ -419,10 +456,8 @@ STATIC const char *procLogName( const char * const *argv )

while( *++argv != NULL ) {
p = *argv;
if( ((p[0] == '-') || (p[0] == Glob.swchar)) &&
(ctolower( p[1] ) == 'l') && (p[2] == NULLCHAR) ) {
return( ((p = *++argv) == NULL || (p[0] == '-')
|| (p[0] == Glob.swchar)) ? NULL : p );
if( CHECK_OPTION( p ) && (ctolower( p[1] ) == 'l') && (p[2] == NULLCHAR) ) {
return( ((p = *++argv) == NULL || CHECK_OPTION( p )) ? NULL : p );
}
}
return( NULL );
Expand Down Expand Up @@ -481,7 +516,7 @@ STATIC void parseFiles( void )
newhead = cur->next;
p = cur->name;
FreeSafe( cur );
if( p[0] == '-' && p[1] == NULLCHAR ) { /* handle -f - */
if( CHECK_STDIN( p ) ) { /* handle -f - */
InsOpenFile( stdin );
ok = true;
} else {
Expand Down
12 changes: 10 additions & 2 deletions bld/wmake/h/usage.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
::
:segment ENGLISH
Usage : wmake [options]* [macro=text]* [target]*
Options: ('/' may be substituted for '-', and '#' for '=')
:segment UNIX
Options:
:elsesegment
Options: ( /option is also accepted )
:endsegment
-a make all targs (ignoring time stamp) -b block/ignore all implicit rules
-c do not check existence of files made -d debug mode (echo progress of work)
-e erase files after error (no prompt)
Expand All @@ -28,7 +32,11 @@ macro=text overrides the definition of 'macro' with the value 'text'
target specifies a target to make (default is first target)
:elsesegment JAPANESE
使用方法: wmake [options]* [macro=text]* [target]*
オプション: ('/''-'で,'=''#'で代用する事ができます)
:segment UNIX
オプション:
:elsesegment
オプション: ( /optionも使用できます )
:endsegment
-a 全ターゲットを作成します(タイム・スタンプを無視) -b すべての暗黙ルールを無視します
-c 作られたファイルがあるどうかチェックしません -d デバッグ・モード(処理過程を出力します)
-e エラーが起きた時、ファイルを消します(確認しません)
Expand Down
8 changes: 6 additions & 2 deletions bld/wmake/master.mif
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,21 @@ exetarg_name = wmk
#
!include verrc.mif

wsplice_opts_linux = -kUNIX
wsplice_opts_qnx = -kUNIX
wsplice_opts_osx = -kUNIX

wresui.res : ../h/wmake.rc ../h/mrcmsg.h usage.gh usagej.gh $(__MAKEFILES__)
@%make echo_rc
$(rcui8)

usage.gh : ../h/usage.sp $(__MAKEFILES__)
@%make echo_wsplice
$(noecho)*wsplice -kENGLISH -f "pick((MSG_USAGE_BASE + %$#%+), \"%s\", \"\")" $[@ $@
$(noecho)*wsplice -kENGLISH $(wsplice_opts_$(host_os)) -f "pick((MSG_USAGE_BASE + %$#%+), \"%s\", \"\")" $[@ $@

usagej.gh : ../h/usage.sp $(__MAKEFILES__)
@%make echo_wsplice
$(noecho)*wsplice -kJAPANESE -f "pick((MSG_USAGE_BASE + %$#%+), \"\", \"%s\")" $[@ $@
$(noecho)*wsplice -kJAPANESE $(wsplice_opts_$(host_os)) -f "pick((MSG_USAGE_BASE + %$#%+), \"\", \"%s\")" $[@ $@

isarray.gh : ./cretype.exe $(__MAKEFILES__)
@%make echo_execute
Expand Down
2 changes: 1 addition & 1 deletion bld/wmake/posmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ wsplice.exe: wsplice.o clibext.o
$(CC) -g wsplice.o clibext.o -o $@

usage.gh : ../h/usage.sp wsplice.exe
./wsplice.exe -kENGLISH -f 'pick((MSG_USAGE_BASE+%#%+), "%s", "")' ../h/usage.sp $@
./wsplice.exe -kENGLISH -kUNIX -f 'pick((MSG_USAGE_BASE+%#%+), "%s", "")' ../h/usage.sp $@

cretype.exe : ../c/cretype.c
$(CC) -I../../watcom/h -D__UNIX__ -o $@ $?
Expand Down
30 changes: 13 additions & 17 deletions bld/wmake/wmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
!ifdef __DOS__
bld_os = dos
bld_os = dos
link_sys_dos = causeway
!else ifdef __NT__
bld_os = nt
bld_os = nt
link_sys_nt = nt
!else ifdef __OS2__
bld_os = os2
bld_os = os2
link_sys_os2 = os2v2
!else ifdef __LINUX__
bld_os = linux
!endif

link_sys_dos = causeway
link_sys_os2 = os2v2

!ifdef link_sys_$(bld_os)
link_sys = $(link_sys_$(bld_os))
!else
link_sys = $(bld_os)
bld_os = linux
link_sys_linux = linux
wsplice_opts_linux = -kUNIX
!endif

objs = &
Expand All @@ -38,20 +34,20 @@ objs = &
*wcc386 -zq -D_BLDVER=$(%OWBLDVERTOOL) -D_CYEAR=xxxx -DBOOTSTRAP -w8-we-s-oaxt-j-fpc-zc -d2 -bt=$(bld_os) -I. -I"../h" -I"../../lib_misc/h" -I"../../watcom/h" -fo="$@" "$<"

./wsplice.exe : wsplice.obj
*wlink name $@ op q, map sys $(link_sys) file {$<}
*wlink name $@ op q, map sys $(link_sys_$(bld_os)) file {$<}

./cretype.exe : cretype.obj
*wlink name $@ op q, map sys $(link_sys) file {$<}
*wlink name $@ op q, map sys $(link_sys_$(bld_os)) file {$<}

# Use inline files for wsplice as a way to sidestep the metacharacter hell.
usage.gh : ./wsplice.exe ../h/usage.sp
$[@ -kENGLISH -f "pick((MSG_USAGE_BASE+%$#%+), \"%s\", \"\")" $]@ $@
$[@ -kENGLISH $(wsplice_opts_$(bld_os)) -f "pick((MSG_USAGE_BASE+%$#%+), \"%s\", \"\")" $]@ $@

isarray.gh : ./cretype.exe
$]@ $@

wmk.exe: usage.gh isarray.gh $(objs)
*wlink debug all name $@ op q, map sys $(link_sys) file {$(objs)}
*wlink debug all name $@ op q, map sys $(link_sys_$(bld_os)) file {$(objs)}

clean: .symbolic
rm -f *.obj *.gh *.exe *.err
7 changes: 3 additions & 4 deletions docs/doc/cmn/wmake.gml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ The formal &makname command line syntax is shown below.
As indicated by the square brackets [ ], all items are optional.
.begnote
.note options
is a list of valid &makname options, each preceded by a slash ("/")
or a dash ("&minus.").
is a list of valid &makname options, each preceded by a dash ("&minus.").
Alternatively, a slash ("/") can be used on non-UNIX systems.
Options may be specified in any order.
.note macro_defs
is a list of valid &makname macro definitions.
Expand All @@ -108,8 +108,7 @@ Macro definitions are of the form:
A=B
.millust end
.pc
and are readily identified by the presence of the "=" (the "#"
character may be used instead of the "=" character if necessary).
and are readily identified by the presence of the "=".
Surround the definition with quotes (") if it contains blanks (e.g.,
"debug_opt=&wlinkdebug").
The macro definitions specified on the command line supersede any
Expand Down

0 comments on commit fd415b5

Please sign in to comment.