summaryrefslogtreecommitdiff
path: root/src/common/utils.c
blob: 00aed7ee46bd2e102f67338509cc5281d62299f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <string.h>
#include "utils.h"
#include <stdio.h>

void dump(unsigned char *buffer, int num)
{
   int     icnt,jcnt;

   printf("         Hex                                                  ASCII\n");
   printf("         -----------------------------------------------      ----------------");

   for (icnt=0;icnt<num;icnt+=16) {
	printf("\n%p ",&buffer[icnt]);
    for (jcnt=icnt;jcnt<icnt+16;++jcnt) {
	    if (jcnt < num) {
              printf("%02hX ",buffer[jcnt]);
		}  else
              printf("   ");
    }

    printf("  |  ");

	for (jcnt=icnt;jcnt<icnt+16;++jcnt) {
        if (jcnt < num) {
            if (buffer[jcnt] > 31 && buffer[jcnt] < 127)
                   printf("%c",buffer[jcnt]);
               else
                   printf(".");
           }  else
               printf(" ");
       }
   }
   printf("\n");
}


#ifdef _WIN32
char *rindex(char *str, char c)
{
        char *sptr;

        sptr = str;
        while(*sptr)
                ++sptr;
        if (c == '\0')
                return(sptr);
        while(str != sptr)
                if (*sptr-- == c)
                        return(++sptr);
        return(NULL);
}

int strcasecmp(const char *arg1, const char *arg2)
{
  int chk, i;

  if (arg1 == NULL || arg2 == NULL) {
    printf("SYSERR: str_cmp() passed a NULL pointer, %p or %p.\n", arg1, arg2);
    return (0);
  }

  for (i = 0; arg1[i] || arg2[i]; i++)
    if ((chk = LOWER(arg1[i]) - LOWER(arg2[i])) != 0)
      return (chk);	/* not equal */

  return (0);
}

int strncasecmp(const char *arg1, const char *arg2, int n)
{
  int chk, i;

  if (arg1 == NULL || arg2 == NULL) {
    printf("SYSERR: strn_cmp() passed a NULL pointer, %p or %p.\n", arg1, arg2);
    return (0);
  }

  for (i = 0; (arg1[i] || arg2[i]) && (n > 0); i++, n--)
    if ((chk = LOWER(arg1[i]) - LOWER(arg2[i])) != 0)
      return (chk);	/* not equal */

  return (0);
}

void str_upper(char *name)
{

  int len = strlen(name);
  while (len--) {
	if (*name >= 'a' && *name <= 'z')
    	*name -= ('a' - 'A');
     name++;
  }
}

void str_lower(char *name)
{
  int len = strlen(name);

  while (len--) {
	if (*name >= 'A' && *name <= 'Z')
    	*name += ('a' - 'A');
    name++;
  }
}

#endif