commit b5fc480b547cdab6c622398134a6b59e2eadb8dd
parent 72dcacbcabfbf2364b098b8ee1862319e59e352a
Author: Kyle Milz <krwmilz@gmail.com>
Date: Sat, 11 Mar 2023 18:58:54 +0000
replace memicmp with strncasecmp
Diffstat:
6 files changed, 18 insertions(+), 39 deletions(-)
diff --git a/dvi-draw.c b/dvi-draw.c
@@ -1518,7 +1518,7 @@ hypertex_special(struct geom_info *g_info, const char *in)
struct htex_data *htex_data = g_info->geom_data;
char *str;
- if (memicmp(in, "html:<a href=\"", 14) != 0)
+ if (strncasecmp(in, "html:<a href=\"", 14) != 0)
return;
str = xstrdup(in + 14);
diff --git a/popups.c b/popups.c
@@ -901,7 +901,7 @@ Act_print(Widget w, XEvent *event, String *params, Cardinal *num_params)
if (s == NULL) s = dvi_name;
else ++s;
n = strlen(s);
- if (n >= 4 && memicmp(s + n - 4, ".dvi", 4) == 0) n -= 4;
+ if (n >= 4 && strncasecmp(s + n - 4, ".dvi", 4) == 0) n -= 4;
s2 = xmalloc(n + 4);
memcpy(s2, s, n);
memcpy(s2 + n, ".ps", 4);
diff --git a/special.c b/special.c
@@ -65,7 +65,7 @@ NOTE:
#include "events.h" /* do_color_change() */
#include "special.h"
#include "xdvi.h"
-#include "util.h" /* xmalloc(), memicmp() */
+#include "util.h" /* xmalloc() */
#define rint(x) floor((x) + 0.5)
@@ -605,7 +605,7 @@ parse_color(const char *cp0, const char *cp, struct rgb *rgbp)
while (*cp == ' ')
++cp;
- if (memicmp(cp, "rgb ", 4) == 0) {
+ if (strncasecmp(cp, "rgb ", 4) == 0) {
if (sscanf(cp + 3, "%lf %lf %lf", &r, &g, &b) == 3
&& r >= 0 && r <= 1 && g >= 0 && g <= 1 && b >= 0 && b <= 1) {
rgbp->r = r * 65535 + 0.5;
@@ -615,14 +615,14 @@ parse_color(const char *cp0, const char *cp, struct rgb *rgbp)
return True;
}
}
- else if (memicmp(cp, "gray ", 5) == 0) {
+ else if (strncasecmp(cp, "gray ", 5) == 0) {
if (sscanf(cp + 4, "%lf", &r) == 1 && r >= 0 && r <= 1) {
rgbp->r = rgbp->g = rgbp->b = r * 65535 + 0.5;
reverse_color(rgbp);
return True;
}
}
- else if (memicmp(cp, "cmyk ", 5) == 0) {
+ else if (strncasecmp(cp, "cmyk ", 5) == 0) {
double k;
if (sscanf(cp + 4, "%lf %lf %lf %lf", &r, &g, &b, &k) == 4
@@ -638,7 +638,7 @@ parse_color(const char *cp0, const char *cp, struct rgb *rgbp)
return True;
}
}
- else if (memicmp(cp, "hsb ", 4) == 0) {
+ else if (strncasecmp(cp, "hsb ", 4) == 0) {
double hue, sat, bri;
if (sscanf(cp + 3, "%lf %lf %lf", &hue, &sat, &bri) == 3 && hue >= 0
@@ -762,7 +762,7 @@ scan_color(const char *cp)
if (page_colors == NULL)
init_page_colors();
- if (memicmp(cp1, "push ", 5) == 0) {
+ if (strncasecmp(cp1, "push ", 5) == 0) {
if (scanstack_current->next == NULL) { /* if at end */
scanstack_current->next = xmalloc(sizeof *scanstack_current);
scanstack_current->next->prev = scanstack_current;
@@ -773,7 +773,7 @@ scan_color(const char *cp)
if (!parse_color(cp, cp1 + 5, &scanstack_current->color))
scanstack_current->color = scanstack_current->prev->color;
}
- else if (memicmp(cp1, "pop", 3) == 0) {
+ else if (strncasecmp(cp1, "pop", 3) == 0) {
if (scanstack_len <= 1) {
warnx("Color pop occurred with empty color stack.");
}
@@ -901,7 +901,7 @@ color_special(const char *cp)
while (*cp == ' ') ++cp;
- if (memicmp(cp, "push ", 5) == 0) {
+ if (strncasecmp(cp, "push ", 5) == 0) {
if (rcs_top == NULL) {
if (rcs_head == NULL) {
rcs_head = xmalloc(sizeof *rcs_head);
@@ -928,7 +928,7 @@ color_special(const char *cp)
}
set_fg_color(&rcs_top->color);
}
- else if (memicmp(cp, "pop", 3) == 0) {
+ else if (strncasecmp(cp, "pop", 3) == 0) {
/* Pop stack */
if (rcs_top != NULL) {
if (color_bot_size > 0)
@@ -1126,7 +1126,7 @@ applicationDoSpecial(char *cp)
++cp;
}
- if (memicmp(cp, "color ", 6) == 0) {
+ if (strncasecmp(cp, "color ", 6) == 0) {
color_special(cp + 6);
return;
}
@@ -1134,11 +1134,11 @@ applicationDoSpecial(char *cp)
/* these should have been scanned */
if (*cp == '!' ||
- (memicmp(cp, "header", 6) == 0 && endofcommand(cp + 6) != NULL)) {
+ (strncasecmp(cp, "header", 6) == 0 && endofcommand(cp + 6) != NULL)) {
return;
}
- if (memicmp(cp, "background ", 11) == 0) {
+ if (strncasecmp(cp, "background ", 11) == 0) {
if (resource._use_color && scanned_page_reset >= 0) {
/* turn on scanning and redraw the page */
scanned_page = scanned_page_color =
@@ -1183,7 +1183,7 @@ applicationDoSpecial(char *cp)
}
/* We support hypertex */
- if (memicmp(cp, "html: ", 5) == 0)
+ if (strncasecmp(cp, "html: ", 5) == 0)
return;
warnx("special '%s' not implemented", cp);
@@ -1207,11 +1207,11 @@ scan_special(char *cp)
while (isspace(*cp)) ++cp;
}
- if (memicmp(cp, "background ", 11) == 0) {
+ if (strncasecmp(cp, "background ", 11) == 0) {
scan_bg_color(cp);
return;
}
- else if (memicmp(cp, "color ", 6) == 0) {
+ else if (strncasecmp(cp, "color ", 6) == 0) {
scan_color(cp);
return;
}
diff --git a/util.c b/util.c
@@ -144,26 +144,6 @@ xputenv(const char *var, const char *value)
/*
- * Hopefully a self-explanatory name. This code assumes the second
- * argument is lower case.
- */
-
-int
-memicmp(const char *s1, const char *s2, size_t n)
-{
- while (n > 0) {
- int i = tolower(*s1) - *s2;
- if (i != 0) return i;
- ++s1;
- ++s2;
- --n;
- }
- return 0;
-}
-
-
-
-/*
* Open a file in the given mode.
*/
diff --git a/util.h b/util.h
@@ -18,7 +18,6 @@ struct avl *avladd(const char *, size_t, struct avl **, size_t);
void expandline(size_t);
const struct passwd *ff_getpw(const char **, const char *);
-int memicmp(const char *, const char *, size_t);
void prep_fd(int, Boolean);
FILE *xfopen(const char *, const char *);
diff --git a/xdvi.c b/xdvi.c
@@ -77,7 +77,7 @@ NOTE:
#include "dvi-draw.h" /* prescan() */
#include "events.h" /* compile_action(), ... */
#include "font-open.h" /* init_font_open() */
-#include "util.h" /* xmalloc(), memicmp() */
+#include "util.h" /* xmalloc() */
#include "version.h"
#include "xdvi.h"
#include "xdvi.icon"