From: borutr Date: Sun, 28 Jan 2007 18:10:42 +0000 (+0000) Subject: * sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=3062f96ccb55d1d05caf9c8782f4961f87b341ce * sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type on WIN32 * src/SDCCdwarf2.c, src/SDCCglobl.h, src/SDCCmain.c, src/SDCCutil.c, src/SDCCutil.h, src/avr/gen.c, src/ds390/gen.c, src/hc08/gen.c, src/mcs51/gen.c, src/pic/device.c, src/pic/gen.c, src/pic/pcode.c, src/pic/pcodepeep.c, src/pic/ralloc.c, src/pic16/device.h, src/pic16/gen.c, src/pic16/main.c, src/pic16/pcode.c, src/pic16/pcodepeep.c, src/pic16/ralloc.c, src/xa51/gen.c, src/z80/gen.c, support/Util/MySystem.c: accept slash and backslash as directory separator on WIN32 and Cygwin ports git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4604 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 9d23a187..9c5b9577 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-01-28 Borut Razem + + * sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type + on WIN32 + * src/SDCCdwarf2.c, src/SDCCglobl.h, src/SDCCmain.c, src/SDCCutil.c, + src/SDCCutil.h, src/avr/gen.c, src/ds390/gen.c, src/hc08/gen.c, + src/mcs51/gen.c, src/pic/device.c, src/pic/gen.c, src/pic/pcode.c, + src/pic/pcodepeep.c, src/pic/ralloc.c, src/pic16/device.h, + src/pic16/gen.c, src/pic16/main.c, src/pic16/pcode.c, + src/pic16/pcodepeep.c, src/pic16/ralloc.c, src/xa51/gen.c, + src/z80/gen.c, support/Util/MySystem.c: + accept slash and backslash as directory separator on WIN32 and + Cygwin ports + 2007-01-28 Raphael Neider * src/pic16/devices.inc, diff --git a/sim/ucsim/cmd.src/cmdutil.cc b/sim/ucsim/cmd.src/cmdutil.cc index 067a3afc..955c51e8 100644 --- a/sim/ucsim/cmd.src/cmdutil.cc +++ b/sim/ucsim/cmd.src/cmdutil.cc @@ -152,12 +152,25 @@ get_handle_type(HANDLE handle) { case FILE_TYPE_CHAR: { - DWORD err; + DWORD err; if (!ClearCommError(handle, &err, NULL)) - { - if (ERROR_INVALID_HANDLE == GetLastError()) - return CH_CONSOLE; + { + switch (GetLastError()) + { + case ERROR_INVALID_HANDLE: + return CH_CONSOLE; + + case ERROR_INVALID_FUNCTION: + /* + * In case of NUL device return type CH_FILE. + * Is this the correct way to test it? + */ + return CH_FILE; + + default: + assert(false); + } } } return CH_SERIAL; @@ -218,13 +231,12 @@ input_avail(HANDLE handle, e_handle_type type) !GetNumberOfConsoleInputEvents(handle, &NumPending) || NumPending == 0 || NULL == (pIRBuf = (PINPUT_RECORD)_alloca(NumPending * sizeof(INPUT_RECORD)))) - return FALSE; + return false; if (PeekConsoleInput(handle, pIRBuf, NumPending, &NumPeeked) && NumPeeked != 0L && NumPeeked <= NumPending) { - /* * Scan all of the peeked events to determine if any is a key event * which should be recognized. diff --git a/src/SDCCdwarf2.c b/src/SDCCdwarf2.c index f02f3795..0e1d1c32 100644 --- a/src/SDCCdwarf2.c +++ b/src/SDCCdwarf2.c @@ -1575,7 +1575,7 @@ dwFindFileIndex (char * filename) if (!strncmp (includeDir, filename, strlen (includeDir)) && strlen (filename) > strlen (includeDir)) { - if (*(filename+strlen (includeDir)) == DIR_SEPARATOR_CHAR) + if (IS_DIR_SEPARATOR(filename[strlen (includeDir)])) break; } } diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 11761f6d..61eac7b0 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -18,6 +18,36 @@ #define UNIX_DIR_SEPARATOR_CHAR '/' +#if defined(__BORLANDC__) || defined(_MSC_VER) +#define STRCASECMP stricmp +#define STRNCASECMP strnicmp +#else +#define STRCASECMP strcasecmp +#define STRNCASECMP strncasecmp +#endif + +#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__) + +#ifndef HAVE_DOS_BASED_FILE_SYSTEM +#define HAVE_DOS_BASED_FILE_SYSTEM 1 +#endif + +#define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR_CHAR || (c) == UNIX_DIR_SEPARATOR_CHAR) +/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is + only semi-absolute. This is because the users of IS_ABSOLUTE_PATH + want to know whether to prepend the current working directory to + a file name, which should not be done with a name like d:foo. */ +#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':'))) +#define FILENAME_CMP(s1, s2) STRCASECMP(s1, s2) + +#else /* not DOSish */ + +#define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR_CHAR) +#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0])) +#define FILENAME_CMP(s1, s2) strcmp(s1, s2) + +#endif /* not DOSish */ + #ifdef WIN32 # define NATIVE_WIN32 1 # ifndef __MINGW32__ diff --git a/src/SDCCmain.c b/src/SDCCmain.c index da935a7a..e6c867f8 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -88,7 +88,8 @@ set *libDirsSet = NULL; /* list of lib search directories */ int ds390_jammed = 0; #endif -/* Globally accessible scratch buffer for file names. */ +/* Globally accessible scratch buffer for file names. + TODO: replace them with local buffers */ char scratchFileName[PATH_MAX]; char buffer[PATH_MAX * 2]; @@ -545,15 +546,15 @@ setParseWithComma (set **dest, const char *src) p = src; while (src < end) { - dbuf_init(&dbuf, 16); + dbuf_init (&dbuf, 16); while (p < end && ',' != *p) ++p; - dbuf_append(&dbuf, src, p - src); + dbuf_append (&dbuf, src, p - src); /* null terminate the buffer */ - dbuf_c_str(&dbuf); - addSet(dest, dbuf_detach(&dbuf)); + dbuf_c_str (&dbuf); + addSet(dest, dbuf_detach (&dbuf)); src = ++p; } @@ -605,29 +606,42 @@ setDefaultOptions (void) static void processFile (char *s) { - char *fext = NULL; + const char *extp; + struct dbuf_s ext; + struct dbuf_s path; - /* get the file extension */ - fext = s + strlen (s); - while ((fext != s) && *fext != '.') - fext--; + dbuf_init (&ext, 128); + dbuf_init (&path, 128); - /* now if no '.' then we don't know what the file type is + /* get the file extension. + If no '.' then we don't know what the file type is so give a warning and return */ - if (fext == s) + if (!dbuf_splitFile (s, &path, &ext)) { werror (W_UNKNOWN_FEXT, s); + + dbuf_destroy (&ext); + dbuf_destroy (&path); + return; } /* otherwise depending on the file type */ - if (strcmp (fext, ".c") == 0 || strcmp (fext, ".C") == 0) + extp = dbuf_c_str (&ext); + if (extp[1] == '\0' && (extp[0] == 'c' || extp[0] == 'C')) { + unsigned char *p; + + dbuf_destroy (&ext); + /* source file name : not if we already have a source file */ if (fullSrcFileName) { werror (W_TOO_MANY_SRC, s); + + dbuf_destroy (&path); + return; } @@ -636,71 +650,55 @@ processFile (char *s) if (!(srcFile = fopen (fullSrcFileName, "r"))) { werror (E_FILE_OPEN_ERR, s); - exit (1); - } - - /* copy the file name into the buffer */ - strncpyz (buffer, s, sizeof(buffer)); - /* get rid of the "."-extension */ + dbuf_destroy (&path); - /* is there a dot at all? */ - if (strrchr (buffer, '.') && - /* is the dot in the filename, not in the path? */ - (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.'))) - { - *strrchr (buffer, '.') = '\0'; + exit (1); } /* get rid of any path information for the module name; */ - fext = buffer + strlen (buffer); -#if NATIVE_WIN32 - /* do this by going backwards till we - get '\' or ':' or start of buffer */ - while (fext != buffer && - *(fext - 1) != DIR_SEPARATOR_CHAR && - *(fext - 1) != ':') - { - fext--; - } -#else - /* do this by going backwards till we - get '/' or start of buffer */ - while (fext != buffer && - *(fext - 1) != DIR_SEPARATOR_CHAR) - { - fext--; - } -#endif - moduleNameBase = Safe_strdup ( fext ); - moduleName = Safe_strdup ( fext ); + dbuf_init (&ext, 128); + + dbuf_splitPath (dbuf_c_str (&path), NULL, &ext); + dbuf_destroy (&path); - for (fext = moduleName; *fext; fext++) - if (!isalnum ((unsigned char)*fext)) - *fext = '_'; + moduleNameBase = Safe_strdup (dbuf_c_str (&ext)); + moduleName = dbuf_detach (&ext); + + for (p = moduleName; *p; ++p) + if (!isalnum(*p)) + *p = '_'; return; } /* if the extention is type .rel or .r or .REL or .R additional object file will be passed to the linker */ - if (strcmp (fext, ".r") == 0 || strcmp (fext, ".rel") == 0 || - strcmp (fext, ".R") == 0 || strcmp (fext, ".REL") == 0 || - strcmp (fext, port->linker.rel_ext) == 0) + if ((extp[1] == '\0' && (extp[0] == 'r' || extp[0] == 'R')) || + strcmp (extp, "rel") == 0 || strcmp (extp, "REL") == 0 || + strcmp (extp, port->linker.rel_ext) == 0) { - addSet(&relFilesSet, Safe_strdup(s)); + dbuf_destroy (&ext); + dbuf_destroy (&path); + + addSet (&relFilesSet, Safe_strdup (s)); return; } /* if .lib or .LIB */ - if (strcmp (fext, ".lib") == 0 || strcmp (fext, ".LIB") == 0) + if (strcmp (extp, "lib") == 0 || strcmp (extp, ".LIB") == 0) { - addSet(&libFilesSet, Safe_strdup(s)); + dbuf_destroy (&ext); + dbuf_destroy (&path); + + addSet (&libFilesSet, Safe_strdup (s)); return; } - werror (W_UNKNOWN_FEXT, s); + dbuf_destroy (&ext); + dbuf_destroy (&path); + werror (W_UNKNOWN_FEXT, s); } static void @@ -729,7 +727,7 @@ getStringArg(const char *szStart, char **argv, int *pi, int argc) { werror (E_ARGUMENT_MISSING, szStart); /* Die here rather than checking for errors later. */ - exit(EXIT_FAILURE); + exit (EXIT_FAILURE); } else { @@ -759,42 +757,43 @@ verifyShortOption(const char *opt) static bool tryHandleUnsupportedOpt(char **argv, int *pi) { - if (argv[*pi][0] == '-') - { - const char *longOpt = ""; - char shortOpt = -1; - int i; + if (argv[*pi][0] == '-') + { + const char *longOpt = ""; + char shortOpt = -1; + int i; - if (argv[*pi][1] == '-') - { - /* Long option. */ - longOpt = argv[*pi]; - } - else - { - shortOpt = argv[*pi][1]; - } - for (i = 0; i < LENGTH(unsupportedOptTable); i++) - { - if (unsupportedOptTable[i].shortOpt == shortOpt || - (longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) { - /* Found an unsupported opt. */ - char buffer[100]; - SNPRINTF(buffer, sizeof(buffer), - "%s%c%c", - longOpt ? longOpt : "", - shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' '); - werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message); - return 1; - } - } - /* Didn't find in the table */ - return 0; + if (argv[*pi][1] == '-') + { + /* Long option. */ + longOpt = argv[*pi]; } - else + else { - /* Not an option, so can't be unsupported :) */ - return 0; + shortOpt = argv[*pi][1]; + } + for (i = 0; i < LENGTH(unsupportedOptTable); i++) + { + if (unsupportedOptTable[i].shortOpt == shortOpt || + (longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) + { + /* Found an unsupported opt. */ + char buffer[100]; + SNPRINTF(buffer, sizeof(buffer), + "%s%c%c", + longOpt ? longOpt : "", + shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' '); + werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message); + return 1; + } + } + /* Didn't find in the table */ + return 0; + } + else + { + /* Not an option, so can't be unsupported :) */ + return 0; } } @@ -1153,9 +1152,9 @@ parseCmdLine (int argc, char **argv) { struct dbuf_s segname; - dbuf_init(&segname, 16); - dbuf_printf(&segname, "%-8s(CODE)", getStringArg(OPTION_CODE_SEG, argv, &i, argc)); - options.code_seg = dbuf_detach(&segname); + dbuf_init (&segname, 16); + dbuf_printf (&segname, "%-8s(CODE)", getStringArg (OPTION_CODE_SEG, argv, &i, argc)); + options.code_seg = dbuf_detach (&segname); continue; } @@ -1163,9 +1162,9 @@ parseCmdLine (int argc, char **argv) { struct dbuf_s segname; - dbuf_init(&segname, 16); - dbuf_printf(&segname, "%-8s(CODE)", getStringArg(OPTION_CONST_SEG, argv, &i, argc)); - options.const_seg = dbuf_detach(&segname); + dbuf_init (&segname, 16); + dbuf_printf (&segname, "%-8s(CODE)", getStringArg (OPTION_CONST_SEG, argv, &i, argc)); + options.const_seg = dbuf_detach (&segname); continue; } @@ -1217,41 +1216,40 @@ parseCmdLine (int argc, char **argv) case 'o': { - char *p; + char *outName = getStringArg("-o", argv, &i, argc); + size_t len = strlen(outName); - /* copy the file name into the buffer */ - strncpyz(buffer, getStringArg("-o", argv, &i, argc), - sizeof(buffer)); /* point to last character */ - p = buffer + strlen (buffer) - 1; - if (*p == DIR_SEPARATOR_CHAR) + if (IS_DIR_SEPARATOR(outName[len - 1])) { /* only output path specified */ - dstPath = Safe_strdup (buffer); + dstPath = Safe_malloc(len); + memcpy(dstPath, outName, len - 1); + dstPath[len - 1] = '\0'; fullDstFileName = NULL; } else { - fullDstFileName = Safe_strdup (buffer); + struct dbuf_s path; - /* get rid of the "."-extension */ + dbuf_init (&path, 128); + fullDstFileName = Safe_strdup (outName); - /* is there a dot at all? */ - if (strrchr (buffer, '.') && - /* is the dot in the filename, not in the path? */ - (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.'))) - *strrchr (buffer, '.') = '\0'; + /* get rid of the "."-extension */ + dbuf_splitFile (outName, &path, NULL); - dstFileName = Safe_strdup (buffer); + dbuf_c_str (&path); + dstFileName = dbuf_detach (&path); + dbuf_init (&path, 128); /* strip module name to get path */ - p = strrchr (buffer, DIR_SEPARATOR_CHAR); - if (p) + if (dbuf_splitPath (dstFileName, &path, NULL)) { - /* path with trailing / */ - p[1] = '\0'; - dstPath = Safe_strdup (buffer); + dbuf_c_str (&path); + dstPath = dbuf_detach (&path); } + else + dbuf_destroy (&path); } break; } @@ -1402,35 +1400,41 @@ parseCmdLine (int argc, char **argv) /* use the modulename from the C-source */ if (fullSrcFileName) { - size_t bufSize = strlen (dstPath) + strlen (moduleNameBase) + 1; + struct dbuf_s path; - dstFileName = Safe_alloc (bufSize); - strncpyz (dstFileName, dstPath, bufSize); - strncatz (dstFileName, moduleNameBase, bufSize); + if (*dstPath != '\0') + { + dbuf_makePath (&path, dstPath, moduleNameBase); + dbuf_c_str (&path); + dstFileName = dbuf_detach (&path); + } + else + dstFileName = Safe_strdup(moduleNameBase); } /* use the modulename from the first object file */ else if ((s = peekSet(relFilesSet)) != NULL) { - char *objectName; - size_t bufSize; + struct dbuf_s file; + + dbuf_init(&file, 128); + + dbuf_splitPath (s, NULL, &file); - strncpyz (buffer, s, sizeof(buffer)); - /* remove extension (it must be .rel) */ - *strrchr (buffer, '.') = '\0'; - /* remove path */ - objectName = strrchr (buffer, DIR_SEPARATOR_CHAR); - if (objectName) + if (*dstPath != '\0') { - ++objectName; + struct dbuf_s path; + + dbuf_init(&path, 128); + dbuf_makePath (&path, dstPath, dbuf_c_str (&file)); + dbuf_destroy (&file); + dbuf_c_str (&path); + dstFileName = dbuf_detach (&path); } else { - objectName = buffer; + dbuf_c_str (&file); + dstFileName = dbuf_detach (&file); } - bufSize = strlen (dstPath) + strlen (objectName) + 1; - dstFileName = Safe_alloc (bufSize); - strncpyz (dstFileName, dstPath, bufSize); - strncatz (dstFileName, objectName, bufSize); } /* else no module given: help text is displayed */ } @@ -1651,7 +1655,7 @@ linkEdit (char **envp) fprintf(stderr, "Add support for your FLAT24 target in %s @ line %d\n", __FILE__, __LINE__); - exit(EXIT_FAILURE); + exit (EXIT_FAILURE); } break; case MODEL_PAGE0: @@ -1699,7 +1703,7 @@ linkEdit (char **envp) fprintf(stderr, "Add support for your FLAT24 target in %s @ line %d\n", __FILE__, __LINE__); - exit(EXIT_FAILURE); + exit (EXIT_FAILURE); } } #endif @@ -1863,12 +1867,6 @@ linkEdit (char **envp) system_ret = my_system (buffer); -#ifdef _WIN32 - #define STRCMP stricmp -#else - #define STRCMP strcmp -#endif - /* TODO: most linker don't have a -o parameter */ /* -o option overrides default name? */ if (fullDstFileName) @@ -1897,7 +1895,7 @@ linkEdit (char **envp) strncatz (scratchFileName, options.out_fmt ? ".S19" : ".ihx", sizeof(scratchFileName)); - if (STRCMP (fullDstFileName, scratchFileName)) + if (FILENAME_CMP (fullDstFileName, scratchFileName)) remove (fullDstFileName); rename (scratchFileName, fullDstFileName); @@ -1913,14 +1911,14 @@ linkEdit (char **envp) strncatz (scratchFileName, ".map", sizeof(scratchFileName)); *q = 0; strncatz(buffer, ".map", sizeof(buffer)); - if (STRCMP (scratchFileName, buffer)) + if (FILENAME_CMP (scratchFileName, buffer)) remove (buffer); rename (scratchFileName, buffer); *p = 0; strncatz (scratchFileName, ".mem", sizeof(scratchFileName)); *q = 0; strncatz(buffer, ".mem", sizeof(buffer)); - if (STRCMP (scratchFileName, buffer)) + if (FILENAME_CMP (scratchFileName, buffer)) remove (buffer); rename (scratchFileName, buffer); if (options.debug) @@ -1929,13 +1927,13 @@ linkEdit (char **envp) strncatz (scratchFileName, ".cdb", sizeof(scratchFileName)); *q = 0; strncatz(buffer, ".cdb", sizeof(buffer)); - if (STRCMP (scratchFileName, buffer)) + if (FILENAME_CMP (scratchFileName, buffer)) remove (buffer); rename (scratchFileName, buffer); /* and the OMF file without extension: */ *p = 0; *q = 0; - if (STRCMP (scratchFileName, buffer)) + if (FILENAME_CMP (scratchFileName, buffer)) remove (buffer); rename (scratchFileName, buffer); } @@ -2131,7 +2129,7 @@ preProcess (char **envp) static void setBinPaths(const char *argv0) { - char *p; + const char *p; char buf[PATH_MAX]; /* @@ -2146,7 +2144,7 @@ setBinPaths(const char *argv0) instead of slower addSet() */ if ((p = getBinPath(argv0)) != NULL) - addSetHead(&binPathSet, Safe_strdup(p)); + addSetHead(&binPathSet, (void *)p); if ((p = getenv(SDCC_DIR_NAME)) != NULL) { SNPRINTF(buf, sizeof buf, "%s" PREFIX2BIN_DIR, p); @@ -2225,7 +2223,7 @@ setLibPath(void) static void setDataPaths(const char *argv0) { - char *p; + const char *p; char buf[PATH_MAX]; /* @@ -2243,6 +2241,7 @@ setDataPaths(const char *argv0) if ((p = getBinPath(argv0)) != NULL) { SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p); + free((void *)p); addSet(&dataDirsSet, Safe_strdup(buf)); } @@ -2442,7 +2441,7 @@ main (int argc, char **argv, char **envp) fatalError = 1; if (fatalError) { - exit (1); + exit (EXIT_FAILURE); } if (port->general.do_glue != NULL) diff --git a/src/SDCCutil.c b/src/SDCCutil.c index 048f5f54..b5ce4b30 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -120,61 +120,151 @@ joinStrSet(set *list) return s; } +/** Split the path string to the directory and file name (including extension) components. + The directory component doesn't contain trailing directory separator. + Returns true if the path contains the directory separator. */ +int +dbuf_splitPath(const char *path, struct dbuf_s *dir, struct dbuf_s *file) +{ + const char *p; + int ret; + const char *end = &path[strlen(path)]; + + for (p = end - 1; p >= path && !IS_DIR_SEPARATOR(*p); --p) + ; + + ret = p >= path; + + if (NULL != dir) + { + int len = p - path; + + if (0 < len) + dbuf_append(dir, path, len); + } + + if (NULL != file) + { + int len; + + ++p; + len = end - p; + + if (0 < len) + dbuf_append(file, p, len); + } + + return ret; +} + +/** Split the path string to the file name (including directory) and file extension components. + The file name component doesn't contain trailing extension separator. + Returns true if the path contains the extension separator. */ +int +dbuf_splitFile(const char *path, struct dbuf_s *file, struct dbuf_s *ext) +{ + const char *p; + const char *end = &path[strlen(path)]; + + for (p = end - 1; p >= path && !IS_DIR_SEPARATOR(*p) && '.' != *p; --p) + ; + + if (p < path || '.' != *p) + { + dbuf_append_str(file, path); + + return 0; + } + else + { + if (NULL != file) + { + int len = p - path; + + if (0 < len) + dbuf_append(file, path, len); + } + + if (NULL != ext) + { + int len; + + ++p; + len = end - p; + + if (0 < len) + dbuf_append(ext, p, len); + } + + return 1; + } +} + +/** Combile directory and the file name to a path string using the DIR_SEPARATOR_CHAR. + */ +void +dbuf_makePath(struct dbuf_s *path,const char *dir, const char *file) +{ + if (dir != NULL) + dbuf_append_str(path, dir); + + dbuf_append_char(path, DIR_SEPARATOR_CHAR); + + if (file != NULL) + dbuf_append_str(path, file); +} + /** Given a file with path information in the binary files directory, returns the directory component. Used for discovery of bin directory of SDCC installation. Returns NULL if the path is impossible. */ #ifdef _WIN32 -char * +const char * getBinPath(const char *prel) { - char *p; - size_t len; - static char path[PATH_MAX]; - - /* try DOS and *nix dir separator on WIN32 */ - if (NULL != (p = strrchr(prel, DIR_SEPARATOR_CHAR)) || - NULL != (p = strrchr(prel, UNIX_DIR_SEPARATOR_CHAR))) { - len = min((sizeof path) - 1, p - prel); - strncpy(path, prel, len); - path[len] = '\0'; - return path; - } - /* not enough info in prel; do it with module name */ - else if (0 != GetModuleFileName(NULL, path, sizeof path) && - NULL != (p = strrchr(path, DIR_SEPARATOR_CHAR))) { - *p = '\0'; - return path; - } + struct dbuf_s path; + const char *p; + + dbuf_init(&path, 128); + dbuf_splitPath(prel, &path, NULL); + + p = dbuf_c_str(&path); + if ('\0' != *p) + return p; else - return NULL; + { + char module[PATH_MAX]; + + dbuf_destroy(&path); + + /* not enough info in prel; do it with module name */ + if (0 != GetModuleFileName(NULL, module, sizeof (module))) + { + dbuf_init(&path, 128); + + dbuf_splitPath(module, &path, NULL); + return dbuf_c_str(&path); + } + else + return NULL; + } } #else -char * +const char * getBinPath(const char *prel) { - static char path[PATH_MAX]; + struct dbuf_s path; const char *ret_path; - if (NULL != (ret_path = findProgramPath(prel))) { - char *p; - size_t len; - - if (NULL != (p = strrchr(ret_path, DIR_SEPARATOR_CHAR)) && - PATH_MAX > (len = p - ret_path)) { - memcpy(path, ret_path, len); - path[len] = '\0'; - free((void *)ret_path); + if (NULL != (ret_path = findProgramPath(prel))) + { + dbuf_splitPath(prel, path, NULL); - return path; - } - else { free((void *)ret_path); - return NULL; + return dbuf_c_str(path); } - } else return NULL; } diff --git a/src/SDCCutil.h b/src/SDCCutil.h index 6d5f75f9..aa29272f 100644 --- a/src/SDCCutil.h +++ b/src/SDCCutil.h @@ -48,12 +48,26 @@ set *appendStrSet(set *list, const char *pre, const char *post); */ const char *joinStrSet(set *list); +/** Split the path string to the directory and file name (including extension) components. + The directory component doesn't contain trailing directory separator. + Returns true if the path contains the directory separator. */ +int dbuf_splitPath(const char *path, struct dbuf_s *dir, struct dbuf_s *file); + +/** Split the path string to the file name (including directory) and file extension components. + The file name component doesn't contain trailing extension separator. + Returns true if the path contains the extension separator. */ +int dbuf_splitFile(const char *path, struct dbuf_s *file, struct dbuf_s *ext); + +/** Combile directory and the file name to a path string using the DIR_SEPARATOR_CHAR. + */ +void dbuf_makePath(struct dbuf_s *path, const char *dir, const char *file); + /** Given a file with path information in the binary files directory, returns the directory component. Used for discovery of bin directory of SDCC installation. Returns NULL if the path is impossible. */ -char *getBinPath (const char *prel); +const char *getBinPath (const char *prel); /** Returns true if the given path exists. */ diff --git a/src/avr/gen.c b/src/avr/gen.c index 5e78cdd3..7c175015 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -1707,12 +1707,6 @@ resultRemat (iCode * ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - /*-----------------------------------------------------------------*/ /* genFunction - generated code for function entry */ /*-----------------------------------------------------------------*/ diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 0c4517c2..d32a3894 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -3355,12 +3355,6 @@ resultRemat (iCode * ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ /*-----------------------------------------------------------------*/ diff --git a/src/hc08/gen.c b/src/hc08/gen.c index a4911827..8c93b380 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -2839,12 +2839,6 @@ resultRemat (iCode * ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ /*-----------------------------------------------------------------*/ diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 10487d91..a2841f70 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -3211,12 +3211,6 @@ resultRemat (iCode * ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ /*-----------------------------------------------------------------*/ diff --git a/src/pic/device.c b/src/pic/device.c index b20b01d5..36c0caf0 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -31,14 +31,6 @@ #include "ralloc.h" #include "device.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#define STRNCASECMP strnicmp -#else -#define STRCASECMP strcasecmp -#define STRNCASECMP strncasecmp -#endif - extern int Gstack_base_addr; extern int Gstack_size; diff --git a/src/pic/gen.c b/src/pic/gen.c index 7cf251c4..c3d8251e 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -2777,12 +2777,6 @@ static int resultRemat (iCode *ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - #if 0 /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 48c1928f..1e7b0fa0 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -33,12 +33,6 @@ pCode *findFunction(char *fname); static void FixRegisterBanking(pBlock *pb); -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - /****************************************************************/ /****************************************************************/ diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index bfa0c757..f041796a 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -28,12 +28,6 @@ #include "pcodeflow.h" #include "ralloc.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval); pCodeOp *popRegFromString(char *str, int size, int offset); diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 4d1ab934..d51dca63 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -31,14 +31,7 @@ #include "gen.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp #define FENTRY2 1 ? (void)0 : printf -#else -#define STRCASECMP strcasecmp -//#define FENTRY2(fmt,...) do { fprintf (stderr, "%s:%d: called.\n", __FUNCTION__, __LINE__); fprintf (stderr, fmt, ## __VA_ARGS__); } while (0) -#define FENTRY2 1 ? (void)0 : printf -#endif /* this should go in SDCCicode.h, but it doesn't. */ #define IS_REF(op) (IS_SYMOP(op) && op->operand.symOperand->isref == 1) diff --git a/src/pic16/device.h b/src/pic16/device.h index ada8cd6d..fd06fc4b 100644 --- a/src/pic16/device.h +++ b/src/pic16/device.h @@ -30,12 +30,6 @@ #ifndef __DEVICE_H__ #define __DEVICE_H__ -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - #define CONFIGURATION_WORDS 20 #define IDLOCATION_BYTES 20 diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 012f409d..c03145c4 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -3598,12 +3598,6 @@ static int resultRemat (iCode *ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - #if 0 /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ diff --git a/src/pic16/main.c b/src/pic16/main.c index ad257088..ee7b4b4f 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -698,8 +698,6 @@ extern set *userIncDirsSet; static void _pic16_initPaths(void) { - char pic16incDir[512]; - char pic16libDir[512]; set *pic16incDirsSet=NULL; set *pic16libDirsSet=NULL; char devlib[512]; @@ -710,13 +708,15 @@ static void _pic16_initPaths(void) setMainValue("mcu1", pic16->name[1] ); addSet(&preArgvSet, Safe_strdup("-D__{mcu1}")); - sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR); - sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR); + if(!options.nostdinc) { + struct dbuf_s pic16incDir; + dbuf_init(&pic16incDir, 128); + dbuf_makePath(&pic16incDir, INCLUDE_DIR_SUFFIX, "pic16"); - if(!options.nostdinc) { /* setup pic16 include directory */ - pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir); + pic16incDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16incDir)); + dbuf_destroy(&pic16incDir); includeDirsSet = pic16incDirsSet; // mergeSets(&includeDirsSet, pic16incDirsSet); } @@ -725,8 +725,13 @@ static void _pic16_initPaths(void) mergeSets(&pic16incDirsSet, userIncDirsSet); if(!options.nostdlib) { + struct dbuf_s pic16libDir; + + dbuf_init(&pic16libDir, 128); + dbuf_makePath(&pic16libDir, INCLUDE_DIR_SUFFIX, "pic16"); /* setup pic16 library directory */ - pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir); + pic16libDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16libDir)); + dbuf_destroy(&pic16libDir); libDirsSet = pic16libDirsSet; // mergeSets(&libDirsSet, pic16libDirsSet); } diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index b4fe226a..9cb878fe 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -35,10 +35,7 @@ extern char *pic16_aopGet (struct asmop *aop, int offset, bool bit16, bool dname); #if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp #define inline -#else -#define STRCASECMP strcasecmp #endif #define DUMP_DF_GRAPHS 0 diff --git a/src/pic16/pcodepeep.c b/src/pic16/pcodepeep.c index e8814db5..ec373e33 100644 --- a/src/pic16/pcodepeep.c +++ b/src/pic16/pcodepeep.c @@ -32,12 +32,6 @@ #include "pcodeflow.h" #include "ralloc.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - pCodeOp *pic16_popCopyGPR2Bit(pCodeOpReg *pc, int bitval); pCodeOp *pic16_newpCodeOpWild(int id, pCodeWildBlock *pcwb, pCodeOp *subtype); diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index 143e92b1..1319ff89 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -31,12 +31,6 @@ #include "gen.h" #include "device.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - #ifndef debugf #define debugf(frm, rest) _debugf(__FILE__, __LINE__, frm, rest) #endif diff --git a/src/xa51/gen.c b/src/xa51/gen.c index dd6fabb3..bf86fa61 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -40,12 +40,6 @@ #include "ralloc.h" #include "gen.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - extern int allocInfo; /* this is the down and dirty file with all kinds of diff --git a/src/z80/gen.c b/src/z80/gen.c index 08cf5b4c..dc639d94 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -87,12 +87,6 @@ #include #include -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - #include "z80.h" #include "SDCCglobl.h" #include "SDCCpeeph.h" diff --git a/support/Util/MySystem.c b/support/Util/MySystem.c index b78d99aa..30e657c5 100644 --- a/support/Util/MySystem.c +++ b/support/Util/MySystem.c @@ -249,10 +249,7 @@ merge_command(const char *command, const char *params) static int has_path(const char *path) { - if (strrchr(path, DIR_SEPARATOR_CHAR) == NULL) - return 0; - - return 1; + return splitPath(path, NULL, 0, NULL, 0); }