123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566 |
- diff --git a/config/config.guess b/config/config.guess
- index 396482d..4592806 100755
- --- a/config/config.guess
- +++ b/config/config.guess
- @@ -831,6 +831,9 @@ EOF
- arm*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit ;;
- + aarch64:Linux:*:*)
- + echo ${UNAME_MACHINE}-unknown-linux-gnu
- + exit ;;
- avr32*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit ;;
- diff --git a/src/configed.H b/src/configed.H
- index b4d1ebf..436bd54 100644
- --- a/src/configed.H
- +++ b/src/configed.H
- @@ -17,10 +17,10 @@
-
- #include "config.h"
-
- -#ifndef COMPILER /* No target compiler specified */
- -#define COMPILER COMPILER_UNKNOWN
- +#ifndef COMPILER
- +#define COMPILER MSC
- #endif
- -#ifndef HOST_COMPILER /* No host compiler specified */
- +#ifndef HOST_COMPILER
- #define HOST_COMPILER COMPILER
- #endif
-
- diff --git a/src/internal.H b/src/internal.H
- index 5e1c19f..94b5a5a 100644
- --- a/src/internal.H
- +++ b/src/internal.H
- @@ -96,7 +96,7 @@
- #define OP_LPA 2 /* ( */
- /* The following are unary. */
- #define FIRST_UNOP OP_PLU /* First unary operator */
- -#define OP_PLU 3 /* + */
- +#define OP_PLU 3 /* + */
- #define OP_NEG 4 /* - */
- #define OP_COM 5 /* ~ */
- #define OP_NOT 6 /* ! */
- @@ -324,7 +324,7 @@ extern struct std_limits_ {
- int inc_nest; /* Least maximum of include nest*/
- long n_macro; /* Least maximum of num of macro*/
- long line_num; /* Maximum source line number */
- -} std_limits;
- +} std_limits;
- /* The boolean flags specified by the execution options. */
- extern struct option_flags_ {
- int c; /* -C option (keep comments) */
- @@ -503,6 +503,8 @@ extern int (* mcpp_fputc)( int c, OUTDEST od),
- (* mcpp_fputs)( const char * s, OUTDEST od),
- (* mcpp_fprintf)( OUTDEST od, const char * format, ...);
-
- +extern void (*g_report_include)(FILE *, const char *, const char *, const char *);
- +
- /* system.c */
- extern void do_options( int argc, char ** argv, char ** in_pp
- , char ** out_pp);
- diff --git a/src/main.c b/src/main.c
- index a438894..b892f81 100644
- --- a/src/main.c
- +++ b/src/main.c
- @@ -334,7 +334,7 @@ int main
- #endif
- (
- int argc,
- - char ** argv
- + const char ** argv
- )
- {
- char * in_file = NULL;
- diff --git a/src/main_libmcpp.c b/src/main_libmcpp.c
- index 7163925..d266c92 100644
- --- a/src/main_libmcpp.c
- +++ b/src/main_libmcpp.c
- @@ -3,7 +3,7 @@
- #include "mcpp_lib.h"
-
- int
- -main (int argc, char *argv[])
- +main (int argc, const char *argv[])
- {
- return mcpp_lib_main (argc, argv);
- }
- diff --git a/src/mcpp_lib.def b/src/mcpp_lib.def
- index c95f440..b3c10e9 100644
- --- a/src/mcpp_lib.def
- +++ b/src/mcpp_lib.def
- @@ -5,3 +5,4 @@ EXPORTS
- mcpp_set_out_func
- mcpp_use_mem_buffers
- mcpp_get_mem_buffer
- + mcpp_set_report_include_callback
- diff --git a/src/mcpp_lib.h b/src/mcpp_lib.h
- index 4827f0a..64b23ae 100644
- --- a/src/mcpp_lib.h
- +++ b/src/mcpp_lib.h
- @@ -1,3 +1,4 @@
- +// # Modifications Copyright (c) Contributors to the Open 3D Engine Project, SPDX-License-Identifier: Apache-2.0 OR MIT
- /* mcpp_lib.h: declarations of libmcpp exported (visible) functions */
- #ifndef _MCPP_LIB_H
- #define _MCPP_LIB_H
- @@ -10,7 +11,7 @@
- || __MINGW64__
- #if DLL_EXPORT || (__CYGWIN__ && PIC)
- #define DLL_DECL __declspec( dllexport)
- -#elif DLL_IMPORT
- +#elif MCPP_DLL_IMPORT
- #define DLL_DECL __declspec( dllimport)
- #else
- #define DLL_DECL
- @@ -19,13 +20,31 @@
- #define DLL_DECL
- #endif
-
- -extern DLL_DECL int mcpp_lib_main( int argc, char ** argv);
- -extern DLL_DECL void mcpp_reset_def_out_func( void);
- -extern DLL_DECL void mcpp_set_out_func(
- - int (* func_fputc) ( int c, OUTDEST od),
- - int (* func_fputs) ( const char * s, OUTDEST od),
- - int (* func_fprintf)( OUTDEST od, const char * format, ...)
- - );
- -extern DLL_DECL void mcpp_use_mem_buffers( int tf);
- -extern DLL_DECL char * mcpp_get_mem_buffer( OUTDEST od);
- +#include <stdio.h>
- +
- +#ifdef __cplusplus
- +extern "C" {
- +#endif
- +
- + extern DLL_DECL int mcpp_lib_main(int argc, const char ** argv);
- + extern DLL_DECL void mcpp_reset_def_out_func(void);
- + extern DLL_DECL void mcpp_set_out_func(
- + int (* func_fputc) ( int c, MCPP_OUTDEST od),
- + int (* func_fputs) ( const char * s, MCPP_OUTDEST od),
- + int (* func_fprintf)(MCPP_OUTDEST od, const char * format, ...)
- + );
- + extern DLL_DECL void mcpp_use_mem_buffers( int tf);
- + extern DLL_DECL char * mcpp_get_mem_buffer(MCPP_OUTDEST od);
- +
- + extern DLL_DECL void mcpp_set_report_include_callback(
- + void(*report_include)(FILE * fp, /* Open file pointer */
- + const char * src_dir, /* Directory of source */
- + const char * filename, /* Name of the file */
- + const char * fullname) /* Full path */
- + );
- +
- +#ifdef __cplusplus
- +}
- +#endif
- +
- #endif /* _MCPP_LIB_H */
- diff --git a/src/mcpp_out.h b/src/mcpp_out.h
- index 02ba2aa..bf0b82e 100644
- --- a/src/mcpp_out.h
- +++ b/src/mcpp_out.h
- @@ -1,13 +1,23 @@
- /* mcpp_out.h: declarations of OUTDEST data types for MCPP */
- +// # Modifications Copyright (c) Contributors to the Open 3D Engine Project, SPDX-License-Identifier: Apache-2.0 OR MIT
- #ifndef _MCPP_OUT_H
- #define _MCPP_OUT_H
-
- /* Choices for output destination */
- typedef enum {
- - OUT, /* ~= fp_out */
- - ERR, /* ~= fp_err */
- - DBG, /* ~= fp_debug */
- - NUM_OUTDEST
- -} OUTDEST;
- + MCPP_OUT, /* ~= fp_out */
- + MCPP_ERR, /* ~= fp_err */
- + MCPP_DBG, /* ~= fp_debug */
- + MCPP_NUM_OUTDEST
- +} MCPP_OUTDEST;
- +
- +// O3DE: keep build compatibility with MCPP
- +#ifndef MCPP_DONT_USE_SHORT_NAMES
- + #define OUT MCPP_OUT
- + #define ERR MCPP_ERR
- + #define DBG MCPP_DBG
- + #define NUM_OUTDEST MCPP_NUM_OUTDEST
- + #define OUTDEST MCPP_OUTDEST
- +#endif
-
- #endif /* _MCPP_OUT_H */
- diff --git a/src/noconfig.H b/src/noconfig.H
- index 6b634fe..6482967 100644
- --- a/src/noconfig.H
- +++ b/src/noconfig.H
- @@ -15,18 +15,18 @@
- */
-
- /* Define target operating-system. */
- -#define SYSTEM SYS_FREEBSD
- +#define SYSTEM SYS_WIN
-
- /* Define target compiler. */
- #ifndef COMPILER
- -#define COMPILER INDEPENDENT /* compiler-independent-build */
- +#define COMPILER MSC /* compiler-independent-build */
- #endif
-
- /* Define host operating-system. */
- #define HOST_SYSTEM SYSTEM
-
- /* Define host compiler. */
- -#define HOST_COMPILER GNUC
- +#define HOST_COMPILER COMPILER
-
- /* Version message. */
- /* "MCPP V.2.* (200y/mm) compiled by " precedes VERSION_MSG */
- diff --git a/src/support.c b/src/support.c
- index c57eaef..c910d86 100644
- --- a/src/support.c
- +++ b/src/support.c
- @@ -364,6 +364,19 @@ void mcpp_set_out_func(
- }
- #endif
-
- +void (*g_report_include)(FILE *, const char *, const char *, const char *);
- +
- +void mcpp_set_report_include_callback(
- + void(*report_include)(
- + FILE * fp, /* Open file pointer */
- + const char * src_dir, /* Directory of source */
- + const char * filename, /* Name of the file */
- + const char * fullname) /* Full path */
- +)
- +{
- + g_report_include = report_include;
- +}
- +
- int get_unexpandable(
- int c, /* First char of token */
- int diag /* Flag of diagnosis */
- @@ -636,7 +649,7 @@ static void scan_id(
- if (mcpp_mode == STD && c == '\\' && stdc2) {
- int cnt;
- char * tp = bp;
- -
- +
- if ((c = get_ch()) == 'u') {
- cnt = 4;
- } else if (c == 'U') {
- @@ -1384,7 +1397,7 @@ static char * scan_op(
- } else { /* . */
- openum = OP_1;
- }
- - } else {
- + } else {
- openum = OP_1;
- }
- break;
- @@ -1654,6 +1667,28 @@ static char * parse_line( void)
- size_t com_size;
- int c;
-
- + // By O3DE:
- + // ---- The Goal:
- + // Match the number of lines between the source AZSL files, before preprocessing,
- + // and the AZSL files after preprocessing. Line number matching is important because it helps
- + // providing accurate line numbers when reporting errors either by AZSLc or DXC.
- + //
- + // ---- The Problem:
- + // MCPP adds a new line after each comment line that starts with '//'
- + //
- + // ---- Solution:
- + // Do not add the extra line ending character '\n'.
- + //
- + // ---- How:
- + // We count here the amount of leading spaces before the first
- + // non space character is detected.
- + // This is used to decide whether comments are going to be printed out or
- + // skipped altogether.
- + // If the current line only contains comments, preceded ONLY by whitespaces then
- + // will print the comment in the output WITHOUT line ending character. Otherwise
- + // the comment won't make it into the output.
- + int NumLeadingSpaces = 0;
- +
- if ((sp = get_line( FALSE)) == NULL) /* Next logical line */
- return NULL; /* End of a file */
- if (in_asm) { /* In #asm block */
- @@ -1668,9 +1703,12 @@ static char * parse_line( void)
-
- while (char_type[ c = *sp++ & UCHARMAX] & HSP) {
- if (mcpp_mode != POST_STD)
- + { // O3DE
- /* Preserve line top horizontal white spaces */
- /* as they are for human-readability */
- *tp++ = c;
- + ++NumLeadingSpaces; //O3DE
- + } // O3DE
- /* Else skip the line top spaces */
- }
- sp--;
- @@ -1719,9 +1757,15 @@ com_start:
- cwarn( "Parsed \"//\" as comment" /* _W2_ */
- , NULL, 0L, NULL);
- if (keep_comments) {
- - sp -= 2;
- - while (*sp != '\n') /* Until end of line */
- - mcpp_fputc( *sp++, OUT);
- + const int numCharactersBeforeComment = (tp - temp);
- + if (numCharactersBeforeComment == NumLeadingSpaces)
- + {
- + // O3DE: It is safe to print the comments
- + sp -= 2;
- + while (*sp != '\n') /* Until end of line */
- + mcpp_fputc( *sp++, OUT);
- + // mcpp_fputc('\n', OUT); // Removed by O3DE. This prevents that each comment line from presenting additional empty lines.
- + }
- }
- goto end_line;
- default: /* Not a comment */
- @@ -1821,7 +1865,7 @@ static char * read_a_comment(
- if (keep_spaces) {
- saved_sp = sp - 2; /* '-2' for beginning / and * */
- *sizp = 0;
- - }
- + }
- if (keep_comments) /* If writing comments */
- mcpp_fputs( "/*", OUT); /* Write the initializer*/
- c = *sp++;
- @@ -1911,7 +1955,7 @@ static char * get_line(
- /*
- * ANSI (ISO) C: translation phase 1, 2.
- * Get the next logical line from source file.
- - * Convert [CR+LF] to [LF].
- + * Convert [CR+LF] to [LF].
- */
- {
- #if COMPILER == INDEPENDENT
- diff --git a/src/system.c b/src/system.c
- index 4759469..5bccf62 100644
- --- a/src/system.c
- +++ b/src/system.c
- @@ -303,7 +303,7 @@ static char * mkdep_mt; /* Argument of -MT option */
- /* sharp_filename is filename for #line line, used only in cur_file() */
- static char * sharp_filename = NULL;
- static char * argv0; /* argv[ 0] for usage() and version() */
- -static int ansi; /* __STRICT_ANSI__ flag for GNUC */
- +static int ansi; /* __STRICT_ANSI__ flag for GNUC */
- static int compat_mode;
- /* "Compatible" mode of recursive macro expansion */
- #define MAX_ARCH_LEN 16
- @@ -530,7 +530,7 @@ plus:
- compat_mode = TRUE; /* 'compatible' mode */
- mcpp_mode = STD;
- }
- - else
- + else
- usage( opt);
- standard = (mcpp_mode == STD || mcpp_mode == POST_STD);
- if (old_mode != STD && old_mode != mcpp_mode)
- @@ -837,7 +837,7 @@ plus:
- /* Fall through */
- case 'k':
- option_flags.k = TRUE;
- - /* Keep white spaces of input lines as they are */
- + /* Keep white spaces of input lines as they are */
- break;
-
- #if COMPILER == GNUC
- @@ -1739,7 +1739,7 @@ static void def_a_macro(
- skip_nl(); /* Clear the appended <newline> */
- }
-
- -static void chk_opts(
- +static void chk_opts(
- int sflag, /* Flag of Standard or post-Standard mode */
- int trad /* -traditional (GCC only) */
- )
- @@ -2239,7 +2239,7 @@ static void set_sys_dirs(
- set_a_dir( "/usr/local/include");
- #endif
-
- -#ifdef C_INCLUDE_DIR1
- +#ifdef C_INCLUDE_DIR1
- set_a_dir( C_INCLUDE_DIR1);
- #endif
- #ifdef C_INCLUDE_DIR2
- @@ -2301,7 +2301,7 @@ static void set_a_dir(
- #if SYSTEM == SYS_MAC
- to_search_framework = &incdir[ framework_pos];
- #endif
- - max_inc *= 2;
- + max_inc *= 2;
- }
-
- if (dirname == NULL)
- @@ -2392,7 +2392,7 @@ static char * norm_dir(
- if (! norm_name && option_flags.v)
- mcpp_fprintf( ERR, "Invalid header map file \"%s\" is ignored\n"
- , dirname);
- - } else
- + } else
- #endif
- {
- norm_name = norm_path( dirname, NULL, FALSE, FALSE);
- @@ -2642,7 +2642,7 @@ static char * norm_path(
- } else { /* Impossible */
- break;
- }
- - } else { /* Impossible */
- + } else { /* Impossible */
- break;
- }
- }
- @@ -2769,7 +2769,7 @@ static void init_gcc_macro( void)
- && scan_token( skip_ws(), (tp = work_buf, &tp), work_end)
- == NAM
- && str_eq( work_buf, "define")) {
- - defp = do_define( TRUE, nargs); /* Ignore re-definition */
- + defp = do_define( TRUE, nargs); /* Ignore re-definition */
- }
- skip_nl();
- }
- @@ -2981,7 +2981,7 @@ void put_depend(
- }
-
- static char * md_init(
- - const char * filename, /* The source file name */
- + const char * filename, /* The source file name */
- char * output /* Output to dependency file */
- )
- /*
- @@ -3288,7 +3288,7 @@ static int has_directory(
- )
- /*
- * If a directory is found in the 'source' filename string (i.e. "includer"),
- - * the directory part of the string is copied to 'directory' and
- + * the directory part of the string is copied to 'directory' and
- * has_directory() returns TRUE.
- * Else, nothing is copied and it returns FALSE.
- */
- @@ -3320,7 +3320,7 @@ static int is_full_path(
- #if SYS_FAMILY == SYS_UNIX
- if (path[0] == PATH_DELIM)
- #elif SYS_FAMILY == SYS_WIN
- - if ((path[1] == ':' && path[2] == PATH_DELIM) /* "C:/path" */
- + if ((path[1] == ':' && (path[2] == PATH_DELIM || path[2] == '\\')) /* "C:/path" */
- || path[0] == PATH_DELIM) /* Root dir of current drive */
- #elif 1
- /* For other systems you should write code here. */
- @@ -3432,7 +3432,7 @@ search:
- return FALSE;
- if (standard && included( fullname)) /* Once included */
- goto true;
- -
- +
- if ((max_open != 0 && max_open <= include_nest)
- /* Exceed the known limit of open files */
- || ((fp = fopen( fullname, "r")) == NULL && errno == EMFILE)) {
- @@ -3462,7 +3462,7 @@ search:
- }
- if (max_open == 0) /* Remember the limit of the system */
- max_open = include_nest;
- - } else if (fp == NULL) /* No read permission */
- + } else if (fp == NULL) /* No read permission */
- goto false;
- /* Truncate buffer of the includer to save memory */
- len = (int) (file->bptr - file->buffer);
- @@ -3480,6 +3480,8 @@ search:
- * Note: inc_dirp is restored to the parent includer's directory
- * by get_ch() when the current includer is finished.
- */
- + if (g_report_include)
- + g_report_include(fp, src_dir, filename, fullname);
- infile->dirp = inc_dirp = dirp;
- #if 0 /* This part is only for debugging */
- chk_dirp( dirp);
- @@ -3762,7 +3764,7 @@ static int search_framework(
- return TRUE;
- }
-
- - *cp2 = PATH_DELIM; /* Restore original include file format */
- + *cp2 = PATH_DELIM; /* Restore original include file format */
-
- return FALSE;
- }
- @@ -3858,6 +3860,28 @@ static int chk_dirp(
- }
- #endif
-
- +char* mincs_ifnotnull(char* p1, char* p2)
- +{
- + if (!p1) return p2;
- + if (!p2) return p1;
- + return p1 < p2 ? p1 : p2;
- +}
- +
- +/* extract directory part of a file path */
- +static char g_space[1024];
- +char * dir_of(const char* path)
- +{
- + const char * lastsep = mincs_ifnotnull(strrchr(path, PATH_DELIM),
- + strrchr(path, '\\'));
- + if (!lastsep) return NULL;
- + if (lastsep - path >= 1024)
- + cfatal("path too long encountered. %s", path, 0L, NULL);
- +
- + strncpy(g_space, path, lastsep - path + 1);
- + g_space[lastsep - path + 1] = 0;
- + return g_space;
- +}
- +
- void sharp(
- FILEINFO * sharp_file,
- int flag /* Flag to append to the line for GCC */
- @@ -3910,17 +3934,34 @@ static void cur_file(
-
- if (mcpp_debug & MACRO_CALL) { /* In macro notification mode */
- if (sharp_file) /* Main input file */
- - name = file->filename;
- + name = file->full_fname;
- else /* Output full-path-list, normalized */
- name = cur_fullname;
- } else { /* Usually, the path not "normalized" */
- if (sharp_file) { /* Main input file */
- name = file->filename;
- } else if (str_eq( file->filename, file->real_fname)) {
- - sprintf( work_buf, "%s%s", *(file->dirp), cur_fname);
- - name = work_buf;
- + name = file->full_fname; // O3DE: absolute paths required
- } else { /* Changed by '#line fname' directive */
- - name = file->filename;
- + if (!is_full_path(file->filename)) { // O3DE: this block does the best it can to get real full paths.
- + name = dir_of(cur_fullname); // extract first part of path
- + if (!name) // no directory found in cur_fullname (weird case)
- + name = file->filename;
- + else {
- + sprintf( work_buf, "%s%s", name, file->filename);
- + FILE* reachable = fopen(work_buf, "r");
- + if (reachable) {
- + name = norm_path(null, work_buf, FALSE, FALSE);
- + fclose(reachable);
- + } else { // non reachable file encountered
- + name = file->filename; // input verbatim
- + }
- + }
- + if (strlen(name) == 0)
- + name = file->filename; // as is
- + } else { // absolute path already
- + name = file->filename;
- + }
- }
- }
- if (sharp_filename == NULL || ! str_eq( name, sharp_filename)) {
- diff --git a/src/testmain.c b/src/testmain.c
- index 33e47b3..ce3e00d 100644
- --- a/src/testmain.c
- +++ b/src/testmain.c
- @@ -13,7 +13,7 @@
-
- #include "mcpp_lib.h"
-
- -int main(int argc, char *argv[])
- +int main(int argc, const char *argv[])
- {
- int i, j;
- char ** tmp_argv;
|