hexsha
stringlengths
40
40
repo
stringlengths
5
105
path
stringlengths
3
173
license
sequence
language
stringclasses
1 value
identifier
stringlengths
1
438
return_type
stringlengths
1
106
original_string
stringlengths
21
40.7k
original_docstring
stringlengths
18
13.4k
docstring
stringlengths
11
3.24k
docstring_tokens
sequence
code
stringlengths
14
20.4k
code_tokens
sequence
short_docstring
stringlengths
0
4.36k
short_docstring_tokens
sequence
comment
sequence
parameters
list
docstring_params
dict
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_del_pair
int
int vdict_del_pair(struct void_dict* vdict, const void* key) { unsigned char* value_ptr = (unsigned char*)vdict_get_value(vdict, key); if (value_ptr) { DICT_SIZE_TYPE hash = (value_ptr + vdict->value_size - vdict->value_bytes) / vdict->key_size; memset(vdict->key_bytes + vdict->key_size * hash, 0, vdict->key_size); if (vdict->value_free_fn) { vdict->value_free_fn(vdict->value_bytes + vdict->value_size * hash); } memset(vdict->value_bytes + vdict->value_size * hash, 0, vdict->value_size); DICT_SIZE_TYPE hash_idx; DICT_SIZE_TYPE* hash_ptr = vdict_hash_bsearch(vdict, hash, &hash_idx); memmove(hash_ptr, hash_ptr + 1, sizeof(DICT_SIZE_TYPE) * (vdict->size - hash_idx)); memset(vdict->hashes + vdict->size, 0, sizeof(DICT_SIZE_TYPE)); vdict->size--; return VDICT_SUCCESS; } else { return VDICT_ERROR ^ VDICT_KEY_404; } }
/** * Deletes key-value Pair of given key * * @param vdict Void Dict to delete from * @param key Key of key-value pair to be deleted * @return Error Code */
Deletes key-value Pair of given key @param vdict Void Dict to delete from @param key Key of key-value pair to be deleted @return Error Code
[ "Deletes", "key", "-", "value", "Pair", "of", "given", "key", "@param", "vdict", "Void", "Dict", "to", "delete", "from", "@param", "key", "Key", "of", "key", "-", "value", "pair", "to", "be", "deleted", "@return", "Error", "Code" ]
int vdict_del_pair(struct void_dict* vdict, const void* key) { unsigned char* value_ptr = (unsigned char*)vdict_get_value(vdict, key); if (value_ptr) { DICT_SIZE_TYPE hash = (value_ptr + vdict->value_size - vdict->value_bytes) / vdict->key_size; memset(vdict->key_bytes + vdict->key_size * hash, 0, vdict->key_size); if (vdict->value_free_fn) { vdict->value_free_fn(vdict->value_bytes + vdict->value_size * hash); } memset(vdict->value_bytes + vdict->value_size * hash, 0, vdict->value_size); DICT_SIZE_TYPE hash_idx; DICT_SIZE_TYPE* hash_ptr = vdict_hash_bsearch(vdict, hash, &hash_idx); memmove(hash_ptr, hash_ptr + 1, sizeof(DICT_SIZE_TYPE) * (vdict->size - hash_idx)); memset(vdict->hashes + vdict->size, 0, sizeof(DICT_SIZE_TYPE)); vdict->size--; return VDICT_SUCCESS; } else { return VDICT_ERROR ^ VDICT_KEY_404; } }
[ "int", "vdict_del_pair", "(", "struct", "void_dict", "*", "vdict", ",", "const", "void", "*", "key", ")", "{", "unsigned", "char", "*", "value_ptr", "=", "(", "unsigned", "char", "*", ")", "vdict_get_value", "(", "vdict", ",", "key", ")", ";", "if", "(", "value_ptr", ")", "{", "DICT_SIZE_TYPE", "hash", "=", "(", "value_ptr", "+", "vdict", "->", "value_size", "-", "vdict", "->", "value_bytes", ")", "/", "vdict", "->", "key_size", ";", "memset", "(", "vdict", "->", "key_bytes", "+", "vdict", "->", "key_size", "*", "hash", ",", "0", ",", "vdict", "->", "key_size", ")", ";", "if", "(", "vdict", "->", "value_free_fn", ")", "{", "vdict", "->", "value_free_fn", "(", "vdict", "->", "value_bytes", "+", "vdict", "->", "value_size", "*", "hash", ")", ";", "}", "memset", "(", "vdict", "->", "value_bytes", "+", "vdict", "->", "value_size", "*", "hash", ",", "0", ",", "vdict", "->", "value_size", ")", ";", "DICT_SIZE_TYPE", "hash_idx", ";", "DICT_SIZE_TYPE", "*", "hash_ptr", "=", "vdict_hash_bsearch", "(", "vdict", ",", "hash", ",", "&", "hash_idx", ")", ";", "memmove", "(", "hash_ptr", ",", "hash_ptr", "+", "1", ",", "sizeof", "(", "DICT_SIZE_TYPE", ")", "*", "(", "vdict", "->", "size", "-", "hash_idx", ")", ")", ";", "memset", "(", "vdict", "->", "hashes", "+", "vdict", "->", "size", ",", "0", ",", "sizeof", "(", "DICT_SIZE_TYPE", ")", ")", ";", "vdict", "->", "size", "--", ";", "return", "VDICT_SUCCESS", ";", "}", "else", "{", "return", "VDICT_ERROR", "^", "VDICT_KEY_404", ";", "}", "}" ]
Deletes key-value Pair of given key
[ "Deletes", "key", "-", "value", "Pair", "of", "given", "key" ]
[]
[ { "param": "vdict", "type": "struct void_dict" }, { "param": "key", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict", "type": "struct void_dict", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
adb22ef79c94d4d0d18971124e46e3a528acbc90
R1yuu/void_utility
void_dict.h
[ "MIT" ]
C
vdict_free
void
void vdict_free(void* vdict_ptr) { struct void_dict* vdict = (struct void_dict*)vdict_ptr; if (vdict->value_free_fn) { for (DICT_SIZE_TYPE hash_idx = 0; hash_idx < vdict->size; hash_idx++) { vdict->value_free_fn(vdict->value_bytes + vdict->value_size * vdict->hashes[hash_idx]); } } free(vdict->key_bytes); free((void*)vdict->key_zero_field); free(vdict->value_bytes); free(vdict->hashes); }
/** * Frees Content of Void Dict.\n * Calls vdict->value_free_fn on values if available. * * @param vdict_ptr Void Dict of which the content is to be freed */
Frees Content of Void Dict.\n Calls vdict->value_free_fn on values if available. @param vdict_ptr Void Dict of which the content is to be freed
[ "Frees", "Content", "of", "Void", "Dict", ".", "\\", "n", "Calls", "vdict", "-", ">", "value_free_fn", "on", "values", "if", "available", ".", "@param", "vdict_ptr", "Void", "Dict", "of", "which", "the", "content", "is", "to", "be", "freed" ]
void vdict_free(void* vdict_ptr) { struct void_dict* vdict = (struct void_dict*)vdict_ptr; if (vdict->value_free_fn) { for (DICT_SIZE_TYPE hash_idx = 0; hash_idx < vdict->size; hash_idx++) { vdict->value_free_fn(vdict->value_bytes + vdict->value_size * vdict->hashes[hash_idx]); } } free(vdict->key_bytes); free((void*)vdict->key_zero_field); free(vdict->value_bytes); free(vdict->hashes); }
[ "void", "vdict_free", "(", "void", "*", "vdict_ptr", ")", "{", "struct", "void_dict", "*", "vdict", "=", "(", "struct", "void_dict", "*", ")", "vdict_ptr", ";", "if", "(", "vdict", "->", "value_free_fn", ")", "{", "for", "(", "DICT_SIZE_TYPE", "hash_idx", "=", "0", ";", "hash_idx", "<", "vdict", "->", "size", ";", "hash_idx", "++", ")", "{", "vdict", "->", "value_free_fn", "(", "vdict", "->", "value_bytes", "+", "vdict", "->", "value_size", "*", "vdict", "->", "hashes", "[", "hash_idx", "]", ")", ";", "}", "}", "free", "(", "vdict", "->", "key_bytes", ")", ";", "free", "(", "(", "void", "*", ")", "vdict", "->", "key_zero_field", ")", ";", "free", "(", "vdict", "->", "value_bytes", ")", ";", "free", "(", "vdict", "->", "hashes", ")", ";", "}" ]
Frees Content of Void Dict.\n Calls vdict->value_free_fn on values if available.
[ "Frees", "Content", "of", "Void", "Dict", ".", "\\", "n", "Calls", "vdict", "-", ">", "value_free_fn", "on", "values", "if", "available", "." ]
[]
[ { "param": "vdict_ptr", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vdict_ptr", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
deba805ee3cf115215d061f5469ad509bd85b451
micahsnyder/micahsnyder.github.io
docs/sample_code/error_handling_in_c/05-else-if.c
[ "BSD-3-Clause" ]
C
append_data_element
bool
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { /* Bad args! */ printf("add_named_rectangle: Invalid arguments!\n"); } else if (NULL == (new_element = malloc(sizeof(named_data_t)))) { /* Out of memory! */ } else if (NULL == (new_element->name = strdup(name))){ /* Out of memory! */ } else { /* We're given ownership of the data, so we'll assign the pointer. */ new_element->data = data; if (false == add_element(new_element)) { /* Failed to add element */ } else { /* * Successs */ printf("add_named_rectangle: Added '%s' element to array!\n", name); } } /* Clean up, as needed */ if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
/** * @brief Add a new named data element to the global array. * * @param name Element name * @param data Pointer to the element data * @return true Element successfully added. * @return false Failed to add element. */
@brief Add a new named data element to the global array. @param name Element name @param data Pointer to the element data @return true Element successfully added. @return false Failed to add element.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", ".", "@param", "name", "Element", "name", "@param", "data", "Pointer", "to", "the", "element", "data", "@return", "true", "Element", "successfully", "added", ".", "@return", "false", "Failed", "to", "add", "element", "." ]
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { printf("add_named_rectangle: Invalid arguments!\n"); } else if (NULL == (new_element = malloc(sizeof(named_data_t)))) { } else if (NULL == (new_element->name = strdup(name))){ } else { new_element->data = data; if (false == add_element(new_element)) { } else { printf("add_named_rectangle: Added '%s' element to array!\n", name); } } if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
[ "bool", "append_data_element", "(", "const", "char", "*", "name", ",", "void", "*", "data", ")", "{", "bool", "status", "=", "false", ";", "named_data_t", "*", "new_element", "=", "NULL", ";", "if", "(", "NULL", "==", "name", "||", "NULL", "==", "data", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "else", "if", "(", "NULL", "==", "(", "new_element", "=", "malloc", "(", "sizeof", "(", "named_data_t", ")", ")", ")", ")", "{", "}", "else", "if", "(", "NULL", "==", "(", "new_element", "->", "name", "=", "strdup", "(", "name", ")", ")", ")", "{", "}", "else", "{", "new_element", "->", "data", "=", "data", ";", "if", "(", "false", "==", "add_element", "(", "new_element", ")", ")", "{", "}", "else", "{", "printf", "(", "\"", "\\n", "\"", ",", "name", ")", ";", "}", "}", "if", "(", "false", "==", "status", ")", "{", "if", "(", "NULL", "!=", "new_element", ")", "{", "if", "(", "NULL", "!=", "new_element", "->", "name", ")", "{", "free", "(", "new_element", "->", "name", ")", ";", "}", "free", "(", "new_element", ")", ";", "}", "}", "return", "status", ";", "}" ]
@brief Add a new named data element to the global array.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", "." ]
[ "/* Bad args! */", "/* Out of memory! */", "/* Out of memory! */", "/* We're given ownership of the data, so we'll assign the pointer. */", "/* Failed to add element */", "/*\n * Successs\n */", "/* Clean up, as needed */" ]
[ { "param": "name", "type": "char" }, { "param": "data", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1b4ea53fc79e36845489e8e2216b674abfcc5889
micahsnyder/micahsnyder.github.io
sample_code/error_handling_in_c/05_else_if.c
[ "BSD-3-Clause" ]
C
append_data_element
bool
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { /* Bad args! */ printf("add_named_rectangle: Invalid arguments!\n"); } else if (NULL == (new_element = malloc(sizeof(named_data_t)))) { /* Out of memory! */ } else if (NULL == (new_element->name = strdup(name))){ /* Out of memory! */ } else { /* We're given ownership of the data, so we'll assign the pointer. */ new_element->data = data; if (false == add_element(new_element)) { /* Failed to add element */ } else { /* * Successs */ status = true; printf("add_named_rectangle: Added '%s' element to array!\n", name); } } /* Clean up, as needed */ if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
/** * @brief Add a new named data element to the global array. * * @param name Element name * @param data Pointer to the element data * @return true Element successfully added. * @return false Failed to add element. */
@brief Add a new named data element to the global array. @param name Element name @param data Pointer to the element data @return true Element successfully added. @return false Failed to add element.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", ".", "@param", "name", "Element", "name", "@param", "data", "Pointer", "to", "the", "element", "data", "@return", "true", "Element", "successfully", "added", ".", "@return", "false", "Failed", "to", "add", "element", "." ]
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { printf("add_named_rectangle: Invalid arguments!\n"); } else if (NULL == (new_element = malloc(sizeof(named_data_t)))) { } else if (NULL == (new_element->name = strdup(name))){ } else { new_element->data = data; if (false == add_element(new_element)) { } else { status = true; printf("add_named_rectangle: Added '%s' element to array!\n", name); } } if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
[ "bool", "append_data_element", "(", "const", "char", "*", "name", ",", "void", "*", "data", ")", "{", "bool", "status", "=", "false", ";", "named_data_t", "*", "new_element", "=", "NULL", ";", "if", "(", "NULL", "==", "name", "||", "NULL", "==", "data", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "else", "if", "(", "NULL", "==", "(", "new_element", "=", "malloc", "(", "sizeof", "(", "named_data_t", ")", ")", ")", ")", "{", "}", "else", "if", "(", "NULL", "==", "(", "new_element", "->", "name", "=", "strdup", "(", "name", ")", ")", ")", "{", "}", "else", "{", "new_element", "->", "data", "=", "data", ";", "if", "(", "false", "==", "add_element", "(", "new_element", ")", ")", "{", "}", "else", "{", "status", "=", "true", ";", "printf", "(", "\"", "\\n", "\"", ",", "name", ")", ";", "}", "}", "if", "(", "false", "==", "status", ")", "{", "if", "(", "NULL", "!=", "new_element", ")", "{", "if", "(", "NULL", "!=", "new_element", "->", "name", ")", "{", "free", "(", "new_element", "->", "name", ")", ";", "}", "free", "(", "new_element", ")", ";", "}", "}", "return", "status", ";", "}" ]
@brief Add a new named data element to the global array.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", "." ]
[ "/* Bad args! */", "/* Out of memory! */", "/* Out of memory! */", "/* We're given ownership of the data, so we'll assign the pointer. */", "/* Failed to add element */", "/*\n * Successs\n */", "/* Clean up, as needed */" ]
[ { "param": "name", "type": "char" }, { "param": "data", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2a1c96019c1d47c8b7e7aa095ccd2a14723d700b
micahsnyder/micahsnyder.github.io
docs/sample_code/multi-return.c
[ "BSD-3-Clause" ]
C
append_data_element
bool
bool append_data_element(const char * name, void * data) { named_data_t *new_element = NULL; if (NULL == name || NULL == data) { /* Bad args! */ printf("add_named_rectangle: Invalid arguments!\n"); return false; } /* Allocate a new struct to put on our array. */ new_element = malloc(sizeof(named_data_t)); if (NULL == new_element) { /* Out of memory! */ return false; } /* We don't own the name, so let's duplicate it. */ new_element->name = strdup(name); if (NULL == new_element->name) { /* Out of memory! */ free(new_element); return false; } /* We're given ownership of the data, so we'll assign the pointer. */ new_element->name = data; /* Lock the array so we can safely add our new element. */ pthread_mutex_lock(&data_array_lock); /* * Append our data element to the end of the array. */ if (NULL == g_data_array) { /* Array doesn't exist, let's allocate it */ g_data_array = malloc(ARRAY_BLK_SZ * sizeof(named_data_t*)); if (NULL == g_data_array) { /* Failed to allocate memory for data array! */ free(new_element->name); free(new_element); return false; } g_data_array_size = ARRAY_BLK_SZ; } else if (g_num_data_elements == g_data_array_size) { /* Array is full, allocate more memory */ named_data_t ** temp; temp = realloc( g_data_array, (g_data_array_size + ARRAY_BLK_SZ) * sizeof(named_data_t*)); if (NULL == temp) { /* Failed to increase size of data array! */ free(new_element->name); free(new_element); return false; } g_data_array = temp; g_data_array_size += ARRAY_BLK_SZ; } g_data_array[g_num_data_elements] = new_element; g_num_data_elements += 1; /* Unlock the array so other threads can access it once more. */ pthread_mutex_unlock(&data_array_lock); printf("add_named_rectangle: Added '%s' element to array!\n", name); return true; }
/** * @brief Add a new named data element to the global array. * * @param name Element name * @param data Pointer to the element data * @return true Element successfully added. * @return false Failed to add element. */
@brief Add a new named data element to the global array. @param name Element name @param data Pointer to the element data @return true Element successfully added. @return false Failed to add element.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", ".", "@param", "name", "Element", "name", "@param", "data", "Pointer", "to", "the", "element", "data", "@return", "true", "Element", "successfully", "added", ".", "@return", "false", "Failed", "to", "add", "element", "." ]
bool append_data_element(const char * name, void * data) { named_data_t *new_element = NULL; if (NULL == name || NULL == data) { printf("add_named_rectangle: Invalid arguments!\n"); return false; } new_element = malloc(sizeof(named_data_t)); if (NULL == new_element) { return false; } new_element->name = strdup(name); if (NULL == new_element->name) { free(new_element); return false; } new_element->name = data; pthread_mutex_lock(&data_array_lock); if (NULL == g_data_array) { g_data_array = malloc(ARRAY_BLK_SZ * sizeof(named_data_t*)); if (NULL == g_data_array) { free(new_element->name); free(new_element); return false; } g_data_array_size = ARRAY_BLK_SZ; } else if (g_num_data_elements == g_data_array_size) { named_data_t ** temp; temp = realloc( g_data_array, (g_data_array_size + ARRAY_BLK_SZ) * sizeof(named_data_t*)); if (NULL == temp) { free(new_element->name); free(new_element); return false; } g_data_array = temp; g_data_array_size += ARRAY_BLK_SZ; } g_data_array[g_num_data_elements] = new_element; g_num_data_elements += 1; pthread_mutex_unlock(&data_array_lock); printf("add_named_rectangle: Added '%s' element to array!\n", name); return true; }
[ "bool", "append_data_element", "(", "const", "char", "*", "name", ",", "void", "*", "data", ")", "{", "named_data_t", "*", "new_element", "=", "NULL", ";", "if", "(", "NULL", "==", "name", "||", "NULL", "==", "data", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "false", ";", "}", "new_element", "=", "malloc", "(", "sizeof", "(", "named_data_t", ")", ")", ";", "if", "(", "NULL", "==", "new_element", ")", "{", "return", "false", ";", "}", "new_element", "->", "name", "=", "strdup", "(", "name", ")", ";", "if", "(", "NULL", "==", "new_element", "->", "name", ")", "{", "free", "(", "new_element", ")", ";", "return", "false", ";", "}", "new_element", "->", "name", "=", "data", ";", "pthread_mutex_lock", "(", "&", "data_array_lock", ")", ";", "if", "(", "NULL", "==", "g_data_array", ")", "{", "g_data_array", "=", "malloc", "(", "ARRAY_BLK_SZ", "*", "sizeof", "(", "named_data_t", "*", ")", ")", ";", "if", "(", "NULL", "==", "g_data_array", ")", "{", "free", "(", "new_element", "->", "name", ")", ";", "free", "(", "new_element", ")", ";", "return", "false", ";", "}", "g_data_array_size", "=", "ARRAY_BLK_SZ", ";", "}", "else", "if", "(", "g_num_data_elements", "==", "g_data_array_size", ")", "{", "named_data_t", "*", "*", "temp", ";", "temp", "=", "realloc", "(", "g_data_array", ",", "(", "g_data_array_size", "+", "ARRAY_BLK_SZ", ")", "*", "sizeof", "(", "named_data_t", "*", ")", ")", ";", "if", "(", "NULL", "==", "temp", ")", "{", "free", "(", "new_element", "->", "name", ")", ";", "free", "(", "new_element", ")", ";", "return", "false", ";", "}", "g_data_array", "=", "temp", ";", "g_data_array_size", "+=", "ARRAY_BLK_SZ", ";", "}", "g_data_array", "[", "g_num_data_elements", "]", "=", "new_element", ";", "g_num_data_elements", "+=", "1", ";", "pthread_mutex_unlock", "(", "&", "data_array_lock", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "name", ")", ";", "return", "true", ";", "}" ]
@brief Add a new named data element to the global array.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", "." ]
[ "/* Bad args! */", "/* Allocate a new struct to put on our array. */", "/* Out of memory! */", "/* We don't own the name, so let's duplicate it. */", "/* Out of memory! */", "/* We're given ownership of the data, so we'll assign the pointer. */", "/* Lock the array so we can safely add our new element. */", "/*\n * Append our data element to the end of the array.\n */", "/* Array doesn't exist, let's allocate it */", "/* Failed to allocate memory for data array! */", "/* Array is full, allocate more memory */", "/* Failed to increase size of data array! */", "/* Unlock the array so other threads can access it once more. */" ]
[ { "param": "name", "type": "char" }, { "param": "data", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
be59d687aa94d02a433c6481b59cadea43ee4337
micahsnyder/micahsnyder.github.io
docs/sample_code/else-if.c
[ "BSD-3-Clause" ]
C
append_data_element
bool
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { /* Bad args! */ printf("add_named_rectangle: Invalid arguments!\n"); } else if (NULL == (new_element = malloc(sizeof(named_data_t)))) { /* Out of memory! */ } else if (NULL == (new_element->name = strdup(name))){ /* Out of memory! */ } else { /* We're given ownership of the data, so we'll assign the pointer. */ new_element->name = data; if (false == add_element(new_element)) { /* Failed to add element */ } else { /* * Successs */ printf("add_named_rectangle: Added '%s' element to array!\n", name); } } /* Clean up, as needed */ if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
/** * @brief Add a new named data element to the global array. * * @param name Element name * @param data Pointer to the element data * @return true Element successfully added. * @return false Failed to add element. */
@brief Add a new named data element to the global array. @param name Element name @param data Pointer to the element data @return true Element successfully added. @return false Failed to add element.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", ".", "@param", "name", "Element", "name", "@param", "data", "Pointer", "to", "the", "element", "data", "@return", "true", "Element", "successfully", "added", ".", "@return", "false", "Failed", "to", "add", "element", "." ]
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { printf("add_named_rectangle: Invalid arguments!\n"); } else if (NULL == (new_element = malloc(sizeof(named_data_t)))) { } else if (NULL == (new_element->name = strdup(name))){ } else { new_element->name = data; if (false == add_element(new_element)) { } else { printf("add_named_rectangle: Added '%s' element to array!\n", name); } } if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
[ "bool", "append_data_element", "(", "const", "char", "*", "name", ",", "void", "*", "data", ")", "{", "bool", "status", "=", "false", ";", "named_data_t", "*", "new_element", "=", "NULL", ";", "if", "(", "NULL", "==", "name", "||", "NULL", "==", "data", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "else", "if", "(", "NULL", "==", "(", "new_element", "=", "malloc", "(", "sizeof", "(", "named_data_t", ")", ")", ")", ")", "{", "}", "else", "if", "(", "NULL", "==", "(", "new_element", "->", "name", "=", "strdup", "(", "name", ")", ")", ")", "{", "}", "else", "{", "new_element", "->", "name", "=", "data", ";", "if", "(", "false", "==", "add_element", "(", "new_element", ")", ")", "{", "}", "else", "{", "printf", "(", "\"", "\\n", "\"", ",", "name", ")", ";", "}", "}", "if", "(", "false", "==", "status", ")", "{", "if", "(", "NULL", "!=", "new_element", ")", "{", "if", "(", "NULL", "!=", "new_element", "->", "name", ")", "{", "free", "(", "new_element", "->", "name", ")", ";", "}", "free", "(", "new_element", ")", ";", "}", "}", "return", "status", ";", "}" ]
@brief Add a new named data element to the global array.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", "." ]
[ "/* Bad args! */", "/* Out of memory! */", "/* Out of memory! */", "/* We're given ownership of the data, so we'll assign the pointer. */", "/* Failed to add element */", "/*\n * Successs\n */", "/* Clean up, as needed */" ]
[ { "param": "name", "type": "char" }, { "param": "data", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
be7c3743c68a8f870fca1445de64fd69e3b6c23d
micahsnyder/micahsnyder.github.io
docs/sample_code/error_handling_in_c/04-goto-done-with-macros.c
[ "BSD-3-Clause" ]
C
append_data_element
bool
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { /* Bad args! */ goto done; } /* Allocate a new struct to put on our array. */ MALLOC_OR_GOTO(new_element, sizeof(named_data_t), done); /* We don't own the name, so let's duplicate it. */ STRDUP_OR_GOTO(new_element->name, name, done); /* We're given ownership of the data, so we'll assign the pointer. */ new_element->data = data; /* Lock the array so we can safely add our new element. */ pthread_mutex_lock(&data_array_lock); /* * Append our data element to the end of the array. */ if (NULL == g_data_array) { /* Array doesn't exist, let's allocate it */ MALLOC_OR_GOTO( g_data_array, ARRAY_BLK_SZ * sizeof(named_data_t*), unlock); g_data_array_size = ARRAY_BLK_SZ; } else if (g_num_data_elements == g_data_array_size) { /* Array is full, allocate more memory */ REALLOC_OR_GOTO( g_data_array, (g_data_array_size + ARRAY_BLK_SZ) * sizeof(named_data_t*), unlock); g_data_array_size += ARRAY_BLK_SZ; } g_data_array[g_num_data_elements] = new_element; g_num_data_elements += 1; /* Success! */ status = true; unlock: /* Unlock the array so other threads can access it once more. */ pthread_mutex_unlock(&data_array_lock); done: if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
/** * @brief Add a new named data element to the global array. * * @param name Element name * @param data Pointer to the element data * @return true Element successfully added. * @return false Failed to add element. */
@brief Add a new named data element to the global array. @param name Element name @param data Pointer to the element data @return true Element successfully added. @return false Failed to add element.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", ".", "@param", "name", "Element", "name", "@param", "data", "Pointer", "to", "the", "element", "data", "@return", "true", "Element", "successfully", "added", ".", "@return", "false", "Failed", "to", "add", "element", "." ]
bool append_data_element(const char * name, void * data) { bool status = false; named_data_t *new_element = NULL; if (NULL == name || NULL == data) { goto done; } MALLOC_OR_GOTO(new_element, sizeof(named_data_t), done); STRDUP_OR_GOTO(new_element->name, name, done); new_element->data = data; pthread_mutex_lock(&data_array_lock); if (NULL == g_data_array) { MALLOC_OR_GOTO( g_data_array, ARRAY_BLK_SZ * sizeof(named_data_t*), unlock); g_data_array_size = ARRAY_BLK_SZ; } else if (g_num_data_elements == g_data_array_size) { REALLOC_OR_GOTO( g_data_array, (g_data_array_size + ARRAY_BLK_SZ) * sizeof(named_data_t*), unlock); g_data_array_size += ARRAY_BLK_SZ; } g_data_array[g_num_data_elements] = new_element; g_num_data_elements += 1; status = true; unlock: pthread_mutex_unlock(&data_array_lock); done: if (false == status) { if (NULL != new_element) { if (NULL != new_element->name) { free(new_element->name); } free(new_element); } } return status; }
[ "bool", "append_data_element", "(", "const", "char", "*", "name", ",", "void", "*", "data", ")", "{", "bool", "status", "=", "false", ";", "named_data_t", "*", "new_element", "=", "NULL", ";", "if", "(", "NULL", "==", "name", "||", "NULL", "==", "data", ")", "{", "goto", "done", ";", "}", "MALLOC_OR_GOTO", "(", "new_element", ",", "sizeof", "(", "named_data_t", ")", ",", "done", ")", ";", "STRDUP_OR_GOTO", "(", "new_element", "->", "name", ",", "name", ",", "done", ")", ";", "new_element", "->", "data", "=", "data", ";", "pthread_mutex_lock", "(", "&", "data_array_lock", ")", ";", "if", "(", "NULL", "==", "g_data_array", ")", "{", "MALLOC_OR_GOTO", "(", "g_data_array", ",", "ARRAY_BLK_SZ", "*", "sizeof", "(", "named_data_t", "*", ")", ",", "unlock", ")", ";", "g_data_array_size", "=", "ARRAY_BLK_SZ", ";", "}", "else", "if", "(", "g_num_data_elements", "==", "g_data_array_size", ")", "{", "REALLOC_OR_GOTO", "(", "g_data_array", ",", "(", "g_data_array_size", "+", "ARRAY_BLK_SZ", ")", "*", "sizeof", "(", "named_data_t", "*", ")", ",", "unlock", ")", ";", "g_data_array_size", "+=", "ARRAY_BLK_SZ", ";", "}", "g_data_array", "[", "g_num_data_elements", "]", "=", "new_element", ";", "g_num_data_elements", "+=", "1", ";", "status", "=", "true", ";", "unlock", ":", "pthread_mutex_unlock", "(", "&", "data_array_lock", ")", ";", "done", ":", "if", "(", "false", "==", "status", ")", "{", "if", "(", "NULL", "!=", "new_element", ")", "{", "if", "(", "NULL", "!=", "new_element", "->", "name", ")", "{", "free", "(", "new_element", "->", "name", ")", ";", "}", "free", "(", "new_element", ")", ";", "}", "}", "return", "status", ";", "}" ]
@brief Add a new named data element to the global array.
[ "@brief", "Add", "a", "new", "named", "data", "element", "to", "the", "global", "array", "." ]
[ "/* Bad args! */", "/* Allocate a new struct to put on our array. */", "/* We don't own the name, so let's duplicate it. */", "/* We're given ownership of the data, so we'll assign the pointer. */", "/* Lock the array so we can safely add our new element. */", "/*\n * Append our data element to the end of the array.\n */", "/* Array doesn't exist, let's allocate it */", "/* Array is full, allocate more memory */", "/* Success! */", "/* Unlock the array so other threads can access it once more. */" ]
[ { "param": "name", "type": "char" }, { "param": "data", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
326fdc26444ea89d3b7f19288c644c5eed231647
cgiannoula/logical-ordering-concurrent-trees
bst-log-order/bst_log_order_fg_spinlock.c
[ "MIT" ]
C
rbt_new
void
void *rbt_new() { printf("Size of tree node is %lu\n", sizeof(bst_node_t)); return _bst_new_helper(); }
/******************************************************************************/ /* BST Logical Ordering Search tree interface implementation */ /******************************************************************************/
BST Logical Ordering Search tree interface implementation
[ "BST", "Logical", "Ordering", "Search", "tree", "interface", "implementation" ]
void *rbt_new() { printf("Size of tree node is %lu\n", sizeof(bst_node_t)); return _bst_new_helper(); }
[ "void", "*", "rbt_new", "(", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "sizeof", "(", "bst_node_t", ")", ")", ";", "return", "_bst_new_helper", "(", ")", ";", "}" ]
BST Logical Ordering Search tree interface implementation
[ "BST", "Logical", "Ordering", "Search", "tree", "interface", "implementation" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
02f333ebe9cfb4e7fe9573528fc69c95302e57a0
guoger/2gen_dcdc_test_util
master.c
[ "BSD-3-Clause" ]
C
Buffer_Init
void
void Buffer_Init(uint8_t type) { uint8_t i; Master_Buf[0] = 0x00; Master_Buf[1] = 0x01; if (type) { for (i = 2; i < BUFFER_SIZE; i++) { Master_Buf[i] = i; } } else { for (i = 0; i < BUFFER_SIZE; i++) { Master_Buf[i] = 0; } } }
/*********************************************************************/ /** * @brief Initialize buffer * @param[in] type: * - 0: Initialize Master_Buf with increment value from 0 * Fill all member in Slave_Buf with 0 * - 1: Initialize Slave_Buf with increment value from 0 * Fill all member in Master_Buf with 0 * @return None **********************************************************************/
@brief Initialize buffer @param[in] type: - 0: Initialize Master_Buf with increment value from 0 Fill all member in Slave_Buf with 0 - 1: Initialize Slave_Buf with increment value from 0 Fill all member in Master_Buf with 0 @return None
[ "@brief", "Initialize", "buffer", "@param", "[", "in", "]", "type", ":", "-", "0", ":", "Initialize", "Master_Buf", "with", "increment", "value", "from", "0", "Fill", "all", "member", "in", "Slave_Buf", "with", "0", "-", "1", ":", "Initialize", "Slave_Buf", "with", "increment", "value", "from", "0", "Fill", "all", "member", "in", "Master_Buf", "with", "0", "@return", "None" ]
void Buffer_Init(uint8_t type) { uint8_t i; Master_Buf[0] = 0x00; Master_Buf[1] = 0x01; if (type) { for (i = 2; i < BUFFER_SIZE; i++) { Master_Buf[i] = i; } } else { for (i = 0; i < BUFFER_SIZE; i++) { Master_Buf[i] = 0; } } }
[ "void", "Buffer_Init", "(", "uint8_t", "type", ")", "{", "uint8_t", "i", ";", "Master_Buf", "[", "0", "]", "=", "0x00", ";", "Master_Buf", "[", "1", "]", "=", "0x01", ";", "if", "(", "type", ")", "{", "for", "(", "i", "=", "2", ";", "i", "<", "BUFFER_SIZE", ";", "i", "++", ")", "{", "Master_Buf", "[", "i", "]", "=", "i", ";", "}", "}", "else", "{", "for", "(", "i", "=", "0", ";", "i", "<", "BUFFER_SIZE", ";", "i", "++", ")", "{", "Master_Buf", "[", "i", "]", "=", "0", ";", "}", "}", "}" ]
@brief Initialize buffer @param[in] type: - 0: Initialize Master_Buf with increment value from 0 Fill all member in Slave_Buf with 0 - 1: Initialize Slave_Buf with increment value from 0 Fill all member in Master_Buf with 0 @return None
[ "@brief", "Initialize", "buffer", "@param", "[", "in", "]", "type", ":", "-", "0", ":", "Initialize", "Master_Buf", "with", "increment", "value", "from", "0", "Fill", "all", "member", "in", "Slave_Buf", "with", "0", "-", "1", ":", "Initialize", "Slave_Buf", "with", "increment", "value", "from", "0", "Fill", "all", "member", "in", "Master_Buf", "with", "0", "@return", "None" ]
[]
[ { "param": "type", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "type", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7e353815c4f19502d8d9b2f9575795732b587f09
ALSCode/CoroOS
STM32F412_CoroOS/Core/Src/main.c
[ "Apache-2.0" ]
C
SystemClock_Config
void
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 4; RCC_OscInitStruct.PLL.PLLN = 72; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 3; RCC_OscInitStruct.PLL.PLLR = 2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } }
/** * @brief System Clock Configuration * @retval None */
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 4; RCC_OscInitStruct.PLL.PLLN = 72; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 3; RCC_OscInitStruct.PLL.PLLR = 2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } }
[ "void", "SystemClock_Config", "(", "void", ")", "{", "RCC_OscInitTypeDef", "RCC_OscInitStruct", "=", "{", "0", "}", ";", "RCC_ClkInitTypeDef", "RCC_ClkInitStruct", "=", "{", "0", "}", ";", "__HAL_RCC_PWR_CLK_ENABLE", "(", ")", ";", "__HAL_PWR_VOLTAGESCALING_CONFIG", "(", "PWR_REGULATOR_VOLTAGE_SCALE1", ")", ";", "RCC_OscInitStruct", ".", "OscillatorType", "=", "RCC_OSCILLATORTYPE_HSE", ";", "RCC_OscInitStruct", ".", "HSEState", "=", "RCC_HSE_BYPASS", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLState", "=", "RCC_PLL_ON", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLSource", "=", "RCC_PLLSOURCE_HSE", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLM", "=", "4", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLN", "=", "72", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLP", "=", "RCC_PLLP_DIV2", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLQ", "=", "3", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLR", "=", "2", ";", "if", "(", "HAL_RCC_OscConfig", "(", "&", "RCC_OscInitStruct", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "RCC_ClkInitStruct", ".", "ClockType", "=", "RCC_CLOCKTYPE_HCLK", "|", "RCC_CLOCKTYPE_SYSCLK", "|", "RCC_CLOCKTYPE_PCLK1", "|", "RCC_CLOCKTYPE_PCLK2", ";", "RCC_ClkInitStruct", ".", "SYSCLKSource", "=", "RCC_SYSCLKSOURCE_PLLCLK", ";", "RCC_ClkInitStruct", ".", "AHBCLKDivider", "=", "RCC_SYSCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB1CLKDivider", "=", "RCC_HCLK_DIV2", ";", "RCC_ClkInitStruct", ".", "APB2CLKDivider", "=", "RCC_HCLK_DIV1", ";", "if", "(", "HAL_RCC_ClockConfig", "(", "&", "RCC_ClkInitStruct", ",", "FLASH_LATENCY_2", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
[ "/** Configure the main internal regulator output voltage\n */", "/** Initializes the RCC Oscillators according to the specified parameters\n * in the RCC_OscInitTypeDef structure.\n */", "/** Initializes the CPU, AHB and APB buses clocks\n */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
537bb7867590fa5f0aaa294fad028df629da000f
Keyaku/ist-asa-projects
proj/2018-2019/p1/src/proj.c
[ "MIT" ]
C
count_scc
void
void count_scc( Graph *g, SCC_data *scc, Stack *st, Vertex u, int *disc, int *low, int *disc_time ) { Edge adj; if (stack_contains(&scc->ap, u)) { return; } disc[u] = low[u] = ++(*disc_time); stack_push(st, u); for (adj = g->first[u]; adj != 0; adj = g->next[adj]) { Vertex v = g->vertex[adj]; if (stack_contains(&scc->ap, v)) { continue; } /* If v is not visited yet, recur for it */ if (disc[v] == 0) { count_scc(g, scc, st, v, disc, low, disc_time); low[u] = min(low[u], low[v]); } /* Update low value of 'u' only if 'v' is still in stack */ else if (stack_contains(st, v)) { low[u] = min(low[u], disc[v]); } } /* head node found; so it's an SCC. Popping stack until we reach head node. */ if (low[u] == disc[u]) { Vertex v; scc->biggest_scc = max(scc->biggest_scc, stack_size(st)); while ((v = stack_pop(st)) != u); } }
/* Runs DFS through graph whilst ignoring Articulation Points */
Runs DFS through graph whilst ignoring Articulation Points
[ "Runs", "DFS", "through", "graph", "whilst", "ignoring", "Articulation", "Points" ]
void count_scc( Graph *g, SCC_data *scc, Stack *st, Vertex u, int *disc, int *low, int *disc_time ) { Edge adj; if (stack_contains(&scc->ap, u)) { return; } disc[u] = low[u] = ++(*disc_time); stack_push(st, u); for (adj = g->first[u]; adj != 0; adj = g->next[adj]) { Vertex v = g->vertex[adj]; if (stack_contains(&scc->ap, v)) { continue; } if (disc[v] == 0) { count_scc(g, scc, st, v, disc, low, disc_time); low[u] = min(low[u], low[v]); } else if (stack_contains(st, v)) { low[u] = min(low[u], disc[v]); } } if (low[u] == disc[u]) { Vertex v; scc->biggest_scc = max(scc->biggest_scc, stack_size(st)); while ((v = stack_pop(st)) != u); } }
[ "void", "count_scc", "(", "Graph", "*", "g", ",", "SCC_data", "*", "scc", ",", "Stack", "*", "st", ",", "Vertex", "u", ",", "int", "*", "disc", ",", "int", "*", "low", ",", "int", "*", "disc_time", ")", "{", "Edge", "adj", ";", "if", "(", "stack_contains", "(", "&", "scc", "->", "ap", ",", "u", ")", ")", "{", "return", ";", "}", "disc", "[", "u", "]", "=", "low", "[", "u", "]", "=", "++", "(", "*", "disc_time", ")", ";", "stack_push", "(", "st", ",", "u", ")", ";", "for", "(", "adj", "=", "g", "->", "first", "[", "u", "]", ";", "adj", "!=", "0", ";", "adj", "=", "g", "->", "next", "[", "adj", "]", ")", "{", "Vertex", "v", "=", "g", "->", "vertex", "[", "adj", "]", ";", "if", "(", "stack_contains", "(", "&", "scc", "->", "ap", ",", "v", ")", ")", "{", "continue", ";", "}", "if", "(", "disc", "[", "v", "]", "==", "0", ")", "{", "count_scc", "(", "g", ",", "scc", ",", "st", ",", "v", ",", "disc", ",", "low", ",", "disc_time", ")", ";", "low", "[", "u", "]", "=", "min", "(", "low", "[", "u", "]", ",", "low", "[", "v", "]", ")", ";", "}", "else", "if", "(", "stack_contains", "(", "st", ",", "v", ")", ")", "{", "low", "[", "u", "]", "=", "min", "(", "low", "[", "u", "]", ",", "disc", "[", "v", "]", ")", ";", "}", "}", "if", "(", "low", "[", "u", "]", "==", "disc", "[", "u", "]", ")", "{", "Vertex", "v", ";", "scc", "->", "biggest_scc", "=", "max", "(", "scc", "->", "biggest_scc", ",", "stack_size", "(", "st", ")", ")", ";", "while", "(", "(", "v", "=", "stack_pop", "(", "st", ")", ")", "!=", "u", ")", ";", "}", "}" ]
Runs DFS through graph whilst ignoring Articulation Points
[ "Runs", "DFS", "through", "graph", "whilst", "ignoring", "Articulation", "Points" ]
[ "/* If v is not visited yet, recur for it */", "/* Update low value of 'u' only if 'v' is still in stack */", "/* head node found; so it's an SCC. Popping stack until we reach head node. */" ]
[ { "param": "g", "type": "Graph" }, { "param": "scc", "type": "SCC_data" }, { "param": "st", "type": "Stack" }, { "param": "u", "type": "Vertex" }, { "param": "disc", "type": "int" }, { "param": "low", "type": "int" }, { "param": "disc_time", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "g", "type": "Graph", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "scc", "type": "SCC_data", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "st", "type": "Stack", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "u", "type": "Vertex", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "disc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "low", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "disc_time", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
537bb7867590fa5f0aaa294fad028df629da000f
Keyaku/ist-asa-projects
proj/2018-2019/p1/src/proj.c
[ "MIT" ]
C
tarjan_aux
void
void tarjan_aux( Graph *g, SCC_data *scc, Stack *st, Vertex u, int *disc, int *low, int *disc_time ) { Edge adj; int children = 0; disc[u] = low[u] = ++(*disc_time); stack_push(st, u); for (adj = g->first[u]; adj != 0; adj = g->next[adj]) { Vertex v = g->vertex[adj]; /* If v is not visited yet, recur for it */ if (disc[v] == 0) { g->parent[v] = u; children++; tarjan_aux(g, scc, st, v, disc, low, disc_time); low[u] = min(low[u], low[v]); if (g->parent[u] == 0 && children > 1) { stack_push(&scc->ap, u); } if (g->parent[u] != 0 && low[v] >= disc[u]) { stack_push(&scc->ap, u); } } /* Update low value of 'u' only if 'v' is still in stack */ else if (stack_contains(st, v)) { low[u] = min(low[u], disc[v]); } } /* head node found; so it's an SCC. Popping stack until we reach head node. */ if (low[u] == disc[u]) { Vertex v, tail = u; while ((v = stack_pop(st)) != u) { tail = max(tail, v); /* Getting the tail of the SCC */ } stack_push(&scc->ids, tail); } }
/* Apply Tarjan's algorithm to find SCCs */
Apply Tarjan's algorithm to find SCCs
[ "Apply", "Tarjan", "'", "s", "algorithm", "to", "find", "SCCs" ]
void tarjan_aux( Graph *g, SCC_data *scc, Stack *st, Vertex u, int *disc, int *low, int *disc_time ) { Edge adj; int children = 0; disc[u] = low[u] = ++(*disc_time); stack_push(st, u); for (adj = g->first[u]; adj != 0; adj = g->next[adj]) { Vertex v = g->vertex[adj]; if (disc[v] == 0) { g->parent[v] = u; children++; tarjan_aux(g, scc, st, v, disc, low, disc_time); low[u] = min(low[u], low[v]); if (g->parent[u] == 0 && children > 1) { stack_push(&scc->ap, u); } if (g->parent[u] != 0 && low[v] >= disc[u]) { stack_push(&scc->ap, u); } } else if (stack_contains(st, v)) { low[u] = min(low[u], disc[v]); } } if (low[u] == disc[u]) { Vertex v, tail = u; while ((v = stack_pop(st)) != u) { tail = max(tail, v); } stack_push(&scc->ids, tail); } }
[ "void", "tarjan_aux", "(", "Graph", "*", "g", ",", "SCC_data", "*", "scc", ",", "Stack", "*", "st", ",", "Vertex", "u", ",", "int", "*", "disc", ",", "int", "*", "low", ",", "int", "*", "disc_time", ")", "{", "Edge", "adj", ";", "int", "children", "=", "0", ";", "disc", "[", "u", "]", "=", "low", "[", "u", "]", "=", "++", "(", "*", "disc_time", ")", ";", "stack_push", "(", "st", ",", "u", ")", ";", "for", "(", "adj", "=", "g", "->", "first", "[", "u", "]", ";", "adj", "!=", "0", ";", "adj", "=", "g", "->", "next", "[", "adj", "]", ")", "{", "Vertex", "v", "=", "g", "->", "vertex", "[", "adj", "]", ";", "if", "(", "disc", "[", "v", "]", "==", "0", ")", "{", "g", "->", "parent", "[", "v", "]", "=", "u", ";", "children", "++", ";", "tarjan_aux", "(", "g", ",", "scc", ",", "st", ",", "v", ",", "disc", ",", "low", ",", "disc_time", ")", ";", "low", "[", "u", "]", "=", "min", "(", "low", "[", "u", "]", ",", "low", "[", "v", "]", ")", ";", "if", "(", "g", "->", "parent", "[", "u", "]", "==", "0", "&&", "children", ">", "1", ")", "{", "stack_push", "(", "&", "scc", "->", "ap", ",", "u", ")", ";", "}", "if", "(", "g", "->", "parent", "[", "u", "]", "!=", "0", "&&", "low", "[", "v", "]", ">=", "disc", "[", "u", "]", ")", "{", "stack_push", "(", "&", "scc", "->", "ap", ",", "u", ")", ";", "}", "}", "else", "if", "(", "stack_contains", "(", "st", ",", "v", ")", ")", "{", "low", "[", "u", "]", "=", "min", "(", "low", "[", "u", "]", ",", "disc", "[", "v", "]", ")", ";", "}", "}", "if", "(", "low", "[", "u", "]", "==", "disc", "[", "u", "]", ")", "{", "Vertex", "v", ",", "tail", "=", "u", ";", "while", "(", "(", "v", "=", "stack_pop", "(", "st", ")", ")", "!=", "u", ")", "{", "tail", "=", "max", "(", "tail", ",", "v", ")", ";", "}", "stack_push", "(", "&", "scc", "->", "ids", ",", "tail", ")", ";", "}", "}" ]
Apply Tarjan's algorithm to find SCCs
[ "Apply", "Tarjan", "'", "s", "algorithm", "to", "find", "SCCs" ]
[ "/* If v is not visited yet, recur for it */", "/* Update low value of 'u' only if 'v' is still in stack */", "/* head node found; so it's an SCC. Popping stack until we reach head node. */", "/* Getting the tail of the SCC */" ]
[ { "param": "g", "type": "Graph" }, { "param": "scc", "type": "SCC_data" }, { "param": "st", "type": "Stack" }, { "param": "u", "type": "Vertex" }, { "param": "disc", "type": "int" }, { "param": "low", "type": "int" }, { "param": "disc_time", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "g", "type": "Graph", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "scc", "type": "SCC_data", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "st", "type": "Stack", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "u", "type": "Vertex", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "disc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "low", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "disc_time", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0e7a23fbd59565ed4baccb3ac75a57218aaeebb6
Keyaku/ist-asa-projects
proj/2017-2018/p2/src/proj.c
[ "MIT" ]
C
graph_get_edge
Edge
Edge graph_get_edge(Graph *g, Pixel u, Pixel v) { Edge adj; /* O(1) : Takes (4 pixel neighbors) amount of time */ for (adj = g->first[u]; adj != 0 && g->pixel[adj] != v; adj = g->next[adj]); return adj; }
/* Returns the index of the connection between two Pixels. 0 if not found. */
Returns the index of the connection between two Pixels. 0 if not found.
[ "Returns", "the", "index", "of", "the", "connection", "between", "two", "Pixels", ".", "0", "if", "not", "found", "." ]
Edge graph_get_edge(Graph *g, Pixel u, Pixel v) { Edge adj; for (adj = g->first[u]; adj != 0 && g->pixel[adj] != v; adj = g->next[adj]); return adj; }
[ "Edge", "graph_get_edge", "(", "Graph", "*", "g", ",", "Pixel", "u", ",", "Pixel", "v", ")", "{", "Edge", "adj", ";", "for", "(", "adj", "=", "g", "->", "first", "[", "u", "]", ";", "adj", "!=", "0", "&&", "g", "->", "pixel", "[", "adj", "]", "!=", "v", ";", "adj", "=", "g", "->", "next", "[", "adj", "]", ")", ";", "return", "adj", ";", "}" ]
Returns the index of the connection between two Pixels.
[ "Returns", "the", "index", "of", "the", "connection", "between", "two", "Pixels", "." ]
[ "/* O(1) : Takes (4 pixel neighbors) amount of time */" ]
[ { "param": "g", "type": "Graph" }, { "param": "u", "type": "Pixel" }, { "param": "v", "type": "Pixel" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "g", "type": "Graph", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "u", "type": "Pixel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v", "type": "Pixel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0e7a23fbd59565ed4baccb3ac75a57218aaeebb6
Keyaku/ist-asa-projects
proj/2017-2018/p2/src/proj.c
[ "MIT" ]
C
graph_connect
Edge
Edge graph_connect(Graph *g, Pixel u, Pixel v, int weight) { Edge e = ++g->nr_edges; g->pixel[e] = v; g->capacity[e] = weight; if (g->first[u] == 0) { g->first[u] = e; } else { Edge adj = g->last[u]; g->next[adj] = e; } g->last[u] = e; return e; }
/* Adds/Removes weight between two Pixels */
Adds/Removes weight between two Pixels
[ "Adds", "/", "Removes", "weight", "between", "two", "Pixels" ]
Edge graph_connect(Graph *g, Pixel u, Pixel v, int weight) { Edge e = ++g->nr_edges; g->pixel[e] = v; g->capacity[e] = weight; if (g->first[u] == 0) { g->first[u] = e; } else { Edge adj = g->last[u]; g->next[adj] = e; } g->last[u] = e; return e; }
[ "Edge", "graph_connect", "(", "Graph", "*", "g", ",", "Pixel", "u", ",", "Pixel", "v", ",", "int", "weight", ")", "{", "Edge", "e", "=", "++", "g", "->", "nr_edges", ";", "g", "->", "pixel", "[", "e", "]", "=", "v", ";", "g", "->", "capacity", "[", "e", "]", "=", "weight", ";", "if", "(", "g", "->", "first", "[", "u", "]", "==", "0", ")", "{", "g", "->", "first", "[", "u", "]", "=", "e", ";", "}", "else", "{", "Edge", "adj", "=", "g", "->", "last", "[", "u", "]", ";", "g", "->", "next", "[", "adj", "]", "=", "e", ";", "}", "g", "->", "last", "[", "u", "]", "=", "e", ";", "return", "e", ";", "}" ]
Adds/Removes weight between two Pixels
[ "Adds", "/", "Removes", "weight", "between", "two", "Pixels" ]
[]
[ { "param": "g", "type": "Graph" }, { "param": "u", "type": "Pixel" }, { "param": "v", "type": "Pixel" }, { "param": "weight", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "g", "type": "Graph", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "u", "type": "Pixel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v", "type": "Pixel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "weight", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0e7a23fbd59565ed4baccb3ac75a57218aaeebb6
Keyaku/ist-asa-projects
proj/2017-2018/p2/src/proj.c
[ "MIT" ]
C
graph_print
void
void graph_print(Graph *g) { Pixel u, v; int i, j = 0; for (i = u = 1; u < g->nr_vertices; i++, u = graph_v_neighbor(g, u)) { /* Printing Pixel's l and c weights */ v = u; for (j = 1; j <= g->n; j++) { printf("( %d | %d )", graph_get_l_weight(g, v), graph_get_c_weight(g, v)); if (j < g->n) { printf(" - %d - ", graph_get_f_weight(g, v, v+1)); } v = graph_h_neighbor(g, v); } printf("\n"); if (i >= g->m) { break; } /* Drawing 1st separator */ for (j = 1; j <= g->n; j++) { print_spaces(4); printf("|"); if (j < g->n) { print_spaces(11); } } printf("\n"); /* Printing vertical Edge weights */ v = u; for (j = 1; j <= g->n; j++) { print_spaces(4); printf("%d", graph_get_f_weight(g, v, graph_v_neighbor(g, v))); if (j < g->n) { print_spaces(11); } v = graph_h_neighbor(g, v); } printf("\n"); /* Drawing 2nd separator */ for (j = 1; j <= g->n; j++) { print_spaces(4); printf("|"); if (j < g->n) { print_spaces(11); } } printf("\n"); } }
/* Prints weights of the Graph's Pixels and their connections */
Prints weights of the Graph's Pixels and their connections
[ "Prints", "weights", "of", "the", "Graph", "'", "s", "Pixels", "and", "their", "connections" ]
void graph_print(Graph *g) { Pixel u, v; int i, j = 0; for (i = u = 1; u < g->nr_vertices; i++, u = graph_v_neighbor(g, u)) { v = u; for (j = 1; j <= g->n; j++) { printf("( %d | %d )", graph_get_l_weight(g, v), graph_get_c_weight(g, v)); if (j < g->n) { printf(" - %d - ", graph_get_f_weight(g, v, v+1)); } v = graph_h_neighbor(g, v); } printf("\n"); if (i >= g->m) { break; } for (j = 1; j <= g->n; j++) { print_spaces(4); printf("|"); if (j < g->n) { print_spaces(11); } } printf("\n"); v = u; for (j = 1; j <= g->n; j++) { print_spaces(4); printf("%d", graph_get_f_weight(g, v, graph_v_neighbor(g, v))); if (j < g->n) { print_spaces(11); } v = graph_h_neighbor(g, v); } printf("\n"); for (j = 1; j <= g->n; j++) { print_spaces(4); printf("|"); if (j < g->n) { print_spaces(11); } } printf("\n"); } }
[ "void", "graph_print", "(", "Graph", "*", "g", ")", "{", "Pixel", "u", ",", "v", ";", "int", "i", ",", "j", "=", "0", ";", "for", "(", "i", "=", "u", "=", "1", ";", "u", "<", "g", "->", "nr_vertices", ";", "i", "++", ",", "u", "=", "graph_v_neighbor", "(", "g", ",", "u", ")", ")", "{", "v", "=", "u", ";", "for", "(", "j", "=", "1", ";", "j", "<=", "g", "->", "n", ";", "j", "++", ")", "{", "printf", "(", "\"", "\"", ",", "graph_get_l_weight", "(", "g", ",", "v", ")", ",", "graph_get_c_weight", "(", "g", ",", "v", ")", ")", ";", "if", "(", "j", "<", "g", "->", "n", ")", "{", "printf", "(", "\"", "\"", ",", "graph_get_f_weight", "(", "g", ",", "v", ",", "v", "+", "1", ")", ")", ";", "}", "v", "=", "graph_h_neighbor", "(", "g", ",", "v", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "if", "(", "i", ">=", "g", "->", "m", ")", "{", "break", ";", "}", "for", "(", "j", "=", "1", ";", "j", "<=", "g", "->", "n", ";", "j", "++", ")", "{", "print_spaces", "(", "4", ")", ";", "printf", "(", "\"", "\"", ")", ";", "if", "(", "j", "<", "g", "->", "n", ")", "{", "print_spaces", "(", "11", ")", ";", "}", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "v", "=", "u", ";", "for", "(", "j", "=", "1", ";", "j", "<=", "g", "->", "n", ";", "j", "++", ")", "{", "print_spaces", "(", "4", ")", ";", "printf", "(", "\"", "\"", ",", "graph_get_f_weight", "(", "g", ",", "v", ",", "graph_v_neighbor", "(", "g", ",", "v", ")", ")", ")", ";", "if", "(", "j", "<", "g", "->", "n", ")", "{", "print_spaces", "(", "11", ")", ";", "}", "v", "=", "graph_h_neighbor", "(", "g", ",", "v", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "for", "(", "j", "=", "1", ";", "j", "<=", "g", "->", "n", ";", "j", "++", ")", "{", "print_spaces", "(", "4", ")", ";", "printf", "(", "\"", "\"", ")", ";", "if", "(", "j", "<", "g", "->", "n", ")", "{", "print_spaces", "(", "11", ")", ";", "}", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "}" ]
Prints weights of the Graph's Pixels and their connections
[ "Prints", "weights", "of", "the", "Graph", "'", "s", "Pixels", "and", "their", "connections" ]
[ "/* Printing Pixel's l and c weights */", "/* Drawing 1st separator */", "/* Printing vertical Edge weights */", "/* Drawing 2nd separator */" ]
[ { "param": "g", "type": "Graph" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "g", "type": "Graph", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0e7a23fbd59565ed4baccb3ac75a57218aaeebb6
Keyaku/ist-asa-projects
proj/2017-2018/p2/src/proj.c
[ "MIT" ]
C
graph_print_segments
void
void graph_print_segments(Graph *g) { int i, j; for (i = 1; i <= g->m; i++) { /* Printing Pixel's segment type */ for (j = 1; j <= g->n; j++) { Pixel u = graph_get_pixel(g, i, j); printf("%c ", g->segments[u]); } printf("\n"); } }
/* Prints the Graph represented through P or C */
Prints the Graph represented through P or C
[ "Prints", "the", "Graph", "represented", "through", "P", "or", "C" ]
void graph_print_segments(Graph *g) { int i, j; for (i = 1; i <= g->m; i++) { for (j = 1; j <= g->n; j++) { Pixel u = graph_get_pixel(g, i, j); printf("%c ", g->segments[u]); } printf("\n"); } }
[ "void", "graph_print_segments", "(", "Graph", "*", "g", ")", "{", "int", "i", ",", "j", ";", "for", "(", "i", "=", "1", ";", "i", "<=", "g", "->", "m", ";", "i", "++", ")", "{", "for", "(", "j", "=", "1", ";", "j", "<=", "g", "->", "n", ";", "j", "++", ")", "{", "Pixel", "u", "=", "graph_get_pixel", "(", "g", ",", "i", ",", "j", ")", ";", "printf", "(", "\"", "\"", ",", "g", "->", "segments", "[", "u", "]", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "}" ]
Prints the Graph represented through P or C
[ "Prints", "the", "Graph", "represented", "through", "P", "or", "C" ]
[ "/* Printing Pixel's segment type */" ]
[ { "param": "g", "type": "Graph" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "g", "type": "Graph", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
reserve
bool
bool reserve( size_t nReserveSize ) { if ( AllocTable( nReserveSize, true ) == false ) { return false; } if ( m_nNumReserved < m_nNumItems ) { m_nNumItems = nReserveSize; } return true; }
//-------------------------------------------------------------------------- /// \brief Reserve memory /// /// Reserve memory enough to store reserveSize items /// so that each push_back will not have to reallocate memory until /// reserveSize items is reached. /// /// \param \reserveSize Number of items to reserve memory for /// \return None //--------------------------------------------------------------------------
\brief Reserve memory Reserve memory enough to store reserveSize items so that each push_back will not have to reallocate memory until reserveSize items is reached. \param \reserveSize Number of items to reserve memory for \return None
[ "\\", "brief", "Reserve", "memory", "Reserve", "memory", "enough", "to", "store", "reserveSize", "items", "so", "that", "each", "push_back", "will", "not", "have", "to", "reallocate", "memory", "until", "reserveSize", "items", "is", "reached", ".", "\\", "param", "\\", "reserveSize", "Number", "of", "items", "to", "reserve", "memory", "for", "\\", "return", "None" ]
bool reserve( size_t nReserveSize ) { if ( AllocTable( nReserveSize, true ) == false ) { return false; } if ( m_nNumReserved < m_nNumItems ) { m_nNumItems = nReserveSize; } return true; }
[ "bool", "reserve", "(", "size_t", "nReserveSize", ")", "{", "if", "(", "AllocTable", "(", "nReserveSize", ",", "true", ")", "==", "false", ")", "{", "return", "false", ";", "}", "if", "(", "m_nNumReserved", "<", "m_nNumItems", ")", "{", "m_nNumItems", "=", "nReserveSize", ";", "}", "return", "true", ";", "}" ]
\brief Reserve memory Reserve memory enough to store reserveSize items so that each push_back will not have to reallocate memory until reserveSize items is reached.
[ "\\", "brief", "Reserve", "memory", "Reserve", "memory", "enough", "to", "store", "reserveSize", "items", "so", "that", "each", "push_back", "will", "not", "have", "to", "reallocate", "memory", "until", "reserveSize", "items", "is", "reached", "." ]
[]
[ { "param": "nReserveSize", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "nReserveSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
resize
bool
bool resize( size_t nNewSize ) { if ( nNewSize >= m_nNumReserved ) { if ( AllocTable( nNewSize, true ) == false ) { return false; } } // End if m_nNumItems = nNewSize; return true; }
//-------------------------------------------------------------------------- /// \brief Resize size of array /// /// Adjusts the size of the array /// /// \param newSize Number of items /// \return None //--------------------------------------------------------------------------
\brief Resize size of array Adjusts the size of the array \param newSize Number of items \return None
[ "\\", "brief", "Resize", "size", "of", "array", "Adjusts", "the", "size", "of", "the", "array", "\\", "param", "newSize", "Number", "of", "items", "\\", "return", "None" ]
bool resize( size_t nNewSize ) { if ( nNewSize >= m_nNumReserved ) { if ( AllocTable( nNewSize, true ) == false ) { return false; } } m_nNumItems = nNewSize; return true; }
[ "bool", "resize", "(", "size_t", "nNewSize", ")", "{", "if", "(", "nNewSize", ">=", "m_nNumReserved", ")", "{", "if", "(", "AllocTable", "(", "nNewSize", ",", "true", ")", "==", "false", ")", "{", "return", "false", ";", "}", "}", "m_nNumItems", "=", "nNewSize", ";", "return", "true", ";", "}" ]
\brief Resize size of array Adjusts the size of the array
[ "\\", "brief", "Resize", "size", "of", "array", "Adjusts", "the", "size", "of", "the", "array" ]
[ "// End if\r" ]
[ { "param": "nNewSize", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "nNewSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
clear
bool
bool clear() { DeallocTable(); return true; }
//-------------------------------------------------------------------------- /// \brief Destroy allocated memory /// /// Clears the entire array, and frees any allocated memory /// /// \return None //--------------------------------------------------------------------------
\brief Destroy allocated memory Clears the entire array, and frees any allocated memory \return None
[ "\\", "brief", "Destroy", "allocated", "memory", "Clears", "the", "entire", "array", "and", "frees", "any", "allocated", "memory", "\\", "return", "None" ]
bool clear() { DeallocTable(); return true; }
[ "bool", "clear", "(", ")", "{", "DeallocTable", "(", ")", ";", "return", "true", ";", "}" ]
\brief Destroy allocated memory Clears the entire array, and frees any allocated memory
[ "\\", "brief", "Destroy", "allocated", "memory", "Clears", "the", "entire", "array", "and", "frees", "any", "allocated", "memory" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
push_back
bool
bool push_back( Type data ) { if ( m_nNumItems >= m_nNumReserved ) { if ( DoubleTableSize( true ) == false ) { return false; } } // End if m_pTable[m_nNumItems] = data; m_nNumItems++; return true; }
//-------------------------------------------------------------------------- /// \brief Add new item to end of array /// /// Add an item to the back of the array /// /// \param data Data to add /// \return true on success //--------------------------------------------------------------------------
\brief Add new item to end of array Add an item to the back of the array \param data Data to add \return true on success
[ "\\", "brief", "Add", "new", "item", "to", "end", "of", "array", "Add", "an", "item", "to", "the", "back", "of", "the", "array", "\\", "param", "data", "Data", "to", "add", "\\", "return", "true", "on", "success" ]
bool push_back( Type data ) { if ( m_nNumItems >= m_nNumReserved ) { if ( DoubleTableSize( true ) == false ) { return false; } } m_pTable[m_nNumItems] = data; m_nNumItems++; return true; }
[ "bool", "push_back", "(", "Type", "data", ")", "{", "if", "(", "m_nNumItems", ">=", "m_nNumReserved", ")", "{", "if", "(", "DoubleTableSize", "(", "true", ")", "==", "false", ")", "{", "return", "false", ";", "}", "}", "m_pTable", "[", "m_nNumItems", "]", "=", "data", ";", "m_nNumItems", "++", ";", "return", "true", ";", "}" ]
\brief Add new item to end of array Add an item to the back of the array
[ "\\", "brief", "Add", "new", "item", "to", "end", "of", "array", "Add", "an", "item", "to", "the", "back", "of", "the", "array" ]
[ "// End if\r" ]
[ { "param": "data", "type": "Type" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "Type", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
pop_back
void
void pop_back() { if( m_nNumItems > 0 ) { ReduceNumItems(); } }
//-------------------------------------------------------------------------- /// \brief Remove the last element in the array //--------------------------------------------------------------------------
\brief Remove the last element in the array
[ "\\", "brief", "Remove", "the", "last", "element", "in", "the", "array" ]
void pop_back() { if( m_nNumItems > 0 ) { ReduceNumItems(); } }
[ "void", "pop_back", "(", ")", "{", "if", "(", "m_nNumItems", ">", "0", ")", "{", "ReduceNumItems", "(", ")", ";", "}", "}" ]
\brief Remove the last element in the array
[ "\\", "brief", "Remove", "the", "last", "element", "in", "the", "array" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
DoubleTableSize
bool
bool DoubleTableSize( bool bPreserve ) { if( m_nNumReserved == 0 ) { return AllocTable( 1, false ); } else { return AllocTable( m_nNumReserved*2, true ); } }
//--------------------------------------------------------------------------------------- /// \brief DoubleTableSize /// /// Doubles the size of the table /// /// \return true on success //--------------------------------------------------------------------------------------
\brief DoubleTableSize Doubles the size of the table \return true on success
[ "\\", "brief", "DoubleTableSize", "Doubles", "the", "size", "of", "the", "table", "\\", "return", "true", "on", "success" ]
bool DoubleTableSize( bool bPreserve ) { if( m_nNumReserved == 0 ) { return AllocTable( 1, false ); } else { return AllocTable( m_nNumReserved*2, true ); } }
[ "bool", "DoubleTableSize", "(", "bool", "bPreserve", ")", "{", "if", "(", "m_nNumReserved", "==", "0", ")", "{", "return", "AllocTable", "(", "1", ",", "false", ")", ";", "}", "else", "{", "return", "AllocTable", "(", "m_nNumReserved", "*", "2", ",", "true", ")", ";", "}", "}" ]
\brief DoubleTableSize Doubles the size of the table
[ "\\", "brief", "DoubleTableSize", "Doubles", "the", "size", "of", "the", "table" ]
[]
[ { "param": "bPreserve", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bPreserve", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
ReduceNumItems
bool
bool ReduceNumItems( ) { m_nNumItems--; if( m_nNumItems < (m_nNumReserved / 4) ) { return AllocTable( m_nNumReserved / 2, true ); } return true; }
//--------------------------------------------------------------------------------------- /// \brief ReduceNumItems /// /// Decrements the number of items, and re-sizes the array if it is less than 1/4 full /// /// \return true on success //--------------------------------------------------------------------------------------
\brief ReduceNumItems Decrements the number of items, and re-sizes the array if it is less than 1/4 full \return true on success
[ "\\", "brief", "ReduceNumItems", "Decrements", "the", "number", "of", "items", "and", "re", "-", "sizes", "the", "array", "if", "it", "is", "less", "than", "1", "/", "4", "full", "\\", "return", "true", "on", "success" ]
bool ReduceNumItems( ) { m_nNumItems--; if( m_nNumItems < (m_nNumReserved / 4) ) { return AllocTable( m_nNumReserved / 2, true ); } return true; }
[ "bool", "ReduceNumItems", "(", ")", "{", "m_nNumItems", "--", ";", "if", "(", "m_nNumItems", "<", "(", "m_nNumReserved", "/", "4", ")", ")", "{", "return", "AllocTable", "(", "m_nNumReserved", "/", "2", ",", "true", ")", ";", "}", "return", "true", ";", "}" ]
\brief ReduceNumItems Decrements the number of items, and re-sizes the array if it is less than 1/4 full
[ "\\", "brief", "ReduceNumItems", "Decrements", "the", "number", "of", "items", "and", "re", "-", "sizes", "the", "array", "if", "it", "is", "less", "than", "1", "/", "4", "full" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
16565ed778a92d3f30cbd07144a8ca17c5ab5788
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuArray.h
[ "MIT" ]
C
ShiftData
bool
bool ShiftData( size_t nStartIndex, int nDirection ) { if( m_nNumItems == 0 ) { return false; } if ( nDirection > 0 ) { SU_ASSERT(( m_nNumItems + nDirection ) <= m_nNumReserved ); for ( size_t i = m_nNumItems - 1; i > nStartIndex; i-- ) { m_pTable[ i + nDirection ] = m_pTable[ i ]; } // End for // copy the last element as a special case, in case nStartIndex == 0 m_pTable[ nStartIndex + nDirection ] = m_pTable[nStartIndex]; } // End if else { SU_ASSERT(( m_nNumItems + nDirection ) >= 0 ); for ( size_t i = nStartIndex; i < m_nNumItems; i++ ) { m_pTable[ i + nDirection ] = m_pTable[ i ]; } // End for } // End else return true; }
//-------------------------------------------------------------------------- /// \brief Shift array of data /// /// Data shifting /// /// - If direction is positive, shift data towards end /// If direction is negative, shift data towards zero /// This function will not update number of items etc /// /// \param nStartIndex Location to start shifting /// \partam nDirection Direction to shift to /// \return true on success //--------------------------------------------------------------------------
\brief Shift array of data Data shifting If direction is positive, shift data towards end If direction is negative, shift data towards zero This function will not update number of items etc \param nStartIndex Location to start shifting \partam nDirection Direction to shift to \return true on success
[ "\\", "brief", "Shift", "array", "of", "data", "Data", "shifting", "If", "direction", "is", "positive", "shift", "data", "towards", "end", "If", "direction", "is", "negative", "shift", "data", "towards", "zero", "This", "function", "will", "not", "update", "number", "of", "items", "etc", "\\", "param", "nStartIndex", "Location", "to", "start", "shifting", "\\", "partam", "nDirection", "Direction", "to", "shift", "to", "\\", "return", "true", "on", "success" ]
bool ShiftData( size_t nStartIndex, int nDirection ) { if( m_nNumItems == 0 ) { return false; } if ( nDirection > 0 ) { SU_ASSERT(( m_nNumItems + nDirection ) <= m_nNumReserved ); for ( size_t i = m_nNumItems - 1; i > nStartIndex; i-- ) { m_pTable[ i + nDirection ] = m_pTable[ i ]; } m_pTable[ nStartIndex + nDirection ] = m_pTable[nStartIndex]; } else { SU_ASSERT(( m_nNumItems + nDirection ) >= 0 ); for ( size_t i = nStartIndex; i < m_nNumItems; i++ ) { m_pTable[ i + nDirection ] = m_pTable[ i ]; } } return true; }
[ "bool", "ShiftData", "(", "size_t", "nStartIndex", ",", "int", "nDirection", ")", "{", "if", "(", "m_nNumItems", "==", "0", ")", "{", "return", "false", ";", "}", "if", "(", "nDirection", ">", "0", ")", "{", "SU_ASSERT", "(", "(", "m_nNumItems", "+", "nDirection", ")", "<=", "m_nNumReserved", ")", ";", "for", "(", "size_t", "i", "=", "m_nNumItems", "-", "1", ";", "i", ">", "nStartIndex", ";", "i", "--", ")", "{", "m_pTable", "[", "i", "+", "nDirection", "]", "=", "m_pTable", "[", "i", "]", ";", "}", "m_pTable", "[", "nStartIndex", "+", "nDirection", "]", "=", "m_pTable", "[", "nStartIndex", "]", ";", "}", "else", "{", "SU_ASSERT", "(", "(", "m_nNumItems", "+", "nDirection", ")", ">=", "0", ")", ";", "for", "(", "size_t", "i", "=", "nStartIndex", ";", "i", "<", "m_nNumItems", ";", "i", "++", ")", "{", "m_pTable", "[", "i", "+", "nDirection", "]", "=", "m_pTable", "[", "i", "]", ";", "}", "}", "return", "true", ";", "}" ]
\brief Shift array of data Data shifting
[ "\\", "brief", "Shift", "array", "of", "data", "Data", "shifting" ]
[ "// End for\r", "// copy the last element as a special case, in case nStartIndex == 0\r", "// End if\r", "// End for\r", "// End else\r" ]
[ { "param": "nStartIndex", "type": "size_t" }, { "param": "nDirection", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "nStartIndex", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nDirection", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
77fe2947bd0f1d7ec0bae98e41f4c5f018b76328
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuHashMap.h
[ "MIT" ]
C
Incrementm_nNumDeletedCells
void
void Incrementm_nNumDeletedCells() { if (++m_nNumDeletedCells >= m_nMaxLengthTimesResizeRatio) Resize(m_nMaxLength); }
//-------------------------------------------------------------------------- /// Increment the number of deleted cells, resize if necessary //--------------------------------------------------------------------------
Increment the number of deleted cells, resize if necessary
[ "Increment", "the", "number", "of", "deleted", "cells", "resize", "if", "necessary" ]
void Incrementm_nNumDeletedCells() { if (++m_nNumDeletedCells >= m_nMaxLengthTimesResizeRatio) Resize(m_nMaxLength); }
[ "void", "Incrementm_nNumDeletedCells", "(", ")", "{", "if", "(", "++", "m_nNumDeletedCells", ">=", "m_nMaxLengthTimesResizeRatio", ")", "Resize", "(", "m_nMaxLength", ")", ";", "}" ]
Increment the number of deleted cells, resize if necessary
[ "Increment", "the", "number", "of", "deleted", "cells", "resize", "if", "necessary" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
77fe2947bd0f1d7ec0bae98e41f4c5f018b76328
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuHashMap.h
[ "MIT" ]
C
Decrementm_nNumDeletedCells
void
void Decrementm_nNumDeletedCells() { m_nNumDeletedCells--; SU_ASSERT( (m_nNumDeletedCells >= 0) ); }
//-------------------------------------------------------------------------- /// Reduce the number of deleted cells //--------------------------------------------------------------------------
Reduce the number of deleted cells
[ "Reduce", "the", "number", "of", "deleted", "cells" ]
void Decrementm_nNumDeletedCells() { m_nNumDeletedCells--; SU_ASSERT( (m_nNumDeletedCells >= 0) ); }
[ "void", "Decrementm_nNumDeletedCells", "(", ")", "{", "m_nNumDeletedCells", "--", ";", "SU_ASSERT", "(", "(", "m_nNumDeletedCells", ">=", "0", ")", ")", ";", "}" ]
Reduce the number of deleted cells
[ "Reduce", "the", "number", "of", "deleted", "cells" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
77fe2947bd0f1d7ec0bae98e41f4c5f018b76328
kostenickj/TressFX
amd_tressfx_sample/prebuilt/include/Common/include/SuHashMap.h
[ "MIT" ]
C
RoundUpToPowerOfTwo
uint32
uint32 RoundUpToPowerOfTwo(uint32 x) { uint32 returnValue = 1; for (; x > returnValue; returnValue*=2) ; // ';' is body of for loop return returnValue; }
//-------------------------------------------------------------------------- /// Utility routine to round a value up to the closest power of 2 //--------------------------------------------------------------------------
Utility routine to round a value up to the closest power of 2
[ "Utility", "routine", "to", "round", "a", "value", "up", "to", "the", "closest", "power", "of", "2" ]
uint32 RoundUpToPowerOfTwo(uint32 x) { uint32 returnValue = 1; for (; x > returnValue; returnValue*=2) ; return returnValue; }
[ "uint32", "RoundUpToPowerOfTwo", "(", "uint32", "x", ")", "{", "uint32", "returnValue", "=", "1", ";", "for", "(", ";", "x", ">", "returnValue", ";", "returnValue", "*=", "2", ")", ";", "return", "returnValue", ";", "}" ]
Utility routine to round a value up to the closest power of 2
[ "Utility", "routine", "to", "round", "a", "value", "up", "to", "the", "closest", "power", "of", "2" ]
[ "// ';' is body of for loop\r" ]
[ { "param": "x", "type": "uint32" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "x", "type": "uint32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
dca9e745eb5037468c9b98a9a90a2ed9c381292e
skeeto/bfc
codegen.c
[ "Unlicense" ]
C
im_codegen
void
void im_codegen (inst_t * head) { /* Handle threads */ static int thread_cnt = 0; if (bfthreads) { fprintf (bfout, "void *bf%d (void *x) {\n", thread_cnt); fprintf (bfout, " int ptri = %d;\n\n", thread_cnt); thread_cnt++; } indent = 1; int returned = 0; inst_t *inst = head; while (inst != NULL) { lineno = inst->lineno; if (inst->comment && pass_comments) { fprintf (bfout, "/*\n %s \n*/\n", inst->comment); } switch (inst->inst * !returned) { case IM_CINC: /* Cell increment */ print_incdec ('+', inst->src); break; case IM_CDEC: /* Cell decrement */ print_incdec ('-', inst->src); break; case IM_PRGHT: /* Move pointer right */ print_move ('>', inst->src); break; case IM_PLEFT: /* Move pointer left */ print_move ('<', inst->src); break; case IM_IN: /* Input */ print_input (); break; case IM_OUT: /* Output */ print_output (); break; case IM_CADD: /* Cell copy */ print_ccpy (inst->dst, inst->src); break; case IM_CCLR: /* Cell clear */ print_cclr (); break; } /* Select next instruction. First from loop, then from next, then from ret. */ if (inst->loop && !returned) { print_loop (); inst = inst->loop; returned = 0; indent++; } else if (inst->next) { inst = inst->next; returned = 0; } else if (inst->ret) { print_end (); inst = inst->ret; returned = 1; indent--; } else inst = NULL; } if (bfthreads) { fprintf (bfout, "\n"); fprintf (bfout, " pthread_exit (NULL);\n"); fprintf (bfout, "} /* thread %d */\n\n", thread_cnt - 1); } }
/* Walk through intermediate tree and generate code. */
Walk through intermediate tree and generate code.
[ "Walk", "through", "intermediate", "tree", "and", "generate", "code", "." ]
void im_codegen (inst_t * head) { static int thread_cnt = 0; if (bfthreads) { fprintf (bfout, "void *bf%d (void *x) {\n", thread_cnt); fprintf (bfout, " int ptri = %d;\n\n", thread_cnt); thread_cnt++; } indent = 1; int returned = 0; inst_t *inst = head; while (inst != NULL) { lineno = inst->lineno; if (inst->comment && pass_comments) { fprintf (bfout, "/*\n %s \n*/\n", inst->comment); } switch (inst->inst * !returned) { case IM_CINC: print_incdec ('+', inst->src); break; case IM_CDEC: print_incdec ('-', inst->src); break; case IM_PRGHT: print_move ('>', inst->src); break; case IM_PLEFT: print_move ('<', inst->src); break; case IM_IN: print_input (); break; case IM_OUT: print_output (); break; case IM_CADD: print_ccpy (inst->dst, inst->src); break; case IM_CCLR: print_cclr (); break; } if (inst->loop && !returned) { print_loop (); inst = inst->loop; returned = 0; indent++; } else if (inst->next) { inst = inst->next; returned = 0; } else if (inst->ret) { print_end (); inst = inst->ret; returned = 1; indent--; } else inst = NULL; } if (bfthreads) { fprintf (bfout, "\n"); fprintf (bfout, " pthread_exit (NULL);\n"); fprintf (bfout, "} /* thread %d */\n\n", thread_cnt - 1); } }
[ "void", "im_codegen", "(", "inst_t", "*", "head", ")", "{", "static", "int", "thread_cnt", "=", "0", ";", "if", "(", "bfthreads", ")", "{", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ",", "thread_cnt", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\\n", "\"", ",", "thread_cnt", ")", ";", "thread_cnt", "++", ";", "}", "indent", "=", "1", ";", "int", "returned", "=", "0", ";", "inst_t", "*", "inst", "=", "head", ";", "while", "(", "inst", "!=", "NULL", ")", "{", "lineno", "=", "inst", "->", "lineno", ";", "if", "(", "inst", "->", "comment", "&&", "pass_comments", ")", "{", "fprintf", "(", "bfout", ",", "\"", "\\n", "\\n", "\\n", "\"", ",", "inst", "->", "comment", ")", ";", "}", "switch", "(", "inst", "->", "inst", "*", "!", "returned", ")", "{", "case", "IM_CINC", ":", "print_incdec", "(", "'", "'", ",", "inst", "->", "src", ")", ";", "break", ";", "case", "IM_CDEC", ":", "print_incdec", "(", "'", "'", ",", "inst", "->", "src", ")", ";", "break", ";", "case", "IM_PRGHT", ":", "print_move", "(", "'", "'", ",", "inst", "->", "src", ")", ";", "break", ";", "case", "IM_PLEFT", ":", "print_move", "(", "'", "'", ",", "inst", "->", "src", ")", ";", "break", ";", "case", "IM_IN", ":", "print_input", "(", ")", ";", "break", ";", "case", "IM_OUT", ":", "print_output", "(", ")", ";", "break", ";", "case", "IM_CADD", ":", "print_ccpy", "(", "inst", "->", "dst", ",", "inst", "->", "src", ")", ";", "break", ";", "case", "IM_CCLR", ":", "print_cclr", "(", ")", ";", "break", ";", "}", "if", "(", "inst", "->", "loop", "&&", "!", "returned", ")", "{", "print_loop", "(", ")", ";", "inst", "=", "inst", "->", "loop", ";", "returned", "=", "0", ";", "indent", "++", ";", "}", "else", "if", "(", "inst", "->", "next", ")", "{", "inst", "=", "inst", "->", "next", ";", "returned", "=", "0", ";", "}", "else", "if", "(", "inst", "->", "ret", ")", "{", "print_end", "(", ")", ";", "inst", "=", "inst", "->", "ret", ";", "returned", "=", "1", ";", "indent", "--", ";", "}", "else", "inst", "=", "NULL", ";", "}", "if", "(", "bfthreads", ")", "{", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\\n", "\"", ",", "thread_cnt", "-", "1", ")", ";", "}", "}" ]
Walk through intermediate tree and generate code.
[ "Walk", "through", "intermediate", "tree", "and", "generate", "code", "." ]
[ "/* Handle threads */", "/* Cell increment */", "/* Cell decrement */", "/* Move pointer right */", "/* Move pointer left */", "/* Input */", "/* Output */", "/* Cell copy */", "/* Cell clear */", "/* Select next instruction. First from loop, then from next,\n then from ret. */" ]
[ { "param": "head", "type": "inst_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "head", "type": "inst_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
dca9e745eb5037468c9b98a9a90a2ed9c381292e
skeeto/bfc
codegen.c
[ "Unlicense" ]
C
print_tail
void
void print_tail () { /* Blank line */ print_indent (); fprintf (bfout, "\n"); if (dump_core) { print_indent (); fprintf (bfout, "dump_core (%s, %s);\n", bfstr_buffer, bfstr_bsize); } print_indent (); fprintf (bfout, "exit (EXIT_SUCCESS);\n"); fprintf (bfout, "}\n"); }
/* Print the bottom of the C file */
Print the bottom of the C file
[ "Print", "the", "bottom", "of", "the", "C", "file" ]
void print_tail () { print_indent (); fprintf (bfout, "\n"); if (dump_core) { print_indent (); fprintf (bfout, "dump_core (%s, %s);\n", bfstr_buffer, bfstr_bsize); } print_indent (); fprintf (bfout, "exit (EXIT_SUCCESS);\n"); fprintf (bfout, "}\n"); }
[ "void", "print_tail", "(", ")", "{", "print_indent", "(", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ")", ";", "if", "(", "dump_core", ")", "{", "print_indent", "(", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ",", "bfstr_buffer", ",", "bfstr_bsize", ")", ";", "}", "print_indent", "(", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ")", ";", "fprintf", "(", "bfout", ",", "\"", "\\n", "\"", ")", ";", "}" ]
Print the bottom of the C file
[ "Print", "the", "bottom", "of", "the", "C", "file" ]
[ "/* Blank line */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f73564a9418dc4738603a3a1b8ec27461d748716
CoinCheung/image_processing
cserver.c
[ "MIT" ]
C
enter_socket_listen
void
void enter_socket_listen() { /* varaiables */ struct sockaddr_in server_addr; // server address struct sockaddr_in client_addr; // request client address int socket_server = -1; // 建立失败不返回值,保持-1 int socket_client = -1; // 没得到client的socket信息,返回值不变 int bind_result = -1; // bind 失败不返回值 int listen_result = -1; // 监听失败无返回值,仍为-1 socklen_t client_addr_len = 0; char receive_buffer[1024]; unsigned int free_port_num; char *resp = "1"; char *endflag = "end"; img_para img_para; /* find an unoccupied port */ free_port_num = scan_leisure_port(); printf("server: find free port ... done\n server: port number is: %d\n",free_port_num); free_port_num = 4000; fprintf(stdout,"server: set the server port number as:%d\n",free_port_num); /* initalize server address struct */ server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); //监听任何一个地址 server_addr.sin_port = htons(4000); //使用free_port_num端口 /* create server socket */ socket_server = socket(AF_INET, SOCK_STREAM, 0); //使用网络通信模式,tcp通信 if(socket_server == -1) { perror("create server socket failed!\n"); close(socket_server); exit(0); } printf("server: establish server socket ... done \n"); /* bind socket with the listening port */ bind_result = bind(socket_server, (struct sockaddr *)&server_addr, sizeof(server_addr)); if(bind_result == -1) { perror("cannot bind the server socket to port free_port_num\n"); close(socket_server); exit(0); } printf("server: bind to port ... done \n"); /* let socket listen to the port it binde */ listen_result = listen(socket_server, 5); if(listen_result == -1) { perror("server listen to port failed\n"); close(socket_server); exit(1); } printf("server: listening ... \n\n\n"); // loop to serve the client connection while(true) { /* establish the connection when a requset is accepted */ client_addr_len = sizeof(client_addr); socket_client = accept(socket_server, (struct sockaddr *)&client_addr, &client_addr_len); if(socket_client == -1) { perror("cannot get client socket information\n"); close(socket_server); close(socket_client); exit(0); } printf("server: connection establishing ... done \n"); /* receive image information sent by client */ img_para = receive_img_data(socket_server, socket_client); fputs("server: Image pixel data received\n",stdout); /* handle the picture in a sub thread */ create_thread_handle(0, &img_para,socket_server,socket_client); /* check if end signal received */ memset(receive_buffer, 0, sizeof(receive_buffer)); read(socket_client, receive_buffer, sizeof(receive_buffer)); fprintf(stdout,"server: receive end flag: %s\n",receive_buffer); write(socket_client,resp,strlen(resp)); if(!strcmp(receive_buffer,endflag)) break; } // wait for the client to disconnect and kill the sokcets fputs("server: exit signal received, wait for client to exit ... done \n",stdout); fputs("server: join for the sub-threads \n",stdout); pthread_join(thread, NULL); fputs("server: all sub-thread terminated \n",stdout); free(img_para.data); fputs("\nserver: closing sockets \n",stdout); shutdown(socket_client, SHUT_RDWR); shutdown(socket_server, SHUT_RDWR); sleep(2); close(socket_client); close(socket_server); fputs("server: exited\n",stdout); }
/* function: void enter_socket_listen() * * establish server socket * run the socket server and listen to a leisure port * * input: * return: * */
void enter_socket_listen() establish server socket run the socket server and listen to a leisure port
[ "void", "enter_socket_listen", "()", "establish", "server", "socket", "run", "the", "socket", "server", "and", "listen", "to", "a", "leisure", "port" ]
void enter_socket_listen() { struct sockaddr_in server_addr; struct sockaddr_in client_addr; int socket_server = -1; int socket_client = -1; int bind_result = -1; int listen_result = -1; socklen_t client_addr_len = 0; char receive_buffer[1024]; unsigned int free_port_num; char *resp = "1"; char *endflag = "end"; img_para img_para; free_port_num = scan_leisure_port(); printf("server: find free port ... done\n server: port number is: %d\n",free_port_num); free_port_num = 4000; fprintf(stdout,"server: set the server port number as:%d\n",free_port_num); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(4000); socket_server = socket(AF_INET, SOCK_STREAM, 0); if(socket_server == -1) { perror("create server socket failed!\n"); close(socket_server); exit(0); } printf("server: establish server socket ... done \n"); bind_result = bind(socket_server, (struct sockaddr *)&server_addr, sizeof(server_addr)); if(bind_result == -1) { perror("cannot bind the server socket to port free_port_num\n"); close(socket_server); exit(0); } printf("server: bind to port ... done \n"); listen_result = listen(socket_server, 5); if(listen_result == -1) { perror("server listen to port failed\n"); close(socket_server); exit(1); } printf("server: listening ... \n\n\n"); while(true) { client_addr_len = sizeof(client_addr); socket_client = accept(socket_server, (struct sockaddr *)&client_addr, &client_addr_len); if(socket_client == -1) { perror("cannot get client socket information\n"); close(socket_server); close(socket_client); exit(0); } printf("server: connection establishing ... done \n"); img_para = receive_img_data(socket_server, socket_client); fputs("server: Image pixel data received\n",stdout); create_thread_handle(0, &img_para,socket_server,socket_client); memset(receive_buffer, 0, sizeof(receive_buffer)); read(socket_client, receive_buffer, sizeof(receive_buffer)); fprintf(stdout,"server: receive end flag: %s\n",receive_buffer); write(socket_client,resp,strlen(resp)); if(!strcmp(receive_buffer,endflag)) break; } fputs("server: exit signal received, wait for client to exit ... done \n",stdout); fputs("server: join for the sub-threads \n",stdout); pthread_join(thread, NULL); fputs("server: all sub-thread terminated \n",stdout); free(img_para.data); fputs("\nserver: closing sockets \n",stdout); shutdown(socket_client, SHUT_RDWR); shutdown(socket_server, SHUT_RDWR); sleep(2); close(socket_client); close(socket_server); fputs("server: exited\n",stdout); }
[ "void", "enter_socket_listen", "(", ")", "{", "struct", "sockaddr_in", "server_addr", ";", "struct", "sockaddr_in", "client_addr", ";", "int", "socket_server", "=", "-1", ";", "int", "socket_client", "=", "-1", ";", "int", "bind_result", "=", "-1", ";", "int", "listen_result", "=", "-1", ";", "socklen_t", "client_addr_len", "=", "0", ";", "char", "receive_buffer", "[", "1024", "]", ";", "unsigned", "int", "free_port_num", ";", "char", "*", "resp", "=", "\"", "\"", ";", "char", "*", "endflag", "=", "\"", "\"", ";", "img_para", "img_para", ";", "free_port_num", "=", "scan_leisure_port", "(", ")", ";", "printf", "(", "\"", "\\n", "\\n", "\"", ",", "free_port_num", ")", ";", "free_port_num", "=", "4000", ";", "fprintf", "(", "stdout", ",", "\"", "\\n", "\"", ",", "free_port_num", ")", ";", "server_addr", ".", "sin_family", "=", "AF_INET", ";", "server_addr", ".", "sin_addr", ".", "s_addr", "=", "htonl", "(", "INADDR_ANY", ")", ";", "server_addr", ".", "sin_port", "=", "htons", "(", "4000", ")", ";", "socket_server", "=", "socket", "(", "AF_INET", ",", "SOCK_STREAM", ",", "0", ")", ";", "if", "(", "socket_server", "==", "-1", ")", "{", "perror", "(", "\"", "\\n", "\"", ")", ";", "close", "(", "socket_server", ")", ";", "exit", "(", "0", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "bind_result", "=", "bind", "(", "socket_server", ",", "(", "struct", "sockaddr", "*", ")", "&", "server_addr", ",", "sizeof", "(", "server_addr", ")", ")", ";", "if", "(", "bind_result", "==", "-1", ")", "{", "perror", "(", "\"", "\\n", "\"", ")", ";", "close", "(", "socket_server", ")", ";", "exit", "(", "0", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "listen_result", "=", "listen", "(", "socket_server", ",", "5", ")", ";", "if", "(", "listen_result", "==", "-1", ")", "{", "perror", "(", "\"", "\\n", "\"", ")", ";", "close", "(", "socket_server", ")", ";", "exit", "(", "1", ")", ";", "}", "printf", "(", "\"", "\\n", "\\n", "\\n", "\"", ")", ";", "while", "(", "true", ")", "{", "client_addr_len", "=", "sizeof", "(", "client_addr", ")", ";", "socket_client", "=", "accept", "(", "socket_server", ",", "(", "struct", "sockaddr", "*", ")", "&", "client_addr", ",", "&", "client_addr_len", ")", ";", "if", "(", "socket_client", "==", "-1", ")", "{", "perror", "(", "\"", "\\n", "\"", ")", ";", "close", "(", "socket_server", ")", ";", "close", "(", "socket_client", ")", ";", "exit", "(", "0", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "img_para", "=", "receive_img_data", "(", "socket_server", ",", "socket_client", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "create_thread_handle", "(", "0", ",", "&", "img_para", ",", "socket_server", ",", "socket_client", ")", ";", "memset", "(", "receive_buffer", ",", "0", ",", "sizeof", "(", "receive_buffer", ")", ")", ";", "read", "(", "socket_client", ",", "receive_buffer", ",", "sizeof", "(", "receive_buffer", ")", ")", ";", "fprintf", "(", "stdout", ",", "\"", "\\n", "\"", ",", "receive_buffer", ")", ";", "write", "(", "socket_client", ",", "resp", ",", "strlen", "(", "resp", ")", ")", ";", "if", "(", "!", "strcmp", "(", "receive_buffer", ",", "endflag", ")", ")", "break", ";", "}", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "pthread_join", "(", "thread", ",", "NULL", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "free", "(", "img_para", ".", "data", ")", ";", "fputs", "(", "\"", "\\n", "\\n", "\"", ",", "stdout", ")", ";", "shutdown", "(", "socket_client", ",", "SHUT_RDWR", ")", ";", "shutdown", "(", "socket_server", ",", "SHUT_RDWR", ")", ";", "sleep", "(", "2", ")", ";", "close", "(", "socket_client", ")", ";", "close", "(", "socket_server", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "}" ]
function: void enter_socket_listen() establish server socket run the socket server and listen to a leisure port
[ "function", ":", "void", "enter_socket_listen", "()", "establish", "server", "socket", "run", "the", "socket", "server", "and", "listen", "to", "a", "leisure", "port" ]
[ "/* varaiables */", "// server address", "// request client address", "// 建立失败不返回值,保持-1", "// 没得到client的socket信息,返回值不变", "// bind 失败不返回值", "// 监听失败无返回值,仍为-1 ", "/* find an unoccupied port */", "/* initalize server address struct */", "//监听任何一个地址", "//使用free_port_num端口", "/* create server socket */", "//使用网络通信模式,tcp通信", "/* bind socket with the listening port */", "/* let socket listen to the port it binde */", "// loop to serve the client connection", "/* establish the connection when a requset is accepted */", "/* receive image information sent by client */", "/* handle the picture in a sub thread */", "/* check if end signal received */", "// wait for the client to disconnect and kill the sokcets" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f73564a9418dc4738603a3a1b8ec27461d748716
CoinCheung/image_processing
cserver.c
[ "MIT" ]
C
scan_leisure_port
null
unsigned int scan_leisure_port() { unsigned int port_num = 1025; char line[1024]; FILE *fhd = NULL; bool portExists = 0; system("netstat -ano > netstat.log"); fhd = fopen("netstat.log", "r"); if(fhd == NULL) { perror("fail to open 'netstat.log'\n"); exit(0); } rewind(fhd); while(1) { memset(line, 0, sizeof(line)); //reset the readline buffer portExists = 0; while(!feof(fhd)) { fgets(line,sizeof(line),fhd); // read one line from the file portExists = is_port_occupied(line, strlen(line), port_num); if(portExists == true) // if the port is occupied, try next one break; } if(portExists == false) // if the port is not occupied, break the loop break; port_num++; } if(fclose(fhd)) { perror("fail to close the file!!\n"); fclose(fhd); exit(1); } return port_num; }
/* function: unsigned int scan_leisure_port() * * scan the ports of the computer and return an unoccupied one * netstat is required here * * input: * return: * */
unsigned int scan_leisure_port() scan the ports of the computer and return an unoccupied one netstat is required here
[ "unsigned", "int", "scan_leisure_port", "()", "scan", "the", "ports", "of", "the", "computer", "and", "return", "an", "unoccupied", "one", "netstat", "is", "required", "here" ]
unsigned int scan_leisure_port() { unsigned int port_num = 1025; char line[1024]; FILE *fhd = NULL; bool portExists = 0; system("netstat -ano > netstat.log"); fhd = fopen("netstat.log", "r"); if(fhd == NULL) { perror("fail to open 'netstat.log'\n"); exit(0); } rewind(fhd); while(1) { memset(line, 0, sizeof(line)); portExists = 0; while(!feof(fhd)) { fgets(line,sizeof(line),fhd); portExists = is_port_occupied(line, strlen(line), port_num); if(portExists == true) break; } if(portExists == false) break; port_num++; } if(fclose(fhd)) { perror("fail to close the file!!\n"); fclose(fhd); exit(1); } return port_num; }
[ "unsigned", "int", "scan_leisure_port", "(", ")", "{", "unsigned", "int", "port_num", "=", "1025", ";", "char", "line", "[", "1024", "]", ";", "FILE", "*", "fhd", "=", "NULL", ";", "bool", "portExists", "=", "0", ";", "system", "(", "\"", "\"", ")", ";", "fhd", "=", "fopen", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "if", "(", "fhd", "==", "NULL", ")", "{", "perror", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "0", ")", ";", "}", "rewind", "(", "fhd", ")", ";", "while", "(", "1", ")", "{", "memset", "(", "line", ",", "0", ",", "sizeof", "(", "line", ")", ")", ";", "portExists", "=", "0", ";", "while", "(", "!", "feof", "(", "fhd", ")", ")", "{", "fgets", "(", "line", ",", "sizeof", "(", "line", ")", ",", "fhd", ")", ";", "portExists", "=", "is_port_occupied", "(", "line", ",", "strlen", "(", "line", ")", ",", "port_num", ")", ";", "if", "(", "portExists", "==", "true", ")", "break", ";", "}", "if", "(", "portExists", "==", "false", ")", "break", ";", "port_num", "++", ";", "}", "if", "(", "fclose", "(", "fhd", ")", ")", "{", "perror", "(", "\"", "\\n", "\"", ")", ";", "fclose", "(", "fhd", ")", ";", "exit", "(", "1", ")", ";", "}", "return", "port_num", ";", "}" ]
function: unsigned int scan_leisure_port() scan the ports of the computer and return an unoccupied one netstat is required here
[ "function", ":", "unsigned", "int", "scan_leisure_port", "()", "scan", "the", "ports", "of", "the", "computer", "and", "return", "an", "unoccupied", "one", "netstat", "is", "required", "here" ]
[ "//reset the readline buffer", "// read one line from the file", "// if the port is occupied, try next one", "// if the port is not occupied, break the loop" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f73564a9418dc4738603a3a1b8ec27461d748716
CoinCheung/image_processing
cserver.c
[ "MIT" ]
C
create_thread_handle
void
void create_thread_handle(int ind,void *img, int socket_server, int socket_client) { int thread_result = 0; thread_para *tp; tp = malloc(sizeof(thread_para)); tp->img = img; tp->ind = ind; tp->socket_server = socket_server; tp->socket_client = socket_client; fputs("\nserver: create subthread to handle this image\n",stdout); if(ind == 0) // if other methods are called, add them here with different ind thread_result = pthread_create(&thread, NULL, thread_handle_img, tp); if(thread_result != 0) { perror("thread create fail"); exit(0); } }
/* function: void create_thread_handle(int ind,void *img, int socket_server, int socket_client) * * create a new thread to handle the image received from the client. Different tasks are optioned with different ind * * input: index of the optional method used upon the image, a structure depicts the image, server socket and client socket used to communicate with the client * return: none */
void create_thread_handle(int ind,void *img, int socket_server, int socket_client) create a new thread to handle the image received from the client. Different tasks are optioned with different ind index of the optional method used upon the image, a structure depicts the image, server socket and client socket used to communicate with the client return: none
[ "void", "create_thread_handle", "(", "int", "ind", "void", "*", "img", "int", "socket_server", "int", "socket_client", ")", "create", "a", "new", "thread", "to", "handle", "the", "image", "received", "from", "the", "client", ".", "Different", "tasks", "are", "optioned", "with", "different", "ind", "index", "of", "the", "optional", "method", "used", "upon", "the", "image", "a", "structure", "depicts", "the", "image", "server", "socket", "and", "client", "socket", "used", "to", "communicate", "with", "the", "client", "return", ":", "none" ]
void create_thread_handle(int ind,void *img, int socket_server, int socket_client) { int thread_result = 0; thread_para *tp; tp = malloc(sizeof(thread_para)); tp->img = img; tp->ind = ind; tp->socket_server = socket_server; tp->socket_client = socket_client; fputs("\nserver: create subthread to handle this image\n",stdout); if(ind == 0) thread_result = pthread_create(&thread, NULL, thread_handle_img, tp); if(thread_result != 0) { perror("thread create fail"); exit(0); } }
[ "void", "create_thread_handle", "(", "int", "ind", ",", "void", "*", "img", ",", "int", "socket_server", ",", "int", "socket_client", ")", "{", "int", "thread_result", "=", "0", ";", "thread_para", "*", "tp", ";", "tp", "=", "malloc", "(", "sizeof", "(", "thread_para", ")", ")", ";", "tp", "->", "img", "=", "img", ";", "tp", "->", "ind", "=", "ind", ";", "tp", "->", "socket_server", "=", "socket_server", ";", "tp", "->", "socket_client", "=", "socket_client", ";", "fputs", "(", "\"", "\\n", "\\n", "\"", ",", "stdout", ")", ";", "if", "(", "ind", "==", "0", ")", "thread_result", "=", "pthread_create", "(", "&", "thread", ",", "NULL", ",", "thread_handle_img", ",", "tp", ")", ";", "if", "(", "thread_result", "!=", "0", ")", "{", "perror", "(", "\"", "\"", ")", ";", "exit", "(", "0", ")", ";", "}", "}" ]
function: void create_thread_handle(int ind,void *img, int socket_server, int socket_client) create a new thread to handle the image received from the client.
[ "function", ":", "void", "create_thread_handle", "(", "int", "ind", "void", "*", "img", "int", "socket_server", "int", "socket_client", ")", "create", "a", "new", "thread", "to", "handle", "the", "image", "received", "from", "the", "client", "." ]
[ "// if other methods are called, add them here with different ind" ]
[ { "param": "ind", "type": "int" }, { "param": "img", "type": "void" }, { "param": "socket_server", "type": "int" }, { "param": "socket_client", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ind", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "img", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "socket_server", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "socket_client", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f73564a9418dc4738603a3a1b8ec27461d748716
CoinCheung/image_processing
cserver.c
[ "MIT" ]
C
thread_handle_img
void
void *thread_handle_img(thread_para *tp) { uint8_t *sk = NULL; long send_length; long send_all_length = 0; long size; size = (((img_para*)(tp->img))->width) * (((img_para*)(tp->img))->height); fputs("[server thread 2] in the new thread!!\n",stdout); if(tp->ind == 0) sk = (uint8_t*)identify_porn(tp->img); fputs("[server thread 2] send handled image to client... \n",stdout); while(send_all_length < size) { send_length = write(tp->socket_client,(sk + send_all_length),(size-send_all_length)); send_all_length += send_length; fprintf(stdout,"[server thread 2] length of sent %ld\n",send_length); } fputs("[server thread2] identification porn done!!\n",stdout); free(tp); free(sk); }
/* function: void* thread_handle_img(thread_para *tp); * * This is the function that run in a new thread * handle the image with different functions assigned by ind in a new thread * * input: a structure of parameters given to the thread * return: none */
void* thread_handle_img(thread_para *tp); This is the function that run in a new thread handle the image with different functions assigned by ind in a new thread a structure of parameters given to the thread return: none
[ "void", "*", "thread_handle_img", "(", "thread_para", "*", "tp", ")", ";", "This", "is", "the", "function", "that", "run", "in", "a", "new", "thread", "handle", "the", "image", "with", "different", "functions", "assigned", "by", "ind", "in", "a", "new", "thread", "a", "structure", "of", "parameters", "given", "to", "the", "thread", "return", ":", "none" ]
void *thread_handle_img(thread_para *tp) { uint8_t *sk = NULL; long send_length; long send_all_length = 0; long size; size = (((img_para*)(tp->img))->width) * (((img_para*)(tp->img))->height); fputs("[server thread 2] in the new thread!!\n",stdout); if(tp->ind == 0) sk = (uint8_t*)identify_porn(tp->img); fputs("[server thread 2] send handled image to client... \n",stdout); while(send_all_length < size) { send_length = write(tp->socket_client,(sk + send_all_length),(size-send_all_length)); send_all_length += send_length; fprintf(stdout,"[server thread 2] length of sent %ld\n",send_length); } fputs("[server thread2] identification porn done!!\n",stdout); free(tp); free(sk); }
[ "void", "*", "thread_handle_img", "(", "thread_para", "*", "tp", ")", "{", "uint8_t", "*", "sk", "=", "NULL", ";", "long", "send_length", ";", "long", "send_all_length", "=", "0", ";", "long", "size", ";", "size", "=", "(", "(", "(", "img_para", "*", ")", "(", "tp", "->", "img", ")", ")", "->", "width", ")", "*", "(", "(", "(", "img_para", "*", ")", "(", "tp", "->", "img", ")", ")", "->", "height", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "if", "(", "tp", "->", "ind", "==", "0", ")", "sk", "=", "(", "uint8_t", "*", ")", "identify_porn", "(", "tp", "->", "img", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "while", "(", "send_all_length", "<", "size", ")", "{", "send_length", "=", "write", "(", "tp", "->", "socket_client", ",", "(", "sk", "+", "send_all_length", ")", ",", "(", "size", "-", "send_all_length", ")", ")", ";", "send_all_length", "+=", "send_length", ";", "fprintf", "(", "stdout", ",", "\"", "\\n", "\"", ",", "send_length", ")", ";", "}", "fputs", "(", "\"", "\\n", "\"", ",", "stdout", ")", ";", "free", "(", "tp", ")", ";", "free", "(", "sk", ")", ";", "}" ]
function: void* thread_handle_img(thread_para *tp); This is the function that run in a new thread handle the image with different functions assigned by ind in a new thread
[ "function", ":", "void", "*", "thread_handle_img", "(", "thread_para", "*", "tp", ")", ";", "This", "is", "the", "function", "that", "run", "in", "a", "new", "thread", "handle", "the", "image", "with", "different", "functions", "assigned", "by", "ind", "in", "a", "new", "thread" ]
[]
[ { "param": "tp", "type": "thread_para" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "tp", "type": "thread_para", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
467adc88dc58c33744b3f5bb2053e338c2a3ce53
cancerAlot/ffviewer-v0.1
main.c
[ "0BSD" ]
C
isFarbfeldFile
char
char* isFarbfeldFile(char *file) { if (strlen(file) == 0) { return NULL; } FILE *f = fopen(file, "r"); if (f == NULL) { printf("empty file\n"); return NULL; } char *ext = strrchr(file, '.'); char *magic = calloc(8, 1); /* read the farbfeld magic */ if (fread(magic, 1, 8, f) != 8) { printf("invalid magic\n"); free(magic); fclose(f); return NULL; } if (ext && strcmp(ext + 1, "ff") == 0 && strcmp(magic, "farbfeld") == 0) { free(magic); fclose(f); return file; } else { printf("invalid file - skipping\n"); free(magic); fclose(f); return NULL; } }
/** * @param the *file, may be NULL * @return *file on success and NULL on failure */
@param the *file, may be NULL @return *file on success and NULL on failure
[ "@param", "the", "*", "file", "may", "be", "NULL", "@return", "*", "file", "on", "success", "and", "NULL", "on", "failure" ]
char* isFarbfeldFile(char *file) { if (strlen(file) == 0) { return NULL; } FILE *f = fopen(file, "r"); if (f == NULL) { printf("empty file\n"); return NULL; } char *ext = strrchr(file, '.'); char *magic = calloc(8, 1); if (fread(magic, 1, 8, f) != 8) { printf("invalid magic\n"); free(magic); fclose(f); return NULL; } if (ext && strcmp(ext + 1, "ff") == 0 && strcmp(magic, "farbfeld") == 0) { free(magic); fclose(f); return file; } else { printf("invalid file - skipping\n"); free(magic); fclose(f); return NULL; } }
[ "char", "*", "isFarbfeldFile", "(", "char", "*", "file", ")", "{", "if", "(", "strlen", "(", "file", ")", "==", "0", ")", "{", "return", "NULL", ";", "}", "FILE", "*", "f", "=", "fopen", "(", "file", ",", "\"", "\"", ")", ";", "if", "(", "f", "==", "NULL", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "NULL", ";", "}", "char", "*", "ext", "=", "strrchr", "(", "file", ",", "'", "'", ")", ";", "char", "*", "magic", "=", "calloc", "(", "8", ",", "1", ")", ";", "if", "(", "fread", "(", "magic", ",", "1", ",", "8", ",", "f", ")", "!=", "8", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "free", "(", "magic", ")", ";", "fclose", "(", "f", ")", ";", "return", "NULL", ";", "}", "if", "(", "ext", "&&", "strcmp", "(", "ext", "+", "1", ",", "\"", "\"", ")", "==", "0", "&&", "strcmp", "(", "magic", ",", "\"", "\"", ")", "==", "0", ")", "{", "free", "(", "magic", ")", ";", "fclose", "(", "f", ")", ";", "return", "file", ";", "}", "else", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "free", "(", "magic", ")", ";", "fclose", "(", "f", ")", ";", "return", "NULL", ";", "}", "}" ]
@param the *file, may be NULL @return *file on success and NULL on failure
[ "@param", "the", "*", "file", "may", "be", "NULL", "@return", "*", "file", "on", "success", "and", "NULL", "on", "failure" ]
[ "/* read the farbfeld magic */" ]
[ { "param": "file", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d825cc5e7befb3378c781e0b3bd19727cab5e813
HolyBlackCat/LD49
src/utils/metronome.h
[ "Zlib" ]
C
SetCompensation
void
void SetCompensation(float threshold, float amount) { comp_th = threshold; comp_amount = amount; }
// Threshold should be positive and small, at least less than 1. // Amount should be at least two times larger (by a some margin) than threshold, otherwise it will break. 0.5 should give best results, but don't make it much larger. // When the abs('frame len' - 'tick len') / 'tick_len' < 'threshold', the compensator kicks in and adds or subtracts 'amount' * 'tick len' from the time.
Threshold should be positive and small, at least less than 1. Amount should be at least two times larger (by a some margin) than threshold, otherwise it will break. 0.5 should give best results, but don't make it much larger.
[ "Threshold", "should", "be", "positive", "and", "small", "at", "least", "less", "than", "1", ".", "Amount", "should", "be", "at", "least", "two", "times", "larger", "(", "by", "a", "some", "margin", ")", "than", "threshold", "otherwise", "it", "will", "break", ".", "0", ".", "5", "should", "give", "best", "results", "but", "don", "'", "t", "make", "it", "much", "larger", "." ]
void SetCompensation(float threshold, float amount) { comp_th = threshold; comp_amount = amount; }
[ "void", "SetCompensation", "(", "float", "threshold", ",", "float", "amount", ")", "{", "comp_th", "=", "threshold", ";", "comp_amount", "=", "amount", ";", "}" ]
Threshold should be positive and small, at least less than 1.
[ "Threshold", "should", "be", "positive", "and", "small", "at", "least", "less", "than", "1", "." ]
[]
[ { "param": "threshold", "type": "float" }, { "param": "amount", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "threshold", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "amount", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0440f8a3aeb48ec217e64b46da68e45272f32b00
HolyBlackCat/LD49
src/utils/unicode.h
[ "Zlib" ]
C
FirstByteToCharacterLength
int
[[nodiscard]] inline int FirstByteToCharacterLength(char first_byte) { if ((first_byte & 0b10000000) == 0b00000000) return 1; // Note the different bit pattern in this one. if ((first_byte & 0b11100000) == 0b11000000) return 2; if ((first_byte & 0b11110000) == 0b11100000) return 3; if ((first_byte & 0b11111000) == 0b11110000) return 4; return 0; }
// Given the first byte of a multibyte character (or a single-byte character), returns the amount of bytes occupied by the character. // Returns 0 if this is not a valid first byte, or not a first byte at all.
Given the first byte of a multibyte character (or a single-byte character), returns the amount of bytes occupied by the character. Returns 0 if this is not a valid first byte, or not a first byte at all.
[ "Given", "the", "first", "byte", "of", "a", "multibyte", "character", "(", "or", "a", "single", "-", "byte", "character", ")", "returns", "the", "amount", "of", "bytes", "occupied", "by", "the", "character", ".", "Returns", "0", "if", "this", "is", "not", "a", "valid", "first", "byte", "or", "not", "a", "first", "byte", "at", "all", "." ]
[[nodiscard]] inline int FirstByteToCharacterLength(char first_byte) { if ((first_byte & 0b10000000) == 0b00000000) return 1; if ((first_byte & 0b11100000) == 0b11000000) return 2; if ((first_byte & 0b11110000) == 0b11100000) return 3; if ((first_byte & 0b11111000) == 0b11110000) return 4; return 0; }
[ "[[", "nodiscard", "]]", "inline", "int", "FirstByteToCharacterLength", "(", "char", "first_byte", ")", "{", "if", "(", "(", "first_byte", "&", "0b10000000", ")", "==", "0b00000000", ")", "return", "1", ";", "if", "(", "(", "first_byte", "&", "0b11100000", ")", "==", "0b11000000", ")", "return", "2", ";", "if", "(", "(", "first_byte", "&", "0b11110000", ")", "==", "0b11100000", ")", "return", "3", ";", "if", "(", "(", "first_byte", "&", "0b11111000", ")", "==", "0b11110000", ")", "return", "4", ";", "return", "0", ";", "}" ]
Given the first byte of a multibyte character (or a single-byte character), returns the amount of bytes occupied by the character.
[ "Given", "the", "first", "byte", "of", "a", "multibyte", "character", "(", "or", "a", "single", "-", "byte", "character", ")", "returns", "the", "amount", "of", "bytes", "occupied", "by", "the", "character", "." ]
[ "// Note the different bit pattern in this one." ]
[ { "param": "first_byte", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "first_byte", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0440f8a3aeb48ec217e64b46da68e45272f32b00
HolyBlackCat/LD49
src/utils/unicode.h
[ "Zlib" ]
C
CharacterCodeToLength
int
[[nodiscard]] inline int CharacterCodeToLength(Char ch) { if (ch <= 0x7f) return 1; if (ch <= 0x7ff) return 2; if (ch <= 0xffff) return 3; // Here `ch <= 0x10ffff`, or the character is invalid. // Mathematically the cap should be `0x1fffff`, but Unicode defines the max value to be lower. return 4; }
// Returns the amount of bytes needed to represent a character. // If the character is invalid (use `IsValidCharacterCode` to check for validity) returns 4, which is the maximum possible length
Returns the amount of bytes needed to represent a character. If the character is invalid (use `IsValidCharacterCode` to check for validity) returns 4, which is the maximum possible length
[ "Returns", "the", "amount", "of", "bytes", "needed", "to", "represent", "a", "character", ".", "If", "the", "character", "is", "invalid", "(", "use", "`", "IsValidCharacterCode", "`", "to", "check", "for", "validity", ")", "returns", "4", "which", "is", "the", "maximum", "possible", "length" ]
[[nodiscard]] inline int CharacterCodeToLength(Char ch) { if (ch <= 0x7f) return 1; if (ch <= 0x7ff) return 2; if (ch <= 0xffff) return 3; return 4; }
[ "[[", "nodiscard", "]]", "inline", "int", "CharacterCodeToLength", "(", "Char", "ch", ")", "{", "if", "(", "ch", "<=", "0x7f", ")", "return", "1", ";", "if", "(", "ch", "<=", "0x7ff", ")", "return", "2", ";", "if", "(", "ch", "<=", "0xffff", ")", "return", "3", ";", "return", "4", ";", "}" ]
Returns the amount of bytes needed to represent a character.
[ "Returns", "the", "amount", "of", "bytes", "needed", "to", "represent", "a", "character", "." ]
[ "// Here `ch <= 0x10ffff`, or the character is invalid.", "// Mathematically the cap should be `0x1fffff`, but Unicode defines the max value to be lower." ]
[ { "param": "ch", "type": "Char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ch", "type": "Char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0440f8a3aeb48ec217e64b46da68e45272f32b00
HolyBlackCat/LD49
src/utils/unicode.h
[ "Zlib" ]
C
Encode
int
inline int Encode(Char ch, char *buffer) { if (!IsValidCharacterCode(ch)) return Encode(default_char, buffer); int len = CharacterCodeToLength(ch); switch (len) { case 1: *buffer = ch; break; case 2: *buffer++ = 0b11000000 | (ch >> 6); *buffer = 0b10000000 | (ch & 0b00111111); break; case 3: *buffer++ = 0b11100000 | (ch >> 12); *buffer++ = 0b10000000 | ((ch >> 6) & 0b00111111); *buffer = 0b10000000 | ( ch & 0b00111111); break; case 4: *buffer++ = 0b11110000 | (ch >> 18); *buffer++ = 0b10000000 | ((ch >> 12) & 0b00111111); *buffer++ = 0b10000000 | ((ch >> 6 ) & 0b00111111); *buffer = 0b10000000 | ( ch & 0b00111111); break; } return len; }
// Encodes a character into UTF8. // The minimal buffer length can be determined with `CharacterCodeToLength`. // If the character is invalid, writes `default_char` instead. // No null-terminator is added. // Returns the amount of bytes written, equal to what `CharacterCodeToLength` would return.
Encodes a character into UTF8. The minimal buffer length can be determined with `CharacterCodeToLength`. If the character is invalid, writes `default_char` instead. No null-terminator is added. Returns the amount of bytes written, equal to what `CharacterCodeToLength` would return.
[ "Encodes", "a", "character", "into", "UTF8", ".", "The", "minimal", "buffer", "length", "can", "be", "determined", "with", "`", "CharacterCodeToLength", "`", ".", "If", "the", "character", "is", "invalid", "writes", "`", "default_char", "`", "instead", ".", "No", "null", "-", "terminator", "is", "added", ".", "Returns", "the", "amount", "of", "bytes", "written", "equal", "to", "what", "`", "CharacterCodeToLength", "`", "would", "return", "." ]
inline int Encode(Char ch, char *buffer) { if (!IsValidCharacterCode(ch)) return Encode(default_char, buffer); int len = CharacterCodeToLength(ch); switch (len) { case 1: *buffer = ch; break; case 2: *buffer++ = 0b11000000 | (ch >> 6); *buffer = 0b10000000 | (ch & 0b00111111); break; case 3: *buffer++ = 0b11100000 | (ch >> 12); *buffer++ = 0b10000000 | ((ch >> 6) & 0b00111111); *buffer = 0b10000000 | ( ch & 0b00111111); break; case 4: *buffer++ = 0b11110000 | (ch >> 18); *buffer++ = 0b10000000 | ((ch >> 12) & 0b00111111); *buffer++ = 0b10000000 | ((ch >> 6 ) & 0b00111111); *buffer = 0b10000000 | ( ch & 0b00111111); break; } return len; }
[ "inline", "int", "Encode", "(", "Char", "ch", ",", "char", "*", "buffer", ")", "{", "if", "(", "!", "IsValidCharacterCode", "(", "ch", ")", ")", "return", "Encode", "(", "default_char", ",", "buffer", ")", ";", "int", "len", "=", "CharacterCodeToLength", "(", "ch", ")", ";", "switch", "(", "len", ")", "{", "case", "1", ":", "*", "buffer", "=", "ch", ";", "break", ";", "case", "2", ":", "*", "buffer", "++", "=", "0b11000000", "|", "(", "ch", ">>", "6", ")", ";", "*", "buffer", "=", "0b10000000", "|", "(", "ch", "&", "0b00111111", ")", ";", "break", ";", "case", "3", ":", "*", "buffer", "++", "=", "0b11100000", "|", "(", "ch", ">>", "12", ")", ";", "*", "buffer", "++", "=", "0b10000000", "|", "(", "(", "ch", ">>", "6", ")", "&", "0b00111111", ")", ";", "*", "buffer", "=", "0b10000000", "|", "(", "ch", "&", "0b00111111", ")", ";", "break", ";", "case", "4", ":", "*", "buffer", "++", "=", "0b11110000", "|", "(", "ch", ">>", "18", ")", ";", "*", "buffer", "++", "=", "0b10000000", "|", "(", "(", "ch", ">>", "12", ")", "&", "0b00111111", ")", ";", "*", "buffer", "++", "=", "0b10000000", "|", "(", "(", "ch", ">>", "6", ")", "&", "0b00111111", ")", ";", "*", "buffer", "=", "0b10000000", "|", "(", "ch", "&", "0b00111111", ")", ";", "break", ";", "}", "return", "len", ";", "}" ]
Encodes a character into UTF8.
[ "Encodes", "a", "character", "into", "UTF8", "." ]
[]
[ { "param": "ch", "type": "Char" }, { "param": "buffer", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ch", "type": "Char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buffer", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7c7a6fe62b497e08d27717160ecd56cd3f4304a5
HolyBlackCat/LD49
src/stream/readonly_data.h
[ "Zlib" ]
C
string
char
[[nodiscard]] const char *string() { if (!ref) return ""; if (!is_null_terminated()) *this = null_terminate(); return (const char *)data(); }
// Returns a pointer to the beginning of the file. // Adds a null-terminator to the data if it was missing.
Returns a pointer to the beginning of the file. Adds a null-terminator to the data if it was missing.
[ "Returns", "a", "pointer", "to", "the", "beginning", "of", "the", "file", ".", "Adds", "a", "null", "-", "terminator", "to", "the", "data", "if", "it", "was", "missing", "." ]
[[nodiscard]] const char *string() { if (!ref) return ""; if (!is_null_terminated()) *this = null_terminate(); return (const char *)data(); }
[ "[[", "nodiscard", "]]", "const", "char", "*", "string", "(", ")", "{", "if", "(", "!", "ref", ")", "return", "\"", "\"", ";", "if", "(", "!", "is_null_terminated", "(", ")", ")", "*", "this", "=", "null_terminate", "(", ")", ";", "return", "(", "const", "char", "*", ")", "data", "(", ")", ";", "}" ]
Returns a pointer to the beginning of the file.
[ "Returns", "a", "pointer", "to", "the", "beginning", "of", "the", "file", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
1308f13a4a64d13cfa075c50853f751fbb4ebfba
HolyBlackCat/LD49
src/audio/parameters.h
[ "Zlib" ]
C
ListenerOrientation
void
inline void ListenerOrientation(fvec3 forward, fvec3 up) { fvec3 array[2] = {forward, up}; alListenerfv(AL_ORIENTATION, array[0].as_array()); }
// Listener orientation, aka rotation. // Both vectors are relative to the listener. // AL uses the same coorinate system as GL: right-handed, by default X is right, Y is up, Z is towards the listener.
Listener orientation, aka rotation. Both vectors are relative to the listener. AL uses the same coorinate system as GL: right-handed, by default X is right, Y is up, Z is towards the listener.
[ "Listener", "orientation", "aka", "rotation", ".", "Both", "vectors", "are", "relative", "to", "the", "listener", ".", "AL", "uses", "the", "same", "coorinate", "system", "as", "GL", ":", "right", "-", "handed", "by", "default", "X", "is", "right", "Y", "is", "up", "Z", "is", "towards", "the", "listener", "." ]
inline void ListenerOrientation(fvec3 forward, fvec3 up) { fvec3 array[2] = {forward, up}; alListenerfv(AL_ORIENTATION, array[0].as_array()); }
[ "inline", "void", "ListenerOrientation", "(", "fvec3", "forward", ",", "fvec3", "up", ")", "{", "fvec3", "array", "[", "2", "]", "=", "{", "forward", ",", "up", "}", ";", "alListenerfv", "(", "AL_ORIENTATION", ",", "array", "[", "0", "]", ".", "as_array", "(", ")", ")", ";", "}" ]
Listener orientation, aka rotation.
[ "Listener", "orientation", "aka", "rotation", "." ]
[]
[ { "param": "forward", "type": "fvec3" }, { "param": "up", "type": "fvec3" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "forward", "type": "fvec3", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "up", "type": "fvec3", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9572c06c2750faefd5485cd1962272d6672c2acd
jayrfink/etu
src/bin/etu.c
[ "MIT-enna" ]
C
update_image
void
void update_image(char *images, char *dst, int height, int quality, int width) { int i; char dst_path[PATH_MAX]; char src_path[PATH_MAX]; char * type; struct dirent *src_dp; DIR * src_dp_handle; src_dp_handle = opendir(images); i = 0; while (src_dp = (readdir(src_dp_handle))) { if (i > -1) { strncpy(dst_path, fullpath(src_dp->d_name, dst), sizeof(src_dp->d_name) + 1); if (check_handle(dst_path) != 0) { strncpy(src_path, fullpath(src_dp->d_name, images), sizeof(src_dp->d_name) + 1); scale_imlib2(src_path, dst_path, height, quality, width); } } i++; } closedir(src_dp_handle); }
/* * update_image - Using a source directory of jpeg files, check a destination * directory of jpeg formatted images to see if they need updated. Also * set the height, quality, and width of each jpeg formatted destination image */
Using a source directory of jpeg files, check a destination directory of jpeg formatted images to see if they need updated. Also set the height, quality, and width of each jpeg formatted destination image
[ "Using", "a", "source", "directory", "of", "jpeg", "files", "check", "a", "destination", "directory", "of", "jpeg", "formatted", "images", "to", "see", "if", "they", "need", "updated", ".", "Also", "set", "the", "height", "quality", "and", "width", "of", "each", "jpeg", "formatted", "destination", "image" ]
void update_image(char *images, char *dst, int height, int quality, int width) { int i; char dst_path[PATH_MAX]; char src_path[PATH_MAX]; char * type; struct dirent *src_dp; DIR * src_dp_handle; src_dp_handle = opendir(images); i = 0; while (src_dp = (readdir(src_dp_handle))) { if (i > -1) { strncpy(dst_path, fullpath(src_dp->d_name, dst), sizeof(src_dp->d_name) + 1); if (check_handle(dst_path) != 0) { strncpy(src_path, fullpath(src_dp->d_name, images), sizeof(src_dp->d_name) + 1); scale_imlib2(src_path, dst_path, height, quality, width); } } i++; } closedir(src_dp_handle); }
[ "void", "update_image", "(", "char", "*", "images", ",", "char", "*", "dst", ",", "int", "height", ",", "int", "quality", ",", "int", "width", ")", "{", "int", "i", ";", "char", "dst_path", "[", "PATH_MAX", "]", ";", "char", "src_path", "[", "PATH_MAX", "]", ";", "char", "*", "type", ";", "struct", "dirent", "*", "src_dp", ";", "DIR", "*", "src_dp_handle", ";", "src_dp_handle", "=", "opendir", "(", "images", ")", ";", "i", "=", "0", ";", "while", "(", "src_dp", "=", "(", "readdir", "(", "src_dp_handle", ")", ")", ")", "{", "if", "(", "i", ">", "-1", ")", "{", "strncpy", "(", "dst_path", ",", "fullpath", "(", "src_dp", "->", "d_name", ",", "dst", ")", ",", "sizeof", "(", "src_dp", "->", "d_name", ")", "+", "1", ")", ";", "if", "(", "check_handle", "(", "dst_path", ")", "!=", "0", ")", "{", "strncpy", "(", "src_path", ",", "fullpath", "(", "src_dp", "->", "d_name", ",", "images", ")", ",", "sizeof", "(", "src_dp", "->", "d_name", ")", "+", "1", ")", ";", "scale_imlib2", "(", "src_path", ",", "dst_path", ",", "height", ",", "quality", ",", "width", ")", ";", "}", "}", "i", "++", ";", "}", "closedir", "(", "src_dp_handle", ")", ";", "}" ]
update_image - Using a source directory of jpeg files, check a destination directory of jpeg formatted images to see if they need updated.
[ "update_image", "-", "Using", "a", "source", "directory", "of", "jpeg", "files", "check", "a", "destination", "directory", "of", "jpeg", "formatted", "images", "to", "see", "if", "they", "need", "updated", "." ]
[]
[ { "param": "images", "type": "char" }, { "param": "dst", "type": "char" }, { "param": "height", "type": "int" }, { "param": "quality", "type": "int" }, { "param": "width", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "images", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "height", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "quality", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "width", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9572c06c2750faefd5485cd1962272d6672c2acd
jayrfink/etu
src/bin/etu.c
[ "MIT-enna" ]
C
update_rescaled
void
void update_rescaled(char *images, char *dst) { int i; char dst_path[PATH_MAX]; char src_path[PATH_MAX]; struct dirent *dst_img; DIR * dst_img_handle; dst_img_handle = opendir(dst); i = 0; while (dst_img = (readdir(dst_img_handle))) { if (i > -1) { strncpy(src_path, fullpath(dst_img->d_name, images), sizeof(dst_img->d_name) + 1); if (check_handle(src_path) != 0) { strncpy(dst_path, fullpath(dst_img->d_name, dst), sizeof(dst_img->d_name) + 1); unlink(dst_path); } } i++; } closedir(dst_img_handle); }
/* * backcheck - Check to see if any files where deleted in the source directory * that also need to be deleted in the rescaled directory. */
Check to see if any files where deleted in the source directory that also need to be deleted in the rescaled directory.
[ "Check", "to", "see", "if", "any", "files", "where", "deleted", "in", "the", "source", "directory", "that", "also", "need", "to", "be", "deleted", "in", "the", "rescaled", "directory", "." ]
void update_rescaled(char *images, char *dst) { int i; char dst_path[PATH_MAX]; char src_path[PATH_MAX]; struct dirent *dst_img; DIR * dst_img_handle; dst_img_handle = opendir(dst); i = 0; while (dst_img = (readdir(dst_img_handle))) { if (i > -1) { strncpy(src_path, fullpath(dst_img->d_name, images), sizeof(dst_img->d_name) + 1); if (check_handle(src_path) != 0) { strncpy(dst_path, fullpath(dst_img->d_name, dst), sizeof(dst_img->d_name) + 1); unlink(dst_path); } } i++; } closedir(dst_img_handle); }
[ "void", "update_rescaled", "(", "char", "*", "images", ",", "char", "*", "dst", ")", "{", "int", "i", ";", "char", "dst_path", "[", "PATH_MAX", "]", ";", "char", "src_path", "[", "PATH_MAX", "]", ";", "struct", "dirent", "*", "dst_img", ";", "DIR", "*", "dst_img_handle", ";", "dst_img_handle", "=", "opendir", "(", "dst", ")", ";", "i", "=", "0", ";", "while", "(", "dst_img", "=", "(", "readdir", "(", "dst_img_handle", ")", ")", ")", "{", "if", "(", "i", ">", "-1", ")", "{", "strncpy", "(", "src_path", ",", "fullpath", "(", "dst_img", "->", "d_name", ",", "images", ")", ",", "sizeof", "(", "dst_img", "->", "d_name", ")", "+", "1", ")", ";", "if", "(", "check_handle", "(", "src_path", ")", "!=", "0", ")", "{", "strncpy", "(", "dst_path", ",", "fullpath", "(", "dst_img", "->", "d_name", ",", "dst", ")", ",", "sizeof", "(", "dst_img", "->", "d_name", ")", "+", "1", ")", ";", "unlink", "(", "dst_path", ")", ";", "}", "}", "i", "++", ";", "}", "closedir", "(", "dst_img_handle", ")", ";", "}" ]
backcheck - Check to see if any files where deleted in the source directory that also need to be deleted in the rescaled directory.
[ "backcheck", "-", "Check", "to", "see", "if", "any", "files", "where", "deleted", "in", "the", "source", "directory", "that", "also", "need", "to", "be", "deleted", "in", "the", "rescaled", "directory", "." ]
[]
[ { "param": "images", "type": "char" }, { "param": "dst", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "images", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9572c06c2750faefd5485cd1962272d6672c2acd
jayrfink/etu
src/bin/etu.c
[ "MIT-enna" ]
C
check_handle
int
int check_handle(char *dir) { struct stat statbuf; if (stat(dir, &statbuf) != 0) return 1; return 0; }
/* * check_handle - Directory exists? Return 1 if it does not. 0 if it does. */
Directory exists. Return 1 if it does not. 0 if it does.
[ "Directory", "exists", ".", "Return", "1", "if", "it", "does", "not", ".", "0", "if", "it", "does", "." ]
int check_handle(char *dir) { struct stat statbuf; if (stat(dir, &statbuf) != 0) return 1; return 0; }
[ "int", "check_handle", "(", "char", "*", "dir", ")", "{", "struct", "stat", "statbuf", ";", "if", "(", "stat", "(", "dir", ",", "&", "statbuf", ")", "!=", "0", ")", "return", "1", ";", "return", "0", ";", "}" ]
check_handle - Directory exists?
[ "check_handle", "-", "Directory", "exists?" ]
[]
[ { "param": "dir", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dir", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9572c06c2750faefd5485cd1962272d6672c2acd
jayrfink/etu
src/bin/etu.c
[ "MIT-enna" ]
C
fullpath
char
char *fullpath(char *file, char *dir) { static char path[PATH_MAX]; strcpy(path, dir); strcat(path, "/"); strcat(path, file); return (path); }
/* * fullpath - Build a full path to a single file. Handy for stats. */
Build a full path to a single file. Handy for stats.
[ "Build", "a", "full", "path", "to", "a", "single", "file", ".", "Handy", "for", "stats", "." ]
char *fullpath(char *file, char *dir) { static char path[PATH_MAX]; strcpy(path, dir); strcat(path, "/"); strcat(path, file); return (path); }
[ "char", "*", "fullpath", "(", "char", "*", "file", ",", "char", "*", "dir", ")", "{", "static", "char", "path", "[", "PATH_MAX", "]", ";", "strcpy", "(", "path", ",", "dir", ")", ";", "strcat", "(", "path", ",", "\"", "\"", ")", ";", "strcat", "(", "path", ",", "file", ")", ";", "return", "(", "path", ")", ";", "}" ]
fullpath - Build a full path to a single file.
[ "fullpath", "-", "Build", "a", "full", "path", "to", "a", "single", "file", "." ]
[]
[ { "param": "file", "type": "char" }, { "param": "dir", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dir", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7adf72e45ccf30882db86b59e31b81e717a67d94
Notidman/lpct
C/lpct.c
[ "MIT" ]
C
prcolor
void
void prcolor(colors_t color, const char *msg) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); printf("%s", msg); SetConsoleTextAttribute(hConsole, white); }
// The function to print text to the console with // certain color without line break
The function to print text to the console with certain color without line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "with", "certain", "color", "without", "line", "break" ]
void prcolor(colors_t color, const char *msg) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); printf("%s", msg); SetConsoleTextAttribute(hConsole, white); }
[ "void", "prcolor", "(", "colors_t", "color", ",", "const", "char", "*", "msg", ")", "{", "HANDLE", "hConsole", "=", "GetStdHandle", "(", "STD_OUTPUT_HANDLE", ")", ";", "SetConsoleTextAttribute", "(", "hConsole", ",", "color", ")", ";", "printf", "(", "\"", "\"", ",", "msg", ")", ";", "SetConsoleTextAttribute", "(", "hConsole", ",", "white", ")", ";", "}" ]
The function to print text to the console with certain color without line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "with", "certain", "color", "without", "line", "break" ]
[]
[ { "param": "color", "type": "colors_t" }, { "param": "msg", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "color", "type": "colors_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7adf72e45ccf30882db86b59e31b81e717a67d94
Notidman/lpct
C/lpct.c
[ "MIT" ]
C
prcolorln
void
void prcolorln(colors_t color, const char *msg) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); printf("%s\n", msg); SetConsoleTextAttribute(hConsole, white); }
// The function to print text to the console // of a certain color with a line break
The function to print text to the console of a certain color with a line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "of", "a", "certain", "color", "with", "a", "line", "break" ]
void prcolorln(colors_t color, const char *msg) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); printf("%s\n", msg); SetConsoleTextAttribute(hConsole, white); }
[ "void", "prcolorln", "(", "colors_t", "color", ",", "const", "char", "*", "msg", ")", "{", "HANDLE", "hConsole", "=", "GetStdHandle", "(", "STD_OUTPUT_HANDLE", ")", ";", "SetConsoleTextAttribute", "(", "hConsole", ",", "color", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "msg", ")", ";", "SetConsoleTextAttribute", "(", "hConsole", ",", "white", ")", ";", "}" ]
The function to print text to the console of a certain color with a line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "of", "a", "certain", "color", "with", "a", "line", "break" ]
[]
[ { "param": "color", "type": "colors_t" }, { "param": "msg", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "color", "type": "colors_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7adf72e45ccf30882db86b59e31b81e717a67d94
Notidman/lpct
C/lpct.c
[ "MIT" ]
C
prcolor
void
void prcolor(colors_t color, const char *msg) { printf("%s%s%s", get_color(color), msg, "\033[0m"); }
// The function to print text to the console with // certain color without line break
The function to print text to the console with certain color without line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "with", "certain", "color", "without", "line", "break" ]
void prcolor(colors_t color, const char *msg) { printf("%s%s%s", get_color(color), msg, "\033[0m"); }
[ "void", "prcolor", "(", "colors_t", "color", ",", "const", "char", "*", "msg", ")", "{", "printf", "(", "\"", "\"", ",", "get_color", "(", "color", ")", ",", "msg", ",", "\"", "\\033", "\"", ")", ";", "}" ]
The function to print text to the console with certain color without line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "with", "certain", "color", "without", "line", "break" ]
[]
[ { "param": "color", "type": "colors_t" }, { "param": "msg", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "color", "type": "colors_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7adf72e45ccf30882db86b59e31b81e717a67d94
Notidman/lpct
C/lpct.c
[ "MIT" ]
C
prcolorln
void
void prcolorln(colors_t color, const char *msg) { printf("%s%s%s\n", get_color(color), msg, "\033[0m"); }
// The function to print text to the console // of a certain color with a line break
The function to print text to the console of a certain color with a line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "of", "a", "certain", "color", "with", "a", "line", "break" ]
void prcolorln(colors_t color, const char *msg) { printf("%s%s%s\n", get_color(color), msg, "\033[0m"); }
[ "void", "prcolorln", "(", "colors_t", "color", ",", "const", "char", "*", "msg", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "get_color", "(", "color", ")", ",", "msg", ",", "\"", "\\033", "\"", ")", ";", "}" ]
The function to print text to the console of a certain color with a line break
[ "The", "function", "to", "print", "text", "to", "the", "console", "of", "a", "certain", "color", "with", "a", "line", "break" ]
[]
[ { "param": "color", "type": "colors_t" }, { "param": "msg", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "color", "type": "colors_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8e0aa7ffb74862caea412e2a0c5d3a8319f9d212
bpachev/plato
search.c
[ "MIT" ]
C
pickMove
int
int pickMove(PlatoBoard* board, int searchDepth) { if (!(board->whitePos[0]) || !(board->blackPos[0])) srand(time(0)); int move = 0; int scores[NSTACKS]; int otherBestMove = 0; int my_best = -MAX_SCORE; int other_best = -MAX_SCORE; int i, temp_score; // Consider each possible move (note pruning usually doesn't help on the first level) for (i = 0; i < NSTACKS; i++) { if (!VALID_MOVE(board, i)) continue; doMove(board, i); //printf("Exploring move %d:\n", i); scores[i] = temp_score = -alphaBetaSearch(board, searchDepth-1, other_best, my_best, &otherBestMove); revertMove(board, i); if (temp_score > my_best) my_best = temp_score; } int candidates[NSTACKS]; int num_candidates = 0; //printf("Best score %d\n", my_best); for (i = 0; i < NSTACKS; i++) { //printf("Move %d, score %d\n",i, scores[i]); if (VALID_MOVE(board, i) && scores[i] == my_best) candidates[num_candidates++] = i; } if (num_candidates > 1) { move = candidates[rand()%num_candidates]; } else if (num_candidates == 1) move = candidates[0]; // Failsafe to avoid a crash if(!VALID_MOVE(board, move)) { for(int i = 0; i < NSTACKS; i++) { if(VALID_MOVE(board,i)){ move = i; break; } } } //const char * color = (board->whiteTurn) ? "White" : "Black"; //printf("Picked move %d for %s, score %d\n", move, color, score); return move; }
//Wrapper function to get the proposed move
Wrapper function to get the proposed move
[ "Wrapper", "function", "to", "get", "the", "proposed", "move" ]
int pickMove(PlatoBoard* board, int searchDepth) { if (!(board->whitePos[0]) || !(board->blackPos[0])) srand(time(0)); int move = 0; int scores[NSTACKS]; int otherBestMove = 0; int my_best = -MAX_SCORE; int other_best = -MAX_SCORE; int i, temp_score; for (i = 0; i < NSTACKS; i++) { if (!VALID_MOVE(board, i)) continue; doMove(board, i); scores[i] = temp_score = -alphaBetaSearch(board, searchDepth-1, other_best, my_best, &otherBestMove); revertMove(board, i); if (temp_score > my_best) my_best = temp_score; } int candidates[NSTACKS]; int num_candidates = 0; for (i = 0; i < NSTACKS; i++) { if (VALID_MOVE(board, i) && scores[i] == my_best) candidates[num_candidates++] = i; } if (num_candidates > 1) { move = candidates[rand()%num_candidates]; } else if (num_candidates == 1) move = candidates[0]; if(!VALID_MOVE(board, move)) { for(int i = 0; i < NSTACKS; i++) { if(VALID_MOVE(board,i)){ move = i; break; } } } return move; }
[ "int", "pickMove", "(", "PlatoBoard", "*", "board", ",", "int", "searchDepth", ")", "{", "if", "(", "!", "(", "board", "->", "whitePos", "[", "0", "]", ")", "||", "!", "(", "board", "->", "blackPos", "[", "0", "]", ")", ")", "srand", "(", "time", "(", "0", ")", ")", ";", "int", "move", "=", "0", ";", "int", "scores", "[", "NSTACKS", "]", ";", "int", "otherBestMove", "=", "0", ";", "int", "my_best", "=", "-", "MAX_SCORE", ";", "int", "other_best", "=", "-", "MAX_SCORE", ";", "int", "i", ",", "temp_score", ";", "for", "(", "i", "=", "0", ";", "i", "<", "NSTACKS", ";", "i", "++", ")", "{", "if", "(", "!", "VALID_MOVE", "(", "board", ",", "i", ")", ")", "continue", ";", "doMove", "(", "board", ",", "i", ")", ";", "scores", "[", "i", "]", "=", "temp_score", "=", "-", "alphaBetaSearch", "(", "board", ",", "searchDepth", "-", "1", ",", "other_best", ",", "my_best", ",", "&", "otherBestMove", ")", ";", "revertMove", "(", "board", ",", "i", ")", ";", "if", "(", "temp_score", ">", "my_best", ")", "my_best", "=", "temp_score", ";", "}", "int", "candidates", "[", "NSTACKS", "]", ";", "int", "num_candidates", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "NSTACKS", ";", "i", "++", ")", "{", "if", "(", "VALID_MOVE", "(", "board", ",", "i", ")", "&&", "scores", "[", "i", "]", "==", "my_best", ")", "candidates", "[", "num_candidates", "++", "]", "=", "i", ";", "}", "if", "(", "num_candidates", ">", "1", ")", "{", "move", "=", "candidates", "[", "rand", "(", ")", "%", "num_candidates", "]", ";", "}", "else", "if", "(", "num_candidates", "==", "1", ")", "move", "=", "candidates", "[", "0", "]", ";", "if", "(", "!", "VALID_MOVE", "(", "board", ",", "move", ")", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "NSTACKS", ";", "i", "++", ")", "{", "if", "(", "VALID_MOVE", "(", "board", ",", "i", ")", ")", "{", "move", "=", "i", ";", "break", ";", "}", "}", "}", "return", "move", ";", "}" ]
Wrapper function to get the proposed move
[ "Wrapper", "function", "to", "get", "the", "proposed", "move" ]
[ "// Consider each possible move (note pruning usually doesn't help on the first level)", "//printf(\"Exploring move %d:\\n\", i);", "//printf(\"Best score %d\\n\", my_best);", "//printf(\"Move %d, score %d\\n\",i, scores[i]);", "// Failsafe to avoid a crash", "//const char * color = (board->whiteTurn) ? \"White\" : \"Black\";", "//printf(\"Picked move %d for %s, score %d\\n\", move, color, score);" ]
[ { "param": "board", "type": "PlatoBoard" }, { "param": "searchDepth", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "board", "type": "PlatoBoard", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "searchDepth", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8e0aa7ffb74862caea412e2a0c5d3a8319f9d212
bpachev/plato
search.c
[ "MIT" ]
C
score
int
int score(PlatoBoard* board) { unsigned short * pos, * otherPos; //If it is White's turn now, the last move was Black's. if (board->whiteTurn) { pos = board->blackPos; otherPos = board->whitePos; } else { pos = board->whitePos; otherPos = board->blackPos; } //Check to see if this move wins if (checkPosVictory(pos)) return MAX_SCORE; int myForcing=0, otherForcing=0; int myOpportunities = countOpportunities(pos, otherPos, &myForcing); int otherOpportunities = countOpportunities(otherPos, pos, &otherForcing); //If this move doesn't win, and leaves our opponent with a way to win, we are toast if (otherForcing) return -MAX_SCORE+1; //game over in 1 move if (myForcing > 1) return MAX_SCORE-2; //we have two threats, and he has none, so we win in two moves return FORCING_WEIGHT * myForcing + OPPORTUNITY_WEIGHT * myOpportunities - OPPONENT_OPPORTUNITY_WEIGHT * otherOpportunities; }
//Compute the leaf node score //The computation is performed for the player whose move it is currently
Compute the leaf node score The computation is performed for the player whose move it is currently
[ "Compute", "the", "leaf", "node", "score", "The", "computation", "is", "performed", "for", "the", "player", "whose", "move", "it", "is", "currently" ]
int score(PlatoBoard* board) { unsigned short * pos, * otherPos; if (board->whiteTurn) { pos = board->blackPos; otherPos = board->whitePos; } else { pos = board->whitePos; otherPos = board->blackPos; } if (checkPosVictory(pos)) return MAX_SCORE; int myForcing=0, otherForcing=0; int myOpportunities = countOpportunities(pos, otherPos, &myForcing); int otherOpportunities = countOpportunities(otherPos, pos, &otherForcing); if (otherForcing) return -MAX_SCORE+1; if (myForcing > 1) return MAX_SCORE-2; return FORCING_WEIGHT * myForcing + OPPORTUNITY_WEIGHT * myOpportunities - OPPONENT_OPPORTUNITY_WEIGHT * otherOpportunities; }
[ "int", "score", "(", "PlatoBoard", "*", "board", ")", "{", "unsigned", "short", "*", "pos", ",", "*", "otherPos", ";", "if", "(", "board", "->", "whiteTurn", ")", "{", "pos", "=", "board", "->", "blackPos", ";", "otherPos", "=", "board", "->", "whitePos", ";", "}", "else", "{", "pos", "=", "board", "->", "whitePos", ";", "otherPos", "=", "board", "->", "blackPos", ";", "}", "if", "(", "checkPosVictory", "(", "pos", ")", ")", "return", "MAX_SCORE", ";", "int", "myForcing", "=", "0", ",", "otherForcing", "=", "0", ";", "int", "myOpportunities", "=", "countOpportunities", "(", "pos", ",", "otherPos", ",", "&", "myForcing", ")", ";", "int", "otherOpportunities", "=", "countOpportunities", "(", "otherPos", ",", "pos", ",", "&", "otherForcing", ")", ";", "if", "(", "otherForcing", ")", "return", "-", "MAX_SCORE", "+", "1", ";", "if", "(", "myForcing", ">", "1", ")", "return", "MAX_SCORE", "-", "2", ";", "return", "FORCING_WEIGHT", "*", "myForcing", "+", "OPPORTUNITY_WEIGHT", "*", "myOpportunities", "-", "OPPONENT_OPPORTUNITY_WEIGHT", "*", "otherOpportunities", ";", "}" ]
Compute the leaf node score The computation is performed for the player whose move it is currently
[ "Compute", "the", "leaf", "node", "score", "The", "computation", "is", "performed", "for", "the", "player", "whose", "move", "it", "is", "currently" ]
[ "//If it is White's turn now, the last move was Black's.", "//Check to see if this move wins", "//If this move doesn't win, and leaves our opponent with a way to win, we are toast", "//game over in 1 move", "//we have two threats, and he has none, so we win in two moves" ]
[ { "param": "board", "type": "PlatoBoard" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "board", "type": "PlatoBoard", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8e0aa7ffb74862caea412e2a0c5d3a8319f9d212
bpachev/plato
search.c
[ "MIT" ]
C
alphaBetaSearch
int
int alphaBetaSearch(PlatoBoard* board, int depth, int my_best, int other_best, int* bestMove) { int i, temp_score; register int best = 0; int best_local_score = -MAX_SCORE; //Don't explore past a terminal node if (checkVictory(board)) return -MAX_SCORE; if (depth <= 1) { for (i = 0; i < NSTACKS; i++) { if (!VALID_MOVE(board, i)) continue; doMove(board, i); temp_score = score(board); revertMove(board, i); if (-temp_score < other_best) return temp_score; if (temp_score > best_local_score) { best_local_score = temp_score; best = i; } } *bestMove = best; return best_local_score; } int otherBestMove = 0; //TODO:: add move ordering for (i = 0; i < NSTACKS; i++) { if (!VALID_MOVE(board, i)) continue; doMove(board, i); temp_score = -alphaBetaSearch(board, depth-1, other_best, my_best, &otherBestMove); revertMove(board, i); //prune this node if (-temp_score < other_best) return temp_score; if (temp_score > my_best) my_best = temp_score; if (temp_score > best_local_score) { best_local_score = temp_score; best = i; } } //printf("\tAlpha-beta search called with depth %d, picked move %d, score %d other score %d\n", depth, best, best_local_score, other_best); *bestMove = best; return best_local_score; }
//Perform alpha beta search - returning the best outcome
Perform alpha beta search - returning the best outcome
[ "Perform", "alpha", "beta", "search", "-", "returning", "the", "best", "outcome" ]
int alphaBetaSearch(PlatoBoard* board, int depth, int my_best, int other_best, int* bestMove) { int i, temp_score; register int best = 0; int best_local_score = -MAX_SCORE; if (checkVictory(board)) return -MAX_SCORE; if (depth <= 1) { for (i = 0; i < NSTACKS; i++) { if (!VALID_MOVE(board, i)) continue; doMove(board, i); temp_score = score(board); revertMove(board, i); if (-temp_score < other_best) return temp_score; if (temp_score > best_local_score) { best_local_score = temp_score; best = i; } } *bestMove = best; return best_local_score; } int otherBestMove = 0; for (i = 0; i < NSTACKS; i++) { if (!VALID_MOVE(board, i)) continue; doMove(board, i); temp_score = -alphaBetaSearch(board, depth-1, other_best, my_best, &otherBestMove); revertMove(board, i); if (-temp_score < other_best) return temp_score; if (temp_score > my_best) my_best = temp_score; if (temp_score > best_local_score) { best_local_score = temp_score; best = i; } } *bestMove = best; return best_local_score; }
[ "int", "alphaBetaSearch", "(", "PlatoBoard", "*", "board", ",", "int", "depth", ",", "int", "my_best", ",", "int", "other_best", ",", "int", "*", "bestMove", ")", "{", "int", "i", ",", "temp_score", ";", "register", "int", "best", "=", "0", ";", "int", "best_local_score", "=", "-", "MAX_SCORE", ";", "if", "(", "checkVictory", "(", "board", ")", ")", "return", "-", "MAX_SCORE", ";", "if", "(", "depth", "<=", "1", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "NSTACKS", ";", "i", "++", ")", "{", "if", "(", "!", "VALID_MOVE", "(", "board", ",", "i", ")", ")", "continue", ";", "doMove", "(", "board", ",", "i", ")", ";", "temp_score", "=", "score", "(", "board", ")", ";", "revertMove", "(", "board", ",", "i", ")", ";", "if", "(", "-", "temp_score", "<", "other_best", ")", "return", "temp_score", ";", "if", "(", "temp_score", ">", "best_local_score", ")", "{", "best_local_score", "=", "temp_score", ";", "best", "=", "i", ";", "}", "}", "*", "bestMove", "=", "best", ";", "return", "best_local_score", ";", "}", "int", "otherBestMove", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "NSTACKS", ";", "i", "++", ")", "{", "if", "(", "!", "VALID_MOVE", "(", "board", ",", "i", ")", ")", "continue", ";", "doMove", "(", "board", ",", "i", ")", ";", "temp_score", "=", "-", "alphaBetaSearch", "(", "board", ",", "depth", "-", "1", ",", "other_best", ",", "my_best", ",", "&", "otherBestMove", ")", ";", "revertMove", "(", "board", ",", "i", ")", ";", "if", "(", "-", "temp_score", "<", "other_best", ")", "return", "temp_score", ";", "if", "(", "temp_score", ">", "my_best", ")", "my_best", "=", "temp_score", ";", "if", "(", "temp_score", ">", "best_local_score", ")", "{", "best_local_score", "=", "temp_score", ";", "best", "=", "i", ";", "}", "}", "*", "bestMove", "=", "best", ";", "return", "best_local_score", ";", "}" ]
Perform alpha beta search - returning the best outcome
[ "Perform", "alpha", "beta", "search", "-", "returning", "the", "best", "outcome" ]
[ "//Don't explore past a terminal node", "//TODO:: add move ordering", "//prune this node", "//printf(\"\\tAlpha-beta search called with depth %d, picked move %d, score %d other score %d\\n\", depth, best, best_local_score, other_best);" ]
[ { "param": "board", "type": "PlatoBoard" }, { "param": "depth", "type": "int" }, { "param": "my_best", "type": "int" }, { "param": "other_best", "type": "int" }, { "param": "bestMove", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "board", "type": "PlatoBoard", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "depth", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "my_best", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "other_best", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bestMove", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c52e5622b6d2bd26ceb3e1a34ae2f1e452fbad6e
bpachev/plato
board.c
[ "MIT" ]
C
checkDiagVictory
int
int checkDiagVictory(unsigned short* base) { int i; //Select first and last rows unsigned short rowMask = base[0] & 0xf00f; //For each 4-bit 'row', get the first and last bit unsigned short colMask = base[0] & 0x9999; static const unsigned short colMasks[] = {0x1111, 0x2222, 0x4444, 0x8888}; for (i=1; i < 4; i++) { rowMask &= ((base[i] >> 4*i) & 0xf) + ((base[i] << 4*i) & 0xf000); colMask &= ((base[i]&colMasks[i]) >> i) + ((base[i]&colMasks[3-i]) << i); } if (rowMask|colMask) return 1; unsigned short diagMask = (base[0] & 0x1001) + (base[1] & 0x220) + (base[2] & 0x440) + (base[3] & 0x8008); unsigned short offDiagMask = (base[3] & 0x1001) + (base[2] & 0x220) + (base[1] & 0x440) + (base[0] & 0x8008); return DIAG_MATCH(diagMask) || DIAG_MATCH(offDiagMask); }
//Check the first four levels for a vertical diagonal victory
Check the first four levels for a vertical diagonal victory
[ "Check", "the", "first", "four", "levels", "for", "a", "vertical", "diagonal", "victory" ]
int checkDiagVictory(unsigned short* base) { int i; unsigned short rowMask = base[0] & 0xf00f; unsigned short colMask = base[0] & 0x9999; static const unsigned short colMasks[] = {0x1111, 0x2222, 0x4444, 0x8888}; for (i=1; i < 4; i++) { rowMask &= ((base[i] >> 4*i) & 0xf) + ((base[i] << 4*i) & 0xf000); colMask &= ((base[i]&colMasks[i]) >> i) + ((base[i]&colMasks[3-i]) << i); } if (rowMask|colMask) return 1; unsigned short diagMask = (base[0] & 0x1001) + (base[1] & 0x220) + (base[2] & 0x440) + (base[3] & 0x8008); unsigned short offDiagMask = (base[3] & 0x1001) + (base[2] & 0x220) + (base[1] & 0x440) + (base[0] & 0x8008); return DIAG_MATCH(diagMask) || DIAG_MATCH(offDiagMask); }
[ "int", "checkDiagVictory", "(", "unsigned", "short", "*", "base", ")", "{", "int", "i", ";", "unsigned", "short", "rowMask", "=", "base", "[", "0", "]", "&", "0xf00f", ";", "unsigned", "short", "colMask", "=", "base", "[", "0", "]", "&", "0x9999", ";", "static", "const", "unsigned", "short", "colMasks", "[", "]", "=", "{", "0x1111", ",", "0x2222", ",", "0x4444", ",", "0x8888", "}", ";", "for", "(", "i", "=", "1", ";", "i", "<", "4", ";", "i", "++", ")", "{", "rowMask", "&=", "(", "(", "base", "[", "i", "]", ">>", "4", "*", "i", ")", "&", "0xf", ")", "+", "(", "(", "base", "[", "i", "]", "<<", "4", "*", "i", ")", "&", "0xf000", ")", ";", "colMask", "&=", "(", "(", "base", "[", "i", "]", "&", "colMasks", "[", "i", "]", ")", ">>", "i", ")", "+", "(", "(", "base", "[", "i", "]", "&", "colMasks", "[", "3", "-", "i", "]", ")", "<<", "i", ")", ";", "}", "if", "(", "rowMask", "|", "colMask", ")", "return", "1", ";", "unsigned", "short", "diagMask", "=", "(", "base", "[", "0", "]", "&", "0x1001", ")", "+", "(", "base", "[", "1", "]", "&", "0x220", ")", "+", "(", "base", "[", "2", "]", "&", "0x440", ")", "+", "(", "base", "[", "3", "]", "&", "0x8008", ")", ";", "unsigned", "short", "offDiagMask", "=", "(", "base", "[", "3", "]", "&", "0x1001", ")", "+", "(", "base", "[", "2", "]", "&", "0x220", ")", "+", "(", "base", "[", "1", "]", "&", "0x440", ")", "+", "(", "base", "[", "0", "]", "&", "0x8008", ")", ";", "return", "DIAG_MATCH", "(", "diagMask", ")", "||", "DIAG_MATCH", "(", "offDiagMask", ")", ";", "}" ]
Check the first four levels for a vertical diagonal victory
[ "Check", "the", "first", "four", "levels", "for", "a", "vertical", "diagonal", "victory" ]
[ "//Select first and last rows", "//For each 4-bit 'row', get the first and last bit" ]
[ { "param": "base", "type": "unsigned short" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "base", "type": "unsigned short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c52e5622b6d2bd26ceb3e1a34ae2f1e452fbad6e
bpachev/plato
board.c
[ "MIT" ]
C
checkLevelVictory
int
int checkLevelVictory(unsigned short mask) { if (!mask) return 0; //check rows and columns unsigned short rowFilter = 0xf; unsigned short colFilter = 0x1111; for (int i = 0; i < 4; i++) { if (MATCH(mask, rowFilter) || MATCH(mask, colFilter)) return 1; rowFilter = rowFilter << 4; colFilter = colFilter << 1; } return DIAG_MATCH(mask); }
//Check one horizontal level of the board for a win
Check one horizontal level of the board for a win
[ "Check", "one", "horizontal", "level", "of", "the", "board", "for", "a", "win" ]
int checkLevelVictory(unsigned short mask) { if (!mask) return 0; unsigned short rowFilter = 0xf; unsigned short colFilter = 0x1111; for (int i = 0; i < 4; i++) { if (MATCH(mask, rowFilter) || MATCH(mask, colFilter)) return 1; rowFilter = rowFilter << 4; colFilter = colFilter << 1; } return DIAG_MATCH(mask); }
[ "int", "checkLevelVictory", "(", "unsigned", "short", "mask", ")", "{", "if", "(", "!", "mask", ")", "return", "0", ";", "unsigned", "short", "rowFilter", "=", "0xf", ";", "unsigned", "short", "colFilter", "=", "0x1111", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "4", ";", "i", "++", ")", "{", "if", "(", "MATCH", "(", "mask", ",", "rowFilter", ")", "||", "MATCH", "(", "mask", ",", "colFilter", ")", ")", "return", "1", ";", "rowFilter", "=", "rowFilter", "<<", "4", ";", "colFilter", "=", "colFilter", "<<", "1", ";", "}", "return", "DIAG_MATCH", "(", "mask", ")", ";", "}" ]
Check one horizontal level of the board for a win
[ "Check", "one", "horizontal", "level", "of", "the", "board", "for", "a", "win" ]
[ "//check rows and columns" ]
[ { "param": "mask", "type": "unsigned short" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mask", "type": "unsigned short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a98a8f03aaf03b56fb78ac62d9e570154c8722db
trombik/esp_wireguard
src/crypto/refc/x25519.h
[ "BSD-3-Clause" ]
C
x25519_base_uniform
void
static inline void x25519_base_uniform ( unsigned char out[EC_PUBLIC_BYTES], const unsigned char scalar[EC_UNIFORM_BYTES] ) { (void)x25519_base(out,scalar,0); }
/** * As x25519_base, but with a scalar that's EC_UNIFORM_BYTES long, * and clamp always 0 (and thus, no return value). * * This is used for signing. Implementors must replace it for * curves that require more bytes for uniformity (Brainpool). */
As x25519_base, but with a scalar that's EC_UNIFORM_BYTES long, and clamp always 0 (and thus, no return value). This is used for signing. Implementors must replace it for curves that require more bytes for uniformity (Brainpool).
[ "As", "x25519_base", "but", "with", "a", "scalar", "that", "'", "s", "EC_UNIFORM_BYTES", "long", "and", "clamp", "always", "0", "(", "and", "thus", "no", "return", "value", ")", ".", "This", "is", "used", "for", "signing", ".", "Implementors", "must", "replace", "it", "for", "curves", "that", "require", "more", "bytes", "for", "uniformity", "(", "Brainpool", ")", "." ]
static inline void x25519_base_uniform ( unsigned char out[EC_PUBLIC_BYTES], const unsigned char scalar[EC_UNIFORM_BYTES] ) { (void)x25519_base(out,scalar,0); }
[ "static", "inline", "void", "x25519_base_uniform", "(", "unsigned", "char", "out", "[", "EC_PUBLIC_BYTES", "]", ",", "const", "unsigned", "char", "scalar", "[", "EC_UNIFORM_BYTES", "]", ")", "{", "(", "void", ")", "x25519_base", "(", "out", ",", "scalar", ",", "0", ")", ";", "}" ]
As x25519_base, but with a scalar that's EC_UNIFORM_BYTES long, and clamp always 0 (and thus, no return value).
[ "As", "x25519_base", "but", "with", "a", "scalar", "that", "'", "s", "EC_UNIFORM_BYTES", "long", "and", "clamp", "always", "0", "(", "and", "thus", "no", "return", "value", ")", "." ]
[]
[ { "param": "out", "type": "unsigned char" }, { "param": "scalar", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "out", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "scalar", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
47b9256853d876cec7f62f583e94df1a7fdb94bb
helo9/zephly
samples/drivers/control_output/src/main.c
[ "Apache-2.0" ]
C
update_outputs
int
int update_outputs(const struct device *control_out, const float target) { const float outputs[4] = {target, target, target, target}; return control_output_set(control_out, outputs); }
/** * @brief write output value to all channels of output device * * @param control_out the output device * @param target the target or setpoint value to write * @return int 0 for success, -errno otherwise */
@brief write output value to all channels of output device @param control_out the output device @param target the target or setpoint value to write @return int 0 for success, -errno otherwise
[ "@brief", "write", "output", "value", "to", "all", "channels", "of", "output", "device", "@param", "control_out", "the", "output", "device", "@param", "target", "the", "target", "or", "setpoint", "value", "to", "write", "@return", "int", "0", "for", "success", "-", "errno", "otherwise" ]
int update_outputs(const struct device *control_out, const float target) { const float outputs[4] = {target, target, target, target}; return control_output_set(control_out, outputs); }
[ "int", "update_outputs", "(", "const", "struct", "device", "*", "control_out", ",", "const", "float", "target", ")", "{", "const", "float", "outputs", "[", "4", "]", "=", "{", "target", ",", "target", ",", "target", ",", "target", "}", ";", "return", "control_output_set", "(", "control_out", ",", "outputs", ")", ";", "}" ]
@brief write output value to all channels of output device
[ "@brief", "write", "output", "value", "to", "all", "channels", "of", "output", "device" ]
[]
[ { "param": "control_out", "type": "struct device" }, { "param": "target", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "control_out", "type": "struct device", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "target", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a3f446e3aa463383fae790c43de3cb189c81998c
ryanplusplus/tiny
include/tiny_event_subscription.h
[ "MIT" ]
C
tiny_event_subscription_publish
void
inline void tiny_event_subscription_publish( tiny_event_subscription_t* self, const void* args) { self->callback(self->context, args); }
/*! * Publishes to the event subscriber. */
Publishes to the event subscriber.
[ "Publishes", "to", "the", "event", "subscriber", "." ]
inline void tiny_event_subscription_publish( tiny_event_subscription_t* self, const void* args) { self->callback(self->context, args); }
[ "inline", "void", "tiny_event_subscription_publish", "(", "tiny_event_subscription_t", "*", "self", ",", "const", "void", "*", "args", ")", "{", "self", "->", "callback", "(", "self", "->", "context", ",", "args", ")", ";", "}" ]
Publishes to the event subscriber.
[ "Publishes", "to", "the", "event", "subscriber", "." ]
[]
[ { "param": "self", "type": "tiny_event_subscription_t" }, { "param": "args", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "tiny_event_subscription_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "args", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1cf48d402888567b4118f7e452f57eb017a39b7e
ryanplusplus/tiny
include/tiny_timer.h
[ "MIT" ]
C
tiny_timer_is_running
bool
inline bool tiny_timer_is_running( tiny_timer_group_t* self, tiny_timer_t* timer) { return tiny_list_contains(&self->timers, &timer->node); }
/*! * Returns true if the specified timer is running and false otherwise. */
Returns true if the specified timer is running and false otherwise.
[ "Returns", "true", "if", "the", "specified", "timer", "is", "running", "and", "false", "otherwise", "." ]
inline bool tiny_timer_is_running( tiny_timer_group_t* self, tiny_timer_t* timer) { return tiny_list_contains(&self->timers, &timer->node); }
[ "inline", "bool", "tiny_timer_is_running", "(", "tiny_timer_group_t", "*", "self", ",", "tiny_timer_t", "*", "timer", ")", "{", "return", "tiny_list_contains", "(", "&", "self", "->", "timers", ",", "&", "timer", "->", "node", ")", ";", "}" ]
Returns true if the specified timer is running and false otherwise.
[ "Returns", "true", "if", "the", "specified", "timer", "is", "running", "and", "false", "otherwise", "." ]
[]
[ { "param": "self", "type": "tiny_timer_group_t" }, { "param": "timer", "type": "tiny_timer_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "tiny_timer_group_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "timer", "type": "tiny_timer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8a75d95a95da3d9baaa555cff797c7def78b9c23
ryanplusplus/tiny
include/tiny_fsm.h
[ "MIT" ]
C
tiny_fsm_init
void
inline void tiny_fsm_init(tiny_fsm_t* self, tiny_fsm_state_t initial) { self->current = initial; self->current(self, tiny_fsm_signal_entry, NULL); }
/*! * Initializes an FSM with the specified initial state. Sends the entry signal to the * initial state. */
Initializes an FSM with the specified initial state. Sends the entry signal to the initial state.
[ "Initializes", "an", "FSM", "with", "the", "specified", "initial", "state", ".", "Sends", "the", "entry", "signal", "to", "the", "initial", "state", "." ]
inline void tiny_fsm_init(tiny_fsm_t* self, tiny_fsm_state_t initial) { self->current = initial; self->current(self, tiny_fsm_signal_entry, NULL); }
[ "inline", "void", "tiny_fsm_init", "(", "tiny_fsm_t", "*", "self", ",", "tiny_fsm_state_t", "initial", ")", "{", "self", "->", "current", "=", "initial", ";", "self", "->", "current", "(", "self", ",", "tiny_fsm_signal_entry", ",", "NULL", ")", ";", "}" ]
Initializes an FSM with the specified initial state.
[ "Initializes", "an", "FSM", "with", "the", "specified", "initial", "state", "." ]
[]
[ { "param": "self", "type": "tiny_fsm_t" }, { "param": "initial", "type": "tiny_fsm_state_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "tiny_fsm_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "initial", "type": "tiny_fsm_state_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bab2f41bde256dfd35f787e3a1edaefacda8a0ae
JangJang3/OpenMS
src/openms/thirdparty/IsoSpec/IsoSpec/marginalTrek++.h
[ "BSL-1.0", "Zlib", "Apache-2.0" ]
C
probeConfigurationIdx
bool
inline bool probeConfigurationIdx(int idx) { while(current_count <= idx) if(!add_next_conf()) return false; return true; }
//! Check if the table of computed subisotopologues does not have to be extended. /*! This function checks if the idx-th most probable subisotopologue was memoized and if not, computes it and memoizes it. \param idx The number of the idx-th most probable subisotopologue. \return Returns false if it the provided idx exceeds the total number of subisotopologues. */
Check if the table of computed subisotopologues does not have to be extended. This function checks if the idx-th most probable subisotopologue was memoized and if not, computes it and memoizes it. \param idx The number of the idx-th most probable subisotopologue. \return Returns false if it the provided idx exceeds the total number of subisotopologues.
[ "Check", "if", "the", "table", "of", "computed", "subisotopologues", "does", "not", "have", "to", "be", "extended", ".", "This", "function", "checks", "if", "the", "idx", "-", "th", "most", "probable", "subisotopologue", "was", "memoized", "and", "if", "not", "computes", "it", "and", "memoizes", "it", ".", "\\", "param", "idx", "The", "number", "of", "the", "idx", "-", "th", "most", "probable", "subisotopologue", ".", "\\", "return", "Returns", "false", "if", "it", "the", "provided", "idx", "exceeds", "the", "total", "number", "of", "subisotopologues", "." ]
inline bool probeConfigurationIdx(int idx) { while(current_count <= idx) if(!add_next_conf()) return false; return true; }
[ "inline", "bool", "probeConfigurationIdx", "(", "int", "idx", ")", "{", "while", "(", "current_count", "<=", "idx", ")", "if", "(", "!", "add_next_conf", "(", ")", ")", "return", "false", ";", "return", "true", ";", "}" ]
Check if the table of computed subisotopologues does not have to be extended.
[ "Check", "if", "the", "table", "of", "computed", "subisotopologues", "does", "not", "have", "to", "be", "extended", "." ]
[]
[ { "param": "idx", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "idx", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3611d2aea27235ed821d7f4314baaaa5aafe0d23
VirtualPythonLLC/VPGP-SGDK
sdk/src/memory.c
[ "MIT" ]
C
pack
u16
static u16* pack(u16 nsize) { u16 *b; u16 *best; u16 bsize, psize; b = heap; best = b; bsize = 0; while ((psize = *b)) { if (psize & USED) { if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; bsize = 0; } b += psize >> 1; best = b; } else { bsize += psize; b += psize >> 1; } } if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; } return NULL; }
/* * Pack free block and return first matching free block. */
Pack free block and return first matching free block.
[ "Pack", "free", "block", "and", "return", "first", "matching", "free", "block", "." ]
static u16* pack(u16 nsize) { u16 *b; u16 *best; u16 bsize, psize; b = heap; best = b; bsize = 0; while ((psize = *b)) { if (psize & USED) { if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; bsize = 0; } b += psize >> 1; best = b; } else { bsize += psize; b += psize >> 1; } } if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; } return NULL; }
[ "static", "u16", "*", "pack", "(", "u16", "nsize", ")", "{", "u16", "*", "b", ";", "u16", "*", "best", ";", "u16", "bsize", ",", "psize", ";", "b", "=", "heap", ";", "best", "=", "b", ";", "bsize", "=", "0", ";", "while", "(", "(", "psize", "=", "*", "b", ")", ")", "{", "if", "(", "psize", "&", "USED", ")", "{", "if", "(", "bsize", "!=", "0", ")", "{", "*", "best", "=", "bsize", ";", "if", "(", "bsize", ">=", "nsize", ")", "return", "best", ";", "bsize", "=", "0", ";", "}", "b", "+=", "psize", ">>", "1", ";", "best", "=", "b", ";", "}", "else", "{", "bsize", "+=", "psize", ";", "b", "+=", "psize", ">>", "1", ";", "}", "}", "if", "(", "bsize", "!=", "0", ")", "{", "*", "best", "=", "bsize", ";", "if", "(", "bsize", ">=", "nsize", ")", "return", "best", ";", "}", "return", "NULL", ";", "}" ]
Pack free block and return first matching free block.
[ "Pack", "free", "block", "and", "return", "first", "matching", "free", "block", "." ]
[]
[ { "param": "nsize", "type": "u16" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "nsize", "type": "u16", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f1e6b8a1dbfd33926af7ba57d12927f7d0cac391
VirtualPythonLLC/VPGP-SGDK
sdk/src/sound.c
[ "MIT" ]
C
SND_isPlaying_PCM
u8
u8 SND_isPlaying_PCM() { vu8 *pb; u8 ret; // disable ints when requesting Z80 bus SYS_disableInts(); // load the appropriate driver if not already done Z80_loadDriver(Z80_DRIVER_PCM, TRUE); Z80_requestBus(TRUE); // point to Z80 status pb = (u8 *) Z80_DRV_STATUS; // play status ret = *pb & Z80_DRV_STAT_PLAYING; Z80_releaseBus(); // re-enable ints SYS_enableInts(); return ret; }
// Z80_DRIVER_PCM // single channel 8 bits signed sample driver ///////////////////////////////////////////////////////////////
Z80_DRIVER_PCM single channel 8 bits signed sample driver
[ "Z80_DRIVER_PCM", "single", "channel", "8", "bits", "signed", "sample", "driver" ]
u8 SND_isPlaying_PCM() { vu8 *pb; u8 ret; SYS_disableInts(); Z80_loadDriver(Z80_DRIVER_PCM, TRUE); Z80_requestBus(TRUE); pb = (u8 *) Z80_DRV_STATUS; ret = *pb & Z80_DRV_STAT_PLAYING; Z80_releaseBus(); SYS_enableInts(); return ret; }
[ "u8", "SND_isPlaying_PCM", "(", ")", "{", "vu8", "*", "pb", ";", "u8", "ret", ";", "SYS_disableInts", "(", ")", ";", "Z80_loadDriver", "(", "Z80_DRIVER_PCM", ",", "TRUE", ")", ";", "Z80_requestBus", "(", "TRUE", ")", ";", "pb", "=", "(", "u8", "*", ")", "Z80_DRV_STATUS", ";", "ret", "=", "*", "pb", "&", "Z80_DRV_STAT_PLAYING", ";", "Z80_releaseBus", "(", ")", ";", "SYS_enableInts", "(", ")", ";", "return", "ret", ";", "}" ]
Z80_DRIVER_PCM single channel 8 bits signed sample driver
[ "Z80_DRIVER_PCM", "single", "channel", "8", "bits", "signed", "sample", "driver" ]
[ "// disable ints when requesting Z80 bus", "// load the appropriate driver if not already done", "// point to Z80 status", "// play status", "// re-enable ints" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f1e6b8a1dbfd33926af7ba57d12927f7d0cac391
VirtualPythonLLC/VPGP-SGDK
sdk/src/sound.c
[ "MIT" ]
C
SND_isPlaying_2ADPCM
u8
u8 SND_isPlaying_2ADPCM(const u16 channel_mask) { vu8 *pb; u8 ret; // disable ints when requesting Z80 bus SYS_disableInts(); // load the appropriate driver if not already done Z80_loadDriver(Z80_DRIVER_2ADPCM, TRUE); Z80_requestBus(TRUE); // point to Z80 status pb = (u8 *) Z80_DRV_STATUS; // play status ret = *pb & (channel_mask << Z80_DRV_STAT_PLAYING_SFT); Z80_releaseBus(); // re-enable ints SYS_enableInts(); return ret; }
// Z80_DRIVER_2ADPCM // 2 channels 4 bits ADPCM sample driver ///////////////////////////////////////////////////////////////
Z80_DRIVER_2ADPCM 2 channels 4 bits ADPCM sample driver
[ "Z80_DRIVER_2ADPCM", "2", "channels", "4", "bits", "ADPCM", "sample", "driver" ]
u8 SND_isPlaying_2ADPCM(const u16 channel_mask) { vu8 *pb; u8 ret; SYS_disableInts(); Z80_loadDriver(Z80_DRIVER_2ADPCM, TRUE); Z80_requestBus(TRUE); pb = (u8 *) Z80_DRV_STATUS; ret = *pb & (channel_mask << Z80_DRV_STAT_PLAYING_SFT); Z80_releaseBus(); SYS_enableInts(); return ret; }
[ "u8", "SND_isPlaying_2ADPCM", "(", "const", "u16", "channel_mask", ")", "{", "vu8", "*", "pb", ";", "u8", "ret", ";", "SYS_disableInts", "(", ")", ";", "Z80_loadDriver", "(", "Z80_DRIVER_2ADPCM", ",", "TRUE", ")", ";", "Z80_requestBus", "(", "TRUE", ")", ";", "pb", "=", "(", "u8", "*", ")", "Z80_DRV_STATUS", ";", "ret", "=", "*", "pb", "&", "(", "channel_mask", "<<", "Z80_DRV_STAT_PLAYING_SFT", ")", ";", "Z80_releaseBus", "(", ")", ";", "SYS_enableInts", "(", ")", ";", "return", "ret", ";", "}" ]
Z80_DRIVER_2ADPCM 2 channels 4 bits ADPCM sample driver
[ "Z80_DRIVER_2ADPCM", "2", "channels", "4", "bits", "ADPCM", "sample", "driver" ]
[ "// disable ints when requesting Z80 bus", "// load the appropriate driver if not already done", "// point to Z80 status", "// play status", "// re-enable ints" ]
[ { "param": "channel_mask", "type": "u16" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "channel_mask", "type": "u16", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f1e6b8a1dbfd33926af7ba57d12927f7d0cac391
VirtualPythonLLC/VPGP-SGDK
sdk/src/sound.c
[ "MIT" ]
C
SND_isPlaying_4PCM_ENV
u8
u8 SND_isPlaying_4PCM_ENV(const u16 channel_mask) { vu8 *pb; u8 ret; // disable ints when requesting Z80 bus SYS_disableInts(); // load the appropriate driver if not already done Z80_loadDriver(Z80_DRIVER_4PCM_ENV, TRUE); Z80_requestBus(TRUE); // point to Z80 status pb = (u8 *) Z80_DRV_STATUS; // play status ret = *pb & (channel_mask << Z80_DRV_STAT_PLAYING_SFT); Z80_releaseBus(); // re-enable ints SYS_enableInts(); return ret; }
// Z80_DRIVER_4PCM_ENV // 4 channels 8 bits signed sample driver with volume support ///////////////////////////////////////////////////////////////
Z80_DRIVER_4PCM_ENV 4 channels 8 bits signed sample driver with volume support
[ "Z80_DRIVER_4PCM_ENV", "4", "channels", "8", "bits", "signed", "sample", "driver", "with", "volume", "support" ]
u8 SND_isPlaying_4PCM_ENV(const u16 channel_mask) { vu8 *pb; u8 ret; SYS_disableInts(); Z80_loadDriver(Z80_DRIVER_4PCM_ENV, TRUE); Z80_requestBus(TRUE); pb = (u8 *) Z80_DRV_STATUS; ret = *pb & (channel_mask << Z80_DRV_STAT_PLAYING_SFT); Z80_releaseBus(); SYS_enableInts(); return ret; }
[ "u8", "SND_isPlaying_4PCM_ENV", "(", "const", "u16", "channel_mask", ")", "{", "vu8", "*", "pb", ";", "u8", "ret", ";", "SYS_disableInts", "(", ")", ";", "Z80_loadDriver", "(", "Z80_DRIVER_4PCM_ENV", ",", "TRUE", ")", ";", "Z80_requestBus", "(", "TRUE", ")", ";", "pb", "=", "(", "u8", "*", ")", "Z80_DRV_STATUS", ";", "ret", "=", "*", "pb", "&", "(", "channel_mask", "<<", "Z80_DRV_STAT_PLAYING_SFT", ")", ";", "Z80_releaseBus", "(", ")", ";", "SYS_enableInts", "(", ")", ";", "return", "ret", ";", "}" ]
Z80_DRIVER_4PCM_ENV 4 channels 8 bits signed sample driver with volume support
[ "Z80_DRIVER_4PCM_ENV", "4", "channels", "8", "bits", "signed", "sample", "driver", "with", "volume", "support" ]
[ "// disable ints when requesting Z80 bus", "// load the appropriate driver if not already done", "// point to Z80 status", "// play status", "// re-enable ints" ]
[ { "param": "channel_mask", "type": "u16" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "channel_mask", "type": "u16", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
765738de9aedc7839da3c8ba250242b224778dda
VirtualPythonLLC/VPGP-SGDK
Propeller/LevelManager.c
[ "MIT" ]
C
LevelManager_UpdateCoinPickup
void
void LevelManager_UpdateCoinPickup() { u16 tilex = VIRTUAL_TO_TILE(playerObject->x); u16 tiley = VIRTUAL_TO_TILE(playerObject->y); u16 tiledata = ARRAY_ITEM_VALUE(levelData.foreground->tilemap, tilex + (tiley << levelData.mapWidthAsShiftValue)); if ((tiledata & SPECIAL_TILE) != 0 && ((tiledata & SPECIAL_TILE_TYPE_MASK) >> 8) == COIN_TYPE) { u16 coinIndexMap = tiledata & SPECIAL_TILE_ARRAY_INDEX_MASK; if (*(coinMap + coinIndexMap)) { u16 tileindex = tiledata & SPECIAL_TILE_INDEX_MASK; tileindex >>= 11; ClearCoin(tileindex, tilex, tiley); coinMap[coinIndexMap] = 0; playerData.numCoins++; UpdateHUDCoins(); } } }
// This function clears the coin tile from the visible map.
This function clears the coin tile from the visible map.
[ "This", "function", "clears", "the", "coin", "tile", "from", "the", "visible", "map", "." ]
void LevelManager_UpdateCoinPickup() { u16 tilex = VIRTUAL_TO_TILE(playerObject->x); u16 tiley = VIRTUAL_TO_TILE(playerObject->y); u16 tiledata = ARRAY_ITEM_VALUE(levelData.foreground->tilemap, tilex + (tiley << levelData.mapWidthAsShiftValue)); if ((tiledata & SPECIAL_TILE) != 0 && ((tiledata & SPECIAL_TILE_TYPE_MASK) >> 8) == COIN_TYPE) { u16 coinIndexMap = tiledata & SPECIAL_TILE_ARRAY_INDEX_MASK; if (*(coinMap + coinIndexMap)) { u16 tileindex = tiledata & SPECIAL_TILE_INDEX_MASK; tileindex >>= 11; ClearCoin(tileindex, tilex, tiley); coinMap[coinIndexMap] = 0; playerData.numCoins++; UpdateHUDCoins(); } } }
[ "void", "LevelManager_UpdateCoinPickup", "(", ")", "{", "u16", "tilex", "=", "VIRTUAL_TO_TILE", "(", "playerObject", "->", "x", ")", ";", "u16", "tiley", "=", "VIRTUAL_TO_TILE", "(", "playerObject", "->", "y", ")", ";", "u16", "tiledata", "=", "ARRAY_ITEM_VALUE", "(", "levelData", ".", "foreground", "->", "tilemap", ",", "tilex", "+", "(", "tiley", "<<", "levelData", ".", "mapWidthAsShiftValue", ")", ")", ";", "if", "(", "(", "tiledata", "&", "SPECIAL_TILE", ")", "!=", "0", "&&", "(", "(", "tiledata", "&", "SPECIAL_TILE_TYPE_MASK", ")", ">>", "8", ")", "==", "COIN_TYPE", ")", "{", "u16", "coinIndexMap", "=", "tiledata", "&", "SPECIAL_TILE_ARRAY_INDEX_MASK", ";", "if", "(", "*", "(", "coinMap", "+", "coinIndexMap", ")", ")", "{", "u16", "tileindex", "=", "tiledata", "&", "SPECIAL_TILE_INDEX_MASK", ";", "tileindex", ">>=", "11", ";", "ClearCoin", "(", "tileindex", ",", "tilex", ",", "tiley", ")", ";", "coinMap", "[", "coinIndexMap", "]", "=", "0", ";", "playerData", ".", "numCoins", "++", ";", "UpdateHUDCoins", "(", ")", ";", "}", "}", "}" ]
This function clears the coin tile from the visible map.
[ "This", "function", "clears", "the", "coin", "tile", "from", "the", "visible", "map", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
d9580a9a93903a1500e5ab06ab865ed85c4fb98d
VirtualPythonLLC/VPGP-SGDK
sdk/src/vram.c
[ "MIT" ]
C
pack
u16
static u16* pack(VRAMRegion *region, u16 nsize) { u16 *b; u16 *best; u16 bsize, psize; b = region->vram; best = b; bsize = 0; while ((psize = *b)) { if (psize & USED_MASK) { if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; bsize = 0; } b += psize & SIZE_MASK; best = b; } else { bsize += psize; b += psize; } } if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; } return NULL; }
/* * Pack free block and return first matching free block */
Pack free block and return first matching free block
[ "Pack", "free", "block", "and", "return", "first", "matching", "free", "block" ]
static u16* pack(VRAMRegion *region, u16 nsize) { u16 *b; u16 *best; u16 bsize, psize; b = region->vram; best = b; bsize = 0; while ((psize = *b)) { if (psize & USED_MASK) { if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; bsize = 0; } b += psize & SIZE_MASK; best = b; } else { bsize += psize; b += psize; } } if (bsize != 0) { *best = bsize; if (bsize >= nsize) return best; } return NULL; }
[ "static", "u16", "*", "pack", "(", "VRAMRegion", "*", "region", ",", "u16", "nsize", ")", "{", "u16", "*", "b", ";", "u16", "*", "best", ";", "u16", "bsize", ",", "psize", ";", "b", "=", "region", "->", "vram", ";", "best", "=", "b", ";", "bsize", "=", "0", ";", "while", "(", "(", "psize", "=", "*", "b", ")", ")", "{", "if", "(", "psize", "&", "USED_MASK", ")", "{", "if", "(", "bsize", "!=", "0", ")", "{", "*", "best", "=", "bsize", ";", "if", "(", "bsize", ">=", "nsize", ")", "return", "best", ";", "bsize", "=", "0", ";", "}", "b", "+=", "psize", "&", "SIZE_MASK", ";", "best", "=", "b", ";", "}", "else", "{", "bsize", "+=", "psize", ";", "b", "+=", "psize", ";", "}", "}", "if", "(", "bsize", "!=", "0", ")", "{", "*", "best", "=", "bsize", ";", "if", "(", "bsize", ">=", "nsize", ")", "return", "best", ";", "}", "return", "NULL", ";", "}" ]
Pack free block and return first matching free block
[ "Pack", "free", "block", "and", "return", "first", "matching", "free", "block" ]
[]
[ { "param": "region", "type": "VRAMRegion" }, { "param": "nsize", "type": "u16" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "region", "type": "VRAMRegion", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nsize", "type": "u16", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
57b488b9da037b34dc78cce8b225c194750bdc40
maletsden/lightning-queen
common_parts/cuda_validator/cuda_validator.h
[ "MIT" ]
C
check_error
cudaError_t
inline cudaError_t check_error(cudaError_t result) { #if defined(DEBUG) || defined(_DEBUG) if (result != cudaSuccess) { fprintf(stderr, "CUDA Runtime Error: %s\n", cudaGetErrorString(result)); assert(result == cudaSuccess); } #endif return result; }
// Convenience function for checking CUDA runtime API results // can be wrapped around any runtime API call. No-op in release builds.
Convenience function for checking CUDA runtime API results can be wrapped around any runtime API call. No-op in release builds.
[ "Convenience", "function", "for", "checking", "CUDA", "runtime", "API", "results", "can", "be", "wrapped", "around", "any", "runtime", "API", "call", ".", "No", "-", "op", "in", "release", "builds", "." ]
inline cudaError_t check_error(cudaError_t result) { #if defined(DEBUG) || defined(_DEBUG) if (result != cudaSuccess) { fprintf(stderr, "CUDA Runtime Error: %s\n", cudaGetErrorString(result)); assert(result == cudaSuccess); } #endif return result; }
[ "inline", "cudaError_t", "check_error", "(", "cudaError_t", "result", ")", "{", "#if", "defined", "(", "DEBUG", ")", "||", "defined", "(", "_DEBUG", ")", "\n", "if", "(", "result", "!=", "cudaSuccess", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "cudaGetErrorString", "(", "result", ")", ")", ";", "assert", "(", "result", "==", "cudaSuccess", ")", ";", "}", "#endif", "return", "result", ";", "}" ]
Convenience function for checking CUDA runtime API results can be wrapped around any runtime API call.
[ "Convenience", "function", "for", "checking", "CUDA", "runtime", "API", "results", "can", "be", "wrapped", "around", "any", "runtime", "API", "call", "." ]
[]
[ { "param": "result", "type": "cudaError_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "result", "type": "cudaError_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
zero_vif
void
void zero_vif(struct uvif *v, int t) { v->uv_flags = 0; /* Default to IGMPv3 */ v->uv_metric = DEFAULT_METRIC; v->uv_admetric = 0; v->uv_threshold = DEFAULT_THRESHOLD; v->uv_rate_limit = t ? DEFAULT_REG_RATE_LIMIT : DEFAULT_PHY_RATE_LIMIT; v->uv_lcl_addr = INADDR_ANY_N; v->uv_rmt_addr = INADDR_ANY_N; v->uv_dst_addr = t ? INADDR_ANY_N : allpimrouters_group; v->uv_subnet = INADDR_ANY_N; v->uv_subnetmask = INADDR_ANY_N; v->uv_subnetbcast = INADDR_ANY_N; strlcpy(v->uv_name, "", IFNAMSIZ); v->uv_groups = (struct listaddr *)NULL; v->uv_dvmrp_neighbors = (struct listaddr *)NULL; NBRM_CLRALL(v->uv_nbrmap); v->uv_querier = (struct listaddr *)NULL; v->uv_igmpv1_warn = 0; v->uv_prune_lifetime = 0; v->uv_acl = (struct vif_acl *)NULL; RESET_TIMER(v->uv_leaf_timer); v->uv_addrs = (struct phaddr *)NULL; v->uv_filter = (struct vif_filter *)NULL; RESET_TIMER(v->uv_hello_timer); v->uv_dr_prio = PIM_HELLO_DR_PRIO_DEFAULT; v->uv_genid = 0; RESET_TIMER(v->uv_gq_timer); RESET_TIMER(v->uv_jp_timer); v->uv_pim_neighbors = (struct pim_nbr_entry *)NULL; v->uv_local_pref = default_route_distance; v->uv_local_metric = default_route_metric; v->uv_ifindex = -1; }
/* * Initialize the passed vif with all appropriate default values. * "t" is true if a tunnel or register_vif, or false if a phyint. */
Initialize the passed vif with all appropriate default values. "t" is true if a tunnel or register_vif, or false if a phyint.
[ "Initialize", "the", "passed", "vif", "with", "all", "appropriate", "default", "values", ".", "\"", "t", "\"", "is", "true", "if", "a", "tunnel", "or", "register_vif", "or", "false", "if", "a", "phyint", "." ]
void zero_vif(struct uvif *v, int t) { v->uv_flags = 0; v->uv_metric = DEFAULT_METRIC; v->uv_admetric = 0; v->uv_threshold = DEFAULT_THRESHOLD; v->uv_rate_limit = t ? DEFAULT_REG_RATE_LIMIT : DEFAULT_PHY_RATE_LIMIT; v->uv_lcl_addr = INADDR_ANY_N; v->uv_rmt_addr = INADDR_ANY_N; v->uv_dst_addr = t ? INADDR_ANY_N : allpimrouters_group; v->uv_subnet = INADDR_ANY_N; v->uv_subnetmask = INADDR_ANY_N; v->uv_subnetbcast = INADDR_ANY_N; strlcpy(v->uv_name, "", IFNAMSIZ); v->uv_groups = (struct listaddr *)NULL; v->uv_dvmrp_neighbors = (struct listaddr *)NULL; NBRM_CLRALL(v->uv_nbrmap); v->uv_querier = (struct listaddr *)NULL; v->uv_igmpv1_warn = 0; v->uv_prune_lifetime = 0; v->uv_acl = (struct vif_acl *)NULL; RESET_TIMER(v->uv_leaf_timer); v->uv_addrs = (struct phaddr *)NULL; v->uv_filter = (struct vif_filter *)NULL; RESET_TIMER(v->uv_hello_timer); v->uv_dr_prio = PIM_HELLO_DR_PRIO_DEFAULT; v->uv_genid = 0; RESET_TIMER(v->uv_gq_timer); RESET_TIMER(v->uv_jp_timer); v->uv_pim_neighbors = (struct pim_nbr_entry *)NULL; v->uv_local_pref = default_route_distance; v->uv_local_metric = default_route_metric; v->uv_ifindex = -1; }
[ "void", "zero_vif", "(", "struct", "uvif", "*", "v", ",", "int", "t", ")", "{", "v", "->", "uv_flags", "=", "0", ";", "v", "->", "uv_metric", "=", "DEFAULT_METRIC", ";", "v", "->", "uv_admetric", "=", "0", ";", "v", "->", "uv_threshold", "=", "DEFAULT_THRESHOLD", ";", "v", "->", "uv_rate_limit", "=", "t", "?", "DEFAULT_REG_RATE_LIMIT", ":", "DEFAULT_PHY_RATE_LIMIT", ";", "v", "->", "uv_lcl_addr", "=", "INADDR_ANY_N", ";", "v", "->", "uv_rmt_addr", "=", "INADDR_ANY_N", ";", "v", "->", "uv_dst_addr", "=", "t", "?", "INADDR_ANY_N", ":", "allpimrouters_group", ";", "v", "->", "uv_subnet", "=", "INADDR_ANY_N", ";", "v", "->", "uv_subnetmask", "=", "INADDR_ANY_N", ";", "v", "->", "uv_subnetbcast", "=", "INADDR_ANY_N", ";", "strlcpy", "(", "v", "->", "uv_name", ",", "\"", "\"", ",", "IFNAMSIZ", ")", ";", "v", "->", "uv_groups", "=", "(", "struct", "listaddr", "*", ")", "NULL", ";", "v", "->", "uv_dvmrp_neighbors", "=", "(", "struct", "listaddr", "*", ")", "NULL", ";", "NBRM_CLRALL", "(", "v", "->", "uv_nbrmap", ")", ";", "v", "->", "uv_querier", "=", "(", "struct", "listaddr", "*", ")", "NULL", ";", "v", "->", "uv_igmpv1_warn", "=", "0", ";", "v", "->", "uv_prune_lifetime", "=", "0", ";", "v", "->", "uv_acl", "=", "(", "struct", "vif_acl", "*", ")", "NULL", ";", "RESET_TIMER", "(", "v", "->", "uv_leaf_timer", ")", ";", "v", "->", "uv_addrs", "=", "(", "struct", "phaddr", "*", ")", "NULL", ";", "v", "->", "uv_filter", "=", "(", "struct", "vif_filter", "*", ")", "NULL", ";", "RESET_TIMER", "(", "v", "->", "uv_hello_timer", ")", ";", "v", "->", "uv_dr_prio", "=", "PIM_HELLO_DR_PRIO_DEFAULT", ";", "v", "->", "uv_genid", "=", "0", ";", "RESET_TIMER", "(", "v", "->", "uv_gq_timer", ")", ";", "RESET_TIMER", "(", "v", "->", "uv_jp_timer", ")", ";", "v", "->", "uv_pim_neighbors", "=", "(", "struct", "pim_nbr_entry", "*", ")", "NULL", ";", "v", "->", "uv_local_pref", "=", "default_route_distance", ";", "v", "->", "uv_local_metric", "=", "default_route_metric", ";", "v", "->", "uv_ifindex", "=", "-1", ";", "}" ]
Initialize the passed vif with all appropriate default values.
[ "Initialize", "the", "passed", "vif", "with", "all", "appropriate", "default", "values", "." ]
[ "/* Default to IGMPv3 */" ]
[ { "param": "v", "type": "struct uvif" }, { "param": "t", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v", "type": "struct uvif", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "t", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
init_reg_vif
int
static int init_reg_vif(void) { struct uvif *v; vifi_t i; v = &uvifs[0]; v->uv_flags = 0; v->uv_flags = VIFF_REGISTER; #ifdef PIM_EXPERIMENTAL v->uv_flags |= VIFF_REGISTER_KERNEL_ENCAP; #endif v->uv_threshold = MINTTL; #ifdef __linux__ if (mrt_table_id != 0) snprintf(v->uv_name, sizeof(v->uv_name), "pimreg%u", mrt_table_id); else strlcpy(v->uv_name, "pimreg", sizeof(v->uv_name)); #else strlcpy(v->uv_name, "register_vif0", sizeof(v->uv_name)); #endif /* __linux__ */ /* Use the address of the first available physical interface to * create the register vif. */ for (i = 0; i < numvifs; i++) { if (uvifs[i].uv_flags & (VIFF_DOWN | VIFF_DISABLED | VIFF_REGISTER | VIFF_TUNNEL)) continue; break; } if (i >= numvifs) { logit(LOG_ERR, 0, "No physical interface enabled, cannot create %s", v->uv_name); return -1; } v->uv_ifindex = 0; v->uv_lcl_addr = uvifs[i].uv_lcl_addr; logit(LOG_DEBUG, 0, "VIF #0: Installing %s, using %s with ifaddr %s", v->uv_name, uvifs[i].uv_name, inet_fmt(v->uv_lcl_addr, s1, sizeof(s1))); total_interfaces++; return 0; }
/* * Add a (the) register vif to the vif table. */
Add a (the) register vif to the vif table.
[ "Add", "a", "(", "the", ")", "register", "vif", "to", "the", "vif", "table", "." ]
static int init_reg_vif(void) { struct uvif *v; vifi_t i; v = &uvifs[0]; v->uv_flags = 0; v->uv_flags = VIFF_REGISTER; #ifdef PIM_EXPERIMENTAL v->uv_flags |= VIFF_REGISTER_KERNEL_ENCAP; #endif v->uv_threshold = MINTTL; #ifdef __linux__ if (mrt_table_id != 0) snprintf(v->uv_name, sizeof(v->uv_name), "pimreg%u", mrt_table_id); else strlcpy(v->uv_name, "pimreg", sizeof(v->uv_name)); #else strlcpy(v->uv_name, "register_vif0", sizeof(v->uv_name)); #endif for (i = 0; i < numvifs; i++) { if (uvifs[i].uv_flags & (VIFF_DOWN | VIFF_DISABLED | VIFF_REGISTER | VIFF_TUNNEL)) continue; break; } if (i >= numvifs) { logit(LOG_ERR, 0, "No physical interface enabled, cannot create %s", v->uv_name); return -1; } v->uv_ifindex = 0; v->uv_lcl_addr = uvifs[i].uv_lcl_addr; logit(LOG_DEBUG, 0, "VIF #0: Installing %s, using %s with ifaddr %s", v->uv_name, uvifs[i].uv_name, inet_fmt(v->uv_lcl_addr, s1, sizeof(s1))); total_interfaces++; return 0; }
[ "static", "int", "init_reg_vif", "(", "void", ")", "{", "struct", "uvif", "*", "v", ";", "vifi_t", "i", ";", "v", "=", "&", "uvifs", "[", "0", "]", ";", "v", "->", "uv_flags", "=", "0", ";", "v", "->", "uv_flags", "=", "VIFF_REGISTER", ";", "#ifdef", "PIM_EXPERIMENTAL", "v", "->", "uv_flags", "|=", "VIFF_REGISTER_KERNEL_ENCAP", ";", "#endif", "v", "->", "uv_threshold", "=", "MINTTL", ";", "#ifdef", "__linux__", "if", "(", "mrt_table_id", "!=", "0", ")", "snprintf", "(", "v", "->", "uv_name", ",", "sizeof", "(", "v", "->", "uv_name", ")", ",", "\"", "\"", ",", "mrt_table_id", ")", ";", "else", "strlcpy", "(", "v", "->", "uv_name", ",", "\"", "\"", ",", "sizeof", "(", "v", "->", "uv_name", ")", ")", ";", "#else", "strlcpy", "(", "v", "->", "uv_name", ",", "\"", "\"", ",", "sizeof", "(", "v", "->", "uv_name", ")", ")", ";", "#endif", "for", "(", "i", "=", "0", ";", "i", "<", "numvifs", ";", "i", "++", ")", "{", "if", "(", "uvifs", "[", "i", "]", ".", "uv_flags", "&", "(", "VIFF_DOWN", "|", "VIFF_DISABLED", "|", "VIFF_REGISTER", "|", "VIFF_TUNNEL", ")", ")", "continue", ";", "break", ";", "}", "if", "(", "i", ">=", "numvifs", ")", "{", "logit", "(", "LOG_ERR", ",", "0", ",", "\"", "\"", ",", "v", "->", "uv_name", ")", ";", "return", "-1", ";", "}", "v", "->", "uv_ifindex", "=", "0", ";", "v", "->", "uv_lcl_addr", "=", "uvifs", "[", "i", "]", ".", "uv_lcl_addr", ";", "logit", "(", "LOG_DEBUG", ",", "0", ",", "\"", "\"", ",", "v", "->", "uv_name", ",", "uvifs", "[", "i", "]", ".", "uv_name", ",", "inet_fmt", "(", "v", "->", "uv_lcl_addr", ",", "s1", ",", "sizeof", "(", "s1", ")", ")", ")", ";", "total_interfaces", "++", ";", "return", "0", ";", "}" ]
Add a (the) register vif to the vif table.
[ "Add", "a", "(", "the", ")", "register", "vif", "to", "the", "vif", "table", "." ]
[ "/* __linux__ */", "/* Use the address of the first available physical interface to\n * create the register vif.\n */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
stop_vif
void
static void stop_vif(vifi_t vifi) { struct uvif *v; struct listaddr *a, *b; pim_nbr_entry_t *n, *next; struct vif_acl *acl; /* * TODO: make sure that the kernel viftable is * consistent with the daemon table */ v = &uvifs[vifi]; if (!(v->uv_flags & VIFF_REGISTER)) { k_leave(pim_socket, allpimrouters_group, v); k_leave(igmp_socket, allrouters_group, v); k_leave(igmp_socket, allreports_group, v); /* * Discard all group addresses. (No need to tell kernel; * the k_del_vif() call will clean up kernel state.) */ while (v->uv_groups) { a = v->uv_groups; v->uv_groups = a->al_next; while (a->al_sources) { b = a->al_sources; a->al_sources = b->al_next; free(b); } /* Clear timers, preventing possible memory double free */ if (a->al_timerid) timer_clear(a->al_timerid); if (a->al_versiontimer) timer_clear(a->al_versiontimer); if (a->al_query) timer_clear(a->al_query); free(a); } } if (v->uv_querier) { free(v->uv_querier); v->uv_querier = NULL; } /* * TODO: inform (eventually) the neighbors I am going down by sending * PIM_HELLO with holdtime=0 so someone else should become a DR. */ /* TODO: dummy! Implement it!! Any problems if don't use it? */ delete_vif_from_mrt(vifi); /* Delete the interface from the kernel's vif structure. */ k_del_vif(igmp_socket, vifi, v); v->uv_flags = (v->uv_flags & ~VIFF_DR & ~VIFF_QUERIER & ~VIFF_NONBRS) | VIFF_DOWN; if (!(v->uv_flags & VIFF_REGISTER)) { RESET_TIMER(v->uv_hello_timer); RESET_TIMER(v->uv_jp_timer); RESET_TIMER(v->uv_gq_timer); for (n = v->uv_pim_neighbors; n; n = next) { next = n->next; /* Free the space for each neighbour */ delete_pim_nbr(n); } v->uv_pim_neighbors = NULL; } /* TODO: currently not used */ /* The Access Control List (list with the scoped addresses) */ while (v->uv_acl) { acl = v->uv_acl; v->uv_acl = acl->acl_next; free(acl); } vifs_down = TRUE; logit(LOG_INFO, 0, "Interface %s goes down; VIF #%u out of service", v->uv_name, vifi); }
/* * Stop a vif (either physical interface, tunnel or * register.) If we are running only PIM we don't have tunnels. */
Stop a vif (either physical interface, tunnel or register.) If we are running only PIM we don't have tunnels.
[ "Stop", "a", "vif", "(", "either", "physical", "interface", "tunnel", "or", "register", ".", ")", "If", "we", "are", "running", "only", "PIM", "we", "don", "'", "t", "have", "tunnels", "." ]
static void stop_vif(vifi_t vifi) { struct uvif *v; struct listaddr *a, *b; pim_nbr_entry_t *n, *next; struct vif_acl *acl; v = &uvifs[vifi]; if (!(v->uv_flags & VIFF_REGISTER)) { k_leave(pim_socket, allpimrouters_group, v); k_leave(igmp_socket, allrouters_group, v); k_leave(igmp_socket, allreports_group, v); while (v->uv_groups) { a = v->uv_groups; v->uv_groups = a->al_next; while (a->al_sources) { b = a->al_sources; a->al_sources = b->al_next; free(b); } if (a->al_timerid) timer_clear(a->al_timerid); if (a->al_versiontimer) timer_clear(a->al_versiontimer); if (a->al_query) timer_clear(a->al_query); free(a); } } if (v->uv_querier) { free(v->uv_querier); v->uv_querier = NULL; } delete_vif_from_mrt(vifi); k_del_vif(igmp_socket, vifi, v); v->uv_flags = (v->uv_flags & ~VIFF_DR & ~VIFF_QUERIER & ~VIFF_NONBRS) | VIFF_DOWN; if (!(v->uv_flags & VIFF_REGISTER)) { RESET_TIMER(v->uv_hello_timer); RESET_TIMER(v->uv_jp_timer); RESET_TIMER(v->uv_gq_timer); for (n = v->uv_pim_neighbors; n; n = next) { next = n->next; delete_pim_nbr(n); } v->uv_pim_neighbors = NULL; } while (v->uv_acl) { acl = v->uv_acl; v->uv_acl = acl->acl_next; free(acl); } vifs_down = TRUE; logit(LOG_INFO, 0, "Interface %s goes down; VIF #%u out of service", v->uv_name, vifi); }
[ "static", "void", "stop_vif", "(", "vifi_t", "vifi", ")", "{", "struct", "uvif", "*", "v", ";", "struct", "listaddr", "*", "a", ",", "*", "b", ";", "pim_nbr_entry_t", "*", "n", ",", "*", "next", ";", "struct", "vif_acl", "*", "acl", ";", "v", "=", "&", "uvifs", "[", "vifi", "]", ";", "if", "(", "!", "(", "v", "->", "uv_flags", "&", "VIFF_REGISTER", ")", ")", "{", "k_leave", "(", "pim_socket", ",", "allpimrouters_group", ",", "v", ")", ";", "k_leave", "(", "igmp_socket", ",", "allrouters_group", ",", "v", ")", ";", "k_leave", "(", "igmp_socket", ",", "allreports_group", ",", "v", ")", ";", "while", "(", "v", "->", "uv_groups", ")", "{", "a", "=", "v", "->", "uv_groups", ";", "v", "->", "uv_groups", "=", "a", "->", "al_next", ";", "while", "(", "a", "->", "al_sources", ")", "{", "b", "=", "a", "->", "al_sources", ";", "a", "->", "al_sources", "=", "b", "->", "al_next", ";", "free", "(", "b", ")", ";", "}", "if", "(", "a", "->", "al_timerid", ")", "timer_clear", "(", "a", "->", "al_timerid", ")", ";", "if", "(", "a", "->", "al_versiontimer", ")", "timer_clear", "(", "a", "->", "al_versiontimer", ")", ";", "if", "(", "a", "->", "al_query", ")", "timer_clear", "(", "a", "->", "al_query", ")", ";", "free", "(", "a", ")", ";", "}", "}", "if", "(", "v", "->", "uv_querier", ")", "{", "free", "(", "v", "->", "uv_querier", ")", ";", "v", "->", "uv_querier", "=", "NULL", ";", "}", "delete_vif_from_mrt", "(", "vifi", ")", ";", "k_del_vif", "(", "igmp_socket", ",", "vifi", ",", "v", ")", ";", "v", "->", "uv_flags", "=", "(", "v", "->", "uv_flags", "&", "~", "VIFF_DR", "&", "~", "VIFF_QUERIER", "&", "~", "VIFF_NONBRS", ")", "|", "VIFF_DOWN", ";", "if", "(", "!", "(", "v", "->", "uv_flags", "&", "VIFF_REGISTER", ")", ")", "{", "RESET_TIMER", "(", "v", "->", "uv_hello_timer", ")", ";", "RESET_TIMER", "(", "v", "->", "uv_jp_timer", ")", ";", "RESET_TIMER", "(", "v", "->", "uv_gq_timer", ")", ";", "for", "(", "n", "=", "v", "->", "uv_pim_neighbors", ";", "n", ";", "n", "=", "next", ")", "{", "next", "=", "n", "->", "next", ";", "delete_pim_nbr", "(", "n", ")", ";", "}", "v", "->", "uv_pim_neighbors", "=", "NULL", ";", "}", "while", "(", "v", "->", "uv_acl", ")", "{", "acl", "=", "v", "->", "uv_acl", ";", "v", "->", "uv_acl", "=", "acl", "->", "acl_next", ";", "free", "(", "acl", ")", ";", "}", "vifs_down", "=", "TRUE", ";", "logit", "(", "LOG_INFO", ",", "0", ",", "\"", "\"", ",", "v", "->", "uv_name", ",", "vifi", ")", ";", "}" ]
Stop a vif (either physical interface, tunnel or register.)
[ "Stop", "a", "vif", "(", "either", "physical", "interface", "tunnel", "or", "register", ".", ")" ]
[ "/*\n * TODO: make sure that the kernel viftable is\n * consistent with the daemon table\n */", "/*\n\t * Discard all group addresses. (No need to tell kernel;\n\t * the k_del_vif() call will clean up kernel state.)\n\t */", "/* Clear timers, preventing possible memory double free */", "/*\n * TODO: inform (eventually) the neighbors I am going down by sending\n * PIM_HELLO with holdtime=0 so someone else should become a DR.\n */", "/* TODO: dummy! Implement it!! Any problems if don't use it? */", "/* Delete the interface from the kernel's vif structure. */", "/* Free the space for each neighbour */", "/* TODO: currently not used */", "/* The Access Control List (list with the scoped addresses) */" ]
[ { "param": "vifi", "type": "vifi_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vifi", "type": "vifi_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
update_reg_vif
int
static int update_reg_vif(vifi_t register_vifi) { struct uvif *v; vifi_t vifi; /* Find the first useable vif with solid physical background */ for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; /* Found. Stop the bogus Register vif first */ stop_vif(register_vifi); uvifs[register_vifi].uv_lcl_addr = uvifs[vifi].uv_lcl_addr; start_vif(register_vifi); IF_DEBUG(DEBUG_PIM_REGISTER | DEBUG_IF) { logit(LOG_NOTICE, 0, "Interface %s has come up; VIF #%u now in service", uvifs[register_vifi].uv_name, register_vifi); } return 0; } vifs_down = TRUE; logit(LOG_WARNING, 0, "Cannot start Register VIF: %s", uvifs[vifi].uv_name); return -1; }
/* * Update the register vif in the multicast routing daemon and the * kernel because the interface used initially to get its local address * is DOWN. register_vifi is the index to the Register vif which needs * to be updated. As a result the Register vif has a new uv_lcl_addr and * is UP (virtually :)) */
Update the register vif in the multicast routing daemon and the kernel because the interface used initially to get its local address is DOWN. register_vifi is the index to the Register vif which needs to be updated. As a result the Register vif has a new uv_lcl_addr and is UP (virtually :))
[ "Update", "the", "register", "vif", "in", "the", "multicast", "routing", "daemon", "and", "the", "kernel", "because", "the", "interface", "used", "initially", "to", "get", "its", "local", "address", "is", "DOWN", ".", "register_vifi", "is", "the", "index", "to", "the", "Register", "vif", "which", "needs", "to", "be", "updated", ".", "As", "a", "result", "the", "Register", "vif", "has", "a", "new", "uv_lcl_addr", "and", "is", "UP", "(", "virtually", ":", "))" ]
static int update_reg_vif(vifi_t register_vifi) { struct uvif *v; vifi_t vifi; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; stop_vif(register_vifi); uvifs[register_vifi].uv_lcl_addr = uvifs[vifi].uv_lcl_addr; start_vif(register_vifi); IF_DEBUG(DEBUG_PIM_REGISTER | DEBUG_IF) { logit(LOG_NOTICE, 0, "Interface %s has come up; VIF #%u now in service", uvifs[register_vifi].uv_name, register_vifi); } return 0; } vifs_down = TRUE; logit(LOG_WARNING, 0, "Cannot start Register VIF: %s", uvifs[vifi].uv_name); return -1; }
[ "static", "int", "update_reg_vif", "(", "vifi_t", "register_vifi", ")", "{", "struct", "uvif", "*", "v", ";", "vifi_t", "vifi", ";", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "if", "(", "v", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_DOWN", "|", "VIFF_REGISTER", "|", "VIFF_TUNNEL", ")", ")", "continue", ";", "stop_vif", "(", "register_vifi", ")", ";", "uvifs", "[", "register_vifi", "]", ".", "uv_lcl_addr", "=", "uvifs", "[", "vifi", "]", ".", "uv_lcl_addr", ";", "start_vif", "(", "register_vifi", ")", ";", "IF_DEBUG", "(", "DEBUG_PIM_REGISTER", "|", "DEBUG_IF", ")", "", "{", "logit", "(", "LOG_NOTICE", ",", "0", ",", "\"", "\"", ",", "uvifs", "[", "register_vifi", "]", ".", "uv_name", ",", "register_vifi", ")", ";", "}", "return", "0", ";", "}", "vifs_down", "=", "TRUE", ";", "logit", "(", "LOG_WARNING", ",", "0", ",", "\"", "\"", ",", "uvifs", "[", "vifi", "]", ".", "uv_name", ")", ";", "return", "-1", ";", "}" ]
Update the register vif in the multicast routing daemon and the kernel because the interface used initially to get its local address is DOWN.
[ "Update", "the", "register", "vif", "in", "the", "multicast", "routing", "daemon", "and", "the", "kernel", "because", "the", "interface", "used", "initially", "to", "get", "its", "local", "address", "is", "DOWN", "." ]
[ "/* Find the first useable vif with solid physical background */", "/* Found. Stop the bogus Register vif first */" ]
[ { "param": "register_vifi", "type": "vifi_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "register_vifi", "type": "vifi_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
check_vif_state
void
void check_vif_state(void) { vifi_t vifi; struct uvif *v; struct ifreq ifr; static int checking_vifs = 0; /* * XXX: TODO: True only for DVMRP?? Check. * If we get an error while checking, (e.g. two interfaces go down * at once, and we decide to send a prune out one of the failed ones) * then don't go into an infinite loop! */ if (checking_vifs) return; vifs_down = FALSE; checking_vifs = 1; /* TODO: Check all potential interfaces!!! */ /* Check the physical and tunnels only */ for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_REGISTER)) continue; /* get the interface flags */ strlcpy(ifr.ifr_name, v->uv_name, sizeof(ifr.ifr_name)); if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0) { if (errno == ENODEV) { logit(LOG_NOTICE, 0, "Interface %s has gone; VIF #%u taken out of service", v->uv_name, vifi); stop_vif(vifi); vifs_down = TRUE; continue; } logit(LOG_ERR, errno, "%s(): ioctl SIOCGIFFLAGS for %s", __func__, ifr.ifr_name); } if (v->uv_flags & VIFF_DOWN) { if (ifr.ifr_flags & IFF_UP) start_vif(vifi); else vifs_down = TRUE; } else { if (!(ifr.ifr_flags & IFF_UP)) { logit(LOG_NOTICE, 0, "Interface %s has gone down; VIF #%u taken out of service", v->uv_name, vifi); stop_vif(vifi); vifs_down = TRUE; } } } /* Check the register(s) vif(s) */ for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { vifi_t vifi2; struct uvif *v2; int found; if (!(v->uv_flags & VIFF_REGISTER)) continue; found = 0; /* Find a physical vif with the same IP address as the * Register vif. */ for (vifi2 = 0, v2 = uvifs; vifi2 < numvifs; ++vifi2, ++v2) { if (v2->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; if (v->uv_lcl_addr != v2->uv_lcl_addr) continue; found = 1; break; } /* The physical interface with the IP address as the Register * vif is probably DOWN. Get a replacement. */ if (!found) update_reg_vif(vifi); } checking_vifs = 0; }
/* * See if any interfaces have changed from up state to down, or vice versa, * including any non-multicast-capable interfaces that are in use as local * tunnel end-points. Ignore interfaces that have been administratively * disabled. */
See if any interfaces have changed from up state to down, or vice versa, including any non-multicast-capable interfaces that are in use as local tunnel end-points. Ignore interfaces that have been administratively disabled.
[ "See", "if", "any", "interfaces", "have", "changed", "from", "up", "state", "to", "down", "or", "vice", "versa", "including", "any", "non", "-", "multicast", "-", "capable", "interfaces", "that", "are", "in", "use", "as", "local", "tunnel", "end", "-", "points", ".", "Ignore", "interfaces", "that", "have", "been", "administratively", "disabled", "." ]
void check_vif_state(void) { vifi_t vifi; struct uvif *v; struct ifreq ifr; static int checking_vifs = 0; if (checking_vifs) return; vifs_down = FALSE; checking_vifs = 1; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_REGISTER)) continue; strlcpy(ifr.ifr_name, v->uv_name, sizeof(ifr.ifr_name)); if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0) { if (errno == ENODEV) { logit(LOG_NOTICE, 0, "Interface %s has gone; VIF #%u taken out of service", v->uv_name, vifi); stop_vif(vifi); vifs_down = TRUE; continue; } logit(LOG_ERR, errno, "%s(): ioctl SIOCGIFFLAGS for %s", __func__, ifr.ifr_name); } if (v->uv_flags & VIFF_DOWN) { if (ifr.ifr_flags & IFF_UP) start_vif(vifi); else vifs_down = TRUE; } else { if (!(ifr.ifr_flags & IFF_UP)) { logit(LOG_NOTICE, 0, "Interface %s has gone down; VIF #%u taken out of service", v->uv_name, vifi); stop_vif(vifi); vifs_down = TRUE; } } } for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { vifi_t vifi2; struct uvif *v2; int found; if (!(v->uv_flags & VIFF_REGISTER)) continue; found = 0; for (vifi2 = 0, v2 = uvifs; vifi2 < numvifs; ++vifi2, ++v2) { if (v2->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; if (v->uv_lcl_addr != v2->uv_lcl_addr) continue; found = 1; break; } if (!found) update_reg_vif(vifi); } checking_vifs = 0; }
[ "void", "check_vif_state", "(", "void", ")", "{", "vifi_t", "vifi", ";", "struct", "uvif", "*", "v", ";", "struct", "ifreq", "ifr", ";", "static", "int", "checking_vifs", "=", "0", ";", "if", "(", "checking_vifs", ")", "return", ";", "vifs_down", "=", "FALSE", ";", "checking_vifs", "=", "1", ";", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "if", "(", "v", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_REGISTER", ")", ")", "continue", ";", "strlcpy", "(", "ifr", ".", "ifr_name", ",", "v", "->", "uv_name", ",", "sizeof", "(", "ifr", ".", "ifr_name", ")", ")", ";", "if", "(", "ioctl", "(", "udp_socket", ",", "SIOCGIFFLAGS", ",", "(", "char", "*", ")", "&", "ifr", ")", "<", "0", ")", "{", "if", "(", "errno", "==", "ENODEV", ")", "{", "logit", "(", "LOG_NOTICE", ",", "0", ",", "\"", "\"", ",", "v", "->", "uv_name", ",", "vifi", ")", ";", "stop_vif", "(", "vifi", ")", ";", "vifs_down", "=", "TRUE", ";", "continue", ";", "}", "logit", "(", "LOG_ERR", ",", "errno", ",", "\"", "\"", ",", "__func__", ",", "ifr", ".", "ifr_name", ")", ";", "}", "if", "(", "v", "->", "uv_flags", "&", "VIFF_DOWN", ")", "{", "if", "(", "ifr", ".", "ifr_flags", "&", "IFF_UP", ")", "start_vif", "(", "vifi", ")", ";", "else", "vifs_down", "=", "TRUE", ";", "}", "else", "{", "if", "(", "!", "(", "ifr", ".", "ifr_flags", "&", "IFF_UP", ")", ")", "{", "logit", "(", "LOG_NOTICE", ",", "0", ",", "\"", "\"", ",", "v", "->", "uv_name", ",", "vifi", ")", ";", "stop_vif", "(", "vifi", ")", ";", "vifs_down", "=", "TRUE", ";", "}", "}", "}", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "vifi_t", "vifi2", ";", "struct", "uvif", "*", "v2", ";", "int", "found", ";", "if", "(", "!", "(", "v", "->", "uv_flags", "&", "VIFF_REGISTER", ")", ")", "continue", ";", "found", "=", "0", ";", "for", "(", "vifi2", "=", "0", ",", "v2", "=", "uvifs", ";", "vifi2", "<", "numvifs", ";", "++", "vifi2", ",", "++", "v2", ")", "{", "if", "(", "v2", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_DOWN", "|", "VIFF_REGISTER", "|", "VIFF_TUNNEL", ")", ")", "continue", ";", "if", "(", "v", "->", "uv_lcl_addr", "!=", "v2", "->", "uv_lcl_addr", ")", "continue", ";", "found", "=", "1", ";", "break", ";", "}", "if", "(", "!", "found", ")", "update_reg_vif", "(", "vifi", ")", ";", "}", "checking_vifs", "=", "0", ";", "}" ]
See if any interfaces have changed from up state to down, or vice versa, including any non-multicast-capable interfaces that are in use as local tunnel end-points.
[ "See", "if", "any", "interfaces", "have", "changed", "from", "up", "state", "to", "down", "or", "vice", "versa", "including", "any", "non", "-", "multicast", "-", "capable", "interfaces", "that", "are", "in", "use", "as", "local", "tunnel", "end", "-", "points", "." ]
[ "/*\n * XXX: TODO: True only for DVMRP?? Check.\n * If we get an error while checking, (e.g. two interfaces go down\n * at once, and we decide to send a prune out one of the failed ones)\n * then don't go into an infinite loop!\n */", "/* TODO: Check all potential interfaces!!! */", "/* Check the physical and tunnels only */", "/* get the interface flags */", "/* Check the register(s) vif(s) */", "/* Find a physical vif with the same IP address as the\n\t * Register vif. */", "/* The physical interface with the IP address as the Register\n\t * vif is probably DOWN. Get a replacement. */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
find_vif_direct
vifi_t
vifi_t find_vif_direct(uint32_t src) { vifi_t vifi; struct uvif *v; struct phaddr *p; struct rpfctl rpf; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; if (src == v->uv_lcl_addr) return NO_VIF; /* src is one of our IP addresses */ if (is_uv_subnet(src, v)) return vifi; /* Check the extra subnets for this vif */ /* TODO: don't think currently pimd can handle extra subnets */ for (p = v->uv_addrs; p; p = p->pa_next) { if (is_pa_subnet(src, v)) return vifi; } /* POINTOPOINT but not VIFF_TUNNEL interface (e.g., GRE) */ if ((v->uv_flags & VIFF_POINT_TO_POINT) && (src == v->uv_rmt_addr)) return vifi; } /* Check if the routing table has a direct route (no gateway). */ if (k_req_incoming(src, &rpf)) { if (rpf.source.s_addr == rpf.rpfneighbor.s_addr) { return rpf.iif; } } return NO_VIF; }
/* * If the source is directly connected to us, find the vif number for * the corresponding physical interface (Register and tunnels excluded). * Local addresses are excluded. * Return the vif number or NO_VIF if not found. */
If the source is directly connected to us, find the vif number for the corresponding physical interface (Register and tunnels excluded). Local addresses are excluded. Return the vif number or NO_VIF if not found.
[ "If", "the", "source", "is", "directly", "connected", "to", "us", "find", "the", "vif", "number", "for", "the", "corresponding", "physical", "interface", "(", "Register", "and", "tunnels", "excluded", ")", ".", "Local", "addresses", "are", "excluded", ".", "Return", "the", "vif", "number", "or", "NO_VIF", "if", "not", "found", "." ]
vifi_t find_vif_direct(uint32_t src) { vifi_t vifi; struct uvif *v; struct phaddr *p; struct rpfctl rpf; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; if (src == v->uv_lcl_addr) return NO_VIF; if (is_uv_subnet(src, v)) return vifi; for (p = v->uv_addrs; p; p = p->pa_next) { if (is_pa_subnet(src, v)) return vifi; } if ((v->uv_flags & VIFF_POINT_TO_POINT) && (src == v->uv_rmt_addr)) return vifi; } if (k_req_incoming(src, &rpf)) { if (rpf.source.s_addr == rpf.rpfneighbor.s_addr) { return rpf.iif; } } return NO_VIF; }
[ "vifi_t", "find_vif_direct", "(", "uint32_t", "src", ")", "{", "vifi_t", "vifi", ";", "struct", "uvif", "*", "v", ";", "struct", "phaddr", "*", "p", ";", "struct", "rpfctl", "rpf", ";", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "if", "(", "v", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_DOWN", "|", "VIFF_REGISTER", "|", "VIFF_TUNNEL", ")", ")", "continue", ";", "if", "(", "src", "==", "v", "->", "uv_lcl_addr", ")", "return", "NO_VIF", ";", "if", "(", "is_uv_subnet", "(", "src", ",", "v", ")", ")", "return", "vifi", ";", "for", "(", "p", "=", "v", "->", "uv_addrs", ";", "p", ";", "p", "=", "p", "->", "pa_next", ")", "{", "if", "(", "is_pa_subnet", "(", "src", ",", "v", ")", ")", "return", "vifi", ";", "}", "if", "(", "(", "v", "->", "uv_flags", "&", "VIFF_POINT_TO_POINT", ")", "&&", "(", "src", "==", "v", "->", "uv_rmt_addr", ")", ")", "return", "vifi", ";", "}", "if", "(", "k_req_incoming", "(", "src", ",", "&", "rpf", ")", ")", "{", "if", "(", "rpf", ".", "source", ".", "s_addr", "==", "rpf", ".", "rpfneighbor", ".", "s_addr", ")", "{", "return", "rpf", ".", "iif", ";", "}", "}", "return", "NO_VIF", ";", "}" ]
If the source is directly connected to us, find the vif number for the corresponding physical interface (Register and tunnels excluded).
[ "If", "the", "source", "is", "directly", "connected", "to", "us", "find", "the", "vif", "number", "for", "the", "corresponding", "physical", "interface", "(", "Register", "and", "tunnels", "excluded", ")", "." ]
[ "/* src is one of our IP addresses */", "/* Check the extra subnets for this vif */", "/* TODO: don't think currently pimd can handle extra subnets */", "/* POINTOPOINT but not VIFF_TUNNEL interface (e.g., GRE) */", "/* Check if the routing table has a direct route (no gateway). */" ]
[ { "param": "src", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "src", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
local_address
vifi_t
vifi_t local_address(uint32_t src) { vifi_t vifi; struct uvif *v; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { /* TODO: XXX: what about VIFF_TUNNEL? */ if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER)) continue; if (src == v->uv_lcl_addr) return vifi; } /* Returning NO_VIF means not a local address */ return NO_VIF; }
/* * Checks if src is local address. If "yes" return the vif index, * otherwise return value is NO_VIF. */
Checks if src is local address. If "yes" return the vif index, otherwise return value is NO_VIF.
[ "Checks", "if", "src", "is", "local", "address", ".", "If", "\"", "yes", "\"", "return", "the", "vif", "index", "otherwise", "return", "value", "is", "NO_VIF", "." ]
vifi_t local_address(uint32_t src) { vifi_t vifi; struct uvif *v; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER)) continue; if (src == v->uv_lcl_addr) return vifi; } return NO_VIF; }
[ "vifi_t", "local_address", "(", "uint32_t", "src", ")", "{", "vifi_t", "vifi", ";", "struct", "uvif", "*", "v", ";", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "if", "(", "v", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_DOWN", "|", "VIFF_REGISTER", ")", ")", "continue", ";", "if", "(", "src", "==", "v", "->", "uv_lcl_addr", ")", "return", "vifi", ";", "}", "return", "NO_VIF", ";", "}" ]
Checks if src is local address.
[ "Checks", "if", "src", "is", "local", "address", "." ]
[ "/* TODO: XXX: what about VIFF_TUNNEL? */", "/* Returning NO_VIF means not a local address */" ]
[ { "param": "src", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "src", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
find_vif_direct_local
vifi_t
vifi_t find_vif_direct_local(uint32_t src) { vifi_t vifi; struct uvif *v; struct phaddr *p; struct rpfctl rpf; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { /* TODO: XXX: what about VIFF_TUNNEL? */ if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; if (src == v->uv_lcl_addr) return vifi; /* src is one of our IP addresses */ if (is_uv_subnet(src, v)) return vifi; /* Check the extra subnets for this vif */ /* TODO: don't think currently pimd can handle extra subnets */ for (p = v->uv_addrs; p; p = p->pa_next) { if (is_pa_subnet(src, v)) return vifi; } /* POINTOPOINT but not VIFF_TUNNEL interface (e.g., GRE) */ if ((v->uv_flags & VIFF_POINT_TO_POINT) && (src == v->uv_rmt_addr)) return vifi; } /* Check if the routing table has a direct route (no gateway). */ if (k_req_incoming(src, &rpf)) { if (rpf.source.s_addr == rpf.rpfneighbor.s_addr) { return rpf.iif; } } return NO_VIF; }
/* * If the source is directly connected, or is local address, * find the vif number for the corresponding physical interface * (Register and tunnels excluded). * Return the vif number or NO_VIF if not found. */
If the source is directly connected, or is local address, find the vif number for the corresponding physical interface (Register and tunnels excluded). Return the vif number or NO_VIF if not found.
[ "If", "the", "source", "is", "directly", "connected", "or", "is", "local", "address", "find", "the", "vif", "number", "for", "the", "corresponding", "physical", "interface", "(", "Register", "and", "tunnels", "excluded", ")", ".", "Return", "the", "vif", "number", "or", "NO_VIF", "if", "not", "found", "." ]
vifi_t find_vif_direct_local(uint32_t src) { vifi_t vifi; struct uvif *v; struct phaddr *p; struct rpfctl rpf; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER | VIFF_TUNNEL)) continue; if (src == v->uv_lcl_addr) return vifi; if (is_uv_subnet(src, v)) return vifi; for (p = v->uv_addrs; p; p = p->pa_next) { if (is_pa_subnet(src, v)) return vifi; } if ((v->uv_flags & VIFF_POINT_TO_POINT) && (src == v->uv_rmt_addr)) return vifi; } if (k_req_incoming(src, &rpf)) { if (rpf.source.s_addr == rpf.rpfneighbor.s_addr) { return rpf.iif; } } return NO_VIF; }
[ "vifi_t", "find_vif_direct_local", "(", "uint32_t", "src", ")", "{", "vifi_t", "vifi", ";", "struct", "uvif", "*", "v", ";", "struct", "phaddr", "*", "p", ";", "struct", "rpfctl", "rpf", ";", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "if", "(", "v", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_DOWN", "|", "VIFF_REGISTER", "|", "VIFF_TUNNEL", ")", ")", "continue", ";", "if", "(", "src", "==", "v", "->", "uv_lcl_addr", ")", "return", "vifi", ";", "if", "(", "is_uv_subnet", "(", "src", ",", "v", ")", ")", "return", "vifi", ";", "for", "(", "p", "=", "v", "->", "uv_addrs", ";", "p", ";", "p", "=", "p", "->", "pa_next", ")", "{", "if", "(", "is_pa_subnet", "(", "src", ",", "v", ")", ")", "return", "vifi", ";", "}", "if", "(", "(", "v", "->", "uv_flags", "&", "VIFF_POINT_TO_POINT", ")", "&&", "(", "src", "==", "v", "->", "uv_rmt_addr", ")", ")", "return", "vifi", ";", "}", "if", "(", "k_req_incoming", "(", "src", ",", "&", "rpf", ")", ")", "{", "if", "(", "rpf", ".", "source", ".", "s_addr", "==", "rpf", ".", "rpfneighbor", ".", "s_addr", ")", "{", "return", "rpf", ".", "iif", ";", "}", "}", "return", "NO_VIF", ";", "}" ]
If the source is directly connected, or is local address, find the vif number for the corresponding physical interface (Register and tunnels excluded).
[ "If", "the", "source", "is", "directly", "connected", "or", "is", "local", "address", "find", "the", "vif", "number", "for", "the", "corresponding", "physical", "interface", "(", "Register", "and", "tunnels", "excluded", ")", "." ]
[ "/* TODO: XXX: what about VIFF_TUNNEL? */", "/* src is one of our IP addresses */", "/* Check the extra subnets for this vif */", "/* TODO: don't think currently pimd can handle extra subnets */", "/* POINTOPOINT but not VIFF_TUNNEL interface (e.g., GRE) */", "/* Check if the routing table has a direct route (no gateway). */" ]
[ { "param": "src", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "src", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9dd08ac9ef18435ef5cdc8f2b69494ca8699a84b
troglobit/pimd
src/vif.c
[ "BSD-3-Clause" ]
C
max_local_address
uint32_t
uint32_t max_local_address(void) { vifi_t vifi; struct uvif *v; uint32_t max_address = 0; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { /* Count vif if not DISABLED or DOWN */ /* TODO: XXX: What about VIFF_TUNNEL? */ if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER)) continue; if (ntohl(v->uv_lcl_addr) > ntohl(max_address)) max_address = v->uv_lcl_addr; } return max_address; }
/* * Returns the highest address of local vif that is UP and ENABLED. * The VIFF_REGISTER interface(s) is/are excluded. */
Returns the highest address of local vif that is UP and ENABLED. The VIFF_REGISTER interface(s) is/are excluded.
[ "Returns", "the", "highest", "address", "of", "local", "vif", "that", "is", "UP", "and", "ENABLED", ".", "The", "VIFF_REGISTER", "interface", "(", "s", ")", "is", "/", "are", "excluded", "." ]
uint32_t max_local_address(void) { vifi_t vifi; struct uvif *v; uint32_t max_address = 0; for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | VIFF_REGISTER)) continue; if (ntohl(v->uv_lcl_addr) > ntohl(max_address)) max_address = v->uv_lcl_addr; } return max_address; }
[ "uint32_t", "max_local_address", "(", "void", ")", "{", "vifi_t", "vifi", ";", "struct", "uvif", "*", "v", ";", "uint32_t", "max_address", "=", "0", ";", "for", "(", "vifi", "=", "0", ",", "v", "=", "uvifs", ";", "vifi", "<", "numvifs", ";", "++", "vifi", ",", "++", "v", ")", "{", "if", "(", "v", "->", "uv_flags", "&", "(", "VIFF_DISABLED", "|", "VIFF_DOWN", "|", "VIFF_REGISTER", ")", ")", "continue", ";", "if", "(", "ntohl", "(", "v", "->", "uv_lcl_addr", ")", ">", "ntohl", "(", "max_address", ")", ")", "max_address", "=", "v", "->", "uv_lcl_addr", ";", "}", "return", "max_address", ";", "}" ]
Returns the highest address of local vif that is UP and ENABLED.
[ "Returns", "the", "highest", "address", "of", "local", "vif", "that", "is", "UP", "and", "ENABLED", "." ]
[ "/* Count vif if not DISABLED or DOWN */", "/* TODO: XXX: What about VIFF_TUNNEL? */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
0a1d978a0a21f5bc3499dfed312974eacaa1971a
troglobit/pimd
src/vif.h
[ "BSD-3-Clause" ]
C
PIMD_VIFM_LASTHOP_ROUTER
int
inline static int PIMD_VIFM_LASTHOP_ROUTER(uint8_t *leaves, uint8_t *oifs) { int i; for (i = 0; i < MAXVIFS; i++) { if (leaves[i] && oifs[i]) return 1; } return 0; }
/* Check with any oifs whether I am the last hop on some LAN */
Check with any oifs whether I am the last hop on some LAN
[ "Check", "with", "any", "oifs", "whether", "I", "am", "the", "last", "hop", "on", "some", "LAN" ]
inline static int PIMD_VIFM_LASTHOP_ROUTER(uint8_t *leaves, uint8_t *oifs) { int i; for (i = 0; i < MAXVIFS; i++) { if (leaves[i] && oifs[i]) return 1; } return 0; }
[ "inline", "static", "int", "PIMD_VIFM_LASTHOP_ROUTER", "(", "uint8_t", "*", "leaves", ",", "uint8_t", "*", "oifs", ")", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "MAXVIFS", ";", "i", "++", ")", "{", "if", "(", "leaves", "[", "i", "]", "&&", "oifs", "[", "i", "]", ")", "return", "1", ";", "}", "return", "0", ";", "}" ]
Check with any oifs whether I am the last hop on some LAN
[ "Check", "with", "any", "oifs", "whether", "I", "am", "the", "last", "hop", "on", "some", "LAN" ]
[]
[ { "param": "leaves", "type": "uint8_t" }, { "param": "oifs", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "leaves", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "oifs", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3625a2deffc6fcbf3dafdc5d3f0773ea9c4dfdef
suikan4github/stm32-defects
d005-nucleo-l152-i2c/Src/stm32l1xx_hal_msp.c
[ "MIT" ]
C
HAL_MspInit
void
void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ __HAL_RCC_COMP_CLK_ENABLE(); __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); /* System interrupt init*/ /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ }
/* USER CODE END 0 */ /** * Initializes the Global MSP. */
USER CODE END 0 Initializes the Global MSP.
[ "USER", "CODE", "END", "0", "Initializes", "the", "Global", "MSP", "." ]
void HAL_MspInit(void) { __HAL_RCC_COMP_CLK_ENABLE(); __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); }
[ "void", "HAL_MspInit", "(", "void", ")", "{", "__HAL_RCC_COMP_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_SYSCFG_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_PWR_CLK_ENABLE", "(", ")", ";", "HAL_NVIC_SetPriorityGrouping", "(", "NVIC_PRIORITYGROUP_0", ")", ";", "}" ]
USER CODE END 0 Initializes the Global MSP.
[ "USER", "CODE", "END", "0", "Initializes", "the", "Global", "MSP", "." ]
[ "/* USER CODE BEGIN MspInit 0 */", "/* USER CODE END MspInit 0 */", "/* System interrupt init*/", "/* USER CODE BEGIN MspInit 1 */", "/* USER CODE END MspInit 1 */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
2049c7431687a890b452f1bf3ea4a9da85fdefed
suikan4github/stm32-defects
d010-nucleo-h743-di2s/Core/Src/main.c
[ "MIT" ]
C
SystemClock_Config
void
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; /** Supply configuration update enable */ HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 1; RCC_OscInitStruct.PLL.PLLN = 24; RCC_OscInitStruct.PLL.PLLP = 2; RCC_OscInitStruct.PLL.PLLQ = 4; RCC_OscInitStruct.PLL.PLLR = 2; RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3; RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; RCC_OscInitStruct.PLL.PLLFRACN = 0; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1; RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_SPI1 |RCC_PERIPHCLK_SPI2|RCC_PERIPHCLK_USB; PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } /** Enable USB Voltage detector */ HAL_PWREx_EnableUSBVoltageDetector(); }
/** * @brief System Clock Configuration * @retval None */
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 1; RCC_OscInitStruct.PLL.PLLN = 24; RCC_OscInitStruct.PLL.PLLP = 2; RCC_OscInitStruct.PLL.PLLQ = 4; RCC_OscInitStruct.PLL.PLLR = 2; RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3; RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; RCC_OscInitStruct.PLL.PLLFRACN = 0; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1; RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_SPI1 |RCC_PERIPHCLK_SPI2|RCC_PERIPHCLK_USB; PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } HAL_PWREx_EnableUSBVoltageDetector(); }
[ "void", "SystemClock_Config", "(", "void", ")", "{", "RCC_OscInitTypeDef", "RCC_OscInitStruct", "=", "{", "0", "}", ";", "RCC_ClkInitTypeDef", "RCC_ClkInitStruct", "=", "{", "0", "}", ";", "RCC_PeriphCLKInitTypeDef", "PeriphClkInitStruct", "=", "{", "0", "}", ";", "HAL_PWREx_ConfigSupply", "(", "PWR_LDO_SUPPLY", ")", ";", "__HAL_PWR_VOLTAGESCALING_CONFIG", "(", "PWR_REGULATOR_VOLTAGE_SCALE1", ")", ";", "while", "(", "!", "__HAL_PWR_GET_FLAG", "(", "PWR_FLAG_VOSRDY", ")", ")", "{", "}", "RCC_OscInitStruct", ".", "OscillatorType", "=", "RCC_OSCILLATORTYPE_HSE", ";", "RCC_OscInitStruct", ".", "HSEState", "=", "RCC_HSE_BYPASS", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLState", "=", "RCC_PLL_ON", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLSource", "=", "RCC_PLLSOURCE_HSE", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLM", "=", "1", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLN", "=", "24", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLP", "=", "2", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLQ", "=", "4", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLR", "=", "2", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLRGE", "=", "RCC_PLL1VCIRANGE_3", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLVCOSEL", "=", "RCC_PLL1VCOWIDE", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLFRACN", "=", "0", ";", "if", "(", "HAL_RCC_OscConfig", "(", "&", "RCC_OscInitStruct", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "RCC_ClkInitStruct", ".", "ClockType", "=", "RCC_CLOCKTYPE_HCLK", "|", "RCC_CLOCKTYPE_SYSCLK", "|", "RCC_CLOCKTYPE_PCLK1", "|", "RCC_CLOCKTYPE_PCLK2", "|", "RCC_CLOCKTYPE_D3PCLK1", "|", "RCC_CLOCKTYPE_D1PCLK1", ";", "RCC_ClkInitStruct", ".", "SYSCLKSource", "=", "RCC_SYSCLKSOURCE_PLLCLK", ";", "RCC_ClkInitStruct", ".", "SYSCLKDivider", "=", "RCC_SYSCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "AHBCLKDivider", "=", "RCC_HCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB3CLKDivider", "=", "RCC_APB3_DIV1", ";", "RCC_ClkInitStruct", ".", "APB1CLKDivider", "=", "RCC_APB1_DIV1", ";", "RCC_ClkInitStruct", ".", "APB2CLKDivider", "=", "RCC_APB2_DIV1", ";", "RCC_ClkInitStruct", ".", "APB4CLKDivider", "=", "RCC_APB4_DIV1", ";", "if", "(", "HAL_RCC_ClockConfig", "(", "&", "RCC_ClkInitStruct", ",", "FLASH_LATENCY_1", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "PeriphClkInitStruct", ".", "PeriphClockSelection", "=", "RCC_PERIPHCLK_USART3", "|", "RCC_PERIPHCLK_SPI1", "|", "RCC_PERIPHCLK_SPI2", "|", "RCC_PERIPHCLK_USB", ";", "PeriphClkInitStruct", ".", "Spi123ClockSelection", "=", "RCC_SPI123CLKSOURCE_PLL", ";", "PeriphClkInitStruct", ".", "Usart234578ClockSelection", "=", "RCC_USART234578CLKSOURCE_D2PCLK1", ";", "PeriphClkInitStruct", ".", "UsbClockSelection", "=", "RCC_USBCLKSOURCE_PLL", ";", "if", "(", "HAL_RCCEx_PeriphCLKConfig", "(", "&", "PeriphClkInitStruct", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "HAL_PWREx_EnableUSBVoltageDetector", "(", ")", ";", "}" ]
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
[ "/** Supply configuration update enable\r\n */", "/** Configure the main internal regulator output voltage\r\n */", "/** Initializes the RCC Oscillators according to the specified parameters\r\n * in the RCC_OscInitTypeDef structure.\r\n */", "/** Initializes the CPU, AHB and APB buses clocks\r\n */", "/** Enable USB Voltage detector\r\n */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
2049c7431687a890b452f1bf3ea4a9da85fdefed
suikan4github/stm32-defects
d010-nucleo-h743-di2s/Core/Src/main.c
[ "MIT" ]
C
MX_I2S1_Init
void
static void MX_I2S1_Init(void) { /* USER CODE BEGIN I2S1_Init 0 */ /* USER CODE END I2S1_Init 0 */ /* USER CODE BEGIN I2S1_Init 1 */ /* USER CODE END I2S1_Init 1 */ hi2s1.Instance = SPI1; hi2s1.Init.Mode = I2S_MODE_MASTER_TX; hi2s1.Init.Standard = I2S_STANDARD_PHILIPS; hi2s1.Init.DataFormat = I2S_DATAFORMAT_16B; hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s1.Init.AudioFreq = I2S_AUDIOFREQ_8K; hi2s1.Init.CPOL = I2S_CPOL_LOW; hi2s1.Init.FirstBit = I2S_FIRSTBIT_MSB; hi2s1.Init.WSInversion = I2S_WS_INVERSION_DISABLE; hi2s1.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT; hi2s1.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE; if (HAL_I2S_Init(&hi2s1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN I2S1_Init 2 */ /* USER CODE END I2S1_Init 2 */ }
/** * @brief I2S1 Initialization Function * @param None * @retval None */
@brief I2S1 Initialization Function @param None @retval None
[ "@brief", "I2S1", "Initialization", "Function", "@param", "None", "@retval", "None" ]
static void MX_I2S1_Init(void) { hi2s1.Instance = SPI1; hi2s1.Init.Mode = I2S_MODE_MASTER_TX; hi2s1.Init.Standard = I2S_STANDARD_PHILIPS; hi2s1.Init.DataFormat = I2S_DATAFORMAT_16B; hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s1.Init.AudioFreq = I2S_AUDIOFREQ_8K; hi2s1.Init.CPOL = I2S_CPOL_LOW; hi2s1.Init.FirstBit = I2S_FIRSTBIT_MSB; hi2s1.Init.WSInversion = I2S_WS_INVERSION_DISABLE; hi2s1.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT; hi2s1.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE; if (HAL_I2S_Init(&hi2s1) != HAL_OK) { Error_Handler(); } }
[ "static", "void", "MX_I2S1_Init", "(", "void", ")", "{", "hi2s1", ".", "Instance", "=", "SPI1", ";", "hi2s1", ".", "Init", ".", "Mode", "=", "I2S_MODE_MASTER_TX", ";", "hi2s1", ".", "Init", ".", "Standard", "=", "I2S_STANDARD_PHILIPS", ";", "hi2s1", ".", "Init", ".", "DataFormat", "=", "I2S_DATAFORMAT_16B", ";", "hi2s1", ".", "Init", ".", "MCLKOutput", "=", "I2S_MCLKOUTPUT_DISABLE", ";", "hi2s1", ".", "Init", ".", "AudioFreq", "=", "I2S_AUDIOFREQ_8K", ";", "hi2s1", ".", "Init", ".", "CPOL", "=", "I2S_CPOL_LOW", ";", "hi2s1", ".", "Init", ".", "FirstBit", "=", "I2S_FIRSTBIT_MSB", ";", "hi2s1", ".", "Init", ".", "WSInversion", "=", "I2S_WS_INVERSION_DISABLE", ";", "hi2s1", ".", "Init", ".", "Data24BitAlignment", "=", "I2S_DATA_24BIT_ALIGNMENT_RIGHT", ";", "hi2s1", ".", "Init", ".", "MasterKeepIOState", "=", "I2S_MASTER_KEEP_IO_STATE_DISABLE", ";", "if", "(", "HAL_I2S_Init", "(", "&", "hi2s1", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief I2S1 Initialization Function @param None @retval None
[ "@brief", "I2S1", "Initialization", "Function", "@param", "None", "@retval", "None" ]
[ "/* USER CODE BEGIN I2S1_Init 0 */", "/* USER CODE END I2S1_Init 0 */", "/* USER CODE BEGIN I2S1_Init 1 */", "/* USER CODE END I2S1_Init 1 */", "/* USER CODE BEGIN I2S1_Init 2 */", "/* USER CODE END I2S1_Init 2 */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
2049c7431687a890b452f1bf3ea4a9da85fdefed
suikan4github/stm32-defects
d010-nucleo-h743-di2s/Core/Src/main.c
[ "MIT" ]
C
MX_I2S2_Init
void
static void MX_I2S2_Init(void) { /* USER CODE BEGIN I2S2_Init 0 */ /* USER CODE END I2S2_Init 0 */ /* USER CODE BEGIN I2S2_Init 1 */ /* USER CODE END I2S2_Init 1 */ hi2s2.Instance = SPI2; hi2s2.Init.Mode = I2S_MODE_SLAVE_TX; hi2s2.Init.Standard = I2S_STANDARD_PHILIPS; hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B; hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_8K; hi2s2.Init.CPOL = I2S_CPOL_LOW; hi2s2.Init.FirstBit = I2S_FIRSTBIT_MSB; hi2s2.Init.WSInversion = I2S_WS_INVERSION_DISABLE; hi2s2.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT; hi2s2.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE; if (HAL_I2S_Init(&hi2s2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN I2S2_Init 2 */ /* USER CODE END I2S2_Init 2 */ }
/** * @brief I2S2 Initialization Function * @param None * @retval None */
@brief I2S2 Initialization Function @param None @retval None
[ "@brief", "I2S2", "Initialization", "Function", "@param", "None", "@retval", "None" ]
static void MX_I2S2_Init(void) { hi2s2.Instance = SPI2; hi2s2.Init.Mode = I2S_MODE_SLAVE_TX; hi2s2.Init.Standard = I2S_STANDARD_PHILIPS; hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B; hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_8K; hi2s2.Init.CPOL = I2S_CPOL_LOW; hi2s2.Init.FirstBit = I2S_FIRSTBIT_MSB; hi2s2.Init.WSInversion = I2S_WS_INVERSION_DISABLE; hi2s2.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT; hi2s2.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE; if (HAL_I2S_Init(&hi2s2) != HAL_OK) { Error_Handler(); } }
[ "static", "void", "MX_I2S2_Init", "(", "void", ")", "{", "hi2s2", ".", "Instance", "=", "SPI2", ";", "hi2s2", ".", "Init", ".", "Mode", "=", "I2S_MODE_SLAVE_TX", ";", "hi2s2", ".", "Init", ".", "Standard", "=", "I2S_STANDARD_PHILIPS", ";", "hi2s2", ".", "Init", ".", "DataFormat", "=", "I2S_DATAFORMAT_16B", ";", "hi2s2", ".", "Init", ".", "MCLKOutput", "=", "I2S_MCLKOUTPUT_DISABLE", ";", "hi2s2", ".", "Init", ".", "AudioFreq", "=", "I2S_AUDIOFREQ_8K", ";", "hi2s2", ".", "Init", ".", "CPOL", "=", "I2S_CPOL_LOW", ";", "hi2s2", ".", "Init", ".", "FirstBit", "=", "I2S_FIRSTBIT_MSB", ";", "hi2s2", ".", "Init", ".", "WSInversion", "=", "I2S_WS_INVERSION_DISABLE", ";", "hi2s2", ".", "Init", ".", "Data24BitAlignment", "=", "I2S_DATA_24BIT_ALIGNMENT_RIGHT", ";", "hi2s2", ".", "Init", ".", "MasterKeepIOState", "=", "I2S_MASTER_KEEP_IO_STATE_DISABLE", ";", "if", "(", "HAL_I2S_Init", "(", "&", "hi2s2", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief I2S2 Initialization Function @param None @retval None
[ "@brief", "I2S2", "Initialization", "Function", "@param", "None", "@retval", "None" ]
[ "/* USER CODE BEGIN I2S2_Init 0 */", "/* USER CODE END I2S2_Init 0 */", "/* USER CODE BEGIN I2S2_Init 1 */", "/* USER CODE END I2S2_Init 1 */", "/* USER CODE BEGIN I2S2_Init 2 */", "/* USER CODE END I2S2_Init 2 */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f9c1b6ad75166265efe2f165988dd5619c0c4dce
suikan4github/stm32-defects
d009-nucleo-g431rb-control/Core/Src/main.c
[ "MIT" ]
C
SystemClock_Config
void
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; RCC_PeriphCLKInitTypeDef PeriphClkInit = { 0 }; /** Configure the main internal regulator output voltage */ HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; RCC_OscInitStruct.PLL.PLLN = 85; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8) != HAL_OK) { Error_Handler(); } /** Initializes the peripherals clocks */ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1; PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } }
/** * @brief System Clock Configuration * @retval None */
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; RCC_PeriphCLKInitTypeDef PeriphClkInit = { 0 }; HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; RCC_OscInitStruct.PLL.PLLN = 85; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1; PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } }
[ "void", "SystemClock_Config", "(", "void", ")", "{", "RCC_OscInitTypeDef", "RCC_OscInitStruct", "=", "{", "0", "}", ";", "RCC_ClkInitTypeDef", "RCC_ClkInitStruct", "=", "{", "0", "}", ";", "RCC_PeriphCLKInitTypeDef", "PeriphClkInit", "=", "{", "0", "}", ";", "HAL_PWREx_ControlVoltageScaling", "(", "PWR_REGULATOR_VOLTAGE_SCALE1_BOOST", ")", ";", "RCC_OscInitStruct", ".", "OscillatorType", "=", "RCC_OSCILLATORTYPE_HSI", ";", "RCC_OscInitStruct", ".", "HSIState", "=", "RCC_HSI_ON", ";", "RCC_OscInitStruct", ".", "HSICalibrationValue", "=", "RCC_HSICALIBRATION_DEFAULT", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLState", "=", "RCC_PLL_ON", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLSource", "=", "RCC_PLLSOURCE_HSI", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLM", "=", "RCC_PLLM_DIV4", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLN", "=", "85", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLP", "=", "RCC_PLLP_DIV2", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLQ", "=", "RCC_PLLQ_DIV2", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLR", "=", "RCC_PLLR_DIV2", ";", "if", "(", "HAL_RCC_OscConfig", "(", "&", "RCC_OscInitStruct", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "RCC_ClkInitStruct", ".", "ClockType", "=", "RCC_CLOCKTYPE_HCLK", "|", "RCC_CLOCKTYPE_SYSCLK", "|", "RCC_CLOCKTYPE_PCLK1", "|", "RCC_CLOCKTYPE_PCLK2", ";", "RCC_ClkInitStruct", ".", "SYSCLKSource", "=", "RCC_SYSCLKSOURCE_PLLCLK", ";", "RCC_ClkInitStruct", ".", "AHBCLKDivider", "=", "RCC_SYSCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB1CLKDivider", "=", "RCC_HCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB2CLKDivider", "=", "RCC_HCLK_DIV1", ";", "if", "(", "HAL_RCC_ClockConfig", "(", "&", "RCC_ClkInitStruct", ",", "FLASH_LATENCY_8", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "PeriphClkInit", ".", "PeriphClockSelection", "=", "RCC_PERIPHCLK_LPUART1", ";", "PeriphClkInit", ".", "Lpuart1ClockSelection", "=", "RCC_LPUART1CLKSOURCE_PCLK1", ";", "if", "(", "HAL_RCCEx_PeriphCLKConfig", "(", "&", "PeriphClkInit", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief System Clock Configuration @retval None
[ "@brief", "System", "Clock", "Configuration", "@retval", "None" ]
[ "/** Configure the main internal regulator output voltage\r\n */", "/** Initializes the CPU, AHB and APB busses clocks\r\n */", "/** Initializes the CPU, AHB and APB busses clocks\r\n */", "/** Initializes the peripherals clocks\r\n */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f9c1b6ad75166265efe2f165988dd5619c0c4dce
suikan4github/stm32-defects
d009-nucleo-g431rb-control/Core/Src/main.c
[ "MIT" ]
C
MX_LPUART1_UART_Init
void
static void MX_LPUART1_UART_Init(void) { /* USER CODE BEGIN LPUART1_Init 0 */ /* USER CODE END LPUART1_Init 0 */ /* USER CODE BEGIN LPUART1_Init 1 */ /* USER CODE END LPUART1_Init 1 */ hlpuart1.Instance = LPUART1; hlpuart1.Init.BaudRate = 115200; hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; hlpuart1.Init.StopBits = UART_STOPBITS_1; hlpuart1.Init.Parity = UART_PARITY_NONE; hlpuart1.Init.Mode = UART_MODE_TX_RX; hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&hlpuart1) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN LPUART1_Init 2 */ /* USER CODE END LPUART1_Init 2 */ }
/** * @brief LPUART1 Initialization Function * @param None * @retval None */
@brief LPUART1 Initialization Function @param None @retval None
[ "@brief", "LPUART1", "Initialization", "Function", "@param", "None", "@retval", "None" ]
static void MX_LPUART1_UART_Init(void) { hlpuart1.Instance = LPUART1; hlpuart1.Init.BaudRate = 115200; hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; hlpuart1.Init.StopBits = UART_STOPBITS_1; hlpuart1.Init.Parity = UART_PARITY_NONE; hlpuart1.Init.Mode = UART_MODE_TX_RX; hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&hlpuart1) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { Error_Handler(); } }
[ "static", "void", "MX_LPUART1_UART_Init", "(", "void", ")", "{", "hlpuart1", ".", "Instance", "=", "LPUART1", ";", "hlpuart1", ".", "Init", ".", "BaudRate", "=", "115200", ";", "hlpuart1", ".", "Init", ".", "WordLength", "=", "UART_WORDLENGTH_8B", ";", "hlpuart1", ".", "Init", ".", "StopBits", "=", "UART_STOPBITS_1", ";", "hlpuart1", ".", "Init", ".", "Parity", "=", "UART_PARITY_NONE", ";", "hlpuart1", ".", "Init", ".", "Mode", "=", "UART_MODE_TX_RX", ";", "hlpuart1", ".", "Init", ".", "HwFlowCtl", "=", "UART_HWCONTROL_NONE", ";", "hlpuart1", ".", "Init", ".", "OneBitSampling", "=", "UART_ONE_BIT_SAMPLE_DISABLE", ";", "hlpuart1", ".", "AdvancedInit", ".", "AdvFeatureInit", "=", "UART_ADVFEATURE_NO_INIT", ";", "if", "(", "HAL_UART_Init", "(", "&", "hlpuart1", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "if", "(", "HAL_UARTEx_SetTxFifoThreshold", "(", "&", "hlpuart1", ",", "UART_TXFIFO_THRESHOLD_1_8", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "if", "(", "HAL_UARTEx_SetRxFifoThreshold", "(", "&", "hlpuart1", ",", "UART_RXFIFO_THRESHOLD_1_8", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "if", "(", "HAL_UARTEx_DisableFifoMode", "(", "&", "hlpuart1", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief LPUART1 Initialization Function @param None @retval None
[ "@brief", "LPUART1", "Initialization", "Function", "@param", "None", "@retval", "None" ]
[ "/* USER CODE BEGIN LPUART1_Init 0 */", "/* USER CODE END LPUART1_Init 0 */", "/* USER CODE BEGIN LPUART1_Init 1 */", "/* USER CODE END LPUART1_Init 1 */", "/* USER CODE BEGIN LPUART1_Init 2 */", "/* USER CODE END LPUART1_Init 2 */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f9c1b6ad75166265efe2f165988dd5619c0c4dce
suikan4github/stm32-defects
d009-nucleo-g431rb-control/Core/Src/main.c
[ "MIT" ]
C
MX_GPIO_Init
void
static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = { 0 }; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : B1_Pin */ GPIO_InitStruct.Pin = B1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : LD2_Pin */ GPIO_InitStruct.Pin = LD2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct); }
/** * @brief GPIO Initialization Function * @param None * @retval None */
@brief GPIO Initialization Function @param None @retval None
[ "@brief", "GPIO", "Initialization", "Function", "@param", "None", "@retval", "None" ]
static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = { 0 }; __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); GPIO_InitStruct.Pin = B1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = LD2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct); }
[ "static", "void", "MX_GPIO_Init", "(", "void", ")", "{", "GPIO_InitTypeDef", "GPIO_InitStruct", "=", "{", "0", "}", ";", "__HAL_RCC_GPIOC_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_GPIOF_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_GPIOA_CLK_ENABLE", "(", ")", ";", "__HAL_RCC_GPIOB_CLK_ENABLE", "(", ")", ";", "HAL_GPIO_WritePin", "(", "LD2_GPIO_Port", ",", "LD2_Pin", ",", "GPIO_PIN_RESET", ")", ";", "GPIO_InitStruct", ".", "Pin", "=", "B1_Pin", ";", "GPIO_InitStruct", ".", "Mode", "=", "GPIO_MODE_IT_RISING", ";", "GPIO_InitStruct", ".", "Pull", "=", "GPIO_NOPULL", ";", "HAL_GPIO_Init", "(", "B1_GPIO_Port", ",", "&", "GPIO_InitStruct", ")", ";", "GPIO_InitStruct", ".", "Pin", "=", "LD2_Pin", ";", "GPIO_InitStruct", ".", "Mode", "=", "GPIO_MODE_OUTPUT_PP", ";", "GPIO_InitStruct", ".", "Pull", "=", "GPIO_NOPULL", ";", "GPIO_InitStruct", ".", "Speed", "=", "GPIO_SPEED_FREQ_LOW", ";", "HAL_GPIO_Init", "(", "LD2_GPIO_Port", ",", "&", "GPIO_InitStruct", ")", ";", "}" ]
@brief GPIO Initialization Function @param None @retval None
[ "@brief", "GPIO", "Initialization", "Function", "@param", "None", "@retval", "None" ]
[ "/* GPIO Ports Clock Enable */", "/*Configure GPIO pin Output Level */", "/*Configure GPIO pin : B1_Pin */", "/*Configure GPIO pin : LD2_Pin */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c8915e538a77c89bc8ba72b20512e0454efdd1bc
culebracut/intruder_alert
intruder_alert.c
[ "FSFAP" ]
C
osd_sink_pad_buffer_probe
GstPadProbeReturn
static GstPadProbeReturn osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer u_data) { GstBuffer *buf = (GstBuffer *) info->data; guint num_rects = 0; NvDsObjectMeta *obj_meta = NULL; guint vehicle_count = 0; guint person_count = 0; NvDsMetaList *l_frame = NULL; NvDsMetaList *l_obj = NULL; NvDsDisplayMeta *display_meta = NULL; NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf); // increment counters for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next) { NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data); int offset = 0; for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) { obj_meta = (NvDsObjectMeta *) (l_obj->data); if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) { vehicle_count++; num_rects++; } if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { person_count++; num_rects++; } } display_meta = nvds_acquire_display_meta_from_pool (batch_meta); NvOSD_TextParams *txt_params = &display_meta->text_params[0]; display_meta->num_labels = 1; txt_params->display_text = g_malloc0 (MAX_DISPLAY_LEN); offset = snprintf (txt_params->display_text, MAX_DISPLAY_LEN, "Person Count = %d ", person_count); offset = snprintf (txt_params->display_text + offset, MAX_DISPLAY_LEN, "Vehicle Count = %d ", vehicle_count); /* Now set the offsets where the string should appear */ txt_params->x_offset = 10; txt_params->y_offset = 12; /* Font , font-color and font-size */ txt_params->font_params.font_name = "Serif"; txt_params->font_params.font_size = 20; txt_params->font_params.font_color.red = 1.0; txt_params->font_params.font_color.green = 0.0; txt_params->font_params.font_color.blue = 0.0; txt_params->font_params.font_color.alpha = 1.0; /* Text background color */ txt_params->set_bg_clr = 1; txt_params->text_bg_clr.red = 0.0; txt_params->text_bg_clr.green = 0.0; txt_params->text_bg_clr.blue = 0.0; txt_params->text_bg_clr.alpha = 1.0; nvds_add_display_meta_to_frame (frame_meta, display_meta); } g_print ("Frame Number = %d Number of objects = %d " "Vehicle Count = %d Person Count = %d\n", frame_number, num_rects, vehicle_count, person_count); frame_number++; return GST_PAD_PROBE_OK; }
/* osd_sink_pad_buffer_probe will extract metadata received on OSD sink pad * and update params for drawing rectangle, object information etc. * Outputs frame number, total object count, vehicle and person counts*/
osd_sink_pad_buffer_probe will extract metadata received on OSD sink pad and update params for drawing rectangle, object information etc. Outputs frame number, total object count, vehicle and person counts
[ "osd_sink_pad_buffer_probe", "will", "extract", "metadata", "received", "on", "OSD", "sink", "pad", "and", "update", "params", "for", "drawing", "rectangle", "object", "information", "etc", ".", "Outputs", "frame", "number", "total", "object", "count", "vehicle", "and", "person", "counts" ]
static GstPadProbeReturn osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer u_data) { GstBuffer *buf = (GstBuffer *) info->data; guint num_rects = 0; NvDsObjectMeta *obj_meta = NULL; guint vehicle_count = 0; guint person_count = 0; NvDsMetaList *l_frame = NULL; NvDsMetaList *l_obj = NULL; NvDsDisplayMeta *display_meta = NULL; NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf); for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next) { NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data); int offset = 0; for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) { obj_meta = (NvDsObjectMeta *) (l_obj->data); if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) { vehicle_count++; num_rects++; } if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { person_count++; num_rects++; } } display_meta = nvds_acquire_display_meta_from_pool (batch_meta); NvOSD_TextParams *txt_params = &display_meta->text_params[0]; display_meta->num_labels = 1; txt_params->display_text = g_malloc0 (MAX_DISPLAY_LEN); offset = snprintf (txt_params->display_text, MAX_DISPLAY_LEN, "Person Count = %d ", person_count); offset = snprintf (txt_params->display_text + offset, MAX_DISPLAY_LEN, "Vehicle Count = %d ", vehicle_count); txt_params->x_offset = 10; txt_params->y_offset = 12; txt_params->font_params.font_name = "Serif"; txt_params->font_params.font_size = 20; txt_params->font_params.font_color.red = 1.0; txt_params->font_params.font_color.green = 0.0; txt_params->font_params.font_color.blue = 0.0; txt_params->font_params.font_color.alpha = 1.0; txt_params->set_bg_clr = 1; txt_params->text_bg_clr.red = 0.0; txt_params->text_bg_clr.green = 0.0; txt_params->text_bg_clr.blue = 0.0; txt_params->text_bg_clr.alpha = 1.0; nvds_add_display_meta_to_frame (frame_meta, display_meta); } g_print ("Frame Number = %d Number of objects = %d " "Vehicle Count = %d Person Count = %d\n", frame_number, num_rects, vehicle_count, person_count); frame_number++; return GST_PAD_PROBE_OK; }
[ "static", "GstPadProbeReturn", "osd_sink_pad_buffer_probe", "(", "GstPad", "*", "pad", ",", "GstPadProbeInfo", "*", "info", ",", "gpointer", "u_data", ")", "{", "GstBuffer", "*", "buf", "=", "(", "GstBuffer", "*", ")", "info", "->", "data", ";", "guint", "num_rects", "=", "0", ";", "NvDsObjectMeta", "*", "obj_meta", "=", "NULL", ";", "guint", "vehicle_count", "=", "0", ";", "guint", "person_count", "=", "0", ";", "NvDsMetaList", "*", "l_frame", "=", "NULL", ";", "NvDsMetaList", "*", "l_obj", "=", "NULL", ";", "NvDsDisplayMeta", "*", "display_meta", "=", "NULL", ";", "NvDsBatchMeta", "*", "batch_meta", "=", "gst_buffer_get_nvds_batch_meta", "(", "buf", ")", ";", "for", "(", "l_frame", "=", "batch_meta", "->", "frame_meta_list", ";", "l_frame", "!=", "NULL", ";", "l_frame", "=", "l_frame", "->", "next", ")", "{", "NvDsFrameMeta", "*", "frame_meta", "=", "(", "NvDsFrameMeta", "*", ")", "(", "l_frame", "->", "data", ")", ";", "int", "offset", "=", "0", ";", "for", "(", "l_obj", "=", "frame_meta", "->", "obj_meta_list", ";", "l_obj", "!=", "NULL", ";", "l_obj", "=", "l_obj", "->", "next", ")", "{", "obj_meta", "=", "(", "NvDsObjectMeta", "*", ")", "(", "l_obj", "->", "data", ")", ";", "if", "(", "obj_meta", "->", "class_id", "==", "PGIE_CLASS_ID_VEHICLE", ")", "{", "vehicle_count", "++", ";", "num_rects", "++", ";", "}", "if", "(", "obj_meta", "->", "class_id", "==", "PGIE_CLASS_ID_PERSON", ")", "{", "person_count", "++", ";", "num_rects", "++", ";", "}", "}", "display_meta", "=", "nvds_acquire_display_meta_from_pool", "(", "batch_meta", ")", ";", "NvOSD_TextParams", "*", "txt_params", "=", "&", "display_meta", "->", "text_params", "[", "0", "]", ";", "display_meta", "->", "num_labels", "=", "1", ";", "txt_params", "->", "display_text", "=", "g_malloc0", "(", "MAX_DISPLAY_LEN", ")", ";", "offset", "=", "snprintf", "(", "txt_params", "->", "display_text", ",", "MAX_DISPLAY_LEN", ",", "\"", "\"", ",", "person_count", ")", ";", "offset", "=", "snprintf", "(", "txt_params", "->", "display_text", "+", "offset", ",", "MAX_DISPLAY_LEN", ",", "\"", "\"", ",", "vehicle_count", ")", ";", "txt_params", "->", "x_offset", "=", "10", ";", "txt_params", "->", "y_offset", "=", "12", ";", "txt_params", "->", "font_params", ".", "font_name", "=", "\"", "\"", ";", "txt_params", "->", "font_params", ".", "font_size", "=", "20", ";", "txt_params", "->", "font_params", ".", "font_color", ".", "red", "=", "1.0", ";", "txt_params", "->", "font_params", ".", "font_color", ".", "green", "=", "0.0", ";", "txt_params", "->", "font_params", ".", "font_color", ".", "blue", "=", "0.0", ";", "txt_params", "->", "font_params", ".", "font_color", ".", "alpha", "=", "1.0", ";", "txt_params", "->", "set_bg_clr", "=", "1", ";", "txt_params", "->", "text_bg_clr", ".", "red", "=", "0.0", ";", "txt_params", "->", "text_bg_clr", ".", "green", "=", "0.0", ";", "txt_params", "->", "text_bg_clr", ".", "blue", "=", "0.0", ";", "txt_params", "->", "text_bg_clr", ".", "alpha", "=", "1.0", ";", "nvds_add_display_meta_to_frame", "(", "frame_meta", ",", "display_meta", ")", ";", "}", "g_print", "(", "\"", "\"", "\"", "\\n", "\"", ",", "frame_number", ",", "num_rects", ",", "vehicle_count", ",", "person_count", ")", ";", "frame_number", "++", ";", "return", "GST_PAD_PROBE_OK", ";", "}" ]
osd_sink_pad_buffer_probe will extract metadata received on OSD sink pad and update params for drawing rectangle, object information etc.
[ "osd_sink_pad_buffer_probe", "will", "extract", "metadata", "received", "on", "OSD", "sink", "pad", "and", "update", "params", "for", "drawing", "rectangle", "object", "information", "etc", "." ]
[ "// increment counters", "/* Now set the offsets where the string should appear */", "/* Font , font-color and font-size */", "/* Text background color */" ]
[ { "param": "pad", "type": "GstPad" }, { "param": "info", "type": "GstPadProbeInfo" }, { "param": "u_data", "type": "gpointer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pad", "type": "GstPad", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "info", "type": "GstPadProbeInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "u_data", "type": "gpointer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c1b5665f8711a04c8b874abae8e0985172fc609f
culebracut/intruder_alert
src/sandbox/bus_call.c
[ "FSFAP" ]
C
bus_call
gboolean
static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("End of stream\n"); t_end = clock(); clock_t t = t_end - t_start; double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds double fps = frame_number/time_taken; g_print("\nThe program took %.2f seconds to redact %d frames, pref = %.2f fps \n\n", time_taken,frame_number,fps); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR:{ gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_printerr ("ERROR from element %s: %s\n", GST_OBJECT_NAME (msg->src), error->message); g_free (debug); g_printerr ("Error: %s\n", error->message); g_error_free (error); g_main_loop_quit (loop); break; } case GST_MESSAGE_STATE_CHANGED:{ GstState oldstate, newstate; gst_message_parse_state_changed (msg, &oldstate, &newstate, NULL); if (GST_ELEMENT (GST_MESSAGE_SRC (msg)) == pipeline) { switch (newstate) { case GST_STATE_PLAYING: g_print ("Pipeline running\n"); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "ds-app-playing"); t_start = clock(); break; case GST_STATE_PAUSED: if (oldstate == GST_STATE_PLAYING) { g_print ("Pipeline paused\n"); } break; case GST_STATE_READY: // GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL,"ds-app-ready"); if (oldstate == GST_STATE_NULL) { g_print ("Pipeline ready\n"); } else { g_print ("Pipeline stopped\n"); } break; default: break; } } break; } default: break; } return TRUE; }
/* This bus callback function detects the error and state change in the main pipe * and then export messages, export pipeline images or terminate the pipeline accordingly. */
This bus callback function detects the error and state change in the main pipe and then export messages, export pipeline images or terminate the pipeline accordingly.
[ "This", "bus", "callback", "function", "detects", "the", "error", "and", "state", "change", "in", "the", "main", "pipe", "and", "then", "export", "messages", "export", "pipeline", "images", "or", "terminate", "the", "pipeline", "accordingly", "." ]
static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("End of stream\n"); t_end = clock(); clock_t t = t_end - t_start; double time_taken = ((double)t)/CLOCKS_PER_SEC; double fps = frame_number/time_taken; g_print("\nThe program took %.2f seconds to redact %d frames, pref = %.2f fps \n\n", time_taken,frame_number,fps); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR:{ gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_printerr ("ERROR from element %s: %s\n", GST_OBJECT_NAME (msg->src), error->message); g_free (debug); g_printerr ("Error: %s\n", error->message); g_error_free (error); g_main_loop_quit (loop); break; } case GST_MESSAGE_STATE_CHANGED:{ GstState oldstate, newstate; gst_message_parse_state_changed (msg, &oldstate, &newstate, NULL); if (GST_ELEMENT (GST_MESSAGE_SRC (msg)) == pipeline) { switch (newstate) { case GST_STATE_PLAYING: g_print ("Pipeline running\n"); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "ds-app-playing"); t_start = clock(); break; case GST_STATE_PAUSED: if (oldstate == GST_STATE_PLAYING) { g_print ("Pipeline paused\n"); } break; case GST_STATE_READY: if (oldstate == GST_STATE_NULL) { g_print ("Pipeline ready\n"); } else { g_print ("Pipeline stopped\n"); } break; default: break; } } break; } default: break; } return TRUE; }
[ "static", "gboolean", "bus_call", "(", "GstBus", "*", "bus", ",", "GstMessage", "*", "msg", ",", "gpointer", "data", ")", "{", "GMainLoop", "*", "loop", "=", "(", "GMainLoop", "*", ")", "data", ";", "switch", "(", "GST_MESSAGE_TYPE", "(", "msg", ")", ")", "{", "case", "GST_MESSAGE_EOS", ":", "g_print", "(", "\"", "\\n", "\"", ")", ";", "t_end", "=", "clock", "(", ")", ";", "clock_t", "t", "=", "t_end", "-", "t_start", ";", "double", "time_taken", "=", "(", "(", "double", ")", "t", ")", "/", "CLOCKS_PER_SEC", ";", "double", "fps", "=", "frame_number", "/", "time_taken", ";", "g_print", "(", "\"", "\\n", "\\n", "\\n", "\"", ",", "time_taken", ",", "frame_number", ",", "fps", ")", ";", "g_main_loop_quit", "(", "loop", ")", ";", "break", ";", "case", "GST_MESSAGE_ERROR", ":", "{", "gchar", "*", "debug", ";", "GError", "*", "error", ";", "gst_message_parse_error", "(", "msg", ",", "&", "error", ",", "&", "debug", ")", ";", "g_printerr", "(", "\"", "\\n", "\"", ",", "GST_OBJECT_NAME", "(", "msg", "->", "src", ")", ",", "error", "->", "message", ")", ";", "g_free", "(", "debug", ")", ";", "g_printerr", "(", "\"", "\\n", "\"", ",", "error", "->", "message", ")", ";", "g_error_free", "(", "error", ")", ";", "g_main_loop_quit", "(", "loop", ")", ";", "break", ";", "}", "case", "GST_MESSAGE_STATE_CHANGED", ":", "{", "GstState", "oldstate", ",", "newstate", ";", "gst_message_parse_state_changed", "(", "msg", ",", "&", "oldstate", ",", "&", "newstate", ",", "NULL", ")", ";", "if", "(", "GST_ELEMENT", "(", "GST_MESSAGE_SRC", "(", "msg", ")", ")", "==", "pipeline", ")", "{", "switch", "(", "newstate", ")", "{", "case", "GST_STATE_PLAYING", ":", "g_print", "(", "\"", "\\n", "\"", ")", ";", "GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS", "(", "GST_BIN", "(", "pipeline", ")", ",", "GST_DEBUG_GRAPH_SHOW_ALL", ",", "\"", "\"", ")", ";", "t_start", "=", "clock", "(", ")", ";", "break", ";", "case", "GST_STATE_PAUSED", ":", "if", "(", "oldstate", "==", "GST_STATE_PLAYING", ")", "{", "g_print", "(", "\"", "\\n", "\"", ")", ";", "}", "break", ";", "case", "GST_STATE_READY", ":", "if", "(", "oldstate", "==", "GST_STATE_NULL", ")", "{", "g_print", "(", "\"", "\\n", "\"", ")", ";", "}", "else", "{", "g_print", "(", "\"", "\\n", "\"", ")", ";", "}", "break", ";", "default", ":", "break", ";", "}", "}", "break", ";", "}", "default", ":", "break", ";", "}", "return", "TRUE", ";", "}" ]
This bus callback function detects the error and state change in the main pipe and then export messages, export pipeline images or terminate the pipeline accordingly.
[ "This", "bus", "callback", "function", "detects", "the", "error", "and", "state", "change", "in", "the", "main", "pipe", "and", "then", "export", "messages", "export", "pipeline", "images", "or", "terminate", "the", "pipeline", "accordingly", "." ]
[ "// in seconds ", "// GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL,\"ds-app-ready\");" ]
[ { "param": "bus", "type": "GstBus" }, { "param": "msg", "type": "GstMessage" }, { "param": "data", "type": "gpointer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bus", "type": "GstBus", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "msg", "type": "GstMessage", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "gpointer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3dde5061b8fe6608f30650244d3e2106012e8a91
ryanhe312/nemu-lab
kernel/src/driver/ide/ide.c
[ "Apache-2.0" ]
C
ide_read
void
void ide_read(uint8_t *buf, uint32_t offset, uint32_t len) { uint32_t i; for (i = 0; i < len; i ++) { buf[i] = read_byte(offset + i); } }
/* The kernel is monolithic, therefore we do not need to * translate the address ``buf'' from the user process to * a physical one, which is necessary for a microkernel. */
The kernel is monolithic, therefore we do not need to translate the address ``buf'' from the user process to a physical one, which is necessary for a microkernel.
[ "The", "kernel", "is", "monolithic", "therefore", "we", "do", "not", "need", "to", "translate", "the", "address", "`", "`", "buf", "'", "'", "from", "the", "user", "process", "to", "a", "physical", "one", "which", "is", "necessary", "for", "a", "microkernel", "." ]
void ide_read(uint8_t *buf, uint32_t offset, uint32_t len) { uint32_t i; for (i = 0; i < len; i ++) { buf[i] = read_byte(offset + i); } }
[ "void", "ide_read", "(", "uint8_t", "*", "buf", ",", "uint32_t", "offset", ",", "uint32_t", "len", ")", "{", "uint32_t", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "buf", "[", "i", "]", "=", "read_byte", "(", "offset", "+", "i", ")", ";", "}", "}" ]
The kernel is monolithic, therefore we do not need to translate the address ``buf'' from the user process to a physical one, which is necessary for a microkernel.
[ "The", "kernel", "is", "monolithic", "therefore", "we", "do", "not", "need", "to", "translate", "the", "address", "`", "`", "buf", "'", "'", "from", "the", "user", "process", "to", "a", "physical", "one", "which", "is", "necessary", "for", "a", "microkernel", "." ]
[]
[ { "param": "buf", "type": "uint8_t" }, { "param": "offset", "type": "uint32_t" }, { "param": "len", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "offset", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f49eec2c0c2879713627d206cb3f937fcba9f916
ryanhe312/nemu-lab
game/src/common/device/palette.c
[ "Apache-2.0" ]
C
write_palette
void
void write_palette(void *colors, int nr_color) { int i; uint8_t (*palette)[4] = colors; out_byte(VGA_DAC_WRITE_INDEX, 0); for(i = 0; i < nr_color; i ++) { out_byte(VGA_DAC_DATA, palette[i][0] >> 2); // red out_byte(VGA_DAC_DATA, palette[i][1] >> 2); // green out_byte(VGA_DAC_DATA, palette[i][2] >> 2); // blue } }
/* Load the palette into VGA. */
Load the palette into VGA.
[ "Load", "the", "palette", "into", "VGA", "." ]
void write_palette(void *colors, int nr_color) { int i; uint8_t (*palette)[4] = colors; out_byte(VGA_DAC_WRITE_INDEX, 0); for(i = 0; i < nr_color; i ++) { out_byte(VGA_DAC_DATA, palette[i][0] >> 2); out_byte(VGA_DAC_DATA, palette[i][1] >> 2); out_byte(VGA_DAC_DATA, palette[i][2] >> 2); } }
[ "void", "write_palette", "(", "void", "*", "colors", ",", "int", "nr_color", ")", "{", "int", "i", ";", "uint8_t", "(", "*", "palette", ")", "[", "4", "]", "=", "colors", ";", "out_byte", "(", "VGA_DAC_WRITE_INDEX", ",", "0", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "nr_color", ";", "i", "++", ")", "{", "out_byte", "(", "VGA_DAC_DATA", ",", "palette", "[", "i", "]", "[", "0", "]", ">>", "2", ")", ";", "out_byte", "(", "VGA_DAC_DATA", ",", "palette", "[", "i", "]", "[", "1", "]", ">>", "2", ")", ";", "out_byte", "(", "VGA_DAC_DATA", ",", "palette", "[", "i", "]", "[", "2", "]", ">>", "2", ")", ";", "}", "}" ]
Load the palette into VGA.
[ "Load", "the", "palette", "into", "VGA", "." ]
[ "// red", "// green", "// blue" ]
[ { "param": "colors", "type": "void" }, { "param": "nr_color", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "colors", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nr_color", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f49eec2c0c2879713627d206cb3f937fcba9f916
ryanhe312/nemu-lab
game/src/common/device/palette.c
[ "Apache-2.0" ]
C
read_palette
void
void read_palette() { int i; uint8_t r,g,b; out_byte(VGA_DAC_READ_INDEX, 0); for(i = 0; i < NR_PALETTE_ENTRY; i ++) { r = in_byte(VGA_DAC_DATA); g = in_byte(VGA_DAC_DATA); b = in_byte(VGA_DAC_DATA); printf("r = %x, g = %x, b = %x\n", r, g, b); } }
/* Print the palette in use. */
Print the palette in use.
[ "Print", "the", "palette", "in", "use", "." ]
void read_palette() { int i; uint8_t r,g,b; out_byte(VGA_DAC_READ_INDEX, 0); for(i = 0; i < NR_PALETTE_ENTRY; i ++) { r = in_byte(VGA_DAC_DATA); g = in_byte(VGA_DAC_DATA); b = in_byte(VGA_DAC_DATA); printf("r = %x, g = %x, b = %x\n", r, g, b); } }
[ "void", "read_palette", "(", ")", "{", "int", "i", ";", "uint8_t", "r", ",", "g", ",", "b", ";", "out_byte", "(", "VGA_DAC_READ_INDEX", ",", "0", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "NR_PALETTE_ENTRY", ";", "i", "++", ")", "{", "r", "=", "in_byte", "(", "VGA_DAC_DATA", ")", ";", "g", "=", "in_byte", "(", "VGA_DAC_DATA", ")", ";", "b", "=", "in_byte", "(", "VGA_DAC_DATA", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "r", ",", "g", ",", "b", ")", ";", "}", "}" ]
Print the palette in use.
[ "Print", "the", "palette", "in", "use", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
e41b111f81add4d4fdde0fca22316d88022228c4
Sycamore-City-passerby/ML
LeetCode/LeetCode_Python-master/LeetCode_Python-master/Algorithm-Easy/225_Implement_Stack_using_Queues.c
[ "MIT" ]
C
push
void
void push(int x) { q_.push(x); for (int i = 1; i < q_.size(); ++i) { q_.push(q_.front()); q_.pop(); } }
/** Push element x onto stack. */
Push element x onto stack.
[ "Push", "element", "x", "onto", "stack", "." ]
void push(int x) { q_.push(x); for (int i = 1; i < q_.size(); ++i) { q_.push(q_.front()); q_.pop(); } }
[ "void", "push", "(", "int", "x", ")", "{", "q_", ".", "push", "(", "x", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "q_", ".", "size", "(", ")", ";", "++", "i", ")", "{", "q_", ".", "push", "(", "q_", ".", "front", "(", ")", ")", ";", "q_", ".", "pop", "(", ")", ";", "}", "}" ]
Push element x onto stack.
[ "Push", "element", "x", "onto", "stack", "." ]
[]
[ { "param": "x", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "x", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
e41b111f81add4d4fdde0fca22316d88022228c4
Sycamore-City-passerby/ML
LeetCode/LeetCode_Python-master/LeetCode_Python-master/Algorithm-Easy/225_Implement_Stack_using_Queues.c
[ "MIT" ]
C
pop
int
int pop() { int top = q_.front(); q_.pop(); return top; }
/** Removes the element on top of the stack and returns that element. */
Removes the element on top of the stack and returns that element.
[ "Removes", "the", "element", "on", "top", "of", "the", "stack", "and", "returns", "that", "element", "." ]
int pop() { int top = q_.front(); q_.pop(); return top; }
[ "int", "pop", "(", ")", "{", "int", "top", "=", "q_", ".", "front", "(", ")", ";", "q_", ".", "pop", "(", ")", ";", "return", "top", ";", "}" ]
Removes the element on top of the stack and returns that element.
[ "Removes", "the", "element", "on", "top", "of", "the", "stack", "and", "returns", "that", "element", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3abede341fcf49f739f8758f1c00022c203f434f
benofbrown/mrsh
parser/word.c
[ "MIT" ]
C
expect_dollar
nan
struct mrsh_word *expect_dollar(struct mrsh_parser *state) { struct mrsh_position dollar_pos = state->pos; char c = parser_read_char(state); assert(c == '$'); struct mrsh_word_parameter *wp; switch (parser_peek_char(state)) { case '{':; // Parameter expansion in the form `${expression}` wp = expect_parameter_expression(state); if (wp == NULL) { return NULL; } wp->dollar_pos = dollar_pos; return &wp->word; // Command substitution in the form `$(command)` or arithmetic expansion in // the form `$((expression))` case '(':; char next[2]; parser_peek(state, next, sizeof(next)); if (next[1] == '(') { struct mrsh_word_arithmetic *wa = expect_word_arithmetic(state); if (wa == NULL) { return NULL; } // TODO: store dollar_pos in wa return &wa->word; } else { struct mrsh_word_command *wc = expect_word_command(state); if (wc == NULL) { return NULL; } // TODO: store dollar_pos in wc return &wc->word; } default:; // Parameter expansion in the form `$parameter` size_t name_len = peek_name(state, false); if (name_len == 0) { name_len = 1; } struct mrsh_range name_range; char *name = read_token(state, name_len, &name_range); wp = mrsh_word_parameter_create(name, MRSH_PARAM_NONE, false, NULL); wp->dollar_pos = dollar_pos; wp->name_range = name_range; return &wp->word; } }
// Expect parameter expansion or command substitution
Expect parameter expansion or command substitution
[ "Expect", "parameter", "expansion", "or", "command", "substitution" ]
struct mrsh_word *expect_dollar(struct mrsh_parser *state) { struct mrsh_position dollar_pos = state->pos; char c = parser_read_char(state); assert(c == '$'); struct mrsh_word_parameter *wp; switch (parser_peek_char(state)) { case '{':; wp = expect_parameter_expression(state); if (wp == NULL) { return NULL; } wp->dollar_pos = dollar_pos; return &wp->word; case '(':; char next[2]; parser_peek(state, next, sizeof(next)); if (next[1] == '(') { struct mrsh_word_arithmetic *wa = expect_word_arithmetic(state); if (wa == NULL) { return NULL; } return &wa->word; } else { struct mrsh_word_command *wc = expect_word_command(state); if (wc == NULL) { return NULL; } return &wc->word; } default:; size_t name_len = peek_name(state, false); if (name_len == 0) { name_len = 1; } struct mrsh_range name_range; char *name = read_token(state, name_len, &name_range); wp = mrsh_word_parameter_create(name, MRSH_PARAM_NONE, false, NULL); wp->dollar_pos = dollar_pos; wp->name_range = name_range; return &wp->word; } }
[ "struct", "mrsh_word", "*", "expect_dollar", "(", "struct", "mrsh_parser", "*", "state", ")", "{", "struct", "mrsh_position", "dollar_pos", "=", "state", "->", "pos", ";", "char", "c", "=", "parser_read_char", "(", "state", ")", ";", "assert", "(", "c", "==", "'", "'", ")", ";", "struct", "mrsh_word_parameter", "*", "wp", ";", "switch", "(", "parser_peek_char", "(", "state", ")", ")", "{", "case", "'", "'", ":", ";", "wp", "=", "expect_parameter_expression", "(", "state", ")", ";", "if", "(", "wp", "==", "NULL", ")", "{", "return", "NULL", ";", "}", "wp", "->", "dollar_pos", "=", "dollar_pos", ";", "return", "&", "wp", "->", "word", ";", "case", "'", "'", ":", ";", "char", "next", "[", "2", "]", ";", "parser_peek", "(", "state", ",", "next", ",", "sizeof", "(", "next", ")", ")", ";", "if", "(", "next", "[", "1", "]", "==", "'", "'", ")", "{", "struct", "mrsh_word_arithmetic", "*", "wa", "=", "expect_word_arithmetic", "(", "state", ")", ";", "if", "(", "wa", "==", "NULL", ")", "{", "return", "NULL", ";", "}", "return", "&", "wa", "->", "word", ";", "}", "else", "{", "struct", "mrsh_word_command", "*", "wc", "=", "expect_word_command", "(", "state", ")", ";", "if", "(", "wc", "==", "NULL", ")", "{", "return", "NULL", ";", "}", "return", "&", "wc", "->", "word", ";", "}", "default", ":", ";", "size_t", "name_len", "=", "peek_name", "(", "state", ",", "false", ")", ";", "if", "(", "name_len", "==", "0", ")", "{", "name_len", "=", "1", ";", "}", "struct", "mrsh_range", "name_range", ";", "char", "*", "name", "=", "read_token", "(", "state", ",", "name_len", ",", "&", "name_range", ")", ";", "wp", "=", "mrsh_word_parameter_create", "(", "name", ",", "MRSH_PARAM_NONE", ",", "false", ",", "NULL", ")", ";", "wp", "->", "dollar_pos", "=", "dollar_pos", ";", "wp", "->", "name_range", "=", "name_range", ";", "return", "&", "wp", "->", "word", ";", "}", "}" ]
Expect parameter expansion or command substitution
[ "Expect", "parameter", "expansion", "or", "command", "substitution" ]
[ "// Parameter expansion in the form `${expression}`", "// Command substitution in the form `$(command)` or arithmetic expansion in", "// the form `$((expression))`", "// TODO: store dollar_pos in wa", "// TODO: store dollar_pos in wc", "// Parameter expansion in the form `$parameter`" ]
[ { "param": "state", "type": "struct mrsh_parser" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "state", "type": "struct mrsh_parser", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8a7295168cab31909deb46c0af9294fc2d54553e
AlanVieyra333/hiredispool
log.c
[ "Apache-2.0" ]
C
_set_logfile
void
static void _set_logfile(const char* filename) { char namebuf[1024]; char* dirsep; char* dir = namebuf; if(filename == NULL) return; /* Create directory and set log_dir */ strncpy(namebuf, filename, sizeof(namebuf)); namebuf[sizeof(namebuf) - 1] = '\0'; while((dirsep = strchr(dir, '/')) != NULL) { *dirsep = '\0'; mkdir(namebuf, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); *dirsep = '/'; dir = dirsep + 1; } dirsep = strrchr(namebuf, '/'); if(dirsep != NULL) { *dirsep = '\0'; strncpy(C.dir, namebuf, sizeof(C.dir)); C.dir[sizeof(C.dir) - 1] = '\0'; *dirsep = '/'; } /* Do set log_file */ strncpy(C.file, filename, sizeof(C.file)); C.file[sizeof(C.file) - 1] = '\0'; }
/* * Control log filename, create directory as needed. */
Control log filename, create directory as needed.
[ "Control", "log", "filename", "create", "directory", "as", "needed", "." ]
static void _set_logfile(const char* filename) { char namebuf[1024]; char* dirsep; char* dir = namebuf; if(filename == NULL) return; strncpy(namebuf, filename, sizeof(namebuf)); namebuf[sizeof(namebuf) - 1] = '\0'; while((dirsep = strchr(dir, '/')) != NULL) { *dirsep = '\0'; mkdir(namebuf, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); *dirsep = '/'; dir = dirsep + 1; } dirsep = strrchr(namebuf, '/'); if(dirsep != NULL) { *dirsep = '\0'; strncpy(C.dir, namebuf, sizeof(C.dir)); C.dir[sizeof(C.dir) - 1] = '\0'; *dirsep = '/'; } strncpy(C.file, filename, sizeof(C.file)); C.file[sizeof(C.file) - 1] = '\0'; }
[ "static", "void", "_set_logfile", "(", "const", "char", "*", "filename", ")", "{", "char", "namebuf", "[", "1024", "]", ";", "char", "*", "dirsep", ";", "char", "*", "dir", "=", "namebuf", ";", "if", "(", "filename", "==", "NULL", ")", "return", ";", "strncpy", "(", "namebuf", ",", "filename", ",", "sizeof", "(", "namebuf", ")", ")", ";", "namebuf", "[", "sizeof", "(", "namebuf", ")", "-", "1", "]", "=", "'", "\\0", "'", ";", "while", "(", "(", "dirsep", "=", "strchr", "(", "dir", ",", "'", "'", ")", ")", "!=", "NULL", ")", "{", "*", "dirsep", "=", "'", "\\0", "'", ";", "mkdir", "(", "namebuf", ",", "S_IRWXU", "|", "S_IRGRP", "|", "S_IXGRP", "|", "S_IROTH", "|", "S_IXOTH", ")", ";", "*", "dirsep", "=", "'", "'", ";", "dir", "=", "dirsep", "+", "1", ";", "}", "dirsep", "=", "strrchr", "(", "namebuf", ",", "'", "'", ")", ";", "if", "(", "dirsep", "!=", "NULL", ")", "{", "*", "dirsep", "=", "'", "\\0", "'", ";", "strncpy", "(", "C", ".", "dir", ",", "namebuf", ",", "sizeof", "(", "C", ".", "dir", ")", ")", ";", "C", ".", "dir", "[", "sizeof", "(", "C", ".", "dir", ")", "-", "1", "]", "=", "'", "\\0", "'", ";", "*", "dirsep", "=", "'", "'", ";", "}", "strncpy", "(", "C", ".", "file", ",", "filename", ",", "sizeof", "(", "C", ".", "file", ")", ")", ";", "C", ".", "file", "[", "sizeof", "(", "C", ".", "file", ")", "-", "1", "]", "=", "'", "\\0", "'", ";", "}" ]
Control log filename, create directory as needed.
[ "Control", "log", "filename", "create", "directory", "as", "needed", "." ]
[ "/* Create directory and set log_dir */", "/* Do set log_file */" ]
[ { "param": "filename", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "filename", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8a7295168cab31909deb46c0af9294fc2d54553e
AlanVieyra333/hiredispool
log.c
[ "Apache-2.0" ]
C
vlog
int
int vlog(int lvl, const char *fmt, va_list ap) { FILE *msgfd = NULL; char *p; char buffer[8192]; char namebuf[1024]; int len, len0; /* * Filter out by level_hold */ if(C.level_hold > (lvl & ~L_CONS)) { return 0; } /* * NOT debugging, and trying to log debug messages. * * Throw the message away. */ if ((C.verbose == 0) && ((lvl & ~L_CONS) <= L_DEBUG)) { return 0; } /* * If we don't want any messages, then * throw them away. */ if (C.dest == LOG_DEST_NULL) { return 0; } if (C.dest == LOG_DEST_STDOUT) { msgfd = stdout; } else if (C.dest == LOG_DEST_STDERR) { msgfd = stderr; } else if (C.dest != LOG_DEST_SYSLOG) { /* * No log file set. It must go to stdout. */ if (C.file[0] == '\0') { msgfd = stdout; /* * Else try to open the file. */ } else { convert_logfilename(C.file, namebuf, sizeof(namebuf)); if ((msgfd = fopen(namebuf, "a+")) == NULL) { fprintf(stderr, "%s: Couldn't open %s for logging: %s\n", C.progname, namebuf, strerror(errno)); fprintf(stderr, " ("); vfprintf(stderr, fmt, ap); /* the message that caused the log */ fprintf(stderr, ")\n"); return -1; } } } if (C.dest == LOG_DEST_SYSLOG) { *buffer = '\0'; len0 = 0; len = 0; } else if(C.print_millisec) { const char* s; struct timeval tv; struct tm local; char deflvl[8]; gettimeofday(&tv, NULL); localtime_r(&tv.tv_sec, &local); sprintf(buffer, "%04d/%02d/%02d %02d:%02d:%02d,%03d", local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec, (int)tv.tv_usec/1000); sprintf(deflvl, " L%04X ", (lvl & ~L_CONS)); s = _int2str(L, (lvl & ~L_CONS), deflvl); len0 = strlen(buffer); strcat(buffer, s); len = strlen(buffer); } else { const char *s; time_t tv; struct tm local; char deflvl[8]; tv = time(NULL); localtime_r(&tv, &local); sprintf(buffer, "%04d/%02d/%02d %02d:%02d:%02d", local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec); sprintf(deflvl, " L%04X ", (lvl & ~L_CONS)); s = _int2str(L, (lvl & ~L_CONS), deflvl); len0 = strlen(buffer); strcat(buffer, s); len = strlen(buffer); } vsnprintf(buffer + len, sizeof(buffer) - len - 1, fmt, ap); buffer[sizeof(buffer) - 2] = '\0'; /* * Filter out characters not in Latin-1. */ for (p = buffer; *p != '\0'; p++) { if (*p == '\r' || *p == '\n') *p = ' '; else if ((*p >=0 && *p < 32) || (/**p >= -128 &&*/ *p < 0)) *p = '?'; } strcat(buffer, "\n"); /* * If we're debugging, for small values of debug, then * we don't do timestamps. */ if (C.verbose == 1) { p = buffer + len0; } else { /* * No debugging, or lots of debugging. Print * the time stamps. */ p = buffer; } if (C.dest != LOG_DEST_SYSLOG) { fputs(p, msgfd); if (msgfd == stdout) { fflush(stdout); } else if (msgfd == stderr) { fflush(stderr); } else { fclose(msgfd); if(lvl & L_CONS) { if((lvl & ~L_CONS) < L_WARN) { fputs(p, stdout); fflush(stdout); } else { fputs(p, stderr); fflush(stderr); } /* * IF debugging, also to console but no flush */ } else if(C.verbose) { if((lvl & ~L_CONS) < L_WARN) { fputs(p, stdout); } else { fputs(p, stderr); } } } } else { /* it was syslog */ lvl = (lvl & ~L_CONS); if(lvl > 0 && lvl <= L_DEBUG) { lvl = LOG_DEBUG; } else if(lvl > L_DEBUG && lvl <= L_INFO) { lvl = LOG_NOTICE; } else if(lvl > L_INFO && lvl <= L_WARN) { lvl = LOG_WARNING; } else if(lvl > L_WARN && lvl <= L_ERROR) { lvl = LOG_ERR; } else if(lvl > L_ERROR && lvl <= L_FATAL) { lvl = LOG_CRIT; } else if(lvl > L_FATAL) { lvl = LOG_ALERT; } else { lvl = LOG_EMERG; } syslog(lvl, "%s", buffer + len0); /* don't print timestamp */ } return 0; }
/* * Log the message to the logfile. Include the severity and * a time stamp. */
Log the message to the logfile. Include the severity and a time stamp.
[ "Log", "the", "message", "to", "the", "logfile", ".", "Include", "the", "severity", "and", "a", "time", "stamp", "." ]
int vlog(int lvl, const char *fmt, va_list ap) { FILE *msgfd = NULL; char *p; char buffer[8192]; char namebuf[1024]; int len, len0; if(C.level_hold > (lvl & ~L_CONS)) { return 0; } if ((C.verbose == 0) && ((lvl & ~L_CONS) <= L_DEBUG)) { return 0; } if (C.dest == LOG_DEST_NULL) { return 0; } if (C.dest == LOG_DEST_STDOUT) { msgfd = stdout; } else if (C.dest == LOG_DEST_STDERR) { msgfd = stderr; } else if (C.dest != LOG_DEST_SYSLOG) { if (C.file[0] == '\0') { msgfd = stdout; } else { convert_logfilename(C.file, namebuf, sizeof(namebuf)); if ((msgfd = fopen(namebuf, "a+")) == NULL) { fprintf(stderr, "%s: Couldn't open %s for logging: %s\n", C.progname, namebuf, strerror(errno)); fprintf(stderr, " ("); vfprintf(stderr, fmt, ap); fprintf(stderr, ")\n"); return -1; } } } if (C.dest == LOG_DEST_SYSLOG) { *buffer = '\0'; len0 = 0; len = 0; } else if(C.print_millisec) { const char* s; struct timeval tv; struct tm local; char deflvl[8]; gettimeofday(&tv, NULL); localtime_r(&tv.tv_sec, &local); sprintf(buffer, "%04d/%02d/%02d %02d:%02d:%02d,%03d", local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec, (int)tv.tv_usec/1000); sprintf(deflvl, " L%04X ", (lvl & ~L_CONS)); s = _int2str(L, (lvl & ~L_CONS), deflvl); len0 = strlen(buffer); strcat(buffer, s); len = strlen(buffer); } else { const char *s; time_t tv; struct tm local; char deflvl[8]; tv = time(NULL); localtime_r(&tv, &local); sprintf(buffer, "%04d/%02d/%02d %02d:%02d:%02d", local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec); sprintf(deflvl, " L%04X ", (lvl & ~L_CONS)); s = _int2str(L, (lvl & ~L_CONS), deflvl); len0 = strlen(buffer); strcat(buffer, s); len = strlen(buffer); } vsnprintf(buffer + len, sizeof(buffer) - len - 1, fmt, ap); buffer[sizeof(buffer) - 2] = '\0'; for (p = buffer; *p != '\0'; p++) { if (*p == '\r' || *p == '\n') *p = ' '; else if ((*p >=0 && *p < 32) || ( *p < 0)) *p = '?'; } strcat(buffer, "\n"); if (C.verbose == 1) { p = buffer + len0; } else { p = buffer; } if (C.dest != LOG_DEST_SYSLOG) { fputs(p, msgfd); if (msgfd == stdout) { fflush(stdout); } else if (msgfd == stderr) { fflush(stderr); } else { fclose(msgfd); if(lvl & L_CONS) { if((lvl & ~L_CONS) < L_WARN) { fputs(p, stdout); fflush(stdout); } else { fputs(p, stderr); fflush(stderr); } } else if(C.verbose) { if((lvl & ~L_CONS) < L_WARN) { fputs(p, stdout); } else { fputs(p, stderr); } } } } else { lvl = (lvl & ~L_CONS); if(lvl > 0 && lvl <= L_DEBUG) { lvl = LOG_DEBUG; } else if(lvl > L_DEBUG && lvl <= L_INFO) { lvl = LOG_NOTICE; } else if(lvl > L_INFO && lvl <= L_WARN) { lvl = LOG_WARNING; } else if(lvl > L_WARN && lvl <= L_ERROR) { lvl = LOG_ERR; } else if(lvl > L_ERROR && lvl <= L_FATAL) { lvl = LOG_CRIT; } else if(lvl > L_FATAL) { lvl = LOG_ALERT; } else { lvl = LOG_EMERG; } syslog(lvl, "%s", buffer + len0); } return 0; }
[ "int", "vlog", "(", "int", "lvl", ",", "const", "char", "*", "fmt", ",", "va_list", "ap", ")", "{", "FILE", "*", "msgfd", "=", "NULL", ";", "char", "*", "p", ";", "char", "buffer", "[", "8192", "]", ";", "char", "namebuf", "[", "1024", "]", ";", "int", "len", ",", "len0", ";", "if", "(", "C", ".", "level_hold", ">", "(", "lvl", "&", "~", "L_CONS", ")", ")", "{", "return", "0", ";", "}", "if", "(", "(", "C", ".", "verbose", "==", "0", ")", "&&", "(", "(", "lvl", "&", "~", "L_CONS", ")", "<=", "L_DEBUG", ")", ")", "{", "return", "0", ";", "}", "if", "(", "C", ".", "dest", "==", "LOG_DEST_NULL", ")", "{", "return", "0", ";", "}", "if", "(", "C", ".", "dest", "==", "LOG_DEST_STDOUT", ")", "{", "msgfd", "=", "stdout", ";", "}", "else", "if", "(", "C", ".", "dest", "==", "LOG_DEST_STDERR", ")", "{", "msgfd", "=", "stderr", ";", "}", "else", "if", "(", "C", ".", "dest", "!=", "LOG_DEST_SYSLOG", ")", "{", "if", "(", "C", ".", "file", "[", "0", "]", "==", "'", "\\0", "'", ")", "{", "msgfd", "=", "stdout", ";", "}", "else", "{", "convert_logfilename", "(", "C", ".", "file", ",", "namebuf", ",", "sizeof", "(", "namebuf", ")", ")", ";", "if", "(", "(", "msgfd", "=", "fopen", "(", "namebuf", ",", "\"", "\"", ")", ")", "==", "NULL", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "C", ".", "progname", ",", "namebuf", ",", "strerror", "(", "errno", ")", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\"", ")", ";", "vfprintf", "(", "stderr", ",", "fmt", ",", "ap", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "return", "-1", ";", "}", "}", "}", "if", "(", "C", ".", "dest", "==", "LOG_DEST_SYSLOG", ")", "{", "*", "buffer", "=", "'", "\\0", "'", ";", "len0", "=", "0", ";", "len", "=", "0", ";", "}", "else", "if", "(", "C", ".", "print_millisec", ")", "{", "const", "char", "*", "s", ";", "struct", "timeval", "tv", ";", "struct", "tm", "local", ";", "char", "deflvl", "[", "8", "]", ";", "gettimeofday", "(", "&", "tv", ",", "NULL", ")", ";", "localtime_r", "(", "&", "tv", ".", "tv_sec", ",", "&", "local", ")", ";", "sprintf", "(", "buffer", ",", "\"", "\"", ",", "local", ".", "tm_year", "+", "1900", ",", "local", ".", "tm_mon", "+", "1", ",", "local", ".", "tm_mday", ",", "local", ".", "tm_hour", ",", "local", ".", "tm_min", ",", "local", ".", "tm_sec", ",", "(", "int", ")", "tv", ".", "tv_usec", "/", "1000", ")", ";", "sprintf", "(", "deflvl", ",", "\"", "\"", ",", "(", "lvl", "&", "~", "L_CONS", ")", ")", ";", "s", "=", "_int2str", "(", "L", ",", "(", "lvl", "&", "~", "L_CONS", ")", ",", "deflvl", ")", ";", "len0", "=", "strlen", "(", "buffer", ")", ";", "strcat", "(", "buffer", ",", "s", ")", ";", "len", "=", "strlen", "(", "buffer", ")", ";", "}", "else", "{", "const", "char", "*", "s", ";", "time_t", "tv", ";", "struct", "tm", "local", ";", "char", "deflvl", "[", "8", "]", ";", "tv", "=", "time", "(", "NULL", ")", ";", "localtime_r", "(", "&", "tv", ",", "&", "local", ")", ";", "sprintf", "(", "buffer", ",", "\"", "\"", ",", "local", ".", "tm_year", "+", "1900", ",", "local", ".", "tm_mon", "+", "1", ",", "local", ".", "tm_mday", ",", "local", ".", "tm_hour", ",", "local", ".", "tm_min", ",", "local", ".", "tm_sec", ")", ";", "sprintf", "(", "deflvl", ",", "\"", "\"", ",", "(", "lvl", "&", "~", "L_CONS", ")", ")", ";", "s", "=", "_int2str", "(", "L", ",", "(", "lvl", "&", "~", "L_CONS", ")", ",", "deflvl", ")", ";", "len0", "=", "strlen", "(", "buffer", ")", ";", "strcat", "(", "buffer", ",", "s", ")", ";", "len", "=", "strlen", "(", "buffer", ")", ";", "}", "vsnprintf", "(", "buffer", "+", "len", ",", "sizeof", "(", "buffer", ")", "-", "len", "-", "1", ",", "fmt", ",", "ap", ")", ";", "buffer", "[", "sizeof", "(", "buffer", ")", "-", "2", "]", "=", "'", "\\0", "'", ";", "for", "(", "p", "=", "buffer", ";", "*", "p", "!=", "'", "\\0", "'", ";", "p", "++", ")", "{", "if", "(", "*", "p", "==", "'", "\\r", "'", "||", "*", "p", "==", "'", "\\n", "'", ")", "*", "p", "=", "'", "'", ";", "else", "if", "(", "(", "*", "p", ">=", "0", "&&", "*", "p", "<", "32", ")", "||", "(", "*", "p", "<", "0", ")", ")", "*", "p", "=", "'", "'", ";", "}", "strcat", "(", "buffer", ",", "\"", "\\n", "\"", ")", ";", "if", "(", "C", ".", "verbose", "==", "1", ")", "{", "p", "=", "buffer", "+", "len0", ";", "}", "else", "{", "p", "=", "buffer", ";", "}", "if", "(", "C", ".", "dest", "!=", "LOG_DEST_SYSLOG", ")", "{", "fputs", "(", "p", ",", "msgfd", ")", ";", "if", "(", "msgfd", "==", "stdout", ")", "{", "fflush", "(", "stdout", ")", ";", "}", "else", "if", "(", "msgfd", "==", "stderr", ")", "{", "fflush", "(", "stderr", ")", ";", "}", "else", "{", "fclose", "(", "msgfd", ")", ";", "if", "(", "lvl", "&", "L_CONS", ")", "{", "if", "(", "(", "lvl", "&", "~", "L_CONS", ")", "<", "L_WARN", ")", "{", "fputs", "(", "p", ",", "stdout", ")", ";", "fflush", "(", "stdout", ")", ";", "}", "else", "{", "fputs", "(", "p", ",", "stderr", ")", ";", "fflush", "(", "stderr", ")", ";", "}", "}", "else", "if", "(", "C", ".", "verbose", ")", "{", "if", "(", "(", "lvl", "&", "~", "L_CONS", ")", "<", "L_WARN", ")", "{", "fputs", "(", "p", ",", "stdout", ")", ";", "}", "else", "{", "fputs", "(", "p", ",", "stderr", ")", ";", "}", "}", "}", "}", "else", "{", "lvl", "=", "(", "lvl", "&", "~", "L_CONS", ")", ";", "if", "(", "lvl", ">", "0", "&&", "lvl", "<=", "L_DEBUG", ")", "{", "lvl", "=", "LOG_DEBUG", ";", "}", "else", "if", "(", "lvl", ">", "L_DEBUG", "&&", "lvl", "<=", "L_INFO", ")", "{", "lvl", "=", "LOG_NOTICE", ";", "}", "else", "if", "(", "lvl", ">", "L_INFO", "&&", "lvl", "<=", "L_WARN", ")", "{", "lvl", "=", "LOG_WARNING", ";", "}", "else", "if", "(", "lvl", ">", "L_WARN", "&&", "lvl", "<=", "L_ERROR", ")", "{", "lvl", "=", "LOG_ERR", ";", "}", "else", "if", "(", "lvl", ">", "L_ERROR", "&&", "lvl", "<=", "L_FATAL", ")", "{", "lvl", "=", "LOG_CRIT", ";", "}", "else", "if", "(", "lvl", ">", "L_FATAL", ")", "{", "lvl", "=", "LOG_ALERT", ";", "}", "else", "{", "lvl", "=", "LOG_EMERG", ";", "}", "syslog", "(", "lvl", ",", "\"", "\"", ",", "buffer", "+", "len0", ")", ";", "}", "return", "0", ";", "}" ]
Log the message to the logfile.
[ "Log", "the", "message", "to", "the", "logfile", "." ]
[ "/*\n * Filter out by level_hold\n */", "/*\n * NOT debugging, and trying to log debug messages.\n *\n * Throw the message away.\n */", "/*\n * If we don't want any messages, then\n * throw them away.\n */", "/*\n * No log file set. It must go to stdout.\n */", "/*\n * Else try to open the file.\n */", "/* the message that caused the log */", "/*\n * Filter out characters not in Latin-1.\n */", "/**p >= -128 &&*/", "/*\n * If we're debugging, for small values of debug, then\n * we don't do timestamps.\n */", "/*\n * No debugging, or lots of debugging. Print\n * the time stamps.\n */", "/*\n * IF debugging, also to console but no flush\n */", "/* it was syslog */", "/* don't print timestamp */" ]
[ { "param": "lvl", "type": "int" }, { "param": "fmt", "type": "char" }, { "param": "ap", "type": "va_list" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "lvl", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fmt", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ap", "type": "va_list", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
17691c50486fcb2f7f0480949c8d56de98caf0f0
AlanVieyra333/hiredispool
hiredispool.c
[ "Apache-2.0" ]
C
connect_single_socket
int
static int connect_single_socket(REDIS_SOCKET *redisocket, REDIS_INSTANCE *inst) { int i; redisContext* c; struct timeval timeout[2]; char *host; int port; DEBUG("%s: Attempting to connect #%d @%d", __func__, redisocket->id, redisocket->backup); /* convert timeout (ms) to timeval */ timeout[0].tv_sec = inst->config->connect_timeout / 1000; timeout[0].tv_usec = 1000 * (inst->config->connect_timeout % 1000); timeout[1].tv_sec = inst->config->net_readwrite_timeout / 1000; timeout[1].tv_usec = 1000 * (inst->config->net_readwrite_timeout % 1000); for (i = 0; i < inst->config->num_endpoints; i++) { /* * Get the target host and port from the backup index */ host = inst->config->endpoints[redisocket->backup].host; port = inst->config->endpoints[redisocket->backup].port; c = redisConnectWithTimeout(host, port, timeout[0]); if (c && c->err == 0) { DEBUG("%s: Connected new redis handle #%d @%d", __func__, redisocket->id, redisocket->backup); redisocket->conn = c; redisocket->state = sockconnected; if (inst->config->num_endpoints > 1) { /* Select the next _random_ endpoint as the new backup */ redisocket->backup = (redisocket->backup + (1 + rand() % (inst->config->num_endpoints - 1) )) % inst->config->num_endpoints; } if (redisSetTimeout(c, timeout[1]) != REDIS_OK) { log_(L_WARN|L_CONS, "%s: Failed to set timeout: blocking-mode: %d, %s", __func__, (c->flags & REDIS_BLOCK), c->errstr); } if (redisEnableKeepAlive(c) != REDIS_OK) { log_(L_WARN|L_CONS, "%s: Failed to enable keepalive: %s", __func__, c->errstr); } return 0; } /* We have tried the last one but still fail */ if (i == inst->config->num_endpoints - 1) break; /* We have more backups to try */ if (c) { log_(L_WARN|L_CONS, "%s: Failed to connect redis handle #%d @%d: %s, trying backup", __func__, redisocket->id, redisocket->backup, c->errstr); redisFree(c); } else { log_(L_WARN|L_CONS, "%s: can't allocate redis handle #%d @%d, trying backup", __func__, redisocket->id, redisocket->backup); } redisocket->backup = (redisocket->backup + 1) % inst->config->num_endpoints; } /* * Error, or SERVER_DOWN. */ if (c) { log_(L_WARN|L_CONS, "%s: Failed to connect redis handle #%d @%d: %s", __func__, redisocket->id, redisocket->backup, c->errstr); redisFree(c); } else { log_(L_WARN|L_CONS, "%s: can't allocate redis handle #%d @%d", __func__, redisocket->id, redisocket->backup); } redisocket->conn = NULL; redisocket->state = sockunconnected; redisocket->backup = (redisocket->backup + 1) % inst->config->num_endpoints; inst->connect_after = time(NULL) + inst->config->connect_failure_retry_delay; return -1; }
/* * Connect to a server. If error, set this socket's state to be * "sockunconnected" and set a grace period, during which we won't try * connecting again (to prevent unduly lagging the server and being * impolite to a server that may be having other issues). If * successful in connecting, set state to sockconnected. * - hh */
Connect to a server. If error, set this socket's state to be "sockunconnected" and set a grace period, during which we won't try connecting again (to prevent unduly lagging the server and being impolite to a server that may be having other issues). If successful in connecting, set state to sockconnected. - hh
[ "Connect", "to", "a", "server", ".", "If", "error", "set", "this", "socket", "'", "s", "state", "to", "be", "\"", "sockunconnected", "\"", "and", "set", "a", "grace", "period", "during", "which", "we", "won", "'", "t", "try", "connecting", "again", "(", "to", "prevent", "unduly", "lagging", "the", "server", "and", "being", "impolite", "to", "a", "server", "that", "may", "be", "having", "other", "issues", ")", ".", "If", "successful", "in", "connecting", "set", "state", "to", "sockconnected", ".", "-", "hh" ]
static int connect_single_socket(REDIS_SOCKET *redisocket, REDIS_INSTANCE *inst) { int i; redisContext* c; struct timeval timeout[2]; char *host; int port; DEBUG("%s: Attempting to connect #%d @%d", __func__, redisocket->id, redisocket->backup); timeout[0].tv_sec = inst->config->connect_timeout / 1000; timeout[0].tv_usec = 1000 * (inst->config->connect_timeout % 1000); timeout[1].tv_sec = inst->config->net_readwrite_timeout / 1000; timeout[1].tv_usec = 1000 * (inst->config->net_readwrite_timeout % 1000); for (i = 0; i < inst->config->num_endpoints; i++) { host = inst->config->endpoints[redisocket->backup].host; port = inst->config->endpoints[redisocket->backup].port; c = redisConnectWithTimeout(host, port, timeout[0]); if (c && c->err == 0) { DEBUG("%s: Connected new redis handle #%d @%d", __func__, redisocket->id, redisocket->backup); redisocket->conn = c; redisocket->state = sockconnected; if (inst->config->num_endpoints > 1) { redisocket->backup = (redisocket->backup + (1 + rand() % (inst->config->num_endpoints - 1) )) % inst->config->num_endpoints; } if (redisSetTimeout(c, timeout[1]) != REDIS_OK) { log_(L_WARN|L_CONS, "%s: Failed to set timeout: blocking-mode: %d, %s", __func__, (c->flags & REDIS_BLOCK), c->errstr); } if (redisEnableKeepAlive(c) != REDIS_OK) { log_(L_WARN|L_CONS, "%s: Failed to enable keepalive: %s", __func__, c->errstr); } return 0; } if (i == inst->config->num_endpoints - 1) break; if (c) { log_(L_WARN|L_CONS, "%s: Failed to connect redis handle #%d @%d: %s, trying backup", __func__, redisocket->id, redisocket->backup, c->errstr); redisFree(c); } else { log_(L_WARN|L_CONS, "%s: can't allocate redis handle #%d @%d, trying backup", __func__, redisocket->id, redisocket->backup); } redisocket->backup = (redisocket->backup + 1) % inst->config->num_endpoints; } if (c) { log_(L_WARN|L_CONS, "%s: Failed to connect redis handle #%d @%d: %s", __func__, redisocket->id, redisocket->backup, c->errstr); redisFree(c); } else { log_(L_WARN|L_CONS, "%s: can't allocate redis handle #%d @%d", __func__, redisocket->id, redisocket->backup); } redisocket->conn = NULL; redisocket->state = sockunconnected; redisocket->backup = (redisocket->backup + 1) % inst->config->num_endpoints; inst->connect_after = time(NULL) + inst->config->connect_failure_retry_delay; return -1; }
[ "static", "int", "connect_single_socket", "(", "REDIS_SOCKET", "*", "redisocket", ",", "REDIS_INSTANCE", "*", "inst", ")", "{", "int", "i", ";", "redisContext", "*", "c", ";", "struct", "timeval", "timeout", "[", "2", "]", ";", "char", "*", "host", ";", "int", "port", ";", "DEBUG", "(", "\"", "\"", ",", "__func__", ",", "redisocket", "->", "id", ",", "redisocket", "->", "backup", ")", ";", "timeout", "[", "0", "]", ".", "tv_sec", "=", "inst", "->", "config", "->", "connect_timeout", "/", "1000", ";", "timeout", "[", "0", "]", ".", "tv_usec", "=", "1000", "*", "(", "inst", "->", "config", "->", "connect_timeout", "%", "1000", ")", ";", "timeout", "[", "1", "]", ".", "tv_sec", "=", "inst", "->", "config", "->", "net_readwrite_timeout", "/", "1000", ";", "timeout", "[", "1", "]", ".", "tv_usec", "=", "1000", "*", "(", "inst", "->", "config", "->", "net_readwrite_timeout", "%", "1000", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "inst", "->", "config", "->", "num_endpoints", ";", "i", "++", ")", "{", "host", "=", "inst", "->", "config", "->", "endpoints", "[", "redisocket", "->", "backup", "]", ".", "host", ";", "port", "=", "inst", "->", "config", "->", "endpoints", "[", "redisocket", "->", "backup", "]", ".", "port", ";", "c", "=", "redisConnectWithTimeout", "(", "host", ",", "port", ",", "timeout", "[", "0", "]", ")", ";", "if", "(", "c", "&&", "c", "->", "err", "==", "0", ")", "{", "DEBUG", "(", "\"", "\"", ",", "__func__", ",", "redisocket", "->", "id", ",", "redisocket", "->", "backup", ")", ";", "redisocket", "->", "conn", "=", "c", ";", "redisocket", "->", "state", "=", "sockconnected", ";", "if", "(", "inst", "->", "config", "->", "num_endpoints", ">", "1", ")", "{", "redisocket", "->", "backup", "=", "(", "redisocket", "->", "backup", "+", "(", "1", "+", "rand", "(", ")", "%", "(", "inst", "->", "config", "->", "num_endpoints", "-", "1", ")", ")", ")", "%", "inst", "->", "config", "->", "num_endpoints", ";", "}", "if", "(", "redisSetTimeout", "(", "c", ",", "timeout", "[", "1", "]", ")", "!=", "REDIS_OK", ")", "{", "log_", "(", "L_WARN", "|", "L_CONS", ",", "\"", "\"", ",", "__func__", ",", "(", "c", "->", "flags", "&", "REDIS_BLOCK", ")", ",", "c", "->", "errstr", ")", ";", "}", "if", "(", "redisEnableKeepAlive", "(", "c", ")", "!=", "REDIS_OK", ")", "{", "log_", "(", "L_WARN", "|", "L_CONS", ",", "\"", "\"", ",", "__func__", ",", "c", "->", "errstr", ")", ";", "}", "return", "0", ";", "}", "if", "(", "i", "==", "inst", "->", "config", "->", "num_endpoints", "-", "1", ")", "break", ";", "if", "(", "c", ")", "{", "log_", "(", "L_WARN", "|", "L_CONS", ",", "\"", "\"", ",", "__func__", ",", "redisocket", "->", "id", ",", "redisocket", "->", "backup", ",", "c", "->", "errstr", ")", ";", "redisFree", "(", "c", ")", ";", "}", "else", "{", "log_", "(", "L_WARN", "|", "L_CONS", ",", "\"", "\"", ",", "__func__", ",", "redisocket", "->", "id", ",", "redisocket", "->", "backup", ")", ";", "}", "redisocket", "->", "backup", "=", "(", "redisocket", "->", "backup", "+", "1", ")", "%", "inst", "->", "config", "->", "num_endpoints", ";", "}", "if", "(", "c", ")", "{", "log_", "(", "L_WARN", "|", "L_CONS", ",", "\"", "\"", ",", "__func__", ",", "redisocket", "->", "id", ",", "redisocket", "->", "backup", ",", "c", "->", "errstr", ")", ";", "redisFree", "(", "c", ")", ";", "}", "else", "{", "log_", "(", "L_WARN", "|", "L_CONS", ",", "\"", "\"", ",", "__func__", ",", "redisocket", "->", "id", ",", "redisocket", "->", "backup", ")", ";", "}", "redisocket", "->", "conn", "=", "NULL", ";", "redisocket", "->", "state", "=", "sockunconnected", ";", "redisocket", "->", "backup", "=", "(", "redisocket", "->", "backup", "+", "1", ")", "%", "inst", "->", "config", "->", "num_endpoints", ";", "inst", "->", "connect_after", "=", "time", "(", "NULL", ")", "+", "inst", "->", "config", "->", "connect_failure_retry_delay", ";", "return", "-1", ";", "}" ]
Connect to a server.
[ "Connect", "to", "a", "server", "." ]
[ "/* convert timeout (ms) to timeval */", "/*\n * Get the target host and port from the backup index\n */", "/* Select the next _random_ endpoint as the new backup */", "/* We have tried the last one but still fail */", "/* We have more backups to try */", "/*\n * Error, or SERVER_DOWN.\n */" ]
[ { "param": "redisocket", "type": "REDIS_SOCKET" }, { "param": "inst", "type": "REDIS_INSTANCE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "redisocket", "type": "REDIS_SOCKET", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "inst", "type": "REDIS_INSTANCE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5aaf6815337c0f46710395192df4a0548bbb31d6
hugllc/HUGESP32IOBoard
HUGESP32IOBoard.h
[ "MIT" ]
C
voltageRead
uint16_t
static inline uint16_t voltageRead(void) { if (port < OUTPUT_PORTS) { return analogRead(VSENSE); } return 0; }
/** * @brief This reads the voltage on the +V Pins * * @return The ADC read of the voltage on the port */
@brief This reads the voltage on the +V Pins @return The ADC read of the voltage on the port
[ "@brief", "This", "reads", "the", "voltage", "on", "the", "+", "V", "Pins", "@return", "The", "ADC", "read", "of", "the", "voltage", "on", "the", "port" ]
static inline uint16_t voltageRead(void) { if (port < OUTPUT_PORTS) { return analogRead(VSENSE); } return 0; }
[ "static", "inline", "uint16_t", "voltageRead", "(", "void", ")", "{", "if", "(", "port", "<", "OUTPUT_PORTS", ")", "{", "return", "analogRead", "(", "VSENSE", ")", ";", "}", "return", "0", ";", "}" ]
@brief This reads the voltage on the +V Pins
[ "@brief", "This", "reads", "the", "voltage", "on", "the", "+", "V", "Pins" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
317f2a30e7340fe1112eb5770aa8e2e88e39d564
Steel46/shadow
src/plugin/shadow-plugin-tgen/shd-tgen-markovmodel.c
[ "BSD-3-Clause" ]
C
_tgenmarkovmodel_findVertexAttributeString
gboolean
static gboolean _tgenmarkovmodel_findVertexAttributeString(TGenMarkovModel* mmodel, igraph_integer_t vertexIndex, VertexAttribute attr, const gchar** valueOut) { TGEN_ASSERT(mmodel); const gchar* name = _tgenmarkovmodel_vertexAttributeToString(attr); if(igraph_cattribute_has_attr(mmodel->graph, IGRAPH_ATTRIBUTE_VERTEX, name)) { const gchar* value = igraph_cattribute_VAS(mmodel->graph, name, vertexIndex); if(value != NULL && value[0] != '\0') { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
/* if the value is found and not NULL, it's value is returned in valueOut. * returns true if valueOut has been set, false otherwise */
if the value is found and not NULL, it's value is returned in valueOut. returns true if valueOut has been set, false otherwise
[ "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", ".", "returns", "true", "if", "valueOut", "has", "been", "set", "false", "otherwise" ]
static gboolean _tgenmarkovmodel_findVertexAttributeString(TGenMarkovModel* mmodel, igraph_integer_t vertexIndex, VertexAttribute attr, const gchar** valueOut) { TGEN_ASSERT(mmodel); const gchar* name = _tgenmarkovmodel_vertexAttributeToString(attr); if(igraph_cattribute_has_attr(mmodel->graph, IGRAPH_ATTRIBUTE_VERTEX, name)) { const gchar* value = igraph_cattribute_VAS(mmodel->graph, name, vertexIndex); if(value != NULL && value[0] != '\0') { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
[ "static", "gboolean", "_tgenmarkovmodel_findVertexAttributeString", "(", "TGenMarkovModel", "*", "mmodel", ",", "igraph_integer_t", "vertexIndex", ",", "VertexAttribute", "attr", ",", "const", "gchar", "*", "*", "valueOut", ")", "{", "TGEN_ASSERT", "(", "mmodel", ")", ";", "const", "gchar", "*", "name", "=", "_tgenmarkovmodel_vertexAttributeToString", "(", "attr", ")", ";", "if", "(", "igraph_cattribute_has_attr", "(", "mmodel", "->", "graph", ",", "IGRAPH_ATTRIBUTE_VERTEX", ",", "name", ")", ")", "{", "const", "gchar", "*", "value", "=", "igraph_cattribute_VAS", "(", "mmodel", "->", "graph", ",", "name", ",", "vertexIndex", ")", ";", "if", "(", "value", "!=", "NULL", "&&", "value", "[", "0", "]", "!=", "'", "\\0", "'", ")", "{", "if", "(", "valueOut", "!=", "NULL", ")", "{", "*", "valueOut", "=", "value", ";", "return", "TRUE", ";", "}", "}", "}", "return", "FALSE", ";", "}" ]
if the value is found and not NULL, it's value is returned in valueOut.
[ "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", "." ]
[]
[ { "param": "mmodel", "type": "TGenMarkovModel" }, { "param": "vertexIndex", "type": "igraph_integer_t" }, { "param": "attr", "type": "VertexAttribute" }, { "param": "valueOut", "type": "gchar" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mmodel", "type": "TGenMarkovModel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vertexIndex", "type": "igraph_integer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "attr", "type": "VertexAttribute", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "valueOut", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
317f2a30e7340fe1112eb5770aa8e2e88e39d564
Steel46/shadow
src/plugin/shadow-plugin-tgen/shd-tgen-markovmodel.c
[ "BSD-3-Clause" ]
C
_tgenmarkovmodel_findEdgeAttributeDouble
gboolean
static gboolean _tgenmarkovmodel_findEdgeAttributeDouble(TGenMarkovModel* mmodel, igraph_integer_t edgeIndex, EdgeAttribute attr, gdouble* valueOut) { TGEN_ASSERT(mmodel); const gchar* name = _tgenmarkovmodel_edgeAttributeToString(attr); if(igraph_cattribute_has_attr(mmodel->graph, IGRAPH_ATTRIBUTE_EDGE, name)) { gdouble value = (gdouble) igraph_cattribute_EAN(mmodel->graph, name, edgeIndex); if(isnan(value) == 0) { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
/* if the value is found and not NULL, it's value is returned in valueOut. * returns true if valueOut has been set, false otherwise */
if the value is found and not NULL, it's value is returned in valueOut. returns true if valueOut has been set, false otherwise
[ "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", ".", "returns", "true", "if", "valueOut", "has", "been", "set", "false", "otherwise" ]
static gboolean _tgenmarkovmodel_findEdgeAttributeDouble(TGenMarkovModel* mmodel, igraph_integer_t edgeIndex, EdgeAttribute attr, gdouble* valueOut) { TGEN_ASSERT(mmodel); const gchar* name = _tgenmarkovmodel_edgeAttributeToString(attr); if(igraph_cattribute_has_attr(mmodel->graph, IGRAPH_ATTRIBUTE_EDGE, name)) { gdouble value = (gdouble) igraph_cattribute_EAN(mmodel->graph, name, edgeIndex); if(isnan(value) == 0) { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
[ "static", "gboolean", "_tgenmarkovmodel_findEdgeAttributeDouble", "(", "TGenMarkovModel", "*", "mmodel", ",", "igraph_integer_t", "edgeIndex", ",", "EdgeAttribute", "attr", ",", "gdouble", "*", "valueOut", ")", "{", "TGEN_ASSERT", "(", "mmodel", ")", ";", "const", "gchar", "*", "name", "=", "_tgenmarkovmodel_edgeAttributeToString", "(", "attr", ")", ";", "if", "(", "igraph_cattribute_has_attr", "(", "mmodel", "->", "graph", ",", "IGRAPH_ATTRIBUTE_EDGE", ",", "name", ")", ")", "{", "gdouble", "value", "=", "(", "gdouble", ")", "igraph_cattribute_EAN", "(", "mmodel", "->", "graph", ",", "name", ",", "edgeIndex", ")", ";", "if", "(", "isnan", "(", "value", ")", "==", "0", ")", "{", "if", "(", "valueOut", "!=", "NULL", ")", "{", "*", "valueOut", "=", "value", ";", "return", "TRUE", ";", "}", "}", "}", "return", "FALSE", ";", "}" ]
if the value is found and not NULL, it's value is returned in valueOut.
[ "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", "." ]
[]
[ { "param": "mmodel", "type": "TGenMarkovModel" }, { "param": "edgeIndex", "type": "igraph_integer_t" }, { "param": "attr", "type": "EdgeAttribute" }, { "param": "valueOut", "type": "gdouble" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mmodel", "type": "TGenMarkovModel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "edgeIndex", "type": "igraph_integer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "attr", "type": "EdgeAttribute", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "valueOut", "type": "gdouble", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
317f2a30e7340fe1112eb5770aa8e2e88e39d564
Steel46/shadow
src/plugin/shadow-plugin-tgen/shd-tgen-markovmodel.c
[ "BSD-3-Clause" ]
C
_tgenmarkovmodel_findEdgeAttributeString
gboolean
static gboolean _tgenmarkovmodel_findEdgeAttributeString(TGenMarkovModel* mmodel, igraph_integer_t edgeIndex, EdgeAttribute attr, const gchar** valueOut) { TGEN_ASSERT(mmodel); const gchar* name = _tgenmarkovmodel_edgeAttributeToString(attr); if(igraph_cattribute_has_attr(mmodel->graph, IGRAPH_ATTRIBUTE_EDGE, name)) { const gchar* value = igraph_cattribute_EAS(mmodel->graph, name, edgeIndex); if(value != NULL && value[0] != '\0') { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
/* if the value is found and not NULL, it's value is returned in valueOut. * returns true if valueOut has been set, false otherwise */
if the value is found and not NULL, it's value is returned in valueOut. returns true if valueOut has been set, false otherwise
[ "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", ".", "returns", "true", "if", "valueOut", "has", "been", "set", "false", "otherwise" ]
static gboolean _tgenmarkovmodel_findEdgeAttributeString(TGenMarkovModel* mmodel, igraph_integer_t edgeIndex, EdgeAttribute attr, const gchar** valueOut) { TGEN_ASSERT(mmodel); const gchar* name = _tgenmarkovmodel_edgeAttributeToString(attr); if(igraph_cattribute_has_attr(mmodel->graph, IGRAPH_ATTRIBUTE_EDGE, name)) { const gchar* value = igraph_cattribute_EAS(mmodel->graph, name, edgeIndex); if(value != NULL && value[0] != '\0') { if(valueOut != NULL) { *valueOut = value; return TRUE; } } } return FALSE; }
[ "static", "gboolean", "_tgenmarkovmodel_findEdgeAttributeString", "(", "TGenMarkovModel", "*", "mmodel", ",", "igraph_integer_t", "edgeIndex", ",", "EdgeAttribute", "attr", ",", "const", "gchar", "*", "*", "valueOut", ")", "{", "TGEN_ASSERT", "(", "mmodel", ")", ";", "const", "gchar", "*", "name", "=", "_tgenmarkovmodel_edgeAttributeToString", "(", "attr", ")", ";", "if", "(", "igraph_cattribute_has_attr", "(", "mmodel", "->", "graph", ",", "IGRAPH_ATTRIBUTE_EDGE", ",", "name", ")", ")", "{", "const", "gchar", "*", "value", "=", "igraph_cattribute_EAS", "(", "mmodel", "->", "graph", ",", "name", ",", "edgeIndex", ")", ";", "if", "(", "value", "!=", "NULL", "&&", "value", "[", "0", "]", "!=", "'", "\\0", "'", ")", "{", "if", "(", "valueOut", "!=", "NULL", ")", "{", "*", "valueOut", "=", "value", ";", "return", "TRUE", ";", "}", "}", "}", "return", "FALSE", ";", "}" ]
if the value is found and not NULL, it's value is returned in valueOut.
[ "if", "the", "value", "is", "found", "and", "not", "NULL", "it", "'", "s", "value", "is", "returned", "in", "valueOut", "." ]
[]
[ { "param": "mmodel", "type": "TGenMarkovModel" }, { "param": "edgeIndex", "type": "igraph_integer_t" }, { "param": "attr", "type": "EdgeAttribute" }, { "param": "valueOut", "type": "gchar" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mmodel", "type": "TGenMarkovModel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "edgeIndex", "type": "igraph_integer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "attr", "type": "EdgeAttribute", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "valueOut", "type": "gchar", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b70e526ebdbabf1873c367e352ed08fd601eb74
Steel46/shadow
src/plugin/shadow-plugin-tgen/shd-tgen-timer.c
[ "BSD-3-Clause" ]
C
tgentimer_settime_micros
void
void tgentimer_settime_micros(TGenTimer *timer, guint64 micros) { TGEN_ASSERT(timer); struct itimerspec arm; guint64 seconds = micros / 1000000; guint64 nanoseconds = (micros % 1000000) * 1000; arm.it_value.tv_sec = seconds; arm.it_value.tv_nsec = nanoseconds; if (timer->isPersistent) { arm.it_interval.tv_sec = seconds; arm.it_interval.tv_nsec = nanoseconds; } else { arm.it_interval.tv_sec = 0; arm.it_interval.tv_nsec = 0; } gint result = timerfd_settime(timer->timerD, 0, &arm, NULL); if (result < 0) { tgen_critical("timerfd_settime(): returned %i error %i: %s", result, errno, g_strerror(errno)); return; } }
/** Sets the timer to go off in the given number of microseconds. If the timer * is persistent, then configure it to continue going off at the new interval. */
Sets the timer to go off in the given number of microseconds. If the timer is persistent, then configure it to continue going off at the new interval.
[ "Sets", "the", "timer", "to", "go", "off", "in", "the", "given", "number", "of", "microseconds", ".", "If", "the", "timer", "is", "persistent", "then", "configure", "it", "to", "continue", "going", "off", "at", "the", "new", "interval", "." ]
void tgentimer_settime_micros(TGenTimer *timer, guint64 micros) { TGEN_ASSERT(timer); struct itimerspec arm; guint64 seconds = micros / 1000000; guint64 nanoseconds = (micros % 1000000) * 1000; arm.it_value.tv_sec = seconds; arm.it_value.tv_nsec = nanoseconds; if (timer->isPersistent) { arm.it_interval.tv_sec = seconds; arm.it_interval.tv_nsec = nanoseconds; } else { arm.it_interval.tv_sec = 0; arm.it_interval.tv_nsec = 0; } gint result = timerfd_settime(timer->timerD, 0, &arm, NULL); if (result < 0) { tgen_critical("timerfd_settime(): returned %i error %i: %s", result, errno, g_strerror(errno)); return; } }
[ "void", "tgentimer_settime_micros", "(", "TGenTimer", "*", "timer", ",", "guint64", "micros", ")", "{", "TGEN_ASSERT", "(", "timer", ")", ";", "struct", "itimerspec", "arm", ";", "guint64", "seconds", "=", "micros", "/", "1000000", ";", "guint64", "nanoseconds", "=", "(", "micros", "%", "1000000", ")", "*", "1000", ";", "arm", ".", "it_value", ".", "tv_sec", "=", "seconds", ";", "arm", ".", "it_value", ".", "tv_nsec", "=", "nanoseconds", ";", "if", "(", "timer", "->", "isPersistent", ")", "{", "arm", ".", "it_interval", ".", "tv_sec", "=", "seconds", ";", "arm", ".", "it_interval", ".", "tv_nsec", "=", "nanoseconds", ";", "}", "else", "{", "arm", ".", "it_interval", ".", "tv_sec", "=", "0", ";", "arm", ".", "it_interval", ".", "tv_nsec", "=", "0", ";", "}", "gint", "result", "=", "timerfd_settime", "(", "timer", "->", "timerD", ",", "0", ",", "&", "arm", ",", "NULL", ")", ";", "if", "(", "result", "<", "0", ")", "{", "tgen_critical", "(", "\"", "\"", ",", "result", ",", "errno", ",", "g_strerror", "(", "errno", ")", ")", ";", "return", ";", "}", "}" ]
Sets the timer to go off in the given number of microseconds.
[ "Sets", "the", "timer", "to", "go", "off", "in", "the", "given", "number", "of", "microseconds", "." ]
[]
[ { "param": "timer", "type": "TGenTimer" }, { "param": "micros", "type": "guint64" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "timer", "type": "TGenTimer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "micros", "type": "guint64", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2794acb72577de8b1ff971705a2afa677dc3a122
Steel46/shadow
src/main/core/shd-worker.c
[ "BSD-3-Clause" ]
C
worker_run
gpointer
gpointer worker_run(WorkerRunData* data) { utility_assert(data && data->userData && data->scheduler); /* create the worker object for this worker thread */ Worker* worker = _worker_new((Slave*)data->userData, data->threadID); utility_assert(worker_isAlive()); worker->scheduler = data->scheduler; scheduler_ref(worker->scheduler); /* wait until the slave is done with initialization */ scheduler_awaitStart(worker->scheduler); /* ask the slave for the next event, blocking until one is available that * we are allowed to run. when this returns NULL, we should stop. */ Event* event = NULL; while((event = scheduler_pop(worker->scheduler)) != NULL) { /* update cache, reset clocks */ worker->clock.now = event_getTime(event); /* process the local event */ event_execute(event); event_unref(event); /* update times */ worker->clock.last = worker->clock.now; worker->clock.now = SIMTIME_INVALID; } /* this will free the host data that we have been managing */ scheduler_awaitFinish(worker->scheduler); scheduler_unref(worker->scheduler); /* tell that we are done running */ if(data->notifyDoneRunning) { countdownlatch_countDown(data->notifyDoneRunning); } /* wait for other cleanup to finish */ if(data->notifyReadyToJoin) { countdownlatch_await(data->notifyReadyToJoin); } /* cleanup is all done, send object counts to slave */ slave_storeCounts(worker->slave, worker->objectCounts); /* synchronize thread join */ CountDownLatch* notifyJoined = data->notifyJoined; /* this is a hack so that we don't free the worker before the scheduler is * finished with object cleanup when running in global mode. * normally, the if statement would not be necessary and we just free * the worker in all cases. */ if(notifyJoined) { _worker_free(worker); g_free(data); } /* now the thread has ended */ if(notifyJoined) { countdownlatch_countDown(notifyJoined); } /* calling pthread_exit(NULL) is equivalent to returning NULL for spawned threads * returning NULL means we don't have to worry about calling pthread_exit on the main thread */ return NULL; }
/* this is the entry point for worker threads when running in parallel mode, * and otherwise is the main event loop when running in serial mode */
this is the entry point for worker threads when running in parallel mode, and otherwise is the main event loop when running in serial mode
[ "this", "is", "the", "entry", "point", "for", "worker", "threads", "when", "running", "in", "parallel", "mode", "and", "otherwise", "is", "the", "main", "event", "loop", "when", "running", "in", "serial", "mode" ]
gpointer worker_run(WorkerRunData* data) { utility_assert(data && data->userData && data->scheduler); Worker* worker = _worker_new((Slave*)data->userData, data->threadID); utility_assert(worker_isAlive()); worker->scheduler = data->scheduler; scheduler_ref(worker->scheduler); scheduler_awaitStart(worker->scheduler); Event* event = NULL; while((event = scheduler_pop(worker->scheduler)) != NULL) { worker->clock.now = event_getTime(event); event_execute(event); event_unref(event); worker->clock.last = worker->clock.now; worker->clock.now = SIMTIME_INVALID; } scheduler_awaitFinish(worker->scheduler); scheduler_unref(worker->scheduler); if(data->notifyDoneRunning) { countdownlatch_countDown(data->notifyDoneRunning); } if(data->notifyReadyToJoin) { countdownlatch_await(data->notifyReadyToJoin); } slave_storeCounts(worker->slave, worker->objectCounts); CountDownLatch* notifyJoined = data->notifyJoined; if(notifyJoined) { _worker_free(worker); g_free(data); } if(notifyJoined) { countdownlatch_countDown(notifyJoined); } return NULL; }
[ "gpointer", "worker_run", "(", "WorkerRunData", "*", "data", ")", "{", "utility_assert", "(", "data", "&&", "data", "->", "userData", "&&", "data", "->", "scheduler", ")", ";", "Worker", "*", "worker", "=", "_worker_new", "(", "(", "Slave", "*", ")", "data", "->", "userData", ",", "data", "->", "threadID", ")", ";", "utility_assert", "(", "worker_isAlive", "(", ")", ")", ";", "worker", "->", "scheduler", "=", "data", "->", "scheduler", ";", "scheduler_ref", "(", "worker", "->", "scheduler", ")", ";", "scheduler_awaitStart", "(", "worker", "->", "scheduler", ")", ";", "Event", "*", "event", "=", "NULL", ";", "while", "(", "(", "event", "=", "scheduler_pop", "(", "worker", "->", "scheduler", ")", ")", "!=", "NULL", ")", "{", "worker", "->", "clock", ".", "now", "=", "event_getTime", "(", "event", ")", ";", "event_execute", "(", "event", ")", ";", "event_unref", "(", "event", ")", ";", "worker", "->", "clock", ".", "last", "=", "worker", "->", "clock", ".", "now", ";", "worker", "->", "clock", ".", "now", "=", "SIMTIME_INVALID", ";", "}", "scheduler_awaitFinish", "(", "worker", "->", "scheduler", ")", ";", "scheduler_unref", "(", "worker", "->", "scheduler", ")", ";", "if", "(", "data", "->", "notifyDoneRunning", ")", "{", "countdownlatch_countDown", "(", "data", "->", "notifyDoneRunning", ")", ";", "}", "if", "(", "data", "->", "notifyReadyToJoin", ")", "{", "countdownlatch_await", "(", "data", "->", "notifyReadyToJoin", ")", ";", "}", "slave_storeCounts", "(", "worker", "->", "slave", ",", "worker", "->", "objectCounts", ")", ";", "CountDownLatch", "*", "notifyJoined", "=", "data", "->", "notifyJoined", ";", "if", "(", "notifyJoined", ")", "{", "_worker_free", "(", "worker", ")", ";", "g_free", "(", "data", ")", ";", "}", "if", "(", "notifyJoined", ")", "{", "countdownlatch_countDown", "(", "notifyJoined", ")", ";", "}", "return", "NULL", ";", "}" ]
this is the entry point for worker threads when running in parallel mode, and otherwise is the main event loop when running in serial mode
[ "this", "is", "the", "entry", "point", "for", "worker", "threads", "when", "running", "in", "parallel", "mode", "and", "otherwise", "is", "the", "main", "event", "loop", "when", "running", "in", "serial", "mode" ]
[ "/* create the worker object for this worker thread */", "/* wait until the slave is done with initialization */", "/* ask the slave for the next event, blocking until one is available that\n * we are allowed to run. when this returns NULL, we should stop. */", "/* update cache, reset clocks */", "/* process the local event */", "/* update times */", "/* this will free the host data that we have been managing */", "/* tell that we are done running */", "/* wait for other cleanup to finish */", "/* cleanup is all done, send object counts to slave */", "/* synchronize thread join */", "/* this is a hack so that we don't free the worker before the scheduler is\n * finished with object cleanup when running in global mode.\n * normally, the if statement would not be necessary and we just free\n * the worker in all cases. */", "/* now the thread has ended */", "/* calling pthread_exit(NULL) is equivalent to returning NULL for spawned threads\n * returning NULL means we don't have to worry about calling pthread_exit on the main thread */" ]
[ { "param": "data", "type": "WorkerRunData" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "WorkerRunData", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }