Subversion Repositories SvarDOS

Rev

Rev 369 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
352 mateuszvis 1
/*
2
 * a variety of helper functions
3
 * Copyright (C) 2021 Mateusz Viste
4
 */
5
 
6
#include "helpers.h"
7
 
8
/* case-insensitive comparison of strings, returns non-zero on equality */
9
int imatch(const char *s1, const char *s2) {
10
  for (;;) {
11
    char c1, c2;
12
    c1 = *s1;
13
    c2 = *s2;
14
    if ((c1 >= 'a') && (c1 <= 'z')) c1 -= ('a' - 'A');
15
    if ((c2 >= 'a') && (c2 <= 'z')) c2 -= ('a' - 'A');
16
    /* */
17
    if (c1 != c2) return(0);
18
    if (c1 == 0) return(1);
19
    s1++;
20
    s2++;
21
  }
22
}
23
 
24
 
25
/* returns zero if s1 starts with s2 */
26
int strstartswith(const char *s1, const char *s2) {
27
  while (*s2 != 0) {
28
    if (*s1 != *s2) return(-1);
29
    s1++;
30
    s2++;
31
  }
32
  return(0);
33
}