From d3a5144876c052c721c19f85f8275174630f9461 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 26 Aug 2007 21:44:03 +0000 Subject: Replace macros with inline functions git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@386 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/fiasco/lib/misc.c | 32 ----------- converter/other/fiasco/params.c | 3 +- converter/other/tiff.c | 6 ++- converter/pbm/g3topbm.c | 12 +++-- converter/pbm/pbmtonokia.c | 14 ++--- converter/ppm/ppmtompeg/param.c | 110 +++++++++++++++++++------------------- converter/ppm/xvminitoppm.c | 6 +-- editor/pammixinterlace.c | 4 +- editor/ppmcolormask.c | 2 +- lib/util/nstring.c | 2 +- lib/util/nstring.h | 42 ++++++++++----- other/pamx/window.c | 4 +- 12 files changed, 115 insertions(+), 122 deletions(-) diff --git a/converter/other/fiasco/lib/misc.c b/converter/other/fiasco/lib/misc.c index 02a1314f..12b94e7a 100644 --- a/converter/other/fiasco/lib/misc.c +++ b/converter/other/fiasco/lib/misc.c @@ -432,38 +432,6 @@ Log2 (double x) return log (x) / 0.69314718; } -#ifndef HAVE_STRCASECMP -bool_t -strcaseeq (const char *s1, const char *s2) -/* - * Compare strings 's1' and 's2', ignoring the case of the characters. - * - * Return value: - * TRUE if strings match, else FALSE - */ -{ - bool_t matched; - char *ls1, *ls2, *ptr; - - assert (s1 && s2); - - ls1 = strdup (s1); - ls2 = strdup (s2); - - for (ptr = ls1; *ptr; ptr++) - *ptr = tolower (*ptr); - for (ptr = ls2; *ptr; ptr++) - *ptr = tolower (*ptr); - - matched = streq (ls1, ls2) ? YES : NO; - - Free (ls1); - Free (ls2); - - return matched; -} -#endif /* not HAVE_STRCASECMP */ - real_t variance (const word_t *pixels, unsigned x0, unsigned y0, unsigned width, unsigned height, unsigned cols) diff --git a/converter/other/fiasco/params.c b/converter/other/fiasco/params.c index 3d0a0252..7a302b82 100644 --- a/converter/other/fiasco/params.c +++ b/converter/other/fiasco/params.c @@ -15,7 +15,8 @@ * $State: Exp $ */ -#define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ +#define _BSD_SOURCE 1 + /* Make sure strdup() is in string.h and strcaseeq() is in nstring.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ #include "config.h" diff --git a/converter/other/tiff.c b/converter/other/tiff.c index a498571b..90d50710 100644 --- a/converter/other/tiff.c +++ b/converter/other/tiff.c @@ -6,6 +6,8 @@ ============================================================================*/ +#define _BSD_SOURCE /* Make sure strcaseeq() is in nstring.h */ + #include #ifdef VMS @@ -40,7 +42,7 @@ number(const char * const value, /* It's not a numeric string, so it must be an enumerated value name */ unsigned int i; for (i = 0; tagvallist[i].name; ++i) { - if (STRCASEEQ(value, tagvallist[i].name)) + if (strcaseeq(value, tagvallist[i].name)) return tagvallist[i].value; } pm_error("'%s' is neither a number nor a valid value name", value); @@ -460,7 +462,7 @@ tagDefFind(const char * const name) { for (i = 0; i < ARRAY_SIZE(tagDefinitions) && tagDefinitions[i].name; ++i) { - if (STRCASEEQ(tagDefinitions[i].name, name)) + if (strcaseeq(tagDefinitions[i].name, name)) return &tagDefinitions[i]; } diff --git a/converter/pbm/g3topbm.c b/converter/pbm/g3topbm.c index 1eefee96..261b6c39 100644 --- a/converter/pbm/g3topbm.c +++ b/converter/pbm/g3topbm.c @@ -18,6 +18,8 @@ contributing their work to the public domain. ===========================================================================*/ +#define _BSD_SOURCE /* Make nstring.h define strcaseeq() */ + #include "pbm.h" #include "shhopt.h" #include "nstring.h" @@ -100,15 +102,15 @@ parseCommandLine(int argc, char ** const argv, if (cmdlineP->expectedLineSize < 1) pm_error("-width must be at least 1"); } else if (paper_sizeSpec) { - if (STRCASEEQ(paperSize, "A6")) + if (strcaseeq(paperSize, "A6")) cmdlineP->expectedLineSize = 864; - else if (STRCASEEQ(paperSize, "A5")) + else if (strcaseeq(paperSize, "A5")) cmdlineP->expectedLineSize = 1216; - else if (STRCASEEQ(paperSize, "A4")) + else if (strcaseeq(paperSize, "A4")) cmdlineP->expectedLineSize = 1728; - else if (STRCASEEQ(paperSize, "B4")) + else if (strcaseeq(paperSize, "B4")) cmdlineP->expectedLineSize = 2048; - else if (STRCASEEQ(paperSize, "A3")) + else if (strcaseeq(paperSize, "A3")) cmdlineP->expectedLineSize = 2432; else pm_error("Unrecognized value for -paper_size '%s'. " diff --git a/converter/pbm/pbmtonokia.c b/converter/pbm/pbmtonokia.c index 3c47eac3..26e60358 100644 --- a/converter/pbm/pbmtonokia.c +++ b/converter/pbm/pbmtonokia.c @@ -4,7 +4,7 @@ Copyright information is at end of file. */ -#define _BSD_SOURCE /* Make sure strcasecmp() is in string.h */ +#define _BSD_SOURCE /* Make sure strcaseeq() is in nstring.h */ #include #include @@ -96,17 +96,17 @@ parseCommandLine(int argc, char ** argv, /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (fmtSpec) { - if (STRCASEEQ(fmtOpt, "HEX_NOL")) + if (strcaseeq(fmtOpt, "HEX_NOL")) cmdlineP->outputFormat = FMT_HEX_NOL; - else if (STRCASEEQ(fmtOpt, "HEX_NGG")) + else if (strcaseeq(fmtOpt, "HEX_NGG")) cmdlineP->outputFormat = FMT_HEX_NGG; - else if (STRCASEEQ(fmtOpt, "HEX_NPM")) + else if (strcaseeq(fmtOpt, "HEX_NPM")) cmdlineP->outputFormat = FMT_HEX_NPM; - else if (STRCASEEQ(fmtOpt, "NOL")) + else if (strcaseeq(fmtOpt, "NOL")) cmdlineP->outputFormat = FMT_NOL; - else if (STRCASEEQ(fmtOpt, "NGG")) + else if (strcaseeq(fmtOpt, "NGG")) cmdlineP->outputFormat = FMT_NGG; - else if (STRCASEEQ(fmtOpt, "NPM")) + else if (strcaseeq(fmtOpt, "NPM")) cmdlineP->outputFormat = FMT_NPM; else pm_error("-fmt option must be HEX_NGG, HEX_NOL, HEX_NPM, " diff --git a/converter/ppm/ppmtompeg/param.c b/converter/ppm/ppmtompeg/param.c index c465dce0..502aee5b 100644 --- a/converter/ppm/ppmtompeg/param.c +++ b/converter/ppm/ppmtompeg/param.c @@ -671,66 +671,66 @@ processParamLine(char const input[], switch(input[0]) { case 'A': - if (STRNEQ(input, "ASPECT_RATIO", 12)) { + if (strneq(input, "ASPECT_RATIO", 12)) { aspectRatio = GetAspectRatio(SkipSpacesTabs(&input[12])); optionSeen[OPTION_ASPECT_RATIO] = TRUE; } break; case 'B': - if (STRNEQ(input, "BQSCALE", 7)) { + if (strneq(input, "BQSCALE", 7)) { SetBQScale(atoi(SkipSpacesTabs(&input[7]))); optionSeen[OPTION_BQSCALE] = TRUE; - } else if (STRNEQ(input, "BASE_FILE_FORMAT", 16)) { + } else if (strneq(input, "BASE_FILE_FORMAT", 16)) { const char * arg = SkipSpacesTabs(&input[16]); SetFileFormat(arg); - if (STRNEQ(arg, "YUV", 3) || streq(arg, "Y")) + if (strneq(arg, "YUV", 3) || streq(arg, "Y")) *yuvUsedP = TRUE; optionSeen[OPTION_BASE_FORMAT] = TRUE; - } else if (STRNEQ(input, "BSEARCH_ALG", 11)) { + } else if (strneq(input, "BSEARCH_ALG", 11)) { SetBSearchAlg(SkipSpacesTabs(&input[11])); optionSeen[OPTION_BSEARCH_ALG] = TRUE; - } else if (STRNEQ(input, "BIT_RATE", 8)) { + } else if (strneq(input, "BIT_RATE", 8)) { setBitRate(SkipSpacesTabs(&input[8])); optionSeen[OPTION_BIT_RATE] = TRUE; - } else if (STRNEQ(input, "BUFFER_SIZE", 11)) { + } else if (strneq(input, "BUFFER_SIZE", 11)) { setBufferSize(SkipSpacesTabs(&input[11])); optionSeen[OPTION_BUFFER_SIZE] = TRUE; } break; case 'C': - if (STRNEQ(input, "CDL_FILE", 8)) { + if (strneq(input, "CDL_FILE", 8)) { strcpy(specificsFile, SkipSpacesTabs(&input[8])); specificsOn = TRUE; optionSeen[OPTION_SPECIFICS] = TRUE; - } else if (STRNEQ(input, "CDL_DEFINES", 11)) { + } else if (strneq(input, "CDL_DEFINES", 11)) { strcpy(specificsDefines, SkipSpacesTabs(&input[11])); optionSeen[OPTION_DEFS_SPECIFICS] = TRUE; } break; case 'F': - if (STRNEQ(input, "FRAME_INPUT_DIR", 15)) { + if (strneq(input, "FRAME_INPUT_DIR", 15)) { const char * const arg = SkipSpacesTabs(&input[15]); - if (STRNCASEEQ(arg, "stdin", 5)) + if (strncaseeq(arg, "stdin", 5)) SetStdinInput(frameInputSourceP); strcpy(currentFramePath, arg); - } else if (STRNEQ(input, "FRAME_INPUT", 11)) { + } else if (strneq(input, "FRAME_INPUT", 11)) { ReadInputFileNames(fpointer, "FRAME_END_INPUT", frameInputSourceP->stdinUsed ? NULL : frameInputSourceP); optionSeen[OPTION_FRAME_INPUT] = TRUE; - } else if (STRNEQ(input, "FORCE_I_ALIGN", 13)) { + } else if (strneq(input, "FORCE_I_ALIGN", 13)) { forceIalign = TRUE; - } else if (STRNEQ(input, "FORCE_ENCODE_LAST_FRAME", 23)) { + } else if (strneq(input, "FORCE_ENCODE_LAST_FRAME", 23)) { /* NO-OP. We used to drop trailing B frames by default and you needed this option to change the last frame to I so you could encode all the frames. Now we just do that all the time. Why wouldn't we? */ - } else if (STRNEQ(input, "FRAME_RATE", 10)) { + } else if (strneq(input, "FRAME_RATE", 10)) { frameRate = GetFrameRate(SkipSpacesTabs(&input[10])); frameRateRounded = (int) VidRateNum[frameRate]; if ((frameRate % 3) == 1) @@ -740,21 +740,21 @@ processParamLine(char const input[], break; case 'G': - if (STRNEQ(input, "GOP_SIZE", 8)) { + if (strneq(input, "GOP_SIZE", 8)) { SetGOPSize(atoi(SkipSpacesTabs(&input[8]))); optionSeen[OPTION_GOP] = TRUE; - } else if (STRNEQ(input, "GOP_INPUT_DIR", 13)) { + } else if (strneq(input, "GOP_INPUT_DIR", 13)) { const char * const arg = SkipSpacesTabs(&input[13]); - if (STRNCASEEQ(arg, "stdin", 5)) + if (strncaseeq(arg, "stdin", 5)) SetStdinInput(gopInputSourceP); strcpy(currentGOPPath, arg); - } else if (STRNEQ(input, "GOP_INPUT", 9)) { + } else if (strneq(input, "GOP_INPUT", 9)) { ReadInputFileNames(fpointer, "GOP_END_INPUT", gopInputSourceP->stdinUsed ? NULL : gopInputSourceP); optionSeen[OPTION_GOP_INPUT] = TRUE; - } else if (STRNEQ(input, "GAMMA", 5)) { + } else if (strneq(input, "GAMMA", 5)) { GammaCorrection = TRUE; sscanf(SkipSpacesTabs(&input[5]), "%f", &GammaValue); optionSeen[OPTION_GAMMA] = TRUE; @@ -762,16 +762,16 @@ processParamLine(char const input[], break; case 'I': - if (STRNEQ(input, "IQSCALE", 7)) { + if (strneq(input, "IQSCALE", 7)) { SetIQScale(atoi(SkipSpacesTabs(&input[7]))); optionSeen[OPTION_IQSCALE] = TRUE; - } else if (STRNEQ(input, "INPUT_DIR", 9)) { + } else if (strneq(input, "INPUT_DIR", 9)) { const char * const arg = SkipSpacesTabs(&input[9]); - if (STRNCASEEQ(arg, "stdin", 5)) + if (strncaseeq(arg, "stdin", 5)) SetStdinInput(inputSourceP); strcpy(currentPath, arg); optionSeen[OPTION_INPUT_DIR] = TRUE; - } else if (STRNEQ(input, "INPUT_CONVERT", 13)) { + } else if (strneq(input, "INPUT_CONVERT", 13)) { strcpy(inputConversion, SkipSpacesTabs(&input[13])); optionSeen[OPTION_INPUT_CONVERT] = TRUE; } else if (streq(input, "INPUT")) { @@ -779,10 +779,10 @@ processParamLine(char const input[], inputSourceP->stdinUsed ? NULL : inputSourceP); optionSeen[OPTION_INPUT] = TRUE; - } else if (STRNEQ(input, "IO_SERVER_CONVERT", 17)) { + } else if (strneq(input, "IO_SERVER_CONVERT", 17)) { strcpy(ioConversion, SkipSpacesTabs(&input[17])); optionSeen[OPTION_IO_CONVERT] = TRUE; - } else if (STRNEQ(input, "IQTABLE", 7)) { + } else if (strneq(input, "IQTABLE", 7)) { processIqtable(fpointer); optionSeen[OPTION_IQTABLE] = TRUE; @@ -790,12 +790,12 @@ processParamLine(char const input[], break; case 'K': - if (STRNEQ(input, "KEEP_TEMP_FILES", 15)) + if (strneq(input, "KEEP_TEMP_FILES", 15)) keepTempFiles = TRUE; break; case 'N': - if (STRNEQ(input, "NIQTABLE", 8)) { + if (strneq(input, "NIQTABLE", 8)) { readNiqTable(fpointer); optionSeen[OPTION_NIQTABLE] = TRUE; @@ -803,7 +803,7 @@ processParamLine(char const input[], break; case 'O': - if (STRNEQ(input, "OUTPUT", 6)) { + if (strneq(input, "OUTPUT", 6)) { const char * const arg = SkipSpacesTabs(&input[6]); if ( whichGOP == -1 ) strcpy(outputFileName, arg); @@ -815,45 +815,45 @@ processParamLine(char const input[], break; case 'P': - if (STRNEQ(input, "PATTERN", 7)) { + if (strneq(input, "PATTERN", 7)) { SetFramePattern(SkipSpacesTabs(&input[7])); optionSeen[OPTION_PATTERN] = TRUE; - } else if (STRNEQ(input, "PIXEL", 5)) { + } else if (strneq(input, "PIXEL", 5)) { SetPixelSearch(SkipSpacesTabs(&input[5])); optionSeen[OPTION_PIXEL] = TRUE; - } else if (STRNEQ(input, "PQSCALE", 7)) { + } else if (strneq(input, "PQSCALE", 7)) { SetPQScale(atoi(SkipSpacesTabs(&input[7]))); optionSeen[OPTION_PQSCALE] = TRUE; - } else if (STRNEQ(input, "PSEARCH_ALG", 11)) { + } else if (strneq(input, "PSEARCH_ALG", 11)) { SetPSearchAlg(SkipSpacesTabs(&input[11])); optionSeen[OPTION_PSEARCH_ALG] = TRUE; - } else if (STRNEQ(input, "PARALLEL_TEST_FRAMES", 20)) { + } else if (strneq(input, "PARALLEL_TEST_FRAMES", 20)) { SetParallelPerfect(FALSE); parallelTestFrames = atoi(SkipSpacesTabs(&input[20])); - } else if (STRNEQ(input, "PARALLEL_TIME_CHUNKS", 20)) { + } else if (strneq(input, "PARALLEL_TIME_CHUNKS", 20)) { SetParallelPerfect(FALSE); parallelTimeChunks = atoi(SkipSpacesTabs(&input[20])); - } else if (STRNEQ(input, "PARALLEL_CHUNK_TAPER", 20)) { + } else if (strneq(input, "PARALLEL_CHUNK_TAPER", 20)) { SetParallelPerfect(FALSE); parallelTimeChunks = -1; - } else if (STRNEQ(input, "PARALLEL_PERFECT", 16)) { + } else if (strneq(input, "PARALLEL_PERFECT", 16)) { SetParallelPerfect(TRUE); - } else if (STRNEQ(input, "PARALLEL", 8)) { + } else if (strneq(input, "PARALLEL", 8)) { ReadMachineNames(fpointer); optionSeen[OPTION_PARALLEL] = TRUE; } break; case 'R': - if (STRNEQ(input, "RANGE", 5)) { + if (strneq(input, "RANGE", 5)) { processRanges(SkipSpacesTabs(&input[5])); optionSeen[OPTION_RANGE] = TRUE; - } else if (STRNEQ(input, "REFERENCE_FRAME", 15)) { + } else if (strneq(input, "REFERENCE_FRAME", 15)) { SetReferenceFrameType(SkipSpacesTabs(&input[15])); optionSeen[OPTION_REF_FRAME] = TRUE; - } else if (STRNEQ(input, "RSH", 3)) { + } else if (strneq(input, "RSH", 3)) { SetRemoteShell(SkipSpacesTabs(&input[3])); - } else if (STRNEQ(input, "RESIZE", 6)) { + } else if (strneq(input, "RESIZE", 6)) { const char * const arg = SkipSpacesTabs(&input[6]); sscanf(arg, "%dx%d", &outputWidth, &outputHeight); outputWidth &= ~(DCTSIZE * 2 - 1); @@ -863,22 +863,22 @@ processParamLine(char const input[], break; case 'S': - if (STRNEQ(input, "SLICES_PER_FRAME", 16)) { + if (strneq(input, "SLICES_PER_FRAME", 16)) { SetSlicesPerFrame(atoi(SkipSpacesTabs(&input[16]))); optionSeen[OPTION_SPF] = TRUE; - } else if (STRNEQ(input, "SLAVE_CONVERT", 13)) { + } else if (strneq(input, "SLAVE_CONVERT", 13)) { strcpy(slaveConversion, SkipSpacesTabs(&input[13])); optionSeen[OPTION_SLAVE_CONVERT] = TRUE; - } else if (STRNEQ(input, "SPECIFICS_FILE", 14)) { + } else if (strneq(input, "SPECIFICS_FILE", 14)) { strcpy(specificsFile, SkipSpacesTabs(&input[14])); specificsOn = TRUE; optionSeen[OPTION_SPECIFICS] = TRUE; - } else if (STRNEQ(input, "SPECIFICS_DEFINES", 16)) { + } else if (strneq(input, "SPECIFICS_DEFINES", 16)) { strcpy(specificsDefines, SkipSpacesTabs(&input[17])); optionSeen[OPTION_DEFS_SPECIFICS] = TRUE; - } else if (STRNEQ(input, "SEQUENCE_SIZE", 13)) { + } else if (strneq(input, "SEQUENCE_SIZE", 13)) { mult_seq_headers = atoi(SkipSpacesTabs(&input[13])); - } else if (STRNEQ(input, "SIZE", 4)) { + } else if (strneq(input, "SIZE", 4)) { const char * const arg = SkipSpacesTabs(&input[4]); sscanf(arg, "%dx%d", &yuvWidth, &yuvHeight); realWidth = yuvWidth; @@ -889,42 +889,42 @@ processParamLine(char const input[], break; case 'T': - if (STRNEQ(input, "TUNE", 4)) { + if (strneq(input, "TUNE", 4)) { tuneingOn = TRUE; ParseTuneParam(SkipSpacesTabs(&input[4])); } break; case 'U': - if (STRNEQ(input, "USER_DATA", 9)) { + if (strneq(input, "USER_DATA", 9)) { strcpy(userDataFileName, SkipSpacesTabs(&input[9])); optionSeen[OPTION_USER_DATA] = TRUE; } break; case 'W': - if (STRNEQ(input, "WARN_UNDERFLOW", 14)) + if (strneq(input, "WARN_UNDERFLOW", 14)) paramP->warnUnderflow = TRUE; - if (STRNEQ(input, "WARN_OVERFLOW", 13)) + if (strneq(input, "WARN_OVERFLOW", 13)) paramP->warnOverflow = TRUE; break; case 'Y': - if (STRNEQ(input, "YUV_SIZE", 8)) { + if (strneq(input, "YUV_SIZE", 8)) { const char * const arg = SkipSpacesTabs(&input[8]); sscanf(arg, "%dx%d", &yuvWidth, &yuvHeight); realWidth = yuvWidth; realHeight = yuvHeight; Fsize_Validate(&yuvWidth, &yuvHeight); optionSeen[OPTION_YUV_SIZE] = TRUE; - } else if (STRNEQ(input, "Y_SIZE", 6)) { + } else if (strneq(input, "Y_SIZE", 6)) { const char * const arg = SkipSpacesTabs(&input[6]); sscanf(arg, "%dx%d", &yuvWidth, &yuvHeight); realWidth = yuvWidth; realHeight = yuvHeight; Fsize_Validate(&yuvWidth, &yuvHeight); optionSeen[OPTION_YUV_SIZE] = TRUE; - } else if (STRNEQ(input, "YUV_FORMAT", 10)) { + } else if (strneq(input, "YUV_FORMAT", 10)) { strcpy(yuvConversion, SkipSpacesTabs(&input[10])); optionSeen[OPTION_YUV_FORMAT] = TRUE; } diff --git a/converter/ppm/xvminitoppm.c b/converter/ppm/xvminitoppm.c index 8cea1f9d..e5bdac7d 100644 --- a/converter/ppm/xvminitoppm.c +++ b/converter/ppm/xvminitoppm.c @@ -109,16 +109,16 @@ readXvHeader(FILE * const ifP, getline(ifP, buf, sizeof(buf)); - if (!STRNEQ(buf, "P7 332", 6)) + if (!strneq(buf, "P7 332", 6)) pm_error("Input is not a XV thumbnail picture. It does not " "begin with the characters 'P7 332'."); endOfComments = FALSE; while (!endOfComments) { getline(ifP, buf, sizeof(buf)); - if (STRNEQ(buf, "#END_OF_COMMENTS", 16)) + if (strneq(buf, "#END_OF_COMMENTS", 16)) endOfComments = TRUE; - else if (STRNEQ(buf, "#BUILTIN", 8)) + else if (strneq(buf, "#BUILTIN", 8)) pm_error("This program does not know how to " "convert builtin XV thumbnail pictures"); } diff --git a/editor/pammixinterlace.c b/editor/pammixinterlace.c index 579a8092..f22563f6 100644 --- a/editor/pammixinterlace.c +++ b/editor/pammixinterlace.c @@ -14,6 +14,8 @@ ******************************************************************************/ +#define _BSD_SOURCE /* Make sure strcaseeq() is in nstring.h */ + #include #include "mallocvar.h" @@ -206,7 +208,7 @@ parseCommandLine(int argc, char ** argv, unsigned int i; cmdlineP->filterP = NULL; for (i = 0; i < sizeof filters / sizeof(struct filter); ++i) { - if (STRCASEEQ(filterName, filters[i].name)) { + if (strcaseeq(filterName, filters[i].name)) { cmdlineP->filterP = &filters[i]; break; } diff --git a/editor/ppmcolormask.c b/editor/ppmcolormask.c index 57e5c825..eed64c19 100644 --- a/editor/ppmcolormask.c +++ b/editor/ppmcolormask.c @@ -60,7 +60,7 @@ parseColorOpt(const char * const colorOpt, const char * token; token = strsepN(&cursor, ","); if (token) { - if (STRNEQ(token, "bk:", 3)) { + if (strneq(token, "bk:", 3)) { cmdlineP->maskColor[colorCount].matchType = MATCH_BK; cmdlineP->maskColor[colorCount].u.bkColor = ppm_bk_color_from_name(&token[3]); diff --git a/lib/util/nstring.c b/lib/util/nstring.c index 58500547..1aec2b9d 100644 --- a/lib/util/nstring.c +++ b/lib/util/nstring.c @@ -890,7 +890,7 @@ memmemN(const char * const haystack, const char * p; for (p = haystack; p <= haystack + haystacklen - needlelen; ++p) - if (MEMEQ(p, needle, needlelen)) + if (memeq(p, needle, needlelen)) return p; return NULL; diff --git a/lib/util/nstring.h b/lib/util/nstring.h index 70a53f45..f49c9927 100644 --- a/lib/util/nstring.h +++ b/lib/util/nstring.h @@ -26,20 +26,8 @@ extern "C" { (strncmp((A), (B), sizeof(A))) #define STRSCAT(A,B) \ (strncpy(A+strlen(A), B, sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0') - -#define STREQ(A, B) \ - (strcmp((A), (B)) == 0) -#define STRNEQ(A, B, C) \ - (strncmp((A), (B), (C)) == 0) -#define STRCASEEQ(A, B) \ - (strcasecmp((A), (B)) == 0) -#define STRNCASEEQ(A, B, C) \ - (strncasecmp((A), (B), (C)) == 0) #define STRSEQ(A, B) \ - (strncmp((A), (B), sizeof(A)) == 0) - -#define MEMEQ(A, B, C) \ - (memcmp((A), (B), (C)) == 0) + (streq((A), (B), sizeof(A))) #define MEMSZERO(A) \ bzero((A), sizeof(A)) @@ -51,6 +39,34 @@ streq(const char * const comparand, return strcmp(comparand, comparator) == 0; } +static __inline__ int +strneq(const char * const comparand, + const char * const comparator, + size_t const size) { + + return strncmp(comparand, comparator, size) == 0; +} + +/* The Standard C Library may not declare strcasecmp() if the including + source file doesn't request BSD functions, with _BSD_SOURCE. So + we don't define functions that use strcasecmp() in that case. +*/ +#ifdef _BSD_SOURCE +static __inline__ int +strcaseeq(const char * const comparand, + const char * const comparator) { + + return strcasecmp(comparand, comparator) == 0; +} + +static __inline__ int +strncaseeq(const char * const comparand, + const char * const comparator, + size_t const size) { + + return strncasecmp(comparand, comparator, size) == 0; +} +#endif /* The standard C library routines isdigit(), for some weird diff --git a/other/pamx/window.c b/other/pamx/window.c index 1a6e510b..2eb48241 100644 --- a/other/pamx/window.c +++ b/other/pamx/window.c @@ -6,6 +6,8 @@ See COPYRIGHT file for copyright information. */ +#define _BSD_SOURCE /* Make sure strcaseeq() is in nstring.h */ + #include #include #include @@ -555,7 +557,7 @@ visualClassFromName(const char * const name) { bool found; for (a = 0, found = FALSE; VisualClassName[a].name; ++a) { - if (STRCASEEQ(VisualClassName[a].name, name)) { + if (strcaseeq(VisualClassName[a].name, name)) { /* Check for uniqueness. We special-case StaticGray because we have two spellings but they are unique if we find either. -- cgit 1.4.1