From ea09c7694c70a72a087245de9df3c6708b57f69b Mon Sep 17 00:00:00 2001 From: Jiri Malak Date: Mon, 5 Aug 2024 00:11:30 +0200 Subject: [PATCH] vi: use const character pointer when possible --- bld/vi/c/autosave.c | 4 +- bld/vi/c/clset.c | 8 +-- bld/vi/c/clsubs.c | 8 +-- bld/vi/c/cstatus.c | 4 +- bld/vi/c/dc.c | 4 +- bld/vi/c/edbind.c | 8 +-- bld/vi/c/file.c | 10 ++-- bld/vi/c/filelast.c | 4 +- bld/vi/c/fini.c | 2 +- bld/vi/c/fts.c | 4 +- bld/vi/c/help.c | 8 +-- bld/vi/c/lang.c | 6 +- bld/vi/c/name.c | 12 ++-- bld/vi/c/savebuf.c | 2 +- bld/vi/c/select.c | 4 +- bld/vi/c/sstyle.c | 12 ++-- bld/vi/c/sstyle_c.c | 68 +++++++++++------------ bld/vi/c/sstyle_f.c | 60 +++++++++----------- bld/vi/c/sstyle_g.c | 33 +++++------ bld/vi/c/sstyle_h.c | 36 ++++++------ bld/vi/c/sstyle_m.c | 39 ++++++------- bld/vi/c/sstyle_p.c | 59 ++++++++++---------- bld/vi/c/sstyle_r.c | 56 +++++++++---------- bld/vi/c/tab_hell.c | 128 +++++++++++++++++++++---------------------- bld/vi/ctags/ctags.c | 6 +- bld/vi/ctags/ctags.h | 4 +- bld/vi/h/dc.h | 4 +- bld/vi/h/rtns.h | 26 ++++----- bld/vi/h/sstyle.h | 4 +- bld/vi/h/sstyle_c.h | 5 +- bld/vi/h/sstyle_f.h | 5 +- bld/vi/h/sstyle_g.h | 5 +- bld/vi/h/sstyle_h.h | 5 +- bld/vi/h/sstyle_m.h | 5 +- bld/vi/h/sstyle_p.h | 5 +- bld/vi/h/struct.h | 2 +- bld/vi/h/viuihelp.h | 3 +- bld/vi/h/win.h | 8 +-- bld/vi/ui/filesel.c | 5 +- bld/vi/ui/windisp.c | 18 +++--- bld/vi/win/clipbrd.c | 4 +- bld/vi/win/cursor.c | 12 ++-- bld/vi/win/display.c | 74 +++++++++++++------------ bld/vi/win/flist.c | 4 +- bld/vi/win/usage.c | 10 ++-- bld/vi/win/utils.c | 8 +-- bld/vi/win/utils.h | 5 +- bld/vi/win/winrtns.h | 8 +-- 48 files changed, 411 insertions(+), 403 deletions(-) diff --git a/bld/vi/c/autosave.c b/bld/vi/c/autosave.c index f11594515f..e133d03325 100644 --- a/bld/vi/c/autosave.c +++ b/bld/vi/c/autosave.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -108,7 +108,7 @@ void GetCurrentFilePath( char *path ) /* * getTmpName - get tmp name in path */ -static void getTmpName( char *path, char *tmpname ) +static void getTmpName( const char *path, char *tmpname ) { char tmp[FILENAME_MAX]; int i; diff --git a/bld/vi/c/clset.c b/bld/vi/c/clset.c index ba7630539d..34810d4299 100644 --- a/bld/vi/c/clset.c +++ b/bld/vi/c/clset.c @@ -53,7 +53,7 @@ static bool msgFlag; static bool needsRedisplay = false; static char msgString[MAX_STR]; -static void setMessage( char *msg, bool redisplay ) +static void setMessage( const char *msg, bool redisplay ) { strcpy( msgString, msg ); needsRedisplay = redisplay; @@ -1133,7 +1133,7 @@ static size_t getLongestTokenLength( const char *list ) /* * getSetInfo - build string of values */ -static list_linenum getSetInfo( char ***vals, char ***list, size_t *longest ) +static list_linenum getSetInfo( const char ***vals, char ***list, size_t *longest ) { list_linenum i; size_t i1; @@ -1150,7 +1150,7 @@ static list_linenum getSetInfo( char ***vals, char ***list, size_t *longest ) tc = tc1 + tc2; sdata = _MemAllocPtrArray( set_data, tc ); *list = _MemAllocPtrArray( char, tc ); - *vals = _MemAllocPtrArray( char, tc ); + *vals = (const char **)_MemAllocPtrArray( char, tc ); for( i1 = 0; i1 < tc1; i1++ ) { sdata[i1] = MemAlloc( sizeof( set_data ) ); @@ -1197,7 +1197,7 @@ vi_rc Set( const char *name ) short tmp; list_linenum tc; list_linenum i; - char **vals = NULL; + const char **vals = NULL; char **list; size_t longest; #endif diff --git a/bld/vi/c/clsubs.c b/bld/vi/c/clsubs.c index d1208bbc4d..befc3c0392 100644 --- a/bld/vi/c/clsubs.c +++ b/bld/vi/c/clsubs.c @@ -194,12 +194,12 @@ static void nextSearchStartPos( i_mark *pos, bool gflag, int rlen ) /* * ReplaceSubString - replace a sub-string with a different one */ -int ReplaceSubString( char *data, int len, int s, int e, char *rep, int replen ) +int ReplaceSubString( char *data, int len, int s, int e, const char *replace, int rlen ) { int i, ln, delta, slen; slen = e - s + 1; - delta = slen - replen; + delta = slen - rlen; /* * make room @@ -220,8 +220,8 @@ int ReplaceSubString( char *data, int len, int s, int e, char *rep, int replen ) /* * copy in new string */ - for( i = 0; i < replen; i++ ) { - data[s + i] = rep[i]; + for( i = 0; i < rlen; i++ ) { + data[s + i] = replace[i]; } return( len ); diff --git a/bld/vi/c/cstatus.c b/bld/vi/c/cstatus.c index bc812464d5..d634c5e001 100644 --- a/bld/vi/c/cstatus.c +++ b/bld/vi/c/cstatus.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2016 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -36,7 +36,7 @@ #include "win.h" #define MAX_CSTATUS_STRLEN 10 -static char *currStatus[] = +static const char * const currStatus[] = { "change", "delete", diff --git a/bld/vi/c/dc.c b/bld/vi/c/dc.c index 197eb56f2f..f5ef849fea 100644 --- a/bld/vi/c/dc.c +++ b/bld/vi/c/dc.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -440,7 +440,7 @@ dc_line *DCFindLine( int c_line_no, window_id wid ) return( NULL ); } -void DCValidateLine( dc_line *dcline, int start_col, char *text ) +void DCValidateLine( dc_line *dcline, int start_col, const char *text ) { size_t nlen; diff --git a/bld/vi/c/edbind.c b/bld/vi/c/edbind.c index 4edaeef4d0..39dea2b2f5 100644 --- a/bld/vi/c/edbind.c +++ b/bld/vi/c/edbind.c @@ -79,7 +79,7 @@ static void Banner( void ) /* * Abort - made a boo-boo */ -static void Abort( char *str, ... ) +static void Abort( const char *str, ... ) { va_list args; @@ -94,7 +94,7 @@ static void Abort( char *str, ... ) /* * MyPrintf - do a printf */ -static void MyPrintf( char *str, ... ) +static void MyPrintf( const char *str, ... ) { va_list args; @@ -142,7 +142,7 @@ static int copy_file( FILE *src, FILE *dst, unsigned long tocopy ) /* * AddDataToEXE - tack data to end of an EXE */ -static void AddDataToEXE( char *exe, char *outexe, char *data, bind_size data_len, struct stat *fs ) +static void AddDataToEXE( const char *exe, const char *outexe, char *data, bind_size data_len, struct stat *fs ) { FILE *fp; FILE *newfp; @@ -273,7 +273,7 @@ static FILE *GetFromEnvAndOpen( const char *inpath ) #if defined( __WATCOMC__ ) #pragma aux Usage __aborts #endif -static void Usage( char *msg ) +static void Usage( const char *msg ) { if( msg != NULL ) { printf( "%s\n", msg ); diff --git a/bld/vi/c/file.c b/bld/vi/c/file.c index 3e7919400a..5f5a4220e0 100644 --- a/bld/vi/c/file.c +++ b/bld/vi/c/file.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -319,11 +319,11 @@ static size_t getFileInfoString( char *st, bool is_small ) return( strlen( st ) ); } -static void make_short_name( char *name, size_t len, char *buffer ) +static void make_short_name( const char *name, size_t len, char *buffer ) { - char *start; - char *end; - size_t newlen; + const char *start; + const char *end; + size_t newlen; len -= 2; /* for 2 quotes */ strcpy( buffer, SingleDQuote ); diff --git a/bld/vi/c/filelast.c b/bld/vi/c/filelast.c index d6c4c7403e..1adea16632 100644 --- a/bld/vi/c/filelast.c +++ b/bld/vi/c/filelast.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -42,7 +42,7 @@ /* * UpdateLastFilesList - update the list of the last files edited */ -void UpdateLastFilesList( char *fname ) +void UpdateLastFilesList( const char *fname ) { history_data *h; int i; diff --git a/bld/vi/c/fini.c b/bld/vi/c/fini.c index ef2e9aade2..a99b4fc4f9 100644 --- a/bld/vi/c/fini.c +++ b/bld/vi/c/fini.c @@ -54,7 +54,7 @@ #define T2 "\t\t" #endif -char * UsageMsg[] = { +const char * const UsageMsg[] = { #ifdef __WIN__ "viw [-?-dinqrvzI] + -k\"keys\" [-s [-p\"prm\"]] [-t]", " [-c] [-P] files", diff --git a/bld/vi/c/fts.c b/bld/vi/c/fts.c index 5670c172df..4e44c5f643 100644 --- a/bld/vi/c/fts.c +++ b/bld/vi/c/fts.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -74,7 +74,7 @@ vi_rc FTSStart( const char *data ) } /* FTSStart */ -static char *expandTokenSet( char *token_no, char *buff ) +static char *expandTokenSet( const char *token_no, char *buff ) { bool val; int tok; diff --git a/bld/vi/c/help.c b/bld/vi/c/help.c index 9b13e17ef8..f742bddb2d 100644 --- a/bld/vi/c/help.c +++ b/bld/vi/c/help.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -52,13 +52,13 @@ pick( "SETtings", "set.hlp" ) \ pick( "STARTing", "start.hlp" ) -static char HelpCmdTokens[] = { +static char const HelpCmdTokens[] = { #define pick(t,h) t "\0" HELPCMDS() #undef pick }; -char *helpFiles[] = { +const char * const helpFiles[] = { #define pick(t,h) h, HELPCMDS() #undef pick @@ -115,7 +115,7 @@ vi_rc DoHelpOnContext( void ) vi_rc DoHelp( const char *data ) { - char *hfile; + const char *hfile; const char *tstr; int token; vi_rc rc; diff --git a/bld/vi/c/lang.c b/bld/vi/c/lang.c index 43caa8c2e8..a897391ef0 100644 --- a/bld/vi/c/lang.c +++ b/bld/vi/c/lang.c @@ -37,6 +37,9 @@ #include "clibext.h" +#define PRAGMA_DATFILE "pragma.dat" +#define DECLSPEC_DATFILE "declspec.dat" + typedef struct vi_keyword { vi_word keyword; int hashValue; @@ -56,9 +59,6 @@ static hash_entry *declspec_table = NULL; static int declspec_table_entries = 0; static char *declspec_read_buf = NULL; -#define PRAGMA_DATFILE "pragma.dat" -#define DECLSPEC_DATFILE "declspec.dat" - /* * hashpjw - taken from red dragon book, pg 436 */ diff --git a/bld/vi/c/name.c b/bld/vi/c/name.c index 4adbdd2efc..6300c67921 100644 --- a/bld/vi/c/name.c +++ b/bld/vi/c/name.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -33,13 +33,11 @@ #include "vi.h" #include "banner.h" -#if defined( __WIN__ ) -# if defined( __OS2__ ) +#if !defined( __WIN__ ) +const char _NEAR BANNER1[] = banner1t( "Vi Text Editor" ); +#elif defined( __OS2__ ) const char _NEAR BANNER1[] = banner1t( "Text Editor for OS/2 PM" ); -# else -const char _NEAR BANNER1[] = banner1t( "Text Editor for Windows" ); -# endif #else -const char _NEAR BANNER1[] = banner1t( "Vi Text Editor" ); +const char _NEAR BANNER1[] = banner1t( "Text Editor for Windows" ); #endif const char _NEAR BANNER2[] = banner1v( _VI_VERSION_ ); diff --git a/bld/vi/c/savebuf.c b/bld/vi/c/savebuf.c index 43674807c4..52b0988aeb 100644 --- a/bld/vi/c/savebuf.c +++ b/bld/vi/c/savebuf.c @@ -377,7 +377,7 @@ void FiniSavebufs( void ) /* * AddLineToSavebuf - add a single line to save buffer */ -void AddLineToSavebuf( char *data, int scol, int ecol ) +void AddLineToSavebuf( const char *data, int scol, int ecol ) { savebuf *tmp; int i, len, j; diff --git a/bld/vi/c/select.c b/bld/vi/c/select.c index 448821bc8e..698b08c903 100644 --- a/bld/vi/c/select.c +++ b/bld/vi/c/select.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2019 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -143,7 +143,7 @@ vi_rc SelectItem( selectitem *si ) */ vi_rc SelectItemAndValue( window_info *wi, char *title, char **list, list_linenum maxlist, vi_rc (*updatertn)( const char *, char *, int * ), - size_t indent, char **vals, int valoff ) + size_t indent, const char **vals, int valoff ) { // list_linenum j; file *cfile; diff --git a/bld/vi/c/sstyle.c b/bld/vi/c/sstyle.c index 24af835bb6..13d6e478ed 100644 --- a/bld/vi/c/sstyle.c +++ b/bld/vi/c/sstyle.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -45,7 +45,7 @@ type_style SEType[SE_MAXSIZE]; -static void getEOFText( ss_block *ss_new, char *text ) +static void getEOFText( ss_block *ss_new, const char *text ) { if( *text ) { ss_new->type = SE_EOFTEXT; @@ -57,9 +57,9 @@ static void getEOFText( ss_block *ss_new, char *text ) } } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start; + const char *end = start; if( *end == '\0' ) { SSGetBeyondText( ss_new ); @@ -70,7 +70,7 @@ static void getText( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getNextBlock( ss_block *ss_new, char *text, int text_col, +static void getNextBlock( ss_block *ss_new, const char *text, int text_col, line *line, linenum line_no ) { /* unused parameters */ (void)line_no; @@ -313,7 +313,7 @@ void SSGetWhiteSpace( ss_block *ss_new, const char *start ) // NOTE! for this to work ... // ss_old must point the the head of a -void SSDifBlock( ss_block *ss_old, char *text, int start_col, +void SSDifBlock( ss_block *ss_old, const char *text, int start_col, line *line, linenum line_no, int *dif ) { ss_block ss_new, *ss_inc; diff --git a/bld/vi/c/sstyle_c.c b/bld/vi/c/sstyle_c.c index 27bd306db6..73e032ba0e 100644 --- a/bld/vi/c/sstyle_c.c +++ b/bld/vi/c/sstyle_c.c @@ -39,7 +39,7 @@ static ss_flags_c flags; static long lenCComment = 0; -static char *firstNonWS; +static const char *firstNonWS; #define DIRECTIVE_ERROR "error" #define DIRECTIVE_IF "if" @@ -78,24 +78,24 @@ static int issymbol( int c ) } } -static bool isdirective( char *text, char *directive ) +static bool isdirective( const char *text, const char *directive ) { int len = strlen( directive ); return( strncmp( text, directive, len ) == 0 && !isalnum( *(text + len) ) && *(text + len) != '_' ); } -void InitCLine( char *text ) +void InitCLine( const char *text ) { SKIP_SPACES( text ); firstNonWS = text; } -static void getHex( ss_block *ss_new, char *start ) +static void getHex( ss_block *ss_new, const char *start ) { - int lastc; - char *end; - bool nodigits = true; + int lastc; + const char *end; + bool nodigits = true; ss_new->type = SE_HEX; for( end = start + 2; isxdigit( *end ); ++end ) { @@ -127,10 +127,10 @@ static void getHex( ss_block *ss_new, char *start ) flags.inDeclspec2 = false; } -static void getFloat( ss_block *ss_new, char *start, int skip, int command ) +static void getFloat( ss_block *ss_new, const char *start, int skip, int command ) { - char *end = start + skip; - char lastc; + const char *end = start + skip; + char lastc; ss_new->type = SE_FLOAT; @@ -204,10 +204,10 @@ static void getFloat( ss_block *ss_new, char *start, int skip, int command ) flags.inDeclspec2 = false; } -static void getNumber( ss_block *ss_new, char *start, char top ) +static void getNumber( ss_block *ss_new, const char *start, char top ) { - int lastc; - char *end = start + 1; + int lastc; + const char *end = start + 1; while( (*end >= '0') && (*end <= top) ) { end++; @@ -254,12 +254,12 @@ static void getNumber( ss_block *ss_new, char *start, char top ) flags.inDeclspec2 = false; } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start + 1; - bool isKeyword; - bool isPragma; - bool isDeclspec; + const char *end = start + 1; + bool isKeyword; + bool isPragma; + bool isDeclspec; while( isalnum( *end ) || ( *end == '_' ) ) { end++; @@ -293,7 +293,7 @@ static void getText( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getSymbol( ss_block *ss_new, char *start ) +static void getSymbol( ss_block *ss_new, const char *start ) { flags.inDeclspec2 = flags.inDeclspec && *start == '('; flags.inDeclspec = false; @@ -301,15 +301,15 @@ static void getSymbol( ss_block *ss_new, char *start ) ss_new->len = 1; } -static void getPreprocessor( ss_block *ss_new, char *start ) +static void getPreprocessor( ss_block *ss_new, const char *start ) { - char *end = start; - bool withinQuotes = flags.inString; + const char *end = start; + bool withinQuotes = flags.inString; ss_new->type = SE_PREPROCESSOR; if( EditFlags.PPKeywordOnly ) { - char *directive; + const char *directive; // just grab the #xxx bit & go @@ -377,9 +377,9 @@ static void getPreprocessor( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getChar( ss_block *ss_new, char *start, int skip ) +static void getChar( ss_block *ss_new, const char *start, int skip ) { - char *end; + const char *end; ss_new->type = SE_CHAR; for( end = start + skip; *end != '\0'; ++end ) { @@ -417,9 +417,9 @@ static void getInvalidChar( ss_block *ss_new ) flags.inDeclspec2 = false; } -static void getCComment( ss_block *ss_new, char *start, int skip ) +static void getCComment( ss_block *ss_new, const char *start, int skip ) { - char *end; + const char *end; lenCComment += skip; flags.inCComment = true; @@ -436,9 +436,9 @@ static void getCComment( ss_block *ss_new, char *start, int skip ) ss_new->len = end - start; } -static void getCPPComment( ss_block *ss_new, char *start ) +static void getCPPComment( ss_block *ss_new, const char *start ) { - char *end; + const char *end; end = start; SKIP_TOEND( end ); @@ -450,9 +450,9 @@ static void getCPPComment( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getString( ss_block *ss_new, char *start, int skip ) +static void getString( ss_block *ss_new, const char *start, int skip ) { - char *end; + const char *end; ss_new->type = SE_STRING; for( end = start + skip; *end != '\0'; ++end ) { @@ -484,9 +484,9 @@ static void getString( ss_block *ss_new, char *start, int skip ) flags.inDeclspec2 = false; } -static void getErrorDirMsg( ss_block *ss_new, char *start ) +static void getErrorDirMsg( ss_block *ss_new, const char *start ) { - char *end = start; + const char *end = start; ss_new->type = SE_IDENTIFIER; SKIP_TOEND( end ); @@ -662,7 +662,7 @@ void InitCFlags( linenum line_no ) } } -void GetCBlock( ss_block *ss_new, char *start, line *line, linenum line_no ) +void GetCBlock( ss_block *ss_new, const char *start, line *line, linenum line_no ) { /* unused parameters */ (void)line; (void)line_no; diff --git a/bld/vi/c/sstyle_f.c b/bld/vi/c/sstyle_f.c index 497dd61289..b6275c1129 100644 --- a/bld/vi/c/sstyle_f.c +++ b/bld/vi/c/sstyle_f.c @@ -85,7 +85,7 @@ static int iscomment( int c ) } } -static int islogical( char *string ) +static int islogical( const char *string ) { if( strnicmp( string, ".ne.", 4 ) == 0 || strnicmp( string, ".eq.", 4 ) == 0 @@ -118,15 +118,15 @@ static bool isInitialLine( line *line ) } } -void InitFORTRANLine( char *text, linenum line_no ) +void InitFORTRANLine( const char *text, linenum line_no ) { firstChar = *text; thisLine = line_no; } -static void getFloat( ss_block *ss_new, char *start, int skip, int command ) +static void getFloat( ss_block *ss_new, const char *start, int skip, int command ) { - char *end = start + skip; + const char *end = start + skip; ss_new->type = SE_FLOAT; @@ -174,12 +174,10 @@ static void getFloat( ss_block *ss_new, char *start, int skip, int command ) } -static void getNumber( ss_block *ss_new, char *start ) +static void getNumber( ss_block *ss_new, const char *start ) { - char *end = start + 1; - char save_char; - char *save_loc; - int nchars; + const char *end = start + 1; + int nchars; SKIP_DIGITS( end ); switch( *end ) { @@ -187,10 +185,7 @@ static void getNumber( ss_block *ss_new, char *start ) case 'H': /* Hollerith constant (string) */ - save_loc = end; - save_char = *end; - *end = 0; - nchars = atoi( start ); + nchars = strtol( start, NULL, 16 ); end++; while( *end != '\0' && nchars != 0 ) { nchars--; @@ -201,7 +196,6 @@ static void getNumber( ss_block *ss_new, char *start ) } else { ss_new->type = SE_STRING; } - *save_loc = save_char; break; case '.': getFloat( ss_new, start, end - start + 1, AFTER_DOT ); @@ -216,10 +210,10 @@ static void getNumber( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *keyword; - char *end = start; + const char *keyword; + const char *end = start; // eliminate leading spaces SKIP_SPACES( end ); @@ -231,7 +225,7 @@ static void getText( ss_block *ss_new, char *start ) // test if string is keyword if( IsKeyword( keyword, end, true ) ) { - char *end2 = end; + const char *end2 = end; ss_new->type = SE_KEYWORD; @@ -254,16 +248,16 @@ static void getSymbol( ss_block *ss_new, int length ) ss_new->len = length; } -static void getLiteral( ss_block *ss_new, char *start, int skip ) +static void getLiteral( ss_block *ss_new, const char *start, int skip ) { - char *end; - char lastchar = '\0'; - bool empty; - bool multiLine = flags.inString; - line *line; - fcb *fcb; - char *data; - vi_rc rc; + const char *end; + char lastchar = '\0'; + bool empty; + bool multiLine = flags.inString; + line *line; + fcb *fcb; + const char *data; + vi_rc rc; empty = true; for( end = start + skip; *end != '\0'; ++end ) { @@ -327,9 +321,9 @@ static void getLiteral( ss_block *ss_new, char *start, int skip ) } } -static void getComment( ss_block *ss_new, char *start ) +static void getComment( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; SKIP_TOEND( end ); ss_new->type = SE_COMMENT; @@ -342,9 +336,9 @@ static void getInvalidChar( ss_block *ss_new ) ss_new->len = 1; } -static void getLabelOrWS( ss_block *ss_new, char *start, int text_col ) +static void getLabelOrWS( ss_block *ss_new, const char *start, int text_col ) { - char *end = start; + const char *end = start; while( isspace( *end ) && text_col <= 4 ) { end++; @@ -367,7 +361,7 @@ static void getLabelOrWS( ss_block *ss_new, char *start, int text_col ) } } -static void getContinuationOrWS( ss_block *ss_new, char *start ) +static void getContinuationOrWS( ss_block *ss_new, const char *start ) { if( isspace( *start ) ) { SSGetWhiteSpace( ss_new, start ); @@ -440,7 +434,7 @@ void InitFORTRANFlags( linenum line_no ) } } -void GetFORTRANBlock( ss_block *ss_new, char *start, int text_col ) +void GetFORTRANBlock( ss_block *ss_new, const char *start, int text_col ) { int length = 0; diff --git a/bld/vi/c/sstyle_g.c b/bld/vi/c/sstyle_g.c index 63377c2b01..2cc93c974b 100644 --- a/bld/vi/c/sstyle_g.c +++ b/bld/vi/c/sstyle_g.c @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -38,12 +39,12 @@ /*----- LOCALS -----*/ -static ss_flags_g flags; -static char *firstNonWS; -static char *firstChar; +static ss_flags_g flags; +static const char *firstNonWS; +static const char *firstChar; -static int isGMLComment( char *string ) +static int isGMLComment( const char *string ) { if( strnicmp( string, ".*", 2 ) == 0 || strnicmp( string, ":cmt", 4 ) == 0 && ( string[4] == '.' || string[4] == ' ' ) ) { return( 1 ); @@ -52,16 +53,16 @@ static int isGMLComment( char *string ) } } -void InitGMLLine( char *text ) +void InitGMLLine( const char *text ) { firstChar = text; SKIP_SPACES( text ); firstNonWS = text; } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; // gather up symbol while( isalnum( *end ) || (*end == '_') ) { @@ -87,12 +88,12 @@ static void getSymbol( ss_block *ss_new ) ss_new->len = 1; } -static void getGMLComment( ss_block *ss_new, char *start, int skip ) +static void getGMLComment( ss_block *ss_new, const char *start, int skip ) { - char *end = start + skip; - char comment1; - char comment2; - char comment3; + const char *end = start + skip; + char comment1; + char comment2; + char comment3; for( ;; ) { // check for "-->" @@ -121,10 +122,10 @@ static void getGMLComment( ss_block *ss_new, char *start, int skip ) ss_new->len = end - start; } -static void getString( ss_block *ss_new, char *start, int skip ) +static void getString( ss_block *ss_new, const char *start, int skip ) { - char *nstart = start + skip; - char *end = nstart; + const char *nstart = start + skip; + const char *end = nstart; ss_new->type = SE_STRING; while( *end != '\0' && *end != '"' ) { @@ -160,7 +161,7 @@ void InitGMLFlags( linenum line_no ) flags.inString = false; } -void GetGMLBlock( ss_block *ss_new, char *start, int line ) +void GetGMLBlock( ss_block *ss_new, const char *start, int line ) { /* unused parameters */ (void)line; diff --git a/bld/vi/c/sstyle_h.c b/bld/vi/c/sstyle_h.c index 7d92d19309..4d766c900b 100644 --- a/bld/vi/c/sstyle_h.c +++ b/bld/vi/c/sstyle_h.c @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -36,19 +37,19 @@ /*----- LOCALS -----*/ -static ss_flags_h flags; -static char *firstNonWS; +static ss_flags_h flags; +static const char *firstNonWS; -void InitHTMLLine( char *text ) +void InitHTMLLine( const char *text ) { SKIP_SPACES( text ); firstNonWS = text; } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; // gather up symbol while( isalnum( *end ) || (*end == '_') ) { @@ -74,12 +75,12 @@ static void getSymbol( ss_block *ss_new ) ss_new->len = 1; } -extern void getHTMLComment( ss_block *ss_new, char *start, int skip ) +extern void getHTMLComment( ss_block *ss_new, const char *start, int skip ) { - char *end = start + skip; - char comment1; - char comment2; - char comment3; + const char *end = start + skip; + char comment1; + char comment2; + char comment3; for( ;; ) { // check for "-->" @@ -108,10 +109,10 @@ extern void getHTMLComment( ss_block *ss_new, char *start, int skip ) ss_new->len = end - start; } -static void getString( ss_block *ss_new, char *start, int skip ) +static void getString( ss_block *ss_new, const char *start, int skip ) { - char *nstart = start + skip; - char *end = nstart; + const char *nstart = start + skip; + const char *end = nstart; ss_new->type = SE_STRING; while( *end != '\0' && *end != '"' ) { @@ -148,7 +149,7 @@ void InitHTMLFlags( linenum line_no ) } -void GetHTMLBlock( ss_block *ss_new, char *start, int line ) +void GetHTMLBlock( ss_block *ss_new, const char *start, int line ) { /* unused parameters */ (void)line; @@ -182,7 +183,9 @@ void GetHTMLBlock( ss_block *ss_new, char *start, int line ) getString( ss_new, start, 1 ); return; case '<': - if( start[1] == '!' && start[2] == '-' && start[3] == '-' ) { + if( start[1] == '!' + && start[2] == '-' + && start[3] == '-' ) { flags.inHTMLComment = true; getHTMLComment( ss_new, start, 4 ); return; @@ -195,7 +198,8 @@ void GetHTMLBlock( ss_block *ss_new, char *start, int line ) break; } - if( isalnum( start[0] ) || (start[0] == '_') ) { + if( isalnum( start[0] ) + || (start[0] == '_') ) { getText( ss_new, start ); } else { getSymbol( ss_new ); diff --git a/bld/vi/c/sstyle_m.c b/bld/vi/c/sstyle_m.c index 0e201c96c5..ce1f78c497 100644 --- a/bld/vi/c/sstyle_m.c +++ b/bld/vi/c/sstyle_m.c @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -40,20 +41,20 @@ /*----- LOCALS -----*/ -static ss_flags_m flags; -static char *firstNonWS; -static char *firstChar; +static ss_flags_m flags; +static const char *firstNonWS; +static const char *firstChar; -void InitMkLine( char *text ) +void InitMkLine( const char *text ) { firstChar = text; SKIP_SPACES( text ); firstNonWS = text; } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; // gather up symbol SKIP_SYMBOL( end ); @@ -77,12 +78,12 @@ static bool isIf( const char *start ) && ( start[1] == 'f' || start[1] == 'F' ) ); } -static void getPreproc( ss_block *ss_new, char *start ) +static void getPreproc( ss_block *ss_new, const char *start ) { - char *end = start + 1; - char *keyword; - char *end2; - char *keyword2; + const char *end = start + 1; + const char *keyword; + const char *end2; + const char *keyword2; // whitespace is allowed after '!' SKIP_SPACES( end ); @@ -114,9 +115,9 @@ static void getPreproc( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getDirective( ss_block *ss_new, char *start ) +static void getDirective( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; // gather up symbol SKIP_SYMBOL( end ); @@ -135,9 +136,9 @@ static void getSymbol( ss_block *ss_new ) ss_new->len = 1; } -static void getComment( ss_block *ss_new, char *start ) +static void getComment( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; // everything is a comment until the end of line SKIP_TOEND( end ); @@ -145,10 +146,10 @@ static void getComment( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getMacro( ss_block *ss_new, char *start, int skip ) +static void getMacro( ss_block *ss_new, const char *start, int skip ) { - char *nstart = start + skip; - char *end = nstart; + const char *nstart = start + skip; + const char *end = nstart; ss_new->type = SE_STRING; @@ -232,7 +233,7 @@ void InitMkFlags( linenum line_no ) flags.inMacro = false; } -void GetMkBlock( ss_block *ss_new, char *start, int line ) +void GetMkBlock( ss_block *ss_new, const char *start, int line ) { /* unused parameters */ (void)line; diff --git a/bld/vi/c/sstyle_p.c b/bld/vi/c/sstyle_p.c index 6c2b7c0fd3..fbc13a5901 100644 --- a/bld/vi/c/sstyle_p.c +++ b/bld/vi/c/sstyle_p.c @@ -38,7 +38,7 @@ /*----- LOCALS -----*/ static ss_flags_p flags; -static char *firstNonWS; +static const char *firstNonWS; enum getFloatCommands { @@ -103,17 +103,17 @@ static int isspecvar( int c ) } } -void InitPerlLine( char *text ) +void InitPerlLine( const char *text ) { SKIP_SPACES( text ); firstNonWS = text; } -static void getHex( ss_block *ss_new, char *start ) +static void getHex( ss_block *ss_new, const char *start ) { - int lastc; - char *end = start + 2; - bool nodigits = true; + int lastc; + const char *end = start + 2; + bool nodigits = true; flags.beforeRegExp = false; ss_new->type = SE_HEX; @@ -144,10 +144,10 @@ static void getHex( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getFloat( ss_block *ss_new, char *start, int skip, int command ) +static void getFloat( ss_block *ss_new, const char *start, int skip, int command ) { - char *end = start + skip; - char lastc; + const char *end = start + skip; + char lastc; ss_new->type = SE_FLOAT; flags.beforeRegExp = false; @@ -219,10 +219,10 @@ static void getFloat( ss_block *ss_new, char *start, int skip, int command ) ss_new->len = end - start; } -static void getNumber( ss_block *ss_new, char *start, char top ) +static void getNumber( ss_block *ss_new, const char *start, char top ) { - int lastc; - char *end = start + 1; + int lastc; + const char *end = start + 1; flags.beforeRegExp = false; while( (*end >= '0') && (*end <= top) ) { @@ -267,10 +267,10 @@ static void getNumber( ss_block *ss_new, char *start, char top ) } } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start + 1; - bool isKeyword; + const char *end = start + 1; + bool isKeyword; while( isalnum( *end ) || (*end == '_') ) { end++; @@ -302,9 +302,9 @@ static void getText( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getVariable( ss_block *ss_new, char *start ) +static void getVariable( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; if( *end == '#' ) { end++; @@ -321,9 +321,10 @@ static void getVariable( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getSpecialVariable( ss_block *ss_new, char *start ) +static void getSpecialVariable( ss_block *ss_new, const char *start ) { - char *end = start + 1; + const char *end = start + 1; + if( isdigit( *end ) ) { end++; SKIP_DIGITS( end ); @@ -335,7 +336,7 @@ static void getSpecialVariable( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getSymbol( ss_block *ss_new, char *start ) +static void getSymbol( ss_block *ss_new, const char *start ) { /* unused parameters */ (void)start; @@ -345,9 +346,9 @@ static void getSymbol( ss_block *ss_new, char *start ) ss_new->len = 1; } -static void getChar( ss_block *ss_new, char *start, int skip ) +static void getChar( ss_block *ss_new, const char *start, int skip ) { - char *end; + const char *end; flags.beforeRegExp = false; ss_new->type = SE_CHAR; @@ -384,9 +385,9 @@ static void getInvalidChar( ss_block *ss_new ) ss_new->len = 1; } -static void getPerlComment( ss_block *ss_new, char *start ) +static void getPerlComment( ss_block *ss_new, const char *start ) { - char *end = start; + const char *end = start; SKIP_TOEND( end ); flags.beforeRegExp = true; @@ -395,9 +396,9 @@ static void getPerlComment( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getString( ss_block *ss_new, char *start, int skip ) +static void getString( ss_block *ss_new, const char *start, int skip ) { - char *end; + const char *end; flags.beforeRegExp = false; ss_new->type = SE_STRING; @@ -428,9 +429,9 @@ static void getString( ss_block *ss_new, char *start, int skip ) ss_new->len = end - start; } -static void getRegExp( ss_block *ss_new, char *start ) +static void getRegExp( ss_block *ss_new, const char *start ) { - char *end; + const char *end; ss_new->type = SE_REGEXP; for( ;; ) { @@ -525,7 +526,7 @@ void InitPerlFlags( linenum line_no ) } } -void GetPerlBlock( ss_block *ss_new, char *start, line *line, linenum line_no ) +void GetPerlBlock( ss_block *ss_new, const char *start, line *line, linenum line_no ) { /* unused parameters */ (void)line; (void)line_no; diff --git a/bld/vi/c/sstyle_r.c b/bld/vi/c/sstyle_r.c index aadbc19ad1..b7056597f1 100644 --- a/bld/vi/c/sstyle_r.c +++ b/bld/vi/c/sstyle_r.c @@ -38,7 +38,7 @@ static ss_flags_c flags; static int lenCComment = 0; -static char *firstNonWS; +static const char *firstNonWS; enum getFloatCommands { @@ -71,17 +71,17 @@ static int issymbol( int c ) } } -void InitRexxLine( char *text ) +void InitRexxLine( const char *text ) { SKIP_SPACES( text ); firstNonWS = text; } -static void getHex( ss_block *ss_new, char *start ) +static void getHex( ss_block *ss_new, const char *start ) { - int lastc; - char *end; - bool nodigits = true; + int lastc; + const char *end; + bool nodigits = true; ss_new->type = SE_HEX; for( end = start + 2; isxdigit( *end ); end++ ) { @@ -105,10 +105,10 @@ static void getHex( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getFloat( ss_block *ss_new, char *start, int skip, int command ) +static void getFloat( ss_block *ss_new, const char *start, int skip, int command ) { - char *end = start + skip; - char lastc; + const char *end = start + skip; + char lastc; ss_new->type = SE_FLOAT; @@ -177,10 +177,10 @@ static void getFloat( ss_block *ss_new, char *start, int skip, int command ) ss_new->len = end - start; } -static void getNumber( ss_block *ss_new, char *start, char top ) +static void getNumber( ss_block *ss_new, const char *start, char top ) { - int lastc; - char *end = start + 1; + int lastc; + const char *end = start + 1; while( *end >= '0' && *end <= top ) { end++; @@ -217,10 +217,10 @@ static void getNumber( ss_block *ss_new, char *start, char top ) } } -static void getText( ss_block *ss_new, char *start ) +static void getText( ss_block *ss_new, const char *start ) { - char *end = start + 1; - char save_char; + const char *end = start + 1; + char save_char; while( isalnum( *end ) || *end == '_' || *end == '.' ) { end++; @@ -245,10 +245,10 @@ static void getSymbol( ss_block *ss_new ) ss_new->len = 1; } -static void getPreprocessor( ss_block *ss_new, char *start ) +static void getPreprocessor( ss_block *ss_new, const char *start ) { - char *end = start; - bool withinQuotes = flags.inString; + const char *end = start; + bool withinQuotes = flags.inString; ss_new->type = SE_PREPROCESSOR; @@ -303,9 +303,9 @@ static void getPreprocessor( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getChar( ss_block *ss_new, char *start, int skip ) +static void getChar( ss_block *ss_new, const char *start, int skip ) { - char *end; + const char *end; ss_new->type = SE_CHAR; for( end = start + skip; *end != '\0'; ++end ) { @@ -329,9 +329,9 @@ static void getInvalidChar( ss_block *ss_new ) ss_new->len = 1; } -static void getCComment( ss_block *ss_new, char *start, int skip ) +static void getCComment( ss_block *ss_new, const char *start, int skip ) { - char *end = start + skip; + const char *end = start + skip; lenCComment += skip; for( ;; ) { @@ -357,9 +357,9 @@ static void getCComment( ss_block *ss_new, char *start, int skip ) ss_new->len = end - start; } -static void getCPPComment( ss_block *ss_new, char *start ) +static void getCPPComment( ss_block *ss_new, const char *start ) { - char *end = start; + const char *end = start; SKIP_TOEND( end ); flags.inCPPComment = true; @@ -370,10 +370,10 @@ static void getCPPComment( ss_block *ss_new, char *start ) ss_new->len = end - start; } -static void getString( ss_block *ss_new, char *start, int skip ) +static void getString( ss_block *ss_new, const char *start, int skip ) { - char *nstart = start + skip; - char *end = nstart; + const char *nstart = start + skip; + const char *end = nstart; ss_new->type = SE_STRING; again: @@ -554,7 +554,7 @@ void InitRexxFlags( linenum line_no ) } } -void GetRexxBlock( ss_block *ss_new, char *start, line *line, linenum line_no ) +void GetRexxBlock( ss_block *ss_new, const char *start, line *line, linenum line_no ) { line = line; line_no = line_no; diff --git a/bld/vi/c/tab_hell.c b/bld/vi/c/tab_hell.c index 01b7d960b3..020c3dd7c8 100644 --- a/bld/vi/c/tab_hell.c +++ b/bld/vi/c/tab_hell.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -117,14 +117,14 @@ size_t InsertTabSpace( size_t j, char *buff, bool *tabme ) /* * ExpandTabsInABufferUpToColumn - expand tabs only up to specified column */ -bool ExpandTabsInABufferUpToColumn( size_t endcol, char *in, size_t inlen, char *out, size_t outsize ) +bool ExpandTabsInABufferUpToColumn( size_t endcol, const char *instr, size_t inlen, char *out, size_t outsize ) { size_t i; size_t j; bool res; if( outsize > 0 ) { - res = ExpandTabsInABuffer( in, endcol, out, outsize ); + res = ExpandTabsInABuffer( instr, endcol, out, outsize ); outsize--; /* reserve space for '\0' terminator */ i = strlen( out ); j = outsize - i + endcol; @@ -132,7 +132,7 @@ bool ExpandTabsInABufferUpToColumn( size_t endcol, char *in, size_t inlen, char inlen = j; } for( j = endcol; j < inlen; j++ ) { - out[i++] = in[j]; + out[i++] = instr[j]; } out[i] = '\0'; return( res ); @@ -144,7 +144,7 @@ bool ExpandTabsInABufferUpToColumn( size_t endcol, char *in, size_t inlen, char /* * ExpandTabsInABuffer - do all tabs in a buffer */ -bool ExpandTabsInABuffer( const char *in, size_t inlen, char *out, size_t outsize ) +bool ExpandTabsInABuffer( const char *instr, size_t inlen, char *out, size_t outsize ) { size_t j; size_t k; @@ -163,7 +163,7 @@ bool ExpandTabsInABuffer( const char *in, size_t inlen, char *out, size_t outsiz /* * if we have a tab, insert some spaces */ - c = (unsigned char)in[j]; + c = (unsigned char)instr[j]; if( c < ' ' || c > 127 ) { if( c == '\t' ) { tabme = true; @@ -206,13 +206,13 @@ bool ExpandTabsInABuffer( const char *in, size_t inlen, char *out, size_t outsiz * curs is base 1 * returned coordinates are base 1 */ -int WinVirtualCursorPosition( char *buff, int curs ) +int WinVirtualCursorPosition( const char *instr, int curs ) { int j; int pos = 0; for( j = 0; j < curs; j++ ) { - if( !getNextPos( (unsigned char)buff[j], &pos ) ) { + if( !getNextPos( (unsigned char)instr[j], &pos ) ) { break; } } @@ -228,21 +228,23 @@ int WinVirtualCursorPosition( char *buff, int curs ) * vc is base 1 * returned coordinates are base 1 */ -int WinRealCursorPosition( char *buff, int vc ) +int WinRealCursorPosition( const char *instr, int vc ) { - int pos, i, len; + int pos; + int i; + int inlen; - len = strlen( buff ); + inlen = strlen( instr ); pos = 0; - for( i = 0; i < len; i++ ) { - if( !getNextPos( (unsigned char)buff[i], &pos ) ) { + for( i = 0; i < inlen; i++ ) { + if( !getNextPos( (unsigned char)instr[i], &pos ) ) { break; } if( pos >= vc ) { return( i + 1 ); } } - return( len ); + return( inlen ); } /* WinRealCursorPosition */ @@ -250,7 +252,7 @@ int WinRealCursorPosition( char *buff, int vc ) * GetVirtualCursorPosition - get the virtual position of the cursor, given * the real position on the current line */ -int GetVirtualCursorPosition( char *buff, int curs ) +int GetVirtualCursorPosition( const char *instr, int curs ) { int j; int pos = 0; @@ -262,7 +264,7 @@ int GetVirtualCursorPosition( char *buff, int curs ) curs--; } for( j = 0; j < curs; j++ ) { - if( !getNextPos( (unsigned char)buff[j], &pos ) ) { + if( !getNextPos( (unsigned char)instr[j], &pos ) ) { break; } } @@ -304,17 +306,17 @@ int VirtualColumnOnCurrentLine( int ccol ) /* * realPosition */ -static int realPosition( int virt_pos, char *buff, int len ) +static int realPosition( int virt_pos, const char *instr, int inlen ) { int j; int pos = 0; if( EditFlags.Modeless ) { - len++; + inlen++; } - for( j = 0; j < len; j++ ) { - if( !getNextPos( (unsigned char)buff[j], &pos ) ) { + for( j = 0; j < inlen; j++ ) { + if( !getNextPos( (unsigned char)instr[j], &pos ) ) { break; } if( pos >= virt_pos ) { @@ -322,7 +324,7 @@ static int realPosition( int virt_pos, char *buff, int len ) } } - return( len ); + return( inlen ); } /* realPosition */ @@ -332,17 +334,17 @@ static int realPosition( int virt_pos, char *buff, int len ) */ int RealColumnOnCurrentLine( int vc ) { - int cl; - char *buff; + int inlen; + const char *instr; if( CurrentLine->u.ld.nolinedata ) { - cl = WorkLine->len; - buff = WorkLine->data; + inlen = WorkLine->len; + instr = WorkLine->data; } else { - cl = CurrentLine->len; - buff = CurrentLine->data; + inlen = CurrentLine->len; + instr = CurrentLine->data; } - return( realPosition( vc, buff, cl ) ); + return( realPosition( vc, instr, inlen ) ); } /* RealColumnOnCurrentLine */ @@ -351,27 +353,28 @@ int RealColumnOnCurrentLine( int vc ) */ bool CursorPositionOffRight( int vc ) { - int cl, j, pos = 0; - char *buff; + int j, pos = 0; + int inlen; + const char *instr; if( CurrentLine->u.ld.nolinedata ) { - cl = WorkLine->len; - buff = WorkLine->data; + inlen = WorkLine->len; + instr = WorkLine->data; } else { - cl = CurrentLine->len; - buff = CurrentLine->data; + inlen = CurrentLine->len; + instr = CurrentLine->data; } - if( cl == 0 ) { + if( inlen == 0 ) { return( false ); } if( EditFlags.Modeless ) { - cl++; + inlen++; } - for(j = 0; j < cl; j++ ) { - if( !getNextPos( (unsigned char)buff[j], &pos ) ) { + for(j = 0; j < inlen; j++ ) { + if( !getNextPos( (unsigned char)instr[j], &pos ) ) { break; } if( pos >= vc ) { @@ -383,9 +386,9 @@ bool CursorPositionOffRight( int vc ) } /* CursorPositionOffRight */ -int RealCursorPositionInString( char *buff, int virt_pos ) +int RealCursorPositionInString( const char *instr, int virt_pos ) { - return( realPosition( virt_pos, buff, strlen( buff ) ) ); + return( realPosition( virt_pos, instr, strlen( instr ) ) ); } int RealCursorPositionOnLine( linenum line_num, int virt_pos ) @@ -407,14 +410,15 @@ int RealCursorPositionOnLine( linenum line_num, int virt_pos ) /* * VirtualLineLen - compute the real length of a specified line */ -int VirtualLineLen( char *buff ) +int VirtualLineLen( const char *instr ) { - int j, cl; + int j; int pos = 0; + int inlen; - cl = strlen( buff ); - for( j = 0; j < cl; j++ ) { - if( !getNextPos( (unsigned char)buff[j], &pos ) ) { + inlen = strlen( instr ); + for( j = 0; j < inlen; j++ ) { + if( !getNextPos( (unsigned char)instr[j], &pos ) ) { break; } } @@ -425,7 +429,7 @@ int VirtualLineLen( char *buff ) /* * AddLeadingTabSpace - make leading spaces tabs (if possible) */ -bool AddLeadingTabSpace( size_t *len, char *buff, int amount ) +bool AddLeadingTabSpace( size_t *len, char *data, int amount ) { char *tmp; size_t i; @@ -440,11 +444,11 @@ bool AddLeadingTabSpace( size_t *len, char *buff, int amount ) * expand leading stuff into spaces */ start = 0; - while( isspace( buff[start] ) ) + while( isspace( data[start] ) ) start++; tmp = StaticAlloc(); j = *len; - ExpandTabsInABuffer( buff, j, tmp, EditVars.MaxLineLen + 1 ); + ExpandTabsInABuffer( data, j, tmp, EditVars.MaxLineLen + 1 ); i = 0; while( tmp[i] == ' ' ) i++; @@ -485,12 +489,13 @@ bool AddLeadingTabSpace( size_t *len, char *buff, int amount ) if( k > 0 ) { k = InsertTabSpace( k, tmp, &tabme ); } - for( l = start; l <= j; l++ ) { - tmp[k++] = buff[l]; + for( l = start; l < j; l++ ) { + tmp[k++] = data[l]; } - memcpy( buff, tmp, k ); + memcpy( data, tmp, k ); + data[k] = '\0'; StaticFree( tmp ); - *len = k - 1; + *len = k; return( full ); } /* AddLeadingTabSpace */ @@ -499,7 +504,7 @@ bool AddLeadingTabSpace( size_t *len, char *buff, int amount ) /* * ConvertSpacesToTabsUpToColumn - add tabs only up to specified column */ -bool ConvertSpacesToTabsUpToColumn( size_t endcol, char *in, size_t inlen, char *out, size_t outlen ) +bool ConvertSpacesToTabsUpToColumn( size_t endcol, const char *instr, size_t inlen, char *out, size_t outlen ) { size_t extra; size_t first_blank; @@ -510,7 +515,6 @@ bool ConvertSpacesToTabsUpToColumn( size_t endcol, char *in, size_t inlen, char size_t m; size_t n; bool blanks_inprog, tabme; - char oc; char c; bool in_quotes; bool in_single_quotes; @@ -530,10 +534,8 @@ bool ConvertSpacesToTabsUpToColumn( size_t endcol, char *in, size_t inlen, char /* * run through each character */ - oc = in[endcol]; - in[endcol] = '\0'; - for( j = 0; j <= endcol; j++ ) { - c = in[j]; + for( j = 0; j < endcol; j++ ) { + c = instr[j]; if( c != ' ' || in_quotes || in_single_quotes ) { /* @@ -600,7 +602,6 @@ bool ConvertSpacesToTabsUpToColumn( size_t endcol, char *in, size_t inlen, char if( c == '\0' ) { break; } - } else { /* * mark start of blanks @@ -609,23 +610,20 @@ bool ConvertSpacesToTabsUpToColumn( size_t endcol, char *in, size_t inlen, char first_blank = j; blanks_inprog = true; } - } - } /* * copy the rest */ - k--; - in[endcol] = oc; +// k--; if( inlen > outlen - k ) { inlen = outlen - k; } for( j = endcol; j < inlen; j++ ) { - out[k++] = in[j]; + out[k++] = instr[j]; } - out[k++] = '\0'; + out[k] = '\0'; return( tabme ); } /* ConvertSpacesToTabsUpToColumn */ diff --git a/bld/vi/ctags/ctags.c b/bld/vi/ctags/ctags.c index 9d9e6b0bab..7b50143a16 100644 --- a/bld/vi/ctags/ctags.c +++ b/bld/vi/ctags/ctags.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -141,7 +141,7 @@ static void displayBanner( void ) } puts( banner1t( "CTAGS Utility" ) "\n" - banner1v( "1.0" ) "\n" + banner1v( _CTAGS_VERSION_ ) "\n" banner2 "\n" banner2a( 1984 ) "\n" banner3 "\n" @@ -488,7 +488,7 @@ bool IsTokenChar( int ch ) /* * MyStricmp - ignore trailing null, advance buf pointer */ -int MyStricmp( char **buf, char *literal ) +int MyStricmp( char **buf, const char *literal ) { int ret; size_t len; diff --git a/bld/vi/ctags/ctags.h b/bld/vi/ctags/ctags.h index b568e1ce02..4d8168720e 100644 --- a/bld/vi/ctags/ctags.h +++ b/bld/vi/ctags/ctags.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -71,7 +71,7 @@ extern bool VerboseFlag; extern void *MemAlloc( size_t size ); extern void MemFree( void *ptr ); extern bool IsTokenChar( int ch ); -extern int MyStricmp( char **buf, char *literal ); +extern int MyStricmp( char **buf, const char *literal ); extern void ErrorMsgExit( const char *, ... ); /* file.c */ diff --git a/bld/vi/h/dc.h b/bld/vi/h/dc.h index 886bb9a131..69195d6b3c 100644 --- a/bld/vi/h/dc.h +++ b/bld/vi/h/dc.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2016 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -48,6 +48,6 @@ extern void DCDisplayAllLines( void ); extern void DCInvalidateSomeLines( int, int ); extern void DCInvalidateAllLines( void ); extern dc_line *DCFindLine( int, window_id ); -extern void DCValidateLine( dc_line *, int, char * ); +extern void DCValidateLine( dc_line *, int, const char * ); #endif diff --git a/bld/vi/h/rtns.h b/bld/vi/h/rtns.h index 2677ff122d..3c889f4d91 100644 --- a/bld/vi/h/rtns.h +++ b/bld/vi/h/rtns.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -81,7 +81,7 @@ const char *GetASetVal( const char *token, char * ); vi_rc SettingSelected( const char *item, char *value, int *winflag ); /* clsubs.c */ -int ReplaceSubString( char *, int, int, int, char *, int ); +int ReplaceSubString( char *, int, int, int, const char *, int ); vi_rc TwoPartSubstitute( const char *, const char *, int, int ); vi_rc Substitute( linenum, linenum, const char * ); linenum SplitUpLine( linenum ); @@ -338,7 +338,7 @@ vi_rc GotoFile( window_id ); void BringUpFile( info *, bool ); /* filelast.c */ -void UpdateLastFilesList( char *fname ); +void UpdateLastFilesList( const char *fname ); char *GetFileInLastFileList( int num ); /* filenew.c */ @@ -673,7 +673,7 @@ vi_rc InsertSavebufBefore2( void ); vi_rc InsertSavebufAfter2( void ); vi_rc InsertGenericSavebuf( int, int ); void InitSavebufs( void ); -void AddLineToSavebuf( char *, int, int ); +void AddLineToSavebuf( const char *, int, int ); vi_rc AddSelRgnToSavebuf( void ); vi_rc AddSelRgnToSavebufAndDelete( void ); void AddFcbsToSavebuf( fcb_list *, bool ); @@ -686,7 +686,7 @@ void FiniSavebufs( void ); /* select.c */ vi_rc SelectItem( selectitem *si ); -vi_rc SelectItemAndValue( window_info *, char *, char **, list_linenum, checkres_fn *, size_t, char **, int ); +vi_rc SelectItemAndValue( window_info *, char *, char **, list_linenum, checkres_fn *, size_t, const char **, int ); /* selrgn.c */ void UpdateDrag( window_id, int, int ); @@ -740,19 +740,19 @@ vi_rc NewStatusWindow( void ); /* tab_hell.c */ vi_rc ExpandWhiteSpace( void ); vi_rc CompressWhiteSpace( void ); -bool ExpandTabsInABufferUpToColumn( size_t, char *, size_t, char *, size_t ); +bool ExpandTabsInABufferUpToColumn( size_t, const char *, size_t, char *, size_t ); bool ExpandTabsInABuffer( const char *, size_t, char *, size_t ); size_t InsertTabSpace( size_t, char *, bool * ); -int GetVirtualCursorPosition( char *, int ); +int GetVirtualCursorPosition( const char *, int ); int VirtualColumnOnCurrentLine( int ); int RealColumnOnCurrentLine( int ); -int RealCursorPositionInString( char *, int ); +int RealCursorPositionInString( const char *, int ); int RealCursorPositionOnLine( linenum, int ); -int WinRealCursorPosition( char *, int ); -int WinVirtualCursorPosition( char *, int ); -int VirtualLineLen( char * ); -bool AddLeadingTabSpace( size_t *, char *, int ); -bool ConvertSpacesToTabsUpToColumn( size_t, char *, size_t, char *, size_t ); +int WinRealCursorPosition( const char *, int ); +int WinVirtualCursorPosition( const char *, int ); +int VirtualLineLen( const char * ); +bool AddLeadingTabSpace( size_t *len, char *data, int amount ); +bool ConvertSpacesToTabsUpToColumn( size_t, const char *, size_t, char *, size_t ); bool CursorPositionOffRight( int vc ); /* tags.c */ diff --git a/bld/vi/h/sstyle.h b/bld/vi/h/sstyle.h index 6f54af5a5f..89177315a6 100644 --- a/bld/vi/h/sstyle.h +++ b/bld/vi/h/sstyle.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2016 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -51,7 +51,7 @@ void SSInitLanguageFlags( linenum ); void SSInitLanguageFlagsGivenValues( ss_flags * ); void SSGetLanguageFlags( ss_flags * ); bool SSKillsFlags( char ); -void SSDifBlock( ss_block *, char *, int, line *, linenum, int * ); +void SSDifBlock( ss_block *, const char *, int, line *, linenum, int * ); ss_block *SSNewBlock( void ); void SSKillBlock( ss_block * ); syntax_element SSGetStyle( int, int ); diff --git a/bld/vi/h/sstyle_c.h b/bld/vi/h/sstyle_c.h index d77cbda919..42425a6256 100644 --- a/bld/vi/h/sstyle_c.h +++ b/bld/vi/h/sstyle_c.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -30,8 +31,8 @@ ****************************************************************************/ -void GetCBlock( ss_block *, char *, line *, linenum ); +void GetCBlock( ss_block *, const char *, line *, linenum ); void InitCFlags( linenum ); void GetCFlags( ss_flags_c * ); void InitCFlagsGivenValues( ss_flags_c * ); -void InitCLine( char * ); +void InitCLine( const char * ); diff --git a/bld/vi/h/sstyle_f.h b/bld/vi/h/sstyle_f.h index 62ce0c1cc9..a145e032d3 100644 --- a/bld/vi/h/sstyle_f.h +++ b/bld/vi/h/sstyle_f.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -30,8 +31,8 @@ ****************************************************************************/ -void GetFORTRANBlock( ss_block *, char *, int ); +void GetFORTRANBlock( ss_block *, const char *, int ); void InitFORTRANFlags( linenum ); void GetFORTRANFlags( ss_flags_f * ); void InitFORTRANFlagsGivenValues( ss_flags_f * ); -void InitFORTRANLine( char *, linenum ); +void InitFORTRANLine( const char *, linenum ); diff --git a/bld/vi/h/sstyle_g.h b/bld/vi/h/sstyle_g.h index 5ac4838fde..416ca23517 100644 --- a/bld/vi/h/sstyle_g.h +++ b/bld/vi/h/sstyle_g.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -29,8 +30,8 @@ ****************************************************************************/ -void GetGMLBlock( ss_block *, char *, int ); +void GetGMLBlock( ss_block *, const char *, int ); void InitGMLFlags( linenum ); void GetGMLFlags( ss_flags_g * ); void InitGMLFlagsGivenValues( ss_flags_g * ); -void InitGMLLine( char * ); +void InitGMLLine( const char * ); diff --git a/bld/vi/h/sstyle_h.h b/bld/vi/h/sstyle_h.h index aeff71a55f..fe45383a24 100644 --- a/bld/vi/h/sstyle_h.h +++ b/bld/vi/h/sstyle_h.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -29,8 +30,8 @@ ****************************************************************************/ -void GetHTMLBlock( ss_block *, char *, int ); +void GetHTMLBlock( ss_block *, const char *, int ); void InitHTMLFlags( linenum ); void GetHTMLFlags( ss_flags_h * ); void InitHTMLFlagsGivenValues( ss_flags_h * ); -void InitHTMLLine( char * ); +void InitHTMLLine( const char * ); diff --git a/bld/vi/h/sstyle_m.h b/bld/vi/h/sstyle_m.h index 231bfb4ebe..d769a3a42f 100644 --- a/bld/vi/h/sstyle_m.h +++ b/bld/vi/h/sstyle_m.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -29,8 +30,8 @@ ****************************************************************************/ -void GetMkBlock( ss_block *, char *, int ); +void GetMkBlock( ss_block *, const char *, int ); void InitMkFlags( linenum ); void GetMkFlags( ss_flags_m * ); void InitMkFlagsGivenValues( ss_flags_m * ); -void InitMkLine( char * ); +void InitMkLine( const char * ); diff --git a/bld/vi/h/sstyle_p.h b/bld/vi/h/sstyle_p.h index 2e8f657b26..a9908fde97 100644 --- a/bld/vi/h/sstyle_p.h +++ b/bld/vi/h/sstyle_p.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -29,8 +30,8 @@ ****************************************************************************/ -void GetPerlBlock( ss_block *, char *, line *, linenum ); +void GetPerlBlock( ss_block *, const char *, line *, linenum ); void InitPerlFlags( linenum ); void GetPerlFlags( ss_flags_p * ); void InitPerlFlagsGivenValues( ss_flags_p * ); -void InitPerlLine( char * ); +void InitPerlLine( const char * ); diff --git a/bld/vi/h/struct.h b/bld/vi/h/struct.h index 6e36a7d34d..81ceaac356 100644 --- a/bld/vi/h/struct.h +++ b/bld/vi/h/struct.h @@ -638,7 +638,7 @@ typedef vi_rc checkres_fn( const char *, char *, int * ); */ typedef struct { file *f; // file with data for lines - char **vals; // values associated with each line + const char **vals; // values associated with each line size_t valoff; // offset to display values beside line data window_info *wi; // info describing window to create list_linenum sl; // selected line diff --git a/bld/vi/h/viuihelp.h b/bld/vi/h/viuihelp.h index d54836e0d1..71346eb96e 100644 --- a/bld/vi/h/viuihelp.h +++ b/bld/vi/h/viuihelp.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -30,6 +31,6 @@ #ifndef __WIN__ -extern char *helpFiles[]; +extern const char * const helpFiles[]; extern int nHelpFiles; #endif diff --git a/bld/vi/h/win.h b/bld/vi/h/win.h index 74577d0f13..c55cdf7a4e 100644 --- a/bld/vi/h/win.h +++ b/bld/vi/h/win.h @@ -146,7 +146,7 @@ extern void WindowTitle( window_id wid, const char *title ); extern void ClearWindow( window_id wid ); extern void ShiftWindowUpDown( window_id wid, int lines ); extern bool SetDrawingObjects( HDC hdc, type_style *ts ); -extern int DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, char *, int, HDC ); +extern int DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, const char *, int, HDC ); /* win/stubs.c */ extern bool DisplayMouse( bool p1 ); @@ -194,7 +194,7 @@ extern vi_rc WindowTile( int, int ); extern vi_rc WindowCascade( void ); /* win/cursor.c */ -extern void SetCursorOnLine( window_id wid, int col, char *str, type_style *style ); +extern void SetCursorOnLine( window_id wid, int col, const char *str, type_style *style ); extern void SetGenericWindowCursor( window_id wid, int row, int col ); extern void ResetEditWindowCursor( window_id wid ); extern void MyShowCaret( window_id wid ); @@ -213,7 +213,7 @@ extern bool IsGadgetStringChanged( const char *str ); extern void UpdateRepeatString( char *str ); /* win/clipbrd.c */ -extern int AddLineToClipboard( char *data, int scol, int ecol ); +extern int AddLineToClipboard( const char *data, int scol, int ecol ); extern int AddFcbsToClipboard( fcb_list *fcbs ); extern int GetClipboardSavebuf( savebuf *clip ); extern bool IsClipboardEmpty( void ); @@ -239,7 +239,7 @@ extern bool IsGadgetStringChanged( const char *str ); /* windisp.c */ extern vi_rc DisplayLineInWindowWithColor( window_id, int, const char *, type_style *, int ); -extern vi_rc DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, char *, int, unsigned int ); +extern vi_rc DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, const char *, int, unsigned int ); extern void DisplayCrossLineInWindow( window_id, int ); extern void HiliteAColumnRange( linenum, int, int ); extern void ColorAColumnRange( int, int, int, type_style * ); diff --git a/bld/vi/ui/filesel.c b/bld/vi/ui/filesel.c index 19ad29e80b..715c1c1ee5 100644 --- a/bld/vi/ui/filesel.c +++ b/bld/vi/ui/filesel.c @@ -179,7 +179,7 @@ vi_rc SelectFileOpen( const char *dir, char **result_ptr, const char *mask, bool */ static vi_rc displayGenericLines( file *f, list_linenum pagetop, int leftcol, list_linenum hi_line, type_style *hilight_style, hichar *hi_list, - char **vals, size_t valoff ) + const char **vals, size_t valoff ) { int j; size_t k; @@ -700,7 +700,8 @@ vi_rc SelectLineInFile( selflinedata *sfd ) MoveWindowToFront( fs_select_window_id ); } if( rc == ERR_NO_ERR ) { - ReplaceString( &(sfd->vals[cln - 1]), tmp ); + MemFree( (void *)sfd->vals[cln - 1] ); + sfd->vals[cln - 1] = DupString( tmp ); redraw = true; } break; diff --git a/bld/vi/ui/windisp.c b/bld/vi/ui/windisp.c index 2ae3f585cd..038f575304 100644 --- a/bld/vi/ui/windisp.c +++ b/bld/vi/ui/windisp.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -235,7 +235,7 @@ vi_rc DisplayLineInWindowWithColor( window_id wid, int c_line_no, const char *te * DisplayLineInWindowWithSyntaxStyle - display wrt syntax lang. settings */ vi_rc DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, line *line, - linenum line_no, char *text, int start_col, + linenum line_no, const char *text, int start_col, unsigned int junk ) { static ss_block ss[MAX_SS_BLOCKS]; @@ -248,12 +248,12 @@ vi_rc DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, line *li /* unused parameters */ (void)junk; + tmp = NULL; if( EditFlags.RealTabs ) { - len = strlen( text ); tmp = StaticAlloc(); + len = strlen( text ); ExpandTabsInABuffer( text, len, tmp, EditVars.MaxLineLen + 1 ); - } else { - tmp = text; + text = tmp; } // this code commented out cause it doesn't quite work. @@ -265,20 +265,20 @@ vi_rc DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, line *li // parse the line (generate new flags as well) ss[0].end = BEYOND_TEXT; - SSDifBlock( ss, tmp, start_col, line, line_no, &dummy ); + SSDifBlock( ss, text, start_col, line, line_no, &dummy ); // prevent displayLineInWindowGeneric from expanding tabs - blech saveRealTabs = EditFlags.RealTabs; EditFlags.RealTabs = false; // display the thing - rc = displayLineInWindowGeneric( wid, c_line_no, tmp, start_col, ss ); + rc = displayLineInWindowGeneric( wid, c_line_no, text, start_col, ss ); EditFlags.RealTabs = saveRealTabs; // now say that it has been displayed and the flags are OK - // DCValidateLine( c_line, start_col, tmp ); + // DCValidateLine( c_line, start_col, text ); - if( EditFlags.RealTabs ) { + if( tmp != NULL ) { StaticFree( tmp ); } return( rc ); diff --git a/bld/vi/win/clipbrd.c b/bld/vi/win/clipbrd.c index 1f304b7f0d..c071b1bd10 100644 --- a/bld/vi/win/clipbrd.c +++ b/bld/vi/win/clipbrd.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -127,7 +127,7 @@ static bool openClipboardForWrite( void ) /* * AddLineToClipboard - add data on specified line to the clipboard */ -int AddLineToClipboard( char *data, int scol, int ecol ) +int AddLineToClipboard( const char *data, int scol, int ecol ) { #ifdef __WINDOWS_386__ char __far *ptr; diff --git a/bld/vi/win/cursor.c b/bld/vi/win/cursor.c index 61575749a8..e7b4b7882a 100644 --- a/bld/vi/win/cursor.c +++ b/bld/vi/win/cursor.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2016 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -45,8 +45,6 @@ static bool haveOldBlinkTime; static bool caretDisplayed = false; static bool caretKilled = false; -extern int WinVirtualCursorPosition( char *, int ); - /* * SetCursorBlinkRate - set the rate of blinking for the caret */ @@ -108,7 +106,7 @@ static int getCursorInfo( window_id wid, int row, int col, int *x, int *width ) dc_line *dcline; int len; int old_col = 0; - char *str; + const char *str; int funny = 0; col--; // we like base 0 @@ -204,8 +202,8 @@ static int getCursorInfo( window_id wid, int row, int col, int *x, int *width ) bool no_tab = false; int avg_width = FontAverageWidth( SEType[ss->type].font ); int left, extent, end_tab; - char *cur_pos; - char *end_str; + const char *cur_pos; + const char *end_str; if( ss != ss_start ) { left = ss_prev->offset; @@ -327,7 +325,7 @@ static void setCursorOnScreen( int row, int col ) /* * SetCursorOnLine - set cursor at specified column in single line text string */ -void SetCursorOnLine( window_id wid, int col, char *str, type_style *style ) +void SetCursorOnLine( window_id wid, int col, const char *str, type_style *style ) { window *w; int x, y; diff --git a/bld/vi/win/display.c b/bld/vi/win/display.c index 80cae23325..1f1207249f 100644 --- a/bld/vi/win/display.c +++ b/bld/vi/win/display.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -158,7 +158,7 @@ bool SetDrawingObjects( HDC hdc, type_style *style ) #ifndef BITBLT_BUFFER_DISPLAY -static void funnyFix( RECT *rect, int x, window_id wid, char *display, size_t len, +static void funnyFix( RECT *rect, int x, window_id wid, const char *display, size_t len, HDC hdc, int max_width, type_style *style, HBRUSH brush ) { // FunnyItalic so draw at bit at begining and end! @@ -187,21 +187,21 @@ static void funnyFix( RECT *rect, int x, window_id wid, char *display, size_t le } static void MyTabbedTextOut( HDC hdc, - char **display, // a reference to a string + const char **display, // a reference to a string size_t len, // number of chars to display bool funny_italic, // fix up begin and end ? POINT *p, // reference to current position type_style *style, // current style RECT *rect, window_id wid, - char *otmp, + const char *otmp, int y ) { if( EditFlags.RealTabs ) { - char *tstring = *display; - char *string_end = tstring + len; - size_t tlen; - RECT new; + const char *tstring = *display; + const char *string_end = tstring + len; + size_t tlen; + RECT new; while( tstring < string_end ) { tlen = 0; @@ -253,10 +253,12 @@ static void MyTabbedTextOut( HDC hdc, } int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, - line *line, linenum line_no, char *text, int start_col, HDC hdc ) + line *line, linenum line_no, const char *text, int start_col, HDC hdc ) { - char *display, *old; - char *tmp, *otmp; + const char *display; + const char *tmp; + char *old; + char *otmp; dc_line *c_line; RECT rect; int height; @@ -285,26 +287,24 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, rect.bottom = y + height; // set up tabs for drawing + otmp = NULL; if( !EditFlags.RealTabs ) { len = strlen( text ); - otmp = tmp = StaticAlloc(); - ExpandTabsInABuffer( text, len, tmp, EditVars.MaxLineLen + 1 ); - } else { - // leave the tabs alone ... - // let tabbedTextExtent and tabbedTextOut do the rest. - otmp = tmp = text; + otmp = StaticAlloc(); + ExpandTabsInABuffer( text, len, otmp, EditVars.MaxLineLen + 1 ); + text = otmp; } + tmp = text + start_col; + display = tmp; + // check out common text prev_col = start_col; if( EditFlags.RealTabs ) { - start_col = WinRealCursorPosition( otmp, start_col + 1 ) -1; + start_col = WinRealCursorPosition( text, start_col + 1 ) - 1; } - tmp += start_col; - display = tmp; - // this section of code makes the ss blocks for this line. // it also compares the new blocks to the ones which existed // so that we can draw less ( although its not very good at it ) @@ -319,7 +319,7 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, /* do not redraw whatever is in common */ old = c_line->text; - SSDifBlock( ss_cache, otmp, start_col, line, line_no, &ssDifIndex ); + SSDifBlock( ss_cache, text, start_col, line, line_no, &ssDifIndex ); while( *old == *display ) { if( *old == 0 || indent == ssDifIndex ) { @@ -344,7 +344,7 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, } } } else { - SSDifBlock( ss_cache, otmp, start_col, line, line_no, &ssDifIndex ); + SSDifBlock( ss_cache, text, start_col, line, line_no, &ssDifIndex ); // start at beginning of line ss_step = ss_cache; x = 0; @@ -378,7 +378,7 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, // MyTabbedTextOut is long and used in 2 places but needs so // many arguments maybe it should be inline. MyTabbedTextOut( hdc, &display, len, funny_italic, - &p, style, &rect, wid, otmp, y ); + &p, style, &rect, wid, text, y ); // save pixel offset where next block is to start GetCurrentPositionEx( hdc, &p ); @@ -413,7 +413,7 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, if( *display != '\0' ) { MyTabbedTextOut( hdc, &display, len, funny_italic, - &p, style, &rect, wid, otmp, y ); + &p, style, &rect, wid, text, y ); } // if the previous line was longer than this one, blot it out. @@ -439,11 +439,13 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, // unfortunately bitblting each line is considerably slower on standard // vga, and at best only comparable to direct TextOut on Window accelerators int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, - line *line, linenum line_no, char *text, int start_col, + line *line, linenum line_no, const char *text, int start_col, HDC hdc_wnd, HDC hdc_mem ) { - char *display, *old; - char *tmp, *otmp; + const char *display; + const char *tmp; + char *old; + char *otmp; dc_line *c_line; RECT rect; int width, height; @@ -471,15 +473,17 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, rect.top = y; rect.bottom = y + height; + otmp = NULL; if( EditFlags.RealTabs ) { len = strlen( text ); - otmp = tmp = StaticAlloc(); - ExpandTabsInABuffer( text, len, tmp, EditVars.MaxLineLen + 1 ); - } else { - otmp = tmp = text; + otmp = StaticAlloc(); + ExpandTabsInABuffer( text, len, otmp, EditVars.MaxLineLen + 1 ); + text = otmp; } - tmp += start_col; + + tmp = text + start_col; display = tmp; + x = 0; c_line = DCFindLine( c_line_no - 1, wid ); SSGetLanguageFlags( &(c_line->flags) ); @@ -489,7 +493,7 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, if( c_line->valid && c_line->start_col == start_col ) { // do not redraw whatever is in common old = c_line->text; - SSDifBlock( ss_cache, otmp, start_col, line, line_no, &ssDifIndex ); + SSDifBlock( ss_cache, text, start_col, line, line_no, &ssDifIndex ); while( *old == *display ) { if( *old == 0 || indent == ssDifIndex ) { break; @@ -513,7 +517,7 @@ int DisplayLineInWindowWithSyntaxStyle( window_id wid, int c_line_no, } } } else { - SSDifBlock( ss_cache, otmp, start_col, line, line_no, &ssDifIndex ); + SSDifBlock( ss_cache, text, start_col, line, line_no, &ssDifIndex ); // start at beginning of line ss_step = ss_cache; x = 0; diff --git a/bld/vi/win/flist.c b/bld/vi/win/flist.c index 8e2a624c26..776baa4152 100644 --- a/bld/vi/win/flist.c +++ b/bld/vi/win/flist.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2022 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -39,7 +39,7 @@ /* Local Windows CALLBACK function prototypes */ WINEXPORT INT_PTR CALLBACK FileListDlgProc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ); -static info *findInfo( char *file_name ) +static info *findInfo( const char *file_name ) { info *i; diff --git a/bld/vi/win/usage.c b/bld/vi/win/usage.c index bdd5a239ec..2d0b68289a 100644 --- a/bld/vi/win/usage.c +++ b/bld/vi/win/usage.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2002-2019 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -39,9 +39,9 @@ /* Local Windows CALLBACK function prototypes */ WINEXPORT INT_PTR CALLBACK UsageDlgProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ); -static char **usageList; -static int usageCnt; -static char *usageStr; +static const char * const *usageList; +static int usageCnt; +static const char *usageStr; /* * UsageDlgProc - callback routine for usage dialog @@ -82,7 +82,7 @@ WINEXPORT INT_PTR CALLBACK UsageDlgProc( HWND hwnd, UINT msg, WPARAM wparam, LPA /* * UsageDialog - show the startup dialog */ -void UsageDialog( char **list, char *msg, int cnt ) +void UsageDialog( const char * const *list, const char *msg, int cnt ) { DLGPROC dlgproc; diff --git a/bld/vi/win/utils.c b/bld/vi/win/utils.c index b66a508e54..8f29d9140b 100644 --- a/bld/vi/win/utils.c +++ b/bld/vi/win/utils.c @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2023 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -196,7 +196,7 @@ void BlankRect( window_id wid, vi_color color, int x1, int x2, int y1, int y2 ) /* * MyTextExtent - get the text extend of a string in a specified style */ -int MyTextExtent( window_id wid, type_style *style, char *text, unsigned length ) +int MyTextExtent( window_id wid, type_style *style, const char *text, unsigned length ) { HDC hdc; int extent; @@ -224,7 +224,7 @@ int MyTextExtent( window_id wid, type_style *style, char *text, unsigned length } /* MyTextExtent */ -int MyStringExtent( window_id wid, type_style *style, char *text ) +int MyStringExtent( window_id wid, type_style *style, const char *text ) { return( MyTextExtent( wid, style, text, strlen( text ) ) ); } @@ -243,7 +243,7 @@ void ClientToRowCol( window_id wid, int x, int y, int *row, int *col, int divide int intoExtent, difExtent; int toleftExtent; int avg_width; - char *str; + const char *str; w = WINDOW_FROM_ID( wid ); *row = y / FontHeight( WIN_TEXT_FONT( w ) ) + 1; diff --git a/bld/vi/win/utils.h b/bld/vi/win/utils.h index a20980b0f8..052cdab538 100644 --- a/bld/vi/win/utils.h +++ b/bld/vi/win/utils.h @@ -2,6 +2,7 @@ * * Open Watcom Project * +* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -57,8 +58,8 @@ extern void WriteText( window_id, int, int, type_style *, const char *, int ); extern void WriteString( window_id, int, int, type_style *, const char *); extern HDC TextGetDC( window_id, type_style *); extern void TextReleaseDC( window_id, HDC ); -extern int MyTextExtent( window_id, type_style *, char *, unsigned ); -extern int MyStringExtent( window_id, type_style *, char * ); +extern int MyTextExtent( window_id, type_style *, const char *, unsigned ); +extern int MyStringExtent( window_id, type_style *, const char * ); extern void BlankRect( window_id, vi_color, int, int, int, int ); extern void BlankRectIndirect( window_id, vi_color, RECT * ); extern void ClientToRowCol( window_id, int, int, int *, int *, int ); diff --git a/bld/vi/win/winrtns.h b/bld/vi/win/winrtns.h index e37014f7a5..b96c163507 100644 --- a/bld/vi/win/winrtns.h +++ b/bld/vi/win/winrtns.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2015-2016 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2015-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -54,9 +54,9 @@ int GetStatusHeight( void ); // display.c void ClearWindow( window_id ); #ifdef BITBLT_BUFFER_DISPLAY -int DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, char *, int, HDC, HDC ); +int DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, const char *, int, HDC, HDC ); #else -int DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, char *, int, HDC ); +int DisplayLineInWindowWithSyntaxStyle( window_id, int, line *, linenum, const char *, int, HDC ); #endif // int CountChars( char *, char * ); // int FindPos( char *, int ); @@ -123,7 +123,7 @@ void FiniInstance( void ); void HandleMenuSelect( WPARAM wparam, LPARAM lparam ); void GetMenuHelpString( char *res ); void SetMenuHelpString( const char *str ); -void UsageDialog( char **, char *, int ); +void UsageDialog( const char * const *, const char *, int ); char *GetInitialFileName( void ); list_linenum PickATag( list_linenum tag_count, char **tag_list, const char *tagname );