Subversion Repositories SvarDOS

Rev

Rev 352 | Rev 388 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 352 Rev 369
1
/*
1
/*
2
 * a variety of helper functions
2
 * a variety of helper functions
3
 * Copyright (C) 2021 Mateusz Viste
3
 * Copyright (C) 2021 Mateusz Viste
4
 */
4
 */
5
 
5
 
6
#include "helpers.h"
6
#include "helpers.h"
7
 
7
 
8
/* case-insensitive comparison of strings, returns non-zero on equality */
8
/* case-insensitive comparison of strings, returns non-zero on equality */
9
int imatch(const char *s1, const char *s2) {
9
int imatch(const char *s1, const char *s2) {
10
  for (;;) {
10
  for (;;) {
11
    char c1, c2;
11
    char c1, c2;
12
    c1 = *s1;
12
    c1 = *s1;
13
    c2 = *s2;
13
    c2 = *s2;
14
    if ((c1 >= 'a') && (c1 <= 'z')) c1 -= ('a' - 'A');
14
    if ((c1 >= 'a') && (c1 <= 'z')) c1 -= ('a' - 'A');
15
    if ((c2 >= 'a') && (c2 <= 'z')) c2 -= ('a' - 'A');
15
    if ((c2 >= 'a') && (c2 <= 'z')) c2 -= ('a' - 'A');
16
    /* */
16
    /* */
17
    if (c1 != c2) return(0);
17
    if (c1 != c2) return(0);
18
    if (c1 == 0) return(1);
18
    if (c1 == 0) return(1);
19
    s1++;
19
    s1++;
20
    s2++;
20
    s2++;
21
  }
21
  }
22
}
22
}
23
 
23
 
24
 
24
 
25
/* returns zero if s1 starts with s2 */
25
/* returns zero if s1 starts with s2 */
26
int strstartswith(const char *s1, const char *s2) {
26
int strstartswith(const char *s1, const char *s2) {
27
  while (*s2 != 0) {
27
  while (*s2 != 0) {
28
    if (*s1 != *s2) return(-1);
28
    if (*s1 != *s2) return(-1);
29
    s1++;
29
    s1++;
30
    s2++;
30
    s2++;
31
  }
31
  }
32
  return(0);
32
  return(0);
33
}
33
}
-
 
34
 
-
 
35
 
-
 
36
/* outputs a NULL-terminated string to stdout */
-
 
37
void output_internal(const char *s, unsigned short nl) {
-
 
38
  _asm {
-
 
39
    mov ah, 0x02 /* AH=9 - write character in DL to stdout */
-
 
40
    mov si, s
-
 
41
    cld          /* clear DF so lodsb increments SI */
-
 
42
    NEXTBYTE:
-
 
43
    lodsb /* load byte from DS:SI into AL, SI++ */
-
 
44
    mov dl, al
-
 
45
    or al, 0  /* is al == 0? */
-
 
46
    jz DONE
-
 
47
    int 0x21
-
 
48
    jmp NEXTBYTE
-
 
49
    DONE:
-
 
50
    or nl, 0
-
 
51
    jz FINITO
-
 
52
    /* print out a CR/LF trailer if nl set */
-
 
53
    mov dl, 0x0D /* CR */
-
 
54
    int 0x21
-
 
55
    mov dl, 0x0A /* LF */
-
 
56
    int 0x21
-
 
57
    FINITO:
-
 
58
  }
-
 
59
}
34
 
60