]> diplodocus.org Git - nmh/blobdiff - sbr/fmt_scan.c
Use HasPrefix() instead of strncmp().
[nmh] / sbr / fmt_scan.c
index 97a4a05a83a78c370eb7b0925f1a0cc0fb6294a3..a47c170e7c78cdabf5b0d51b1818230d38098033 100644 (file)
@@ -49,24 +49,14 @@ match (char *str, char *sub)
     char *s1, *s2;
 
     while ((c1 = *sub)) {
     char *s1, *s2;
 
     while ((c1 = *sub)) {
-       c1 = (isascii((unsigned char) c1) && isalpha((unsigned char) c1) &&
-             isupper((unsigned char) c1)) ? tolower((unsigned char) c1) : c1;
-       while ((c2 = *str++) && c1 != ((isascii((unsigned char) c2) &&
-                                       isalpha((unsigned char) c2) &&
-                                       isupper((unsigned char) c2)) ?
-                                           tolower((unsigned char) c2) : c2))
+       c1 = tolower((unsigned char)c1);
+       while ((c2 = *str++) && c1 != tolower((unsigned char)c2))
            ;
        if (! c2)
            return 0;
        s1 = sub + 1; s2 = str;
            ;
        if (! c2)
            return 0;
        s1 = sub + 1; s2 = str;
-       while ((c1 = *s1++) && ((isascii((unsigned char) c1) &&
-                                isalpha((unsigned char) c1) &&
-                                isupper((unsigned char) c1)) ?
-                                       tolower(c1) : c1) ==
-                       ((isascii((unsigned char) (c2 =*s2++)) &&
-                         isalpha((unsigned char) c2) &&
-                         isupper((unsigned char) c2)) ?
-                               tolower((unsigned char) c2) : c2))
+       while ((c1 = *s1++) &&
+            tolower((unsigned char)c1) == tolower((unsigned char)(c2 = *s2++)))
            ;
        if (! c1)
            return 1;
            ;
        if (! c1)
            return 1;
@@ -696,7 +686,8 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
            if (str) {
                    char *xp;
 
            if (str) {
                    char *xp;
 
-                   strncpy(buffer, str, sizeof(buffer));
+                   if (str != buffer)
+                       strncpy(buffer, str, sizeof(buffer));
                    buffer[sizeof(buffer)-1] = '\0';
                    str = buffer;
                    while (isspace((unsigned char) *str))
                    buffer[sizeof(buffer)-1] = '\0';
                    str = buffer;
                    while (isspace((unsigned char) *str))
@@ -745,6 +736,9 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
        case FT_LV_MINUS_L:
            value = fmt->f_value - value;
            break;
        case FT_LV_MINUS_L:
            value = fmt->f_value - value;
            break;
+       case FT_LV_MULTIPLY_L:
+           value *= fmt->f_value;
+           break;
        case FT_LV_DIVIDE_L:
            if (fmt->f_value)
                value = value / fmt->f_value;
        case FT_LV_DIVIDE_L:
            if (fmt->f_value)
                value = value / fmt->f_value;
@@ -886,7 +880,8 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
                goto unfriendly;
            if ((str = mn->m_pers) == NULL) {
                if ((str = mn->m_note)) {
                goto unfriendly;
            if ((str = mn->m_pers) == NULL) {
                if ((str = mn->m_note)) {
-                   strncpy (buffer, str, sizeof(buffer));
+                   if (str != buffer)
+                       strncpy (buffer, str, sizeof(buffer));
                    buffer[sizeof(buffer)-1] = '\0';
                    str = buffer;
                    if (*str == '(')
                    buffer[sizeof(buffer)-1] = '\0';
                    str = buffer;
                    if (*str == '(')
@@ -930,7 +925,8 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
                /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */
        case FT_LS_UNQUOTE:
            if (str) {          
                /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */
        case FT_LS_UNQUOTE:
            if (str) {          
-               strncpy(buffer, str, sizeof(buffer));
+               if (str != buffer)
+                   strncpy(buffer, str, sizeof(buffer));
                /* strncpy doesn't NUL-terminate if it fills the buffer */
                buffer[sizeof(buffer)-1] = '\0';
                unquote_string(buffer, buffer2);
                /* strncpy doesn't NUL-terminate if it fills the buffer */
                buffer[sizeof(buffer)-1] = '\0';
                unquote_string(buffer, buffer2);
@@ -1179,5 +1175,5 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
        }
     }
 
        }
     }
 
-    return ((struct format *)0);
+    return (NULL);
 }
 }