diff --git a/tools/ScriptQuestReleaseTracker/hashset.c b/tools/ScriptQuestReleaseTracker/hashset.c deleted file mode 100644 index 71300f69f2..0000000000 --- a/tools/ScriptQuestReleaseTracker/hashset.c +++ /dev/null @@ -1,238 +0,0 @@ -#include -#include -#include - -//NOTE: should the HASH_MAXITEM or HASH_NUMBUCK value be too small, program will crash by SIG_SEGV -#define HASH_MAXITEM 4000 -#define HASH_NUMBUCK 1340 -#define HASH_HIVALUE 2147483647 //32-BIT integer - -#define HASH_REHTHRE 3.5 -#define HASH_REHRATE 5 - -typedef struct { - int list[HASH_MAXITEM]; - int first; - - unsigned int count; -} HastSetIndex; - -typedef struct { - HastSetIndex **table; - int *list; - - unsigned int threshold; - unsigned int length; - unsigned int count; -} HashSet; - -void hashset_create_table(HashSet *hs) { - hs->table = (HastSetIndex **)malloc(hs->length * sizeof(HastSetIndex *)); - hs->threshold = (unsigned int)(HASH_REHTHRE * hs->length); - - unsigned int i; - for(i = 0; i < hs->length; i++) { - hs->table[i] = (HastSetIndex *)malloc(sizeof(HastSetIndex)); - hs->table[i]->count = 0; - hs->table[i]->first = HASH_HIVALUE; - } -} - -HashSet* hashset_create() { - HashSet *hs = (HashSet *)malloc(sizeof(HashSet)); - hs->count = 0; - hs->length = HASH_NUMBUCK; - hs->list = NULL; - - hashset_create_table(hs); - return(hs); -} - -void hashset_destroy(HashSet *hs) { - if(hs->list != NULL) { - free(hs->list); - } - - unsigned int i; - for(i = 0; i < hs->length; i++) - free(hs->table[i]); - - free(hs->table); - free(hs); -} - -unsigned int hashset_maptable(HashSet *hs, int item) { - return(item % hs->length); -} - -unsigned int hashset_slot(HashSet *hs, int item, unsigned int *bucket) { - *bucket = hashset_maptable(hs, item); - - unsigned int i; - for(i = 0; i < hs->table[*bucket]->count; i++) { - if(hs->table[*bucket]->list[i] == item) - return(i); - } - - return(-1); -} - -short hashset_contains(HashSet *hs, int item, unsigned int *bucket) { - return(hashset_slot(hs, item, bucket) != -1); -} - -short hashset_insertinto(HashSet *hs, int item) { - unsigned int bucket; - - if(!hashset_contains(hs, item, &bucket)) { - if(hs->table[bucket]->first > item) - hs->table[bucket]->first = item; - - hs->table[bucket]->list[hs->table[bucket]->count] = item; - - (hs->count)++; - (hs->table[bucket]->count)++; - if(hs->table[bucket]->count > hs->threshold) return(1); - } - - return(0); -} - -void hashset_rehash(HashSet *hs) { - int *temp = (int *)malloc(hs->count * sizeof(int)); - unsigned int temp_cursor = 0, i, j; - - for(i = 0; i < hs->length; i++) { - for(j = 0; j < hs->table[i]->count; j++) { - temp[temp_cursor] = hs->table[i]->list[j]; - temp_cursor++; - } - } - - for(i = 0; i < hs->length; i++) - free(hs->table[i]); - free(hs->table); - - hs->count = 0; - hs->length *= HASH_REHRATE; - hashset_create_table(hs); - - for(i = 0; i < temp_cursor; i++) - hashset_insertinto(hs, temp[i]); - - free(temp); -} - -void hashset_insert(HashSet *hs, int item) { - if(hashset_insertinto(hs, item)) { - hashset_rehash(hs); - } -} - -int hashset_recalc_first(HashSet *hs, int bucket) { - int i, val = HASH_HIVALUE; - for(i = 0; i < hs->table[bucket]->count; i++) { - if(val > hs->table[bucket]->list[i]) - val = hs->table[bucket]->list[i]; - } - - return(val); -} - -void hashset_remove(HashSet *hs, int item) { - unsigned int bucket; - unsigned int slot = hashset_slot(hs, item, &bucket); - - if(slot != -1) { - (hs->count)--; - (hs->table[bucket]->count)--; - hs->table[bucket]->list[slot] = hs->table[bucket]->list[hs->table[bucket]->count]; - - if(item == hs->table[bucket]->first) - hs->table[bucket]->first = hashset_recalc_first(hs, bucket); - } -} - -short hashset_is_empty(HashSet *hs) { - return(hs->count == 0); -} - -void hashset_make_empty(HashSet *hs) { - unsigned int i; - for(i = 0; i < hs->length; i++) { - hs->table[i]->first = HASH_HIVALUE; - hs->table[i]->count = 0; - } - - hs->count = 0; -} - -int hashset_remove_first(HashSet *hs) { - int i, take = HASH_HIVALUE; - for(i = 0; i < hs->length; i++) { - if(take > hs->table[i]->first) - take = hs->table[i]->first; - } - - hashset_remove(hs, take); - return(take); -} - -void hashset_merge(HashSet *hs1, HashSet *hs2) { - //add values from hs2 to hs1 - - unsigned int i, j; - for(i = 0; i < hs2->length; i++) { - for(j = 0; j < hs2->table[i]->count; j++) { - hashset_insert(hs1, hs2->table[i]->list[j]); - } - } -} - -void hashset_dump(HashSet *hs) { - printf("HASHSET v1.0 -- count: %d, buckets: %d, threshold: %d\n", hs->count, hs->length, hs->threshold); - - unsigned int i, j; - for(i = 0; i < hs->length; i++) { - printf("\n%d -> ", i); - for(j = 0; j < hs->table[i]->count; j++) { - printf("%d ", hs->table[i]->list[j]); - } - printf("$"); - } - printf("\n"); -} - -int* hashset_list(HashSet *hs) { - int *list = hs->list; - if(list != NULL) { - free(list); - } - - list = (int *)malloc(hs->count * sizeof(int)); - - unsigned int i, j, k = 0; - for(i = 0; i < hs->length; i++) { - for(j = 0; j < hs->table[i]->count; j++) { - list[k] = hs->table[i]->list[j]; - k++; - } - } - - return list; -} - -/* - HASHSET: - - HashSet* hashset_create(); - void hashset_destroy(HashSet *hs); - short hashset_contains(HashSet *hs, int item, unsigned int *bucket); - void hashset_insert(HashSet *hs, int item); - void hashset_remove(HashSet *hs, int item); - short hashset_is_empty(HashSet *hs); - void hashset_make_empty(HashSet *hs); - int hashset_remove_first(HashSet *hs); - void hashset_merge(HashSet *hs1, HashSet *hs2); - void hashset_dump(HashSet *hs); -*/ diff --git a/tools/ScriptQuestReleaseTracker/pcre3.dll b/tools/ScriptQuestReleaseTracker/pcre3.dll deleted file mode 100644 index b5fd2a6378..0000000000 Binary files a/tools/ScriptQuestReleaseTracker/pcre3.dll and /dev/null differ diff --git a/tools/ScriptQuestReleaseTracker/quest_diff.c b/tools/ScriptQuestReleaseTracker/quest_diff.c deleted file mode 100644 index 6e842924ea..0000000000 --- a/tools/ScriptQuestReleaseTracker/quest_diff.c +++ /dev/null @@ -1,85 +0,0 @@ -#include - -// string hash version by chqrlie - https://stackoverflow.com/questions/20462826/hash-function-for-strings-in-c -unsigned int strhash(const char *word) { - unsigned int hash = 0, c; - - size_t i = 0; - for (i = 0; word[i] != '\0'; i++) { - c = (unsigned char)word[i]; - hash = (hash << 3) + (hash >> (sizeof(hash) * CHAR_BIT - 3)) + c; - } - return hash % UINT_MAX; -} - -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include "strmap.h" -#include "hashset.c" - -void performQuestDiff(ScriptedQuestList *quests_then, ScriptedQuestList *quests_curr) { - char buf[100], bufhash[100]; - HashSet *script_quests = hashset_create(); - - // bookkeep quest-script hash - StrMap *sm = sm_new(2000); - - // insert ongoing scripts - resetScriptedQuestCursor(quests_curr); - while(true) { - ScriptedQuest *method = readScriptedQuest(quests_curr); - if (method == NULL) { - break; - } - - int hash_quest = strhash(method->name); - sprintf(bufhash, "%d", hash_quest); - - sm_put(sm, bufhash, method->name); - hashset_insert(script_quests, hash_quest); - } - - // remove initial scripts - resetScriptedQuestCursor(quests_then); - while(true) { - ScriptedQuest *method = readScriptedQuest(quests_then); - if (method == NULL) { - break; - } - - int hash_quest = strhash(method->name); - hashset_remove(script_quests, hash_quest); - } - - int *list = hashset_list(script_quests); - int i; - for (i = 0; i < script_quests->count; i++) { - int hash_quest = list[i]; - sprintf(bufhash, "%d", hash_quest); - - // dump ongoing script releases - sm_get(sm, bufhash, buf, sizeof(buf)); - printf("%s\n", buf); - } - - sm_delete(sm); - hashset_destroy(script_quests); -} diff --git a/tools/ScriptQuestReleaseTracker/quest_diff.h b/tools/ScriptQuestReleaseTracker/quest_diff.h deleted file mode 100644 index 9911d581cc..0000000000 --- a/tools/ScriptQuestReleaseTracker/quest_diff.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef QUEST_DIFF_H_ -#define QUEST_DIFF_H_ - -void performQuestDiff(ScriptedQuestList *quests_then, ScriptedQuestList *quests_curr); - -#include "quest_diff.c" - -#endif /* QUEST_DIFF_H_ */ diff --git a/tools/ScriptQuestReleaseTracker/quest_list.c b/tools/ScriptQuestReleaseTracker/quest_list.c deleted file mode 100644 index 758bc64ab5..0000000000 --- a/tools/ScriptQuestReleaseTracker/quest_list.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -ScriptedQuest* createScriptedQuest(const char *name) { - ScriptedQuest* method = (ScriptedQuest *)malloc(sizeof(ScriptedQuest)); - method->name = (char *)malloc((strlen(name) + 1) * sizeof(char)); - strcpy(method->name, name); - return method; -} - -void freeScriptedQuest(ScriptedQuest *method) { - free(method->name); - free(method); -} - -ScriptedQuestList createScriptedQuestList() { - ScriptedQuestList list; - list.size = 0; - - ScriptedQuestListItem *item = (ScriptedQuestListItem *)malloc(sizeof(ScriptedQuestListItem)); - item->prox = NULL; - - list.last = item; - list.first = list.last; - - return list; -} - -void insertScriptedQuest(ScriptedQuestList *list, ScriptedQuest *method) { - ScriptedQuestListItem *item = (ScriptedQuestListItem *)malloc(sizeof(ScriptedQuestListItem)); - item->prox = NULL; - - list->last->method = method; - list->last->prox = item; - - list->last = item; - list->size++; -} - -void freeScriptedQuestList(ScriptedQuestList *list) { - ScriptedQuestListItem *aux = list->first; - - list->first = list->last; - list->size = 0; - - while (aux->prox != NULL) { - ScriptedQuestListItem *aux2 = aux; - aux = aux->prox; - - freeScriptedQuest(aux2->method); - free(aux2); - } - free(aux); -} - -void resetScriptedQuestCursor(ScriptedQuestList *list) { - list->cursor = list->first; -} - -ScriptedQuest* readScriptedQuest(ScriptedQuestList *list) { - ScriptedQuestListItem *aux = list->cursor; - if (aux->prox == NULL) { - return NULL; - } - - list->cursor = aux->prox; - return aux->method; -} diff --git a/tools/ScriptQuestReleaseTracker/quest_list.h b/tools/ScriptQuestReleaseTracker/quest_list.h deleted file mode 100644 index 4d6b91ef3b..0000000000 --- a/tools/ScriptQuestReleaseTracker/quest_list.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef QUEST_LIST_H_ -#define QUEST_LIST_H_ - -typedef struct { - char *name; -} ScriptedQuest; - -typedef struct ScriptedQuestListItem { - ScriptedQuest *method; - struct ScriptedQuestListItem *prox; -} ScriptedQuestListItem; - -typedef struct { - ScriptedQuestListItem *first; - ScriptedQuestListItem *last; - ScriptedQuestListItem *cursor; - - int size; -} ScriptedQuestList; - -#include "quest_list.c" - -#endif /* QUEST_LIST_H_ */ diff --git a/tools/ScriptQuestReleaseTracker/script_tracker.c b/tools/ScriptQuestReleaseTracker/script_tracker.c deleted file mode 100644 index 4a1bb71fe0..0000000000 --- a/tools/ScriptQuestReleaseTracker/script_tracker.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include - -#include "strmap.c" -#include "quest_list.h" -#include "quest_diff.h" - -ScriptedQuestList getBestSubstringsFromStringList(char *aStrRegex, ScriptedQuestList *lines, int lines_size) { - ScriptedQuestList ret = createScriptedQuestList(); - - // ------------ an adaptation from Mitch Richling's https://www.mitchr.me/SS/exampleCode/AUPG/pcre_example.c.html ----------- - - int subStrVec[30]; - int subStrVecLength = 30; - const char *pcreErrorStr; - int pcreErrorOffset; - - pcre *reCompiled = pcre_compile(aStrRegex, 0, &pcreErrorStr, &pcreErrorOffset, NULL); - if(reCompiled == NULL) { - printf("ERROR: Could not compile '%s': %s\n", aStrRegex, pcreErrorStr); - return ret; - } - - pcre_extra *pcreExtra = pcre_study(reCompiled, 0, &pcreErrorStr); - if(pcreErrorStr != NULL) { - printf("ERROR: Could not study '%s': %s\n", aStrRegex, pcreErrorStr); - return ret; - } - - int i; - for (i = 0; i < lines_size; i++) { - ScriptedQuestList list = lines[i]; - - resetScriptedQuestCursor(&list); - while(true) { - ScriptedQuest *method = readScriptedQuest(&list); - if (method == NULL) { - break; - } - - char *str = method->name; - int st = 0, en = strlen(str); - while(st < en) { - int pcreExecRet = pcre_exec(reCompiled, pcreExtra, str, en, st, 0, subStrVec, subStrVecLength); - if(pcreExecRet < 0) { - switch(pcreExecRet) { - //case PCRE_ERROR_NOMATCH : printf("String did not match the pattern\n"); break; - case PCRE_ERROR_NULL : printf("Something was null\n"); break; - case PCRE_ERROR_BADOPTION : printf("A bad option was passed\n"); break; - case PCRE_ERROR_BADMAGIC : printf("Magic number bad (compiled re corrupt?)\n"); break; - case PCRE_ERROR_UNKNOWN_NODE : printf("Something kooky in the compiled re\n"); break; - case PCRE_ERROR_NOMEMORY : printf("Ran out of memory\n"); break; - //default : printf("Unknown error\n"); break; - } - - break; - } else { - if(pcreExecRet == 0) { - printf("But too many substrings were found to fit in subStrVec!\n"); - // Set rc to the max number of substring matches possible. - pcreExecRet = 30 / 3; - } - - const char *psubStrMatchStr; - pcre_get_substring(str, subStrVec, pcreExecRet, 1, &(psubStrMatchStr)); - - insertScriptedQuest(&ret, createScriptedQuest(psubStrMatchStr)); - pcre_free_substring(psubStrMatchStr); - - st = subStrVec[1]; - } - } - } - } - - pcre_free(reCompiled); - - if(pcreExtra != NULL) { - pcre_free(pcreExtra); - } - - return ret; -} - -char *getContentFromFile(FILE *f) { - fseek(f, 0, SEEK_END); // implemented by user529758 @ StackOverflow - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); /* same as rewind(f); */ - - char *string = malloc(fsize + 1); - fread(string, 1, fsize, f); - - string[fsize] = 0; - return string; -} - -ScriptedQuestList readQuestXml(char *file_path) { - ScriptedQuestList *file_content = (ScriptedQuestList *)malloc(sizeof(ScriptedQuestList)); - file_content[0] = createScriptedQuestList(); - - FILE *f = fopen(file_path, "r+t"); - char *content = getContentFromFile(f); - - char *tok = strtok(content, "\n"); - int i = 0; - while (tok != NULL) { - insertScriptedQuest(&(file_content[0]), createScriptedQuest(tok)); - tok = strtok(NULL, "\n"); - i++; - } - - free(content); - fclose(f); - - ScriptedQuestList ret = getBestSubstringsFromStringList("script\" value=\"(.+)\"", file_content, 1); - - freeScriptedQuestList(&file_content[0]); - free(file_content); - - return ret; -} - -void trackScriptQuestReleases() { - ScriptedQuestList quests_then = readQuestXml("Check2.img.xml"); - ScriptedQuestList quests_curr = readQuestXml("Check.img.xml"); - - performQuestDiff(&quests_then, &quests_curr); - - freeScriptedQuestList(&quests_curr); - freeScriptedQuestList(&quests_then); -} - -int main() { - trackScriptQuestReleases(); - return 0; -} diff --git a/tools/ScriptQuestReleaseTracker/strmap.c b/tools/ScriptQuestReleaseTracker/strmap.c deleted file mode 100644 index 6111209abe..0000000000 --- a/tools/ScriptQuestReleaseTracker/strmap.c +++ /dev/null @@ -1,515 +0,0 @@ -/* - * strmap version 2.0.1 - * - * ANSI C hash table for strings. - * - * Version history: - * 1.0.0 - initial release - * 2.0.0 - changed function prefix from strmap to sm to ensure - * ANSI C compatibility - * 2.0.1 - improved documentation - * - * strmap.c - * - * Copyright (c) 2009, 2011, 2013 Per Ola Kristensson. - * - * Per Ola Kristensson - * Inference Group, Department of Physics - * University of Cambridge - * Cavendish Laboratory - * JJ Thomson Avenue - * CB3 0HE Cambridge - * United Kingdom - * - * strmap is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * strmap is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with strmap. If not, see . - */ -#include "strmap.h" - -typedef struct Pair Pair; - -typedef struct Bucket Bucket; - -struct Pair { - char *key; - char *value; -}; - -struct Bucket { - unsigned int count; - Pair *pairs; -}; - -struct StrMap { - unsigned int count; - Bucket *buckets; -}; - -static Pair * get_pair(Bucket *bucket, const char *key); -static unsigned long hash(const char *str); - -StrMap * sm_new(unsigned int capacity) -{ - StrMap *map; - - map = malloc(sizeof(StrMap)); - if (map == NULL) { - return NULL; - } - map->count = capacity; - map->buckets = malloc(map->count * sizeof(Bucket)); - if (map->buckets == NULL) { - free(map); - return NULL; - } - memset(map->buckets, 0, map->count * sizeof(Bucket)); - return map; -} - -void sm_delete(StrMap *map) -{ - unsigned int i, j, n, m; - Bucket *bucket; - Pair *pair; - - if (map == NULL) { - return; - } - n = map->count; - bucket = map->buckets; - i = 0; - while (i < n) { - m = bucket->count; - pair = bucket->pairs; - j = 0; - while(j < m) { - free(pair->key); - free(pair->value); - pair++; - j++; - } - free(bucket->pairs); - bucket++; - i++; - } - free(map->buckets); - free(map); -} - -int sm_get(const StrMap *map, const char *key, char *out_buf, unsigned int n_out_buf) -{ - unsigned int index; - Bucket *bucket; - Pair *pair; - - if (map == NULL) { - return 0; - } - if (key == NULL) { - return 0; - } - index = hash(key) % map->count; - bucket = &(map->buckets[index]); - pair = get_pair(bucket, key); - if (pair == NULL) { - return 0; - } - if (out_buf == NULL && n_out_buf == 0) { - return strlen(pair->value) + 1; - } - if (out_buf == NULL) { - return 0; - } - if (strlen(pair->value) >= n_out_buf) { - return 0; - } - strcpy(out_buf, pair->value); - return 1; -} - -int sm_exists(const StrMap *map, const char *key) -{ - unsigned int index; - Bucket *bucket; - Pair *pair; - - if (map == NULL) { - return 0; - } - if (key == NULL) { - return 0; - } - index = hash(key) % map->count; - bucket = &(map->buckets[index]); - pair = get_pair(bucket, key); - if (pair == NULL) { - return 0; - } - return 1; -} - -int sm_put(StrMap *map, const char *key, const char *value) -{ - unsigned int key_len, value_len, index; - Bucket *bucket; - Pair *tmp_pairs, *pair; - char *tmp_value; - char *new_key, *new_value; - - if (map == NULL) { - return 0; - } - if (key == NULL || value == NULL) { - return 0; - } - key_len = strlen(key); - value_len = strlen(value); - /* Get a pointer to the bucket the key string hashes to */ - index = hash(key) % map->count; - bucket = &(map->buckets[index]); - /* Check if we can handle insertion by simply replacing - * an existing value in a key-value pair in the bucket. - */ - if ((pair = get_pair(bucket, key)) != NULL) { - /* The bucket contains a pair that matches the provided key, - * change the value for that pair to the new value. - */ - if (strlen(pair->value) < value_len) { - /* If the new value is larger than the old value, re-allocate - * space for the new larger value. - */ - tmp_value = realloc(pair->value, (value_len + 1) * sizeof(char)); - if (tmp_value == NULL) { - return 0; - } - pair->value = tmp_value; - } - /* Copy the new value into the pair that matches the key */ - strcpy(pair->value, value); - return 1; - } - /* Allocate space for a new key and value */ - new_key = malloc((key_len + 1) * sizeof(char)); - if (new_key == NULL) { - return 0; - } - new_value = malloc((value_len + 1) * sizeof(char)); - if (new_value == NULL) { - free(new_key); - return 0; - } - /* Create a key-value pair */ - if (bucket->count == 0) { - /* The bucket is empty, lazily allocate space for a single - * key-value pair. - */ - bucket->pairs = malloc(sizeof(Pair)); - if (bucket->pairs == NULL) { - free(new_key); - free(new_value); - return 0; - } - bucket->count = 1; - } - else { - /* The bucket wasn't empty but no pair existed that matches the provided - * key, so create a new key-value pair. - */ - tmp_pairs = realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair)); - if (tmp_pairs == NULL) { - free(new_key); - free(new_value); - return 0; - } - bucket->pairs = tmp_pairs; - bucket->count++; - } - /* Get the last pair in the chain for the bucket */ - pair = &(bucket->pairs[bucket->count - 1]); - pair->key = new_key; - pair->value = new_value; - /* Copy the key and its value into the key-value pair */ - strcpy(pair->key, key); - strcpy(pair->value, value); - return 1; -} - -int sm_get_count(const StrMap *map) -{ - unsigned int i, j, n, m; - unsigned int count; - Bucket *bucket; - Pair *pair; - - if (map == NULL) { - return 0; - } - bucket = map->buckets; - n = map->count; - i = 0; - count = 0; - while (i < n) { - pair = bucket->pairs; - m = bucket->count; - j = 0; - while (j < m) { - count++; - pair++; - j++; - } - bucket++; - i++; - } - return count; -} - -int sm_enum(const StrMap *map, sm_enum_func enum_func, const void *obj) -{ - unsigned int i, j, n, m; - Bucket *bucket; - Pair *pair; - - if (map == NULL) { - return 0; - } - if (enum_func == NULL) { - return 0; - } - bucket = map->buckets; - n = map->count; - i = 0; - while (i < n) { - pair = bucket->pairs; - m = bucket->count; - j = 0; - while (j < m) { - enum_func(pair->key, pair->value, obj); - pair++; - j++; - } - bucket++; - i++; - } - return 1; -} - -/* - * Returns a pair from the bucket that matches the provided key, - * or null if no such pair exist. - */ -static Pair * get_pair(Bucket *bucket, const char *key) -{ - unsigned int i, n; - Pair *pair; - - n = bucket->count; - if (n == 0) { - return NULL; - } - pair = bucket->pairs; - i = 0; - while (i < n) { - if (pair->key != NULL && pair->value != NULL) { - if (strcmp(pair->key, key) == 0) { - return pair; - } - } - pair++; - i++; - } - return NULL; -} - -/* - * Returns a hash code for the provided string. - */ -static unsigned long hash(const char *str) -{ - unsigned long hash = 5381; - int c; - - while (c = *str++) { - hash = ((hash << 5) + hash) + c; - } - return hash; -} - -/* - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - -*/ \ No newline at end of file diff --git a/tools/ScriptQuestReleaseTracker/strmap.h b/tools/ScriptQuestReleaseTracker/strmap.h deleted file mode 100644 index 66118af39e..0000000000 --- a/tools/ScriptQuestReleaseTracker/strmap.h +++ /dev/null @@ -1,356 +0,0 @@ -/* - * strmap version 2.0.1 - * - * ANSI C hash table for strings. - * - * Version history: - * 1.0.0 - initial release - * 2.0.0 - changed function prefix from strmap to sm to ensure - * ANSI C compatibility - * 2.0.1 - improved documentation - * - * strmap.h - * - * Copyright (c) 2009, 2011, 2013 Per Ola Kristensson. - * - * Per Ola Kristensson - * Inference Group, Department of Physics - * University of Cambridge - * Cavendish Laboratory - * JJ Thomson Avenue - * CB3 0HE Cambridge - * United Kingdom - * - * strmap is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * strmap is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with strmap. If not, see . - */ -#ifndef _STRMAP_H_ -#define _STRMAP_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include - -typedef struct StrMap StrMap; - -/* - * This callback function is called once per key-value when iterating over - * all keys associated to values. - * - * Parameters: - * - * key: A pointer to a null-terminated C string. The string must not - * be modified. - * - * value: A pointer to a null-terminated C string. The string must - * not be modified. - * - * obj: A pointer to a client-specific object. This parameter may be - * null. - * - * Return value: None. - */ -typedef void(*sm_enum_func)(const char *key, const char *value, const void *obj); - -/* - * Creates a string map. - * - * Parameters: - * - * capacity: The number of top-level slots this string map - * should allocate. This parameter must be > 0. - * - * Return value: A pointer to a string map object, - * or null if a new string map could not be allocated. - */ -StrMap * sm_new(unsigned int capacity); - -/* - * Releases all memory held by a string map object. - * - * Parameters: - * - * map: A pointer to a string map. This parameter cannot be null. - * If the supplied string map has been previously released, the - * behaviour of this function is undefined. - * - * Return value: None. - */ -void sm_delete(StrMap *map); - -/* - * Returns the value associated with the supplied key. - * - * Parameters: - * - * map: A pointer to a string map. This parameter cannot be null. - * - * key: A pointer to a null-terminated C string. This parameter cannot - * be null. - * - * out_buf: A pointer to an output buffer which will contain the value, - * if it exists and fits into the buffer. - * - * n_out_buf: The size of the output buffer in bytes. - * - * Return value: If out_buf is set to null and n_out_buf is set to 0 the return - * value will be the number of bytes required to store the value (if it exists) - * and its null-terminator. For all other parameter configurations the return value - * is 1 if an associated value was found and completely copied into the output buffer, - * 0 otherwise. - */ -int sm_get(const StrMap *map, const char *key, char *out_buf, unsigned int n_out_buf); - -/* - * Queries the existence of a key. - * - * Parameters: - * - * map: A pointer to a string map. This parameter cannot be null. - * - * key: A pointer to a null-terminated C string. This parameter cannot - * be null. - * - * Return value: 1 if the key exists, 0 otherwise. - */ -int sm_exists(const StrMap *map, const char *key); - -/* - * Associates a value with the supplied key. If the key is already - * associated with a value, the previous value is replaced. - * - * Parameters: - * - * map: A pointer to a string map. This parameter cannot be null. - * - * key: A pointer to a null-terminated C string. This parameter - * cannot be null. The string must have a string length > 0. The - * string will be copied. - * - * value: A pointer to a null-terminated C string. This parameter - * cannot be null. The string must have a string length > 0. The - * string will be copied. - * - * Return value: 1 if the association succeeded, 0 otherwise. - */ -int sm_put(StrMap *map, const char *key, const char *value); - -/* - * Returns the number of associations between keys and values. - * - * Parameters: - * - * map: A pointer to a string map. This parameter cannot be null. - * - * Return value: The number of associations between keys and values. - */ -int sm_get_count(const StrMap *map); - -/* - * An enumerator over all associations between keys and values. - * - * Parameters: - * - * map: A pointer to a string map. This parameter cannot be null. - * - * enum_func: A pointer to a callback function that will be - * called from this procedure once for every key associated - * with a value. This parameter cannot be null. - * - * obj: A pointer to a client-specific object. This parameter will be - * passed back to the client's callback function. This parameter can - * be null. - * - * Return value: 1 if enumeration completed, 0 otherwise. - */ -int sm_enum(const StrMap *map, sm_enum_func enum_func, const void *obj); - -#ifdef __cplusplus -} -#endif - -#endif - -/* - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - -*/ \ No newline at end of file diff --git a/tools/ScriptStaticMethodTracker/method_list.c b/tools/ScriptStaticMethodTracker/method_list.c deleted file mode 100644 index 4fd6a87372..0000000000 --- a/tools/ScriptStaticMethodTracker/method_list.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -JavaMethod* createJavaMethod(const char *name) { - JavaMethod* method = (JavaMethod *)malloc(sizeof(JavaMethod)); - method->name = (char *)malloc((strlen(name) + 1) * sizeof(char)); - strcpy(method->name, name); - return method; -} - -void freeJavaMethod(JavaMethod *method) { - free(method->name); - free(method); -} - -JavaMethodList createJavaMethodList() { - JavaMethodList list; - list.size = 0; - - JavaMethodListItem *item = (JavaMethodListItem *)malloc(sizeof(JavaMethodListItem)); - item->prox = NULL; - - list.last = item; - list.first = list.last; - - return list; -} - -void insertJavaMethod(JavaMethodList *list, JavaMethod *method) { - JavaMethodListItem *item = (JavaMethodListItem *)malloc(sizeof(JavaMethodListItem)); - item->prox = NULL; - - list->last->method = method; - list->last->prox = item; - - list->last = item; - list->size++; -} - -void freeJavaMethodList(JavaMethodList *list) { - JavaMethodListItem *aux = list->first; - - list->first = list->last; - list->size = 0; - - while (aux->prox != NULL) { - JavaMethodListItem *aux2 = aux; - aux = aux->prox; - - freeJavaMethod(aux2->method); - free(aux2); - } - free(aux); -} - -void resetJavaMethodCursor(JavaMethodList *list) { - list->cursor = list->first; -} - -JavaMethod* readJavaMethod(JavaMethodList *list) { - JavaMethodListItem *aux = list->cursor; - if (aux->prox == NULL) { - return NULL; - } - - list->cursor = aux->prox; - return aux->method; -} diff --git a/tools/ScriptStaticMethodTracker/method_list.h b/tools/ScriptStaticMethodTracker/method_list.h deleted file mode 100644 index ae4fabed1d..0000000000 --- a/tools/ScriptStaticMethodTracker/method_list.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef METHOD_LIST_H_ -#define METHOD_LIST_H_ - -typedef struct { - char *name; -} JavaMethod; - -typedef struct JavaMethodListItem { - JavaMethod *method; - struct JavaMethodListItem *prox; -} JavaMethodListItem; - -typedef struct { - JavaMethodListItem *first; - JavaMethodListItem *last; - JavaMethodListItem *cursor; - - int size; -} JavaMethodList; - -#include "method_list.c" - -#endif /* METHOD_LIST_H_ */ diff --git a/tools/ScriptStaticMethodTracker/method_tracker.c b/tools/ScriptStaticMethodTracker/method_tracker.c deleted file mode 100644 index 5a23d0f23e..0000000000 --- a/tools/ScriptStaticMethodTracker/method_tracker.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include - -#include "method_list.h" -#include "script_path.h" - -JavaMethodList getBestSubstringsFromStringList(char *aStrRegex, JavaMethodList *lines, int lines_size) { - JavaMethodList ret = createJavaMethodList(); - - // ------------ an adaptation from Mitch Richling's https://www.mitchr.me/SS/exampleCode/AUPG/pcre_example.c.html ----------- - - int subStrVec[30]; - int subStrVecLength = 30; - const char *pcreErrorStr; - int pcreErrorOffset; - - pcre *reCompiled = pcre_compile(aStrRegex, 0, &pcreErrorStr, &pcreErrorOffset, NULL); - if(reCompiled == NULL) { - printf("ERROR: Could not compile '%s': %s\n", aStrRegex, pcreErrorStr); - return ret; - } - - pcre_extra *pcreExtra = pcre_study(reCompiled, 0, &pcreErrorStr); - if(pcreErrorStr != NULL) { - printf("ERROR: Could not study '%s': %s\n", aStrRegex, pcreErrorStr); - return ret; - } - - int i; - for (i = 0; i < lines_size; i++) { - JavaMethodList list = lines[i]; - - resetJavaMethodCursor(&list); - while(true) { - JavaMethod *method = readJavaMethod(&list); - if (method == NULL) { - break; - } - - char *str = method->name; - int st = 0, en = strlen(str); - while (st < en) { - int pcreExecRet = pcre_exec(reCompiled, pcreExtra, str, en, st, 0, subStrVec, subStrVecLength); - if(pcreExecRet < 0) { - switch(pcreExecRet) { - //case PCRE_ERROR_NOMATCH : printf("String did not match the pattern\n"); break; - case PCRE_ERROR_NULL : printf("Something was null\n"); break; - case PCRE_ERROR_BADOPTION : printf("A bad option was passed\n"); break; - case PCRE_ERROR_BADMAGIC : printf("Magic number bad (compiled re corrupt?)\n"); break; - case PCRE_ERROR_UNKNOWN_NODE : printf("Something kooky in the compiled re\n"); break; - case PCRE_ERROR_NOMEMORY : printf("Ran out of memory\n"); break; - //default : printf("Unknown error\n"); break; - } - - break; // no more matches found - } else { - if(pcreExecRet == 0) { - printf("But too many substrings were found to fit in subStrVec!\n"); - // Set rc to the max number of substring matches possible. - pcreExecRet = 30 / 3; - } - - const char *psubStrMatchStr; - pcre_get_substring(str, subStrVec, pcreExecRet, 0, &(psubStrMatchStr)); - - insertJavaMethod(&ret, createJavaMethod(psubStrMatchStr)); - pcre_free_substring(psubStrMatchStr); - - st = subStrVec[1]; - } - } - } - } - - pcre_free(reCompiled); - - if(pcreExtra != NULL) { - pcre_free(pcreExtra); - } - - return ret; -} - -char* extractStaticMethodName(const char *method_line) { - char *aStrRegex = "([A-Za-z0-9])+(\\s)*\\("; - - int lines_size = 1; - JavaMethodList *lines = (JavaMethodList *)malloc(lines_size * sizeof(JavaMethodList)); - - int i; - for (i = 0; i < lines_size; i++) { - lines[i] = createJavaMethodList(); - insertJavaMethod(&(lines[i]), createJavaMethod(method_line)); - } - - JavaMethodList subs = getBestSubstringsFromStringList(aStrRegex, lines, lines_size); - - char *ret; - if (subs.size > 0) { - resetJavaMethodCursor(&subs); - JavaMethod *method = readJavaMethod(&subs); - - char *method_scoop = method->name; - int i; - for (i = 0; i < strlen(method_scoop) - 1; i++) { - char ch = method_scoop[i]; - if (ch == '(' || ch == ' ' || ch == '\t') { - break; - } - } - method->name[i] = 0; - - ret = (char *)malloc((strlen(method->name) + 1) * sizeof(char)); - strcpy(ret, method->name); - } else { - ret = NULL; - } - - freeJavaMethodList(&subs); - - for (i = 0; i < lines_size; i++) { - freeJavaMethodList(&(lines[i])); - } - - free(lines); - - return ret; -} - -JavaMethodList getStaticJavaMethodNames(char *aStrRegex, JavaMethodList *lines, int lines_size) { - JavaMethodList subs = getBestSubstringsFromStringList(aStrRegex, lines, lines_size); - JavaMethodList ret = createJavaMethodList(); - - resetJavaMethodCursor(&subs); - while (true) { - JavaMethod *method = readJavaMethod(&subs); - if (method == NULL) { - break; - } - - char *method_name = extractStaticMethodName(method->name); - if (method_name != NULL) { - insertJavaMethod(&ret, createJavaMethod(method_name)); - free(method_name); - } - } - - freeJavaMethodList(&subs); - - return ret; -} - -bool isIgnoreMethod(char *method_name) { - const char * ignoreMethods[] = {"getInstance", "toString", NULL}; - - int i = 0; - while(true) { - const char *ign = ignoreMethods[i]; - if (ign == NULL) { - break; - } - - if (!strcmp(method_name, ign)) { - return true; - } - - i++; - } - - return false; -} - -JavaMethodList trackerFindSourceStaticMethods(JavaMethodList *lines, int lines_size) { - char *aStrRegex = "(public static\\s).*([A-Za-z0-9])+(\\s)*\\(.*\\{"; - JavaMethodList ret = createJavaMethodList(); - - JavaMethodList list = getStaticJavaMethodNames(aStrRegex, lines, lines_size); - resetJavaMethodCursor(&list); - while(true) { - JavaMethod *method = readJavaMethod(&list); - if (method == NULL) { - break; - } - - if (isIgnoreMethod(method->name)) { - continue; - } - - insertJavaMethod(&ret, createJavaMethod(method->name)); - } - - freeJavaMethodList(&list); - - return ret; -} - -char *getContentFromFile(FILE *f) { - fseek(f, 0, SEEK_END); // implemented by user529758 @ StackOverflow - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); /* same as rewind(f); */ - - char *string = malloc(fsize + 1); - fread(string, 1, fsize, f); - - string[fsize] = 0; - return string; -} - -bool locateMethodCall(const char *method_name, char *file_path) { - FILE *f = fopen(file_path, "r+t"); - - char aStrRegex[1000]; - strcpy(aStrRegex, method_name); - strcat(aStrRegex, "(\\s)*\\("); - - JavaMethodList *file_content = (JavaMethodList *)malloc(sizeof(JavaMethodList)); - file_content[0] = createJavaMethodList(); - - char *content = getContentFromFile(f); - - JavaMethod *method = createJavaMethod(content); - insertJavaMethod(&(file_content[0]), method); - free(content); - - JavaMethodList list = getBestSubstringsFromStringList(aStrRegex, file_content, 1); - bool found = (list.size > 0); - - freeJavaMethodList(&(file_content[0])); - free(file_content); - fclose(f); - - return found; -} - -void locateMethodCalls(const char *method_name, char **file_paths, int file_paths_size) { - int i; - for (i = 0; i < file_paths_size; i++) { - char *path = file_paths[i]; - if (locateMethodCall(method_name, path)) { - printf(" %s : \'%s\'\n", path, method_name); - } - } -} - -int trackerLocateScriptsStaticCalls(JavaMethodList method_names) { - ScriptFiles *files = createScriptFiles("../../scripts"); - if (files == NULL) { - printf("ERROR: Could not initialize script files.\n"); - return -1; - } - - resetJavaMethodCursor(&method_names); - while (true) { - JavaMethod *method = readJavaMethod(&method_names); - if (method == NULL) { - break; - } - - locateMethodCalls(method->name, files->file_paths, files->file_paths_size); - } - - freeScriptFiles(files); - return 0; -} - -typedef struct { - JavaMethodList *file_content; - int size; -} SourceFilesContent; - -SourceFilesContent* readSourceFileContents() { - ScriptFiles *srcFilePaths = createScriptFiles("../../src"); - - SourceFilesContent *files = (SourceFilesContent *)malloc(sizeof(SourceFilesContent)); - files->file_content = (JavaMethodList *)malloc(srcFilePaths->file_paths_size * sizeof(JavaMethodList)); - files->size = srcFilePaths->file_paths_size; - - //int max_len = 0; - int i; - for (i = 0; i < srcFilePaths->file_paths_size; i++) { - files->file_content[i] = createJavaMethodList(); - - FILE *f = fopen(srcFilePaths->file_paths[i], "r+t"); - char *content = getContentFromFile(f); - - //int this_len = strlen(content); - //if (max_len < this_len) max_len = this_len; - - fclose(f); - - insertJavaMethod(&(files->file_content[i]), createJavaMethod(content)); - } - - freeScriptFiles(srcFilePaths); - - return files; -} - -void freeSourceFileContents(SourceFilesContent *files) { - int i; - for (i = 0; i < files->size; i++) { - freeJavaMethodList(&(files->file_content[i])); - } - - free(files->file_content); - free(files); -} - -int main() { - printf("Loading source files...\n"); - SourceFilesContent *src_contents = readSourceFileContents(); - - int lines_size = src_contents->size; - JavaMethodList *lines = src_contents->file_content; - - printf("Tracking static methods on source...\n"); - JavaMethodList method_names = trackerFindSourceStaticMethods(lines, lines_size); - printf("Finding static methods calls on scripts...\n"); - trackerLocateScriptsStaticCalls(method_names); - printf("Track complete!\n"); - - freeSourceFileContents(src_contents); - freeJavaMethodList(&method_names); - - return 0; -} diff --git a/tools/ScriptStaticMethodTracker/pcre3.dll b/tools/ScriptStaticMethodTracker/pcre3.dll deleted file mode 100644 index b5fd2a6378..0000000000 Binary files a/tools/ScriptStaticMethodTracker/pcre3.dll and /dev/null differ diff --git a/tools/ScriptStaticMethodTracker/script_path.c b/tools/ScriptStaticMethodTracker/script_path.c deleted file mode 100644 index aab9ddd1b8..0000000000 --- a/tools/ScriptStaticMethodTracker/script_path.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include - -void fetchScriptFilesFromDirectory(ScriptFiles *files, char *root_dir) { - struct dirent *de; - struct stat info; - DIR *dir = opendir(root_dir); - if (dir != NULL) { - de = readdir(dir); // skip . - de = readdir(dir); // skip .. - - while ((de = readdir(dir)) != NULL) { - char file_path[SCRIPT_FILES_MAX_PATH_SIZE]; - strcpy(file_path, root_dir); - strcat(file_path, "/"); - strcat(file_path, de->d_name); - - stat(file_path, &info); - if (S_ISREG(info.st_mode)) { - files->file_paths[files->file_paths_size] = (char *)malloc(SCRIPT_FILES_MAX_PATH_SIZE * sizeof(char)); - strcpy(files->file_paths[files->file_paths_size], file_path); - files->file_paths_size++; - } else { - fetchScriptFilesFromDirectory(files, file_path); - } - } - } -} - -ScriptFiles* createScriptFiles(char *root_dir) { - ScriptFiles *files = (ScriptFiles *)malloc(sizeof(ScriptFiles)); - - files->file_paths = (char **)malloc(SCRIPT_FILES_MAX_COUNT * sizeof(char *)); - files->file_paths_size = 0; - - fetchScriptFilesFromDirectory(files, root_dir); - - return files; -} - -void freeScriptFiles(ScriptFiles *files) { - int i; - for (i = 0; i < files->file_paths_size; i++) { - free(files->file_paths[i]); - } - - free(files->file_paths); - free(files); -} diff --git a/tools/ScriptStaticMethodTracker/script_path.h b/tools/ScriptStaticMethodTracker/script_path.h deleted file mode 100644 index cd2452a517..0000000000 --- a/tools/ScriptStaticMethodTracker/script_path.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef SCRIPT_PATH_H_ -#define SCRIPT_PATH_H_ - -#define SCRIPT_FILES_MAX_COUNT 70000 -#define SCRIPT_FILES_MAX_PATH_SIZE 40000 - -typedef struct { - char **file_paths; - int file_paths_size; -} ScriptFiles; - -#include "script_path.c" - -#endif /* SCRIPT_PATH_H_ */