mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-02-13 08:58:40 +00:00
fix
This commit is contained in:
parent
4d53adb958
commit
246b77ca08
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
namespace Stdlib {
|
namespace Stdlib {
|
||||||
class AssocArray {
|
class AssocArray {
|
||||||
|
|
@ -38,7 +39,7 @@ namespace Stdlib {
|
||||||
static
|
static
|
||||||
int hash_index(assoc_arr *h, void *key)
|
int hash_index(assoc_arr *h, void *key)
|
||||||
{
|
{
|
||||||
int i = (int) key % h->size;
|
int i = (*((int *) key)) % h->size;
|
||||||
while (h->keys[i] && h->keys[i] != key) {
|
while (h->keys[i] && h->keys[i] != key) {
|
||||||
i = (i + 1) % h->size;
|
i = (i + 1) % h->size;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../Stdlib/AssocArray.h"
|
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
@ -23,19 +22,31 @@ namespace Utils {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static inline
|
static inline
|
||||||
char* get_arg (char *id, Stdlib::AssocArray::assoc_arr *args)
|
char* get_arg (const char *id, char **argv, int length)
|
||||||
{
|
{
|
||||||
if (Utils::StringUtils::is_number(id)) {
|
if (Utils::StringUtils::is_number(id)) {
|
||||||
return (char *) args->values[atoi(id)];
|
return argv[atoi(id)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char *) Stdlib::AssocArray::hash_lookup(args, id);
|
for (int i = 0; i < length - 1; ++i) {
|
||||||
|
if (strcmp(id, argv[i]) == 0) {
|
||||||
|
return argv[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
bool has_arg (char *id, Stdlib::AssocArray::assoc_arr *args)
|
bool has_arg (const char *id, char **argv, int length)
|
||||||
{
|
{
|
||||||
return Stdlib::AssocArray::hash_lookup(args, id) == NULL;
|
for (int i = 0; i < length; ++i) {
|
||||||
|
if (strcmp(id, argv[i]) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Utils {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static inline
|
static inline
|
||||||
bool is_number (char *s)
|
bool is_number (const char *s)
|
||||||
{
|
{
|
||||||
while (*s != '\0') {
|
while (*s != '\0') {
|
||||||
if (!isdigit(*s)) {
|
if (!isdigit(*s)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user