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
8a0c213be647b8d3a09658686b67ca7e6c606ed1
TedPap/opsys
kernel_dev.c
[ "MIT" ]
C
serial_read
int
int serial_read(void* dev, char *buf, unsigned int size) { serial_dcb_t* dcb = (serial_dcb_t*)dev; preempt_off; /* Stop preemption */ Mutex_Lock(& dcb->spinlock); uint count = 0; while(count<size) { int valid = bios_read_serial(dcb->devno, &buf[count]); if (valid) { /** Mark thread as IO */ assert(CURTHREAD); if (CURTHREAD->isIO == false) CURTHREAD->isIO = true; count++; } else if(count==0) { Cond_Wait(&dcb->spinlock, &dcb->rx_ready); } else break; } Mutex_Unlock(& dcb->spinlock); preempt_on; /* Restart preemption */ return count; }
/* Read from the device, sleeping if needed. */
Read from the device, sleeping if needed.
[ "Read", "from", "the", "device", "sleeping", "if", "needed", "." ]
int serial_read(void* dev, char *buf, unsigned int size) { serial_dcb_t* dcb = (serial_dcb_t*)dev; preempt_off; Mutex_Lock(& dcb->spinlock); uint count = 0; while(count<size) { int valid = bios_read_serial(dcb->devno, &buf[count]); if (valid) { assert(CURTHREAD); if (CURTHREAD->isIO == false) CURTHREAD->isIO = true; count++; } else if(count==0) { Cond_Wait(&dcb->spinlock, &dcb->rx_ready); } else break; } Mutex_Unlock(& dcb->spinlock); preempt_on; return count; }
[ "int", "serial_read", "(", "void", "*", "dev", ",", "char", "*", "buf", ",", "unsigned", "int", "size", ")", "{", "serial_dcb_t", "*", "dcb", "=", "(", "serial_dcb_t", "*", ")", "dev", ";", "preempt_off", ";", "Mutex_Lock", "(", "&", "dcb", "->", "spinlock", ")", ";", "uint", "count", "=", "0", ";", "while", "(", "count", "<", "size", ")", "{", "int", "valid", "=", "bios_read_serial", "(", "dcb", "->", "devno", ",", "&", "buf", "[", "count", "]", ")", ";", "if", "(", "valid", ")", "{", "assert", "(", "CURTHREAD", ")", ";", "if", "(", "CURTHREAD", "->", "isIO", "==", "false", ")", "CURTHREAD", "->", "isIO", "=", "true", ";", "count", "++", ";", "}", "else", "if", "(", "count", "==", "0", ")", "{", "Cond_Wait", "(", "&", "dcb", "->", "spinlock", ",", "&", "dcb", "->", "rx_ready", ")", ";", "}", "else", "break", ";", "}", "Mutex_Unlock", "(", "&", "dcb", "->", "spinlock", ")", ";", "preempt_on", ";", "return", "count", ";", "}" ]
Read from the device, sleeping if needed.
[ "Read", "from", "the", "device", "sleeping", "if", "needed", "." ]
[ "/* Stop preemption */", "/** Mark thread as IO */", "/* Restart preemption */" ]
[ { "param": "dev", "type": "void" }, { "param": "buf", "type": "char" }, { "param": "size", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8a0c213be647b8d3a09658686b67ca7e6c606ed1
TedPap/opsys
kernel_dev.c
[ "MIT" ]
C
serial_write
int
int serial_write(void* dev, const char* buf, unsigned int size) { serial_dcb_t* dcb = (serial_dcb_t*)dev; unsigned int count = 0; while(count < size) { int success = bios_write_serial(dcb->devno, buf[count] ); if(success) { /** Mark thread as IO */ assert(CURTHREAD); if (CURTHREAD->isIO == false) CURTHREAD->isIO = true; count++; } else if(count==0) { yield(SERIAL_WRT); } else break; } return count; }
/* Write call This is currently a polling driver. */
Write call This is currently a polling driver.
[ "Write", "call", "This", "is", "currently", "a", "polling", "driver", "." ]
int serial_write(void* dev, const char* buf, unsigned int size) { serial_dcb_t* dcb = (serial_dcb_t*)dev; unsigned int count = 0; while(count < size) { int success = bios_write_serial(dcb->devno, buf[count] ); if(success) { assert(CURTHREAD); if (CURTHREAD->isIO == false) CURTHREAD->isIO = true; count++; } else if(count==0) { yield(SERIAL_WRT); } else break; } return count; }
[ "int", "serial_write", "(", "void", "*", "dev", ",", "const", "char", "*", "buf", ",", "unsigned", "int", "size", ")", "{", "serial_dcb_t", "*", "dcb", "=", "(", "serial_dcb_t", "*", ")", "dev", ";", "unsigned", "int", "count", "=", "0", ";", "while", "(", "count", "<", "size", ")", "{", "int", "success", "=", "bios_write_serial", "(", "dcb", "->", "devno", ",", "buf", "[", "count", "]", ")", ";", "if", "(", "success", ")", "{", "assert", "(", "CURTHREAD", ")", ";", "if", "(", "CURTHREAD", "->", "isIO", "==", "false", ")", "CURTHREAD", "->", "isIO", "=", "true", ";", "count", "++", ";", "}", "else", "if", "(", "count", "==", "0", ")", "{", "yield", "(", "SERIAL_WRT", ")", ";", "}", "else", "break", ";", "}", "return", "count", ";", "}" ]
Write call This is currently a polling driver.
[ "Write", "call", "This", "is", "currently", "a", "polling", "driver", "." ]
[ "/** Mark thread as IO */" ]
[ { "param": "dev", "type": "void" }, { "param": "buf", "type": "char" }, { "param": "size", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bf3e15c098fff9ff11947a60b15e29ce97a21c59
TedPap/opsys
symposium.c
[ "MIT" ]
C
print_state
void
void print_state(int N, PHIL* state, const char* fmt, int ph) { #if QUIET==0 int i; if(N<100) { for(i=0;i<N;i++) { char c= (".THE")[state[i]]; if(i==ph) printf("[%c]", c); else printf(" %c ", c); } } printf(fmt, ph); #endif }
/* Prints the current state given a change (described by fmt) for philosopher ph */
Prints the current state given a change (described by fmt) for philosopher ph
[ "Prints", "the", "current", "state", "given", "a", "change", "(", "described", "by", "fmt", ")", "for", "philosopher", "ph" ]
void print_state(int N, PHIL* state, const char* fmt, int ph) { #if QUIET==0 int i; if(N<100) { for(i=0;i<N;i++) { char c= (".THE")[state[i]]; if(i==ph) printf("[%c]", c); else printf(" %c ", c); } } printf(fmt, ph); #endif }
[ "void", "print_state", "(", "int", "N", ",", "PHIL", "*", "state", ",", "const", "char", "*", "fmt", ",", "int", "ph", ")", "{", "#if", "QUIET", "==", "0", "\n", "int", "i", ";", "if", "(", "N", "<", "100", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "char", "c", "=", "(", "\"", "\"", ")", "[", "state", "[", "i", "]", "]", ";", "if", "(", "i", "==", "ph", ")", "printf", "(", "\"", "\"", ",", "c", ")", ";", "else", "printf", "(", "\"", "\"", ",", "c", ")", ";", "}", "}", "printf", "(", "fmt", ",", "ph", ")", ";", "#endif", "}" ]
Prints the current state given a change (described by fmt) for philosopher ph
[ "Prints", "the", "current", "state", "given", "a", "change", "(", "described", "by", "fmt", ")", "for", "philosopher", "ph" ]
[]
[ { "param": "N", "type": "int" }, { "param": "state", "type": "PHIL" }, { "param": "fmt", "type": "char" }, { "param": "ph", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "N", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "state", "type": "PHIL", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fmt", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ph", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bf3e15c098fff9ff11947a60b15e29ce97a21c59
TedPap/opsys
symposium.c
[ "MIT" ]
C
trytoeat
void
void trytoeat(SymposiumTable* S, int i) { int N = S->symp->N; PHIL* state = S->state; if(state[i]==HUNGRY && state[LEFT(i,N)]!=EATING && state[RIGHT(i,N)]!=EATING) { state[i] = EATING; print_state(N, state, " %d is eating\n",i); Cond_Signal(&(S->hungry[i])); } }
/* Attempt to make a (hungry) philosopher i to start eating */
Attempt to make a (hungry) philosopher i to start eating
[ "Attempt", "to", "make", "a", "(", "hungry", ")", "philosopher", "i", "to", "start", "eating" ]
void trytoeat(SymposiumTable* S, int i) { int N = S->symp->N; PHIL* state = S->state; if(state[i]==HUNGRY && state[LEFT(i,N)]!=EATING && state[RIGHT(i,N)]!=EATING) { state[i] = EATING; print_state(N, state, " %d is eating\n",i); Cond_Signal(&(S->hungry[i])); } }
[ "void", "trytoeat", "(", "SymposiumTable", "*", "S", ",", "int", "i", ")", "{", "int", "N", "=", "S", "->", "symp", "->", "N", ";", "PHIL", "*", "state", "=", "S", "->", "state", ";", "if", "(", "state", "[", "i", "]", "==", "HUNGRY", "&&", "state", "[", "LEFT", "(", "i", ",", "N", ")", "]", "!=", "EATING", "&&", "state", "[", "RIGHT", "(", "i", ",", "N", ")", "]", "!=", "EATING", ")", "{", "state", "[", "i", "]", "=", "EATING", ";", "print_state", "(", "N", ",", "state", ",", "\"", "\\n", "\"", ",", "i", ")", ";", "Cond_Signal", "(", "&", "(", "S", "->", "hungry", "[", "i", "]", ")", ")", ";", "}", "}" ]
Attempt to make a (hungry) philosopher i to start eating
[ "Attempt", "to", "make", "a", "(", "hungry", ")", "philosopher", "i", "to", "start", "eating" ]
[]
[ { "param": "S", "type": "SymposiumTable" }, { "param": "i", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "S", "type": "SymposiumTable", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "i", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bf3e15c098fff9ff11947a60b15e29ce97a21c59
TedPap/opsys
symposium.c
[ "MIT" ]
C
SymposiumOfProcesses
int
int SymposiumOfProcesses(int argl, void* args) { assert(argl == sizeof(symposium_t)); symposium_t* symp = args; int N = symp->N; /* Initialize structures */ SymposiumTable S; SymposiumTable_init(&S, symp); /* Execute philosophers */ for(int i=0;i<N;i++) { philosopher_args Args; Args.i = i; Args.S = &S; Exec(PhilosopherProcess, sizeof(Args), &Args); } /* Wait for philosophers to exit */ for(int i=0;i<N;i++) { WaitChild(NOPROC, NULL); } SymposiumTable_destroy(&S); return 0; }
/* This process executes a "symposium" for a number of philosophers. */
This process executes a "symposium" for a number of philosophers.
[ "This", "process", "executes", "a", "\"", "symposium", "\"", "for", "a", "number", "of", "philosophers", "." ]
int SymposiumOfProcesses(int argl, void* args) { assert(argl == sizeof(symposium_t)); symposium_t* symp = args; int N = symp->N; SymposiumTable S; SymposiumTable_init(&S, symp); for(int i=0;i<N;i++) { philosopher_args Args; Args.i = i; Args.S = &S; Exec(PhilosopherProcess, sizeof(Args), &Args); } for(int i=0;i<N;i++) { WaitChild(NOPROC, NULL); } SymposiumTable_destroy(&S); return 0; }
[ "int", "SymposiumOfProcesses", "(", "int", "argl", ",", "void", "*", "args", ")", "{", "assert", "(", "argl", "==", "sizeof", "(", "symposium_t", ")", ")", ";", "symposium_t", "*", "symp", "=", "args", ";", "int", "N", "=", "symp", "->", "N", ";", "SymposiumTable", "S", ";", "SymposiumTable_init", "(", "&", "S", ",", "symp", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "philosopher_args", "Args", ";", "Args", ".", "i", "=", "i", ";", "Args", ".", "S", "=", "&", "S", ";", "Exec", "(", "PhilosopherProcess", ",", "sizeof", "(", "Args", ")", ",", "&", "Args", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "WaitChild", "(", "NOPROC", ",", "NULL", ")", ";", "}", "SymposiumTable_destroy", "(", "&", "S", ")", ";", "return", "0", ";", "}" ]
This process executes a "symposium" for a number of philosophers.
[ "This", "process", "executes", "a", "\"", "symposium", "\"", "for", "a", "number", "of", "philosophers", "." ]
[ "/* Initialize structures */", "/* Execute philosophers */", "/* Wait for philosophers to exit */" ]
[ { "param": "argl", "type": "int" }, { "param": "args", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argl", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "args", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bf3e15c098fff9ff11947a60b15e29ce97a21c59
TedPap/opsys
symposium.c
[ "MIT" ]
C
SymposiumOfThreads
int
int SymposiumOfThreads(int argl, void* args) { assert(argl == sizeof(symposium_t)); symposium_t* symp = args; int N = symp->N; /* Initialize structures */ SymposiumTable S; SymposiumTable_init(&S, symp); /* Execute philosophers */ Tid_t thread[symp->N]; for(int i=0;i<N;i++) { thread[i] = CreateThread(PhilosopherThread, i, &S); } /* Wait for philosophers to exit */ for(int i=0;i<N;i++) { ThreadJoin(thread[i],NULL); } SymposiumTable_destroy(&S); return 0; }
/* This process executes a "symposium" for a number of philosophers. Each philosopher is a thread. */
This process executes a "symposium" for a number of philosophers. Each philosopher is a thread.
[ "This", "process", "executes", "a", "\"", "symposium", "\"", "for", "a", "number", "of", "philosophers", ".", "Each", "philosopher", "is", "a", "thread", "." ]
int SymposiumOfThreads(int argl, void* args) { assert(argl == sizeof(symposium_t)); symposium_t* symp = args; int N = symp->N; SymposiumTable S; SymposiumTable_init(&S, symp); Tid_t thread[symp->N]; for(int i=0;i<N;i++) { thread[i] = CreateThread(PhilosopherThread, i, &S); } for(int i=0;i<N;i++) { ThreadJoin(thread[i],NULL); } SymposiumTable_destroy(&S); return 0; }
[ "int", "SymposiumOfThreads", "(", "int", "argl", ",", "void", "*", "args", ")", "{", "assert", "(", "argl", "==", "sizeof", "(", "symposium_t", ")", ")", ";", "symposium_t", "*", "symp", "=", "args", ";", "int", "N", "=", "symp", "->", "N", ";", "SymposiumTable", "S", ";", "SymposiumTable_init", "(", "&", "S", ",", "symp", ")", ";", "Tid_t", "thread", "[", "symp", "->", "N", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "thread", "[", "i", "]", "=", "CreateThread", "(", "PhilosopherThread", ",", "i", ",", "&", "S", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "N", ";", "i", "++", ")", "{", "ThreadJoin", "(", "thread", "[", "i", "]", ",", "NULL", ")", ";", "}", "SymposiumTable_destroy", "(", "&", "S", ")", ";", "return", "0", ";", "}" ]
This process executes a "symposium" for a number of philosophers.
[ "This", "process", "executes", "a", "\"", "symposium", "\"", "for", "a", "number", "of", "philosophers", "." ]
[ "/* Initialize structures */", "/* Execute philosophers */", "/* Wait for philosophers to exit */" ]
[ { "param": "argl", "type": "int" }, { "param": "args", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argl", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "args", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bede57b3ccbc03381c51469b2e5278229f96a851
TedPap/opsys
tinyos_shell.c
[ "MIT" ]
C
rsrv_listener_thread
int
static int rsrv_listener_thread(int port, void* __globals) { Fid_t lsock = Socket(port); if(Listen(lsock) == -1) { printf("Cannot listen to the given port: %d\n", port); return -1; } GS(listener_socket) = lsock; /* Accept loop */ while(1) { Fid_t sock = Accept(lsock); if(sock==NOFILE) { /* We failed! Check if we should quit */ if(GS(quit)) return 0; log_message(__globals, "listener(port=%d): failed to accept!\n", port); } else { GS(active_conn)++; GS(total_conn)++; Tid_t t = CreateThread(rsrv_client, sock, __globals); ThreadDetach(t); } } return 0; }
/* the thread that accepts new connections */
the thread that accepts new connections
[ "the", "thread", "that", "accepts", "new", "connections" ]
static int rsrv_listener_thread(int port, void* __globals) { Fid_t lsock = Socket(port); if(Listen(lsock) == -1) { printf("Cannot listen to the given port: %d\n", port); return -1; } GS(listener_socket) = lsock; while(1) { Fid_t sock = Accept(lsock); if(sock==NOFILE) { if(GS(quit)) return 0; log_message(__globals, "listener(port=%d): failed to accept!\n", port); } else { GS(active_conn)++; GS(total_conn)++; Tid_t t = CreateThread(rsrv_client, sock, __globals); ThreadDetach(t); } } return 0; }
[ "static", "int", "rsrv_listener_thread", "(", "int", "port", ",", "void", "*", "__globals", ")", "{", "Fid_t", "lsock", "=", "Socket", "(", "port", ")", ";", "if", "(", "Listen", "(", "lsock", ")", "==", "-1", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "port", ")", ";", "return", "-1", ";", "}", "GS", "(", "listener_socket", ")", "=", "lsock", ";", "while", "(", "1", ")", "{", "Fid_t", "sock", "=", "Accept", "(", "lsock", ")", ";", "if", "(", "sock", "==", "NOFILE", ")", "{", "if", "(", "GS", "(", "quit", ")", ")", "return", "0", ";", "log_message", "(", "__globals", ",", "\"", "\\n", "\"", ",", "port", ")", ";", "}", "else", "{", "GS", "(", "active_conn", ")", "++", ";", "GS", "(", "total_conn", ")", "++", ";", "Tid_t", "t", "=", "CreateThread", "(", "rsrv_client", ",", "sock", ",", "__globals", ")", ";", "ThreadDetach", "(", "t", ")", ";", "}", "}", "return", "0", ";", "}" ]
the thread that accepts new connections
[ "the", "thread", "that", "accepts", "new", "connections" ]
[ "/* Accept loop */", "/* We failed! Check if we should quit */" ]
[ { "param": "port", "type": "int" }, { "param": "__globals", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "port", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "__globals", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bede57b3ccbc03381c51469b2e5278229f96a851
TedPap/opsys
tinyos_shell.c
[ "MIT" ]
C
log_print
void
static void log_print(void* __globals) { Mutex_Lock(& GS(mx)); for(rlnode* ptr = GS(log).next; ptr != &GS(log); ptr=ptr->next) { logrec *rec = (logrec*)ptr; printf("%6d: %s\n", rec->node.num, rec->message); } Mutex_Unlock(& GS(mx)); }
/* Print the log to the console */
Print the log to the console
[ "Print", "the", "log", "to", "the", "console" ]
static void log_print(void* __globals) { Mutex_Lock(& GS(mx)); for(rlnode* ptr = GS(log).next; ptr != &GS(log); ptr=ptr->next) { logrec *rec = (logrec*)ptr; printf("%6d: %s\n", rec->node.num, rec->message); } Mutex_Unlock(& GS(mx)); }
[ "static", "void", "log_print", "(", "void", "*", "__globals", ")", "{", "Mutex_Lock", "(", "&", "GS", "(", "mx", ")", ")", ";", "for", "(", "rlnode", "*", "ptr", "=", "GS", "(", "log", ")", ".", "next", ";", "ptr", "!=", "&", "GS", "(", "log", ")", ";", "ptr", "=", "ptr", "->", "next", ")", "{", "logrec", "*", "rec", "=", "(", "logrec", "*", ")", "ptr", ";", "printf", "(", "\"", "\\n", "\"", ",", "rec", "->", "node", ".", "num", ",", "rec", "->", "message", ")", ";", "}", "Mutex_Unlock", "(", "&", "GS", "(", "mx", ")", ")", ";", "}" ]
Print the log to the console
[ "Print", "the", "log", "to", "the", "console" ]
[]
[ { "param": "__globals", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "__globals", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bede57b3ccbc03381c51469b2e5278229f96a851
TedPap/opsys
tinyos_shell.c
[ "MIT" ]
C
rsrv_process
int
static int rsrv_process(size_t argc, const char** argv) { checkargs(2); Fid_t sock = atoi(argv[1]); /* Fix the streams */ assert(sock!=0 && sock!=1); Dup2(sock, 0); Dup2(sock, 1); Close(sock); /* (a) find the command */ int c = getprog(2); if(c==-1) { /* This will appear in the rcli console */ printf("Error in remote process: Command %s is not found\n", argv[2]); return -1; } Program proc = COMMANDS[c].prog; /* Execute */ int exitstatus; WaitChild(Execute(proc, argc-2, argv+2), &exitstatus); return exitstatus; }
/* Helper to execute a remote process */
Helper to execute a remote process
[ "Helper", "to", "execute", "a", "remote", "process" ]
static int rsrv_process(size_t argc, const char** argv) { checkargs(2); Fid_t sock = atoi(argv[1]); assert(sock!=0 && sock!=1); Dup2(sock, 0); Dup2(sock, 1); Close(sock); int c = getprog(2); if(c==-1) { printf("Error in remote process: Command %s is not found\n", argv[2]); return -1; } Program proc = COMMANDS[c].prog; int exitstatus; WaitChild(Execute(proc, argc-2, argv+2), &exitstatus); return exitstatus; }
[ "static", "int", "rsrv_process", "(", "size_t", "argc", ",", "const", "char", "*", "*", "argv", ")", "{", "checkargs", "(", "2", ")", ";", "Fid_t", "sock", "=", "atoi", "(", "argv", "[", "1", "]", ")", ";", "assert", "(", "sock", "!=", "0", "&&", "sock", "!=", "1", ")", ";", "Dup2", "(", "sock", ",", "0", ")", ";", "Dup2", "(", "sock", ",", "1", ")", ";", "Close", "(", "sock", ")", ";", "int", "c", "=", "getprog", "(", "2", ")", ";", "if", "(", "c", "==", "-1", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "argv", "[", "2", "]", ")", ";", "return", "-1", ";", "}", "Program", "proc", "=", "COMMANDS", "[", "c", "]", ".", "prog", ";", "int", "exitstatus", ";", "WaitChild", "(", "Execute", "(", "proc", ",", "argc", "-", "2", ",", "argv", "+", "2", ")", ",", "&", "exitstatus", ")", ";", "return", "exitstatus", ";", "}" ]
Helper to execute a remote process
[ "Helper", "to", "execute", "a", "remote", "process" ]
[ "/* Fix the streams */", "/* (a) find the command */", "/* This will appear in the rcli console */", "/* Execute */" ]
[ { "param": "argc", "type": "size_t" }, { "param": "argv", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argc", "type": "size_t", "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": [] }
bede57b3ccbc03381c51469b2e5278229f96a851
TedPap/opsys
tinyos_shell.c
[ "MIT" ]
C
rsrv_client
int
static int rsrv_client(int sock, void* __globals) { /* Get your client id */ Mutex_Lock(&GS(mx)); size_t ID = ++GS(conn_id_counter); Mutex_Unlock(&GS(mx)); log_message(__globals, "Client[%6zu]: started", ID); /* Get the command from the client. The protocol is [int argl, void* args] where argl is the length of the subsequent message args. */ int argl; if(! recv_message(sock, &argl, sizeof(argl))) { log_message(__globals, "Cliend[%6zu]: error in receiving request, aborting", ID); goto finish; } assert(argl>0 && argl <= 2048); { char args[argl]; if(! recv_message(sock, args, argl)) { log_message(__globals, "Cliend[%6zu]: error in receiving request, aborting", ID); goto finish; } /* Prepare to execute subprocess */ size_t argc = argscount(argl, args); const char* argv[argc+2]; argv[0] = "rsrv_process"; char sock_value[32]; sprintf(sock_value, "%d", sock); argv[1] = sock_value; argvunpack(argc, argv+2, argl, args); /* Now, execute the message in a new process */ int exitstatus; Pid_t pid = Execute(rsrv_process, argc+2, argv); Close(sock); WaitChild(pid, &exitstatus); log_message(__globals, "Client[%6zu]: finished with status %d", ID, exitstatus); } finish: Mutex_Lock(&GS(mx)); GS(active_conn)--; Cond_Broadcast(& GS(conn_done)); Mutex_Unlock(&GS(mx)); return 0; }
/* this server thread serves a remote cliend */
this server thread serves a remote cliend
[ "this", "server", "thread", "serves", "a", "remote", "cliend" ]
static int rsrv_client(int sock, void* __globals) { Mutex_Lock(&GS(mx)); size_t ID = ++GS(conn_id_counter); Mutex_Unlock(&GS(mx)); log_message(__globals, "Client[%6zu]: started", ID); int argl; if(! recv_message(sock, &argl, sizeof(argl))) { log_message(__globals, "Cliend[%6zu]: error in receiving request, aborting", ID); goto finish; } assert(argl>0 && argl <= 2048); { char args[argl]; if(! recv_message(sock, args, argl)) { log_message(__globals, "Cliend[%6zu]: error in receiving request, aborting", ID); goto finish; } size_t argc = argscount(argl, args); const char* argv[argc+2]; argv[0] = "rsrv_process"; char sock_value[32]; sprintf(sock_value, "%d", sock); argv[1] = sock_value; argvunpack(argc, argv+2, argl, args); int exitstatus; Pid_t pid = Execute(rsrv_process, argc+2, argv); Close(sock); WaitChild(pid, &exitstatus); log_message(__globals, "Client[%6zu]: finished with status %d", ID, exitstatus); } finish: Mutex_Lock(&GS(mx)); GS(active_conn)--; Cond_Broadcast(& GS(conn_done)); Mutex_Unlock(&GS(mx)); return 0; }
[ "static", "int", "rsrv_client", "(", "int", "sock", ",", "void", "*", "__globals", ")", "{", "Mutex_Lock", "(", "&", "GS", "(", "mx", ")", ")", ";", "size_t", "ID", "=", "++", "GS", "(", "conn_id_counter", ")", ";", "Mutex_Unlock", "(", "&", "GS", "(", "mx", ")", ")", ";", "log_message", "(", "__globals", ",", "\"", "\"", ",", "ID", ")", ";", "int", "argl", ";", "if", "(", "!", "recv_message", "(", "sock", ",", "&", "argl", ",", "sizeof", "(", "argl", ")", ")", ")", "{", "log_message", "(", "__globals", ",", "\"", "\"", ",", "ID", ")", ";", "goto", "finish", ";", "}", "assert", "(", "argl", ">", "0", "&&", "argl", "<=", "2048", ")", ";", "{", "char", "args", "[", "argl", "]", ";", "if", "(", "!", "recv_message", "(", "sock", ",", "args", ",", "argl", ")", ")", "{", "log_message", "(", "__globals", ",", "\"", "\"", ",", "ID", ")", ";", "goto", "finish", ";", "}", "size_t", "argc", "=", "argscount", "(", "argl", ",", "args", ")", ";", "const", "char", "*", "argv", "[", "argc", "+", "2", "]", ";", "argv", "[", "0", "]", "=", "\"", "\"", ";", "char", "sock_value", "[", "32", "]", ";", "sprintf", "(", "sock_value", ",", "\"", "\"", ",", "sock", ")", ";", "argv", "[", "1", "]", "=", "sock_value", ";", "argvunpack", "(", "argc", ",", "argv", "+", "2", ",", "argl", ",", "args", ")", ";", "int", "exitstatus", ";", "Pid_t", "pid", "=", "Execute", "(", "rsrv_process", ",", "argc", "+", "2", ",", "argv", ")", ";", "Close", "(", "sock", ")", ";", "WaitChild", "(", "pid", ",", "&", "exitstatus", ")", ";", "log_message", "(", "__globals", ",", "\"", "\"", ",", "ID", ",", "exitstatus", ")", ";", "}", "finish", ":", "Mutex_Lock", "(", "&", "GS", "(", "mx", ")", ")", ";", "GS", "(", "active_conn", ")", "--", ";", "Cond_Broadcast", "(", "&", "GS", "(", "conn_done", ")", ")", ";", "Mutex_Unlock", "(", "&", "GS", "(", "mx", ")", ")", ";", "return", "0", ";", "}" ]
this server thread serves a remote cliend
[ "this", "server", "thread", "serves", "a", "remote", "cliend" ]
[ "/* Get your client id */", "/* Get the command from the client. The protocol is\n\t [int argl, void* args] where argl is the length of\n\t the subsequent message args.\n\t */", "/* Prepare to execute subprocess */", "/* Now, execute the message in a new process */" ]
[ { "param": "sock", "type": "int" }, { "param": "__globals", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sock", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "__globals", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bede57b3ccbc03381c51469b2e5278229f96a851
TedPap/opsys
tinyos_shell.c
[ "MIT" ]
C
process_builtin
int
int process_builtin(int argc, const char** argv) { if(strcmp(argv[0], "?")==0) { printf("Type 'help' for help, 'exit' to quit.\n"); return 1; } return 0; }
/************************************* A very simple shell for tinyos ***************************************/
A very simple shell for tinyos
[ "A", "very", "simple", "shell", "for", "tinyos" ]
int process_builtin(int argc, const char** argv) { if(strcmp(argv[0], "?")==0) { printf("Type 'help' for help, 'exit' to quit.\n"); return 1; } return 0; }
[ "int", "process_builtin", "(", "int", "argc", ",", "const", "char", "*", "*", "argv", ")", "{", "if", "(", "strcmp", "(", "argv", "[", "0", "]", ",", "\"", "\"", ")", "==", "0", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "1", ";", "}", "return", "0", ";", "}" ]
A very simple shell for tinyos
[ "A", "very", "simple", "shell", "for", "tinyos" ]
[]
[ { "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": [] }
083742a27aa2396bccbe0530499f9f060fdb2a0d
TedPap/opsys
kernel_pipe.c
[ "MIT" ]
C
pipe_read
int
int pipe_read(void* ptr, char *buf, unsigned int size) { int i = 0; bool err = false; PICB* picb = (PICB*) ptr; Mutex_Lock(& picb->spinlock); /** Error check */ if (picb->pfcb[1]->refcount == 0) { if (picb->balance <= 0) err = true; } /** While buffer doesn't have enough bytes to read, wait on picb's cv */ while (picb->balance < size && picb->pfcb[1]->refcount != 0) Cond_Wait(& picb->spinlock, & picb->buff_full); /** Read size amount of bytes into buf */ while ( i < size && i < buffer_size && picb->balance > 0) { buf[i] = picb->puffer[i]; i++; picb->balance--; } Mutex_Unlock(& picb->spinlock); switch (err){ case true: return 0; case false: return i; } return 0; }
/** Read size amount of bytes from the pipe buffer to the buf */
Read size amount of bytes from the pipe buffer to the buf
[ "Read", "size", "amount", "of", "bytes", "from", "the", "pipe", "buffer", "to", "the", "buf" ]
int pipe_read(void* ptr, char *buf, unsigned int size) { int i = 0; bool err = false; PICB* picb = (PICB*) ptr; Mutex_Lock(& picb->spinlock); if (picb->pfcb[1]->refcount == 0) { if (picb->balance <= 0) err = true; } while (picb->balance < size && picb->pfcb[1]->refcount != 0) Cond_Wait(& picb->spinlock, & picb->buff_full); while ( i < size && i < buffer_size && picb->balance > 0) { buf[i] = picb->puffer[i]; i++; picb->balance--; } Mutex_Unlock(& picb->spinlock); switch (err){ case true: return 0; case false: return i; } return 0; }
[ "int", "pipe_read", "(", "void", "*", "ptr", ",", "char", "*", "buf", ",", "unsigned", "int", "size", ")", "{", "int", "i", "=", "0", ";", "bool", "err", "=", "false", ";", "PICB", "*", "picb", "=", "(", "PICB", "*", ")", "ptr", ";", "Mutex_Lock", "(", "&", "picb", "->", "spinlock", ")", ";", "if", "(", "picb", "->", "pfcb", "[", "1", "]", "->", "refcount", "==", "0", ")", "{", "if", "(", "picb", "->", "balance", "<=", "0", ")", "err", "=", "true", ";", "}", "while", "(", "picb", "->", "balance", "<", "size", "&&", "picb", "->", "pfcb", "[", "1", "]", "->", "refcount", "!=", "0", ")", "Cond_Wait", "(", "&", "picb", "->", "spinlock", ",", "&", "picb", "->", "buff_full", ")", ";", "while", "(", "i", "<", "size", "&&", "i", "<", "buffer_size", "&&", "picb", "->", "balance", ">", "0", ")", "{", "buf", "[", "i", "]", "=", "picb", "->", "puffer", "[", "i", "]", ";", "i", "++", ";", "picb", "->", "balance", "--", ";", "}", "Mutex_Unlock", "(", "&", "picb", "->", "spinlock", ")", ";", "switch", "(", "err", ")", "{", "case", "true", ":", "return", "0", ";", "case", "false", ":", "return", "i", ";", "}", "return", "0", ";", "}" ]
Read size amount of bytes from the pipe buffer to the buf
[ "Read", "size", "amount", "of", "bytes", "from", "the", "pipe", "buffer", "to", "the", "buf" ]
[ "/** Error check */", "/** While buffer doesn't have enough bytes to read, wait on picb's cv */", "/** Read size amount of bytes into buf */" ]
[ { "param": "ptr", "type": "void" }, { "param": "buf", "type": "char" }, { "param": "size", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ptr", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
083742a27aa2396bccbe0530499f9f060fdb2a0d
TedPap/opsys
kernel_pipe.c
[ "MIT" ]
C
pipe_write
int
int pipe_write(void* ptr, const char* buf, unsigned int size) { int i = 0; bool err = false; PICB* picb = (PICB*) ptr; /** Error check */ if (picb->pfcb[0]->refcount == 0) err = true; /** When buffer is full signal reader */ if (picb->balance >= buffer_size) { Cond_Broadcast(& picb->buff_full); } /** Write the bytes */ while (i < size && i < buffer_size) { picb->puffer[i] = buf[i]; i++; picb->balance++; } Mutex_Unlock(& picb->spinlock); switch (err){ case true: return -1; case false: return i; } return -1; }
/** Write size amount of bytes from buf to pipe's buffer. */
Write size amount of bytes from buf to pipe's buffer.
[ "Write", "size", "amount", "of", "bytes", "from", "buf", "to", "pipe", "'", "s", "buffer", "." ]
int pipe_write(void* ptr, const char* buf, unsigned int size) { int i = 0; bool err = false; PICB* picb = (PICB*) ptr; if (picb->pfcb[0]->refcount == 0) err = true; if (picb->balance >= buffer_size) { Cond_Broadcast(& picb->buff_full); } while (i < size && i < buffer_size) { picb->puffer[i] = buf[i]; i++; picb->balance++; } Mutex_Unlock(& picb->spinlock); switch (err){ case true: return -1; case false: return i; } return -1; }
[ "int", "pipe_write", "(", "void", "*", "ptr", ",", "const", "char", "*", "buf", ",", "unsigned", "int", "size", ")", "{", "int", "i", "=", "0", ";", "bool", "err", "=", "false", ";", "PICB", "*", "picb", "=", "(", "PICB", "*", ")", "ptr", ";", "if", "(", "picb", "->", "pfcb", "[", "0", "]", "->", "refcount", "==", "0", ")", "err", "=", "true", ";", "if", "(", "picb", "->", "balance", ">=", "buffer_size", ")", "{", "Cond_Broadcast", "(", "&", "picb", "->", "buff_full", ")", ";", "}", "while", "(", "i", "<", "size", "&&", "i", "<", "buffer_size", ")", "{", "picb", "->", "puffer", "[", "i", "]", "=", "buf", "[", "i", "]", ";", "i", "++", ";", "picb", "->", "balance", "++", ";", "}", "Mutex_Unlock", "(", "&", "picb", "->", "spinlock", ")", ";", "switch", "(", "err", ")", "{", "case", "true", ":", "return", "-1", ";", "case", "false", ":", "return", "i", ";", "}", "return", "-1", ";", "}" ]
Write size amount of bytes from buf to pipe's buffer.
[ "Write", "size", "amount", "of", "bytes", "from", "buf", "to", "pipe", "'", "s", "buffer", "." ]
[ "/** Error check */", "/** When buffer is full signal reader */", "/** Write the bytes */" ]
[ { "param": "ptr", "type": "void" }, { "param": "buf", "type": "char" }, { "param": "size", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ptr", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
af3f79b15474b48e50ada8bbaa1635003ceaa667
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesLeitura.c
[ "MIT" ]
C
le_cabecalho_veiculo
cabecalho_veiculo
cabecalho_veiculo *le_cabecalho_veiculo(FILE *fp_bin) { cabecalho_veiculo *cabecalho = (cabecalho_veiculo*) malloc(sizeof(cabecalho_veiculo)); fseek(fp_bin, 0, SEEK_SET); fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descrevePrefixo, sizeof(char), 18, fp_bin); fread(&cabecalho->descreveData, sizeof(char), 35, fp_bin); fread(&cabecalho->descreveLugares, sizeof(char), 42, fp_bin); fread(&cabecalho->descreveLinha, sizeof(char), 26, fp_bin); fread(&cabecalho->descreveModelo, sizeof(char), 17, fp_bin); fread(&cabecalho->descreveCategoria, sizeof(char), 20, fp_bin); return cabecalho; }
//Funcao responsavle pela leitura do cabecalho dos veiculos no arquivo binario
Funcao responsavle pela leitura do cabecalho dos veiculos no arquivo binario
[ "Funcao", "responsavle", "pela", "leitura", "do", "cabecalho", "dos", "veiculos", "no", "arquivo", "binario" ]
cabecalho_veiculo *le_cabecalho_veiculo(FILE *fp_bin) { cabecalho_veiculo *cabecalho = (cabecalho_veiculo*) malloc(sizeof(cabecalho_veiculo)); fseek(fp_bin, 0, SEEK_SET); fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descrevePrefixo, sizeof(char), 18, fp_bin); fread(&cabecalho->descreveData, sizeof(char), 35, fp_bin); fread(&cabecalho->descreveLugares, sizeof(char), 42, fp_bin); fread(&cabecalho->descreveLinha, sizeof(char), 26, fp_bin); fread(&cabecalho->descreveModelo, sizeof(char), 17, fp_bin); fread(&cabecalho->descreveCategoria, sizeof(char), 20, fp_bin); return cabecalho; }
[ "cabecalho_veiculo", "*", "le_cabecalho_veiculo", "(", "FILE", "*", "fp_bin", ")", "{", "cabecalho_veiculo", "*", "cabecalho", "=", "(", "cabecalho_veiculo", "*", ")", "malloc", "(", "sizeof", "(", "cabecalho_veiculo", ")", ")", ";", "fseek", "(", "fp_bin", ",", "0", ",", "SEEK_SET", ")", ";", "fread", "(", "&", "cabecalho", "->", "status", ",", "sizeof", "(", "char", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "byteProxReg", ",", "sizeof", "(", "long", "long", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegistros", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegRemovidos", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descrevePrefixo", ",", "sizeof", "(", "char", ")", ",", "18", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveData", ",", "sizeof", "(", "char", ")", ",", "35", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveLugares", ",", "sizeof", "(", "char", ")", ",", "42", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveLinha", ",", "sizeof", "(", "char", ")", ",", "26", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveModelo", ",", "sizeof", "(", "char", ")", ",", "17", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCategoria", ",", "sizeof", "(", "char", ")", ",", "20", ",", "fp_bin", ")", ";", "return", "cabecalho", ";", "}" ]
Funcao responsavle pela leitura do cabecalho dos veiculos no arquivo binario
[ "Funcao", "responsavle", "pela", "leitura", "do", "cabecalho", "dos", "veiculos", "no", "arquivo", "binario" ]
[]
[ { "param": "fp_bin", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp_bin", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
af3f79b15474b48e50ada8bbaa1635003ceaa667
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesLeitura.c
[ "MIT" ]
C
recebe_dados_veiculo
void
void recebe_dados_veiculo(FILE *fp_bin, dados_veiculo *dados){ fread(&dados->prefixo, sizeof(char), 5, fp_bin); dados->prefixo[5] = '\0'; fread(&dados->data, sizeof(char), 10, fp_bin); dados->data[11] = '\0'; fread(&dados->quantidadeLugares, sizeof(int), 1, fp_bin); fread(&dados->codLinha, sizeof(int), 1, fp_bin); fread(&dados->tamanhoModelo, sizeof(int), 1, fp_bin); dados->modelo = (char*) malloc((dados->tamanhoModelo+1) * sizeof(char)); fread(dados->modelo, sizeof(char), dados->tamanhoModelo, fp_bin); dados->modelo [dados->tamanhoModelo] = '\0'; fread(&dados->tamanhoCategoria, sizeof(int), 1, fp_bin); dados->categoria = (char*) malloc((dados->tamanhoCategoria+1) * sizeof(char)); fread(dados->categoria, sizeof(char), dados->tamanhoCategoria, fp_bin); dados->categoria [dados->tamanhoCategoria] = '\0'; }
//Funcao responsavel pela leitura dos campos do registro no arquivo binario veiculos
Funcao responsavel pela leitura dos campos do registro no arquivo binario veiculos
[ "Funcao", "responsavel", "pela", "leitura", "dos", "campos", "do", "registro", "no", "arquivo", "binario", "veiculos" ]
void recebe_dados_veiculo(FILE *fp_bin, dados_veiculo *dados){ fread(&dados->prefixo, sizeof(char), 5, fp_bin); dados->prefixo[5] = '\0'; fread(&dados->data, sizeof(char), 10, fp_bin); dados->data[11] = '\0'; fread(&dados->quantidadeLugares, sizeof(int), 1, fp_bin); fread(&dados->codLinha, sizeof(int), 1, fp_bin); fread(&dados->tamanhoModelo, sizeof(int), 1, fp_bin); dados->modelo = (char*) malloc((dados->tamanhoModelo+1) * sizeof(char)); fread(dados->modelo, sizeof(char), dados->tamanhoModelo, fp_bin); dados->modelo [dados->tamanhoModelo] = '\0'; fread(&dados->tamanhoCategoria, sizeof(int), 1, fp_bin); dados->categoria = (char*) malloc((dados->tamanhoCategoria+1) * sizeof(char)); fread(dados->categoria, sizeof(char), dados->tamanhoCategoria, fp_bin); dados->categoria [dados->tamanhoCategoria] = '\0'; }
[ "void", "recebe_dados_veiculo", "(", "FILE", "*", "fp_bin", ",", "dados_veiculo", "*", "dados", ")", "{", "fread", "(", "&", "dados", "->", "prefixo", ",", "sizeof", "(", "char", ")", ",", "5", ",", "fp_bin", ")", ";", "dados", "->", "prefixo", "[", "5", "]", "=", "'", "\\0", "'", ";", "fread", "(", "&", "dados", "->", "data", ",", "sizeof", "(", "char", ")", ",", "10", ",", "fp_bin", ")", ";", "dados", "->", "data", "[", "11", "]", "=", "'", "\\0", "'", ";", "fread", "(", "&", "dados", "->", "quantidadeLugares", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "dados", "->", "codLinha", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "dados", "->", "tamanhoModelo", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "dados", "->", "modelo", "=", "(", "char", "*", ")", "malloc", "(", "(", "dados", "->", "tamanhoModelo", "+", "1", ")", "*", "sizeof", "(", "char", ")", ")", ";", "fread", "(", "dados", "->", "modelo", ",", "sizeof", "(", "char", ")", ",", "dados", "->", "tamanhoModelo", ",", "fp_bin", ")", ";", "dados", "->", "modelo", "[", "dados", "->", "tamanhoModelo", "]", "=", "'", "\\0", "'", ";", "fread", "(", "&", "dados", "->", "tamanhoCategoria", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "dados", "->", "categoria", "=", "(", "char", "*", ")", "malloc", "(", "(", "dados", "->", "tamanhoCategoria", "+", "1", ")", "*", "sizeof", "(", "char", ")", ")", ";", "fread", "(", "dados", "->", "categoria", ",", "sizeof", "(", "char", ")", ",", "dados", "->", "tamanhoCategoria", ",", "fp_bin", ")", ";", "dados", "->", "categoria", "[", "dados", "->", "tamanhoCategoria", "]", "=", "'", "\\0", "'", ";", "}" ]
Funcao responsavel pela leitura dos campos do registro no arquivo binario veiculos
[ "Funcao", "responsavel", "pela", "leitura", "dos", "campos", "do", "registro", "no", "arquivo", "binario", "veiculos" ]
[]
[ { "param": "fp_bin", "type": "FILE" }, { "param": "dados", "type": "dados_veiculo" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp_bin", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dados", "type": "dados_veiculo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
af3f79b15474b48e50ada8bbaa1635003ceaa667
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesLeitura.c
[ "MIT" ]
C
le_cabecalho_linha
cabecalho_linha
cabecalho_linha *le_cabecalho_linha(FILE *fp_bin){ cabecalho_linha *cabecalho = (cabecalho_linha*) malloc(sizeof(cabecalho_linha)); fseek(fp_bin, 0, SEEK_SET); fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descreveCodigo, sizeof(char), 15, fp_bin); fread(&cabecalho->descreveCartao, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveNome, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveCor, sizeof(char), 24, fp_bin); return cabecalho; }
//Funcao responsavel pela leitura do cabecalho das linhas no arquivo binario
Funcao responsavel pela leitura do cabecalho das linhas no arquivo binario
[ "Funcao", "responsavel", "pela", "leitura", "do", "cabecalho", "das", "linhas", "no", "arquivo", "binario" ]
cabecalho_linha *le_cabecalho_linha(FILE *fp_bin){ cabecalho_linha *cabecalho = (cabecalho_linha*) malloc(sizeof(cabecalho_linha)); fseek(fp_bin, 0, SEEK_SET); fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descreveCodigo, sizeof(char), 15, fp_bin); fread(&cabecalho->descreveCartao, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveNome, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveCor, sizeof(char), 24, fp_bin); return cabecalho; }
[ "cabecalho_linha", "*", "le_cabecalho_linha", "(", "FILE", "*", "fp_bin", ")", "{", "cabecalho_linha", "*", "cabecalho", "=", "(", "cabecalho_linha", "*", ")", "malloc", "(", "sizeof", "(", "cabecalho_linha", ")", ")", ";", "fseek", "(", "fp_bin", ",", "0", ",", "SEEK_SET", ")", ";", "fread", "(", "&", "cabecalho", "->", "status", ",", "sizeof", "(", "char", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "byteProxReg", ",", "sizeof", "(", "long", "long", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegistros", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegRemovidos", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCodigo", ",", "sizeof", "(", "char", ")", ",", "15", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCartao", ",", "sizeof", "(", "char", ")", ",", "13", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveNome", ",", "sizeof", "(", "char", ")", ",", "13", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCor", ",", "sizeof", "(", "char", ")", ",", "24", ",", "fp_bin", ")", ";", "return", "cabecalho", ";", "}" ]
Funcao responsavel pela leitura do cabecalho das linhas no arquivo binario
[ "Funcao", "responsavel", "pela", "leitura", "do", "cabecalho", "das", "linhas", "no", "arquivo", "binario" ]
[]
[ { "param": "fp_bin", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp_bin", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
af3f79b15474b48e50ada8bbaa1635003ceaa667
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesLeitura.c
[ "MIT" ]
C
recebe_dados_linha
void
void recebe_dados_linha(FILE *fp_bin, dados_linha *dados){ fread(&dados->codLinha, sizeof(int), 1, fp_bin); fread(&dados->aceitaCartao, sizeof(char), 1, fp_bin); fread(&dados->tamanhoNome, sizeof(int), 1, fp_bin); dados->nomeLinha = (char*) malloc((dados->tamanhoNome+1) * sizeof(char)); fread(dados->nomeLinha, sizeof(char), dados->tamanhoNome, fp_bin); dados->nomeLinha [dados->tamanhoNome] = '\0'; fread(&dados->tamanhoCor, sizeof(int), 1, fp_bin); dados->corLinha = (char*) malloc((dados->tamanhoCor+1) * sizeof(char)); fread(dados->corLinha, sizeof(char), dados->tamanhoCor, fp_bin); dados->corLinha [dados->tamanhoCor] = '\0'; }
//Funcao responsavel pela leitura dos campos do registro no arquivo binario linhas
Funcao responsavel pela leitura dos campos do registro no arquivo binario linhas
[ "Funcao", "responsavel", "pela", "leitura", "dos", "campos", "do", "registro", "no", "arquivo", "binario", "linhas" ]
void recebe_dados_linha(FILE *fp_bin, dados_linha *dados){ fread(&dados->codLinha, sizeof(int), 1, fp_bin); fread(&dados->aceitaCartao, sizeof(char), 1, fp_bin); fread(&dados->tamanhoNome, sizeof(int), 1, fp_bin); dados->nomeLinha = (char*) malloc((dados->tamanhoNome+1) * sizeof(char)); fread(dados->nomeLinha, sizeof(char), dados->tamanhoNome, fp_bin); dados->nomeLinha [dados->tamanhoNome] = '\0'; fread(&dados->tamanhoCor, sizeof(int), 1, fp_bin); dados->corLinha = (char*) malloc((dados->tamanhoCor+1) * sizeof(char)); fread(dados->corLinha, sizeof(char), dados->tamanhoCor, fp_bin); dados->corLinha [dados->tamanhoCor] = '\0'; }
[ "void", "recebe_dados_linha", "(", "FILE", "*", "fp_bin", ",", "dados_linha", "*", "dados", ")", "{", "fread", "(", "&", "dados", "->", "codLinha", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "dados", "->", "aceitaCartao", ",", "sizeof", "(", "char", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "dados", "->", "tamanhoNome", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "dados", "->", "nomeLinha", "=", "(", "char", "*", ")", "malloc", "(", "(", "dados", "->", "tamanhoNome", "+", "1", ")", "*", "sizeof", "(", "char", ")", ")", ";", "fread", "(", "dados", "->", "nomeLinha", ",", "sizeof", "(", "char", ")", ",", "dados", "->", "tamanhoNome", ",", "fp_bin", ")", ";", "dados", "->", "nomeLinha", "[", "dados", "->", "tamanhoNome", "]", "=", "'", "\\0", "'", ";", "fread", "(", "&", "dados", "->", "tamanhoCor", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "dados", "->", "corLinha", "=", "(", "char", "*", ")", "malloc", "(", "(", "dados", "->", "tamanhoCor", "+", "1", ")", "*", "sizeof", "(", "char", ")", ")", ";", "fread", "(", "dados", "->", "corLinha", ",", "sizeof", "(", "char", ")", ",", "dados", "->", "tamanhoCor", ",", "fp_bin", ")", ";", "dados", "->", "corLinha", "[", "dados", "->", "tamanhoCor", "]", "=", "'", "\\0", "'", ";", "}" ]
Funcao responsavel pela leitura dos campos do registro no arquivo binario linhas
[ "Funcao", "responsavel", "pela", "leitura", "dos", "campos", "do", "registro", "no", "arquivo", "binario", "linhas" ]
[]
[ { "param": "fp_bin", "type": "FILE" }, { "param": "dados", "type": "dados_linha" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp_bin", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dados", "type": "dados_linha", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d43650796aad2b7adf6abb594753694807146bb3
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesEscrita.c
[ "MIT" ]
C
printa_veiculo
void
void printa_veiculo(dados_veiculo *dados, cabecalho_veiculo *cabecalho){ for(int i = 0; i < 18; i++) printf("%c", cabecalho->descrevePrefixo[i]); printf(": %s\n", dados->prefixo); for(int i = 0; i < 17; i++) printf("%c", cabecalho->descreveModelo[i]); if(dados->tamanhoModelo == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->modelo); for(int i = 0 ; i < 20 ; i++) printf("%c", cabecalho->descreveCategoria[i]); if(dados->tamanhoCategoria == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->categoria); for(int i = 0 ; i < 35 ; i++) printf("%c", cabecalho->descreveData[i]); printf(": "); if(dados->data[0] != '\0') converte_e_printa_data(dados->data); else printf("campo com valor nulo"); printf("\n"); for(int i = 0 ; i < 42 ; i++) printf("%c", cabecalho->descreveLugares[i]); if(dados->quantidadeLugares == -1) printf(": campo com valor nulo\n"); else printf(": %d\n", dados->quantidadeLugares); }
//Funcao responsavel pela simples impressao dos dados na tela usando a struct cabecalho e a struct dados
Funcao responsavel pela simples impressao dos dados na tela usando a struct cabecalho e a struct dados
[ "Funcao", "responsavel", "pela", "simples", "impressao", "dos", "dados", "na", "tela", "usando", "a", "struct", "cabecalho", "e", "a", "struct", "dados" ]
void printa_veiculo(dados_veiculo *dados, cabecalho_veiculo *cabecalho){ for(int i = 0; i < 18; i++) printf("%c", cabecalho->descrevePrefixo[i]); printf(": %s\n", dados->prefixo); for(int i = 0; i < 17; i++) printf("%c", cabecalho->descreveModelo[i]); if(dados->tamanhoModelo == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->modelo); for(int i = 0 ; i < 20 ; i++) printf("%c", cabecalho->descreveCategoria[i]); if(dados->tamanhoCategoria == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->categoria); for(int i = 0 ; i < 35 ; i++) printf("%c", cabecalho->descreveData[i]); printf(": "); if(dados->data[0] != '\0') converte_e_printa_data(dados->data); else printf("campo com valor nulo"); printf("\n"); for(int i = 0 ; i < 42 ; i++) printf("%c", cabecalho->descreveLugares[i]); if(dados->quantidadeLugares == -1) printf(": campo com valor nulo\n"); else printf(": %d\n", dados->quantidadeLugares); }
[ "void", "printa_veiculo", "(", "dados_veiculo", "*", "dados", ",", "cabecalho_veiculo", "*", "cabecalho", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "18", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descrevePrefixo", "[", "i", "]", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "prefixo", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "17", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveModelo", "[", "i", "]", ")", ";", "if", "(", "dados", "->", "tamanhoModelo", "==", "0", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "else", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "modelo", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "20", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveCategoria", "[", "i", "]", ")", ";", "if", "(", "dados", "->", "tamanhoCategoria", "==", "0", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "else", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "categoria", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "35", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveData", "[", "i", "]", ")", ";", "printf", "(", "\"", "\"", ")", ";", "if", "(", "dados", "->", "data", "[", "0", "]", "!=", "'", "\\0", "'", ")", "converte_e_printa_data", "(", "dados", "->", "data", ")", ";", "else", "printf", "(", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "42", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveLugares", "[", "i", "]", ")", ";", "if", "(", "dados", "->", "quantidadeLugares", "==", "-1", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "else", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "quantidadeLugares", ")", ";", "}" ]
Funcao responsavel pela simples impressao dos dados na tela usando a struct cabecalho e a struct dados
[ "Funcao", "responsavel", "pela", "simples", "impressao", "dos", "dados", "na", "tela", "usando", "a", "struct", "cabecalho", "e", "a", "struct", "dados" ]
[]
[ { "param": "dados", "type": "dados_veiculo" }, { "param": "cabecalho", "type": "cabecalho_veiculo" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dados", "type": "dados_veiculo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cabecalho", "type": "cabecalho_veiculo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d43650796aad2b7adf6abb594753694807146bb3
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesEscrita.c
[ "MIT" ]
C
printa_linha
void
void printa_linha(dados_linha *dados, cabecalho_linha *cabecalho){ for(int i = 0; i < 15; i++) printf("%c", cabecalho->descreveCodigo[i]); printf(": %d\n", dados->codLinha); for(int i = 0; i < 13; i++) printf("%c", cabecalho->descreveNome[i]); if(dados->tamanhoNome == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->nomeLinha); for(int i = 0; i < 24; i++) printf("%c", cabecalho->descreveCor[i]); if(dados->tamanhoCor == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->corLinha); for(int i = 0; i < 13; i++) printf("%c", cabecalho->descreveCartao[i]); printf(": "); if(dados->aceitaCartao != '\0') valor_cartao(dados->aceitaCartao); else printf("campo com valor nulo"); printf("\n\n"); }
//Funcao responsavel pela simples impressao dos dados na tela usando a struct cabecalho e a struct dados
Funcao responsavel pela simples impressao dos dados na tela usando a struct cabecalho e a struct dados
[ "Funcao", "responsavel", "pela", "simples", "impressao", "dos", "dados", "na", "tela", "usando", "a", "struct", "cabecalho", "e", "a", "struct", "dados" ]
void printa_linha(dados_linha *dados, cabecalho_linha *cabecalho){ for(int i = 0; i < 15; i++) printf("%c", cabecalho->descreveCodigo[i]); printf(": %d\n", dados->codLinha); for(int i = 0; i < 13; i++) printf("%c", cabecalho->descreveNome[i]); if(dados->tamanhoNome == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->nomeLinha); for(int i = 0; i < 24; i++) printf("%c", cabecalho->descreveCor[i]); if(dados->tamanhoCor == 0) printf(": campo com valor nulo\n"); else printf(": %s\n", dados->corLinha); for(int i = 0; i < 13; i++) printf("%c", cabecalho->descreveCartao[i]); printf(": "); if(dados->aceitaCartao != '\0') valor_cartao(dados->aceitaCartao); else printf("campo com valor nulo"); printf("\n\n"); }
[ "void", "printa_linha", "(", "dados_linha", "*", "dados", ",", "cabecalho_linha", "*", "cabecalho", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "15", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveCodigo", "[", "i", "]", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "codLinha", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "13", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveNome", "[", "i", "]", ")", ";", "if", "(", "dados", "->", "tamanhoNome", "==", "0", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "else", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "nomeLinha", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "24", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveCor", "[", "i", "]", ")", ";", "if", "(", "dados", "->", "tamanhoCor", "==", "0", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "else", "printf", "(", "\"", "\\n", "\"", ",", "dados", "->", "corLinha", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "13", ";", "i", "++", ")", "printf", "(", "\"", "\"", ",", "cabecalho", "->", "descreveCartao", "[", "i", "]", ")", ";", "printf", "(", "\"", "\"", ")", ";", "if", "(", "dados", "->", "aceitaCartao", "!=", "'", "\\0", "'", ")", "valor_cartao", "(", "dados", "->", "aceitaCartao", ")", ";", "else", "printf", "(", "\"", "\"", ")", ";", "printf", "(", "\"", "\\n", "\\n", "\"", ")", ";", "}" ]
Funcao responsavel pela simples impressao dos dados na tela usando a struct cabecalho e a struct dados
[ "Funcao", "responsavel", "pela", "simples", "impressao", "dos", "dados", "na", "tela", "usando", "a", "struct", "cabecalho", "e", "a", "struct", "dados" ]
[]
[ { "param": "dados", "type": "dados_linha" }, { "param": "cabecalho", "type": "cabecalho_linha" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dados", "type": "dados_linha", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cabecalho", "type": "cabecalho_linha", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d43650796aad2b7adf6abb594753694807146bb3
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesEscrita.c
[ "MIT" ]
C
converte_e_printa_data
void
void converte_e_printa_data(char *data){ int dia, ano, mes; char nome_mes[25], *aux; aux = strtok(data, "-"); ano = atoi(aux); aux = strtok(NULL, "-"); mes = atoi(aux); if (mes == 1) strcpy(nome_mes, "janeiro"); else if (mes == 2) strcpy(nome_mes, "fevereiro"); else if (mes == 3) strcpy(nome_mes, "março"); else if (mes == 4) strcpy(nome_mes, "abril"); else if (mes == 5) strcpy(nome_mes, "maio"); else if (mes == 6) strcpy(nome_mes, "junho"); else if (mes == 7) strcpy(nome_mes, "julho"); else if (mes == 8) strcpy(nome_mes, "agosto"); else if (mes == 9) strcpy(nome_mes, "setembro"); else if (mes == 10) strcpy(nome_mes, "outubro"); else if (mes == 11) strcpy(nome_mes, "novembro"); else if (mes == 12) strcpy(nome_mes, "dezembro"); aux = strtok(NULL, "-"); dia = atoi(aux); if (dia >= 10) printf("%d de %s de %d", dia, nome_mes, ano); else printf("0%d de %s de %d", dia, nome_mes, ano); }
// Funcao responsavel por ler a data e converter para o formato dia - mes por extenso - ano
Funcao responsavel por ler a data e converter para o formato dia - mes por extenso - ano
[ "Funcao", "responsavel", "por", "ler", "a", "data", "e", "converter", "para", "o", "formato", "dia", "-", "mes", "por", "extenso", "-", "ano" ]
void converte_e_printa_data(char *data){ int dia, ano, mes; char nome_mes[25], *aux; aux = strtok(data, "-"); ano = atoi(aux); aux = strtok(NULL, "-"); mes = atoi(aux); if (mes == 1) strcpy(nome_mes, "janeiro"); else if (mes == 2) strcpy(nome_mes, "fevereiro"); else if (mes == 3) strcpy(nome_mes, "março"); else if (mes == 4) strcpy(nome_mes, "abril"); else if (mes == 5) strcpy(nome_mes, "maio"); else if (mes == 6) strcpy(nome_mes, "junho"); else if (mes == 7) strcpy(nome_mes, "julho"); else if (mes == 8) strcpy(nome_mes, "agosto"); else if (mes == 9) strcpy(nome_mes, "setembro"); else if (mes == 10) strcpy(nome_mes, "outubro"); else if (mes == 11) strcpy(nome_mes, "novembro"); else if (mes == 12) strcpy(nome_mes, "dezembro"); aux = strtok(NULL, "-"); dia = atoi(aux); if (dia >= 10) printf("%d de %s de %d", dia, nome_mes, ano); else printf("0%d de %s de %d", dia, nome_mes, ano); }
[ "void", "converte_e_printa_data", "(", "char", "*", "data", ")", "{", "int", "dia", ",", "ano", ",", "mes", ";", "char", "nome_mes", "[", "25", "]", ",", "*", "aux", ";", "aux", "=", "strtok", "(", "data", ",", "\"", "\"", ")", ";", "ano", "=", "atoi", "(", "aux", ")", ";", "aux", "=", "strtok", "(", "NULL", ",", "\"", "\"", ")", ";", "mes", "=", "atoi", "(", "aux", ")", ";", "if", "(", "mes", "==", "1", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "2", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "3", ")", "strcpy", "(", "nome_mes", ",", "\"", ")", ";", "", "else", "if", "(", "mes", "==", "4", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "5", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "6", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "7", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "8", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "9", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "10", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "11", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "else", "if", "(", "mes", "==", "12", ")", "strcpy", "(", "nome_mes", ",", "\"", "\"", ")", ";", "aux", "=", "strtok", "(", "NULL", ",", "\"", "\"", ")", ";", "dia", "=", "atoi", "(", "aux", ")", ";", "if", "(", "dia", ">=", "10", ")", "printf", "(", "\"", "\"", ",", "dia", ",", "nome_mes", ",", "ano", ")", ";", "else", "printf", "(", "\"", "\"", ",", "dia", ",", "nome_mes", ",", "ano", ")", ";", "}" ]
Funcao responsavel por ler a data e converter para o formato dia - mes por extenso - ano
[ "Funcao", "responsavel", "por", "ler", "a", "data", "e", "converter", "para", "o", "formato", "dia", "-", "mes", "por", "extenso", "-", "ano" ]
[]
[ { "param": "data", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d43650796aad2b7adf6abb594753694807146bb3
thiagohsc21/USP-Graduation
File Organization/Problem 3 - Ordering and Merge/Trabalho 3/funcoesEscrita.c
[ "MIT" ]
C
valor_cartao
void
void valor_cartao(char cartao){ if (cartao == 'S') printf("PAGAMENTO SOMENTE COM CARTAO SEM PRESENCA DE COBRADOR"); else if (cartao == 'N') printf("PAGAMENTO EM CARTAO E DINHEIRO"); else if (cartao == 'F') printf("PAGAMENTO EM CARTAO SOMENTE NO FINAL DE SEMANA"); }
//Funcao resposavel por pegar o valor do aceita cartao e printar a frase correspondente
Funcao resposavel por pegar o valor do aceita cartao e printar a frase correspondente
[ "Funcao", "resposavel", "por", "pegar", "o", "valor", "do", "aceita", "cartao", "e", "printar", "a", "frase", "correspondente" ]
void valor_cartao(char cartao){ if (cartao == 'S') printf("PAGAMENTO SOMENTE COM CARTAO SEM PRESENCA DE COBRADOR"); else if (cartao == 'N') printf("PAGAMENTO EM CARTAO E DINHEIRO"); else if (cartao == 'F') printf("PAGAMENTO EM CARTAO SOMENTE NO FINAL DE SEMANA"); }
[ "void", "valor_cartao", "(", "char", "cartao", ")", "{", "if", "(", "cartao", "==", "'", "'", ")", "printf", "(", "\"", "\"", ")", ";", "else", "if", "(", "cartao", "==", "'", "'", ")", "printf", "(", "\"", "\"", ")", ";", "else", "if", "(", "cartao", "==", "'", "'", ")", "printf", "(", "\"", "\"", ")", ";", "}" ]
Funcao resposavel por pegar o valor do aceita cartao e printar a frase correspondente
[ "Funcao", "resposavel", "por", "pegar", "o", "valor", "do", "aceita", "cartao", "e", "printar", "a", "frase", "correspondente" ]
[]
[ { "param": "cartao", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cartao", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
53948700422f6b3483b0627891b36d685da7957b
thiagohsc21/USP-Graduation
File Organization/Problem 1 - Sequencial Organization/Trabalho 1/funcoesLeitura.c
[ "MIT" ]
C
le_cabecalho_veiculo
void
void le_cabecalho_veiculo(FILE *fp_bin, cabecalho_veiculo *cabecalho){ fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descrevePrefixo, sizeof(char), 18, fp_bin); fread(&cabecalho->descreveData, sizeof(char), 35, fp_bin); fread(&cabecalho->descreveLugares, sizeof(char), 42, fp_bin); fread(&cabecalho->descreveLinha, sizeof(char), 26, fp_bin); fread(&cabecalho->descreveModelo, sizeof(char), 17, fp_bin); fread(&cabecalho->descreveCategoria, sizeof(char), 20, fp_bin); }
//Funcao responsavle pela leitura do cabecalho dos veiculos no arquivo binario
Funcao responsavle pela leitura do cabecalho dos veiculos no arquivo binario
[ "Funcao", "responsavle", "pela", "leitura", "do", "cabecalho", "dos", "veiculos", "no", "arquivo", "binario" ]
void le_cabecalho_veiculo(FILE *fp_bin, cabecalho_veiculo *cabecalho){ fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descrevePrefixo, sizeof(char), 18, fp_bin); fread(&cabecalho->descreveData, sizeof(char), 35, fp_bin); fread(&cabecalho->descreveLugares, sizeof(char), 42, fp_bin); fread(&cabecalho->descreveLinha, sizeof(char), 26, fp_bin); fread(&cabecalho->descreveModelo, sizeof(char), 17, fp_bin); fread(&cabecalho->descreveCategoria, sizeof(char), 20, fp_bin); }
[ "void", "le_cabecalho_veiculo", "(", "FILE", "*", "fp_bin", ",", "cabecalho_veiculo", "*", "cabecalho", ")", "{", "fread", "(", "&", "cabecalho", "->", "status", ",", "sizeof", "(", "char", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "byteProxReg", ",", "sizeof", "(", "long", "long", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegistros", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegRemovidos", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descrevePrefixo", ",", "sizeof", "(", "char", ")", ",", "18", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveData", ",", "sizeof", "(", "char", ")", ",", "35", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveLugares", ",", "sizeof", "(", "char", ")", ",", "42", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveLinha", ",", "sizeof", "(", "char", ")", ",", "26", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveModelo", ",", "sizeof", "(", "char", ")", ",", "17", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCategoria", ",", "sizeof", "(", "char", ")", ",", "20", ",", "fp_bin", ")", ";", "}" ]
Funcao responsavle pela leitura do cabecalho dos veiculos no arquivo binario
[ "Funcao", "responsavle", "pela", "leitura", "do", "cabecalho", "dos", "veiculos", "no", "arquivo", "binario" ]
[]
[ { "param": "fp_bin", "type": "FILE" }, { "param": "cabecalho", "type": "cabecalho_veiculo" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp_bin", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cabecalho", "type": "cabecalho_veiculo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
53948700422f6b3483b0627891b36d685da7957b
thiagohsc21/USP-Graduation
File Organization/Problem 1 - Sequencial Organization/Trabalho 1/funcoesLeitura.c
[ "MIT" ]
C
le_cabecalho_linha
void
void le_cabecalho_linha(FILE *fp_bin, cabecalho_linha *cabecalho){ fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descreveCodigo, sizeof(char), 15, fp_bin); fread(&cabecalho->descreveCartao, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveNome, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveCor, sizeof(char), 24, fp_bin); }
//Funcao responsavel pela leitura do cabecalho das linhas no arquivo binario
Funcao responsavel pela leitura do cabecalho das linhas no arquivo binario
[ "Funcao", "responsavel", "pela", "leitura", "do", "cabecalho", "das", "linhas", "no", "arquivo", "binario" ]
void le_cabecalho_linha(FILE *fp_bin, cabecalho_linha *cabecalho){ fread(&cabecalho->status, sizeof(char), 1, fp_bin); fread(&cabecalho->byteProxReg, sizeof(long long), 1, fp_bin); fread(&cabecalho->nroRegistros, sizeof(int), 1, fp_bin); fread(&cabecalho->nroRegRemovidos, sizeof(int), 1, fp_bin); fread(&cabecalho->descreveCodigo, sizeof(char), 15, fp_bin); fread(&cabecalho->descreveCartao, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveNome, sizeof(char), 13, fp_bin); fread(&cabecalho->descreveCor, sizeof(char), 24, fp_bin); }
[ "void", "le_cabecalho_linha", "(", "FILE", "*", "fp_bin", ",", "cabecalho_linha", "*", "cabecalho", ")", "{", "fread", "(", "&", "cabecalho", "->", "status", ",", "sizeof", "(", "char", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "byteProxReg", ",", "sizeof", "(", "long", "long", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegistros", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "nroRegRemovidos", ",", "sizeof", "(", "int", ")", ",", "1", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCodigo", ",", "sizeof", "(", "char", ")", ",", "15", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCartao", ",", "sizeof", "(", "char", ")", ",", "13", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveNome", ",", "sizeof", "(", "char", ")", ",", "13", ",", "fp_bin", ")", ";", "fread", "(", "&", "cabecalho", "->", "descreveCor", ",", "sizeof", "(", "char", ")", ",", "24", ",", "fp_bin", ")", ";", "}" ]
Funcao responsavel pela leitura do cabecalho das linhas no arquivo binario
[ "Funcao", "responsavel", "pela", "leitura", "do", "cabecalho", "das", "linhas", "no", "arquivo", "binario" ]
[]
[ { "param": "fp_bin", "type": "FILE" }, { "param": "cabecalho", "type": "cabecalho_linha" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp_bin", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cabecalho", "type": "cabecalho_linha", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40dc232b5f0f2f1d57cbc9a923ebec6d3e443286
thiagohsc21/USP-Graduation
Introduction to Computer Science/labirinto.c
[ "MIT" ]
C
Le_Entradas_e_Retorna_PonteiroArquivo
FILE
FILE* Le_Entradas_e_Retorna_PonteiroArquivo(int *linhas, int *colunas, int *posicaox, int *posicaoy){ char name[25]; scanf("%s",name); FILE* fp = fopen(name,"r"); fscanf(fp, "%d %d", linhas, colunas); fscanf(fp, "%d %d", posicaox, posicaoy); return fp; }
//le por referencia todas as entradas e retorna o ponteiro pro arquivo
le por referencia todas as entradas e retorna o ponteiro pro arquivo
[ "le", "por", "referencia", "todas", "as", "entradas", "e", "retorna", "o", "ponteiro", "pro", "arquivo" ]
FILE* Le_Entradas_e_Retorna_PonteiroArquivo(int *linhas, int *colunas, int *posicaox, int *posicaoy){ char name[25]; scanf("%s",name); FILE* fp = fopen(name,"r"); fscanf(fp, "%d %d", linhas, colunas); fscanf(fp, "%d %d", posicaox, posicaoy); return fp; }
[ "FILE", "*", "Le_Entradas_e_Retorna_PonteiroArquivo", "(", "int", "*", "linhas", ",", "int", "*", "colunas", ",", "int", "*", "posicaox", ",", "int", "*", "posicaoy", ")", "{", "char", "name", "[", "25", "]", ";", "scanf", "(", "\"", "\"", ",", "name", ")", ";", "FILE", "*", "fp", "=", "fopen", "(", "name", ",", "\"", "\"", ")", ";", "fscanf", "(", "fp", ",", "\"", "\"", ",", "linhas", ",", "colunas", ")", ";", "fscanf", "(", "fp", ",", "\"", "\"", ",", "posicaox", ",", "posicaoy", ")", ";", "return", "fp", ";", "}" ]
le por referencia todas as entradas e retorna o ponteiro pro arquivo
[ "le", "por", "referencia", "todas", "as", "entradas", "e", "retorna", "o", "ponteiro", "pro", "arquivo" ]
[]
[ { "param": "linhas", "type": "int" }, { "param": "colunas", "type": "int" }, { "param": "posicaox", "type": "int" }, { "param": "posicaoy", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "linhas", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "colunas", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "posicaox", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "posicaoy", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40dc232b5f0f2f1d57cbc9a923ebec6d3e443286
thiagohsc21/USP-Graduation
Introduction to Computer Science/labirinto.c
[ "MIT" ]
C
Desaloca_Tudo_e_Fecha_Arquivo
void
void Desaloca_Tudo_e_Fecha_Arquivo(FILE *fp, char **labirinto, int linhas){ for(int i = 0; i < linhas; i++) free(labirinto[i]); free(labirinto); fclose(fp); }
//desaloca toda a memoria alocada dinamicamente na heap
desaloca toda a memoria alocada dinamicamente na heap
[ "desaloca", "toda", "a", "memoria", "alocada", "dinamicamente", "na", "heap" ]
void Desaloca_Tudo_e_Fecha_Arquivo(FILE *fp, char **labirinto, int linhas){ for(int i = 0; i < linhas; i++) free(labirinto[i]); free(labirinto); fclose(fp); }
[ "void", "Desaloca_Tudo_e_Fecha_Arquivo", "(", "FILE", "*", "fp", ",", "char", "*", "*", "labirinto", ",", "int", "linhas", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "linhas", ";", "i", "++", ")", "free", "(", "labirinto", "[", "i", "]", ")", ";", "free", "(", "labirinto", ")", ";", "fclose", "(", "fp", ")", ";", "}" ]
desaloca toda a memoria alocada dinamicamente na heap
[ "desaloca", "toda", "a", "memoria", "alocada", "dinamicamente", "na", "heap" ]
[]
[ { "param": "fp", "type": "FILE" }, { "param": "labirinto", "type": "char" }, { "param": "linhas", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "labirinto", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "linhas", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
eff90ac2a237511b3ba7e18c89a65985561da096
thiagohsc21/USP-Graduation
Introduction to Computer Science/mergesort3vias.c
[ "MIT" ]
C
recebe_entrada
void
void recebe_entrada(livro *p){ char c = 0; int pos = 0; char *nomeaux = (char*) malloc(sizeof(char)); //recebe os caracteres e vai colocando na regiao apontada pelo ponteiro nomeaux while(c != ','){ c = getchar(); if(c != '\n' && c != '\r'){ nomeaux = realloc(nomeaux, (pos+1)*sizeof(char)); nomeaux[pos++] = c; } } nomeaux[--pos] = '\0'; //passa o end alocado pelo nomeaux para o p->nome da struct atual p->nome = nomeaux; nomeaux = NULL; scanf("%f", &p->valor); }
//funcao que recebe a entrada e armazena numa struct livro
funcao que recebe a entrada e armazena numa struct livro
[ "funcao", "que", "recebe", "a", "entrada", "e", "armazena", "numa", "struct", "livro" ]
void recebe_entrada(livro *p){ char c = 0; int pos = 0; char *nomeaux = (char*) malloc(sizeof(char)); while(c != ','){ c = getchar(); if(c != '\n' && c != '\r'){ nomeaux = realloc(nomeaux, (pos+1)*sizeof(char)); nomeaux[pos++] = c; } } nomeaux[--pos] = '\0'; p->nome = nomeaux; nomeaux = NULL; scanf("%f", &p->valor); }
[ "void", "recebe_entrada", "(", "livro", "*", "p", ")", "{", "char", "c", "=", "0", ";", "int", "pos", "=", "0", ";", "char", "*", "nomeaux", "=", "(", "char", "*", ")", "malloc", "(", "sizeof", "(", "char", ")", ")", ";", "while", "(", "c", "!=", "'", "'", ")", "{", "c", "=", "getchar", "(", ")", ";", "if", "(", "c", "!=", "'", "\\n", "'", "&&", "c", "!=", "'", "\\r", "'", ")", "{", "nomeaux", "=", "realloc", "(", "nomeaux", ",", "(", "pos", "+", "1", ")", "*", "sizeof", "(", "char", ")", ")", ";", "nomeaux", "[", "pos", "++", "]", "=", "c", ";", "}", "}", "nomeaux", "[", "--", "pos", "]", "=", "'", "\\0", "'", ";", "p", "->", "nome", "=", "nomeaux", ";", "nomeaux", "=", "NULL", ";", "scanf", "(", "\"", "\"", ",", "&", "p", "->", "valor", ")", ";", "}" ]
funcao que recebe a entrada e armazena numa struct livro
[ "funcao", "que", "recebe", "a", "entrada", "e", "armazena", "numa", "struct", "livro" ]
[ "//recebe os caracteres e vai colocando na regiao apontada pelo ponteiro nomeaux", "//passa o end alocado pelo nomeaux para o p->nome da struct atual" ]
[ { "param": "p", "type": "livro" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "p", "type": "livro", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
eff90ac2a237511b3ba7e18c89a65985561da096
thiagohsc21/USP-Graduation
Introduction to Computer Science/mergesort3vias.c
[ "MIT" ]
C
ordena_mergesort_3vias
void
void ordena_mergesort_3vias(float *v, int ini, int fim){ for(int i = ini; i <= fim; i++){ printf("%.2f ", v[i]); if(i == fim) printf("\n"); } if(fim <= ini) return; int c1 = ini + (fim-ini)/3; int c2 = c1 + (fim-c1+1)/2; ordena_mergesort_3vias(v, ini, c1); ordena_mergesort_3vias(v, c1+1, c2); ordena_mergesort_3vias(v, c2+1, fim); //intercala as partes dentro desses três vetores float *aux = (float*) malloc((fim-ini+1)*sizeof(float)); int i = ini; //índice para a primeira parte (ini -> c1) int j = c1+1; //índice para a segunda parte (c1+1 -> c2) int k = c2+1; //índice para a terceira parte (c2+1 -> fim) int pos = 0; //índice para o vetor auxiliar while(i <= c1 && j <= c2 && k <= fim){ //se o elemento da lista 1 for maior que o da lista 2 e 3, coloca ele no vetor if(v[i] <= v[j] && v[i] <= v[k]){ aux[pos] = v[i]; i++; //incrementa para que tenhamos acesso ao proximo elemento da lista 1 } //se o elemento da lista 2 for maior que o da lista 1 e 3, coloca ele no vetor else if(v[j] <= v[i] && v[j] <= v[k]){ aux[pos] = v[j]; j++; //incrementa para que tenhamos acesso ao proximo elemento da lista 2 } //se o elemento da lista 3 for maior que o da lista 1 e 2, coloca ele no vetor else{ aux[pos] = v[k]; k++; //incrementa para que tenhamos acesso ao proximo elemento da lista 3 } pos++; //a cada rodada colocamos um elemento no vetor aux, portanto temos que avançar //uma posicao nele } //se a lista 1 tiver vazia e as outras ainda nao, compara os elementos delas if(i > c1 && (j <= c2 && k <= fim)){ while(j <= c2 && k <= fim){ if(v[j] <= v[k]){ aux[pos] = v[j]; j++; } else{ aux[pos] = v[k]; k++; } pos++; } } //se a lista 2 estiver vazia e as outras ainda nao, compara os elementos delas else if(j > c2 && (i <= c1 && k <= fim)){ while(i <= c1 && k <= fim){ if(v[i] <= v[k]){ aux[pos] = v[i]; i++; } else{ aux[pos] = v[k]; k++; } pos++; } } //se a lista 3 estiver vazia e as outas ainda nao, compara os elementos delas else if(k > fim && (j <= c2 && i <= c1)){ while(i <= c1 && j <= c2){ if(v[i] <= v[j]){ aux[pos] = v[i]; i++; } else{ aux[pos] = v[j]; j++; } pos++; } } //se a lista 1 e lista 2 estiverem vazias, copia a 3 para o vetor if(i > c1 && j > c2 && k <=fim){ while(k <= fim){ aux[pos] = v[k]; k++; pos++; } } //se a lista 1 e lista 3 estiverem vazias, copia a 2 para o vetor else if(i > c1 && k > fim && j <= c2){ while(j <= c2){ aux[pos] = v[j]; j++; pos++; } } //se a lista 2 e a lista 3 estiverem vazias, copia a 1 para o vetor else if(j > c2 && k > fim && i <= c1){ while(i <= c1){ aux[pos] = v[i]; i++; pos++; } } //copia o vetor aux para o vetor original passado na entrada for(i = ini, pos = 0; i <= fim; i++, pos++) v[i] = aux[pos]; free(aux); }
//ordena segundo o algoritmo de mergesort, mas com 3 vias
ordena segundo o algoritmo de mergesort, mas com 3 vias
[ "ordena", "segundo", "o", "algoritmo", "de", "mergesort", "mas", "com", "3", "vias" ]
void ordena_mergesort_3vias(float *v, int ini, int fim){ for(int i = ini; i <= fim; i++){ printf("%.2f ", v[i]); if(i == fim) printf("\n"); } if(fim <= ini) return; int c1 = ini + (fim-ini)/3; int c2 = c1 + (fim-c1+1)/2; ordena_mergesort_3vias(v, ini, c1); ordena_mergesort_3vias(v, c1+1, c2); ordena_mergesort_3vias(v, c2+1, fim); float *aux = (float*) malloc((fim-ini+1)*sizeof(float)); int i = ini; int j = c1+1; int k = c2+1; int pos = 0; while(i <= c1 && j <= c2 && k <= fim){ if(v[i] <= v[j] && v[i] <= v[k]){ aux[pos] = v[i]; i++; } else if(v[j] <= v[i] && v[j] <= v[k]){ aux[pos] = v[j]; j++; } else{ aux[pos] = v[k]; k++; } pos++; } if(i > c1 && (j <= c2 && k <= fim)){ while(j <= c2 && k <= fim){ if(v[j] <= v[k]){ aux[pos] = v[j]; j++; } else{ aux[pos] = v[k]; k++; } pos++; } } else if(j > c2 && (i <= c1 && k <= fim)){ while(i <= c1 && k <= fim){ if(v[i] <= v[k]){ aux[pos] = v[i]; i++; } else{ aux[pos] = v[k]; k++; } pos++; } } else if(k > fim && (j <= c2 && i <= c1)){ while(i <= c1 && j <= c2){ if(v[i] <= v[j]){ aux[pos] = v[i]; i++; } else{ aux[pos] = v[j]; j++; } pos++; } } if(i > c1 && j > c2 && k <=fim){ while(k <= fim){ aux[pos] = v[k]; k++; pos++; } } else if(i > c1 && k > fim && j <= c2){ while(j <= c2){ aux[pos] = v[j]; j++; pos++; } } else if(j > c2 && k > fim && i <= c1){ while(i <= c1){ aux[pos] = v[i]; i++; pos++; } } for(i = ini, pos = 0; i <= fim; i++, pos++) v[i] = aux[pos]; free(aux); }
[ "void", "ordena_mergesort_3vias", "(", "float", "*", "v", ",", "int", "ini", ",", "int", "fim", ")", "{", "for", "(", "int", "i", "=", "ini", ";", "i", "<=", "fim", ";", "i", "++", ")", "{", "printf", "(", "\"", "\"", ",", "v", "[", "i", "]", ")", ";", "if", "(", "i", "==", "fim", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "}", "if", "(", "fim", "<=", "ini", ")", "return", ";", "int", "c1", "=", "ini", "+", "(", "fim", "-", "ini", ")", "/", "3", ";", "int", "c2", "=", "c1", "+", "(", "fim", "-", "c1", "+", "1", ")", "/", "2", ";", "ordena_mergesort_3vias", "(", "v", ",", "ini", ",", "c1", ")", ";", "ordena_mergesort_3vias", "(", "v", ",", "c1", "+", "1", ",", "c2", ")", ";", "ordena_mergesort_3vias", "(", "v", ",", "c2", "+", "1", ",", "fim", ")", ";", "float", "*", "aux", "=", "(", "float", "*", ")", "malloc", "(", "(", "fim", "-", "ini", "+", "1", ")", "*", "sizeof", "(", "float", ")", ")", ";", "int", "i", "=", "ini", ";", "int", "j", "=", "c1", "+", "1", ";", "int", "k", "=", "c2", "+", "1", ";", "int", "pos", "=", "0", ";", "while", "(", "i", "<=", "c1", "&&", "j", "<=", "c2", "&&", "k", "<=", "fim", ")", "{", "if", "(", "v", "[", "i", "]", "<=", "v", "[", "j", "]", "&&", "v", "[", "i", "]", "<=", "v", "[", "k", "]", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "i", "]", ";", "i", "++", ";", "}", "else", "if", "(", "v", "[", "j", "]", "<=", "v", "[", "i", "]", "&&", "v", "[", "j", "]", "<=", "v", "[", "k", "]", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "j", "]", ";", "j", "++", ";", "}", "else", "{", "aux", "[", "pos", "]", "=", "v", "[", "k", "]", ";", "k", "++", ";", "}", "pos", "++", ";", "}", "if", "(", "i", ">", "c1", "&&", "(", "j", "<=", "c2", "&&", "k", "<=", "fim", ")", ")", "{", "while", "(", "j", "<=", "c2", "&&", "k", "<=", "fim", ")", "{", "if", "(", "v", "[", "j", "]", "<=", "v", "[", "k", "]", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "j", "]", ";", "j", "++", ";", "}", "else", "{", "aux", "[", "pos", "]", "=", "v", "[", "k", "]", ";", "k", "++", ";", "}", "pos", "++", ";", "}", "}", "else", "if", "(", "j", ">", "c2", "&&", "(", "i", "<=", "c1", "&&", "k", "<=", "fim", ")", ")", "{", "while", "(", "i", "<=", "c1", "&&", "k", "<=", "fim", ")", "{", "if", "(", "v", "[", "i", "]", "<=", "v", "[", "k", "]", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "i", "]", ";", "i", "++", ";", "}", "else", "{", "aux", "[", "pos", "]", "=", "v", "[", "k", "]", ";", "k", "++", ";", "}", "pos", "++", ";", "}", "}", "else", "if", "(", "k", ">", "fim", "&&", "(", "j", "<=", "c2", "&&", "i", "<=", "c1", ")", ")", "{", "while", "(", "i", "<=", "c1", "&&", "j", "<=", "c2", ")", "{", "if", "(", "v", "[", "i", "]", "<=", "v", "[", "j", "]", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "i", "]", ";", "i", "++", ";", "}", "else", "{", "aux", "[", "pos", "]", "=", "v", "[", "j", "]", ";", "j", "++", ";", "}", "pos", "++", ";", "}", "}", "if", "(", "i", ">", "c1", "&&", "j", ">", "c2", "&&", "k", "<=", "fim", ")", "{", "while", "(", "k", "<=", "fim", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "k", "]", ";", "k", "++", ";", "pos", "++", ";", "}", "}", "else", "if", "(", "i", ">", "c1", "&&", "k", ">", "fim", "&&", "j", "<=", "c2", ")", "{", "while", "(", "j", "<=", "c2", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "j", "]", ";", "j", "++", ";", "pos", "++", ";", "}", "}", "else", "if", "(", "j", ">", "c2", "&&", "k", ">", "fim", "&&", "i", "<=", "c1", ")", "{", "while", "(", "i", "<=", "c1", ")", "{", "aux", "[", "pos", "]", "=", "v", "[", "i", "]", ";", "i", "++", ";", "pos", "++", ";", "}", "}", "for", "(", "i", "=", "ini", ",", "pos", "=", "0", ";", "i", "<=", "fim", ";", "i", "++", ",", "pos", "++", ")", "v", "[", "i", "]", "=", "aux", "[", "pos", "]", ";", "free", "(", "aux", ")", ";", "}" ]
ordena segundo o algoritmo de mergesort, mas com 3 vias
[ "ordena", "segundo", "o", "algoritmo", "de", "mergesort", "mas", "com", "3", "vias" ]
[ "//intercala as partes dentro desses três vetores", "//índice para a primeira parte (ini -> c1)", "//índice para a segunda parte (c1+1 -> c2)", "//índice para a terceira parte (c2+1 -> fim)", "//índice para o vetor auxiliar ", "//se o elemento da lista 1 for maior que o da lista 2 e 3, coloca ele no vetor", "//incrementa para que tenhamos acesso ao proximo elemento da lista 1", "//se o elemento da lista 2 for maior que o da lista 1 e 3, coloca ele no vetor", "//incrementa para que tenhamos acesso ao proximo elemento da lista 2", "//se o elemento da lista 3 for maior que o da lista 1 e 2, coloca ele no vetor", "//incrementa para que tenhamos acesso ao proximo elemento da lista 3", "//a cada rodada colocamos um elemento no vetor aux, portanto temos que avançar", "//uma posicao nele", "//se a lista 1 tiver vazia e as outras ainda nao, compara os elementos delas", "//se a lista 2 estiver vazia e as outras ainda nao, compara os elementos delas", "//se a lista 3 estiver vazia e as outas ainda nao, compara os elementos delas", "//se a lista 1 e lista 2 estiverem vazias, copia a 3 para o vetor", "//se a lista 1 e lista 3 estiverem vazias, copia a 2 para o vetor", "//se a lista 2 e a lista 3 estiverem vazias, copia a 1 para o vetor", "//copia o vetor aux para o vetor original passado na entrada" ]
[ { "param": "v", "type": "float" }, { "param": "ini", "type": "int" }, { "param": "fim", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ini", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fim", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0e359335250ea18100b21edee981884e2901aa7f
sketch-hq/flatbuffers
include/flatbuffers/flexbuffers.h
[ "Apache-2.0" ]
C
MutateInt
bool
bool MutateInt(int64_t i) { if (type_ == FBT_INT) { return Mutate(data_, i, parent_width_, WidthI(i)); } else if (type_ == FBT_INDIRECT_INT) { return Mutate(Indirect(), i, byte_width_, WidthI(i)); } else if (type_ == FBT_UINT) { auto u = static_cast<uint64_t>(i); return Mutate(data_, u, parent_width_, WidthU(u)); } else if (type_ == FBT_INDIRECT_UINT) { auto u = static_cast<uint64_t>(i); return Mutate(Indirect(), u, byte_width_, WidthU(u)); } else { return false; } }
// Experimental: Mutation functions. // These allow scalars in an already created buffer to be updated in-place. // Since by default scalars are stored in the smallest possible space, // the new value may not fit, in which case these functions return false. // To avoid this, you can construct the values you intend to mutate using // Builder::ForceMinimumBitWidth.
Mutation functions. These allow scalars in an already created buffer to be updated in-place. Since by default scalars are stored in the smallest possible space, the new value may not fit, in which case these functions return false. To avoid this, you can construct the values you intend to mutate using Builder::ForceMinimumBitWidth.
[ "Mutation", "functions", ".", "These", "allow", "scalars", "in", "an", "already", "created", "buffer", "to", "be", "updated", "in", "-", "place", ".", "Since", "by", "default", "scalars", "are", "stored", "in", "the", "smallest", "possible", "space", "the", "new", "value", "may", "not", "fit", "in", "which", "case", "these", "functions", "return", "false", ".", "To", "avoid", "this", "you", "can", "construct", "the", "values", "you", "intend", "to", "mutate", "using", "Builder", "::", "ForceMinimumBitWidth", "." ]
bool MutateInt(int64_t i) { if (type_ == FBT_INT) { return Mutate(data_, i, parent_width_, WidthI(i)); } else if (type_ == FBT_INDIRECT_INT) { return Mutate(Indirect(), i, byte_width_, WidthI(i)); } else if (type_ == FBT_UINT) { auto u = static_cast<uint64_t>(i); return Mutate(data_, u, parent_width_, WidthU(u)); } else if (type_ == FBT_INDIRECT_UINT) { auto u = static_cast<uint64_t>(i); return Mutate(Indirect(), u, byte_width_, WidthU(u)); } else { return false; } }
[ "bool", "MutateInt", "(", "int64_t", "i", ")", "{", "if", "(", "type_", "==", "FBT_INT", ")", "{", "return", "Mutate", "(", "data_", ",", "i", ",", "parent_width_", ",", "WidthI", "(", "i", ")", ")", ";", "}", "else", "if", "(", "type_", "==", "FBT_INDIRECT_INT", ")", "{", "return", "Mutate", "(", "Indirect", "(", ")", ",", "i", ",", "byte_width_", ",", "WidthI", "(", "i", ")", ")", ";", "}", "else", "if", "(", "type_", "==", "FBT_UINT", ")", "{", "auto", "u", "", "=", "static_cast", "<", "uint64_t", ">", "(", "i", ")", ";", "return", "Mutate", "(", "data_", ",", "u", ",", "parent_width_", ",", "WidthU", "(", "u", ")", ")", ";", "}", "else", "if", "(", "type_", "==", "FBT_INDIRECT_UINT", ")", "{", "auto", "u", "", "=", "static_cast", "<", "uint64_t", ">", "(", "i", ")", ";", "return", "Mutate", "(", "Indirect", "(", ")", ",", "u", ",", "byte_width_", ",", "WidthU", "(", "u", ")", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Experimental: Mutation functions.
[ "Experimental", ":", "Mutation", "functions", "." ]
[]
[ { "param": "i", "type": "int64_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "i", "type": "int64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0e359335250ea18100b21edee981884e2901aa7f
sketch-hq/flatbuffers
include/flatbuffers/flexbuffers.h
[ "Apache-2.0" ]
C
Clear
void
void Clear() { buf_.clear(); stack_.clear(); finished_ = false; // flags_ remains as-is; force_min_bit_width_ = BIT_WIDTH_8; key_pool.clear(); string_pool.clear(); }
// Reset all state so we can re-use the buffer.
Reset all state so we can re-use the buffer.
[ "Reset", "all", "state", "so", "we", "can", "re", "-", "use", "the", "buffer", "." ]
void Clear() { buf_.clear(); stack_.clear(); finished_ = false; force_min_bit_width_ = BIT_WIDTH_8; key_pool.clear(); string_pool.clear(); }
[ "void", "Clear", "(", ")", "{", "buf_", ".", "clear", "(", ")", ";", "stack_", ".", "clear", "(", ")", ";", "finished_", "=", "false", ";", "force_min_bit_width_", "=", "BIT_WIDTH_8", ";", "key_pool", ".", "clear", "(", ")", ";", "string_pool", ".", "clear", "(", ")", ";", "}" ]
Reset all state so we can re-use the buffer.
[ "Reset", "all", "state", "so", "we", "can", "re", "-", "use", "the", "buffer", "." ]
[ "// flags_ remains as-is;" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
0c1a1dce1b08e463c293506141bbf411ccdf2643
xeecos/MusicBox
lib/Synth/synth.h
[ "MIT" ]
C
begin
void
void begin(unsigned char d) { TCCR1A = 0x00; //-Start audio interrupt TCCR1B = 0x09; TCCR1C = 0x00; OCR1A=16000000.0 / FS; //-Auto sample rate SET(TIMSK1, OCIE1A); //-Start audio interrupt sei(); //-+ output_mode=d; switch(d) { case DIFF: //-Differntial signal on CHA and CHB pins (11,3) TCCR2A = 0xB3; //-8 bit audio PWM TCCR2B = 0x01; // | OCR2A = OCR2B = 127; //-+ SET(DDRB, 3); //-PWM pin SET(DDRD, 3); //-PWM pin break; case CHB: //-Single ended signal on CHB pin (3) TCCR2A = 0x23; //-8 bit audio PWM TCCR2B = 0x01; // | OCR2A = OCR2B = 127; //-+ SET(DDRD, 3); //-PWM pin break; case CHA: default: output_mode=CHA; //-Single ended signal in CHA pin (11) TCCR2A = 0x83; //-8 bit audio PWM TCCR2B = 0x01; // | OCR2A = OCR2B = 127; //-+ SET(DDRB, 3); //-PWM pin break; } }
//********************************************************************* // Startup fancy selecting various output modes //*********************************************************************
Startup fancy selecting various output modes
[ "Startup", "fancy", "selecting", "various", "output", "modes" ]
void begin(unsigned char d) { TCCR1A = 0x00; TCCR1B = 0x09; TCCR1C = 0x00; OCR1A=16000000.0 / FS; SET(TIMSK1, OCIE1A); sei(); output_mode=d; switch(d) { case DIFF: TCCR2A = 0xB3; TCCR2B = 0x01; OCR2A = OCR2B = 127; SET(DDRB, 3); SET(DDRD, 3); break; case CHB: TCCR2A = 0x23; TCCR2B = 0x01; OCR2A = OCR2B = 127; SET(DDRD, 3); break; case CHA: default: output_mode=CHA; TCCR2A = 0x83; TCCR2B = 0x01; OCR2A = OCR2B = 127; SET(DDRB, 3); break; } }
[ "void", "begin", "(", "unsigned", "char", "d", ")", "{", "TCCR1A", "=", "0x00", ";", "TCCR1B", "=", "0x09", ";", "TCCR1C", "=", "0x00", ";", "OCR1A", "=", "16000000.0", "/", "FS", ";", "SET", "(", "TIMSK1", ",", "OCIE1A", ")", ";", "sei", "(", ")", ";", "output_mode", "=", "d", ";", "switch", "(", "d", ")", "{", "case", "DIFF", ":", "TCCR2A", "=", "0xB3", ";", "TCCR2B", "=", "0x01", ";", "OCR2A", "=", "OCR2B", "=", "127", ";", "SET", "(", "DDRB", ",", "3", ")", ";", "SET", "(", "DDRD", ",", "3", ")", ";", "break", ";", "case", "CHB", ":", "TCCR2A", "=", "0x23", ";", "TCCR2B", "=", "0x01", ";", "OCR2A", "=", "OCR2B", "=", "127", ";", "SET", "(", "DDRD", ",", "3", ")", ";", "break", ";", "case", "CHA", ":", "default", ":", "output_mode", "=", "CHA", ";", "TCCR2A", "=", "0x83", ";", "TCCR2B", "=", "0x01", ";", "OCR2A", "=", "OCR2B", "=", "127", ";", "SET", "(", "DDRB", ",", "3", ")", ";", "break", ";", "}", "}" ]
Startup fancy selecting various output modes
[ "Startup", "fancy", "selecting", "various", "output", "modes" ]
[ "//-Start audio interrupt", "//-Auto sample rate", "//-Start audio interrupt", "//-+", "//-Differntial signal on CHA and CHB pins (11,3)", "//-8 bit audio PWM", "// |", "//-+", "//-PWM pin", "//-PWM pin", "//-Single ended signal on CHB pin (3)", "//-8 bit audio PWM", "// |", "//-+", "//-PWM pin", "//-Single ended signal in CHA pin (11)", "//-8 bit audio PWM", "// |", "//-+", "//-PWM pin" ]
[ { "param": "d", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "d", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
467f2ef16aac584023bb4f2d85e19e75c03f1ed0
GoodiesHQ/Roach
src/buffer.c
[ "MIT" ]
C
buffer_to_str
char
char *buffer_to_str(const buffer_t *buf) { char *ret; if((ret = calloc(1, buf->used + 1)) == NULL) { debugf(DBG_CRIT, "%s\n", "calloc() error"); return NULL; } memmove(ret, buf->data, buf->used); return ret; }
// converts a buffer to a string and returns a copy. Does not free the buffer.
converts a buffer to a string and returns a copy. Does not free the buffer.
[ "converts", "a", "buffer", "to", "a", "string", "and", "returns", "a", "copy", ".", "Does", "not", "free", "the", "buffer", "." ]
char *buffer_to_str(const buffer_t *buf) { char *ret; if((ret = calloc(1, buf->used + 1)) == NULL) { debugf(DBG_CRIT, "%s\n", "calloc() error"); return NULL; } memmove(ret, buf->data, buf->used); return ret; }
[ "char", "*", "buffer_to_str", "(", "const", "buffer_t", "*", "buf", ")", "{", "char", "*", "ret", ";", "if", "(", "(", "ret", "=", "calloc", "(", "1", ",", "buf", "->", "used", "+", "1", ")", ")", "==", "NULL", ")", "{", "debugf", "(", "DBG_CRIT", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "NULL", ";", "}", "memmove", "(", "ret", ",", "buf", "->", "data", ",", "buf", "->", "used", ")", ";", "return", "ret", ";", "}" ]
converts a buffer to a string and returns a copy.
[ "converts", "a", "buffer", "to", "a", "string", "and", "returns", "a", "copy", "." ]
[]
[ { "param": "buf", "type": "buffer_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "buffer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
467f2ef16aac584023bb4f2d85e19e75c03f1ed0
GoodiesHQ/Roach
src/buffer.c
[ "MIT" ]
C
buffer_create
buffer_t
buffer_t *buffer_create(void) { buffer_t *buf; if((buf = calloc(1, sizeof(buffer_t))) == NULL) { debugf(DBG_CRIT, "%s\n", "calloc() error"); return NULL; } return buf; }
// creates a buffer object. Returns NULL on failure;
creates a buffer object. Returns NULL on failure.
[ "creates", "a", "buffer", "object", ".", "Returns", "NULL", "on", "failure", "." ]
buffer_t *buffer_create(void) { buffer_t *buf; if((buf = calloc(1, sizeof(buffer_t))) == NULL) { debugf(DBG_CRIT, "%s\n", "calloc() error"); return NULL; } return buf; }
[ "buffer_t", "*", "buffer_create", "(", "void", ")", "{", "buffer_t", "*", "buf", ";", "if", "(", "(", "buf", "=", "calloc", "(", "1", ",", "sizeof", "(", "buffer_t", ")", ")", ")", "==", "NULL", ")", "{", "debugf", "(", "DBG_CRIT", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "NULL", ";", "}", "return", "buf", ";", "}" ]
creates a buffer object.
[ "creates", "a", "buffer", "object", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
467f2ef16aac584023bb4f2d85e19e75c03f1ed0
GoodiesHQ/Roach
src/buffer.c
[ "MIT" ]
C
buffer_append
status_t
status_t buffer_append(buffer_t *buf, const void *data, const size_t size) { char *tmp; const size_t orig_used = buf->used, orig_allocated = buf->allocated; buf->used += size; if(buf->allocated <= buf->used) { buf->allocated = ALIGN(buf->used, BUFFER_CHUNK); // aligns to the nearest multiple of BUFFER_CHUNK if((tmp = realloc(buf->data, buf->allocated)) == NULL) { buf->allocated = orig_allocated; debugf(DBG_CRIT, "%s\n", "realloc() error."); return FAILURE; } buf->data = tmp; } memmove(buf->data + orig_used, data, size); return SUCCESS; }
// appends data to a buffer with a given size. Buffer dynamically grows as needed.
appends data to a buffer with a given size. Buffer dynamically grows as needed.
[ "appends", "data", "to", "a", "buffer", "with", "a", "given", "size", ".", "Buffer", "dynamically", "grows", "as", "needed", "." ]
status_t buffer_append(buffer_t *buf, const void *data, const size_t size) { char *tmp; const size_t orig_used = buf->used, orig_allocated = buf->allocated; buf->used += size; if(buf->allocated <= buf->used) { buf->allocated = ALIGN(buf->used, BUFFER_CHUNK); if((tmp = realloc(buf->data, buf->allocated)) == NULL) { buf->allocated = orig_allocated; debugf(DBG_CRIT, "%s\n", "realloc() error."); return FAILURE; } buf->data = tmp; } memmove(buf->data + orig_used, data, size); return SUCCESS; }
[ "status_t", "buffer_append", "(", "buffer_t", "*", "buf", ",", "const", "void", "*", "data", ",", "const", "size_t", "size", ")", "{", "char", "*", "tmp", ";", "const", "size_t", "orig_used", "=", "buf", "->", "used", ",", "orig_allocated", "=", "buf", "->", "allocated", ";", "buf", "->", "used", "+=", "size", ";", "if", "(", "buf", "->", "allocated", "<=", "buf", "->", "used", ")", "{", "buf", "->", "allocated", "=", "ALIGN", "(", "buf", "->", "used", ",", "BUFFER_CHUNK", ")", ";", "if", "(", "(", "tmp", "=", "realloc", "(", "buf", "->", "data", ",", "buf", "->", "allocated", ")", ")", "==", "NULL", ")", "{", "buf", "->", "allocated", "=", "orig_allocated", ";", "debugf", "(", "DBG_CRIT", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "FAILURE", ";", "}", "buf", "->", "data", "=", "tmp", ";", "}", "memmove", "(", "buf", "->", "data", "+", "orig_used", ",", "data", ",", "size", ")", ";", "return", "SUCCESS", ";", "}" ]
appends data to a buffer with a given size.
[ "appends", "data", "to", "a", "buffer", "with", "a", "given", "size", "." ]
[ "// aligns to the nearest multiple of BUFFER_CHUNK" ]
[ { "param": "buf", "type": "buffer_t" }, { "param": "data", "type": "void" }, { "param": "size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "buffer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
41b9f6ad4d76a6520e637373007a1411cc12292c
GoodiesHQ/Roach
src/url.c
[ "MIT" ]
C
url_create
url_t
url_t * url_create(const char *uri) { const size_t uriSize = strlen(uri); // length of the original URI size_t tokenSize, protoSize; // string lengths char *uriStr, *token, *tokenPtr, *tokenHost, *tokenPtrHost, *tmp; // tokens for parsing url_t *url; if((url = (url_t*)calloc(1, sizeof(url_t))) == NULL) { debugf(DBG_CRIT, "%s\n", "calloc() failure"); return NULL; } if((uriStr = (char*)calloc(1, uriSize + 1)) == NULL) { url_destroy(&url); debugf(DBG_CRIT, "%s\n", "calloc() failure"); return NULL; } memmove(uriStr, uri, uriSize); // Determine the protocol token = strtok_r(uriStr, ":", &tokenPtr); debugf(DBG_INFO, "URL Protocol: %s\n", token); // Only HTTP is going to be supported to keep the binary small and monolithic if(strcmp(token, HTTP_PROTO) != 0) { free(uriStr); url_destroy(&url); debugf(DBG_MAJOR, "Protocol '%s' is not supported\n", token); return NULL; } protoSize = strlen(token); url->proto = (char*)malloc(protoSize); strncpy(url->proto, token, protoSize); if((token = strtok_r(NULL, "/", &tokenPtr)) != NULL) { tokenSize = strlen(token); tokenHost = (char*)malloc(tokenSize + 1); strncpy(tokenHost, token, tokenSize); } else { free(uriStr); url_destroy(&url); debugf(DBG_MAJOR, "%s\n", "The token was NULL."); return NULL; } if((token = strtok_r(tokenHost, ":", &tokenPtrHost)) != NULL) { printf("LOL 1: %s\n", token); tokenSize = strlen(token); url->host = (char*)malloc(tokenSize + 1); strncpy(url->host, token, tokenSize); } else { free(tokenHost); url_destroy(&url); debugf(DBG_MAJOR, "%s\n", "The token was NULL."); return NULL; } debugf(DBG_INFO, "Host: %s\n", url->host); if((token = strtok_r(NULL, ":", &tokenPtrHost)) == NULL) { tokenSize = strlen(DEFAULT_HTTP_PORT); url->port = calloc(1, tokenSize + 1); strncpy(url->port, DEFAULT_HTTP_PORT, tokenSize); } else { strtol(token, &tmp, 10); if(*tmp) { debugf(DBG_MAJOR, "'%s' is an invalid port\n", token); free(tokenHost); free(uriStr); url_destroy(&url); return NULL; } tokenSize = strlen(token); url->port = calloc(1, tokenSize + 1); strncpy(url->port, token, tokenSize); } debugf(DBG_INFO, "Port: %s\n", url->port); if((token = strtok_r(NULL, "?", &tokenPtr)) == NULL) { // There is no more to parse. Use default HTTP path. url->path = (char*)calloc(1, 2); strcpy(url->path, "/"); } else { tokenSize = strlen(token); url->path = (char*)calloc(1, tokenSize + 2); strcpy(url->path, "/"); strcpy(url->path + 1, token); } debugf(DBG_INFO, "Path: %s\n", url->path); if((token = strtok_r(NULL, "?", &tokenPtr)) == NULL) { // There is no more to parse. Use empty HTTP query. url->query = (char*)calloc(1, 1); } else { tokenSize = strlen(token); url->query = (char*)calloc(1, tokenSize + 1); strncpy(url->query, token, tokenSize); } debugf(DBG_INFO, "Query: %s\n", url->query); free(tokenHost); free(uriStr); return url; }
// A likely very buggy URL parser, but functional for my purposes
A likely very buggy URL parser, but functional for my purposes
[ "A", "likely", "very", "buggy", "URL", "parser", "but", "functional", "for", "my", "purposes" ]
url_t * url_create(const char *uri) { const size_t uriSize = strlen(uri); size_t tokenSize, protoSize; char *uriStr, *token, *tokenPtr, *tokenHost, *tokenPtrHost, *tmp; url_t *url; if((url = (url_t*)calloc(1, sizeof(url_t))) == NULL) { debugf(DBG_CRIT, "%s\n", "calloc() failure"); return NULL; } if((uriStr = (char*)calloc(1, uriSize + 1)) == NULL) { url_destroy(&url); debugf(DBG_CRIT, "%s\n", "calloc() failure"); return NULL; } memmove(uriStr, uri, uriSize); token = strtok_r(uriStr, ":", &tokenPtr); debugf(DBG_INFO, "URL Protocol: %s\n", token); if(strcmp(token, HTTP_PROTO) != 0) { free(uriStr); url_destroy(&url); debugf(DBG_MAJOR, "Protocol '%s' is not supported\n", token); return NULL; } protoSize = strlen(token); url->proto = (char*)malloc(protoSize); strncpy(url->proto, token, protoSize); if((token = strtok_r(NULL, "/", &tokenPtr)) != NULL) { tokenSize = strlen(token); tokenHost = (char*)malloc(tokenSize + 1); strncpy(tokenHost, token, tokenSize); } else { free(uriStr); url_destroy(&url); debugf(DBG_MAJOR, "%s\n", "The token was NULL."); return NULL; } if((token = strtok_r(tokenHost, ":", &tokenPtrHost)) != NULL) { printf("LOL 1: %s\n", token); tokenSize = strlen(token); url->host = (char*)malloc(tokenSize + 1); strncpy(url->host, token, tokenSize); } else { free(tokenHost); url_destroy(&url); debugf(DBG_MAJOR, "%s\n", "The token was NULL."); return NULL; } debugf(DBG_INFO, "Host: %s\n", url->host); if((token = strtok_r(NULL, ":", &tokenPtrHost)) == NULL) { tokenSize = strlen(DEFAULT_HTTP_PORT); url->port = calloc(1, tokenSize + 1); strncpy(url->port, DEFAULT_HTTP_PORT, tokenSize); } else { strtol(token, &tmp, 10); if(*tmp) { debugf(DBG_MAJOR, "'%s' is an invalid port\n", token); free(tokenHost); free(uriStr); url_destroy(&url); return NULL; } tokenSize = strlen(token); url->port = calloc(1, tokenSize + 1); strncpy(url->port, token, tokenSize); } debugf(DBG_INFO, "Port: %s\n", url->port); if((token = strtok_r(NULL, "?", &tokenPtr)) == NULL) { url->path = (char*)calloc(1, 2); strcpy(url->path, "/"); } else { tokenSize = strlen(token); url->path = (char*)calloc(1, tokenSize + 2); strcpy(url->path, "/"); strcpy(url->path + 1, token); } debugf(DBG_INFO, "Path: %s\n", url->path); if((token = strtok_r(NULL, "?", &tokenPtr)) == NULL) { url->query = (char*)calloc(1, 1); } else { tokenSize = strlen(token); url->query = (char*)calloc(1, tokenSize + 1); strncpy(url->query, token, tokenSize); } debugf(DBG_INFO, "Query: %s\n", url->query); free(tokenHost); free(uriStr); return url; }
[ "url_t", "*", "url_create", "(", "const", "char", "*", "uri", ")", "{", "const", "size_t", "uriSize", "=", "strlen", "(", "uri", ")", ";", "size_t", "tokenSize", ",", "protoSize", ";", "char", "*", "uriStr", ",", "*", "token", ",", "*", "tokenPtr", ",", "*", "tokenHost", ",", "*", "tokenPtrHost", ",", "*", "tmp", ";", "url_t", "*", "url", ";", "if", "(", "(", "url", "=", "(", "url_t", "*", ")", "calloc", "(", "1", ",", "sizeof", "(", "url_t", ")", ")", ")", "==", "NULL", ")", "{", "debugf", "(", "DBG_CRIT", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "NULL", ";", "}", "if", "(", "(", "uriStr", "=", "(", "char", "*", ")", "calloc", "(", "1", ",", "uriSize", "+", "1", ")", ")", "==", "NULL", ")", "{", "url_destroy", "(", "&", "url", ")", ";", "debugf", "(", "DBG_CRIT", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "NULL", ";", "}", "memmove", "(", "uriStr", ",", "uri", ",", "uriSize", ")", ";", "token", "=", "strtok_r", "(", "uriStr", ",", "\"", "\"", ",", "&", "tokenPtr", ")", ";", "debugf", "(", "DBG_INFO", ",", "\"", "\\n", "\"", ",", "token", ")", ";", "if", "(", "strcmp", "(", "token", ",", "HTTP_PROTO", ")", "!=", "0", ")", "{", "free", "(", "uriStr", ")", ";", "url_destroy", "(", "&", "url", ")", ";", "debugf", "(", "DBG_MAJOR", ",", "\"", "\\n", "\"", ",", "token", ")", ";", "return", "NULL", ";", "}", "protoSize", "=", "strlen", "(", "token", ")", ";", "url", "->", "proto", "=", "(", "char", "*", ")", "malloc", "(", "protoSize", ")", ";", "strncpy", "(", "url", "->", "proto", ",", "token", ",", "protoSize", ")", ";", "if", "(", "(", "token", "=", "strtok_r", "(", "NULL", ",", "\"", "\"", ",", "&", "tokenPtr", ")", ")", "!=", "NULL", ")", "{", "tokenSize", "=", "strlen", "(", "token", ")", ";", "tokenHost", "=", "(", "char", "*", ")", "malloc", "(", "tokenSize", "+", "1", ")", ";", "strncpy", "(", "tokenHost", ",", "token", ",", "tokenSize", ")", ";", "}", "else", "{", "free", "(", "uriStr", ")", ";", "url_destroy", "(", "&", "url", ")", ";", "debugf", "(", "DBG_MAJOR", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "NULL", ";", "}", "if", "(", "(", "token", "=", "strtok_r", "(", "tokenHost", ",", "\"", "\"", ",", "&", "tokenPtrHost", ")", ")", "!=", "NULL", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "token", ")", ";", "tokenSize", "=", "strlen", "(", "token", ")", ";", "url", "->", "host", "=", "(", "char", "*", ")", "malloc", "(", "tokenSize", "+", "1", ")", ";", "strncpy", "(", "url", "->", "host", ",", "token", ",", "tokenSize", ")", ";", "}", "else", "{", "free", "(", "tokenHost", ")", ";", "url_destroy", "(", "&", "url", ")", ";", "debugf", "(", "DBG_MAJOR", ",", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "return", "NULL", ";", "}", "debugf", "(", "DBG_INFO", ",", "\"", "\\n", "\"", ",", "url", "->", "host", ")", ";", "if", "(", "(", "token", "=", "strtok_r", "(", "NULL", ",", "\"", "\"", ",", "&", "tokenPtrHost", ")", ")", "==", "NULL", ")", "{", "tokenSize", "=", "strlen", "(", "DEFAULT_HTTP_PORT", ")", ";", "url", "->", "port", "=", "calloc", "(", "1", ",", "tokenSize", "+", "1", ")", ";", "strncpy", "(", "url", "->", "port", ",", "DEFAULT_HTTP_PORT", ",", "tokenSize", ")", ";", "}", "else", "{", "strtol", "(", "token", ",", "&", "tmp", ",", "10", ")", ";", "if", "(", "*", "tmp", ")", "{", "debugf", "(", "DBG_MAJOR", ",", "\"", "\\n", "\"", ",", "token", ")", ";", "free", "(", "tokenHost", ")", ";", "free", "(", "uriStr", ")", ";", "url_destroy", "(", "&", "url", ")", ";", "return", "NULL", ";", "}", "tokenSize", "=", "strlen", "(", "token", ")", ";", "url", "->", "port", "=", "calloc", "(", "1", ",", "tokenSize", "+", "1", ")", ";", "strncpy", "(", "url", "->", "port", ",", "token", ",", "tokenSize", ")", ";", "}", "debugf", "(", "DBG_INFO", ",", "\"", "\\n", "\"", ",", "url", "->", "port", ")", ";", "if", "(", "(", "token", "=", "strtok_r", "(", "NULL", ",", "\"", "\"", ",", "&", "tokenPtr", ")", ")", "==", "NULL", ")", "{", "url", "->", "path", "=", "(", "char", "*", ")", "calloc", "(", "1", ",", "2", ")", ";", "strcpy", "(", "url", "->", "path", ",", "\"", "\"", ")", ";", "}", "else", "{", "tokenSize", "=", "strlen", "(", "token", ")", ";", "url", "->", "path", "=", "(", "char", "*", ")", "calloc", "(", "1", ",", "tokenSize", "+", "2", ")", ";", "strcpy", "(", "url", "->", "path", ",", "\"", "\"", ")", ";", "strcpy", "(", "url", "->", "path", "+", "1", ",", "token", ")", ";", "}", "debugf", "(", "DBG_INFO", ",", "\"", "\\n", "\"", ",", "url", "->", "path", ")", ";", "if", "(", "(", "token", "=", "strtok_r", "(", "NULL", ",", "\"", "\"", ",", "&", "tokenPtr", ")", ")", "==", "NULL", ")", "{", "url", "->", "query", "=", "(", "char", "*", ")", "calloc", "(", "1", ",", "1", ")", ";", "}", "else", "{", "tokenSize", "=", "strlen", "(", "token", ")", ";", "url", "->", "query", "=", "(", "char", "*", ")", "calloc", "(", "1", ",", "tokenSize", "+", "1", ")", ";", "strncpy", "(", "url", "->", "query", ",", "token", ",", "tokenSize", ")", ";", "}", "debugf", "(", "DBG_INFO", ",", "\"", "\\n", "\"", ",", "url", "->", "query", ")", ";", "free", "(", "tokenHost", ")", ";", "free", "(", "uriStr", ")", ";", "return", "url", ";", "}" ]
A likely very buggy URL parser, but functional for my purposes
[ "A", "likely", "very", "buggy", "URL", "parser", "but", "functional", "for", "my", "purposes" ]
[ "// length of the original URI", "// string lengths", "// tokens for parsing", "// Determine the protocol", "// Only HTTP is going to be supported to keep the binary small and monolithic", "// There is no more to parse. Use default HTTP path.", "// There is no more to parse. Use empty HTTP query." ]
[ { "param": "uri", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "uri", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4a46f1aa8889c8bfb0f64386d09927e2e7e07ef5
ZiyiLikeIt/ETX_Firmware
evrs_tx_cc2650etx_app/src/evrs_tx_main.c
[ "MIT" ]
C
ETX_enqueueMsg
void
static void ETX_enqueueMsg(uint8_t event, uint8_t state) { SbpEvt_t *pMsg; // Create dynamic pointer to message. if ((pMsg = ICall_malloc(sizeof(SbpEvt_t)))) { pMsg->hdr.event = event; pMsg->hdr.state = state; // Enqueue the message. Util_enqueueMsg(appMsgQueue, sem, (uint8*) pMsg); } }
/** Creates a message and puts the message in RTOS queue **/
Creates a message and puts the message in RTOS queue
[ "Creates", "a", "message", "and", "puts", "the", "message", "in", "RTOS", "queue" ]
static void ETX_enqueueMsg(uint8_t event, uint8_t state) { SbpEvt_t *pMsg; if ((pMsg = ICall_malloc(sizeof(SbpEvt_t)))) { pMsg->hdr.event = event; pMsg->hdr.state = state; Util_enqueueMsg(appMsgQueue, sem, (uint8*) pMsg); } }
[ "static", "void", "ETX_enqueueMsg", "(", "uint8_t", "event", ",", "uint8_t", "state", ")", "{", "SbpEvt_t", "*", "pMsg", ";", "if", "(", "(", "pMsg", "=", "ICall_malloc", "(", "sizeof", "(", "SbpEvt_t", ")", ")", ")", ")", "{", "pMsg", "->", "hdr", ".", "event", "=", "event", ";", "pMsg", "->", "hdr", ".", "state", "=", "state", ";", "Util_enqueueMsg", "(", "appMsgQueue", ",", "sem", ",", "(", "uint8", "*", ")", "pMsg", ")", ";", "}", "}" ]
Creates a message and puts the message in RTOS queue
[ "Creates", "a", "message", "and", "puts", "the", "message", "in", "RTOS", "queue" ]
[ "// Create dynamic pointer to message.\r", "// Enqueue the message.\r" ]
[ { "param": "event", "type": "uint8_t" }, { "param": "state", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "event", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "state", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
407d15cff2a9d40295cb14bd3409daf9070a4298
ZiyiLikeIt/ETX_Firmware
evrs_tx_cc2650etx_app/src/etx_gatt_prof.c
[ "MIT" ]
C
ETXProfile_AddService
bStatus_t
bStatus_t ETXProfile_AddService(uint32 services) { uint8 status; // Allocate Client Characteristic Configuration table // Initialize Client Characteristic Configuration attributes //GATTServApp_InitCharCfg( INVALID_CONNHANDLE, ETXProfileDataConfig ); if (services & ETXPROFILE_SERVICE) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService(ETXProfileAttrTbl, GATT_NUM_ATTRS(ETXProfileAttrTbl), GATT_MAX_ENCRYPT_KEY_SIZE, &ETXProfileCBs); } else { status = SUCCESS; } return (status); }
/********************************************************************* * @fn ETXProfile_AddService * * @brief Initializes the ETX Profile service by registering * GATT attributes with the GATT server. * * @param services - services to add. This is a bit map and can * contain more than one service. * * @return Success or Failure */
@fn ETXProfile_AddService @brief Initializes the ETX Profile service by registering GATT attributes with the GATT server. @param services - services to add. This is a bit map and can contain more than one service. @return Success or Failure
[ "@fn", "ETXProfile_AddService", "@brief", "Initializes", "the", "ETX", "Profile", "service", "by", "registering", "GATT", "attributes", "with", "the", "GATT", "server", ".", "@param", "services", "-", "services", "to", "add", ".", "This", "is", "a", "bit", "map", "and", "can", "contain", "more", "than", "one", "service", ".", "@return", "Success", "or", "Failure" ]
bStatus_t ETXProfile_AddService(uint32 services) { uint8 status; if (services & ETXPROFILE_SERVICE) { status = GATTServApp_RegisterService(ETXProfileAttrTbl, GATT_NUM_ATTRS(ETXProfileAttrTbl), GATT_MAX_ENCRYPT_KEY_SIZE, &ETXProfileCBs); } else { status = SUCCESS; } return (status); }
[ "bStatus_t", "ETXProfile_AddService", "(", "uint32", "services", ")", "{", "uint8", "status", ";", "if", "(", "services", "&", "ETXPROFILE_SERVICE", ")", "{", "status", "=", "GATTServApp_RegisterService", "(", "ETXProfileAttrTbl", ",", "GATT_NUM_ATTRS", "(", "ETXProfileAttrTbl", ")", ",", "GATT_MAX_ENCRYPT_KEY_SIZE", ",", "&", "ETXProfileCBs", ")", ";", "}", "else", "{", "status", "=", "SUCCESS", ";", "}", "return", "(", "status", ")", ";", "}" ]
@fn ETXProfile_AddService @brief Initializes the ETX Profile service by registering GATT attributes with the GATT server.
[ "@fn", "ETXProfile_AddService", "@brief", "Initializes", "the", "ETX", "Profile", "service", "by", "registering", "GATT", "attributes", "with", "the", "GATT", "server", "." ]
[ "// Allocate Client Characteristic Configuration table", "// Initialize Client Characteristic Configuration attributes", "//GATTServApp_InitCharCfg( INVALID_CONNHANDLE, ETXProfileDataConfig );", "// Register GATT attribute list and CBs with GATT Server App" ]
[ { "param": "services", "type": "uint32" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "services", "type": "uint32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
407d15cff2a9d40295cb14bd3409daf9070a4298
ZiyiLikeIt/ETX_Firmware
evrs_tx_cc2650etx_app/src/etx_gatt_prof.c
[ "MIT" ]
C
ETXProfile_RegisterAppCBs
bStatus_t
bStatus_t ETXProfile_RegisterAppCBs(ETXProfileCBs_t *appCallbacks) { if (appCallbacks) { ETXProfile_AppCBs = appCallbacks; return ( SUCCESS); } else { return ( bleAlreadyInRequestedMode); } }
/********************************************************************* * @fn ETXProfile_RegisterAppCBs * * @brief Registers the application callback function. Only call * this function once. * * @param callbacks - pointer to application callbacks. * * @return SUCCESS or bleAlreadyInRequestedMode */
@fn ETXProfile_RegisterAppCBs @brief Registers the application callback function. Only call this function once. @param callbacks - pointer to application callbacks. @return SUCCESS or bleAlreadyInRequestedMode
[ "@fn", "ETXProfile_RegisterAppCBs", "@brief", "Registers", "the", "application", "callback", "function", ".", "Only", "call", "this", "function", "once", ".", "@param", "callbacks", "-", "pointer", "to", "application", "callbacks", ".", "@return", "SUCCESS", "or", "bleAlreadyInRequestedMode" ]
bStatus_t ETXProfile_RegisterAppCBs(ETXProfileCBs_t *appCallbacks) { if (appCallbacks) { ETXProfile_AppCBs = appCallbacks; return ( SUCCESS); } else { return ( bleAlreadyInRequestedMode); } }
[ "bStatus_t", "ETXProfile_RegisterAppCBs", "(", "ETXProfileCBs_t", "*", "appCallbacks", ")", "{", "if", "(", "appCallbacks", ")", "{", "ETXProfile_AppCBs", "=", "appCallbacks", ";", "return", "(", "SUCCESS", ")", ";", "}", "else", "{", "return", "(", "bleAlreadyInRequestedMode", ")", ";", "}", "}" ]
@fn ETXProfile_RegisterAppCBs @brief Registers the application callback function.
[ "@fn", "ETXProfile_RegisterAppCBs", "@brief", "Registers", "the", "application", "callback", "function", "." ]
[]
[ { "param": "appCallbacks", "type": "ETXProfileCBs_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "appCallbacks", "type": "ETXProfileCBs_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
407d15cff2a9d40295cb14bd3409daf9070a4298
ZiyiLikeIt/ETX_Firmware
evrs_tx_cc2650etx_app/src/etx_gatt_prof.c
[ "MIT" ]
C
ETXProfile_SetParameter
bStatus_t
bStatus_t ETXProfile_SetParameter(uint8 param, uint8 len, void *value) { bStatus_t rtn = SUCCESS; switch (param) { case ETXPROFILE_CMD: if (len == sizeof(uint8)) { ETXProfileCmd = *((uint8*) value); } else { rtn = bleInvalidRange; } break; case ETXPROFILE_DATA: if (len == sizeof(uint8)) { ETXProfileData = *((uint8*) value); } else { rtn = bleInvalidRange; } break; default: rtn = INVALIDPARAMETER; break; } return (rtn); }
/********************************************************************* * @fn ETXProfile_SetParameter * * @brief Set a ETX Profile parameter. * * @param param - Profile parameter ID * @param len - length of data to write * @param value - pointer to data to write. This is dependent on * the parameter ID and WILL be cast to the appropriate * data type (example: data type of uint16 will be cast to * uint16 pointer). * * @return bStatus_t */
@fn ETXProfile_SetParameter @brief Set a ETX Profile parameter. @param param - Profile parameter ID @param len - length of data to write @param value - pointer to data to write. This is dependent on the parameter ID and WILL be cast to the appropriate data type (example: data type of uint16 will be cast to uint16 pointer).
[ "@fn", "ETXProfile_SetParameter", "@brief", "Set", "a", "ETX", "Profile", "parameter", ".", "@param", "param", "-", "Profile", "parameter", "ID", "@param", "len", "-", "length", "of", "data", "to", "write", "@param", "value", "-", "pointer", "to", "data", "to", "write", ".", "This", "is", "dependent", "on", "the", "parameter", "ID", "and", "WILL", "be", "cast", "to", "the", "appropriate", "data", "type", "(", "example", ":", "data", "type", "of", "uint16", "will", "be", "cast", "to", "uint16", "pointer", ")", "." ]
bStatus_t ETXProfile_SetParameter(uint8 param, uint8 len, void *value) { bStatus_t rtn = SUCCESS; switch (param) { case ETXPROFILE_CMD: if (len == sizeof(uint8)) { ETXProfileCmd = *((uint8*) value); } else { rtn = bleInvalidRange; } break; case ETXPROFILE_DATA: if (len == sizeof(uint8)) { ETXProfileData = *((uint8*) value); } else { rtn = bleInvalidRange; } break; default: rtn = INVALIDPARAMETER; break; } return (rtn); }
[ "bStatus_t", "ETXProfile_SetParameter", "(", "uint8", "param", ",", "uint8", "len", ",", "void", "*", "value", ")", "{", "bStatus_t", "rtn", "=", "SUCCESS", ";", "switch", "(", "param", ")", "{", "case", "ETXPROFILE_CMD", ":", "if", "(", "len", "==", "sizeof", "(", "uint8", ")", ")", "{", "ETXProfileCmd", "=", "*", "(", "(", "uint8", "*", ")", "value", ")", ";", "}", "else", "{", "rtn", "=", "bleInvalidRange", ";", "}", "break", ";", "case", "ETXPROFILE_DATA", ":", "if", "(", "len", "==", "sizeof", "(", "uint8", ")", ")", "{", "ETXProfileData", "=", "*", "(", "(", "uint8", "*", ")", "value", ")", ";", "}", "else", "{", "rtn", "=", "bleInvalidRange", ";", "}", "break", ";", "default", ":", "rtn", "=", "INVALIDPARAMETER", ";", "break", ";", "}", "return", "(", "rtn", ")", ";", "}" ]
@fn ETXProfile_SetParameter @brief Set a ETX Profile parameter.
[ "@fn", "ETXProfile_SetParameter", "@brief", "Set", "a", "ETX", "Profile", "parameter", "." ]
[]
[ { "param": "param", "type": "uint8" }, { "param": "len", "type": "uint8" }, { "param": "value", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "param", "type": "uint8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "uint8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "value", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
407d15cff2a9d40295cb14bd3409daf9070a4298
ZiyiLikeIt/ETX_Firmware
evrs_tx_cc2650etx_app/src/etx_gatt_prof.c
[ "MIT" ]
C
ETXProfile_GetParameter
bStatus_t
bStatus_t ETXProfile_GetParameter(uint8 param, void *value) { bStatus_t rtn = SUCCESS; switch (param) { case ETXPROFILE_CMD: *((uint8*) value) = ETXProfileCmd; break; case ETXPROFILE_DATA: *((uint8*) value) = ETXProfileData; break; default: rtn = INVALIDPARAMETER; break; } return (rtn); }
/********************************************************************* * @fn ETXProfile_GetParameter * * @brief Get a ETX Profile parameter. * * @param param - Profile parameter ID * @param value - pointer to data to put. This is dependent on * the parameter ID and WILL be cast to the appropriate * data type (example: data type of uint16 will be cast to * uint16 pointer). * * @return bStatus_t */
@fn ETXProfile_GetParameter @brief Get a ETX Profile parameter. @param param - Profile parameter ID @param value - pointer to data to put. This is dependent on the parameter ID and WILL be cast to the appropriate data type (example: data type of uint16 will be cast to uint16 pointer).
[ "@fn", "ETXProfile_GetParameter", "@brief", "Get", "a", "ETX", "Profile", "parameter", ".", "@param", "param", "-", "Profile", "parameter", "ID", "@param", "value", "-", "pointer", "to", "data", "to", "put", ".", "This", "is", "dependent", "on", "the", "parameter", "ID", "and", "WILL", "be", "cast", "to", "the", "appropriate", "data", "type", "(", "example", ":", "data", "type", "of", "uint16", "will", "be", "cast", "to", "uint16", "pointer", ")", "." ]
bStatus_t ETXProfile_GetParameter(uint8 param, void *value) { bStatus_t rtn = SUCCESS; switch (param) { case ETXPROFILE_CMD: *((uint8*) value) = ETXProfileCmd; break; case ETXPROFILE_DATA: *((uint8*) value) = ETXProfileData; break; default: rtn = INVALIDPARAMETER; break; } return (rtn); }
[ "bStatus_t", "ETXProfile_GetParameter", "(", "uint8", "param", ",", "void", "*", "value", ")", "{", "bStatus_t", "rtn", "=", "SUCCESS", ";", "switch", "(", "param", ")", "{", "case", "ETXPROFILE_CMD", ":", "*", "(", "(", "uint8", "*", ")", "value", ")", "=", "ETXProfileCmd", ";", "break", ";", "case", "ETXPROFILE_DATA", ":", "*", "(", "(", "uint8", "*", ")", "value", ")", "=", "ETXProfileData", ";", "break", ";", "default", ":", "rtn", "=", "INVALIDPARAMETER", ";", "break", ";", "}", "return", "(", "rtn", ")", ";", "}" ]
@fn ETXProfile_GetParameter @brief Get a ETX Profile parameter.
[ "@fn", "ETXProfile_GetParameter", "@brief", "Get", "a", "ETX", "Profile", "parameter", "." ]
[]
[ { "param": "param", "type": "uint8" }, { "param": "value", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "param", "type": "uint8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "value", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
407d15cff2a9d40295cb14bd3409daf9070a4298
ZiyiLikeIt/ETX_Firmware
evrs_tx_cc2650etx_app/src/etx_gatt_prof.c
[ "MIT" ]
C
ETXProfile_WriteAttrCB
bStatus_t
static bStatus_t ETXProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method) { bStatus_t status = SUCCESS; uint8 notifyApp = 0xFF; if (pAttr->type.len == ATT_BT_UUID_SIZE) { // 16-bit UUID uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]); switch (uuid) { case ETXPROFILE_CMD_UUID: //Validate the value // Make sure it's not a blob oper if (offset == 0) { if (len != 1) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } //Write the value if (status == SUCCESS) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; notifyApp = ETXPROFILE_CMD; } break; case ETXPROFILE_DATA_UUID: default: // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { // 128-bit UUID status = ATT_ERR_INVALID_HANDLE; } // If a characteristic value changed then callback function to notify application if ((notifyApp != 0xFF) && ETXProfile_AppCBs && ETXProfile_AppCBs->pfnETXProfileChange) { ETXProfile_AppCBs->pfnETXProfileChange(notifyApp); } return (status); }
/********************************************************************* * @fn ETXProfile_WriteAttrCB * * @brief Validate attribute data prior to a write operation * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be written * @param len - length of data * @param offset - offset of the first octet to be written * @param method - type of write message * * @return SUCCESS, blePending or Failure */
@fn ETXProfile_WriteAttrCB @brief Validate attribute data prior to a write operation @return SUCCESS, blePending or Failure
[ "@fn", "ETXProfile_WriteAttrCB", "@brief", "Validate", "attribute", "data", "prior", "to", "a", "write", "operation", "@return", "SUCCESS", "blePending", "or", "Failure" ]
static bStatus_t ETXProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method) { bStatus_t status = SUCCESS; uint8 notifyApp = 0xFF; if (pAttr->type.len == ATT_BT_UUID_SIZE) { uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]); switch (uuid) { case ETXPROFILE_CMD_UUID: if (offset == 0) { if (len != 1) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } if (status == SUCCESS) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; notifyApp = ETXPROFILE_CMD; } break; case ETXPROFILE_DATA_UUID: default: status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { status = ATT_ERR_INVALID_HANDLE; } if ((notifyApp != 0xFF) && ETXProfile_AppCBs && ETXProfile_AppCBs->pfnETXProfileChange) { ETXProfile_AppCBs->pfnETXProfileChange(notifyApp); } return (status); }
[ "static", "bStatus_t", "ETXProfile_WriteAttrCB", "(", "uint16_t", "connHandle", ",", "gattAttribute_t", "*", "pAttr", ",", "uint8_t", "*", "pValue", ",", "uint16_t", "len", ",", "uint16_t", "offset", ",", "uint8_t", "method", ")", "{", "bStatus_t", "status", "=", "SUCCESS", ";", "uint8", "notifyApp", "=", "0xFF", ";", "if", "(", "pAttr", "->", "type", ".", "len", "==", "ATT_BT_UUID_SIZE", ")", "{", "uint16", "uuid", "=", "BUILD_UINT16", "(", "pAttr", "->", "type", ".", "uuid", "[", "0", "]", ",", "pAttr", "->", "type", ".", "uuid", "[", "1", "]", ")", ";", "switch", "(", "uuid", ")", "{", "case", "ETXPROFILE_CMD_UUID", ":", "if", "(", "offset", "==", "0", ")", "{", "if", "(", "len", "!=", "1", ")", "{", "status", "=", "ATT_ERR_INVALID_VALUE_SIZE", ";", "}", "}", "else", "{", "status", "=", "ATT_ERR_ATTR_NOT_LONG", ";", "}", "if", "(", "status", "==", "SUCCESS", ")", "{", "uint8", "*", "pCurValue", "=", "(", "uint8", "*", ")", "pAttr", "->", "pValue", ";", "*", "pCurValue", "=", "pValue", "[", "0", "]", ";", "notifyApp", "=", "ETXPROFILE_CMD", ";", "}", "break", ";", "case", "ETXPROFILE_DATA_UUID", ":", "default", ":", "status", "=", "ATT_ERR_ATTR_NOT_FOUND", ";", "break", ";", "}", "}", "else", "{", "status", "=", "ATT_ERR_INVALID_HANDLE", ";", "}", "if", "(", "(", "notifyApp", "!=", "0xFF", ")", "&&", "ETXProfile_AppCBs", "&&", "ETXProfile_AppCBs", "->", "pfnETXProfileChange", ")", "{", "ETXProfile_AppCBs", "->", "pfnETXProfileChange", "(", "notifyApp", ")", ";", "}", "return", "(", "status", ")", ";", "}" ]
@fn ETXProfile_WriteAttrCB @brief Validate attribute data prior to a write operation
[ "@fn", "ETXProfile_WriteAttrCB", "@brief", "Validate", "attribute", "data", "prior", "to", "a", "write", "operation" ]
[ "// 16-bit UUID", "//Validate the value", "// Make sure it's not a blob oper", "//Write the value", "// Should never get here! (characteristics 2 and 4 do not have write permissions)", "// 128-bit UUID", "// If a characteristic value changed then callback function to notify application" ]
[ { "param": "connHandle", "type": "uint16_t" }, { "param": "pAttr", "type": "gattAttribute_t" }, { "param": "pValue", "type": "uint8_t" }, { "param": "len", "type": "uint16_t" }, { "param": "offset", "type": "uint16_t" }, { "param": "method", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "connHandle", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pAttr", "type": "gattAttribute_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pValue", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "offset", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "method", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
207d3ff078d604060a16c53313056afa8b19550b
abobija/esp-discord
src/discord/private/_api.c
[ "MIT" ]
C
dcapi_download_handler_fire
esp_err_t
static esp_err_t dcapi_download_handler_fire(discord_handle_t client, void* data, size_t length) { if(! client || ! client->api_download_handler) { return ESP_ERR_INVALID_ARG; } discord_download_info_t info = { .data = data, .length = length, .offset = client->api_download_offset, .total_length = client->api_download_total }; esp_err_t err = client->api_download_handler(&info, client->api_download_arg); client->api_download_offset += length; return err; }
/** * @return ESP_OK if user has not break stream of upcoming chunks */
@return ESP_OK if user has not break stream of upcoming chunks
[ "@return", "ESP_OK", "if", "user", "has", "not", "break", "stream", "of", "upcoming", "chunks" ]
static esp_err_t dcapi_download_handler_fire(discord_handle_t client, void* data, size_t length) { if(! client || ! client->api_download_handler) { return ESP_ERR_INVALID_ARG; } discord_download_info_t info = { .data = data, .length = length, .offset = client->api_download_offset, .total_length = client->api_download_total }; esp_err_t err = client->api_download_handler(&info, client->api_download_arg); client->api_download_offset += length; return err; }
[ "static", "esp_err_t", "dcapi_download_handler_fire", "(", "discord_handle_t", "client", ",", "void", "*", "data", ",", "size_t", "length", ")", "{", "if", "(", "!", "client", "||", "!", "client", "->", "api_download_handler", ")", "{", "return", "ESP_ERR_INVALID_ARG", ";", "}", "discord_download_info_t", "info", "=", "{", ".", "data", "=", "data", ",", ".", "length", "=", "length", ",", ".", "offset", "=", "client", "->", "api_download_offset", ",", ".", "total_length", "=", "client", "->", "api_download_total", "}", ";", "esp_err_t", "err", "=", "client", "->", "api_download_handler", "(", "&", "info", ",", "client", "->", "api_download_arg", ")", ";", "client", "->", "api_download_offset", "+=", "length", ";", "return", "err", ";", "}" ]
@return ESP_OK if user has not break stream of upcoming chunks
[ "@return", "ESP_OK", "if", "user", "has", "not", "break", "stream", "of", "upcoming", "chunks" ]
[]
[ { "param": "client", "type": "discord_handle_t" }, { "param": "data", "type": "void" }, { "param": "length", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "client", "type": "discord_handle_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "length", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3ba6b50edcb8baa21d3d0bb88eb6ade26b71a2fc
tomasztuzel/oss-fuzz
projects/postgresql/fuzzer/simple_query_fuzzer.c
[ "Apache-2.0" ]
C
LLVMFuzzerTestOneInput
int
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { char* query_string; sigjmp_buf local_sigjmp_buf; query_string = (char*) calloc( (size+1), sizeof(char) ); memcpy(query_string, data, size); if (!sigsetjmp(local_sigjmp_buf, 0)) { PG_exception_stack = &local_sigjmp_buf; error_context_stack = NULL; set_stack_base(); disable_all_timeouts(false); QueryCancelPending = false; pq_comm_reset(); EmitErrorReport(); AbortCurrentTransaction(); PortalErrorCleanup(); SPICleanup(); jit_reset_after_error(); MemoryContextSwitchTo(TopMemoryContext); FlushErrorState(); MemoryContextSwitchTo(MessageContext); MemoryContextResetAndDeleteChildren(MessageContext); InvalidateCatalogSnapshotConditionally(); SetCurrentStatementStartTimestamp(); exec_simple_query(query_string); } free(query_string); return 0; }
/* ** Main entry point. The fuzzer invokes this function with each ** fuzzed input. */
Main entry point. The fuzzer invokes this function with each fuzzed input.
[ "Main", "entry", "point", ".", "The", "fuzzer", "invokes", "this", "function", "with", "each", "fuzzed", "input", "." ]
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { char* query_string; sigjmp_buf local_sigjmp_buf; query_string = (char*) calloc( (size+1), sizeof(char) ); memcpy(query_string, data, size); if (!sigsetjmp(local_sigjmp_buf, 0)) { PG_exception_stack = &local_sigjmp_buf; error_context_stack = NULL; set_stack_base(); disable_all_timeouts(false); QueryCancelPending = false; pq_comm_reset(); EmitErrorReport(); AbortCurrentTransaction(); PortalErrorCleanup(); SPICleanup(); jit_reset_after_error(); MemoryContextSwitchTo(TopMemoryContext); FlushErrorState(); MemoryContextSwitchTo(MessageContext); MemoryContextResetAndDeleteChildren(MessageContext); InvalidateCatalogSnapshotConditionally(); SetCurrentStatementStartTimestamp(); exec_simple_query(query_string); } free(query_string); return 0; }
[ "int", "LLVMFuzzerTestOneInput", "(", "const", "uint8_t", "*", "data", ",", "size_t", "size", ")", "{", "char", "*", "query_string", ";", "sigjmp_buf", "local_sigjmp_buf", ";", "query_string", "=", "(", "char", "*", ")", "calloc", "(", "(", "size", "+", "1", ")", ",", "sizeof", "(", "char", ")", ")", ";", "memcpy", "(", "query_string", ",", "data", ",", "size", ")", ";", "if", "(", "!", "sigsetjmp", "(", "local_sigjmp_buf", ",", "0", ")", ")", "{", "PG_exception_stack", "=", "&", "local_sigjmp_buf", ";", "error_context_stack", "=", "NULL", ";", "set_stack_base", "(", ")", ";", "disable_all_timeouts", "(", "false", ")", ";", "QueryCancelPending", "=", "false", ";", "pq_comm_reset", "(", ")", ";", "EmitErrorReport", "(", ")", ";", "AbortCurrentTransaction", "(", ")", ";", "PortalErrorCleanup", "(", ")", ";", "SPICleanup", "(", ")", ";", "jit_reset_after_error", "(", ")", ";", "MemoryContextSwitchTo", "(", "TopMemoryContext", ")", ";", "FlushErrorState", "(", ")", ";", "MemoryContextSwitchTo", "(", "MessageContext", ")", ";", "MemoryContextResetAndDeleteChildren", "(", "MessageContext", ")", ";", "InvalidateCatalogSnapshotConditionally", "(", ")", ";", "SetCurrentStatementStartTimestamp", "(", ")", ";", "exec_simple_query", "(", "query_string", ")", ";", "}", "free", "(", "query_string", ")", ";", "return", "0", ";", "}" ]
Main entry point.
[ "Main", "entry", "point", "." ]
[]
[ { "param": "data", "type": "uint8_t" }, { "param": "size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1e325af7aa9212eb532ccaf73da4b931807dbaaa
gatzka/ciol
lib/cio/sha1/sha1.c
[ "MIT" ]
C
sha1_reset
int
int sha1_reset(sha1_context *context) { if (!context) { return SHA_NULL; } context->length_low = 0; context->length_high = 0; context->message_block_index = 0; context->intermediate_hash[0] = 0x67452301; context->intermediate_hash[1] = 0xEFCDAB89; context->intermediate_hash[2] = 0x98BADCFE; context->intermediate_hash[3] = 0x10325476; context->intermediate_hash[4] = 0xC3D2E1F0; context->computed = 0; context->corrupted = 0; return SHA_SUCCESS; }
/* * SHA1Reset * * Description: * This function will initialize the SHA1Context in preparation * for computing a new SHA1 message digest. * * Parameters: * context: [in/out] * The context to reset. * * Returns: * sha Error Code. * */
SHA1Reset Description: This function will initialize the SHA1Context in preparation for computing a new SHA1 message digest. [in/out] The context to reset. sha Error Code.
[ "SHA1Reset", "Description", ":", "This", "function", "will", "initialize", "the", "SHA1Context", "in", "preparation", "for", "computing", "a", "new", "SHA1", "message", "digest", ".", "[", "in", "/", "out", "]", "The", "context", "to", "reset", ".", "sha", "Error", "Code", "." ]
int sha1_reset(sha1_context *context) { if (!context) { return SHA_NULL; } context->length_low = 0; context->length_high = 0; context->message_block_index = 0; context->intermediate_hash[0] = 0x67452301; context->intermediate_hash[1] = 0xEFCDAB89; context->intermediate_hash[2] = 0x98BADCFE; context->intermediate_hash[3] = 0x10325476; context->intermediate_hash[4] = 0xC3D2E1F0; context->computed = 0; context->corrupted = 0; return SHA_SUCCESS; }
[ "int", "sha1_reset", "(", "sha1_context", "*", "context", ")", "{", "if", "(", "!", "context", ")", "{", "return", "SHA_NULL", ";", "}", "context", "->", "length_low", "=", "0", ";", "context", "->", "length_high", "=", "0", ";", "context", "->", "message_block_index", "=", "0", ";", "context", "->", "intermediate_hash", "[", "0", "]", "=", "0x67452301", ";", "context", "->", "intermediate_hash", "[", "1", "]", "=", "0xEFCDAB89", ";", "context", "->", "intermediate_hash", "[", "2", "]", "=", "0x98BADCFE", ";", "context", "->", "intermediate_hash", "[", "3", "]", "=", "0x10325476", ";", "context", "->", "intermediate_hash", "[", "4", "]", "=", "0xC3D2E1F0", ";", "context", "->", "computed", "=", "0", ";", "context", "->", "corrupted", "=", "0", ";", "return", "SHA_SUCCESS", ";", "}" ]
SHA1Reset Description: This function will initialize the SHA1Context in preparation for computing a new SHA1 message digest.
[ "SHA1Reset", "Description", ":", "This", "function", "will", "initialize", "the", "SHA1Context", "in", "preparation", "for", "computing", "a", "new", "SHA1", "message", "digest", "." ]
[]
[ { "param": "context", "type": "sha1_context" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "sha1_context", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1e325af7aa9212eb532ccaf73da4b931807dbaaa
gatzka/ciol
lib/cio/sha1/sha1.c
[ "MIT" ]
C
sha1_process_message_block
void
static void sha1_process_message_block(sha1_context *context) { const uint32_t K[] = {/* Constants defined in SHA-1 */ 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6}; int t; /* Loop counter */ uint32_t temp; /* Temporary word value */ uint32_t W[80]; /* Word sequence */ uint32_t A; /* Word buffers */ uint32_t B; /* Word buffers */ uint32_t C; /* Word buffers */ uint32_t D; /* Word buffers */ uint32_t E; /* Word buffers */ /* * Initialize the first 16 words in the array W */ for (t = 0; t < 16; t++) { W[t] = (uint32_t)(context->message_block[t * 4]) << 24U; W[t] |= (uint32_t)(context->message_block[t * 4 + 1]) << 16U; W[t] |= (uint32_t)(context->message_block[t * 4 + 2]) << 8U; W[t] |= (uint32_t)(context->message_block[t * 4 + 3]); } for (t = 16; t < 80; t++) { W[t] = SHA1_CIRCULAR_SHIFT(1U, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]); } A = context->intermediate_hash[0]; B = context->intermediate_hash[1]; C = context->intermediate_hash[2]; D = context->intermediate_hash[3]; E = context->intermediate_hash[4]; for (t = 0; t < 20; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } for (t = 20; t < 40; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + (B ^ C ^ D) + E + W[t] + K[1]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } for (t = 40; t < 60; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } for (t = 60; t < 80; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + (B ^ C ^ D) + E + W[t] + K[3]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } context->intermediate_hash[0] += A; context->intermediate_hash[1] += B; context->intermediate_hash[2] += C; context->intermediate_hash[3] += D; context->intermediate_hash[4] += E; context->message_block_index = 0; }
/* * sha1_process_message_block * * Description: * This function will process the next 512 bits of the message * stored in the Message_Block array. * * Parameters: * None. * * Returns: * Nothing. * * Comments: * Many of the variable names in this code, especially the * single character names, were used because those were the * names used in the publication. * * */
sha1_process_message_block Description: This function will process the next 512 bits of the message stored in the Message_Block array. None. Nothing. Many of the variable names in this code, especially the single character names, were used because those were the names used in the publication.
[ "sha1_process_message_block", "Description", ":", "This", "function", "will", "process", "the", "next", "512", "bits", "of", "the", "message", "stored", "in", "the", "Message_Block", "array", ".", "None", ".", "Nothing", ".", "Many", "of", "the", "variable", "names", "in", "this", "code", "especially", "the", "single", "character", "names", "were", "used", "because", "those", "were", "the", "names", "used", "in", "the", "publication", "." ]
static void sha1_process_message_block(sha1_context *context) { const uint32_t K[] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6}; int t; uint32_t temp; uint32_t W[80]; uint32_t A; uint32_t B; uint32_t C; uint32_t D; uint32_t E; for (t = 0; t < 16; t++) { W[t] = (uint32_t)(context->message_block[t * 4]) << 24U; W[t] |= (uint32_t)(context->message_block[t * 4 + 1]) << 16U; W[t] |= (uint32_t)(context->message_block[t * 4 + 2]) << 8U; W[t] |= (uint32_t)(context->message_block[t * 4 + 3]); } for (t = 16; t < 80; t++) { W[t] = SHA1_CIRCULAR_SHIFT(1U, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]); } A = context->intermediate_hash[0]; B = context->intermediate_hash[1]; C = context->intermediate_hash[2]; D = context->intermediate_hash[3]; E = context->intermediate_hash[4]; for (t = 0; t < 20; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } for (t = 20; t < 40; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + (B ^ C ^ D) + E + W[t] + K[1]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } for (t = 40; t < 60; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } for (t = 60; t < 80; t++) { temp = SHA1_CIRCULAR_SHIFT(5U, A) + (B ^ C ^ D) + E + W[t] + K[3]; E = D; D = C; C = SHA1_CIRCULAR_SHIFT(30U, B); B = A; A = temp; } context->intermediate_hash[0] += A; context->intermediate_hash[1] += B; context->intermediate_hash[2] += C; context->intermediate_hash[3] += D; context->intermediate_hash[4] += E; context->message_block_index = 0; }
[ "static", "void", "sha1_process_message_block", "(", "sha1_context", "*", "context", ")", "{", "const", "uint32_t", "K", "[", "]", "=", "{", "0x5A827999", ",", "0x6ED9EBA1", ",", "0x8F1BBCDC", ",", "0xCA62C1D6", "}", ";", "int", "t", ";", "uint32_t", "temp", ";", "uint32_t", "W", "[", "80", "]", ";", "uint32_t", "A", ";", "uint32_t", "B", ";", "uint32_t", "C", ";", "uint32_t", "D", ";", "uint32_t", "E", ";", "for", "(", "t", "=", "0", ";", "t", "<", "16", ";", "t", "++", ")", "{", "W", "[", "t", "]", "=", "(", "uint32_t", ")", "(", "context", "->", "message_block", "[", "t", "*", "4", "]", ")", "<<", "24U", ";", "W", "[", "t", "]", "|=", "(", "uint32_t", ")", "(", "context", "->", "message_block", "[", "t", "*", "4", "+", "1", "]", ")", "<<", "16U", ";", "W", "[", "t", "]", "|=", "(", "uint32_t", ")", "(", "context", "->", "message_block", "[", "t", "*", "4", "+", "2", "]", ")", "<<", "8U", ";", "W", "[", "t", "]", "|=", "(", "uint32_t", ")", "(", "context", "->", "message_block", "[", "t", "*", "4", "+", "3", "]", ")", ";", "}", "for", "(", "t", "=", "16", ";", "t", "<", "80", ";", "t", "++", ")", "{", "W", "[", "t", "]", "=", "SHA1_CIRCULAR_SHIFT", "(", "1U", ",", "W", "[", "t", "-", "3", "]", "^", "W", "[", "t", "-", "8", "]", "^", "W", "[", "t", "-", "14", "]", "^", "W", "[", "t", "-", "16", "]", ")", ";", "}", "A", "=", "context", "->", "intermediate_hash", "[", "0", "]", ";", "B", "=", "context", "->", "intermediate_hash", "[", "1", "]", ";", "C", "=", "context", "->", "intermediate_hash", "[", "2", "]", ";", "D", "=", "context", "->", "intermediate_hash", "[", "3", "]", ";", "E", "=", "context", "->", "intermediate_hash", "[", "4", "]", ";", "for", "(", "t", "=", "0", ";", "t", "<", "20", ";", "t", "++", ")", "{", "temp", "=", "SHA1_CIRCULAR_SHIFT", "(", "5U", ",", "A", ")", "+", "(", "(", "B", "&", "C", ")", "|", "(", "(", "~", "B", ")", "&", "D", ")", ")", "+", "E", "+", "W", "[", "t", "]", "+", "K", "[", "0", "]", ";", "E", "=", "D", ";", "D", "=", "C", ";", "C", "=", "SHA1_CIRCULAR_SHIFT", "(", "30U", ",", "B", ")", ";", "B", "=", "A", ";", "A", "=", "temp", ";", "}", "for", "(", "t", "=", "20", ";", "t", "<", "40", ";", "t", "++", ")", "{", "temp", "=", "SHA1_CIRCULAR_SHIFT", "(", "5U", ",", "A", ")", "+", "(", "B", "^", "C", "^", "D", ")", "+", "E", "+", "W", "[", "t", "]", "+", "K", "[", "1", "]", ";", "E", "=", "D", ";", "D", "=", "C", ";", "C", "=", "SHA1_CIRCULAR_SHIFT", "(", "30U", ",", "B", ")", ";", "B", "=", "A", ";", "A", "=", "temp", ";", "}", "for", "(", "t", "=", "40", ";", "t", "<", "60", ";", "t", "++", ")", "{", "temp", "=", "SHA1_CIRCULAR_SHIFT", "(", "5U", ",", "A", ")", "+", "(", "(", "B", "&", "C", ")", "|", "(", "B", "&", "D", ")", "|", "(", "C", "&", "D", ")", ")", "+", "E", "+", "W", "[", "t", "]", "+", "K", "[", "2", "]", ";", "E", "=", "D", ";", "D", "=", "C", ";", "C", "=", "SHA1_CIRCULAR_SHIFT", "(", "30U", ",", "B", ")", ";", "B", "=", "A", ";", "A", "=", "temp", ";", "}", "for", "(", "t", "=", "60", ";", "t", "<", "80", ";", "t", "++", ")", "{", "temp", "=", "SHA1_CIRCULAR_SHIFT", "(", "5U", ",", "A", ")", "+", "(", "B", "^", "C", "^", "D", ")", "+", "E", "+", "W", "[", "t", "]", "+", "K", "[", "3", "]", ";", "E", "=", "D", ";", "D", "=", "C", ";", "C", "=", "SHA1_CIRCULAR_SHIFT", "(", "30U", ",", "B", ")", ";", "B", "=", "A", ";", "A", "=", "temp", ";", "}", "context", "->", "intermediate_hash", "[", "0", "]", "+=", "A", ";", "context", "->", "intermediate_hash", "[", "1", "]", "+=", "B", ";", "context", "->", "intermediate_hash", "[", "2", "]", "+=", "C", ";", "context", "->", "intermediate_hash", "[", "3", "]", "+=", "D", ";", "context", "->", "intermediate_hash", "[", "4", "]", "+=", "E", ";", "context", "->", "message_block_index", "=", "0", ";", "}" ]
sha1_process_message_block Description: This function will process the next 512 bits of the message stored in the Message_Block array.
[ "sha1_process_message_block", "Description", ":", "This", "function", "will", "process", "the", "next", "512", "bits", "of", "the", "message", "stored", "in", "the", "Message_Block", "array", "." ]
[ "/* Constants defined in SHA-1 */", "/* Loop counter */", "/* Temporary word value */", "/* Word sequence */", "/* Word buffers */", "/* Word buffers */", "/* Word buffers */", "/* Word buffers */", "/* Word buffers */", "/*\n * Initialize the first 16 words in the array W\n */" ]
[ { "param": "context", "type": "sha1_context" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "sha1_context", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1e325af7aa9212eb532ccaf73da4b931807dbaaa
gatzka/ciol
lib/cio/sha1/sha1.c
[ "MIT" ]
C
sha1_pad_message
void
static void sha1_pad_message(sha1_context *context) { /* * Check to see if the current message block is too small to hold * the initial padding bits and length. If so, we will pad the * block, process it, and then continue padding into a second * block. */ if (context->message_block_index > 55) { context->message_block[context->message_block_index++] = 0x80; while (context->message_block_index < 64) { context->message_block[context->message_block_index++] = 0; } sha1_process_message_block(context); while (context->message_block_index < 56) { context->message_block[context->message_block_index++] = 0; } } else { context->message_block[context->message_block_index++] = 0x80; while (context->message_block_index < 56) { context->message_block[context->message_block_index++] = 0; } } /* * Store the message length as the last 8 octets */ context->message_block[56] = (uint8_t)(context->length_high >> 24U); context->message_block[57] = (uint8_t)(context->length_high >> 16U); context->message_block[58] = (uint8_t)(context->length_high >> 8U); context->message_block[59] = (uint8_t)(context->length_high); context->message_block[60] = (uint8_t)(context->length_low >> 24U); context->message_block[61] = (uint8_t)(context->length_low >> 16U); context->message_block[62] = (uint8_t)(context->length_low >> 8U); context->message_block[63] = (uint8_t)(context->length_low); sha1_process_message_block(context); }
/* * sha1_pad_message * * Description: * According to the standard, the message must be padded to an even * 512 bits. The first padding bit must be a '1'. The last 64 * bits represent the length of the original message. All bits in * between should be 0. This function will pad the message * according to those rules by filling the Message_Block array * accordingly. It will also call the ProcessMessageBlock function * provided appropriately. When it returns, it can be assumed that * the message digest has been computed. * * Parameters: * context: [in/out] * The context to pad * ProcessMessageBlock: [in] * The appropriate SHA*ProcessMessageBlock function * Returns: * Nothing. * */
sha1_pad_message Description: According to the standard, the message must be padded to an even 512 bits. The first padding bit must be a '1'. The last 64 bits represent the length of the original message. All bits in between should be 0. This function will pad the message according to those rules by filling the Message_Block array accordingly. It will also call the ProcessMessageBlock function provided appropriately. When it returns, it can be assumed that the message digest has been computed. [in/out] The context to pad ProcessMessageBlock: [in] The appropriate SHA*ProcessMessageBlock function Returns: Nothing.
[ "sha1_pad_message", "Description", ":", "According", "to", "the", "standard", "the", "message", "must", "be", "padded", "to", "an", "even", "512", "bits", ".", "The", "first", "padding", "bit", "must", "be", "a", "'", "1", "'", ".", "The", "last", "64", "bits", "represent", "the", "length", "of", "the", "original", "message", ".", "All", "bits", "in", "between", "should", "be", "0", ".", "This", "function", "will", "pad", "the", "message", "according", "to", "those", "rules", "by", "filling", "the", "Message_Block", "array", "accordingly", ".", "It", "will", "also", "call", "the", "ProcessMessageBlock", "function", "provided", "appropriately", ".", "When", "it", "returns", "it", "can", "be", "assumed", "that", "the", "message", "digest", "has", "been", "computed", ".", "[", "in", "/", "out", "]", "The", "context", "to", "pad", "ProcessMessageBlock", ":", "[", "in", "]", "The", "appropriate", "SHA", "*", "ProcessMessageBlock", "function", "Returns", ":", "Nothing", "." ]
static void sha1_pad_message(sha1_context *context) { if (context->message_block_index > 55) { context->message_block[context->message_block_index++] = 0x80; while (context->message_block_index < 64) { context->message_block[context->message_block_index++] = 0; } sha1_process_message_block(context); while (context->message_block_index < 56) { context->message_block[context->message_block_index++] = 0; } } else { context->message_block[context->message_block_index++] = 0x80; while (context->message_block_index < 56) { context->message_block[context->message_block_index++] = 0; } } context->message_block[56] = (uint8_t)(context->length_high >> 24U); context->message_block[57] = (uint8_t)(context->length_high >> 16U); context->message_block[58] = (uint8_t)(context->length_high >> 8U); context->message_block[59] = (uint8_t)(context->length_high); context->message_block[60] = (uint8_t)(context->length_low >> 24U); context->message_block[61] = (uint8_t)(context->length_low >> 16U); context->message_block[62] = (uint8_t)(context->length_low >> 8U); context->message_block[63] = (uint8_t)(context->length_low); sha1_process_message_block(context); }
[ "static", "void", "sha1_pad_message", "(", "sha1_context", "*", "context", ")", "{", "if", "(", "context", "->", "message_block_index", ">", "55", ")", "{", "context", "->", "message_block", "[", "context", "->", "message_block_index", "++", "]", "=", "0x80", ";", "while", "(", "context", "->", "message_block_index", "<", "64", ")", "{", "context", "->", "message_block", "[", "context", "->", "message_block_index", "++", "]", "=", "0", ";", "}", "sha1_process_message_block", "(", "context", ")", ";", "while", "(", "context", "->", "message_block_index", "<", "56", ")", "{", "context", "->", "message_block", "[", "context", "->", "message_block_index", "++", "]", "=", "0", ";", "}", "}", "else", "{", "context", "->", "message_block", "[", "context", "->", "message_block_index", "++", "]", "=", "0x80", ";", "while", "(", "context", "->", "message_block_index", "<", "56", ")", "{", "context", "->", "message_block", "[", "context", "->", "message_block_index", "++", "]", "=", "0", ";", "}", "}", "context", "->", "message_block", "[", "56", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_high", ">>", "24U", ")", ";", "context", "->", "message_block", "[", "57", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_high", ">>", "16U", ")", ";", "context", "->", "message_block", "[", "58", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_high", ">>", "8U", ")", ";", "context", "->", "message_block", "[", "59", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_high", ")", ";", "context", "->", "message_block", "[", "60", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_low", ">>", "24U", ")", ";", "context", "->", "message_block", "[", "61", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_low", ">>", "16U", ")", ";", "context", "->", "message_block", "[", "62", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_low", ">>", "8U", ")", ";", "context", "->", "message_block", "[", "63", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "length_low", ")", ";", "sha1_process_message_block", "(", "context", ")", ";", "}" ]
sha1_pad_message Description: According to the standard, the message must be padded to an even 512 bits.
[ "sha1_pad_message", "Description", ":", "According", "to", "the", "standard", "the", "message", "must", "be", "padded", "to", "an", "even", "512", "bits", "." ]
[ "/*\n * Check to see if the current message block is too small to hold\n * the initial padding bits and length. If so, we will pad the\n * block, process it, and then continue padding into a second\n * block.\n */", "/*\n * Store the message length as the last 8 octets\n */" ]
[ { "param": "context", "type": "sha1_context" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "sha1_context", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1e325af7aa9212eb532ccaf73da4b931807dbaaa
gatzka/ciol
lib/cio/sha1/sha1.c
[ "MIT" ]
C
sha1_result
int
int sha1_result(sha1_context *context, uint8_t Message_Digest[SHA1_HASH_SIZE]) { if ((!context) || (!Message_Digest)) { return SHA_NULL; } if (context->corrupted) { return context->corrupted; } if (!context->computed) { sha1_pad_message(context); for (uint_fast8_t i = 0; i < 64; ++i) { /* message may be sensitive, clear it out */ context->message_block[i] = 0; } context->length_low = 0; /* and clear length */ context->length_high = 0; context->computed = 1; } for (uint_fast8_t i = 0; i < SHA1_HASH_SIZE; ++i) { Message_Digest[i] = (uint8_t)(context->intermediate_hash[i >> 2U] >> 8 * (3 - (i & 0x03U))); } return SHA_SUCCESS; }
/* * sha1_result * * Description: * This function will return the 160-bit message digest into the * Message_Digest array provided by the caller. * NOTE: The first octet of hash is stored in the 0th element, * the last octet of hash in the 19th element. * * Parameters: * context: [in/out] * The context to use to calculate the SHA-1 hash. * Message_Digest: [out] * Where the digest is returned. * * Returns: * sha Error Code. * */
sha1_result Description: This function will return the 160-bit message digest into the Message_Digest array provided by the caller. NOTE: The first octet of hash is stored in the 0th element, the last octet of hash in the 19th element. [in/out] The context to use to calculate the SHA-1 hash. Message_Digest: [out] Where the digest is returned. sha Error Code.
[ "sha1_result", "Description", ":", "This", "function", "will", "return", "the", "160", "-", "bit", "message", "digest", "into", "the", "Message_Digest", "array", "provided", "by", "the", "caller", ".", "NOTE", ":", "The", "first", "octet", "of", "hash", "is", "stored", "in", "the", "0th", "element", "the", "last", "octet", "of", "hash", "in", "the", "19th", "element", ".", "[", "in", "/", "out", "]", "The", "context", "to", "use", "to", "calculate", "the", "SHA", "-", "1", "hash", ".", "Message_Digest", ":", "[", "out", "]", "Where", "the", "digest", "is", "returned", ".", "sha", "Error", "Code", "." ]
int sha1_result(sha1_context *context, uint8_t Message_Digest[SHA1_HASH_SIZE]) { if ((!context) || (!Message_Digest)) { return SHA_NULL; } if (context->corrupted) { return context->corrupted; } if (!context->computed) { sha1_pad_message(context); for (uint_fast8_t i = 0; i < 64; ++i) { context->message_block[i] = 0; } context->length_low = 0; context->length_high = 0; context->computed = 1; } for (uint_fast8_t i = 0; i < SHA1_HASH_SIZE; ++i) { Message_Digest[i] = (uint8_t)(context->intermediate_hash[i >> 2U] >> 8 * (3 - (i & 0x03U))); } return SHA_SUCCESS; }
[ "int", "sha1_result", "(", "sha1_context", "*", "context", ",", "uint8_t", "Message_Digest", "[", "SHA1_HASH_SIZE", "]", ")", "{", "if", "(", "(", "!", "context", ")", "||", "(", "!", "Message_Digest", ")", ")", "{", "return", "SHA_NULL", ";", "}", "if", "(", "context", "->", "corrupted", ")", "{", "return", "context", "->", "corrupted", ";", "}", "if", "(", "!", "context", "->", "computed", ")", "{", "sha1_pad_message", "(", "context", ")", ";", "for", "(", "uint_fast8_t", "i", "=", "0", ";", "i", "<", "64", ";", "++", "i", ")", "{", "context", "->", "message_block", "[", "i", "]", "=", "0", ";", "}", "context", "->", "length_low", "=", "0", ";", "context", "->", "length_high", "=", "0", ";", "context", "->", "computed", "=", "1", ";", "}", "for", "(", "uint_fast8_t", "i", "=", "0", ";", "i", "<", "SHA1_HASH_SIZE", ";", "++", "i", ")", "{", "Message_Digest", "[", "i", "]", "=", "(", "uint8_t", ")", "(", "context", "->", "intermediate_hash", "[", "i", ">>", "2U", "]", ">>", "8", "*", "(", "3", "-", "(", "i", "&", "0x03U", ")", ")", ")", ";", "}", "return", "SHA_SUCCESS", ";", "}" ]
sha1_result Description: This function will return the 160-bit message digest into the Message_Digest array provided by the caller.
[ "sha1_result", "Description", ":", "This", "function", "will", "return", "the", "160", "-", "bit", "message", "digest", "into", "the", "Message_Digest", "array", "provided", "by", "the", "caller", "." ]
[ "/* message may be sensitive, clear it out */", "/* and clear length */" ]
[ { "param": "context", "type": "sha1_context" }, { "param": "Message_Digest", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "sha1_context", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Message_Digest", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_insert
void
static inline void cio_write_buffer_insert(struct cio_write_buffer *wbh, struct cio_write_buffer *new_wb, struct cio_write_buffer *prev_wb, struct cio_write_buffer *next_wb) { new_wb->next = next_wb; new_wb->prev = prev_wb; next_wb->prev = prev_wb->next = new_wb; wbh->data.head.q_len++; wbh->data.head.total_length += new_wb->data.element.length; }
/** * @brief Insert a new write buffer element into the write buffer chain. * @param wbh The write buffer chain that is manipulated. * @param new_wb The write buffer element that shall be inserted * @param prev_wb The write buffer element after which the new write buffer element shall be inserted. * @param next_wb The write buffer element before which the new write buffer element shall be inserted. */
@brief Insert a new write buffer element into the write buffer chain. @param wbh The write buffer chain that is manipulated. @param new_wb The write buffer element that shall be inserted @param prev_wb The write buffer element after which the new write buffer element shall be inserted. @param next_wb The write buffer element before which the new write buffer element shall be inserted.
[ "@brief", "Insert", "a", "new", "write", "buffer", "element", "into", "the", "write", "buffer", "chain", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@param", "new_wb", "The", "write", "buffer", "element", "that", "shall", "be", "inserted", "@param", "prev_wb", "The", "write", "buffer", "element", "after", "which", "the", "new", "write", "buffer", "element", "shall", "be", "inserted", ".", "@param", "next_wb", "The", "write", "buffer", "element", "before", "which", "the", "new", "write", "buffer", "element", "shall", "be", "inserted", "." ]
static inline void cio_write_buffer_insert(struct cio_write_buffer *wbh, struct cio_write_buffer *new_wb, struct cio_write_buffer *prev_wb, struct cio_write_buffer *next_wb) { new_wb->next = next_wb; new_wb->prev = prev_wb; next_wb->prev = prev_wb->next = new_wb; wbh->data.head.q_len++; wbh->data.head.total_length += new_wb->data.element.length; }
[ "static", "inline", "void", "cio_write_buffer_insert", "(", "struct", "cio_write_buffer", "*", "wbh", ",", "struct", "cio_write_buffer", "*", "new_wb", ",", "struct", "cio_write_buffer", "*", "prev_wb", ",", "struct", "cio_write_buffer", "*", "next_wb", ")", "{", "new_wb", "->", "next", "=", "next_wb", ";", "new_wb", "->", "prev", "=", "prev_wb", ";", "next_wb", "->", "prev", "=", "prev_wb", "->", "next", "=", "new_wb", ";", "wbh", "->", "data", ".", "head", ".", "q_len", "++", ";", "wbh", "->", "data", ".", "head", ".", "total_length", "+=", "new_wb", "->", "data", ".", "element", ".", "length", ";", "}" ]
@brief Insert a new write buffer element into the write buffer chain.
[ "@brief", "Insert", "a", "new", "write", "buffer", "element", "into", "the", "write", "buffer", "chain", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" }, { "param": "new_wb", "type": "struct cio_write_buffer" }, { "param": "prev_wb", "type": "struct cio_write_buffer" }, { "param": "next_wb", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "new_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "prev_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "next_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_before
void
static inline void cio_write_buffer_queue_before(struct cio_write_buffer *wbh, struct cio_write_buffer *next_wb, struct cio_write_buffer *new_wb) { cio_write_buffer_insert(wbh, new_wb, next_wb->prev, next_wb); }
/** * @brief Queue a new write buffer element before a write buffer element in a write buffer chain. * @param wbh The write buffer chain that is manipulated. * @param next_wb The write buffer element before which the new write buffer element shall be inserted. * @param new_wb The write buffer element that shall be inserted */
@brief Queue a new write buffer element before a write buffer element in a write buffer chain. @param wbh The write buffer chain that is manipulated. @param next_wb The write buffer element before which the new write buffer element shall be inserted. @param new_wb The write buffer element that shall be inserted
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "before", "a", "write", "buffer", "element", "in", "a", "write", "buffer", "chain", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@param", "next_wb", "The", "write", "buffer", "element", "before", "which", "the", "new", "write", "buffer", "element", "shall", "be", "inserted", ".", "@param", "new_wb", "The", "write", "buffer", "element", "that", "shall", "be", "inserted" ]
static inline void cio_write_buffer_queue_before(struct cio_write_buffer *wbh, struct cio_write_buffer *next_wb, struct cio_write_buffer *new_wb) { cio_write_buffer_insert(wbh, new_wb, next_wb->prev, next_wb); }
[ "static", "inline", "void", "cio_write_buffer_queue_before", "(", "struct", "cio_write_buffer", "*", "wbh", ",", "struct", "cio_write_buffer", "*", "next_wb", ",", "struct", "cio_write_buffer", "*", "new_wb", ")", "{", "cio_write_buffer_insert", "(", "wbh", ",", "new_wb", ",", "next_wb", "->", "prev", ",", "next_wb", ")", ";", "}" ]
@brief Queue a new write buffer element before a write buffer element in a write buffer chain.
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "before", "a", "write", "buffer", "element", "in", "a", "write", "buffer", "chain", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" }, { "param": "next_wb", "type": "struct cio_write_buffer" }, { "param": "new_wb", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "next_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "new_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_after
void
static inline void cio_write_buffer_queue_after(struct cio_write_buffer *wbh, struct cio_write_buffer *prev_wb, struct cio_write_buffer *new_wb) { cio_write_buffer_insert(wbh, new_wb, prev_wb, prev_wb->next); }
/** * @brief Queue a new write buffer element after a write buffer element in a write buffer chain. * @param wbh The write buffer chain that is manipulated. * @param prev_wb The write buffer element after which the new write buffer element shall be inserted. * @param new_wb The write buffer element that shall be inserted */
@brief Queue a new write buffer element after a write buffer element in a write buffer chain. @param wbh The write buffer chain that is manipulated. @param prev_wb The write buffer element after which the new write buffer element shall be inserted. @param new_wb The write buffer element that shall be inserted
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "after", "a", "write", "buffer", "element", "in", "a", "write", "buffer", "chain", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@param", "prev_wb", "The", "write", "buffer", "element", "after", "which", "the", "new", "write", "buffer", "element", "shall", "be", "inserted", ".", "@param", "new_wb", "The", "write", "buffer", "element", "that", "shall", "be", "inserted" ]
static inline void cio_write_buffer_queue_after(struct cio_write_buffer *wbh, struct cio_write_buffer *prev_wb, struct cio_write_buffer *new_wb) { cio_write_buffer_insert(wbh, new_wb, prev_wb, prev_wb->next); }
[ "static", "inline", "void", "cio_write_buffer_queue_after", "(", "struct", "cio_write_buffer", "*", "wbh", ",", "struct", "cio_write_buffer", "*", "prev_wb", ",", "struct", "cio_write_buffer", "*", "new_wb", ")", "{", "cio_write_buffer_insert", "(", "wbh", ",", "new_wb", ",", "prev_wb", ",", "prev_wb", "->", "next", ")", ";", "}" ]
@brief Queue a new write buffer element after a write buffer element in a write buffer chain.
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "after", "a", "write", "buffer", "element", "in", "a", "write", "buffer", "chain", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" }, { "param": "prev_wb", "type": "struct cio_write_buffer" }, { "param": "new_wb", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "prev_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "new_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_head
void
static inline void cio_write_buffer_queue_head(struct cio_write_buffer *wbh, struct cio_write_buffer *new_wb) { cio_write_buffer_queue_after(wbh, wbh, new_wb); }
/** * @brief Queue a new write buffer element at the head of a write buffer chain. * @param wbh The write buffer chain that is manipulated. * @param new_wb The write buffer element that shall be inserted */
@brief Queue a new write buffer element at the head of a write buffer chain. @param wbh The write buffer chain that is manipulated. @param new_wb The write buffer element that shall be inserted
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "at", "the", "head", "of", "a", "write", "buffer", "chain", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@param", "new_wb", "The", "write", "buffer", "element", "that", "shall", "be", "inserted" ]
static inline void cio_write_buffer_queue_head(struct cio_write_buffer *wbh, struct cio_write_buffer *new_wb) { cio_write_buffer_queue_after(wbh, wbh, new_wb); }
[ "static", "inline", "void", "cio_write_buffer_queue_head", "(", "struct", "cio_write_buffer", "*", "wbh", ",", "struct", "cio_write_buffer", "*", "new_wb", ")", "{", "cio_write_buffer_queue_after", "(", "wbh", ",", "wbh", ",", "new_wb", ")", ";", "}" ]
@brief Queue a new write buffer element at the head of a write buffer chain.
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "at", "the", "head", "of", "a", "write", "buffer", "chain", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" }, { "param": "new_wb", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "new_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_tail
void
static inline void cio_write_buffer_queue_tail(struct cio_write_buffer *wbh, struct cio_write_buffer *new_wb) { cio_write_buffer_queue_before(wbh, wbh, new_wb); }
/** * @brief Queue a new write buffer element at the tail of a write buffer chain. * @param wbh The write buffer chain that is manipulated. * @param new_wb The write buffer element that shall be inserted */
@brief Queue a new write buffer element at the tail of a write buffer chain. @param wbh The write buffer chain that is manipulated. @param new_wb The write buffer element that shall be inserted
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "at", "the", "tail", "of", "a", "write", "buffer", "chain", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@param", "new_wb", "The", "write", "buffer", "element", "that", "shall", "be", "inserted" ]
static inline void cio_write_buffer_queue_tail(struct cio_write_buffer *wbh, struct cio_write_buffer *new_wb) { cio_write_buffer_queue_before(wbh, wbh, new_wb); }
[ "static", "inline", "void", "cio_write_buffer_queue_tail", "(", "struct", "cio_write_buffer", "*", "wbh", ",", "struct", "cio_write_buffer", "*", "new_wb", ")", "{", "cio_write_buffer_queue_before", "(", "wbh", ",", "wbh", ",", "new_wb", ")", ";", "}" ]
@brief Queue a new write buffer element at the tail of a write buffer chain.
[ "@brief", "Queue", "a", "new", "write", "buffer", "element", "at", "the", "tail", "of", "a", "write", "buffer", "chain", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" }, { "param": "new_wb", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "new_wb", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_peek
null
static inline struct cio_write_buffer *cio_write_buffer_queue_peek(const struct cio_write_buffer *wbh) { struct cio_write_buffer *wbe = wbh->next; if (wbe == wbh) { wbe = NULL; } return wbe; }
/** * @brief Access the first element of a write buffer chain without removing it. * @param wbh The write buffer chain that is asked. * @return The first write buffer element if available, @c NULL otherwise. */
@brief Access the first element of a write buffer chain without removing it. @param wbh The write buffer chain that is asked. @return The first write buffer element if available, @c NULL otherwise.
[ "@brief", "Access", "the", "first", "element", "of", "a", "write", "buffer", "chain", "without", "removing", "it", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "asked", ".", "@return", "The", "first", "write", "buffer", "element", "if", "available", "@c", "NULL", "otherwise", "." ]
static inline struct cio_write_buffer *cio_write_buffer_queue_peek(const struct cio_write_buffer *wbh) { struct cio_write_buffer *wbe = wbh->next; if (wbe == wbh) { wbe = NULL; } return wbe; }
[ "static", "inline", "struct", "cio_write_buffer", "*", "cio_write_buffer_queue_peek", "(", "const", "struct", "cio_write_buffer", "*", "wbh", ")", "{", "struct", "cio_write_buffer", "*", "wbe", "=", "wbh", "->", "next", ";", "if", "(", "wbe", "==", "wbh", ")", "{", "wbe", "=", "NULL", ";", "}", "return", "wbe", ";", "}" ]
@brief Access the first element of a write buffer chain without removing it.
[ "@brief", "Access", "the", "first", "element", "of", "a", "write", "buffer", "chain", "without", "removing", "it", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_last
null
static inline struct cio_write_buffer *cio_write_buffer_queue_last(const struct cio_write_buffer *wbh) { struct cio_write_buffer *wbe = wbh->prev; if (wbe == wbh) { wbe = NULL; } return wbe; }
/** * @brief Access the last element of a write buffer chain without removing it. * @param wbh The write buffer chain that is asked. * @return The last write buffer element if available, @c otherwise. */
@brief Access the last element of a write buffer chain without removing it. @param wbh The write buffer chain that is asked. @return The last write buffer element if available, @c otherwise.
[ "@brief", "Access", "the", "last", "element", "of", "a", "write", "buffer", "chain", "without", "removing", "it", ".", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "asked", ".", "@return", "The", "last", "write", "buffer", "element", "if", "available", "@c", "otherwise", "." ]
static inline struct cio_write_buffer *cio_write_buffer_queue_last(const struct cio_write_buffer *wbh) { struct cio_write_buffer *wbe = wbh->prev; if (wbe == wbh) { wbe = NULL; } return wbe; }
[ "static", "inline", "struct", "cio_write_buffer", "*", "cio_write_buffer_queue_last", "(", "const", "struct", "cio_write_buffer", "*", "wbh", ")", "{", "struct", "cio_write_buffer", "*", "wbe", "=", "wbh", "->", "prev", ";", "if", "(", "wbe", "==", "wbh", ")", "{", "wbe", "=", "NULL", ";", "}", "return", "wbe", ";", "}" ]
@brief Access the last element of a write buffer chain without removing it.
[ "@brief", "Access", "the", "last", "element", "of", "a", "write", "buffer", "chain", "without", "removing", "it", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_unlink
void
static inline void cio_write_buffer_unlink(struct cio_write_buffer *wbh, const struct cio_write_buffer *wbe) { struct cio_write_buffer *next = NULL; struct cio_write_buffer *prev = NULL; wbh->data.head.q_len--; wbh->data.head.total_length -= wbe->data.element.length; next = wbe->next; prev = wbe->prev; next->prev = prev; prev->next = next; }
/** * @brief Removes a write buffer element from the write buffer chain * @param wbh The write buffer chain that is manipulated. * @param wbe The element that shall be removed. */
@brief Removes a write buffer element from the write buffer chain @param wbh The write buffer chain that is manipulated. @param wbe The element that shall be removed.
[ "@brief", "Removes", "a", "write", "buffer", "element", "from", "the", "write", "buffer", "chain", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@param", "wbe", "The", "element", "that", "shall", "be", "removed", "." ]
static inline void cio_write_buffer_unlink(struct cio_write_buffer *wbh, const struct cio_write_buffer *wbe) { struct cio_write_buffer *next = NULL; struct cio_write_buffer *prev = NULL; wbh->data.head.q_len--; wbh->data.head.total_length -= wbe->data.element.length; next = wbe->next; prev = wbe->prev; next->prev = prev; prev->next = next; }
[ "static", "inline", "void", "cio_write_buffer_unlink", "(", "struct", "cio_write_buffer", "*", "wbh", ",", "const", "struct", "cio_write_buffer", "*", "wbe", ")", "{", "struct", "cio_write_buffer", "*", "next", "=", "NULL", ";", "struct", "cio_write_buffer", "*", "prev", "=", "NULL", ";", "wbh", "->", "data", ".", "head", ".", "q_len", "--", ";", "wbh", "->", "data", ".", "head", ".", "total_length", "-=", "wbe", "->", "data", ".", "element", ".", "length", ";", "next", "=", "wbe", "->", "next", ";", "prev", "=", "wbe", "->", "prev", ";", "next", "->", "prev", "=", "prev", ";", "prev", "->", "next", "=", "next", ";", "}" ]
@brief Removes a write buffer element from the write buffer chain @param wbh The write buffer chain that is manipulated.
[ "@brief", "Removes", "a", "write", "buffer", "element", "from", "the", "write", "buffer", "chain", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" }, { "param": "wbe", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wbe", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_queue_dequeue
null
static inline struct cio_write_buffer *cio_write_buffer_queue_dequeue(struct cio_write_buffer *wbh) { struct cio_write_buffer *wbe = cio_write_buffer_queue_peek(wbh); if (wbe) { cio_write_buffer_unlink(wbh, wbe); } return wbe; }
/** * @brief Accesses and removes the first element from the write buffer chain * @param wbh The write buffer chain that is manipulated. * @return The first element of the queue, @c NULL if empty. */
@brief Accesses and removes the first element from the write buffer chain @param wbh The write buffer chain that is manipulated. @return The first element of the queue, @c NULL if empty.
[ "@brief", "Accesses", "and", "removes", "the", "first", "element", "from", "the", "write", "buffer", "chain", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", ".", "@return", "The", "first", "element", "of", "the", "queue", "@c", "NULL", "if", "empty", "." ]
static inline struct cio_write_buffer *cio_write_buffer_queue_dequeue(struct cio_write_buffer *wbh) { struct cio_write_buffer *wbe = cio_write_buffer_queue_peek(wbh); if (wbe) { cio_write_buffer_unlink(wbh, wbe); } return wbe; }
[ "static", "inline", "struct", "cio_write_buffer", "*", "cio_write_buffer_queue_dequeue", "(", "struct", "cio_write_buffer", "*", "wbh", ")", "{", "struct", "cio_write_buffer", "*", "wbe", "=", "cio_write_buffer_queue_peek", "(", "wbh", ")", ";", "if", "(", "wbe", ")", "{", "cio_write_buffer_unlink", "(", "wbh", ",", "wbe", ")", ";", "}", "return", "wbe", ";", "}" ]
@brief Accesses and removes the first element from the write buffer chain @param wbh The write buffer chain that is manipulated.
[ "@brief", "Accesses", "and", "removes", "the", "first", "element", "from", "the", "write", "buffer", "chain", "@param", "wbh", "The", "write", "buffer", "chain", "that", "is", "manipulated", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_head_init
void
static inline void cio_write_buffer_head_init(struct cio_write_buffer *wbh) { wbh->prev = wbh; wbh->next = wbh; wbh->data.head.q_len = 0; wbh->data.head.total_length = 0; }
/** * @brief Initializes a write buffer head. * @param wbh The write buffer head to be initialized. */
@brief Initializes a write buffer head. @param wbh The write buffer head to be initialized.
[ "@brief", "Initializes", "a", "write", "buffer", "head", ".", "@param", "wbh", "The", "write", "buffer", "head", "to", "be", "initialized", "." ]
static inline void cio_write_buffer_head_init(struct cio_write_buffer *wbh) { wbh->prev = wbh; wbh->next = wbh; wbh->data.head.q_len = 0; wbh->data.head.total_length = 0; }
[ "static", "inline", "void", "cio_write_buffer_head_init", "(", "struct", "cio_write_buffer", "*", "wbh", ")", "{", "wbh", "->", "prev", "=", "wbh", ";", "wbh", "->", "next", "=", "wbh", ";", "wbh", "->", "data", ".", "head", ".", "q_len", "=", "0", ";", "wbh", "->", "data", ".", "head", ".", "total_length", "=", "0", ";", "}" ]
@brief Initializes a write buffer head.
[ "@brief", "Initializes", "a", "write", "buffer", "head", "." ]
[]
[ { "param": "wbh", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbh", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_const_element_init
void
static inline void cio_write_buffer_const_element_init(struct cio_write_buffer *wbe, const void *data, size_t length) { wbe->data.element.const_data = data; wbe->data.element.length = length; }
/** * @brief Initializes a write buffer element with const data. * @param wbe The write buffer element to be initialized. * @param data A pointer to the data the write buffer element shall be handled. * @param length The length in bytes of @p data. */
@brief Initializes a write buffer element with const data. @param wbe The write buffer element to be initialized. @param data A pointer to the data the write buffer element shall be handled. @param length The length in bytes of @p data.
[ "@brief", "Initializes", "a", "write", "buffer", "element", "with", "const", "data", ".", "@param", "wbe", "The", "write", "buffer", "element", "to", "be", "initialized", ".", "@param", "data", "A", "pointer", "to", "the", "data", "the", "write", "buffer", "element", "shall", "be", "handled", ".", "@param", "length", "The", "length", "in", "bytes", "of", "@p", "data", "." ]
static inline void cio_write_buffer_const_element_init(struct cio_write_buffer *wbe, const void *data, size_t length) { wbe->data.element.const_data = data; wbe->data.element.length = length; }
[ "static", "inline", "void", "cio_write_buffer_const_element_init", "(", "struct", "cio_write_buffer", "*", "wbe", ",", "const", "void", "*", "data", ",", "size_t", "length", ")", "{", "wbe", "->", "data", ".", "element", ".", "const_data", "=", "data", ";", "wbe", "->", "data", ".", "element", ".", "length", "=", "length", ";", "}" ]
@brief Initializes a write buffer element with const data.
[ "@brief", "Initializes", "a", "write", "buffer", "element", "with", "const", "data", "." ]
[]
[ { "param": "wbe", "type": "struct cio_write_buffer" }, { "param": "data", "type": "void" }, { "param": "length", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbe", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "length", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_element_init
void
static inline void cio_write_buffer_element_init(struct cio_write_buffer *wbe, void *data, size_t length) { wbe->data.element.data = data; wbe->data.element.length = length; }
/** * @brief Initializes a write buffer element with non-const data. * @param wbe The write buffer element to be initialized. * @param data A pointer to the data the write buffer element shall be handled. * @param length The length in bytes of @p data. */
@brief Initializes a write buffer element with non-const data. @param wbe The write buffer element to be initialized. @param data A pointer to the data the write buffer element shall be handled. @param length The length in bytes of @p data.
[ "@brief", "Initializes", "a", "write", "buffer", "element", "with", "non", "-", "const", "data", ".", "@param", "wbe", "The", "write", "buffer", "element", "to", "be", "initialized", ".", "@param", "data", "A", "pointer", "to", "the", "data", "the", "write", "buffer", "element", "shall", "be", "handled", ".", "@param", "length", "The", "length", "in", "bytes", "of", "@p", "data", "." ]
static inline void cio_write_buffer_element_init(struct cio_write_buffer *wbe, void *data, size_t length) { wbe->data.element.data = data; wbe->data.element.length = length; }
[ "static", "inline", "void", "cio_write_buffer_element_init", "(", "struct", "cio_write_buffer", "*", "wbe", ",", "void", "*", "data", ",", "size_t", "length", ")", "{", "wbe", "->", "data", ".", "element", ".", "data", "=", "data", ";", "wbe", "->", "data", ".", "element", ".", "length", "=", "length", ";", "}" ]
@brief Initializes a write buffer element with non-const data.
[ "@brief", "Initializes", "a", "write", "buffer", "element", "with", "non", "-", "const", "data", "." ]
[]
[ { "param": "wbe", "type": "struct cio_write_buffer" }, { "param": "data", "type": "void" }, { "param": "length", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wbe", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "length", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d3c6570b7be303a290dd13f0dc6f3995fd2565e
gatzka/ciol
lib/include/cio/write_buffer.h
[ "MIT" ]
C
cio_write_buffer_splice
void
static inline void cio_write_buffer_splice(struct cio_write_buffer *list, struct cio_write_buffer *head) { if (!cio_write_buffer_queue_empty(list)) { struct cio_write_buffer *new_last = list->prev; struct cio_write_buffer *new_first = list->next; struct cio_write_buffer *last = head->prev; last->next = list->next; new_first->prev = last; new_last->next = head; head->prev = new_last; head->data.head.q_len += list->data.head.q_len; head->data.head.total_length += list->data.head.total_length; cio_write_buffer_head_init(list); } }
/** * @brief Appends the write buffer elements of @p list to @p head. * @param list The elements which shall be appended to @p head. * @param head The list that shall pick up the elements of @p list. */
@brief Appends the write buffer elements of @p list to @p head. @param list The elements which shall be appended to @p head. @param head The list that shall pick up the elements of @p list.
[ "@brief", "Appends", "the", "write", "buffer", "elements", "of", "@p", "list", "to", "@p", "head", ".", "@param", "list", "The", "elements", "which", "shall", "be", "appended", "to", "@p", "head", ".", "@param", "head", "The", "list", "that", "shall", "pick", "up", "the", "elements", "of", "@p", "list", "." ]
static inline void cio_write_buffer_splice(struct cio_write_buffer *list, struct cio_write_buffer *head) { if (!cio_write_buffer_queue_empty(list)) { struct cio_write_buffer *new_last = list->prev; struct cio_write_buffer *new_first = list->next; struct cio_write_buffer *last = head->prev; last->next = list->next; new_first->prev = last; new_last->next = head; head->prev = new_last; head->data.head.q_len += list->data.head.q_len; head->data.head.total_length += list->data.head.total_length; cio_write_buffer_head_init(list); } }
[ "static", "inline", "void", "cio_write_buffer_splice", "(", "struct", "cio_write_buffer", "*", "list", ",", "struct", "cio_write_buffer", "*", "head", ")", "{", "if", "(", "!", "cio_write_buffer_queue_empty", "(", "list", ")", ")", "{", "struct", "cio_write_buffer", "*", "new_last", "=", "list", "->", "prev", ";", "struct", "cio_write_buffer", "*", "new_first", "=", "list", "->", "next", ";", "struct", "cio_write_buffer", "*", "last", "=", "head", "->", "prev", ";", "last", "->", "next", "=", "list", "->", "next", ";", "new_first", "->", "prev", "=", "last", ";", "new_last", "->", "next", "=", "head", ";", "head", "->", "prev", "=", "new_last", ";", "head", "->", "data", ".", "head", ".", "q_len", "+=", "list", "->", "data", ".", "head", ".", "q_len", ";", "head", "->", "data", ".", "head", ".", "total_length", "+=", "list", "->", "data", ".", "head", ".", "total_length", ";", "cio_write_buffer_head_init", "(", "list", ")", ";", "}", "}" ]
@brief Appends the write buffer elements of @p list to @p head.
[ "@brief", "Appends", "the", "write", "buffer", "elements", "of", "@p", "list", "to", "@p", "head", "." ]
[]
[ { "param": "list", "type": "struct cio_write_buffer" }, { "param": "head", "type": "struct cio_write_buffer" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "list", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "head", "type": "struct cio_write_buffer", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
87c2b1eba3d47d2c8590c1877e13f1c2e92b2857
bsdshell/dejsonlz4
src/ref_compress/jsonlz4.c
[ "BSD-2-Clause" ]
C
ensure_binary
int
int ensure_binary(FILE *f) { #ifdef _WIN32 /* -1 is failure: https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx */ return _setmode(_fileno(f), O_BINARY) == -1; #else return 0; /* not required */ #endif }
/* If required, prevents EOL translations with f. Returns non-zero on failure */
If required, prevents EOL translations with f. Returns non-zero on failure
[ "If", "required", "prevents", "EOL", "translations", "with", "f", ".", "Returns", "non", "-", "zero", "on", "failure" ]
int ensure_binary(FILE *f) { #ifdef _WIN32 return _setmode(_fileno(f), O_BINARY) == -1; #else return 0; #endif }
[ "int", "ensure_binary", "(", "FILE", "*", "f", ")", "{", "#ifdef", "_WIN32", "return", "_setmode", "(", "_fileno", "(", "f", ")", ",", "O_BINARY", ")", "==", "-1", ";", "#else", "return", "0", ";", "#endif", "}" ]
If required, prevents EOL translations with f. Returns non-zero on failure
[ "If", "required", "prevents", "EOL", "translations", "with", "f", ".", "Returns", "non", "-", "zero", "on", "failure" ]
[ "/* -1 is failure: https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx */", "/* not required */" ]
[ { "param": "f", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "f", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
87c2b1eba3d47d2c8590c1877e13f1c2e92b2857
bsdshell/dejsonlz4
src/ref_compress/jsonlz4.c
[ "BSD-2-Clause" ]
C
file_to_mem
void
void *file_to_mem(const char *fname, size_t *out_size) { unsigned char *buf = 0, *rv = 0; size_t buf_size = 0, got = 0; FILE *f = fname ? fopen(fname, "rb") : stdin; if (!f) return 0; /* can't do anything */ if (!fname && ensure_binary(f)) fprintf(stderr, "Warning: cannot set stdin to binary mode\n"); do { buf_size = got ? got * 2 : INITIAL_ALLOC_SIZE; if (buf_size <= got || !(buf = realloc(buf, buf_size))) break; /* size_t wrap-around or OOM: break before EOF */ rv = buf; got += fread(buf + got, 1, buf_size - got, f); } while (got == buf_size); /* otherwise feof(f) or ferror(f) */ if (!buf || !feof(f) || ferror(f)) { if (rv) free(rv); rv = 0; } if (f && fname) fclose(f); if (rv && out_size) *out_size = got; return rv; }
/* if fname is NULL, reads from stdin till EOF */
if fname is NULL, reads from stdin till EOF
[ "if", "fname", "is", "NULL", "reads", "from", "stdin", "till", "EOF" ]
void *file_to_mem(const char *fname, size_t *out_size) { unsigned char *buf = 0, *rv = 0; size_t buf_size = 0, got = 0; FILE *f = fname ? fopen(fname, "rb") : stdin; if (!f) return 0; if (!fname && ensure_binary(f)) fprintf(stderr, "Warning: cannot set stdin to binary mode\n"); do { buf_size = got ? got * 2 : INITIAL_ALLOC_SIZE; if (buf_size <= got || !(buf = realloc(buf, buf_size))) break; rv = buf; got += fread(buf + got, 1, buf_size - got, f); } while (got == buf_size); if (!buf || !feof(f) || ferror(f)) { if (rv) free(rv); rv = 0; } if (f && fname) fclose(f); if (rv && out_size) *out_size = got; return rv; }
[ "void", "*", "file_to_mem", "(", "const", "char", "*", "fname", ",", "size_t", "*", "out_size", ")", "{", "unsigned", "char", "*", "buf", "=", "0", ",", "*", "rv", "=", "0", ";", "size_t", "buf_size", "=", "0", ",", "got", "=", "0", ";", "FILE", "*", "f", "=", "fname", "?", "fopen", "(", "fname", ",", "\"", "\"", ")", ":", "stdin", ";", "if", "(", "!", "f", ")", "return", "0", ";", "if", "(", "!", "fname", "&&", "ensure_binary", "(", "f", ")", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "do", "{", "buf_size", "=", "got", "?", "got", "*", "2", ":", "INITIAL_ALLOC_SIZE", ";", "if", "(", "buf_size", "<=", "got", "||", "!", "(", "buf", "=", "realloc", "(", "buf", ",", "buf_size", ")", ")", ")", "break", ";", "rv", "=", "buf", ";", "got", "+=", "fread", "(", "buf", "+", "got", ",", "1", ",", "buf_size", "-", "got", ",", "f", ")", ";", "}", "while", "(", "got", "==", "buf_size", ")", ";", "if", "(", "!", "buf", "||", "!", "feof", "(", "f", ")", "||", "ferror", "(", "f", ")", ")", "{", "if", "(", "rv", ")", "free", "(", "rv", ")", ";", "rv", "=", "0", ";", "}", "if", "(", "f", "&&", "fname", ")", "fclose", "(", "f", ")", ";", "if", "(", "rv", "&&", "out_size", ")", "*", "out_size", "=", "got", ";", "return", "rv", ";", "}" ]
if fname is NULL, reads from stdin till EOF
[ "if", "fname", "is", "NULL", "reads", "from", "stdin", "till", "EOF" ]
[ "/* can't do anything */", "/* size_t wrap-around or OOM: break before EOF */", "/* otherwise feof(f) or ferror(f) */" ]
[ { "param": "fname", "type": "char" }, { "param": "out_size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "out_size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
read_rotary_encoder
int
int read_rotary_encoder(ioexpander_t *ioe, int channel) { int last = ioe->_encoder_last[channel]; uint8_t reg = 0; switch(channel) { case 1: reg = REG_ENC_1_COUNT; break; case 2: reg = REG_ENC_2_COUNT; break; case 3: reg = REG_ENC_3_COUNT; break; case 4: reg = REG_ENC_4_COUNT; break; default: fprintf(stderr, "Invalid channel: %d\n", channel); exit(1); } int value = _ioe_i2c_read8(ioe, reg); if (value & 0b10000000) { value -= 256; } if (last > 64 && value < -64) { ioe->_encoder_offset[channel - 1] += 256; } if (last < -64 && value > 64) { ioe->_encoder_offset[channel - 1] -= 256; } ioe->_encoder_last[channel - 1] = value; return ioe->_encoder_offset[channel - 1] + value; }
/** Read the step count from a rotary encoder. */
Read the step count from a rotary encoder.
[ "Read", "the", "step", "count", "from", "a", "rotary", "encoder", "." ]
int read_rotary_encoder(ioexpander_t *ioe, int channel) { int last = ioe->_encoder_last[channel]; uint8_t reg = 0; switch(channel) { case 1: reg = REG_ENC_1_COUNT; break; case 2: reg = REG_ENC_2_COUNT; break; case 3: reg = REG_ENC_3_COUNT; break; case 4: reg = REG_ENC_4_COUNT; break; default: fprintf(stderr, "Invalid channel: %d\n", channel); exit(1); } int value = _ioe_i2c_read8(ioe, reg); if (value & 0b10000000) { value -= 256; } if (last > 64 && value < -64) { ioe->_encoder_offset[channel - 1] += 256; } if (last < -64 && value > 64) { ioe->_encoder_offset[channel - 1] -= 256; } ioe->_encoder_last[channel - 1] = value; return ioe->_encoder_offset[channel - 1] + value; }
[ "int", "read_rotary_encoder", "(", "ioexpander_t", "*", "ioe", ",", "int", "channel", ")", "{", "int", "last", "=", "ioe", "->", "_encoder_last", "[", "channel", "]", ";", "uint8_t", "reg", "=", "0", ";", "switch", "(", "channel", ")", "{", "case", "1", ":", "reg", "=", "REG_ENC_1_COUNT", ";", "break", ";", "case", "2", ":", "reg", "=", "REG_ENC_2_COUNT", ";", "break", ";", "case", "3", ":", "reg", "=", "REG_ENC_3_COUNT", ";", "break", ";", "case", "4", ":", "reg", "=", "REG_ENC_4_COUNT", ";", "break", ";", "default", ":", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "channel", ")", ";", "exit", "(", "1", ")", ";", "}", "int", "value", "=", "_ioe_i2c_read8", "(", "ioe", ",", "reg", ")", ";", "if", "(", "value", "&", "0b10000000", ")", "{", "value", "-=", "256", ";", "}", "if", "(", "last", ">", "64", "&&", "value", "<", "-64", ")", "{", "ioe", "->", "_encoder_offset", "[", "channel", "-", "1", "]", "+=", "256", ";", "}", "if", "(", "last", "<", "-64", "&&", "value", ">", "64", ")", "{", "ioe", "->", "_encoder_offset", "[", "channel", "-", "1", "]", "-=", "256", ";", "}", "ioe", "->", "_encoder_last", "[", "channel", "-", "1", "]", "=", "value", ";", "return", "ioe", "->", "_encoder_offset", "[", "channel", "-", "1", "]", "+", "value", ";", "}" ]
Read the step count from a rotary encoder.
[ "Read", "the", "step", "count", "from", "a", "rotary", "encoder", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "channel", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "channel", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
_ioe_set_bits
void
void _ioe_set_bits(ioexpander_t *ioe, uint8_t reg, uint8_t bits) { if (isBitAddressedReg(reg)) { // What is this? for (int bit = 0; bit < 8; bit++) { if (bits & (1 << bit)) { _ioe_i2c_write8(ioe, reg, 0b1000 | (bit & 0b111)); } } } else { uint8_t value = _ioe_i2c_read8(ioe, reg); usleep(1000); _ioe_i2c_write8(ioe, reg, value | bits); } }
/** Set the specified bits (using a mask) in a register. */
Set the specified bits (using a mask) in a register.
[ "Set", "the", "specified", "bits", "(", "using", "a", "mask", ")", "in", "a", "register", "." ]
void _ioe_set_bits(ioexpander_t *ioe, uint8_t reg, uint8_t bits) { if (isBitAddressedReg(reg)) { for (int bit = 0; bit < 8; bit++) { if (bits & (1 << bit)) { _ioe_i2c_write8(ioe, reg, 0b1000 | (bit & 0b111)); } } } else { uint8_t value = _ioe_i2c_read8(ioe, reg); usleep(1000); _ioe_i2c_write8(ioe, reg, value | bits); } }
[ "void", "_ioe_set_bits", "(", "ioexpander_t", "*", "ioe", ",", "uint8_t", "reg", ",", "uint8_t", "bits", ")", "{", "if", "(", "isBitAddressedReg", "(", "reg", ")", ")", "{", "for", "(", "int", "bit", "=", "0", ";", "bit", "<", "8", ";", "bit", "++", ")", "{", "if", "(", "bits", "&", "(", "1", "<<", "bit", ")", ")", "{", "_ioe_i2c_write8", "(", "ioe", ",", "reg", ",", "0b1000", "|", "(", "bit", "&", "0b111", ")", ")", ";", "}", "}", "}", "else", "{", "uint8_t", "value", "=", "_ioe_i2c_read8", "(", "ioe", ",", "reg", ")", ";", "usleep", "(", "1000", ")", ";", "_ioe_i2c_write8", "(", "ioe", ",", "reg", ",", "value", "|", "bits", ")", ";", "}", "}" ]
Set the specified bits (using a mask) in a register.
[ "Set", "the", "specified", "bits", "(", "using", "a", "mask", ")", "in", "a", "register", "." ]
[ "// What is this?" ]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "reg", "type": "uint8_t" }, { "param": "bits", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "reg", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bits", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
_ioe_clr_bits
void
void _ioe_clr_bits(ioexpander_t *ioe, uint8_t reg, uint8_t bits) { if (isBitAddressedReg(reg)) { for (int bit = 0; bit < 8; bit++) { if (bits & (1 << bit)) { _ioe_i2c_write8(ioe, reg, 0b0000 | (bit & 0b111)); } } } else { uint8_t value = _ioe_i2c_read8(ioe, reg); usleep(1000); _ioe_i2c_write8(ioe, reg, value & ~bits); } }
/** Clear the specified bits (using a mask) in a register. */
Clear the specified bits (using a mask) in a register.
[ "Clear", "the", "specified", "bits", "(", "using", "a", "mask", ")", "in", "a", "register", "." ]
void _ioe_clr_bits(ioexpander_t *ioe, uint8_t reg, uint8_t bits) { if (isBitAddressedReg(reg)) { for (int bit = 0; bit < 8; bit++) { if (bits & (1 << bit)) { _ioe_i2c_write8(ioe, reg, 0b0000 | (bit & 0b111)); } } } else { uint8_t value = _ioe_i2c_read8(ioe, reg); usleep(1000); _ioe_i2c_write8(ioe, reg, value & ~bits); } }
[ "void", "_ioe_clr_bits", "(", "ioexpander_t", "*", "ioe", ",", "uint8_t", "reg", ",", "uint8_t", "bits", ")", "{", "if", "(", "isBitAddressedReg", "(", "reg", ")", ")", "{", "for", "(", "int", "bit", "=", "0", ";", "bit", "<", "8", ";", "bit", "++", ")", "{", "if", "(", "bits", "&", "(", "1", "<<", "bit", ")", ")", "{", "_ioe_i2c_write8", "(", "ioe", ",", "reg", ",", "0b0000", "|", "(", "bit", "&", "0b111", ")", ")", ";", "}", "}", "}", "else", "{", "uint8_t", "value", "=", "_ioe_i2c_read8", "(", "ioe", ",", "reg", ")", ";", "usleep", "(", "1000", ")", ";", "_ioe_i2c_write8", "(", "ioe", ",", "reg", ",", "value", "&", "~", "bits", ")", ";", "}", "}" ]
Clear the specified bits (using a mask) in a register.
[ "Clear", "the", "specified", "bits", "(", "using", "a", "mask", ")", "in", "a", "register", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "reg", "type": "uint8_t" }, { "param": "bits", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "reg", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bits", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
_ioe_change_bit
void
void _ioe_change_bit(ioexpander_t *ioe, uint8_t reg, uint8_t bit, bool state) { if (state) { _ioe_set_bit(ioe, reg, bit); } else { _ioe_clr_bit(ioe, reg, bit); } }
/** Toggle one register bit on/off. */
Toggle one register bit on/off.
[ "Toggle", "one", "register", "bit", "on", "/", "off", "." ]
void _ioe_change_bit(ioexpander_t *ioe, uint8_t reg, uint8_t bit, bool state) { if (state) { _ioe_set_bit(ioe, reg, bit); } else { _ioe_clr_bit(ioe, reg, bit); } }
[ "void", "_ioe_change_bit", "(", "ioexpander_t", "*", "ioe", ",", "uint8_t", "reg", ",", "uint8_t", "bit", ",", "bool", "state", ")", "{", "if", "(", "state", ")", "{", "_ioe_set_bit", "(", "ioe", ",", "reg", ",", "bit", ")", ";", "}", "else", "{", "_ioe_clr_bit", "(", "ioe", ",", "reg", ",", "bit", ")", ";", "}", "}" ]
Toggle one register bit on/off.
[ "Toggle", "one", "register", "bit", "on", "/", "off", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "reg", "type": "uint8_t" }, { "param": "bit", "type": "uint8_t" }, { "param": "state", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "reg", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bit", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "state", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
_ioe_get_interrupt
void
void _ioe_get_interrupt(ioexpander_t *ioe) { if (ioe->_interrupt_pin != -1) { return !get_gpio_pin_value(ioe->_interrupt_pin); } else { return _ioe_get_bit(ioe, REG_INT, BIT_INT_TRIGD); } }
/** Get the IOE interrupt state. */
Get the IOE interrupt state.
[ "Get", "the", "IOE", "interrupt", "state", "." ]
void _ioe_get_interrupt(ioexpander_t *ioe) { if (ioe->_interrupt_pin != -1) { return !get_gpio_pin_value(ioe->_interrupt_pin); } else { return _ioe_get_bit(ioe, REG_INT, BIT_INT_TRIGD); } }
[ "void", "_ioe_get_interrupt", "(", "ioexpander_t", "*", "ioe", ")", "{", "if", "(", "ioe", "->", "_interrupt_pin", "!=", "-1", ")", "{", "return", "!", "get_gpio_pin_value", "(", "ioe", "->", "_interrupt_pin", ")", ";", "}", "else", "{", "return", "_ioe_get_bit", "(", "ioe", ",", "REG_INT", ",", "BIT_INT_TRIGD", ")", ";", "}", "}" ]
Get the IOE interrupt state.
[ "Get", "the", "IOE", "interrupt", "state", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
on_interrupt
void
void on_interrupt(ioexpander_t *ioe, void (*callback)()) { if (ioe->_interrupt_pin != -1) { ioe->_gpio.add_event_detect(ioe->_interrupt_pin, ioe->_gpio.FALLING, callback=callback, bouncetime=1); } }
/** * Attach an event handler to be run on interrupt. * @param callback Callback function to run: callback(pin) */
Attach an event handler to be run on interrupt. @param callback Callback function to run: callback(pin)
[ "Attach", "an", "event", "handler", "to", "be", "run", "on", "interrupt", ".", "@param", "callback", "Callback", "function", "to", "run", ":", "callback", "(", "pin", ")" ]
void on_interrupt(ioexpander_t *ioe, void (*callback)()) { if (ioe->_interrupt_pin != -1) { ioe->_gpio.add_event_detect(ioe->_interrupt_pin, ioe->_gpio.FALLING, callback=callback, bouncetime=1); } }
[ "void", "on_interrupt", "(", "ioexpander_t", "*", "ioe", ",", "void", "(", "*", "callback", ")", "(", ")", ")", "{", "if", "(", "ioe", "->", "_interrupt_pin", "!=", "-1", ")", "{", "ioe", "->", "_gpio", ".", "add_event_detect", "(", "ioe", "->", "_interrupt_pin", ",", "ioe", "->", "_gpio", ".", "FALLING", ",", "callback", "=", "callback", ",", "bouncetime", "=", "1", ")", ";", "}", "}" ]
Attach an event handler to be run on interrupt.
[ "Attach", "an", "event", "handler", "to", "be", "run", "on", "interrupt", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "callback", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "callback", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
_ioe_wait_for_flash
void
void _ioe_wait_for_flash(ioexpander_t *ioe) { double t_start = _ioe_fractime(); while (_ioe_get_interrupt(ioe) { if (_ioe_fractime() - t_start > ioe->_timeout) { fprintf(stderr, "Timed out waiting for interrupt!\n"); exit(1); } usleep(1000); } t_start = _ioe_fractime(); while (! _ioe_get_interrupt(ioe) { if (_ioe_fractime() - t_start > ioe->_timeout) { fprintf(stderr, "Timed out waiting for interrupt!\n"); exit(1); } usleep(1000); } }
/** Wait for the IOE to finish writing non-volatile memory. */
Wait for the IOE to finish writing non-volatile memory.
[ "Wait", "for", "the", "IOE", "to", "finish", "writing", "non", "-", "volatile", "memory", "." ]
void _ioe_wait_for_flash(ioexpander_t *ioe) { double t_start = _ioe_fractime(); while (_ioe_get_interrupt(ioe) { if (_ioe_fractime() - t_start > ioe->_timeout) { fprintf(stderr, "Timed out waiting for interrupt!\n"); exit(1); } usleep(1000); } t_start = _ioe_fractime(); while (! _ioe_get_interrupt(ioe) { if (_ioe_fractime() - t_start > ioe->_timeout) { fprintf(stderr, "Timed out waiting for interrupt!\n"); exit(1); } usleep(1000); } }
[ "void", "_ioe_wait_for_flash", "(", "ioexpander_t", "*", "ioe", ")", "{", "double", "t_start", "=", "_ioe_fractime", "(", ")", ";", "while", "(", "_ioe_get_interrupt", "(", "ioe", ")", "", "{", "if", "(", "_ioe_fractime", "(", ")", "-", "t_start", ">", "ioe", "->", "_timeout", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "usleep", "(", "1000", ")", ";", "}", "t_start", "=", "_ioe_fractime", "(", ")", ";", "while", "(", "!", "_ioe_get_interrupt", "(", "ioe", ")", "", "{", "if", "(", "_ioe_fractime", "(", ")", "-", "t_start", ">", "ioe", "->", "_timeout", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "usleep", "(", "1000", ")", ";", "}", "}" ]
Wait for the IOE to finish writing non-volatile memory.
[ "Wait", "for", "the", "IOE", "to", "finish", "writing", "non", "-", "volatile", "memory", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
ioe_set_mode
void
void ioe_set_mode(ioexpander_t *ioe, int pinNumber, int mode, bool schmitt_trigger /* false */, bool invert /* false */) { if (pinNumber < 1 || pinNumber > (sizeof(ioe->_pins) / sizeof(ioe->_pins[0]))) { fprintf(stderr, "Pin should be in range 1-14.\n"); exit(1); } pin_t *io_pin = ioe->_pins[pinNumber - 1]; if (io_pin->mode == mode) { return; } int gpio_mode = mode & 0b11; int io_mode = (mode >> 2) & 0b11; int initial_state = mode >> 4; if (io_mode != PIN_MODE_IO && !io_pin->modeSupported[mode]) { fprintf(stderr,"Pin %d does not support %s!\n", pinNumber, MODE_NAMES[io_mode]); exit(1); } io_pin->mode = mode; if (ioe->_debug) { printf("Setting pin %d to mode %d %s %s, state: %s\n", pinNumber, io_mode, MODE_NAMES[io_mode], GPIO_NAMES[gpio_mode], STATE_NAMES[initial_state]); } if (mode == PIN_MODE_PWM) { _ioe_set_bit(ioe, io_pin->reg_iopwm, io_pin->pwm_channel); _ioe_change_bit(ioe, REG_PNP, io_pin->pwm_channel, invert); _ioe_set_bit(ioe, REG_PWMCON0, 7); // Set PWMRUN bit; } else { if (io_pin->modeSupported[PIN_MODE_PWM]) { if (ioe->_debug) { fprintf(stderr, "Disabling PWM on pin %d\n", pinNumber); } _ioe_clr_bit(ioe, io_pin->reg_iopwm, io_pin->pwm_channel); } } int pm1 = _ioe_i2c_read8(ioe, io_pin->reg_m1); int pm2 = _ioe_i2c_read8(ioe, io_pin->reg_m2); // Clear the pm1 and pm2 bits pm1 &= 255 - (1 << io_pin->pinNumber); pm2 &= 255 - (1 << io_pin->pinNumber); // Set the new pm1 and pm2 bits according to our gpio_mode pm1 |= (gpio_mode >> 1) << io_pin->pinNumber; pm2 |= (gpio_mode & 0b1) << io_pin->pinNumber; _ioe_i2c_write8(ioe, io_pin->reg_m1, pm1); _ioe_i2c_write8(ioe, io_pin->reg_m2, pm2); // Set up Schmitt trigger mode on inputs if (mode == PIN_MODE_PU || mode == PIN_MODE_IN) { _ioe_change_bit(ioe, io_pin->reg_ps, io_pin->pinNumber, schmitt_trigger); } // 5th bit of mode encodes default output pin state _ioe_i2c_write8(ioe, io_pin->reg_p, (initial_state << 3) | io_pin->pinNumber); }
/** * Set a pin output mode. * @param mode one of the supplied IN, OUT, PWM or ADC constants */
Set a pin output mode.
[ "Set", "a", "pin", "output", "mode", "." ]
void ioe_set_mode(ioexpander_t *ioe, int pinNumber, int mode, bool schmitt_trigger , bool invert ) { if (pinNumber < 1 || pinNumber > (sizeof(ioe->_pins) / sizeof(ioe->_pins[0]))) { fprintf(stderr, "Pin should be in range 1-14.\n"); exit(1); } pin_t *io_pin = ioe->_pins[pinNumber - 1]; if (io_pin->mode == mode) { return; } int gpio_mode = mode & 0b11; int io_mode = (mode >> 2) & 0b11; int initial_state = mode >> 4; if (io_mode != PIN_MODE_IO && !io_pin->modeSupported[mode]) { fprintf(stderr,"Pin %d does not support %s!\n", pinNumber, MODE_NAMES[io_mode]); exit(1); } io_pin->mode = mode; if (ioe->_debug) { printf("Setting pin %d to mode %d %s %s, state: %s\n", pinNumber, io_mode, MODE_NAMES[io_mode], GPIO_NAMES[gpio_mode], STATE_NAMES[initial_state]); } if (mode == PIN_MODE_PWM) { _ioe_set_bit(ioe, io_pin->reg_iopwm, io_pin->pwm_channel); _ioe_change_bit(ioe, REG_PNP, io_pin->pwm_channel, invert); _ioe_set_bit(ioe, REG_PWMCON0, 7); } else { if (io_pin->modeSupported[PIN_MODE_PWM]) { if (ioe->_debug) { fprintf(stderr, "Disabling PWM on pin %d\n", pinNumber); } _ioe_clr_bit(ioe, io_pin->reg_iopwm, io_pin->pwm_channel); } } int pm1 = _ioe_i2c_read8(ioe, io_pin->reg_m1); int pm2 = _ioe_i2c_read8(ioe, io_pin->reg_m2); pm1 &= 255 - (1 << io_pin->pinNumber); pm2 &= 255 - (1 << io_pin->pinNumber); pm1 |= (gpio_mode >> 1) << io_pin->pinNumber; pm2 |= (gpio_mode & 0b1) << io_pin->pinNumber; _ioe_i2c_write8(ioe, io_pin->reg_m1, pm1); _ioe_i2c_write8(ioe, io_pin->reg_m2, pm2); if (mode == PIN_MODE_PU || mode == PIN_MODE_IN) { _ioe_change_bit(ioe, io_pin->reg_ps, io_pin->pinNumber, schmitt_trigger); } _ioe_i2c_write8(ioe, io_pin->reg_p, (initial_state << 3) | io_pin->pinNumber); }
[ "void", "ioe_set_mode", "(", "ioexpander_t", "*", "ioe", ",", "int", "pinNumber", ",", "int", "mode", ",", "bool", "schmitt_trigger", ",", "bool", "invert", ")", "{", "if", "(", "pinNumber", "<", "1", "||", "pinNumber", ">", "(", "sizeof", "(", "ioe", "->", "_pins", ")", "/", "sizeof", "(", "ioe", "->", "_pins", "[", "0", "]", ")", ")", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "pin_t", "*", "io_pin", "=", "ioe", "->", "_pins", "[", "pinNumber", "-", "1", "]", ";", "if", "(", "io_pin", "->", "mode", "==", "mode", ")", "{", "return", ";", "}", "int", "gpio_mode", "=", "mode", "&", "0b11", ";", "int", "io_mode", "=", "(", "mode", ">>", "2", ")", "&", "0b11", ";", "int", "initial_state", "=", "mode", ">>", "4", ";", "if", "(", "io_mode", "!=", "PIN_MODE_IO", "&&", "!", "io_pin", "->", "modeSupported", "[", "mode", "]", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "pinNumber", ",", "MODE_NAMES", "[", "io_mode", "]", ")", ";", "exit", "(", "1", ")", ";", "}", "io_pin", "->", "mode", "=", "mode", ";", "if", "(", "ioe", "->", "_debug", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "pinNumber", ",", "io_mode", ",", "MODE_NAMES", "[", "io_mode", "]", ",", "GPIO_NAMES", "[", "gpio_mode", "]", ",", "STATE_NAMES", "[", "initial_state", "]", ")", ";", "}", "if", "(", "mode", "==", "PIN_MODE_PWM", ")", "{", "_ioe_set_bit", "(", "ioe", ",", "io_pin", "->", "reg_iopwm", ",", "io_pin", "->", "pwm_channel", ")", ";", "_ioe_change_bit", "(", "ioe", ",", "REG_PNP", ",", "io_pin", "->", "pwm_channel", ",", "invert", ")", ";", "_ioe_set_bit", "(", "ioe", ",", "REG_PWMCON0", ",", "7", ")", ";", "}", "else", "{", "if", "(", "io_pin", "->", "modeSupported", "[", "PIN_MODE_PWM", "]", ")", "{", "if", "(", "ioe", "->", "_debug", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "pinNumber", ")", ";", "}", "_ioe_clr_bit", "(", "ioe", ",", "io_pin", "->", "reg_iopwm", ",", "io_pin", "->", "pwm_channel", ")", ";", "}", "}", "int", "pm1", "=", "_ioe_i2c_read8", "(", "ioe", ",", "io_pin", "->", "reg_m1", ")", ";", "int", "pm2", "=", "_ioe_i2c_read8", "(", "ioe", ",", "io_pin", "->", "reg_m2", ")", ";", "pm1", "&=", "255", "-", "(", "1", "<<", "io_pin", "->", "pinNumber", ")", ";", "pm2", "&=", "255", "-", "(", "1", "<<", "io_pin", "->", "pinNumber", ")", ";", "pm1", "|=", "(", "gpio_mode", ">>", "1", ")", "<<", "io_pin", "->", "pinNumber", ";", "pm2", "|=", "(", "gpio_mode", "&", "0b1", ")", "<<", "io_pin", "->", "pinNumber", ";", "_ioe_i2c_write8", "(", "ioe", ",", "io_pin", "->", "reg_m1", ",", "pm1", ")", ";", "_ioe_i2c_write8", "(", "ioe", ",", "io_pin", "->", "reg_m2", ",", "pm2", ")", ";", "if", "(", "mode", "==", "PIN_MODE_PU", "||", "mode", "==", "PIN_MODE_IN", ")", "{", "_ioe_change_bit", "(", "ioe", ",", "io_pin", "->", "reg_ps", ",", "io_pin", "->", "pinNumber", ",", "schmitt_trigger", ")", ";", "}", "_ioe_i2c_write8", "(", "ioe", ",", "io_pin", "->", "reg_p", ",", "(", "initial_state", "<<", "3", ")", "|", "io_pin", "->", "pinNumber", ")", ";", "}" ]
Set a pin output mode.
[ "Set", "a", "pin", "output", "mode", "." ]
[ "/* false */", "/* false */", "// Set PWMRUN bit;", "// Clear the pm1 and pm2 bits", "// Set the new pm1 and pm2 bits according to our gpio_mode", "// Set up Schmitt trigger mode on inputs", "// 5th bit of mode encodes default output pin state" ]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "pinNumber", "type": "int" }, { "param": "mode", "type": "int" }, { "param": "schmitt_trigger", "type": "bool" }, { "param": "invert", "type": "bool" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pinNumber", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mode", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "schmitt_trigger", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "invert", "type": "bool", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
input
int
int input(ioexpander_t *ioe, int pinNumber, double adc_timeout /* 1.0 */) { if (pinNumber < 1 || pinNumber > (sizeof(ioe->_pins) / sizeof(ioe->_pins[0]))) { fprintf(stderr, "Pin should be in range 1-14.\n"); exit(1); } pin_t *io_pin = ioe->_pins[pinNumber - 1]; if (ioe->_debug) { fprintf(stderr, "Read pin %d channel %d\n", pinNumber, io_pin->adc_channel); } if (io_pin->mode == PIN_MODE_ADC) { if (ioe->_debug) { printf("Reading ADC from pin %d\n", pinNumber); printf("ADC Channel: %d\n", io_pin->adc_channel); } _ioe_clr_bits(ioe, REG_ADCCON0, 0x0f); _ioe_set_bits(ioe, REG_ADCCON0, io_pin->adc_channel); _ioe_i2c_write8(ioe, REG_AINDIDS, 0); _ioe_set_bit(ioe, REG_AINDIDS, io_pin->adc_channel); _ioe_set_bit(ioe, REG_ADCCON1, 0); _ioe_clr_bit(ioe, REG_ADCCON0, 7); // ADCF - Clear the conversion complete flag _ioe_set_bit(ioe, REG_ADCCON0, 6); // ADCS - Set the ADC conversion start flag // Wait for the ADCF conversion complete flag to be set double t_start = _ioe_fractime(); while (!_ioe_get_bit(ioe, REG_ADCCON0, 7)) { usleep(10000); if (_ioe_fractime() - t_start >= adc_timeout) { fprintf(stderr, "Timeout waiting for ADC conversion!\n"); exit(1); } } uint8_t hi = _ioe_i2c_read8(ioe, REG_ADCRH); uint8_t lo = _ioe_i2c_read8(ioe, REG_ADCRL); if (ioe->_debug) { fprintf(stderr, "Hi: %d lo: %d computed: %d\n", hi, lo, ((hi << 4) | lo)); } return (((int)hi << 4) | lo); // Original Python code was this value / 4095.0 * ioe->_vref, // but we need to represent it as an integer from 0..4095. } else { if (ioe->_debug) { printf("Reading IO from pin %d\n", pinNumber); } bool pv = _ioe_get_bit(ioe, io_pin->reg_p, io_pin->pinNumber); return pv ? HIGH : LOW; } }
/** * Read the IO pin state. * * Returns a 12-bit ADC reading if the pin is in ADC mode * Returns True/False if the pin is in any other input mode * Returns 0 if the pin is in PWM mode * @param adc_timeout Timeout (in seconds) for an ADC read (default 1.0) */
Read the IO pin state. Returns a 12-bit ADC reading if the pin is in ADC mode Returns True/False if the pin is in any other input mode Returns 0 if the pin is in PWM mode @param adc_timeout Timeout (in seconds) for an ADC read (default 1.0)
[ "Read", "the", "IO", "pin", "state", ".", "Returns", "a", "12", "-", "bit", "ADC", "reading", "if", "the", "pin", "is", "in", "ADC", "mode", "Returns", "True", "/", "False", "if", "the", "pin", "is", "in", "any", "other", "input", "mode", "Returns", "0", "if", "the", "pin", "is", "in", "PWM", "mode", "@param", "adc_timeout", "Timeout", "(", "in", "seconds", ")", "for", "an", "ADC", "read", "(", "default", "1", ".", "0", ")" ]
int input(ioexpander_t *ioe, int pinNumber, double adc_timeout ) { if (pinNumber < 1 || pinNumber > (sizeof(ioe->_pins) / sizeof(ioe->_pins[0]))) { fprintf(stderr, "Pin should be in range 1-14.\n"); exit(1); } pin_t *io_pin = ioe->_pins[pinNumber - 1]; if (ioe->_debug) { fprintf(stderr, "Read pin %d channel %d\n", pinNumber, io_pin->adc_channel); } if (io_pin->mode == PIN_MODE_ADC) { if (ioe->_debug) { printf("Reading ADC from pin %d\n", pinNumber); printf("ADC Channel: %d\n", io_pin->adc_channel); } _ioe_clr_bits(ioe, REG_ADCCON0, 0x0f); _ioe_set_bits(ioe, REG_ADCCON0, io_pin->adc_channel); _ioe_i2c_write8(ioe, REG_AINDIDS, 0); _ioe_set_bit(ioe, REG_AINDIDS, io_pin->adc_channel); _ioe_set_bit(ioe, REG_ADCCON1, 0); _ioe_clr_bit(ioe, REG_ADCCON0, 7); _ioe_set_bit(ioe, REG_ADCCON0, 6); double t_start = _ioe_fractime(); while (!_ioe_get_bit(ioe, REG_ADCCON0, 7)) { usleep(10000); if (_ioe_fractime() - t_start >= adc_timeout) { fprintf(stderr, "Timeout waiting for ADC conversion!\n"); exit(1); } } uint8_t hi = _ioe_i2c_read8(ioe, REG_ADCRH); uint8_t lo = _ioe_i2c_read8(ioe, REG_ADCRL); if (ioe->_debug) { fprintf(stderr, "Hi: %d lo: %d computed: %d\n", hi, lo, ((hi << 4) | lo)); } return (((int)hi << 4) | lo); } else { if (ioe->_debug) { printf("Reading IO from pin %d\n", pinNumber); } bool pv = _ioe_get_bit(ioe, io_pin->reg_p, io_pin->pinNumber); return pv ? HIGH : LOW; } }
[ "int", "input", "(", "ioexpander_t", "*", "ioe", ",", "int", "pinNumber", ",", "double", "adc_timeout", ")", "{", "if", "(", "pinNumber", "<", "1", "||", "pinNumber", ">", "(", "sizeof", "(", "ioe", "->", "_pins", ")", "/", "sizeof", "(", "ioe", "->", "_pins", "[", "0", "]", ")", ")", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "pin_t", "*", "io_pin", "=", "ioe", "->", "_pins", "[", "pinNumber", "-", "1", "]", ";", "if", "(", "ioe", "->", "_debug", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "pinNumber", ",", "io_pin", "->", "adc_channel", ")", ";", "}", "if", "(", "io_pin", "->", "mode", "==", "PIN_MODE_ADC", ")", "{", "if", "(", "ioe", "->", "_debug", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "pinNumber", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "io_pin", "->", "adc_channel", ")", ";", "}", "_ioe_clr_bits", "(", "ioe", ",", "REG_ADCCON0", ",", "0x0f", ")", ";", "_ioe_set_bits", "(", "ioe", ",", "REG_ADCCON0", ",", "io_pin", "->", "adc_channel", ")", ";", "_ioe_i2c_write8", "(", "ioe", ",", "REG_AINDIDS", ",", "0", ")", ";", "_ioe_set_bit", "(", "ioe", ",", "REG_AINDIDS", ",", "io_pin", "->", "adc_channel", ")", ";", "_ioe_set_bit", "(", "ioe", ",", "REG_ADCCON1", ",", "0", ")", ";", "_ioe_clr_bit", "(", "ioe", ",", "REG_ADCCON0", ",", "7", ")", ";", "_ioe_set_bit", "(", "ioe", ",", "REG_ADCCON0", ",", "6", ")", ";", "double", "t_start", "=", "_ioe_fractime", "(", ")", ";", "while", "(", "!", "_ioe_get_bit", "(", "ioe", ",", "REG_ADCCON0", ",", "7", ")", ")", "{", "usleep", "(", "10000", ")", ";", "if", "(", "_ioe_fractime", "(", ")", "-", "t_start", ">=", "adc_timeout", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "}", "uint8_t", "hi", "=", "_ioe_i2c_read8", "(", "ioe", ",", "REG_ADCRH", ")", ";", "uint8_t", "lo", "=", "_ioe_i2c_read8", "(", "ioe", ",", "REG_ADCRL", ")", ";", "if", "(", "ioe", "->", "_debug", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "hi", ",", "lo", ",", "(", "(", "hi", "<<", "4", ")", "|", "lo", ")", ")", ";", "}", "return", "(", "(", "(", "int", ")", "hi", "<<", "4", ")", "|", "lo", ")", ";", "}", "else", "{", "if", "(", "ioe", "->", "_debug", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "pinNumber", ")", ";", "}", "bool", "pv", "=", "_ioe_get_bit", "(", "ioe", ",", "io_pin", "->", "reg_p", ",", "io_pin", "->", "pinNumber", ")", ";", "return", "pv", "?", "HIGH", ":", "LOW", ";", "}", "}" ]
Read the IO pin state.
[ "Read", "the", "IO", "pin", "state", "." ]
[ "/* 1.0 */", "// ADCF - Clear the conversion complete flag", "// ADCS - Set the ADC conversion start flag", "// Wait for the ADCF conversion complete flag to be set", "// Original Python code was this value / 4095.0 * ioe->_vref,", "// but we need to represent it as an integer from 0..4095." ]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "pinNumber", "type": "int" }, { "param": "adc_timeout", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pinNumber", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "adc_timeout", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a76694bba4e2698a70aa7223634b4c95d7efdfe5
dgatwood/ioe-c
library/ioexpander/ioexpander.c
[ "MIT" ]
C
_ioe_output
void
void _ioe_output(ioexpander_t *ioe, int pinNumber, uint32_t value) { if (pinNumber < 1 || pinNumber > (sizeof(ioe->_pins) / sizeof(ioe->_pins[0]))) { fprintf(stderr, "Pin should be in range 1-14.\n"); exit(1); } pin_t *io_pin = ioe->_pins[pinNumber - 1]; if (io_pin->mode == PIN_MODE_PWM) { if (ioe->_debug) { printf("Outputting PWM to pin: %d\n", pinNumber); } _ioe_i2c_write8(ioe, io_pin->reg_pwml, value & 0xff); _ioe_i2c_write8(ioe, io_pin->reg_pwmh, value >> 8); _ioe_pwm_load(ioe); } else { if (value == LOW) { if (ioe->_debug) { printf("Outputting LOW to pin: %d\n", pinNumber); } _ioe_clr_bit(ioe, io_pin->reg_p, io_pin->pinNumber); } else if (value == HIGH) { if (ioe->_debug) { printf("Outputting HIGH to pin: %d\n", pinNumber); } _ioe_set_bit(ioe, io_pin->reg_p, io_pin->pinNumber); } } }
/** * Write an IO pin state or PWM duty cycle. * @param value Either True/False for OUT, or a number between 0 and PWM period for PWM. * */
Write an IO pin state or PWM duty cycle. @param value Either True/False for OUT, or a number between 0 and PWM period for PWM.
[ "Write", "an", "IO", "pin", "state", "or", "PWM", "duty", "cycle", ".", "@param", "value", "Either", "True", "/", "False", "for", "OUT", "or", "a", "number", "between", "0", "and", "PWM", "period", "for", "PWM", "." ]
void _ioe_output(ioexpander_t *ioe, int pinNumber, uint32_t value) { if (pinNumber < 1 || pinNumber > (sizeof(ioe->_pins) / sizeof(ioe->_pins[0]))) { fprintf(stderr, "Pin should be in range 1-14.\n"); exit(1); } pin_t *io_pin = ioe->_pins[pinNumber - 1]; if (io_pin->mode == PIN_MODE_PWM) { if (ioe->_debug) { printf("Outputting PWM to pin: %d\n", pinNumber); } _ioe_i2c_write8(ioe, io_pin->reg_pwml, value & 0xff); _ioe_i2c_write8(ioe, io_pin->reg_pwmh, value >> 8); _ioe_pwm_load(ioe); } else { if (value == LOW) { if (ioe->_debug) { printf("Outputting LOW to pin: %d\n", pinNumber); } _ioe_clr_bit(ioe, io_pin->reg_p, io_pin->pinNumber); } else if (value == HIGH) { if (ioe->_debug) { printf("Outputting HIGH to pin: %d\n", pinNumber); } _ioe_set_bit(ioe, io_pin->reg_p, io_pin->pinNumber); } } }
[ "void", "_ioe_output", "(", "ioexpander_t", "*", "ioe", ",", "int", "pinNumber", ",", "uint32_t", "value", ")", "{", "if", "(", "pinNumber", "<", "1", "||", "pinNumber", ">", "(", "sizeof", "(", "ioe", "->", "_pins", ")", "/", "sizeof", "(", "ioe", "->", "_pins", "[", "0", "]", ")", ")", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "pin_t", "*", "io_pin", "=", "ioe", "->", "_pins", "[", "pinNumber", "-", "1", "]", ";", "if", "(", "io_pin", "->", "mode", "==", "PIN_MODE_PWM", ")", "{", "if", "(", "ioe", "->", "_debug", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "pinNumber", ")", ";", "}", "_ioe_i2c_write8", "(", "ioe", ",", "io_pin", "->", "reg_pwml", ",", "value", "&", "0xff", ")", ";", "_ioe_i2c_write8", "(", "ioe", ",", "io_pin", "->", "reg_pwmh", ",", "value", ">>", "8", ")", ";", "_ioe_pwm_load", "(", "ioe", ")", ";", "}", "else", "{", "if", "(", "value", "==", "LOW", ")", "{", "if", "(", "ioe", "->", "_debug", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "pinNumber", ")", ";", "}", "_ioe_clr_bit", "(", "ioe", ",", "io_pin", "->", "reg_p", ",", "io_pin", "->", "pinNumber", ")", ";", "}", "else", "if", "(", "value", "==", "HIGH", ")", "{", "if", "(", "ioe", "->", "_debug", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "pinNumber", ")", ";", "}", "_ioe_set_bit", "(", "ioe", ",", "io_pin", "->", "reg_p", ",", "io_pin", "->", "pinNumber", ")", ";", "}", "}", "}" ]
Write an IO pin state or PWM duty cycle.
[ "Write", "an", "IO", "pin", "state", "or", "PWM", "duty", "cycle", "." ]
[]
[ { "param": "ioe", "type": "ioexpander_t" }, { "param": "pinNumber", "type": "int" }, { "param": "value", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ioe", "type": "ioexpander_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pinNumber", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "value", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornGetForeignRelSize
void
static void multicornGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid) { MulticornPlanState *planstate = palloc0(sizeof(MulticornPlanState)); ForeignTable *ftable = GetForeignTable(foreigntableid); ListCell *lc; bool needWholeRow = false; TupleDesc desc; baserel->fdw_private = planstate; planstate->fdw_instance = getInstance(foreigntableid); planstate->foreigntableid = foreigntableid; /* Initialize the conversion info array */ { Relation rel = RelationIdGetRelation(ftable->relid); AttInMetadata *attinmeta; desc = RelationGetDescr(rel); attinmeta = TupleDescGetAttInMetadata(desc); planstate->numattrs = RelationGetNumberOfAttributes(rel); planstate->cinfos = palloc0(sizeof(ConversionInfo *) * planstate->numattrs); initConversioninfo(planstate->cinfos, attinmeta); needWholeRow = rel->trigdesc && rel->trigdesc->trig_insert_after_row; RelationClose(rel); } if (needWholeRow) { int i; for (i = 0; i < desc->natts; i++) { Form_pg_attribute att = TupleDescAttr(desc, i); if (!att->attisdropped) { planstate->target_list = lappend(planstate->target_list, makeString(NameStr(att->attname))); } } } else { /* Pull "var" clauses to build an appropriate target list */ #if PG_VERSION_NUM >= 90600 foreach(lc, extractColumns(baserel->reltarget->exprs, baserel->baserestrictinfo)) #else foreach(lc, extractColumns(baserel->reltargetlist, baserel->baserestrictinfo)) #endif { Var *var = (Var *) lfirst(lc); Value *colname; /* * Store only a Value node containing the string name of the * column. */ colname = colnameFromVar(var, root, planstate); if (colname != NULL && strVal(colname) != NULL) { planstate->target_list = lappend(planstate->target_list, colname); } } } /* Extract the restrictions from the plan. */ foreach(lc, baserel->baserestrictinfo) { extractRestrictions(baserel->relids, ((RestrictInfo *) lfirst(lc))->clause, &planstate->qual_list); } /* Inject the "rows" and "width" attribute into the baserel */ #if PG_VERSION_NUM >= 90600 getRelSize(planstate, root, &baserel->rows, &baserel->reltarget->width); planstate->width = baserel->reltarget->width; #else getRelSize(planstate, root, &baserel->rows, &baserel->width); #endif }
/* * multicornGetForeignRelSize * Obtain relation size estimates for a foreign table. * This is done by calling the */
multicornGetForeignRelSize Obtain relation size estimates for a foreign table. This is done by calling the
[ "multicornGetForeignRelSize", "Obtain", "relation", "size", "estimates", "for", "a", "foreign", "table", ".", "This", "is", "done", "by", "calling", "the" ]
static void multicornGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid) { MulticornPlanState *planstate = palloc0(sizeof(MulticornPlanState)); ForeignTable *ftable = GetForeignTable(foreigntableid); ListCell *lc; bool needWholeRow = false; TupleDesc desc; baserel->fdw_private = planstate; planstate->fdw_instance = getInstance(foreigntableid); planstate->foreigntableid = foreigntableid; { Relation rel = RelationIdGetRelation(ftable->relid); AttInMetadata *attinmeta; desc = RelationGetDescr(rel); attinmeta = TupleDescGetAttInMetadata(desc); planstate->numattrs = RelationGetNumberOfAttributes(rel); planstate->cinfos = palloc0(sizeof(ConversionInfo *) * planstate->numattrs); initConversioninfo(planstate->cinfos, attinmeta); needWholeRow = rel->trigdesc && rel->trigdesc->trig_insert_after_row; RelationClose(rel); } if (needWholeRow) { int i; for (i = 0; i < desc->natts; i++) { Form_pg_attribute att = TupleDescAttr(desc, i); if (!att->attisdropped) { planstate->target_list = lappend(planstate->target_list, makeString(NameStr(att->attname))); } } } else { #if PG_VERSION_NUM >= 90600 foreach(lc, extractColumns(baserel->reltarget->exprs, baserel->baserestrictinfo)) #else foreach(lc, extractColumns(baserel->reltargetlist, baserel->baserestrictinfo)) #endif { Var *var = (Var *) lfirst(lc); Value *colname; colname = colnameFromVar(var, root, planstate); if (colname != NULL && strVal(colname) != NULL) { planstate->target_list = lappend(planstate->target_list, colname); } } } foreach(lc, baserel->baserestrictinfo) { extractRestrictions(baserel->relids, ((RestrictInfo *) lfirst(lc))->clause, &planstate->qual_list); } #if PG_VERSION_NUM >= 90600 getRelSize(planstate, root, &baserel->rows, &baserel->reltarget->width); planstate->width = baserel->reltarget->width; #else getRelSize(planstate, root, &baserel->rows, &baserel->width); #endif }
[ "static", "void", "multicornGetForeignRelSize", "(", "PlannerInfo", "*", "root", ",", "RelOptInfo", "*", "baserel", ",", "Oid", "foreigntableid", ")", "{", "MulticornPlanState", "*", "planstate", "=", "palloc0", "(", "sizeof", "(", "MulticornPlanState", ")", ")", ";", "ForeignTable", "*", "ftable", "=", "GetForeignTable", "(", "foreigntableid", ")", ";", "ListCell", "*", "lc", ";", "bool", "needWholeRow", "=", "false", ";", "TupleDesc", "desc", ";", "baserel", "->", "fdw_private", "=", "planstate", ";", "planstate", "->", "fdw_instance", "=", "getInstance", "(", "foreigntableid", ")", ";", "planstate", "->", "foreigntableid", "=", "foreigntableid", ";", "{", "Relation", "rel", "=", "RelationIdGetRelation", "(", "ftable", "->", "relid", ")", ";", "AttInMetadata", "*", "attinmeta", ";", "desc", "=", "RelationGetDescr", "(", "rel", ")", ";", "attinmeta", "=", "TupleDescGetAttInMetadata", "(", "desc", ")", ";", "planstate", "->", "numattrs", "=", "RelationGetNumberOfAttributes", "(", "rel", ")", ";", "planstate", "->", "cinfos", "=", "palloc0", "(", "sizeof", "(", "ConversionInfo", "*", ")", "*", "planstate", "->", "numattrs", ")", ";", "initConversioninfo", "(", "planstate", "->", "cinfos", ",", "attinmeta", ")", ";", "needWholeRow", "=", "rel", "->", "trigdesc", "&&", "rel", "->", "trigdesc", "->", "trig_insert_after_row", ";", "RelationClose", "(", "rel", ")", ";", "}", "if", "(", "needWholeRow", ")", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "desc", "->", "natts", ";", "i", "++", ")", "{", "Form_pg_attribute", "att", "=", "TupleDescAttr", "(", "desc", ",", "i", ")", ";", "if", "(", "!", "att", "->", "attisdropped", ")", "{", "planstate", "->", "target_list", "=", "lappend", "(", "planstate", "->", "target_list", ",", "makeString", "(", "NameStr", "(", "att", "->", "attname", ")", ")", ")", ";", "}", "}", "}", "else", "{", "#if", "PG_VERSION_NUM", ">=", "90600", "\n", "foreach", "(", "lc", ",", "extractColumns", "(", "baserel", "->", "reltarget", "->", "exprs", ",", "baserel", "->", "baserestrictinfo", ")", ")", "", "#else", "foreach", "(", "lc", ",", "extractColumns", "(", "baserel", "->", "reltargetlist", ",", "baserel", "->", "baserestrictinfo", ")", ")", "", "#endif", "{", "Var", "*", "var", "=", "(", "Var", "*", ")", "lfirst", "(", "lc", ")", ";", "Value", "*", "colname", ";", "colname", "=", "colnameFromVar", "(", "var", ",", "root", ",", "planstate", ")", ";", "if", "(", "colname", "!=", "NULL", "&&", "strVal", "(", "colname", ")", "!=", "NULL", ")", "{", "planstate", "->", "target_list", "=", "lappend", "(", "planstate", "->", "target_list", ",", "colname", ")", ";", "}", "}", "}", "foreach", "(", "lc", ",", "baserel", "->", "baserestrictinfo", ")", "", "{", "extractRestrictions", "(", "baserel", "->", "relids", ",", "(", "(", "RestrictInfo", "*", ")", "lfirst", "(", "lc", ")", ")", "->", "clause", ",", "&", "planstate", "->", "qual_list", ")", ";", "}", "#if", "PG_VERSION_NUM", ">=", "90600", "\n", "getRelSize", "(", "planstate", ",", "root", ",", "&", "baserel", "->", "rows", ",", "&", "baserel", "->", "reltarget", "->", "width", ")", ";", "planstate", "->", "width", "=", "baserel", "->", "reltarget", "->", "width", ";", "#else", "getRelSize", "(", "planstate", ",", "root", ",", "&", "baserel", "->", "rows", ",", "&", "baserel", "->", "width", ")", ";", "#endif", "}" ]
multicornGetForeignRelSize Obtain relation size estimates for a foreign table.
[ "multicornGetForeignRelSize", "Obtain", "relation", "size", "estimates", "for", "a", "foreign", "table", "." ]
[ "/* Initialize the conversion info array */", "/* Pull \"var\" clauses to build an appropriate target list */", "/*\n\t\t\t * Store only a Value node containing the string name of the\n\t\t\t * column.\n\t\t\t */", "/* Extract the restrictions from the plan. */", "/* Inject the \"rows\" and \"width\" attribute into the baserel */" ]
[ { "param": "root", "type": "PlannerInfo" }, { "param": "baserel", "type": "RelOptInfo" }, { "param": "foreigntableid", "type": "Oid" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "root", "type": "PlannerInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "baserel", "type": "RelOptInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "foreigntableid", "type": "Oid", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornExplainForeignScan
void
static void multicornExplainForeignScan(ForeignScanState *node, ExplainState *es) { PyObject *p_iterable = execute(node, es), *p_item, *p_str; Py_INCREF(p_iterable); while((p_item = PyIter_Next(p_iterable))){ p_str = PyObject_Str(p_item); ExplainPropertyText("Multicorn", PyString_AsString(p_str), es); Py_DECREF(p_str); } Py_DECREF(p_iterable); errorCheck(); }
/* * multicornExplainForeignScan * Placeholder for additional "EXPLAIN" information. * This should (at least) output the python class name, as well * as information that was taken into account for the choice of a path. */
multicornExplainForeignScan Placeholder for additional "EXPLAIN" information. This should (at least) output the python class name, as well as information that was taken into account for the choice of a path.
[ "multicornExplainForeignScan", "Placeholder", "for", "additional", "\"", "EXPLAIN", "\"", "information", ".", "This", "should", "(", "at", "least", ")", "output", "the", "python", "class", "name", "as", "well", "as", "information", "that", "was", "taken", "into", "account", "for", "the", "choice", "of", "a", "path", "." ]
static void multicornExplainForeignScan(ForeignScanState *node, ExplainState *es) { PyObject *p_iterable = execute(node, es), *p_item, *p_str; Py_INCREF(p_iterable); while((p_item = PyIter_Next(p_iterable))){ p_str = PyObject_Str(p_item); ExplainPropertyText("Multicorn", PyString_AsString(p_str), es); Py_DECREF(p_str); } Py_DECREF(p_iterable); errorCheck(); }
[ "static", "void", "multicornExplainForeignScan", "(", "ForeignScanState", "*", "node", ",", "ExplainState", "*", "es", ")", "{", "PyObject", "*", "p_iterable", "=", "execute", "(", "node", ",", "es", ")", ",", "*", "p_item", ",", "*", "p_str", ";", "Py_INCREF", "(", "p_iterable", ")", ";", "while", "(", "(", "p_item", "=", "PyIter_Next", "(", "p_iterable", ")", ")", ")", "{", "p_str", "=", "PyObject_Str", "(", "p_item", ")", ";", "ExplainPropertyText", "(", "\"", "\"", ",", "PyString_AsString", "(", "p_str", ")", ",", "es", ")", ";", "Py_DECREF", "(", "p_str", ")", ";", "}", "Py_DECREF", "(", "p_iterable", ")", ";", "errorCheck", "(", ")", ";", "}" ]
multicornExplainForeignScan Placeholder for additional "EXPLAIN" information.
[ "multicornExplainForeignScan", "Placeholder", "for", "additional", "\"", "EXPLAIN", "\"", "information", "." ]
[]
[ { "param": "node", "type": "ForeignScanState" }, { "param": "es", "type": "ExplainState" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "node", "type": "ForeignScanState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "es", "type": "ExplainState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornBeginForeignScan
void
static void multicornBeginForeignScan(ForeignScanState *node, int eflags) { ForeignScan *fscan = (ForeignScan *) node->ss.ps.plan; MulticornExecState *execstate; TupleDesc tupdesc = RelationGetDescr(node->ss.ss_currentRelation); ListCell *lc; execstate = initializeExecState(fscan->fdw_private); execstate->values = palloc(sizeof(Datum) * tupdesc->natts); execstate->nulls = palloc(sizeof(bool) * tupdesc->natts); execstate->qual_list = NULL; foreach(lc, fscan->fdw_exprs) { extractRestrictions(bms_make_singleton(fscan->scan.scanrelid), ((Expr *) lfirst(lc)), &execstate->qual_list); } initConversioninfo(execstate->cinfos, TupleDescGetAttInMetadata(tupdesc)); node->fdw_state = execstate; }
/* * multicornBeginForeignScan * Initialize the foreign scan. * This (primarily) involves : * - retrieving cached info from the plan phase * - initializing various buffers */
multicornBeginForeignScan Initialize the foreign scan. This (primarily) involves : - retrieving cached info from the plan phase - initializing various buffers
[ "multicornBeginForeignScan", "Initialize", "the", "foreign", "scan", ".", "This", "(", "primarily", ")", "involves", ":", "-", "retrieving", "cached", "info", "from", "the", "plan", "phase", "-", "initializing", "various", "buffers" ]
static void multicornBeginForeignScan(ForeignScanState *node, int eflags) { ForeignScan *fscan = (ForeignScan *) node->ss.ps.plan; MulticornExecState *execstate; TupleDesc tupdesc = RelationGetDescr(node->ss.ss_currentRelation); ListCell *lc; execstate = initializeExecState(fscan->fdw_private); execstate->values = palloc(sizeof(Datum) * tupdesc->natts); execstate->nulls = palloc(sizeof(bool) * tupdesc->natts); execstate->qual_list = NULL; foreach(lc, fscan->fdw_exprs) { extractRestrictions(bms_make_singleton(fscan->scan.scanrelid), ((Expr *) lfirst(lc)), &execstate->qual_list); } initConversioninfo(execstate->cinfos, TupleDescGetAttInMetadata(tupdesc)); node->fdw_state = execstate; }
[ "static", "void", "multicornBeginForeignScan", "(", "ForeignScanState", "*", "node", ",", "int", "eflags", ")", "{", "ForeignScan", "*", "fscan", "=", "(", "ForeignScan", "*", ")", "node", "->", "ss", ".", "ps", ".", "plan", ";", "MulticornExecState", "*", "execstate", ";", "TupleDesc", "tupdesc", "=", "RelationGetDescr", "(", "node", "->", "ss", ".", "ss_currentRelation", ")", ";", "ListCell", "*", "lc", ";", "execstate", "=", "initializeExecState", "(", "fscan", "->", "fdw_private", ")", ";", "execstate", "->", "values", "=", "palloc", "(", "sizeof", "(", "Datum", ")", "*", "tupdesc", "->", "natts", ")", ";", "execstate", "->", "nulls", "=", "palloc", "(", "sizeof", "(", "bool", ")", "*", "tupdesc", "->", "natts", ")", ";", "execstate", "->", "qual_list", "=", "NULL", ";", "foreach", "(", "lc", ",", "fscan", "->", "fdw_exprs", ")", "", "{", "extractRestrictions", "(", "bms_make_singleton", "(", "fscan", "->", "scan", ".", "scanrelid", ")", ",", "(", "(", "Expr", "*", ")", "lfirst", "(", "lc", ")", ")", ",", "&", "execstate", "->", "qual_list", ")", ";", "}", "initConversioninfo", "(", "execstate", "->", "cinfos", ",", "TupleDescGetAttInMetadata", "(", "tupdesc", ")", ")", ";", "node", "->", "fdw_state", "=", "execstate", ";", "}" ]
multicornBeginForeignScan Initialize the foreign scan.
[ "multicornBeginForeignScan", "Initialize", "the", "foreign", "scan", "." ]
[]
[ { "param": "node", "type": "ForeignScanState" }, { "param": "eflags", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "node", "type": "ForeignScanState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "eflags", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornIterateForeignScan
TupleTableSlot
static TupleTableSlot * multicornIterateForeignScan(ForeignScanState *node) { TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; MulticornExecState *execstate = node->fdw_state; PyObject *p_value; if (execstate->p_iterator == NULL) { execute(node, NULL); } ExecClearTuple(slot); if (execstate->p_iterator == Py_None) { /* No iterator returned from get_iterator */ Py_DECREF(execstate->p_iterator); return slot; } p_value = PyIter_Next(execstate->p_iterator); errorCheck(); /* A none value results in an empty slot. */ if (p_value == NULL || p_value == Py_None) { Py_XDECREF(p_value); return slot; } slot->tts_values = execstate->values; slot->tts_isnull = execstate->nulls; pythonResultToTuple(p_value, slot, execstate->cinfos, execstate->buffer); ExecStoreVirtualTuple(slot); Py_DECREF(p_value); return slot; }
/* * multicornIterateForeignScan * Retrieve next row from the result set, or clear tuple slot to indicate * EOF. * * This is done by iterating over the result from the "execute" python * method. */
multicornIterateForeignScan Retrieve next row from the result set, or clear tuple slot to indicate EOF. This is done by iterating over the result from the "execute" python method.
[ "multicornIterateForeignScan", "Retrieve", "next", "row", "from", "the", "result", "set", "or", "clear", "tuple", "slot", "to", "indicate", "EOF", ".", "This", "is", "done", "by", "iterating", "over", "the", "result", "from", "the", "\"", "execute", "\"", "python", "method", "." ]
static TupleTableSlot * multicornIterateForeignScan(ForeignScanState *node) { TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; MulticornExecState *execstate = node->fdw_state; PyObject *p_value; if (execstate->p_iterator == NULL) { execute(node, NULL); } ExecClearTuple(slot); if (execstate->p_iterator == Py_None) { Py_DECREF(execstate->p_iterator); return slot; } p_value = PyIter_Next(execstate->p_iterator); errorCheck(); if (p_value == NULL || p_value == Py_None) { Py_XDECREF(p_value); return slot; } slot->tts_values = execstate->values; slot->tts_isnull = execstate->nulls; pythonResultToTuple(p_value, slot, execstate->cinfos, execstate->buffer); ExecStoreVirtualTuple(slot); Py_DECREF(p_value); return slot; }
[ "static", "TupleTableSlot", "*", "multicornIterateForeignScan", "(", "ForeignScanState", "*", "node", ")", "{", "TupleTableSlot", "*", "slot", "=", "node", "->", "ss", ".", "ss_ScanTupleSlot", ";", "MulticornExecState", "*", "execstate", "=", "node", "->", "fdw_state", ";", "PyObject", "*", "p_value", ";", "if", "(", "execstate", "->", "p_iterator", "==", "NULL", ")", "{", "execute", "(", "node", ",", "NULL", ")", ";", "}", "ExecClearTuple", "(", "slot", ")", ";", "if", "(", "execstate", "->", "p_iterator", "==", "Py_None", ")", "{", "Py_DECREF", "(", "execstate", "->", "p_iterator", ")", ";", "return", "slot", ";", "}", "p_value", "=", "PyIter_Next", "(", "execstate", "->", "p_iterator", ")", ";", "errorCheck", "(", ")", ";", "if", "(", "p_value", "==", "NULL", "||", "p_value", "==", "Py_None", ")", "{", "Py_XDECREF", "(", "p_value", ")", ";", "return", "slot", ";", "}", "slot", "->", "tts_values", "=", "execstate", "->", "values", ";", "slot", "->", "tts_isnull", "=", "execstate", "->", "nulls", ";", "pythonResultToTuple", "(", "p_value", ",", "slot", ",", "execstate", "->", "cinfos", ",", "execstate", "->", "buffer", ")", ";", "ExecStoreVirtualTuple", "(", "slot", ")", ";", "Py_DECREF", "(", "p_value", ")", ";", "return", "slot", ";", "}" ]
multicornIterateForeignScan Retrieve next row from the result set, or clear tuple slot to indicate EOF.
[ "multicornIterateForeignScan", "Retrieve", "next", "row", "from", "the", "result", "set", "or", "clear", "tuple", "slot", "to", "indicate", "EOF", "." ]
[ "/* No iterator returned from get_iterator */", "/* A none value results in an empty slot. */" ]
[ { "param": "node", "type": "ForeignScanState" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "node", "type": "ForeignScanState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornEndForeignScan
void
static void multicornEndForeignScan(ForeignScanState *node) { MulticornExecState *state = node->fdw_state; PyObject *result = PyObject_CallMethod(state->fdw_instance, "end_scan", "()"); errorCheck(); Py_DECREF(result); Py_DECREF(state->fdw_instance); Py_XDECREF(state->p_iterator); state->p_iterator = NULL; }
/* * multicornEndForeignScan * Finish scanning foreign table and dispose objects used for this scan. */
multicornEndForeignScan Finish scanning foreign table and dispose objects used for this scan.
[ "multicornEndForeignScan", "Finish", "scanning", "foreign", "table", "and", "dispose", "objects", "used", "for", "this", "scan", "." ]
static void multicornEndForeignScan(ForeignScanState *node) { MulticornExecState *state = node->fdw_state; PyObject *result = PyObject_CallMethod(state->fdw_instance, "end_scan", "()"); errorCheck(); Py_DECREF(result); Py_DECREF(state->fdw_instance); Py_XDECREF(state->p_iterator); state->p_iterator = NULL; }
[ "static", "void", "multicornEndForeignScan", "(", "ForeignScanState", "*", "node", ")", "{", "MulticornExecState", "*", "state", "=", "node", "->", "fdw_state", ";", "PyObject", "*", "result", "=", "PyObject_CallMethod", "(", "state", "->", "fdw_instance", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "errorCheck", "(", ")", ";", "Py_DECREF", "(", "result", ")", ";", "Py_DECREF", "(", "state", "->", "fdw_instance", ")", ";", "Py_XDECREF", "(", "state", "->", "p_iterator", ")", ";", "state", "->", "p_iterator", "=", "NULL", ";", "}" ]
multicornEndForeignScan Finish scanning foreign table and dispose objects used for this scan.
[ "multicornEndForeignScan", "Finish", "scanning", "foreign", "table", "and", "dispose", "objects", "used", "for", "this", "scan", "." ]
[]
[ { "param": "node", "type": "ForeignScanState" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "node", "type": "ForeignScanState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornAddForeignUpdateTargets
void
static void multicornAddForeignUpdateTargets(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation) { Var *var = NULL; TargetEntry *tle, *returningTle; PyObject *instance = getInstance(target_relation->rd_id); const char *attrname = getRowIdColumn(instance); TupleDesc desc = target_relation->rd_att; int i; ListCell *cell; foreach(cell, parsetree->returningList) { returningTle = lfirst(cell); tle = copyObject(returningTle); tle->resjunk = true; parsetree->targetList = lappend(parsetree->targetList, tle); } for (i = 0; i < desc->natts; i++) { Form_pg_attribute att = TupleDescAttr(desc, i); if (!att->attisdropped) { if (strcmp(NameStr(att->attname), attrname) == 0) { var = makeVar(parsetree->resultRelation, att->attnum, att->atttypid, att->atttypmod, att->attcollation, 0); break; } } } if (var == NULL) { ereport(ERROR, (errmsg("%s", "The rowid attribute does not exist"))); } tle = makeTargetEntry((Expr *) var, list_length(parsetree->targetList) + 1, strdup(attrname), true); parsetree->targetList = lappend(parsetree->targetList, tle); Py_DECREF(instance); }
/* * multicornAddForeigUpdateTargets * Add resjunk columns needed for update/delete. */
multicornAddForeigUpdateTargets Add resjunk columns needed for update/delete.
[ "multicornAddForeigUpdateTargets", "Add", "resjunk", "columns", "needed", "for", "update", "/", "delete", "." ]
static void multicornAddForeignUpdateTargets(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation) { Var *var = NULL; TargetEntry *tle, *returningTle; PyObject *instance = getInstance(target_relation->rd_id); const char *attrname = getRowIdColumn(instance); TupleDesc desc = target_relation->rd_att; int i; ListCell *cell; foreach(cell, parsetree->returningList) { returningTle = lfirst(cell); tle = copyObject(returningTle); tle->resjunk = true; parsetree->targetList = lappend(parsetree->targetList, tle); } for (i = 0; i < desc->natts; i++) { Form_pg_attribute att = TupleDescAttr(desc, i); if (!att->attisdropped) { if (strcmp(NameStr(att->attname), attrname) == 0) { var = makeVar(parsetree->resultRelation, att->attnum, att->atttypid, att->atttypmod, att->attcollation, 0); break; } } } if (var == NULL) { ereport(ERROR, (errmsg("%s", "The rowid attribute does not exist"))); } tle = makeTargetEntry((Expr *) var, list_length(parsetree->targetList) + 1, strdup(attrname), true); parsetree->targetList = lappend(parsetree->targetList, tle); Py_DECREF(instance); }
[ "static", "void", "multicornAddForeignUpdateTargets", "(", "Query", "*", "parsetree", ",", "RangeTblEntry", "*", "target_rte", ",", "Relation", "target_relation", ")", "{", "Var", "*", "var", "=", "NULL", ";", "TargetEntry", "*", "tle", ",", "*", "returningTle", ";", "PyObject", "*", "instance", "=", "getInstance", "(", "target_relation", "->", "rd_id", ")", ";", "const", "char", "*", "attrname", "=", "getRowIdColumn", "(", "instance", ")", ";", "TupleDesc", "desc", "=", "target_relation", "->", "rd_att", ";", "int", "i", ";", "ListCell", "*", "cell", ";", "foreach", "(", "cell", ",", "parsetree", "->", "returningList", ")", "", "{", "returningTle", "=", "lfirst", "(", "cell", ")", ";", "tle", "=", "copyObject", "(", "returningTle", ")", ";", "tle", "->", "resjunk", "=", "true", ";", "parsetree", "->", "targetList", "=", "lappend", "(", "parsetree", "->", "targetList", ",", "tle", ")", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "desc", "->", "natts", ";", "i", "++", ")", "{", "Form_pg_attribute", "att", "=", "TupleDescAttr", "(", "desc", ",", "i", ")", ";", "if", "(", "!", "att", "->", "attisdropped", ")", "{", "if", "(", "strcmp", "(", "NameStr", "(", "att", "->", "attname", ")", ",", "attrname", ")", "==", "0", ")", "{", "var", "=", "makeVar", "(", "parsetree", "->", "resultRelation", ",", "att", "->", "attnum", ",", "att", "->", "atttypid", ",", "att", "->", "atttypmod", ",", "att", "->", "attcollation", ",", "0", ")", ";", "break", ";", "}", "}", "}", "if", "(", "var", "==", "NULL", ")", "{", "ereport", "(", "ERROR", ",", "(", "errmsg", "(", "\"", "\"", ",", "\"", "\"", ")", ")", ")", ";", "}", "tle", "=", "makeTargetEntry", "(", "(", "Expr", "*", ")", "var", ",", "list_length", "(", "parsetree", "->", "targetList", ")", "+", "1", ",", "strdup", "(", "attrname", ")", ",", "true", ")", ";", "parsetree", "->", "targetList", "=", "lappend", "(", "parsetree", "->", "targetList", ",", "tle", ")", ";", "Py_DECREF", "(", "instance", ")", ";", "}" ]
multicornAddForeigUpdateTargets Add resjunk columns needed for update/delete.
[ "multicornAddForeigUpdateTargets", "Add", "resjunk", "columns", "needed", "for", "update", "/", "delete", "." ]
[]
[ { "param": "parsetree", "type": "Query" }, { "param": "target_rte", "type": "RangeTblEntry" }, { "param": "target_relation", "type": "Relation" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "parsetree", "type": "Query", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "target_rte", "type": "RangeTblEntry", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "target_relation", "type": "Relation", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornPlanForeignModify
List
static List * multicornPlanForeignModify(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index) { return NULL; }
/* * multicornPlanForeignModify * Plan a foreign write operation. * This is done by checking the "supported operations" attribute * on the python class. */
multicornPlanForeignModify Plan a foreign write operation. This is done by checking the "supported operations" attribute on the python class.
[ "multicornPlanForeignModify", "Plan", "a", "foreign", "write", "operation", ".", "This", "is", "done", "by", "checking", "the", "\"", "supported", "operations", "\"", "attribute", "on", "the", "python", "class", "." ]
static List * multicornPlanForeignModify(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index) { return NULL; }
[ "static", "List", "*", "multicornPlanForeignModify", "(", "PlannerInfo", "*", "root", ",", "ModifyTable", "*", "plan", ",", "Index", "resultRelation", ",", "int", "subplan_index", ")", "{", "return", "NULL", ";", "}" ]
multicornPlanForeignModify Plan a foreign write operation.
[ "multicornPlanForeignModify", "Plan", "a", "foreign", "write", "operation", "." ]
[]
[ { "param": "root", "type": "PlannerInfo" }, { "param": "plan", "type": "ModifyTable" }, { "param": "resultRelation", "type": "Index" }, { "param": "subplan_index", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "root", "type": "PlannerInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "plan", "type": "ModifyTable", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "resultRelation", "type": "Index", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "subplan_index", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornBeginForeignModify
void
static void multicornBeginForeignModify(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo, List *fdw_private, int subplan_index, int eflags) { MulticornModifyState *modstate = palloc0(sizeof(MulticornModifyState)); Relation rel = resultRelInfo->ri_RelationDesc; TupleDesc desc = RelationGetDescr(rel); PlanState *ps = mtstate->mt_plans[subplan_index]; Plan *subplan = ps->plan; MemoryContext oldcontext; int i; modstate->cinfos = palloc0(sizeof(ConversionInfo *) * desc->natts); modstate->buffer = makeStringInfo(); modstate->fdw_instance = getInstance(rel->rd_id); modstate->rowidAttrName = getRowIdColumn(modstate->fdw_instance); initConversioninfo(modstate->cinfos, TupleDescGetAttInMetadata(desc)); oldcontext = MemoryContextSwitchTo(TopMemoryContext); MemoryContextSwitchTo(oldcontext); if (ps->ps_ResultTupleSlot) { TupleDesc resultTupleDesc = ps->ps_ResultTupleSlot->tts_tupleDescriptor; modstate->resultCinfos = palloc0(sizeof(ConversionInfo *) * resultTupleDesc->natts); initConversioninfo(modstate->resultCinfos, TupleDescGetAttInMetadata(resultTupleDesc)); } for (i = 0; i < desc->natts; i++) { Form_pg_attribute att = TupleDescAttr(desc, i); if (!att->attisdropped) { if (strcmp(NameStr(att->attname), modstate->rowidAttrName) == 0) { modstate->rowidCinfo = modstate->cinfos[i]; break; } } } modstate->rowidAttno = ExecFindJunkAttributeInTlist(subplan->targetlist, modstate->rowidAttrName); resultRelInfo->ri_FdwState = modstate; }
/* * multicornBeginForeignModify * Initialize a foreign write operation. */
multicornBeginForeignModify Initialize a foreign write operation.
[ "multicornBeginForeignModify", "Initialize", "a", "foreign", "write", "operation", "." ]
static void multicornBeginForeignModify(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo, List *fdw_private, int subplan_index, int eflags) { MulticornModifyState *modstate = palloc0(sizeof(MulticornModifyState)); Relation rel = resultRelInfo->ri_RelationDesc; TupleDesc desc = RelationGetDescr(rel); PlanState *ps = mtstate->mt_plans[subplan_index]; Plan *subplan = ps->plan; MemoryContext oldcontext; int i; modstate->cinfos = palloc0(sizeof(ConversionInfo *) * desc->natts); modstate->buffer = makeStringInfo(); modstate->fdw_instance = getInstance(rel->rd_id); modstate->rowidAttrName = getRowIdColumn(modstate->fdw_instance); initConversioninfo(modstate->cinfos, TupleDescGetAttInMetadata(desc)); oldcontext = MemoryContextSwitchTo(TopMemoryContext); MemoryContextSwitchTo(oldcontext); if (ps->ps_ResultTupleSlot) { TupleDesc resultTupleDesc = ps->ps_ResultTupleSlot->tts_tupleDescriptor; modstate->resultCinfos = palloc0(sizeof(ConversionInfo *) * resultTupleDesc->natts); initConversioninfo(modstate->resultCinfos, TupleDescGetAttInMetadata(resultTupleDesc)); } for (i = 0; i < desc->natts; i++) { Form_pg_attribute att = TupleDescAttr(desc, i); if (!att->attisdropped) { if (strcmp(NameStr(att->attname), modstate->rowidAttrName) == 0) { modstate->rowidCinfo = modstate->cinfos[i]; break; } } } modstate->rowidAttno = ExecFindJunkAttributeInTlist(subplan->targetlist, modstate->rowidAttrName); resultRelInfo->ri_FdwState = modstate; }
[ "static", "void", "multicornBeginForeignModify", "(", "ModifyTableState", "*", "mtstate", ",", "ResultRelInfo", "*", "resultRelInfo", ",", "List", "*", "fdw_private", ",", "int", "subplan_index", ",", "int", "eflags", ")", "{", "MulticornModifyState", "*", "modstate", "=", "palloc0", "(", "sizeof", "(", "MulticornModifyState", ")", ")", ";", "Relation", "rel", "=", "resultRelInfo", "->", "ri_RelationDesc", ";", "TupleDesc", "desc", "=", "RelationGetDescr", "(", "rel", ")", ";", "PlanState", "*", "ps", "=", "mtstate", "->", "mt_plans", "[", "subplan_index", "]", ";", "Plan", "*", "subplan", "=", "ps", "->", "plan", ";", "MemoryContext", "oldcontext", ";", "int", "i", ";", "modstate", "->", "cinfos", "=", "palloc0", "(", "sizeof", "(", "ConversionInfo", "*", ")", "*", "desc", "->", "natts", ")", ";", "modstate", "->", "buffer", "=", "makeStringInfo", "(", ")", ";", "modstate", "->", "fdw_instance", "=", "getInstance", "(", "rel", "->", "rd_id", ")", ";", "modstate", "->", "rowidAttrName", "=", "getRowIdColumn", "(", "modstate", "->", "fdw_instance", ")", ";", "initConversioninfo", "(", "modstate", "->", "cinfos", ",", "TupleDescGetAttInMetadata", "(", "desc", ")", ")", ";", "oldcontext", "=", "MemoryContextSwitchTo", "(", "TopMemoryContext", ")", ";", "MemoryContextSwitchTo", "(", "oldcontext", ")", ";", "if", "(", "ps", "->", "ps_ResultTupleSlot", ")", "{", "TupleDesc", "resultTupleDesc", "=", "ps", "->", "ps_ResultTupleSlot", "->", "tts_tupleDescriptor", ";", "modstate", "->", "resultCinfos", "=", "palloc0", "(", "sizeof", "(", "ConversionInfo", "*", ")", "*", "resultTupleDesc", "->", "natts", ")", ";", "initConversioninfo", "(", "modstate", "->", "resultCinfos", ",", "TupleDescGetAttInMetadata", "(", "resultTupleDesc", ")", ")", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "desc", "->", "natts", ";", "i", "++", ")", "{", "Form_pg_attribute", "att", "=", "TupleDescAttr", "(", "desc", ",", "i", ")", ";", "if", "(", "!", "att", "->", "attisdropped", ")", "{", "if", "(", "strcmp", "(", "NameStr", "(", "att", "->", "attname", ")", ",", "modstate", "->", "rowidAttrName", ")", "==", "0", ")", "{", "modstate", "->", "rowidCinfo", "=", "modstate", "->", "cinfos", "[", "i", "]", ";", "break", ";", "}", "}", "}", "modstate", "->", "rowidAttno", "=", "ExecFindJunkAttributeInTlist", "(", "subplan", "->", "targetlist", ",", "modstate", "->", "rowidAttrName", ")", ";", "resultRelInfo", "->", "ri_FdwState", "=", "modstate", ";", "}" ]
multicornBeginForeignModify Initialize a foreign write operation.
[ "multicornBeginForeignModify", "Initialize", "a", "foreign", "write", "operation", "." ]
[]
[ { "param": "mtstate", "type": "ModifyTableState" }, { "param": "resultRelInfo", "type": "ResultRelInfo" }, { "param": "fdw_private", "type": "List" }, { "param": "subplan_index", "type": "int" }, { "param": "eflags", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mtstate", "type": "ModifyTableState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "resultRelInfo", "type": "ResultRelInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fdw_private", "type": "List", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "subplan_index", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "eflags", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornExecForeignInsert
TupleTableSlot
static TupleTableSlot * multicornExecForeignInsert(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *fdw_instance = modstate->fdw_instance; PyObject *values = tupleTableSlotToPyObject(slot, modstate->cinfos); PyObject *p_new_value = PyObject_CallMethod(fdw_instance, "insert", "(O)", values); errorCheck(); if (p_new_value && p_new_value != Py_None) { ExecClearTuple(slot); pythonResultToTuple(p_new_value, slot, modstate->cinfos, modstate->buffer); ExecStoreVirtualTuple(slot); } Py_XDECREF(p_new_value); Py_DECREF(values); errorCheck(); return slot; }
/* * multicornExecForeignInsert * Execute a foreign insert operation * This is done by calling the python "insert" method. */
multicornExecForeignInsert Execute a foreign insert operation This is done by calling the python "insert" method.
[ "multicornExecForeignInsert", "Execute", "a", "foreign", "insert", "operation", "This", "is", "done", "by", "calling", "the", "python", "\"", "insert", "\"", "method", "." ]
static TupleTableSlot * multicornExecForeignInsert(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *fdw_instance = modstate->fdw_instance; PyObject *values = tupleTableSlotToPyObject(slot, modstate->cinfos); PyObject *p_new_value = PyObject_CallMethod(fdw_instance, "insert", "(O)", values); errorCheck(); if (p_new_value && p_new_value != Py_None) { ExecClearTuple(slot); pythonResultToTuple(p_new_value, slot, modstate->cinfos, modstate->buffer); ExecStoreVirtualTuple(slot); } Py_XDECREF(p_new_value); Py_DECREF(values); errorCheck(); return slot; }
[ "static", "TupleTableSlot", "*", "multicornExecForeignInsert", "(", "EState", "*", "estate", ",", "ResultRelInfo", "*", "resultRelInfo", ",", "TupleTableSlot", "*", "slot", ",", "TupleTableSlot", "*", "planSlot", ")", "{", "MulticornModifyState", "*", "modstate", "=", "resultRelInfo", "->", "ri_FdwState", ";", "PyObject", "*", "fdw_instance", "=", "modstate", "->", "fdw_instance", ";", "PyObject", "*", "values", "=", "tupleTableSlotToPyObject", "(", "slot", ",", "modstate", "->", "cinfos", ")", ";", "PyObject", "*", "p_new_value", "=", "PyObject_CallMethod", "(", "fdw_instance", ",", "\"", "\"", ",", "\"", "\"", ",", "values", ")", ";", "errorCheck", "(", ")", ";", "if", "(", "p_new_value", "&&", "p_new_value", "!=", "Py_None", ")", "{", "ExecClearTuple", "(", "slot", ")", ";", "pythonResultToTuple", "(", "p_new_value", ",", "slot", ",", "modstate", "->", "cinfos", ",", "modstate", "->", "buffer", ")", ";", "ExecStoreVirtualTuple", "(", "slot", ")", ";", "}", "Py_XDECREF", "(", "p_new_value", ")", ";", "Py_DECREF", "(", "values", ")", ";", "errorCheck", "(", ")", ";", "return", "slot", ";", "}" ]
multicornExecForeignInsert Execute a foreign insert operation This is done by calling the python "insert" method.
[ "multicornExecForeignInsert", "Execute", "a", "foreign", "insert", "operation", "This", "is", "done", "by", "calling", "the", "python", "\"", "insert", "\"", "method", "." ]
[]
[ { "param": "estate", "type": "EState" }, { "param": "resultRelInfo", "type": "ResultRelInfo" }, { "param": "slot", "type": "TupleTableSlot" }, { "param": "planSlot", "type": "TupleTableSlot" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "estate", "type": "EState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "resultRelInfo", "type": "ResultRelInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "slot", "type": "TupleTableSlot", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "planSlot", "type": "TupleTableSlot", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornExecForeignDelete
TupleTableSlot
static TupleTableSlot * multicornExecForeignDelete(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *fdw_instance = modstate->fdw_instance, *p_row_id, *p_new_value; bool is_null; ConversionInfo *cinfo = modstate->rowidCinfo; Datum value = ExecGetJunkAttribute(planSlot, modstate->rowidAttno, &is_null); p_row_id = datumToPython(value, cinfo->atttypoid, cinfo); p_new_value = PyObject_CallMethod(fdw_instance, "delete", "(O)", p_row_id); errorCheck(); if (p_new_value == NULL || p_new_value == Py_None) { Py_XDECREF(p_new_value); p_new_value = tupleTableSlotToPyObject(planSlot, modstate->resultCinfos); } ExecClearTuple(slot); pythonResultToTuple(p_new_value, slot, modstate->cinfos, modstate->buffer); ExecStoreVirtualTuple(slot); Py_DECREF(p_new_value); Py_DECREF(p_row_id); errorCheck(); return slot; }
/* * multicornExecForeignDelete * Execute a foreign delete operation * This is done by calling the python "delete" method, with the opaque * rowid that was supplied. */
multicornExecForeignDelete Execute a foreign delete operation This is done by calling the python "delete" method, with the opaque rowid that was supplied.
[ "multicornExecForeignDelete", "Execute", "a", "foreign", "delete", "operation", "This", "is", "done", "by", "calling", "the", "python", "\"", "delete", "\"", "method", "with", "the", "opaque", "rowid", "that", "was", "supplied", "." ]
static TupleTableSlot * multicornExecForeignDelete(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *fdw_instance = modstate->fdw_instance, *p_row_id, *p_new_value; bool is_null; ConversionInfo *cinfo = modstate->rowidCinfo; Datum value = ExecGetJunkAttribute(planSlot, modstate->rowidAttno, &is_null); p_row_id = datumToPython(value, cinfo->atttypoid, cinfo); p_new_value = PyObject_CallMethod(fdw_instance, "delete", "(O)", p_row_id); errorCheck(); if (p_new_value == NULL || p_new_value == Py_None) { Py_XDECREF(p_new_value); p_new_value = tupleTableSlotToPyObject(planSlot, modstate->resultCinfos); } ExecClearTuple(slot); pythonResultToTuple(p_new_value, slot, modstate->cinfos, modstate->buffer); ExecStoreVirtualTuple(slot); Py_DECREF(p_new_value); Py_DECREF(p_row_id); errorCheck(); return slot; }
[ "static", "TupleTableSlot", "*", "multicornExecForeignDelete", "(", "EState", "*", "estate", ",", "ResultRelInfo", "*", "resultRelInfo", ",", "TupleTableSlot", "*", "slot", ",", "TupleTableSlot", "*", "planSlot", ")", "{", "MulticornModifyState", "*", "modstate", "=", "resultRelInfo", "->", "ri_FdwState", ";", "PyObject", "*", "fdw_instance", "=", "modstate", "->", "fdw_instance", ",", "*", "p_row_id", ",", "*", "p_new_value", ";", "bool", "is_null", ";", "ConversionInfo", "*", "cinfo", "=", "modstate", "->", "rowidCinfo", ";", "Datum", "value", "=", "ExecGetJunkAttribute", "(", "planSlot", ",", "modstate", "->", "rowidAttno", ",", "&", "is_null", ")", ";", "p_row_id", "=", "datumToPython", "(", "value", ",", "cinfo", "->", "atttypoid", ",", "cinfo", ")", ";", "p_new_value", "=", "PyObject_CallMethod", "(", "fdw_instance", ",", "\"", "\"", ",", "\"", "\"", ",", "p_row_id", ")", ";", "errorCheck", "(", ")", ";", "if", "(", "p_new_value", "==", "NULL", "||", "p_new_value", "==", "Py_None", ")", "{", "Py_XDECREF", "(", "p_new_value", ")", ";", "p_new_value", "=", "tupleTableSlotToPyObject", "(", "planSlot", ",", "modstate", "->", "resultCinfos", ")", ";", "}", "ExecClearTuple", "(", "slot", ")", ";", "pythonResultToTuple", "(", "p_new_value", ",", "slot", ",", "modstate", "->", "cinfos", ",", "modstate", "->", "buffer", ")", ";", "ExecStoreVirtualTuple", "(", "slot", ")", ";", "Py_DECREF", "(", "p_new_value", ")", ";", "Py_DECREF", "(", "p_row_id", ")", ";", "errorCheck", "(", ")", ";", "return", "slot", ";", "}" ]
multicornExecForeignDelete Execute a foreign delete operation This is done by calling the python "delete" method, with the opaque rowid that was supplied.
[ "multicornExecForeignDelete", "Execute", "a", "foreign", "delete", "operation", "This", "is", "done", "by", "calling", "the", "python", "\"", "delete", "\"", "method", "with", "the", "opaque", "rowid", "that", "was", "supplied", "." ]
[]
[ { "param": "estate", "type": "EState" }, { "param": "resultRelInfo", "type": "ResultRelInfo" }, { "param": "slot", "type": "TupleTableSlot" }, { "param": "planSlot", "type": "TupleTableSlot" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "estate", "type": "EState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "resultRelInfo", "type": "ResultRelInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "slot", "type": "TupleTableSlot", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "planSlot", "type": "TupleTableSlot", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornExecForeignUpdate
TupleTableSlot
static TupleTableSlot * multicornExecForeignUpdate(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *fdw_instance = modstate->fdw_instance, *p_row_id, *p_new_value, *p_value = tupleTableSlotToPyObject(slot, modstate->cinfos); bool is_null; ConversionInfo *cinfo = modstate->rowidCinfo; Datum value = ExecGetJunkAttribute(planSlot, modstate->rowidAttno, &is_null); p_row_id = datumToPython(value, cinfo->atttypoid, cinfo); p_new_value = PyObject_CallMethod(fdw_instance, "update", "(O,O)", p_row_id, p_value); errorCheck(); if (p_new_value != NULL && p_new_value != Py_None) { ExecClearTuple(slot); pythonResultToTuple(p_new_value, slot, modstate->cinfos, modstate->buffer); ExecStoreVirtualTuple(slot); } Py_XDECREF(p_new_value); Py_DECREF(p_row_id); errorCheck(); return slot; }
/* * multicornExecForeignUpdate * Execute a foreign update operation * This is done by calling the python "update" method, with the opaque * rowid that was supplied. */
multicornExecForeignUpdate Execute a foreign update operation This is done by calling the python "update" method, with the opaque rowid that was supplied.
[ "multicornExecForeignUpdate", "Execute", "a", "foreign", "update", "operation", "This", "is", "done", "by", "calling", "the", "python", "\"", "update", "\"", "method", "with", "the", "opaque", "rowid", "that", "was", "supplied", "." ]
static TupleTableSlot * multicornExecForeignUpdate(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *fdw_instance = modstate->fdw_instance, *p_row_id, *p_new_value, *p_value = tupleTableSlotToPyObject(slot, modstate->cinfos); bool is_null; ConversionInfo *cinfo = modstate->rowidCinfo; Datum value = ExecGetJunkAttribute(planSlot, modstate->rowidAttno, &is_null); p_row_id = datumToPython(value, cinfo->atttypoid, cinfo); p_new_value = PyObject_CallMethod(fdw_instance, "update", "(O,O)", p_row_id, p_value); errorCheck(); if (p_new_value != NULL && p_new_value != Py_None) { ExecClearTuple(slot); pythonResultToTuple(p_new_value, slot, modstate->cinfos, modstate->buffer); ExecStoreVirtualTuple(slot); } Py_XDECREF(p_new_value); Py_DECREF(p_row_id); errorCheck(); return slot; }
[ "static", "TupleTableSlot", "*", "multicornExecForeignUpdate", "(", "EState", "*", "estate", ",", "ResultRelInfo", "*", "resultRelInfo", ",", "TupleTableSlot", "*", "slot", ",", "TupleTableSlot", "*", "planSlot", ")", "{", "MulticornModifyState", "*", "modstate", "=", "resultRelInfo", "->", "ri_FdwState", ";", "PyObject", "*", "fdw_instance", "=", "modstate", "->", "fdw_instance", ",", "*", "p_row_id", ",", "*", "p_new_value", ",", "*", "p_value", "=", "tupleTableSlotToPyObject", "(", "slot", ",", "modstate", "->", "cinfos", ")", ";", "bool", "is_null", ";", "ConversionInfo", "*", "cinfo", "=", "modstate", "->", "rowidCinfo", ";", "Datum", "value", "=", "ExecGetJunkAttribute", "(", "planSlot", ",", "modstate", "->", "rowidAttno", ",", "&", "is_null", ")", ";", "p_row_id", "=", "datumToPython", "(", "value", ",", "cinfo", "->", "atttypoid", ",", "cinfo", ")", ";", "p_new_value", "=", "PyObject_CallMethod", "(", "fdw_instance", ",", "\"", "\"", ",", "\"", "\"", ",", "p_row_id", ",", "p_value", ")", ";", "errorCheck", "(", ")", ";", "if", "(", "p_new_value", "!=", "NULL", "&&", "p_new_value", "!=", "Py_None", ")", "{", "ExecClearTuple", "(", "slot", ")", ";", "pythonResultToTuple", "(", "p_new_value", ",", "slot", ",", "modstate", "->", "cinfos", ",", "modstate", "->", "buffer", ")", ";", "ExecStoreVirtualTuple", "(", "slot", ")", ";", "}", "Py_XDECREF", "(", "p_new_value", ")", ";", "Py_DECREF", "(", "p_row_id", ")", ";", "errorCheck", "(", ")", ";", "return", "slot", ";", "}" ]
multicornExecForeignUpdate Execute a foreign update operation This is done by calling the python "update" method, with the opaque rowid that was supplied.
[ "multicornExecForeignUpdate", "Execute", "a", "foreign", "update", "operation", "This", "is", "done", "by", "calling", "the", "python", "\"", "update", "\"", "method", "with", "the", "opaque", "rowid", "that", "was", "supplied", "." ]
[]
[ { "param": "estate", "type": "EState" }, { "param": "resultRelInfo", "type": "ResultRelInfo" }, { "param": "slot", "type": "TupleTableSlot" }, { "param": "planSlot", "type": "TupleTableSlot" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "estate", "type": "EState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "resultRelInfo", "type": "ResultRelInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "slot", "type": "TupleTableSlot", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "planSlot", "type": "TupleTableSlot", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicornEndForeignModify
void
static void multicornEndForeignModify(EState *estate, ResultRelInfo *resultRelInfo) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *result = PyObject_CallMethod(modstate->fdw_instance, "end_modify", "()"); errorCheck(); Py_DECREF(modstate->fdw_instance); Py_DECREF(result); }
/* * multicornEndForeignModify * Clean internal state after a modify operation. */
multicornEndForeignModify Clean internal state after a modify operation.
[ "multicornEndForeignModify", "Clean", "internal", "state", "after", "a", "modify", "operation", "." ]
static void multicornEndForeignModify(EState *estate, ResultRelInfo *resultRelInfo) { MulticornModifyState *modstate = resultRelInfo->ri_FdwState; PyObject *result = PyObject_CallMethod(modstate->fdw_instance, "end_modify", "()"); errorCheck(); Py_DECREF(modstate->fdw_instance); Py_DECREF(result); }
[ "static", "void", "multicornEndForeignModify", "(", "EState", "*", "estate", ",", "ResultRelInfo", "*", "resultRelInfo", ")", "{", "MulticornModifyState", "*", "modstate", "=", "resultRelInfo", "->", "ri_FdwState", ";", "PyObject", "*", "result", "=", "PyObject_CallMethod", "(", "modstate", "->", "fdw_instance", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "errorCheck", "(", ")", ";", "Py_DECREF", "(", "modstate", "->", "fdw_instance", ")", ";", "Py_DECREF", "(", "result", ")", ";", "}" ]
multicornEndForeignModify Clean internal state after a modify operation.
[ "multicornEndForeignModify", "Clean", "internal", "state", "after", "a", "modify", "operation", "." ]
[]
[ { "param": "estate", "type": "EState" }, { "param": "resultRelInfo", "type": "ResultRelInfo" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "estate", "type": "EState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "resultRelInfo", "type": "ResultRelInfo", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicorn_subxact_callback
void
static void multicorn_subxact_callback(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg) { PyObject *instance; int curlevel; HASH_SEQ_STATUS status; CacheEntry *entry; /* Nothing to do after commit or subtransaction start. */ if (event == SUBXACT_EVENT_COMMIT_SUB || event == SUBXACT_EVENT_START_SUB) return; curlevel = GetCurrentTransactionNestLevel(); hash_seq_init(&status, InstancesHash); while ((entry = (CacheEntry *) hash_seq_search(&status)) != NULL) { if (entry->xact_depth < curlevel) continue; instance = entry->value; if (event == SUBXACT_EVENT_PRE_COMMIT_SUB) { PyObject_CallMethod(instance, "sub_commit", "(i)", curlevel); } else { PyObject_CallMethod(instance, "sub_rollback", "(i)", curlevel); } errorCheck(); entry->xact_depth--; } }
/* * Callback used to propagate a subtransaction end. */
Callback used to propagate a subtransaction end.
[ "Callback", "used", "to", "propagate", "a", "subtransaction", "end", "." ]
static void multicorn_subxact_callback(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg) { PyObject *instance; int curlevel; HASH_SEQ_STATUS status; CacheEntry *entry; if (event == SUBXACT_EVENT_COMMIT_SUB || event == SUBXACT_EVENT_START_SUB) return; curlevel = GetCurrentTransactionNestLevel(); hash_seq_init(&status, InstancesHash); while ((entry = (CacheEntry *) hash_seq_search(&status)) != NULL) { if (entry->xact_depth < curlevel) continue; instance = entry->value; if (event == SUBXACT_EVENT_PRE_COMMIT_SUB) { PyObject_CallMethod(instance, "sub_commit", "(i)", curlevel); } else { PyObject_CallMethod(instance, "sub_rollback", "(i)", curlevel); } errorCheck(); entry->xact_depth--; } }
[ "static", "void", "multicorn_subxact_callback", "(", "SubXactEvent", "event", ",", "SubTransactionId", "mySubid", ",", "SubTransactionId", "parentSubid", ",", "void", "*", "arg", ")", "{", "PyObject", "*", "instance", ";", "int", "curlevel", ";", "HASH_SEQ_STATUS", "status", ";", "CacheEntry", "*", "entry", ";", "if", "(", "event", "==", "SUBXACT_EVENT_COMMIT_SUB", "||", "event", "==", "SUBXACT_EVENT_START_SUB", ")", "return", ";", "curlevel", "=", "GetCurrentTransactionNestLevel", "(", ")", ";", "hash_seq_init", "(", "&", "status", ",", "InstancesHash", ")", ";", "while", "(", "(", "entry", "=", "(", "CacheEntry", "*", ")", "hash_seq_search", "(", "&", "status", ")", ")", "!=", "NULL", ")", "{", "if", "(", "entry", "->", "xact_depth", "<", "curlevel", ")", "continue", ";", "instance", "=", "entry", "->", "value", ";", "if", "(", "event", "==", "SUBXACT_EVENT_PRE_COMMIT_SUB", ")", "{", "PyObject_CallMethod", "(", "instance", ",", "\"", "\"", ",", "\"", "\"", ",", "curlevel", ")", ";", "}", "else", "{", "PyObject_CallMethod", "(", "instance", ",", "\"", "\"", ",", "\"", "\"", ",", "curlevel", ")", ";", "}", "errorCheck", "(", ")", ";", "entry", "->", "xact_depth", "--", ";", "}", "}" ]
Callback used to propagate a subtransaction end.
[ "Callback", "used", "to", "propagate", "a", "subtransaction", "end", "." ]
[ "/* Nothing to do after commit or subtransaction start. */" ]
[ { "param": "event", "type": "SubXactEvent" }, { "param": "mySubid", "type": "SubTransactionId" }, { "param": "parentSubid", "type": "SubTransactionId" }, { "param": "arg", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "event", "type": "SubXactEvent", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mySubid", "type": "SubTransactionId", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "parentSubid", "type": "SubTransactionId", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
multicorn_xact_callback
void
static void multicorn_xact_callback(XactEvent event, void *arg) { PyObject *instance; HASH_SEQ_STATUS status; CacheEntry *entry; hash_seq_init(&status, InstancesHash); while ((entry = (CacheEntry *) hash_seq_search(&status)) != NULL) { instance = entry->value; if (entry->xact_depth == 0) continue; switch (event) { #if PG_VERSION_NUM >= 90300 case XACT_EVENT_PRE_COMMIT: PyObject_CallMethod(instance, "pre_commit", "()"); break; #endif case XACT_EVENT_COMMIT: PyObject_CallMethod(instance, "commit", "()"); entry->xact_depth = 0; break; case XACT_EVENT_ABORT: PyObject_CallMethod(instance, "rollback", "()"); entry->xact_depth = 0; break; default: break; } errorCheck(); } }
/* * Callback used to propagate pre-commit / commit / rollback. */
Callback used to propagate pre-commit / commit / rollback.
[ "Callback", "used", "to", "propagate", "pre", "-", "commit", "/", "commit", "/", "rollback", "." ]
static void multicorn_xact_callback(XactEvent event, void *arg) { PyObject *instance; HASH_SEQ_STATUS status; CacheEntry *entry; hash_seq_init(&status, InstancesHash); while ((entry = (CacheEntry *) hash_seq_search(&status)) != NULL) { instance = entry->value; if (entry->xact_depth == 0) continue; switch (event) { #if PG_VERSION_NUM >= 90300 case XACT_EVENT_PRE_COMMIT: PyObject_CallMethod(instance, "pre_commit", "()"); break; #endif case XACT_EVENT_COMMIT: PyObject_CallMethod(instance, "commit", "()"); entry->xact_depth = 0; break; case XACT_EVENT_ABORT: PyObject_CallMethod(instance, "rollback", "()"); entry->xact_depth = 0; break; default: break; } errorCheck(); } }
[ "static", "void", "multicorn_xact_callback", "(", "XactEvent", "event", ",", "void", "*", "arg", ")", "{", "PyObject", "*", "instance", ";", "HASH_SEQ_STATUS", "status", ";", "CacheEntry", "*", "entry", ";", "hash_seq_init", "(", "&", "status", ",", "InstancesHash", ")", ";", "while", "(", "(", "entry", "=", "(", "CacheEntry", "*", ")", "hash_seq_search", "(", "&", "status", ")", ")", "!=", "NULL", ")", "{", "instance", "=", "entry", "->", "value", ";", "if", "(", "entry", "->", "xact_depth", "==", "0", ")", "continue", ";", "switch", "(", "event", ")", "{", "#if", "PG_VERSION_NUM", ">=", "90300", "\n", "case", "XACT_EVENT_PRE_COMMIT", ":", "PyObject_CallMethod", "(", "instance", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "break", ";", "#endif", "case", "XACT_EVENT_COMMIT", ":", "PyObject_CallMethod", "(", "instance", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "entry", "->", "xact_depth", "=", "0", ";", "break", ";", "case", "XACT_EVENT_ABORT", ":", "PyObject_CallMethod", "(", "instance", ",", "\"", "\"", ",", "\"", "\"", ")", ";", "entry", "->", "xact_depth", "=", "0", ";", "break", ";", "default", ":", "break", ";", "}", "errorCheck", "(", ")", ";", "}", "}" ]
Callback used to propagate pre-commit / commit / rollback.
[ "Callback", "used", "to", "propagate", "pre", "-", "commit", "/", "commit", "/", "rollback", "." ]
[]
[ { "param": "event", "type": "XactEvent" }, { "param": "arg", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "event", "type": "XactEvent", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "arg", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
serializePlanState
void
void * serializePlanState(MulticornPlanState * state) { List *result = NULL; result = lappend(result, makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum(state->numattrs), false, true)); result = lappend(result, makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum(state->foreigntableid), false, true)); result = lappend(result, state->target_list); result = lappend(result, serializeDeparsedSortGroup(state->pathkeys)); return result; }
/* * "Serialize" a MulticornPlanState, so that it is safe to be carried * between the plan and the execution safe. */
"Serialize" a MulticornPlanState, so that it is safe to be carried between the plan and the execution safe.
[ "\"", "Serialize", "\"", "a", "MulticornPlanState", "so", "that", "it", "is", "safe", "to", "be", "carried", "between", "the", "plan", "and", "the", "execution", "safe", "." ]
void * serializePlanState(MulticornPlanState * state) { List *result = NULL; result = lappend(result, makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum(state->numattrs), false, true)); result = lappend(result, makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum(state->foreigntableid), false, true)); result = lappend(result, state->target_list); result = lappend(result, serializeDeparsedSortGroup(state->pathkeys)); return result; }
[ "void", "*", "serializePlanState", "(", "MulticornPlanState", "*", "state", ")", "{", "List", "*", "result", "=", "NULL", ";", "result", "=", "lappend", "(", "result", ",", "makeConst", "(", "INT4OID", ",", "-1", ",", "InvalidOid", ",", "4", ",", "Int32GetDatum", "(", "state", "->", "numattrs", ")", ",", "false", ",", "true", ")", ")", ";", "result", "=", "lappend", "(", "result", ",", "makeConst", "(", "INT4OID", ",", "-1", ",", "InvalidOid", ",", "4", ",", "Int32GetDatum", "(", "state", "->", "foreigntableid", ")", ",", "false", ",", "true", ")", ")", ";", "result", "=", "lappend", "(", "result", ",", "state", "->", "target_list", ")", ";", "result", "=", "lappend", "(", "result", ",", "serializeDeparsedSortGroup", "(", "state", "->", "pathkeys", ")", ")", ";", "return", "result", ";", "}" ]
"Serialize" a MulticornPlanState, so that it is safe to be carried between the plan and the execution safe.
[ "\"", "Serialize", "\"", "a", "MulticornPlanState", "so", "that", "it", "is", "safe", "to", "be", "carried", "between", "the", "plan", "and", "the", "execution", "safe", "." ]
[]
[ { "param": "state", "type": "MulticornPlanState" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "state", "type": "MulticornPlanState", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
55eb06d5e34d4c1844187d46fa03467bb7b8d470
Kozea/Multicorn
src/multicorn.c
[ "PostgreSQL" ]
C
initializeExecState
MulticornExecState
MulticornExecState * initializeExecState(void *internalstate) { MulticornExecState *execstate = palloc0(sizeof(MulticornExecState)); List *values = (List *) internalstate; AttrNumber attnum = ((Const *) linitial(values))->constvalue; Oid foreigntableid = ((Const *) lsecond(values))->constvalue; List *pathkeys; /* Those list must be copied, because their memory context can become */ /* invalid during the execution (in particular with the cursor interface) */ execstate->target_list = copyObject(lthird(values)); pathkeys = lfourth(values); execstate->pathkeys = deserializeDeparsedSortGroup(pathkeys); execstate->fdw_instance = getInstance(foreigntableid); execstate->buffer = makeStringInfo(); execstate->cinfos = palloc0(sizeof(ConversionInfo *) * attnum); execstate->values = palloc(attnum * sizeof(Datum)); execstate->nulls = palloc(attnum * sizeof(bool)); return execstate; }
/* * "Deserialize" an internal state and inject it in an * MulticornExecState */
"Deserialize" an internal state and inject it in an MulticornExecState
[ "\"", "Deserialize", "\"", "an", "internal", "state", "and", "inject", "it", "in", "an", "MulticornExecState" ]
MulticornExecState * initializeExecState(void *internalstate) { MulticornExecState *execstate = palloc0(sizeof(MulticornExecState)); List *values = (List *) internalstate; AttrNumber attnum = ((Const *) linitial(values))->constvalue; Oid foreigntableid = ((Const *) lsecond(values))->constvalue; List *pathkeys; execstate->target_list = copyObject(lthird(values)); pathkeys = lfourth(values); execstate->pathkeys = deserializeDeparsedSortGroup(pathkeys); execstate->fdw_instance = getInstance(foreigntableid); execstate->buffer = makeStringInfo(); execstate->cinfos = palloc0(sizeof(ConversionInfo *) * attnum); execstate->values = palloc(attnum * sizeof(Datum)); execstate->nulls = palloc(attnum * sizeof(bool)); return execstate; }
[ "MulticornExecState", "*", "initializeExecState", "(", "void", "*", "internalstate", ")", "{", "MulticornExecState", "*", "execstate", "=", "palloc0", "(", "sizeof", "(", "MulticornExecState", ")", ")", ";", "List", "*", "values", "=", "(", "List", "*", ")", "internalstate", ";", "AttrNumber", "attnum", "=", "(", "(", "Const", "*", ")", "linitial", "(", "values", ")", ")", "->", "constvalue", ";", "Oid", "foreigntableid", "=", "(", "(", "Const", "*", ")", "lsecond", "(", "values", ")", ")", "->", "constvalue", ";", "List", "*", "pathkeys", ";", "execstate", "->", "target_list", "=", "copyObject", "(", "lthird", "(", "values", ")", ")", ";", "pathkeys", "=", "lfourth", "(", "values", ")", ";", "execstate", "->", "pathkeys", "=", "deserializeDeparsedSortGroup", "(", "pathkeys", ")", ";", "execstate", "->", "fdw_instance", "=", "getInstance", "(", "foreigntableid", ")", ";", "execstate", "->", "buffer", "=", "makeStringInfo", "(", ")", ";", "execstate", "->", "cinfos", "=", "palloc0", "(", "sizeof", "(", "ConversionInfo", "*", ")", "*", "attnum", ")", ";", "execstate", "->", "values", "=", "palloc", "(", "attnum", "*", "sizeof", "(", "Datum", ")", ")", ";", "execstate", "->", "nulls", "=", "palloc", "(", "attnum", "*", "sizeof", "(", "bool", ")", ")", ";", "return", "execstate", ";", "}" ]
"Deserialize" an internal state and inject it in an MulticornExecState
[ "\"", "Deserialize", "\"", "an", "internal", "state", "and", "inject", "it", "in", "an", "MulticornExecState" ]
[ "/* Those list must be copied, because their memory context can become */", "/* invalid during the execution (in particular with the cursor interface) */" ]
[ { "param": "internalstate", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "internalstate", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bed9d2d81946d227389a2c97ad24d483d96a84c4
robgjansen/shadow
src/main/host/syscall/socket.c
[ "BSD-3-Clause" ]
C
_syscallhandler_readableWhenClosed
bool
static bool _syscallhandler_readableWhenClosed(SysCallHandler* sys, LegacyDescriptor* desc) { if (desc && descriptor_getType(desc) == DT_TCPSOCKET && (descriptor_getStatus(desc) & STATUS_DESCRIPTOR_CLOSED)) { /* Connection error will be -ENOTCONN when reading is done. */ if (tcp_getConnectionError((TCP*)desc) == -EISCONN) { return true; } } return false; }
/* It's valid to read data from a socket even if close() was already called, * as long as the EOF has not yet been read (i.e., there is still data that * must be read from the socket). This function checks if the descriptor is * in this corner case and we should be allowed to read from it. */
It's valid to read data from a socket even if close() was already called, as long as the EOF has not yet been read . This function checks if the descriptor is in this corner case and we should be allowed to read from it.
[ "It", "'", "s", "valid", "to", "read", "data", "from", "a", "socket", "even", "if", "close", "()", "was", "already", "called", "as", "long", "as", "the", "EOF", "has", "not", "yet", "been", "read", ".", "This", "function", "checks", "if", "the", "descriptor", "is", "in", "this", "corner", "case", "and", "we", "should", "be", "allowed", "to", "read", "from", "it", "." ]
static bool _syscallhandler_readableWhenClosed(SysCallHandler* sys, LegacyDescriptor* desc) { if (desc && descriptor_getType(desc) == DT_TCPSOCKET && (descriptor_getStatus(desc) & STATUS_DESCRIPTOR_CLOSED)) { if (tcp_getConnectionError((TCP*)desc) == -EISCONN) { return true; } } return false; }
[ "static", "bool", "_syscallhandler_readableWhenClosed", "(", "SysCallHandler", "*", "sys", ",", "LegacyDescriptor", "*", "desc", ")", "{", "if", "(", "desc", "&&", "descriptor_getType", "(", "desc", ")", "==", "DT_TCPSOCKET", "&&", "(", "descriptor_getStatus", "(", "desc", ")", "&", "STATUS_DESCRIPTOR_CLOSED", ")", ")", "{", "if", "(", "tcp_getConnectionError", "(", "(", "TCP", "*", ")", "desc", ")", "==", "-", "EISCONN", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
It's valid to read data from a socket even if close() was already called, as long as the EOF has not yet been read (i.e., there is still data that must be read from the socket).
[ "It", "'", "s", "valid", "to", "read", "data", "from", "a", "socket", "even", "if", "close", "()", "was", "already", "called", "as", "long", "as", "the", "EOF", "has", "not", "yet", "been", "read", "(", "i", ".", "e", ".", "there", "is", "still", "data", "that", "must", "be", "read", "from", "the", "socket", ")", "." ]
[ "/* Connection error will be -ENOTCONN when reading is done. */" ]
[ { "param": "sys", "type": "SysCallHandler" }, { "param": "desc", "type": "LegacyDescriptor" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sys", "type": "SysCallHandler", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "desc", "type": "LegacyDescriptor", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c44502365cfea7fd7100c75745ded518062ff0a5
okhlif/SVT-AV1
Source/App/EbAppContext.c
[ "BSD-2-Clause-Patent" ]
C
AllocateMemoryTable
void
void AllocateMemoryTable( uint32_t instanceIdx) { // Malloc Memory Table for the instance @ instanceIdx appMemoryMapAllChannels[instanceIdx] = (EbMemoryMapEntry*)malloc(sizeof(EbMemoryMapEntry) * MAX_APP_NUM_PTR); // Init the table index appMemoryMapIndexAllChannels[instanceIdx] = 0; // Size of the table appMemoryMallocdAllChannels[instanceIdx] = sizeof(EbMemoryMapEntry) * MAX_APP_NUM_PTR; totalAppMemory = &appMemoryMallocdAllChannels[instanceIdx]; // Set pointer to the first entry appMemoryMap = appMemoryMapAllChannels[instanceIdx]; // Set index to the first entry appMemoryMapIndex = &appMemoryMapIndexAllChannels[instanceIdx]; // Init Number of pointers appMallocCount = 0; return; }
/*************************************** * Allocation and initializing a memory table * hosting all allocated pointers ***************************************/
Allocation and initializing a memory table hosting all allocated pointers
[ "Allocation", "and", "initializing", "a", "memory", "table", "hosting", "all", "allocated", "pointers" ]
void AllocateMemoryTable( uint32_t instanceIdx) { appMemoryMapAllChannels[instanceIdx] = (EbMemoryMapEntry*)malloc(sizeof(EbMemoryMapEntry) * MAX_APP_NUM_PTR); appMemoryMapIndexAllChannels[instanceIdx] = 0; appMemoryMallocdAllChannels[instanceIdx] = sizeof(EbMemoryMapEntry) * MAX_APP_NUM_PTR; totalAppMemory = &appMemoryMallocdAllChannels[instanceIdx]; appMemoryMap = appMemoryMapAllChannels[instanceIdx]; appMemoryMapIndex = &appMemoryMapIndexAllChannels[instanceIdx]; appMallocCount = 0; return; }
[ "void", "AllocateMemoryTable", "(", "uint32_t", "instanceIdx", ")", "{", "appMemoryMapAllChannels", "[", "instanceIdx", "]", "=", "(", "EbMemoryMapEntry", "*", ")", "malloc", "(", "sizeof", "(", "EbMemoryMapEntry", ")", "*", "MAX_APP_NUM_PTR", ")", ";", "appMemoryMapIndexAllChannels", "[", "instanceIdx", "]", "=", "0", ";", "appMemoryMallocdAllChannels", "[", "instanceIdx", "]", "=", "sizeof", "(", "EbMemoryMapEntry", ")", "*", "MAX_APP_NUM_PTR", ";", "totalAppMemory", "=", "&", "appMemoryMallocdAllChannels", "[", "instanceIdx", "]", ";", "appMemoryMap", "=", "appMemoryMapAllChannels", "[", "instanceIdx", "]", ";", "appMemoryMapIndex", "=", "&", "appMemoryMapIndexAllChannels", "[", "instanceIdx", "]", ";", "appMallocCount", "=", "0", ";", "return", ";", "}" ]
Allocation and initializing a memory table hosting all allocated pointers
[ "Allocation", "and", "initializing", "a", "memory", "table", "hosting", "all", "allocated", "pointers" ]
[ "// Malloc Memory Table for the instance @ instanceIdx", "// Init the table index", "// Size of the table", "// Set pointer to the first entry", "// Set index to the first entry", "// Init Number of pointers" ]
[ { "param": "instanceIdx", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "instanceIdx", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c44502365cfea7fd7100c75745ded518062ff0a5
okhlif/SVT-AV1
Source/App/EbAppContext.c
[ "BSD-2-Clause-Patent" ]
C
CopyConfigurationParameters
EbErrorType
EbErrorType CopyConfigurationParameters( EbConfig_t *config, EbAppContext_t *callbackData, uint32_t instanceIdx) { EbErrorType return_error = EB_ErrorNone; uint32_t hmeRegionIndex; // Assign Instance index to the library callbackData->instanceIdx = (uint8_t)instanceIdx; // Initialize Port Activity Flags callbackData->outputStreamPortActive = APP_PortActive; callbackData->ebEncParameters.source_width = config->sourceWidth; callbackData->ebEncParameters.source_height = config->sourceHeight; callbackData->ebEncParameters.intra_period_length = config->intraPeriod; callbackData->ebEncParameters.intra_refresh_type = config->intraRefreshType; callbackData->ebEncParameters.base_layer_switch_mode = config->base_layer_switch_mode; callbackData->ebEncParameters.enc_mode = (EbBool)config->encMode; callbackData->ebEncParameters.frame_rate = config->frameRate; callbackData->ebEncParameters.frame_rate_denominator = config->frameRateDenominator; callbackData->ebEncParameters.frame_rate_numerator = config->frameRateNumerator; callbackData->ebEncParameters.hierarchical_levels = config->hierarchicalLevels; callbackData->ebEncParameters.pred_structure = (uint8_t)config->predStructure; callbackData->ebEncParameters.in_loop_me_flag = config->in_loop_me_flag; callbackData->ebEncParameters.ext_block_flag = config->ext_block_flag; #if TILES callbackData->ebEncParameters.tile_rows = config->tile_rows; callbackData->ebEncParameters.tile_columns = config->tile_columns; #endif callbackData->ebEncParameters.scene_change_detection = config->scene_change_detection; callbackData->ebEncParameters.look_ahead_distance = config->look_ahead_distance; callbackData->ebEncParameters.frames_to_be_encoded = config->frames_to_be_encoded; callbackData->ebEncParameters.rate_control_mode = config->rateControlMode; callbackData->ebEncParameters.target_bit_rate = config->targetBitRate; callbackData->ebEncParameters.max_qp_allowed = config->max_qp_allowed; callbackData->ebEncParameters.min_qp_allowed = config->min_qp_allowed; callbackData->ebEncParameters.qp = config->qp; callbackData->ebEncParameters.use_qp_file = (EbBool)config->use_qp_file; callbackData->ebEncParameters.disable_dlf_flag = (EbBool)config->disable_dlf_flag; callbackData->ebEncParameters.enable_warped_motion = (EbBool)config->enable_warped_motion; callbackData->ebEncParameters.use_default_me_hme = (EbBool)config->use_default_me_hme; callbackData->ebEncParameters.enable_hme_flag = (EbBool)config->enableHmeFlag; callbackData->ebEncParameters.enable_hme_level0_flag = (EbBool)config->enableHmeLevel0Flag; callbackData->ebEncParameters.enable_hme_level1_flag = (EbBool)config->enableHmeLevel1Flag; callbackData->ebEncParameters.enable_hme_level2_flag = (EbBool)config->enableHmeLevel2Flag; callbackData->ebEncParameters.search_area_width = config->searchAreaWidth; callbackData->ebEncParameters.search_area_height = config->searchAreaHeight; callbackData->ebEncParameters.number_hme_search_region_in_width = config->numberHmeSearchRegionInWidth; callbackData->ebEncParameters.number_hme_search_region_in_height = config->numberHmeSearchRegionInHeight; callbackData->ebEncParameters.hme_level0_total_search_area_width = config->hmeLevel0TotalSearchAreaWidth; callbackData->ebEncParameters.hme_level0_total_search_area_height = config->hmeLevel0TotalSearchAreaHeight; callbackData->ebEncParameters.constrained_intra = (EbBool)config->constrained_intra; callbackData->ebEncParameters.channel_id = config->channel_id; callbackData->ebEncParameters.active_channel_count = config->active_channel_count; callbackData->ebEncParameters.improve_sharpness = (uint8_t)config->improve_sharpness; callbackData->ebEncParameters.high_dynamic_range_input = config->high_dynamic_range_input; callbackData->ebEncParameters.encoder_bit_depth = config->encoderBitDepth; callbackData->ebEncParameters.compressed_ten_bit_format = config->compressedTenBitFormat; callbackData->ebEncParameters.profile = config->profile; callbackData->ebEncParameters.tier = config->tier; callbackData->ebEncParameters.level = config->level; callbackData->ebEncParameters.injector_frame_rate = config->injector_frame_rate; callbackData->ebEncParameters.speed_control_flag = config->speed_control_flag; callbackData->ebEncParameters.asm_type = config->asmType; callbackData->ebEncParameters.logical_processors = config->logicalProcessors; callbackData->ebEncParameters.target_socket = config->targetSocket; callbackData->ebEncParameters.recon_enabled = config->reconFile ? EB_TRUE : EB_FALSE; for (hmeRegionIndex = 0; hmeRegionIndex < callbackData->ebEncParameters.number_hme_search_region_in_width; ++hmeRegionIndex) { callbackData->ebEncParameters.hme_level0_search_area_in_width_array[hmeRegionIndex] = config->hmeLevel0SearchAreaInWidthArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level1_search_area_in_width_array[hmeRegionIndex] = config->hmeLevel1SearchAreaInWidthArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level2_search_area_in_width_array[hmeRegionIndex] = config->hmeLevel2SearchAreaInWidthArray[hmeRegionIndex]; } for (hmeRegionIndex = 0; hmeRegionIndex < callbackData->ebEncParameters.number_hme_search_region_in_height; ++hmeRegionIndex) { callbackData->ebEncParameters.hme_level0_search_area_in_height_array[hmeRegionIndex] = config->hmeLevel0SearchAreaInHeightArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level1_search_area_in_height_array[hmeRegionIndex] = config->hmeLevel1SearchAreaInHeightArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level2_search_area_in_height_array[hmeRegionIndex] = config->hmeLevel2SearchAreaInHeightArray[hmeRegionIndex]; } return return_error; }
/*********************************************** * Copy configuration parameters from * The config structure, to the * callback structure to send to the library ***********************************************/
Copy configuration parameters from The config structure, to the callback structure to send to the library
[ "Copy", "configuration", "parameters", "from", "The", "config", "structure", "to", "the", "callback", "structure", "to", "send", "to", "the", "library" ]
EbErrorType CopyConfigurationParameters( EbConfig_t *config, EbAppContext_t *callbackData, uint32_t instanceIdx) { EbErrorType return_error = EB_ErrorNone; uint32_t hmeRegionIndex; callbackData->instanceIdx = (uint8_t)instanceIdx; callbackData->outputStreamPortActive = APP_PortActive; callbackData->ebEncParameters.source_width = config->sourceWidth; callbackData->ebEncParameters.source_height = config->sourceHeight; callbackData->ebEncParameters.intra_period_length = config->intraPeriod; callbackData->ebEncParameters.intra_refresh_type = config->intraRefreshType; callbackData->ebEncParameters.base_layer_switch_mode = config->base_layer_switch_mode; callbackData->ebEncParameters.enc_mode = (EbBool)config->encMode; callbackData->ebEncParameters.frame_rate = config->frameRate; callbackData->ebEncParameters.frame_rate_denominator = config->frameRateDenominator; callbackData->ebEncParameters.frame_rate_numerator = config->frameRateNumerator; callbackData->ebEncParameters.hierarchical_levels = config->hierarchicalLevels; callbackData->ebEncParameters.pred_structure = (uint8_t)config->predStructure; callbackData->ebEncParameters.in_loop_me_flag = config->in_loop_me_flag; callbackData->ebEncParameters.ext_block_flag = config->ext_block_flag; #if TILES callbackData->ebEncParameters.tile_rows = config->tile_rows; callbackData->ebEncParameters.tile_columns = config->tile_columns; #endif callbackData->ebEncParameters.scene_change_detection = config->scene_change_detection; callbackData->ebEncParameters.look_ahead_distance = config->look_ahead_distance; callbackData->ebEncParameters.frames_to_be_encoded = config->frames_to_be_encoded; callbackData->ebEncParameters.rate_control_mode = config->rateControlMode; callbackData->ebEncParameters.target_bit_rate = config->targetBitRate; callbackData->ebEncParameters.max_qp_allowed = config->max_qp_allowed; callbackData->ebEncParameters.min_qp_allowed = config->min_qp_allowed; callbackData->ebEncParameters.qp = config->qp; callbackData->ebEncParameters.use_qp_file = (EbBool)config->use_qp_file; callbackData->ebEncParameters.disable_dlf_flag = (EbBool)config->disable_dlf_flag; callbackData->ebEncParameters.enable_warped_motion = (EbBool)config->enable_warped_motion; callbackData->ebEncParameters.use_default_me_hme = (EbBool)config->use_default_me_hme; callbackData->ebEncParameters.enable_hme_flag = (EbBool)config->enableHmeFlag; callbackData->ebEncParameters.enable_hme_level0_flag = (EbBool)config->enableHmeLevel0Flag; callbackData->ebEncParameters.enable_hme_level1_flag = (EbBool)config->enableHmeLevel1Flag; callbackData->ebEncParameters.enable_hme_level2_flag = (EbBool)config->enableHmeLevel2Flag; callbackData->ebEncParameters.search_area_width = config->searchAreaWidth; callbackData->ebEncParameters.search_area_height = config->searchAreaHeight; callbackData->ebEncParameters.number_hme_search_region_in_width = config->numberHmeSearchRegionInWidth; callbackData->ebEncParameters.number_hme_search_region_in_height = config->numberHmeSearchRegionInHeight; callbackData->ebEncParameters.hme_level0_total_search_area_width = config->hmeLevel0TotalSearchAreaWidth; callbackData->ebEncParameters.hme_level0_total_search_area_height = config->hmeLevel0TotalSearchAreaHeight; callbackData->ebEncParameters.constrained_intra = (EbBool)config->constrained_intra; callbackData->ebEncParameters.channel_id = config->channel_id; callbackData->ebEncParameters.active_channel_count = config->active_channel_count; callbackData->ebEncParameters.improve_sharpness = (uint8_t)config->improve_sharpness; callbackData->ebEncParameters.high_dynamic_range_input = config->high_dynamic_range_input; callbackData->ebEncParameters.encoder_bit_depth = config->encoderBitDepth; callbackData->ebEncParameters.compressed_ten_bit_format = config->compressedTenBitFormat; callbackData->ebEncParameters.profile = config->profile; callbackData->ebEncParameters.tier = config->tier; callbackData->ebEncParameters.level = config->level; callbackData->ebEncParameters.injector_frame_rate = config->injector_frame_rate; callbackData->ebEncParameters.speed_control_flag = config->speed_control_flag; callbackData->ebEncParameters.asm_type = config->asmType; callbackData->ebEncParameters.logical_processors = config->logicalProcessors; callbackData->ebEncParameters.target_socket = config->targetSocket; callbackData->ebEncParameters.recon_enabled = config->reconFile ? EB_TRUE : EB_FALSE; for (hmeRegionIndex = 0; hmeRegionIndex < callbackData->ebEncParameters.number_hme_search_region_in_width; ++hmeRegionIndex) { callbackData->ebEncParameters.hme_level0_search_area_in_width_array[hmeRegionIndex] = config->hmeLevel0SearchAreaInWidthArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level1_search_area_in_width_array[hmeRegionIndex] = config->hmeLevel1SearchAreaInWidthArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level2_search_area_in_width_array[hmeRegionIndex] = config->hmeLevel2SearchAreaInWidthArray[hmeRegionIndex]; } for (hmeRegionIndex = 0; hmeRegionIndex < callbackData->ebEncParameters.number_hme_search_region_in_height; ++hmeRegionIndex) { callbackData->ebEncParameters.hme_level0_search_area_in_height_array[hmeRegionIndex] = config->hmeLevel0SearchAreaInHeightArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level1_search_area_in_height_array[hmeRegionIndex] = config->hmeLevel1SearchAreaInHeightArray[hmeRegionIndex]; callbackData->ebEncParameters.hme_level2_search_area_in_height_array[hmeRegionIndex] = config->hmeLevel2SearchAreaInHeightArray[hmeRegionIndex]; } return return_error; }
[ "EbErrorType", "CopyConfigurationParameters", "(", "EbConfig_t", "*", "config", ",", "EbAppContext_t", "*", "callbackData", ",", "uint32_t", "instanceIdx", ")", "{", "EbErrorType", "return_error", "=", "EB_ErrorNone", ";", "uint32_t", "hmeRegionIndex", ";", "callbackData", "->", "instanceIdx", "=", "(", "uint8_t", ")", "instanceIdx", ";", "callbackData", "->", "outputStreamPortActive", "=", "APP_PortActive", ";", "callbackData", "->", "ebEncParameters", ".", "source_width", "=", "config", "->", "sourceWidth", ";", "callbackData", "->", "ebEncParameters", ".", "source_height", "=", "config", "->", "sourceHeight", ";", "callbackData", "->", "ebEncParameters", ".", "intra_period_length", "=", "config", "->", "intraPeriod", ";", "callbackData", "->", "ebEncParameters", ".", "intra_refresh_type", "=", "config", "->", "intraRefreshType", ";", "callbackData", "->", "ebEncParameters", ".", "base_layer_switch_mode", "=", "config", "->", "base_layer_switch_mode", ";", "callbackData", "->", "ebEncParameters", ".", "enc_mode", "=", "(", "EbBool", ")", "config", "->", "encMode", ";", "callbackData", "->", "ebEncParameters", ".", "frame_rate", "=", "config", "->", "frameRate", ";", "callbackData", "->", "ebEncParameters", ".", "frame_rate_denominator", "=", "config", "->", "frameRateDenominator", ";", "callbackData", "->", "ebEncParameters", ".", "frame_rate_numerator", "=", "config", "->", "frameRateNumerator", ";", "callbackData", "->", "ebEncParameters", ".", "hierarchical_levels", "=", "config", "->", "hierarchicalLevels", ";", "callbackData", "->", "ebEncParameters", ".", "pred_structure", "=", "(", "uint8_t", ")", "config", "->", "predStructure", ";", "callbackData", "->", "ebEncParameters", ".", "in_loop_me_flag", "=", "config", "->", "in_loop_me_flag", ";", "callbackData", "->", "ebEncParameters", ".", "ext_block_flag", "=", "config", "->", "ext_block_flag", ";", "#if", "TILES", "\n", "callbackData", "->", "ebEncParameters", ".", "tile_rows", "=", "config", "->", "tile_rows", ";", "callbackData", "->", "ebEncParameters", ".", "tile_columns", "=", "config", "->", "tile_columns", ";", "#endif", "callbackData", "->", "ebEncParameters", ".", "scene_change_detection", "=", "config", "->", "scene_change_detection", ";", "callbackData", "->", "ebEncParameters", ".", "look_ahead_distance", "=", "config", "->", "look_ahead_distance", ";", "callbackData", "->", "ebEncParameters", ".", "frames_to_be_encoded", "=", "config", "->", "frames_to_be_encoded", ";", "callbackData", "->", "ebEncParameters", ".", "rate_control_mode", "=", "config", "->", "rateControlMode", ";", "callbackData", "->", "ebEncParameters", ".", "target_bit_rate", "=", "config", "->", "targetBitRate", ";", "callbackData", "->", "ebEncParameters", ".", "max_qp_allowed", "=", "config", "->", "max_qp_allowed", ";", "callbackData", "->", "ebEncParameters", ".", "min_qp_allowed", "=", "config", "->", "min_qp_allowed", ";", "callbackData", "->", "ebEncParameters", ".", "qp", "=", "config", "->", "qp", ";", "callbackData", "->", "ebEncParameters", ".", "use_qp_file", "=", "(", "EbBool", ")", "config", "->", "use_qp_file", ";", "callbackData", "->", "ebEncParameters", ".", "disable_dlf_flag", "=", "(", "EbBool", ")", "config", "->", "disable_dlf_flag", ";", "callbackData", "->", "ebEncParameters", ".", "enable_warped_motion", "=", "(", "EbBool", ")", "config", "->", "enable_warped_motion", ";", "callbackData", "->", "ebEncParameters", ".", "use_default_me_hme", "=", "(", "EbBool", ")", "config", "->", "use_default_me_hme", ";", "callbackData", "->", "ebEncParameters", ".", "enable_hme_flag", "=", "(", "EbBool", ")", "config", "->", "enableHmeFlag", ";", "callbackData", "->", "ebEncParameters", ".", "enable_hme_level0_flag", "=", "(", "EbBool", ")", "config", "->", "enableHmeLevel0Flag", ";", "callbackData", "->", "ebEncParameters", ".", "enable_hme_level1_flag", "=", "(", "EbBool", ")", "config", "->", "enableHmeLevel1Flag", ";", "callbackData", "->", "ebEncParameters", ".", "enable_hme_level2_flag", "=", "(", "EbBool", ")", "config", "->", "enableHmeLevel2Flag", ";", "callbackData", "->", "ebEncParameters", ".", "search_area_width", "=", "config", "->", "searchAreaWidth", ";", "callbackData", "->", "ebEncParameters", ".", "search_area_height", "=", "config", "->", "searchAreaHeight", ";", "callbackData", "->", "ebEncParameters", ".", "number_hme_search_region_in_width", "=", "config", "->", "numberHmeSearchRegionInWidth", ";", "callbackData", "->", "ebEncParameters", ".", "number_hme_search_region_in_height", "=", "config", "->", "numberHmeSearchRegionInHeight", ";", "callbackData", "->", "ebEncParameters", ".", "hme_level0_total_search_area_width", "=", "config", "->", "hmeLevel0TotalSearchAreaWidth", ";", "callbackData", "->", "ebEncParameters", ".", "hme_level0_total_search_area_height", "=", "config", "->", "hmeLevel0TotalSearchAreaHeight", ";", "callbackData", "->", "ebEncParameters", ".", "constrained_intra", "=", "(", "EbBool", ")", "config", "->", "constrained_intra", ";", "callbackData", "->", "ebEncParameters", ".", "channel_id", "=", "config", "->", "channel_id", ";", "callbackData", "->", "ebEncParameters", ".", "active_channel_count", "=", "config", "->", "active_channel_count", ";", "callbackData", "->", "ebEncParameters", ".", "improve_sharpness", "=", "(", "uint8_t", ")", "config", "->", "improve_sharpness", ";", "callbackData", "->", "ebEncParameters", ".", "high_dynamic_range_input", "=", "config", "->", "high_dynamic_range_input", ";", "callbackData", "->", "ebEncParameters", ".", "encoder_bit_depth", "=", "config", "->", "encoderBitDepth", ";", "callbackData", "->", "ebEncParameters", ".", "compressed_ten_bit_format", "=", "config", "->", "compressedTenBitFormat", ";", "callbackData", "->", "ebEncParameters", ".", "profile", "=", "config", "->", "profile", ";", "callbackData", "->", "ebEncParameters", ".", "tier", "=", "config", "->", "tier", ";", "callbackData", "->", "ebEncParameters", ".", "level", "=", "config", "->", "level", ";", "callbackData", "->", "ebEncParameters", ".", "injector_frame_rate", "=", "config", "->", "injector_frame_rate", ";", "callbackData", "->", "ebEncParameters", ".", "speed_control_flag", "=", "config", "->", "speed_control_flag", ";", "callbackData", "->", "ebEncParameters", ".", "asm_type", "=", "config", "->", "asmType", ";", "callbackData", "->", "ebEncParameters", ".", "logical_processors", "=", "config", "->", "logicalProcessors", ";", "callbackData", "->", "ebEncParameters", ".", "target_socket", "=", "config", "->", "targetSocket", ";", "callbackData", "->", "ebEncParameters", ".", "recon_enabled", "=", "config", "->", "reconFile", "?", "EB_TRUE", ":", "EB_FALSE", ";", "for", "(", "hmeRegionIndex", "=", "0", ";", "hmeRegionIndex", "<", "callbackData", "->", "ebEncParameters", ".", "number_hme_search_region_in_width", ";", "++", "hmeRegionIndex", ")", "{", "callbackData", "->", "ebEncParameters", ".", "hme_level0_search_area_in_width_array", "[", "hmeRegionIndex", "]", "=", "config", "->", "hmeLevel0SearchAreaInWidthArray", "[", "hmeRegionIndex", "]", ";", "callbackData", "->", "ebEncParameters", ".", "hme_level1_search_area_in_width_array", "[", "hmeRegionIndex", "]", "=", "config", "->", "hmeLevel1SearchAreaInWidthArray", "[", "hmeRegionIndex", "]", ";", "callbackData", "->", "ebEncParameters", ".", "hme_level2_search_area_in_width_array", "[", "hmeRegionIndex", "]", "=", "config", "->", "hmeLevel2SearchAreaInWidthArray", "[", "hmeRegionIndex", "]", ";", "}", "for", "(", "hmeRegionIndex", "=", "0", ";", "hmeRegionIndex", "<", "callbackData", "->", "ebEncParameters", ".", "number_hme_search_region_in_height", ";", "++", "hmeRegionIndex", ")", "{", "callbackData", "->", "ebEncParameters", ".", "hme_level0_search_area_in_height_array", "[", "hmeRegionIndex", "]", "=", "config", "->", "hmeLevel0SearchAreaInHeightArray", "[", "hmeRegionIndex", "]", ";", "callbackData", "->", "ebEncParameters", ".", "hme_level1_search_area_in_height_array", "[", "hmeRegionIndex", "]", "=", "config", "->", "hmeLevel1SearchAreaInHeightArray", "[", "hmeRegionIndex", "]", ";", "callbackData", "->", "ebEncParameters", ".", "hme_level2_search_area_in_height_array", "[", "hmeRegionIndex", "]", "=", "config", "->", "hmeLevel2SearchAreaInHeightArray", "[", "hmeRegionIndex", "]", ";", "}", "return", "return_error", ";", "}" ]
Copy configuration parameters from The config structure, to the callback structure to send to the library
[ "Copy", "configuration", "parameters", "from", "The", "config", "structure", "to", "the", "callback", "structure", "to", "send", "to", "the", "library" ]
[ "// Assign Instance index to the library", "// Initialize Port Activity Flags" ]
[ { "param": "config", "type": "EbConfig_t" }, { "param": "callbackData", "type": "EbAppContext_t" }, { "param": "instanceIdx", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "config", "type": "EbConfig_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "callbackData", "type": "EbAppContext_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "instanceIdx", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
be9be29e58947cde2933ee81ba69ffdbd5cb9771
aristanetworks/ctypegen
test/PreMockTest.c
[ "Apache-2.0" ]
C
preEntry
void
void preEntry() { int val = 22; preF( 0, "hello world", &val ); assert( val == 24 ); // make sure the actual function is called. }
/* * Testing for the "pre" mock type. preEntry calls preF with *ipval == 22, but * we expect it to run through the python wrapper, which changes *ipval to 42. * Because Clang does IPA between functions (even global functions) in the same * unit, we cannot place preF in this file - it's defined in PreMockTestExtern.c */
Testing for the "pre" mock type. preEntry calls preF with *ipval == 22, but we expect it to run through the python wrapper, which changes *ipval to 42. Because Clang does IPA between functions (even global functions) in the same unit, we cannot place preF in this file - it's defined in PreMockTestExtern.c
[ "Testing", "for", "the", "\"", "pre", "\"", "mock", "type", ".", "preEntry", "calls", "preF", "with", "*", "ipval", "==", "22", "but", "we", "expect", "it", "to", "run", "through", "the", "python", "wrapper", "which", "changes", "*", "ipval", "to", "42", ".", "Because", "Clang", "does", "IPA", "between", "functions", "(", "even", "global", "functions", ")", "in", "the", "same", "unit", "we", "cannot", "place", "preF", "in", "this", "file", "-", "it", "'", "s", "defined", "in", "PreMockTestExtern", ".", "c" ]
void preEntry() { int val = 22; preF( 0, "hello world", &val ); assert( val == 24 ); }
[ "void", "preEntry", "(", ")", "{", "int", "val", "=", "22", ";", "preF", "(", "0", ",", "\"", "\"", ",", "&", "val", ")", ";", "assert", "(", "val", "==", "24", ")", ";", "}" ]
Testing for the "pre" mock type.
[ "Testing", "for", "the", "\"", "pre", "\"", "mock", "type", "." ]
[ "// make sure the actual function is called." ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
39f45d2485215da42c28feb144d08bc05f7aac20
thp/wipeout-pulse-shipedit
src/psp-save/psf.c
[ "Zlib", "MIT" ]
C
find_psf_section
int
int find_psf_section(const char *name, unsigned char *data, int dataLen, unsigned char **location, int *size) { unsigned short int nameLoc; int i, magicHead, strLoc, headLen, numSects; int sectCurLen, sectBufLen, sectBufLoc, curPos; if (dataLen < 0x14) return -1; /* Get the basics from the header */ magicHead = *(unsigned int *)&data[0x00]; strLoc = *(unsigned int *)&data[0x08]; headLen = *(unsigned int *)&data[0x0C]; numSects = *(unsigned int *)&data[0x10]; /* Do some error checking */ if (magicHead != 0x46535000) return -2; /* Verify strLoc is proper */ if ((strLoc > headLen) || (strLoc >= dataLen)) return -3; /* Verify headLen is proper */ if (headLen >= dataLen) return -4; /* Verify numSects is proper */ if (numSects != ((strLoc - 0x14) / 0x10)) return -5; /* Process all sections */ for (i = 0; i < numSects; i++) { /* Get the curPos */ curPos = 0x14 + (i * 0x10); /* Verify curPos is proper */ if (curPos >= strLoc) return -6; /* Get some basic info about this section */ nameLoc = *(unsigned short *)&data[curPos]; sectCurLen = *(unsigned short *)&data[curPos + 0x04]; sectBufLen = *(unsigned short *)&data[curPos + 0x08]; sectBufLoc = *(unsigned short *)&data[curPos + 0x0C]; /* Do some error checking */ if ((nameLoc < dataLen) && (sectCurLen < dataLen) && (sectBufLen < dataLen) && (sectBufLoc < dataLen)) { /* Check if this is the section we want */ if (!strcasecmp((char *)&data[strLoc + nameLoc], name)) { /* Update the location and size */ *location = &data[headLen + sectBufLoc]; *size = sectBufLen; return 0; } } } /* Section was not found if it makes it here */ return -7; }
/* Find to the named section in the PSF file, and return an absolute pointer to it and the section size. */
Find to the named section in the PSF file, and return an absolute pointer to it and the section size.
[ "Find", "to", "the", "named", "section", "in", "the", "PSF", "file", "and", "return", "an", "absolute", "pointer", "to", "it", "and", "the", "section", "size", "." ]
int find_psf_section(const char *name, unsigned char *data, int dataLen, unsigned char **location, int *size) { unsigned short int nameLoc; int i, magicHead, strLoc, headLen, numSects; int sectCurLen, sectBufLen, sectBufLoc, curPos; if (dataLen < 0x14) return -1; magicHead = *(unsigned int *)&data[0x00]; strLoc = *(unsigned int *)&data[0x08]; headLen = *(unsigned int *)&data[0x0C]; numSects = *(unsigned int *)&data[0x10]; if (magicHead != 0x46535000) return -2; if ((strLoc > headLen) || (strLoc >= dataLen)) return -3; if (headLen >= dataLen) return -4; if (numSects != ((strLoc - 0x14) / 0x10)) return -5; for (i = 0; i < numSects; i++) { curPos = 0x14 + (i * 0x10); if (curPos >= strLoc) return -6; nameLoc = *(unsigned short *)&data[curPos]; sectCurLen = *(unsigned short *)&data[curPos + 0x04]; sectBufLen = *(unsigned short *)&data[curPos + 0x08]; sectBufLoc = *(unsigned short *)&data[curPos + 0x0C]; if ((nameLoc < dataLen) && (sectCurLen < dataLen) && (sectBufLen < dataLen) && (sectBufLoc < dataLen)) { if (!strcasecmp((char *)&data[strLoc + nameLoc], name)) { *location = &data[headLen + sectBufLoc]; *size = sectBufLen; return 0; } } } return -7; }
[ "int", "find_psf_section", "(", "const", "char", "*", "name", ",", "unsigned", "char", "*", "data", ",", "int", "dataLen", ",", "unsigned", "char", "*", "*", "location", ",", "int", "*", "size", ")", "{", "unsigned", "short", "int", "nameLoc", ";", "int", "i", ",", "magicHead", ",", "strLoc", ",", "headLen", ",", "numSects", ";", "int", "sectCurLen", ",", "sectBufLen", ",", "sectBufLoc", ",", "curPos", ";", "if", "(", "dataLen", "<", "0x14", ")", "return", "-1", ";", "magicHead", "=", "*", "(", "unsigned", "int", "*", ")", "&", "data", "[", "0x00", "]", ";", "strLoc", "=", "*", "(", "unsigned", "int", "*", ")", "&", "data", "[", "0x08", "]", ";", "headLen", "=", "*", "(", "unsigned", "int", "*", ")", "&", "data", "[", "0x0C", "]", ";", "numSects", "=", "*", "(", "unsigned", "int", "*", ")", "&", "data", "[", "0x10", "]", ";", "if", "(", "magicHead", "!=", "0x46535000", ")", "return", "-2", ";", "if", "(", "(", "strLoc", ">", "headLen", ")", "||", "(", "strLoc", ">=", "dataLen", ")", ")", "return", "-3", ";", "if", "(", "headLen", ">=", "dataLen", ")", "return", "-4", ";", "if", "(", "numSects", "!=", "(", "(", "strLoc", "-", "0x14", ")", "/", "0x10", ")", ")", "return", "-5", ";", "for", "(", "i", "=", "0", ";", "i", "<", "numSects", ";", "i", "++", ")", "{", "curPos", "=", "0x14", "+", "(", "i", "*", "0x10", ")", ";", "if", "(", "curPos", ">=", "strLoc", ")", "return", "-6", ";", "nameLoc", "=", "*", "(", "unsigned", "short", "*", ")", "&", "data", "[", "curPos", "]", ";", "sectCurLen", "=", "*", "(", "unsigned", "short", "*", ")", "&", "data", "[", "curPos", "+", "0x04", "]", ";", "sectBufLen", "=", "*", "(", "unsigned", "short", "*", ")", "&", "data", "[", "curPos", "+", "0x08", "]", ";", "sectBufLoc", "=", "*", "(", "unsigned", "short", "*", ")", "&", "data", "[", "curPos", "+", "0x0C", "]", ";", "if", "(", "(", "nameLoc", "<", "dataLen", ")", "&&", "(", "sectCurLen", "<", "dataLen", ")", "&&", "(", "sectBufLen", "<", "dataLen", ")", "&&", "(", "sectBufLoc", "<", "dataLen", ")", ")", "{", "if", "(", "!", "strcasecmp", "(", "(", "char", "*", ")", "&", "data", "[", "strLoc", "+", "nameLoc", "]", ",", "name", ")", ")", "{", "*", "location", "=", "&", "data", "[", "headLen", "+", "sectBufLoc", "]", ";", "*", "size", "=", "sectBufLen", ";", "return", "0", ";", "}", "}", "}", "return", "-7", ";", "}" ]
Find to the named section in the PSF file, and return an absolute pointer to it and the section size.
[ "Find", "to", "the", "named", "section", "in", "the", "PSF", "file", "and", "return", "an", "absolute", "pointer", "to", "it", "and", "the", "section", "size", "." ]
[ "/* Get the basics from the header */", "/* Do some error checking */", "/* Verify strLoc is proper */", "/* Verify headLen is proper */", "/* Verify numSects is proper */", "/* Process all sections */", "/* Get the curPos */", "/* Verify curPos is proper */", "/* Get some basic info about this section */", "/* Do some error checking */", "/* Check if this is the section we want */", "/* Update the location and size */", "/* Section was not found if it makes it here */" ]
[ { "param": "name", "type": "char" }, { "param": "data", "type": "unsigned char" }, { "param": "dataLen", "type": "int" }, { "param": "location", "type": "unsigned char" }, { "param": "size", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dataLen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "location", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
39f45d2485215da42c28feb144d08bc05f7aac20
thp/wipeout-pulse-shipedit
src/psp-save/psf.c
[ "Zlib", "MIT" ]
C
find_psf_datafile
int
int find_psf_datafile(const char *name, unsigned char *filelist, int size, unsigned char **location) { int i; /* Process all files */ for (i = 0; (i + 0x0d) <= size; i += 0x20) /* Check if this is the filename we want */ if (!strncasecmp((char *)&filelist[i], name, 0x0d)) { *location = &filelist[i]; return 0; } /* File was not found if it makes it here */ return -1; }
/* Find the named file inside the FILE_LIST, and return an absolute pointer to it. */
Find the named file inside the FILE_LIST, and return an absolute pointer to it.
[ "Find", "the", "named", "file", "inside", "the", "FILE_LIST", "and", "return", "an", "absolute", "pointer", "to", "it", "." ]
int find_psf_datafile(const char *name, unsigned char *filelist, int size, unsigned char **location) { int i; for (i = 0; (i + 0x0d) <= size; i += 0x20) if (!strncasecmp((char *)&filelist[i], name, 0x0d)) { *location = &filelist[i]; return 0; } return -1; }
[ "int", "find_psf_datafile", "(", "const", "char", "*", "name", ",", "unsigned", "char", "*", "filelist", ",", "int", "size", ",", "unsigned", "char", "*", "*", "location", ")", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "(", "i", "+", "0x0d", ")", "<=", "size", ";", "i", "+=", "0x20", ")", "if", "(", "!", "strncasecmp", "(", "(", "char", "*", ")", "&", "filelist", "[", "i", "]", ",", "name", ",", "0x0d", ")", ")", "{", "*", "location", "=", "&", "filelist", "[", "i", "]", ";", "return", "0", ";", "}", "return", "-1", ";", "}" ]
Find the named file inside the FILE_LIST, and return an absolute pointer to it.
[ "Find", "the", "named", "file", "inside", "the", "FILE_LIST", "and", "return", "an", "absolute", "pointer", "to", "it", "." ]
[ "/* Process all files */", "/* Check if this is the filename we want */", "/* File was not found if it makes it here */" ]
[ { "param": "name", "type": "char" }, { "param": "filelist", "type": "unsigned char" }, { "param": "size", "type": "int" }, { "param": "location", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "filelist", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "location", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bce74f18c3c8887a68dfba137d2fbb2840361382
thp/wipeout-pulse-shipedit
src/psp-save/psp-save.c
[ "Zlib", "MIT" ]
C
decrypt_data
int
int decrypt_data(unsigned int mode, unsigned char *data, int *data_len, int *aligned_len, unsigned char *key) { pspChnnlsvContext1 ctx1; pspChnnlsvContext2 ctx2; /* Need a 16-byte IV plus some data */ if (*aligned_len <= 0x10) return -1; *data_len -= 0x10; *aligned_len -= 0x10; /* Set up buffers */ memset(&ctx1, 0, sizeof(ctx1)); memset(&ctx2, 0, sizeof(ctx2)); /* Perform the magic */ if (sceSdSetIndex_(&ctx1, mode) < 0) return -2; if (sceSdCreateList_(&ctx2, mode, 2, data, key) < 0) return -3; if (sceSdRemoveValue_(&ctx1, data, 0x10) < 0) return -4; if (sceSdRemoveValue_(&ctx1, data + 0x10, *aligned_len) < 0) return -5; if (sceSdSetMember_(&ctx2, data + 0x10, *aligned_len) < 0) return -6; /* Verify that it decrypted correctly */ if (sceChnnlsv_21BE78B4_(&ctx2) < 0) return -7; /* The decrypted data starts at data + 0x10, so shift it back. */ memmove(data, data + 0x10, *data_len); return 0; }
/* Do the actual hardware decryption. mode is 3 for saves with a cryptkey, or 1 otherwise data, dataLen, and cryptkey must be multiples of 0x10. cryptkey is NULL if mode == 1. */
Do the actual hardware decryption. mode is 3 for saves with a cryptkey, or 1 otherwise data, dataLen, and cryptkey must be multiples of 0x10. cryptkey is NULL if mode == 1.
[ "Do", "the", "actual", "hardware", "decryption", ".", "mode", "is", "3", "for", "saves", "with", "a", "cryptkey", "or", "1", "otherwise", "data", "dataLen", "and", "cryptkey", "must", "be", "multiples", "of", "0x10", ".", "cryptkey", "is", "NULL", "if", "mode", "==", "1", "." ]
int decrypt_data(unsigned int mode, unsigned char *data, int *data_len, int *aligned_len, unsigned char *key) { pspChnnlsvContext1 ctx1; pspChnnlsvContext2 ctx2; if (*aligned_len <= 0x10) return -1; *data_len -= 0x10; *aligned_len -= 0x10; memset(&ctx1, 0, sizeof(ctx1)); memset(&ctx2, 0, sizeof(ctx2)); if (sceSdSetIndex_(&ctx1, mode) < 0) return -2; if (sceSdCreateList_(&ctx2, mode, 2, data, key) < 0) return -3; if (sceSdRemoveValue_(&ctx1, data, 0x10) < 0) return -4; if (sceSdRemoveValue_(&ctx1, data + 0x10, *aligned_len) < 0) return -5; if (sceSdSetMember_(&ctx2, data + 0x10, *aligned_len) < 0) return -6; if (sceChnnlsv_21BE78B4_(&ctx2) < 0) return -7; memmove(data, data + 0x10, *data_len); return 0; }
[ "int", "decrypt_data", "(", "unsigned", "int", "mode", ",", "unsigned", "char", "*", "data", ",", "int", "*", "data_len", ",", "int", "*", "aligned_len", ",", "unsigned", "char", "*", "key", ")", "{", "pspChnnlsvContext1", "ctx1", ";", "pspChnnlsvContext2", "ctx2", ";", "if", "(", "*", "aligned_len", "<=", "0x10", ")", "return", "-1", ";", "*", "data_len", "-=", "0x10", ";", "*", "aligned_len", "-=", "0x10", ";", "memset", "(", "&", "ctx1", ",", "0", ",", "sizeof", "(", "ctx1", ")", ")", ";", "memset", "(", "&", "ctx2", ",", "0", ",", "sizeof", "(", "ctx2", ")", ")", ";", "if", "(", "sceSdSetIndex_", "(", "&", "ctx1", ",", "mode", ")", "<", "0", ")", "return", "-2", ";", "if", "(", "sceSdCreateList_", "(", "&", "ctx2", ",", "mode", ",", "2", ",", "data", ",", "key", ")", "<", "0", ")", "return", "-3", ";", "if", "(", "sceSdRemoveValue_", "(", "&", "ctx1", ",", "data", ",", "0x10", ")", "<", "0", ")", "return", "-4", ";", "if", "(", "sceSdRemoveValue_", "(", "&", "ctx1", ",", "data", "+", "0x10", ",", "*", "aligned_len", ")", "<", "0", ")", "return", "-5", ";", "if", "(", "sceSdSetMember_", "(", "&", "ctx2", ",", "data", "+", "0x10", ",", "*", "aligned_len", ")", "<", "0", ")", "return", "-6", ";", "if", "(", "sceChnnlsv_21BE78B4_", "(", "&", "ctx2", ")", "<", "0", ")", "return", "-7", ";", "memmove", "(", "data", ",", "data", "+", "0x10", ",", "*", "data_len", ")", ";", "return", "0", ";", "}" ]
Do the actual hardware decryption.
[ "Do", "the", "actual", "hardware", "decryption", "." ]
[ "/* Need a 16-byte IV plus some data */", "/* Set up buffers */", "/* Perform the magic */", "/* Verify that it decrypted correctly */", "/* The decrypted data starts at data + 0x10, so shift it back. */" ]
[ { "param": "mode", "type": "unsigned int" }, { "param": "data", "type": "unsigned char" }, { "param": "data_len", "type": "int" }, { "param": "aligned_len", "type": "int" }, { "param": "key", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mode", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data_len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "aligned_len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bce74f18c3c8887a68dfba137d2fbb2840361382
thp/wipeout-pulse-shipedit
src/psp-save/psp-save.c
[ "Zlib", "MIT" ]
C
encrypt_data
int
int encrypt_data(unsigned int mode, unsigned char *data, int *dataLen, int *alignedLen, unsigned char *hash, unsigned char *cryptkey) { pspChnnlsvContext1 ctx1; pspChnnlsvContext2 ctx2; /* Make room for the IV in front of the data. */ memmove(data + 0x10, data, *alignedLen); /* Set up buffers */ memset(&ctx1, 0, sizeof(ctx1)); memset(&ctx2, 0, sizeof(ctx2)); memset(hash, 0, 0x10); memset(data, 0, 0x10); /* Build the 0x10-byte IV and setup encryption */ if (sceSdCreateList_(&ctx2, mode, 1, data, cryptkey) < 0) return -1; if (sceSdSetIndex_(&ctx1, mode) < 0) return -2; if (sceSdRemoveValue_(&ctx1, data, 0x10) < 0) return -3; if (sceSdSetMember_(&ctx2, data + 0x10, *alignedLen) < 0) return -4; /* Clear any extra bytes left from the previous steps */ memset(data + 0x10 + *dataLen, 0, *alignedLen - *dataLen); /* Encrypt the data */ if (sceSdRemoveValue_(&ctx1, data + 0x10, *alignedLen) < 0) return -5; /* Verify encryption */ if (sceChnnlsv_21BE78B4_(&ctx2) < 0) return -6; /* Build the file hash from this PSP */ if (sceSdGetLastIndex_(&ctx1, hash, cryptkey) < 0) return -7; /* Adjust sizes to account for IV */ *alignedLen += 0x10; *dataLen += 0x10; /* All done */ return 0; }
/* Do the actual hardware encryption. mode is 3 for saves with a cryptkey, or 1 otherwise data, dataLen, and cryptkey must be multiples of 0x10. cryptkey is NULL if mode == 1. */
Do the actual hardware encryption. mode is 3 for saves with a cryptkey, or 1 otherwise data, dataLen, and cryptkey must be multiples of 0x10. cryptkey is NULL if mode == 1.
[ "Do", "the", "actual", "hardware", "encryption", ".", "mode", "is", "3", "for", "saves", "with", "a", "cryptkey", "or", "1", "otherwise", "data", "dataLen", "and", "cryptkey", "must", "be", "multiples", "of", "0x10", ".", "cryptkey", "is", "NULL", "if", "mode", "==", "1", "." ]
int encrypt_data(unsigned int mode, unsigned char *data, int *dataLen, int *alignedLen, unsigned char *hash, unsigned char *cryptkey) { pspChnnlsvContext1 ctx1; pspChnnlsvContext2 ctx2; memmove(data + 0x10, data, *alignedLen); memset(&ctx1, 0, sizeof(ctx1)); memset(&ctx2, 0, sizeof(ctx2)); memset(hash, 0, 0x10); memset(data, 0, 0x10); if (sceSdCreateList_(&ctx2, mode, 1, data, cryptkey) < 0) return -1; if (sceSdSetIndex_(&ctx1, mode) < 0) return -2; if (sceSdRemoveValue_(&ctx1, data, 0x10) < 0) return -3; if (sceSdSetMember_(&ctx2, data + 0x10, *alignedLen) < 0) return -4; memset(data + 0x10 + *dataLen, 0, *alignedLen - *dataLen); if (sceSdRemoveValue_(&ctx1, data + 0x10, *alignedLen) < 0) return -5; if (sceChnnlsv_21BE78B4_(&ctx2) < 0) return -6; if (sceSdGetLastIndex_(&ctx1, hash, cryptkey) < 0) return -7; *alignedLen += 0x10; *dataLen += 0x10; return 0; }
[ "int", "encrypt_data", "(", "unsigned", "int", "mode", ",", "unsigned", "char", "*", "data", ",", "int", "*", "dataLen", ",", "int", "*", "alignedLen", ",", "unsigned", "char", "*", "hash", ",", "unsigned", "char", "*", "cryptkey", ")", "{", "pspChnnlsvContext1", "ctx1", ";", "pspChnnlsvContext2", "ctx2", ";", "memmove", "(", "data", "+", "0x10", ",", "data", ",", "*", "alignedLen", ")", ";", "memset", "(", "&", "ctx1", ",", "0", ",", "sizeof", "(", "ctx1", ")", ")", ";", "memset", "(", "&", "ctx2", ",", "0", ",", "sizeof", "(", "ctx2", ")", ")", ";", "memset", "(", "hash", ",", "0", ",", "0x10", ")", ";", "memset", "(", "data", ",", "0", ",", "0x10", ")", ";", "if", "(", "sceSdCreateList_", "(", "&", "ctx2", ",", "mode", ",", "1", ",", "data", ",", "cryptkey", ")", "<", "0", ")", "return", "-1", ";", "if", "(", "sceSdSetIndex_", "(", "&", "ctx1", ",", "mode", ")", "<", "0", ")", "return", "-2", ";", "if", "(", "sceSdRemoveValue_", "(", "&", "ctx1", ",", "data", ",", "0x10", ")", "<", "0", ")", "return", "-3", ";", "if", "(", "sceSdSetMember_", "(", "&", "ctx2", ",", "data", "+", "0x10", ",", "*", "alignedLen", ")", "<", "0", ")", "return", "-4", ";", "memset", "(", "data", "+", "0x10", "+", "*", "dataLen", ",", "0", ",", "*", "alignedLen", "-", "*", "dataLen", ")", ";", "if", "(", "sceSdRemoveValue_", "(", "&", "ctx1", ",", "data", "+", "0x10", ",", "*", "alignedLen", ")", "<", "0", ")", "return", "-5", ";", "if", "(", "sceChnnlsv_21BE78B4_", "(", "&", "ctx2", ")", "<", "0", ")", "return", "-6", ";", "if", "(", "sceSdGetLastIndex_", "(", "&", "ctx1", ",", "hash", ",", "cryptkey", ")", "<", "0", ")", "return", "-7", ";", "*", "alignedLen", "+=", "0x10", ";", "*", "dataLen", "+=", "0x10", ";", "return", "0", ";", "}" ]
Do the actual hardware encryption.
[ "Do", "the", "actual", "hardware", "encryption", "." ]
[ "/* Make room for the IV in front of the data. */", "/* Set up buffers */", "/* Build the 0x10-byte IV and setup encryption */", "/* Clear any extra bytes left from the previous steps */", "/* Encrypt the data */", "/* Verify encryption */", "/* Build the file hash from this PSP */", "/* Adjust sizes to account for IV */", "/* All done */" ]
[ { "param": "mode", "type": "unsigned int" }, { "param": "data", "type": "unsigned char" }, { "param": "dataLen", "type": "int" }, { "param": "alignedLen", "type": "int" }, { "param": "hash", "type": "unsigned char" }, { "param": "cryptkey", "type": "unsigned char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mode", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dataLen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "alignedLen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hash", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cryptkey", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a98b2050ecb0a12a9cb4565df29375ca44a09b17
thp/wipeout-pulse-shipedit
src/psp-save/chnnlsv.c
[ "Zlib", "MIT" ]
C
numFromMode
int
static int numFromMode(int mode) { int num = 0; switch (mode) { case 1: num = 3; break; case 2: num = 5; break; case 3: num = 12; break; case 4: num = 13; break; case 6: num = 17; break; default: num = 16; break; } return num; }
/* The reason for the values from *FromMode calculations are not known. */
The reason for the values from *FromMode calculations are not known.
[ "The", "reason", "for", "the", "values", "from", "*", "FromMode", "calculations", "are", "not", "known", "." ]
static int numFromMode(int mode) { int num = 0; switch (mode) { case 1: num = 3; break; case 2: num = 5; break; case 3: num = 12; break; case 4: num = 13; break; case 6: num = 17; break; default: num = 16; break; } return num; }
[ "static", "int", "numFromMode", "(", "int", "mode", ")", "{", "int", "num", "=", "0", ";", "switch", "(", "mode", ")", "{", "case", "1", ":", "num", "=", "3", ";", "break", ";", "case", "2", ":", "num", "=", "5", ";", "break", ";", "case", "3", ":", "num", "=", "12", ";", "break", ";", "case", "4", ":", "num", "=", "13", ";", "break", ";", "case", "6", ":", "num", "=", "17", ";", "break", ";", "default", ":", "num", "=", "16", ";", "break", ";", "}", "return", "num", ";", "}" ]
The reason for the values from *FromMode calculations are not known.
[ "The", "reason", "for", "the", "values", "from", "*", "FromMode", "calculations", "are", "not", "known", "." ]
[]
[ { "param": "mode", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mode", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
846f90f44bbaddc1c3199ae25c0c9674c4466297
thp/wipeout-pulse-shipedit
src/shipedit.c
[ "Zlib", "MIT" ]
C
xtea8
void
static void xtea8(uint32_t *genkey, const uint32_t *key) { uint32_t v0 = genkey[0]; uint32_t v1 = genkey[1]; const uint32_t k = 0x9e3779b9; const uint32_t num_rounds = 8; uint32_t sum = 0; for (uint32_t i=0; i<num_rounds; ++i) { v0 += (((v1 << 4 ^ v1 >> 5) + v1) ^ (key[sum&3] + sum)); sum += k; v1 += (((v0 << 4 ^ v0 >> 5) + v0) ^ (key[(sum>>11)&3] + sum)); } genkey[0] = v0; genkey[1] = v1; }
/** * This is simply 8-round XTEA encryption. * * See also: * https://en.wikipedia.org/wiki/XTEA * https://cryptography.fandom.com/wiki/XTEA **/
This is simply 8-round XTEA encryption.
[ "This", "is", "simply", "8", "-", "round", "XTEA", "encryption", "." ]
static void xtea8(uint32_t *genkey, const uint32_t *key) { uint32_t v0 = genkey[0]; uint32_t v1 = genkey[1]; const uint32_t k = 0x9e3779b9; const uint32_t num_rounds = 8; uint32_t sum = 0; for (uint32_t i=0; i<num_rounds; ++i) { v0 += (((v1 << 4 ^ v1 >> 5) + v1) ^ (key[sum&3] + sum)); sum += k; v1 += (((v0 << 4 ^ v0 >> 5) + v0) ^ (key[(sum>>11)&3] + sum)); } genkey[0] = v0; genkey[1] = v1; }
[ "static", "void", "xtea8", "(", "uint32_t", "*", "genkey", ",", "const", "uint32_t", "*", "key", ")", "{", "uint32_t", "v0", "=", "genkey", "[", "0", "]", ";", "uint32_t", "v1", "=", "genkey", "[", "1", "]", ";", "const", "uint32_t", "k", "=", "0x9e3779b9", ";", "const", "uint32_t", "num_rounds", "=", "8", ";", "uint32_t", "sum", "=", "0", ";", "for", "(", "uint32_t", "i", "=", "0", ";", "i", "<", "num_rounds", ";", "++", "i", ")", "{", "v0", "+=", "(", "(", "(", "v1", "<<", "4", "^", "v1", ">>", "5", ")", "+", "v1", ")", "^", "(", "key", "[", "sum", "&", "3", "]", "+", "sum", ")", ")", ";", "sum", "+=", "k", ";", "v1", "+=", "(", "(", "(", "v0", "<<", "4", "^", "v0", ">>", "5", ")", "+", "v0", ")", "^", "(", "key", "[", "(", "sum", ">>", "11", ")", "&", "3", "]", "+", "sum", ")", ")", ";", "}", "genkey", "[", "0", "]", "=", "v0", ";", "genkey", "[", "1", "]", "=", "v1", ";", "}" ]
This is simply 8-round XTEA encryption.
[ "This", "is", "simply", "8", "-", "round", "XTEA", "encryption", "." ]
[]
[ { "param": "genkey", "type": "uint32_t" }, { "param": "key", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "genkey", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "key", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bfdd86bcc4fdc7b2a26b28e28613fb85c31f182f
thp/wipeout-pulse-shipedit
src/libkirk/ec.c
[ "Zlib", "MIT" ]
C
generate_ecdsa
void
static void generate_ecdsa(u8 *outR, u8 *outS, u8 *k, u8 *hash) { u8 e[21]; u8 kk[21]; u8 m[21]; u8 R[21]; u8 S[21]; u8 minv[21]; struct point mG; e[0] = 0;R[0] = 0;S[0] = 0; memcpy(e + 1, hash, 20); bn_reduce(e, ec_N, 21); // Original removed for portability //try_again: //fp = fopen("/dev/random", "rb"); //if (fread(m, sizeof m, 1, fp) != 1) //fail("reading random"); //fclose(fp); //m[0] = 0; //if (bn_compare(m, ec_N, 21) >= 0) //goto try_again; // R = (mG).x // Added call back to kirk PRNG - July 2011 kirk_CMD14(m+1, 20); m[0] = 0; point_mul(&mG, m, &ec_G); point_from_mon(&mG); R[0] = 0; elt_copy(R+1, mG.x); // S = m**-1*(e + Rk) (mod N) bn_copy(kk, k, 21); bn_reduce(kk, ec_N, 21); bn_to_mon(m, ec_N, 21); bn_to_mon(e, ec_N, 21); bn_to_mon(R, ec_N, 21); bn_to_mon(kk, ec_N, 21); bn_mon_mul(S, R, kk, ec_N, 21); bn_add(kk, S, e, ec_N, 21); bn_mon_inv(minv, m, ec_N, 21); bn_mon_mul(S, minv, kk, ec_N, 21); bn_from_mon(R, ec_N, 21); bn_from_mon(S, ec_N, 21); memcpy(outR,R+1,20); memcpy(outS,S+1,20); }
// Modified from original to support kirk engine use - July 2011 // Added call to Kirk Random number generator rather than /dev/random
Modified from original to support kirk engine use - July 2011 Added call to Kirk Random number generator rather than /dev/random
[ "Modified", "from", "original", "to", "support", "kirk", "engine", "use", "-", "July", "2011", "Added", "call", "to", "Kirk", "Random", "number", "generator", "rather", "than", "/", "dev", "/", "random" ]
static void generate_ecdsa(u8 *outR, u8 *outS, u8 *k, u8 *hash) { u8 e[21]; u8 kk[21]; u8 m[21]; u8 R[21]; u8 S[21]; u8 minv[21]; struct point mG; e[0] = 0;R[0] = 0;S[0] = 0; memcpy(e + 1, hash, 20); bn_reduce(e, ec_N, 21); kirk_CMD14(m+1, 20); m[0] = 0; point_mul(&mG, m, &ec_G); point_from_mon(&mG); R[0] = 0; elt_copy(R+1, mG.x); bn_copy(kk, k, 21); bn_reduce(kk, ec_N, 21); bn_to_mon(m, ec_N, 21); bn_to_mon(e, ec_N, 21); bn_to_mon(R, ec_N, 21); bn_to_mon(kk, ec_N, 21); bn_mon_mul(S, R, kk, ec_N, 21); bn_add(kk, S, e, ec_N, 21); bn_mon_inv(minv, m, ec_N, 21); bn_mon_mul(S, minv, kk, ec_N, 21); bn_from_mon(R, ec_N, 21); bn_from_mon(S, ec_N, 21); memcpy(outR,R+1,20); memcpy(outS,S+1,20); }
[ "static", "void", "generate_ecdsa", "(", "u8", "*", "outR", ",", "u8", "*", "outS", ",", "u8", "*", "k", ",", "u8", "*", "hash", ")", "{", "u8", "e", "[", "21", "]", ";", "u8", "kk", "[", "21", "]", ";", "u8", "m", "[", "21", "]", ";", "u8", "R", "[", "21", "]", ";", "u8", "S", "[", "21", "]", ";", "u8", "minv", "[", "21", "]", ";", "struct", "point", "mG", ";", "e", "[", "0", "]", "=", "0", ";", "R", "[", "0", "]", "=", "0", ";", "S", "[", "0", "]", "=", "0", ";", "memcpy", "(", "e", "+", "1", ",", "hash", ",", "20", ")", ";", "bn_reduce", "(", "e", ",", "ec_N", ",", "21", ")", ";", "kirk_CMD14", "(", "m", "+", "1", ",", "20", ")", ";", "m", "[", "0", "]", "=", "0", ";", "point_mul", "(", "&", "mG", ",", "m", ",", "&", "ec_G", ")", ";", "point_from_mon", "(", "&", "mG", ")", ";", "R", "[", "0", "]", "=", "0", ";", "elt_copy", "(", "R", "+", "1", ",", "mG", ".", "x", ")", ";", "bn_copy", "(", "kk", ",", "k", ",", "21", ")", ";", "bn_reduce", "(", "kk", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "m", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "e", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "R", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "kk", ",", "ec_N", ",", "21", ")", ";", "bn_mon_mul", "(", "S", ",", "R", ",", "kk", ",", "ec_N", ",", "21", ")", ";", "bn_add", "(", "kk", ",", "S", ",", "e", ",", "ec_N", ",", "21", ")", ";", "bn_mon_inv", "(", "minv", ",", "m", ",", "ec_N", ",", "21", ")", ";", "bn_mon_mul", "(", "S", ",", "minv", ",", "kk", ",", "ec_N", ",", "21", ")", ";", "bn_from_mon", "(", "R", ",", "ec_N", ",", "21", ")", ";", "bn_from_mon", "(", "S", ",", "ec_N", ",", "21", ")", ";", "memcpy", "(", "outR", ",", "R", "+", "1", ",", "20", ")", ";", "memcpy", "(", "outS", ",", "S", "+", "1", ",", "20", ")", ";", "}" ]
Modified from original to support kirk engine use - July 2011 Added call to Kirk Random number generator rather than /dev/random
[ "Modified", "from", "original", "to", "support", "kirk", "engine", "use", "-", "July", "2011", "Added", "call", "to", "Kirk", "Random", "number", "generator", "rather", "than", "/", "dev", "/", "random" ]
[ "// Original removed for portability", "//try_again:", "//fp = fopen(\"/dev/random\", \"rb\");", "//if (fread(m, sizeof m, 1, fp) != 1)", "//fail(\"reading random\");", "//fclose(fp);", "//m[0] = 0;", "//if (bn_compare(m, ec_N, 21) >= 0)", "//goto try_again;", "// R = (mG).x", "// Added call back to kirk PRNG - July 2011", "// S = m**-1*(e + Rk) (mod N)" ]
[ { "param": "outR", "type": "u8" }, { "param": "outS", "type": "u8" }, { "param": "k", "type": "u8" }, { "param": "hash", "type": "u8" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "outR", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "outS", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "k", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hash", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bfdd86bcc4fdc7b2a26b28e28613fb85c31f182f
thp/wipeout-pulse-shipedit
src/libkirk/ec.c
[ "Zlib", "MIT" ]
C
check_ecdsa
int
static int check_ecdsa(struct point *Q, u8 *inR, u8 *inS, u8 *hash) { u8 Sinv[21]; u8 e[21], R[21], S[21]; u8 w1[21], w2[21]; struct point r1, r2; u8 rr[21]; e[0] = 0; memcpy(e + 1, hash, 20); bn_reduce(e, ec_N, 21); R[0] = 0; memcpy(R + 1, inR, 20); bn_reduce(R, ec_N, 21); S[0] = 0; memcpy(S + 1, inS, 20); bn_reduce(S, ec_N, 21); bn_to_mon(R, ec_N, 21); bn_to_mon(S, ec_N, 21); bn_to_mon(e, ec_N, 21); // make Sinv = 1/S bn_mon_inv(Sinv, S, ec_N, 21); // w1 = m * Sinv bn_mon_mul(w1, e, Sinv, ec_N, 21); // w2 = r * Sinv bn_mon_mul(w2, R, Sinv, ec_N, 21); // mod N both bn_from_mon(w1, ec_N, 21); bn_from_mon(w2, ec_N, 21); // r1 = m/s * G point_mul(&r1, w1, &ec_G); // r2 = r/s * P point_mul(&r2, w2, Q); //r1 = r1 + r2 point_add(&r1, &r1, &r2); point_from_mon(&r1); rr[0] = 0; memcpy(rr + 1, r1.x, 20); bn_reduce(rr, ec_N, 21); bn_from_mon(R, ec_N, 21); bn_from_mon(S, ec_N, 21); return (bn_compare(rr, R, 21) == 0); }
// Slightly modified to support kirk compatible signature input - July 2011
Slightly modified to support kirk compatible signature input - July 2011
[ "Slightly", "modified", "to", "support", "kirk", "compatible", "signature", "input", "-", "July", "2011" ]
static int check_ecdsa(struct point *Q, u8 *inR, u8 *inS, u8 *hash) { u8 Sinv[21]; u8 e[21], R[21], S[21]; u8 w1[21], w2[21]; struct point r1, r2; u8 rr[21]; e[0] = 0; memcpy(e + 1, hash, 20); bn_reduce(e, ec_N, 21); R[0] = 0; memcpy(R + 1, inR, 20); bn_reduce(R, ec_N, 21); S[0] = 0; memcpy(S + 1, inS, 20); bn_reduce(S, ec_N, 21); bn_to_mon(R, ec_N, 21); bn_to_mon(S, ec_N, 21); bn_to_mon(e, ec_N, 21); bn_mon_inv(Sinv, S, ec_N, 21); bn_mon_mul(w1, e, Sinv, ec_N, 21); bn_mon_mul(w2, R, Sinv, ec_N, 21); bn_from_mon(w1, ec_N, 21); bn_from_mon(w2, ec_N, 21); point_mul(&r1, w1, &ec_G); point_mul(&r2, w2, Q); point_add(&r1, &r1, &r2); point_from_mon(&r1); rr[0] = 0; memcpy(rr + 1, r1.x, 20); bn_reduce(rr, ec_N, 21); bn_from_mon(R, ec_N, 21); bn_from_mon(S, ec_N, 21); return (bn_compare(rr, R, 21) == 0); }
[ "static", "int", "check_ecdsa", "(", "struct", "point", "*", "Q", ",", "u8", "*", "inR", ",", "u8", "*", "inS", ",", "u8", "*", "hash", ")", "{", "u8", "Sinv", "[", "21", "]", ";", "u8", "e", "[", "21", "]", ",", "R", "[", "21", "]", ",", "S", "[", "21", "]", ";", "u8", "w1", "[", "21", "]", ",", "w2", "[", "21", "]", ";", "struct", "point", "r1", ",", "r2", ";", "u8", "rr", "[", "21", "]", ";", "e", "[", "0", "]", "=", "0", ";", "memcpy", "(", "e", "+", "1", ",", "hash", ",", "20", ")", ";", "bn_reduce", "(", "e", ",", "ec_N", ",", "21", ")", ";", "R", "[", "0", "]", "=", "0", ";", "memcpy", "(", "R", "+", "1", ",", "inR", ",", "20", ")", ";", "bn_reduce", "(", "R", ",", "ec_N", ",", "21", ")", ";", "S", "[", "0", "]", "=", "0", ";", "memcpy", "(", "S", "+", "1", ",", "inS", ",", "20", ")", ";", "bn_reduce", "(", "S", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "R", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "S", ",", "ec_N", ",", "21", ")", ";", "bn_to_mon", "(", "e", ",", "ec_N", ",", "21", ")", ";", "bn_mon_inv", "(", "Sinv", ",", "S", ",", "ec_N", ",", "21", ")", ";", "bn_mon_mul", "(", "w1", ",", "e", ",", "Sinv", ",", "ec_N", ",", "21", ")", ";", "bn_mon_mul", "(", "w2", ",", "R", ",", "Sinv", ",", "ec_N", ",", "21", ")", ";", "bn_from_mon", "(", "w1", ",", "ec_N", ",", "21", ")", ";", "bn_from_mon", "(", "w2", ",", "ec_N", ",", "21", ")", ";", "point_mul", "(", "&", "r1", ",", "w1", ",", "&", "ec_G", ")", ";", "point_mul", "(", "&", "r2", ",", "w2", ",", "Q", ")", ";", "point_add", "(", "&", "r1", ",", "&", "r1", ",", "&", "r2", ")", ";", "point_from_mon", "(", "&", "r1", ")", ";", "rr", "[", "0", "]", "=", "0", ";", "memcpy", "(", "rr", "+", "1", ",", "r1", ".", "x", ",", "20", ")", ";", "bn_reduce", "(", "rr", ",", "ec_N", ",", "21", ")", ";", "bn_from_mon", "(", "R", ",", "ec_N", ",", "21", ")", ";", "bn_from_mon", "(", "S", ",", "ec_N", ",", "21", ")", ";", "return", "(", "bn_compare", "(", "rr", ",", "R", ",", "21", ")", "==", "0", ")", ";", "}" ]
Slightly modified to support kirk compatible signature input - July 2011
[ "Slightly", "modified", "to", "support", "kirk", "compatible", "signature", "input", "-", "July", "2011" ]
[ "// make Sinv = 1/S", "// w1 = m * Sinv", "// w2 = r * Sinv", "// mod N both", "// r1 = m/s * G", "// r2 = r/s * P", "//r1 = r1 + r2" ]
[ { "param": "Q", "type": "struct point" }, { "param": "inR", "type": "u8" }, { "param": "inS", "type": "u8" }, { "param": "hash", "type": "u8" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Q", "type": "struct point", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "inR", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "inS", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hash", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bfdd86bcc4fdc7b2a26b28e28613fb85c31f182f
thp/wipeout-pulse-shipedit
src/libkirk/ec.c
[ "Zlib", "MIT" ]
C
ec_priv_to_pub
void
void ec_priv_to_pub(u8 *k, u8 *Q) { struct point ec_temp; bn_to_mon(k, ec_N, 21); point_mul(&ec_temp, k, &ec_G); point_from_mon(&ec_temp); //bn_from_mon(k, ec_N, 21); memcpy(Q,ec_temp.x,20); memcpy(Q+20,ec_temp.y,20); }
// Modified from original to support kirk engine use - July 2011
Modified from original to support kirk engine use - July 2011
[ "Modified", "from", "original", "to", "support", "kirk", "engine", "use", "-", "July", "2011" ]
void ec_priv_to_pub(u8 *k, u8 *Q) { struct point ec_temp; bn_to_mon(k, ec_N, 21); point_mul(&ec_temp, k, &ec_G); point_from_mon(&ec_temp); memcpy(Q,ec_temp.x,20); memcpy(Q+20,ec_temp.y,20); }
[ "void", "ec_priv_to_pub", "(", "u8", "*", "k", ",", "u8", "*", "Q", ")", "{", "struct", "point", "ec_temp", ";", "bn_to_mon", "(", "k", ",", "ec_N", ",", "21", ")", ";", "point_mul", "(", "&", "ec_temp", ",", "k", ",", "&", "ec_G", ")", ";", "point_from_mon", "(", "&", "ec_temp", ")", ";", "memcpy", "(", "Q", ",", "ec_temp", ".", "x", ",", "20", ")", ";", "memcpy", "(", "Q", "+", "20", ",", "ec_temp", ".", "y", ",", "20", ")", ";", "}" ]
Modified from original to support kirk engine use - July 2011
[ "Modified", "from", "original", "to", "support", "kirk", "engine", "use", "-", "July", "2011" ]
[ "//bn_from_mon(k, ec_N, 21);" ]
[ { "param": "k", "type": "u8" }, { "param": "Q", "type": "u8" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "k", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Q", "type": "u8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }