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
de8617211637425764b615f058550899e06dc569
timonsku/mes-final-project
samd21-afe/samd21-afe/usb_start.c
[ "BSD-3-Clause" ]
C
usb_device_cb_bulk_out
bool
static bool usb_device_cb_bulk_out(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) { cdcdf_acm_write((uint8_t *)usbd_cdc_buffer, count); /* No error. */ return false; }
/** * \brief Callback invoked when bulk OUT data received */
\brief Callback invoked when bulk OUT data received
[ "\\", "brief", "Callback", "invoked", "when", "bulk", "OUT", "data", "received" ]
static bool usb_device_cb_bulk_out(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) { cdcdf_acm_write((uint8_t *)usbd_cdc_buffer, count); return false; }
[ "static", "bool", "usb_device_cb_bulk_out", "(", "const", "uint8_t", "ep", ",", "const", "enum", "usb_xfer_code", "rc", ",", "const", "uint32_t", "count", ")", "{", "cdcdf_acm_write", "(", "(", "uint8_t", "*", ")", "usbd_cdc_buffer", ",", "count", ")", ";", "return", "false", ";", "}" ]
\brief Callback invoked when bulk OUT data received
[ "\\", "brief", "Callback", "invoked", "when", "bulk", "OUT", "data", "received" ]
[ "/* No error. */" ]
[ { "param": "ep", "type": "uint8_t" }, { "param": "rc", "type": "enum usb_xfer_code" }, { "param": "count", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ep", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rc", "type": "enum usb_xfer_code", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "count", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
de8617211637425764b615f058550899e06dc569
timonsku/mes-final-project
samd21-afe/samd21-afe/usb_start.c
[ "BSD-3-Clause" ]
C
usb_device_cb_bulk_in
bool
static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) { /* Echo data. */ cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer)); /* No error. */ return false; }
/** * \brief Callback invoked when bulk IN data received */
\brief Callback invoked when bulk IN data received
[ "\\", "brief", "Callback", "invoked", "when", "bulk", "IN", "data", "received" ]
static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) { cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer)); return false; }
[ "static", "bool", "usb_device_cb_bulk_in", "(", "const", "uint8_t", "ep", ",", "const", "enum", "usb_xfer_code", "rc", ",", "const", "uint32_t", "count", ")", "{", "cdcdf_acm_read", "(", "(", "uint8_t", "*", ")", "usbd_cdc_buffer", ",", "sizeof", "(", "usbd_cdc_buffer", ")", ")", ";", "return", "false", ";", "}" ]
\brief Callback invoked when bulk IN data received
[ "\\", "brief", "Callback", "invoked", "when", "bulk", "IN", "data", "received" ]
[ "/* Echo data. */", "/* No error. */" ]
[ { "param": "ep", "type": "uint8_t" }, { "param": "rc", "type": "enum usb_xfer_code" }, { "param": "count", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ep", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rc", "type": "enum usb_xfer_code", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "count", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
de8617211637425764b615f058550899e06dc569
timonsku/mes-final-project
samd21-afe/samd21-afe/usb_start.c
[ "BSD-3-Clause" ]
C
usb_device_cb_state_c
bool
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state) { if (state.rs232.DTR) { /* Callbacks must be registered after endpoint allocation */ cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out); cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in); /* Start Rx */ cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer)); } /* No error. */ return false; }
/** * \brief Callback invoked when Line State Change */
\brief Callback invoked when Line State Change
[ "\\", "brief", "Callback", "invoked", "when", "Line", "State", "Change" ]
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state) { if (state.rs232.DTR) { cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out); cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in); cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer)); } return false; }
[ "static", "bool", "usb_device_cb_state_c", "(", "usb_cdc_control_signal_t", "state", ")", "{", "if", "(", "state", ".", "rs232", ".", "DTR", ")", "{", "cdcdf_acm_register_callback", "(", "CDCDF_ACM_CB_READ", ",", "(", "FUNC_PTR", ")", "usb_device_cb_bulk_out", ")", ";", "cdcdf_acm_register_callback", "(", "CDCDF_ACM_CB_WRITE", ",", "(", "FUNC_PTR", ")", "usb_device_cb_bulk_in", ")", ";", "cdcdf_acm_read", "(", "(", "uint8_t", "*", ")", "usbd_cdc_buffer", ",", "sizeof", "(", "usbd_cdc_buffer", ")", ")", ";", "}", "return", "false", ";", "}" ]
\brief Callback invoked when Line State Change
[ "\\", "brief", "Callback", "invoked", "when", "Line", "State", "Change" ]
[ "/* Callbacks must be registered after endpoint allocation */", "/* Start Rx */", "/* No error. */" ]
[ { "param": "state", "type": "usb_cdc_control_signal_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "state", "type": "usb_cdc_control_signal_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
de8617211637425764b615f058550899e06dc569
timonsku/mes-final-project
samd21-afe/samd21-afe/usb_start.c
[ "BSD-3-Clause" ]
C
cdcd_acm_example
void
void cdcd_acm_example(void) { while (!cdcdf_acm_is_enabled()) { // wait cdc acm to be installed }; cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c); while (1) { } }
/** * Example of using CDC ACM Function. * \note * In this example, we will use a PC as a USB host: * - Connect the DEBUG USB on XPLAINED board to PC for program download. * - Connect the TARGET USB on XPLAINED board to PC for running program. * The application will behave as a virtual COM. * - Open a HyperTerminal or other COM tools in PC side. * - Send out a character or string and it will echo the content received. */
Example of using CDC ACM Function. \note In this example, we will use a PC as a USB host: - Connect the DEBUG USB on XPLAINED board to PC for program download.
[ "Example", "of", "using", "CDC", "ACM", "Function", ".", "\\", "note", "In", "this", "example", "we", "will", "use", "a", "PC", "as", "a", "USB", "host", ":", "-", "Connect", "the", "DEBUG", "USB", "on", "XPLAINED", "board", "to", "PC", "for", "program", "download", "." ]
void cdcd_acm_example(void) { while (!cdcdf_acm_is_enabled()) { }; cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c); while (1) { } }
[ "void", "cdcd_acm_example", "(", "void", ")", "{", "while", "(", "!", "cdcdf_acm_is_enabled", "(", ")", ")", "{", "}", ";", "cdcdf_acm_register_callback", "(", "CDCDF_ACM_CB_STATE_C", ",", "(", "FUNC_PTR", ")", "usb_device_cb_state_c", ")", ";", "while", "(", "1", ")", "{", "}", "}" ]
Example of using CDC ACM Function.
[ "Example", "of", "using", "CDC", "ACM", "Function", "." ]
[ "// wait cdc acm to be installed" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8e84a61730257ccd667291ccd26371e8b762d374
Robert-Stackflow/HUST-Courses
05_Principles of Imperative Computation/Courseware/18-mem/code/bst.c
[ "MIT" ]
C
tree_insert
tree
tree *tree_insert(tree *T, elem e) //@requires is_ordtree(T); //@requires e != NULL; //@ensures is_ordtree(\result); { REQUIRES(is_ordtree(T)); REQUIRES(e != NULL); if (T == NULL) { /* create new node and return it */ T = xmalloc(sizeof(struct tree_node)); T->data = e; T->left = NULL; T->right = NULL; ENSURES(is_ordtree(T)); return T; } int r = key_compare(elem_key(e), elem_key(T->data)); if (r == 0) { elem_free(T->data); T->data = e; /* modify in place */ } else if (r < 0) T->left = tree_insert(T->left, e); else //@assert r > 0; T->right = tree_insert(T->right, e); ENSURES(is_ordtree(T)); return T; }
/* tree_insert(T, e) returns the modified tree * this avoids some complications in case T = NULL */
tree_insert(T, e) returns the modified tree this avoids some complications in case T = NULL
[ "tree_insert", "(", "T", "e", ")", "returns", "the", "modified", "tree", "this", "avoids", "some", "complications", "in", "case", "T", "=", "NULL" ]
tree *tree_insert(tree *T, elem e) { REQUIRES(is_ordtree(T)); REQUIRES(e != NULL); if (T == NULL) { T = xmalloc(sizeof(struct tree_node)); T->data = e; T->left = NULL; T->right = NULL; ENSURES(is_ordtree(T)); return T; } int r = key_compare(elem_key(e), elem_key(T->data)); if (r == 0) { elem_free(T->data); T->data = e; } else if (r < 0) T->left = tree_insert(T->left, e); else T->right = tree_insert(T->right, e); ENSURES(is_ordtree(T)); return T; }
[ "tree", "*", "tree_insert", "(", "tree", "*", "T", ",", "elem", "e", ")", "{", "REQUIRES", "(", "is_ordtree", "(", "T", ")", ")", ";", "REQUIRES", "(", "e", "!=", "NULL", ")", ";", "if", "(", "T", "==", "NULL", ")", "{", "T", "=", "xmalloc", "(", "sizeof", "(", "struct", "tree_node", ")", ")", ";", "T", "->", "data", "=", "e", ";", "T", "->", "left", "=", "NULL", ";", "T", "->", "right", "=", "NULL", ";", "ENSURES", "(", "is_ordtree", "(", "T", ")", ")", ";", "return", "T", ";", "}", "int", "r", "=", "key_compare", "(", "elem_key", "(", "e", ")", ",", "elem_key", "(", "T", "->", "data", ")", ")", ";", "if", "(", "r", "==", "0", ")", "{", "elem_free", "(", "T", "->", "data", ")", ";", "T", "->", "data", "=", "e", ";", "}", "else", "if", "(", "r", "<", "0", ")", "T", "->", "left", "=", "tree_insert", "(", "T", "->", "left", ",", "e", ")", ";", "else", "T", "->", "right", "=", "tree_insert", "(", "T", "->", "right", ",", "e", ")", ";", "ENSURES", "(", "is_ordtree", "(", "T", ")", ")", ";", "return", "T", ";", "}" ]
tree_insert(T, e) returns the modified tree this avoids some complications in case T = NULL
[ "tree_insert", "(", "T", "e", ")", "returns", "the", "modified", "tree", "this", "avoids", "some", "complications", "in", "case", "T", "=", "NULL" ]
[ "//@requires is_ordtree(T);", "//@requires e != NULL;", "//@ensures is_ordtree(\\result);", "/* create new node and return it */", "/* modify in place */", "//@assert r > 0;" ]
[ { "param": "T", "type": "tree" }, { "param": "e", "type": "elem" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "T", "type": "tree", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "e", "type": "elem", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
781f660964337316ce4521315d23c68aa9ee165a
Robert-Stackflow/HUST-Courses
03_Data Structure Course Design/4_Code/src/dpll.c
[ "MIT" ]
C
Decide_0
int
int Decide_0(HeadNode *head) { // Return the first literal in the list HeadNode *p = head; while (p) { if (p->flag == 0) { ClauseNode *q = p->horizon; while (q) { if (q->flag == 0) return q->literal; q = q->next; } } p = p->next; } return 0; }
// a series of functions used to decide variables
a series of functions used to decide variables
[ "a", "series", "of", "functions", "used", "to", "decide", "variables" ]
int Decide_0(HeadNode *head) { HeadNode *p = head; while (p) { if (p->flag == 0) { ClauseNode *q = p->horizon; while (q) { if (q->flag == 0) return q->literal; q = q->next; } } p = p->next; } return 0; }
[ "int", "Decide_0", "(", "HeadNode", "*", "head", ")", "{", "HeadNode", "*", "p", "=", "head", ";", "while", "(", "p", ")", "{", "if", "(", "p", "->", "flag", "==", "0", ")", "{", "ClauseNode", "*", "q", "=", "p", "->", "horizon", ";", "while", "(", "q", ")", "{", "if", "(", "q", "->", "flag", "==", "0", ")", "return", "q", "->", "literal", ";", "q", "=", "q", "->", "next", ";", "}", "}", "p", "=", "p", "->", "next", ";", "}", "return", "0", ";", "}" ]
a series of functions used to decide variables
[ "a", "series", "of", "functions", "used", "to", "decide", "variables" ]
[ "// Return the first literal in the list" ]
[ { "param": "head", "type": "HeadNode" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "head", "type": "HeadNode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8f55b70bc0806c902cbd6aff4af3f981a28f4133
Robert-Stackflow/HUST-Courses
05_Principles of Imperative Computation/Courseware/19-avl/code/avl.c
[ "MIT" ]
C
fix_height
void
void fix_height(tree *T) { REQUIRES(T != NULL); REQUIRES(is_specified_height(T->left) && is_specified_height(T->right)); int hl = height(T->left); int hr = height(T->right); T->height = (hl > hr ? hl+1 : hr+1); ENSURES(is_specified_height(T)); }
/* fix_height(T) calculates the height of T and stores it in * T->height, assuming the height of the subtrees is correct. */
fix_height(T) calculates the height of T and stores it in T->height, assuming the height of the subtrees is correct.
[ "fix_height", "(", "T", ")", "calculates", "the", "height", "of", "T", "and", "stores", "it", "in", "T", "-", ">", "height", "assuming", "the", "height", "of", "the", "subtrees", "is", "correct", "." ]
void fix_height(tree *T) { REQUIRES(T != NULL); REQUIRES(is_specified_height(T->left) && is_specified_height(T->right)); int hl = height(T->left); int hr = height(T->right); T->height = (hl > hr ? hl+1 : hr+1); ENSURES(is_specified_height(T)); }
[ "void", "fix_height", "(", "tree", "*", "T", ")", "{", "REQUIRES", "(", "T", "!=", "NULL", ")", ";", "REQUIRES", "(", "is_specified_height", "(", "T", "->", "left", ")", "&&", "is_specified_height", "(", "T", "->", "right", ")", ")", ";", "int", "hl", "=", "height", "(", "T", "->", "left", ")", ";", "int", "hr", "=", "height", "(", "T", "->", "right", ")", ";", "T", "->", "height", "=", "(", "hl", ">", "hr", "?", "hl", "+", "1", ":", "hr", "+", "1", ")", ";", "ENSURES", "(", "is_specified_height", "(", "T", ")", ")", ";", "}" ]
fix_height(T) calculates the height of T and stores it in T->height, assuming the height of the subtrees is correct.
[ "fix_height", "(", "T", ")", "calculates", "the", "height", "of", "T", "and", "stores", "it", "in", "T", "-", ">", "height", "assuming", "the", "height", "of", "the", "subtrees", "is", "correct", "." ]
[]
[ { "param": "T", "type": "tree" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "T", "type": "tree", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8f55b70bc0806c902cbd6aff4af3f981a28f4133
Robert-Stackflow/HUST-Courses
05_Principles of Imperative Computation/Courseware/19-avl/code/avl.c
[ "MIT" ]
C
tree_insert
tree
tree *tree_insert(tree *T, elem e) { REQUIRES(is_ordtree(T)); REQUIRES(is_specified_height(T)); REQUIRES(e != NULL); if (T == NULL) { /* create new leaf with the data e */ T = xmalloc(sizeof(struct tree_node)); T->data = e; T->height = 1; T->left = NULL; T->right = NULL; } else { int r = key_compare(elem_key(e), elem_key(T->data)); if (r == 0) { T->data = e; /* modify in place */ } else if (r < 0) { T->left = tree_insert(T->left, e); T = rebalance_left(T); /* also fixes height */ } else { ASSERT(r > 0); T->right = tree_insert(T->right, e); T = rebalance_right(T); /* also fixes height */ } } ENSURES(is_ordtree(T)); ENSURES(is_specified_height(T)); return T; }
/* tree_insert(T, e) returns the modified tree * this avoids some complications in case T = NULL * * Additional postcondition: Given a tree of height h, the height of * the returned tree is either h or h+1. */
tree_insert(T, e) returns the modified tree this avoids some complications in case T = NULL Additional postcondition: Given a tree of height h, the height of the returned tree is either h or h+1.
[ "tree_insert", "(", "T", "e", ")", "returns", "the", "modified", "tree", "this", "avoids", "some", "complications", "in", "case", "T", "=", "NULL", "Additional", "postcondition", ":", "Given", "a", "tree", "of", "height", "h", "the", "height", "of", "the", "returned", "tree", "is", "either", "h", "or", "h", "+", "1", "." ]
tree *tree_insert(tree *T, elem e) { REQUIRES(is_ordtree(T)); REQUIRES(is_specified_height(T)); REQUIRES(e != NULL); if (T == NULL) { T = xmalloc(sizeof(struct tree_node)); T->data = e; T->height = 1; T->left = NULL; T->right = NULL; } else { int r = key_compare(elem_key(e), elem_key(T->data)); if (r == 0) { T->data = e; } else if (r < 0) { T->left = tree_insert(T->left, e); T = rebalance_left(T); } else { ASSERT(r > 0); T->right = tree_insert(T->right, e); T = rebalance_right(T); } } ENSURES(is_ordtree(T)); ENSURES(is_specified_height(T)); return T; }
[ "tree", "*", "tree_insert", "(", "tree", "*", "T", ",", "elem", "e", ")", "{", "REQUIRES", "(", "is_ordtree", "(", "T", ")", ")", ";", "REQUIRES", "(", "is_specified_height", "(", "T", ")", ")", ";", "REQUIRES", "(", "e", "!=", "NULL", ")", ";", "if", "(", "T", "==", "NULL", ")", "{", "T", "=", "xmalloc", "(", "sizeof", "(", "struct", "tree_node", ")", ")", ";", "T", "->", "data", "=", "e", ";", "T", "->", "height", "=", "1", ";", "T", "->", "left", "=", "NULL", ";", "T", "->", "right", "=", "NULL", ";", "}", "else", "{", "int", "r", "=", "key_compare", "(", "elem_key", "(", "e", ")", ",", "elem_key", "(", "T", "->", "data", ")", ")", ";", "if", "(", "r", "==", "0", ")", "{", "T", "->", "data", "=", "e", ";", "}", "else", "if", "(", "r", "<", "0", ")", "{", "T", "->", "left", "=", "tree_insert", "(", "T", "->", "left", ",", "e", ")", ";", "T", "=", "rebalance_left", "(", "T", ")", ";", "}", "else", "{", "ASSERT", "(", "r", ">", "0", ")", ";", "T", "->", "right", "=", "tree_insert", "(", "T", "->", "right", ",", "e", ")", ";", "T", "=", "rebalance_right", "(", "T", ")", ";", "}", "}", "ENSURES", "(", "is_ordtree", "(", "T", ")", ")", ";", "ENSURES", "(", "is_specified_height", "(", "T", ")", ")", ";", "return", "T", ";", "}" ]
tree_insert(T, e) returns the modified tree this avoids some complications in case T = NULL
[ "tree_insert", "(", "T", "e", ")", "returns", "the", "modified", "tree", "this", "avoids", "some", "complications", "in", "case", "T", "=", "NULL" ]
[ "/* create new leaf with the data e */", "/* modify in place */", "/* also fixes height */", "/* also fixes height */" ]
[ { "param": "T", "type": "tree" }, { "param": "e", "type": "elem" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "T", "type": "tree", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "e", "type": "elem", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cd20ace514a23bd28916bb817f05db4c6155fc7f
alonSadan/os_3
priorityQueue.c
[ "MIT-0" ]
C
insertHeap
void
void insertHeap(struct heap_p array[], struct heap_p newHeap,int *sizePtr) { if (*sizePtr == 0) { array[0] = newHeap; *sizePtr += 1; } else { array[*sizePtr] = newHeap; *sizePtr += 1; for (int i = *sizePtr / 2 - 1; i >= 0; i--) { heapify(array, *sizePtr, i); } } }
// Function to insert an element into the tree
Function to insert an element into the tree
[ "Function", "to", "insert", "an", "element", "into", "the", "tree" ]
void insertHeap(struct heap_p array[], struct heap_p newHeap,int *sizePtr) { if (*sizePtr == 0) { array[0] = newHeap; *sizePtr += 1; } else { array[*sizePtr] = newHeap; *sizePtr += 1; for (int i = *sizePtr / 2 - 1; i >= 0; i--) { heapify(array, *sizePtr, i); } } }
[ "void", "insertHeap", "(", "struct", "heap_p", "array", "[", "]", ",", "struct", "heap_p", "newHeap", ",", "int", "*", "sizePtr", ")", "{", "if", "(", "*", "sizePtr", "==", "0", ")", "{", "array", "[", "0", "]", "=", "newHeap", ";", "*", "sizePtr", "+=", "1", ";", "}", "else", "{", "array", "[", "*", "sizePtr", "]", "=", "newHeap", ";", "*", "sizePtr", "+=", "1", ";", "for", "(", "int", "i", "=", "*", "sizePtr", "/", "2", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "heapify", "(", "array", ",", "*", "sizePtr", ",", "i", ")", ";", "}", "}", "}" ]
Function to insert an element into the tree
[ "Function", "to", "insert", "an", "element", "into", "the", "tree" ]
[]
[ { "param": "array", "type": "struct heap_p" }, { "param": "newHeap", "type": "struct heap_p" }, { "param": "sizePtr", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "array", "type": "struct heap_p", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "newHeap", "type": "struct heap_p", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sizePtr", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cd20ace514a23bd28916bb817f05db4c6155fc7f
alonSadan/os_3
priorityQueue.c
[ "MIT-0" ]
C
deleteRoot
null
struct heap_p deleteRoot(struct heap_p array[], int index,int *sizePtr) { int i; for (i = 0; i < *sizePtr; i++) { if (index == array[i].index) break; } if(i == *sizePtr) return (struct heap_p){-1,-1}; struct heap_p out = array[i]; swapHeapNode(&array[i], &array[*sizePtr - 1]); *sizePtr -= 1; for (int i = *sizePtr / 2 - 1; i >= 0; i--) { heapify(array, *sizePtr, i); } return out; }
// Function to delete an element from the tree
Function to delete an element from the tree
[ "Function", "to", "delete", "an", "element", "from", "the", "tree" ]
struct heap_p deleteRoot(struct heap_p array[], int index,int *sizePtr) { int i; for (i = 0; i < *sizePtr; i++) { if (index == array[i].index) break; } if(i == *sizePtr) return (struct heap_p){-1,-1}; struct heap_p out = array[i]; swapHeapNode(&array[i], &array[*sizePtr - 1]); *sizePtr -= 1; for (int i = *sizePtr / 2 - 1; i >= 0; i--) { heapify(array, *sizePtr, i); } return out; }
[ "struct", "heap_p", "deleteRoot", "(", "struct", "heap_p", "array", "[", "]", ",", "int", "index", ",", "int", "*", "sizePtr", ")", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "*", "sizePtr", ";", "i", "++", ")", "{", "if", "(", "index", "==", "array", "[", "i", "]", ".", "index", ")", "break", ";", "}", "if", "(", "i", "==", "*", "sizePtr", ")", "return", "(", "struct", "heap_p", ")", "{", "-1", ",", "-1", "}", ";", "struct", "heap_p", "out", "=", "array", "[", "i", "]", ";", "swapHeapNode", "(", "&", "array", "[", "i", "]", ",", "&", "array", "[", "*", "sizePtr", "-", "1", "]", ")", ";", "*", "sizePtr", "-=", "1", ";", "for", "(", "int", "i", "=", "*", "sizePtr", "/", "2", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "heapify", "(", "array", ",", "*", "sizePtr", ",", "i", ")", ";", "}", "return", "out", ";", "}" ]
Function to delete an element from the tree
[ "Function", "to", "delete", "an", "element", "from", "the", "tree" ]
[]
[ { "param": "array", "type": "struct heap_p" }, { "param": "index", "type": "int" }, { "param": "sizePtr", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "array", "type": "struct heap_p", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "index", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sizePtr", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b54e8087d5ec2ab7ee1b28e6d24ca161008751bb
alonSadan/os_3
kalloc.c
[ "MIT-0" ]
C
kinit1
void
void kinit1(void *vstart, void *vend) { initlock(&kmem.lock, "kmem"); kmem.use_lock = 0; freerange(vstart, vend); }
// Initialization happens in two phases. // 1. main() calls kinit1() while still using entrypgdir to place just // the pages mapped by entrypgdir on free list. // 2. main() calls kinit2() with the rest of the physical pages // after installing a full page table that maps them on all cores.
Initialization happens in two phases. 1. main() calls kinit1() while still using entrypgdir to place just the pages mapped by entrypgdir on free list. 2. main() calls kinit2() with the rest of the physical pages after installing a full page table that maps them on all cores.
[ "Initialization", "happens", "in", "two", "phases", ".", "1", ".", "main", "()", "calls", "kinit1", "()", "while", "still", "using", "entrypgdir", "to", "place", "just", "the", "pages", "mapped", "by", "entrypgdir", "on", "free", "list", ".", "2", ".", "main", "()", "calls", "kinit2", "()", "with", "the", "rest", "of", "the", "physical", "pages", "after", "installing", "a", "full", "page", "table", "that", "maps", "them", "on", "all", "cores", "." ]
void kinit1(void *vstart, void *vend) { initlock(&kmem.lock, "kmem"); kmem.use_lock = 0; freerange(vstart, vend); }
[ "void", "kinit1", "(", "void", "*", "vstart", ",", "void", "*", "vend", ")", "{", "initlock", "(", "&", "kmem", ".", "lock", ",", "\"", "\"", ")", ";", "kmem", ".", "use_lock", "=", "0", ";", "freerange", "(", "vstart", ",", "vend", ")", ";", "}" ]
Initialization happens in two phases.
[ "Initialization", "happens", "in", "two", "phases", "." ]
[]
[ { "param": "vstart", "type": "void" }, { "param": "vend", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vstart", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vend", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b54e8087d5ec2ab7ee1b28e6d24ca161008751bb
alonSadan/os_3
kalloc.c
[ "MIT-0" ]
C
kfree
void
void kfree(char *v) { struct run *r; //cprintf("Free\n"); if ((uint)v % PGSIZE || v < end || V2P(v) >= PHYSTOP) panic("kfree"); // Fill with junk to catch dangling refs. memset(v, 1, PGSIZE); if(kmem.use_lock){ acquire(&kmem.lock); } r = &kmem.runArr[(V2P(v) / PGSIZE)]; //r = (struct run*)v; if (r->ref != 1){ //cprintf("a: %d",r->ref); cprintf("kfree: wrong ref r %d\n",r->ref); panic("kfree: ref"); } r->next = kmem.freelist; r->ref = 0; occupiedPages--; kmem.freelist = r; if(kmem.use_lock) release(&kmem.lock); }
//PAGEBREAK: 21 // Free the page of physical memory pointed at by v, // which normally should have been returned by a // call to kalloc(). (The exception is when // initializing the allocator; see kinit above.)
21 Free the page of physical memory pointed at by v, which normally should have been returned by a call to kalloc(). (The exception is when initializing the allocator; see kinit above.)
[ "21", "Free", "the", "page", "of", "physical", "memory", "pointed", "at", "by", "v", "which", "normally", "should", "have", "been", "returned", "by", "a", "call", "to", "kalloc", "()", ".", "(", "The", "exception", "is", "when", "initializing", "the", "allocator", ";", "see", "kinit", "above", ".", ")" ]
void kfree(char *v) { struct run *r; if ((uint)v % PGSIZE || v < end || V2P(v) >= PHYSTOP) panic("kfree"); memset(v, 1, PGSIZE); if(kmem.use_lock){ acquire(&kmem.lock); } r = &kmem.runArr[(V2P(v) / PGSIZE)]; if (r->ref != 1){ cprintf("kfree: wrong ref r %d\n",r->ref); panic("kfree: ref"); } r->next = kmem.freelist; r->ref = 0; occupiedPages--; kmem.freelist = r; if(kmem.use_lock) release(&kmem.lock); }
[ "void", "kfree", "(", "char", "*", "v", ")", "{", "struct", "run", "*", "r", ";", "if", "(", "(", "uint", ")", "v", "%", "PGSIZE", "||", "v", "<", "end", "||", "V2P", "(", "v", ")", ">=", "PHYSTOP", ")", "panic", "(", "\"", "\"", ")", ";", "memset", "(", "v", ",", "1", ",", "PGSIZE", ")", ";", "if", "(", "kmem", ".", "use_lock", ")", "{", "acquire", "(", "&", "kmem", ".", "lock", ")", ";", "}", "r", "=", "&", "kmem", ".", "runArr", "[", "(", "V2P", "(", "v", ")", "/", "PGSIZE", ")", "]", ";", "if", "(", "r", "->", "ref", "!=", "1", ")", "{", "cprintf", "(", "\"", "\\n", "\"", ",", "r", "->", "ref", ")", ";", "panic", "(", "\"", "\"", ")", ";", "}", "r", "->", "next", "=", "kmem", ".", "freelist", ";", "r", "->", "ref", "=", "0", ";", "occupiedPages", "--", ";", "kmem", ".", "freelist", "=", "r", ";", "if", "(", "kmem", ".", "use_lock", ")", "release", "(", "&", "kmem", ".", "lock", ")", ";", "}" ]
PAGEBREAK: 21 Free the page of physical memory pointed at by v, which normally should have been returned by a call to kalloc().
[ "PAGEBREAK", ":", "21", "Free", "the", "page", "of", "physical", "memory", "pointed", "at", "by", "v", "which", "normally", "should", "have", "been", "returned", "by", "a", "call", "to", "kalloc", "()", "." ]
[ "//cprintf(\"Free\\n\");", "// Fill with junk to catch dangling refs.", "//r = (struct run*)v;", "//cprintf(\"a: %d\",r->ref);" ]
[ { "param": "v", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b54e8087d5ec2ab7ee1b28e6d24ca161008751bb
alonSadan/os_3
kalloc.c
[ "MIT-0" ]
C
kalloc
char
char* kalloc(void) { struct run *r; //cprintf("Kalloc\n"); if (kmem.use_lock) acquire(&kmem.lock); r = kmem.freelist; if (r){ kmem.freelist = r->next; r->ref=1; occupiedPages++; } if (kmem.use_lock) release(&kmem.lock); //return (char *)r; char *rv = r ? P2V((r - kmem.runArr) * PGSIZE) : r; return rv; }
// Allocate one 4096-byte page of physical memory. // Returns a pointer that the kernel can use. // Returns 0 if the memory cannot be allocated.
Allocate one 4096-byte page of physical memory. Returns a pointer that the kernel can use. Returns 0 if the memory cannot be allocated.
[ "Allocate", "one", "4096", "-", "byte", "page", "of", "physical", "memory", ".", "Returns", "a", "pointer", "that", "the", "kernel", "can", "use", ".", "Returns", "0", "if", "the", "memory", "cannot", "be", "allocated", "." ]
char* kalloc(void) { struct run *r; if (kmem.use_lock) acquire(&kmem.lock); r = kmem.freelist; if (r){ kmem.freelist = r->next; r->ref=1; occupiedPages++; } if (kmem.use_lock) release(&kmem.lock); char *rv = r ? P2V((r - kmem.runArr) * PGSIZE) : r; return rv; }
[ "char", "*", "kalloc", "(", "void", ")", "{", "struct", "run", "*", "r", ";", "if", "(", "kmem", ".", "use_lock", ")", "acquire", "(", "&", "kmem", ".", "lock", ")", ";", "r", "=", "kmem", ".", "freelist", ";", "if", "(", "r", ")", "{", "kmem", ".", "freelist", "=", "r", "->", "next", ";", "r", "->", "ref", "=", "1", ";", "occupiedPages", "++", ";", "}", "if", "(", "kmem", ".", "use_lock", ")", "release", "(", "&", "kmem", ".", "lock", ")", ";", "char", "*", "rv", "=", "r", "?", "P2V", "(", "(", "r", "-", "kmem", ".", "runArr", ")", "*", "PGSIZE", ")", ":", "r", ";", "return", "rv", ";", "}" ]
Allocate one 4096-byte page of physical memory.
[ "Allocate", "one", "4096", "-", "byte", "page", "of", "physical", "memory", "." ]
[ "//cprintf(\"Kalloc\\n\");", "//return (char *)r;" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
print_func_calls
void
static void print_func_calls(const uint32_t n) { uint32_t func_addr = 0; uint32_t calls_printed = 0; uint32_t hist_offset = g_dbg_state->call_history_top; for (; hist_offset > 0 && (calls_printed != n || n == 0);) { func_addr = g_dbg_state->call_history[--hist_offset]; if (n == 0) { printf("#%i ", calls_printed + 1); } printf("0x%08X %s (", func_addr, addr_to_func_name(func_addr)); if (hist_offset > 0) { for (uint32_t arg_offset = g_dbg_state->call_history[--hist_offset]; arg_offset > 0; arg_offset--) { printf(" 0x%08X", g_dbg_state->call_history[--hist_offset]); if (arg_offset - 1 > 0) { printf(","); } } } printf(" )"); if (n == 0) { printf("\n"); } calls_printed++; } }
/** * Print out last n function calls or all calls if n is 0. * When n = 0, prints a numbered vertical list. **/
Print out last n function calls or all calls if n is 0. When n = 0, prints a numbered vertical list.
[ "Print", "out", "last", "n", "function", "calls", "or", "all", "calls", "if", "n", "is", "0", ".", "When", "n", "=", "0", "prints", "a", "numbered", "vertical", "list", "." ]
static void print_func_calls(const uint32_t n) { uint32_t func_addr = 0; uint32_t calls_printed = 0; uint32_t hist_offset = g_dbg_state->call_history_top; for (; hist_offset > 0 && (calls_printed != n || n == 0);) { func_addr = g_dbg_state->call_history[--hist_offset]; if (n == 0) { printf("#%i ", calls_printed + 1); } printf("0x%08X %s (", func_addr, addr_to_func_name(func_addr)); if (hist_offset > 0) { for (uint32_t arg_offset = g_dbg_state->call_history[--hist_offset]; arg_offset > 0; arg_offset--) { printf(" 0x%08X", g_dbg_state->call_history[--hist_offset]); if (arg_offset - 1 > 0) { printf(","); } } } printf(" )"); if (n == 0) { printf("\n"); } calls_printed++; } }
[ "static", "void", "print_func_calls", "(", "const", "uint32_t", "n", ")", "{", "uint32_t", "func_addr", "=", "0", ";", "uint32_t", "calls_printed", "=", "0", ";", "uint32_t", "hist_offset", "=", "g_dbg_state", "->", "call_history_top", ";", "for", "(", ";", "hist_offset", ">", "0", "&&", "(", "calls_printed", "!=", "n", "||", "n", "==", "0", ")", ";", ")", "{", "func_addr", "=", "g_dbg_state", "->", "call_history", "[", "--", "hist_offset", "]", ";", "if", "(", "n", "==", "0", ")", "{", "printf", "(", "\"", "\"", ",", "calls_printed", "+", "1", ")", ";", "}", "printf", "(", "\"", "\"", ",", "func_addr", ",", "addr_to_func_name", "(", "func_addr", ")", ")", ";", "if", "(", "hist_offset", ">", "0", ")", "{", "for", "(", "uint32_t", "arg_offset", "=", "g_dbg_state", "->", "call_history", "[", "--", "hist_offset", "]", ";", "arg_offset", ">", "0", ";", "arg_offset", "--", ")", "{", "printf", "(", "\"", "\"", ",", "g_dbg_state", "->", "call_history", "[", "--", "hist_offset", "]", ")", ";", "if", "(", "arg_offset", "-", "1", ">", "0", ")", "{", "printf", "(", "\"", "\"", ")", ";", "}", "}", "}", "printf", "(", "\"", "\"", ")", ";", "if", "(", "n", "==", "0", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "calls_printed", "++", ";", "}", "}" ]
Print out last n function calls or all calls if n is 0.
[ "Print", "out", "last", "n", "function", "calls", "or", "all", "calls", "if", "n", "is", "0", "." ]
[]
[ { "param": "n", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "n", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
print_breakpoint_msg
void
static void print_breakpoint_msg(const uint32_t id) { printf("Breakpoint %i, in ", id); print_func_calls(1); }
/** * Print out information regarding the breakpoint with a given id. * Called is responsible for printing a new line character (after adding information if needed). **/
Print out information regarding the breakpoint with a given id. Called is responsible for printing a new line character (after adding information if needed).
[ "Print", "out", "information", "regarding", "the", "breakpoint", "with", "a", "given", "id", ".", "Called", "is", "responsible", "for", "printing", "a", "new", "line", "character", "(", "after", "adding", "information", "if", "needed", ")", "." ]
static void print_breakpoint_msg(const uint32_t id) { printf("Breakpoint %i, in ", id); print_func_calls(1); }
[ "static", "void", "print_breakpoint_msg", "(", "const", "uint32_t", "id", ")", "{", "printf", "(", "\"", "\"", ",", "id", ")", ";", "print_func_calls", "(", "1", ")", ";", "}" ]
Print out information regarding the breakpoint with a given id.
[ "Print", "out", "information", "regarding", "the", "breakpoint", "with", "a", "given", "id", "." ]
[]
[ { "param": "id", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "id", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
addr_to_func_name
char
static const char* addr_to_func_name(const uint32_t addr) { char* parent_symb_name = NULL; if (g_debug_data->func_label.num == 0) { return "??"; } for (uint32_t i = 0; i < g_debug_data->func_label.num; i++) { if (addr == g_debug_data->func_label.addr[i]) { parent_symb_name = get_func_name(i); break; } if (addr < g_debug_data->func_label.addr[i]) { // Previous symbol had the closest address hence the "i - 1" parent_symb_name = get_func_name(i - 1); break; } } if (parent_symb_name == NULL) { return "??"; } return parent_symb_name; }
/** * Return a function name that contains a given address. * Return function name string on success * "??" string on failure (e.g. when there are no symbols in the binary) **/
Return a function name that contains a given address. Return function name string on success "??" string on failure
[ "Return", "a", "function", "name", "that", "contains", "a", "given", "address", ".", "Return", "function", "name", "string", "on", "success", "\"", "??", "\"", "string", "on", "failure" ]
static const char* addr_to_func_name(const uint32_t addr) { char* parent_symb_name = NULL; if (g_debug_data->func_label.num == 0) { return "??"; } for (uint32_t i = 0; i < g_debug_data->func_label.num; i++) { if (addr == g_debug_data->func_label.addr[i]) { parent_symb_name = get_func_name(i); break; } if (addr < g_debug_data->func_label.addr[i]) { parent_symb_name = get_func_name(i - 1); break; } } if (parent_symb_name == NULL) { return "??"; } return parent_symb_name; }
[ "static", "const", "char", "*", "addr_to_func_name", "(", "const", "uint32_t", "addr", ")", "{", "char", "*", "parent_symb_name", "=", "NULL", ";", "if", "(", "g_debug_data", "->", "func_label", ".", "num", "==", "0", ")", "{", "return", "\"", "\"", ";", "}", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "g_debug_data", "->", "func_label", ".", "num", ";", "i", "++", ")", "{", "if", "(", "addr", "==", "g_debug_data", "->", "func_label", ".", "addr", "[", "i", "]", ")", "{", "parent_symb_name", "=", "get_func_name", "(", "i", ")", ";", "break", ";", "}", "if", "(", "addr", "<", "g_debug_data", "->", "func_label", ".", "addr", "[", "i", "]", ")", "{", "parent_symb_name", "=", "get_func_name", "(", "i", "-", "1", ")", ";", "break", ";", "}", "}", "if", "(", "parent_symb_name", "==", "NULL", ")", "{", "return", "\"", "\"", ";", "}", "return", "parent_symb_name", ";", "}" ]
Return a function name that contains a given address.
[ "Return", "a", "function", "name", "that", "contains", "a", "given", "address", "." ]
[ "// Previous symbol had the closest address hence the \"i - 1\"" ]
[ { "param": "addr", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "addr", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
label_name_to_addr
uint32_t
static uint32_t label_name_to_addr(const char* label_name) { uint32_t symb_addr = SIZE_MAX_UINT32_T; if (g_debug_data->sec_label.num == 0) { return symb_addr; } // Looking in section names for (uint32_t i = 0; i < g_debug_data->sec_label.num; i++) { if (strcmp(label_name, get_section_name(i)) == 0) { symb_addr = g_debug_data->sec_label.addr[i]; break; } } if (symb_addr != SIZE_MAX_UINT32_T || g_debug_data->func_label.num == 0) { return symb_addr; } // Looking in function names for (uint32_t i = 0; i < g_debug_data->func_label.num; i++) { if (strcmp(label_name, get_func_name(i)) == 0) { symb_addr = g_debug_data->func_label.addr[i]; break; } } return symb_addr; }
/** * Return the address of a given label name. (function or section) * Return label address on success * SIZE_MAX_UINT32_T on failure (e.g. when there are no symbols in the binary) **/
Return the address of a given label name. (function or section) Return label address on success SIZE_MAX_UINT32_T on failure
[ "Return", "the", "address", "of", "a", "given", "label", "name", ".", "(", "function", "or", "section", ")", "Return", "label", "address", "on", "success", "SIZE_MAX_UINT32_T", "on", "failure" ]
static uint32_t label_name_to_addr(const char* label_name) { uint32_t symb_addr = SIZE_MAX_UINT32_T; if (g_debug_data->sec_label.num == 0) { return symb_addr; } for (uint32_t i = 0; i < g_debug_data->sec_label.num; i++) { if (strcmp(label_name, get_section_name(i)) == 0) { symb_addr = g_debug_data->sec_label.addr[i]; break; } } if (symb_addr != SIZE_MAX_UINT32_T || g_debug_data->func_label.num == 0) { return symb_addr; } for (uint32_t i = 0; i < g_debug_data->func_label.num; i++) { if (strcmp(label_name, get_func_name(i)) == 0) { symb_addr = g_debug_data->func_label.addr[i]; break; } } return symb_addr; }
[ "static", "uint32_t", "label_name_to_addr", "(", "const", "char", "*", "label_name", ")", "{", "uint32_t", "symb_addr", "=", "SIZE_MAX_UINT32_T", ";", "if", "(", "g_debug_data", "->", "sec_label", ".", "num", "==", "0", ")", "{", "return", "symb_addr", ";", "}", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "g_debug_data", "->", "sec_label", ".", "num", ";", "i", "++", ")", "{", "if", "(", "strcmp", "(", "label_name", ",", "get_section_name", "(", "i", ")", ")", "==", "0", ")", "{", "symb_addr", "=", "g_debug_data", "->", "sec_label", ".", "addr", "[", "i", "]", ";", "break", ";", "}", "}", "if", "(", "symb_addr", "!=", "SIZE_MAX_UINT32_T", "||", "g_debug_data", "->", "func_label", ".", "num", "==", "0", ")", "{", "return", "symb_addr", ";", "}", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "g_debug_data", "->", "func_label", ".", "num", ";", "i", "++", ")", "{", "if", "(", "strcmp", "(", "label_name", ",", "get_func_name", "(", "i", ")", ")", "==", "0", ")", "{", "symb_addr", "=", "g_debug_data", "->", "func_label", ".", "addr", "[", "i", "]", ";", "break", ";", "}", "}", "return", "symb_addr", ";", "}" ]
Return the address of a given label name.
[ "Return", "the", "address", "of", "a", "given", "label", "name", "." ]
[ "// Looking in section names", "// Looking in function names" ]
[ { "param": "label_name", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "label_name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
at_breakpoint
uint32_t
static uint32_t at_breakpoint(void) { const uint32_t curr_pc = (uint32_t)g_cpu->pc; for (uint32_t i = 0; i < (uint32_t)g_dbg_state->brkpts.num; i++) { if (g_dbg_state->brkpts.addrs[i] == curr_pc) { return i + 1; } } return 0; }
/** * Uses the program counter to determine if any of the breakpoints have been reached. * Return number of breakpoint that was reached * 0 if no breakpoint was reached **/
Uses the program counter to determine if any of the breakpoints have been reached. Return number of breakpoint that was reached 0 if no breakpoint was reached
[ "Uses", "the", "program", "counter", "to", "determine", "if", "any", "of", "the", "breakpoints", "have", "been", "reached", ".", "Return", "number", "of", "breakpoint", "that", "was", "reached", "0", "if", "no", "breakpoint", "was", "reached" ]
static uint32_t at_breakpoint(void) { const uint32_t curr_pc = (uint32_t)g_cpu->pc; for (uint32_t i = 0; i < (uint32_t)g_dbg_state->brkpts.num; i++) { if (g_dbg_state->brkpts.addrs[i] == curr_pc) { return i + 1; } } return 0; }
[ "static", "uint32_t", "at_breakpoint", "(", "void", ")", "{", "const", "uint32_t", "curr_pc", "=", "(", "uint32_t", ")", "g_cpu", "->", "pc", ";", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "(", "uint32_t", ")", "g_dbg_state", "->", "brkpts", ".", "num", ";", "i", "++", ")", "{", "if", "(", "g_dbg_state", "->", "brkpts", ".", "addrs", "[", "i", "]", "==", "curr_pc", ")", "{", "return", "i", "+", "1", ";", "}", "}", "return", "0", ";", "}" ]
Uses the program counter to determine if any of the breakpoints have been reached.
[ "Uses", "the", "program", "counter", "to", "determine", "if", "any", "of", "the", "breakpoints", "have", "been", "reached", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
create_call_history
void
static void create_call_history(void) { if (g_cpu->code_mem[g_cpu->pc] == OP_INVOKEVIRTUAL) { store_func_call(); if (g_dbg_state->quit_flag == true) { return; // Something went wrong when storing the function call } } else if (g_cpu->code_mem[g_cpu->pc] == OP_IRETURN) { remove_last_func_call(); } }
/** * Needs to be called on every step to create a function call history * for use by the debugger. **/
Needs to be called on every step to create a function call history for use by the debugger.
[ "Needs", "to", "be", "called", "on", "every", "step", "to", "create", "a", "function", "call", "history", "for", "use", "by", "the", "debugger", "." ]
static void create_call_history(void) { if (g_cpu->code_mem[g_cpu->pc] == OP_INVOKEVIRTUAL) { store_func_call(); if (g_dbg_state->quit_flag == true) { return; } } else if (g_cpu->code_mem[g_cpu->pc] == OP_IRETURN) { remove_last_func_call(); } }
[ "static", "void", "create_call_history", "(", "void", ")", "{", "if", "(", "g_cpu", "->", "code_mem", "[", "g_cpu", "->", "pc", "]", "==", "OP_INVOKEVIRTUAL", ")", "{", "store_func_call", "(", ")", ";", "if", "(", "g_dbg_state", "->", "quit_flag", "==", "true", ")", "{", "return", ";", "}", "}", "else", "if", "(", "g_cpu", "->", "code_mem", "[", "g_cpu", "->", "pc", "]", "==", "OP_IRETURN", ")", "{", "remove_last_func_call", "(", ")", ";", "}", "}" ]
Needs to be called on every step to create a function call history for use by the debugger.
[ "Needs", "to", "be", "called", "on", "every", "step", "to", "create", "a", "function", "call", "history", "for", "use", "by", "the", "debugger", "." ]
[ "// Something went wrong when storing the function call" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
store_func_call
void
static void store_func_call(void) { uint32_t func_addr; uint32_t func_num_args; uint32_t* tmp_call_history; uint32_t call_elements_num; uint32_t tmp_call_history_size; func_addr = (uint32_t)get_constant(get_code_short(g_cpu->pc + 1)); func_num_args = (uint32_t)get_code_short((int)func_addr); call_elements_num = 1 + 1 + func_num_args; // Check if call history can fit the new call if (g_dbg_state->call_history_top + call_elements_num > g_dbg_state->call_history_size) { g_dbg_state->call_history_size = g_dbg_state->call_history_top + call_elements_num + 1024; // Store current function plus an extra margin tmp_call_history = g_dbg_state->call_history; // In case allocation fails tmp_call_history_size = g_dbg_state->call_history_size; g_dbg_state->call_history = (uint32_t*)realloc(g_dbg_state->call_history, tmp_call_history_size * sizeof(uint32_t)); if (g_dbg_state->call_history == NULL) { fprintf(stderr, "[ERR] Failed to allocate memory. In \"ijdb.c::store_func_call\".\n"); g_dbg_state->quit_flag = true; g_dbg_state->call_history = tmp_call_history; return; } } // Save all elements of the call for (uint32_t i = 0; i < func_num_args; i++) { g_dbg_state->call_history[g_dbg_state->call_history_top++] = (uint32_t)g_cpu->stack[(uint32_t)g_cpu->sp - i]; } g_dbg_state->call_history[g_dbg_state->call_history_top++] = func_num_args; g_dbg_state->call_history[g_dbg_state->call_history_top++] = func_addr; /** * Call history after: * * [empty] <- top * func addr * arg num * arg 1 * arg 2 * ... * arg n - 1 * arg n * ... **/ }
/** * Save the function call at current PC **/
Save the function call at current PC
[ "Save", "the", "function", "call", "at", "current", "PC" ]
static void store_func_call(void) { uint32_t func_addr; uint32_t func_num_args; uint32_t* tmp_call_history; uint32_t call_elements_num; uint32_t tmp_call_history_size; func_addr = (uint32_t)get_constant(get_code_short(g_cpu->pc + 1)); func_num_args = (uint32_t)get_code_short((int)func_addr); call_elements_num = 1 + 1 + func_num_args; if (g_dbg_state->call_history_top + call_elements_num > g_dbg_state->call_history_size) { g_dbg_state->call_history_size = g_dbg_state->call_history_top + call_elements_num + 1024; tmp_call_history = g_dbg_state->call_history; tmp_call_history_size = g_dbg_state->call_history_size; g_dbg_state->call_history = (uint32_t*)realloc(g_dbg_state->call_history, tmp_call_history_size * sizeof(uint32_t)); if (g_dbg_state->call_history == NULL) { fprintf(stderr, "[ERR] Failed to allocate memory. In \"ijdb.c::store_func_call\".\n"); g_dbg_state->quit_flag = true; g_dbg_state->call_history = tmp_call_history; return; } } for (uint32_t i = 0; i < func_num_args; i++) { g_dbg_state->call_history[g_dbg_state->call_history_top++] = (uint32_t)g_cpu->stack[(uint32_t)g_cpu->sp - i]; } g_dbg_state->call_history[g_dbg_state->call_history_top++] = func_num_args; g_dbg_state->call_history[g_dbg_state->call_history_top++] = func_addr; }
[ "static", "void", "store_func_call", "(", "void", ")", "{", "uint32_t", "func_addr", ";", "uint32_t", "func_num_args", ";", "uint32_t", "*", "tmp_call_history", ";", "uint32_t", "call_elements_num", ";", "uint32_t", "tmp_call_history_size", ";", "func_addr", "=", "(", "uint32_t", ")", "get_constant", "(", "get_code_short", "(", "g_cpu", "->", "pc", "+", "1", ")", ")", ";", "func_num_args", "=", "(", "uint32_t", ")", "get_code_short", "(", "(", "int", ")", "func_addr", ")", ";", "call_elements_num", "=", "1", "+", "1", "+", "func_num_args", ";", "if", "(", "g_dbg_state", "->", "call_history_top", "+", "call_elements_num", ">", "g_dbg_state", "->", "call_history_size", ")", "{", "g_dbg_state", "->", "call_history_size", "=", "g_dbg_state", "->", "call_history_top", "+", "call_elements_num", "+", "1024", ";", "tmp_call_history", "=", "g_dbg_state", "->", "call_history", ";", "tmp_call_history_size", "=", "g_dbg_state", "->", "call_history_size", ";", "g_dbg_state", "->", "call_history", "=", "(", "uint32_t", "*", ")", "realloc", "(", "g_dbg_state", "->", "call_history", ",", "tmp_call_history_size", "*", "sizeof", "(", "uint32_t", ")", ")", ";", "if", "(", "g_dbg_state", "->", "call_history", "==", "NULL", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\\"", "\\\"", "\\n", "\"", ")", ";", "g_dbg_state", "->", "quit_flag", "=", "true", ";", "g_dbg_state", "->", "call_history", "=", "tmp_call_history", ";", "return", ";", "}", "}", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "func_num_args", ";", "i", "++", ")", "{", "g_dbg_state", "->", "call_history", "[", "g_dbg_state", "->", "call_history_top", "++", "]", "=", "(", "uint32_t", ")", "g_cpu", "->", "stack", "[", "(", "uint32_t", ")", "g_cpu", "->", "sp", "-", "i", "]", ";", "}", "g_dbg_state", "->", "call_history", "[", "g_dbg_state", "->", "call_history_top", "++", "]", "=", "func_num_args", ";", "g_dbg_state", "->", "call_history", "[", "g_dbg_state", "->", "call_history_top", "++", "]", "=", "func_addr", ";", "}" ]
Save the function call at current PC
[ "Save", "the", "function", "call", "at", "current", "PC" ]
[ "// Check if call history can fit the new call", "// Store current function plus an extra margin", "// In case allocation fails", "// Save all elements of the call", "/**\n * Call history after:\n *\n * [empty] <- top\n * func addr\n * arg num\n * arg 1\n * arg 2\n * ...\n * arg n - 1\n * arg n\n * ...\n **/" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
save_last_prog
void
static void save_last_prog(const char* prog_path) { char* prog_path_cpy = str_dup(prog_path); // In case pointers are the same (case prog_path == g_dbg_state->last_prog_path) free(g_dbg_state->last_prog_path); g_dbg_state->last_prog_path = str_dup(prog_path_cpy); if (g_dbg_state->last_prog_path == NULL) { printf("Failed to save path to last executed program. " "Any subsequent attempts to re-load the program will fail.\n"); return; } free(prog_path_cpy); }
/** * Store program path for furutre use when a re-load is needed **/
Store program path for furutre use when a re-load is needed
[ "Store", "program", "path", "for", "furutre", "use", "when", "a", "re", "-", "load", "is", "needed" ]
static void save_last_prog(const char* prog_path) { char* prog_path_cpy = str_dup(prog_path); free(g_dbg_state->last_prog_path); g_dbg_state->last_prog_path = str_dup(prog_path_cpy); if (g_dbg_state->last_prog_path == NULL) { printf("Failed to save path to last executed program. " "Any subsequent attempts to re-load the program will fail.\n"); return; } free(prog_path_cpy); }
[ "static", "void", "save_last_prog", "(", "const", "char", "*", "prog_path", ")", "{", "char", "*", "prog_path_cpy", "=", "str_dup", "(", "prog_path", ")", ";", "free", "(", "g_dbg_state", "->", "last_prog_path", ")", ";", "g_dbg_state", "->", "last_prog_path", "=", "str_dup", "(", "prog_path_cpy", ")", ";", "if", "(", "g_dbg_state", "->", "last_prog_path", "==", "NULL", ")", "{", "printf", "(", "\"", "\"", "\"", "\\n", "\"", ")", ";", "return", ";", "}", "free", "(", "prog_path_cpy", ")", ";", "}" ]
Store program path for furutre use when a re-load is needed
[ "Store", "program", "path", "for", "furutre", "use", "when", "a", "re", "-", "load", "is", "needed" ]
[ "// In case pointers are the same (case prog_path == g_dbg_state->last_prog_path)" ]
[ { "param": "prog_path", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "prog_path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
dbg_step
void
static void dbg_step(const bool step_log) { const char* op = op_decode(g_cpu->code_mem[g_cpu->pc]); create_call_history(); if (step_log) { printf("0x%08X: %-14s\n", g_cpu->pc, op); } step(); if (at_breakpoint() != 0) { op = op_decode(g_cpu->code_mem[g_cpu->pc]); print_breakpoint_msg(at_breakpoint()); printf(" when PC=0x%08X and OP=%-14s\n", g_cpu->pc, op); } }
/** * Step the VM and print out debugger information about the step (including breakpoint information) **/
Step the VM and print out debugger information about the step (including breakpoint information)
[ "Step", "the", "VM", "and", "print", "out", "debugger", "information", "about", "the", "step", "(", "including", "breakpoint", "information", ")" ]
static void dbg_step(const bool step_log) { const char* op = op_decode(g_cpu->code_mem[g_cpu->pc]); create_call_history(); if (step_log) { printf("0x%08X: %-14s\n", g_cpu->pc, op); } step(); if (at_breakpoint() != 0) { op = op_decode(g_cpu->code_mem[g_cpu->pc]); print_breakpoint_msg(at_breakpoint()); printf(" when PC=0x%08X and OP=%-14s\n", g_cpu->pc, op); } }
[ "static", "void", "dbg_step", "(", "const", "bool", "step_log", ")", "{", "const", "char", "*", "op", "=", "op_decode", "(", "g_cpu", "->", "code_mem", "[", "g_cpu", "->", "pc", "]", ")", ";", "create_call_history", "(", ")", ";", "if", "(", "step_log", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "g_cpu", "->", "pc", ",", "op", ")", ";", "}", "step", "(", ")", ";", "if", "(", "at_breakpoint", "(", ")", "!=", "0", ")", "{", "op", "=", "op_decode", "(", "g_cpu", "->", "code_mem", "[", "g_cpu", "->", "pc", "]", ")", ";", "print_breakpoint_msg", "(", "at_breakpoint", "(", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "g_cpu", "->", "pc", ",", "op", ")", ";", "}", "}" ]
Step the VM and print out debugger information about the step (including breakpoint information)
[ "Step", "the", "VM", "and", "print", "out", "debugger", "information", "about", "the", "step", "(", "including", "breakpoint", "information", ")" ]
[]
[ { "param": "step_log", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "step_log", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
337ad5eabe36056ecc864eb1d3d039ece712f5ec
tomasz-lisowski/integer-java-virtual-machine
src/ijdb.c
[ "MIT" ]
C
dbg_run
void
static void dbg_run(const bool single_step) { if (single_step) { dbg_step(true); if (finished()) { g_dbg_state->prog_state = FINISHED; } } else { do { dbg_step(false); } while ((at_breakpoint() == 0 && !finished()) || g_dbg_state->quit_flag == true); if (finished()) { g_dbg_state->prog_state = FINISHED; } } }
/** * Step through program (taking into account breakpoints) **/
Step through program (taking into account breakpoints)
[ "Step", "through", "program", "(", "taking", "into", "account", "breakpoints", ")" ]
static void dbg_run(const bool single_step) { if (single_step) { dbg_step(true); if (finished()) { g_dbg_state->prog_state = FINISHED; } } else { do { dbg_step(false); } while ((at_breakpoint() == 0 && !finished()) || g_dbg_state->quit_flag == true); if (finished()) { g_dbg_state->prog_state = FINISHED; } } }
[ "static", "void", "dbg_run", "(", "const", "bool", "single_step", ")", "{", "if", "(", "single_step", ")", "{", "dbg_step", "(", "true", ")", ";", "if", "(", "finished", "(", ")", ")", "{", "g_dbg_state", "->", "prog_state", "=", "FINISHED", ";", "}", "}", "else", "{", "do", "{", "dbg_step", "(", "false", ")", ";", "}", "while", "(", "(", "at_breakpoint", "(", ")", "==", "0", "&&", "!", "finished", "(", ")", ")", "||", "g_dbg_state", "->", "quit_flag", "==", "true", ")", ";", "if", "(", "finished", "(", ")", ")", "{", "g_dbg_state", "->", "prog_state", "=", "FINISHED", ";", "}", "}", "}" ]
Step through program (taking into account breakpoints)
[ "Step", "through", "program", "(", "taking", "into", "account", "breakpoints", ")" ]
[]
[ { "param": "single_step", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "single_step", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cac93d3898e5213f7ffc777fa76837060f823a0a
tomasz-lisowski/integer-java-virtual-machine
src/loader.c
[ "MIT" ]
C
check_file_signature
bool
static bool check_file_signature(const uint32_t magic_number) { if (swap_uint32(magic_number) != MAGIC_NUMBER) { fprintf(stderr, "[ERR] Bad file signature. In \"loader.c::check_file_signature\".\n"); return false; } else { return true; } }
/** * Check that magic number fits the IJVM binary signature * Returns 1 on good magic number * 0 on bad magic number **/
Check that magic number fits the IJVM binary signature Returns 1 on good magic number 0 on bad magic number
[ "Check", "that", "magic", "number", "fits", "the", "IJVM", "binary", "signature", "Returns", "1", "on", "good", "magic", "number", "0", "on", "bad", "magic", "number" ]
static bool check_file_signature(const uint32_t magic_number) { if (swap_uint32(magic_number) != MAGIC_NUMBER) { fprintf(stderr, "[ERR] Bad file signature. In \"loader.c::check_file_signature\".\n"); return false; } else { return true; } }
[ "static", "bool", "check_file_signature", "(", "const", "uint32_t", "magic_number", ")", "{", "if", "(", "swap_uint32", "(", "magic_number", ")", "!=", "MAGIC_NUMBER", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\\"", "\\\"", "\\n", "\"", ")", ";", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Check that magic number fits the IJVM binary signature Returns 1 on good magic number 0 on bad magic number
[ "Check", "that", "magic", "number", "fits", "the", "IJVM", "binary", "signature", "Returns", "1", "on", "good", "magic", "number", "0", "on", "bad", "magic", "number" ]
[]
[ { "param": "magic_number", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "magic_number", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cac93d3898e5213f7ffc777fa76837060f823a0a
tomasz-lisowski/integer-java-virtual-machine
src/loader.c
[ "MIT" ]
C
load_consts
bool
static bool load_consts(FILE* f) { size_t num_elements_read; int tmp_mem_size; // Read origin uint32_t const_pool_origin; num_elements_read = fread(&(const_pool_origin), sizeof(const_pool_origin), 1, f); if (num_elements_read != 1) { return false; } const_pool_origin = swap_uint32(const_pool_origin); // Read size num_elements_read = fread(&(g_cpu->const_mem_size), sizeof(g_cpu->const_mem_size), 1, f); if (num_elements_read != 1) { return false; } g_cpu->const_mem_size = (int)swap_uint32((uint32_t)g_cpu->const_mem_size); if (g_cpu->const_mem_size % 4 != 0) { return false; // There aren't an integer number of constants } // Read consts tmp_mem_size = g_cpu->const_mem_size; g_cpu->const_mem = (word_t*)malloc((uint32_t)tmp_mem_size * sizeof(word_t)); if (g_cpu->const_mem == NULL) { return false; } num_elements_read = fread(g_cpu->const_mem, sizeof(word_t), (uint32_t)g_cpu->const_mem_size / sizeof(word_t), f); if (num_elements_read != (uint32_t)g_cpu->const_mem_size / sizeof(word_t)) { return false; } for (unsigned int i = 0; i < (uint32_t)g_cpu->const_mem_size / sizeof(word_t); i++) { (g_cpu->const_mem)[i] = (word_t)swap_uint32((uint32_t)(g_cpu->const_mem)[i]); } return true; }
/** * Given an open file, load the const origin, size, and pool into the CPU * Returns 1 on success * 0 on failure **/
Given an open file, load the const origin, size, and pool into the CPU Returns 1 on success 0 on failure
[ "Given", "an", "open", "file", "load", "the", "const", "origin", "size", "and", "pool", "into", "the", "CPU", "Returns", "1", "on", "success", "0", "on", "failure" ]
static bool load_consts(FILE* f) { size_t num_elements_read; int tmp_mem_size; uint32_t const_pool_origin; num_elements_read = fread(&(const_pool_origin), sizeof(const_pool_origin), 1, f); if (num_elements_read != 1) { return false; } const_pool_origin = swap_uint32(const_pool_origin); num_elements_read = fread(&(g_cpu->const_mem_size), sizeof(g_cpu->const_mem_size), 1, f); if (num_elements_read != 1) { return false; } g_cpu->const_mem_size = (int)swap_uint32((uint32_t)g_cpu->const_mem_size); if (g_cpu->const_mem_size % 4 != 0) { return false; } tmp_mem_size = g_cpu->const_mem_size; g_cpu->const_mem = (word_t*)malloc((uint32_t)tmp_mem_size * sizeof(word_t)); if (g_cpu->const_mem == NULL) { return false; } num_elements_read = fread(g_cpu->const_mem, sizeof(word_t), (uint32_t)g_cpu->const_mem_size / sizeof(word_t), f); if (num_elements_read != (uint32_t)g_cpu->const_mem_size / sizeof(word_t)) { return false; } for (unsigned int i = 0; i < (uint32_t)g_cpu->const_mem_size / sizeof(word_t); i++) { (g_cpu->const_mem)[i] = (word_t)swap_uint32((uint32_t)(g_cpu->const_mem)[i]); } return true; }
[ "static", "bool", "load_consts", "(", "FILE", "*", "f", ")", "{", "size_t", "num_elements_read", ";", "int", "tmp_mem_size", ";", "uint32_t", "const_pool_origin", ";", "num_elements_read", "=", "fread", "(", "&", "(", "const_pool_origin", ")", ",", "sizeof", "(", "const_pool_origin", ")", ",", "1", ",", "f", ")", ";", "if", "(", "num_elements_read", "!=", "1", ")", "{", "return", "false", ";", "}", "const_pool_origin", "=", "swap_uint32", "(", "const_pool_origin", ")", ";", "num_elements_read", "=", "fread", "(", "&", "(", "g_cpu", "->", "const_mem_size", ")", ",", "sizeof", "(", "g_cpu", "->", "const_mem_size", ")", ",", "1", ",", "f", ")", ";", "if", "(", "num_elements_read", "!=", "1", ")", "{", "return", "false", ";", "}", "g_cpu", "->", "const_mem_size", "=", "(", "int", ")", "swap_uint32", "(", "(", "uint32_t", ")", "g_cpu", "->", "const_mem_size", ")", ";", "if", "(", "g_cpu", "->", "const_mem_size", "%", "4", "!=", "0", ")", "{", "return", "false", ";", "}", "tmp_mem_size", "=", "g_cpu", "->", "const_mem_size", ";", "g_cpu", "->", "const_mem", "=", "(", "word_t", "*", ")", "malloc", "(", "(", "uint32_t", ")", "tmp_mem_size", "*", "sizeof", "(", "word_t", ")", ")", ";", "if", "(", "g_cpu", "->", "const_mem", "==", "NULL", ")", "{", "return", "false", ";", "}", "num_elements_read", "=", "fread", "(", "g_cpu", "->", "const_mem", ",", "sizeof", "(", "word_t", ")", ",", "(", "uint32_t", ")", "g_cpu", "->", "const_mem_size", "/", "sizeof", "(", "word_t", ")", ",", "f", ")", ";", "if", "(", "num_elements_read", "!=", "(", "uint32_t", ")", "g_cpu", "->", "const_mem_size", "/", "sizeof", "(", "word_t", ")", ")", "{", "return", "false", ";", "}", "for", "(", "unsigned", "int", "i", "=", "0", ";", "i", "<", "(", "uint32_t", ")", "g_cpu", "->", "const_mem_size", "/", "sizeof", "(", "word_t", ")", ";", "i", "++", ")", "{", "(", "g_cpu", "->", "const_mem", ")", "[", "i", "]", "=", "(", "word_t", ")", "swap_uint32", "(", "(", "uint32_t", ")", "(", "g_cpu", "->", "const_mem", ")", "[", "i", "]", ")", ";", "}", "return", "true", ";", "}" ]
Given an open file, load the const origin, size, and pool into the CPU Returns 1 on success 0 on failure
[ "Given", "an", "open", "file", "load", "the", "const", "origin", "size", "and", "pool", "into", "the", "CPU", "Returns", "1", "on", "success", "0", "on", "failure" ]
[ "// Read origin", "// Read size", "// There aren't an integer number of constants", "// Read consts" ]
[ { "param": "f", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "f", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
cac93d3898e5213f7ffc777fa76837060f823a0a
tomasz-lisowski/integer-java-virtual-machine
src/loader.c
[ "MIT" ]
C
load_code
bool
static bool load_code(FILE* f) { size_t num_elements_read; int tmp_mem_size; // Read origin uint32_t text_origin; num_elements_read = fread(&(text_origin), sizeof(text_origin), 1, f); if (num_elements_read != 1) { return false; } text_origin = swap_uint32(text_origin); // Read size num_elements_read = fread(&(g_cpu->code_mem_size), sizeof(g_cpu->code_mem_size), 1, f); if (num_elements_read != 1) { return false; } g_cpu->code_mem_size = (int)swap_uint32((uint32_t)g_cpu->code_mem_size); // Read code tmp_mem_size = g_cpu->code_mem_size; g_cpu->code_mem = (byte_t*)malloc((uint32_t)tmp_mem_size * sizeof(byte_t)); if (g_cpu->code_mem == NULL) { return false; } num_elements_read = fread(g_cpu->code_mem, sizeof(byte_t), (uint32_t)g_cpu->code_mem_size, f); if (num_elements_read != (uint32_t)g_cpu->code_mem_size / sizeof(byte_t)) { return false; } return true; }
/** * Given an open file, load the text origin, size, and code into the CPU * Returns 1 on success * 0 on failure **/
Given an open file, load the text origin, size, and code into the CPU Returns 1 on success 0 on failure
[ "Given", "an", "open", "file", "load", "the", "text", "origin", "size", "and", "code", "into", "the", "CPU", "Returns", "1", "on", "success", "0", "on", "failure" ]
static bool load_code(FILE* f) { size_t num_elements_read; int tmp_mem_size; uint32_t text_origin; num_elements_read = fread(&(text_origin), sizeof(text_origin), 1, f); if (num_elements_read != 1) { return false; } text_origin = swap_uint32(text_origin); num_elements_read = fread(&(g_cpu->code_mem_size), sizeof(g_cpu->code_mem_size), 1, f); if (num_elements_read != 1) { return false; } g_cpu->code_mem_size = (int)swap_uint32((uint32_t)g_cpu->code_mem_size); tmp_mem_size = g_cpu->code_mem_size; g_cpu->code_mem = (byte_t*)malloc((uint32_t)tmp_mem_size * sizeof(byte_t)); if (g_cpu->code_mem == NULL) { return false; } num_elements_read = fread(g_cpu->code_mem, sizeof(byte_t), (uint32_t)g_cpu->code_mem_size, f); if (num_elements_read != (uint32_t)g_cpu->code_mem_size / sizeof(byte_t)) { return false; } return true; }
[ "static", "bool", "load_code", "(", "FILE", "*", "f", ")", "{", "size_t", "num_elements_read", ";", "int", "tmp_mem_size", ";", "uint32_t", "text_origin", ";", "num_elements_read", "=", "fread", "(", "&", "(", "text_origin", ")", ",", "sizeof", "(", "text_origin", ")", ",", "1", ",", "f", ")", ";", "if", "(", "num_elements_read", "!=", "1", ")", "{", "return", "false", ";", "}", "text_origin", "=", "swap_uint32", "(", "text_origin", ")", ";", "num_elements_read", "=", "fread", "(", "&", "(", "g_cpu", "->", "code_mem_size", ")", ",", "sizeof", "(", "g_cpu", "->", "code_mem_size", ")", ",", "1", ",", "f", ")", ";", "if", "(", "num_elements_read", "!=", "1", ")", "{", "return", "false", ";", "}", "g_cpu", "->", "code_mem_size", "=", "(", "int", ")", "swap_uint32", "(", "(", "uint32_t", ")", "g_cpu", "->", "code_mem_size", ")", ";", "tmp_mem_size", "=", "g_cpu", "->", "code_mem_size", ";", "g_cpu", "->", "code_mem", "=", "(", "byte_t", "*", ")", "malloc", "(", "(", "uint32_t", ")", "tmp_mem_size", "*", "sizeof", "(", "byte_t", ")", ")", ";", "if", "(", "g_cpu", "->", "code_mem", "==", "NULL", ")", "{", "return", "false", ";", "}", "num_elements_read", "=", "fread", "(", "g_cpu", "->", "code_mem", ",", "sizeof", "(", "byte_t", ")", ",", "(", "uint32_t", ")", "g_cpu", "->", "code_mem_size", ",", "f", ")", ";", "if", "(", "num_elements_read", "!=", "(", "uint32_t", ")", "g_cpu", "->", "code_mem_size", "/", "sizeof", "(", "byte_t", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Given an open file, load the text origin, size, and code into the CPU Returns 1 on success 0 on failure
[ "Given", "an", "open", "file", "load", "the", "text", "origin", "size", "and", "code", "into", "the", "CPU", "Returns", "1", "on", "success", "0", "on", "failure" ]
[ "// Read origin", "// Read size", "// Read code" ]
[ { "param": "f", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "f", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
e3feea02603cb8012b441bedb0b464d8929cb03c
tomasz-lisowski/integer-java-virtual-machine
src/net.c
[ "MIT" ]
C
socket_create
word_t
static word_t socket_create(const uint32_t host, const uint16_t port) { Sock_t* sock = (Sock_t*)malloc(sizeof(Sock_t)); sock->fd = socket(AF_INET, SOCK_STREAM, 0); sock->fds = -1; sock->client = false; sock->server = false; sock->addr.sin_family = AF_INET; sock->addr.sin_port = htons(port); sock->addr.sin_addr.s_addr = htonl(host); sock->addr_len = sizeof(sock->addr); return socket_store(sock); }
/** * Create an IPv4 TCP socket and return it's network reference **/
Create an IPv4 TCP socket and return it's network reference
[ "Create", "an", "IPv4", "TCP", "socket", "and", "return", "it", "'", "s", "network", "reference" ]
static word_t socket_create(const uint32_t host, const uint16_t port) { Sock_t* sock = (Sock_t*)malloc(sizeof(Sock_t)); sock->fd = socket(AF_INET, SOCK_STREAM, 0); sock->fds = -1; sock->client = false; sock->server = false; sock->addr.sin_family = AF_INET; sock->addr.sin_port = htons(port); sock->addr.sin_addr.s_addr = htonl(host); sock->addr_len = sizeof(sock->addr); return socket_store(sock); }
[ "static", "word_t", "socket_create", "(", "const", "uint32_t", "host", ",", "const", "uint16_t", "port", ")", "{", "Sock_t", "*", "sock", "=", "(", "Sock_t", "*", ")", "malloc", "(", "sizeof", "(", "Sock_t", ")", ")", ";", "sock", "->", "fd", "=", "socket", "(", "AF_INET", ",", "SOCK_STREAM", ",", "0", ")", ";", "sock", "->", "fds", "=", "-1", ";", "sock", "->", "client", "=", "false", ";", "sock", "->", "server", "=", "false", ";", "sock", "->", "addr", ".", "sin_family", "=", "AF_INET", ";", "sock", "->", "addr", ".", "sin_port", "=", "htons", "(", "port", ")", ";", "sock", "->", "addr", ".", "sin_addr", ".", "s_addr", "=", "htonl", "(", "host", ")", ";", "sock", "->", "addr_len", "=", "sizeof", "(", "sock", "->", "addr", ")", ";", "return", "socket_store", "(", "sock", ")", ";", "}" ]
Create an IPv4 TCP socket and return it's network reference
[ "Create", "an", "IPv4", "TCP", "socket", "and", "return", "it", "'", "s", "network", "reference" ]
[]
[ { "param": "host", "type": "uint32_t" }, { "param": "port", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "host", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "port", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
e3feea02603cb8012b441bedb0b464d8929cb03c
tomasz-lisowski/integer-java-virtual-machine
src/net.c
[ "MIT" ]
C
net_check_ref
void
static void net_check_ref(const word_t net_ref) { if ((((uint32_t)net_ref & 0xFF00000F) ^ k_index_to_ref) != 0) { fprintf(stderr, "[ERR] Invalid network reference or program requires more connections than is possible. In \"net.c::net_check_ref\".\n"); destroy_ijvm_now(); } }
/** * Utility to check if network reference is valid **/
Utility to check if network reference is valid
[ "Utility", "to", "check", "if", "network", "reference", "is", "valid" ]
static void net_check_ref(const word_t net_ref) { if ((((uint32_t)net_ref & 0xFF00000F) ^ k_index_to_ref) != 0) { fprintf(stderr, "[ERR] Invalid network reference or program requires more connections than is possible. In \"net.c::net_check_ref\".\n"); destroy_ijvm_now(); } }
[ "static", "void", "net_check_ref", "(", "const", "word_t", "net_ref", ")", "{", "if", "(", "(", "(", "(", "uint32_t", ")", "net_ref", "&", "0xFF00000F", ")", "^", "k_index_to_ref", ")", "!=", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\\"", "\\\"", "\\n", "\"", ")", ";", "destroy_ijvm_now", "(", ")", ";", "}", "}" ]
Utility to check if network reference is valid
[ "Utility", "to", "check", "if", "network", "reference", "is", "valid" ]
[]
[ { "param": "net_ref", "type": "word_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "net_ref", "type": "word_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
e3feea02603cb8012b441bedb0b464d8929cb03c
tomasz-lisowski/integer-java-virtual-machine
src/net.c
[ "MIT" ]
C
socket_store
word_t
static word_t socket_store(const Sock_t* sock) { uint32_t net_i; word_t net_ref; // Initialize if needed if (net_conn.size == 0) { marr_init(&net_conn, NET_CONN_MIN_NUM); } // Save connection info net_i = marr_add_element(&net_conn, (uintptr_t)sock); if (net_i == SIZE_MAX_UINT32_T) { marr_resize(&net_conn, net_conn.size + 16); net_i = marr_add_element(&net_conn, (uintptr_t)sock); } // Return network reference net_ref = index_to_ref(net_i); net_check_ref(net_ref); return net_ref; }
/** * Add the socket to network connections so it can be tracked/modified. * Return network reference of saved socket **/
Add the socket to network connections so it can be tracked/modified. Return network reference of saved socket
[ "Add", "the", "socket", "to", "network", "connections", "so", "it", "can", "be", "tracked", "/", "modified", ".", "Return", "network", "reference", "of", "saved", "socket" ]
static word_t socket_store(const Sock_t* sock) { uint32_t net_i; word_t net_ref; if (net_conn.size == 0) { marr_init(&net_conn, NET_CONN_MIN_NUM); } net_i = marr_add_element(&net_conn, (uintptr_t)sock); if (net_i == SIZE_MAX_UINT32_T) { marr_resize(&net_conn, net_conn.size + 16); net_i = marr_add_element(&net_conn, (uintptr_t)sock); } net_ref = index_to_ref(net_i); net_check_ref(net_ref); return net_ref; }
[ "static", "word_t", "socket_store", "(", "const", "Sock_t", "*", "sock", ")", "{", "uint32_t", "net_i", ";", "word_t", "net_ref", ";", "if", "(", "net_conn", ".", "size", "==", "0", ")", "{", "marr_init", "(", "&", "net_conn", ",", "NET_CONN_MIN_NUM", ")", ";", "}", "net_i", "=", "marr_add_element", "(", "&", "net_conn", ",", "(", "uintptr_t", ")", "sock", ")", ";", "if", "(", "net_i", "==", "SIZE_MAX_UINT32_T", ")", "{", "marr_resize", "(", "&", "net_conn", ",", "net_conn", ".", "size", "+", "16", ")", ";", "net_i", "=", "marr_add_element", "(", "&", "net_conn", ",", "(", "uintptr_t", ")", "sock", ")", ";", "}", "net_ref", "=", "index_to_ref", "(", "net_i", ")", ";", "net_check_ref", "(", "net_ref", ")", ";", "return", "net_ref", ";", "}" ]
Add the socket to network connections so it can be tracked/modified.
[ "Add", "the", "socket", "to", "network", "connections", "so", "it", "can", "be", "tracked", "/", "modified", "." ]
[ "// Initialize if needed", "// Save connection info", "// Return network reference" ]
[ { "param": "sock", "type": "Sock_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sock", "type": "Sock_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ba3e4747f0d1213013921b73b7eddf6d5239d4c2
ct2034/pebble_roadmap
src/c/ks-clock-face.c
[ "MIT" ]
C
prv_unobstructed_will_change
void
static void prv_unobstructed_will_change(GRect final_unobstructed_screen_area, void *context) { if(s_animating) { return; } // Reset the clock animation s_radius = 0; s_anim_hours_60 = 0; }
// Event fires once, before the obstruction appears or disappears
Event fires once, before the obstruction appears or disappears
[ "Event", "fires", "once", "before", "the", "obstruction", "appears", "or", "disappears" ]
static void prv_unobstructed_will_change(GRect final_unobstructed_screen_area, void *context) { if(s_animating) { return; } s_radius = 0; s_anim_hours_60 = 0; }
[ "static", "void", "prv_unobstructed_will_change", "(", "GRect", "final_unobstructed_screen_area", ",", "void", "*", "context", ")", "{", "if", "(", "s_animating", ")", "{", "return", ";", "}", "s_radius", "=", "0", ";", "s_anim_hours_60", "=", "0", ";", "}" ]
Event fires once, before the obstruction appears or disappears
[ "Event", "fires", "once", "before", "the", "obstruction", "appears", "or", "disappears" ]
[ "// Reset the clock animation" ]
[ { "param": "final_unobstructed_screen_area", "type": "GRect" }, { "param": "context", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "final_unobstructed_screen_area", "type": "GRect", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ba3e4747f0d1213013921b73b7eddf6d5239d4c2
ct2034/pebble_roadmap
src/c/ks-clock-face.c
[ "MIT" ]
C
prv_unobstructed_did_change
void
static void prv_unobstructed_did_change(void *context) { if(s_animating) { return; } // Play the clock animation prv_start_animation(); }
// Event fires once, after obstruction appears or disappears
Event fires once, after obstruction appears or disappears
[ "Event", "fires", "once", "after", "obstruction", "appears", "or", "disappears" ]
static void prv_unobstructed_did_change(void *context) { if(s_animating) { return; } prv_start_animation(); }
[ "static", "void", "prv_unobstructed_did_change", "(", "void", "*", "context", ")", "{", "if", "(", "s_animating", ")", "{", "return", ";", "}", "prv_start_animation", "(", ")", ";", "}" ]
Event fires once, after obstruction appears or disappears
[ "Event", "fires", "once", "after", "obstruction", "appears", "or", "disappears" ]
[ "// Play the clock animation" ]
[ { "param": "context", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0ecb9a751f9b34d06081622f146affb3b528e11e
justahuman1/bustub
test/buffer/counter.h
[ "MIT" ]
C
CheckFetchPage
void
void CheckFetchPage() { EXPECT_EQ(counts[0], 1) << "has to call FetchPage once"; for (int i = 1; i < num_types; ++i) { EXPECT_EQ(counts[i], 0) << "FetchPage Should not call other functions"; } }
// Make sure fetch page function only calls fetch page once and // does not call other functions
Make sure fetch page function only calls fetch page once and does not call other functions
[ "Make", "sure", "fetch", "page", "function", "only", "calls", "fetch", "page", "once", "and", "does", "not", "call", "other", "functions" ]
void CheckFetchPage() { EXPECT_EQ(counts[0], 1) << "has to call FetchPage once"; for (int i = 1; i < num_types; ++i) { EXPECT_EQ(counts[i], 0) << "FetchPage Should not call other functions"; } }
[ "void", "CheckFetchPage", "(", ")", "{", "EXPECT_EQ", "(", "counts", "[", "0", "]", ",", "1", ")", "<<", "\"", "\"", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "num_types", ";", "++", "i", ")", "{", "EXPECT_EQ", "(", "counts", "[", "i", "]", ",", "0", ")", "<<", "\"", "\"", ";", "}", "}" ]
Make sure fetch page function only calls fetch page once and does not call other functions
[ "Make", "sure", "fetch", "page", "function", "only", "calls", "fetch", "page", "once", "and", "does", "not", "call", "other", "functions" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
377ac22f286f228add8c73110c79d122c15302b9
Artoriasviel/POET
tools/test_files/input/vmult_1.c
[ "BSD-3-Clause" ]
C
vmult_1
void
void vmult_1(const int M,const int N,const double alpha,const double *val,const int n_rows,const double *src,const int incX,const double beta,double *dst,const int incY, int* rowstart, int* col) { int row, j; /*@;BEGIN(Nest1=Nest)@*/for (row=0; row<n_rows; ++row) { /*@;BEGIN(Nest2=Nest)@*/for (j = rowstart[row]; j < rowstart[row+1]; j++) { dst[row] += val[j] * src[col[j]]; } } }
/* pre-transformations: 1. eliminate pointer arithmetics; 2. normalize loops using index variables */
pre-transformations: 1. eliminate pointer arithmetics; 2. normalize loops using index variables
[ "pre", "-", "transformations", ":", "1", ".", "eliminate", "pointer", "arithmetics", ";", "2", ".", "normalize", "loops", "using", "index", "variables" ]
void vmult_1(const int M,const int N,const double alpha,const double *val,const int n_rows,const double *src,const int incX,const double beta,double *dst,const int incY, int* rowstart, int* col) { int row, j; for (row=0; row<n_rows; ++row) { for (j = rowstart[row]; j < rowstart[row+1]; j++) { dst[row] += val[j] * src[col[j]]; } } }
[ "void", "vmult_1", "(", "const", "int", "M", ",", "const", "int", "N", ",", "const", "double", "alpha", ",", "const", "double", "*", "val", ",", "const", "int", "n_rows", ",", "const", "double", "*", "src", ",", "const", "int", "incX", ",", "const", "double", "beta", ",", "double", "*", "dst", ",", "const", "int", "incY", ",", "int", "*", "rowstart", ",", "int", "*", "col", ")", "{", "int", "row", ",", "j", ";", "for", "(", "row", "=", "0", ";", "row", "<", "n_rows", ";", "++", "row", ")", "{", "for", "(", "j", "=", "rowstart", "[", "row", "]", ";", "j", "<", "rowstart", "[", "row", "+", "1", "]", ";", "j", "++", ")", "{", "dst", "[", "row", "]", "+=", "val", "[", "j", "]", "*", "src", "[", "col", "[", "j", "]", "]", ";", "}", "}", "}" ]
pre-transformations: 1. eliminate pointer arithmetics; 2. normalize loops using index variables
[ "pre", "-", "transformations", ":", "1", ".", "eliminate", "pointer", "arithmetics", ";", "2", ".", "normalize", "loops", "using", "index", "variables" ]
[ "/*@;BEGIN(Nest1=Nest)@*/", "/*@;BEGIN(Nest2=Nest)@*/" ]
[ { "param": "M", "type": "int" }, { "param": "N", "type": "int" }, { "param": "alpha", "type": "double" }, { "param": "val", "type": "double" }, { "param": "n_rows", "type": "int" }, { "param": "src", "type": "double" }, { "param": "incX", "type": "int" }, { "param": "beta", "type": "double" }, { "param": "dst", "type": "double" }, { "param": "incY", "type": "int" }, { "param": "rowstart", "type": "int" }, { "param": "col", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "M", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "N", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "alpha", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "val", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "n_rows", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "src", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "incX", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "beta", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "incY", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rowstart", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "col", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
76fea2b1e848127af0e819cd28adb753a803584e
indie12345/My-Projects
Particle_Projects/ParticleSmartClock_OLED_Display/main.c
[ "MIT" ]
C
watchMode
int
int watchMode(String cmd) { /* Fill timeMin with some unexpected value to that doesn't match with the value from Time.minute function and therefore get's updated and printed on the display */ timeMin = 0xFF; if((cmd == "12H") || (cmd == "12h") || (cmd == "12")) { /* Update the variable and store it in EEPROM */ backupVariable = AM_PM_FORMAT; EEPROM.put(EEPROM_ADDR, backupVariable); return 12; } else if((cmd == "24H") || (cmd == "24h") || (cmd == "24")) { backupVariable = HR_FORMAT; EEPROM.put(EEPROM_ADDR, backupVariable); return 24; } else { return 0; } }
/* This function is called when the time mode is change and the function is called */
This function is called when the time mode is change and the function is called
[ "This", "function", "is", "called", "when", "the", "time", "mode", "is", "change", "and", "the", "function", "is", "called" ]
int watchMode(String cmd) { timeMin = 0xFF; if((cmd == "12H") || (cmd == "12h") || (cmd == "12")) { backupVariable = AM_PM_FORMAT; EEPROM.put(EEPROM_ADDR, backupVariable); return 12; } else if((cmd == "24H") || (cmd == "24h") || (cmd == "24")) { backupVariable = HR_FORMAT; EEPROM.put(EEPROM_ADDR, backupVariable); return 24; } else { return 0; } }
[ "int", "watchMode", "(", "String", "cmd", ")", "{", "timeMin", "=", "0xFF", ";", "if", "(", "(", "cmd", "==", "\"", "\"", ")", "||", "(", "cmd", "==", "\"", "\"", ")", "||", "(", "cmd", "==", "\"", "\"", ")", ")", "{", "backupVariable", "=", "AM_PM_FORMAT", ";", "EEPROM", ".", "put", "(", "EEPROM_ADDR", ",", "backupVariable", ")", ";", "return", "12", ";", "}", "else", "if", "(", "(", "cmd", "==", "\"", "\"", ")", "||", "(", "cmd", "==", "\"", "\"", ")", "||", "(", "cmd", "==", "\"", "\"", ")", ")", "{", "backupVariable", "=", "HR_FORMAT", ";", "EEPROM", ".", "put", "(", "EEPROM_ADDR", ",", "backupVariable", ")", ";", "return", "24", ";", "}", "else", "{", "return", "0", ";", "}", "}" ]
This function is called when the time mode is change and the function is called
[ "This", "function", "is", "called", "when", "the", "time", "mode", "is", "change", "and", "the", "function", "is", "called" ]
[ "/* Fill timeMin with some unexpected value to that \n doesn't match with the value from Time.minute function \n and therefore get's updated and printed on the display */", "/* Update the variable and store it in EEPROM */" ]
[ { "param": "cmd", "type": "String" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cmd", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6ff723ce5b3616cc91309a0c41a13a4253929587
acwars/emilia
include/wp_primary_selection.h
[ "MIT" ]
C
zwp_primary_selection_device_manager_v1_destroy
void
static inline void zwp_primary_selection_device_manager_v1_destroy(struct zwp_primary_selection_device_manager_v1 *zwp_primary_selection_device_manager_v1) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_device_manager_v1, ZWP_PRIMARY_SELECTION_DEVICE_MANAGER_V1_DESTROY); wl_proxy_destroy((struct wl_proxy *) zwp_primary_selection_device_manager_v1); }
/** * @ingroup iface_zwp_primary_selection_device_manager_v1 * * Destroy the primary selection device manager. */
@ingroup iface_zwp_primary_selection_device_manager_v1 Destroy the primary selection device manager.
[ "@ingroup", "iface_zwp_primary_selection_device_manager_v1", "Destroy", "the", "primary", "selection", "device", "manager", "." ]
static inline void zwp_primary_selection_device_manager_v1_destroy(struct zwp_primary_selection_device_manager_v1 *zwp_primary_selection_device_manager_v1) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_device_manager_v1, ZWP_PRIMARY_SELECTION_DEVICE_MANAGER_V1_DESTROY); wl_proxy_destroy((struct wl_proxy *) zwp_primary_selection_device_manager_v1); }
[ "static", "inline", "void", "zwp_primary_selection_device_manager_v1_destroy", "(", "struct", "zwp_primary_selection_device_manager_v1", "*", "zwp_primary_selection_device_manager_v1", ")", "{", "wl_proxy_marshal", "(", "(", "struct", "wl_proxy", "*", ")", "zwp_primary_selection_device_manager_v1", ",", "ZWP_PRIMARY_SELECTION_DEVICE_MANAGER_V1_DESTROY", ")", ";", "wl_proxy_destroy", "(", "(", "struct", "wl_proxy", "*", ")", "zwp_primary_selection_device_manager_v1", ")", ";", "}" ]
@ingroup iface_zwp_primary_selection_device_manager_v1 Destroy the primary selection device manager.
[ "@ingroup", "iface_zwp_primary_selection_device_manager_v1", "Destroy", "the", "primary", "selection", "device", "manager", "." ]
[]
[ { "param": "zwp_primary_selection_device_manager_v1", "type": "struct zwp_primary_selection_device_manager_v1" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "zwp_primary_selection_device_manager_v1", "type": "struct zwp_primary_selection_device_manager_v1", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6ff723ce5b3616cc91309a0c41a13a4253929587
acwars/emilia
include/wp_primary_selection.h
[ "MIT" ]
C
zwp_primary_selection_device_v1_set_selection
void
static inline void zwp_primary_selection_device_v1_set_selection(struct zwp_primary_selection_device_v1 *zwp_primary_selection_device_v1, struct zwp_primary_selection_source_v1 *source, uint32_t serial) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_device_v1, ZWP_PRIMARY_SELECTION_DEVICE_V1_SET_SELECTION, source, serial); }
/** * @ingroup iface_zwp_primary_selection_device_v1 * * Replaces the current selection. The previous owner of the primary * selection will receive a wp_primary_selection_source.cancelled event. * * To unset the selection, set the source to NULL. */
@ingroup iface_zwp_primary_selection_device_v1 Replaces the current selection. The previous owner of the primary selection will receive a wp_primary_selection_source.cancelled event. To unset the selection, set the source to NULL.
[ "@ingroup", "iface_zwp_primary_selection_device_v1", "Replaces", "the", "current", "selection", ".", "The", "previous", "owner", "of", "the", "primary", "selection", "will", "receive", "a", "wp_primary_selection_source", ".", "cancelled", "event", ".", "To", "unset", "the", "selection", "set", "the", "source", "to", "NULL", "." ]
static inline void zwp_primary_selection_device_v1_set_selection(struct zwp_primary_selection_device_v1 *zwp_primary_selection_device_v1, struct zwp_primary_selection_source_v1 *source, uint32_t serial) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_device_v1, ZWP_PRIMARY_SELECTION_DEVICE_V1_SET_SELECTION, source, serial); }
[ "static", "inline", "void", "zwp_primary_selection_device_v1_set_selection", "(", "struct", "zwp_primary_selection_device_v1", "*", "zwp_primary_selection_device_v1", ",", "struct", "zwp_primary_selection_source_v1", "*", "source", ",", "uint32_t", "serial", ")", "{", "wl_proxy_marshal", "(", "(", "struct", "wl_proxy", "*", ")", "zwp_primary_selection_device_v1", ",", "ZWP_PRIMARY_SELECTION_DEVICE_V1_SET_SELECTION", ",", "source", ",", "serial", ")", ";", "}" ]
@ingroup iface_zwp_primary_selection_device_v1 Replaces the current selection.
[ "@ingroup", "iface_zwp_primary_selection_device_v1", "Replaces", "the", "current", "selection", "." ]
[]
[ { "param": "zwp_primary_selection_device_v1", "type": "struct zwp_primary_selection_device_v1" }, { "param": "source", "type": "struct zwp_primary_selection_source_v1" }, { "param": "serial", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "zwp_primary_selection_device_v1", "type": "struct zwp_primary_selection_device_v1", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "source", "type": "struct zwp_primary_selection_source_v1", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "serial", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6ff723ce5b3616cc91309a0c41a13a4253929587
acwars/emilia
include/wp_primary_selection.h
[ "MIT" ]
C
zwp_primary_selection_offer_v1_receive
void
static inline void zwp_primary_selection_offer_v1_receive(struct zwp_primary_selection_offer_v1 *zwp_primary_selection_offer_v1, const char *mime_type, int32_t fd) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_offer_v1, ZWP_PRIMARY_SELECTION_OFFER_V1_RECEIVE, mime_type, fd); }
/** * @ingroup iface_zwp_primary_selection_offer_v1 * * To transfer the contents of the primary selection clipboard, the client * issues this request and indicates the mime type that it wants to * receive. The transfer happens through the passed file descriptor * (typically created with the pipe system call). The source client writes * the data in the mime type representation requested and then closes the * file descriptor. * * The receiving client reads from the read end of the pipe until EOF and * closes its end, at which point the transfer is complete. */
@ingroup iface_zwp_primary_selection_offer_v1 To transfer the contents of the primary selection clipboard, the client issues this request and indicates the mime type that it wants to receive. The transfer happens through the passed file descriptor (typically created with the pipe system call). The source client writes the data in the mime type representation requested and then closes the file descriptor. The receiving client reads from the read end of the pipe until EOF and closes its end, at which point the transfer is complete.
[ "@ingroup", "iface_zwp_primary_selection_offer_v1", "To", "transfer", "the", "contents", "of", "the", "primary", "selection", "clipboard", "the", "client", "issues", "this", "request", "and", "indicates", "the", "mime", "type", "that", "it", "wants", "to", "receive", ".", "The", "transfer", "happens", "through", "the", "passed", "file", "descriptor", "(", "typically", "created", "with", "the", "pipe", "system", "call", ")", ".", "The", "source", "client", "writes", "the", "data", "in", "the", "mime", "type", "representation", "requested", "and", "then", "closes", "the", "file", "descriptor", ".", "The", "receiving", "client", "reads", "from", "the", "read", "end", "of", "the", "pipe", "until", "EOF", "and", "closes", "its", "end", "at", "which", "point", "the", "transfer", "is", "complete", "." ]
static inline void zwp_primary_selection_offer_v1_receive(struct zwp_primary_selection_offer_v1 *zwp_primary_selection_offer_v1, const char *mime_type, int32_t fd) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_offer_v1, ZWP_PRIMARY_SELECTION_OFFER_V1_RECEIVE, mime_type, fd); }
[ "static", "inline", "void", "zwp_primary_selection_offer_v1_receive", "(", "struct", "zwp_primary_selection_offer_v1", "*", "zwp_primary_selection_offer_v1", ",", "const", "char", "*", "mime_type", ",", "int32_t", "fd", ")", "{", "wl_proxy_marshal", "(", "(", "struct", "wl_proxy", "*", ")", "zwp_primary_selection_offer_v1", ",", "ZWP_PRIMARY_SELECTION_OFFER_V1_RECEIVE", ",", "mime_type", ",", "fd", ")", ";", "}" ]
@ingroup iface_zwp_primary_selection_offer_v1 To transfer the contents of the primary selection clipboard, the client issues this request and indicates the mime type that it wants to receive.
[ "@ingroup", "iface_zwp_primary_selection_offer_v1", "To", "transfer", "the", "contents", "of", "the", "primary", "selection", "clipboard", "the", "client", "issues", "this", "request", "and", "indicates", "the", "mime", "type", "that", "it", "wants", "to", "receive", "." ]
[]
[ { "param": "zwp_primary_selection_offer_v1", "type": "struct zwp_primary_selection_offer_v1" }, { "param": "mime_type", "type": "char" }, { "param": "fd", "type": "int32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "zwp_primary_selection_offer_v1", "type": "struct zwp_primary_selection_offer_v1", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mime_type", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fd", "type": "int32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6ff723ce5b3616cc91309a0c41a13a4253929587
acwars/emilia
include/wp_primary_selection.h
[ "MIT" ]
C
zwp_primary_selection_source_v1_offer
void
static inline void zwp_primary_selection_source_v1_offer(struct zwp_primary_selection_source_v1 *zwp_primary_selection_source_v1, const char *mime_type) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_source_v1, ZWP_PRIMARY_SELECTION_SOURCE_V1_OFFER, mime_type); }
/** * @ingroup iface_zwp_primary_selection_source_v1 * * This request adds a mime type to the set of mime types advertised to * targets. Can be called several times to offer multiple types. */
@ingroup iface_zwp_primary_selection_source_v1 This request adds a mime type to the set of mime types advertised to targets. Can be called several times to offer multiple types.
[ "@ingroup", "iface_zwp_primary_selection_source_v1", "This", "request", "adds", "a", "mime", "type", "to", "the", "set", "of", "mime", "types", "advertised", "to", "targets", ".", "Can", "be", "called", "several", "times", "to", "offer", "multiple", "types", "." ]
static inline void zwp_primary_selection_source_v1_offer(struct zwp_primary_selection_source_v1 *zwp_primary_selection_source_v1, const char *mime_type) { wl_proxy_marshal((struct wl_proxy *) zwp_primary_selection_source_v1, ZWP_PRIMARY_SELECTION_SOURCE_V1_OFFER, mime_type); }
[ "static", "inline", "void", "zwp_primary_selection_source_v1_offer", "(", "struct", "zwp_primary_selection_source_v1", "*", "zwp_primary_selection_source_v1", ",", "const", "char", "*", "mime_type", ")", "{", "wl_proxy_marshal", "(", "(", "struct", "wl_proxy", "*", ")", "zwp_primary_selection_source_v1", ",", "ZWP_PRIMARY_SELECTION_SOURCE_V1_OFFER", ",", "mime_type", ")", ";", "}" ]
@ingroup iface_zwp_primary_selection_source_v1 This request adds a mime type to the set of mime types advertised to targets.
[ "@ingroup", "iface_zwp_primary_selection_source_v1", "This", "request", "adds", "a", "mime", "type", "to", "the", "set", "of", "mime", "types", "advertised", "to", "targets", "." ]
[]
[ { "param": "zwp_primary_selection_source_v1", "type": "struct zwp_primary_selection_source_v1" }, { "param": "mime_type", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "zwp_primary_selection_source_v1", "type": "struct zwp_primary_selection_source_v1", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mime_type", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5a650c457b7bf36a7d0214f294ed1ae6f1a0905b
alfredrc/beepbox
include/VRand.h
[ "Apache-2.0" ]
C
CTZ
int
int inline CTZ(int num) { int i=0; while (((num>>i)&1)==0 && i<sizeof(int)) i++; return i; }
// please contribute assembler for mac/sparc/sgi/etc.
please contribute assembler for mac/sparc/sgi/etc.
[ "please", "contribute", "assembler", "for", "mac", "/", "sparc", "/", "sgi", "/", "etc", "." ]
int inline CTZ(int num) { int i=0; while (((num>>i)&1)==0 && i<sizeof(int)) i++; return i; }
[ "int", "inline", "CTZ", "(", "int", "num", ")", "{", "int", "i", "=", "0", ";", "while", "(", "(", "(", "num", ">>", "i", ")", "&", "1", ")", "==", "0", "&&", "i", "<", "sizeof", "(", "int", ")", ")", "i", "++", ";", "return", "i", ";", "}" ]
please contribute assembler for mac/sparc/sgi/etc.
[ "please", "contribute", "assembler", "for", "mac", "/", "sparc", "/", "sgi", "/", "etc", "." ]
[]
[ { "param": "num", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "num", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5a650c457b7bf36a7d0214f294ed1ae6f1a0905b
alfredrc/beepbox
include/VRand.h
[ "Apache-2.0" ]
C
pink
float
inline float pink(void) { float prevr; float r; unsigned long k; k = CTZ(m_count); k = k & NumPinkBins1; // get previous value of this octave prevr = m_pinkStore[k]; while (true) { r = white(); // store new value m_pinkStore[k] = r; r -= prevr; // update total m_pink += r; if (m_pink <-4.0f || m_pink > 4.0f) m_pink -= r; else break; } // update counter m_count++; return (white() + m_pink)*0.125f; }
// returns pink noise random number in the range -0.5 to 0.5 //
returns pink noise random number in the range -0.5 to 0.5
[ "returns", "pink", "noise", "random", "number", "in", "the", "range", "-", "0", ".", "5", "to", "0", ".", "5" ]
inline float pink(void) { float prevr; float r; unsigned long k; k = CTZ(m_count); k = k & NumPinkBins1; prevr = m_pinkStore[k]; while (true) { r = white(); m_pinkStore[k] = r; r -= prevr; m_pink += r; if (m_pink <-4.0f || m_pink > 4.0f) m_pink -= r; else break; } m_count++; return (white() + m_pink)*0.125f; }
[ "inline", "float", "pink", "(", "void", ")", "{", "float", "prevr", ";", "float", "r", ";", "unsigned", "long", "k", ";", "k", "=", "CTZ", "(", "m_count", ")", ";", "k", "=", "k", "&", "NumPinkBins1", ";", "prevr", "=", "m_pinkStore", "[", "k", "]", ";", "while", "(", "true", ")", "{", "r", "=", "white", "(", ")", ";", "m_pinkStore", "[", "k", "]", "=", "r", ";", "r", "-=", "prevr", ";", "m_pink", "+=", "r", ";", "if", "(", "m_pink", "<", "-4.0f", "||", "m_pink", ">", "4.0f", ")", "m_pink", "-=", "r", ";", "else", "break", ";", "}", "m_count", "++", ";", "return", "(", "white", "(", ")", "+", "m_pink", ")", "*", "0.125f", ";", "}" ]
returns pink noise random number in the range -0.5 to 0.5
[ "returns", "pink", "noise", "random", "number", "in", "the", "range", "-", "0", ".", "5", "to", "0", ".", "5" ]
[ "// get previous value of this octave ", "// store new value ", "// update total ", "// update counter " ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
5a650c457b7bf36a7d0214f294ed1ae6f1a0905b
alfredrc/beepbox
include/VRand.h
[ "Apache-2.0" ]
C
brown
float
inline float brown(void) { while (true) { float r = white(); m_brown += r; if (m_brown<-8.0f || m_brown>8.0f) m_brown -= r; else break; } return m_brown*0.0625f; }
// returns brown noise random number in the range -0.5 to 0.5 //
returns brown noise random number in the range -0.5 to 0.5
[ "returns", "brown", "noise", "random", "number", "in", "the", "range", "-", "0", ".", "5", "to", "0", ".", "5" ]
inline float brown(void) { while (true) { float r = white(); m_brown += r; if (m_brown<-8.0f || m_brown>8.0f) m_brown -= r; else break; } return m_brown*0.0625f; }
[ "inline", "float", "brown", "(", "void", ")", "{", "while", "(", "true", ")", "{", "float", "r", "=", "white", "(", ")", ";", "m_brown", "+=", "r", ";", "if", "(", "m_brown", "<", "-8.0f", "||", "m_brown", ">", "8.0f", ")", "m_brown", "-=", "r", ";", "else", "break", ";", "}", "return", "m_brown", "*", "0.0625f", ";", "}" ]
returns brown noise random number in the range -0.5 to 0.5
[ "returns", "brown", "noise", "random", "number", "in", "the", "range", "-", "0", ".", "5", "to", "0", ".", "5" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8aadfab5e37bb52fba4455accedb27f809830445
codezinfinity/esp-homekit
src/accessories.c
[ "MIT" ]
C
homekit_accessories_clear_notify_callbacks
void
void homekit_accessories_clear_notify_callbacks( homekit_accessory_t **accessories, homekit_characteristic_change_callback_fn function, void *context ) { for (homekit_accessory_t **accessory_it = accessories; *accessory_it; accessory_it++) { homekit_accessory_t *accessory = *accessory_it; for (homekit_service_t **service_it = accessory->services; *service_it; service_it++) { homekit_service_t *service = *service_it; for (homekit_characteristic_t **ch_it = service->characteristics; *ch_it; ch_it++) { homekit_characteristic_t *ch = *ch_it; homekit_characteristic_remove_notify_callback(ch, function, context); } } } }
// Removes particular callback from all characteristics
Removes particular callback from all characteristics
[ "Removes", "particular", "callback", "from", "all", "characteristics" ]
void homekit_accessories_clear_notify_callbacks( homekit_accessory_t **accessories, homekit_characteristic_change_callback_fn function, void *context ) { for (homekit_accessory_t **accessory_it = accessories; *accessory_it; accessory_it++) { homekit_accessory_t *accessory = *accessory_it; for (homekit_service_t **service_it = accessory->services; *service_it; service_it++) { homekit_service_t *service = *service_it; for (homekit_characteristic_t **ch_it = service->characteristics; *ch_it; ch_it++) { homekit_characteristic_t *ch = *ch_it; homekit_characteristic_remove_notify_callback(ch, function, context); } } } }
[ "void", "homekit_accessories_clear_notify_callbacks", "(", "homekit_accessory_t", "*", "*", "accessories", ",", "homekit_characteristic_change_callback_fn", "function", ",", "void", "*", "context", ")", "{", "for", "(", "homekit_accessory_t", "*", "*", "accessory_it", "=", "accessories", ";", "*", "accessory_it", ";", "accessory_it", "++", ")", "{", "homekit_accessory_t", "*", "accessory", "=", "*", "accessory_it", ";", "for", "(", "homekit_service_t", "*", "*", "service_it", "=", "accessory", "->", "services", ";", "*", "service_it", ";", "service_it", "++", ")", "{", "homekit_service_t", "*", "service", "=", "*", "service_it", ";", "for", "(", "homekit_characteristic_t", "*", "*", "ch_it", "=", "service", "->", "characteristics", ";", "*", "ch_it", ";", "ch_it", "++", ")", "{", "homekit_characteristic_t", "*", "ch", "=", "*", "ch_it", ";", "homekit_characteristic_remove_notify_callback", "(", "ch", ",", "function", ",", "context", ")", ";", "}", "}", "}", "}" ]
Removes particular callback from all characteristics
[ "Removes", "particular", "callback", "from", "all", "characteristics" ]
[]
[ { "param": "accessories", "type": "homekit_accessory_t" }, { "param": "function", "type": "homekit_characteristic_change_callback_fn" }, { "param": "context", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "accessories", "type": "homekit_accessory_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "function", "type": "homekit_characteristic_change_callback_fn", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c4591518cde489206ce96af9a4488c428b84df22
pavpen/cpp-operation-log
include/operation_log/function_entry.h
[ "Apache-2.0" ]
C
exit_function
void
void exit_function() { static volatile bool leaving_function; leaving_function = true; }
// This method is used just to keep the object from being destroyed until // the end of the function block has been reached.
This method is used just to keep the object from being destroyed until the end of the function block has been reached.
[ "This", "method", "is", "used", "just", "to", "keep", "the", "object", "from", "being", "destroyed", "until", "the", "end", "of", "the", "function", "block", "has", "been", "reached", "." ]
void exit_function() { static volatile bool leaving_function; leaving_function = true; }
[ "void", "exit_function", "(", ")", "{", "static", "volatile", "bool", "leaving_function", ";", "leaving_function", "=", "true", ";", "}" ]
This method is used just to keep the object from being destroyed until the end of the function block has been reached.
[ "This", "method", "is", "used", "just", "to", "keep", "the", "object", "from", "being", "destroyed", "until", "the", "end", "of", "the", "function", "block", "has", "been", "reached", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
91d6b4e95829292bb608b95d3229572f69e25c78
CordeiroLucas/programs
programs-in-C/file-manipulation/questao1/operaArray.h
[ "MIT" ]
C
deleteN
void
void deleteN (int tamanho, int array[tamanho], FILE *arquivo) { int elemento, m, i = 0; int arrayDelet[tamanho]; printf("\n-DeleteN-\nEnésimo elemento -> "); scanf(" %d", &elemento); for (m = 0; m < tamanho; m++) { if (elemento == m+1) continue; else { arrayDelet[i] = array[m]; i++; } } printf("\nnewArray -> [ "); for (m = 0; m < i; m++) printf("%d ", arrayDelet[m]); printf("]\n"); char resposta; printf("\nDeseja Salvar o Resultado?\nS - Sim | N - Não\n\n-> "); scanf(" %c", &resposta); if (resposta == 'S') { fprintf(arquivo, "deleteN %d = [ ", elemento); for (m = 0; m < i; m++) fprintf(arquivo, "%d ", arrayDelet[m]); fprintf(arquivo, "]\n"); } else return; }
/*Retorna um array de int | Array antigo menos o valor no index escolhido*/
Retorna um array de int | Array antigo menos o valor no index escolhido
[ "Retorna", "um", "array", "de", "int", "|", "Array", "antigo", "menos", "o", "valor", "no", "index", "escolhido" ]
void deleteN (int tamanho, int array[tamanho], FILE *arquivo) { int elemento, m, i = 0; int arrayDelet[tamanho]; printf("\n-DeleteN-\nEnésimo elemento -> "); scanf(" %d", &elemento); for (m = 0; m < tamanho; m++) { if (elemento == m+1) continue; else { arrayDelet[i] = array[m]; i++; } } printf("\nnewArray -> [ "); for (m = 0; m < i; m++) printf("%d ", arrayDelet[m]); printf("]\n"); char resposta; printf("\nDeseja Salvar o Resultado?\nS - Sim | N - Não\n\n-> "); scanf(" %c", &resposta); if (resposta == 'S') { fprintf(arquivo, "deleteN %d = [ ", elemento); for (m = 0; m < i; m++) fprintf(arquivo, "%d ", arrayDelet[m]); fprintf(arquivo, "]\n"); } else return; }
[ "void", "deleteN", "(", "int", "tamanho", ",", "int", "array", "[", "tamanho", "]", ",", "FILE", "*", "arquivo", ")", "{", "int", "elemento", ",", "m", ",", "i", "=", "0", ";", "int", "arrayDelet", "[", "tamanho", "]", ";", "printf", "(", "\"", "\\n", "\\n", ")", ";", "", "scanf", "(", "\"", "\"", ",", "&", "elemento", ")", ";", "for", "(", "m", "=", "0", ";", "m", "<", "tamanho", ";", "m", "++", ")", "{", "if", "(", "elemento", "==", "m", "+", "1", ")", "continue", ";", "else", "{", "arrayDelet", "[", "i", "]", "=", "array", "[", "m", "]", ";", "i", "++", ";", "}", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "for", "(", "m", "=", "0", ";", "m", "<", "i", ";", "m", "++", ")", "printf", "(", "\"", "\"", ",", "arrayDelet", "[", "m", "]", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "char", "resposta", ";", "printf", "(", "\"", "\\n", "\\n", "n\\", "n-", ")", ";", "", "scanf", "(", "\"", "\"", ",", "&", "resposta", ")", ";", "if", "(", "resposta", "==", "'", "'", ")", "{", "fprintf", "(", "arquivo", ",", "\"", "\"", ",", "elemento", ")", ";", "for", "(", "m", "=", "0", ";", "m", "<", "i", ";", "m", "++", ")", "fprintf", "(", "arquivo", ",", "\"", "\"", ",", "arrayDelet", "[", "m", "]", ")", ";", "fprintf", "(", "arquivo", ",", "\"", "\\n", "\"", ")", ";", "}", "else", "return", ";", "}" ]
Retorna um array de int | Array antigo menos o valor no index escolhido
[ "Retorna", "um", "array", "de", "int", "|", "Array", "antigo", "menos", "o", "valor", "no", "index", "escolhido" ]
[]
[ { "param": "tamanho", "type": "int" }, { "param": "array", "type": "int" }, { "param": "arquivo", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "tamanho", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "array", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "arquivo", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9eebf100b41ce88c960c67ae71b3e9e78057207e
chloe0b0/E
src/E.c
[ "MIT" ]
C
Evolve
void
void Evolve(struct Universe* universe){ int ruleIndex; bool* newState = calloc(universe->length, sizeof(bool)); for (int i = 0; i <= universe->length; ++i){ bool l, c, r; l = i ? universe->state[i - 1] : universe->state[universe->length]; c = universe->state[i]; r = universe->state[i + 1]; ruleIndex = (l*4) + (c*2) + (r); newState[i] = universe->rule & (1 << ruleIndex); } free(universe->state); universe->state = newState; }
// evolve the state of the system by one epoch according to its rule
evolve the state of the system by one epoch according to its rule
[ "evolve", "the", "state", "of", "the", "system", "by", "one", "epoch", "according", "to", "its", "rule" ]
void Evolve(struct Universe* universe){ int ruleIndex; bool* newState = calloc(universe->length, sizeof(bool)); for (int i = 0; i <= universe->length; ++i){ bool l, c, r; l = i ? universe->state[i - 1] : universe->state[universe->length]; c = universe->state[i]; r = universe->state[i + 1]; ruleIndex = (l*4) + (c*2) + (r); newState[i] = universe->rule & (1 << ruleIndex); } free(universe->state); universe->state = newState; }
[ "void", "Evolve", "(", "struct", "Universe", "*", "universe", ")", "{", "int", "ruleIndex", ";", "bool", "*", "newState", "=", "calloc", "(", "universe", "->", "length", ",", "sizeof", "(", "bool", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<=", "universe", "->", "length", ";", "++", "i", ")", "{", "bool", "l", ",", "c", ",", "r", ";", "l", "=", "i", "?", "universe", "->", "state", "[", "i", "-", "1", "]", ":", "universe", "->", "state", "[", "universe", "->", "length", "]", ";", "c", "=", "universe", "->", "state", "[", "i", "]", ";", "r", "=", "universe", "->", "state", "[", "i", "+", "1", "]", ";", "ruleIndex", "=", "(", "l", "*", "4", ")", "+", "(", "c", "*", "2", ")", "+", "(", "r", ")", ";", "newState", "[", "i", "]", "=", "universe", "->", "rule", "&", "(", "1", "<<", "ruleIndex", ")", ";", "}", "free", "(", "universe", "->", "state", ")", ";", "universe", "->", "state", "=", "newState", ";", "}" ]
evolve the state of the system by one epoch according to its rule
[ "evolve", "the", "state", "of", "the", "system", "by", "one", "epoch", "according", "to", "its", "rule" ]
[]
[ { "param": "universe", "type": "struct Universe" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "universe", "type": "struct Universe", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6fa096a4d689743607c8b3ece4e3cd23687a7c13
Tangkaiyuan0311/6.S081
user/find.c
[ "MIT-0" ]
C
find
void
void find(int fd, char* path, char* name) { struct dirent de; //directory entry struct stat st; // file status char buf[512], *p; int _fd; // read each entry of directory fd into de while (read(fd, &de, sizeof(de)) == sizeof(de)) { if (de.inum == 0) continue; if ((strcmp(de.name, ".") == 0) || (strcmp(de.name, "..") == 0)) continue; // construct full filename into buf (path + de.name) memmove(buf, path, strlen(path)+1); p = buf + strlen(path); // *p == 0 *(p++) = '/'; memmove(p, de.name, strlen(de.name)+1); if (strcmp(de.name, name) == 0) printf("%s\n", buf); if(stat(buf, &st) < 0){ printf("cannot stat %s\n", buf); continue; } if (st.type == T_DIR) { if((_fd = open(buf, 0)) < 0){ fprintf(2, "find: cannot open %s\n", buf); continue; } find(_fd, buf, name); close(_fd); } } }
// print all filename in the given directory fd (with path) recursively // do not recurse into . .. // assume: fd has been opened, fd is a directory, fd = open(path, 0);
print all filename in the given directory fd (with path) recursively do not recurse into . assume: fd has been opened, fd is a directory, fd = open(path, 0).
[ "print", "all", "filename", "in", "the", "given", "directory", "fd", "(", "with", "path", ")", "recursively", "do", "not", "recurse", "into", ".", "assume", ":", "fd", "has", "been", "opened", "fd", "is", "a", "directory", "fd", "=", "open", "(", "path", "0", ")", "." ]
void find(int fd, char* path, char* name) { struct dirent de; struct stat st; char buf[512], *p; int _fd; while (read(fd, &de, sizeof(de)) == sizeof(de)) { if (de.inum == 0) continue; if ((strcmp(de.name, ".") == 0) || (strcmp(de.name, "..") == 0)) continue; memmove(buf, path, strlen(path)+1); p = buf + strlen(path); *(p++) = '/'; memmove(p, de.name, strlen(de.name)+1); if (strcmp(de.name, name) == 0) printf("%s\n", buf); if(stat(buf, &st) < 0){ printf("cannot stat %s\n", buf); continue; } if (st.type == T_DIR) { if((_fd = open(buf, 0)) < 0){ fprintf(2, "find: cannot open %s\n", buf); continue; } find(_fd, buf, name); close(_fd); } } }
[ "void", "find", "(", "int", "fd", ",", "char", "*", "path", ",", "char", "*", "name", ")", "{", "struct", "dirent", "de", ";", "struct", "stat", "st", ";", "char", "buf", "[", "512", "]", ",", "*", "p", ";", "int", "_fd", ";", "while", "(", "read", "(", "fd", ",", "&", "de", ",", "sizeof", "(", "de", ")", ")", "==", "sizeof", "(", "de", ")", ")", "{", "if", "(", "de", ".", "inum", "==", "0", ")", "continue", ";", "if", "(", "(", "strcmp", "(", "de", ".", "name", ",", "\"", "\"", ")", "==", "0", ")", "||", "(", "strcmp", "(", "de", ".", "name", ",", "\"", "\"", ")", "==", "0", ")", ")", "continue", ";", "memmove", "(", "buf", ",", "path", ",", "strlen", "(", "path", ")", "+", "1", ")", ";", "p", "=", "buf", "+", "strlen", "(", "path", ")", ";", "*", "(", "p", "++", ")", "=", "'", "'", ";", "memmove", "(", "p", ",", "de", ".", "name", ",", "strlen", "(", "de", ".", "name", ")", "+", "1", ")", ";", "if", "(", "strcmp", "(", "de", ".", "name", ",", "name", ")", "==", "0", ")", "printf", "(", "\"", "\\n", "\"", ",", "buf", ")", ";", "if", "(", "stat", "(", "buf", ",", "&", "st", ")", "<", "0", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "buf", ")", ";", "continue", ";", "}", "if", "(", "st", ".", "type", "==", "T_DIR", ")", "{", "if", "(", "(", "_fd", "=", "open", "(", "buf", ",", "0", ")", ")", "<", "0", ")", "{", "fprintf", "(", "2", ",", "\"", "\\n", "\"", ",", "buf", ")", ";", "continue", ";", "}", "find", "(", "_fd", ",", "buf", ",", "name", ")", ";", "close", "(", "_fd", ")", ";", "}", "}", "}" ]
print all filename in the given directory fd (with path) recursively do not recurse into .
[ "print", "all", "filename", "in", "the", "given", "directory", "fd", "(", "with", "path", ")", "recursively", "do", "not", "recurse", "into", "." ]
[ "//directory entry", "// file status", "// read each entry of directory fd into de", "// construct full filename into buf (path + de.name)", "// *p == 0" ]
[ { "param": "fd", "type": "int" }, { "param": "path", "type": "char" }, { "param": "name", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fd", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5ceddb015d375ddcdc6433640aece999f7182e22
Tangkaiyuan0311/6.S081
user/xargs.c
[ "MIT-0" ]
C
readline
int
int readline(char* line, int fd) { int i = 0; // bytes counter char c; while (read(fd, &c, 1) == 1) { if (c != '\n') line[i++] = c; else { line[i] = 0; break; } } return i; }
// read a line from fd, stores as c string in line, return number of bytes excluding '\0' // size of line is maintained by caller // return 0 on EOF or a single '\n'
read a line from fd, stores as c string in line, return number of bytes excluding '\0' size of line is maintained by caller return 0 on EOF or a single '\n'
[ "read", "a", "line", "from", "fd", "stores", "as", "c", "string", "in", "line", "return", "number", "of", "bytes", "excluding", "'", "\\", "0", "'", "size", "of", "line", "is", "maintained", "by", "caller", "return", "0", "on", "EOF", "or", "a", "single", "'", "\\", "n", "'" ]
int readline(char* line, int fd) { int i = 0; char c; while (read(fd, &c, 1) == 1) { if (c != '\n') line[i++] = c; else { line[i] = 0; break; } } return i; }
[ "int", "readline", "(", "char", "*", "line", ",", "int", "fd", ")", "{", "int", "i", "=", "0", ";", "char", "c", ";", "while", "(", "read", "(", "fd", ",", "&", "c", ",", "1", ")", "==", "1", ")", "{", "if", "(", "c", "!=", "'", "\\n", "'", ")", "line", "[", "i", "++", "]", "=", "c", ";", "else", "{", "line", "[", "i", "]", "=", "0", ";", "break", ";", "}", "}", "return", "i", ";", "}" ]
read a line from fd, stores as c string in line, return number of bytes excluding '\0' size of line is maintained by caller return 0 on EOF or a single '\n'
[ "read", "a", "line", "from", "fd", "stores", "as", "c", "string", "in", "line", "return", "number", "of", "bytes", "excluding", "'", "\\", "0", "'", "size", "of", "line", "is", "maintained", "by", "caller", "return", "0", "on", "EOF", "or", "a", "single", "'", "\\", "n", "'" ]
[ "// bytes counter" ]
[ { "param": "line", "type": "char" }, { "param": "fd", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "line", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fd", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
saadc_init
ret_code_t
static ret_code_t saadc_init(void) { ret_code_t err; static nrfx_saadc_config_t default_config = NRFX_SAADC_DEFAULT_CONFIG; default_config.resolution = NRF_SAADC_RESOLUTION_12BIT; err = nrfx_saadc_init(&default_config, saadc_callback); APP_ERROR_CHECK(err); sensor_hardware_t * hardware; nrf_saadc_channel_config_t conf = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NULL); for (sensor_t s_i = SENSOR_FIRST; s_i <= SENSOR_LAST; s_i++) { hardware = sensor_handle_get_hardware(s_i); err = saadc_config_channel(s_i); APP_ERROR_CHECK(err); nrf_gpio_cfg_output(hardware->pwr_pin); } return NRF_SUCCESS; }
/** * @brief initialize the ADC module and ADC channel for each sensor * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief initialize the ADC module and ADC channel for each sensor @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "initialize", "the", "ADC", "module", "and", "ADC", "channel", "for", "each", "sensor", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
static ret_code_t saadc_init(void) { ret_code_t err; static nrfx_saadc_config_t default_config = NRFX_SAADC_DEFAULT_CONFIG; default_config.resolution = NRF_SAADC_RESOLUTION_12BIT; err = nrfx_saadc_init(&default_config, saadc_callback); APP_ERROR_CHECK(err); sensor_hardware_t * hardware; nrf_saadc_channel_config_t conf = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NULL); for (sensor_t s_i = SENSOR_FIRST; s_i <= SENSOR_LAST; s_i++) { hardware = sensor_handle_get_hardware(s_i); err = saadc_config_channel(s_i); APP_ERROR_CHECK(err); nrf_gpio_cfg_output(hardware->pwr_pin); } return NRF_SUCCESS; }
[ "static", "ret_code_t", "saadc_init", "(", "void", ")", "{", "ret_code_t", "err", ";", "static", "nrfx_saadc_config_t", "default_config", "=", "NRFX_SAADC_DEFAULT_CONFIG", ";", "default_config", ".", "resolution", "=", "NRF_SAADC_RESOLUTION_12BIT", ";", "err", "=", "nrfx_saadc_init", "(", "&", "default_config", ",", "saadc_callback", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "sensor_hardware_t", "*", "hardware", ";", "nrf_saadc_channel_config_t", "conf", "=", "NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE", "(", "NULL", ")", ";", "for", "(", "sensor_t", "s_i", "=", "SENSOR_FIRST", ";", "s_i", "<=", "SENSOR_LAST", ";", "s_i", "++", ")", "{", "hardware", "=", "sensor_handle_get_hardware", "(", "s_i", ")", ";", "err", "=", "saadc_config_channel", "(", "s_i", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "nrf_gpio_cfg_output", "(", "hardware", "->", "pwr_pin", ")", ";", "}", "return", "NRF_SUCCESS", ";", "}" ]
@brief initialize the ADC module and ADC channel for each sensor @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "initialize", "the", "ADC", "module", "and", "ADC", "channel", "for", "each", "sensor", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
sample_one_sensor
ret_code_t
static ret_code_t sample_one_sensor(sensor_t sensor) { ret_code_t err; nrf_saadc_value_t adc_val; sensor_hardware_t * hardware = sensor_handle_get_hardware(sensor); nrf_gpio_pin_set(hardware->pwr_pin); nrf_delay_ms(1); err = nrfx_saadc_sample_convert(hardware->adc_chanel, &adc_val); APP_ERROR_CHECK(err); err = sensor_handle_add_single_value(sensor, adc_val); APP_ERROR_CHECK(err); nrf_gpio_pin_clear(hardware->pwr_pin); //NRF_LOG_INFO("sensor %d adc_val %d", sensor + 1, adc_val); return err; }
/** * @brief Sample the ADC channel for one sensor * * @param[in] sensor Selected sensor * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Sample the ADC channel for one sensor @param[in] sensor Selected sensor @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Sample", "the", "ADC", "channel", "for", "one", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
static ret_code_t sample_one_sensor(sensor_t sensor) { ret_code_t err; nrf_saadc_value_t adc_val; sensor_hardware_t * hardware = sensor_handle_get_hardware(sensor); nrf_gpio_pin_set(hardware->pwr_pin); nrf_delay_ms(1); err = nrfx_saadc_sample_convert(hardware->adc_chanel, &adc_val); APP_ERROR_CHECK(err); err = sensor_handle_add_single_value(sensor, adc_val); APP_ERROR_CHECK(err); nrf_gpio_pin_clear(hardware->pwr_pin); return err; }
[ "static", "ret_code_t", "sample_one_sensor", "(", "sensor_t", "sensor", ")", "{", "ret_code_t", "err", ";", "nrf_saadc_value_t", "adc_val", ";", "sensor_hardware_t", "*", "hardware", "=", "sensor_handle_get_hardware", "(", "sensor", ")", ";", "nrf_gpio_pin_set", "(", "hardware", "->", "pwr_pin", ")", ";", "nrf_delay_ms", "(", "1", ")", ";", "err", "=", "nrfx_saadc_sample_convert", "(", "hardware", "->", "adc_chanel", ",", "&", "adc_val", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "err", "=", "sensor_handle_add_single_value", "(", "sensor", ",", "adc_val", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "nrf_gpio_pin_clear", "(", "hardware", "->", "pwr_pin", ")", ";", "return", "err", ";", "}" ]
@brief Sample the ADC channel for one sensor @param[in] sensor Selected sensor
[ "@brief", "Sample", "the", "ADC", "channel", "for", "one", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor" ]
[ "//NRF_LOG_INFO(\"sensor %d adc_val %d\", sensor + 1, adc_val);" ]
[ { "param": "sensor", "type": "sensor_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
sample_all_sensors
ret_code_t
static ret_code_t sample_all_sensors(void) { ret_code_t err; sensor_ctrl_t * ctrl; ctrl = sensor_handle_get_control(SENSOR_1); if (ctrl->enable) { err = sample_one_sensor(SENSOR_1); //err = sensor_handle_add_single_value(SENSOR_1, 0); APP_ERROR_CHECK(err); } ctrl = sensor_handle_get_control(SENSOR_2); if (ctrl->enable) { err = sample_one_sensor(SENSOR_2); // err = sensor_handle_add_single_value(SENSOR_2, mock_adc++); APP_ERROR_CHECK(err); } ctrl = sensor_handle_get_control(SENSOR_3); if (ctrl->enable) { err = sample_one_sensor(SENSOR_3); // err = sensor_handle_add_single_value(SENSOR_3, 0); APP_ERROR_CHECK(err); } #if (SENSOR_CNT >= 4) ctrl = sensor_handle_get_control(SENSOR_4); if (ctrl->enable) { err = sensor_handle_add_single_value(SENSOR_4, 0); // err = sensor_handle_add_single_value(SENSOR_4, 0); APP_ERROR_CHECK(err); } #endif return err; }
/** * @brief Sample the ADC channels for all sensors * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Sample the ADC channels for all sensors @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Sample", "the", "ADC", "channels", "for", "all", "sensors", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
static ret_code_t sample_all_sensors(void) { ret_code_t err; sensor_ctrl_t * ctrl; ctrl = sensor_handle_get_control(SENSOR_1); if (ctrl->enable) { err = sample_one_sensor(SENSOR_1); APP_ERROR_CHECK(err); } ctrl = sensor_handle_get_control(SENSOR_2); if (ctrl->enable) { err = sample_one_sensor(SENSOR_2); APP_ERROR_CHECK(err); } ctrl = sensor_handle_get_control(SENSOR_3); if (ctrl->enable) { err = sample_one_sensor(SENSOR_3); APP_ERROR_CHECK(err); } #if (SENSOR_CNT >= 4) ctrl = sensor_handle_get_control(SENSOR_4); if (ctrl->enable) { err = sensor_handle_add_single_value(SENSOR_4, 0); APP_ERROR_CHECK(err); } #endif return err; }
[ "static", "ret_code_t", "sample_all_sensors", "(", "void", ")", "{", "ret_code_t", "err", ";", "sensor_ctrl_t", "*", "ctrl", ";", "ctrl", "=", "sensor_handle_get_control", "(", "SENSOR_1", ")", ";", "if", "(", "ctrl", "->", "enable", ")", "{", "err", "=", "sample_one_sensor", "(", "SENSOR_1", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "}", "ctrl", "=", "sensor_handle_get_control", "(", "SENSOR_2", ")", ";", "if", "(", "ctrl", "->", "enable", ")", "{", "err", "=", "sample_one_sensor", "(", "SENSOR_2", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "}", "ctrl", "=", "sensor_handle_get_control", "(", "SENSOR_3", ")", ";", "if", "(", "ctrl", "->", "enable", ")", "{", "err", "=", "sample_one_sensor", "(", "SENSOR_3", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "}", "#if", "(", "SENSOR_CNT", ">=", "4", ")", "\n", "ctrl", "=", "sensor_handle_get_control", "(", "SENSOR_4", ")", ";", "if", "(", "ctrl", "->", "enable", ")", "{", "err", "=", "sensor_handle_add_single_value", "(", "SENSOR_4", ",", "0", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "}", "#endif", "return", "err", ";", "}" ]
@brief Sample the ADC channels for all sensors @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Sample", "the", "ADC", "channels", "for", "all", "sensors", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
[ "//err = sensor_handle_add_single_value(SENSOR_1, 0);", "// err = sensor_handle_add_single_value(SENSOR_2, mock_adc++);", "// err = sensor_handle_add_single_value(SENSOR_3, 0);", "// err = sensor_handle_add_single_value(SENSOR_4, 0);" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
saadc_timer_init
ret_code_t
static ret_code_t saadc_timer_init(void) { ret_code_t err_code; nrfx_timer_config_t timer_conf = NRFX_TIMER_DEFAULT_CONFIG; timer_conf.bit_width = NRF_TIMER_BIT_WIDTH_32; err_code = nrfx_timer_init( &saadc_timer_instance, &timer_conf, saadc_timer_handler); APP_ERROR_CHECK(err_code); uint32_t time_ticks = nrfx_timer_ms_to_ticks(&saadc_timer_instance, INITIAL_SAMPLE_RATE_MS); nrfx_timer_extended_compare(&saadc_timer_instance, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrfx_timer_enable(&saadc_timer_instance); }
/** * @brief Initialize the timer for the periodic ADC sampling * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Initialize the timer for the periodic ADC sampling @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Initialize", "the", "timer", "for", "the", "periodic", "ADC", "sampling", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
static ret_code_t saadc_timer_init(void) { ret_code_t err_code; nrfx_timer_config_t timer_conf = NRFX_TIMER_DEFAULT_CONFIG; timer_conf.bit_width = NRF_TIMER_BIT_WIDTH_32; err_code = nrfx_timer_init( &saadc_timer_instance, &timer_conf, saadc_timer_handler); APP_ERROR_CHECK(err_code); uint32_t time_ticks = nrfx_timer_ms_to_ticks(&saadc_timer_instance, INITIAL_SAMPLE_RATE_MS); nrfx_timer_extended_compare(&saadc_timer_instance, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrfx_timer_enable(&saadc_timer_instance); }
[ "static", "ret_code_t", "saadc_timer_init", "(", "void", ")", "{", "ret_code_t", "err_code", ";", "nrfx_timer_config_t", "timer_conf", "=", "NRFX_TIMER_DEFAULT_CONFIG", ";", "timer_conf", ".", "bit_width", "=", "NRF_TIMER_BIT_WIDTH_32", ";", "err_code", "=", "nrfx_timer_init", "(", "&", "saadc_timer_instance", ",", "&", "timer_conf", ",", "saadc_timer_handler", ")", ";", "APP_ERROR_CHECK", "(", "err_code", ")", ";", "uint32_t", "time_ticks", "=", "nrfx_timer_ms_to_ticks", "(", "&", "saadc_timer_instance", ",", "INITIAL_SAMPLE_RATE_MS", ")", ";", "nrfx_timer_extended_compare", "(", "&", "saadc_timer_instance", ",", "NRF_TIMER_CC_CHANNEL0", ",", "time_ticks", ",", "NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK", ",", "true", ")", ";", "nrfx_timer_enable", "(", "&", "saadc_timer_instance", ")", ";", "}" ]
@brief Initialize the timer for the periodic ADC sampling @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Initialize", "the", "timer", "for", "the", "periodic", "ADC", "sampling", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
update_saadc_timer
ret_code_t
static ret_code_t update_saadc_timer(sensor_t sensor) { ret_code_t err; nrfx_timer_uninit(&saadc_timer_instance); nrfx_timer_config_t timer_conf = NRFX_TIMER_DEFAULT_CONFIG; timer_conf.bit_width = NRF_TIMER_BIT_WIDTH_32; err = nrfx_timer_init( &saadc_timer_instance, &timer_conf, saadc_timer_handler); APP_ERROR_CHECK(err); sensor_ctrl_t * ctrl = sensor_handle_get_control(sensor); uint32_t time_ticks = nrfx_timer_ms_to_ticks(&saadc_timer_instance, ctrl->sample_period_ms); nrfx_timer_extended_compare(&saadc_timer_instance, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrfx_timer_enable(&saadc_timer_instance); return NRF_SUCCESS; }
/** * @brief Update the time for the ADC sampling, especially the frequency * * @param[in] sensor Selected sensor * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Update the time for the ADC sampling, especially the frequency @param[in] sensor Selected sensor @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Update", "the", "time", "for", "the", "ADC", "sampling", "especially", "the", "frequency", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
static ret_code_t update_saadc_timer(sensor_t sensor) { ret_code_t err; nrfx_timer_uninit(&saadc_timer_instance); nrfx_timer_config_t timer_conf = NRFX_TIMER_DEFAULT_CONFIG; timer_conf.bit_width = NRF_TIMER_BIT_WIDTH_32; err = nrfx_timer_init( &saadc_timer_instance, &timer_conf, saadc_timer_handler); APP_ERROR_CHECK(err); sensor_ctrl_t * ctrl = sensor_handle_get_control(sensor); uint32_t time_ticks = nrfx_timer_ms_to_ticks(&saadc_timer_instance, ctrl->sample_period_ms); nrfx_timer_extended_compare(&saadc_timer_instance, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrfx_timer_enable(&saadc_timer_instance); return NRF_SUCCESS; }
[ "static", "ret_code_t", "update_saadc_timer", "(", "sensor_t", "sensor", ")", "{", "ret_code_t", "err", ";", "nrfx_timer_uninit", "(", "&", "saadc_timer_instance", ")", ";", "nrfx_timer_config_t", "timer_conf", "=", "NRFX_TIMER_DEFAULT_CONFIG", ";", "timer_conf", ".", "bit_width", "=", "NRF_TIMER_BIT_WIDTH_32", ";", "err", "=", "nrfx_timer_init", "(", "&", "saadc_timer_instance", ",", "&", "timer_conf", ",", "saadc_timer_handler", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "sensor_ctrl_t", "*", "ctrl", "=", "sensor_handle_get_control", "(", "sensor", ")", ";", "uint32_t", "time_ticks", "=", "nrfx_timer_ms_to_ticks", "(", "&", "saadc_timer_instance", ",", "ctrl", "->", "sample_period_ms", ")", ";", "nrfx_timer_extended_compare", "(", "&", "saadc_timer_instance", ",", "NRF_TIMER_CC_CHANNEL0", ",", "time_ticks", ",", "NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK", ",", "true", ")", ";", "nrfx_timer_enable", "(", "&", "saadc_timer_instance", ")", ";", "return", "NRF_SUCCESS", ";", "}" ]
@brief Update the time for the ADC sampling, especially the frequency @param[in] sensor Selected sensor
[ "@brief", "Update", "the", "time", "for", "the", "ADC", "sampling", "especially", "the", "frequency", "@param", "[", "in", "]", "sensor", "Selected", "sensor" ]
[]
[ { "param": "sensor", "type": "sensor_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
random_vector_generate
uint8_t
static uint8_t random_vector_generate(uint8_t * p_buff, uint8_t size) { uint32_t err_code; uint8_t available; nrf_drv_rng_bytes_available(&available); uint8_t length = MIN(size, available); err_code = nrf_drv_rng_rand(p_buff, length); APP_ERROR_CHECK(err_code); return length; }
/** * @brief Generate a vector/array of random number * * @param[in] p_buff Pointer to a buffer where random number will be copied * @param[in] size Amount of random number to be generated * * @retval Amount of random numbers that have been generated */
@brief Generate a vector/array of random number @param[in] p_buff Pointer to a buffer where random number will be copied @param[in] size Amount of random number to be generated @retval Amount of random numbers that have been generated
[ "@brief", "Generate", "a", "vector", "/", "array", "of", "random", "number", "@param", "[", "in", "]", "p_buff", "Pointer", "to", "a", "buffer", "where", "random", "number", "will", "be", "copied", "@param", "[", "in", "]", "size", "Amount", "of", "random", "number", "to", "be", "generated", "@retval", "Amount", "of", "random", "numbers", "that", "have", "been", "generated" ]
static uint8_t random_vector_generate(uint8_t * p_buff, uint8_t size) { uint32_t err_code; uint8_t available; nrf_drv_rng_bytes_available(&available); uint8_t length = MIN(size, available); err_code = nrf_drv_rng_rand(p_buff, length); APP_ERROR_CHECK(err_code); return length; }
[ "static", "uint8_t", "random_vector_generate", "(", "uint8_t", "*", "p_buff", ",", "uint8_t", "size", ")", "{", "uint32_t", "err_code", ";", "uint8_t", "available", ";", "nrf_drv_rng_bytes_available", "(", "&", "available", ")", ";", "uint8_t", "length", "=", "MIN", "(", "size", ",", "available", ")", ";", "err_code", "=", "nrf_drv_rng_rand", "(", "p_buff", ",", "length", ")", ";", "APP_ERROR_CHECK", "(", "err_code", ")", ";", "return", "length", ";", "}" ]
@brief Generate a vector/array of random number @param[in] p_buff Pointer to a buffer where random number will be copied @param[in] size Amount of random number to be generated
[ "@brief", "Generate", "a", "vector", "/", "array", "of", "random", "number", "@param", "[", "in", "]", "p_buff", "Pointer", "to", "a", "buffer", "where", "random", "number", "will", "be", "copied", "@param", "[", "in", "]", "size", "Amount", "of", "random", "number", "to", "be", "generated" ]
[]
[ { "param": "p_buff", "type": "uint8_t" }, { "param": "size", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "p_buff", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
random_vector_generate_init
void
static void random_vector_generate_init(void) { uint32_t err_code; err_code = nrf_drv_rng_init(NULL); APP_ERROR_CHECK(err_code); }
/** * @brief initialize the random number module */
@brief initialize the random number module
[ "@brief", "initialize", "the", "random", "number", "module" ]
static void random_vector_generate_init(void) { uint32_t err_code; err_code = nrf_drv_rng_init(NULL); APP_ERROR_CHECK(err_code); }
[ "static", "void", "random_vector_generate_init", "(", "void", ")", "{", "uint32_t", "err_code", ";", "err_code", "=", "nrf_drv_rng_init", "(", "NULL", ")", ";", "APP_ERROR_CHECK", "(", "err_code", ")", ";", "}" ]
@brief initialize the random number module
[ "@brief", "initialize", "the", "random", "number", "module" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
mock_sensor_values
void
static void mock_sensor_values(sensors_t * sensors) { uint8_t randoms[SENSORS_COUNT]; random_vector_generate(randoms, SENSORS_COUNT); for (int i = 0; i < SENSORS_COUNT; i++) sensors->values[i] = randoms[i]; }
/** * @brief generate random values for each sensors * * @param[in] sensors Array of sensors */
@brief generate random values for each sensors @param[in] sensors Array of sensors
[ "@brief", "generate", "random", "values", "for", "each", "sensors", "@param", "[", "in", "]", "sensors", "Array", "of", "sensors" ]
static void mock_sensor_values(sensors_t * sensors) { uint8_t randoms[SENSORS_COUNT]; random_vector_generate(randoms, SENSORS_COUNT); for (int i = 0; i < SENSORS_COUNT; i++) sensors->values[i] = randoms[i]; }
[ "static", "void", "mock_sensor_values", "(", "sensors_t", "*", "sensors", ")", "{", "uint8_t", "randoms", "[", "SENSORS_COUNT", "]", ";", "random_vector_generate", "(", "randoms", ",", "SENSORS_COUNT", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "SENSORS_COUNT", ";", "i", "++", ")", "sensors", "->", "values", "[", "i", "]", "=", "randoms", "[", "i", "]", ";", "}" ]
@brief generate random values for each sensors @param[in] sensors Array of sensors
[ "@brief", "generate", "random", "values", "for", "each", "sensors", "@param", "[", "in", "]", "sensors", "Array", "of", "sensors" ]
[]
[ { "param": "sensors", "type": "sensors_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensors", "type": "sensors_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
sensor_sampling_init
ret_code_t
ret_code_t sensor_sampling_init(void) { #if (MOCK_ADC) random_vector_generate_init(); #else mock_adc = 0; sensor_handles_init(); // init_sensor_buffer(); saadc_init(); saadc_timer_init(); #endif return NRF_SUCCESS; }
/** * @brief Initialize the sensor sampling module: ADC, timer, sensor handles * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Initialize the sensor sampling module: ADC, timer, sensor handles @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Initialize", "the", "sensor", "sampling", "module", ":", "ADC", "timer", "sensor", "handles", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
ret_code_t sensor_sampling_init(void) { #if (MOCK_ADC) random_vector_generate_init(); #else mock_adc = 0; sensor_handles_init(); saadc_init(); saadc_timer_init(); #endif return NRF_SUCCESS; }
[ "ret_code_t", "sensor_sampling_init", "(", "void", ")", "{", "#if", "(", "MOCK_ADC", ")", "\n", "random_vector_generate_init", "(", ")", ";", "#else", "mock_adc", "=", "0", ";", "sensor_handles_init", "(", ")", ";", "saadc_init", "(", ")", ";", "saadc_timer_init", "(", ")", ";", "#endif", "return", "NRF_SUCCESS", ";", "}" ]
@brief Initialize the sensor sampling module: ADC, timer, sensor handles @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Initialize", "the", "sensor", "sampling", "module", ":", "ADC", "timer", "sensor", "handles", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
[ "// init_sensor_buffer();" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ded75d3a130c738477dfa5cb456e3083429d3e24
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_sampling.c
[ "MIT" ]
C
sensor_sampling_update_sensor_control
ret_code_t
ret_code_t sensor_sampling_update_sensor_control( sensor_t sensor, sensor_ctrl_t * new_sensor_ctrl) { ret_code_t err; if (!is_sensor_ctrl_valid(new_sensor_ctrl)) { return NRF_ERROR_INVALID_DATA; } sensor_hardware_t * hardware = sensor_handle_get_hardware(sensor); err = nrfx_saadc_channel_uninit(hardware->adc_chanel); APP_ERROR_CHECK(err); err = sensor_handle_set_control(sensor, new_sensor_ctrl); APP_ERROR_CHECK(err); err = saadc_config_channel(sensor); APP_ERROR_CHECK(err); err = update_saadc_timer(sensor); APP_ERROR_CHECK(err); return NRF_SUCCESS; }
/** * @brief update the ADC configuration/control for particuliar sensor * * @param[in] sensor Selected sensor * @param[in] ctrl Pointer to a sensor control handle with new values * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief update the ADC configuration/control for particuliar sensor @param[in] sensor Selected sensor @param[in] ctrl Pointer to a sensor control handle with new values @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "update", "the", "ADC", "configuration", "/", "control", "for", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "in", "]", "ctrl", "Pointer", "to", "a", "sensor", "control", "handle", "with", "new", "values", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
ret_code_t sensor_sampling_update_sensor_control( sensor_t sensor, sensor_ctrl_t * new_sensor_ctrl) { ret_code_t err; if (!is_sensor_ctrl_valid(new_sensor_ctrl)) { return NRF_ERROR_INVALID_DATA; } sensor_hardware_t * hardware = sensor_handle_get_hardware(sensor); err = nrfx_saadc_channel_uninit(hardware->adc_chanel); APP_ERROR_CHECK(err); err = sensor_handle_set_control(sensor, new_sensor_ctrl); APP_ERROR_CHECK(err); err = saadc_config_channel(sensor); APP_ERROR_CHECK(err); err = update_saadc_timer(sensor); APP_ERROR_CHECK(err); return NRF_SUCCESS; }
[ "ret_code_t", "sensor_sampling_update_sensor_control", "(", "sensor_t", "sensor", ",", "sensor_ctrl_t", "*", "new_sensor_ctrl", ")", "{", "ret_code_t", "err", ";", "if", "(", "!", "is_sensor_ctrl_valid", "(", "new_sensor_ctrl", ")", ")", "{", "return", "NRF_ERROR_INVALID_DATA", ";", "}", "sensor_hardware_t", "*", "hardware", "=", "sensor_handle_get_hardware", "(", "sensor", ")", ";", "err", "=", "nrfx_saadc_channel_uninit", "(", "hardware", "->", "adc_chanel", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "err", "=", "sensor_handle_set_control", "(", "sensor", ",", "new_sensor_ctrl", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "err", "=", "saadc_config_channel", "(", "sensor", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "err", "=", "update_saadc_timer", "(", "sensor", ")", ";", "APP_ERROR_CHECK", "(", "err", ")", ";", "return", "NRF_SUCCESS", ";", "}" ]
@brief update the ADC configuration/control for particuliar sensor @param[in] sensor Selected sensor @param[in] ctrl Pointer to a sensor control handle with new values
[ "@brief", "update", "the", "ADC", "configuration", "/", "control", "for", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "in", "]", "ctrl", "Pointer", "to", "a", "sensor", "control", "handle", "with", "new", "values" ]
[]
[ { "param": "sensor", "type": "sensor_t" }, { "param": "new_sensor_ctrl", "type": "sensor_ctrl_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "new_sensor_ctrl", "type": "sensor_ctrl_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_get
sensor_handle_t
static sensor_handle_t * sensor_handle_get(sensor_t sensor) { switch (sensor) { case (SENSOR_1): return &s_h_1; case (SENSOR_2): return &s_h_2; case (SENSOR_3): return &s_h_3; #if (SENSOR_CNT >= 4) case (SENSOR_4): return &s_h_4; #endif } }
/** * @brief Get the handle for a particuliar sensr * * @param[in] sensor Selected sensor * * @retval Pointer to a sensor handle */
@brief Get the handle for a particuliar sensr @param[in] sensor Selected sensor @retval Pointer to a sensor handle
[ "@brief", "Get", "the", "handle", "for", "a", "particuliar", "sensr", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@retval", "Pointer", "to", "a", "sensor", "handle" ]
static sensor_handle_t * sensor_handle_get(sensor_t sensor) { switch (sensor) { case (SENSOR_1): return &s_h_1; case (SENSOR_2): return &s_h_2; case (SENSOR_3): return &s_h_3; #if (SENSOR_CNT >= 4) case (SENSOR_4): return &s_h_4; #endif } }
[ "static", "sensor_handle_t", "*", "sensor_handle_get", "(", "sensor_t", "sensor", ")", "{", "switch", "(", "sensor", ")", "{", "case", "(", "SENSOR_1", ")", ":", "return", "&", "s_h_1", ";", "case", "(", "SENSOR_2", ")", ":", "return", "&", "s_h_2", ";", "case", "(", "SENSOR_3", ")", ":", "return", "&", "s_h_3", ";", "#if", "(", "SENSOR_CNT", ">=", "4", ")", "\n", "case", "(", "SENSOR_4", ")", ":", "return", "&", "s_h_4", ";", "#endif", "}", "}" ]
@brief Get the handle for a particuliar sensr @param[in] sensor Selected sensor
[ "@brief", "Get", "the", "handle", "for", "a", "particuliar", "sensr", "@param", "[", "in", "]", "sensor", "Selected", "sensor" ]
[]
[ { "param": "sensor", "type": "sensor_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handles_init
void
void sensor_handles_init(void) { s_h_1.buffer = &s_1_data; nrf_ringbuf_init(s_h_1.buffer); s_h_2.buffer = &s_2_data; nrf_ringbuf_init(s_h_2.buffer); s_h_3.buffer = &s_3_data; nrf_ringbuf_init(s_h_3.buffer); #if (SENSOR_CNT >= 4) s_h_4.buffer = &s_4_data; nrf_ringbuf_init(s_h_4.buffer); #endif sensor_ctrl_t * ctrl; for (sensor_t s_i = SENSOR_FIRST; s_i <= SENSOR_LAST; s_i++) { ctrl = sensor_handle_get_control(s_i); //ctrl->gain = SAADC_CH_CONFIG_GAIN_Gain1_6; ctrl->gain = SAADC_CH_CONFIG_GAIN_Gain1_6; ctrl->enable = true; ctrl->sample_period_ms = 100; // ms } s_h_1.hardware.pwr_pin = SENSOR_1_PWR_PIN; s_h_1.hardware.adc_pin = SENSOR_1_ADC_PIN; s_h_1.hardware.adc_chanel = SENSOR_1_ADC_CHANNEL; s_h_1.hardware.analog_input = SENSOR_1_ANALOG_INPUT; s_h_2.hardware.pwr_pin = SENSOR_2_PWR_PIN; s_h_2.hardware.adc_pin = SENSOR_2_ADC_PIN; s_h_2.hardware.adc_chanel = SENSOR_2_ADC_CHANNEL; s_h_2.hardware.analog_input = SENSOR_2_ANALOG_INPUT; s_h_3.hardware.pwr_pin = SENSOR_3_PWR_PIN; s_h_3.hardware.adc_pin = SENSOR_3_ADC_PIN; s_h_3.hardware.adc_chanel = SENSOR_3_ADC_CHANNEL; s_h_3.hardware.analog_input = SENSOR_3_ANALOG_INPUT; #if (SENSOR_CNT >= 4) s_h_4.hardware.pwr_pin = SENSOR_4_PWR_PIN; s_h_4.hardware.adc_pin = SENSOR_4_ADC_PIN; s_h_4.hardware.adc_chanel = SENSOR_4_ADC_CHANNEL; s_h_4.hardware.analog_input = SENSOR_4_ANALOG_INPUT; #endif }
/** * @brief Link all the sensor handle to there control and buffer * initialise the buffer and add the hardware config for each sensor */
@brief Link all the sensor handle to there control and buffer initialise the buffer and add the hardware config for each sensor
[ "@brief", "Link", "all", "the", "sensor", "handle", "to", "there", "control", "and", "buffer", "initialise", "the", "buffer", "and", "add", "the", "hardware", "config", "for", "each", "sensor" ]
void sensor_handles_init(void) { s_h_1.buffer = &s_1_data; nrf_ringbuf_init(s_h_1.buffer); s_h_2.buffer = &s_2_data; nrf_ringbuf_init(s_h_2.buffer); s_h_3.buffer = &s_3_data; nrf_ringbuf_init(s_h_3.buffer); #if (SENSOR_CNT >= 4) s_h_4.buffer = &s_4_data; nrf_ringbuf_init(s_h_4.buffer); #endif sensor_ctrl_t * ctrl; for (sensor_t s_i = SENSOR_FIRST; s_i <= SENSOR_LAST; s_i++) { ctrl = sensor_handle_get_control(s_i); ctrl->gain = SAADC_CH_CONFIG_GAIN_Gain1_6; ctrl->enable = true; ctrl->sample_period_ms = 100; } s_h_1.hardware.pwr_pin = SENSOR_1_PWR_PIN; s_h_1.hardware.adc_pin = SENSOR_1_ADC_PIN; s_h_1.hardware.adc_chanel = SENSOR_1_ADC_CHANNEL; s_h_1.hardware.analog_input = SENSOR_1_ANALOG_INPUT; s_h_2.hardware.pwr_pin = SENSOR_2_PWR_PIN; s_h_2.hardware.adc_pin = SENSOR_2_ADC_PIN; s_h_2.hardware.adc_chanel = SENSOR_2_ADC_CHANNEL; s_h_2.hardware.analog_input = SENSOR_2_ANALOG_INPUT; s_h_3.hardware.pwr_pin = SENSOR_3_PWR_PIN; s_h_3.hardware.adc_pin = SENSOR_3_ADC_PIN; s_h_3.hardware.adc_chanel = SENSOR_3_ADC_CHANNEL; s_h_3.hardware.analog_input = SENSOR_3_ANALOG_INPUT; #if (SENSOR_CNT >= 4) s_h_4.hardware.pwr_pin = SENSOR_4_PWR_PIN; s_h_4.hardware.adc_pin = SENSOR_4_ADC_PIN; s_h_4.hardware.adc_chanel = SENSOR_4_ADC_CHANNEL; s_h_4.hardware.analog_input = SENSOR_4_ANALOG_INPUT; #endif }
[ "void", "sensor_handles_init", "(", "void", ")", "{", "s_h_1", ".", "buffer", "=", "&", "s_1_data", ";", "nrf_ringbuf_init", "(", "s_h_1", ".", "buffer", ")", ";", "s_h_2", ".", "buffer", "=", "&", "s_2_data", ";", "nrf_ringbuf_init", "(", "s_h_2", ".", "buffer", ")", ";", "s_h_3", ".", "buffer", "=", "&", "s_3_data", ";", "nrf_ringbuf_init", "(", "s_h_3", ".", "buffer", ")", ";", "#if", "(", "SENSOR_CNT", ">=", "4", ")", "\n", "s_h_4", ".", "buffer", "=", "&", "s_4_data", ";", "nrf_ringbuf_init", "(", "s_h_4", ".", "buffer", ")", ";", "#endif", "sensor_ctrl_t", "*", "ctrl", ";", "for", "(", "sensor_t", "s_i", "=", "SENSOR_FIRST", ";", "s_i", "<=", "SENSOR_LAST", ";", "s_i", "++", ")", "{", "ctrl", "=", "sensor_handle_get_control", "(", "s_i", ")", ";", "ctrl", "->", "gain", "=", "SAADC_CH_CONFIG_GAIN_Gain1_6", ";", "ctrl", "->", "enable", "=", "true", ";", "ctrl", "->", "sample_period_ms", "=", "100", ";", "}", "s_h_1", ".", "hardware", ".", "pwr_pin", "=", "SENSOR_1_PWR_PIN", ";", "s_h_1", ".", "hardware", ".", "adc_pin", "=", "SENSOR_1_ADC_PIN", ";", "s_h_1", ".", "hardware", ".", "adc_chanel", "=", "SENSOR_1_ADC_CHANNEL", ";", "s_h_1", ".", "hardware", ".", "analog_input", "=", "SENSOR_1_ANALOG_INPUT", ";", "s_h_2", ".", "hardware", ".", "pwr_pin", "=", "SENSOR_2_PWR_PIN", ";", "s_h_2", ".", "hardware", ".", "adc_pin", "=", "SENSOR_2_ADC_PIN", ";", "s_h_2", ".", "hardware", ".", "adc_chanel", "=", "SENSOR_2_ADC_CHANNEL", ";", "s_h_2", ".", "hardware", ".", "analog_input", "=", "SENSOR_2_ANALOG_INPUT", ";", "s_h_3", ".", "hardware", ".", "pwr_pin", "=", "SENSOR_3_PWR_PIN", ";", "s_h_3", ".", "hardware", ".", "adc_pin", "=", "SENSOR_3_ADC_PIN", ";", "s_h_3", ".", "hardware", ".", "adc_chanel", "=", "SENSOR_3_ADC_CHANNEL", ";", "s_h_3", ".", "hardware", ".", "analog_input", "=", "SENSOR_3_ANALOG_INPUT", ";", "#if", "(", "SENSOR_CNT", ">=", "4", ")", "\n", "s_h_4", ".", "hardware", ".", "pwr_pin", "=", "SENSOR_4_PWR_PIN", ";", "s_h_4", ".", "hardware", ".", "adc_pin", "=", "SENSOR_4_ADC_PIN", ";", "s_h_4", ".", "hardware", ".", "adc_chanel", "=", "SENSOR_4_ADC_CHANNEL", ";", "s_h_4", ".", "hardware", ".", "analog_input", "=", "SENSOR_4_ANALOG_INPUT", ";", "#endif", "}" ]
@brief Link all the sensor handle to there control and buffer initialise the buffer and add the hardware config for each sensor
[ "@brief", "Link", "all", "the", "sensor", "handle", "to", "there", "control", "and", "buffer", "initialise", "the", "buffer", "and", "add", "the", "hardware", "config", "for", "each", "sensor" ]
[ "//ctrl->gain = SAADC_CH_CONFIG_GAIN_Gain1_6;", "// ms" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_get_hardware
sensor_hardware_t
sensor_hardware_t * sensor_handle_get_hardware(sensor_t sensor) { sensor_handle_t * s_h = sensor_handle_get(sensor); return &s_h->hardware; }
/** * @brief Get the hardware handle for a particuliar sensor * * @param[in] sensor Selected sensor * * @retval Pointer to the hardware handle for the selected sensor */
@brief Get the hardware handle for a particuliar sensor @param[in] sensor Selected sensor @retval Pointer to the hardware handle for the selected sensor
[ "@brief", "Get", "the", "hardware", "handle", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@retval", "Pointer", "to", "the", "hardware", "handle", "for", "the", "selected", "sensor" ]
sensor_hardware_t * sensor_handle_get_hardware(sensor_t sensor) { sensor_handle_t * s_h = sensor_handle_get(sensor); return &s_h->hardware; }
[ "sensor_hardware_t", "*", "sensor_handle_get_hardware", "(", "sensor_t", "sensor", ")", "{", "sensor_handle_t", "*", "s_h", "=", "sensor_handle_get", "(", "sensor", ")", ";", "return", "&", "s_h", "->", "hardware", ";", "}" ]
@brief Get the hardware handle for a particuliar sensor @param[in] sensor Selected sensor
[ "@brief", "Get", "the", "hardware", "handle", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor" ]
[]
[ { "param": "sensor", "type": "sensor_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_get_control
sensor_ctrl_t
sensor_ctrl_t * sensor_handle_get_control(sensor_t sensor) { sensor_handle_t * s_h = sensor_handle_get(sensor); return &s_h->control; }
/** * @brief Get the control handle for a particuliar sensor * * @param[in] sensor Selected sensor * * @retval Pointer to the control handle for the selected sensor */
@brief Get the control handle for a particuliar sensor @param[in] sensor Selected sensor @retval Pointer to the control handle for the selected sensor
[ "@brief", "Get", "the", "control", "handle", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@retval", "Pointer", "to", "the", "control", "handle", "for", "the", "selected", "sensor" ]
sensor_ctrl_t * sensor_handle_get_control(sensor_t sensor) { sensor_handle_t * s_h = sensor_handle_get(sensor); return &s_h->control; }
[ "sensor_ctrl_t", "*", "sensor_handle_get_control", "(", "sensor_t", "sensor", ")", "{", "sensor_handle_t", "*", "s_h", "=", "sensor_handle_get", "(", "sensor", ")", ";", "return", "&", "s_h", "->", "control", ";", "}" ]
@brief Get the control handle for a particuliar sensor @param[in] sensor Selected sensor
[ "@brief", "Get", "the", "control", "handle", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor" ]
[]
[ { "param": "sensor", "type": "sensor_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_set_control
ret_code_t
ret_code_t sensor_handle_set_control( sensor_t sensor, sensor_ctrl_t * sensor_ctrl) { if (!is_sensor_ctrl_valid(sensor_ctrl)) { return NRF_ERROR_INVALID_DATA; } sensor_ctrl_t * sensor_ctrl_dest = sensor_handle_get_control(sensor); memcpy(sensor_ctrl_dest, sensor_ctrl, sizeof(sensor_ctrl_t)); return NRF_SUCCESS; }
/** * @brief Set the control handle for a particuliar sensor * * @param[in] sensor Selected sensor * @param[in] sensor_ctrl Pointer a new control handle to update the * old one * * @retval Pointer to the control handle for the selected sensor */
@brief Set the control handle for a particuliar sensor @param[in] sensor Selected sensor @param[in] sensor_ctrl Pointer a new control handle to update the old one @retval Pointer to the control handle for the selected sensor
[ "@brief", "Set", "the", "control", "handle", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "in", "]", "sensor_ctrl", "Pointer", "a", "new", "control", "handle", "to", "update", "the", "old", "one", "@retval", "Pointer", "to", "the", "control", "handle", "for", "the", "selected", "sensor" ]
ret_code_t sensor_handle_set_control( sensor_t sensor, sensor_ctrl_t * sensor_ctrl) { if (!is_sensor_ctrl_valid(sensor_ctrl)) { return NRF_ERROR_INVALID_DATA; } sensor_ctrl_t * sensor_ctrl_dest = sensor_handle_get_control(sensor); memcpy(sensor_ctrl_dest, sensor_ctrl, sizeof(sensor_ctrl_t)); return NRF_SUCCESS; }
[ "ret_code_t", "sensor_handle_set_control", "(", "sensor_t", "sensor", ",", "sensor_ctrl_t", "*", "sensor_ctrl", ")", "{", "if", "(", "!", "is_sensor_ctrl_valid", "(", "sensor_ctrl", ")", ")", "{", "return", "NRF_ERROR_INVALID_DATA", ";", "}", "sensor_ctrl_t", "*", "sensor_ctrl_dest", "=", "sensor_handle_get_control", "(", "sensor", ")", ";", "memcpy", "(", "sensor_ctrl_dest", ",", "sensor_ctrl", ",", "sizeof", "(", "sensor_ctrl_t", ")", ")", ";", "return", "NRF_SUCCESS", ";", "}" ]
@brief Set the control handle for a particuliar sensor @param[in] sensor Selected sensor @param[in] sensor_ctrl Pointer a new control handle to update the old one
[ "@brief", "Set", "the", "control", "handle", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "in", "]", "sensor_ctrl", "Pointer", "a", "new", "control", "handle", "to", "update", "the", "old", "one" ]
[]
[ { "param": "sensor", "type": "sensor_t" }, { "param": "sensor_ctrl", "type": "sensor_ctrl_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sensor_ctrl", "type": "sensor_ctrl_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_available_data
int
int sensor_handle_available_data(sensor_t sensor) { const nrf_ringbuf_t * buf = get_sensor_buffer(sensor); return sensor_handle_available_data_buf(buf) / sizeof(sensor_val_t); }
/** * @brief Check how many bytes a ring buffer has available for a particuliar * sensor * * @param[in] sensor Selected sensor * * @retval The amount of available bytes of data */
@brief Check how many bytes a ring buffer has available for a particuliar sensor @param[in] sensor Selected sensor @retval The amount of available bytes of data
[ "@brief", "Check", "how", "many", "bytes", "a", "ring", "buffer", "has", "available", "for", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@retval", "The", "amount", "of", "available", "bytes", "of", "data" ]
int sensor_handle_available_data(sensor_t sensor) { const nrf_ringbuf_t * buf = get_sensor_buffer(sensor); return sensor_handle_available_data_buf(buf) / sizeof(sensor_val_t); }
[ "int", "sensor_handle_available_data", "(", "sensor_t", "sensor", ")", "{", "const", "nrf_ringbuf_t", "*", "buf", "=", "get_sensor_buffer", "(", "sensor", ")", ";", "return", "sensor_handle_available_data_buf", "(", "buf", ")", "/", "sizeof", "(", "sensor_val_t", ")", ";", "}" ]
@brief Check how many bytes a ring buffer has available for a particuliar sensor
[ "@brief", "Check", "how", "many", "bytes", "a", "ring", "buffer", "has", "available", "for", "a", "particuliar", "sensor" ]
[]
[ { "param": "sensor", "type": "sensor_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_add_single_value
ret_code_t
ret_code_t sensor_handle_add_single_value(sensor_t sensor, sensor_val_t val) { ret_code_t err; const nrf_ringbuf_t * buf = get_sensor_buffer(sensor); size_t len = sizeof(sensor_val_t); uint8_t * data_p; uint8_t ** data_pp = &data_p; // Allocate (check) space for data err = nrf_ringbuf_alloc(buf, data_pp, &len, false); if (err) return err; // if the buffer is full, we free place and retry if (len != sizeof(sensor_val_t)) { sensor_val_t dummy = 0; err = sensor_handle_get_values(sensor, &dummy, 1); if (err) return err; len = sizeof(sensor_val_t); err = nrf_ringbuf_alloc(buf, data_pp, &len, false); if (err) return err; if (len != sizeof(sensor_val_t)) return NRF_ERROR_DATA_SIZE; } // Commit (put) the data in the buffer (after allocating it) err = nrf_ringbuf_cpy_put(buf, (uint8_t *)&val, &len); if (err != NRF_SUCCESS || len != sizeof(sensor_val_t)) { return NRF_ERROR_DATA_SIZE; } return NRF_SUCCESS; }
/** * @brief Add a value for a sensor into its ring buffer * * @param[in] sensor Selected sensor * @param[in] val sensor ADC value * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Add a value for a sensor into its ring buffer @param[in] sensor Selected sensor @param[in] val sensor ADC value @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Add", "a", "value", "for", "a", "sensor", "into", "its", "ring", "buffer", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "in", "]", "val", "sensor", "ADC", "value", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
ret_code_t sensor_handle_add_single_value(sensor_t sensor, sensor_val_t val) { ret_code_t err; const nrf_ringbuf_t * buf = get_sensor_buffer(sensor); size_t len = sizeof(sensor_val_t); uint8_t * data_p; uint8_t ** data_pp = &data_p; err = nrf_ringbuf_alloc(buf, data_pp, &len, false); if (err) return err; if (len != sizeof(sensor_val_t)) { sensor_val_t dummy = 0; err = sensor_handle_get_values(sensor, &dummy, 1); if (err) return err; len = sizeof(sensor_val_t); err = nrf_ringbuf_alloc(buf, data_pp, &len, false); if (err) return err; if (len != sizeof(sensor_val_t)) return NRF_ERROR_DATA_SIZE; } err = nrf_ringbuf_cpy_put(buf, (uint8_t *)&val, &len); if (err != NRF_SUCCESS || len != sizeof(sensor_val_t)) { return NRF_ERROR_DATA_SIZE; } return NRF_SUCCESS; }
[ "ret_code_t", "sensor_handle_add_single_value", "(", "sensor_t", "sensor", ",", "sensor_val_t", "val", ")", "{", "ret_code_t", "err", ";", "const", "nrf_ringbuf_t", "*", "buf", "=", "get_sensor_buffer", "(", "sensor", ")", ";", "size_t", "len", "=", "sizeof", "(", "sensor_val_t", ")", ";", "uint8_t", "*", "data_p", ";", "uint8_t", "*", "*", "data_pp", "=", "&", "data_p", ";", "err", "=", "nrf_ringbuf_alloc", "(", "buf", ",", "data_pp", ",", "&", "len", ",", "false", ")", ";", "if", "(", "err", ")", "return", "err", ";", "if", "(", "len", "!=", "sizeof", "(", "sensor_val_t", ")", ")", "{", "sensor_val_t", "dummy", "=", "0", ";", "err", "=", "sensor_handle_get_values", "(", "sensor", ",", "&", "dummy", ",", "1", ")", ";", "if", "(", "err", ")", "return", "err", ";", "len", "=", "sizeof", "(", "sensor_val_t", ")", ";", "err", "=", "nrf_ringbuf_alloc", "(", "buf", ",", "data_pp", ",", "&", "len", ",", "false", ")", ";", "if", "(", "err", ")", "return", "err", ";", "if", "(", "len", "!=", "sizeof", "(", "sensor_val_t", ")", ")", "return", "NRF_ERROR_DATA_SIZE", ";", "}", "err", "=", "nrf_ringbuf_cpy_put", "(", "buf", ",", "(", "uint8_t", "*", ")", "&", "val", ",", "&", "len", ")", ";", "if", "(", "err", "!=", "NRF_SUCCESS", "||", "len", "!=", "sizeof", "(", "sensor_val_t", ")", ")", "{", "return", "NRF_ERROR_DATA_SIZE", ";", "}", "return", "NRF_SUCCESS", ";", "}" ]
@brief Add a value for a sensor into its ring buffer @param[in] sensor Selected sensor @param[in] val sensor ADC value
[ "@brief", "Add", "a", "value", "for", "a", "sensor", "into", "its", "ring", "buffer", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "in", "]", "val", "sensor", "ADC", "value" ]
[ "// Allocate (check) space for data", "// if the buffer is full, we free place and retry", "// Commit (put) the data in the buffer (after allocating it)" ]
[ { "param": "sensor", "type": "sensor_t" }, { "param": "val", "type": "sensor_val_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "val", "type": "sensor_val_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
sensor_handle_get_values
ret_code_t
ret_code_t sensor_handle_get_values( sensor_t sensor, sensor_val_t * vals, uint8_t amount) { ret_code_t err; const nrf_ringbuf_t * buf = get_sensor_buffer(sensor); size_t len = amount * sizeof(sensor_val_t); if (sensor_handle_available_data_buf(buf) < len) { return NRF_ERROR_DATA_SIZE; } err = nrf_ringbuf_cpy_get(buf, (uint8_t *)vals, &len); if (len != amount * sizeof(sensor_val_t)) { return NRF_ERROR_DATA_SIZE; } return err; }
/** * @brief Get [amount] values (if available) from a particuliar sensor * * @param[in] sensor Selected sensor * @param[out] vals Pointer to a sensor value to be copied into * @param[in] amount amount of value to be copied into vals * * @retval NRF_SUCCESS on success, otherwise an error code is returned */
@brief Get [amount] values (if available) from a particuliar sensor @param[in] sensor Selected sensor @param[out] vals Pointer to a sensor value to be copied into @param[in] amount amount of value to be copied into vals @retval NRF_SUCCESS on success, otherwise an error code is returned
[ "@brief", "Get", "[", "amount", "]", "values", "(", "if", "available", ")", "from", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "out", "]", "vals", "Pointer", "to", "a", "sensor", "value", "to", "be", "copied", "into", "@param", "[", "in", "]", "amount", "amount", "of", "value", "to", "be", "copied", "into", "vals", "@retval", "NRF_SUCCESS", "on", "success", "otherwise", "an", "error", "code", "is", "returned" ]
ret_code_t sensor_handle_get_values( sensor_t sensor, sensor_val_t * vals, uint8_t amount) { ret_code_t err; const nrf_ringbuf_t * buf = get_sensor_buffer(sensor); size_t len = amount * sizeof(sensor_val_t); if (sensor_handle_available_data_buf(buf) < len) { return NRF_ERROR_DATA_SIZE; } err = nrf_ringbuf_cpy_get(buf, (uint8_t *)vals, &len); if (len != amount * sizeof(sensor_val_t)) { return NRF_ERROR_DATA_SIZE; } return err; }
[ "ret_code_t", "sensor_handle_get_values", "(", "sensor_t", "sensor", ",", "sensor_val_t", "*", "vals", ",", "uint8_t", "amount", ")", "{", "ret_code_t", "err", ";", "const", "nrf_ringbuf_t", "*", "buf", "=", "get_sensor_buffer", "(", "sensor", ")", ";", "size_t", "len", "=", "amount", "*", "sizeof", "(", "sensor_val_t", ")", ";", "if", "(", "sensor_handle_available_data_buf", "(", "buf", ")", "<", "len", ")", "{", "return", "NRF_ERROR_DATA_SIZE", ";", "}", "err", "=", "nrf_ringbuf_cpy_get", "(", "buf", ",", "(", "uint8_t", "*", ")", "vals", ",", "&", "len", ")", ";", "if", "(", "len", "!=", "amount", "*", "sizeof", "(", "sensor_val_t", ")", ")", "{", "return", "NRF_ERROR_DATA_SIZE", ";", "}", "return", "err", ";", "}" ]
@brief Get [amount] values (if available) from a particuliar sensor @param[in] sensor Selected sensor @param[out] vals Pointer to a sensor value to be copied into @param[in] amount amount of value to be copied into vals
[ "@brief", "Get", "[", "amount", "]", "values", "(", "if", "available", ")", "from", "a", "particuliar", "sensor", "@param", "[", "in", "]", "sensor", "Selected", "sensor", "@param", "[", "out", "]", "vals", "Pointer", "to", "a", "sensor", "value", "to", "be", "copied", "into", "@param", "[", "in", "]", "amount", "amount", "of", "value", "to", "be", "copied", "into", "vals" ]
[]
[ { "param": "sensor", "type": "sensor_t" }, { "param": "vals", "type": "sensor_val_t" }, { "param": "amount", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sensor", "type": "sensor_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "vals", "type": "sensor_val_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "amount", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
60d006d1d077e7673da91c8681a419d2bbc36645
pseudoincorrect/smart_mask
Embedded_system/smart_mask/src/sensors/sensor_handle.c
[ "MIT" ]
C
is_sensor_ctrl_valid
bool
bool is_sensor_ctrl_valid(sensor_ctrl_t * ctrl) { if (ctrl->sample_period_ms < 200 || ctrl->sample_period_ms > 2000) { return false; } if (ctrl->gain < SAADC_CH_CONFIG_GAIN_Gain1_6 || ctrl->gain > SAADC_CH_CONFIG_GAIN_Gain4) { return false; } return true; }
/** * @brief Validate a sensor control handle * * @param[in] ctrl Pointer to a sensor control handle to be validated * * @retval true if valid, false otherwise */
@brief Validate a sensor control handle @param[in] ctrl Pointer to a sensor control handle to be validated @retval true if valid, false otherwise
[ "@brief", "Validate", "a", "sensor", "control", "handle", "@param", "[", "in", "]", "ctrl", "Pointer", "to", "a", "sensor", "control", "handle", "to", "be", "validated", "@retval", "true", "if", "valid", "false", "otherwise" ]
bool is_sensor_ctrl_valid(sensor_ctrl_t * ctrl) { if (ctrl->sample_period_ms < 200 || ctrl->sample_period_ms > 2000) { return false; } if (ctrl->gain < SAADC_CH_CONFIG_GAIN_Gain1_6 || ctrl->gain > SAADC_CH_CONFIG_GAIN_Gain4) { return false; } return true; }
[ "bool", "is_sensor_ctrl_valid", "(", "sensor_ctrl_t", "*", "ctrl", ")", "{", "if", "(", "ctrl", "->", "sample_period_ms", "<", "200", "||", "ctrl", "->", "sample_period_ms", ">", "2000", ")", "{", "return", "false", ";", "}", "if", "(", "ctrl", "->", "gain", "<", "SAADC_CH_CONFIG_GAIN_Gain1_6", "||", "ctrl", "->", "gain", ">", "SAADC_CH_CONFIG_GAIN_Gain4", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
@brief Validate a sensor control handle @param[in] ctrl Pointer to a sensor control handle to be validated
[ "@brief", "Validate", "a", "sensor", "control", "handle", "@param", "[", "in", "]", "ctrl", "Pointer", "to", "a", "sensor", "control", "handle", "to", "be", "validated" ]
[]
[ { "param": "ctrl", "type": "sensor_ctrl_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctrl", "type": "sensor_ctrl_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37fcbe788fb91e5b95c3499c96152cd4212d4a8c
VaporShader/Custom-Compiler
main/phases.c
[ "MIT" ]
C
phaseOneProcess
void
void phaseOneProcess(int argc, char* argv[]) { /*set up the data structs*/ symbol* symbolHead = NULL; dWord* dataHead = NULL; entry* entryList = NULL; psr* parsed = NULL; /*a flag used to block file making*/ boolean status = True; int i, /* index for loops*/ line, /*the number of line */ ic = 0, /*instruction counter*/ dc = 0; /*data counter*/ char *fileName = NULL, /*file name given as a parameter from argv, might be converted if contains the .ps file name at the end*/ *asmFileName = NULL; /*the file name of the asm file, just the fileName but with .as*/ FILE* asmFile = NULL; char buffer[BUFFER_SIZE]; if (argc >= 2) { for (i = 1; i < argc; i++) { /*reset the values after we've delt if the previous file*/ symbolHead = NULL; dataHead = NULL; entryList = NULL; status = True; line = 1, ic = dc = 0; asmFileName = NULL; asmFile = NULL; parsed = NULL; if(stringCmp(".as", argv[i], (int)(strlen(argv[i]) - AS_LEN),(int)(strlen(argv[i])))){ asmFile = fopen(argv[i], "r"); fileName = (char*)malloc((int)(strlen(argv[i]) - AS_LEN + 1)); if (!fileName) return; strncpy(fileName, argv[i], strlen(argv[i]) -AS_LEN); fileName[(int)(strlen(argv[i]) - AS_LEN)] = '\0'; } else { fileName = argv[i]; if (!fileName) return; asmFileName = (char*)malloc(strlen(fileName)); if (!asmFileName) return; strcpy(asmFileName, fileName); strcat(asmFileName, ".as"); asmFile = fopen(asmFileName, "r"); } /*check if the file could be opened*/ if (!asmFile) { printf("#Error: Can not open file!\n"); } /*if the file is openable we check if it's empty or not*/ else if (!checkIfFileEmpty(asmFile)) { /*if the file is not empty get each line and put it to the buffer*/ while (fgets(buffer, BUFFER_SIZE, asmFile)) { /*a valid line should be less than 80 letters*/ if (strlen(buffer) > LINE_LEN) { printf("#Error in file %s at line %d- Invalid line lenght:" " a line should be less than 80 words!\n", argv[i] + firstNameIndex(argv[i]), line); status = False; } else { /*add ' ' just for empty strings*/ strcat(buffer, " "); /*get the processed line into word array*/ parsed = parser(buffer, argv[i], line, True); /*now we send these words to word handlers*/ if (parsed && !phasesHandler(NULL, parsed, &symbolHead, &dataHead, &entryList, argv[i], line, &ic, &dc, True) && status) { status = False; } freePsr(parsed); } line++; } /*if the file was valid we update the symbol table*/ if (status) updateSymbols(&symbolHead, &ic); phaseTwoProcess(asmFile, fileName, &symbolHead, &dataHead, &entryList, status, &ic, &dc); } else { printf("#Error in file %s: file is empty\n", argv[i] + firstNameIndex(argv[i])); fclose(asmFile); } } } else { printf("#Error: no file was given!\n"); return; } }
/* This method handles the first phase of the project INPUT: int argc - th number of files INPUT: char* argv[] - the array of strings that contains the file names OUTPUT: NONE */
This method handles the first phase of the project INPUT: int argc - th number of files INPUT: char* argv[] - the array of strings that contains the file names OUTPUT: NONE
[ "This", "method", "handles", "the", "first", "phase", "of", "the", "project", "INPUT", ":", "int", "argc", "-", "th", "number", "of", "files", "INPUT", ":", "char", "*", "argv", "[]", "-", "the", "array", "of", "strings", "that", "contains", "the", "file", "names", "OUTPUT", ":", "NONE" ]
void phaseOneProcess(int argc, char* argv[]) { symbol* symbolHead = NULL; dWord* dataHead = NULL; entry* entryList = NULL; psr* parsed = NULL; boolean status = True; int i, line, ic = 0, dc = 0; char *fileName = NULL, *asmFileName = NULL; FILE* asmFile = NULL; char buffer[BUFFER_SIZE]; if (argc >= 2) { for (i = 1; i < argc; i++) { symbolHead = NULL; dataHead = NULL; entryList = NULL; status = True; line = 1, ic = dc = 0; asmFileName = NULL; asmFile = NULL; parsed = NULL; if(stringCmp(".as", argv[i], (int)(strlen(argv[i]) - AS_LEN),(int)(strlen(argv[i])))){ asmFile = fopen(argv[i], "r"); fileName = (char*)malloc((int)(strlen(argv[i]) - AS_LEN + 1)); if (!fileName) return; strncpy(fileName, argv[i], strlen(argv[i]) -AS_LEN); fileName[(int)(strlen(argv[i]) - AS_LEN)] = '\0'; } else { fileName = argv[i]; if (!fileName) return; asmFileName = (char*)malloc(strlen(fileName)); if (!asmFileName) return; strcpy(asmFileName, fileName); strcat(asmFileName, ".as"); asmFile = fopen(asmFileName, "r"); } if (!asmFile) { printf("#Error: Can not open file!\n"); } else if (!checkIfFileEmpty(asmFile)) { while (fgets(buffer, BUFFER_SIZE, asmFile)) { if (strlen(buffer) > LINE_LEN) { printf("#Error in file %s at line %d- Invalid line lenght:" " a line should be less than 80 words!\n", argv[i] + firstNameIndex(argv[i]), line); status = False; } else { strcat(buffer, " "); parsed = parser(buffer, argv[i], line, True); if (parsed && !phasesHandler(NULL, parsed, &symbolHead, &dataHead, &entryList, argv[i], line, &ic, &dc, True) && status) { status = False; } freePsr(parsed); } line++; } if (status) updateSymbols(&symbolHead, &ic); phaseTwoProcess(asmFile, fileName, &symbolHead, &dataHead, &entryList, status, &ic, &dc); } else { printf("#Error in file %s: file is empty\n", argv[i] + firstNameIndex(argv[i])); fclose(asmFile); } } } else { printf("#Error: no file was given!\n"); return; } }
[ "void", "phaseOneProcess", "(", "int", "argc", ",", "char", "*", "argv", "[", "]", ")", "{", "symbol", "*", "symbolHead", "=", "NULL", ";", "dWord", "*", "dataHead", "=", "NULL", ";", "entry", "*", "entryList", "=", "NULL", ";", "psr", "*", "parsed", "=", "NULL", ";", "boolean", "status", "=", "True", ";", "int", "i", ",", "line", ",", "ic", "=", "0", ",", "dc", "=", "0", ";", "char", "*", "fileName", "=", "NULL", ",", "*", "asmFileName", "=", "NULL", ";", "FILE", "*", "asmFile", "=", "NULL", ";", "char", "buffer", "[", "BUFFER_SIZE", "]", ";", "if", "(", "argc", ">=", "2", ")", "{", "for", "(", "i", "=", "1", ";", "i", "<", "argc", ";", "i", "++", ")", "{", "symbolHead", "=", "NULL", ";", "dataHead", "=", "NULL", ";", "entryList", "=", "NULL", ";", "status", "=", "True", ";", "line", "=", "1", ",", "ic", "=", "dc", "=", "0", ";", "asmFileName", "=", "NULL", ";", "asmFile", "=", "NULL", ";", "parsed", "=", "NULL", ";", "if", "(", "stringCmp", "(", "\"", "\"", ",", "argv", "[", "i", "]", ",", "(", "int", ")", "(", "strlen", "(", "argv", "[", "i", "]", ")", "-", "AS_LEN", ")", ",", "(", "int", ")", "(", "strlen", "(", "argv", "[", "i", "]", ")", ")", ")", ")", "{", "asmFile", "=", "fopen", "(", "argv", "[", "i", "]", ",", "\"", "\"", ")", ";", "fileName", "=", "(", "char", "*", ")", "malloc", "(", "(", "int", ")", "(", "strlen", "(", "argv", "[", "i", "]", ")", "-", "AS_LEN", "+", "1", ")", ")", ";", "if", "(", "!", "fileName", ")", "return", ";", "strncpy", "(", "fileName", ",", "argv", "[", "i", "]", ",", "strlen", "(", "argv", "[", "i", "]", ")", "-", "AS_LEN", ")", ";", "fileName", "[", "(", "int", ")", "(", "strlen", "(", "argv", "[", "i", "]", ")", "-", "AS_LEN", ")", "]", "=", "'", "\\0", "'", ";", "}", "else", "{", "fileName", "=", "argv", "[", "i", "]", ";", "if", "(", "!", "fileName", ")", "return", ";", "asmFileName", "=", "(", "char", "*", ")", "malloc", "(", "strlen", "(", "fileName", ")", ")", ";", "if", "(", "!", "asmFileName", ")", "return", ";", "strcpy", "(", "asmFileName", ",", "fileName", ")", ";", "strcat", "(", "asmFileName", ",", "\"", "\"", ")", ";", "asmFile", "=", "fopen", "(", "asmFileName", ",", "\"", "\"", ")", ";", "}", "if", "(", "!", "asmFile", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "else", "if", "(", "!", "checkIfFileEmpty", "(", "asmFile", ")", ")", "{", "while", "(", "fgets", "(", "buffer", ",", "BUFFER_SIZE", ",", "asmFile", ")", ")", "{", "if", "(", "strlen", "(", "buffer", ")", ">", "LINE_LEN", ")", "{", "printf", "(", "\"", "\"", "\"", "\\n", "\"", ",", "argv", "[", "i", "]", "+", "firstNameIndex", "(", "argv", "[", "i", "]", ")", ",", "line", ")", ";", "status", "=", "False", ";", "}", "else", "{", "strcat", "(", "buffer", ",", "\"", "\"", ")", ";", "parsed", "=", "parser", "(", "buffer", ",", "argv", "[", "i", "]", ",", "line", ",", "True", ")", ";", "if", "(", "parsed", "&&", "!", "phasesHandler", "(", "NULL", ",", "parsed", ",", "&", "symbolHead", ",", "&", "dataHead", ",", "&", "entryList", ",", "argv", "[", "i", "]", ",", "line", ",", "&", "ic", ",", "&", "dc", ",", "True", ")", "&&", "status", ")", "{", "status", "=", "False", ";", "}", "freePsr", "(", "parsed", ")", ";", "}", "line", "++", ";", "}", "if", "(", "status", ")", "updateSymbols", "(", "&", "symbolHead", ",", "&", "ic", ")", ";", "phaseTwoProcess", "(", "asmFile", ",", "fileName", ",", "&", "symbolHead", ",", "&", "dataHead", ",", "&", "entryList", ",", "status", ",", "&", "ic", ",", "&", "dc", ")", ";", "}", "else", "{", "printf", "(", "\"", "\\n", "\"", ",", "argv", "[", "i", "]", "+", "firstNameIndex", "(", "argv", "[", "i", "]", ")", ")", ";", "fclose", "(", "asmFile", ")", ";", "}", "}", "}", "else", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", ";", "}", "}" ]
This method handles the first phase of the project INPUT: int argc - th number of files INPUT: char* argv[] - the array of strings that contains the file names OUTPUT: NONE
[ "This", "method", "handles", "the", "first", "phase", "of", "the", "project", "INPUT", ":", "int", "argc", "-", "th", "number", "of", "files", "INPUT", ":", "char", "*", "argv", "[]", "-", "the", "array", "of", "strings", "that", "contains", "the", "file", "names", "OUTPUT", ":", "NONE" ]
[ "/*set up the data structs*/", "/*a flag used to block file making*/", "/* index for loops*/", "/*the number of line */", "/*instruction counter*/", "/*data counter*/", "/*file name given as a parameter from argv, might be converted if contains the .ps file name at the end*/", "/*the file name of the asm file, just the fileName but with .as*/", "/*reset the values after we've delt if the previous file*/", "/*check if the file could be opened*/", "/*if the file is openable we check if it's empty or not*/", "/*if the file is not empty get each line and put it to the buffer*/", "/*a valid line should be less than 80 letters*/", "/*add ' ' just for empty strings*/", "/*get the processed line into word array*/", "/*now we send these words to word handlers*/", "/*if the file was valid we update the symbol table*/" ]
[ { "param": "argc", "type": "int" }, { "param": "argv", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "argv", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
176d7f539b26f27977a417db260f5fdd8f500355
VaporShader/Custom-Compiler
main/data.c
[ "MIT" ]
C
clearData
void
void clearData(symbol** symbolHead, dWord** dataHead, entry** entryList) { symbol* symbolTemp = *symbolHead, *syNext; dWord* dtTemp = *dataHead, * dtNext; entry* entryTemp = *entryList, * entryNext; if(symbolTemp) { while (symbolTemp) { syNext = symbolTemp->next; free(symbolTemp); symbolTemp = syNext; } } if(dtTemp) { while (dtTemp) { dtNext = dtTemp->next; free(dtTemp); dtTemp = dtNext; } } if (entryTemp) { while (entryTemp) { entryNext = entryTemp->next; free(entryTemp); entryTemp = entryNext; } } }
/* This method frees up the data of the symbols and data words INPUT: symbol** symbolHead - the symbol table array list INPUT: dWord** dataHead - the data word array list OUTPUT: NONE */
This method frees up the data of the symbols and data words INPUT: symbol** symbolHead - the symbol table array list INPUT: dWord** dataHead - the data word array list OUTPUT: NONE
[ "This", "method", "frees", "up", "the", "data", "of", "the", "symbols", "and", "data", "words", "INPUT", ":", "symbol", "**", "symbolHead", "-", "the", "symbol", "table", "array", "list", "INPUT", ":", "dWord", "**", "dataHead", "-", "the", "data", "word", "array", "list", "OUTPUT", ":", "NONE" ]
void clearData(symbol** symbolHead, dWord** dataHead, entry** entryList) { symbol* symbolTemp = *symbolHead, *syNext; dWord* dtTemp = *dataHead, * dtNext; entry* entryTemp = *entryList, * entryNext; if(symbolTemp) { while (symbolTemp) { syNext = symbolTemp->next; free(symbolTemp); symbolTemp = syNext; } } if(dtTemp) { while (dtTemp) { dtNext = dtTemp->next; free(dtTemp); dtTemp = dtNext; } } if (entryTemp) { while (entryTemp) { entryNext = entryTemp->next; free(entryTemp); entryTemp = entryNext; } } }
[ "void", "clearData", "(", "symbol", "*", "*", "symbolHead", ",", "dWord", "*", "*", "dataHead", ",", "entry", "*", "*", "entryList", ")", "{", "symbol", "*", "symbolTemp", "=", "*", "symbolHead", ",", "*", "syNext", ";", "dWord", "*", "dtTemp", "=", "*", "dataHead", ",", "*", "dtNext", ";", "entry", "*", "entryTemp", "=", "*", "entryList", ",", "*", "entryNext", ";", "if", "(", "symbolTemp", ")", "{", "while", "(", "symbolTemp", ")", "{", "syNext", "=", "symbolTemp", "->", "next", ";", "free", "(", "symbolTemp", ")", ";", "symbolTemp", "=", "syNext", ";", "}", "}", "if", "(", "dtTemp", ")", "{", "while", "(", "dtTemp", ")", "{", "dtNext", "=", "dtTemp", "->", "next", ";", "free", "(", "dtTemp", ")", ";", "dtTemp", "=", "dtNext", ";", "}", "}", "if", "(", "entryTemp", ")", "{", "while", "(", "entryTemp", ")", "{", "entryNext", "=", "entryTemp", "->", "next", ";", "free", "(", "entryTemp", ")", ";", "entryTemp", "=", "entryNext", ";", "}", "}", "}" ]
This method frees up the data of the symbols and data words INPUT: symbol** symbolHead - the symbol table array list INPUT: dWord** dataHead - the data word array list OUTPUT: NONE
[ "This", "method", "frees", "up", "the", "data", "of", "the", "symbols", "and", "data", "words", "INPUT", ":", "symbol", "**", "symbolHead", "-", "the", "symbol", "table", "array", "list", "INPUT", ":", "dWord", "**", "dataHead", "-", "the", "data", "word", "array", "list", "OUTPUT", ":", "NONE" ]
[]
[ { "param": "symbolHead", "type": "symbol" }, { "param": "dataHead", "type": "dWord" }, { "param": "entryList", "type": "entry" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "symbolHead", "type": "symbol", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dataHead", "type": "dWord", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "entryList", "type": "entry", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
176d7f539b26f27977a417db260f5fdd8f500355
VaporShader/Custom-Compiler
main/data.c
[ "MIT" ]
C
addDataWord
void
void addDataWord(dWord** dataHead, char word[], int dc) { dWord* ptr, * temp = (dWord*)malloc(sizeof(dWord)); int size; if (!temp) return; size = (int)(strlen(word)) + 1; temp->word = (char*)malloc(size); if (!temp->word) return; temp->word[(int)(size - 1)] = '\0'; strcpy(temp->word, word); temp->dc = dc; temp->next = NULL; if (!*dataHead) (*dataHead) = temp; else { for (ptr = *dataHead; ptr->next; ptr = ptr->next); ptr->next = temp; } }
/* This method adds a new data word to the array list INPUT: dWord** dataHead - the data word array list INPUT: char word[] - the string that contains the word INPUT: int dc - the index of where it is placed OUTPUT: NONE */
This method adds a new data word to the array list INPUT: dWord** dataHead - the data word array list INPUT: char word[] - the string that contains the word INPUT: int dc - the index of where it is placed OUTPUT: NONE
[ "This", "method", "adds", "a", "new", "data", "word", "to", "the", "array", "list", "INPUT", ":", "dWord", "**", "dataHead", "-", "the", "data", "word", "array", "list", "INPUT", ":", "char", "word", "[]", "-", "the", "string", "that", "contains", "the", "word", "INPUT", ":", "int", "dc", "-", "the", "index", "of", "where", "it", "is", "placed", "OUTPUT", ":", "NONE" ]
void addDataWord(dWord** dataHead, char word[], int dc) { dWord* ptr, * temp = (dWord*)malloc(sizeof(dWord)); int size; if (!temp) return; size = (int)(strlen(word)) + 1; temp->word = (char*)malloc(size); if (!temp->word) return; temp->word[(int)(size - 1)] = '\0'; strcpy(temp->word, word); temp->dc = dc; temp->next = NULL; if (!*dataHead) (*dataHead) = temp; else { for (ptr = *dataHead; ptr->next; ptr = ptr->next); ptr->next = temp; } }
[ "void", "addDataWord", "(", "dWord", "*", "*", "dataHead", ",", "char", "word", "[", "]", ",", "int", "dc", ")", "{", "dWord", "*", "ptr", ",", "*", "temp", "=", "(", "dWord", "*", ")", "malloc", "(", "sizeof", "(", "dWord", ")", ")", ";", "int", "size", ";", "if", "(", "!", "temp", ")", "return", ";", "size", "=", "(", "int", ")", "(", "strlen", "(", "word", ")", ")", "+", "1", ";", "temp", "->", "word", "=", "(", "char", "*", ")", "malloc", "(", "size", ")", ";", "if", "(", "!", "temp", "->", "word", ")", "return", ";", "temp", "->", "word", "[", "(", "int", ")", "(", "size", "-", "1", ")", "]", "=", "'", "\\0", "'", ";", "strcpy", "(", "temp", "->", "word", ",", "word", ")", ";", "temp", "->", "dc", "=", "dc", ";", "temp", "->", "next", "=", "NULL", ";", "if", "(", "!", "*", "dataHead", ")", "(", "*", "dataHead", ")", "=", "temp", ";", "else", "{", "for", "(", "ptr", "=", "*", "dataHead", ";", "ptr", "->", "next", ";", "ptr", "=", "ptr", "->", "next", ")", ";", "ptr", "->", "next", "=", "temp", ";", "}", "}" ]
This method adds a new data word to the array list INPUT: dWord** dataHead - the data word array list INPUT: char word[] - the string that contains the word INPUT: int dc - the index of where it is placed OUTPUT: NONE
[ "This", "method", "adds", "a", "new", "data", "word", "to", "the", "array", "list", "INPUT", ":", "dWord", "**", "dataHead", "-", "the", "data", "word", "array", "list", "INPUT", ":", "char", "word", "[]", "-", "the", "string", "that", "contains", "the", "word", "INPUT", ":", "int", "dc", "-", "the", "index", "of", "where", "it", "is", "placed", "OUTPUT", ":", "NONE" ]
[]
[ { "param": "dataHead", "type": "dWord" }, { "param": "word", "type": "char" }, { "param": "dc", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dataHead", "type": "dWord", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "word", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
176d7f539b26f27977a417db260f5fdd8f500355
VaporShader/Custom-Compiler
main/data.c
[ "MIT" ]
C
addEntry
void
void addEntry(entry** entryList, char name[]) { entry* ptr, * temp = (entry*)malloc(sizeof(entry)); int size = strlen(name) + 1; if (!temp) return; temp->name = (char*)malloc(size); if (!temp->name) return; temp->name[(int)(size - 1)] = '\0'; strcpy(temp->name, name); temp->next = NULL; if (!*entryList) (*entryList) = temp; else { for (ptr = *entryList; ptr->next; ptr = ptr->next); ptr->next = temp; } }
/* This method adds a new entry to the entry list INPUT: entry** entryList - the entry array list INPUT: char name[] - the string that contains the word OUTPUT: NONE */
This method adds a new entry to the entry list INPUT: entry** entryList - the entry array list INPUT: char name[] - the string that contains the word OUTPUT: NONE
[ "This", "method", "adds", "a", "new", "entry", "to", "the", "entry", "list", "INPUT", ":", "entry", "**", "entryList", "-", "the", "entry", "array", "list", "INPUT", ":", "char", "name", "[]", "-", "the", "string", "that", "contains", "the", "word", "OUTPUT", ":", "NONE" ]
void addEntry(entry** entryList, char name[]) { entry* ptr, * temp = (entry*)malloc(sizeof(entry)); int size = strlen(name) + 1; if (!temp) return; temp->name = (char*)malloc(size); if (!temp->name) return; temp->name[(int)(size - 1)] = '\0'; strcpy(temp->name, name); temp->next = NULL; if (!*entryList) (*entryList) = temp; else { for (ptr = *entryList; ptr->next; ptr = ptr->next); ptr->next = temp; } }
[ "void", "addEntry", "(", "entry", "*", "*", "entryList", ",", "char", "name", "[", "]", ")", "{", "entry", "*", "ptr", ",", "*", "temp", "=", "(", "entry", "*", ")", "malloc", "(", "sizeof", "(", "entry", ")", ")", ";", "int", "size", "=", "strlen", "(", "name", ")", "+", "1", ";", "if", "(", "!", "temp", ")", "return", ";", "temp", "->", "name", "=", "(", "char", "*", ")", "malloc", "(", "size", ")", ";", "if", "(", "!", "temp", "->", "name", ")", "return", ";", "temp", "->", "name", "[", "(", "int", ")", "(", "size", "-", "1", ")", "]", "=", "'", "\\0", "'", ";", "strcpy", "(", "temp", "->", "name", ",", "name", ")", ";", "temp", "->", "next", "=", "NULL", ";", "if", "(", "!", "*", "entryList", ")", "(", "*", "entryList", ")", "=", "temp", ";", "else", "{", "for", "(", "ptr", "=", "*", "entryList", ";", "ptr", "->", "next", ";", "ptr", "=", "ptr", "->", "next", ")", ";", "ptr", "->", "next", "=", "temp", ";", "}", "}" ]
This method adds a new entry to the entry list INPUT: entry** entryList - the entry array list INPUT: char name[] - the string that contains the word OUTPUT: NONE
[ "This", "method", "adds", "a", "new", "entry", "to", "the", "entry", "list", "INPUT", ":", "entry", "**", "entryList", "-", "the", "entry", "array", "list", "INPUT", ":", "char", "name", "[]", "-", "the", "string", "that", "contains", "the", "word", "OUTPUT", ":", "NONE" ]
[]
[ { "param": "entryList", "type": "entry" }, { "param": "name", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "entryList", "type": "entry", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
176d7f539b26f27977a417db260f5fdd8f500355
VaporShader/Custom-Compiler
main/data.c
[ "MIT" ]
C
updateSymbols
void
void updateSymbols(symbol** symbolHead, int* ic) { symbol* ptr; if (*symbolHead) { for (ptr = *symbolHead; ptr; ptr = ptr->next) { if (ptr->type == Code) ptr->value += 100; else if (ptr->type == Data) ptr->value += 100 + *ic; } } }
/* This method updates the indexes of the symbols in the symbol table INPUT: symbol** symbolHead - the symbol table INPUT: int* ic - the lenght of the ic to sum with OUTPUT: NONE */
This method updates the indexes of the symbols in the symbol table INPUT: symbol** symbolHead - the symbol table INPUT: int* ic - the lenght of the ic to sum with OUTPUT: NONE
[ "This", "method", "updates", "the", "indexes", "of", "the", "symbols", "in", "the", "symbol", "table", "INPUT", ":", "symbol", "**", "symbolHead", "-", "the", "symbol", "table", "INPUT", ":", "int", "*", "ic", "-", "the", "lenght", "of", "the", "ic", "to", "sum", "with", "OUTPUT", ":", "NONE" ]
void updateSymbols(symbol** symbolHead, int* ic) { symbol* ptr; if (*symbolHead) { for (ptr = *symbolHead; ptr; ptr = ptr->next) { if (ptr->type == Code) ptr->value += 100; else if (ptr->type == Data) ptr->value += 100 + *ic; } } }
[ "void", "updateSymbols", "(", "symbol", "*", "*", "symbolHead", ",", "int", "*", "ic", ")", "{", "symbol", "*", "ptr", ";", "if", "(", "*", "symbolHead", ")", "{", "for", "(", "ptr", "=", "*", "symbolHead", ";", "ptr", ";", "ptr", "=", "ptr", "->", "next", ")", "{", "if", "(", "ptr", "->", "type", "==", "Code", ")", "ptr", "->", "value", "+=", "100", ";", "else", "if", "(", "ptr", "->", "type", "==", "Data", ")", "ptr", "->", "value", "+=", "100", "+", "*", "ic", ";", "}", "}", "}" ]
This method updates the indexes of the symbols in the symbol table INPUT: symbol** symbolHead - the symbol table INPUT: int* ic - the lenght of the ic to sum with OUTPUT: NONE
[ "This", "method", "updates", "the", "indexes", "of", "the", "symbols", "in", "the", "symbol", "table", "INPUT", ":", "symbol", "**", "symbolHead", "-", "the", "symbol", "table", "INPUT", ":", "int", "*", "ic", "-", "the", "lenght", "of", "the", "ic", "to", "sum", "with", "OUTPUT", ":", "NONE" ]
[]
[ { "param": "symbolHead", "type": "symbol" }, { "param": "ic", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "symbolHead", "type": "symbol", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ic", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0eb1a74332ca5933ee83eb9c1a51a8c2a2deffb1
VaporShader/Custom-Compiler
main/handler.c
[ "MIT" ]
C
printDataToFile
void
void printDataToFile(FILE* file, dWord** dataHead, int* ic) { dWord* dTemp; for (dTemp = *dataHead; dTemp; dTemp = dTemp->next) { fprintf(file, "%04d %s\n", dTemp->dc + *ic, dTemp->word); } }
/* This method prints Data and String lines to the end of the object file INPUT: FILE* file - the file to print to INPUT: dWord** dataHead - the array list that contains the data INPUT: int *ic - the instruction counter that we sum with the data counter OUTPUT: NONE */
This method prints Data and String lines to the end of the object file INPUT: FILE* file - the file to print to INPUT: dWord** dataHead - the array list that contains the data INPUT: int *ic - the instruction counter that we sum with the data counter OUTPUT: NONE
[ "This", "method", "prints", "Data", "and", "String", "lines", "to", "the", "end", "of", "the", "object", "file", "INPUT", ":", "FILE", "*", "file", "-", "the", "file", "to", "print", "to", "INPUT", ":", "dWord", "**", "dataHead", "-", "the", "array", "list", "that", "contains", "the", "data", "INPUT", ":", "int", "*", "ic", "-", "the", "instruction", "counter", "that", "we", "sum", "with", "the", "data", "counter", "OUTPUT", ":", "NONE" ]
void printDataToFile(FILE* file, dWord** dataHead, int* ic) { dWord* dTemp; for (dTemp = *dataHead; dTemp; dTemp = dTemp->next) { fprintf(file, "%04d %s\n", dTemp->dc + *ic, dTemp->word); } }
[ "void", "printDataToFile", "(", "FILE", "*", "file", ",", "dWord", "*", "*", "dataHead", ",", "int", "*", "ic", ")", "{", "dWord", "*", "dTemp", ";", "for", "(", "dTemp", "=", "*", "dataHead", ";", "dTemp", ";", "dTemp", "=", "dTemp", "->", "next", ")", "{", "fprintf", "(", "file", ",", "\"", "\\n", "\"", ",", "dTemp", "->", "dc", "+", "*", "ic", ",", "dTemp", "->", "word", ")", ";", "}", "}" ]
This method prints Data and String lines to the end of the object file INPUT: FILE* file - the file to print to INPUT: dWord** dataHead - the array list that contains the data INPUT: int *ic - the instruction counter that we sum with the data counter OUTPUT: NONE
[ "This", "method", "prints", "Data", "and", "String", "lines", "to", "the", "end", "of", "the", "object", "file", "INPUT", ":", "FILE", "*", "file", "-", "the", "file", "to", "print", "to", "INPUT", ":", "dWord", "**", "dataHead", "-", "the", "array", "list", "that", "contains", "the", "data", "INPUT", ":", "int", "*", "ic", "-", "the", "instruction", "counter", "that", "we", "sum", "with", "the", "data", "counter", "OUTPUT", ":", "NONE" ]
[]
[ { "param": "file", "type": "FILE" }, { "param": "dataHead", "type": "dWord" }, { "param": "ic", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dataHead", "type": "dWord", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ic", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d3254efcc6e025215a13cba7ec5d3eccfd7898c6
VaporShader/Custom-Compiler
main/helper.c
[ "MIT" ]
C
firstNameIndex
int
int firstNameIndex(char str[]) { int i, lastSlash = 0; for (i = 0; i < strlen(str); i++) { /*in linux we have / as a dir symbol and in windows we have \*/ if ((str[i] == '/' || str[i] == '\\' )&& lastSlash < i) lastSlash = i; } return (lastSlash)? lastSlash + 1 : 0; }
/* This method finds the first index of the file name because the user could give the program a full lenght name the includes the directory with the file name INPUT: char str[] - the string to check OUTPUT: int - the position of the file name else 0 */
This method finds the first index of the file name because the user could give the program a full lenght name the includes the directory with the file name INPUT: char str[] - the string to check OUTPUT: int - the position of the file name else 0
[ "This", "method", "finds", "the", "first", "index", "of", "the", "file", "name", "because", "the", "user", "could", "give", "the", "program", "a", "full", "lenght", "name", "the", "includes", "the", "directory", "with", "the", "file", "name", "INPUT", ":", "char", "str", "[]", "-", "the", "string", "to", "check", "OUTPUT", ":", "int", "-", "the", "position", "of", "the", "file", "name", "else", "0" ]
int firstNameIndex(char str[]) { int i, lastSlash = 0; for (i = 0; i < strlen(str); i++) { if ((str[i] == '/' || str[i] == '\\' )&& lastSlash < i) lastSlash = i; } return (lastSlash)? lastSlash + 1 : 0; }
[ "int", "firstNameIndex", "(", "char", "str", "[", "]", ")", "{", "int", "i", ",", "lastSlash", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "strlen", "(", "str", ")", ";", "i", "++", ")", "{", "if", "(", "(", "str", "[", "i", "]", "==", "'", "'", "||", "str", "[", "i", "]", "==", "'", "\\\\", "'", ")", "&&", "lastSlash", "<", "i", ")", "lastSlash", "=", "i", ";", "}", "return", "(", "lastSlash", ")", "?", "lastSlash", "+", "1", ":", "0", ";", "}" ]
This method finds the first index of the file name because the user could give the program a full lenght name the includes the directory with the file name INPUT: char str[] - the string to check OUTPUT: int - the position of the file name else 0
[ "This", "method", "finds", "the", "first", "index", "of", "the", "file", "name", "because", "the", "user", "could", "give", "the", "program", "a", "full", "lenght", "name", "the", "includes", "the", "directory", "with", "the", "file", "name", "INPUT", ":", "char", "str", "[]", "-", "the", "string", "to", "check", "OUTPUT", ":", "int", "-", "the", "position", "of", "the", "file", "name", "else", "0" ]
[ "/*in linux we have / as a dir symbol and in windows we have \\*/" ]
[ { "param": "str", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "str", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d3254efcc6e025215a13cba7ec5d3eccfd7898c6
VaporShader/Custom-Compiler
main/helper.c
[ "MIT" ]
C
binToSpe
void
void binToSpe(char src[], char dst[]) { int i, j ; for (i = 0, j = 0; i < WORD_LEN; j++, i = i+2) { if (src[i] == '0' && src[i + 1] == '0') dst[j] = '*'; else if (src[i] == '0' && src[i + 1] == '1') dst[j] = '#'; else if (src[i] == '1' && src[i + 1] == '0') dst[j] = '%'; else if (src[i] == '1' && src[i + 1] == '1') dst[j] = '!'; } }
/* This method converts a binary string into a special machine string INPUT: char src[] - the source string that contains the binary data INPUT: char dst[] - the destination string to store the special converted string OUTPUT: NONE */
This method converts a binary string into a special machine string INPUT: char src[] - the source string that contains the binary data INPUT: char dst[] - the destination string to store the special converted string OUTPUT: NONE
[ "This", "method", "converts", "a", "binary", "string", "into", "a", "special", "machine", "string", "INPUT", ":", "char", "src", "[]", "-", "the", "source", "string", "that", "contains", "the", "binary", "data", "INPUT", ":", "char", "dst", "[]", "-", "the", "destination", "string", "to", "store", "the", "special", "converted", "string", "OUTPUT", ":", "NONE" ]
void binToSpe(char src[], char dst[]) { int i, j ; for (i = 0, j = 0; i < WORD_LEN; j++, i = i+2) { if (src[i] == '0' && src[i + 1] == '0') dst[j] = '*'; else if (src[i] == '0' && src[i + 1] == '1') dst[j] = '#'; else if (src[i] == '1' && src[i + 1] == '0') dst[j] = '%'; else if (src[i] == '1' && src[i + 1] == '1') dst[j] = '!'; } }
[ "void", "binToSpe", "(", "char", "src", "[", "]", ",", "char", "dst", "[", "]", ")", "{", "int", "i", ",", "j", ";", "for", "(", "i", "=", "0", ",", "j", "=", "0", ";", "i", "<", "WORD_LEN", ";", "j", "++", ",", "i", "=", "i", "+", "2", ")", "{", "if", "(", "src", "[", "i", "]", "==", "'", "'", "&&", "src", "[", "i", "+", "1", "]", "==", "'", "'", ")", "dst", "[", "j", "]", "=", "'", "'", ";", "else", "if", "(", "src", "[", "i", "]", "==", "'", "'", "&&", "src", "[", "i", "+", "1", "]", "==", "'", "'", ")", "dst", "[", "j", "]", "=", "'", "'", ";", "else", "if", "(", "src", "[", "i", "]", "==", "'", "'", "&&", "src", "[", "i", "+", "1", "]", "==", "'", "'", ")", "dst", "[", "j", "]", "=", "'", "'", ";", "else", "if", "(", "src", "[", "i", "]", "==", "'", "'", "&&", "src", "[", "i", "+", "1", "]", "==", "'", "'", ")", "dst", "[", "j", "]", "=", "'", "'", ";", "}", "}" ]
This method converts a binary string into a special machine string INPUT: char src[] - the source string that contains the binary data INPUT: char dst[] - the destination string to store the special converted string OUTPUT: NONE
[ "This", "method", "converts", "a", "binary", "string", "into", "a", "special", "machine", "string", "INPUT", ":", "char", "src", "[]", "-", "the", "source", "string", "that", "contains", "the", "binary", "data", "INPUT", ":", "char", "dst", "[]", "-", "the", "destination", "string", "to", "store", "the", "special", "converted", "string", "OUTPUT", ":", "NONE" ]
[]
[ { "param": "src", "type": "char" }, { "param": "dst", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "src", "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": [] }
d3254efcc6e025215a13cba7ec5d3eccfd7898c6
VaporShader/Custom-Compiler
main/helper.c
[ "MIT" ]
C
printEntryList
void
void printEntryList(files* outputFiles, symbol** symbolHead, entry** entryList) { entry* entryPtr; symbol* symbolPtr; for (symbolPtr = *symbolHead; symbolPtr; symbolPtr = symbolPtr->next) { for (entryPtr = *entryList; entryPtr; entryPtr = entryPtr->next) { if (!strcmp(symbolPtr->name, entryPtr->name)) { fprintf(outputFiles->entryFile, "%s %04d\n", symbolPtr->name, symbolPtr->value); } } } }
/* This method finds a label in the entry list and if they match the label will be printed in the entry list INPUT: entry** entryList - the label list INPUT: char str[] - the name of the label to find OUTPUT: True if label is signed to Entry else false */
This method finds a label in the entry list and if they match the label will be printed in the entry list INPUT: entry** entryList - the label list INPUT: char str[] - the name of the label to find OUTPUT: True if label is signed to Entry else false
[ "This", "method", "finds", "a", "label", "in", "the", "entry", "list", "and", "if", "they", "match", "the", "label", "will", "be", "printed", "in", "the", "entry", "list", "INPUT", ":", "entry", "**", "entryList", "-", "the", "label", "list", "INPUT", ":", "char", "str", "[]", "-", "the", "name", "of", "the", "label", "to", "find", "OUTPUT", ":", "True", "if", "label", "is", "signed", "to", "Entry", "else", "false" ]
void printEntryList(files* outputFiles, symbol** symbolHead, entry** entryList) { entry* entryPtr; symbol* symbolPtr; for (symbolPtr = *symbolHead; symbolPtr; symbolPtr = symbolPtr->next) { for (entryPtr = *entryList; entryPtr; entryPtr = entryPtr->next) { if (!strcmp(symbolPtr->name, entryPtr->name)) { fprintf(outputFiles->entryFile, "%s %04d\n", symbolPtr->name, symbolPtr->value); } } } }
[ "void", "printEntryList", "(", "files", "*", "outputFiles", ",", "symbol", "*", "*", "symbolHead", ",", "entry", "*", "*", "entryList", ")", "{", "entry", "*", "entryPtr", ";", "symbol", "*", "symbolPtr", ";", "for", "(", "symbolPtr", "=", "*", "symbolHead", ";", "symbolPtr", ";", "symbolPtr", "=", "symbolPtr", "->", "next", ")", "{", "for", "(", "entryPtr", "=", "*", "entryList", ";", "entryPtr", ";", "entryPtr", "=", "entryPtr", "->", "next", ")", "{", "if", "(", "!", "strcmp", "(", "symbolPtr", "->", "name", ",", "entryPtr", "->", "name", ")", ")", "{", "fprintf", "(", "outputFiles", "->", "entryFile", ",", "\"", "\\n", "\"", ",", "symbolPtr", "->", "name", ",", "symbolPtr", "->", "value", ")", ";", "}", "}", "}", "}" ]
This method finds a label in the entry list and if they match the label will be printed in the entry list INPUT: entry** entryList - the label list INPUT: char str[] - the name of the label to find OUTPUT: True if label is signed to Entry else false
[ "This", "method", "finds", "a", "label", "in", "the", "entry", "list", "and", "if", "they", "match", "the", "label", "will", "be", "printed", "in", "the", "entry", "list", "INPUT", ":", "entry", "**", "entryList", "-", "the", "label", "list", "INPUT", ":", "char", "str", "[]", "-", "the", "name", "of", "the", "label", "to", "find", "OUTPUT", ":", "True", "if", "label", "is", "signed", "to", "Entry", "else", "false" ]
[]
[ { "param": "outputFiles", "type": "files" }, { "param": "symbolHead", "type": "symbol" }, { "param": "entryList", "type": "entry" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "outputFiles", "type": "files", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "symbolHead", "type": "symbol", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "entryList", "type": "entry", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d3254efcc6e025215a13cba7ec5d3eccfd7898c6
VaporShader/Custom-Compiler
main/helper.c
[ "MIT" ]
C
checkNumber
boolean
boolean checkNumber(char str[], int start, int end) { int i, num = 0, pm = 0; if (str[start] == '+' || str[start] == '-') pm++; /*check if there's one plus or minus*/ for (i = start; i < end; i++) if (str[i] >= '0' && str[i] <= '9') num++; /*if its a number add it to the counter*/ return (num + pm != end - start)? False : True; /*return true if the lenght of the string is equal to the count of numbers*/ }
/* This method checks if the string between two indexes is a real number INPUT: char str[] - the string that contains the number INPUT: int start - the first index to check INPUT: int end - the index to stop OUTPUT: boolean - True if real number else False */
This method checks if the string between two indexes is a real number INPUT: char str[] - the string that contains the number INPUT: int start - the first index to check INPUT: int end - the index to stop OUTPUT: boolean - True if real number else False
[ "This", "method", "checks", "if", "the", "string", "between", "two", "indexes", "is", "a", "real", "number", "INPUT", ":", "char", "str", "[]", "-", "the", "string", "that", "contains", "the", "number", "INPUT", ":", "int", "start", "-", "the", "first", "index", "to", "check", "INPUT", ":", "int", "end", "-", "the", "index", "to", "stop", "OUTPUT", ":", "boolean", "-", "True", "if", "real", "number", "else", "False" ]
boolean checkNumber(char str[], int start, int end) { int i, num = 0, pm = 0; if (str[start] == '+' || str[start] == '-') pm++; for (i = start; i < end; i++) if (str[i] >= '0' && str[i] <= '9') num++; return (num + pm != end - start)? False : True; }
[ "boolean", "checkNumber", "(", "char", "str", "[", "]", ",", "int", "start", ",", "int", "end", ")", "{", "int", "i", ",", "num", "=", "0", ",", "pm", "=", "0", ";", "if", "(", "str", "[", "start", "]", "==", "'", "'", "||", "str", "[", "start", "]", "==", "'", "'", ")", "pm", "++", ";", "for", "(", "i", "=", "start", ";", "i", "<", "end", ";", "i", "++", ")", "if", "(", "str", "[", "i", "]", ">=", "'", "'", "&&", "str", "[", "i", "]", "<=", "'", "'", ")", "num", "++", ";", "return", "(", "num", "+", "pm", "!=", "end", "-", "start", ")", "?", "False", ":", "True", ";", "}" ]
This method checks if the string between two indexes is a real number INPUT: char str[] - the string that contains the number INPUT: int start - the first index to check INPUT: int end - the index to stop OUTPUT: boolean - True if real number else False
[ "This", "method", "checks", "if", "the", "string", "between", "two", "indexes", "is", "a", "real", "number", "INPUT", ":", "char", "str", "[]", "-", "the", "string", "that", "contains", "the", "number", "INPUT", ":", "int", "start", "-", "the", "first", "index", "to", "check", "INPUT", ":", "int", "end", "-", "the", "index", "to", "stop", "OUTPUT", ":", "boolean", "-", "True", "if", "real", "number", "else", "False" ]
[ "/*check if there's one plus or minus*/", "/*if its a number add it to the counter*/", "/*return true if the lenght of the string is equal to the count of numbers*/" ]
[ { "param": "str", "type": "char" }, { "param": "start", "type": "int" }, { "param": "end", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "str", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "start", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "end", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d3254efcc6e025215a13cba7ec5d3eccfd7898c6
VaporShader/Custom-Compiler
main/helper.c
[ "MIT" ]
C
checkIfFileEmpty
boolean
boolean checkIfFileEmpty(FILE* file) { int size; if (file) { fseek(file, 0, SEEK_END); size = ftell(file); rewind(file); /*we reset the pointer so that we will be able to use a non empty file*/ return(size == 0) ? True : False; } return True; }
/* This method checks if the file is empty INPUT: FILE* file - the file to check if it's empty OUTPUT: boolean - True if file empty else False */
This method checks if the file is empty INPUT: FILE* file - the file to check if it's empty OUTPUT: boolean - True if file empty else False
[ "This", "method", "checks", "if", "the", "file", "is", "empty", "INPUT", ":", "FILE", "*", "file", "-", "the", "file", "to", "check", "if", "it", "'", "s", "empty", "OUTPUT", ":", "boolean", "-", "True", "if", "file", "empty", "else", "False" ]
boolean checkIfFileEmpty(FILE* file) { int size; if (file) { fseek(file, 0, SEEK_END); size = ftell(file); rewind(file); return(size == 0) ? True : False; } return True; }
[ "boolean", "checkIfFileEmpty", "(", "FILE", "*", "file", ")", "{", "int", "size", ";", "if", "(", "file", ")", "{", "fseek", "(", "file", ",", "0", ",", "SEEK_END", ")", ";", "size", "=", "ftell", "(", "file", ")", ";", "rewind", "(", "file", ")", ";", "return", "(", "size", "==", "0", ")", "?", "True", ":", "False", ";", "}", "return", "True", ";", "}" ]
This method checks if the file is empty INPUT: FILE* file - the file to check if it's empty OUTPUT: boolean - True if file empty else False
[ "This", "method", "checks", "if", "the", "file", "is", "empty", "INPUT", ":", "FILE", "*", "file", "-", "the", "file", "to", "check", "if", "it", "'", "s", "empty", "OUTPUT", ":", "boolean", "-", "True", "if", "file", "empty", "else", "False" ]
[ "/*we reset the pointer so that we will be able to use a non empty file*/" ]
[ { "param": "file", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "file", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
load_crl
X509_CRL
X509_CRL *load_crl(const char *uri, int format, const char *desc) { X509_CRL *crl = NULL; if (desc == NULL) desc = "CRL"; (void)load_key_cert_crl(uri, 0, NULL, desc, NULL, NULL, &crl); if (crl == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } return crl; }
/* the format parameter is meanwhile not needed anymore and thus ignored */
the format parameter is meanwhile not needed anymore and thus ignored
[ "the", "format", "parameter", "is", "meanwhile", "not", "needed", "anymore", "and", "thus", "ignored" ]
X509_CRL *load_crl(const char *uri, int format, const char *desc) { X509_CRL *crl = NULL; if (desc == NULL) desc = "CRL"; (void)load_key_cert_crl(uri, 0, NULL, desc, NULL, NULL, &crl); if (crl == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } return crl; }
[ "X509_CRL", "*", "load_crl", "(", "const", "char", "*", "uri", ",", "int", "format", ",", "const", "char", "*", "desc", ")", "{", "X509_CRL", "*", "crl", "=", "NULL", ";", "if", "(", "desc", "==", "NULL", ")", "desc", "=", "\"", "\"", ";", "(", "void", ")", "load_key_cert_crl", "(", "uri", ",", "0", ",", "NULL", ",", "desc", ",", "NULL", ",", "NULL", ",", "&", "crl", ")", ";", "if", "(", "crl", "==", "NULL", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "desc", ")", ";", "ERR_print_errors", "(", "bio_err", ")", ";", "}", "return", "crl", ";", "}" ]
the format parameter is meanwhile not needed anymore and thus ignored
[ "the", "format", "parameter", "is", "meanwhile", "not", "needed", "anymore", "and", "thus", "ignored" ]
[]
[ { "param": "uri", "type": "char" }, { "param": "format", "type": "int" }, { "param": "desc", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "uri", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "format", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "desc", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
load_key_cert_crl
int
int load_key_cert_crl(const char *uri, int maybe_stdin, const char *pass, const char *desc, EVP_PKEY **ppkey, X509 **pcert, X509_CRL **pcrl) { PW_CB_DATA uidata; OSSL_STORE_CTX *ctx = NULL; int ret = 0; /* TODO make use of the engine reference 'eng' when loading pkeys */ if (ppkey != NULL) *ppkey = NULL; if (pcert != NULL) *pcert = NULL; if (pcrl != NULL) *pcrl = NULL; if (desc == NULL) desc = "key/certificate/CRL"; uidata.password = pass; uidata.prompt_info = uri; if (uri == NULL) { BIO *bio; if (!maybe_stdin) { BIO_printf(bio_err, "No filename or uri specified for loading %s\n", desc); goto end; } unbuffer(stdin); bio = BIO_new_fp(stdin, 0); if (bio != NULL) ctx = OSSL_STORE_attach(bio, NULL, "file", NULL, get_ui_method(), &uidata, NULL, NULL); uri = "<stdin>"; } else { ctx = OSSL_STORE_open(uri, get_ui_method(), &uidata, NULL, NULL); } if (ctx == NULL) { BIO_printf(bio_err, "Could not open file or uri %s for loading %s\n", uri, desc); goto end; } for (;;) { OSSL_STORE_INFO *info = OSSL_STORE_load(ctx); int type = info == NULL ? 0 : OSSL_STORE_INFO_get_type(info); const char *infostr = info == NULL ? NULL : OSSL_STORE_INFO_type_string(type); int err = 0; if (info == NULL) { if (OSSL_STORE_eof(ctx)) ret = 1; break; } switch (type) { case OSSL_STORE_INFO_PKEY: if (ppkey != NULL && *ppkey == NULL) err = ((*ppkey = OSSL_STORE_INFO_get1_PKEY(info)) == NULL); break; case OSSL_STORE_INFO_CERT: if (pcert != NULL && *pcert == NULL) err = ((*pcert = OSSL_STORE_INFO_get1_CERT(info)) == NULL); break; case OSSL_STORE_INFO_CRL: if (pcrl != NULL && *pcrl == NULL) err = ((*pcrl = OSSL_STORE_INFO_get1_CRL(info)) == NULL); break; default: /* skip any other type */ break; } OSSL_STORE_INFO_free(info); if (err) { BIO_printf(bio_err, "Could not read %s of %s from %s\n", infostr, desc, uri); break; } } end: OSSL_STORE_close(ctx); if (!ret) ERR_print_errors(bio_err); return ret; }
/* * Load those types of credentials for which the result pointer is not NULL. * Reads from stdio if uri is NULL and maybe_stdin is nonzero. * For each type the first credential found in the store is loaded. * May yield partial result even if rv == 0. */
Load those types of credentials for which the result pointer is not NULL. Reads from stdio if uri is NULL and maybe_stdin is nonzero. For each type the first credential found in the store is loaded. May yield partial result even if rv == 0.
[ "Load", "those", "types", "of", "credentials", "for", "which", "the", "result", "pointer", "is", "not", "NULL", ".", "Reads", "from", "stdio", "if", "uri", "is", "NULL", "and", "maybe_stdin", "is", "nonzero", ".", "For", "each", "type", "the", "first", "credential", "found", "in", "the", "store", "is", "loaded", ".", "May", "yield", "partial", "result", "even", "if", "rv", "==", "0", "." ]
int load_key_cert_crl(const char *uri, int maybe_stdin, const char *pass, const char *desc, EVP_PKEY **ppkey, X509 **pcert, X509_CRL **pcrl) { PW_CB_DATA uidata; OSSL_STORE_CTX *ctx = NULL; int ret = 0; if (ppkey != NULL) *ppkey = NULL; if (pcert != NULL) *pcert = NULL; if (pcrl != NULL) *pcrl = NULL; if (desc == NULL) desc = "key/certificate/CRL"; uidata.password = pass; uidata.prompt_info = uri; if (uri == NULL) { BIO *bio; if (!maybe_stdin) { BIO_printf(bio_err, "No filename or uri specified for loading %s\n", desc); goto end; } unbuffer(stdin); bio = BIO_new_fp(stdin, 0); if (bio != NULL) ctx = OSSL_STORE_attach(bio, NULL, "file", NULL, get_ui_method(), &uidata, NULL, NULL); uri = "<stdin>"; } else { ctx = OSSL_STORE_open(uri, get_ui_method(), &uidata, NULL, NULL); } if (ctx == NULL) { BIO_printf(bio_err, "Could not open file or uri %s for loading %s\n", uri, desc); goto end; } for (;;) { OSSL_STORE_INFO *info = OSSL_STORE_load(ctx); int type = info == NULL ? 0 : OSSL_STORE_INFO_get_type(info); const char *infostr = info == NULL ? NULL : OSSL_STORE_INFO_type_string(type); int err = 0; if (info == NULL) { if (OSSL_STORE_eof(ctx)) ret = 1; break; } switch (type) { case OSSL_STORE_INFO_PKEY: if (ppkey != NULL && *ppkey == NULL) err = ((*ppkey = OSSL_STORE_INFO_get1_PKEY(info)) == NULL); break; case OSSL_STORE_INFO_CERT: if (pcert != NULL && *pcert == NULL) err = ((*pcert = OSSL_STORE_INFO_get1_CERT(info)) == NULL); break; case OSSL_STORE_INFO_CRL: if (pcrl != NULL && *pcrl == NULL) err = ((*pcrl = OSSL_STORE_INFO_get1_CRL(info)) == NULL); break; default: break; } OSSL_STORE_INFO_free(info); if (err) { BIO_printf(bio_err, "Could not read %s of %s from %s\n", infostr, desc, uri); break; } } end: OSSL_STORE_close(ctx); if (!ret) ERR_print_errors(bio_err); return ret; }
[ "int", "load_key_cert_crl", "(", "const", "char", "*", "uri", ",", "int", "maybe_stdin", ",", "const", "char", "*", "pass", ",", "const", "char", "*", "desc", ",", "EVP_PKEY", "*", "*", "ppkey", ",", "X509", "*", "*", "pcert", ",", "X509_CRL", "*", "*", "pcrl", ")", "{", "PW_CB_DATA", "uidata", ";", "OSSL_STORE_CTX", "*", "ctx", "=", "NULL", ";", "int", "ret", "=", "0", ";", "if", "(", "ppkey", "!=", "NULL", ")", "*", "ppkey", "=", "NULL", ";", "if", "(", "pcert", "!=", "NULL", ")", "*", "pcert", "=", "NULL", ";", "if", "(", "pcrl", "!=", "NULL", ")", "*", "pcrl", "=", "NULL", ";", "if", "(", "desc", "==", "NULL", ")", "desc", "=", "\"", "\"", ";", "uidata", ".", "password", "=", "pass", ";", "uidata", ".", "prompt_info", "=", "uri", ";", "if", "(", "uri", "==", "NULL", ")", "{", "BIO", "*", "bio", ";", "if", "(", "!", "maybe_stdin", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "desc", ")", ";", "goto", "end", ";", "}", "unbuffer", "(", "stdin", ")", ";", "bio", "=", "BIO_new_fp", "(", "stdin", ",", "0", ")", ";", "if", "(", "bio", "!=", "NULL", ")", "ctx", "=", "OSSL_STORE_attach", "(", "bio", ",", "NULL", ",", "\"", "\"", ",", "NULL", ",", "get_ui_method", "(", ")", ",", "&", "uidata", ",", "NULL", ",", "NULL", ")", ";", "uri", "=", "\"", "\"", ";", "}", "else", "{", "ctx", "=", "OSSL_STORE_open", "(", "uri", ",", "get_ui_method", "(", ")", ",", "&", "uidata", ",", "NULL", ",", "NULL", ")", ";", "}", "if", "(", "ctx", "==", "NULL", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "uri", ",", "desc", ")", ";", "goto", "end", ";", "}", "for", "(", ";", ";", ")", "{", "OSSL_STORE_INFO", "*", "info", "=", "OSSL_STORE_load", "(", "ctx", ")", ";", "int", "type", "=", "info", "==", "NULL", "?", "0", ":", "OSSL_STORE_INFO_get_type", "(", "info", ")", ";", "const", "char", "*", "infostr", "=", "info", "==", "NULL", "?", "NULL", ":", "OSSL_STORE_INFO_type_string", "(", "type", ")", ";", "int", "err", "=", "0", ";", "if", "(", "info", "==", "NULL", ")", "{", "if", "(", "OSSL_STORE_eof", "(", "ctx", ")", ")", "ret", "=", "1", ";", "break", ";", "}", "switch", "(", "type", ")", "{", "case", "OSSL_STORE_INFO_PKEY", ":", "if", "(", "ppkey", "!=", "NULL", "&&", "*", "ppkey", "==", "NULL", ")", "err", "=", "(", "(", "*", "ppkey", "=", "OSSL_STORE_INFO_get1_PKEY", "(", "info", ")", ")", "==", "NULL", ")", ";", "break", ";", "case", "OSSL_STORE_INFO_CERT", ":", "if", "(", "pcert", "!=", "NULL", "&&", "*", "pcert", "==", "NULL", ")", "err", "=", "(", "(", "*", "pcert", "=", "OSSL_STORE_INFO_get1_CERT", "(", "info", ")", ")", "==", "NULL", ")", ";", "break", ";", "case", "OSSL_STORE_INFO_CRL", ":", "if", "(", "pcrl", "!=", "NULL", "&&", "*", "pcrl", "==", "NULL", ")", "err", "=", "(", "(", "*", "pcrl", "=", "OSSL_STORE_INFO_get1_CRL", "(", "info", ")", ")", "==", "NULL", ")", ";", "break", ";", "default", ":", "break", ";", "}", "OSSL_STORE_INFO_free", "(", "info", ")", ";", "if", "(", "err", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "infostr", ",", "desc", ",", "uri", ")", ";", "break", ";", "}", "}", "end", ":", "OSSL_STORE_close", "(", "ctx", ")", ";", "if", "(", "!", "ret", ")", "ERR_print_errors", "(", "bio_err", ")", ";", "return", "ret", ";", "}" ]
Load those types of credentials for which the result pointer is not NULL.
[ "Load", "those", "types", "of", "credentials", "for", "which", "the", "result", "pointer", "is", "not", "NULL", "." ]
[ "/* TODO make use of the engine reference 'eng' when loading pkeys */", "/* skip any other type */" ]
[ { "param": "uri", "type": "char" }, { "param": "maybe_stdin", "type": "int" }, { "param": "pass", "type": "char" }, { "param": "desc", "type": "char" }, { "param": "ppkey", "type": "EVP_PKEY" }, { "param": "pcert", "type": "X509" }, { "param": "pcrl", "type": "X509_CRL" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "uri", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "maybe_stdin", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pass", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "desc", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ppkey", "type": "EVP_PKEY", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pcert", "type": "X509", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pcrl", "type": "X509_CRL", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
parse_name
X509_NAME
X509_NAME *parse_name(const char *cp, long chtype, int canmulti) { int nextismulti = 0; char *work; X509_NAME *n; if (*cp++ != '/') { BIO_printf(bio_err, "name is expected to be in the format " "/type0=value0/type1=value1/type2=... where characters may " "be escaped by \\. This name is not in that format: '%s'\n", --cp); return NULL; } n = X509_NAME_new(); if (n == NULL) return NULL; work = OPENSSL_strdup(cp); if (work == NULL) { BIO_printf(bio_err, "%s: Error copying name input\n", opt_getprog()); goto err; } while (*cp) { char *bp = work; char *typestr = bp; unsigned char *valstr; int nid; int ismulti = nextismulti; nextismulti = 0; /* Collect the type */ while (*cp && *cp != '=') *bp++ = *cp++; if (*cp == '\0') { BIO_printf(bio_err, "%s: Hit end of string before finding the '='\n", opt_getprog()); goto err; } *bp++ = '\0'; ++cp; /* Collect the value. */ valstr = (unsigned char *)bp; for (; *cp && *cp != '/'; *bp++ = *cp++) { if (canmulti && *cp == '+') { nextismulti = 1; break; } if (*cp == '\\' && *++cp == '\0') { BIO_printf(bio_err, "%s: Escape character at end of string\n", opt_getprog()); goto err; } } *bp++ = '\0'; /* If not at EOS (must be + or /), move forward. */ if (*cp) ++cp; /* Parse */ nid = OBJ_txt2nid(typestr); if (nid == NID_undef) { BIO_printf(bio_err, "%s: Skipping unknown attribute \"%s\"\n", opt_getprog(), typestr); continue; } if (*valstr == '\0') { BIO_printf(bio_err, "%s: No value provided for Subject Attribute %s, skipped\n", opt_getprog(), typestr); continue; } if (!X509_NAME_add_entry_by_NID(n, nid, chtype, valstr, strlen((char *)valstr), -1, ismulti ? -1 : 0)) { BIO_printf(bio_err, "%s: Error adding name attribute \"/%s=%s\"\n", opt_getprog(), typestr ,valstr); goto err; } } OPENSSL_free(work); return n; err: X509_NAME_free(n); OPENSSL_free(work); return NULL; }
/* * name is expected to be in the format /type0=value0/type1=value1/type2=... * where characters may be escaped by \ */
name is expected to be in the format /type0=value0/type1=value1/type2= where characters may be escaped by \
[ "name", "is", "expected", "to", "be", "in", "the", "format", "/", "type0", "=", "value0", "/", "type1", "=", "value1", "/", "type2", "=", "where", "characters", "may", "be", "escaped", "by", "\\" ]
X509_NAME *parse_name(const char *cp, long chtype, int canmulti) { int nextismulti = 0; char *work; X509_NAME *n; if (*cp++ != '/') { BIO_printf(bio_err, "name is expected to be in the format " "/type0=value0/type1=value1/type2=... where characters may " "be escaped by \\. This name is not in that format: '%s'\n", --cp); return NULL; } n = X509_NAME_new(); if (n == NULL) return NULL; work = OPENSSL_strdup(cp); if (work == NULL) { BIO_printf(bio_err, "%s: Error copying name input\n", opt_getprog()); goto err; } while (*cp) { char *bp = work; char *typestr = bp; unsigned char *valstr; int nid; int ismulti = nextismulti; nextismulti = 0; while (*cp && *cp != '=') *bp++ = *cp++; if (*cp == '\0') { BIO_printf(bio_err, "%s: Hit end of string before finding the '='\n", opt_getprog()); goto err; } *bp++ = '\0'; ++cp; valstr = (unsigned char *)bp; for (; *cp && *cp != '/'; *bp++ = *cp++) { if (canmulti && *cp == '+') { nextismulti = 1; break; } if (*cp == '\\' && *++cp == '\0') { BIO_printf(bio_err, "%s: Escape character at end of string\n", opt_getprog()); goto err; } } *bp++ = '\0'; if (*cp) ++cp; nid = OBJ_txt2nid(typestr); if (nid == NID_undef) { BIO_printf(bio_err, "%s: Skipping unknown attribute \"%s\"\n", opt_getprog(), typestr); continue; } if (*valstr == '\0') { BIO_printf(bio_err, "%s: No value provided for Subject Attribute %s, skipped\n", opt_getprog(), typestr); continue; } if (!X509_NAME_add_entry_by_NID(n, nid, chtype, valstr, strlen((char *)valstr), -1, ismulti ? -1 : 0)) { BIO_printf(bio_err, "%s: Error adding name attribute \"/%s=%s\"\n", opt_getprog(), typestr ,valstr); goto err; } } OPENSSL_free(work); return n; err: X509_NAME_free(n); OPENSSL_free(work); return NULL; }
[ "X509_NAME", "*", "parse_name", "(", "const", "char", "*", "cp", ",", "long", "chtype", ",", "int", "canmulti", ")", "{", "int", "nextismulti", "=", "0", ";", "char", "*", "work", ";", "X509_NAME", "*", "n", ";", "if", "(", "*", "cp", "++", "!=", "'", "'", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\"", "\"", "\"", "\"", "\\\\", "\\n", "\"", ",", "--", "cp", ")", ";", "return", "NULL", ";", "}", "n", "=", "X509_NAME_new", "(", ")", ";", "if", "(", "n", "==", "NULL", ")", "return", "NULL", ";", "work", "=", "OPENSSL_strdup", "(", "cp", ")", ";", "if", "(", "work", "==", "NULL", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "opt_getprog", "(", ")", ")", ";", "goto", "err", ";", "}", "while", "(", "*", "cp", ")", "{", "char", "*", "bp", "=", "work", ";", "char", "*", "typestr", "=", "bp", ";", "unsigned", "char", "*", "valstr", ";", "int", "nid", ";", "int", "ismulti", "=", "nextismulti", ";", "nextismulti", "=", "0", ";", "while", "(", "*", "cp", "&&", "*", "cp", "!=", "'", "'", ")", "*", "bp", "++", "=", "*", "cp", "++", ";", "if", "(", "*", "cp", "==", "'", "\\0", "'", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "opt_getprog", "(", ")", ")", ";", "goto", "err", ";", "}", "*", "bp", "++", "=", "'", "\\0", "'", ";", "++", "cp", ";", "valstr", "=", "(", "unsigned", "char", "*", ")", "bp", ";", "for", "(", ";", "*", "cp", "&&", "*", "cp", "!=", "'", "'", ";", "*", "bp", "++", "=", "*", "cp", "++", ")", "{", "if", "(", "canmulti", "&&", "*", "cp", "==", "'", "'", ")", "{", "nextismulti", "=", "1", ";", "break", ";", "}", "if", "(", "*", "cp", "==", "'", "\\\\", "'", "&&", "*", "++", "cp", "==", "'", "\\0", "'", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "opt_getprog", "(", ")", ")", ";", "goto", "err", ";", "}", "}", "*", "bp", "++", "=", "'", "\\0", "'", ";", "if", "(", "*", "cp", ")", "++", "cp", ";", "nid", "=", "OBJ_txt2nid", "(", "typestr", ")", ";", "if", "(", "nid", "==", "NID_undef", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\\"", "\\\"", "\\n", "\"", ",", "opt_getprog", "(", ")", ",", "typestr", ")", ";", "continue", ";", "}", "if", "(", "*", "valstr", "==", "'", "\\0", "'", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\n", "\"", ",", "opt_getprog", "(", ")", ",", "typestr", ")", ";", "continue", ";", "}", "if", "(", "!", "X509_NAME_add_entry_by_NID", "(", "n", ",", "nid", ",", "chtype", ",", "valstr", ",", "strlen", "(", "(", "char", "*", ")", "valstr", ")", ",", "-1", ",", "ismulti", "?", "-1", ":", "0", ")", ")", "{", "BIO_printf", "(", "bio_err", ",", "\"", "\\\"", "\\\"", "\\n", "\"", ",", "opt_getprog", "(", ")", ",", "typestr", ",", "valstr", ")", ";", "goto", "err", ";", "}", "}", "OPENSSL_free", "(", "work", ")", ";", "return", "n", ";", "err", ":", "X509_NAME_free", "(", "n", ")", ";", "OPENSSL_free", "(", "work", ")", ";", "return", "NULL", ";", "}" ]
name is expected to be in the format /type0=value0/type1=value1/type2=... where characters may be escaped by \
[ "name", "is", "expected", "to", "be", "in", "the", "format", "/", "type0", "=", "value0", "/", "type1", "=", "value1", "/", "type2", "=", "...", "where", "characters", "may", "be", "escaped", "by", "\\" ]
[ "/* Collect the type */", "/* Collect the value. */", "/* If not at EOS (must be + or /), move forward. */", "/* Parse */" ]
[ { "param": "cp", "type": "char" }, { "param": "chtype", "type": "long" }, { "param": "canmulti", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cp", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "chtype", "type": "long", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "canmulti", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
next_protos_parse
null
unsigned char *next_protos_parse(size_t *outlen, const char *in) { size_t len; unsigned char *out; size_t i, start = 0; size_t skipped = 0; len = strlen(in); if (len == 0 || len >= 65535) return NULL; out = app_malloc(len + 1, "NPN buffer"); for (i = 0; i <= len; ++i) { if (i == len || in[i] == ',') { /* * Zero-length ALPN elements are invalid on the wire, we could be * strict and reject the entire string, but just ignoring extra * commas seems harmless and more friendly. * * Every comma we skip in this way puts the input buffer another * byte ahead of the output buffer, so all stores into the output * buffer need to be decremented by the number commas skipped. */ if (i == start) { ++start; ++skipped; continue; } if (i - start > 255) { OPENSSL_free(out); return NULL; } out[start-skipped] = (unsigned char)(i - start); start = i + 1; } else { out[i + 1 - skipped] = in[i]; } } if (len <= skipped) { OPENSSL_free(out); return NULL; } *outlen = len + 1 - skipped; return out; }
/*- * next_protos_parse parses a comma separated list of strings into a string * in a format suitable for passing to SSL_CTX_set_next_protos_advertised. * outlen: (output) set to the length of the resulting buffer on success. * err: (maybe NULL) on failure, an error message line is written to this BIO. * in: a NUL terminated string like "abc,def,ghi" * * returns: a malloc'd buffer or NULL on failure. */
next_protos_parse parses a comma separated list of strings into a string in a format suitable for passing to SSL_CTX_set_next_protos_advertised. outlen: (output) set to the length of the resulting buffer on success. err: (maybe NULL) on failure, an error message line is written to this BIO. in: a NUL terminated string like "abc,def,ghi" a malloc'd buffer or NULL on failure.
[ "next_protos_parse", "parses", "a", "comma", "separated", "list", "of", "strings", "into", "a", "string", "in", "a", "format", "suitable", "for", "passing", "to", "SSL_CTX_set_next_protos_advertised", ".", "outlen", ":", "(", "output", ")", "set", "to", "the", "length", "of", "the", "resulting", "buffer", "on", "success", ".", "err", ":", "(", "maybe", "NULL", ")", "on", "failure", "an", "error", "message", "line", "is", "written", "to", "this", "BIO", ".", "in", ":", "a", "NUL", "terminated", "string", "like", "\"", "abc", "def", "ghi", "\"", "a", "malloc", "'", "d", "buffer", "or", "NULL", "on", "failure", "." ]
unsigned char *next_protos_parse(size_t *outlen, const char *in) { size_t len; unsigned char *out; size_t i, start = 0; size_t skipped = 0; len = strlen(in); if (len == 0 || len >= 65535) return NULL; out = app_malloc(len + 1, "NPN buffer"); for (i = 0; i <= len; ++i) { if (i == len || in[i] == ',') { if (i == start) { ++start; ++skipped; continue; } if (i - start > 255) { OPENSSL_free(out); return NULL; } out[start-skipped] = (unsigned char)(i - start); start = i + 1; } else { out[i + 1 - skipped] = in[i]; } } if (len <= skipped) { OPENSSL_free(out); return NULL; } *outlen = len + 1 - skipped; return out; }
[ "unsigned", "char", "*", "next_protos_parse", "(", "size_t", "*", "outlen", ",", "const", "char", "*", "in", ")", "{", "size_t", "len", ";", "unsigned", "char", "*", "out", ";", "size_t", "i", ",", "start", "=", "0", ";", "size_t", "skipped", "=", "0", ";", "len", "=", "strlen", "(", "in", ")", ";", "if", "(", "len", "==", "0", "||", "len", ">=", "65535", ")", "return", "NULL", ";", "out", "=", "app_malloc", "(", "len", "+", "1", ",", "\"", "\"", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<=", "len", ";", "++", "i", ")", "{", "if", "(", "i", "==", "len", "||", "in", "[", "i", "]", "==", "'", "'", ")", "{", "if", "(", "i", "==", "start", ")", "{", "++", "start", ";", "++", "skipped", ";", "continue", ";", "}", "if", "(", "i", "-", "start", ">", "255", ")", "{", "OPENSSL_free", "(", "out", ")", ";", "return", "NULL", ";", "}", "out", "[", "start", "-", "skipped", "]", "=", "(", "unsigned", "char", ")", "(", "i", "-", "start", ")", ";", "start", "=", "i", "+", "1", ";", "}", "else", "{", "out", "[", "i", "+", "1", "-", "skipped", "]", "=", "in", "[", "i", "]", ";", "}", "}", "if", "(", "len", "<=", "skipped", ")", "{", "OPENSSL_free", "(", "out", ")", ";", "return", "NULL", ";", "}", "*", "outlen", "=", "len", "+", "1", "-", "skipped", ";", "return", "out", ";", "}" ]
next_protos_parse parses a comma separated list of strings into a string in a format suitable for passing to SSL_CTX_set_next_protos_advertised.
[ "next_protos_parse", "parses", "a", "comma", "separated", "list", "of", "strings", "into", "a", "string", "in", "a", "format", "suitable", "for", "passing", "to", "SSL_CTX_set_next_protos_advertised", "." ]
[ "/*\n * Zero-length ALPN elements are invalid on the wire, we could be\n * strict and reject the entire string, but just ignoring extra\n * commas seems harmless and more friendly.\n *\n * Every comma we skip in this way puts the input buffer another\n * byte ahead of the output buffer, so all stores into the output\n * buffer need to be decremented by the number commas skipped.\n */" ]
[ { "param": "outlen", "type": "size_t" }, { "param": "in", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "outlen", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "in", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
load_crl_crldp
X509_CRL
static X509_CRL *load_crl_crldp(STACK_OF(DIST_POINT) *crldp) { int i; const char *urlptr = NULL; for (i = 0; i < sk_DIST_POINT_num(crldp); i++) { DIST_POINT *dp = sk_DIST_POINT_value(crldp, i); urlptr = get_dp_url(dp); if (urlptr) return load_crl(urlptr, FORMAT_HTTP, "CRL via CDP"); } return NULL; }
/* * Look through a CRLDP structure and attempt to find an http URL to * downloads a CRL from. */
Look through a CRLDP structure and attempt to find an http URL to downloads a CRL from.
[ "Look", "through", "a", "CRLDP", "structure", "and", "attempt", "to", "find", "an", "http", "URL", "to", "downloads", "a", "CRL", "from", "." ]
static X509_CRL *load_crl_crldp(STACK_OF(DIST_POINT) *crldp) { int i; const char *urlptr = NULL; for (i = 0; i < sk_DIST_POINT_num(crldp); i++) { DIST_POINT *dp = sk_DIST_POINT_value(crldp, i); urlptr = get_dp_url(dp); if (urlptr) return load_crl(urlptr, FORMAT_HTTP, "CRL via CDP"); } return NULL; }
[ "static", "X509_CRL", "*", "load_crl_crldp", "(", "STACK_OF", "(", "DIST_POINT", ")", "*", "crldp", ")", "{", "int", "i", ";", "const", "char", "*", "urlptr", "=", "NULL", ";", "for", "(", "i", "=", "0", ";", "i", "<", "sk_DIST_POINT_num", "(", "crldp", ")", ";", "i", "++", ")", "{", "DIST_POINT", "*", "dp", "=", "sk_DIST_POINT_value", "(", "crldp", ",", "i", ")", ";", "urlptr", "=", "get_dp_url", "(", "dp", ")", ";", "if", "(", "urlptr", ")", "return", "load_crl", "(", "urlptr", ",", "FORMAT_HTTP", ",", "\"", "\"", ")", ";", "}", "return", "NULL", ";", "}" ]
Look through a CRLDP structure and attempt to find an http URL to downloads a CRL from.
[ "Look", "through", "a", "CRLDP", "structure", "and", "attempt", "to", "find", "an", "http", "URL", "to", "downloads", "a", "CRL", "from", "." ]
[]
[ { "param": "STACK_OF", "type": "STACK_OF(DIST_POINT)" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "STACK_OF", "type": "STACK_OF(DIST_POINT)", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
crls_http_cb
null
static STACK_OF(X509_CRL) *crls_http_cb(const X509_STORE_CTX *ctx, const X509_NAME *nm) { X509 *x; STACK_OF(X509_CRL) *crls = NULL; X509_CRL *crl; STACK_OF(DIST_POINT) *crldp; crls = sk_X509_CRL_new_null(); if (!crls) return NULL; x = X509_STORE_CTX_get_current_cert(ctx); crldp = X509_get_ext_d2i(x, NID_crl_distribution_points, NULL, NULL); crl = load_crl_crldp(crldp); sk_DIST_POINT_pop_free(crldp, DIST_POINT_free); if (!crl) { sk_X509_CRL_free(crls); return NULL; } sk_X509_CRL_push(crls, crl); /* Try to download delta CRL */ crldp = X509_get_ext_d2i(x, NID_freshest_crl, NULL, NULL); crl = load_crl_crldp(crldp); sk_DIST_POINT_pop_free(crldp, DIST_POINT_free); if (crl) sk_X509_CRL_push(crls, crl); return crls; }
/* * Example of downloading CRLs from CRLDP: * not usable for real world as it always downloads and doesn't cache anything. */
Example of downloading CRLs from CRLDP: not usable for real world as it always downloads and doesn't cache anything.
[ "Example", "of", "downloading", "CRLs", "from", "CRLDP", ":", "not", "usable", "for", "real", "world", "as", "it", "always", "downloads", "and", "doesn", "'", "t", "cache", "anything", "." ]
static STACK_OF(X509_CRL) *crls_http_cb(const X509_STORE_CTX *ctx, const X509_NAME *nm) { X509 *x; STACK_OF(X509_CRL) *crls = NULL; X509_CRL *crl; STACK_OF(DIST_POINT) *crldp; crls = sk_X509_CRL_new_null(); if (!crls) return NULL; x = X509_STORE_CTX_get_current_cert(ctx); crldp = X509_get_ext_d2i(x, NID_crl_distribution_points, NULL, NULL); crl = load_crl_crldp(crldp); sk_DIST_POINT_pop_free(crldp, DIST_POINT_free); if (!crl) { sk_X509_CRL_free(crls); return NULL; } sk_X509_CRL_push(crls, crl); crldp = X509_get_ext_d2i(x, NID_freshest_crl, NULL, NULL); crl = load_crl_crldp(crldp); sk_DIST_POINT_pop_free(crldp, DIST_POINT_free); if (crl) sk_X509_CRL_push(crls, crl); return crls; }
[ "static", "STACK_OF", "(", "X509_CRL", ")", "*", "crls_http_cb", "(", "const", "X509_STORE_CTX", "*", "ctx", ",", "const", "X509_NAME", "*", "nm", ")", "{", "X509", "*", "x", ";", "STACK_OF", "(", "X509_CRL", ")", "*", "crls", "=", "NULL", ";", "X509_CRL", "*", "crl", ";", "STACK_OF", "(", "DIST_POINT", ")", "*", "crldp", ";", "crls", "=", "sk_X509_CRL_new_null", "(", ")", ";", "if", "(", "!", "crls", ")", "return", "NULL", ";", "x", "=", "X509_STORE_CTX_get_current_cert", "(", "ctx", ")", ";", "crldp", "=", "X509_get_ext_d2i", "(", "x", ",", "NID_crl_distribution_points", ",", "NULL", ",", "NULL", ")", ";", "crl", "=", "load_crl_crldp", "(", "crldp", ")", ";", "sk_DIST_POINT_pop_free", "(", "crldp", ",", "DIST_POINT_free", ")", ";", "if", "(", "!", "crl", ")", "{", "sk_X509_CRL_free", "(", "crls", ")", ";", "return", "NULL", ";", "}", "sk_X509_CRL_push", "(", "crls", ",", "crl", ")", ";", "crldp", "=", "X509_get_ext_d2i", "(", "x", ",", "NID_freshest_crl", ",", "NULL", ",", "NULL", ")", ";", "crl", "=", "load_crl_crldp", "(", "crldp", ")", ";", "sk_DIST_POINT_pop_free", "(", "crldp", ",", "DIST_POINT_free", ")", ";", "if", "(", "crl", ")", "sk_X509_CRL_push", "(", "crls", ",", "crl", ")", ";", "return", "crls", ";", "}" ]
Example of downloading CRLs from CRLDP: not usable for real world as it always downloads and doesn't cache anything.
[ "Example", "of", "downloading", "CRLs", "from", "CRLDP", ":", "not", "usable", "for", "real", "world", "as", "it", "always", "downloads", "and", "doesn", "'", "t", "cache", "anything", "." ]
[ "/* Try to download delta CRL */" ]
[ { "param": "ctx", "type": "X509_STORE_CTX" }, { "param": "nm", "type": "X509_NAME" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "X509_STORE_CTX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nm", "type": "X509_NAME", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
app_http_tls_cb
BIO
BIO *app_http_tls_cb(BIO *hbio, void *arg, int connect, int detail) { APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg; SSL_CTX *ssl_ctx = info->ssl_ctx; SSL *ssl; BIO *sbio = NULL; if (connect && detail) { /* connecting with TLS */ if ((info->use_proxy && !OSSL_HTTP_proxy_connect(hbio, info->server, info->port, NULL, NULL, /* no proxy credentials */ info->timeout, bio_err, opt_getprog())) || (sbio = BIO_new(BIO_f_ssl())) == NULL) { return NULL; } if (ssl_ctx == NULL || (ssl = SSL_new(ssl_ctx)) == NULL) { BIO_free(sbio); return NULL; } SSL_set_tlsext_host_name(ssl, info->server); SSL_set_connect_state(ssl); BIO_set_ssl(sbio, ssl, BIO_CLOSE); hbio = BIO_push(sbio, hbio); } else if (!connect && !detail) { /* disconnecting after error */ const char *hint = tls_error_hint(); if (hint != NULL) ERR_add_error_data(2, " : ", hint); /* * If we pop sbio and BIO_free() it this may lead to libssl double free. * Rely on BIO_free_all() done by OSSL_HTTP_transfer() in http_client.c */ } return hbio; }
/* HTTP callback function that supports TLS connection also via HTTPS proxy */
HTTP callback function that supports TLS connection also via HTTPS proxy
[ "HTTP", "callback", "function", "that", "supports", "TLS", "connection", "also", "via", "HTTPS", "proxy" ]
BIO *app_http_tls_cb(BIO *hbio, void *arg, int connect, int detail) { APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg; SSL_CTX *ssl_ctx = info->ssl_ctx; SSL *ssl; BIO *sbio = NULL; if (connect && detail) { if ((info->use_proxy && !OSSL_HTTP_proxy_connect(hbio, info->server, info->port, NULL, NULL, info->timeout, bio_err, opt_getprog())) || (sbio = BIO_new(BIO_f_ssl())) == NULL) { return NULL; } if (ssl_ctx == NULL || (ssl = SSL_new(ssl_ctx)) == NULL) { BIO_free(sbio); return NULL; } SSL_set_tlsext_host_name(ssl, info->server); SSL_set_connect_state(ssl); BIO_set_ssl(sbio, ssl, BIO_CLOSE); hbio = BIO_push(sbio, hbio); } else if (!connect && !detail) { const char *hint = tls_error_hint(); if (hint != NULL) ERR_add_error_data(2, " : ", hint); } return hbio; }
[ "BIO", "*", "app_http_tls_cb", "(", "BIO", "*", "hbio", ",", "void", "*", "arg", ",", "int", "connect", ",", "int", "detail", ")", "{", "APP_HTTP_TLS_INFO", "*", "info", "=", "(", "APP_HTTP_TLS_INFO", "*", ")", "arg", ";", "SSL_CTX", "*", "ssl_ctx", "=", "info", "->", "ssl_ctx", ";", "SSL", "*", "ssl", ";", "BIO", "*", "sbio", "=", "NULL", ";", "if", "(", "connect", "&&", "detail", ")", "{", "if", "(", "(", "info", "->", "use_proxy", "&&", "!", "OSSL_HTTP_proxy_connect", "(", "hbio", ",", "info", "->", "server", ",", "info", "->", "port", ",", "NULL", ",", "NULL", ",", "info", "->", "timeout", ",", "bio_err", ",", "opt_getprog", "(", ")", ")", ")", "||", "(", "sbio", "=", "BIO_new", "(", "BIO_f_ssl", "(", ")", ")", ")", "==", "NULL", ")", "{", "return", "NULL", ";", "}", "if", "(", "ssl_ctx", "==", "NULL", "||", "(", "ssl", "=", "SSL_new", "(", "ssl_ctx", ")", ")", "==", "NULL", ")", "{", "BIO_free", "(", "sbio", ")", ";", "return", "NULL", ";", "}", "SSL_set_tlsext_host_name", "(", "ssl", ",", "info", "->", "server", ")", ";", "SSL_set_connect_state", "(", "ssl", ")", ";", "BIO_set_ssl", "(", "sbio", ",", "ssl", ",", "BIO_CLOSE", ")", ";", "hbio", "=", "BIO_push", "(", "sbio", ",", "hbio", ")", ";", "}", "else", "if", "(", "!", "connect", "&&", "!", "detail", ")", "{", "const", "char", "*", "hint", "=", "tls_error_hint", "(", ")", ";", "if", "(", "hint", "!=", "NULL", ")", "ERR_add_error_data", "(", "2", ",", "\"", "\"", ",", "hint", ")", ";", "}", "return", "hbio", ";", "}" ]
HTTP callback function that supports TLS connection also via HTTPS proxy
[ "HTTP", "callback", "function", "that", "supports", "TLS", "connection", "also", "via", "HTTPS", "proxy" ]
[ "/* connecting with TLS */", "/* no proxy credentials */", "/* disconnecting after error */", "/*\n * If we pop sbio and BIO_free() it this may lead to libssl double free.\n * Rely on BIO_free_all() done by OSSL_HTTP_transfer() in http_client.c\n */" ]
[ { "param": "hbio", "type": "BIO" }, { "param": "arg", "type": "void" }, { "param": "connect", "type": "int" }, { "param": "detail", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "hbio", "type": "BIO", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "connect", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "detail", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
087ef4ec84427d9d215861c17b255211fd9d42b4
cy15196/openssl
apps/lib/apps.c
[ "Apache-2.0" ]
C
dup_bio_in
BIO
BIO *dup_bio_in(int format) { return BIO_new_fp(stdin, BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0)); }
/* * Centralized handling of input and output files with format specification * The format is meant to show what the input and output is supposed to be, * and is therefore a show of intent more than anything else. However, it * does impact behavior on some platforms, such as differentiating between * text and binary input/output on non-Unix platforms */
Centralized handling of input and output files with format specification The format is meant to show what the input and output is supposed to be, and is therefore a show of intent more than anything else. However, it does impact behavior on some platforms, such as differentiating between text and binary input/output on non-Unix platforms
[ "Centralized", "handling", "of", "input", "and", "output", "files", "with", "format", "specification", "The", "format", "is", "meant", "to", "show", "what", "the", "input", "and", "output", "is", "supposed", "to", "be", "and", "is", "therefore", "a", "show", "of", "intent", "more", "than", "anything", "else", ".", "However", "it", "does", "impact", "behavior", "on", "some", "platforms", "such", "as", "differentiating", "between", "text", "and", "binary", "input", "/", "output", "on", "non", "-", "Unix", "platforms" ]
BIO *dup_bio_in(int format) { return BIO_new_fp(stdin, BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0)); }
[ "BIO", "*", "dup_bio_in", "(", "int", "format", ")", "{", "return", "BIO_new_fp", "(", "stdin", ",", "BIO_NOCLOSE", "|", "(", "FMT_istext", "(", "format", ")", "?", "BIO_FP_TEXT", ":", "0", ")", ")", ";", "}" ]
Centralized handling of input and output files with format specification The format is meant to show what the input and output is supposed to be, and is therefore a show of intent more than anything else.
[ "Centralized", "handling", "of", "input", "and", "output", "files", "with", "format", "specification", "The", "format", "is", "meant", "to", "show", "what", "the", "input", "and", "output", "is", "supposed", "to", "be", "and", "is", "therefore", "a", "show", "of", "intent", "more", "than", "anything", "else", "." ]
[]
[ { "param": "format", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "format", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
83e2138263560f7276e2351cba8a904ee674f1f0
giacomini/esc15
hands-on/MPI/Solutions/ring.c
[ "CC-BY-4.0" ]
C
out_results
void
void out_results( double min_time, /* minimum time for ring test */ double max_time, /* maximum time for ring test */ int num_nodes, /* number of nodes in the ring */ int size, /* size of the message passed around the ring */ int num_shifts) /* number of times the message is shifted */ { double bandwidth; /* bandwidth */ #ifdef DEBUG printf("\nRING: %d nodes, length = %d,",num_nodes,size); printf(" %d shifts:",num_shifts); #endif printf("\n Times: %f to %f secs, ",min_time,max_time); bandwidth = (double)(num_shifts * num_nodes * size *sizeof(double)); bandwidth = MB_CONV * bandwidth / max_time; printf(" Bandwidth = %5.4f megabytes/sec \n",bandwidth); }
/******************************************************************* NAME: out_results PURPOSE: This simple C-functions takes the input from the ring test programs, and outputs the desired results. *******************************************************************/
This simple C-functions takes the input from the ring test programs, and outputs the desired results.
[ "This", "simple", "C", "-", "functions", "takes", "the", "input", "from", "the", "ring", "test", "programs", "and", "outputs", "the", "desired", "results", "." ]
void out_results( double min_time, double max_time, int num_nodes, int size, int num_shifts) { double bandwidth; #ifdef DEBUG printf("\nRING: %d nodes, length = %d,",num_nodes,size); printf(" %d shifts:",num_shifts); #endif printf("\n Times: %f to %f secs, ",min_time,max_time); bandwidth = (double)(num_shifts * num_nodes * size *sizeof(double)); bandwidth = MB_CONV * bandwidth / max_time; printf(" Bandwidth = %5.4f megabytes/sec \n",bandwidth); }
[ "void", "out_results", "(", "double", "min_time", ",", "double", "max_time", ",", "int", "num_nodes", ",", "int", "size", ",", "int", "num_shifts", ")", "{", "double", "bandwidth", ";", "#ifdef", "DEBUG", "printf", "(", "\"", "\\n", "\"", ",", "num_nodes", ",", "size", ")", ";", "printf", "(", "\"", "\"", ",", "num_shifts", ")", ";", "#endif", "printf", "(", "\"", "\\n", "\"", ",", "min_time", ",", "max_time", ")", ";", "bandwidth", "=", "(", "double", ")", "(", "num_shifts", "*", "num_nodes", "*", "size", "*", "sizeof", "(", "double", ")", ")", ";", "bandwidth", "=", "MB_CONV", "*", "bandwidth", "/", "max_time", ";", "printf", "(", "\"", "\\n", "\"", ",", "bandwidth", ")", ";", "}" ]
NAME: out_results
[ "NAME", ":", "out_results" ]
[ "/* minimum time for ring test */", "/* maximum time for ring test */", "/* number of nodes in the ring */", "/* size of the message passed around the ring */", "/* number of times the message is shifted */", "/* bandwidth */" ]
[ { "param": "min_time", "type": "double" }, { "param": "max_time", "type": "double" }, { "param": "num_nodes", "type": "int" }, { "param": "size", "type": "int" }, { "param": "num_shifts", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "min_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "max_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "num_nodes", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "num_shifts", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1bc413bfd736eb82a11f9d952613f3ef120b302e
giacomini/esc15
hands-on/MPI/trans_utility.c
[ "CC-BY-4.0" ]
C
fill_mat
void
void fill_mat(int my_ID, int Global_order, int Block_order, double *buff) { int i, j; double col_val; for (j=0;j<Block_order;j++) { col_val = col_shift * (my_ID*Block_order + j); for (i=0;i<Global_order; i++) { *(buff+i*Block_order+j) = col_val + row_shift * i; } } #ifdef DEBUG printf(" Output original column block on node %d\n",my_ID); outmat(buff,Global_order,Block_order); fflush(stdout); #endif }
/********************************************************************* ** fill_mat ** ** Call on each node to fill the original column matrix in buff. ** ** Note: this function is tightly linked to the test_results() ** function. ** *********************************************************************/
fill_mat Call on each node to fill the original column matrix in buff. this function is tightly linked to the test_results() function.
[ "fill_mat", "Call", "on", "each", "node", "to", "fill", "the", "original", "column", "matrix", "in", "buff", ".", "this", "function", "is", "tightly", "linked", "to", "the", "test_results", "()", "function", "." ]
void fill_mat(int my_ID, int Global_order, int Block_order, double *buff) { int i, j; double col_val; for (j=0;j<Block_order;j++) { col_val = col_shift * (my_ID*Block_order + j); for (i=0;i<Global_order; i++) { *(buff+i*Block_order+j) = col_val + row_shift * i; } } #ifdef DEBUG printf(" Output original column block on node %d\n",my_ID); outmat(buff,Global_order,Block_order); fflush(stdout); #endif }
[ "void", "fill_mat", "(", "int", "my_ID", ",", "int", "Global_order", ",", "int", "Block_order", ",", "double", "*", "buff", ")", "{", "int", "i", ",", "j", ";", "double", "col_val", ";", "for", "(", "j", "=", "0", ";", "j", "<", "Block_order", ";", "j", "++", ")", "{", "col_val", "=", "col_shift", "*", "(", "my_ID", "*", "Block_order", "+", "j", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "Global_order", ";", "i", "++", ")", "{", "*", "(", "buff", "+", "i", "*", "Block_order", "+", "j", ")", "=", "col_val", "+", "row_shift", "*", "i", ";", "}", "}", "#ifdef", "DEBUG", "printf", "(", "\"", "\\n", "\"", ",", "my_ID", ")", ";", "outmat", "(", "buff", ",", "Global_order", ",", "Block_order", ")", ";", "fflush", "(", "stdout", ")", ";", "#endif", "}" ]
fill_mat Call on each node to fill the original column matrix in buff.
[ "fill_mat", "Call", "on", "each", "node", "to", "fill", "the", "original", "column", "matrix", "in", "buff", "." ]
[]
[ { "param": "my_ID", "type": "int" }, { "param": "Global_order", "type": "int" }, { "param": "Block_order", "type": "int" }, { "param": "buff", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "my_ID", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Global_order", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Block_order", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buff", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1bc413bfd736eb82a11f9d952613f3ef120b302e
giacomini/esc15
hands-on/MPI/trans_utility.c
[ "CC-BY-4.0" ]
C
fill_garbage
void
void fill_garbage(int my_ID, int Global_order, int Block_order, double *trans) { int i, j; for (j=0;j<Block_order;j++) { for (i=0;i<Global_order; i++) { *(trans+i*Block_order+j) = -1.0; } } }
/********************************************************************* ** fill_garbage ** ** Call on each node to fill the column matrix with garbage. ** In this case, we define garbage as "-1". *********************************************************************/
fill_garbage Call on each node to fill the column matrix with garbage. In this case, we define garbage as "-1".
[ "fill_garbage", "Call", "on", "each", "node", "to", "fill", "the", "column", "matrix", "with", "garbage", ".", "In", "this", "case", "we", "define", "garbage", "as", "\"", "-", "1", "\"", "." ]
void fill_garbage(int my_ID, int Global_order, int Block_order, double *trans) { int i, j; for (j=0;j<Block_order;j++) { for (i=0;i<Global_order; i++) { *(trans+i*Block_order+j) = -1.0; } } }
[ "void", "fill_garbage", "(", "int", "my_ID", ",", "int", "Global_order", ",", "int", "Block_order", ",", "double", "*", "trans", ")", "{", "int", "i", ",", "j", ";", "for", "(", "j", "=", "0", ";", "j", "<", "Block_order", ";", "j", "++", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "Global_order", ";", "i", "++", ")", "{", "*", "(", "trans", "+", "i", "*", "Block_order", "+", "j", ")", "=", "-1.0", ";", "}", "}", "}" ]
fill_garbage Call on each node to fill the column matrix with garbage.
[ "fill_garbage", "Call", "on", "each", "node", "to", "fill", "the", "column", "matrix", "with", "garbage", "." ]
[]
[ { "param": "my_ID", "type": "int" }, { "param": "Global_order", "type": "int" }, { "param": "Block_order", "type": "int" }, { "param": "trans", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "my_ID", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Global_order", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Block_order", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "trans", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1bc413bfd736eb82a11f9d952613f3ef120b302e
giacomini/esc15
hands-on/MPI/trans_utility.c
[ "CC-BY-4.0" ]
C
analyze_results
void
void analyze_results (int my_ID, double trans_time, int iters, double *min_time, double *max_time, double *min_max_time, int *min_iter, int *max_iter, int *min_max_iter) { double new_min_time; double new_max_time; MPI_Barrier(MPI_COMM_WORLD); MPI_Reduce(&trans_time, &new_min_time, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&trans_time, &new_max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if(my_ID == 0){ #ifdef DEBUG printf("\n on %d, min & max times %f %f \n", my_ID,new_min_time, new_max_time); #endif if( new_min_time < *min_time) { *min_time = new_min_time; *min_iter = iters; } if( new_max_time > *max_time) { *max_time = new_max_time; *max_iter = iters; } if( new_max_time < *min_max_time ) { *min_max_time = new_max_time; *min_max_iter = iters; } } }
/********************************************************************* ** Analyze Results ** ** Call on every node. Output values only relevant on node of ** rank 0 ** ** This function will collect min and max time statistics for all ** processes in MPI_COMM_WORLD. Make sure on the my_ID == 0 process, ** that max_time has been set to a small number and the two min times ** have been set to large numbers to start the process off. *********************************************************************/
Analyze Results Call on every node. Output values only relevant on node of rank 0 This function will collect min and max time statistics for all processes in MPI_COMM_WORLD. Make sure on the my_ID == 0 process, that max_time has been set to a small number and the two min times have been set to large numbers to start the process off.
[ "Analyze", "Results", "Call", "on", "every", "node", ".", "Output", "values", "only", "relevant", "on", "node", "of", "rank", "0", "This", "function", "will", "collect", "min", "and", "max", "time", "statistics", "for", "all", "processes", "in", "MPI_COMM_WORLD", ".", "Make", "sure", "on", "the", "my_ID", "==", "0", "process", "that", "max_time", "has", "been", "set", "to", "a", "small", "number", "and", "the", "two", "min", "times", "have", "been", "set", "to", "large", "numbers", "to", "start", "the", "process", "off", "." ]
void analyze_results (int my_ID, double trans_time, int iters, double *min_time, double *max_time, double *min_max_time, int *min_iter, int *max_iter, int *min_max_iter) { double new_min_time; double new_max_time; MPI_Barrier(MPI_COMM_WORLD); MPI_Reduce(&trans_time, &new_min_time, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&trans_time, &new_max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if(my_ID == 0){ #ifdef DEBUG printf("\n on %d, min & max times %f %f \n", my_ID,new_min_time, new_max_time); #endif if( new_min_time < *min_time) { *min_time = new_min_time; *min_iter = iters; } if( new_max_time > *max_time) { *max_time = new_max_time; *max_iter = iters; } if( new_max_time < *min_max_time ) { *min_max_time = new_max_time; *min_max_iter = iters; } } }
[ "void", "analyze_results", "(", "int", "my_ID", ",", "double", "trans_time", ",", "int", "iters", ",", "double", "*", "min_time", ",", "double", "*", "max_time", ",", "double", "*", "min_max_time", ",", "int", "*", "min_iter", ",", "int", "*", "max_iter", ",", "int", "*", "min_max_iter", ")", "{", "double", "new_min_time", ";", "double", "new_max_time", ";", "MPI_Barrier", "(", "MPI_COMM_WORLD", ")", ";", "MPI_Reduce", "(", "&", "trans_time", ",", "&", "new_min_time", ",", "1", ",", "MPI_DOUBLE", ",", "MPI_MIN", ",", "0", ",", "MPI_COMM_WORLD", ")", ";", "MPI_Reduce", "(", "&", "trans_time", ",", "&", "new_max_time", ",", "1", ",", "MPI_DOUBLE", ",", "MPI_MAX", ",", "0", ",", "MPI_COMM_WORLD", ")", ";", "if", "(", "my_ID", "==", "0", ")", "{", "#ifdef", "DEBUG", "printf", "(", "\"", "\\n", "\\n", "\"", ",", "my_ID", ",", "new_min_time", ",", "new_max_time", ")", ";", "#endif", "if", "(", "new_min_time", "<", "*", "min_time", ")", "{", "*", "min_time", "=", "new_min_time", ";", "*", "min_iter", "=", "iters", ";", "}", "if", "(", "new_max_time", ">", "*", "max_time", ")", "{", "*", "max_time", "=", "new_max_time", ";", "*", "max_iter", "=", "iters", ";", "}", "if", "(", "new_max_time", "<", "*", "min_max_time", ")", "{", "*", "min_max_time", "=", "new_max_time", ";", "*", "min_max_iter", "=", "iters", ";", "}", "}", "}" ]
Analyze Results Call on every node.
[ "Analyze", "Results", "Call", "on", "every", "node", "." ]
[]
[ { "param": "my_ID", "type": "int" }, { "param": "trans_time", "type": "double" }, { "param": "iters", "type": "int" }, { "param": "min_time", "type": "double" }, { "param": "max_time", "type": "double" }, { "param": "min_max_time", "type": "double" }, { "param": "min_iter", "type": "int" }, { "param": "max_iter", "type": "int" }, { "param": "min_max_iter", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "my_ID", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "trans_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "iters", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "max_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_max_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_iter", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "max_iter", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_max_iter", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1bc413bfd736eb82a11f9d952613f3ef120b302e
giacomini/esc15
hands-on/MPI/trans_utility.c
[ "CC-BY-4.0" ]
C
output_timings
void
void output_timings (char *lable, int Num_procs, int Block_order, double min_time, double max_time, double min_max_time, int min_iter, int max_iter, int min_max_iter) { double Mbytes_trans; /* Total Megabytes transfered */ int block_size; block_size = Block_order * Block_order; Mbytes_trans = block_size * Num_procs * (Num_procs-1)*sizeof(double); Mbytes_trans = Mbytes_trans/(1000000.0); printf("\n min_time(%3d) = %f; max_time(%3d) = %f \n", min_iter, min_time, max_iter,max_time); if(( min_time > 0) && (max_time > 0.0)){ printf("Bandwidths (MB/sec) from %f to %f\n", Mbytes_trans/max_time, Mbytes_trans/min_time); } if (min_max_time > 0.0){ printf(" %s: order %d matrix. %f Mbytes at %f Mbytes/sec \n", lable, Block_order * Num_procs, Mbytes_trans, Mbytes_trans/min_max_time); } }
/********************************************************************* ** output_timings ** ** Call on the node of rank 0 (my_ID == 0) to compute bandwidths ** and output resutls to stdout. ** ** Note: to be consistent with ring test and output what is the most ** defensible single bandwidth number, the bandwidth to publish is ** the one computed from the shortest maximum communication time. *********************************************************************/
output_timings Call on the node of rank 0 (my_ID == 0) to compute bandwidths and output resutls to stdout. to be consistent with ring test and output what is the most defensible single bandwidth number, the bandwidth to publish is the one computed from the shortest maximum communication time.
[ "output_timings", "Call", "on", "the", "node", "of", "rank", "0", "(", "my_ID", "==", "0", ")", "to", "compute", "bandwidths", "and", "output", "resutls", "to", "stdout", ".", "to", "be", "consistent", "with", "ring", "test", "and", "output", "what", "is", "the", "most", "defensible", "single", "bandwidth", "number", "the", "bandwidth", "to", "publish", "is", "the", "one", "computed", "from", "the", "shortest", "maximum", "communication", "time", "." ]
void output_timings (char *lable, int Num_procs, int Block_order, double min_time, double max_time, double min_max_time, int min_iter, int max_iter, int min_max_iter) { double Mbytes_trans; int block_size; block_size = Block_order * Block_order; Mbytes_trans = block_size * Num_procs * (Num_procs-1)*sizeof(double); Mbytes_trans = Mbytes_trans/(1000000.0); printf("\n min_time(%3d) = %f; max_time(%3d) = %f \n", min_iter, min_time, max_iter,max_time); if(( min_time > 0) && (max_time > 0.0)){ printf("Bandwidths (MB/sec) from %f to %f\n", Mbytes_trans/max_time, Mbytes_trans/min_time); } if (min_max_time > 0.0){ printf(" %s: order %d matrix. %f Mbytes at %f Mbytes/sec \n", lable, Block_order * Num_procs, Mbytes_trans, Mbytes_trans/min_max_time); } }
[ "void", "output_timings", "(", "char", "*", "lable", ",", "int", "Num_procs", ",", "int", "Block_order", ",", "double", "min_time", ",", "double", "max_time", ",", "double", "min_max_time", ",", "int", "min_iter", ",", "int", "max_iter", ",", "int", "min_max_iter", ")", "{", "double", "Mbytes_trans", ";", "int", "block_size", ";", "block_size", "=", "Block_order", "*", "Block_order", ";", "Mbytes_trans", "=", "block_size", "*", "Num_procs", "*", "(", "Num_procs", "-", "1", ")", "*", "sizeof", "(", "double", ")", ";", "Mbytes_trans", "=", "Mbytes_trans", "/", "(", "1000000.0", ")", ";", "printf", "(", "\"", "\\n", "\\n", "\"", ",", "min_iter", ",", "min_time", ",", "max_iter", ",", "max_time", ")", ";", "if", "(", "(", "min_time", ">", "0", ")", "&&", "(", "max_time", ">", "0.0", ")", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "Mbytes_trans", "/", "max_time", ",", "Mbytes_trans", "/", "min_time", ")", ";", "}", "if", "(", "min_max_time", ">", "0.0", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "lable", ",", "Block_order", "*", "Num_procs", ",", "Mbytes_trans", ",", "Mbytes_trans", "/", "min_max_time", ")", ";", "}", "}" ]
output_timings Call on the node of rank 0 (my_ID == 0) to compute bandwidths and output resutls to stdout.
[ "output_timings", "Call", "on", "the", "node", "of", "rank", "0", "(", "my_ID", "==", "0", ")", "to", "compute", "bandwidths", "and", "output", "resutls", "to", "stdout", "." ]
[ "/* Total Megabytes transfered */" ]
[ { "param": "lable", "type": "char" }, { "param": "Num_procs", "type": "int" }, { "param": "Block_order", "type": "int" }, { "param": "min_time", "type": "double" }, { "param": "max_time", "type": "double" }, { "param": "min_max_time", "type": "double" }, { "param": "min_iter", "type": "int" }, { "param": "max_iter", "type": "int" }, { "param": "min_max_iter", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "lable", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Num_procs", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Block_order", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "max_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_max_time", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_iter", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "max_iter", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "min_max_iter", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1bc413bfd736eb82a11f9d952613f3ef120b302e
giacomini/esc15
hands-on/MPI/trans_utility.c
[ "CC-BY-4.0" ]
C
outmat
void
void outmat( double* buff, /* The base address of the matrix to output */ int Nrows, /* The number of rows in the matrix */ int Ncols) /* The number of columns in the matirx */ { int i,j; for (i=0;i<Nrows;i++){ for(j=0;j<Ncols;j++){ printf(" %10f ",*(buff+i*Ncols+j)); } printf("\n"); } }
/******************************************************************* ** outmat: output an array. Formatting is simple so use this only ** tiny matrices. *********************************************************************/
output an array. Formatting is simple so use this only tiny matrices.
[ "output", "an", "array", ".", "Formatting", "is", "simple", "so", "use", "this", "only", "tiny", "matrices", "." ]
void outmat( double* buff, int Nrows, int Ncols) { int i,j; for (i=0;i<Nrows;i++){ for(j=0;j<Ncols;j++){ printf(" %10f ",*(buff+i*Ncols+j)); } printf("\n"); } }
[ "void", "outmat", "(", "double", "*", "buff", ",", "int", "Nrows", ",", "int", "Ncols", ")", "{", "int", "i", ",", "j", ";", "for", "(", "i", "=", "0", ";", "i", "<", "Nrows", ";", "i", "++", ")", "{", "for", "(", "j", "=", "0", ";", "j", "<", "Ncols", ";", "j", "++", ")", "{", "printf", "(", "\"", "\"", ",", "*", "(", "buff", "+", "i", "*", "Ncols", "+", "j", ")", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "}" ]
outmat: output an array.
[ "outmat", ":", "output", "an", "array", "." ]
[ "/* The base address of the matrix to output */", "/* The number of rows in the matrix */", "/* The number of columns in the matirx */" ]
[ { "param": "buff", "type": "double" }, { "param": "Nrows", "type": "int" }, { "param": "Ncols", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buff", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Nrows", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Ncols", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1bc413bfd736eb82a11f9d952613f3ef120b302e
giacomini/esc15
hands-on/MPI/trans_utility.c
[ "CC-BY-4.0" ]
C
transpose
void
void transpose( double* A, int Acols, /* input matrix */ double* B, int Bcols, /* transposed mat */ int sub_rows, int sub_cols) /* size of slice to transpose */ { int i,j,jinc; double *Abase; double *Bbase; /* Transpose the matrix. */ Abase = A; Bbase = B; for (i=0;i<sub_cols; i++) { jinc = 0; for (j=0;j<sub_rows;j++) { *(Bbase+jinc) = *(Abase+j); jinc += Bcols; } Abase += Acols; Bbase += 1; } }
/******************************************************************* ** Copy the transpose of an array slice inside matrix A into ** the an array slide inside matrix B. ** ** Parameters: ** ** A, B base address of the slices ** Acols Numb or cols in full A matrix ** Bcols Numb or cols in full B matrix ** sub_rows, sub_cols Numb of rows/cols in the slice. ** *******************************************************************/
Copy the transpose of an array slice inside matrix A into the an array slide inside matrix B. A, B base address of the slices Acols Numb or cols in full A matrix Bcols Numb or cols in full B matrix sub_rows, sub_cols Numb of rows/cols in the slice.
[ "Copy", "the", "transpose", "of", "an", "array", "slice", "inside", "matrix", "A", "into", "the", "an", "array", "slide", "inside", "matrix", "B", ".", "A", "B", "base", "address", "of", "the", "slices", "Acols", "Numb", "or", "cols", "in", "full", "A", "matrix", "Bcols", "Numb", "or", "cols", "in", "full", "B", "matrix", "sub_rows", "sub_cols", "Numb", "of", "rows", "/", "cols", "in", "the", "slice", "." ]
void transpose( double* A, int Acols, double* B, int Bcols, int sub_rows, int sub_cols) { int i,j,jinc; double *Abase; double *Bbase; Abase = A; Bbase = B; for (i=0;i<sub_cols; i++) { jinc = 0; for (j=0;j<sub_rows;j++) { *(Bbase+jinc) = *(Abase+j); jinc += Bcols; } Abase += Acols; Bbase += 1; } }
[ "void", "transpose", "(", "double", "*", "A", ",", "int", "Acols", ",", "double", "*", "B", ",", "int", "Bcols", ",", "int", "sub_rows", ",", "int", "sub_cols", ")", "{", "int", "i", ",", "j", ",", "jinc", ";", "double", "*", "Abase", ";", "double", "*", "Bbase", ";", "Abase", "=", "A", ";", "Bbase", "=", "B", ";", "for", "(", "i", "=", "0", ";", "i", "<", "sub_cols", ";", "i", "++", ")", "{", "jinc", "=", "0", ";", "for", "(", "j", "=", "0", ";", "j", "<", "sub_rows", ";", "j", "++", ")", "{", "*", "(", "Bbase", "+", "jinc", ")", "=", "*", "(", "Abase", "+", "j", ")", ";", "jinc", "+=", "Bcols", ";", "}", "Abase", "+=", "Acols", ";", "Bbase", "+=", "1", ";", "}", "}" ]
Copy the transpose of an array slice inside matrix A into the an array slide inside matrix B.
[ "Copy", "the", "transpose", "of", "an", "array", "slice", "inside", "matrix", "A", "into", "the", "an", "array", "slide", "inside", "matrix", "B", "." ]
[ "/* input matrix */", "/* transposed mat */", "/* size of slice to transpose */", "/* Transpose the matrix. */" ]
[ { "param": "A", "type": "double" }, { "param": "Acols", "type": "int" }, { "param": "B", "type": "double" }, { "param": "Bcols", "type": "int" }, { "param": "sub_rows", "type": "int" }, { "param": "sub_cols", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "A", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Acols", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "B", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Bcols", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sub_rows", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sub_cols", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
39af1aba710f0faba4792b696a3472ff6a8380ee
JellyPixelGames/tracy
zstd/zstd_compress_superblock.c
[ "BSD-3-Clause" ]
C
ZSTD_buildSuperBlockEntropy_literal
size_t
static size_t ZSTD_buildSuperBlockEntropy_literal(void* const src, size_t srcSize, const ZSTD_hufCTables_t* prevHuf, ZSTD_hufCTables_t* nextHuf, ZSTD_hufCTablesMetadata_t* hufMetadata, void* workspace, size_t wkspSize) { BYTE* const wkspStart = (BYTE*)workspace; BYTE* const wkspEnd = wkspStart + wkspSize; BYTE* const countWkspStart = wkspStart; unsigned* const countWksp = (unsigned*)workspace; const size_t countWkspSize = (HUF_SYMBOLVALUE_MAX + 1) * sizeof(unsigned); BYTE* const nodeWksp = countWkspStart + countWkspSize; const size_t nodeWkspSize = wkspEnd-nodeWksp; unsigned maxSymbolValue = 255; unsigned huffLog = 11; DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy_literal (srcSize=%zu)", srcSize); /* Prepare nextEntropy assuming reusing the existing table */ memcpy(nextHuf, prevHuf, sizeof(*prevHuf)); /* small ? don't even attempt compression (speed opt) */ # define COMPRESS_LITERALS_SIZE_MIN 63 { size_t const minLitSize = COMPRESS_LITERALS_SIZE_MIN; if (srcSize <= minLitSize) { hufMetadata->hType = set_basic; return 0; } } /* Scan input and build symbol stats */ { size_t const largest = HIST_count_wksp (countWksp, &maxSymbolValue, (const BYTE*)src, srcSize, workspace, wkspSize); FORWARD_IF_ERROR(largest); if (largest == srcSize) { hufMetadata->hType = set_rle; return 0; } if (largest <= (srcSize >> 7)+4) { hufMetadata->hType = set_basic; return 0; } } /* Build Huffman Tree */ memset(nextHuf->CTable, 0, sizeof(nextHuf->CTable)); huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue); { size_t const maxBits = HUF_buildCTable_wksp((HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue, huffLog, nodeWksp, nodeWkspSize); FORWARD_IF_ERROR(maxBits); huffLog = (U32)maxBits; { size_t cSize = HUF_estimateCompressedSize( (HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue); size_t hSize = HUF_writeCTable( hufMetadata->hufDesBuffer, sizeof(hufMetadata->hufDesBuffer), (HUF_CElt*)nextHuf->CTable, maxSymbolValue, huffLog); if (cSize + hSize >= srcSize) { hufMetadata->hType = set_basic; return 0; } hufMetadata->hType = set_compressed; return hSize; } } }
/** ZSTD_buildSuperBlockEntropy_literal() : * Builds entropy for the super-block literals. * Stores literals block type (raw, rle, compressed) and * huffman description table to hufMetadata. * Currently, this does not consider the option of reusing huffman table from * previous super-block. I think it would be a good improvement to add that option. * @return : size of huffman description table or error code */
ZSTD_buildSuperBlockEntropy_literal() : Builds entropy for the super-block literals. Stores literals block type (raw, rle, compressed) and huffman description table to hufMetadata. Currently, this does not consider the option of reusing huffman table from previous super-block. I think it would be a good improvement to add that option. @return : size of huffman description table or error code
[ "ZSTD_buildSuperBlockEntropy_literal", "()", ":", "Builds", "entropy", "for", "the", "super", "-", "block", "literals", ".", "Stores", "literals", "block", "type", "(", "raw", "rle", "compressed", ")", "and", "huffman", "description", "table", "to", "hufMetadata", ".", "Currently", "this", "does", "not", "consider", "the", "option", "of", "reusing", "huffman", "table", "from", "previous", "super", "-", "block", ".", "I", "think", "it", "would", "be", "a", "good", "improvement", "to", "add", "that", "option", ".", "@return", ":", "size", "of", "huffman", "description", "table", "or", "error", "code" ]
static size_t ZSTD_buildSuperBlockEntropy_literal(void* const src, size_t srcSize, const ZSTD_hufCTables_t* prevHuf, ZSTD_hufCTables_t* nextHuf, ZSTD_hufCTablesMetadata_t* hufMetadata, void* workspace, size_t wkspSize) { BYTE* const wkspStart = (BYTE*)workspace; BYTE* const wkspEnd = wkspStart + wkspSize; BYTE* const countWkspStart = wkspStart; unsigned* const countWksp = (unsigned*)workspace; const size_t countWkspSize = (HUF_SYMBOLVALUE_MAX + 1) * sizeof(unsigned); BYTE* const nodeWksp = countWkspStart + countWkspSize; const size_t nodeWkspSize = wkspEnd-nodeWksp; unsigned maxSymbolValue = 255; unsigned huffLog = 11; DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy_literal (srcSize=%zu)", srcSize); memcpy(nextHuf, prevHuf, sizeof(*prevHuf)); # define COMPRESS_LITERALS_SIZE_MIN 63 { size_t const minLitSize = COMPRESS_LITERALS_SIZE_MIN; if (srcSize <= minLitSize) { hufMetadata->hType = set_basic; return 0; } } { size_t const largest = HIST_count_wksp (countWksp, &maxSymbolValue, (const BYTE*)src, srcSize, workspace, wkspSize); FORWARD_IF_ERROR(largest); if (largest == srcSize) { hufMetadata->hType = set_rle; return 0; } if (largest <= (srcSize >> 7)+4) { hufMetadata->hType = set_basic; return 0; } } memset(nextHuf->CTable, 0, sizeof(nextHuf->CTable)); huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue); { size_t const maxBits = HUF_buildCTable_wksp((HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue, huffLog, nodeWksp, nodeWkspSize); FORWARD_IF_ERROR(maxBits); huffLog = (U32)maxBits; { size_t cSize = HUF_estimateCompressedSize( (HUF_CElt*)nextHuf->CTable, countWksp, maxSymbolValue); size_t hSize = HUF_writeCTable( hufMetadata->hufDesBuffer, sizeof(hufMetadata->hufDesBuffer), (HUF_CElt*)nextHuf->CTable, maxSymbolValue, huffLog); if (cSize + hSize >= srcSize) { hufMetadata->hType = set_basic; return 0; } hufMetadata->hType = set_compressed; return hSize; } } }
[ "static", "size_t", "ZSTD_buildSuperBlockEntropy_literal", "(", "void", "*", "const", "src", ",", "size_t", "srcSize", ",", "const", "ZSTD_hufCTables_t", "*", "prevHuf", ",", "ZSTD_hufCTables_t", "*", "nextHuf", ",", "ZSTD_hufCTablesMetadata_t", "*", "hufMetadata", ",", "void", "*", "workspace", ",", "size_t", "wkspSize", ")", "{", "BYTE", "*", "const", "wkspStart", "=", "(", "BYTE", "*", ")", "workspace", ";", "BYTE", "*", "const", "wkspEnd", "=", "wkspStart", "+", "wkspSize", ";", "BYTE", "*", "const", "countWkspStart", "=", "wkspStart", ";", "unsigned", "*", "const", "countWksp", "=", "(", "unsigned", "*", ")", "workspace", ";", "const", "size_t", "countWkspSize", "=", "(", "HUF_SYMBOLVALUE_MAX", "+", "1", ")", "*", "sizeof", "(", "unsigned", ")", ";", "BYTE", "*", "const", "nodeWksp", "=", "countWkspStart", "+", "countWkspSize", ";", "const", "size_t", "nodeWkspSize", "=", "wkspEnd", "-", "nodeWksp", ";", "unsigned", "maxSymbolValue", "=", "255", ";", "unsigned", "huffLog", "=", "11", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "srcSize", ")", ";", "memcpy", "(", "nextHuf", ",", "prevHuf", ",", "sizeof", "(", "*", "prevHuf", ")", ")", ";", "# define", "COMPRESS_LITERALS_SIZE_MIN", " 63", "\n", "{", "size_t", "const", "minLitSize", "=", "COMPRESS_LITERALS_SIZE_MIN", ";", "if", "(", "srcSize", "<=", "minLitSize", ")", "{", "hufMetadata", "->", "hType", "=", "set_basic", ";", "return", "0", ";", "}", "}", "{", "size_t", "const", "largest", "=", "HIST_count_wksp", "(", "countWksp", ",", "&", "maxSymbolValue", ",", "(", "const", "BYTE", "*", ")", "src", ",", "srcSize", ",", "workspace", ",", "wkspSize", ")", ";", "FORWARD_IF_ERROR", "(", "largest", ")", ";", "if", "(", "largest", "==", "srcSize", ")", "{", "hufMetadata", "->", "hType", "=", "set_rle", ";", "return", "0", ";", "}", "if", "(", "largest", "<=", "(", "srcSize", ">>", "7", ")", "+", "4", ")", "{", "hufMetadata", "->", "hType", "=", "set_basic", ";", "return", "0", ";", "}", "}", "memset", "(", "nextHuf", "->", "CTable", ",", "0", ",", "sizeof", "(", "nextHuf", "->", "CTable", ")", ")", ";", "huffLog", "=", "HUF_optimalTableLog", "(", "huffLog", ",", "srcSize", ",", "maxSymbolValue", ")", ";", "{", "size_t", "const", "maxBits", "=", "HUF_buildCTable_wksp", "(", "(", "HUF_CElt", "*", ")", "nextHuf", "->", "CTable", ",", "countWksp", ",", "maxSymbolValue", ",", "huffLog", ",", "nodeWksp", ",", "nodeWkspSize", ")", ";", "FORWARD_IF_ERROR", "(", "maxBits", ")", ";", "huffLog", "=", "(", "U32", ")", "maxBits", ";", "{", "size_t", "cSize", "=", "HUF_estimateCompressedSize", "(", "(", "HUF_CElt", "*", ")", "nextHuf", "->", "CTable", ",", "countWksp", ",", "maxSymbolValue", ")", ";", "size_t", "hSize", "=", "HUF_writeCTable", "(", "hufMetadata", "->", "hufDesBuffer", ",", "sizeof", "(", "hufMetadata", "->", "hufDesBuffer", ")", ",", "(", "HUF_CElt", "*", ")", "nextHuf", "->", "CTable", ",", "maxSymbolValue", ",", "huffLog", ")", ";", "if", "(", "cSize", "+", "hSize", ">=", "srcSize", ")", "{", "hufMetadata", "->", "hType", "=", "set_basic", ";", "return", "0", ";", "}", "hufMetadata", "->", "hType", "=", "set_compressed", ";", "return", "hSize", ";", "}", "}", "}" ]
ZSTD_buildSuperBlockEntropy_literal() : Builds entropy for the super-block literals.
[ "ZSTD_buildSuperBlockEntropy_literal", "()", ":", "Builds", "entropy", "for", "the", "super", "-", "block", "literals", "." ]
[ "/* Prepare nextEntropy assuming reusing the existing table */", "/* small ? don't even attempt compression (speed opt) */", "/* Scan input and build symbol stats */", "/* Build Huffman Tree */" ]
[ { "param": "src", "type": "void" }, { "param": "srcSize", "type": "size_t" }, { "param": "prevHuf", "type": "ZSTD_hufCTables_t" }, { "param": "nextHuf", "type": "ZSTD_hufCTables_t" }, { "param": "hufMetadata", "type": "ZSTD_hufCTablesMetadata_t" }, { "param": "workspace", "type": "void" }, { "param": "wkspSize", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "src", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "srcSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "prevHuf", "type": "ZSTD_hufCTables_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nextHuf", "type": "ZSTD_hufCTables_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hufMetadata", "type": "ZSTD_hufCTablesMetadata_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "workspace", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wkspSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
39af1aba710f0faba4792b696a3472ff6a8380ee
JellyPixelGames/tracy
zstd/zstd_compress_superblock.c
[ "BSD-3-Clause" ]
C
ZSTD_buildSuperBlockEntropy_sequences
size_t
static size_t ZSTD_buildSuperBlockEntropy_sequences(seqStore_t* seqStorePtr, const ZSTD_fseCTables_t* prevEntropy, ZSTD_fseCTables_t* nextEntropy, const ZSTD_CCtx_params* cctxParams, ZSTD_fseCTablesMetadata_t* fseMetadata, void* workspace, size_t wkspSize) { BYTE* const wkspStart = (BYTE*)workspace; BYTE* const wkspEnd = wkspStart + wkspSize; BYTE* const countWkspStart = wkspStart; unsigned* const countWksp = (unsigned*)workspace; const size_t countWkspSize = (MaxSeq + 1) * sizeof(unsigned); BYTE* const cTableWksp = countWkspStart + countWkspSize; const size_t cTableWkspSize = wkspEnd-cTableWksp; ZSTD_strategy const strategy = cctxParams->cParams.strategy; FSE_CTable* CTable_LitLength = nextEntropy->litlengthCTable; FSE_CTable* CTable_OffsetBits = nextEntropy->offcodeCTable; FSE_CTable* CTable_MatchLength = nextEntropy->matchlengthCTable; const BYTE* const ofCodeTable = seqStorePtr->ofCode; const BYTE* const llCodeTable = seqStorePtr->llCode; const BYTE* const mlCodeTable = seqStorePtr->mlCode; size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; BYTE* const ostart = fseMetadata->fseTablesBuffer; BYTE* const oend = ostart + sizeof(fseMetadata->fseTablesBuffer); BYTE* op = ostart; assert(cTableWkspSize >= (1 << MaxFSELog) * sizeof(FSE_FUNCTION_TYPE)); DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy_sequences (nbSeq=%zu)", nbSeq); memset(workspace, 0, wkspSize); fseMetadata->lastCountSize = 0; /* convert length/distances into codes */ ZSTD_seqToCodes(seqStorePtr); /* build CTable for Literal Lengths */ { U32 LLtype; unsigned max = MaxLL; size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, llCodeTable, nbSeq, workspace, wkspSize); /* can't fail */ DEBUGLOG(5, "Building LL table"); nextEntropy->litlength_repeatMode = prevEntropy->litlength_repeatMode; LLtype = ZSTD_selectEncodingType(&nextEntropy->litlength_repeatMode, countWksp, max, mostFrequent, nbSeq, LLFSELog, prevEntropy->litlengthCTable, LL_defaultNorm, LL_defaultNormLog, ZSTD_defaultAllowed, strategy); assert(set_basic < set_compressed && set_rle < set_compressed); assert(!(LLtype < set_compressed && nextEntropy->litlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */ { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_LitLength, LLFSELog, (symbolEncodingType_e)LLtype, countWksp, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL, prevEntropy->litlengthCTable, sizeof(prevEntropy->litlengthCTable), cTableWksp, cTableWkspSize); FORWARD_IF_ERROR(countSize); if (LLtype == set_compressed) fseMetadata->lastCountSize = countSize; op += countSize; fseMetadata->llType = (symbolEncodingType_e) LLtype; } } /* build CTable for Offsets */ { U32 Offtype; unsigned max = MaxOff; size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, ofCodeTable, nbSeq, workspace, wkspSize); /* can't fail */ /* We can only use the basic table if max <= DefaultMaxOff, otherwise the offsets are too large */ ZSTD_defaultPolicy_e const defaultPolicy = (max <= DefaultMaxOff) ? ZSTD_defaultAllowed : ZSTD_defaultDisallowed; DEBUGLOG(5, "Building OF table"); nextEntropy->offcode_repeatMode = prevEntropy->offcode_repeatMode; Offtype = ZSTD_selectEncodingType(&nextEntropy->offcode_repeatMode, countWksp, max, mostFrequent, nbSeq, OffFSELog, prevEntropy->offcodeCTable, OF_defaultNorm, OF_defaultNormLog, defaultPolicy, strategy); assert(!(Offtype < set_compressed && nextEntropy->offcode_repeatMode != FSE_repeat_none)); /* We don't copy tables */ { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_OffsetBits, OffFSELog, (symbolEncodingType_e)Offtype, countWksp, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff, prevEntropy->offcodeCTable, sizeof(prevEntropy->offcodeCTable), cTableWksp, cTableWkspSize); FORWARD_IF_ERROR(countSize); if (Offtype == set_compressed) fseMetadata->lastCountSize = countSize; op += countSize; fseMetadata->ofType = (symbolEncodingType_e) Offtype; } } /* build CTable for MatchLengths */ { U32 MLtype; unsigned max = MaxML; size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, mlCodeTable, nbSeq, workspace, wkspSize); /* can't fail */ DEBUGLOG(5, "Building ML table (remaining space : %i)", (int)(oend-op)); nextEntropy->matchlength_repeatMode = prevEntropy->matchlength_repeatMode; MLtype = ZSTD_selectEncodingType(&nextEntropy->matchlength_repeatMode, countWksp, max, mostFrequent, nbSeq, MLFSELog, prevEntropy->matchlengthCTable, ML_defaultNorm, ML_defaultNormLog, ZSTD_defaultAllowed, strategy); assert(!(MLtype < set_compressed && nextEntropy->matchlength_repeatMode != FSE_repeat_none)); /* We don't copy tables */ { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_MatchLength, MLFSELog, (symbolEncodingType_e)MLtype, countWksp, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML, prevEntropy->matchlengthCTable, sizeof(prevEntropy->matchlengthCTable), cTableWksp, cTableWkspSize); FORWARD_IF_ERROR(countSize); if (MLtype == set_compressed) fseMetadata->lastCountSize = countSize; op += countSize; fseMetadata->mlType = (symbolEncodingType_e) MLtype; } } assert((size_t) (op-ostart) <= sizeof(fseMetadata->fseTablesBuffer)); return op-ostart; }
/** ZSTD_buildSuperBlockEntropy_sequences() : * Builds entropy for the super-block sequences. * Stores symbol compression modes and fse table to fseMetadata. * @return : size of fse tables or error code */
ZSTD_buildSuperBlockEntropy_sequences() : Builds entropy for the super-block sequences. Stores symbol compression modes and fse table to fseMetadata. @return : size of fse tables or error code
[ "ZSTD_buildSuperBlockEntropy_sequences", "()", ":", "Builds", "entropy", "for", "the", "super", "-", "block", "sequences", ".", "Stores", "symbol", "compression", "modes", "and", "fse", "table", "to", "fseMetadata", ".", "@return", ":", "size", "of", "fse", "tables", "or", "error", "code" ]
static size_t ZSTD_buildSuperBlockEntropy_sequences(seqStore_t* seqStorePtr, const ZSTD_fseCTables_t* prevEntropy, ZSTD_fseCTables_t* nextEntropy, const ZSTD_CCtx_params* cctxParams, ZSTD_fseCTablesMetadata_t* fseMetadata, void* workspace, size_t wkspSize) { BYTE* const wkspStart = (BYTE*)workspace; BYTE* const wkspEnd = wkspStart + wkspSize; BYTE* const countWkspStart = wkspStart; unsigned* const countWksp = (unsigned*)workspace; const size_t countWkspSize = (MaxSeq + 1) * sizeof(unsigned); BYTE* const cTableWksp = countWkspStart + countWkspSize; const size_t cTableWkspSize = wkspEnd-cTableWksp; ZSTD_strategy const strategy = cctxParams->cParams.strategy; FSE_CTable* CTable_LitLength = nextEntropy->litlengthCTable; FSE_CTable* CTable_OffsetBits = nextEntropy->offcodeCTable; FSE_CTable* CTable_MatchLength = nextEntropy->matchlengthCTable; const BYTE* const ofCodeTable = seqStorePtr->ofCode; const BYTE* const llCodeTable = seqStorePtr->llCode; const BYTE* const mlCodeTable = seqStorePtr->mlCode; size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; BYTE* const ostart = fseMetadata->fseTablesBuffer; BYTE* const oend = ostart + sizeof(fseMetadata->fseTablesBuffer); BYTE* op = ostart; assert(cTableWkspSize >= (1 << MaxFSELog) * sizeof(FSE_FUNCTION_TYPE)); DEBUGLOG(5, "ZSTD_buildSuperBlockEntropy_sequences (nbSeq=%zu)", nbSeq); memset(workspace, 0, wkspSize); fseMetadata->lastCountSize = 0; ZSTD_seqToCodes(seqStorePtr); { U32 LLtype; unsigned max = MaxLL; size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, llCodeTable, nbSeq, workspace, wkspSize); DEBUGLOG(5, "Building LL table"); nextEntropy->litlength_repeatMode = prevEntropy->litlength_repeatMode; LLtype = ZSTD_selectEncodingType(&nextEntropy->litlength_repeatMode, countWksp, max, mostFrequent, nbSeq, LLFSELog, prevEntropy->litlengthCTable, LL_defaultNorm, LL_defaultNormLog, ZSTD_defaultAllowed, strategy); assert(set_basic < set_compressed && set_rle < set_compressed); assert(!(LLtype < set_compressed && nextEntropy->litlength_repeatMode != FSE_repeat_none)); { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_LitLength, LLFSELog, (symbolEncodingType_e)LLtype, countWksp, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL, prevEntropy->litlengthCTable, sizeof(prevEntropy->litlengthCTable), cTableWksp, cTableWkspSize); FORWARD_IF_ERROR(countSize); if (LLtype == set_compressed) fseMetadata->lastCountSize = countSize; op += countSize; fseMetadata->llType = (symbolEncodingType_e) LLtype; } } { U32 Offtype; unsigned max = MaxOff; size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, ofCodeTable, nbSeq, workspace, wkspSize); ZSTD_defaultPolicy_e const defaultPolicy = (max <= DefaultMaxOff) ? ZSTD_defaultAllowed : ZSTD_defaultDisallowed; DEBUGLOG(5, "Building OF table"); nextEntropy->offcode_repeatMode = prevEntropy->offcode_repeatMode; Offtype = ZSTD_selectEncodingType(&nextEntropy->offcode_repeatMode, countWksp, max, mostFrequent, nbSeq, OffFSELog, prevEntropy->offcodeCTable, OF_defaultNorm, OF_defaultNormLog, defaultPolicy, strategy); assert(!(Offtype < set_compressed && nextEntropy->offcode_repeatMode != FSE_repeat_none)); { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_OffsetBits, OffFSELog, (symbolEncodingType_e)Offtype, countWksp, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff, prevEntropy->offcodeCTable, sizeof(prevEntropy->offcodeCTable), cTableWksp, cTableWkspSize); FORWARD_IF_ERROR(countSize); if (Offtype == set_compressed) fseMetadata->lastCountSize = countSize; op += countSize; fseMetadata->ofType = (symbolEncodingType_e) Offtype; } } { U32 MLtype; unsigned max = MaxML; size_t const mostFrequent = HIST_countFast_wksp(countWksp, &max, mlCodeTable, nbSeq, workspace, wkspSize); DEBUGLOG(5, "Building ML table (remaining space : %i)", (int)(oend-op)); nextEntropy->matchlength_repeatMode = prevEntropy->matchlength_repeatMode; MLtype = ZSTD_selectEncodingType(&nextEntropy->matchlength_repeatMode, countWksp, max, mostFrequent, nbSeq, MLFSELog, prevEntropy->matchlengthCTable, ML_defaultNorm, ML_defaultNormLog, ZSTD_defaultAllowed, strategy); assert(!(MLtype < set_compressed && nextEntropy->matchlength_repeatMode != FSE_repeat_none)); { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_MatchLength, MLFSELog, (symbolEncodingType_e)MLtype, countWksp, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML, prevEntropy->matchlengthCTable, sizeof(prevEntropy->matchlengthCTable), cTableWksp, cTableWkspSize); FORWARD_IF_ERROR(countSize); if (MLtype == set_compressed) fseMetadata->lastCountSize = countSize; op += countSize; fseMetadata->mlType = (symbolEncodingType_e) MLtype; } } assert((size_t) (op-ostart) <= sizeof(fseMetadata->fseTablesBuffer)); return op-ostart; }
[ "static", "size_t", "ZSTD_buildSuperBlockEntropy_sequences", "(", "seqStore_t", "*", "seqStorePtr", ",", "const", "ZSTD_fseCTables_t", "*", "prevEntropy", ",", "ZSTD_fseCTables_t", "*", "nextEntropy", ",", "const", "ZSTD_CCtx_params", "*", "cctxParams", ",", "ZSTD_fseCTablesMetadata_t", "*", "fseMetadata", ",", "void", "*", "workspace", ",", "size_t", "wkspSize", ")", "{", "BYTE", "*", "const", "wkspStart", "=", "(", "BYTE", "*", ")", "workspace", ";", "BYTE", "*", "const", "wkspEnd", "=", "wkspStart", "+", "wkspSize", ";", "BYTE", "*", "const", "countWkspStart", "=", "wkspStart", ";", "unsigned", "*", "const", "countWksp", "=", "(", "unsigned", "*", ")", "workspace", ";", "const", "size_t", "countWkspSize", "=", "(", "MaxSeq", "+", "1", ")", "*", "sizeof", "(", "unsigned", ")", ";", "BYTE", "*", "const", "cTableWksp", "=", "countWkspStart", "+", "countWkspSize", ";", "const", "size_t", "cTableWkspSize", "=", "wkspEnd", "-", "cTableWksp", ";", "ZSTD_strategy", "const", "strategy", "=", "cctxParams", "->", "cParams", ".", "strategy", ";", "FSE_CTable", "*", "CTable_LitLength", "=", "nextEntropy", "->", "litlengthCTable", ";", "FSE_CTable", "*", "CTable_OffsetBits", "=", "nextEntropy", "->", "offcodeCTable", ";", "FSE_CTable", "*", "CTable_MatchLength", "=", "nextEntropy", "->", "matchlengthCTable", ";", "const", "BYTE", "*", "const", "ofCodeTable", "=", "seqStorePtr", "->", "ofCode", ";", "const", "BYTE", "*", "const", "llCodeTable", "=", "seqStorePtr", "->", "llCode", ";", "const", "BYTE", "*", "const", "mlCodeTable", "=", "seqStorePtr", "->", "mlCode", ";", "size_t", "const", "nbSeq", "=", "seqStorePtr", "->", "sequences", "-", "seqStorePtr", "->", "sequencesStart", ";", "BYTE", "*", "const", "ostart", "=", "fseMetadata", "->", "fseTablesBuffer", ";", "BYTE", "*", "const", "oend", "=", "ostart", "+", "sizeof", "(", "fseMetadata", "->", "fseTablesBuffer", ")", ";", "BYTE", "*", "op", "=", "ostart", ";", "assert", "(", "cTableWkspSize", ">=", "(", "1", "<<", "MaxFSELog", ")", "*", "sizeof", "(", "FSE_FUNCTION_TYPE", ")", ")", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "nbSeq", ")", ";", "memset", "(", "workspace", ",", "0", ",", "wkspSize", ")", ";", "fseMetadata", "->", "lastCountSize", "=", "0", ";", "ZSTD_seqToCodes", "(", "seqStorePtr", ")", ";", "{", "U32", "LLtype", ";", "unsigned", "max", "=", "MaxLL", ";", "size_t", "const", "mostFrequent", "=", "HIST_countFast_wksp", "(", "countWksp", ",", "&", "max", ",", "llCodeTable", ",", "nbSeq", ",", "workspace", ",", "wkspSize", ")", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ")", ";", "nextEntropy", "->", "litlength_repeatMode", "=", "prevEntropy", "->", "litlength_repeatMode", ";", "LLtype", "=", "ZSTD_selectEncodingType", "(", "&", "nextEntropy", "->", "litlength_repeatMode", ",", "countWksp", ",", "max", ",", "mostFrequent", ",", "nbSeq", ",", "LLFSELog", ",", "prevEntropy", "->", "litlengthCTable", ",", "LL_defaultNorm", ",", "LL_defaultNormLog", ",", "ZSTD_defaultAllowed", ",", "strategy", ")", ";", "assert", "(", "set_basic", "<", "set_compressed", "&&", "set_rle", "<", "set_compressed", ")", ";", "assert", "(", "!", "(", "LLtype", "<", "set_compressed", "&&", "nextEntropy", "->", "litlength_repeatMode", "!=", "FSE_repeat_none", ")", ")", ";", "{", "size_t", "const", "countSize", "=", "ZSTD_buildCTable", "(", "op", ",", "oend", "-", "op", ",", "CTable_LitLength", ",", "LLFSELog", ",", "(", "symbolEncodingType_e", ")", "LLtype", ",", "countWksp", ",", "max", ",", "llCodeTable", ",", "nbSeq", ",", "LL_defaultNorm", ",", "LL_defaultNormLog", ",", "MaxLL", ",", "prevEntropy", "->", "litlengthCTable", ",", "sizeof", "(", "prevEntropy", "->", "litlengthCTable", ")", ",", "cTableWksp", ",", "cTableWkspSize", ")", ";", "FORWARD_IF_ERROR", "(", "countSize", ")", ";", "if", "(", "LLtype", "==", "set_compressed", ")", "fseMetadata", "->", "lastCountSize", "=", "countSize", ";", "op", "+=", "countSize", ";", "fseMetadata", "->", "llType", "=", "(", "symbolEncodingType_e", ")", "LLtype", ";", "}", "}", "{", "U32", "Offtype", ";", "unsigned", "max", "=", "MaxOff", ";", "size_t", "const", "mostFrequent", "=", "HIST_countFast_wksp", "(", "countWksp", ",", "&", "max", ",", "ofCodeTable", ",", "nbSeq", ",", "workspace", ",", "wkspSize", ")", ";", "ZSTD_defaultPolicy_e", "const", "defaultPolicy", "=", "(", "max", "<=", "DefaultMaxOff", ")", "?", "ZSTD_defaultAllowed", ":", "ZSTD_defaultDisallowed", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ")", ";", "nextEntropy", "->", "offcode_repeatMode", "=", "prevEntropy", "->", "offcode_repeatMode", ";", "Offtype", "=", "ZSTD_selectEncodingType", "(", "&", "nextEntropy", "->", "offcode_repeatMode", ",", "countWksp", ",", "max", ",", "mostFrequent", ",", "nbSeq", ",", "OffFSELog", ",", "prevEntropy", "->", "offcodeCTable", ",", "OF_defaultNorm", ",", "OF_defaultNormLog", ",", "defaultPolicy", ",", "strategy", ")", ";", "assert", "(", "!", "(", "Offtype", "<", "set_compressed", "&&", "nextEntropy", "->", "offcode_repeatMode", "!=", "FSE_repeat_none", ")", ")", ";", "{", "size_t", "const", "countSize", "=", "ZSTD_buildCTable", "(", "op", ",", "oend", "-", "op", ",", "CTable_OffsetBits", ",", "OffFSELog", ",", "(", "symbolEncodingType_e", ")", "Offtype", ",", "countWksp", ",", "max", ",", "ofCodeTable", ",", "nbSeq", ",", "OF_defaultNorm", ",", "OF_defaultNormLog", ",", "DefaultMaxOff", ",", "prevEntropy", "->", "offcodeCTable", ",", "sizeof", "(", "prevEntropy", "->", "offcodeCTable", ")", ",", "cTableWksp", ",", "cTableWkspSize", ")", ";", "FORWARD_IF_ERROR", "(", "countSize", ")", ";", "if", "(", "Offtype", "==", "set_compressed", ")", "fseMetadata", "->", "lastCountSize", "=", "countSize", ";", "op", "+=", "countSize", ";", "fseMetadata", "->", "ofType", "=", "(", "symbolEncodingType_e", ")", "Offtype", ";", "}", "}", "{", "U32", "MLtype", ";", "unsigned", "max", "=", "MaxML", ";", "size_t", "const", "mostFrequent", "=", "HIST_countFast_wksp", "(", "countWksp", ",", "&", "max", ",", "mlCodeTable", ",", "nbSeq", ",", "workspace", ",", "wkspSize", ")", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "(", "int", ")", "(", "oend", "-", "op", ")", ")", ";", "nextEntropy", "->", "matchlength_repeatMode", "=", "prevEntropy", "->", "matchlength_repeatMode", ";", "MLtype", "=", "ZSTD_selectEncodingType", "(", "&", "nextEntropy", "->", "matchlength_repeatMode", ",", "countWksp", ",", "max", ",", "mostFrequent", ",", "nbSeq", ",", "MLFSELog", ",", "prevEntropy", "->", "matchlengthCTable", ",", "ML_defaultNorm", ",", "ML_defaultNormLog", ",", "ZSTD_defaultAllowed", ",", "strategy", ")", ";", "assert", "(", "!", "(", "MLtype", "<", "set_compressed", "&&", "nextEntropy", "->", "matchlength_repeatMode", "!=", "FSE_repeat_none", ")", ")", ";", "{", "size_t", "const", "countSize", "=", "ZSTD_buildCTable", "(", "op", ",", "oend", "-", "op", ",", "CTable_MatchLength", ",", "MLFSELog", ",", "(", "symbolEncodingType_e", ")", "MLtype", ",", "countWksp", ",", "max", ",", "mlCodeTable", ",", "nbSeq", ",", "ML_defaultNorm", ",", "ML_defaultNormLog", ",", "MaxML", ",", "prevEntropy", "->", "matchlengthCTable", ",", "sizeof", "(", "prevEntropy", "->", "matchlengthCTable", ")", ",", "cTableWksp", ",", "cTableWkspSize", ")", ";", "FORWARD_IF_ERROR", "(", "countSize", ")", ";", "if", "(", "MLtype", "==", "set_compressed", ")", "fseMetadata", "->", "lastCountSize", "=", "countSize", ";", "op", "+=", "countSize", ";", "fseMetadata", "->", "mlType", "=", "(", "symbolEncodingType_e", ")", "MLtype", ";", "}", "}", "assert", "(", "(", "size_t", ")", "(", "op", "-", "ostart", ")", "<=", "sizeof", "(", "fseMetadata", "->", "fseTablesBuffer", ")", ")", ";", "return", "op", "-", "ostart", ";", "}" ]
ZSTD_buildSuperBlockEntropy_sequences() : Builds entropy for the super-block sequences.
[ "ZSTD_buildSuperBlockEntropy_sequences", "()", ":", "Builds", "entropy", "for", "the", "super", "-", "block", "sequences", "." ]
[ "/* convert length/distances into codes */", "/* build CTable for Literal Lengths */", "/* can't fail */", "/* We don't copy tables */", "/* build CTable for Offsets */", "/* can't fail */", "/* We can only use the basic table if max <= DefaultMaxOff, otherwise the offsets are too large */", "/* We don't copy tables */", "/* build CTable for MatchLengths */", "/* can't fail */", "/* We don't copy tables */" ]
[ { "param": "seqStorePtr", "type": "seqStore_t" }, { "param": "prevEntropy", "type": "ZSTD_fseCTables_t" }, { "param": "nextEntropy", "type": "ZSTD_fseCTables_t" }, { "param": "cctxParams", "type": "ZSTD_CCtx_params" }, { "param": "fseMetadata", "type": "ZSTD_fseCTablesMetadata_t" }, { "param": "workspace", "type": "void" }, { "param": "wkspSize", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "seqStorePtr", "type": "seqStore_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "prevEntropy", "type": "ZSTD_fseCTables_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nextEntropy", "type": "ZSTD_fseCTables_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cctxParams", "type": "ZSTD_CCtx_params", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fseMetadata", "type": "ZSTD_fseCTablesMetadata_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "workspace", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wkspSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
39af1aba710f0faba4792b696a3472ff6a8380ee
JellyPixelGames/tracy
zstd/zstd_compress_superblock.c
[ "BSD-3-Clause" ]
C
ZSTD_compressSubBlock_sequences
size_t
static size_t ZSTD_compressSubBlock_sequences(const ZSTD_fseCTables_t* fseTables, const ZSTD_fseCTablesMetadata_t* fseMetadata, const seqDef* sequences, size_t nbSeq, const BYTE* llCode, const BYTE* mlCode, const BYTE* ofCode, const ZSTD_CCtx_params* cctxParams, void* dst, size_t dstCapacity, const int bmi2, int writeEntropy) { const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN; BYTE* const ostart = (BYTE*)dst; BYTE* const oend = ostart + dstCapacity; BYTE* op = ostart; BYTE* seqHead; DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (nbSeq=%zu, writeEntropy=%d, longOffsets=%d)", nbSeq, writeEntropy, longOffsets); /* Sequences Header */ RETURN_ERROR_IF((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/, dstSize_tooSmall); if (nbSeq < 0x7F) *op++ = (BYTE)nbSeq; else if (nbSeq < LONGNBSEQ) op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2; else op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3; if (writeEntropy && nbSeq == 0) { return 0; } if (nbSeq==0) { return op - ostart; } /* seqHead : flags for FSE encoding type */ seqHead = op++; DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (seqHeadSize=%u)", (unsigned)(op-ostart)); if (writeEntropy) { const U32 LLtype = fseMetadata->llType; const U32 Offtype = fseMetadata->ofType; const U32 MLtype = fseMetadata->mlType; DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (fseTablesSize=%zu)", fseMetadata->fseTablesSize); *seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2)); memcpy(op, fseMetadata->fseTablesBuffer, fseMetadata->fseTablesSize); op += fseMetadata->fseTablesSize; } else { const U32 repeat = set_repeat; *seqHead = (BYTE)((repeat<<6) + (repeat<<4) + (repeat<<2)); } { size_t const bitstreamSize = ZSTD_encodeSequences( op, oend - op, fseTables->matchlengthCTable, mlCode, fseTables->offcodeCTable, ofCode, fseTables->litlengthCTable, llCode, sequences, nbSeq, longOffsets, bmi2); FORWARD_IF_ERROR(bitstreamSize); op += bitstreamSize; /* zstd versions <= 1.3.4 mistakenly report corruption when * FSE_readNCount() receives a buffer < 4 bytes. * Fixed by https://github.com/facebook/zstd/pull/1146. * This can happen when the last set_compressed table present is 2 * bytes and the bitstream is only one byte. * In this exceedingly rare case, we will simply emit an uncompressed * block, since it isn't worth optimizing. */ if (writeEntropy && fseMetadata->lastCountSize && fseMetadata->lastCountSize + bitstreamSize < 4) { /* NCountSize >= 2 && bitstreamSize > 0 ==> lastCountSize == 3 */ assert(fseMetadata->lastCountSize + bitstreamSize == 3); DEBUGLOG(5, "Avoiding bug in zstd decoder in versions <= 1.3.4 by " "emitting an uncompressed block."); return 0; } DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (bitstreamSize=%zu)", bitstreamSize); } /* zstd versions <= 1.4.0 mistakenly report error when * sequences section body size is less than 3 bytes. * Fixed by https://github.com/facebook/zstd/pull/1664. * This can happen when the previous sequences section block is compressed * with rle mode and the current block's sequences section is compressed * with repeat mode where sequences section body size can be 1 byte. */ if (op-seqHead < 4) { return 0; } return op - ostart; }
/** ZSTD_compressSubBlock_sequences() : * Compresses sequences section for a sub-block. * fseMetadata->llType, fseMetadata->ofType, and fseMetadata->mlType have * symbol compression modes for the super-block. * First sub-block will have these in its header. The following sub-blocks * will always have repeat mode. * @return : compressed size of sequences section of a sub-block * Or 0 if it is unable to compress * Or error code. */
ZSTD_compressSubBlock_sequences() : Compresses sequences section for a sub-block. fseMetadata->llType, fseMetadata->ofType, and fseMetadata->mlType have symbol compression modes for the super-block. First sub-block will have these in its header. The following sub-blocks will always have repeat mode. @return : compressed size of sequences section of a sub-block Or 0 if it is unable to compress Or error code.
[ "ZSTD_compressSubBlock_sequences", "()", ":", "Compresses", "sequences", "section", "for", "a", "sub", "-", "block", ".", "fseMetadata", "-", ">", "llType", "fseMetadata", "-", ">", "ofType", "and", "fseMetadata", "-", ">", "mlType", "have", "symbol", "compression", "modes", "for", "the", "super", "-", "block", ".", "First", "sub", "-", "block", "will", "have", "these", "in", "its", "header", ".", "The", "following", "sub", "-", "blocks", "will", "always", "have", "repeat", "mode", ".", "@return", ":", "compressed", "size", "of", "sequences", "section", "of", "a", "sub", "-", "block", "Or", "0", "if", "it", "is", "unable", "to", "compress", "Or", "error", "code", "." ]
static size_t ZSTD_compressSubBlock_sequences(const ZSTD_fseCTables_t* fseTables, const ZSTD_fseCTablesMetadata_t* fseMetadata, const seqDef* sequences, size_t nbSeq, const BYTE* llCode, const BYTE* mlCode, const BYTE* ofCode, const ZSTD_CCtx_params* cctxParams, void* dst, size_t dstCapacity, const int bmi2, int writeEntropy) { const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN; BYTE* const ostart = (BYTE*)dst; BYTE* const oend = ostart + dstCapacity; BYTE* op = ostart; BYTE* seqHead; DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (nbSeq=%zu, writeEntropy=%d, longOffsets=%d)", nbSeq, writeEntropy, longOffsets); RETURN_ERROR_IF((oend-op) < 3 + 1 , dstSize_tooSmall); if (nbSeq < 0x7F) *op++ = (BYTE)nbSeq; else if (nbSeq < LONGNBSEQ) op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2; else op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3; if (writeEntropy && nbSeq == 0) { return 0; } if (nbSeq==0) { return op - ostart; } seqHead = op++; DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (seqHeadSize=%u)", (unsigned)(op-ostart)); if (writeEntropy) { const U32 LLtype = fseMetadata->llType; const U32 Offtype = fseMetadata->ofType; const U32 MLtype = fseMetadata->mlType; DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (fseTablesSize=%zu)", fseMetadata->fseTablesSize); *seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2)); memcpy(op, fseMetadata->fseTablesBuffer, fseMetadata->fseTablesSize); op += fseMetadata->fseTablesSize; } else { const U32 repeat = set_repeat; *seqHead = (BYTE)((repeat<<6) + (repeat<<4) + (repeat<<2)); } { size_t const bitstreamSize = ZSTD_encodeSequences( op, oend - op, fseTables->matchlengthCTable, mlCode, fseTables->offcodeCTable, ofCode, fseTables->litlengthCTable, llCode, sequences, nbSeq, longOffsets, bmi2); FORWARD_IF_ERROR(bitstreamSize); op += bitstreamSize; if (writeEntropy && fseMetadata->lastCountSize && fseMetadata->lastCountSize + bitstreamSize < 4) { assert(fseMetadata->lastCountSize + bitstreamSize == 3); DEBUGLOG(5, "Avoiding bug in zstd decoder in versions <= 1.3.4 by " "emitting an uncompressed block."); return 0; } DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (bitstreamSize=%zu)", bitstreamSize); } if (op-seqHead < 4) { return 0; } return op - ostart; }
[ "static", "size_t", "ZSTD_compressSubBlock_sequences", "(", "const", "ZSTD_fseCTables_t", "*", "fseTables", ",", "const", "ZSTD_fseCTablesMetadata_t", "*", "fseMetadata", ",", "const", "seqDef", "*", "sequences", ",", "size_t", "nbSeq", ",", "const", "BYTE", "*", "llCode", ",", "const", "BYTE", "*", "mlCode", ",", "const", "BYTE", "*", "ofCode", ",", "const", "ZSTD_CCtx_params", "*", "cctxParams", ",", "void", "*", "dst", ",", "size_t", "dstCapacity", ",", "const", "int", "bmi2", ",", "int", "writeEntropy", ")", "{", "const", "int", "longOffsets", "=", "cctxParams", "->", "cParams", ".", "windowLog", ">", "STREAM_ACCUMULATOR_MIN", ";", "BYTE", "*", "const", "ostart", "=", "(", "BYTE", "*", ")", "dst", ";", "BYTE", "*", "const", "oend", "=", "ostart", "+", "dstCapacity", ";", "BYTE", "*", "op", "=", "ostart", ";", "BYTE", "*", "seqHead", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "nbSeq", ",", "writeEntropy", ",", "longOffsets", ")", ";", "RETURN_ERROR_IF", "(", "(", "oend", "-", "op", ")", "<", "3", "+", "1", ",", "dstSize_tooSmall", ")", ";", "if", "(", "nbSeq", "<", "0x7F", ")", "*", "op", "++", "=", "(", "BYTE", ")", "nbSeq", ";", "else", "if", "(", "nbSeq", "<", "LONGNBSEQ", ")", "op", "[", "0", "]", "=", "(", "BYTE", ")", "(", "(", "nbSeq", ">>", "8", ")", "+", "0x80", ")", ",", "op", "[", "1", "]", "=", "(", "BYTE", ")", "nbSeq", ",", "op", "+=", "2", ";", "else", "op", "[", "0", "]", "=", "0xFF", ",", "MEM_writeLE16", "(", "op", "+", "1", ",", "(", "U16", ")", "(", "nbSeq", "-", "LONGNBSEQ", ")", ")", ",", "op", "+=", "3", ";", "if", "(", "writeEntropy", "&&", "nbSeq", "==", "0", ")", "{", "return", "0", ";", "}", "if", "(", "nbSeq", "==", "0", ")", "{", "return", "op", "-", "ostart", ";", "}", "seqHead", "=", "op", "++", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "(", "unsigned", ")", "(", "op", "-", "ostart", ")", ")", ";", "if", "(", "writeEntropy", ")", "{", "const", "U32", "LLtype", "=", "fseMetadata", "->", "llType", ";", "const", "U32", "Offtype", "=", "fseMetadata", "->", "ofType", ";", "const", "U32", "MLtype", "=", "fseMetadata", "->", "mlType", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "fseMetadata", "->", "fseTablesSize", ")", ";", "*", "seqHead", "=", "(", "BYTE", ")", "(", "(", "LLtype", "<<", "6", ")", "+", "(", "Offtype", "<<", "4", ")", "+", "(", "MLtype", "<<", "2", ")", ")", ";", "memcpy", "(", "op", ",", "fseMetadata", "->", "fseTablesBuffer", ",", "fseMetadata", "->", "fseTablesSize", ")", ";", "op", "+=", "fseMetadata", "->", "fseTablesSize", ";", "}", "else", "{", "const", "U32", "repeat", "=", "set_repeat", ";", "*", "seqHead", "=", "(", "BYTE", ")", "(", "(", "repeat", "<<", "6", ")", "+", "(", "repeat", "<<", "4", ")", "+", "(", "repeat", "<<", "2", ")", ")", ";", "}", "{", "size_t", "const", "bitstreamSize", "=", "ZSTD_encodeSequences", "(", "op", ",", "oend", "-", "op", ",", "fseTables", "->", "matchlengthCTable", ",", "mlCode", ",", "fseTables", "->", "offcodeCTable", ",", "ofCode", ",", "fseTables", "->", "litlengthCTable", ",", "llCode", ",", "sequences", ",", "nbSeq", ",", "longOffsets", ",", "bmi2", ")", ";", "FORWARD_IF_ERROR", "(", "bitstreamSize", ")", ";", "op", "+=", "bitstreamSize", ";", "if", "(", "writeEntropy", "&&", "fseMetadata", "->", "lastCountSize", "&&", "fseMetadata", "->", "lastCountSize", "+", "bitstreamSize", "<", "4", ")", "{", "assert", "(", "fseMetadata", "->", "lastCountSize", "+", "bitstreamSize", "==", "3", ")", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", "\"", "\"", ")", ";", "return", "0", ";", "}", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "bitstreamSize", ")", ";", "}", "if", "(", "op", "-", "seqHead", "<", "4", ")", "{", "return", "0", ";", "}", "return", "op", "-", "ostart", ";", "}" ]
ZSTD_compressSubBlock_sequences() : Compresses sequences section for a sub-block.
[ "ZSTD_compressSubBlock_sequences", "()", ":", "Compresses", "sequences", "section", "for", "a", "sub", "-", "block", "." ]
[ "/* Sequences Header */", "/*max nbSeq Size*/", "/*seqHead*/", "/* seqHead : flags for FSE encoding type */", "/* zstd versions <= 1.3.4 mistakenly report corruption when\n * FSE_readNCount() receives a buffer < 4 bytes.\n * Fixed by https://github.com/facebook/zstd/pull/1146.\n * This can happen when the last set_compressed table present is 2\n * bytes and the bitstream is only one byte.\n * In this exceedingly rare case, we will simply emit an uncompressed\n * block, since it isn't worth optimizing.\n */", "/* NCountSize >= 2 && bitstreamSize > 0 ==> lastCountSize == 3 */", "/* zstd versions <= 1.4.0 mistakenly report error when\n * sequences section body size is less than 3 bytes.\n * Fixed by https://github.com/facebook/zstd/pull/1664.\n * This can happen when the previous sequences section block is compressed\n * with rle mode and the current block's sequences section is compressed\n * with repeat mode where sequences section body size can be 1 byte.\n */" ]
[ { "param": "fseTables", "type": "ZSTD_fseCTables_t" }, { "param": "fseMetadata", "type": "ZSTD_fseCTablesMetadata_t" }, { "param": "sequences", "type": "seqDef" }, { "param": "nbSeq", "type": "size_t" }, { "param": "llCode", "type": "BYTE" }, { "param": "mlCode", "type": "BYTE" }, { "param": "ofCode", "type": "BYTE" }, { "param": "cctxParams", "type": "ZSTD_CCtx_params" }, { "param": "dst", "type": "void" }, { "param": "dstCapacity", "type": "size_t" }, { "param": "bmi2", "type": "int" }, { "param": "writeEntropy", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fseTables", "type": "ZSTD_fseCTables_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fseMetadata", "type": "ZSTD_fseCTablesMetadata_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sequences", "type": "seqDef", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nbSeq", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "llCode", "type": "BYTE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mlCode", "type": "BYTE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ofCode", "type": "BYTE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cctxParams", "type": "ZSTD_CCtx_params", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dstCapacity", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bmi2", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "writeEntropy", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
39af1aba710f0faba4792b696a3472ff6a8380ee
JellyPixelGames/tracy
zstd/zstd_compress_superblock.c
[ "BSD-3-Clause" ]
C
ZSTD_compressSubBlock_multi
size_t
static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr, const ZSTD_entropyCTables_t* entropy, const ZSTD_entropyCTablesMetadata_t* entropyMetadata, const ZSTD_CCtx_params* cctxParams, void* dst, size_t dstCapacity, const int bmi2, U32 lastBlock, void* workspace, size_t wkspSize) { const seqDef* const sstart = seqStorePtr->sequencesStart; const seqDef* const send = seqStorePtr->sequences; const seqDef* sp = sstart; const BYTE* const lstart = seqStorePtr->litStart; const BYTE* const lend = seqStorePtr->lit; const BYTE* lp = lstart; BYTE* const ostart = (BYTE*)dst; BYTE* const oend = ostart + dstCapacity; BYTE* op = ostart; const BYTE* llCodePtr = seqStorePtr->llCode; const BYTE* mlCodePtr = seqStorePtr->mlCode; const BYTE* ofCodePtr = seqStorePtr->ofCode; size_t targetCBlockSize = cctxParams->targetCBlockSize; size_t litSize, seqCount; int writeEntropy = 1; size_t remaining = ZSTD_seqDecompressedSize(sstart, send-sstart, lend-lstart); size_t cBlockSizeEstimate = 0; DEBUGLOG(5, "ZSTD_compressSubBlock_multi (litSize=%u, nbSeq=%u)", (unsigned)(lend-lp), (unsigned)(send-sstart)); litSize = 0; seqCount = 0; while (sp + seqCount < send) { const seqDef* const sequence = sp + seqCount; const U32 lastSequence = sequence+1 == send; litSize = (sequence == send) ? (size_t)(lend-lp) : litSize + sequence->litLength; seqCount++; /* I think there is an optimization opportunity here. * Calling ZSTD_estimateSubBlockSize for every sequence can be wasteful * since it recalculates estimate from scratch. * For example, it would recount literal distribution and symbol codes everytime. */ cBlockSizeEstimate = ZSTD_estimateSubBlockSize(lp, litSize, ofCodePtr, llCodePtr, mlCodePtr, seqCount, entropy, entropyMetadata, workspace, wkspSize, writeEntropy); if (cBlockSizeEstimate > targetCBlockSize || lastSequence) { const size_t decompressedSize = ZSTD_seqDecompressedSize(sp, seqCount, litSize); const size_t cSize = ZSTD_compressSubBlock(entropy, entropyMetadata, sp, seqCount, lp, litSize, llCodePtr, mlCodePtr, ofCodePtr, cctxParams, op, oend-op, bmi2, writeEntropy, lastBlock && lastSequence); FORWARD_IF_ERROR(cSize); if (cSize > 0 && cSize < decompressedSize) { assert(remaining >= decompressedSize); remaining -= decompressedSize; sp += seqCount; lp += litSize; op += cSize; llCodePtr += seqCount; mlCodePtr += seqCount; ofCodePtr += seqCount; litSize = 0; seqCount = 0; writeEntropy = 0; // Entropy only needs to be written once } } } if (remaining) { DEBUGLOG(5, "ZSTD_compressSubBlock_multi failed to compress"); return 0; } DEBUGLOG(5, "ZSTD_compressSubBlock_multi compressed"); return op-ostart; }
/** ZSTD_compressSubBlock_multi() : * Breaks super-block into multiple sub-blocks and compresses them. * Entropy will be written to the first block. * The following blocks will use repeat mode to compress. * All sub-blocks are compressed blocks (no raw or rle blocks). * @return : compressed size of the super block (which is multiple ZSTD blocks) * Or 0 if it failed to compress. */
ZSTD_compressSubBlock_multi() : Breaks super-block into multiple sub-blocks and compresses them. Entropy will be written to the first block. The following blocks will use repeat mode to compress. All sub-blocks are compressed blocks (no raw or rle blocks). @return : compressed size of the super block (which is multiple ZSTD blocks) Or 0 if it failed to compress.
[ "ZSTD_compressSubBlock_multi", "()", ":", "Breaks", "super", "-", "block", "into", "multiple", "sub", "-", "blocks", "and", "compresses", "them", ".", "Entropy", "will", "be", "written", "to", "the", "first", "block", ".", "The", "following", "blocks", "will", "use", "repeat", "mode", "to", "compress", ".", "All", "sub", "-", "blocks", "are", "compressed", "blocks", "(", "no", "raw", "or", "rle", "blocks", ")", ".", "@return", ":", "compressed", "size", "of", "the", "super", "block", "(", "which", "is", "multiple", "ZSTD", "blocks", ")", "Or", "0", "if", "it", "failed", "to", "compress", "." ]
static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr, const ZSTD_entropyCTables_t* entropy, const ZSTD_entropyCTablesMetadata_t* entropyMetadata, const ZSTD_CCtx_params* cctxParams, void* dst, size_t dstCapacity, const int bmi2, U32 lastBlock, void* workspace, size_t wkspSize) { const seqDef* const sstart = seqStorePtr->sequencesStart; const seqDef* const send = seqStorePtr->sequences; const seqDef* sp = sstart; const BYTE* const lstart = seqStorePtr->litStart; const BYTE* const lend = seqStorePtr->lit; const BYTE* lp = lstart; BYTE* const ostart = (BYTE*)dst; BYTE* const oend = ostart + dstCapacity; BYTE* op = ostart; const BYTE* llCodePtr = seqStorePtr->llCode; const BYTE* mlCodePtr = seqStorePtr->mlCode; const BYTE* ofCodePtr = seqStorePtr->ofCode; size_t targetCBlockSize = cctxParams->targetCBlockSize; size_t litSize, seqCount; int writeEntropy = 1; size_t remaining = ZSTD_seqDecompressedSize(sstart, send-sstart, lend-lstart); size_t cBlockSizeEstimate = 0; DEBUGLOG(5, "ZSTD_compressSubBlock_multi (litSize=%u, nbSeq=%u)", (unsigned)(lend-lp), (unsigned)(send-sstart)); litSize = 0; seqCount = 0; while (sp + seqCount < send) { const seqDef* const sequence = sp + seqCount; const U32 lastSequence = sequence+1 == send; litSize = (sequence == send) ? (size_t)(lend-lp) : litSize + sequence->litLength; seqCount++; cBlockSizeEstimate = ZSTD_estimateSubBlockSize(lp, litSize, ofCodePtr, llCodePtr, mlCodePtr, seqCount, entropy, entropyMetadata, workspace, wkspSize, writeEntropy); if (cBlockSizeEstimate > targetCBlockSize || lastSequence) { const size_t decompressedSize = ZSTD_seqDecompressedSize(sp, seqCount, litSize); const size_t cSize = ZSTD_compressSubBlock(entropy, entropyMetadata, sp, seqCount, lp, litSize, llCodePtr, mlCodePtr, ofCodePtr, cctxParams, op, oend-op, bmi2, writeEntropy, lastBlock && lastSequence); FORWARD_IF_ERROR(cSize); if (cSize > 0 && cSize < decompressedSize) { assert(remaining >= decompressedSize); remaining -= decompressedSize; sp += seqCount; lp += litSize; op += cSize; llCodePtr += seqCount; mlCodePtr += seqCount; ofCodePtr += seqCount; litSize = 0; seqCount = 0; writeEntropy = 0; } } } if (remaining) { DEBUGLOG(5, "ZSTD_compressSubBlock_multi failed to compress"); return 0; } DEBUGLOG(5, "ZSTD_compressSubBlock_multi compressed"); return op-ostart; }
[ "static", "size_t", "ZSTD_compressSubBlock_multi", "(", "const", "seqStore_t", "*", "seqStorePtr", ",", "const", "ZSTD_entropyCTables_t", "*", "entropy", ",", "const", "ZSTD_entropyCTablesMetadata_t", "*", "entropyMetadata", ",", "const", "ZSTD_CCtx_params", "*", "cctxParams", ",", "void", "*", "dst", ",", "size_t", "dstCapacity", ",", "const", "int", "bmi2", ",", "U32", "lastBlock", ",", "void", "*", "workspace", ",", "size_t", "wkspSize", ")", "{", "const", "seqDef", "*", "const", "sstart", "=", "seqStorePtr", "->", "sequencesStart", ";", "const", "seqDef", "*", "const", "send", "=", "seqStorePtr", "->", "sequences", ";", "const", "seqDef", "*", "sp", "=", "sstart", ";", "const", "BYTE", "*", "const", "lstart", "=", "seqStorePtr", "->", "litStart", ";", "const", "BYTE", "*", "const", "lend", "=", "seqStorePtr", "->", "lit", ";", "const", "BYTE", "*", "lp", "=", "lstart", ";", "BYTE", "*", "const", "ostart", "=", "(", "BYTE", "*", ")", "dst", ";", "BYTE", "*", "const", "oend", "=", "ostart", "+", "dstCapacity", ";", "BYTE", "*", "op", "=", "ostart", ";", "const", "BYTE", "*", "llCodePtr", "=", "seqStorePtr", "->", "llCode", ";", "const", "BYTE", "*", "mlCodePtr", "=", "seqStorePtr", "->", "mlCode", ";", "const", "BYTE", "*", "ofCodePtr", "=", "seqStorePtr", "->", "ofCode", ";", "size_t", "targetCBlockSize", "=", "cctxParams", "->", "targetCBlockSize", ";", "size_t", "litSize", ",", "seqCount", ";", "int", "writeEntropy", "=", "1", ";", "size_t", "remaining", "=", "ZSTD_seqDecompressedSize", "(", "sstart", ",", "send", "-", "sstart", ",", "lend", "-", "lstart", ")", ";", "size_t", "cBlockSizeEstimate", "=", "0", ";", "DEBUGLOG", "(", "5", ",", "\"", "\"", ",", "(", "unsigned", ")", "(", "lend", "-", "lp", ")", ",", "(", "unsigned", ")", "(", "send", "-", "sstart", ")", ")", ";", "litSize", "=", "0", ";", "seqCount", "=", "0", ";", "while", "(", "sp", "+", "seqCount", "<", "send", ")", "{", "const", "seqDef", "*", "const", "sequence", "=", "sp", "+", "seqCount", ";", "const", "U32", "lastSequence", "=", "sequence", "+", "1", "==", "send", ";", "litSize", "=", "(", "sequence", "==", "send", ")", "?", "(", "size_t", ")", "(", "lend", "-", "lp", ")", ":", "litSize", "+", "sequence", "->", "litLength", ";", "seqCount", "++", ";", "cBlockSizeEstimate", "=", "ZSTD_estimateSubBlockSize", "(", "lp", ",", "litSize", ",", "ofCodePtr", ",", "llCodePtr", ",", "mlCodePtr", ",", "seqCount", ",", "entropy", ",", "entropyMetadata", ",", "workspace", ",", "wkspSize", ",", "writeEntropy", ")", ";", "if", "(", "cBlockSizeEstimate", ">", "targetCBlockSize", "||", "lastSequence", ")", "{", "const", "size_t", "decompressedSize", "=", "ZSTD_seqDecompressedSize", "(", "sp", ",", "seqCount", ",", "litSize", ")", ";", "const", "size_t", "cSize", "=", "ZSTD_compressSubBlock", "(", "entropy", ",", "entropyMetadata", ",", "sp", ",", "seqCount", ",", "lp", ",", "litSize", ",", "llCodePtr", ",", "mlCodePtr", ",", "ofCodePtr", ",", "cctxParams", ",", "op", ",", "oend", "-", "op", ",", "bmi2", ",", "writeEntropy", ",", "lastBlock", "&&", "lastSequence", ")", ";", "FORWARD_IF_ERROR", "(", "cSize", ")", ";", "if", "(", "cSize", ">", "0", "&&", "cSize", "<", "decompressedSize", ")", "{", "assert", "(", "remaining", ">=", "decompressedSize", ")", ";", "remaining", "-=", "decompressedSize", ";", "sp", "+=", "seqCount", ";", "lp", "+=", "litSize", ";", "op", "+=", "cSize", ";", "llCodePtr", "+=", "seqCount", ";", "mlCodePtr", "+=", "seqCount", ";", "ofCodePtr", "+=", "seqCount", ";", "litSize", "=", "0", ";", "seqCount", "=", "0", ";", "writeEntropy", "=", "0", ";", "}", "}", "}", "if", "(", "remaining", ")", "{", "DEBUGLOG", "(", "5", ",", "\"", "\"", ")", ";", "return", "0", ";", "}", "DEBUGLOG", "(", "5", ",", "\"", "\"", ")", ";", "return", "op", "-", "ostart", ";", "}" ]
ZSTD_compressSubBlock_multi() : Breaks super-block into multiple sub-blocks and compresses them.
[ "ZSTD_compressSubBlock_multi", "()", ":", "Breaks", "super", "-", "block", "into", "multiple", "sub", "-", "blocks", "and", "compresses", "them", "." ]
[ "/* I think there is an optimization opportunity here.\n * Calling ZSTD_estimateSubBlockSize for every sequence can be wasteful\n * since it recalculates estimate from scratch.\n * For example, it would recount literal distribution and symbol codes everytime.\n */", "// Entropy only needs to be written once" ]
[ { "param": "seqStorePtr", "type": "seqStore_t" }, { "param": "entropy", "type": "ZSTD_entropyCTables_t" }, { "param": "entropyMetadata", "type": "ZSTD_entropyCTablesMetadata_t" }, { "param": "cctxParams", "type": "ZSTD_CCtx_params" }, { "param": "dst", "type": "void" }, { "param": "dstCapacity", "type": "size_t" }, { "param": "bmi2", "type": "int" }, { "param": "lastBlock", "type": "U32" }, { "param": "workspace", "type": "void" }, { "param": "wkspSize", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "seqStorePtr", "type": "seqStore_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "entropy", "type": "ZSTD_entropyCTables_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "entropyMetadata", "type": "ZSTD_entropyCTablesMetadata_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cctxParams", "type": "ZSTD_CCtx_params", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dstCapacity", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bmi2", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "lastBlock", "type": "U32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "workspace", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wkspSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8b1bee988dbc78f27125f1901c86e29f6087c11c
katakk/iperf
src/Timestamp.h
[ "MIT" ]
C
delta_usec
null
long delta_usec(void) { struct timeval previous = mTime; setnow(); return subUsec(previous); }
/* ------------------------------------------------------------------- * Return the number of microseconds from now to last time of setting. * ------------------------------------------------------------------- */
Return the number of microseconds from now to last time of setting.
[ "Return", "the", "number", "of", "microseconds", "from", "now", "to", "last", "time", "of", "setting", "." ]
long delta_usec(void) { struct timeval previous = mTime; setnow(); return subUsec(previous); }
[ "long", "delta_usec", "(", "void", ")", "{", "struct", "timeval", "previous", "=", "mTime", ";", "setnow", "(", ")", ";", "return", "subUsec", "(", "previous", ")", ";", "}" ]
Return the number of microseconds from now to last time of setting.
[ "Return", "the", "number", "of", "microseconds", "from", "now", "to", "last", "time", "of", "setting", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8b1bee988dbc78f27125f1901c86e29f6087c11c
katakk/iperf
src/Timestamp.h
[ "MIT" ]
C
add
void
void add( Timestamp right ) { mTime.tv_sec += right.mTime.tv_sec; mTime.tv_usec += right.mTime.tv_usec; // watch for under- and overflow if ( mTime.tv_usec < 0 ) { mTime.tv_usec += kMillion; mTime.tv_sec--; } if ( mTime.tv_usec >= kMillion ) { mTime.tv_usec -= kMillion; mTime.tv_sec++; } assert( mTime.tv_usec >= 0 && mTime.tv_usec < kMillion ); }
/* ------------------------------------------------------------------- * add the right timestamp to my timestamp. * ------------------------------------------------------------------- */
add the right timestamp to my timestamp.
[ "add", "the", "right", "timestamp", "to", "my", "timestamp", "." ]
void add( Timestamp right ) { mTime.tv_sec += right.mTime.tv_sec; mTime.tv_usec += right.mTime.tv_usec; if ( mTime.tv_usec < 0 ) { mTime.tv_usec += kMillion; mTime.tv_sec--; } if ( mTime.tv_usec >= kMillion ) { mTime.tv_usec -= kMillion; mTime.tv_sec++; } assert( mTime.tv_usec >= 0 && mTime.tv_usec < kMillion ); }
[ "void", "add", "(", "Timestamp", "right", ")", "{", "mTime", ".", "tv_sec", "+=", "right", ".", "mTime", ".", "tv_sec", ";", "mTime", ".", "tv_usec", "+=", "right", ".", "mTime", ".", "tv_usec", ";", "if", "(", "mTime", ".", "tv_usec", "<", "0", ")", "{", "mTime", ".", "tv_usec", "+=", "kMillion", ";", "mTime", ".", "tv_sec", "--", ";", "}", "if", "(", "mTime", ".", "tv_usec", ">=", "kMillion", ")", "{", "mTime", ".", "tv_usec", "-=", "kMillion", ";", "mTime", ".", "tv_sec", "++", ";", "}", "assert", "(", "mTime", ".", "tv_usec", ">=", "0", "&&", "mTime", ".", "tv_usec", "<", "kMillion", ")", ";", "}" ]
add the right timestamp to my timestamp.
[ "add", "the", "right", "timestamp", "to", "my", "timestamp", "." ]
[ "// watch for under- and overflow" ]
[ { "param": "right", "type": "Timestamp" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "right", "type": "Timestamp", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8b1bee988dbc78f27125f1901c86e29f6087c11c
katakk/iperf
src/Timestamp.h
[ "MIT" ]
C
add
void
void add( double sec ) { mTime.tv_sec += (long) sec; mTime.tv_usec += (long) ((sec - ((long) sec )) * kMillion); // watch for overflow if ( mTime.tv_usec >= kMillion ) { mTime.tv_usec -= kMillion; mTime.tv_sec++; } assert( mTime.tv_usec >= 0 && mTime.tv_usec < kMillion ); }
/* ------------------------------------------------------------------- * add the seconds to my timestamp. * TODO optimize? * ------------------------------------------------------------------- */
add the seconds to my timestamp.
[ "add", "the", "seconds", "to", "my", "timestamp", "." ]
void add( double sec ) { mTime.tv_sec += (long) sec; mTime.tv_usec += (long) ((sec - ((long) sec )) * kMillion); if ( mTime.tv_usec >= kMillion ) { mTime.tv_usec -= kMillion; mTime.tv_sec++; } assert( mTime.tv_usec >= 0 && mTime.tv_usec < kMillion ); }
[ "void", "add", "(", "double", "sec", ")", "{", "mTime", ".", "tv_sec", "+=", "(", "long", ")", "sec", ";", "mTime", ".", "tv_usec", "+=", "(", "long", ")", "(", "(", "sec", "-", "(", "(", "long", ")", "sec", ")", ")", "*", "kMillion", ")", ";", "if", "(", "mTime", ".", "tv_usec", ">=", "kMillion", ")", "{", "mTime", ".", "tv_usec", "-=", "kMillion", ";", "mTime", ".", "tv_sec", "++", ";", "}", "assert", "(", "mTime", ".", "tv_usec", ">=", "0", "&&", "mTime", ".", "tv_usec", "<", "kMillion", ")", ";", "}" ]
add the seconds to my timestamp.
[ "add", "the", "seconds", "to", "my", "timestamp", "." ]
[ "// watch for overflow" ]
[ { "param": "sec", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sec", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8b1bee988dbc78f27125f1901c86e29f6087c11c
katakk/iperf
src/Timestamp.h
[ "MIT" ]
C
before
bool
bool before( timeval right ) { return mTime.tv_sec < right.tv_sec || (mTime.tv_sec == right.tv_sec && mTime.tv_usec < right.tv_usec); }
/* ------------------------------------------------------------------- * return true if my timestamp is before the right timestamp. * ------------------------------------------------------------------- */
return true if my timestamp is before the right timestamp.
[ "return", "true", "if", "my", "timestamp", "is", "before", "the", "right", "timestamp", "." ]
bool before( timeval right ) { return mTime.tv_sec < right.tv_sec || (mTime.tv_sec == right.tv_sec && mTime.tv_usec < right.tv_usec); }
[ "bool", "before", "(", "timeval", "right", ")", "{", "return", "mTime", ".", "tv_sec", "<", "right", ".", "tv_sec", "||", "(", "mTime", ".", "tv_sec", "==", "right", ".", "tv_sec", "&&", "mTime", ".", "tv_usec", "<", "right", ".", "tv_usec", ")", ";", "}" ]
return true if my timestamp is before the right timestamp.
[ "return", "true", "if", "my", "timestamp", "is", "before", "the", "right", "timestamp", "." ]
[]
[ { "param": "right", "type": "timeval" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "right", "type": "timeval", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }