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
bce6b51fd1c86f9870bd33f43771a8509ca895c9
mischcon/Clustering
src/main/resources/gems/debase-0.2.2.beta9/ext/debase_internals.c
[ "Apache-2.0" ]
C
Debase_verbose
VALUE
static VALUE Debase_verbose(VALUE self) { return verbose; }
/* * call-seq: * Debase.verbose? -> bool * * Returns +true+ if verbose output of TracePoint API events is enabled. */
Returns +true+ if verbose output of TracePoint API events is enabled.
[ "Returns", "+", "true", "+", "if", "verbose", "output", "of", "TracePoint", "API", "events", "is", "enabled", "." ]
static VALUE Debase_verbose(VALUE self) { return verbose; }
[ "static", "VALUE", "Debase_verbose", "(", "VALUE", "self", ")", "{", "return", "verbose", ";", "}" ]
call-seq: Debase.verbose?
[ "call", "-", "seq", ":", "Debase", ".", "verbose?" ]
[]
[ { "param": "self", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bce6b51fd1c86f9870bd33f43771a8509ca895c9
mischcon/Clustering
src/main/resources/gems/debase-0.2.2.beta9/ext/debase_internals.c
[ "Apache-2.0" ]
C
Debase_set_verbose
VALUE
static VALUE Debase_set_verbose(VALUE self, VALUE value) { verbose = RTEST(value) ? Qtrue : Qfalse; return value; }
/* * call-seq: * Debase.verbose = bool * * Enable verbose output of every TracePoint API events, useful for debugging debase. */
Enable verbose output of every TracePoint API events, useful for debugging debase.
[ "Enable", "verbose", "output", "of", "every", "TracePoint", "API", "events", "useful", "for", "debugging", "debase", "." ]
static VALUE Debase_set_verbose(VALUE self, VALUE value) { verbose = RTEST(value) ? Qtrue : Qfalse; return value; }
[ "static", "VALUE", "Debase_set_verbose", "(", "VALUE", "self", ",", "VALUE", "value", ")", "{", "verbose", "=", "RTEST", "(", "value", ")", "?", "Qtrue", ":", "Qfalse", ";", "return", "value", ";", "}" ]
call-seq: Debase.verbose = bool
[ "call", "-", "seq", ":", "Debase", ".", "verbose", "=", "bool" ]
[]
[ { "param": "self", "type": "VALUE" }, { "param": "value", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "value", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bce6b51fd1c86f9870bd33f43771a8509ca895c9
mischcon/Clustering
src/main/resources/gems/debase-0.2.2.beta9/ext/debase_internals.c
[ "Apache-2.0" ]
C
Init_debase_internals
void
void Init_debase_internals() { mDebase = rb_define_module("Debase"); rb_define_module_function(mDebase, "setup_tracepoints", Debase_setup_tracepoints, 0); rb_define_module_function(mDebase, "remove_tracepoints", Debase_remove_tracepoints, 0); rb_define_module_function(mDebase, "current_context", Debase_current_context, 0); rb_define_module_function(mDebase, "debug_load", Debase_debug_load, -1); rb_define_module_function(mDebase, "contexts", Debase_contexts, 0); rb_define_module_function(mDebase, "breakpoints", Debase_breakpoints, 0); rb_define_module_function(mDebase, "catchpoints", Debase_catchpoints, 0); rb_define_module_function(mDebase, "started?", Debase_started, 0); rb_define_module_function(mDebase, "verbose?", Debase_verbose, 0); rb_define_module_function(mDebase, "verbose=", Debase_set_verbose, 1); rb_define_module_function(mDebase, "enable_file_filtering", Debase_enable_file_filtering, 1); rb_define_module_function(mDebase, "enable_trace_points", Debase_enable_trace_points, 0); rb_define_module_function(mDebase, "prepare_context", Debase_prepare_context, 0); rb_define_module_function(mDebase, "init_variables", Debase_init_variables, 0); idAlive = rb_intern("alive?"); idAtLine = rb_intern("at_line"); idAtBreakpoint = rb_intern("at_breakpoint"); idAtCatchpoint = rb_intern("at_catchpoint"); idFileFilter = rb_intern("file_filter"); idAccept = rb_intern("accept?"); cContext = Init_context(mDebase); Init_breakpoint(mDebase); cDebugThread = rb_define_class_under(mDebase, "DebugThread", rb_cThread); Debase_init_variables(); rb_global_variable(&locker); rb_global_variable(&breakpoints); rb_global_variable(&catchpoints); rb_global_variable(&contexts); }
/* * Document-class: Debase * * == Summary * * This is a singleton class allows controlling the debugger. Use it to start/stop debugger, * set/remove breakpoints, etc. */
Document-class: Debase == Summary This is a singleton class allows controlling the debugger. Use it to start/stop debugger, set/remove breakpoints, etc.
[ "Document", "-", "class", ":", "Debase", "==", "Summary", "This", "is", "a", "singleton", "class", "allows", "controlling", "the", "debugger", ".", "Use", "it", "to", "start", "/", "stop", "debugger", "set", "/", "remove", "breakpoints", "etc", "." ]
void Init_debase_internals() { mDebase = rb_define_module("Debase"); rb_define_module_function(mDebase, "setup_tracepoints", Debase_setup_tracepoints, 0); rb_define_module_function(mDebase, "remove_tracepoints", Debase_remove_tracepoints, 0); rb_define_module_function(mDebase, "current_context", Debase_current_context, 0); rb_define_module_function(mDebase, "debug_load", Debase_debug_load, -1); rb_define_module_function(mDebase, "contexts", Debase_contexts, 0); rb_define_module_function(mDebase, "breakpoints", Debase_breakpoints, 0); rb_define_module_function(mDebase, "catchpoints", Debase_catchpoints, 0); rb_define_module_function(mDebase, "started?", Debase_started, 0); rb_define_module_function(mDebase, "verbose?", Debase_verbose, 0); rb_define_module_function(mDebase, "verbose=", Debase_set_verbose, 1); rb_define_module_function(mDebase, "enable_file_filtering", Debase_enable_file_filtering, 1); rb_define_module_function(mDebase, "enable_trace_points", Debase_enable_trace_points, 0); rb_define_module_function(mDebase, "prepare_context", Debase_prepare_context, 0); rb_define_module_function(mDebase, "init_variables", Debase_init_variables, 0); idAlive = rb_intern("alive?"); idAtLine = rb_intern("at_line"); idAtBreakpoint = rb_intern("at_breakpoint"); idAtCatchpoint = rb_intern("at_catchpoint"); idFileFilter = rb_intern("file_filter"); idAccept = rb_intern("accept?"); cContext = Init_context(mDebase); Init_breakpoint(mDebase); cDebugThread = rb_define_class_under(mDebase, "DebugThread", rb_cThread); Debase_init_variables(); rb_global_variable(&locker); rb_global_variable(&breakpoints); rb_global_variable(&catchpoints); rb_global_variable(&contexts); }
[ "void", "Init_debase_internals", "(", ")", "{", "mDebase", "=", "rb_define_module", "(", "\"", "\"", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_setup_tracepoints", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_remove_tracepoints", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_current_context", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_debug_load", ",", "-1", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_contexts", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_breakpoints", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_catchpoints", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_started", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_verbose", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_set_verbose", ",", "1", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_enable_file_filtering", ",", "1", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_enable_trace_points", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_prepare_context", ",", "0", ")", ";", "rb_define_module_function", "(", "mDebase", ",", "\"", "\"", ",", "Debase_init_variables", ",", "0", ")", ";", "idAlive", "=", "rb_intern", "(", "\"", "\"", ")", ";", "idAtLine", "=", "rb_intern", "(", "\"", "\"", ")", ";", "idAtBreakpoint", "=", "rb_intern", "(", "\"", "\"", ")", ";", "idAtCatchpoint", "=", "rb_intern", "(", "\"", "\"", ")", ";", "idFileFilter", "=", "rb_intern", "(", "\"", "\"", ")", ";", "idAccept", "=", "rb_intern", "(", "\"", "\"", ")", ";", "cContext", "=", "Init_context", "(", "mDebase", ")", ";", "Init_breakpoint", "(", "mDebase", ")", ";", "cDebugThread", "=", "rb_define_class_under", "(", "mDebase", ",", "\"", "\"", ",", "rb_cThread", ")", ";", "Debase_init_variables", "(", ")", ";", "rb_global_variable", "(", "&", "locker", ")", ";", "rb_global_variable", "(", "&", "breakpoints", ")", ";", "rb_global_variable", "(", "&", "catchpoints", ")", ";", "rb_global_variable", "(", "&", "contexts", ")", ";", "}" ]
Document-class: Debase == Summary
[ "Document", "-", "class", ":", "Debase", "==", "Summary" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
6d497b0df1576e214145eed8902bfeaf4dd65440
vsvld/rmagick
ext/RMagick/rmkinfo.c
[ "MIT" ]
C
rm_kernel_info_destroy
void
static void rm_kernel_info_destroy(void *kernel) { if (kernel) DestroyKernelInfo((KernelInfo*)kernel); }
/** * If there's a kernel info, delete it before destroying the KernelInfo * * No Ruby usage (internal function) * * @param kernel pointer to the KernelInfo object associated with instance */
If there's a kernel info, delete it before destroying the KernelInfo No Ruby usage (internal function) @param kernel pointer to the KernelInfo object associated with instance
[ "If", "there", "'", "s", "a", "kernel", "info", "delete", "it", "before", "destroying", "the", "KernelInfo", "No", "Ruby", "usage", "(", "internal", "function", ")", "@param", "kernel", "pointer", "to", "the", "KernelInfo", "object", "associated", "with", "instance" ]
static void rm_kernel_info_destroy(void *kernel) { if (kernel) DestroyKernelInfo((KernelInfo*)kernel); }
[ "static", "void", "rm_kernel_info_destroy", "(", "void", "*", "kernel", ")", "{", "if", "(", "kernel", ")", "DestroyKernelInfo", "(", "(", "KernelInfo", "*", ")", "kernel", ")", ";", "}" ]
If there's a kernel info, delete it before destroying the KernelInfo No Ruby usage (internal function)
[ "If", "there", "'", "s", "a", "kernel", "info", "delete", "it", "before", "destroying", "the", "KernelInfo", "No", "Ruby", "usage", "(", "internal", "function", ")" ]
[]
[ { "param": "kernel", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "kernel", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6d497b0df1576e214145eed8902bfeaf4dd65440
vsvld/rmagick
ext/RMagick/rmkinfo.c
[ "MIT" ]
C
KernelInfo_alloc
VALUE
VALUE KernelInfo_alloc(VALUE class) { return Data_Wrap_Struct(class, NULL, rm_kernel_info_destroy, NULL); }
/** * Create a KernelInfo object. * * No Ruby usage (internal function) * * @param class the Ruby class to use * @return a new KernelInfo object */
Create a KernelInfo object. No Ruby usage (internal function) @param class the Ruby class to use @return a new KernelInfo object
[ "Create", "a", "KernelInfo", "object", ".", "No", "Ruby", "usage", "(", "internal", "function", ")", "@param", "class", "the", "Ruby", "class", "to", "use", "@return", "a", "new", "KernelInfo", "object" ]
VALUE KernelInfo_alloc(VALUE class) { return Data_Wrap_Struct(class, NULL, rm_kernel_info_destroy, NULL); }
[ "VALUE", "KernelInfo_alloc", "(", "VALUE", "class", ")", "{", "return", "Data_Wrap_Struct", "(", "class", ",", "NULL", ",", "rm_kernel_info_destroy", ",", "NULL", ")", ";", "}" ]
Create a KernelInfo object.
[ "Create", "a", "KernelInfo", "object", "." ]
[]
[ { "param": "class", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "class", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6d497b0df1576e214145eed8902bfeaf4dd65440
vsvld/rmagick
ext/RMagick/rmkinfo.c
[ "MIT" ]
C
KernelInfo_initialize
VALUE
VALUE KernelInfo_initialize(VALUE self, VALUE kernel_string) { KernelInfo *kernel; #if defined(IMAGEMAGICK_7) ExceptionInfo *exception; #endif Check_Type(kernel_string, T_STRING); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); kernel = AcquireKernelInfo(StringValueCStr(kernel_string), exception); if (rm_should_raise_exception(exception, DestroyExceptionRetention)) { if (kernel != (KernelInfo *) NULL) { (void) DestroyKernelInfo(kernel); } rm_raise_exception(exception); } #else kernel = AcquireKernelInfo(StringValueCStr(kernel_string)); #endif if (!kernel) { rb_raise(rb_eRuntimeError, "failed to parse kernel string"); } DATA_PTR(self) = kernel; return self; }
/** * KernelInfo object constructor * * Ruby usage: * - @verbatim KernelInfo#initialize @endverbatim * * @param self this object * @param kernel_string kernel info string representation to be parsed * @return self */
KernelInfo object constructor Ruby usage: - @verbatim KernelInfo#initialize @endverbatim @param self this object @param kernel_string kernel info string representation to be parsed @return self
[ "KernelInfo", "object", "constructor", "Ruby", "usage", ":", "-", "@verbatim", "KernelInfo#initialize", "@endverbatim", "@param", "self", "this", "object", "@param", "kernel_string", "kernel", "info", "string", "representation", "to", "be", "parsed", "@return", "self" ]
VALUE KernelInfo_initialize(VALUE self, VALUE kernel_string) { KernelInfo *kernel; #if defined(IMAGEMAGICK_7) ExceptionInfo *exception; #endif Check_Type(kernel_string, T_STRING); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); kernel = AcquireKernelInfo(StringValueCStr(kernel_string), exception); if (rm_should_raise_exception(exception, DestroyExceptionRetention)) { if (kernel != (KernelInfo *) NULL) { (void) DestroyKernelInfo(kernel); } rm_raise_exception(exception); } #else kernel = AcquireKernelInfo(StringValueCStr(kernel_string)); #endif if (!kernel) { rb_raise(rb_eRuntimeError, "failed to parse kernel string"); } DATA_PTR(self) = kernel; return self; }
[ "VALUE", "KernelInfo_initialize", "(", "VALUE", "self", ",", "VALUE", "kernel_string", ")", "{", "KernelInfo", "*", "kernel", ";", "#if", "defined", "(", "IMAGEMAGICK_7", ")", "\n", "ExceptionInfo", "*", "exception", ";", "#endif", "Check_Type", "(", "kernel_string", ",", "T_STRING", ")", ";", "#if", "defined", "(", "IMAGEMAGICK_7", ")", "\n", "exception", "=", "AcquireExceptionInfo", "(", ")", ";", "kernel", "=", "AcquireKernelInfo", "(", "StringValueCStr", "(", "kernel_string", ")", ",", "exception", ")", ";", "if", "(", "rm_should_raise_exception", "(", "exception", ",", "DestroyExceptionRetention", ")", ")", "{", "if", "(", "kernel", "!=", "(", "KernelInfo", "*", ")", "NULL", ")", "{", "(", "void", ")", "DestroyKernelInfo", "(", "kernel", ")", ";", "}", "rm_raise_exception", "(", "exception", ")", ";", "}", "#else", "kernel", "=", "AcquireKernelInfo", "(", "StringValueCStr", "(", "kernel_string", ")", ")", ";", "#endif", "if", "(", "!", "kernel", ")", "{", "rb_raise", "(", "rb_eRuntimeError", ",", "\"", "\"", ")", ";", "}", "DATA_PTR", "(", "self", ")", "=", "kernel", ";", "return", "self", ";", "}" ]
KernelInfo object constructor Ruby usage: - @verbatim KernelInfo#initialize @endverbatim
[ "KernelInfo", "object", "constructor", "Ruby", "usage", ":", "-", "@verbatim", "KernelInfo#initialize", "@endverbatim" ]
[]
[ { "param": "self", "type": "VALUE" }, { "param": "kernel_string", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "kernel_string", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6d497b0df1576e214145eed8902bfeaf4dd65440
vsvld/rmagick
ext/RMagick/rmkinfo.c
[ "MIT" ]
C
KernelInfo_scale_geometry
VALUE
VALUE KernelInfo_scale_geometry(VALUE self, VALUE geometry) { Check_Type(geometry, T_STRING); ScaleGeometryKernelInfo((KernelInfo*)DATA_PTR(self), StringValueCStr(geometry)); return Qnil; }
/** * Takes a geometry argument string, typically provided as a "-set option:convolve:scale {geometry}" user setting, * and modifies the kernel according to the parsed arguments of that setting. * * Ruby usage: * - @verbatim KernelInfo#scale_geometry(geometry) @endverbatim * * @param geometry geometry string to parse and apply * @param self this object */
Takes a geometry argument string, typically provided as a "-set option:convolve:scale {geometry}" user setting, and modifies the kernel according to the parsed arguments of that setting. @param geometry geometry string to parse and apply @param self this object
[ "Takes", "a", "geometry", "argument", "string", "typically", "provided", "as", "a", "\"", "-", "set", "option", ":", "convolve", ":", "scale", "{", "geometry", "}", "\"", "user", "setting", "and", "modifies", "the", "kernel", "according", "to", "the", "parsed", "arguments", "of", "that", "setting", ".", "@param", "geometry", "geometry", "string", "to", "parse", "and", "apply", "@param", "self", "this", "object" ]
VALUE KernelInfo_scale_geometry(VALUE self, VALUE geometry) { Check_Type(geometry, T_STRING); ScaleGeometryKernelInfo((KernelInfo*)DATA_PTR(self), StringValueCStr(geometry)); return Qnil; }
[ "VALUE", "KernelInfo_scale_geometry", "(", "VALUE", "self", ",", "VALUE", "geometry", ")", "{", "Check_Type", "(", "geometry", ",", "T_STRING", ")", ";", "ScaleGeometryKernelInfo", "(", "(", "KernelInfo", "*", ")", "DATA_PTR", "(", "self", ")", ",", "StringValueCStr", "(", "geometry", ")", ")", ";", "return", "Qnil", ";", "}" ]
Takes a geometry argument string, typically provided as a "-set option:convolve:scale {geometry}" user setting, and modifies the kernel according to the parsed arguments of that setting.
[ "Takes", "a", "geometry", "argument", "string", "typically", "provided", "as", "a", "\"", "-", "set", "option", ":", "convolve", ":", "scale", "{", "geometry", "}", "\"", "user", "setting", "and", "modifies", "the", "kernel", "according", "to", "the", "parsed", "arguments", "of", "that", "setting", "." ]
[]
[ { "param": "self", "type": "VALUE" }, { "param": "geometry", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "geometry", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6d497b0df1576e214145eed8902bfeaf4dd65440
vsvld/rmagick
ext/RMagick/rmkinfo.c
[ "MIT" ]
C
KernelInfo_clone
VALUE
VALUE KernelInfo_clone(VALUE self) { KernelInfo *kernel = CloneKernelInfo((KernelInfo*)DATA_PTR(self)); return Data_Wrap_Struct(Class_KernelInfo, NULL, rm_kernel_info_destroy, kernel); }
/** * Creates a new clone of the object so that its can be modified without effecting the original. * * Ruby usage: * - @verbatim KernelInfo#clone @endverbatim * * @param self this object * @return new KernelInfo instance */
Creates a new clone of the object so that its can be modified without effecting the original. Ruby usage: - @verbatim KernelInfo#clone @endverbatim @param self this object @return new KernelInfo instance
[ "Creates", "a", "new", "clone", "of", "the", "object", "so", "that", "its", "can", "be", "modified", "without", "effecting", "the", "original", ".", "Ruby", "usage", ":", "-", "@verbatim", "KernelInfo#clone", "@endverbatim", "@param", "self", "this", "object", "@return", "new", "KernelInfo", "instance" ]
VALUE KernelInfo_clone(VALUE self) { KernelInfo *kernel = CloneKernelInfo((KernelInfo*)DATA_PTR(self)); return Data_Wrap_Struct(Class_KernelInfo, NULL, rm_kernel_info_destroy, kernel); }
[ "VALUE", "KernelInfo_clone", "(", "VALUE", "self", ")", "{", "KernelInfo", "*", "kernel", "=", "CloneKernelInfo", "(", "(", "KernelInfo", "*", ")", "DATA_PTR", "(", "self", ")", ")", ";", "return", "Data_Wrap_Struct", "(", "Class_KernelInfo", ",", "NULL", ",", "rm_kernel_info_destroy", ",", "kernel", ")", ";", "}" ]
Creates a new clone of the object so that its can be modified without effecting the original.
[ "Creates", "a", "new", "clone", "of", "the", "object", "so", "that", "its", "can", "be", "modified", "without", "effecting", "the", "original", "." ]
[]
[ { "param": "self", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6d497b0df1576e214145eed8902bfeaf4dd65440
vsvld/rmagick
ext/RMagick/rmkinfo.c
[ "MIT" ]
C
KernelInfo_builtin
VALUE
VALUE KernelInfo_builtin(VALUE self, VALUE what, VALUE geometry) { KernelInfo *kernel; KernelInfoType kernel_type; GeometryInfo info; #if defined(IMAGEMAGICK_7) ExceptionInfo *exception; #endif Check_Type(geometry, T_STRING); VALUE_TO_ENUM(what, kernel_type, KernelInfoType); ParseGeometry(StringValueCStr(geometry), &info); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); kernel = AcquireKernelBuiltIn(kernel_type, &info, exception); if (rm_should_raise_exception(exception, DestroyExceptionRetention)) { if (kernel != (KernelInfo *) NULL) { (void) DestroyKernelInfo(kernel); } rm_raise_exception(exception); } #else kernel = AcquireKernelBuiltIn(kernel_type, &info); #endif if (!kernel) { rb_raise(rb_eRuntimeError, "failed to acquire builtin kernel"); } return Data_Wrap_Struct(self, NULL, rm_kernel_info_destroy, kernel); }
/** * Create new instance of KernelInfo with one of the 'named' built-in types of * kernels used for special purposes such as gaussian blurring, skeleton * pruning, and edge distance determination. * * Ruby usage: * - @verbatim KernelInfo.builtin(kernel, geometry = nil) @endverbatim * * @parms kernel one of Magick::KernelInfoType enums: * Magick::UndefinedKernel * Magick::UnityKernel * Magick::GaussianKernel * Magick::DoGKernel * Magick::LoGKernel * Magick::BlurKernel * Magick::CometKernel * Magick::LaplacianKernel * Magick::SobelKernel * Magick::FreiChenKernel * Magick::RobertsKernel * Magick::PrewittKernel * Magick::CompassKernel * Magick::KirschKernel * Magick::DiamondKernel * Magick::SquareKernel * Magick::RectangleKernel * Magick::OctagonKernel * Magick::DiskKernel * Magick::PlusKernel * Magick::CrossKernel * Magick::RingKernel * Magick::PeaksKernel * Magick::EdgesKernel * Magick::CornersKernel * Magick::DiagonalsKernel * Magick::LineEndsKernel * Magick::LineJunctionsKernel * Magick::RidgesKernel * Magick::ConvexHullKernel * Magick::ThinSEKernel * Magick::SkeletonKernel * Magick::ChebyshevKernel * Magick::ManhattanKernel * Magick::OctagonalKernel * Magick::EuclideanKernel * Magick::UserDefinedKernel * Magick::BinomialKernel * @param geometry geometry to pass to default kernel * @return KernelInfo instance */
Create new instance of KernelInfo with one of the 'named' built-in types of kernels used for special purposes such as gaussian blurring, skeleton pruning, and edge distance determination. Ruby usage: - @verbatim KernelInfo.builtin(kernel, geometry = nil) @endverbatim
[ "Create", "new", "instance", "of", "KernelInfo", "with", "one", "of", "the", "'", "named", "'", "built", "-", "in", "types", "of", "kernels", "used", "for", "special", "purposes", "such", "as", "gaussian", "blurring", "skeleton", "pruning", "and", "edge", "distance", "determination", ".", "Ruby", "usage", ":", "-", "@verbatim", "KernelInfo", ".", "builtin", "(", "kernel", "geometry", "=", "nil", ")", "@endverbatim" ]
VALUE KernelInfo_builtin(VALUE self, VALUE what, VALUE geometry) { KernelInfo *kernel; KernelInfoType kernel_type; GeometryInfo info; #if defined(IMAGEMAGICK_7) ExceptionInfo *exception; #endif Check_Type(geometry, T_STRING); VALUE_TO_ENUM(what, kernel_type, KernelInfoType); ParseGeometry(StringValueCStr(geometry), &info); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); kernel = AcquireKernelBuiltIn(kernel_type, &info, exception); if (rm_should_raise_exception(exception, DestroyExceptionRetention)) { if (kernel != (KernelInfo *) NULL) { (void) DestroyKernelInfo(kernel); } rm_raise_exception(exception); } #else kernel = AcquireKernelBuiltIn(kernel_type, &info); #endif if (!kernel) { rb_raise(rb_eRuntimeError, "failed to acquire builtin kernel"); } return Data_Wrap_Struct(self, NULL, rm_kernel_info_destroy, kernel); }
[ "VALUE", "KernelInfo_builtin", "(", "VALUE", "self", ",", "VALUE", "what", ",", "VALUE", "geometry", ")", "{", "KernelInfo", "*", "kernel", ";", "KernelInfoType", "kernel_type", ";", "GeometryInfo", "info", ";", "#if", "defined", "(", "IMAGEMAGICK_7", ")", "\n", "ExceptionInfo", "*", "exception", ";", "#endif", "Check_Type", "(", "geometry", ",", "T_STRING", ")", ";", "VALUE_TO_ENUM", "(", "what", ",", "kernel_type", ",", "KernelInfoType", ")", ";", "ParseGeometry", "(", "StringValueCStr", "(", "geometry", ")", ",", "&", "info", ")", ";", "#if", "defined", "(", "IMAGEMAGICK_7", ")", "\n", "exception", "=", "AcquireExceptionInfo", "(", ")", ";", "kernel", "=", "AcquireKernelBuiltIn", "(", "kernel_type", ",", "&", "info", ",", "exception", ")", ";", "if", "(", "rm_should_raise_exception", "(", "exception", ",", "DestroyExceptionRetention", ")", ")", "{", "if", "(", "kernel", "!=", "(", "KernelInfo", "*", ")", "NULL", ")", "{", "(", "void", ")", "DestroyKernelInfo", "(", "kernel", ")", ";", "}", "rm_raise_exception", "(", "exception", ")", ";", "}", "#else", "kernel", "=", "AcquireKernelBuiltIn", "(", "kernel_type", ",", "&", "info", ")", ";", "#endif", "if", "(", "!", "kernel", ")", "{", "rb_raise", "(", "rb_eRuntimeError", ",", "\"", "\"", ")", ";", "}", "return", "Data_Wrap_Struct", "(", "self", ",", "NULL", ",", "rm_kernel_info_destroy", ",", "kernel", ")", ";", "}" ]
Create new instance of KernelInfo with one of the 'named' built-in types of kernels used for special purposes such as gaussian blurring, skeleton pruning, and edge distance determination.
[ "Create", "new", "instance", "of", "KernelInfo", "with", "one", "of", "the", "'", "named", "'", "built", "-", "in", "types", "of", "kernels", "used", "for", "special", "purposes", "such", "as", "gaussian", "blurring", "skeleton", "pruning", "and", "edge", "distance", "determination", "." ]
[]
[ { "param": "self", "type": "VALUE" }, { "param": "what", "type": "VALUE" }, { "param": "geometry", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "self", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "what", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "geometry", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c2304a521de33d97841756f8514f3c1870b026f0
vsvld/rmagick
ext/RMagick/rmmain.c
[ "MIT" ]
C
managed_memory_enable
void
static inline void managed_memory_enable(VALUE enable) { if (enable) { SetMagickMemoryMethods(rm_malloc, rm_realloc, rm_free); } rb_define_const(Module_Magick, "MANAGED_MEMORY", enable); }
/** * Use managed memory. * * No Ruby usage (internal function) */
Use managed memory. No Ruby usage (internal function)
[ "Use", "managed", "memory", ".", "No", "Ruby", "usage", "(", "internal", "function", ")" ]
static inline void managed_memory_enable(VALUE enable) { if (enable) { SetMagickMemoryMethods(rm_malloc, rm_realloc, rm_free); } rb_define_const(Module_Magick, "MANAGED_MEMORY", enable); }
[ "static", "inline", "void", "managed_memory_enable", "(", "VALUE", "enable", ")", "{", "if", "(", "enable", ")", "{", "SetMagickMemoryMethods", "(", "rm_malloc", ",", "rm_realloc", ",", "rm_free", ")", ";", "}", "rb_define_const", "(", "Module_Magick", ",", "\"", "\"", ",", "enable", ")", ";", "}" ]
Use managed memory.
[ "Use", "managed", "memory", "." ]
[]
[ { "param": "enable", "type": "VALUE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "enable", "type": "VALUE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c2304a521de33d97841756f8514f3c1870b026f0
vsvld/rmagick
ext/RMagick/rmmain.c
[ "MIT" ]
C
features_constant
void
static void features_constant(void) { VALUE features; // 6.5.7 - latest (7.0.0) features = rb_str_new2(GetMagickFeatures()); rb_obj_freeze(features); rb_define_const(Module_Magick, "Magick_features", features); RB_GC_GUARD(features); }
/** * Create Features constant. * * No Ruby usage (internal function) */
Create Features constant. No Ruby usage (internal function)
[ "Create", "Features", "constant", ".", "No", "Ruby", "usage", "(", "internal", "function", ")" ]
static void features_constant(void) { VALUE features; features = rb_str_new2(GetMagickFeatures()); rb_obj_freeze(features); rb_define_const(Module_Magick, "Magick_features", features); RB_GC_GUARD(features); }
[ "static", "void", "features_constant", "(", "void", ")", "{", "VALUE", "features", ";", "features", "=", "rb_str_new2", "(", "GetMagickFeatures", "(", ")", ")", ";", "rb_obj_freeze", "(", "features", ")", ";", "rb_define_const", "(", "Module_Magick", ",", "\"", "\"", ",", "features", ")", ";", "RB_GC_GUARD", "(", "features", ")", ";", "}" ]
Create Features constant.
[ "Create", "Features", "constant", "." ]
[ "// 6.5.7 - latest (7.0.0)" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8ba05a8c0db822d7223f8c24d2f45672135352c6
TheRyanKing87/Kernel-threads
kernel/proc.c
[ "Xnet", "X11" ]
C
userinit
void
void userinit(void) { struct proc *p; extern char _binary_initcode_start[], _binary_initcode_size[]; p = allocproc(); acquire(&ptable.lock); initproc = p; if((p->pgdir = setupkvm()) == 0) panic("userinit: out of memory?"); inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size); p->sz = PGSIZE; memset(p->tf, 0, sizeof(*p->tf)); p->tf->cs = (SEG_UCODE << 3) | DPL_USER; p->tf->ds = (SEG_UDATA << 3) | DPL_USER; p->tf->es = p->tf->ds; p->tf->ss = p->tf->ds; p->tf->eflags = FL_IF; p->tf->esp = PGSIZE; p->tf->eip = 0; // beginning of initcode.S p->priority = 1; // P2 - initialize this (and all) procs to priority 1 p->wokeUp = 0; safestrcpy(p->name, "initcode", sizeof(p->name)); p->cwd = namei("/"); p->state = RUNNABLE; release(&ptable.lock); }
// Set up first user process.
Set up first user process.
[ "Set", "up", "first", "user", "process", "." ]
void userinit(void) { struct proc *p; extern char _binary_initcode_start[], _binary_initcode_size[]; p = allocproc(); acquire(&ptable.lock); initproc = p; if((p->pgdir = setupkvm()) == 0) panic("userinit: out of memory?"); inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size); p->sz = PGSIZE; memset(p->tf, 0, sizeof(*p->tf)); p->tf->cs = (SEG_UCODE << 3) | DPL_USER; p->tf->ds = (SEG_UDATA << 3) | DPL_USER; p->tf->es = p->tf->ds; p->tf->ss = p->tf->ds; p->tf->eflags = FL_IF; p->tf->esp = PGSIZE; p->tf->eip = 0; p->priority = 1; p->wokeUp = 0; safestrcpy(p->name, "initcode", sizeof(p->name)); p->cwd = namei("/"); p->state = RUNNABLE; release(&ptable.lock); }
[ "void", "userinit", "(", "void", ")", "{", "struct", "proc", "*", "p", ";", "extern", "char", "_binary_initcode_start", "[", "]", ",", "_binary_initcode_size", "[", "]", ";", "p", "=", "allocproc", "(", ")", ";", "acquire", "(", "&", "ptable", ".", "lock", ")", ";", "initproc", "=", "p", ";", "if", "(", "(", "p", "->", "pgdir", "=", "setupkvm", "(", ")", ")", "==", "0", ")", "panic", "(", "\"", "\"", ")", ";", "inituvm", "(", "p", "->", "pgdir", ",", "_binary_initcode_start", ",", "(", "int", ")", "_binary_initcode_size", ")", ";", "p", "->", "sz", "=", "PGSIZE", ";", "memset", "(", "p", "->", "tf", ",", "0", ",", "sizeof", "(", "*", "p", "->", "tf", ")", ")", ";", "p", "->", "tf", "->", "cs", "=", "(", "SEG_UCODE", "<<", "3", ")", "|", "DPL_USER", ";", "p", "->", "tf", "->", "ds", "=", "(", "SEG_UDATA", "<<", "3", ")", "|", "DPL_USER", ";", "p", "->", "tf", "->", "es", "=", "p", "->", "tf", "->", "ds", ";", "p", "->", "tf", "->", "ss", "=", "p", "->", "tf", "->", "ds", ";", "p", "->", "tf", "->", "eflags", "=", "FL_IF", ";", "p", "->", "tf", "->", "esp", "=", "PGSIZE", ";", "p", "->", "tf", "->", "eip", "=", "0", ";", "p", "->", "priority", "=", "1", ";", "p", "->", "wokeUp", "=", "0", ";", "safestrcpy", "(", "p", "->", "name", ",", "\"", "\"", ",", "sizeof", "(", "p", "->", "name", ")", ")", ";", "p", "->", "cwd", "=", "namei", "(", "\"", "\"", ")", ";", "p", "->", "state", "=", "RUNNABLE", ";", "release", "(", "&", "ptable", ".", "lock", ")", ";", "}" ]
Set up first user process.
[ "Set", "up", "first", "user", "process", "." ]
[ "// beginning of initcode.S", "// P2 - initialize this (and all) procs to priority 1" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8ba05a8c0db822d7223f8c24d2f45672135352c6
TheRyanKing87/Kernel-threads
kernel/proc.c
[ "Xnet", "X11" ]
C
growproc
int
int growproc(int n) { //adding threads stuff uint sz; struct proc *p; pde_t *pageDirectory = proc->pgdir; sz = proc->sz; //for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ //if(p->pgdir != proc->pgdir) // continue; //if(n > 0){ // if((sz = allocuvm(p->pgdir, sz, sz + n)) == 0) // return -1; //} else if(n < 0){ // if((sz = deallocuvm(p->pgdir, sz, sz + n)) == 0) // return -1; //} //p->sz = sz; //} if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->pgdir == pageDirectory){ p->sz = sz; acquire(&lock); switchuvm(p); release(&lock); } } release(&ptable.lock); switchuvm(proc); return 0; }
// Grow current process's memory by n bytes. // Return 0 on success, -1 on failure.
Grow current process's memory by n bytes. Return 0 on success, -1 on failure.
[ "Grow", "current", "process", "'", "s", "memory", "by", "n", "bytes", ".", "Return", "0", "on", "success", "-", "1", "on", "failure", "." ]
int growproc(int n) { uint sz; struct proc *p; pde_t *pageDirectory = proc->pgdir; sz = proc->sz; if(n > 0){ if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } else if(n < 0){ if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) return -1; } proc->sz = sz; acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->pgdir == pageDirectory){ p->sz = sz; acquire(&lock); switchuvm(p); release(&lock); } } release(&ptable.lock); switchuvm(proc); return 0; }
[ "int", "growproc", "(", "int", "n", ")", "{", "uint", "sz", ";", "struct", "proc", "*", "p", ";", "pde_t", "*", "pageDirectory", "=", "proc", "->", "pgdir", ";", "sz", "=", "proc", "->", "sz", ";", "if", "(", "n", ">", "0", ")", "{", "if", "(", "(", "sz", "=", "allocuvm", "(", "proc", "->", "pgdir", ",", "sz", ",", "sz", "+", "n", ")", ")", "==", "0", ")", "return", "-1", ";", "}", "else", "if", "(", "n", "<", "0", ")", "{", "if", "(", "(", "sz", "=", "deallocuvm", "(", "proc", "->", "pgdir", ",", "sz", ",", "sz", "+", "n", ")", ")", "==", "0", ")", "return", "-1", ";", "}", "proc", "->", "sz", "=", "sz", ";", "acquire", "(", "&", "ptable", ".", "lock", ")", ";", "for", "(", "p", "=", "ptable", ".", "proc", ";", "p", "<", "&", "ptable", ".", "proc", "[", "NPROC", "]", ";", "p", "++", ")", "{", "if", "(", "p", "->", "pgdir", "==", "pageDirectory", ")", "{", "p", "->", "sz", "=", "sz", ";", "acquire", "(", "&", "lock", ")", ";", "switchuvm", "(", "p", ")", ";", "release", "(", "&", "lock", ")", ";", "}", "}", "release", "(", "&", "ptable", ".", "lock", ")", ";", "switchuvm", "(", "proc", ")", ";", "return", "0", ";", "}" ]
Grow current process's memory by n bytes.
[ "Grow", "current", "process", "'", "s", "memory", "by", "n", "bytes", "." ]
[ "//adding threads stuff", "//for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){", "//if(p->pgdir != proc->pgdir)", "// continue;", "//if(n > 0){", "// if((sz = allocuvm(p->pgdir, sz, sz + n)) == 0)", "//\treturn -1;", "//} else if(n < 0){", "// if((sz = deallocuvm(p->pgdir, sz, sz + n)) == 0)", "//\treturn -1;", "//}", "//p->sz = sz;", "//}" ]
[ { "param": "n", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "n", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8ba05a8c0db822d7223f8c24d2f45672135352c6
TheRyanKing87/Kernel-threads
kernel/proc.c
[ "Xnet", "X11" ]
C
fork
int
int fork(void) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; //pretending this is clone not fork //set up new user stack //and registers (np->tf->eip, //np->tf->esp) for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); np->priority = proc->priority; // P2 - make sure priority is copied np->wokeUp = 0; return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE.
Create a new process copying p as the parent. Sets up stack to return as if from system call. Caller must set state of returned proc to RUNNABLE.
[ "Create", "a", "new", "process", "copying", "p", "as", "the", "parent", ".", "Sets", "up", "stack", "to", "return", "as", "if", "from", "system", "call", ".", "Caller", "must", "set", "state", "of", "returned", "proc", "to", "RUNNABLE", "." ]
int fork(void) { int i, pid; struct proc *np; if((np = allocproc()) == 0) return -1; if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); np->priority = proc->priority; np->wokeUp = 0; return pid; }
[ "int", "fork", "(", "void", ")", "{", "int", "i", ",", "pid", ";", "struct", "proc", "*", "np", ";", "if", "(", "(", "np", "=", "allocproc", "(", ")", ")", "==", "0", ")", "return", "-1", ";", "if", "(", "(", "np", "->", "pgdir", "=", "copyuvm", "(", "proc", "->", "pgdir", ",", "proc", "->", "sz", ")", ")", "==", "0", ")", "{", "kfree", "(", "np", "->", "kstack", ")", ";", "np", "->", "kstack", "=", "0", ";", "np", "->", "state", "=", "UNUSED", ";", "return", "-1", ";", "}", "np", "->", "sz", "=", "proc", "->", "sz", ";", "np", "->", "parent", "=", "proc", ";", "*", "np", "->", "tf", "=", "*", "proc", "->", "tf", ";", "np", "->", "tf", "->", "eax", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "NOFILE", ";", "i", "++", ")", "if", "(", "proc", "->", "ofile", "[", "i", "]", ")", "np", "->", "ofile", "[", "i", "]", "=", "filedup", "(", "proc", "->", "ofile", "[", "i", "]", ")", ";", "np", "->", "cwd", "=", "idup", "(", "proc", "->", "cwd", ")", ";", "pid", "=", "np", "->", "pid", ";", "np", "->", "state", "=", "RUNNABLE", ";", "safestrcpy", "(", "np", "->", "name", ",", "proc", "->", "name", ",", "sizeof", "(", "proc", "->", "name", ")", ")", ";", "np", "->", "priority", "=", "proc", "->", "priority", ";", "np", "->", "wokeUp", "=", "0", ";", "return", "pid", ";", "}" ]
Create a new process copying p as the parent.
[ "Create", "a", "new", "process", "copying", "p", "as", "the", "parent", "." ]
[ "// Allocate process.", "// Copy process state from p.", "// Clear %eax so that fork returns 0 in the child.", "//pretending this is clone not fork", "//set up new user stack", "//and registers (np->tf->eip,", "//np->tf->esp)", "// P2 - make sure priority is copied" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8ba05a8c0db822d7223f8c24d2f45672135352c6
TheRyanKing87/Kernel-threads
kernel/proc.c
[ "Xnet", "X11" ]
C
wait
int
int wait(void) { struct proc *p; int havekids, pid; acquire(&ptable.lock); for(;;){ // Scan through table looking for zombie children. havekids = 0; for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if((p->parent != proc) || (p->pgdir == proc->pgdir)) continue; havekids = 1; if(p->state == ZOMBIE){ // Found one. pid = p->pid; kfree(p->kstack); p->kstack = 0; freevm(p->pgdir); p->state = UNUSED; p->pid = 0; p->parent = 0; p->name[0] = 0; p->killed = 0; release(&ptable.lock); return pid; } } // No point waiting if we don't have any children. if(!havekids || proc->killed){ release(&ptable.lock); //freevm(proc->pgdir); return -1; } //freevm(proc->pgdir); // Wait for children to exit. (See wakeup1 call in proc_exit.) sleep(proc, &ptable.lock); //DOC: wait-sleep } }
// Wait for a child process to exit and return its pid. // Return -1 if this process has no children.
Wait for a child process to exit and return its pid. Return -1 if this process has no children.
[ "Wait", "for", "a", "child", "process", "to", "exit", "and", "return", "its", "pid", ".", "Return", "-", "1", "if", "this", "process", "has", "no", "children", "." ]
int wait(void) { struct proc *p; int havekids, pid; acquire(&ptable.lock); for(;;){ havekids = 0; for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if((p->parent != proc) || (p->pgdir == proc->pgdir)) continue; havekids = 1; if(p->state == ZOMBIE){ pid = p->pid; kfree(p->kstack); p->kstack = 0; freevm(p->pgdir); p->state = UNUSED; p->pid = 0; p->parent = 0; p->name[0] = 0; p->killed = 0; release(&ptable.lock); return pid; } } if(!havekids || proc->killed){ release(&ptable.lock); return -1; } sleep(proc, &ptable.lock); } }
[ "int", "wait", "(", "void", ")", "{", "struct", "proc", "*", "p", ";", "int", "havekids", ",", "pid", ";", "acquire", "(", "&", "ptable", ".", "lock", ")", ";", "for", "(", ";", ";", ")", "{", "havekids", "=", "0", ";", "for", "(", "p", "=", "ptable", ".", "proc", ";", "p", "<", "&", "ptable", ".", "proc", "[", "NPROC", "]", ";", "p", "++", ")", "{", "if", "(", "(", "p", "->", "parent", "!=", "proc", ")", "||", "(", "p", "->", "pgdir", "==", "proc", "->", "pgdir", ")", ")", "continue", ";", "havekids", "=", "1", ";", "if", "(", "p", "->", "state", "==", "ZOMBIE", ")", "{", "pid", "=", "p", "->", "pid", ";", "kfree", "(", "p", "->", "kstack", ")", ";", "p", "->", "kstack", "=", "0", ";", "freevm", "(", "p", "->", "pgdir", ")", ";", "p", "->", "state", "=", "UNUSED", ";", "p", "->", "pid", "=", "0", ";", "p", "->", "parent", "=", "0", ";", "p", "->", "name", "[", "0", "]", "=", "0", ";", "p", "->", "killed", "=", "0", ";", "release", "(", "&", "ptable", ".", "lock", ")", ";", "return", "pid", ";", "}", "}", "if", "(", "!", "havekids", "||", "proc", "->", "killed", ")", "{", "release", "(", "&", "ptable", ".", "lock", ")", ";", "return", "-1", ";", "}", "sleep", "(", "proc", ",", "&", "ptable", ".", "lock", ")", ";", "}", "}" ]
Wait for a child process to exit and return its pid.
[ "Wait", "for", "a", "child", "process", "to", "exit", "and", "return", "its", "pid", "." ]
[ "// Scan through table looking for zombie children.", "// Found one.", "// No point waiting if we don't have any children.", "//freevm(proc->pgdir);", "//freevm(proc->pgdir);", "// Wait for children to exit. (See wakeup1 call in proc_exit.)", "//DOC: wait-sleep" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8ba05a8c0db822d7223f8c24d2f45672135352c6
TheRyanKing87/Kernel-threads
kernel/proc.c
[ "Xnet", "X11" ]
C
scheduler
void
void scheduler(void) { // put P2 stuff in here struct proc *p; struct proc *q; struct pstat processStat; int bookmarkPID = -1; int wokeUpNum = 0; for(;;){ // Enable interrupts on this processor. sti(); acquire(&ptable.lock); //if (numberOfPriority2 == 0) { //numberOfPriority2 = 0; wokeUpNum = 0; for(q = ptable.proc; q < &ptable.proc[NPROC]; q++){ if ((q->wokeUp == 1) && (q->priority == 2)) { wokeUpNum++; } } // Loop over process table looking for process to run. //acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != RUNNABLE) { continue; } else { //runnable if (p->priority != 2) { //not high priority if (bookmarkPID < 0) { //no bookmarks - start tracking bookmarkPID = p->pid; continue; } else if (bookmarkPID == p->pid) { //already have bookmark - run it bookmarkPID = -1; } } else if (p->priority == 2) { if (wokeUpNum > 0) { if (p->wokeUp == 0) { continue; } else if (p->wokeUp == 1) { p->wokeUp = 0; bookmarkPID = -1; //high priority } } else { if (p->wokeUp == 1) { p->wokeUp = 0; } bookmarkPID = -1; } } } // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. proc = p; int pid = p->pid; switchuvm(p); p->state = RUNNING; processStat.pid[pid] = pid; processStat.inuse[pid] = 1; swtch(&cpu->scheduler, proc->context); processStat.inuse[pid] = 0; switchkvm(); int priority = proc->priority; if (priority == 1) { p->lticks++; } if (priority == 2) { p->hticks++; } // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; } release(&ptable.lock); } }
// Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler.
Per-CPU process scheduler. Each CPU calls scheduler() after setting itself up. Scheduler never returns. It loops, doing: choose a process to run swtch to start running that process eventually that process transfers control via swtch back to the scheduler.
[ "Per", "-", "CPU", "process", "scheduler", ".", "Each", "CPU", "calls", "scheduler", "()", "after", "setting", "itself", "up", ".", "Scheduler", "never", "returns", ".", "It", "loops", "doing", ":", "choose", "a", "process", "to", "run", "swtch", "to", "start", "running", "that", "process", "eventually", "that", "process", "transfers", "control", "via", "swtch", "back", "to", "the", "scheduler", "." ]
void scheduler(void) { struct proc *p; struct proc *q; struct pstat processStat; int bookmarkPID = -1; int wokeUpNum = 0; for(;;){ sti(); acquire(&ptable.lock); wokeUpNum = 0; for(q = ptable.proc; q < &ptable.proc[NPROC]; q++){ if ((q->wokeUp == 1) && (q->priority == 2)) { wokeUpNum++; } } for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state != RUNNABLE) { continue; } else { if (p->priority != 2) { if (bookmarkPID < 0) { bookmarkPID = p->pid; continue; } else if (bookmarkPID == p->pid) { bookmarkPID = -1; } } else if (p->priority == 2) { if (wokeUpNum > 0) { if (p->wokeUp == 0) { continue; } else if (p->wokeUp == 1) { p->wokeUp = 0; bookmarkPID = -1; } } else { if (p->wokeUp == 1) { p->wokeUp = 0; } bookmarkPID = -1; } } } proc = p; int pid = p->pid; switchuvm(p); p->state = RUNNING; processStat.pid[pid] = pid; processStat.inuse[pid] = 1; swtch(&cpu->scheduler, proc->context); processStat.inuse[pid] = 0; switchkvm(); int priority = proc->priority; if (priority == 1) { p->lticks++; } if (priority == 2) { p->hticks++; } proc = 0; } release(&ptable.lock); } }
[ "void", "scheduler", "(", "void", ")", "{", "struct", "proc", "*", "p", ";", "struct", "proc", "*", "q", ";", "struct", "pstat", "processStat", ";", "int", "bookmarkPID", "=", "-1", ";", "int", "wokeUpNum", "=", "0", ";", "for", "(", ";", ";", ")", "{", "sti", "(", ")", ";", "acquire", "(", "&", "ptable", ".", "lock", ")", ";", "wokeUpNum", "=", "0", ";", "for", "(", "q", "=", "ptable", ".", "proc", ";", "q", "<", "&", "ptable", ".", "proc", "[", "NPROC", "]", ";", "q", "++", ")", "{", "if", "(", "(", "q", "->", "wokeUp", "==", "1", ")", "&&", "(", "q", "->", "priority", "==", "2", ")", ")", "{", "wokeUpNum", "++", ";", "}", "}", "for", "(", "p", "=", "ptable", ".", "proc", ";", "p", "<", "&", "ptable", ".", "proc", "[", "NPROC", "]", ";", "p", "++", ")", "{", "if", "(", "p", "->", "state", "!=", "RUNNABLE", ")", "{", "continue", ";", "}", "else", "{", "if", "(", "p", "->", "priority", "!=", "2", ")", "{", "if", "(", "bookmarkPID", "<", "0", ")", "{", "bookmarkPID", "=", "p", "->", "pid", ";", "continue", ";", "}", "else", "if", "(", "bookmarkPID", "==", "p", "->", "pid", ")", "{", "bookmarkPID", "=", "-1", ";", "}", "}", "else", "if", "(", "p", "->", "priority", "==", "2", ")", "{", "if", "(", "wokeUpNum", ">", "0", ")", "{", "if", "(", "p", "->", "wokeUp", "==", "0", ")", "{", "continue", ";", "}", "else", "if", "(", "p", "->", "wokeUp", "==", "1", ")", "{", "p", "->", "wokeUp", "=", "0", ";", "bookmarkPID", "=", "-1", ";", "}", "}", "else", "{", "if", "(", "p", "->", "wokeUp", "==", "1", ")", "{", "p", "->", "wokeUp", "=", "0", ";", "}", "bookmarkPID", "=", "-1", ";", "}", "}", "}", "proc", "=", "p", ";", "int", "pid", "=", "p", "->", "pid", ";", "switchuvm", "(", "p", ")", ";", "p", "->", "state", "=", "RUNNING", ";", "processStat", ".", "pid", "[", "pid", "]", "=", "pid", ";", "processStat", ".", "inuse", "[", "pid", "]", "=", "1", ";", "swtch", "(", "&", "cpu", "->", "scheduler", ",", "proc", "->", "context", ")", ";", "processStat", ".", "inuse", "[", "pid", "]", "=", "0", ";", "switchkvm", "(", ")", ";", "int", "priority", "=", "proc", "->", "priority", ";", "if", "(", "priority", "==", "1", ")", "{", "p", "->", "lticks", "++", ";", "}", "if", "(", "priority", "==", "2", ")", "{", "p", "->", "hticks", "++", ";", "}", "proc", "=", "0", ";", "}", "release", "(", "&", "ptable", ".", "lock", ")", ";", "}", "}" ]
Per-CPU process scheduler.
[ "Per", "-", "CPU", "process", "scheduler", "." ]
[ "// put P2 stuff in here", "// Enable interrupts on this processor.", "//if (numberOfPriority2 == 0) {", "//numberOfPriority2 = 0;", "// Loop over process table looking for process to run.", "//acquire(&ptable.lock);", "//runnable", "//not high priority", "//no bookmarks - start tracking", "//already have bookmark - run it", "//high priority", "// Switch to chosen process. It is the process's job", "// to release ptable.lock and then reacquire it", "// before jumping back to us.", "// Process is done running for now.", "// It should have changed its p->state before coming back." ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8ba05a8c0db822d7223f8c24d2f45672135352c6
TheRyanKing87/Kernel-threads
kernel/proc.c
[ "Xnet", "X11" ]
C
wakeup1
void
static void wakeup1(void *chan) { struct proc *p; for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) if(p->state == SLEEPING && p->chan == chan) { p->state = RUNNABLE; p->wokeUp = 1; //P2 } }
// Wake up all processes sleeping on chan. // The ptable lock must be held.
Wake up all processes sleeping on chan. The ptable lock must be held.
[ "Wake", "up", "all", "processes", "sleeping", "on", "chan", ".", "The", "ptable", "lock", "must", "be", "held", "." ]
static void wakeup1(void *chan) { struct proc *p; for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) if(p->state == SLEEPING && p->chan == chan) { p->state = RUNNABLE; p->wokeUp = 1; } }
[ "static", "void", "wakeup1", "(", "void", "*", "chan", ")", "{", "struct", "proc", "*", "p", ";", "for", "(", "p", "=", "ptable", ".", "proc", ";", "p", "<", "&", "ptable", ".", "proc", "[", "NPROC", "]", ";", "p", "++", ")", "if", "(", "p", "->", "state", "==", "SLEEPING", "&&", "p", "->", "chan", "==", "chan", ")", "{", "p", "->", "state", "=", "RUNNABLE", ";", "p", "->", "wokeUp", "=", "1", ";", "}", "}" ]
Wake up all processes sleeping on chan.
[ "Wake", "up", "all", "processes", "sleeping", "on", "chan", "." ]
[ "//P2" ]
[ { "param": "chan", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "chan", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
46b8c05c537b4d686da58719c82968b051e8c3b9
zrajani/Game_of_Life
Game of Life Project Files/source/cells.c
[ "MIT" ]
C
countLiveNeighbours
size_t
size_t countLiveNeighbours (size_t row, size_t col) { size_t cell_count = 0; for (size_t i = row - 1; i <= row + 1; i++) { for (size_t j = col - 1; j <= col + 1; j++) { // To make sure that you don't count the cell whose neighbours are counted if (i != 0 && j != 0) { cell_count = cell_count + (size_t) env[(i + config_NC) % config_NC][(j + config_MC)% config_MC]; //cell_count=(size_t)env[i-1][j-1]+(size_t)env[i-1][j]+(size_t)env[i-1][j+1]+(size_t)env[i][j-1]+ //(size_t)env[i][j+1]+(size_t)env[i+1][j-1]+(size_t)env[i+1][j]+(size_t)env[i+1][j+1]; } } } cell_count=cell_count - env[row][col]; return cell_count; }
/* * function counts the number of live neighbours of a cell located * at row r and column c of the env array * * for reference, neighbours are designated as follows: * a b c * d X e * f g h * * */
function counts the number of live neighbours of a cell located at row r and column c of the env array for reference, neighbours are designated as follows: a b c d X e f g h
[ "function", "counts", "the", "number", "of", "live", "neighbours", "of", "a", "cell", "located", "at", "row", "r", "and", "column", "c", "of", "the", "env", "array", "for", "reference", "neighbours", "are", "designated", "as", "follows", ":", "a", "b", "c", "d", "X", "e", "f", "g", "h" ]
size_t countLiveNeighbours (size_t row, size_t col) { size_t cell_count = 0; for (size_t i = row - 1; i <= row + 1; i++) { for (size_t j = col - 1; j <= col + 1; j++) { if (i != 0 && j != 0) { cell_count = cell_count + (size_t) env[(i + config_NC) % config_NC][(j + config_MC)% config_MC]; } } } cell_count=cell_count - env[row][col]; return cell_count; }
[ "size_t", "countLiveNeighbours", "(", "size_t", "row", ",", "size_t", "col", ")", "{", "size_t", "cell_count", "=", "0", ";", "for", "(", "size_t", "i", "=", "row", "-", "1", ";", "i", "<=", "row", "+", "1", ";", "i", "++", ")", "{", "for", "(", "size_t", "j", "=", "col", "-", "1", ";", "j", "<=", "col", "+", "1", ";", "j", "++", ")", "{", "if", "(", "i", "!=", "0", "&&", "j", "!=", "0", ")", "{", "cell_count", "=", "cell_count", "+", "(", "size_t", ")", "env", "[", "(", "i", "+", "config_NC", ")", "%", "config_NC", "]", "[", "(", "j", "+", "config_MC", ")", "%", "config_MC", "]", ";", "}", "}", "}", "cell_count", "=", "cell_count", "-", "env", "[", "row", "]", "[", "col", "]", ";", "return", "cell_count", ";", "}" ]
function counts the number of live neighbours of a cell located at row r and column c of the env array
[ "function", "counts", "the", "number", "of", "live", "neighbours", "of", "a", "cell", "located", "at", "row", "r", "and", "column", "c", "of", "the", "env", "array" ]
[ "// To make sure that you don't count the cell whose neighbours are counted", "//cell_count=(size_t)env[i-1][j-1]+(size_t)env[i-1][j]+(size_t)env[i-1][j+1]+(size_t)env[i][j-1]+", "//(size_t)env[i][j+1]+(size_t)env[i+1][j-1]+(size_t)env[i+1][j]+(size_t)env[i+1][j+1];" ]
[ { "param": "row", "type": "size_t" }, { "param": "col", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "row", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "col", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
46b8c05c537b4d686da58719c82968b051e8c3b9
zrajani/Game_of_Life
Game of Life Project Files/source/cells.c
[ "MIT" ]
C
updateCell
void
void updateCell (size_t r, size_t c) { cell_t state_cell = env[r][c]; size_t live_neighbours = countLiveNeighbours (r, c); if (state_cell == 0 && (live_neighbours == 3)) { update_env[r][c] = state_cell=live; } else if (state_cell == 1 && (live_neighbours > 3)) { update_env[r][c] =state_cell= dead; } else if (state_cell == 1 && (live_neighbours < 2)) { update_env[r][c] =state_cell= dead; } else { update_env[r][c]=state_cell; } }
/* * update cell located at row r and column c in env (indicated by X): * * a b c * d X e * f g h * * with nearest neighbours indicated as shown from a, b, ..., h. * * this function features Conway's rules: * - if a cell is dead but surrounded by exactly three live neighbours, it sprouts to life (birth) * - if a cell is live but has more than 4 live neighbours, it dies (overpopulation) * - if a cell is live but has fewer than 2 live neighbours, it dies (underpopulation) * - all other dead or live cells remain the same to the next generation (i.e., a live cell must * have exactly three neighbours to survive) * */
update cell located at row r and column c in env (indicated by X): a b c d X e f g h with nearest neighbours indicated as shown from a, b, ..., h. this function features Conway's rules: - if a cell is dead but surrounded by exactly three live neighbours, it sprouts to life (birth) - if a cell is live but has more than 4 live neighbours, it dies (overpopulation) - if a cell is live but has fewer than 2 live neighbours, it dies (underpopulation) - all other dead or live cells remain the same to the next generation
[ "update", "cell", "located", "at", "row", "r", "and", "column", "c", "in", "env", "(", "indicated", "by", "X", ")", ":", "a", "b", "c", "d", "X", "e", "f", "g", "h", "with", "nearest", "neighbours", "indicated", "as", "shown", "from", "a", "b", "...", "h", ".", "this", "function", "features", "Conway", "'", "s", "rules", ":", "-", "if", "a", "cell", "is", "dead", "but", "surrounded", "by", "exactly", "three", "live", "neighbours", "it", "sprouts", "to", "life", "(", "birth", ")", "-", "if", "a", "cell", "is", "live", "but", "has", "more", "than", "4", "live", "neighbours", "it", "dies", "(", "overpopulation", ")", "-", "if", "a", "cell", "is", "live", "but", "has", "fewer", "than", "2", "live", "neighbours", "it", "dies", "(", "underpopulation", ")", "-", "all", "other", "dead", "or", "live", "cells", "remain", "the", "same", "to", "the", "next", "generation" ]
void updateCell (size_t r, size_t c) { cell_t state_cell = env[r][c]; size_t live_neighbours = countLiveNeighbours (r, c); if (state_cell == 0 && (live_neighbours == 3)) { update_env[r][c] = state_cell=live; } else if (state_cell == 1 && (live_neighbours > 3)) { update_env[r][c] =state_cell= dead; } else if (state_cell == 1 && (live_neighbours < 2)) { update_env[r][c] =state_cell= dead; } else { update_env[r][c]=state_cell; } }
[ "void", "updateCell", "(", "size_t", "r", ",", "size_t", "c", ")", "{", "cell_t", "state_cell", "=", "env", "[", "r", "]", "[", "c", "]", ";", "size_t", "live_neighbours", "=", "countLiveNeighbours", "(", "r", ",", "c", ")", ";", "if", "(", "state_cell", "==", "0", "&&", "(", "live_neighbours", "==", "3", ")", ")", "{", "update_env", "[", "r", "]", "[", "c", "]", "=", "state_cell", "=", "live", ";", "}", "else", "if", "(", "state_cell", "==", "1", "&&", "(", "live_neighbours", ">", "3", ")", ")", "{", "update_env", "[", "r", "]", "[", "c", "]", "=", "state_cell", "=", "dead", ";", "}", "else", "if", "(", "state_cell", "==", "1", "&&", "(", "live_neighbours", "<", "2", ")", ")", "{", "update_env", "[", "r", "]", "[", "c", "]", "=", "state_cell", "=", "dead", ";", "}", "else", "{", "update_env", "[", "r", "]", "[", "c", "]", "=", "state_cell", ";", "}", "}" ]
update cell located at row r and column c in env (indicated by X): a b c d X e f g h
[ "update", "cell", "located", "at", "row", "r", "and", "column", "c", "in", "env", "(", "indicated", "by", "X", ")", ":", "a", "b", "c", "d", "X", "e", "f", "g", "h" ]
[]
[ { "param": "r", "type": "size_t" }, { "param": "c", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "r", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "c", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
46b8c05c537b4d686da58719c82968b051e8c3b9
zrajani/Game_of_Life
Game of Life Project Files/source/cells.c
[ "MIT" ]
C
initEnvironment
void
void initEnvironment (void) { // start by reading in a single community int token; cell_t datum; cell_t community_init[config_NC][config_MC]; printf ("\nInitializing environment...\n"); printf (" ... loading template community from stdin\n"); for (size_t i = 0; i != config_NC; ++i) { for (size_t j = 0; j != config_MC; ++j) { scanf ("%d", &token); datum = (cell_t) token; community_init[i][j] = datum; } } printf (" ... done.\n"); printf (" ... creating communities\n"); // copy this community to each community in env to initialize it for (size_t i = 0; i != config_K; ++i) { for (size_t j = 0; j != config_L; ++j) { transferCommunity (i, j, community_init); } } printf (" ... done.\n"); }
/* * seed environment on a community-by-community basis, * from standard input; we assume that the seed input is exactly * the size of a community; 9999 indicates end of file; * run this before started ncurses environment; */
seed environment on a community-by-community basis, from standard input; we assume that the seed input is exactly the size of a community; 9999 indicates end of file; run this before started ncurses environment.
[ "seed", "environment", "on", "a", "community", "-", "by", "-", "community", "basis", "from", "standard", "input", ";", "we", "assume", "that", "the", "seed", "input", "is", "exactly", "the", "size", "of", "a", "community", ";", "9999", "indicates", "end", "of", "file", ";", "run", "this", "before", "started", "ncurses", "environment", "." ]
void initEnvironment (void) { int token; cell_t datum; cell_t community_init[config_NC][config_MC]; printf ("\nInitializing environment...\n"); printf (" ... loading template community from stdin\n"); for (size_t i = 0; i != config_NC; ++i) { for (size_t j = 0; j != config_MC; ++j) { scanf ("%d", &token); datum = (cell_t) token; community_init[i][j] = datum; } } printf (" ... done.\n"); printf (" ... creating communities\n"); for (size_t i = 0; i != config_K; ++i) { for (size_t j = 0; j != config_L; ++j) { transferCommunity (i, j, community_init); } } printf (" ... done.\n"); }
[ "void", "initEnvironment", "(", "void", ")", "{", "int", "token", ";", "cell_t", "datum", ";", "cell_t", "community_init", "[", "config_NC", "]", "[", "config_MC", "]", ";", "printf", "(", "\"", "\\n", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "for", "(", "size_t", "i", "=", "0", ";", "i", "!=", "config_NC", ";", "++", "i", ")", "{", "for", "(", "size_t", "j", "=", "0", ";", "j", "!=", "config_MC", ";", "++", "j", ")", "{", "scanf", "(", "\"", "\"", ",", "&", "token", ")", ";", "datum", "=", "(", "cell_t", ")", "token", ";", "community_init", "[", "i", "]", "[", "j", "]", "=", "datum", ";", "}", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "for", "(", "size_t", "i", "=", "0", ";", "i", "!=", "config_K", ";", "++", "i", ")", "{", "for", "(", "size_t", "j", "=", "0", ";", "j", "!=", "config_L", ";", "++", "j", ")", "{", "transferCommunity", "(", "i", ",", "j", ",", "community_init", ")", ";", "}", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "}" ]
seed environment on a community-by-community basis, from standard input; we assume that the seed input is exactly the size of a community; 9999 indicates end of file; run this before started ncurses environment;
[ "seed", "environment", "on", "a", "community", "-", "by", "-", "community", "basis", "from", "standard", "input", ";", "we", "assume", "that", "the", "seed", "input", "is", "exactly", "the", "size", "of", "a", "community", ";", "9999", "indicates", "end", "of", "file", ";", "run", "this", "before", "started", "ncurses", "environment", ";" ]
[ "// start by reading in a single community", "// copy this community to each community in env to initialize it" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
46b8c05c537b4d686da58719c82968b051e8c3b9
zrajani/Game_of_Life
Game of Life Project Files/source/cells.c
[ "MIT" ]
C
copyEnvironment
void
void copyEnvironment (void) { // copy this community to each community in env to initialize it for (size_t i = 0; i != config_NE; ++i) { for (size_t j = 0; j != config_ME; ++j) { env[i][j] = update_env[i][j]; } } }
/* * write changes to the environment, env, from update_env */
write changes to the environment, env, from update_env
[ "write", "changes", "to", "the", "environment", "env", "from", "update_env" ]
void copyEnvironment (void) { for (size_t i = 0; i != config_NE; ++i) { for (size_t j = 0; j != config_ME; ++j) { env[i][j] = update_env[i][j]; } } }
[ "void", "copyEnvironment", "(", "void", ")", "{", "for", "(", "size_t", "i", "=", "0", ";", "i", "!=", "config_NE", ";", "++", "i", ")", "{", "for", "(", "size_t", "j", "=", "0", ";", "j", "!=", "config_ME", ";", "++", "j", ")", "{", "env", "[", "i", "]", "[", "j", "]", "=", "update_env", "[", "i", "]", "[", "j", "]", ";", "}", "}", "}" ]
write changes to the environment, env, from update_env
[ "write", "changes", "to", "the", "environment", "env", "from", "update_env" ]
[ "// copy this community to each community in env to initialize it" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
46b8c05c537b4d686da58719c82968b051e8c3b9
zrajani/Game_of_Life
Game of Life Project Files/source/cells.c
[ "MIT" ]
C
updateCommFunc
void
void* updateCommFunc (void *param) { while (1) { if (reproduction_flag) { threadID_t *var = param; size_t i_0 = var->row; size_t j_0 = var->col; size_t a = i_0 * config_NC; size_t b = j_0 * config_MC; for (size_t i = 0; i != config_NC; ++i) { for (size_t j = 0; j != config_MC; ++j) { updateCell (i+a, j+b); } } } } }
/* * this function updates all the cells for a thread (corresponding to one community) */
this function updates all the cells for a thread (corresponding to one community)
[ "this", "function", "updates", "all", "the", "cells", "for", "a", "thread", "(", "corresponding", "to", "one", "community", ")" ]
void* updateCommFunc (void *param) { while (1) { if (reproduction_flag) { threadID_t *var = param; size_t i_0 = var->row; size_t j_0 = var->col; size_t a = i_0 * config_NC; size_t b = j_0 * config_MC; for (size_t i = 0; i != config_NC; ++i) { for (size_t j = 0; j != config_MC; ++j) { updateCell (i+a, j+b); } } } } }
[ "void", "*", "updateCommFunc", "(", "void", "*", "param", ")", "{", "while", "(", "1", ")", "{", "if", "(", "reproduction_flag", ")", "{", "threadID_t", "*", "var", "=", "param", ";", "size_t", "i_0", "=", "var", "->", "row", ";", "size_t", "j_0", "=", "var", "->", "col", ";", "size_t", "a", "=", "i_0", "*", "config_NC", ";", "size_t", "b", "=", "j_0", "*", "config_MC", ";", "for", "(", "size_t", "i", "=", "0", ";", "i", "!=", "config_NC", ";", "++", "i", ")", "{", "for", "(", "size_t", "j", "=", "0", ";", "j", "!=", "config_MC", ";", "++", "j", ")", "{", "updateCell", "(", "i", "+", "a", ",", "j", "+", "b", ")", ";", "}", "}", "}", "}", "}" ]
this function updates all the cells for a thread (corresponding to one community)
[ "this", "function", "updates", "all", "the", "cells", "for", "a", "thread", "(", "corresponding", "to", "one", "community", ")" ]
[]
[ { "param": "param", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "param", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a47e3b3dd500225db60a4c367c3687497413467c
Afterback/Deadrop
engine/core/math/matrix4x4.h
[ "Zlib" ]
C
GetTranspose
Matrix4x4
Matrix4x4 GetTranspose() { Matrix4x4 temp = {}; for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { temp.mat[i][j] = mat[j][i]; } } return temp; }
// returns the transpose of the matrix
returns the transpose of the matrix
[ "returns", "the", "transpose", "of", "the", "matrix" ]
Matrix4x4 GetTranspose() { Matrix4x4 temp = {}; for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { temp.mat[i][j] = mat[j][i]; } } return temp; }
[ "Matrix4x4", "GetTranspose", "(", ")", "{", "Matrix4x4", "temp", "=", "{", "}", ";", "for", "(", "size_t", "i", "=", "0", ";", "i", "<", "4", ";", "i", "++", ")", "{", "for", "(", "size_t", "j", "=", "0", ";", "j", "<", "4", ";", "j", "++", ")", "{", "temp", ".", "mat", "[", "i", "]", "[", "j", "]", "=", "mat", "[", "j", "]", "[", "i", "]", ";", "}", "}", "return", "temp", ";", "}" ]
returns the transpose of the matrix
[ "returns", "the", "transpose", "of", "the", "matrix" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
137eeb80bad3c367df0bfe714500949c52014de9
arthurfeeney/Marley-Accel
src/loading_util.c
[ "MIT" ]
C
load_config
int
int load_config(accel_settings_t *as, const char *config_path) { FILE *config = fopen(config_path, "r"); char line[CONFIG_LINE_LENGTH]; while (fgets(line, sizeof(line), config) != NULL) { make_lowercase(line); remove_spaces(line); remove_comments(line); int err = assign_settings(line, as); if (err) { return err; } } // default to quake accel if nothing specified. if (!as->accel) { as->accel = quake_accel; } fclose(config); return 0; }
/** * Load users accel settings from the specified configuration file. * This will automatically perform some cleaning to the config file and remove * comments */
Load users accel settings from the specified configuration file. This will automatically perform some cleaning to the config file and remove comments
[ "Load", "users", "accel", "settings", "from", "the", "specified", "configuration", "file", ".", "This", "will", "automatically", "perform", "some", "cleaning", "to", "the", "config", "file", "and", "remove", "comments" ]
int load_config(accel_settings_t *as, const char *config_path) { FILE *config = fopen(config_path, "r"); char line[CONFIG_LINE_LENGTH]; while (fgets(line, sizeof(line), config) != NULL) { make_lowercase(line); remove_spaces(line); remove_comments(line); int err = assign_settings(line, as); if (err) { return err; } } if (!as->accel) { as->accel = quake_accel; } fclose(config); return 0; }
[ "int", "load_config", "(", "accel_settings_t", "*", "as", ",", "const", "char", "*", "config_path", ")", "{", "FILE", "*", "config", "=", "fopen", "(", "config_path", ",", "\"", "\"", ")", ";", "char", "line", "[", "CONFIG_LINE_LENGTH", "]", ";", "while", "(", "fgets", "(", "line", ",", "sizeof", "(", "line", ")", ",", "config", ")", "!=", "NULL", ")", "{", "make_lowercase", "(", "line", ")", ";", "remove_spaces", "(", "line", ")", ";", "remove_comments", "(", "line", ")", ";", "int", "err", "=", "assign_settings", "(", "line", ",", "as", ")", ";", "if", "(", "err", ")", "{", "return", "err", ";", "}", "}", "if", "(", "!", "as", "->", "accel", ")", "{", "as", "->", "accel", "=", "quake_accel", ";", "}", "fclose", "(", "config", ")", ";", "return", "0", ";", "}" ]
Load users accel settings from the specified configuration file.
[ "Load", "users", "accel", "settings", "from", "the", "specified", "configuration", "file", "." ]
[ "// default to quake accel if nothing specified." ]
[ { "param": "as", "type": "accel_settings_t" }, { "param": "config_path", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "as", "type": "accel_settings_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "config_path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
137eeb80bad3c367df0bfe714500949c52014de9
arthurfeeney/Marley-Accel
src/loading_util.c
[ "MIT" ]
C
dev_setup
int
int dev_setup(mouse_dev_t *dev) { int err = libusb_init(&dev->usb_ctx); if (err) { return err; } // find the device using the vendor and product ids. // These can be found using the "usb-devices" command in the terminal. dev->usb_handle = libusb_open_device_with_vid_pid( dev->usb_ctx, dev->vendor_id, dev->product_id); if (!dev->usb_handle) { printf("Marley-Accel: Device not found, try running with sudo.\n"); return -1; } // after an error, on restart the driver may not be attached. So, // we make sure that it is attached. // If driver is already attached, this has no effect. libusb_attach_kernel_driver(dev->usb_handle, dev->interface); if (libusb_kernel_driver_active(dev->usb_handle, dev->interface) == 1) { err = libusb_detach_kernel_driver(dev->usb_handle, dev->interface); if (err != 0) { libusb_errmsg("Failed to detach kernel driver.\n", err); return err; } dev->usb_detached = true; } else { printf("Marley-Accel: Device does not have an attached driver.\n"); printf("Marley-Accel: May not have been reattached after prior run.\n"); return -1; } if ((err = libusb_claim_interface(dev->usb_handle, dev->interface)) != 0) { libusb_errmsg("Marley-Accel: Failed to claim device interface.\n", err); return err; } dev->usb_claimed = true; return 0; }
/** * Device setup. This connects to usb mouse device using libusb. Detaches the * kernel driver and claims the device. */
Device setup. This connects to usb mouse device using libusb. Detaches the kernel driver and claims the device.
[ "Device", "setup", ".", "This", "connects", "to", "usb", "mouse", "device", "using", "libusb", ".", "Detaches", "the", "kernel", "driver", "and", "claims", "the", "device", "." ]
int dev_setup(mouse_dev_t *dev) { int err = libusb_init(&dev->usb_ctx); if (err) { return err; } dev->usb_handle = libusb_open_device_with_vid_pid( dev->usb_ctx, dev->vendor_id, dev->product_id); if (!dev->usb_handle) { printf("Marley-Accel: Device not found, try running with sudo.\n"); return -1; } libusb_attach_kernel_driver(dev->usb_handle, dev->interface); if (libusb_kernel_driver_active(dev->usb_handle, dev->interface) == 1) { err = libusb_detach_kernel_driver(dev->usb_handle, dev->interface); if (err != 0) { libusb_errmsg("Failed to detach kernel driver.\n", err); return err; } dev->usb_detached = true; } else { printf("Marley-Accel: Device does not have an attached driver.\n"); printf("Marley-Accel: May not have been reattached after prior run.\n"); return -1; } if ((err = libusb_claim_interface(dev->usb_handle, dev->interface)) != 0) { libusb_errmsg("Marley-Accel: Failed to claim device interface.\n", err); return err; } dev->usb_claimed = true; return 0; }
[ "int", "dev_setup", "(", "mouse_dev_t", "*", "dev", ")", "{", "int", "err", "=", "libusb_init", "(", "&", "dev", "->", "usb_ctx", ")", ";", "if", "(", "err", ")", "{", "return", "err", ";", "}", "dev", "->", "usb_handle", "=", "libusb_open_device_with_vid_pid", "(", "dev", "->", "usb_ctx", ",", "dev", "->", "vendor_id", ",", "dev", "->", "product_id", ")", ";", "if", "(", "!", "dev", "->", "usb_handle", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "-1", ";", "}", "libusb_attach_kernel_driver", "(", "dev", "->", "usb_handle", ",", "dev", "->", "interface", ")", ";", "if", "(", "libusb_kernel_driver_active", "(", "dev", "->", "usb_handle", ",", "dev", "->", "interface", ")", "==", "1", ")", "{", "err", "=", "libusb_detach_kernel_driver", "(", "dev", "->", "usb_handle", ",", "dev", "->", "interface", ")", ";", "if", "(", "err", "!=", "0", ")", "{", "libusb_errmsg", "(", "\"", "\\n", "\"", ",", "err", ")", ";", "return", "err", ";", "}", "dev", "->", "usb_detached", "=", "true", ";", "}", "else", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "-1", ";", "}", "if", "(", "(", "err", "=", "libusb_claim_interface", "(", "dev", "->", "usb_handle", ",", "dev", "->", "interface", ")", ")", "!=", "0", ")", "{", "libusb_errmsg", "(", "\"", "\\n", "\"", ",", "err", ")", ";", "return", "err", ";", "}", "dev", "->", "usb_claimed", "=", "true", ";", "return", "0", ";", "}" ]
Device setup.
[ "Device", "setup", "." ]
[ "// find the device using the vendor and product ids.", "// These can be found using the \"usb-devices\" command in the terminal.", "// after an error, on restart the driver may not be attached. So,", "// we make sure that it is attached.", "// If driver is already attached, this has no effect." ]
[ { "param": "dev", "type": "mouse_dev_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dev", "type": "mouse_dev_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
137eeb80bad3c367df0bfe714500949c52014de9
arthurfeeney/Marley-Accel
src/loading_util.c
[ "MIT" ]
C
create_input_device
int
int create_input_device(uint16_t vendor_id, uint16_t product_id) { int err; const int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (fd < 0) { errmsg("Failed to open uinput", fd); return fd; } create_bindings(fd); err = initialize_device(fd, vendor_id, product_id); if (err < 0) { errmsg("Failed to write uinput device description", err); return err; } err = ioctl(fd, UI_DEV_CREATE); if (err < 0) { errmsg("Failed to ioctl UI_DEV_CREATE", err); return err; } return fd; }
/** * Creates uinput driver for the mouse with vendor_id and product_id. * These values are part of the mouse settings. */
Creates uinput driver for the mouse with vendor_id and product_id. These values are part of the mouse settings.
[ "Creates", "uinput", "driver", "for", "the", "mouse", "with", "vendor_id", "and", "product_id", ".", "These", "values", "are", "part", "of", "the", "mouse", "settings", "." ]
int create_input_device(uint16_t vendor_id, uint16_t product_id) { int err; const int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (fd < 0) { errmsg("Failed to open uinput", fd); return fd; } create_bindings(fd); err = initialize_device(fd, vendor_id, product_id); if (err < 0) { errmsg("Failed to write uinput device description", err); return err; } err = ioctl(fd, UI_DEV_CREATE); if (err < 0) { errmsg("Failed to ioctl UI_DEV_CREATE", err); return err; } return fd; }
[ "int", "create_input_device", "(", "uint16_t", "vendor_id", ",", "uint16_t", "product_id", ")", "{", "int", "err", ";", "const", "int", "fd", "=", "open", "(", "\"", "\"", ",", "O_WRONLY", "|", "O_NONBLOCK", ")", ";", "if", "(", "fd", "<", "0", ")", "{", "errmsg", "(", "\"", "\"", ",", "fd", ")", ";", "return", "fd", ";", "}", "create_bindings", "(", "fd", ")", ";", "err", "=", "initialize_device", "(", "fd", ",", "vendor_id", ",", "product_id", ")", ";", "if", "(", "err", "<", "0", ")", "{", "errmsg", "(", "\"", "\"", ",", "err", ")", ";", "return", "err", ";", "}", "err", "=", "ioctl", "(", "fd", ",", "UI_DEV_CREATE", ")", ";", "if", "(", "err", "<", "0", ")", "{", "errmsg", "(", "\"", "\"", ",", "err", ")", ";", "return", "err", ";", "}", "return", "fd", ";", "}" ]
Creates uinput driver for the mouse with vendor_id and product_id.
[ "Creates", "uinput", "driver", "for", "the", "mouse", "with", "vendor_id", "and", "product_id", "." ]
[]
[ { "param": "vendor_id", "type": "uint16_t" }, { "param": "product_id", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "vendor_id", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "product_id", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
137eeb80bad3c367df0bfe714500949c52014de9
arthurfeeney/Marley-Accel
src/loading_util.c
[ "MIT" ]
C
remove_spaces
void
static void remove_spaces(char *line) { for (int idx = 0; idx < CONFIG_LINE_LENGTH && line[idx] != '\0'; ++idx) { // shift text over to remove space. if (isspace(line[idx])) { for (int shift = idx; shift < CONFIG_LINE_LENGTH && line[shift] != '\0'; ++shift) { line[shift] = line[shift + 1]; } } } }
/** * Remove all spaces from the line string. The config files are small. This can * be done efficiently enough by shifting text to cover spaces in-place. */
Remove all spaces from the line string. The config files are small. This can be done efficiently enough by shifting text to cover spaces in-place.
[ "Remove", "all", "spaces", "from", "the", "line", "string", ".", "The", "config", "files", "are", "small", ".", "This", "can", "be", "done", "efficiently", "enough", "by", "shifting", "text", "to", "cover", "spaces", "in", "-", "place", "." ]
static void remove_spaces(char *line) { for (int idx = 0; idx < CONFIG_LINE_LENGTH && line[idx] != '\0'; ++idx) { if (isspace(line[idx])) { for (int shift = idx; shift < CONFIG_LINE_LENGTH && line[shift] != '\0'; ++shift) { line[shift] = line[shift + 1]; } } } }
[ "static", "void", "remove_spaces", "(", "char", "*", "line", ")", "{", "for", "(", "int", "idx", "=", "0", ";", "idx", "<", "CONFIG_LINE_LENGTH", "&&", "line", "[", "idx", "]", "!=", "'", "\\0", "'", ";", "++", "idx", ")", "{", "if", "(", "isspace", "(", "line", "[", "idx", "]", ")", ")", "{", "for", "(", "int", "shift", "=", "idx", ";", "shift", "<", "CONFIG_LINE_LENGTH", "&&", "line", "[", "shift", "]", "!=", "'", "\\0", "'", ";", "++", "shift", ")", "{", "line", "[", "shift", "]", "=", "line", "[", "shift", "+", "1", "]", ";", "}", "}", "}", "}" ]
Remove all spaces from the line string.
[ "Remove", "all", "spaces", "from", "the", "line", "string", "." ]
[ "// shift text over to remove space." ]
[ { "param": "line", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "line", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
137eeb80bad3c367df0bfe714500949c52014de9
arthurfeeney/Marley-Accel
src/loading_util.c
[ "MIT" ]
C
remove_comments
void
static void remove_comments(char *line) { for (int idx = 0; idx < CONFIG_LINE_LENGTH; ++idx) { if (line[idx] == '#') { line[idx] = '\0'; } } }
/** * Remove comments from a line in a config file * This is done by Replace '#' with end of string. */
Remove comments from a line in a config file This is done by Replace '#' with end of string.
[ "Remove", "comments", "from", "a", "line", "in", "a", "config", "file", "This", "is", "done", "by", "Replace", "'", "#", "'", "with", "end", "of", "string", "." ]
static void remove_comments(char *line) { for (int idx = 0; idx < CONFIG_LINE_LENGTH; ++idx) { if (line[idx] == '#') { line[idx] = '\0'; } } }
[ "static", "void", "remove_comments", "(", "char", "*", "line", ")", "{", "for", "(", "int", "idx", "=", "0", ";", "idx", "<", "CONFIG_LINE_LENGTH", ";", "++", "idx", ")", "{", "if", "(", "line", "[", "idx", "]", "==", "'", "'", ")", "{", "line", "[", "idx", "]", "=", "'", "\\0", "'", ";", "}", "}", "}" ]
Remove comments from a line in a config file This is done by Replace '#' with end of string.
[ "Remove", "comments", "from", "a", "line", "in", "a", "config", "file", "This", "is", "done", "by", "Replace", "'", "#", "'", "with", "end", "of", "string", "." ]
[]
[ { "param": "line", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "line", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c683559ae7122aa5be57f97af652ae02b580e006
qq476743842/weex-saoa
platforms/ios/plus/Pods/SSLunarDate/SSLunarDate/libLunar.c
[ "MIT" ]
C
Solar2Day1
null
long Solar2Day1(SSLunarSimpleDate *d) { long offset, delta; int i; delta = d->year - BYEAR; if (delta<0) Error("Internal error: pick a larger constant for BYEAR."); offset = delta * 365 + delta / 4 - delta / 100 + delta / 400; for (i=1; i< d->month; i++) offset += daysInSolarMonth[i]; if ((d->month > 2) && LeapYear(d->year)) offset++; offset += d->day - 1; if ((d->month == 2) && LeapYear(d->year)) { if (d->day > 29) Error("Day out of range."); } else if (d->day > daysInSolarMonth[d->month]) Error("Day out of range."); return offset; }
/* Compute the number of days from the Solar date BYEAR.1.1 */
Compute the number of days from the Solar date BYEAR.1.1
[ "Compute", "the", "number", "of", "days", "from", "the", "Solar", "date", "BYEAR", ".", "1", ".", "1" ]
long Solar2Day1(SSLunarSimpleDate *d) { long offset, delta; int i; delta = d->year - BYEAR; if (delta<0) Error("Internal error: pick a larger constant for BYEAR."); offset = delta * 365 + delta / 4 - delta / 100 + delta / 400; for (i=1; i< d->month; i++) offset += daysInSolarMonth[i]; if ((d->month > 2) && LeapYear(d->year)) offset++; offset += d->day - 1; if ((d->month == 2) && LeapYear(d->year)) { if (d->day > 29) Error("Day out of range."); } else if (d->day > daysInSolarMonth[d->month]) Error("Day out of range."); return offset; }
[ "long", "Solar2Day1", "(", "SSLunarSimpleDate", "*", "d", ")", "{", "long", "offset", ",", "delta", ";", "int", "i", ";", "delta", "=", "d", "->", "year", "-", "BYEAR", ";", "if", "(", "delta", "<", "0", ")", "Error", "(", "\"", "\"", ")", ";", "offset", "=", "delta", "*", "365", "+", "delta", "/", "4", "-", "delta", "/", "100", "+", "delta", "/", "400", ";", "for", "(", "i", "=", "1", ";", "i", "<", "d", "->", "month", ";", "i", "++", ")", "offset", "+=", "daysInSolarMonth", "[", "i", "]", ";", "if", "(", "(", "d", "->", "month", ">", "2", ")", "&&", "LeapYear", "(", "d", "->", "year", ")", ")", "offset", "++", ";", "offset", "+=", "d", "->", "day", "-", "1", ";", "if", "(", "(", "d", "->", "month", "==", "2", ")", "&&", "LeapYear", "(", "d", "->", "year", ")", ")", "{", "if", "(", "d", "->", "day", ">", "29", ")", "Error", "(", "\"", "\"", ")", ";", "}", "else", "if", "(", "d", "->", "day", ">", "daysInSolarMonth", "[", "d", "->", "month", "]", ")", "Error", "(", "\"", "\"", ")", ";", "return", "offset", ";", "}" ]
Compute the number of days from the Solar date BYEAR.1.1
[ "Compute", "the", "number", "of", "days", "from", "the", "Solar", "date", "BYEAR", ".", "1", ".", "1" ]
[]
[ { "param": "d", "type": "SSLunarSimpleDate" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "d", "type": "SSLunarSimpleDate", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c683559ae7122aa5be57f97af652ae02b580e006
qq476743842/weex-saoa
platforms/ios/plus/Pods/SSLunarDate/SSLunarDate/libLunar.c
[ "MIT" ]
C
Lunar2Day
null
long Lunar2Day(LibLunarContext *ctx, SSLunarSimpleDate *d) { long offset = 0; int year, i, m, leapMonth; year = d->year - LunarFirstDate.year; for (i=0; i<year; i++) offset += ctx->_yday[i]; leapMonth = make_mday(ctx, year); if ((d->leap) && (leapMonth!=d->month)) { printf("%d is not a leap month in year %d.\n", d->month, d->year); exit(1); } for (m=1; m<d->month; m++) offset += ctx->_mday[m]; if (leapMonth && ((d->month>leapMonth) || (d->leap && (d->month==leapMonth)))) offset += ctx->_mday[m++]; offset += d->day - 1; if (d->day > ctx->_mday[m]) Error("Day out of range."); return offset; }
/* Compute offset days of a lunar date from the beginning of the table */
Compute offset days of a lunar date from the beginning of the table
[ "Compute", "offset", "days", "of", "a", "lunar", "date", "from", "the", "beginning", "of", "the", "table" ]
long Lunar2Day(LibLunarContext *ctx, SSLunarSimpleDate *d) { long offset = 0; int year, i, m, leapMonth; year = d->year - LunarFirstDate.year; for (i=0; i<year; i++) offset += ctx->_yday[i]; leapMonth = make_mday(ctx, year); if ((d->leap) && (leapMonth!=d->month)) { printf("%d is not a leap month in year %d.\n", d->month, d->year); exit(1); } for (m=1; m<d->month; m++) offset += ctx->_mday[m]; if (leapMonth && ((d->month>leapMonth) || (d->leap && (d->month==leapMonth)))) offset += ctx->_mday[m++]; offset += d->day - 1; if (d->day > ctx->_mday[m]) Error("Day out of range."); return offset; }
[ "long", "Lunar2Day", "(", "LibLunarContext", "*", "ctx", ",", "SSLunarSimpleDate", "*", "d", ")", "{", "long", "offset", "=", "0", ";", "int", "year", ",", "i", ",", "m", ",", "leapMonth", ";", "year", "=", "d", "->", "year", "-", "LunarFirstDate", ".", "year", ";", "for", "(", "i", "=", "0", ";", "i", "<", "year", ";", "i", "++", ")", "offset", "+=", "ctx", "->", "_yday", "[", "i", "]", ";", "leapMonth", "=", "make_mday", "(", "ctx", ",", "year", ")", ";", "if", "(", "(", "d", "->", "leap", ")", "&&", "(", "leapMonth", "!=", "d", "->", "month", ")", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "d", "->", "month", ",", "d", "->", "year", ")", ";", "exit", "(", "1", ")", ";", "}", "for", "(", "m", "=", "1", ";", "m", "<", "d", "->", "month", ";", "m", "++", ")", "offset", "+=", "ctx", "->", "_mday", "[", "m", "]", ";", "if", "(", "leapMonth", "&&", "(", "(", "d", "->", "month", ">", "leapMonth", ")", "||", "(", "d", "->", "leap", "&&", "(", "d", "->", "month", "==", "leapMonth", ")", ")", ")", ")", "offset", "+=", "ctx", "->", "_mday", "[", "m", "++", "]", ";", "offset", "+=", "d", "->", "day", "-", "1", ";", "if", "(", "d", "->", "day", ">", "ctx", "->", "_mday", "[", "m", "]", ")", "Error", "(", "\"", "\"", ")", ";", "return", "offset", ";", "}" ]
Compute offset days of a lunar date from the beginning of the table
[ "Compute", "offset", "days", "of", "a", "lunar", "date", "from", "the", "beginning", "of", "the", "table" ]
[]
[ { "param": "ctx", "type": "LibLunarContext" }, { "param": "d", "type": "SSLunarSimpleDate" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "LibLunarContext", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "d", "type": "SSLunarSimpleDate", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c683559ae7122aa5be57f97af652ae02b580e006
qq476743842/weex-saoa
platforms/ios/plus/Pods/SSLunarDate/SSLunarDate/libLunar.c
[ "MIT" ]
C
JieDate
int
int JieDate(SSLunarSimpleDate *ds, SSLunarSimpleDate *dl) { int m, flag; if (ds->month==1) { flag = CmpDate(ds->month, ds->day, 1, fest[ds->year - SolarFirstDate.year - 1][11]); if (flag<0) dl->month = 11; else if (flag>0) dl->month = 12; dl->year = ds->year - 1; return(flag==0); } for (m=2; m<=12; m++) { flag = CmpDate(ds->month, ds->day, m, fest[ds->year - SolarFirstDate.year][m-2]); if (flag==0) m++; if (flag<=0) break; } dl->month = (m-2) % 12; dl->year = ds->year; if ((dl->month)==0) { dl->year = ds->year - 1; dl->month = 12; } return(flag==0); }
/* Given a solar date, find the "lunar" date for the purpose of calculating the "4-columns" by taking jie into consideration. */
Given a solar date, find the "lunar" date for the purpose of calculating the "4-columns" by taking jie into consideration.
[ "Given", "a", "solar", "date", "find", "the", "\"", "lunar", "\"", "date", "for", "the", "purpose", "of", "calculating", "the", "\"", "4", "-", "columns", "\"", "by", "taking", "jie", "into", "consideration", "." ]
int JieDate(SSLunarSimpleDate *ds, SSLunarSimpleDate *dl) { int m, flag; if (ds->month==1) { flag = CmpDate(ds->month, ds->day, 1, fest[ds->year - SolarFirstDate.year - 1][11]); if (flag<0) dl->month = 11; else if (flag>0) dl->month = 12; dl->year = ds->year - 1; return(flag==0); } for (m=2; m<=12; m++) { flag = CmpDate(ds->month, ds->day, m, fest[ds->year - SolarFirstDate.year][m-2]); if (flag==0) m++; if (flag<=0) break; } dl->month = (m-2) % 12; dl->year = ds->year; if ((dl->month)==0) { dl->year = ds->year - 1; dl->month = 12; } return(flag==0); }
[ "int", "JieDate", "(", "SSLunarSimpleDate", "*", "ds", ",", "SSLunarSimpleDate", "*", "dl", ")", "{", "int", "m", ",", "flag", ";", "if", "(", "ds", "->", "month", "==", "1", ")", "{", "flag", "=", "CmpDate", "(", "ds", "->", "month", ",", "ds", "->", "day", ",", "1", ",", "fest", "[", "ds", "->", "year", "-", "SolarFirstDate", ".", "year", "-", "1", "]", "[", "11", "]", ")", ";", "if", "(", "flag", "<", "0", ")", "dl", "->", "month", "=", "11", ";", "else", "if", "(", "flag", ">", "0", ")", "dl", "->", "month", "=", "12", ";", "dl", "->", "year", "=", "ds", "->", "year", "-", "1", ";", "return", "(", "flag", "==", "0", ")", ";", "}", "for", "(", "m", "=", "2", ";", "m", "<=", "12", ";", "m", "++", ")", "{", "flag", "=", "CmpDate", "(", "ds", "->", "month", ",", "ds", "->", "day", ",", "m", ",", "fest", "[", "ds", "->", "year", "-", "SolarFirstDate", ".", "year", "]", "[", "m", "-", "2", "]", ")", ";", "if", "(", "flag", "==", "0", ")", "m", "++", ";", "if", "(", "flag", "<=", "0", ")", "break", ";", "}", "dl", "->", "month", "=", "(", "m", "-", "2", ")", "%", "12", ";", "dl", "->", "year", "=", "ds", "->", "year", ";", "if", "(", "(", "dl", "->", "month", ")", "==", "0", ")", "{", "dl", "->", "year", "=", "ds", "->", "year", "-", "1", ";", "dl", "->", "month", "=", "12", ";", "}", "return", "(", "flag", "==", "0", ")", ";", "}" ]
Given a solar date, find the "lunar" date for the purpose of calculating the "4-columns" by taking jie into consideration.
[ "Given", "a", "solar", "date", "find", "the", "\"", "lunar", "\"", "date", "for", "the", "purpose", "of", "calculating", "the", "\"", "4", "-", "columns", "\"", "by", "taking", "jie", "into", "consideration", "." ]
[]
[ { "param": "ds", "type": "SSLunarSimpleDate" }, { "param": "dl", "type": "SSLunarSimpleDate" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ds", "type": "SSLunarSimpleDate", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dl", "type": "SSLunarSimpleDate", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c683559ae7122aa5be57f97af652ae02b580e006
qq476743842/weex-saoa
platforms/ios/plus/Pods/SSLunarDate/SSLunarDate/libLunar.c
[ "MIT" ]
C
make_yday
int
int make_yday(LibLunarContext *ctx) { int year, i, leap; long code; for (year = 0; year < Nyear; year++) { code = yearInfo[year]; leap = code & 0xf; ctx->_yday[year] = 0; if (leap != 0) { i = (code >> 16) & 0x1; ctx->_yday[year] += moon[i]; /* Big month or small month.... got it. Leap month only * have two day, big month or small month. */ } code >>= 4; for (i = 0; i < Nmonth-1; i++) { /* 12 months. */ ctx->_yday[year] += moon[code&0x1]; code >>= 1; } ctx->_ymonth[year] = 12; if (leap != 0) ctx->_ymonth[year]++; } return Nyear; }
/* Compute the number of days in each lunar year in the table */
Compute the number of days in each lunar year in the table
[ "Compute", "the", "number", "of", "days", "in", "each", "lunar", "year", "in", "the", "table" ]
int make_yday(LibLunarContext *ctx) { int year, i, leap; long code; for (year = 0; year < Nyear; year++) { code = yearInfo[year]; leap = code & 0xf; ctx->_yday[year] = 0; if (leap != 0) { i = (code >> 16) & 0x1; ctx->_yday[year] += moon[i]; } code >>= 4; for (i = 0; i < Nmonth-1; i++) { ctx->_yday[year] += moon[code&0x1]; code >>= 1; } ctx->_ymonth[year] = 12; if (leap != 0) ctx->_ymonth[year]++; } return Nyear; }
[ "int", "make_yday", "(", "LibLunarContext", "*", "ctx", ")", "{", "int", "year", ",", "i", ",", "leap", ";", "long", "code", ";", "for", "(", "year", "=", "0", ";", "year", "<", "Nyear", ";", "year", "++", ")", "{", "code", "=", "yearInfo", "[", "year", "]", ";", "leap", "=", "code", "&", "0xf", ";", "ctx", "->", "_yday", "[", "year", "]", "=", "0", ";", "if", "(", "leap", "!=", "0", ")", "{", "i", "=", "(", "code", ">>", "16", ")", "&", "0x1", ";", "ctx", "->", "_yday", "[", "year", "]", "+=", "moon", "[", "i", "]", ";", "}", "code", ">>=", "4", ";", "for", "(", "i", "=", "0", ";", "i", "<", "Nmonth", "-", "1", ";", "i", "++", ")", "{", "ctx", "->", "_yday", "[", "year", "]", "+=", "moon", "[", "code", "&", "0x1", "]", ";", "code", ">>=", "1", ";", "}", "ctx", "->", "_ymonth", "[", "year", "]", "=", "12", ";", "if", "(", "leap", "!=", "0", ")", "ctx", "->", "_ymonth", "[", "year", "]", "++", ";", "}", "return", "Nyear", ";", "}" ]
Compute the number of days in each lunar year in the table
[ "Compute", "the", "number", "of", "days", "in", "each", "lunar", "year", "in", "the", "table" ]
[ "/* Big month or small month.... got it. Leap month only\n * have two day, big month or small month. */", "/* 12 months. */" ]
[ { "param": "ctx", "type": "LibLunarContext" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "LibLunarContext", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c683559ae7122aa5be57f97af652ae02b580e006
qq476743842/weex-saoa
platforms/ios/plus/Pods/SSLunarDate/SSLunarDate/libLunar.c
[ "MIT" ]
C
make_mday
int
int make_mday(LibLunarContext *ctx, int year) { int i, leapMonth; long code; code = yearInfo[year]; leapMonth = code & 0xf; /* leapMonth == 0 means no leap month */ code >>= 4; if (leapMonth == 0) { ctx->_mday[Nmonth] = 0; for (i = Nmonth-1; i >= 1; i--) { ctx->_mday[i] = moon[code&0x1]; code >>= 1; } } else { /* There is a leap month (run4 yue4) L in this year. mday[1] contains the number of days in the 1-st month; mday[L] contains the number of days in the L-th month; mday[L+1] contains the number of days in the L-th leap month; mday[L+2] contains the number of days in the L+1 month, etc. cf. yearInfo[]: info about the leap month is encoded differently. */ i = (yearInfo[year] >> 16) & 0x1; ctx->_mday[leapMonth+1] = moon[i]; for (i = Nmonth; i >= 1; i--) { if (i == leapMonth+1) i--; ctx->_mday[i] = moon[code&0x1]; code >>= 1; } } return leapMonth; }
/* Compute the days of each month in the given lunar year */
Compute the days of each month in the given lunar year
[ "Compute", "the", "days", "of", "each", "month", "in", "the", "given", "lunar", "year" ]
int make_mday(LibLunarContext *ctx, int year) { int i, leapMonth; long code; code = yearInfo[year]; leapMonth = code & 0xf; code >>= 4; if (leapMonth == 0) { ctx->_mday[Nmonth] = 0; for (i = Nmonth-1; i >= 1; i--) { ctx->_mday[i] = moon[code&0x1]; code >>= 1; } } else { i = (yearInfo[year] >> 16) & 0x1; ctx->_mday[leapMonth+1] = moon[i]; for (i = Nmonth; i >= 1; i--) { if (i == leapMonth+1) i--; ctx->_mday[i] = moon[code&0x1]; code >>= 1; } } return leapMonth; }
[ "int", "make_mday", "(", "LibLunarContext", "*", "ctx", ",", "int", "year", ")", "{", "int", "i", ",", "leapMonth", ";", "long", "code", ";", "code", "=", "yearInfo", "[", "year", "]", ";", "leapMonth", "=", "code", "&", "0xf", ";", "code", ">>=", "4", ";", "if", "(", "leapMonth", "==", "0", ")", "{", "ctx", "->", "_mday", "[", "Nmonth", "]", "=", "0", ";", "for", "(", "i", "=", "Nmonth", "-", "1", ";", "i", ">=", "1", ";", "i", "--", ")", "{", "ctx", "->", "_mday", "[", "i", "]", "=", "moon", "[", "code", "&", "0x1", "]", ";", "code", ">>=", "1", ";", "}", "}", "else", "{", "i", "=", "(", "yearInfo", "[", "year", "]", ">>", "16", ")", "&", "0x1", ";", "ctx", "->", "_mday", "[", "leapMonth", "+", "1", "]", "=", "moon", "[", "i", "]", ";", "for", "(", "i", "=", "Nmonth", ";", "i", ">=", "1", ";", "i", "--", ")", "{", "if", "(", "i", "==", "leapMonth", "+", "1", ")", "i", "--", ";", "ctx", "->", "_mday", "[", "i", "]", "=", "moon", "[", "code", "&", "0x1", "]", ";", "code", ">>=", "1", ";", "}", "}", "return", "leapMonth", ";", "}" ]
Compute the days of each month in the given lunar year
[ "Compute", "the", "days", "of", "each", "month", "in", "the", "given", "lunar", "year" ]
[ "/* leapMonth == 0 means no leap month */", "/*\n There is a leap month (run4 yue4) L in this year.\n mday[1] contains the number of days in the 1-st month;\n mday[L] contains the number of days in the L-th month;\n mday[L+1] contains the number of days in the L-th leap month;\n mday[L+2] contains the number of days in the L+1 month, etc.\n \n cf. yearInfo[]: info about the leap month is encoded differently.\n */" ]
[ { "param": "ctx", "type": "LibLunarContext" }, { "param": "year", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "LibLunarContext", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "year", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
6be0195c32779659db3aca6d6faa5b83c160c820
scizzorz/rain
rain/base/regex/regex.c
[ "BSD-2-Clause", "MIT" ]
C
table_from_matches
void
void table_from_matches(box *table, const char *matched, int *ovector, int pcre_exec_ret) { const char *match; box key; box val; rain_set_str(&key, "count"); rain_set_int(&val, pcre_exec_ret); rain_put(table, &key, &val); for(int i = 0; i < pcre_exec_ret; ++i) { pcre_get_substring(matched, ovector, pcre_exec_ret, i, &match); rain_set_int(&key, i); rain_set_strcpy(&val, match, strlen(match)); rain_put(table, &key, &val); pcre_free_substring(match); } }
/* proof of concept regular expression library */
proof of concept regular expression library
[ "proof", "of", "concept", "regular", "expression", "library" ]
void table_from_matches(box *table, const char *matched, int *ovector, int pcre_exec_ret) { const char *match; box key; box val; rain_set_str(&key, "count"); rain_set_int(&val, pcre_exec_ret); rain_put(table, &key, &val); for(int i = 0; i < pcre_exec_ret; ++i) { pcre_get_substring(matched, ovector, pcre_exec_ret, i, &match); rain_set_int(&key, i); rain_set_strcpy(&val, match, strlen(match)); rain_put(table, &key, &val); pcre_free_substring(match); } }
[ "void", "table_from_matches", "(", "box", "*", "table", ",", "const", "char", "*", "matched", ",", "int", "*", "ovector", ",", "int", "pcre_exec_ret", ")", "{", "const", "char", "*", "match", ";", "box", "key", ";", "box", "val", ";", "rain_set_str", "(", "&", "key", ",", "\"", "\"", ")", ";", "rain_set_int", "(", "&", "val", ",", "pcre_exec_ret", ")", ";", "rain_put", "(", "table", ",", "&", "key", ",", "&", "val", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pcre_exec_ret", ";", "++", "i", ")", "{", "pcre_get_substring", "(", "matched", ",", "ovector", ",", "pcre_exec_ret", ",", "i", ",", "&", "match", ")", ";", "rain_set_int", "(", "&", "key", ",", "i", ")", ";", "rain_set_strcpy", "(", "&", "val", ",", "match", ",", "strlen", "(", "match", ")", ")", ";", "rain_put", "(", "table", ",", "&", "key", ",", "&", "val", ")", ";", "pcre_free_substring", "(", "match", ")", ";", "}", "}" ]
proof of concept regular expression library
[ "proof", "of", "concept", "regular", "expression", "library" ]
[]
[ { "param": "table", "type": "box" }, { "param": "matched", "type": "char" }, { "param": "ovector", "type": "int" }, { "param": "pcre_exec_ret", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "table", "type": "box", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "matched", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ovector", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pcre_exec_ret", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
stringLength
int
int stringLength(String *string){ int i = 0; for(i; string->stuff[i] != '\0'; i++); return i; }
//Count the length of a string inside the object String. Access the 'stuff' member.
Count the length of a string inside the object String. Access the 'stuff' member.
[ "Count", "the", "length", "of", "a", "string", "inside", "the", "object", "String", ".", "Access", "the", "'", "stuff", "'", "member", "." ]
int stringLength(String *string){ int i = 0; for(i; string->stuff[i] != '\0'; i++); return i; }
[ "int", "stringLength", "(", "String", "*", "string", ")", "{", "int", "i", "=", "0", ";", "for", "(", "i", ";", "string", "->", "stuff", "[", "i", "]", "!=", "'", "\\0", "'", ";", "i", "++", ")", ";", "return", "i", ";", "}" ]
Count the length of a string inside the object String.
[ "Count", "the", "length", "of", "a", "string", "inside", "the", "object", "String", "." ]
[]
[ { "param": "string", "type": "String" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "string", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
forEach
void
void forEach( String *string, void (*lambda)( void ) ){ int i = 0; for(i; string->stuff[i] != '\0'; i++){ lambda(); } }
//Expects a function without parameters to be executed each character inside the string.
Expects a function without parameters to be executed each character inside the string.
[ "Expects", "a", "function", "without", "parameters", "to", "be", "executed", "each", "character", "inside", "the", "string", "." ]
void forEach( String *string, void (*lambda)( void ) ){ int i = 0; for(i; string->stuff[i] != '\0'; i++){ lambda(); } }
[ "void", "forEach", "(", "String", "*", "string", ",", "void", "(", "*", "lambda", ")", "(", "void", ")", ")", "{", "int", "i", "=", "0", ";", "for", "(", "i", ";", "string", "->", "stuff", "[", "i", "]", "!=", "'", "\\0", "'", ";", "i", "++", ")", "{", "lambda", "(", ")", ";", "}", "}" ]
Expects a function without parameters to be executed each character inside the string.
[ "Expects", "a", "function", "without", "parameters", "to", "be", "executed", "each", "character", "inside", "the", "string", "." ]
[]
[ { "param": "string", "type": "String" }, { "param": "lambda", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "string", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "lambda", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
searchFor
int
int searchFor( String *string, char* searching ) { int i = 0; int condition = localLength(searching); for(i; string->stuff[i] != '\0'; i++){ if( searching[0] == string->stuff[i] ){ condition--; for( int y = 1; searching[y] != '\0'; y++ ){ if( searching[y] == '\0') break; else if( searching[y] == string->stuff[i + y] ){ condition--; continue; }else{ condition = localLength(searching); break; } } if(condition == 0) return 1; } } return 0; }
//Receives the String object and a char array, and searches inside the 'stuff' member of the object for the char array.
Receives the String object and a char array, and searches inside the 'stuff' member of the object for the char array.
[ "Receives", "the", "String", "object", "and", "a", "char", "array", "and", "searches", "inside", "the", "'", "stuff", "'", "member", "of", "the", "object", "for", "the", "char", "array", "." ]
int searchFor( String *string, char* searching ) { int i = 0; int condition = localLength(searching); for(i; string->stuff[i] != '\0'; i++){ if( searching[0] == string->stuff[i] ){ condition--; for( int y = 1; searching[y] != '\0'; y++ ){ if( searching[y] == '\0') break; else if( searching[y] == string->stuff[i + y] ){ condition--; continue; }else{ condition = localLength(searching); break; } } if(condition == 0) return 1; } } return 0; }
[ "int", "searchFor", "(", "String", "*", "string", ",", "char", "*", "searching", ")", "{", "int", "i", "=", "0", ";", "int", "condition", "=", "localLength", "(", "searching", ")", ";", "for", "(", "i", ";", "string", "->", "stuff", "[", "i", "]", "!=", "'", "\\0", "'", ";", "i", "++", ")", "{", "if", "(", "searching", "[", "0", "]", "==", "string", "->", "stuff", "[", "i", "]", ")", "{", "condition", "--", ";", "for", "(", "int", "y", "=", "1", ";", "searching", "[", "y", "]", "!=", "'", "\\0", "'", ";", "y", "++", ")", "{", "if", "(", "searching", "[", "y", "]", "==", "'", "\\0", "'", ")", "break", ";", "else", "if", "(", "searching", "[", "y", "]", "==", "string", "->", "stuff", "[", "i", "+", "y", "]", ")", "{", "condition", "--", ";", "continue", ";", "}", "else", "{", "condition", "=", "localLength", "(", "searching", ")", ";", "break", ";", "}", "}", "if", "(", "condition", "==", "0", ")", "return", "1", ";", "}", "}", "return", "0", ";", "}" ]
Receives the String object and a char array, and searches inside the 'stuff' member of the object for the char array.
[ "Receives", "the", "String", "object", "and", "a", "char", "array", "and", "searches", "inside", "the", "'", "stuff", "'", "member", "of", "the", "object", "for", "the", "char", "array", "." ]
[]
[ { "param": "string", "type": "String" }, { "param": "searching", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "string", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "searching", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
isNull
int
int isNull( String *string ){ if(string == NULL){ return 1; } if(string->stuff == NULL){ return 1; } return 0; }
//Return 1 if the pointer is NULL. 0 if not.
Return 1 if the pointer is NULL. 0 if not.
[ "Return", "1", "if", "the", "pointer", "is", "NULL", ".", "0", "if", "not", "." ]
int isNull( String *string ){ if(string == NULL){ return 1; } if(string->stuff == NULL){ return 1; } return 0; }
[ "int", "isNull", "(", "String", "*", "string", ")", "{", "if", "(", "string", "==", "NULL", ")", "{", "return", "1", ";", "}", "if", "(", "string", "->", "stuff", "==", "NULL", ")", "{", "return", "1", ";", "}", "return", "0", ";", "}" ]
Return 1 if the pointer is NULL.
[ "Return", "1", "if", "the", "pointer", "is", "NULL", "." ]
[]
[ { "param": "string", "type": "String" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "string", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
isEqual
int
int isEqual( String *string1, char *string2 ){ int i = 0; if(string1->length(string1->self) != localLength(string2)) return 0; for(i; string1->stuff[i] != '\0'; i++){ if(string1->stuff[i] != string2[i]) return 0; } return 1; }
//Receives the String object itself, and a char array, to compare then. Returns 1 if they are equal, or 0 if not.
Receives the String object itself, and a char array, to compare then. Returns 1 if they are equal, or 0 if not.
[ "Receives", "the", "String", "object", "itself", "and", "a", "char", "array", "to", "compare", "then", ".", "Returns", "1", "if", "they", "are", "equal", "or", "0", "if", "not", "." ]
int isEqual( String *string1, char *string2 ){ int i = 0; if(string1->length(string1->self) != localLength(string2)) return 0; for(i; string1->stuff[i] != '\0'; i++){ if(string1->stuff[i] != string2[i]) return 0; } return 1; }
[ "int", "isEqual", "(", "String", "*", "string1", ",", "char", "*", "string2", ")", "{", "int", "i", "=", "0", ";", "if", "(", "string1", "->", "length", "(", "string1", "->", "self", ")", "!=", "localLength", "(", "string2", ")", ")", "return", "0", ";", "for", "(", "i", ";", "string1", "->", "stuff", "[", "i", "]", "!=", "'", "\\0", "'", ";", "i", "++", ")", "{", "if", "(", "string1", "->", "stuff", "[", "i", "]", "!=", "string2", "[", "i", "]", ")", "return", "0", ";", "}", "return", "1", ";", "}" ]
Receives the String object itself, and a char array, to compare then.
[ "Receives", "the", "String", "object", "itself", "and", "a", "char", "array", "to", "compare", "then", "." ]
[]
[ { "param": "string1", "type": "String" }, { "param": "string2", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "string1", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "string2", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
concat
void
void concat( String *toReceive, String *toAdd){ int newSize = (toReceive->length(toReceive->self)); newSize+= toAdd->length(toAdd->self); char *newP = (char*) calloc(sizeof(char), newSize); int i = 0; for(i; i < toReceive->length(toReceive->self); i++){ if(toReceive->stuff[i] != '\0') newP[i] = toReceive->stuff[i]; } for(i; (i - toReceive->length(toReceive->self)) < toAdd->length(toAdd->self); i++){ newP[i] = toAdd->stuff[i - toReceive->length(toReceive->self)]; } toReceive->stuff = newP; }
//Concatenate a string to another.
Concatenate a string to another.
[ "Concatenate", "a", "string", "to", "another", "." ]
void concat( String *toReceive, String *toAdd){ int newSize = (toReceive->length(toReceive->self)); newSize+= toAdd->length(toAdd->self); char *newP = (char*) calloc(sizeof(char), newSize); int i = 0; for(i; i < toReceive->length(toReceive->self); i++){ if(toReceive->stuff[i] != '\0') newP[i] = toReceive->stuff[i]; } for(i; (i - toReceive->length(toReceive->self)) < toAdd->length(toAdd->self); i++){ newP[i] = toAdd->stuff[i - toReceive->length(toReceive->self)]; } toReceive->stuff = newP; }
[ "void", "concat", "(", "String", "*", "toReceive", ",", "String", "*", "toAdd", ")", "{", "int", "newSize", "=", "(", "toReceive", "->", "length", "(", "toReceive", "->", "self", ")", ")", ";", "newSize", "+=", "toAdd", "->", "length", "(", "toAdd", "->", "self", ")", ";", "char", "*", "newP", "=", "(", "char", "*", ")", "calloc", "(", "sizeof", "(", "char", ")", ",", "newSize", ")", ";", "int", "i", "=", "0", ";", "for", "(", "i", ";", "i", "<", "toReceive", "->", "length", "(", "toReceive", "->", "self", ")", ";", "i", "++", ")", "{", "if", "(", "toReceive", "->", "stuff", "[", "i", "]", "!=", "'", "\\0", "'", ")", "newP", "[", "i", "]", "=", "toReceive", "->", "stuff", "[", "i", "]", ";", "}", "for", "(", "i", ";", "(", "i", "-", "toReceive", "->", "length", "(", "toReceive", "->", "self", ")", ")", "<", "toAdd", "->", "length", "(", "toAdd", "->", "self", ")", ";", "i", "++", ")", "{", "newP", "[", "i", "]", "=", "toAdd", "->", "stuff", "[", "i", "-", "toReceive", "->", "length", "(", "toReceive", "->", "self", ")", "]", ";", "}", "toReceive", "->", "stuff", "=", "newP", ";", "}" ]
Concatenate a string to another.
[ "Concatenate", "a", "string", "to", "another", "." ]
[]
[ { "param": "toReceive", "type": "String" }, { "param": "toAdd", "type": "String" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "toReceive", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "toAdd", "type": "String", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4be490ea4f4b253bfa7978d4e82d4619700e3ff1
FLira2000/String
String.c
[ "MIT" ]
C
newString
String
String* newString( char *string ){ String *s = (String*) malloc(sizeof(String)); s->stuff = string; s->self = s; s->length = &stringLength; s->forEach = &forEach; s->searchFor = &searchFor; s->isBlank = &isBlank; s->isEqual = &isEqual; s->concat = &concat; s->setString = &setString; s->exportString = &exportString; return s; }
//Constructor. Receives the stuff in characters to fill the object that will be created.
Constructor. Receives the stuff in characters to fill the object that will be created.
[ "Constructor", ".", "Receives", "the", "stuff", "in", "characters", "to", "fill", "the", "object", "that", "will", "be", "created", "." ]
String* newString( char *string ){ String *s = (String*) malloc(sizeof(String)); s->stuff = string; s->self = s; s->length = &stringLength; s->forEach = &forEach; s->searchFor = &searchFor; s->isBlank = &isBlank; s->isEqual = &isEqual; s->concat = &concat; s->setString = &setString; s->exportString = &exportString; return s; }
[ "String", "*", "newString", "(", "char", "*", "string", ")", "{", "String", "*", "s", "=", "(", "String", "*", ")", "malloc", "(", "sizeof", "(", "String", ")", ")", ";", "s", "->", "stuff", "=", "string", ";", "s", "->", "self", "=", "s", ";", "s", "->", "length", "=", "&", "stringLength", ";", "s", "->", "forEach", "=", "&", "forEach", ";", "s", "->", "searchFor", "=", "&", "searchFor", ";", "s", "->", "isBlank", "=", "&", "isBlank", ";", "s", "->", "isEqual", "=", "&", "isEqual", ";", "s", "->", "concat", "=", "&", "concat", ";", "s", "->", "setString", "=", "&", "setString", ";", "s", "->", "exportString", "=", "&", "exportString", ";", "return", "s", ";", "}" ]
Constructor.
[ "Constructor", "." ]
[]
[ { "param": "string", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "string", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
909c67f2cec8fb3568dd98e385b7a88b8ba3d600
tornado12345/ChakraCore
lib/Runtime/Debug/TTSupport.h
[ "MIT" ]
C
AddNewBlock
void
void AddNewBlock() { byte* allocBlock = TT_HEAP_ALLOC_ARRAY(byte, this->m_slabBlockSize); TTDAssert((reinterpret_cast<uint64>(allocBlock) & 0x3) == 0, "We have non-word aligned allocations so all our later work is not so useful"); SlabBlock* newBlock = (SlabBlock*)allocBlock; byte* dataArray = (allocBlock + TTD_SLAB_BLOCK_SIZE); this->m_currPos = dataArray; this->m_endPos = dataArray + TTD_SLAB_BLOCK_USABLE_SIZE(this->m_slabBlockSize); newBlock->BlockData = dataArray; newBlock->Next = nullptr; newBlock->Previous = this->m_headBlock; newBlock->RefCounter = 0; this->m_headBlock->Next = newBlock; this->m_headBlock = newBlock; }
//Get a new block in the slab
Get a new block in the slab
[ "Get", "a", "new", "block", "in", "the", "slab" ]
void AddNewBlock() { byte* allocBlock = TT_HEAP_ALLOC_ARRAY(byte, this->m_slabBlockSize); TTDAssert((reinterpret_cast<uint64>(allocBlock) & 0x3) == 0, "We have non-word aligned allocations so all our later work is not so useful"); SlabBlock* newBlock = (SlabBlock*)allocBlock; byte* dataArray = (allocBlock + TTD_SLAB_BLOCK_SIZE); this->m_currPos = dataArray; this->m_endPos = dataArray + TTD_SLAB_BLOCK_USABLE_SIZE(this->m_slabBlockSize); newBlock->BlockData = dataArray; newBlock->Next = nullptr; newBlock->Previous = this->m_headBlock; newBlock->RefCounter = 0; this->m_headBlock->Next = newBlock; this->m_headBlock = newBlock; }
[ "void", "AddNewBlock", "(", ")", "{", "byte", "*", "allocBlock", "=", "TT_HEAP_ALLOC_ARRAY", "(", "byte", ",", "this", "->", "m_slabBlockSize", ")", ";", "TTDAssert", "(", "(", "reinterpret_cast", "<", "uint64", ">", "(", "allocBlock", ")", "&", "0x3", ")", "==", "0", ",", "\"", "\"", ")", ";", "SlabBlock", "*", "newBlock", "=", "(", "SlabBlock", "*", ")", "allocBlock", ";", "byte", "*", "dataArray", "=", "(", "allocBlock", "+", "TTD_SLAB_BLOCK_SIZE", ")", ";", "this", "->", "m_currPos", "=", "dataArray", ";", "this", "->", "m_endPos", "=", "dataArray", "+", "TTD_SLAB_BLOCK_USABLE_SIZE", "(", "this", "->", "m_slabBlockSize", ")", ";", "newBlock", "->", "BlockData", "=", "dataArray", ";", "newBlock", "->", "Next", "=", "nullptr", ";", "newBlock", "->", "Previous", "=", "this", "->", "m_headBlock", ";", "newBlock", "->", "RefCounter", "=", "0", ";", "this", "->", "m_headBlock", "->", "Next", "=", "newBlock", ";", "this", "->", "m_headBlock", "=", "newBlock", ";", "}" ]
Get a new block in the slab
[ "Get", "a", "new", "block", "in", "the", "slab" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
909c67f2cec8fb3568dd98e385b7a88b8ba3d600
tornado12345/ChakraCore
lib/Runtime/Debug/TTSupport.h
[ "MIT" ]
C
CommitLargeBlockAllocation
void
void CommitLargeBlockAllocation(LargeSlabBlock* newBlock, size_t blockSize) { #if ENABLE_TTD_INTERNAL_DIAGNOSTICS this->m_totalAllocatedSize += blockSize; #endif if (this->m_largeBlockList != nullptr) { this->m_largeBlockList->Next = newBlock; } this->m_largeBlockList = newBlock; }
//Commit the allocation of a large block
Commit the allocation of a large block
[ "Commit", "the", "allocation", "of", "a", "large", "block" ]
void CommitLargeBlockAllocation(LargeSlabBlock* newBlock, size_t blockSize) { #if ENABLE_TTD_INTERNAL_DIAGNOSTICS this->m_totalAllocatedSize += blockSize; #endif if (this->m_largeBlockList != nullptr) { this->m_largeBlockList->Next = newBlock; } this->m_largeBlockList = newBlock; }
[ "void", "CommitLargeBlockAllocation", "(", "LargeSlabBlock", "*", "newBlock", ",", "size_t", "blockSize", ")", "{", "#if", "ENABLE_TTD_INTERNAL_DIAGNOSTICS", "\n", "this", "->", "m_totalAllocatedSize", "+=", "blockSize", ";", "#endif", "if", "(", "this", "->", "m_largeBlockList", "!=", "nullptr", ")", "{", "this", "->", "m_largeBlockList", "->", "Next", "=", "newBlock", ";", "}", "this", "->", "m_largeBlockList", "=", "newBlock", ";", "}" ]
Commit the allocation of a large block
[ "Commit", "the", "allocation", "of", "a", "large", "block" ]
[]
[ { "param": "newBlock", "type": "LargeSlabBlock" }, { "param": "blockSize", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "newBlock", "type": "LargeSlabBlock", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "blockSize", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
909c67f2cec8fb3568dd98e385b7a88b8ba3d600
tornado12345/ChakraCore
lib/Runtime/Debug/TTSupport.h
[ "MIT" ]
C
CopyRawNullTerminatedStringInto
char16
const char16* CopyRawNullTerminatedStringInto(const char16* str) { if (str == nullptr) { return nullptr; } else { size_t length = wcslen(str) + 1; size_t byteLength = length * sizeof(char16); char16* res = this->SlabAllocateArray<char16>(length); js_memcpy_s(res, byteLength, str, byteLength); return res; } }
//clone a null terminated char16* string (or nullptr) into the allocator -- currently only used for wellknown tokens
clone a null terminated char16* string (or nullptr) into the allocator -- currently only used for wellknown tokens
[ "clone", "a", "null", "terminated", "char16", "*", "string", "(", "or", "nullptr", ")", "into", "the", "allocator", "--", "currently", "only", "used", "for", "wellknown", "tokens" ]
const char16* CopyRawNullTerminatedStringInto(const char16* str) { if (str == nullptr) { return nullptr; } else { size_t length = wcslen(str) + 1; size_t byteLength = length * sizeof(char16); char16* res = this->SlabAllocateArray<char16>(length); js_memcpy_s(res, byteLength, str, byteLength); return res; } }
[ "const", "char16", "*", "CopyRawNullTerminatedStringInto", "(", "const", "char16", "*", "str", ")", "{", "if", "(", "str", "==", "nullptr", ")", "{", "return", "nullptr", ";", "}", "else", "{", "size_t", "length", "=", "wcslen", "(", "str", ")", "+", "1", ";", "size_t", "byteLength", "=", "length", "*", "sizeof", "(", "char16", ")", ";", "char16", "*", "res", "=", "this", "->", "SlabAllocateArray", "<", "char16", ">", "(", "length", ")", ";", "js_memcpy_s", "(", "res", ",", "byteLength", ",", "str", ",", "byteLength", ")", ";", "return", "res", ";", "}", "}" ]
clone a null terminated char16* string (or nullptr) into the allocator -- currently only used for wellknown tokens
[ "clone", "a", "null", "terminated", "char16", "*", "string", "(", "or", "nullptr", ")", "into", "the", "allocator", "--", "currently", "only", "used", "for", "wellknown", "tokens" ]
[]
[ { "param": "str", "type": "char16" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "str", "type": "char16", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
909c67f2cec8fb3568dd98e385b7a88b8ba3d600
tornado12345/ChakraCore
lib/Runtime/Debug/TTSupport.h
[ "MIT" ]
C
UnlinkAllocation
void
void UnlinkAllocation(const void* allocation) { TTDAssert(canUnlink != 0, "Unlink not allowed with this slab allocator."); TTDAssert(this->m_reserveActiveBytes == 0, "We don't have anything reserved."); //get the meta-data for this allocation and see if it is a byte* realBase = ((byte*)allocation) - canUnlink; ptrdiff_t offset = *((ptrdiff_t*)realBase); if (offset == 0) { //it is a large allocation just free it LargeSlabBlock* largeBlock = (LargeSlabBlock*)(((byte*)allocation) - TTD_LARGE_SLAB_BLOCK_SIZE); if (largeBlock == this->m_largeBlockList) { TTDAssert(largeBlock->Next == nullptr, "Should always have a null next at head"); this->m_largeBlockList = this->m_largeBlockList->Previous; if (this->m_largeBlockList != nullptr) { this->m_largeBlockList->Next = nullptr; } } else { if (largeBlock->Next != nullptr) { largeBlock->Next->Previous = largeBlock->Previous; } if (largeBlock->Previous != nullptr) { largeBlock->Previous->Next = largeBlock->Next; } } TT_HEAP_FREE_ARRAY(byte, (byte*)largeBlock, largeBlock->TotalBlockSize); } else { //lookup the slab block and do ref counting SlabBlock* block = (SlabBlock*)(realBase - offset); block->RefCounter--; if (block->RefCounter == 0) { if (block == this->m_headBlock) { //we always need a head block to allocate out of -- so instead of deleting just reset it this->m_currPos = this->m_headBlock->BlockData; this->m_endPos = this->m_headBlock->BlockData + TTD_SLAB_BLOCK_USABLE_SIZE(this->m_slabBlockSize); memset(this->m_currPos, 0, TTD_SLAB_BLOCK_USABLE_SIZE(this->m_slabBlockSize)); this->m_headBlock->RefCounter = 0; } else { if (block->Next != nullptr) { block->Next->Previous = block->Previous; } if (block->Previous != nullptr) { block->Previous->Next = block->Next; } TT_HEAP_FREE_ARRAY(byte, (byte*)block, this->m_slabBlockSize); } } } }
//If allowed unlink the memory allocation specified and free the block if it is no longer used by anyone
If allowed unlink the memory allocation specified and free the block if it is no longer used by anyone
[ "If", "allowed", "unlink", "the", "memory", "allocation", "specified", "and", "free", "the", "block", "if", "it", "is", "no", "longer", "used", "by", "anyone" ]
void UnlinkAllocation(const void* allocation) { TTDAssert(canUnlink != 0, "Unlink not allowed with this slab allocator."); TTDAssert(this->m_reserveActiveBytes == 0, "We don't have anything reserved."); byte* realBase = ((byte*)allocation) - canUnlink; ptrdiff_t offset = *((ptrdiff_t*)realBase); if (offset == 0) { LargeSlabBlock* largeBlock = (LargeSlabBlock*)(((byte*)allocation) - TTD_LARGE_SLAB_BLOCK_SIZE); if (largeBlock == this->m_largeBlockList) { TTDAssert(largeBlock->Next == nullptr, "Should always have a null next at head"); this->m_largeBlockList = this->m_largeBlockList->Previous; if (this->m_largeBlockList != nullptr) { this->m_largeBlockList->Next = nullptr; } } else { if (largeBlock->Next != nullptr) { largeBlock->Next->Previous = largeBlock->Previous; } if (largeBlock->Previous != nullptr) { largeBlock->Previous->Next = largeBlock->Next; } } TT_HEAP_FREE_ARRAY(byte, (byte*)largeBlock, largeBlock->TotalBlockSize); } else { SlabBlock* block = (SlabBlock*)(realBase - offset); block->RefCounter--; if (block->RefCounter == 0) { if (block == this->m_headBlock) { this->m_currPos = this->m_headBlock->BlockData; this->m_endPos = this->m_headBlock->BlockData + TTD_SLAB_BLOCK_USABLE_SIZE(this->m_slabBlockSize); memset(this->m_currPos, 0, TTD_SLAB_BLOCK_USABLE_SIZE(this->m_slabBlockSize)); this->m_headBlock->RefCounter = 0; } else { if (block->Next != nullptr) { block->Next->Previous = block->Previous; } if (block->Previous != nullptr) { block->Previous->Next = block->Next; } TT_HEAP_FREE_ARRAY(byte, (byte*)block, this->m_slabBlockSize); } } } }
[ "void", "UnlinkAllocation", "(", "const", "void", "*", "allocation", ")", "{", "TTDAssert", "(", "canUnlink", "!=", "0", ",", "\"", "\"", ")", ";", "TTDAssert", "(", "this", "->", "m_reserveActiveBytes", "==", "0", ",", "\"", "\"", ")", ";", "byte", "*", "realBase", "=", "(", "(", "byte", "*", ")", "allocation", ")", "-", "canUnlink", ";", "ptrdiff_t", "offset", "=", "*", "(", "(", "ptrdiff_t", "*", ")", "realBase", ")", ";", "if", "(", "offset", "==", "0", ")", "{", "LargeSlabBlock", "*", "largeBlock", "=", "(", "LargeSlabBlock", "*", ")", "(", "(", "(", "byte", "*", ")", "allocation", ")", "-", "TTD_LARGE_SLAB_BLOCK_SIZE", ")", ";", "if", "(", "largeBlock", "==", "this", "->", "m_largeBlockList", ")", "{", "TTDAssert", "(", "largeBlock", "->", "Next", "==", "nullptr", ",", "\"", "\"", ")", ";", "this", "->", "m_largeBlockList", "=", "this", "->", "m_largeBlockList", "->", "Previous", ";", "if", "(", "this", "->", "m_largeBlockList", "!=", "nullptr", ")", "{", "this", "->", "m_largeBlockList", "->", "Next", "=", "nullptr", ";", "}", "}", "else", "{", "if", "(", "largeBlock", "->", "Next", "!=", "nullptr", ")", "{", "largeBlock", "->", "Next", "->", "Previous", "=", "largeBlock", "->", "Previous", ";", "}", "if", "(", "largeBlock", "->", "Previous", "!=", "nullptr", ")", "{", "largeBlock", "->", "Previous", "->", "Next", "=", "largeBlock", "->", "Next", ";", "}", "}", "TT_HEAP_FREE_ARRAY", "(", "byte", ",", "(", "byte", "*", ")", "largeBlock", ",", "largeBlock", "->", "TotalBlockSize", ")", ";", "}", "else", "{", "SlabBlock", "*", "block", "=", "(", "SlabBlock", "*", ")", "(", "realBase", "-", "offset", ")", ";", "block", "->", "RefCounter", "--", ";", "if", "(", "block", "->", "RefCounter", "==", "0", ")", "{", "if", "(", "block", "==", "this", "->", "m_headBlock", ")", "{", "this", "->", "m_currPos", "=", "this", "->", "m_headBlock", "->", "BlockData", ";", "this", "->", "m_endPos", "=", "this", "->", "m_headBlock", "->", "BlockData", "+", "TTD_SLAB_BLOCK_USABLE_SIZE", "(", "this", "->", "m_slabBlockSize", ")", ";", "memset", "(", "this", "->", "m_currPos", ",", "0", ",", "TTD_SLAB_BLOCK_USABLE_SIZE", "(", "this", "->", "m_slabBlockSize", ")", ")", ";", "this", "->", "m_headBlock", "->", "RefCounter", "=", "0", ";", "}", "else", "{", "if", "(", "block", "->", "Next", "!=", "nullptr", ")", "{", "block", "->", "Next", "->", "Previous", "=", "block", "->", "Previous", ";", "}", "if", "(", "block", "->", "Previous", "!=", "nullptr", ")", "{", "block", "->", "Previous", "->", "Next", "=", "block", "->", "Next", ";", "}", "TT_HEAP_FREE_ARRAY", "(", "byte", ",", "(", "byte", "*", ")", "block", ",", "this", "->", "m_slabBlockSize", ")", ";", "}", "}", "}", "}" ]
If allowed unlink the memory allocation specified and free the block if it is no longer used by anyone
[ "If", "allowed", "unlink", "the", "memory", "allocation", "specified", "and", "free", "the", "block", "if", "it", "is", "no", "longer", "used", "by", "anyone" ]
[ "//get the meta-data for this allocation and see if it is a", "//it is a large allocation just free it", "//lookup the slab block and do ref counting", "//we always need a head block to allocate out of -- so instead of deleting just reset it" ]
[ { "param": "allocation", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "allocation", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
909c67f2cec8fb3568dd98e385b7a88b8ba3d600
tornado12345/ChakraCore
lib/Runtime/Debug/TTSupport.h
[ "MIT" ]
C
AddEntry
void
void AddEntry(T data) { TTDAssert(this->m_inlineHeadBlock.CurrPos <= this->m_inlineHeadBlock.EndPos, "We are off the end of the array"); TTDAssert((((byte*)this->m_inlineHeadBlock.CurrPos) - ((byte*)this->m_inlineHeadBlock.BlockData)) / sizeof(T) <= allocSize, "We are off the end of the array"); if (this->m_inlineHeadBlock.CurrPos == this->m_inlineHeadBlock.EndPos) { this->AddArrayLink(); } *(this->m_inlineHeadBlock.CurrPos) = data; this->m_inlineHeadBlock.CurrPos++; }
//Add the entry to the unordered list
Add the entry to the unordered list
[ "Add", "the", "entry", "to", "the", "unordered", "list" ]
void AddEntry(T data) { TTDAssert(this->m_inlineHeadBlock.CurrPos <= this->m_inlineHeadBlock.EndPos, "We are off the end of the array"); TTDAssert((((byte*)this->m_inlineHeadBlock.CurrPos) - ((byte*)this->m_inlineHeadBlock.BlockData)) / sizeof(T) <= allocSize, "We are off the end of the array"); if (this->m_inlineHeadBlock.CurrPos == this->m_inlineHeadBlock.EndPos) { this->AddArrayLink(); } *(this->m_inlineHeadBlock.CurrPos) = data; this->m_inlineHeadBlock.CurrPos++; }
[ "void", "AddEntry", "(", "T", "data", ")", "{", "TTDAssert", "(", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", "<=", "this", "->", "m_inlineHeadBlock", ".", "EndPos", ",", "\"", "\"", ")", ";", "TTDAssert", "(", "(", "(", "(", "byte", "*", ")", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", ")", "-", "(", "(", "byte", "*", ")", "this", "->", "m_inlineHeadBlock", ".", "BlockData", ")", ")", "/", "sizeof", "(", "T", ")", "<=", "allocSize", ",", "\"", "\"", ")", ";", "if", "(", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", "==", "this", "->", "m_inlineHeadBlock", ".", "EndPos", ")", "{", "this", "->", "AddArrayLink", "(", ")", ";", "}", "*", "(", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", ")", "=", "data", ";", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", "++", ";", "}" ]
Add the entry to the unordered list
[ "Add", "the", "entry", "to", "the", "unordered", "list" ]
[]
[ { "param": "data", "type": "T" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "T", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
909c67f2cec8fb3568dd98e385b7a88b8ba3d600
tornado12345/ChakraCore
lib/Runtime/Debug/TTSupport.h
[ "MIT" ]
C
NextOpenEntry
T
T* NextOpenEntry() { TTDAssert(this->m_inlineHeadBlock.CurrPos <= this->m_inlineHeadBlock.EndPos, "We are off the end of the array"); TTDAssert((((byte*)this->m_inlineHeadBlock.CurrPos) - ((byte*)this->m_inlineHeadBlock.BlockData)) / sizeof(T) <= allocSize, "We are off the end of the array"); if (this->m_inlineHeadBlock.CurrPos == this->m_inlineHeadBlock.EndPos) { this->AddArrayLink(); } T* entry = this->m_inlineHeadBlock.CurrPos; this->m_inlineHeadBlock.CurrPos++; return entry; }
//Get the next uninitialized entry (at the front of the sequence) //We expect the caller to initialize this memory appropriately
Get the next uninitialized entry (at the front of the sequence) We expect the caller to initialize this memory appropriately
[ "Get", "the", "next", "uninitialized", "entry", "(", "at", "the", "front", "of", "the", "sequence", ")", "We", "expect", "the", "caller", "to", "initialize", "this", "memory", "appropriately" ]
T* NextOpenEntry() { TTDAssert(this->m_inlineHeadBlock.CurrPos <= this->m_inlineHeadBlock.EndPos, "We are off the end of the array"); TTDAssert((((byte*)this->m_inlineHeadBlock.CurrPos) - ((byte*)this->m_inlineHeadBlock.BlockData)) / sizeof(T) <= allocSize, "We are off the end of the array"); if (this->m_inlineHeadBlock.CurrPos == this->m_inlineHeadBlock.EndPos) { this->AddArrayLink(); } T* entry = this->m_inlineHeadBlock.CurrPos; this->m_inlineHeadBlock.CurrPos++; return entry; }
[ "T", "*", "NextOpenEntry", "(", ")", "{", "TTDAssert", "(", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", "<=", "this", "->", "m_inlineHeadBlock", ".", "EndPos", ",", "\"", "\"", ")", ";", "TTDAssert", "(", "(", "(", "(", "byte", "*", ")", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", ")", "-", "(", "(", "byte", "*", ")", "this", "->", "m_inlineHeadBlock", ".", "BlockData", ")", ")", "/", "sizeof", "(", "T", ")", "<=", "allocSize", ",", "\"", "\"", ")", ";", "if", "(", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", "==", "this", "->", "m_inlineHeadBlock", ".", "EndPos", ")", "{", "this", "->", "AddArrayLink", "(", ")", ";", "}", "T", "*", "entry", "=", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", ";", "this", "->", "m_inlineHeadBlock", ".", "CurrPos", "++", ";", "return", "entry", ";", "}" ]
Get the next uninitialized entry (at the front of the sequence) We expect the caller to initialize this memory appropriately
[ "Get", "the", "next", "uninitialized", "entry", "(", "at", "the", "front", "of", "the", "sequence", ")", "We", "expect", "the", "caller", "to", "initialize", "this", "memory", "appropriately" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
6a083aab2073e9cdabbb41464ffd92e6caa15f49
paulbartell/tfm-staging
platform/ext/target/arm/diphda/tfm_hal_isolation.c
[ "BSD-3-Clause" ]
C
tfm_hal_bind_boundaries
nan
enum tfm_hal_status_t tfm_hal_bind_boundaries( const struct partition_load_info_t *p_ldinf, void **pp_boundaries) { (void)p_ldinf; (void)pp_boundaries; return TFM_HAL_SUCCESS; }
/* * Implementation of tfm_hal_bind_boundaries() on Diphda: * * The API encodes some attributes into a handle and returns it to SPM. * The attributes include isolation boundaries, privilege, and MMIO information. * When scheduler switches running partitions, SPM compares the handle between * partitions to know if boundary update is necessary. If update is required, * SPM passes the handle to platform to do platform settings and update * isolation boundaries. */
Implementation of tfm_hal_bind_boundaries() on Diphda: The API encodes some attributes into a handle and returns it to SPM. The attributes include isolation boundaries, privilege, and MMIO information. When scheduler switches running partitions, SPM compares the handle between partitions to know if boundary update is necessary. If update is required, SPM passes the handle to platform to do platform settings and update isolation boundaries.
[ "Implementation", "of", "tfm_hal_bind_boundaries", "()", "on", "Diphda", ":", "The", "API", "encodes", "some", "attributes", "into", "a", "handle", "and", "returns", "it", "to", "SPM", ".", "The", "attributes", "include", "isolation", "boundaries", "privilege", "and", "MMIO", "information", ".", "When", "scheduler", "switches", "running", "partitions", "SPM", "compares", "the", "handle", "between", "partitions", "to", "know", "if", "boundary", "update", "is", "necessary", ".", "If", "update", "is", "required", "SPM", "passes", "the", "handle", "to", "platform", "to", "do", "platform", "settings", "and", "update", "isolation", "boundaries", "." ]
enum tfm_hal_status_t tfm_hal_bind_boundaries( const struct partition_load_info_t *p_ldinf, void **pp_boundaries) { (void)p_ldinf; (void)pp_boundaries; return TFM_HAL_SUCCESS; }
[ "enum", "tfm_hal_status_t", "tfm_hal_bind_boundaries", "(", "const", "struct", "partition_load_info_t", "*", "p_ldinf", ",", "void", "*", "*", "pp_boundaries", ")", "{", "(", "void", ")", "p_ldinf", ";", "(", "void", ")", "pp_boundaries", ";", "return", "TFM_HAL_SUCCESS", ";", "}" ]
Implementation of tfm_hal_bind_boundaries() on Diphda: The API encodes some attributes into a handle and returns it to SPM.
[ "Implementation", "of", "tfm_hal_bind_boundaries", "()", "on", "Diphda", ":", "The", "API", "encodes", "some", "attributes", "into", "a", "handle", "and", "returns", "it", "to", "SPM", "." ]
[]
[ { "param": "p_ldinf", "type": "struct partition_load_info_t" }, { "param": "pp_boundaries", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "p_ldinf", "type": "struct partition_load_info_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pp_boundaries", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5cdcc718c7582cc5ebc7b5085f0998310c89645a
paulbartell/tfm-staging
secure_fw/partitions/protected_storage/ps_object_system.c
[ "BSD-3-Clause" ]
C
ps_remove_old_data
psa_status_t
static psa_status_t ps_remove_old_data(uint32_t old_fid) { psa_status_t err; /* Delete old object table from the persistent area */ err = ps_object_table_delete_old_table(); if (err != PSA_SUCCESS) { return err; } /* Delete old file from the persistent area */ return psa_its_remove(old_fid); }
/** * \brief Removes the old object table and object from the file system. * * \param[in] old_fid Old file ID to remove. * * \return Returns error code as specified in \ref psa_status_t */
\brief Removes the old object table and object from the file system. \param[in] old_fid Old file ID to remove. \return Returns error code as specified in \ref psa_status_t
[ "\\", "brief", "Removes", "the", "old", "object", "table", "and", "object", "from", "the", "file", "system", ".", "\\", "param", "[", "in", "]", "old_fid", "Old", "file", "ID", "to", "remove", ".", "\\", "return", "Returns", "error", "code", "as", "specified", "in", "\\", "ref", "psa_status_t" ]
static psa_status_t ps_remove_old_data(uint32_t old_fid) { psa_status_t err; err = ps_object_table_delete_old_table(); if (err != PSA_SUCCESS) { return err; } return psa_its_remove(old_fid); }
[ "static", "psa_status_t", "ps_remove_old_data", "(", "uint32_t", "old_fid", ")", "{", "psa_status_t", "err", ";", "err", "=", "ps_object_table_delete_old_table", "(", ")", ";", "if", "(", "err", "!=", "PSA_SUCCESS", ")", "{", "return", "err", ";", "}", "return", "psa_its_remove", "(", "old_fid", ")", ";", "}" ]
\brief Removes the old object table and object from the file system.
[ "\\", "brief", "Removes", "the", "old", "object", "table", "and", "object", "from", "the", "file", "system", "." ]
[ "/* Delete old object table from the persistent area */", "/* Delete old file from the persistent area */" ]
[ { "param": "old_fid", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "old_fid", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
5cdcc718c7582cc5ebc7b5085f0998310c89645a
paulbartell/tfm-staging
secure_fw/partitions/protected_storage/ps_object_system.c
[ "BSD-3-Clause" ]
C
ps_write_object
psa_status_t
static psa_status_t ps_write_object(uint32_t wrt_size) { /* Add object identification and increase object version */ g_ps_object.header.fid = g_obj_tbl_info.fid; g_ps_object.header.version++; /* Save object version to be stored in the object table */ g_obj_tbl_info.version = g_ps_object.header.version; return psa_its_set(g_obj_tbl_info.fid, wrt_size, (const void *)&g_ps_object, PSA_STORAGE_FLAG_NONE); }
/** * \brief Writes an object based on its object table info stored in * g_obj_tbl_info and the input parameter. * * \param[in] wrt_size Number of bytes to write * * \return Returns error code as specified in \ref psa_status_t */
\brief Writes an object based on its object table info stored in g_obj_tbl_info and the input parameter. \param[in] wrt_size Number of bytes to write \return Returns error code as specified in \ref psa_status_t
[ "\\", "brief", "Writes", "an", "object", "based", "on", "its", "object", "table", "info", "stored", "in", "g_obj_tbl_info", "and", "the", "input", "parameter", ".", "\\", "param", "[", "in", "]", "wrt_size", "Number", "of", "bytes", "to", "write", "\\", "return", "Returns", "error", "code", "as", "specified", "in", "\\", "ref", "psa_status_t" ]
static psa_status_t ps_write_object(uint32_t wrt_size) { g_ps_object.header.fid = g_obj_tbl_info.fid; g_ps_object.header.version++; g_obj_tbl_info.version = g_ps_object.header.version; return psa_its_set(g_obj_tbl_info.fid, wrt_size, (const void *)&g_ps_object, PSA_STORAGE_FLAG_NONE); }
[ "static", "psa_status_t", "ps_write_object", "(", "uint32_t", "wrt_size", ")", "{", "g_ps_object", ".", "header", ".", "fid", "=", "g_obj_tbl_info", ".", "fid", ";", "g_ps_object", ".", "header", ".", "version", "++", ";", "g_obj_tbl_info", ".", "version", "=", "g_ps_object", ".", "header", ".", "version", ";", "return", "psa_its_set", "(", "g_obj_tbl_info", ".", "fid", ",", "wrt_size", ",", "(", "const", "void", "*", ")", "&", "g_ps_object", ",", "PSA_STORAGE_FLAG_NONE", ")", ";", "}" ]
\brief Writes an object based on its object table info stored in g_obj_tbl_info and the input parameter.
[ "\\", "brief", "Writes", "an", "object", "based", "on", "its", "object", "table", "info", "stored", "in", "g_obj_tbl_info", "and", "the", "input", "parameter", "." ]
[ "/* Add object identification and increase object version */", "/* Save object version to be stored in the object table */" ]
[ { "param": "wrt_size", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "wrt_size", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
823e293f906c1e3a70cd08b6264d3db6086eee78
paulbartell/tfm-staging
secure_fw/spm/cmsis_psa/arch/tfm_arch.c
[ "BSD-3-Clause" ]
C
tfm_arch_init_state_context
void
static void tfm_arch_init_state_context(struct tfm_state_context_t *p_sctx, void *param, uintptr_t pfn, uintptr_t pfnlr) { p_sctx->r0 = (uint32_t)param; p_sctx->ra = (uint32_t)pfn; p_sctx->lr = (uint32_t)pfnlr; p_sctx->xpsr = XPSR_T32; }
/* * Initializes the State Context. The Context is used to do Except Return to * Thread Mode to start a function. * * p_sctx[out] - pointer to the State Context to be initialized. * param [in] - The parameter for the function to start * pfn [in] - Pointer to the function to excute * pfnlr [in] - The Link Register of the State Context - the return address of * the function */
Initializes the State Context. The Context is used to do Except Return to Thread Mode to start a function. p_sctx[out] - pointer to the State Context to be initialized. param [in] - The parameter for the function to start pfn [in] - Pointer to the function to excute pfnlr [in] - The Link Register of the State Context - the return address of the function
[ "Initializes", "the", "State", "Context", ".", "The", "Context", "is", "used", "to", "do", "Except", "Return", "to", "Thread", "Mode", "to", "start", "a", "function", ".", "p_sctx", "[", "out", "]", "-", "pointer", "to", "the", "State", "Context", "to", "be", "initialized", ".", "param", "[", "in", "]", "-", "The", "parameter", "for", "the", "function", "to", "start", "pfn", "[", "in", "]", "-", "Pointer", "to", "the", "function", "to", "excute", "pfnlr", "[", "in", "]", "-", "The", "Link", "Register", "of", "the", "State", "Context", "-", "the", "return", "address", "of", "the", "function" ]
static void tfm_arch_init_state_context(struct tfm_state_context_t *p_sctx, void *param, uintptr_t pfn, uintptr_t pfnlr) { p_sctx->r0 = (uint32_t)param; p_sctx->ra = (uint32_t)pfn; p_sctx->lr = (uint32_t)pfnlr; p_sctx->xpsr = XPSR_T32; }
[ "static", "void", "tfm_arch_init_state_context", "(", "struct", "tfm_state_context_t", "*", "p_sctx", ",", "void", "*", "param", ",", "uintptr_t", "pfn", ",", "uintptr_t", "pfnlr", ")", "{", "p_sctx", "->", "r0", "=", "(", "uint32_t", ")", "param", ";", "p_sctx", "->", "ra", "=", "(", "uint32_t", ")", "pfn", ";", "p_sctx", "->", "lr", "=", "(", "uint32_t", ")", "pfnlr", ";", "p_sctx", "->", "xpsr", "=", "XPSR_T32", ";", "}" ]
Initializes the State Context.
[ "Initializes", "the", "State", "Context", "." ]
[]
[ { "param": "p_sctx", "type": "struct tfm_state_context_t" }, { "param": "param", "type": "void" }, { "param": "pfn", "type": "uintptr_t" }, { "param": "pfnlr", "type": "uintptr_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "p_sctx", "type": "struct tfm_state_context_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "param", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pfn", "type": "uintptr_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pfnlr", "type": "uintptr_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a7259d82945aa1117c7c5437dddd288cf11aaadc
watchpoints/daily-interview
code/2021/lex-yacc-examples/temp/y.tab.c
[ "Apache-2.0" ]
C
yydestruct
void
static void yydestruct (const char *yymsg, yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YYUSE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END }
/*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/
. | Release the memory associated to this symbol.
[ ".", "|", "Release", "the", "memory", "associated", "to", "this", "symbol", "." ]
static void yydestruct (const char *yymsg, yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YYUSE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END }
[ "static", "void", "yydestruct", "(", "const", "char", "*", "yymsg", ",", "yysymbol_kind_t", "yykind", ",", "YYSTYPE", "*", "yyvaluep", ")", "{", "YYUSE", "(", "yyvaluep", ")", ";", "if", "(", "!", "yymsg", ")", "yymsg", "=", "\"", "\"", ";", "YY_SYMBOL_PRINT", "(", "yymsg", ",", "yykind", ",", "yyvaluep", ",", "yylocationp", ")", ";", "YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN", "YYUSE", "(", "yykind", ")", ";", "YY_IGNORE_MAYBE_UNINITIALIZED_END", "", "}" ]
.
[ "." ]
[]
[ { "param": "yymsg", "type": "char" }, { "param": "yykind", "type": "yysymbol_kind_t" }, { "param": "yyvaluep", "type": "YYSTYPE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "yymsg", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yykind", "type": "yysymbol_kind_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yyvaluep", "type": "YYSTYPE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
04f43de7c93811fa7e19dd1de85caafc21028a3b
valerie-sd/mumt306project
src/midicsv-1.1/midicsv.c
[ "MIT" ]
C
vlength
vlint
static vlint vlength(byte **trk, long *trklen) { vlint value; byte ch; byte *cp = *trk; trklen--; if ((value = *cp++) & 0x80) { value &= 0x7F; do { value = (value << 7) | ((ch = *cp++) & 0x7F); trklen--; } while (ch & 0x80); } #ifdef DUMP fprintf(stderr, "Time lapse: %d bytes, %d\n", cp - *trk, value); #endif *trk = cp; return value; }
/* VLENGTH -- Parse variable length item from in-memory track */
VLENGTH -- Parse variable length item from in-memory track
[ "VLENGTH", "--", "Parse", "variable", "length", "item", "from", "in", "-", "memory", "track" ]
static vlint vlength(byte **trk, long *trklen) { vlint value; byte ch; byte *cp = *trk; trklen--; if ((value = *cp++) & 0x80) { value &= 0x7F; do { value = (value << 7) | ((ch = *cp++) & 0x7F); trklen--; } while (ch & 0x80); } #ifdef DUMP fprintf(stderr, "Time lapse: %d bytes, %d\n", cp - *trk, value); #endif *trk = cp; return value; }
[ "static", "vlint", "vlength", "(", "byte", "*", "*", "trk", ",", "long", "*", "trklen", ")", "{", "vlint", "value", ";", "byte", "ch", ";", "byte", "*", "cp", "=", "*", "trk", ";", "trklen", "--", ";", "if", "(", "(", "value", "=", "*", "cp", "++", ")", "&", "0x80", ")", "{", "value", "&=", "0x7F", ";", "do", "{", "value", "=", "(", "value", "<<", "7", ")", "|", "(", "(", "ch", "=", "*", "cp", "++", ")", "&", "0x7F", ")", ";", "trklen", "--", ";", "}", "while", "(", "ch", "&", "0x80", ")", ";", "}", "#ifdef", "DUMP", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "cp", "-", "*", "trk", ",", "value", ")", ";", "#endif", "*", "trk", "=", "cp", ";", "return", "value", ";", "}" ]
VLENGTH -- Parse variable length item from in-memory track
[ "VLENGTH", "--", "Parse", "variable", "length", "item", "from", "in", "-", "memory", "track" ]
[]
[ { "param": "trk", "type": "byte" }, { "param": "trklen", "type": "long" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "trk", "type": "byte", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "trklen", "type": "long", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b6d4d1aa659d1d282ea83d0254012efb0dadf7ca
elmot/open-oscilloscope-stm32f3
Src/usbd_conf.c
[ "MIT" ]
C
HAL_PCD_SuspendCallback
void
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) { /* Inform USB library that core enters in suspend Mode */ USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); /*Enter in STOP mode */ /* USER CODE BEGIN 2 */ if (hpcd->Init.low_power_enable) { /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */ SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); } /* USER CODE END 2 */ }
/** * @brief Suspend callback. * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) * @param hpcd: PCD handle * @retval None */
@brief Suspend callback. When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) @param hpcd: PCD handle @retval None
[ "@brief", "Suspend", "callback", ".", "When", "Low", "power", "mode", "is", "enabled", "the", "debug", "cannot", "be", "used", "(", "IAR", "Keil", "doesn", "'", "t", "support", "it", ")", "@param", "hpcd", ":", "PCD", "handle", "@retval", "None" ]
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) { USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); if (hpcd->Init.low_power_enable) { SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); } }
[ "void", "HAL_PCD_SuspendCallback", "(", "PCD_HandleTypeDef", "*", "hpcd", ")", "{", "USBD_LL_Suspend", "(", "(", "USBD_HandleTypeDef", "*", ")", "hpcd", "->", "pData", ")", ";", "if", "(", "hpcd", "->", "Init", ".", "low_power_enable", ")", "{", "SCB", "->", "SCR", "|=", "(", "uint32_t", ")", "(", "(", "uint32_t", ")", "(", "SCB_SCR_SLEEPDEEP_Msk", "|", "SCB_SCR_SLEEPONEXIT_Msk", ")", ")", ";", "}", "}" ]
@brief Suspend callback.
[ "@brief", "Suspend", "callback", "." ]
[ "/* Inform USB library that core enters in suspend Mode */", "/*Enter in STOP mode */", "/* USER CODE BEGIN 2 */", "/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */", "/* USER CODE END 2 */" ]
[ { "param": "hpcd", "type": "PCD_HandleTypeDef" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "hpcd", "type": "PCD_HandleTypeDef", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b6d4d1aa659d1d282ea83d0254012efb0dadf7ca
elmot/open-oscilloscope-stm32f3
Src/usbd_conf.c
[ "MIT" ]
C
USBD_LL_Init
USBD_StatusTypeDef
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) { /* Init USB_IP */ /* Link The driver to the stack */ hpcd_USB_FS.pData = pdev; pdev->pData = &hpcd_USB_FS; hpcd_USB_FS.Instance = USB; hpcd_USB_FS.Init.dev_endpoints = 8; hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_64; hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; hpcd_USB_FS.Init.low_power_enable = DISABLE; hpcd_USB_FS.Init.battery_charging_enable = DISABLE; if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) { Error_Handler(); } HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); return USBD_OK; }
/** * @brief Initializes the Low Level portion of the Device driver. * @param pdev: Device handle * @retval USBD Status */
@brief Initializes the Low Level portion of the Device driver. @param pdev: Device handle @retval USBD Status
[ "@brief", "Initializes", "the", "Low", "Level", "portion", "of", "the", "Device", "driver", ".", "@param", "pdev", ":", "Device", "handle", "@retval", "USBD", "Status" ]
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) { hpcd_USB_FS.pData = pdev; pdev->pData = &hpcd_USB_FS; hpcd_USB_FS.Instance = USB; hpcd_USB_FS.Init.dev_endpoints = 8; hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_64; hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; hpcd_USB_FS.Init.low_power_enable = DISABLE; hpcd_USB_FS.Init.battery_charging_enable = DISABLE; if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) { Error_Handler(); } HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); return USBD_OK; }
[ "USBD_StatusTypeDef", "USBD_LL_Init", "(", "USBD_HandleTypeDef", "*", "pdev", ")", "{", "hpcd_USB_FS", ".", "pData", "=", "pdev", ";", "pdev", "->", "pData", "=", "&", "hpcd_USB_FS", ";", "hpcd_USB_FS", ".", "Instance", "=", "USB", ";", "hpcd_USB_FS", ".", "Init", ".", "dev_endpoints", "=", "8", ";", "hpcd_USB_FS", ".", "Init", ".", "speed", "=", "PCD_SPEED_FULL", ";", "hpcd_USB_FS", ".", "Init", ".", "ep0_mps", "=", "DEP0CTL_MPS_64", ";", "hpcd_USB_FS", ".", "Init", ".", "phy_itface", "=", "PCD_PHY_EMBEDDED", ";", "hpcd_USB_FS", ".", "Init", ".", "low_power_enable", "=", "DISABLE", ";", "hpcd_USB_FS", ".", "Init", ".", "battery_charging_enable", "=", "DISABLE", ";", "if", "(", "HAL_PCD_Init", "(", "&", "hpcd_USB_FS", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "HAL_PCDEx_PMAConfig", "(", "(", "PCD_HandleTypeDef", "*", ")", "pdev", "->", "pData", ",", "0x00", ",", "PCD_SNG_BUF", ",", "0x18", ")", ";", "HAL_PCDEx_PMAConfig", "(", "(", "PCD_HandleTypeDef", "*", ")", "pdev", "->", "pData", ",", "0x80", ",", "PCD_SNG_BUF", ",", "0x58", ")", ";", "HAL_PCDEx_PMAConfig", "(", "(", "PCD_HandleTypeDef", "*", ")", "pdev", "->", "pData", ",", "0x81", ",", "PCD_SNG_BUF", ",", "0xC0", ")", ";", "HAL_PCDEx_PMAConfig", "(", "(", "PCD_HandleTypeDef", "*", ")", "pdev", "->", "pData", ",", "0x01", ",", "PCD_SNG_BUF", ",", "0x110", ")", ";", "HAL_PCDEx_PMAConfig", "(", "(", "PCD_HandleTypeDef", "*", ")", "pdev", "->", "pData", ",", "0x82", ",", "PCD_SNG_BUF", ",", "0x100", ")", ";", "return", "USBD_OK", ";", "}" ]
@brief Initializes the Low Level portion of the Device driver.
[ "@brief", "Initializes", "the", "Low", "Level", "portion", "of", "the", "Device", "driver", "." ]
[ "/* Init USB_IP */", "/* Link The driver to the stack */" ]
[ { "param": "pdev", "type": "USBD_HandleTypeDef" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pdev", "type": "USBD_HandleTypeDef", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
817bd31d7ac657ba045b68a27b20822b02f3374c
Stoefff/Object-Oriented-Programming-FMI-2017
Week03/StudentTask/Student.h
[ "MIT" ]
C
readData
void
void readData(char data[], size_t size){ while(cin && isspace(cin.peek())) cin.ignore(); cin.getline(data, size); if(cin.fail()){ cin.clear(); while(cin && '\n' != cin.get()); } cin.clear(); }
//Magic getData, or just save getline for the name
Magic getData, or just save getline for the name
[ "Magic", "getData", "or", "just", "save", "getline", "for", "the", "name" ]
void readData(char data[], size_t size){ while(cin && isspace(cin.peek())) cin.ignore(); cin.getline(data, size); if(cin.fail()){ cin.clear(); while(cin && '\n' != cin.get()); } cin.clear(); }
[ "void", "readData", "(", "char", "data", "[", "]", ",", "size_t", "size", ")", "{", "while", "(", "cin", "&&", "isspace", "(", "cin", ".", "peek", "(", ")", ")", ")", "cin", ".", "ignore", "(", ")", ";", "cin", ".", "getline", "(", "data", ",", "size", ")", ";", "if", "(", "cin", ".", "fail", "(", ")", ")", "{", "cin", ".", "clear", "(", ")", ";", "while", "(", "cin", "&&", "'", "\\n", "'", "!=", "cin", ".", "get", "(", ")", ")", ";", "}", "cin", ".", "clear", "(", ")", ";", "}" ]
Magic getData, or just save getline for the name
[ "Magic", "getData", "or", "just", "save", "getline", "for", "the", "name" ]
[]
[ { "param": "data", "type": "char" }, { "param": "size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "char", "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": [] }
acdf20a2e73b8c062bd336076e946812d78558a7
jcmoyer/moonstorm
src/moonstorm.c
[ "Apache-2.0" ]
C
luaopen_moonstorm
int
int luaopen_moonstorm(lua_State* L) { ms_init_mpqhandle(L); ms_init_filehandle(L); lua_newtable(L); luaL_setfuncs(L, ms_lib, 0); return 1; }
// C linkage required for lua to see this function
C linkage required for lua to see this function
[ "C", "linkage", "required", "for", "lua", "to", "see", "this", "function" ]
int luaopen_moonstorm(lua_State* L) { ms_init_mpqhandle(L); ms_init_filehandle(L); lua_newtable(L); luaL_setfuncs(L, ms_lib, 0); return 1; }
[ "int", "luaopen_moonstorm", "(", "lua_State", "*", "L", ")", "{", "ms_init_mpqhandle", "(", "L", ")", ";", "ms_init_filehandle", "(", "L", ")", ";", "lua_newtable", "(", "L", ")", ";", "luaL_setfuncs", "(", "L", ",", "ms_lib", ",", "0", ")", ";", "return", "1", ";", "}" ]
C linkage required for lua to see this function
[ "C", "linkage", "required", "for", "lua", "to", "see", "this", "function" ]
[]
[ { "param": "L", "type": "lua_State" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "L", "type": "lua_State", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ba5a05b0da0bad63426d406a61a7c17974e3c279
scorchfly/tpm2-tools
lib/tpm2_eventlog.c
[ "BSD-3-Clause" ]
C
foreach_digest2
bool
bool foreach_digest2(tpm2_eventlog_context *ctx, unsigned pcr_index, TCG_DIGEST2 const *digest, size_t count, size_t size) { if (digest == NULL) { LOG_ERR("digest cannot be NULL"); return false; } /* Because pcr_index is used for array indexing and bit-shift operations it is 1 less than the max value */ if (pcr_index > (TPM2_MAX_PCRS - 1)) { LOG_ERR("PCR Index %d is out of bounds for max available PCRS %d", pcr_index, TPM2_MAX_PCRS); return false; } bool ret = true; size_t i; for (i = 0; i < count; ++i) { if (size < sizeof(*digest)) { LOG_ERR("insufficient size for digest header"); return false; } const TPMI_ALG_HASH alg = digest->AlgorithmId; const size_t alg_size = tpm2_alg_util_get_hash_size(alg); if (size < sizeof(*digest) + alg_size) { LOG_ERR("insufficient size for digest buffer"); return false; } uint8_t *pcr = NULL; if (alg == TPM2_ALG_SHA1) { pcr = ctx->sha1_pcrs[pcr_index]; ctx->sha1_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SHA256) { pcr = ctx->sha256_pcrs[pcr_index]; ctx->sha256_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SHA384) { pcr = ctx->sha384_pcrs[pcr_index]; ctx->sha384_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SHA512) { pcr = ctx->sha512_pcrs[pcr_index]; ctx->sha512_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SM3_256) { pcr = ctx->sm3_256_pcrs[pcr_index]; ctx->sm3_256_used |= (1 << pcr_index); } else { LOG_WARN("PCR%d algorithm %d unsupported", pcr_index, alg); } if (pcr && !tpm2_openssl_pcr_extend(alg, pcr, digest->Digest, alg_size)) { LOG_ERR("PCR%d extend failed", pcr_index); return false; } if (ctx->digest2_cb != NULL) { ret = ctx->digest2_cb(digest, alg_size, ctx->data); if (!ret) { LOG_ERR("callback failed for digest at %p with size %zu", digest, alg_size); break; } } size -= sizeof(*digest) + alg_size; digest = (TCG_DIGEST2*)((uintptr_t)digest->Digest + alg_size); } return ret; }
/* * Invoke callback function for each TCG_DIGEST2 structure in the provided * TCG_EVENT_HEADER2. The callback function is only invoked if this function * is first able to determine that the provided buffer is large enough to * hold the digest. The size of the digest is passed to the callback in the * 'size' parameter. */
Invoke callback function for each TCG_DIGEST2 structure in the provided TCG_EVENT_HEADER2. The callback function is only invoked if this function is first able to determine that the provided buffer is large enough to hold the digest. The size of the digest is passed to the callback in the 'size' parameter.
[ "Invoke", "callback", "function", "for", "each", "TCG_DIGEST2", "structure", "in", "the", "provided", "TCG_EVENT_HEADER2", ".", "The", "callback", "function", "is", "only", "invoked", "if", "this", "function", "is", "first", "able", "to", "determine", "that", "the", "provided", "buffer", "is", "large", "enough", "to", "hold", "the", "digest", ".", "The", "size", "of", "the", "digest", "is", "passed", "to", "the", "callback", "in", "the", "'", "size", "'", "parameter", "." ]
bool foreach_digest2(tpm2_eventlog_context *ctx, unsigned pcr_index, TCG_DIGEST2 const *digest, size_t count, size_t size) { if (digest == NULL) { LOG_ERR("digest cannot be NULL"); return false; } if (pcr_index > (TPM2_MAX_PCRS - 1)) { LOG_ERR("PCR Index %d is out of bounds for max available PCRS %d", pcr_index, TPM2_MAX_PCRS); return false; } bool ret = true; size_t i; for (i = 0; i < count; ++i) { if (size < sizeof(*digest)) { LOG_ERR("insufficient size for digest header"); return false; } const TPMI_ALG_HASH alg = digest->AlgorithmId; const size_t alg_size = tpm2_alg_util_get_hash_size(alg); if (size < sizeof(*digest) + alg_size) { LOG_ERR("insufficient size for digest buffer"); return false; } uint8_t *pcr = NULL; if (alg == TPM2_ALG_SHA1) { pcr = ctx->sha1_pcrs[pcr_index]; ctx->sha1_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SHA256) { pcr = ctx->sha256_pcrs[pcr_index]; ctx->sha256_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SHA384) { pcr = ctx->sha384_pcrs[pcr_index]; ctx->sha384_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SHA512) { pcr = ctx->sha512_pcrs[pcr_index]; ctx->sha512_used |= (1 << pcr_index); } else if (alg == TPM2_ALG_SM3_256) { pcr = ctx->sm3_256_pcrs[pcr_index]; ctx->sm3_256_used |= (1 << pcr_index); } else { LOG_WARN("PCR%d algorithm %d unsupported", pcr_index, alg); } if (pcr && !tpm2_openssl_pcr_extend(alg, pcr, digest->Digest, alg_size)) { LOG_ERR("PCR%d extend failed", pcr_index); return false; } if (ctx->digest2_cb != NULL) { ret = ctx->digest2_cb(digest, alg_size, ctx->data); if (!ret) { LOG_ERR("callback failed for digest at %p with size %zu", digest, alg_size); break; } } size -= sizeof(*digest) + alg_size; digest = (TCG_DIGEST2*)((uintptr_t)digest->Digest + alg_size); } return ret; }
[ "bool", "foreach_digest2", "(", "tpm2_eventlog_context", "*", "ctx", ",", "unsigned", "pcr_index", ",", "TCG_DIGEST2", "const", "*", "digest", ",", "size_t", "count", ",", "size_t", "size", ")", "{", "if", "(", "digest", "==", "NULL", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "if", "(", "pcr_index", ">", "(", "TPM2_MAX_PCRS", "-", "1", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "pcr_index", ",", "TPM2_MAX_PCRS", ")", ";", "return", "false", ";", "}", "bool", "ret", "=", "true", ";", "size_t", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "count", ";", "++", "i", ")", "{", "if", "(", "size", "<", "sizeof", "(", "*", "digest", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "const", "TPMI_ALG_HASH", "alg", "=", "digest", "->", "AlgorithmId", ";", "const", "size_t", "alg_size", "=", "tpm2_alg_util_get_hash_size", "(", "alg", ")", ";", "if", "(", "size", "<", "sizeof", "(", "*", "digest", ")", "+", "alg_size", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "uint8_t", "*", "pcr", "=", "NULL", ";", "if", "(", "alg", "==", "TPM2_ALG_SHA1", ")", "{", "pcr", "=", "ctx", "->", "sha1_pcrs", "[", "pcr_index", "]", ";", "ctx", "->", "sha1_used", "|=", "(", "1", "<<", "pcr_index", ")", ";", "}", "else", "if", "(", "alg", "==", "TPM2_ALG_SHA256", ")", "{", "pcr", "=", "ctx", "->", "sha256_pcrs", "[", "pcr_index", "]", ";", "ctx", "->", "sha256_used", "|=", "(", "1", "<<", "pcr_index", ")", ";", "}", "else", "if", "(", "alg", "==", "TPM2_ALG_SHA384", ")", "{", "pcr", "=", "ctx", "->", "sha384_pcrs", "[", "pcr_index", "]", ";", "ctx", "->", "sha384_used", "|=", "(", "1", "<<", "pcr_index", ")", ";", "}", "else", "if", "(", "alg", "==", "TPM2_ALG_SHA512", ")", "{", "pcr", "=", "ctx", "->", "sha512_pcrs", "[", "pcr_index", "]", ";", "ctx", "->", "sha512_used", "|=", "(", "1", "<<", "pcr_index", ")", ";", "}", "else", "if", "(", "alg", "==", "TPM2_ALG_SM3_256", ")", "{", "pcr", "=", "ctx", "->", "sm3_256_pcrs", "[", "pcr_index", "]", ";", "ctx", "->", "sm3_256_used", "|=", "(", "1", "<<", "pcr_index", ")", ";", "}", "else", "{", "LOG_WARN", "(", "\"", "\"", ",", "pcr_index", ",", "alg", ")", ";", "}", "if", "(", "pcr", "&&", "!", "tpm2_openssl_pcr_extend", "(", "alg", ",", "pcr", ",", "digest", "->", "Digest", ",", "alg_size", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "pcr_index", ")", ";", "return", "false", ";", "}", "if", "(", "ctx", "->", "digest2_cb", "!=", "NULL", ")", "{", "ret", "=", "ctx", "->", "digest2_cb", "(", "digest", ",", "alg_size", ",", "ctx", "->", "data", ")", ";", "if", "(", "!", "ret", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "digest", ",", "alg_size", ")", ";", "break", ";", "}", "}", "size", "-=", "sizeof", "(", "*", "digest", ")", "+", "alg_size", ";", "digest", "=", "(", "TCG_DIGEST2", "*", ")", "(", "(", "uintptr_t", ")", "digest", "->", "Digest", "+", "alg_size", ")", ";", "}", "return", "ret", ";", "}" ]
Invoke callback function for each TCG_DIGEST2 structure in the provided TCG_EVENT_HEADER2.
[ "Invoke", "callback", "function", "for", "each", "TCG_DIGEST2", "structure", "in", "the", "provided", "TCG_EVENT_HEADER2", "." ]
[ "/* Because pcr_index is used for array indexing and bit-shift operations it\n is 1 less than the max value */" ]
[ { "param": "ctx", "type": "tpm2_eventlog_context" }, { "param": "pcr_index", "type": "unsigned" }, { "param": "digest", "type": "TCG_DIGEST2" }, { "param": "count", "type": "size_t" }, { "param": "size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "tpm2_eventlog_context", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pcr_index", "type": "unsigned", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "digest", "type": "TCG_DIGEST2", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "count", "type": "size_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": [] }
ba5a05b0da0bad63426d406a61a7c17974e3c279
scorchfly/tpm2-tools
lib/tpm2_eventlog.c
[ "BSD-3-Clause" ]
C
parse_event2body
bool
bool parse_event2body(TCG_EVENT2 const *event, UINT32 type) { switch (type) { /* TCG PC Client FPF section 9.2.6 */ case EV_EFI_VARIABLE_DRIVER_CONFIG: case EV_EFI_VARIABLE_BOOT: case EV_EFI_VARIABLE_AUTHORITY: { UEFI_VARIABLE_DATA *data = (UEFI_VARIABLE_DATA*)event->Event; if (event->EventSize < sizeof(*data)) { LOG_ERR("size is insufficient for UEFI variable data"); return false; } if (event->EventSize < sizeof(*data) + data->UnicodeNameLength * sizeof(char16_t) + data->VariableDataLength) { LOG_ERR("size is insufficient for UEFI variable data"); return false; } } break; /* TCG PC Client FPF section 2.3.4.1 and 9.4.1 */ case EV_POST_CODE: // the event is a string, so there are no length requirements. break; /* TCG PC Client FPF section 9.2.5 */ case EV_S_CRTM_CONTENTS: case EV_EFI_PLATFORM_FIRMWARE_BLOB: { UEFI_PLATFORM_FIRMWARE_BLOB *data = (UEFI_PLATFORM_FIRMWARE_BLOB*)event->Event; UNUSED(data); if (event->EventSize < sizeof(*data)) { LOG_ERR("size is insufficient for UEFI FW blob data"); return false; } } break; case EV_EFI_BOOT_SERVICES_APPLICATION: case EV_EFI_BOOT_SERVICES_DRIVER: case EV_EFI_RUNTIME_SERVICES_DRIVER: { UEFI_IMAGE_LOAD_EVENT *data = (UEFI_IMAGE_LOAD_EVENT*)event->Event; UNUSED(data); if (event->EventSize < sizeof(*data)) { LOG_ERR("size is insufficient for UEFI image load event"); return false; } /* what about the device path? */ } break; } return true; }
/* * given the provided event type, parse event to ensure the structure / data * in the buffer doesn't exceed the buffer size */
given the provided event type, parse event to ensure the structure / data in the buffer doesn't exceed the buffer size
[ "given", "the", "provided", "event", "type", "parse", "event", "to", "ensure", "the", "structure", "/", "data", "in", "the", "buffer", "doesn", "'", "t", "exceed", "the", "buffer", "size" ]
bool parse_event2body(TCG_EVENT2 const *event, UINT32 type) { switch (type) { case EV_EFI_VARIABLE_DRIVER_CONFIG: case EV_EFI_VARIABLE_BOOT: case EV_EFI_VARIABLE_AUTHORITY: { UEFI_VARIABLE_DATA *data = (UEFI_VARIABLE_DATA*)event->Event; if (event->EventSize < sizeof(*data)) { LOG_ERR("size is insufficient for UEFI variable data"); return false; } if (event->EventSize < sizeof(*data) + data->UnicodeNameLength * sizeof(char16_t) + data->VariableDataLength) { LOG_ERR("size is insufficient for UEFI variable data"); return false; } } break; case EV_POST_CODE: break; case EV_S_CRTM_CONTENTS: case EV_EFI_PLATFORM_FIRMWARE_BLOB: { UEFI_PLATFORM_FIRMWARE_BLOB *data = (UEFI_PLATFORM_FIRMWARE_BLOB*)event->Event; UNUSED(data); if (event->EventSize < sizeof(*data)) { LOG_ERR("size is insufficient for UEFI FW blob data"); return false; } } break; case EV_EFI_BOOT_SERVICES_APPLICATION: case EV_EFI_BOOT_SERVICES_DRIVER: case EV_EFI_RUNTIME_SERVICES_DRIVER: { UEFI_IMAGE_LOAD_EVENT *data = (UEFI_IMAGE_LOAD_EVENT*)event->Event; UNUSED(data); if (event->EventSize < sizeof(*data)) { LOG_ERR("size is insufficient for UEFI image load event"); return false; } } break; } return true; }
[ "bool", "parse_event2body", "(", "TCG_EVENT2", "const", "*", "event", ",", "UINT32", "type", ")", "{", "switch", "(", "type", ")", "{", "case", "EV_EFI_VARIABLE_DRIVER_CONFIG", ":", "case", "EV_EFI_VARIABLE_BOOT", ":", "case", "EV_EFI_VARIABLE_AUTHORITY", ":", "{", "UEFI_VARIABLE_DATA", "*", "data", "=", "(", "UEFI_VARIABLE_DATA", "*", ")", "event", "->", "Event", ";", "if", "(", "event", "->", "EventSize", "<", "sizeof", "(", "*", "data", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "if", "(", "event", "->", "EventSize", "<", "sizeof", "(", "*", "data", ")", "+", "data", "->", "UnicodeNameLength", "*", "sizeof", "(", "char16_t", ")", "+", "data", "->", "VariableDataLength", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "}", "break", ";", "case", "EV_POST_CODE", ":", "break", ";", "case", "EV_S_CRTM_CONTENTS", ":", "case", "EV_EFI_PLATFORM_FIRMWARE_BLOB", ":", "{", "UEFI_PLATFORM_FIRMWARE_BLOB", "*", "data", "=", "(", "UEFI_PLATFORM_FIRMWARE_BLOB", "*", ")", "event", "->", "Event", ";", "UNUSED", "(", "data", ")", ";", "if", "(", "event", "->", "EventSize", "<", "sizeof", "(", "*", "data", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "}", "break", ";", "case", "EV_EFI_BOOT_SERVICES_APPLICATION", ":", "case", "EV_EFI_BOOT_SERVICES_DRIVER", ":", "case", "EV_EFI_RUNTIME_SERVICES_DRIVER", ":", "{", "UEFI_IMAGE_LOAD_EVENT", "*", "data", "=", "(", "UEFI_IMAGE_LOAD_EVENT", "*", ")", "event", "->", "Event", ";", "UNUSED", "(", "data", ")", ";", "if", "(", "event", "->", "EventSize", "<", "sizeof", "(", "*", "data", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "}", "break", ";", "}", "return", "true", ";", "}" ]
given the provided event type, parse event to ensure the structure / data in the buffer doesn't exceed the buffer size
[ "given", "the", "provided", "event", "type", "parse", "event", "to", "ensure", "the", "structure", "/", "data", "in", "the", "buffer", "doesn", "'", "t", "exceed", "the", "buffer", "size" ]
[ "/* TCG PC Client FPF section 9.2.6 */", "/* TCG PC Client FPF section 2.3.4.1 and 9.4.1 */", "// the event is a string, so there are no length requirements.", "/* TCG PC Client FPF section 9.2.5 */", "/* what about the device path? */" ]
[ { "param": "event", "type": "TCG_EVENT2" }, { "param": "type", "type": "UINT32" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "event", "type": "TCG_EVENT2", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "type", "type": "UINT32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ba5a05b0da0bad63426d406a61a7c17974e3c279
scorchfly/tpm2-tools
lib/tpm2_eventlog.c
[ "BSD-3-Clause" ]
C
parse_event2
bool
bool parse_event2(TCG_EVENT_HEADER2 const *eventhdr, size_t buf_size, size_t *event_size, size_t *digests_size) { bool ret; if (buf_size < sizeof(*eventhdr)) { LOG_ERR("corrupted log, insufficient size for event header: %zu", buf_size); return false; } *event_size = sizeof(*eventhdr); tpm2_eventlog_context ctx = { .data = digests_size, .digest2_cb = digest2_accumulator_callback, }; ret = foreach_digest2(&ctx, eventhdr->PCRIndex, eventhdr->Digests, eventhdr->DigestCount, buf_size - sizeof(*eventhdr)); if (ret != true) { return false; } *event_size += *digests_size; TCG_EVENT2 *event = (TCG_EVENT2*)((uintptr_t)eventhdr + *event_size); if (buf_size < *event_size + sizeof(*event)) { LOG_ERR("corrupted log: size insufficient for EventSize"); return false; } *event_size += sizeof(*event); if (buf_size < *event_size + event->EventSize) { LOG_ERR("size insufficient for event data"); return false; } *event_size += event->EventSize; return true; }
/* * parse event structure, including header, digests and event buffer ensuring * it all fits within the provided buffer (buf_size). */
parse event structure, including header, digests and event buffer ensuring it all fits within the provided buffer (buf_size).
[ "parse", "event", "structure", "including", "header", "digests", "and", "event", "buffer", "ensuring", "it", "all", "fits", "within", "the", "provided", "buffer", "(", "buf_size", ")", "." ]
bool parse_event2(TCG_EVENT_HEADER2 const *eventhdr, size_t buf_size, size_t *event_size, size_t *digests_size) { bool ret; if (buf_size < sizeof(*eventhdr)) { LOG_ERR("corrupted log, insufficient size for event header: %zu", buf_size); return false; } *event_size = sizeof(*eventhdr); tpm2_eventlog_context ctx = { .data = digests_size, .digest2_cb = digest2_accumulator_callback, }; ret = foreach_digest2(&ctx, eventhdr->PCRIndex, eventhdr->Digests, eventhdr->DigestCount, buf_size - sizeof(*eventhdr)); if (ret != true) { return false; } *event_size += *digests_size; TCG_EVENT2 *event = (TCG_EVENT2*)((uintptr_t)eventhdr + *event_size); if (buf_size < *event_size + sizeof(*event)) { LOG_ERR("corrupted log: size insufficient for EventSize"); return false; } *event_size += sizeof(*event); if (buf_size < *event_size + event->EventSize) { LOG_ERR("size insufficient for event data"); return false; } *event_size += event->EventSize; return true; }
[ "bool", "parse_event2", "(", "TCG_EVENT_HEADER2", "const", "*", "eventhdr", ",", "size_t", "buf_size", ",", "size_t", "*", "event_size", ",", "size_t", "*", "digests_size", ")", "{", "bool", "ret", ";", "if", "(", "buf_size", "<", "sizeof", "(", "*", "eventhdr", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ",", "buf_size", ")", ";", "return", "false", ";", "}", "*", "event_size", "=", "sizeof", "(", "*", "eventhdr", ")", ";", "tpm2_eventlog_context", "ctx", "=", "{", ".", "data", "=", "digests_size", ",", ".", "digest2_cb", "=", "digest2_accumulator_callback", ",", "}", ";", "ret", "=", "foreach_digest2", "(", "&", "ctx", ",", "eventhdr", "->", "PCRIndex", ",", "eventhdr", "->", "Digests", ",", "eventhdr", "->", "DigestCount", ",", "buf_size", "-", "sizeof", "(", "*", "eventhdr", ")", ")", ";", "if", "(", "ret", "!=", "true", ")", "{", "return", "false", ";", "}", "*", "event_size", "+=", "*", "digests_size", ";", "TCG_EVENT2", "*", "event", "=", "(", "TCG_EVENT2", "*", ")", "(", "(", "uintptr_t", ")", "eventhdr", "+", "*", "event_size", ")", ";", "if", "(", "buf_size", "<", "*", "event_size", "+", "sizeof", "(", "*", "event", ")", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "*", "event_size", "+=", "sizeof", "(", "*", "event", ")", ";", "if", "(", "buf_size", "<", "*", "event_size", "+", "event", "->", "EventSize", ")", "{", "LOG_ERR", "(", "\"", "\"", ")", ";", "return", "false", ";", "}", "*", "event_size", "+=", "event", "->", "EventSize", ";", "return", "true", ";", "}" ]
parse event structure, including header, digests and event buffer ensuring it all fits within the provided buffer (buf_size).
[ "parse", "event", "structure", "including", "header", "digests", "and", "event", "buffer", "ensuring", "it", "all", "fits", "within", "the", "provided", "buffer", "(", "buf_size", ")", "." ]
[]
[ { "param": "eventhdr", "type": "TCG_EVENT_HEADER2" }, { "param": "buf_size", "type": "size_t" }, { "param": "event_size", "type": "size_t" }, { "param": "digests_size", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "eventhdr", "type": "TCG_EVENT_HEADER2", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf_size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "event_size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "digests_size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
051f7bbba2d023ca41cb722c930441030a3004ef
YJessicaGao/easydk
infer_server/src/util/env.h
[ "Apache-2.0" ]
C
GetCpuCoreNumber
int
inline int GetCpuCoreNumber() { #ifdef _MSC_VER SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); return sysInfo.dwNumberOfProcessors; #else /* return sysconf(_SC_NPROCESSORS_ONLN); */ // GNU way return get_nprocs(); #endif }
/** * @brief Get CPU core number * * @return int CPU core number */
@brief Get CPU core number @return int CPU core number
[ "@brief", "Get", "CPU", "core", "number", "@return", "int", "CPU", "core", "number" ]
inline int GetCpuCoreNumber() { #ifdef _MSC_VER SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); return sysInfo.dwNumberOfProcessors; #else return get_nprocs(); #endif }
[ "inline", "int", "GetCpuCoreNumber", "(", ")", "{", "#ifdef", "_MSC_VER", "SYSTEM_INFO", "sysInfo", ";", "GetSystemInfo", "(", "&", "sysInfo", ")", ";", "return", "sysInfo", ".", "dwNumberOfProcessors", ";", "#else", "return", "get_nprocs", "(", ")", ";", "#endif", "}" ]
@brief Get CPU core number @return int CPU core number
[ "@brief", "Get", "CPU", "core", "number", "@return", "int", "CPU", "core", "number" ]
[ "/* return sysconf(_SC_NPROCESSORS_ONLN); */", "// GNU way" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
674ff21ddf98de9d22b5fd0bcae07177ebbc479a
ARLM-Attic/nkinect
External/Include/XnCppWrapper.h
[ "Apache-2.0" ]
C
AllocateData
XnStatus
XnStatus AllocateData(XnUInt32 nBytes) { if (nBytes > m_nAllocatedSize) { // reallocate XnUInt8* pData = (XnUInt8*)xnOSMallocAligned(nBytes, XN_DEFAULT_MEM_ALIGN); XN_VALIDATE_ALLOC_PTR(pData); // allocation succeeded, replace Free(); m_pAllocatedData = pData; m_nAllocatedSize = nBytes; } DataSize() = nBytes; *m_ppData = m_pAllocatedData; return XN_STATUS_OK; }
/** * @brief Allocated a writable buffer. If a previous buffer was allocated it will be freed (or reused if possible). * Also see @ref conc_meta_data. * * @param nBytes [in] The requested size for the buffer, in bytes. */
@brief Allocated a writable buffer. If a previous buffer was allocated it will be freed (or reused if possible). Also see @ref conc_meta_data. @param nBytes [in] The requested size for the buffer, in bytes.
[ "@brief", "Allocated", "a", "writable", "buffer", ".", "If", "a", "previous", "buffer", "was", "allocated", "it", "will", "be", "freed", "(", "or", "reused", "if", "possible", ")", ".", "Also", "see", "@ref", "conc_meta_data", ".", "@param", "nBytes", "[", "in", "]", "The", "requested", "size", "for", "the", "buffer", "in", "bytes", "." ]
XnStatus AllocateData(XnUInt32 nBytes) { if (nBytes > m_nAllocatedSize) { XnUInt8* pData = (XnUInt8*)xnOSMallocAligned(nBytes, XN_DEFAULT_MEM_ALIGN); XN_VALIDATE_ALLOC_PTR(pData); Free(); m_pAllocatedData = pData; m_nAllocatedSize = nBytes; } DataSize() = nBytes; *m_ppData = m_pAllocatedData; return XN_STATUS_OK; }
[ "XnStatus", "AllocateData", "(", "XnUInt32", "nBytes", ")", "{", "if", "(", "nBytes", ">", "m_nAllocatedSize", ")", "{", "XnUInt8", "*", "pData", "=", "(", "XnUInt8", "*", ")", "xnOSMallocAligned", "(", "nBytes", ",", "XN_DEFAULT_MEM_ALIGN", ")", ";", "XN_VALIDATE_ALLOC_PTR", "(", "pData", ")", ";", "Free", "(", ")", ";", "m_pAllocatedData", "=", "pData", ";", "m_nAllocatedSize", "=", "nBytes", ";", "}", "DataSize", "(", ")", "=", "nBytes", ";", "*", "m_ppData", "=", "m_pAllocatedData", ";", "return", "XN_STATUS_OK", ";", "}" ]
@brief Allocated a writable buffer.
[ "@brief", "Allocated", "a", "writable", "buffer", "." ]
[ "// reallocate\r", "// allocation succeeded, replace\r" ]
[ { "param": "nBytes", "type": "XnUInt32" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "nBytes", "type": "XnUInt32", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
674ff21ddf98de9d22b5fd0bcae07177ebbc479a
ARLM-Attic/nkinect
External/Include/XnCppWrapper.h
[ "Apache-2.0" ]
C
ReplaceUnderlyingObject
void
inline void ReplaceUnderlyingObject(XnNodeInfoList* pList) { FreeImpl(); m_pList = pList; m_bAllocated = TRUE; }
/** * Replaces the underlying object, taking ownership of the object (meaning, it * will be freed upon destruction). * * @param pList [in] The list to wrap. */
Replaces the underlying object, taking ownership of the object (meaning, it will be freed upon destruction). @param pList [in] The list to wrap.
[ "Replaces", "the", "underlying", "object", "taking", "ownership", "of", "the", "object", "(", "meaning", "it", "will", "be", "freed", "upon", "destruction", ")", ".", "@param", "pList", "[", "in", "]", "The", "list", "to", "wrap", "." ]
inline void ReplaceUnderlyingObject(XnNodeInfoList* pList) { FreeImpl(); m_pList = pList; m_bAllocated = TRUE; }
[ "inline", "void", "ReplaceUnderlyingObject", "(", "XnNodeInfoList", "*", "pList", ")", "{", "FreeImpl", "(", ")", ";", "m_pList", "=", "pList", ";", "m_bAllocated", "=", "TRUE", ";", "}" ]
Replaces the underlying object, taking ownership of the object (meaning, it will be freed upon destruction).
[ "Replaces", "the", "underlying", "object", "taking", "ownership", "of", "the", "object", "(", "meaning", "it", "will", "be", "freed", "upon", "destruction", ")", "." ]
[]
[ { "param": "pList", "type": "XnNodeInfoList" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pList", "type": "XnNodeInfoList", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
054641f90218e099054d3eeb52bee5c975324d70
ab1aw/stm32f4-bare-metal
projects/itm/itm.c
[ "MIT" ]
C
delay
void
void delay(volatile uint32_t s) { for(s; s>0; s--){ // Do nothing } }
// A simple and not accurate delay function // that will change the speed based on the optimization settings
A simple and not accurate delay function that will change the speed based on the optimization settings
[ "A", "simple", "and", "not", "accurate", "delay", "function", "that", "will", "change", "the", "speed", "based", "on", "the", "optimization", "settings" ]
void delay(volatile uint32_t s) { for(s; s>0; s--){ } }
[ "void", "delay", "(", "volatile", "uint32_t", "s", ")", "{", "for", "(", "s", ";", "s", ">", "0", ";", "s", "--", ")", "{", "}", "}" ]
A simple and not accurate delay function that will change the speed based on the optimization settings
[ "A", "simple", "and", "not", "accurate", "delay", "function", "that", "will", "change", "the", "speed", "based", "on", "the", "optimization", "settings" ]
[ "// Do nothing" ]
[ { "param": "s", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "s", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
34f9b17e9177df34cbd73090455dab06f180d14c
GZHoffie/Approximate-String-Matching
GASMA/hurdle_matrix.h
[ "MIT" ]
C
_update_match
void
void _update_match(int best_lane, int curr_lane, int distance) { // update matched strings if (best_lane < curr_lane) { for (int i = best_lane; i < curr_lane; i++) { A_match[A_match_index] = A_orig[A_index]; B_match[B_match_index] = '-'; A_match_index++, B_match_index++, A_index++; } } else { for (int i = curr_lane; i < best_lane; i++) { A_match[A_match_index] = '-'; B_match[B_match_index] = B_orig[B_index]; A_match_index++, B_match_index++, B_index++; } } for (int i = 0; i < distance; i++) { A_match[A_match_index] = A_orig[A_index]; B_match[B_match_index] = B_orig[B_index]; A_match_index++, B_match_index++, A_index++, B_index++; } #ifdef DEBUG printf("%s\n%s\n", A_match, B_match); #endif }
/** * Update the matching strings given the lanes we are leaping to and the distance we * are moving. * @param best_lane The lane we are leaping to. * @param curr_lane The lane we are currently at. * @param distance The distance we travel on best_lane to reach the highway. */
Update the matching strings given the lanes we are leaping to and the distance we are moving. @param best_lane The lane we are leaping to. @param curr_lane The lane we are currently at. @param distance The distance we travel on best_lane to reach the highway.
[ "Update", "the", "matching", "strings", "given", "the", "lanes", "we", "are", "leaping", "to", "and", "the", "distance", "we", "are", "moving", ".", "@param", "best_lane", "The", "lane", "we", "are", "leaping", "to", ".", "@param", "curr_lane", "The", "lane", "we", "are", "currently", "at", ".", "@param", "distance", "The", "distance", "we", "travel", "on", "best_lane", "to", "reach", "the", "highway", "." ]
void _update_match(int best_lane, int curr_lane, int distance) { if (best_lane < curr_lane) { for (int i = best_lane; i < curr_lane; i++) { A_match[A_match_index] = A_orig[A_index]; B_match[B_match_index] = '-'; A_match_index++, B_match_index++, A_index++; } } else { for (int i = curr_lane; i < best_lane; i++) { A_match[A_match_index] = '-'; B_match[B_match_index] = B_orig[B_index]; A_match_index++, B_match_index++, B_index++; } } for (int i = 0; i < distance; i++) { A_match[A_match_index] = A_orig[A_index]; B_match[B_match_index] = B_orig[B_index]; A_match_index++, B_match_index++, A_index++, B_index++; } #ifdef DEBUG printf("%s\n%s\n", A_match, B_match); #endif }
[ "void", "_update_match", "(", "int", "best_lane", ",", "int", "curr_lane", ",", "int", "distance", ")", "{", "if", "(", "best_lane", "<", "curr_lane", ")", "{", "for", "(", "int", "i", "=", "best_lane", ";", "i", "<", "curr_lane", ";", "i", "++", ")", "{", "A_match", "[", "A_match_index", "]", "=", "A_orig", "[", "A_index", "]", ";", "B_match", "[", "B_match_index", "]", "=", "'", "'", ";", "A_match_index", "++", ",", "B_match_index", "++", ",", "A_index", "++", ";", "}", "}", "else", "{", "for", "(", "int", "i", "=", "curr_lane", ";", "i", "<", "best_lane", ";", "i", "++", ")", "{", "A_match", "[", "A_match_index", "]", "=", "'", "'", ";", "B_match", "[", "B_match_index", "]", "=", "B_orig", "[", "B_index", "]", ";", "A_match_index", "++", ",", "B_match_index", "++", ",", "B_index", "++", ";", "}", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "distance", ";", "i", "++", ")", "{", "A_match", "[", "A_match_index", "]", "=", "A_orig", "[", "A_index", "]", ";", "B_match", "[", "B_match_index", "]", "=", "B_orig", "[", "B_index", "]", ";", "A_match_index", "++", ",", "B_match_index", "++", ",", "A_index", "++", ",", "B_index", "++", ";", "}", "#ifdef", "DEBUG", "printf", "(", "\"", "\\n", "\\n", "\"", ",", "A_match", ",", "B_match", ")", ";", "#endif", "}" ]
Update the matching strings given the lanes we are leaping to and the distance we are moving.
[ "Update", "the", "matching", "strings", "given", "the", "lanes", "we", "are", "leaping", "to", "and", "the", "distance", "we", "are", "moving", "." ]
[ "// update matched strings\r" ]
[ { "param": "best_lane", "type": "int" }, { "param": "curr_lane", "type": "int" }, { "param": "distance", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "best_lane", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "curr_lane", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "distance", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
34f9b17e9177df34cbd73090455dab06f180d14c
GZHoffie/Approximate-String-Matching
GASMA/hurdle_matrix.h
[ "MIT" ]
C
_step
bool
bool _step() { if (!_update_highway_list()) { return true; } int best_lane = _choose_best_highway(); cost += (*highway_list)[best_lane].switch_cost + (*highway_list)[best_lane].hurdle_cost; // update matched strings int distance = (*highway_list)[best_lane].starting_point + (*highway_list)[best_lane].length - (current_column + switch_forward_column(current_lane, best_lane)); #ifdef DISPLAY _update_match(best_lane, current_lane, distance); #endif // Update CIGAR _update_CIGAR(best_lane, current_lane, distance - (*highway_list)[best_lane].length, (*highway_list)[best_lane].length); // Update position current_lane = best_lane; current_column = (*highway_list)[best_lane].starting_point + (*highway_list)[best_lane].length; #ifdef DEBUG printf("current position: %d, %d\n", current_lane, current_column); #endif // Check if we reach the destination if (current_column >= (*highway_list)[current_lane].destination) { return true; } return false; }
/** * Perform one step in the greedy algorithm. * @return a boolean value indicating whether we complete the matching. */
Perform one step in the greedy algorithm. @return a boolean value indicating whether we complete the matching.
[ "Perform", "one", "step", "in", "the", "greedy", "algorithm", ".", "@return", "a", "boolean", "value", "indicating", "whether", "we", "complete", "the", "matching", "." ]
bool _step() { if (!_update_highway_list()) { return true; } int best_lane = _choose_best_highway(); cost += (*highway_list)[best_lane].switch_cost + (*highway_list)[best_lane].hurdle_cost; int distance = (*highway_list)[best_lane].starting_point + (*highway_list)[best_lane].length - (current_column + switch_forward_column(current_lane, best_lane)); #ifdef DISPLAY _update_match(best_lane, current_lane, distance); #endif _update_CIGAR(best_lane, current_lane, distance - (*highway_list)[best_lane].length, (*highway_list)[best_lane].length); current_lane = best_lane; current_column = (*highway_list)[best_lane].starting_point + (*highway_list)[best_lane].length; #ifdef DEBUG printf("current position: %d, %d\n", current_lane, current_column); #endif if (current_column >= (*highway_list)[current_lane].destination) { return true; } return false; }
[ "bool", "_step", "(", ")", "{", "if", "(", "!", "_update_highway_list", "(", ")", ")", "{", "return", "true", ";", "}", "int", "best_lane", "=", "_choose_best_highway", "(", ")", ";", "cost", "+=", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "switch_cost", "+", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "hurdle_cost", ";", "int", "distance", "=", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "starting_point", "+", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "length", "-", "(", "current_column", "+", "switch_forward_column", "(", "current_lane", ",", "best_lane", ")", ")", ";", "#ifdef", "DISPLAY", "_update_match", "(", "best_lane", ",", "current_lane", ",", "distance", ")", ";", "#endif", "_update_CIGAR", "(", "best_lane", ",", "current_lane", ",", "distance", "-", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "length", ",", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "length", ")", ";", "current_lane", "=", "best_lane", ";", "current_column", "=", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "starting_point", "+", "(", "*", "highway_list", ")", "[", "best_lane", "]", ".", "length", ";", "#ifdef", "DEBUG", "printf", "(", "\"", "\\n", "\"", ",", "current_lane", ",", "current_column", ")", ";", "#endif", "if", "(", "current_column", ">=", "(", "*", "highway_list", ")", "[", "current_lane", "]", ".", "destination", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Perform one step in the greedy algorithm.
[ "Perform", "one", "step", "in", "the", "greedy", "algorithm", "." ]
[ "// update matched strings\r", "// Update CIGAR\r", "// Update position\r", "// Check if we reach the destination\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
34f9b17e9177df34cbd73090455dab06f180d14c
GZHoffie/Approximate-String-Matching
GASMA/hurdle_matrix.h
[ "MIT" ]
C
_construct_hurdles
void
void _construct_hurdles() { int_128bit mask_bit0, mask_bit1; for (int lane = lower_bound; lane <= upper_bound; lane++) { if (lane < 0) { mask_bit0 = (A_bit0_mask->shift_left(-lane))._xor(*B_bit0_mask); mask_bit1 = (A_bit1_mask->shift_left(-lane))._xor(*B_bit1_mask); } else { mask_bit0 = (B_bit0_mask->shift_left(lane))._xor(*A_bit0_mask); mask_bit1 = (B_bit1_mask->shift_left(lane))._xor(*A_bit1_mask); } auto mask = mask_bit0._or(mask_bit1); (*this)[lane] = mask; } }
/** * Construct 128-bit boolean vectors where the i-th element stores whether * read[i] matches ref[i+shift], where shift is the lane id that is between * -k and k. Store everything in `lanes`. */
Construct 128-bit boolean vectors where the i-th element stores whether read[i] matches ref[i+shift], where shift is the lane id that is between -k and k. Store everything in `lanes`.
[ "Construct", "128", "-", "bit", "boolean", "vectors", "where", "the", "i", "-", "th", "element", "stores", "whether", "read", "[", "i", "]", "matches", "ref", "[", "i", "+", "shift", "]", "where", "shift", "is", "the", "lane", "id", "that", "is", "between", "-", "k", "and", "k", ".", "Store", "everything", "in", "`", "lanes", "`", "." ]
void _construct_hurdles() { int_128bit mask_bit0, mask_bit1; for (int lane = lower_bound; lane <= upper_bound; lane++) { if (lane < 0) { mask_bit0 = (A_bit0_mask->shift_left(-lane))._xor(*B_bit0_mask); mask_bit1 = (A_bit1_mask->shift_left(-lane))._xor(*B_bit1_mask); } else { mask_bit0 = (B_bit0_mask->shift_left(lane))._xor(*A_bit0_mask); mask_bit1 = (B_bit1_mask->shift_left(lane))._xor(*A_bit1_mask); } auto mask = mask_bit0._or(mask_bit1); (*this)[lane] = mask; } }
[ "void", "_construct_hurdles", "(", ")", "{", "int_128bit", "mask_bit0", ",", "mask_bit1", ";", "for", "(", "int", "lane", "=", "lower_bound", ";", "lane", "<=", "upper_bound", ";", "lane", "++", ")", "{", "if", "(", "lane", "<", "0", ")", "{", "mask_bit0", "=", "(", "A_bit0_mask", "->", "shift_left", "(", "-", "lane", ")", ")", ".", "_xor", "(", "*", "B_bit0_mask", ")", ";", "mask_bit1", "=", "(", "A_bit1_mask", "->", "shift_left", "(", "-", "lane", ")", ")", ".", "_xor", "(", "*", "B_bit1_mask", ")", ";", "}", "else", "{", "mask_bit0", "=", "(", "B_bit0_mask", "->", "shift_left", "(", "lane", ")", ")", ".", "_xor", "(", "*", "A_bit0_mask", ")", ";", "mask_bit1", "=", "(", "B_bit1_mask", "->", "shift_left", "(", "lane", ")", ")", ".", "_xor", "(", "*", "A_bit1_mask", ")", ";", "}", "auto", "mask", "", "=", "mask_bit0", ".", "_or", "(", "mask_bit1", ")", ";", "(", "*", "this", ")", "[", "lane", "]", "=", "mask", ";", "}", "}" ]
Construct 128-bit boolean vectors where the i-th element stores whether read[i] matches ref[i+shift], where shift is the lane id that is between -k and k. Store everything in `lanes`.
[ "Construct", "128", "-", "bit", "boolean", "vectors", "where", "the", "i", "-", "th", "element", "stores", "whether", "read", "[", "i", "]", "matches", "ref", "[", "i", "+", "shift", "]", "where", "shift", "is", "the", "lane", "id", "that", "is", "between", "-", "k", "and", "k", ".", "Store", "everything", "in", "`", "lanes", "`", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
34f9b17e9177df34cbd73090455dab06f180d14c
GZHoffie/Approximate-String-Matching
GASMA/hurdle_matrix.h
[ "MIT" ]
C
print
void
void print() { for (int i = lower_bound; i <= upper_bound; i++) { printf("lane %d:", i); (*this)[i].print(); } }
/** * Print out the hurdle matrix in bit form. */
Print out the hurdle matrix in bit form.
[ "Print", "out", "the", "hurdle", "matrix", "in", "bit", "form", "." ]
void print() { for (int i = lower_bound; i <= upper_bound; i++) { printf("lane %d:", i); (*this)[i].print(); } }
[ "void", "print", "(", ")", "{", "for", "(", "int", "i", "=", "lower_bound", ";", "i", "<=", "upper_bound", ";", "i", "++", ")", "{", "printf", "(", "\"", "\"", ",", "i", ")", ";", "(", "*", "this", ")", "[", "i", "]", ".", "print", "(", ")", ";", "}", "}" ]
Print out the hurdle matrix in bit form.
[ "Print", "out", "the", "hurdle", "matrix", "in", "bit", "form", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
16b657d4e983799a4bf5658bc90299a1e2afea17
GZHoffie/Approximate-String-Matching
GASMA/benchmark/benchmark_dataset.h
[ "MIT" ]
C
rand_iid
uint64_t
uint64_t rand_iid(const uint64_t min,const uint64_t max) { int n_rand = rand(); // [0, RAND_MAX] const uint64_t range = max - min; const uint64_t rem = RAND_MAX % range; const uint64_t sample = RAND_MAX / range; // Consider the small interval within remainder of RAND_MAX if (n_rand < RAND_MAX - rem) { return min + n_rand/sample; } else { return rand_iid(min,max); } }
/** * Generate random number between min and max * @return a uint64 object that is randomly generated between min and max */
Generate random number between min and max @return a uint64 object that is randomly generated between min and max
[ "Generate", "random", "number", "between", "min", "and", "max", "@return", "a", "uint64", "object", "that", "is", "randomly", "generated", "between", "min", "and", "max" ]
uint64_t rand_iid(const uint64_t min,const uint64_t max) { int n_rand = rand(); const uint64_t range = max - min; const uint64_t rem = RAND_MAX % range; const uint64_t sample = RAND_MAX / range; if (n_rand < RAND_MAX - rem) { return min + n_rand/sample; } else { return rand_iid(min,max); } }
[ "uint64_t", "rand_iid", "(", "const", "uint64_t", "min", ",", "const", "uint64_t", "max", ")", "{", "int", "n_rand", "=", "rand", "(", ")", ";", "const", "uint64_t", "range", "=", "max", "-", "min", ";", "const", "uint64_t", "rem", "=", "RAND_MAX", "%", "range", ";", "const", "uint64_t", "sample", "=", "RAND_MAX", "/", "range", ";", "if", "(", "n_rand", "<", "RAND_MAX", "-", "rem", ")", "{", "return", "min", "+", "n_rand", "/", "sample", ";", "}", "else", "{", "return", "rand_iid", "(", "min", ",", "max", ")", ";", "}", "}" ]
Generate random number between min and max @return a uint64 object that is randomly generated between min and max
[ "Generate", "random", "number", "between", "min", "and", "max", "@return", "a", "uint64", "object", "that", "is", "randomly", "generated", "between", "min", "and", "max" ]
[ "// [0, RAND_MAX]\r", "// Consider the small interval within remainder of RAND_MAX\r" ]
[ { "param": "min", "type": "uint64_t" }, { "param": "max", "type": "uint64_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "min", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "max", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
16b657d4e983799a4bf5658bc90299a1e2afea17
GZHoffie/Approximate-String-Matching
GASMA/benchmark/benchmark_dataset.h
[ "MIT" ]
C
generate_candidate_text_add_mismatch
void
void generate_candidate_text_add_mismatch( char* const candidate_text, const uint64_t candidate_length) { // Generate random mismatch int position = rand_iid(0,candidate_length); char character = alphabet[rand_iid(0,ALPHABET_SIZE)]; candidate_text[position] = character; }
/* * Generate candidate-text from pattern adding random errors */
Generate candidate-text from pattern adding random errors
[ "Generate", "candidate", "-", "text", "from", "pattern", "adding", "random", "errors" ]
void generate_candidate_text_add_mismatch( char* const candidate_text, const uint64_t candidate_length) { int position = rand_iid(0,candidate_length); char character = alphabet[rand_iid(0,ALPHABET_SIZE)]; candidate_text[position] = character; }
[ "void", "generate_candidate_text_add_mismatch", "(", "char", "*", "const", "candidate_text", ",", "const", "uint64_t", "candidate_length", ")", "{", "int", "position", "=", "rand_iid", "(", "0", ",", "candidate_length", ")", ";", "char", "character", "=", "alphabet", "[", "rand_iid", "(", "0", ",", "ALPHABET_SIZE", ")", "]", ";", "candidate_text", "[", "position", "]", "=", "character", ";", "}" ]
Generate candidate-text from pattern adding random errors
[ "Generate", "candidate", "-", "text", "from", "pattern", "adding", "random", "errors" ]
[ "// Generate random mismatch\r" ]
[ { "param": "candidate_text", "type": "char" }, { "param": "candidate_length", "type": "uint64_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "candidate_text", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "candidate_length", "type": "uint64_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
edd202ad727db72d012deb10cd241fc621c86fd3
GZHoffie/Approximate-String-Matching
GASMA/benchmark/benchmark_utils.h
[ "MIT" ]
C
_run_nw
void
void _run_nw( const char * s1, const int s1Len, const char * s2, const int s2Len) { parasail_result_t* result; parasail_cigar_t* cigar_result; // TODO: check what the band width is affecting times(&start_time); result = parasail_nw_trace(s1, s1Len, s2, s2Len, o, e, penalty_matrix); cigar_result = parasail_result_get_cigar(result, s1, s1Len, s2, s2Len, penalty_matrix); nw_results->CIGAR = parasail_cigar_decode(cigar_result); nw_results->penalty = - result->score; times(&end_time); nw_time.tms_stime += end_time.tms_stime - start_time.tms_stime; nw_time.tms_utime += end_time.tms_utime - start_time.tms_utime; parasail_result_free(result); parasail_cigar_free(cigar_result); }
/** * Run banded Needleman-Wunsch algorithm on two strings s1 and s2. Store the results * in nw_results. * @param s1 the read string. * @param s1Len length of the read string. * @param s2 the reference string. * @param s2Len length of the reference string. */
Run banded Needleman-Wunsch algorithm on two strings s1 and s2. Store the results in nw_results. @param s1 the read string. @param s1Len length of the read string. @param s2 the reference string. @param s2Len length of the reference string.
[ "Run", "banded", "Needleman", "-", "Wunsch", "algorithm", "on", "two", "strings", "s1", "and", "s2", ".", "Store", "the", "results", "in", "nw_results", ".", "@param", "s1", "the", "read", "string", ".", "@param", "s1Len", "length", "of", "the", "read", "string", ".", "@param", "s2", "the", "reference", "string", ".", "@param", "s2Len", "length", "of", "the", "reference", "string", "." ]
void _run_nw( const char * s1, const int s1Len, const char * s2, const int s2Len) { parasail_result_t* result; parasail_cigar_t* cigar_result; times(&start_time); result = parasail_nw_trace(s1, s1Len, s2, s2Len, o, e, penalty_matrix); cigar_result = parasail_result_get_cigar(result, s1, s1Len, s2, s2Len, penalty_matrix); nw_results->CIGAR = parasail_cigar_decode(cigar_result); nw_results->penalty = - result->score; times(&end_time); nw_time.tms_stime += end_time.tms_stime - start_time.tms_stime; nw_time.tms_utime += end_time.tms_utime - start_time.tms_utime; parasail_result_free(result); parasail_cigar_free(cigar_result); }
[ "void", "_run_nw", "(", "const", "char", "*", "s1", ",", "const", "int", "s1Len", ",", "const", "char", "*", "s2", ",", "const", "int", "s2Len", ")", "{", "parasail_result_t", "*", "result", ";", "parasail_cigar_t", "*", "cigar_result", ";", "times", "(", "&", "start_time", ")", ";", "result", "=", "parasail_nw_trace", "(", "s1", ",", "s1Len", ",", "s2", ",", "s2Len", ",", "o", ",", "e", ",", "penalty_matrix", ")", ";", "cigar_result", "=", "parasail_result_get_cigar", "(", "result", ",", "s1", ",", "s1Len", ",", "s2", ",", "s2Len", ",", "penalty_matrix", ")", ";", "nw_results", "->", "CIGAR", "=", "parasail_cigar_decode", "(", "cigar_result", ")", ";", "nw_results", "->", "penalty", "=", "-", "result", "->", "score", ";", "times", "(", "&", "end_time", ")", ";", "nw_time", ".", "tms_stime", "+=", "end_time", ".", "tms_stime", "-", "start_time", ".", "tms_stime", ";", "nw_time", ".", "tms_utime", "+=", "end_time", ".", "tms_utime", "-", "start_time", ".", "tms_utime", ";", "parasail_result_free", "(", "result", ")", ";", "parasail_cigar_free", "(", "cigar_result", ")", ";", "}" ]
Run banded Needleman-Wunsch algorithm on two strings s1 and s2.
[ "Run", "banded", "Needleman", "-", "Wunsch", "algorithm", "on", "two", "strings", "s1", "and", "s2", "." ]
[ "// TODO: check what the band width is affecting\r" ]
[ { "param": "s1", "type": "char" }, { "param": "s1Len", "type": "int" }, { "param": "s2", "type": "char" }, { "param": "s2Len", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "s1", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s1Len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s2", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s2Len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
edd202ad727db72d012deb10cd241fc621c86fd3
GZHoffie/Approximate-String-Matching
GASMA/benchmark/benchmark_utils.h
[ "MIT" ]
C
_run_nw_sse
void
void _run_nw_sse( const char * s1, const int s1Len, const char * s2, const int s2Len) { parasail_result_t* result; parasail_cigar_t* cigar_result; times(&start_time); result = parasail_nw_trace_striped_sse41_128_16(s1, s1Len, s2, s2Len, o, e, penalty_matrix); cigar_result = parasail_result_get_cigar(result, s1, s1Len, s2, s2Len, penalty_matrix); nw_results->CIGAR = parasail_cigar_decode(cigar_result); nw_results->penalty = - result->score; times(&end_time); nw_time.tms_stime += end_time.tms_stime - start_time.tms_stime; nw_time.tms_utime += end_time.tms_utime - start_time.tms_utime; parasail_result_free(result); parasail_cigar_free(cigar_result); }
/** * Run Needleman-Wunsch algorithm with SSE acceleration on two strings s1 and s2. Store the results * in nw_results. */
Run Needleman-Wunsch algorithm with SSE acceleration on two strings s1 and s2. Store the results in nw_results.
[ "Run", "Needleman", "-", "Wunsch", "algorithm", "with", "SSE", "acceleration", "on", "two", "strings", "s1", "and", "s2", ".", "Store", "the", "results", "in", "nw_results", "." ]
void _run_nw_sse( const char * s1, const int s1Len, const char * s2, const int s2Len) { parasail_result_t* result; parasail_cigar_t* cigar_result; times(&start_time); result = parasail_nw_trace_striped_sse41_128_16(s1, s1Len, s2, s2Len, o, e, penalty_matrix); cigar_result = parasail_result_get_cigar(result, s1, s1Len, s2, s2Len, penalty_matrix); nw_results->CIGAR = parasail_cigar_decode(cigar_result); nw_results->penalty = - result->score; times(&end_time); nw_time.tms_stime += end_time.tms_stime - start_time.tms_stime; nw_time.tms_utime += end_time.tms_utime - start_time.tms_utime; parasail_result_free(result); parasail_cigar_free(cigar_result); }
[ "void", "_run_nw_sse", "(", "const", "char", "*", "s1", ",", "const", "int", "s1Len", ",", "const", "char", "*", "s2", ",", "const", "int", "s2Len", ")", "{", "parasail_result_t", "*", "result", ";", "parasail_cigar_t", "*", "cigar_result", ";", "times", "(", "&", "start_time", ")", ";", "result", "=", "parasail_nw_trace_striped_sse41_128_16", "(", "s1", ",", "s1Len", ",", "s2", ",", "s2Len", ",", "o", ",", "e", ",", "penalty_matrix", ")", ";", "cigar_result", "=", "parasail_result_get_cigar", "(", "result", ",", "s1", ",", "s1Len", ",", "s2", ",", "s2Len", ",", "penalty_matrix", ")", ";", "nw_results", "->", "CIGAR", "=", "parasail_cigar_decode", "(", "cigar_result", ")", ";", "nw_results", "->", "penalty", "=", "-", "result", "->", "score", ";", "times", "(", "&", "end_time", ")", ";", "nw_time", ".", "tms_stime", "+=", "end_time", ".", "tms_stime", "-", "start_time", ".", "tms_stime", ";", "nw_time", ".", "tms_utime", "+=", "end_time", ".", "tms_utime", "-", "start_time", ".", "tms_utime", ";", "parasail_result_free", "(", "result", ")", ";", "parasail_cigar_free", "(", "cigar_result", ")", ";", "}" ]
Run Needleman-Wunsch algorithm with SSE acceleration on two strings s1 and s2.
[ "Run", "Needleman", "-", "Wunsch", "algorithm", "with", "SSE", "acceleration", "on", "two", "strings", "s1", "and", "s2", "." ]
[]
[ { "param": "s1", "type": "char" }, { "param": "s1Len", "type": "int" }, { "param": "s2", "type": "char" }, { "param": "s2Len", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "s1", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s1Len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s2", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s2Len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
edd202ad727db72d012deb10cd241fc621c86fd3
GZHoffie/Approximate-String-Matching
GASMA/benchmark/benchmark_utils.h
[ "MIT" ]
C
_run_greedy
void
void _run_greedy( const char * s1, const int s1Len, const char * s2, const int s2Len ) { times(&start_time); matrix->reset(s1, s1Len, s2, s2Len, k); matrix->run(); greedy_results->penalty = matrix->get_cost(); greedy_results->CIGAR = matrix->get_CIGAR(); times(&end_time); greedy_time.tms_stime += end_time.tms_stime - start_time.tms_stime; greedy_time.tms_utime += end_time.tms_utime - start_time.tms_utime; }
/** * Run greedy algorithm on two strings s1 and s2. * Store the results in greedy_results. */
Run greedy algorithm on two strings s1 and s2. Store the results in greedy_results.
[ "Run", "greedy", "algorithm", "on", "two", "strings", "s1", "and", "s2", ".", "Store", "the", "results", "in", "greedy_results", "." ]
void _run_greedy( const char * s1, const int s1Len, const char * s2, const int s2Len ) { times(&start_time); matrix->reset(s1, s1Len, s2, s2Len, k); matrix->run(); greedy_results->penalty = matrix->get_cost(); greedy_results->CIGAR = matrix->get_CIGAR(); times(&end_time); greedy_time.tms_stime += end_time.tms_stime - start_time.tms_stime; greedy_time.tms_utime += end_time.tms_utime - start_time.tms_utime; }
[ "void", "_run_greedy", "(", "const", "char", "*", "s1", ",", "const", "int", "s1Len", ",", "const", "char", "*", "s2", ",", "const", "int", "s2Len", ")", "{", "times", "(", "&", "start_time", ")", ";", "matrix", "->", "reset", "(", "s1", ",", "s1Len", ",", "s2", ",", "s2Len", ",", "k", ")", ";", "matrix", "->", "run", "(", ")", ";", "greedy_results", "->", "penalty", "=", "matrix", "->", "get_cost", "(", ")", ";", "greedy_results", "->", "CIGAR", "=", "matrix", "->", "get_CIGAR", "(", ")", ";", "times", "(", "&", "end_time", ")", ";", "greedy_time", ".", "tms_stime", "+=", "end_time", ".", "tms_stime", "-", "start_time", ".", "tms_stime", ";", "greedy_time", ".", "tms_utime", "+=", "end_time", ".", "tms_utime", "-", "start_time", ".", "tms_utime", ";", "}" ]
Run greedy algorithm on two strings s1 and s2.
[ "Run", "greedy", "algorithm", "on", "two", "strings", "s1", "and", "s2", "." ]
[]
[ { "param": "s1", "type": "char" }, { "param": "s1Len", "type": "int" }, { "param": "s2", "type": "char" }, { "param": "s2Len", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "s1", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s1Len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s2", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s2Len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
edd202ad727db72d012deb10cd241fc621c86fd3
GZHoffie/Approximate-String-Matching
GASMA/benchmark/benchmark_utils.h
[ "MIT" ]
C
print
void
void print() { printf("===================== Benchmark Results =====================\n"); printf("Total number of alignments: %d\n[Time]\n", total_tests); printf("=> Needleman-Wunsch | %.3f s\n", (double) nw_time.tms_utime / sysconf(_SC_CLK_TCK)); printf("=> LEAP | %.3f s\n", (double) LEAP_time.tms_utime / sysconf(_SC_CLK_TCK)); printf("=> Greedy | %.3f s\n", (double) greedy_time.tms_utime / sysconf(_SC_CLK_TCK)); printf("[Accuracy] (percentage of alignments matching optimal penalty)\n"); printf("=> Needleman-Wunsch | %.3f %%\n", (double) nw_correct / total_tests * 100); printf("=> LEAP | %.3f %%\n", (double) LEAP_correct / total_tests * 100); printf("=> Greedy | %.3f %%\n", (double) greedy_correct / total_tests * 100); printf("[Coverage] (percentage of alignments covering all long consecutive matches)\n"); printf("=> Greedy | %.3f %%\n", (double) greedy_coverage / total_tests * 100); }
/** * Print out the benchmark results. Must be run after run(). */
Print out the benchmark results. Must be run after run().
[ "Print", "out", "the", "benchmark", "results", ".", "Must", "be", "run", "after", "run", "()", "." ]
void print() { printf("===================== Benchmark Results =====================\n"); printf("Total number of alignments: %d\n[Time]\n", total_tests); printf("=> Needleman-Wunsch | %.3f s\n", (double) nw_time.tms_utime / sysconf(_SC_CLK_TCK)); printf("=> LEAP | %.3f s\n", (double) LEAP_time.tms_utime / sysconf(_SC_CLK_TCK)); printf("=> Greedy | %.3f s\n", (double) greedy_time.tms_utime / sysconf(_SC_CLK_TCK)); printf("[Accuracy] (percentage of alignments matching optimal penalty)\n"); printf("=> Needleman-Wunsch | %.3f %%\n", (double) nw_correct / total_tests * 100); printf("=> LEAP | %.3f %%\n", (double) LEAP_correct / total_tests * 100); printf("=> Greedy | %.3f %%\n", (double) greedy_correct / total_tests * 100); printf("[Coverage] (percentage of alignments covering all long consecutive matches)\n"); printf("=> Greedy | %.3f %%\n", (double) greedy_coverage / total_tests * 100); }
[ "void", "print", "(", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\\n", "\"", ",", "total_tests", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "nw_time", ".", "tms_utime", "/", "sysconf", "(", "_SC_CLK_TCK", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "LEAP_time", ".", "tms_utime", "/", "sysconf", "(", "_SC_CLK_TCK", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "greedy_time", ".", "tms_utime", "/", "sysconf", "(", "_SC_CLK_TCK", ")", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "nw_correct", "/", "total_tests", "*", "100", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "LEAP_correct", "/", "total_tests", "*", "100", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "greedy_correct", "/", "total_tests", "*", "100", ")", ";", "printf", "(", "\"", "\\n", "\"", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "(", "double", ")", "greedy_coverage", "/", "total_tests", "*", "100", ")", ";", "}" ]
Print out the benchmark results.
[ "Print", "out", "the", "benchmark", "results", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
print_byte_vector
void
void print_byte_vector(uint8_t *data, int length) { for (int i = 0; i < length; i++) { for (int m = 0; m < 8; m++) { if (data[i] & (1ULL << m)) printf("1"); else printf("0"); } } }
/** * Utility function for printing out the data in an array of * uint8_t objects of certain length. * @param data the array of uint8_t needed for printing * @param length the length of this array */
Utility function for printing out the data in an array of uint8_t objects of certain length. @param data the array of uint8_t needed for printing @param length the length of this array
[ "Utility", "function", "for", "printing", "out", "the", "data", "in", "an", "array", "of", "uint8_t", "objects", "of", "certain", "length", ".", "@param", "data", "the", "array", "of", "uint8_t", "needed", "for", "printing", "@param", "length", "the", "length", "of", "this", "array" ]
void print_byte_vector(uint8_t *data, int length) { for (int i = 0; i < length; i++) { for (int m = 0; m < 8; m++) { if (data[i] & (1ULL << m)) printf("1"); else printf("0"); } } }
[ "void", "print_byte_vector", "(", "uint8_t", "*", "data", ",", "int", "length", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "for", "(", "int", "m", "=", "0", ";", "m", "<", "8", ";", "m", "++", ")", "{", "if", "(", "data", "[", "i", "]", "&", "(", "1ULL", "<<", "m", ")", ")", "printf", "(", "\"", "\"", ")", ";", "else", "printf", "(", "\"", "\"", ")", ";", "}", "}", "}" ]
Utility function for printing out the data in an array of uint8_t objects of certain length.
[ "Utility", "function", "for", "printing", "out", "the", "data", "in", "an", "array", "of", "uint8_t", "objects", "of", "certain", "length", "." ]
[]
[ { "param": "data", "type": "uint8_t" }, { "param": "length", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "length", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
first_zero
int
int first_zero() { // TODO: replace this with de Brujin Sequence that is faster than scanning auto data = this->_not(); return data.first_one(); }
/** * Return the index of the lowest unset bit. */
Return the index of the lowest unset bit.
[ "Return", "the", "index", "of", "the", "lowest", "unset", "bit", "." ]
int first_zero() { auto data = this->_not(); return data.first_one(); }
[ "int", "first_zero", "(", ")", "{", "auto", "data", "", "=", "this", "->", "_not", "(", ")", ";", "return", "data", ".", "first_one", "(", ")", ";", "}" ]
Return the index of the lowest unset bit.
[ "Return", "the", "index", "of", "the", "lowest", "unset", "bit", "." ]
[ "// TODO: replace this with de Brujin Sequence that is faster than scanning\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
flip_short_hurdles
int_128bit
int_128bit flip_short_hurdles() { int_128bit l1 = this->shift_left_one(); int_128bit r1 = this->shift_right_one(); int_128bit mask = l1._or(r1); return this->_and(mask); }
/** * Flip the short 1 bit in this->val if both of its neighbors are zeros * * @return this->val with short 1 bits flipped. */
Flip the short 1 bit in this->val if both of its neighbors are zeros @return this->val with short 1 bits flipped.
[ "Flip", "the", "short", "1", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "zeros", "@return", "this", "-", ">", "val", "with", "short", "1", "bits", "flipped", "." ]
int_128bit flip_short_hurdles() { int_128bit l1 = this->shift_left_one(); int_128bit r1 = this->shift_right_one(); int_128bit mask = l1._or(r1); return this->_and(mask); }
[ "int_128bit", "flip_short_hurdles", "(", ")", "{", "int_128bit", "l1", "=", "this", "->", "shift_left_one", "(", ")", ";", "int_128bit", "r1", "=", "this", "->", "shift_right_one", "(", ")", ";", "int_128bit", "mask", "=", "l1", ".", "_or", "(", "r1", ")", ";", "return", "this", "->", "_and", "(", "mask", ")", ";", "}" ]
Flip the short 1 bit in this->val if both of its neighbors are zeros
[ "Flip", "the", "short", "1", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "zeros" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
flip_short_matches
int_128bit
int_128bit flip_short_matches(int threshold) { int_128bit l1 = this->shift_left_one(); int_128bit r1 = this->shift_right_one(); int_128bit l2, r2; if (threshold > 1) { l2 = l1.shift_left_one(); r2 = l2.shift_right_one(); } int_128bit mask_1 = l1._and(r1); if (threshold > 1) { int_128bit mask_2 = l1._and(r2)._or(l2._and(r1)); return this->_or(mask_1)._or(mask_2); } else { return this->_or(mask_1); } }
/** * Flip the short 0 bit in this->val if both of its neighbors are ones * @param threshold the number of short consecutive matches to neglect. Only support 1 and 2. * @return this->val with short 0 bits flipped. */
Flip the short 0 bit in this->val if both of its neighbors are ones @param threshold the number of short consecutive matches to neglect. Only support 1 and 2. @return this->val with short 0 bits flipped.
[ "Flip", "the", "short", "0", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "ones", "@param", "threshold", "the", "number", "of", "short", "consecutive", "matches", "to", "neglect", ".", "Only", "support", "1", "and", "2", ".", "@return", "this", "-", ">", "val", "with", "short", "0", "bits", "flipped", "." ]
int_128bit flip_short_matches(int threshold) { int_128bit l1 = this->shift_left_one(); int_128bit r1 = this->shift_right_one(); int_128bit l2, r2; if (threshold > 1) { l2 = l1.shift_left_one(); r2 = l2.shift_right_one(); } int_128bit mask_1 = l1._and(r1); if (threshold > 1) { int_128bit mask_2 = l1._and(r2)._or(l2._and(r1)); return this->_or(mask_1)._or(mask_2); } else { return this->_or(mask_1); } }
[ "int_128bit", "flip_short_matches", "(", "int", "threshold", ")", "{", "int_128bit", "l1", "=", "this", "->", "shift_left_one", "(", ")", ";", "int_128bit", "r1", "=", "this", "->", "shift_right_one", "(", ")", ";", "int_128bit", "l2", ",", "r2", ";", "if", "(", "threshold", ">", "1", ")", "{", "l2", "=", "l1", ".", "shift_left_one", "(", ")", ";", "r2", "=", "l2", ".", "shift_right_one", "(", ")", ";", "}", "int_128bit", "mask_1", "=", "l1", ".", "_and", "(", "r1", ")", ";", "if", "(", "threshold", ">", "1", ")", "{", "int_128bit", "mask_2", "=", "l1", ".", "_and", "(", "r2", ")", ".", "_or", "(", "l2", ".", "_and", "(", "r1", ")", ")", ";", "return", "this", "->", "_or", "(", "mask_1", ")", ".", "_or", "(", "mask_2", ")", ";", "}", "else", "{", "return", "this", "->", "_or", "(", "mask_1", ")", ";", "}", "}" ]
Flip the short 0 bit in this->val if both of its neighbors are ones @param threshold the number of short consecutive matches to neglect.
[ "Flip", "the", "short", "0", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "ones", "@param", "threshold", "the", "number", "of", "short", "consecutive", "matches", "to", "neglect", "." ]
[]
[ { "param": "threshold", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "threshold", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
pop_count
int
int pop_count() { const __m128i n_hi = _mm_unpackhi_epi64(this->val, this->val); #ifdef _MSC_VER return (int) (__popcnt64(_mm_cvtsi128_si64(n)) + __popcnt64(_mm_cvtsi128_si64(n_hi))); #else return (int) (__popcntq(_mm_cvtsi128_si64(this->val)) + __popcntq(_mm_cvtsi128_si64(n_hi))); #endif }
/** * Count the number of set bits in this->val using hardware POPCNT instruction. * Reference: https://stackoverflow.com/questions/17354971/fast-counting-the-number-of-set-bits-in-m128i-register/17355341. * @return an integer showing the number of set bits in this->val. */
Count the number of set bits in this->val using hardware POPCNT instruction.
[ "Count", "the", "number", "of", "set", "bits", "in", "this", "-", ">", "val", "using", "hardware", "POPCNT", "instruction", "." ]
int pop_count() { const __m128i n_hi = _mm_unpackhi_epi64(this->val, this->val); #ifdef _MSC_VER return (int) (__popcnt64(_mm_cvtsi128_si64(n)) + __popcnt64(_mm_cvtsi128_si64(n_hi))); #else return (int) (__popcntq(_mm_cvtsi128_si64(this->val)) + __popcntq(_mm_cvtsi128_si64(n_hi))); #endif }
[ "int", "pop_count", "(", ")", "{", "const", "__m128i", "n_hi", "=", "_mm_unpackhi_epi64", "(", "this", "->", "val", ",", "this", "->", "val", ")", ";", "#ifdef", "_MSC_VER", "return", "(", "int", ")", "(", "__popcnt64", "(", "_mm_cvtsi128_si64", "(", "n", ")", ")", "+", "__popcnt64", "(", "_mm_cvtsi128_si64", "(", "n_hi", ")", ")", ")", ";", "#else", "return", "(", "int", ")", "(", "__popcntq", "(", "_mm_cvtsi128_si64", "(", "this", "->", "val", ")", ")", "+", "__popcntq", "(", "_mm_cvtsi128_si64", "(", "n_hi", ")", ")", ")", ";", "#endif", "}" ]
Count the number of set bits in this->val using hardware POPCNT instruction.
[ "Count", "the", "number", "of", "set", "bits", "in", "this", "-", ">", "val", "using", "hardware", "POPCNT", "instruction", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
flip_short_hurdles
int_256bit
int_256bit flip_short_hurdles() { int_256bit l1 = this->shift_left_one(); int_256bit r1 = this->shift_right_one(); int_256bit mask = l1._or(r1); return this->_and(mask); }
/** * Flip the short 1 bit in this->val if both of its neighbors are zeros * * @return this->val with short 1 bits flipped. */
Flip the short 1 bit in this->val if both of its neighbors are zeros @return this->val with short 1 bits flipped.
[ "Flip", "the", "short", "1", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "zeros", "@return", "this", "-", ">", "val", "with", "short", "1", "bits", "flipped", "." ]
int_256bit flip_short_hurdles() { int_256bit l1 = this->shift_left_one(); int_256bit r1 = this->shift_right_one(); int_256bit mask = l1._or(r1); return this->_and(mask); }
[ "int_256bit", "flip_short_hurdles", "(", ")", "{", "int_256bit", "l1", "=", "this", "->", "shift_left_one", "(", ")", ";", "int_256bit", "r1", "=", "this", "->", "shift_right_one", "(", ")", ";", "int_256bit", "mask", "=", "l1", ".", "_or", "(", "r1", ")", ";", "return", "this", "->", "_and", "(", "mask", ")", ";", "}" ]
Flip the short 1 bit in this->val if both of its neighbors are zeros
[ "Flip", "the", "short", "1", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "zeros" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
501b513f7c0c26e6ba1ee6cdc6d2b03c9ae6eff4
GZHoffie/Approximate-String-Matching
GASMA/utils.h
[ "MIT" ]
C
flip_short_matches
int_256bit
int_256bit flip_short_matches(int threshold) { int_256bit l1 = this->shift_left_one(); int_256bit r1 = this->shift_right_one(); int_256bit l2, r2; if (threshold > 1) { l2 = l1.shift_left_one(); r2 = l2.shift_right_one(); } int_256bit mask_1 = l1._and(r1); if (threshold > 1) { int_256bit mask_2 = l1._and(r2)._or(l2._and(r1)); return this->_or(mask_1)._or(mask_2); } else { return this->_or(mask_1); } }
/** * Flip the short 0 bit in this->val if both of its neighbors are ones * @param threshold the number of short consecutive matches to neglect. Only support 1 and 2. * @return this->val with short 0 bits flipped. */
Flip the short 0 bit in this->val if both of its neighbors are ones @param threshold the number of short consecutive matches to neglect. Only support 1 and 2. @return this->val with short 0 bits flipped.
[ "Flip", "the", "short", "0", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "ones", "@param", "threshold", "the", "number", "of", "short", "consecutive", "matches", "to", "neglect", ".", "Only", "support", "1", "and", "2", ".", "@return", "this", "-", ">", "val", "with", "short", "0", "bits", "flipped", "." ]
int_256bit flip_short_matches(int threshold) { int_256bit l1 = this->shift_left_one(); int_256bit r1 = this->shift_right_one(); int_256bit l2, r2; if (threshold > 1) { l2 = l1.shift_left_one(); r2 = l2.shift_right_one(); } int_256bit mask_1 = l1._and(r1); if (threshold > 1) { int_256bit mask_2 = l1._and(r2)._or(l2._and(r1)); return this->_or(mask_1)._or(mask_2); } else { return this->_or(mask_1); } }
[ "int_256bit", "flip_short_matches", "(", "int", "threshold", ")", "{", "int_256bit", "l1", "=", "this", "->", "shift_left_one", "(", ")", ";", "int_256bit", "r1", "=", "this", "->", "shift_right_one", "(", ")", ";", "int_256bit", "l2", ",", "r2", ";", "if", "(", "threshold", ">", "1", ")", "{", "l2", "=", "l1", ".", "shift_left_one", "(", ")", ";", "r2", "=", "l2", ".", "shift_right_one", "(", ")", ";", "}", "int_256bit", "mask_1", "=", "l1", ".", "_and", "(", "r1", ")", ";", "if", "(", "threshold", ">", "1", ")", "{", "int_256bit", "mask_2", "=", "l1", ".", "_and", "(", "r2", ")", ".", "_or", "(", "l2", ".", "_and", "(", "r1", ")", ")", ";", "return", "this", "->", "_or", "(", "mask_1", ")", ".", "_or", "(", "mask_2", ")", ";", "}", "else", "{", "return", "this", "->", "_or", "(", "mask_1", ")", ";", "}", "}" ]
Flip the short 0 bit in this->val if both of its neighbors are ones @param threshold the number of short consecutive matches to neglect.
[ "Flip", "the", "short", "0", "bit", "in", "this", "-", ">", "val", "if", "both", "of", "its", "neighbors", "are", "ones", "@param", "threshold", "the", "number", "of", "short", "consecutive", "matches", "to", "neglect", "." ]
[]
[ { "param": "threshold", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "threshold", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0a7a0efdd2f864f69472851939e9d975a3919cac
rcarbone/lb
servers.c
[ "BSD-3-Clause" ]
C
mkserver
server_t
server_t * mkserver (char * full, counter_t todo, unsigned concurrency, unsigned maxretry, time_t reply, u_char keepalive, u_char head, char * proxy, char * authproxy) { server_t * s; char * p; int i; /* Attempt to parse and split 'url' into pieces */ uri_t * uri = splituri (full); if (! uri) { printf ("%s: syntax error while processing [%s]\n", run -> progname, full); return NULL; } s = calloc (sizeof (server_t), 1); s -> full = strdup (full); s -> uri = uri; s -> todo = todo; s -> concurrency = concurrency; s -> maxretry = maxretry; msecstotv (reply, & s -> reply_tv); s -> keepalive = keepalive; s -> head = head; /* Split proxy passed in the format hostname[:port] into their components hostname and port */ if (proxy) { p = strchr (proxy, ':'); if (p) * p = '\0'; s -> proxyname = strdup (proxy); s -> proxyport = p ? atoi (p + 1) : DEFAULT_PROXY_PORT; if (p) * p = ':'; } s -> authproxy = authproxy ? strdup (authproxy) : NULL; /* Allocate the table of concurrent requests for this server */ for (i = 0; i < concurrency; i ++) s -> argv = morereq (s -> argv, mkreq (run -> base, s)); /* Define here the callback to benchmark the HTTP server */ evtimer_assign (& s -> req_evt, run -> base, server_cb, s); s -> min = MAXINT; return s; }
/* Allocate and initialize new HTTP server identified by its hostname/ip address for outgoing benchmark activities */
Allocate and initialize new HTTP server identified by its hostname/ip address for outgoing benchmark activities
[ "Allocate", "and", "initialize", "new", "HTTP", "server", "identified", "by", "its", "hostname", "/", "ip", "address", "for", "outgoing", "benchmark", "activities" ]
server_t * mkserver (char * full, counter_t todo, unsigned concurrency, unsigned maxretry, time_t reply, u_char keepalive, u_char head, char * proxy, char * authproxy) { server_t * s; char * p; int i; uri_t * uri = splituri (full); if (! uri) { printf ("%s: syntax error while processing [%s]\n", run -> progname, full); return NULL; } s = calloc (sizeof (server_t), 1); s -> full = strdup (full); s -> uri = uri; s -> todo = todo; s -> concurrency = concurrency; s -> maxretry = maxretry; msecstotv (reply, & s -> reply_tv); s -> keepalive = keepalive; s -> head = head; if (proxy) { p = strchr (proxy, ':'); if (p) * p = '\0'; s -> proxyname = strdup (proxy); s -> proxyport = p ? atoi (p + 1) : DEFAULT_PROXY_PORT; if (p) * p = ':'; } s -> authproxy = authproxy ? strdup (authproxy) : NULL; for (i = 0; i < concurrency; i ++) s -> argv = morereq (s -> argv, mkreq (run -> base, s)); evtimer_assign (& s -> req_evt, run -> base, server_cb, s); s -> min = MAXINT; return s; }
[ "server_t", "*", "mkserver", "(", "char", "*", "full", ",", "counter_t", "todo", ",", "unsigned", "concurrency", ",", "unsigned", "maxretry", ",", "time_t", "reply", ",", "u_char", "keepalive", ",", "u_char", "head", ",", "char", "*", "proxy", ",", "char", "*", "authproxy", ")", "{", "server_t", "*", "s", ";", "char", "*", "p", ";", "int", "i", ";", "uri_t", "*", "uri", "=", "splituri", "(", "full", ")", ";", "if", "(", "!", "uri", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "run", "->", "progname", ",", "full", ")", ";", "return", "NULL", ";", "}", "s", "=", "calloc", "(", "sizeof", "(", "server_t", ")", ",", "1", ")", ";", "s", "->", "full", "=", "strdup", "(", "full", ")", ";", "s", "->", "uri", "=", "uri", ";", "s", "->", "todo", "=", "todo", ";", "s", "->", "concurrency", "=", "concurrency", ";", "s", "->", "maxretry", "=", "maxretry", ";", "msecstotv", "(", "reply", ",", "&", "s", "->", "reply_tv", ")", ";", "s", "->", "keepalive", "=", "keepalive", ";", "s", "->", "head", "=", "head", ";", "if", "(", "proxy", ")", "{", "p", "=", "strchr", "(", "proxy", ",", "'", "'", ")", ";", "if", "(", "p", ")", "*", "p", "=", "'", "\\0", "'", ";", "s", "->", "proxyname", "=", "strdup", "(", "proxy", ")", ";", "s", "->", "proxyport", "=", "p", "?", "atoi", "(", "p", "+", "1", ")", ":", "DEFAULT_PROXY_PORT", ";", "if", "(", "p", ")", "*", "p", "=", "'", "'", ";", "}", "s", "->", "authproxy", "=", "authproxy", "?", "strdup", "(", "authproxy", ")", ":", "NULL", ";", "for", "(", "i", "=", "0", ";", "i", "<", "concurrency", ";", "i", "++", ")", "s", "->", "argv", "=", "morereq", "(", "s", "->", "argv", ",", "mkreq", "(", "run", "->", "base", ",", "s", ")", ")", ";", "evtimer_assign", "(", "&", "s", "->", "req_evt", ",", "run", "->", "base", ",", "server_cb", ",", "s", ")", ";", "s", "->", "min", "=", "MAXINT", ";", "return", "s", ";", "}" ]
Allocate and initialize new HTTP server identified by its hostname/ip address for outgoing benchmark activities
[ "Allocate", "and", "initialize", "new", "HTTP", "server", "identified", "by", "its", "hostname", "/", "ip", "address", "for", "outgoing", "benchmark", "activities" ]
[ "/* Attempt to parse and split 'url' into pieces */", "/* Split proxy passed in the format hostname[:port] into their components hostname and port */", "/* Allocate the table of concurrent requests for this server */", "/* Define here the callback to benchmark the HTTP server */" ]
[ { "param": "full", "type": "char" }, { "param": "todo", "type": "counter_t" }, { "param": "concurrency", "type": "unsigned" }, { "param": "maxretry", "type": "unsigned" }, { "param": "reply", "type": "time_t" }, { "param": "keepalive", "type": "u_char" }, { "param": "head", "type": "u_char" }, { "param": "proxy", "type": "char" }, { "param": "authproxy", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "full", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "todo", "type": "counter_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "concurrency", "type": "unsigned", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "maxretry", "type": "unsigned", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "reply", "type": "time_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "keepalive", "type": "u_char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "head", "type": "u_char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "proxy", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "authproxy", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0a7a0efdd2f864f69472851939e9d975a3919cac
rcarbone/lb
servers.c
[ "BSD-3-Clause" ]
C
rmserver
void
void rmserver (void * server) { server_t * s = (server_t *) server; if (! s) return; safefree (s -> full); freeuri (s -> uri); safefree (s -> servername); safefree (s -> proxyname); safefree (s -> authproxy); cleanupreq (s -> argv, rmreq); free (s); }
/* Free allocated memory and resources used to keep a HTTP server */
Free allocated memory and resources used to keep a HTTP server
[ "Free", "allocated", "memory", "and", "resources", "used", "to", "keep", "a", "HTTP", "server" ]
void rmserver (void * server) { server_t * s = (server_t *) server; if (! s) return; safefree (s -> full); freeuri (s -> uri); safefree (s -> servername); safefree (s -> proxyname); safefree (s -> authproxy); cleanupreq (s -> argv, rmreq); free (s); }
[ "void", "rmserver", "(", "void", "*", "server", ")", "{", "server_t", "*", "s", "=", "(", "server_t", "*", ")", "server", ";", "if", "(", "!", "s", ")", "return", ";", "safefree", "(", "s", "->", "full", ")", ";", "freeuri", "(", "s", "->", "uri", ")", ";", "safefree", "(", "s", "->", "servername", ")", ";", "safefree", "(", "s", "->", "proxyname", ")", ";", "safefree", "(", "s", "->", "authproxy", ")", ";", "cleanupreq", "(", "s", "->", "argv", ",", "rmreq", ")", ";", "free", "(", "s", ")", ";", "}" ]
Free allocated memory and resources used to keep a HTTP server
[ "Free", "allocated", "memory", "and", "resources", "used", "to", "keep", "a", "HTTP", "server" ]
[]
[ { "param": "server", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "server", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0a7a0efdd2f864f69472851939e9d975a3919cac
rcarbone/lb
servers.c
[ "BSD-3-Clause" ]
C
finished
int
int finished (server_t * argv []) { server_t ** s = argv; while (s && * s) if ((* s) -> done != (* s) -> todo) return 0; else s ++; return 1; }
/* Give an indication if all the requests for all the servers have been completed */
Give an indication if all the requests for all the servers have been completed
[ "Give", "an", "indication", "if", "all", "the", "requests", "for", "all", "the", "servers", "have", "been", "completed" ]
int finished (server_t * argv []) { server_t ** s = argv; while (s && * s) if ((* s) -> done != (* s) -> todo) return 0; else s ++; return 1; }
[ "int", "finished", "(", "server_t", "*", "argv", "[", "]", ")", "{", "server_t", "*", "*", "s", "=", "argv", ";", "while", "(", "s", "&&", "*", "s", ")", "if", "(", "(", "*", "s", ")", "->", "done", "!=", "(", "*", "s", ")", "->", "todo", ")", "return", "0", ";", "else", "s", "++", ";", "return", "1", ";", "}" ]
Give an indication if all the requests for all the servers have been completed
[ "Give", "an", "indication", "if", "all", "the", "requests", "for", "all", "the", "servers", "have", "been", "completed" ]
[]
[ { "param": "argv", "type": "server_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argv", "type": "server_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0a7a0efdd2f864f69472851939e9d975a3919cac
rcarbone/lb
servers.c
[ "BSD-3-Clause" ]
C
lbstats
void
void lbstats (server_t * argv []) { server_t ** s = argv; while (s && * s) lbstat (* s ++); }
/* Print out statistics for all HTTP servers */
Print out statistics for all HTTP servers
[ "Print", "out", "statistics", "for", "all", "HTTP", "servers" ]
void lbstats (server_t * argv []) { server_t ** s = argv; while (s && * s) lbstat (* s ++); }
[ "void", "lbstats", "(", "server_t", "*", "argv", "[", "]", ")", "{", "server_t", "*", "*", "s", "=", "argv", ";", "while", "(", "s", "&&", "*", "s", ")", "lbstat", "(", "*", "s", "++", ")", ";", "}" ]
Print out statistics for all HTTP servers
[ "Print", "out", "statistics", "for", "all", "HTTP", "servers" ]
[]
[ { "param": "argv", "type": "server_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "argv", "type": "server_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0abded139bef134a43c39f7b24e3e960d801b2d9
SizzlingStats/sizzlingplugins
external/polarssl/src/ssl_srv.c
[ "Unlicense", "BSD-3-Clause" ]
C
ssl_save_session
int
static int ssl_save_session( const ssl_session *session, unsigned char *buf, size_t buf_len, size_t *olen ) { unsigned char *p = buf; size_t left = buf_len; #if defined(POLARSSL_X509_CRT_PARSE_C) size_t cert_len; #endif /* POLARSSL_X509_CRT_PARSE_C */ if( left < sizeof( ssl_session ) ) return( -1 ); memcpy( p, session, sizeof( ssl_session ) ); p += sizeof( ssl_session ); left -= sizeof( ssl_session ); #if defined(POLARSSL_X509_CRT_PARSE_C) if( session->peer_cert == NULL ) cert_len = 0; else cert_len = session->peer_cert->raw.len; if( left < 3 + cert_len ) return( -1 ); *p++ = (unsigned char)( cert_len >> 16 & 0xFF ); *p++ = (unsigned char)( cert_len >> 8 & 0xFF ); *p++ = (unsigned char)( cert_len & 0xFF ); if( session->peer_cert != NULL ) memcpy( p, session->peer_cert->raw.p, cert_len ); p += cert_len; #endif /* POLARSSL_X509_CRT_PARSE_C */ *olen = p - buf; return( 0 ); }
/* * Serialize a session in the following format: * 0 . n-1 session structure, n = sizeof(ssl_session) * n . n+2 peer_cert length = m (0 if no certificate) * n+3 . n+2+m peer cert ASN.1 * * Assumes ticket is NULL (always true on server side). */
Serialize a session in the following format: 0 . Assumes ticket is NULL (always true on server side).
[ "Serialize", "a", "session", "in", "the", "following", "format", ":", "0", ".", "Assumes", "ticket", "is", "NULL", "(", "always", "true", "on", "server", "side", ")", "." ]
static int ssl_save_session( const ssl_session *session, unsigned char *buf, size_t buf_len, size_t *olen ) { unsigned char *p = buf; size_t left = buf_len; #if defined(POLARSSL_X509_CRT_PARSE_C) size_t cert_len; #endif if( left < sizeof( ssl_session ) ) return( -1 ); memcpy( p, session, sizeof( ssl_session ) ); p += sizeof( ssl_session ); left -= sizeof( ssl_session ); #if defined(POLARSSL_X509_CRT_PARSE_C) if( session->peer_cert == NULL ) cert_len = 0; else cert_len = session->peer_cert->raw.len; if( left < 3 + cert_len ) return( -1 ); *p++ = (unsigned char)( cert_len >> 16 & 0xFF ); *p++ = (unsigned char)( cert_len >> 8 & 0xFF ); *p++ = (unsigned char)( cert_len & 0xFF ); if( session->peer_cert != NULL ) memcpy( p, session->peer_cert->raw.p, cert_len ); p += cert_len; #endif *olen = p - buf; return( 0 ); }
[ "static", "int", "ssl_save_session", "(", "const", "ssl_session", "*", "session", ",", "unsigned", "char", "*", "buf", ",", "size_t", "buf_len", ",", "size_t", "*", "olen", ")", "{", "unsigned", "char", "*", "p", "=", "buf", ";", "size_t", "left", "=", "buf_len", ";", "#if", "defined", "(", "POLARSSL_X509_CRT_PARSE_C", ")", "\n", "size_t", "cert_len", ";", "#endif", "if", "(", "left", "<", "sizeof", "(", "ssl_session", ")", ")", "return", "(", "-1", ")", ";", "memcpy", "(", "p", ",", "session", ",", "sizeof", "(", "ssl_session", ")", ")", ";", "p", "+=", "sizeof", "(", "ssl_session", ")", ";", "left", "-=", "sizeof", "(", "ssl_session", ")", ";", "#if", "defined", "(", "POLARSSL_X509_CRT_PARSE_C", ")", "\n", "if", "(", "session", "->", "peer_cert", "==", "NULL", ")", "cert_len", "=", "0", ";", "else", "cert_len", "=", "session", "->", "peer_cert", "->", "raw", ".", "len", ";", "if", "(", "left", "<", "3", "+", "cert_len", ")", "return", "(", "-1", ")", ";", "*", "p", "++", "=", "(", "unsigned", "char", ")", "(", "cert_len", ">>", "16", "&", "0xFF", ")", ";", "*", "p", "++", "=", "(", "unsigned", "char", ")", "(", "cert_len", ">>", "8", "&", "0xFF", ")", ";", "*", "p", "++", "=", "(", "unsigned", "char", ")", "(", "cert_len", "&", "0xFF", ")", ";", "if", "(", "session", "->", "peer_cert", "!=", "NULL", ")", "memcpy", "(", "p", ",", "session", "->", "peer_cert", "->", "raw", ".", "p", ",", "cert_len", ")", ";", "p", "+=", "cert_len", ";", "#endif", "*", "olen", "=", "p", "-", "buf", ";", "return", "(", "0", ")", ";", "}" ]
Serialize a session in the following format: 0 .
[ "Serialize", "a", "session", "in", "the", "following", "format", ":", "0", "." ]
[ "/* POLARSSL_X509_CRT_PARSE_C */", "/* POLARSSL_X509_CRT_PARSE_C */" ]
[ { "param": "session", "type": "ssl_session" }, { "param": "buf", "type": "unsigned char" }, { "param": "buf_len", "type": "size_t" }, { "param": "olen", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "session", "type": "ssl_session", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf_len", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "olen", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0abded139bef134a43c39f7b24e3e960d801b2d9
SizzlingStats/sizzlingplugins
external/polarssl/src/ssl_srv.c
[ "Unlicense", "BSD-3-Clause" ]
C
ssl_ciphersuite_match
int
static int ssl_ciphersuite_match( ssl_context *ssl, int suite_id, const ssl_ciphersuite_t **ciphersuite_info ) { const ssl_ciphersuite_t *suite_info; suite_info = ssl_ciphersuite_from_id( suite_id ); if( suite_info == NULL ) { SSL_DEBUG_MSG( 1, ( "ciphersuite info for %04x not found", suite_id ) ); return( POLARSSL_ERR_SSL_BAD_INPUT_DATA ); } if( suite_info->min_minor_ver > ssl->minor_ver || suite_info->max_minor_ver < ssl->minor_ver ) return( 0 ); #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C) if( ssl_ciphersuite_uses_ec( suite_info ) && ( ssl->handshake->curves == NULL || ssl->handshake->curves[0] == NULL ) ) return( 0 ); #endif #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED) /* If the ciphersuite requires a pre-shared key and we don't * have one, skip it now rather than failing later */ if( ssl_ciphersuite_uses_psk( suite_info ) && ssl->f_psk == NULL && ( ssl->psk == NULL || ssl->psk_identity == NULL || ssl->psk_identity_len == 0 || ssl->psk_len == 0 ) ) return( 0 ); #endif #if defined(POLARSSL_X509_CRT_PARSE_C) /* * Final check: if ciphersuite requires us to have a * certificate/key of a particular type: * - select the appropriate certificate if we have one, or * - try the next ciphersuite if we don't * This must be done last since we modify the key_cert list. */ if( ssl_pick_cert( ssl, suite_info ) != 0 ) return( 0 ); #endif *ciphersuite_info = suite_info; return( 0 ); }
/* * Check if a given ciphersuite is suitable for use with our config/keys/etc * Sets ciphersuite_info only if the suite matches. */
Check if a given ciphersuite is suitable for use with our config/keys/etc Sets ciphersuite_info only if the suite matches.
[ "Check", "if", "a", "given", "ciphersuite", "is", "suitable", "for", "use", "with", "our", "config", "/", "keys", "/", "etc", "Sets", "ciphersuite_info", "only", "if", "the", "suite", "matches", "." ]
static int ssl_ciphersuite_match( ssl_context *ssl, int suite_id, const ssl_ciphersuite_t **ciphersuite_info ) { const ssl_ciphersuite_t *suite_info; suite_info = ssl_ciphersuite_from_id( suite_id ); if( suite_info == NULL ) { SSL_DEBUG_MSG( 1, ( "ciphersuite info for %04x not found", suite_id ) ); return( POLARSSL_ERR_SSL_BAD_INPUT_DATA ); } if( suite_info->min_minor_ver > ssl->minor_ver || suite_info->max_minor_ver < ssl->minor_ver ) return( 0 ); #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C) if( ssl_ciphersuite_uses_ec( suite_info ) && ( ssl->handshake->curves == NULL || ssl->handshake->curves[0] == NULL ) ) return( 0 ); #endif #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED) if( ssl_ciphersuite_uses_psk( suite_info ) && ssl->f_psk == NULL && ( ssl->psk == NULL || ssl->psk_identity == NULL || ssl->psk_identity_len == 0 || ssl->psk_len == 0 ) ) return( 0 ); #endif #if defined(POLARSSL_X509_CRT_PARSE_C) if( ssl_pick_cert( ssl, suite_info ) != 0 ) return( 0 ); #endif *ciphersuite_info = suite_info; return( 0 ); }
[ "static", "int", "ssl_ciphersuite_match", "(", "ssl_context", "*", "ssl", ",", "int", "suite_id", ",", "const", "ssl_ciphersuite_t", "*", "*", "ciphersuite_info", ")", "{", "const", "ssl_ciphersuite_t", "*", "suite_info", ";", "suite_info", "=", "ssl_ciphersuite_from_id", "(", "suite_id", ")", ";", "if", "(", "suite_info", "==", "NULL", ")", "{", "SSL_DEBUG_MSG", "(", "1", ",", "(", "\"", "\"", ",", "suite_id", ")", ")", ";", "return", "(", "POLARSSL_ERR_SSL_BAD_INPUT_DATA", ")", ";", "}", "if", "(", "suite_info", "->", "min_minor_ver", ">", "ssl", "->", "minor_ver", "||", "suite_info", "->", "max_minor_ver", "<", "ssl", "->", "minor_ver", ")", "return", "(", "0", ")", ";", "#if", "defined", "(", "POLARSSL_ECDH_C", ")", "||", "defined", "(", "POLARSSL_ECDSA_C", ")", "\n", "if", "(", "ssl_ciphersuite_uses_ec", "(", "suite_info", ")", "&&", "(", "ssl", "->", "handshake", "->", "curves", "==", "NULL", "||", "ssl", "->", "handshake", "->", "curves", "[", "0", "]", "==", "NULL", ")", ")", "return", "(", "0", ")", ";", "#endif", "#if", "defined", "(", "POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED", ")", "\n", "if", "(", "ssl_ciphersuite_uses_psk", "(", "suite_info", ")", "&&", "ssl", "->", "f_psk", "==", "NULL", "&&", "(", "ssl", "->", "psk", "==", "NULL", "||", "ssl", "->", "psk_identity", "==", "NULL", "||", "ssl", "->", "psk_identity_len", "==", "0", "||", "ssl", "->", "psk_len", "==", "0", ")", ")", "return", "(", "0", ")", ";", "#endif", "#if", "defined", "(", "POLARSSL_X509_CRT_PARSE_C", ")", "\n", "if", "(", "ssl_pick_cert", "(", "ssl", ",", "suite_info", ")", "!=", "0", ")", "return", "(", "0", ")", ";", "#endif", "*", "ciphersuite_info", "=", "suite_info", ";", "return", "(", "0", ")", ";", "}" ]
Check if a given ciphersuite is suitable for use with our config/keys/etc Sets ciphersuite_info only if the suite matches.
[ "Check", "if", "a", "given", "ciphersuite", "is", "suitable", "for", "use", "with", "our", "config", "/", "keys", "/", "etc", "Sets", "ciphersuite_info", "only", "if", "the", "suite", "matches", "." ]
[ "/* If the ciphersuite requires a pre-shared key and we don't\n * have one, skip it now rather than failing later */", "/*\n * Final check: if ciphersuite requires us to have a\n * certificate/key of a particular type:\n * - select the appropriate certificate if we have one, or\n * - try the next ciphersuite if we don't\n * This must be done last since we modify the key_cert list.\n */" ]
[ { "param": "ssl", "type": "ssl_context" }, { "param": "suite_id", "type": "int" }, { "param": "ciphersuite_info", "type": "ssl_ciphersuite_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ssl", "type": "ssl_context", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "suite_id", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ciphersuite_info", "type": "ssl_ciphersuite_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2072d5559369eeea463c1853c48a33ad03a5afb5
SizzlingStats/sizzlingplugins
external/polarssl/src/ecdsa.c
[ "Unlicense", "BSD-3-Clause" ]
C
derive_mpi
int
static int derive_mpi( const ecp_group *grp, mpi *x, const unsigned char *buf, size_t blen ) { size_t n_size = (grp->nbits + 7) / 8; return( mpi_read_binary( x, buf, blen > n_size ? n_size : blen ) ); }
/* * Derive a suitable integer for group grp from a buffer of length len * SEC1 4.1.3 step 5 aka SEC1 4.1.4 step 3 */
Derive a suitable integer for group grp from a buffer of length len SEC1 4.1.3 step 5 aka SEC1 4.1.4 step 3
[ "Derive", "a", "suitable", "integer", "for", "group", "grp", "from", "a", "buffer", "of", "length", "len", "SEC1", "4", ".", "1", ".", "3", "step", "5", "aka", "SEC1", "4", ".", "1", ".", "4", "step", "3" ]
static int derive_mpi( const ecp_group *grp, mpi *x, const unsigned char *buf, size_t blen ) { size_t n_size = (grp->nbits + 7) / 8; return( mpi_read_binary( x, buf, blen > n_size ? n_size : blen ) ); }
[ "static", "int", "derive_mpi", "(", "const", "ecp_group", "*", "grp", ",", "mpi", "*", "x", ",", "const", "unsigned", "char", "*", "buf", ",", "size_t", "blen", ")", "{", "size_t", "n_size", "=", "(", "grp", "->", "nbits", "+", "7", ")", "/", "8", ";", "return", "(", "mpi_read_binary", "(", "x", ",", "buf", ",", "blen", ">", "n_size", "?", "n_size", ":", "blen", ")", ")", ";", "}" ]
Derive a suitable integer for group grp from a buffer of length len SEC1 4.1.3 step 5 aka SEC1 4.1.4 step 3
[ "Derive", "a", "suitable", "integer", "for", "group", "grp", "from", "a", "buffer", "of", "length", "len", "SEC1", "4", ".", "1", ".", "3", "step", "5", "aka", "SEC1", "4", ".", "1", ".", "4", "step", "3" ]
[]
[ { "param": "grp", "type": "ecp_group" }, { "param": "x", "type": "mpi" }, { "param": "buf", "type": "unsigned char" }, { "param": "blen", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "grp", "type": "ecp_group", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "x", "type": "mpi", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "blen", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0c5d2d9243bf127a55f700f1e8a04b6559940f75
SizzlingStats/sizzlingplugins
common/ThreadFunctorQueue.h
[ "Unlicense", "BSD-3-Clause" ]
C
JoinQueue
void
void JoinQueue() { if (!m_bJoining) { m_bJoining = true; //Msg( "=== joining\n" ); // let the queue run past the // lock so it can exit m_waitingForItems.Set(); Join(); } }
// there might be a deadlock // somewhere around when this // is called... need to test
there might be a deadlock somewhere around when this is called... need to test
[ "there", "might", "be", "a", "deadlock", "somewhere", "around", "when", "this", "is", "called", "...", "need", "to", "test" ]
void JoinQueue() { if (!m_bJoining) { m_bJoining = true; m_waitingForItems.Set(); Join(); } }
[ "void", "JoinQueue", "(", ")", "{", "if", "(", "!", "m_bJoining", ")", "{", "m_bJoining", "=", "true", ";", "m_waitingForItems", ".", "Set", "(", ")", ";", "Join", "(", ")", ";", "}", "}" ]
there might be a deadlock somewhere around when this is called... need to test
[ "there", "might", "be", "a", "deadlock", "somewhere", "around", "when", "this", "is", "called", "...", "need", "to", "test" ]
[ "//Msg( \"=== joining\\n\" );\r", "// let the queue run past the \r", "// lock so it can exit\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
8632f7140a1b44443303160b73185c5f8b45b3c6
SizzlingStats/sizzlingplugins
external/polarssl/src/x509_crt.c
[ "Unlicense", "BSD-3-Clause" ]
C
x509_crt_parse_der
int
int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf, size_t buflen ) { int ret; x509_crt *crt = chain, *prev = NULL; /* * Check for valid input */ if( crt == NULL || buf == NULL ) return( POLARSSL_ERR_X509_BAD_INPUT_DATA ); while( crt->version != 0 && crt->next != NULL ) { prev = crt; crt = crt->next; } /* * Add new certificate on the end of the chain if needed. */ if ( crt->version != 0 && crt->next == NULL) { crt->next = (x509_crt *) polarssl_malloc( sizeof( x509_crt ) ); if( crt->next == NULL ) return( POLARSSL_ERR_X509_MALLOC_FAILED ); prev = crt; crt = crt->next; x509_crt_init( crt ); } if( ( ret = x509_crt_parse_der_core( crt, buf, buflen ) ) != 0 ) { if( prev ) prev->next = NULL; if( crt != chain ) polarssl_free( crt ); return( ret ); } return( 0 ); }
/* * Parse one X.509 certificate in DER format from a buffer and add them to a * chained list */
Parse one X.509 certificate in DER format from a buffer and add them to a chained list
[ "Parse", "one", "X", ".", "509", "certificate", "in", "DER", "format", "from", "a", "buffer", "and", "add", "them", "to", "a", "chained", "list" ]
int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf, size_t buflen ) { int ret; x509_crt *crt = chain, *prev = NULL; if( crt == NULL || buf == NULL ) return( POLARSSL_ERR_X509_BAD_INPUT_DATA ); while( crt->version != 0 && crt->next != NULL ) { prev = crt; crt = crt->next; } if ( crt->version != 0 && crt->next == NULL) { crt->next = (x509_crt *) polarssl_malloc( sizeof( x509_crt ) ); if( crt->next == NULL ) return( POLARSSL_ERR_X509_MALLOC_FAILED ); prev = crt; crt = crt->next; x509_crt_init( crt ); } if( ( ret = x509_crt_parse_der_core( crt, buf, buflen ) ) != 0 ) { if( prev ) prev->next = NULL; if( crt != chain ) polarssl_free( crt ); return( ret ); } return( 0 ); }
[ "int", "x509_crt_parse_der", "(", "x509_crt", "*", "chain", ",", "const", "unsigned", "char", "*", "buf", ",", "size_t", "buflen", ")", "{", "int", "ret", ";", "x509_crt", "*", "crt", "=", "chain", ",", "*", "prev", "=", "NULL", ";", "if", "(", "crt", "==", "NULL", "||", "buf", "==", "NULL", ")", "return", "(", "POLARSSL_ERR_X509_BAD_INPUT_DATA", ")", ";", "while", "(", "crt", "->", "version", "!=", "0", "&&", "crt", "->", "next", "!=", "NULL", ")", "{", "prev", "=", "crt", ";", "crt", "=", "crt", "->", "next", ";", "}", "if", "(", "crt", "->", "version", "!=", "0", "&&", "crt", "->", "next", "==", "NULL", ")", "{", "crt", "->", "next", "=", "(", "x509_crt", "*", ")", "polarssl_malloc", "(", "sizeof", "(", "x509_crt", ")", ")", ";", "if", "(", "crt", "->", "next", "==", "NULL", ")", "return", "(", "POLARSSL_ERR_X509_MALLOC_FAILED", ")", ";", "prev", "=", "crt", ";", "crt", "=", "crt", "->", "next", ";", "x509_crt_init", "(", "crt", ")", ";", "}", "if", "(", "(", "ret", "=", "x509_crt_parse_der_core", "(", "crt", ",", "buf", ",", "buflen", ")", ")", "!=", "0", ")", "{", "if", "(", "prev", ")", "prev", "->", "next", "=", "NULL", ";", "if", "(", "crt", "!=", "chain", ")", "polarssl_free", "(", "crt", ")", ";", "return", "(", "ret", ")", ";", "}", "return", "(", "0", ")", ";", "}" ]
Parse one X.509 certificate in DER format from a buffer and add them to a chained list
[ "Parse", "one", "X", ".", "509", "certificate", "in", "DER", "format", "from", "a", "buffer", "and", "add", "them", "to", "a", "chained", "list" ]
[ "/*\n * Check for valid input\n */", "/*\n * Add new certificate on the end of the chain if needed.\n */" ]
[ { "param": "chain", "type": "x509_crt" }, { "param": "buf", "type": "unsigned char" }, { "param": "buflen", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "chain", "type": "x509_crt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buflen", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8632f7140a1b44443303160b73185c5f8b45b3c6
SizzlingStats/sizzlingplugins
external/polarssl/src/x509_crt.c
[ "Unlicense", "BSD-3-Clause" ]
C
x509_crt_parse
int
int x509_crt_parse( x509_crt *chain, const unsigned char *buf, size_t buflen ) { int success = 0, first_error = 0, total_failed = 0; int buf_format = X509_FORMAT_DER; /* * Check for valid input */ if( chain == NULL || buf == NULL ) return( POLARSSL_ERR_X509_BAD_INPUT_DATA ); /* * Determine buffer content. Buffer contains either one DER certificate or * one or more PEM certificates. */ #if defined(POLARSSL_PEM_PARSE_C) if( strstr( (const char *) buf, "-----BEGIN CERTIFICATE-----" ) != NULL ) buf_format = X509_FORMAT_PEM; #endif if( buf_format == X509_FORMAT_DER ) return x509_crt_parse_der( chain, buf, buflen ); #if defined(POLARSSL_PEM_PARSE_C) if( buf_format == X509_FORMAT_PEM ) { int ret; pem_context pem; while( buflen > 0 ) { size_t use_len; pem_init( &pem ); ret = pem_read_buffer( &pem, "-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----", buf, NULL, 0, &use_len ); if( ret == 0 ) { /* * Was PEM encoded */ buflen -= use_len; buf += use_len; } else if( ret == POLARSSL_ERR_PEM_BAD_INPUT_DATA ) { return( ret ); } else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) { pem_free( &pem ); /* * PEM header and footer were found */ buflen -= use_len; buf += use_len; if( first_error == 0 ) first_error = ret; continue; } else break; ret = x509_crt_parse_der( chain, pem.buf, pem.buflen ); pem_free( &pem ); if( ret != 0 ) { /* * Quit parsing on a memory error */ if( ret == POLARSSL_ERR_X509_MALLOC_FAILED ) return( ret ); if( first_error == 0 ) first_error = ret; total_failed++; continue; } success = 1; } } #endif if( success ) return( total_failed ); else if( first_error ) return( first_error ); else return( POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT ); }
/* * Parse one or more PEM certificates from a buffer and add them to the chained list */
Parse one or more PEM certificates from a buffer and add them to the chained list
[ "Parse", "one", "or", "more", "PEM", "certificates", "from", "a", "buffer", "and", "add", "them", "to", "the", "chained", "list" ]
int x509_crt_parse( x509_crt *chain, const unsigned char *buf, size_t buflen ) { int success = 0, first_error = 0, total_failed = 0; int buf_format = X509_FORMAT_DER; if( chain == NULL || buf == NULL ) return( POLARSSL_ERR_X509_BAD_INPUT_DATA ); #if defined(POLARSSL_PEM_PARSE_C) if( strstr( (const char *) buf, "-----BEGIN CERTIFICATE-----" ) != NULL ) buf_format = X509_FORMAT_PEM; #endif if( buf_format == X509_FORMAT_DER ) return x509_crt_parse_der( chain, buf, buflen ); #if defined(POLARSSL_PEM_PARSE_C) if( buf_format == X509_FORMAT_PEM ) { int ret; pem_context pem; while( buflen > 0 ) { size_t use_len; pem_init( &pem ); ret = pem_read_buffer( &pem, "-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----", buf, NULL, 0, &use_len ); if( ret == 0 ) { buflen -= use_len; buf += use_len; } else if( ret == POLARSSL_ERR_PEM_BAD_INPUT_DATA ) { return( ret ); } else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) { pem_free( &pem ); buflen -= use_len; buf += use_len; if( first_error == 0 ) first_error = ret; continue; } else break; ret = x509_crt_parse_der( chain, pem.buf, pem.buflen ); pem_free( &pem ); if( ret != 0 ) { if( ret == POLARSSL_ERR_X509_MALLOC_FAILED ) return( ret ); if( first_error == 0 ) first_error = ret; total_failed++; continue; } success = 1; } } #endif if( success ) return( total_failed ); else if( first_error ) return( first_error ); else return( POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT ); }
[ "int", "x509_crt_parse", "(", "x509_crt", "*", "chain", ",", "const", "unsigned", "char", "*", "buf", ",", "size_t", "buflen", ")", "{", "int", "success", "=", "0", ",", "first_error", "=", "0", ",", "total_failed", "=", "0", ";", "int", "buf_format", "=", "X509_FORMAT_DER", ";", "if", "(", "chain", "==", "NULL", "||", "buf", "==", "NULL", ")", "return", "(", "POLARSSL_ERR_X509_BAD_INPUT_DATA", ")", ";", "#if", "defined", "(", "POLARSSL_PEM_PARSE_C", ")", "\n", "if", "(", "strstr", "(", "(", "const", "char", "*", ")", "buf", ",", "\"", "\"", ")", "!=", "NULL", ")", "buf_format", "=", "X509_FORMAT_PEM", ";", "#endif", "if", "(", "buf_format", "==", "X509_FORMAT_DER", ")", "return", "x509_crt_parse_der", "(", "chain", ",", "buf", ",", "buflen", ")", ";", "#if", "defined", "(", "POLARSSL_PEM_PARSE_C", ")", "\n", "if", "(", "buf_format", "==", "X509_FORMAT_PEM", ")", "{", "int", "ret", ";", "pem_context", "pem", ";", "while", "(", "buflen", ">", "0", ")", "{", "size_t", "use_len", ";", "pem_init", "(", "&", "pem", ")", ";", "ret", "=", "pem_read_buffer", "(", "&", "pem", ",", "\"", "\"", ",", "\"", "\"", ",", "buf", ",", "NULL", ",", "0", ",", "&", "use_len", ")", ";", "if", "(", "ret", "==", "0", ")", "{", "buflen", "-=", "use_len", ";", "buf", "+=", "use_len", ";", "}", "else", "if", "(", "ret", "==", "POLARSSL_ERR_PEM_BAD_INPUT_DATA", ")", "{", "return", "(", "ret", ")", ";", "}", "else", "if", "(", "ret", "!=", "POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT", ")", "{", "pem_free", "(", "&", "pem", ")", ";", "buflen", "-=", "use_len", ";", "buf", "+=", "use_len", ";", "if", "(", "first_error", "==", "0", ")", "first_error", "=", "ret", ";", "continue", ";", "}", "else", "break", ";", "ret", "=", "x509_crt_parse_der", "(", "chain", ",", "pem", ".", "buf", ",", "pem", ".", "buflen", ")", ";", "pem_free", "(", "&", "pem", ")", ";", "if", "(", "ret", "!=", "0", ")", "{", "if", "(", "ret", "==", "POLARSSL_ERR_X509_MALLOC_FAILED", ")", "return", "(", "ret", ")", ";", "if", "(", "first_error", "==", "0", ")", "first_error", "=", "ret", ";", "total_failed", "++", ";", "continue", ";", "}", "success", "=", "1", ";", "}", "}", "#endif", "if", "(", "success", ")", "return", "(", "total_failed", ")", ";", "else", "if", "(", "first_error", ")", "return", "(", "first_error", ")", ";", "else", "return", "(", "POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT", ")", ";", "}" ]
Parse one or more PEM certificates from a buffer and add them to the chained list
[ "Parse", "one", "or", "more", "PEM", "certificates", "from", "a", "buffer", "and", "add", "them", "to", "the", "chained", "list" ]
[ "/*\n * Check for valid input\n */", "/*\n * Determine buffer content. Buffer contains either one DER certificate or\n * one or more PEM certificates.\n */", "/*\n * Was PEM encoded\n */", "/*\n * PEM header and footer were found\n */", "/*\n * Quit parsing on a memory error\n */" ]
[ { "param": "chain", "type": "x509_crt" }, { "param": "buf", "type": "unsigned char" }, { "param": "buflen", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "chain", "type": "x509_crt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buflen", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8632f7140a1b44443303160b73185c5f8b45b3c6
SizzlingStats/sizzlingplugins
external/polarssl/src/x509_crt.c
[ "Unlicense", "BSD-3-Clause" ]
C
x509_crt_parse_file
int
int x509_crt_parse_file( x509_crt *chain, const char *path ) { int ret; size_t n; unsigned char *buf; if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) return( ret ); ret = x509_crt_parse( chain, buf, n ); memset( buf, 0, n + 1 ); polarssl_free( buf ); return( ret ); }
/* * Load one or more certificates and add them to the chained list */
Load one or more certificates and add them to the chained list
[ "Load", "one", "or", "more", "certificates", "and", "add", "them", "to", "the", "chained", "list" ]
int x509_crt_parse_file( x509_crt *chain, const char *path ) { int ret; size_t n; unsigned char *buf; if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) return( ret ); ret = x509_crt_parse( chain, buf, n ); memset( buf, 0, n + 1 ); polarssl_free( buf ); return( ret ); }
[ "int", "x509_crt_parse_file", "(", "x509_crt", "*", "chain", ",", "const", "char", "*", "path", ")", "{", "int", "ret", ";", "size_t", "n", ";", "unsigned", "char", "*", "buf", ";", "if", "(", "(", "ret", "=", "x509_load_file", "(", "path", ",", "&", "buf", ",", "&", "n", ")", ")", "!=", "0", ")", "return", "(", "ret", ")", ";", "ret", "=", "x509_crt_parse", "(", "chain", ",", "buf", ",", "n", ")", ";", "memset", "(", "buf", ",", "0", ",", "n", "+", "1", ")", ";", "polarssl_free", "(", "buf", ")", ";", "return", "(", "ret", ")", ";", "}" ]
Load one or more certificates and add them to the chained list
[ "Load", "one", "or", "more", "certificates", "and", "add", "them", "to", "the", "chained", "list" ]
[]
[ { "param": "chain", "type": "x509_crt" }, { "param": "path", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "chain", "type": "x509_crt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8632f7140a1b44443303160b73185c5f8b45b3c6
SizzlingStats/sizzlingplugins
external/polarssl/src/x509_crt.c
[ "Unlicense", "BSD-3-Clause" ]
C
x509_crt_revoked
int
int x509_crt_revoked( const x509_crt *crt, const x509_crl *crl ) { const x509_crl_entry *cur = &crl->entry; while( cur != NULL && cur->serial.len != 0 ) { if( crt->serial.len == cur->serial.len && memcmp( crt->serial.p, cur->serial.p, crt->serial.len ) == 0 ) { if( x509_time_expired( &cur->revocation_date ) ) return( 1 ); } cur = cur->next; } return( 0 ); }
/* * Return 1 if the certificate is revoked, or 0 otherwise. */
Return 1 if the certificate is revoked, or 0 otherwise.
[ "Return", "1", "if", "the", "certificate", "is", "revoked", "or", "0", "otherwise", "." ]
int x509_crt_revoked( const x509_crt *crt, const x509_crl *crl ) { const x509_crl_entry *cur = &crl->entry; while( cur != NULL && cur->serial.len != 0 ) { if( crt->serial.len == cur->serial.len && memcmp( crt->serial.p, cur->serial.p, crt->serial.len ) == 0 ) { if( x509_time_expired( &cur->revocation_date ) ) return( 1 ); } cur = cur->next; } return( 0 ); }
[ "int", "x509_crt_revoked", "(", "const", "x509_crt", "*", "crt", ",", "const", "x509_crl", "*", "crl", ")", "{", "const", "x509_crl_entry", "*", "cur", "=", "&", "crl", "->", "entry", ";", "while", "(", "cur", "!=", "NULL", "&&", "cur", "->", "serial", ".", "len", "!=", "0", ")", "{", "if", "(", "crt", "->", "serial", ".", "len", "==", "cur", "->", "serial", ".", "len", "&&", "memcmp", "(", "crt", "->", "serial", ".", "p", ",", "cur", "->", "serial", ".", "p", ",", "crt", "->", "serial", ".", "len", ")", "==", "0", ")", "{", "if", "(", "x509_time_expired", "(", "&", "cur", "->", "revocation_date", ")", ")", "return", "(", "1", ")", ";", "}", "cur", "=", "cur", "->", "next", ";", "}", "return", "(", "0", ")", ";", "}" ]
Return 1 if the certificate is revoked, or 0 otherwise.
[ "Return", "1", "if", "the", "certificate", "is", "revoked", "or", "0", "otherwise", "." ]
[]
[ { "param": "crt", "type": "x509_crt" }, { "param": "crl", "type": "x509_crl" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "crt", "type": "x509_crt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "crl", "type": "x509_crl", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8632f7140a1b44443303160b73185c5f8b45b3c6
SizzlingStats/sizzlingplugins
external/polarssl/src/x509_crt.c
[ "Unlicense", "BSD-3-Clause" ]
C
x509_crt_verifycrl
int
static int x509_crt_verifycrl( x509_crt *crt, x509_crt *ca, x509_crl *crl_list) { int flags = 0; unsigned char hash[POLARSSL_MD_MAX_SIZE]; const md_info_t *md_info; if( ca == NULL ) return( flags ); /* * TODO: What happens if no CRL is present? * Suggestion: Revocation state should be unknown if no CRL is present. * For backwards compatibility this is not yet implemented. */ while( crl_list != NULL ) { if( crl_list->version == 0 || crl_list->issuer_raw.len != ca->subject_raw.len || memcmp( crl_list->issuer_raw.p, ca->subject_raw.p, crl_list->issuer_raw.len ) != 0 ) { crl_list = crl_list->next; continue; } /* * Check if CRL is correctly signed by the trusted CA */ md_info = md_info_from_type( crl_list->sig_md ); if( md_info == NULL ) { /* * Cannot check 'unknown' hash */ flags |= BADCRL_NOT_TRUSTED; break; } md( md_info, crl_list->tbs.p, crl_list->tbs.len, hash ); if( pk_can_do( &ca->pk, crl_list->sig_pk ) == 0 || pk_verify( &ca->pk, crl_list->sig_md, hash, md_info->size, crl_list->sig.p, crl_list->sig.len ) != 0 ) { flags |= BADCRL_NOT_TRUSTED; break; } /* * Check for validity of CRL (Do not drop out) */ if( x509_time_expired( &crl_list->next_update ) ) flags |= BADCRL_EXPIRED; /* * Check if certificate is revoked */ if( x509_crt_revoked(crt, crl_list) ) { flags |= BADCERT_REVOKED; break; } crl_list = crl_list->next; } return flags; }
/* * Check that the given certificate is valid according to the CRL. */
Check that the given certificate is valid according to the CRL.
[ "Check", "that", "the", "given", "certificate", "is", "valid", "according", "to", "the", "CRL", "." ]
static int x509_crt_verifycrl( x509_crt *crt, x509_crt *ca, x509_crl *crl_list) { int flags = 0; unsigned char hash[POLARSSL_MD_MAX_SIZE]; const md_info_t *md_info; if( ca == NULL ) return( flags ); while( crl_list != NULL ) { if( crl_list->version == 0 || crl_list->issuer_raw.len != ca->subject_raw.len || memcmp( crl_list->issuer_raw.p, ca->subject_raw.p, crl_list->issuer_raw.len ) != 0 ) { crl_list = crl_list->next; continue; } md_info = md_info_from_type( crl_list->sig_md ); if( md_info == NULL ) { flags |= BADCRL_NOT_TRUSTED; break; } md( md_info, crl_list->tbs.p, crl_list->tbs.len, hash ); if( pk_can_do( &ca->pk, crl_list->sig_pk ) == 0 || pk_verify( &ca->pk, crl_list->sig_md, hash, md_info->size, crl_list->sig.p, crl_list->sig.len ) != 0 ) { flags |= BADCRL_NOT_TRUSTED; break; } if( x509_time_expired( &crl_list->next_update ) ) flags |= BADCRL_EXPIRED; if( x509_crt_revoked(crt, crl_list) ) { flags |= BADCERT_REVOKED; break; } crl_list = crl_list->next; } return flags; }
[ "static", "int", "x509_crt_verifycrl", "(", "x509_crt", "*", "crt", ",", "x509_crt", "*", "ca", ",", "x509_crl", "*", "crl_list", ")", "{", "int", "flags", "=", "0", ";", "unsigned", "char", "hash", "[", "POLARSSL_MD_MAX_SIZE", "]", ";", "const", "md_info_t", "*", "md_info", ";", "if", "(", "ca", "==", "NULL", ")", "return", "(", "flags", ")", ";", "while", "(", "crl_list", "!=", "NULL", ")", "{", "if", "(", "crl_list", "->", "version", "==", "0", "||", "crl_list", "->", "issuer_raw", ".", "len", "!=", "ca", "->", "subject_raw", ".", "len", "||", "memcmp", "(", "crl_list", "->", "issuer_raw", ".", "p", ",", "ca", "->", "subject_raw", ".", "p", ",", "crl_list", "->", "issuer_raw", ".", "len", ")", "!=", "0", ")", "{", "crl_list", "=", "crl_list", "->", "next", ";", "continue", ";", "}", "md_info", "=", "md_info_from_type", "(", "crl_list", "->", "sig_md", ")", ";", "if", "(", "md_info", "==", "NULL", ")", "{", "flags", "|=", "BADCRL_NOT_TRUSTED", ";", "break", ";", "}", "md", "(", "md_info", ",", "crl_list", "->", "tbs", ".", "p", ",", "crl_list", "->", "tbs", ".", "len", ",", "hash", ")", ";", "if", "(", "pk_can_do", "(", "&", "ca", "->", "pk", ",", "crl_list", "->", "sig_pk", ")", "==", "0", "||", "pk_verify", "(", "&", "ca", "->", "pk", ",", "crl_list", "->", "sig_md", ",", "hash", ",", "md_info", "->", "size", ",", "crl_list", "->", "sig", ".", "p", ",", "crl_list", "->", "sig", ".", "len", ")", "!=", "0", ")", "{", "flags", "|=", "BADCRL_NOT_TRUSTED", ";", "break", ";", "}", "if", "(", "x509_time_expired", "(", "&", "crl_list", "->", "next_update", ")", ")", "flags", "|=", "BADCRL_EXPIRED", ";", "if", "(", "x509_crt_revoked", "(", "crt", ",", "crl_list", ")", ")", "{", "flags", "|=", "BADCERT_REVOKED", ";", "break", ";", "}", "crl_list", "=", "crl_list", "->", "next", ";", "}", "return", "flags", ";", "}" ]
Check that the given certificate is valid according to the CRL.
[ "Check", "that", "the", "given", "certificate", "is", "valid", "according", "to", "the", "CRL", "." ]
[ "/*\n * TODO: What happens if no CRL is present?\n * Suggestion: Revocation state should be unknown if no CRL is present.\n * For backwards compatibility this is not yet implemented.\n */", "/*\n * Check if CRL is correctly signed by the trusted CA\n */", "/*\n * Cannot check 'unknown' hash\n */", "/*\n * Check for validity of CRL (Do not drop out)\n */", "/*\n * Check if certificate is revoked\n */" ]
[ { "param": "crt", "type": "x509_crt" }, { "param": "ca", "type": "x509_crt" }, { "param": "crl_list", "type": "x509_crl" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "crt", "type": "x509_crt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ca", "type": "x509_crt", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "crl_list", "type": "x509_crl", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c338716b73e9bace45ad738fc75b371df86f824d
ronxin/word2vec
word2phrase.c
[ "Apache-2.0" ]
C
LearnVocabFromTrainFile
void
void LearnVocabFromTrainFile() { char word[MAX_STRING], last_word[MAX_STRING], bigram_word[MAX_STRING * 2]; FILE *fin; long long a, i, start = 1; for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; fin = fopen(train_file, "rb"); if (fin == NULL) { printf("ERROR: training data file not found!\n"); exit(1); } vocab_size = 0; AddWordToVocab((char *)"</s>"); while (1) { ReadWord(word, fin); if (feof(fin)) break; if (!strcmp(word, "</s>")) { start = 1; continue; } else start = 0; train_words++; if ((debug_mode > 1) && (train_words % 100000 == 0)) { printf("Words processed: %lldK Vocab size: %lldK %c", train_words / 1000, vocab_size / 1000, 13); fflush(stdout); } i = SearchVocab(word); if (i == -1) { a = AddWordToVocab(word); vocab[a].cn = 1; } else vocab[i].cn++; if (start) continue; sprintf(bigram_word, "%s_%s", last_word, word); bigram_word[MAX_STRING - 1] = 0; strcpy(last_word, word); i = SearchVocab(bigram_word); if (i == -1) { a = AddWordToVocab(bigram_word); vocab[a].cn = 1; } else vocab[i].cn++; if (vocab_size > vocab_hash_size * 0.7) ReduceVocab(); } SortVocab(); if (debug_mode > 0) { printf("\nVocab size (unigrams + bigrams): %lld\n", vocab_size); printf("Words in train file: %lld\n", train_words); } fclose(fin); }
// XR: make vocab of unigrams and bigrams
make vocab of unigrams and bigrams
[ "make", "vocab", "of", "unigrams", "and", "bigrams" ]
void LearnVocabFromTrainFile() { char word[MAX_STRING], last_word[MAX_STRING], bigram_word[MAX_STRING * 2]; FILE *fin; long long a, i, start = 1; for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1; fin = fopen(train_file, "rb"); if (fin == NULL) { printf("ERROR: training data file not found!\n"); exit(1); } vocab_size = 0; AddWordToVocab((char *)"</s>"); while (1) { ReadWord(word, fin); if (feof(fin)) break; if (!strcmp(word, "</s>")) { start = 1; continue; } else start = 0; train_words++; if ((debug_mode > 1) && (train_words % 100000 == 0)) { printf("Words processed: %lldK Vocab size: %lldK %c", train_words / 1000, vocab_size / 1000, 13); fflush(stdout); } i = SearchVocab(word); if (i == -1) { a = AddWordToVocab(word); vocab[a].cn = 1; } else vocab[i].cn++; if (start) continue; sprintf(bigram_word, "%s_%s", last_word, word); bigram_word[MAX_STRING - 1] = 0; strcpy(last_word, word); i = SearchVocab(bigram_word); if (i == -1) { a = AddWordToVocab(bigram_word); vocab[a].cn = 1; } else vocab[i].cn++; if (vocab_size > vocab_hash_size * 0.7) ReduceVocab(); } SortVocab(); if (debug_mode > 0) { printf("\nVocab size (unigrams + bigrams): %lld\n", vocab_size); printf("Words in train file: %lld\n", train_words); } fclose(fin); }
[ "void", "LearnVocabFromTrainFile", "(", ")", "{", "char", "word", "[", "MAX_STRING", "]", ",", "last_word", "[", "MAX_STRING", "]", ",", "bigram_word", "[", "MAX_STRING", "*", "2", "]", ";", "FILE", "*", "fin", ";", "long", "long", "a", ",", "i", ",", "start", "=", "1", ";", "for", "(", "a", "=", "0", ";", "a", "<", "vocab_hash_size", ";", "a", "++", ")", "vocab_hash", "[", "a", "]", "=", "-1", ";", "fin", "=", "fopen", "(", "train_file", ",", "\"", "\"", ")", ";", "if", "(", "fin", "==", "NULL", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}", "vocab_size", "=", "0", ";", "AddWordToVocab", "(", "(", "char", "*", ")", "\"", "\"", ")", ";", "while", "(", "1", ")", "{", "ReadWord", "(", "word", ",", "fin", ")", ";", "if", "(", "feof", "(", "fin", ")", ")", "break", ";", "if", "(", "!", "strcmp", "(", "word", ",", "\"", "\"", ")", ")", "{", "start", "=", "1", ";", "continue", ";", "}", "else", "start", "=", "0", ";", "train_words", "++", ";", "if", "(", "(", "debug_mode", ">", "1", ")", "&&", "(", "train_words", "%", "100000", "==", "0", ")", ")", "{", "printf", "(", "\"", "\"", ",", "train_words", "/", "1000", ",", "vocab_size", "/", "1000", ",", "13", ")", ";", "fflush", "(", "stdout", ")", ";", "}", "i", "=", "SearchVocab", "(", "word", ")", ";", "if", "(", "i", "==", "-1", ")", "{", "a", "=", "AddWordToVocab", "(", "word", ")", ";", "vocab", "[", "a", "]", ".", "cn", "=", "1", ";", "}", "else", "vocab", "[", "i", "]", ".", "cn", "++", ";", "if", "(", "start", ")", "continue", ";", "sprintf", "(", "bigram_word", ",", "\"", "\"", ",", "last_word", ",", "word", ")", ";", "bigram_word", "[", "MAX_STRING", "-", "1", "]", "=", "0", ";", "strcpy", "(", "last_word", ",", "word", ")", ";", "i", "=", "SearchVocab", "(", "bigram_word", ")", ";", "if", "(", "i", "==", "-1", ")", "{", "a", "=", "AddWordToVocab", "(", "bigram_word", ")", ";", "vocab", "[", "a", "]", ".", "cn", "=", "1", ";", "}", "else", "vocab", "[", "i", "]", ".", "cn", "++", ";", "if", "(", "vocab_size", ">", "vocab_hash_size", "*", "0.7", ")", "ReduceVocab", "(", ")", ";", "}", "SortVocab", "(", ")", ";", "if", "(", "debug_mode", ">", "0", ")", "{", "printf", "(", "\"", "\\n", "\\n", "\"", ",", "vocab_size", ")", ";", "printf", "(", "\"", "\\n", "\"", ",", "train_words", ")", ";", "}", "fclose", "(", "fin", ")", ";", "}" ]
XR: make vocab of unigrams and bigrams
[ "XR", ":", "make", "vocab", "of", "unigrams", "and", "bigrams" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c338716b73e9bace45ad738fc75b371df86f824d
ronxin/word2vec
word2phrase.c
[ "Apache-2.0" ]
C
TrainModel
void
void TrainModel() { long long pa = 0, pb = 0, pab = 0, oov, i, li = -1, cn = 0; char word[MAX_STRING], last_word[MAX_STRING], bigram_word[MAX_STRING * 2]; real score; FILE *fo, *fin; printf("Starting training using file %s\n", train_file); // rx: unigram and bigrams only. LearnVocabFromTrainFile(); fin = fopen(train_file, "rb"); fo = fopen(output_file, "wb"); word[0] = 0; while (1) { strcpy(last_word, word); ReadWord(word, fin); if (feof(fin)) break; if (!strcmp(word, "</s>")) { fprintf(fo, "\n"); continue; } cn++; if ((debug_mode > 1) && (cn % 100000 == 0)) { printf("Words written: %lldK%c", cn / 1000, 13); fflush(stdout); } oov = 0; // oov is whether this bigram should be output as bigram i = SearchVocab(word); if (i == -1) oov = 1; else pb = vocab[i].cn; if (li == -1) oov = 1; // "li" is the index of the last word li = i; sprintf(bigram_word, "%s_%s", last_word, word); bigram_word[MAX_STRING - 1] = 0; i = SearchVocab(bigram_word); if (i == -1) oov = 1; else pab = vocab[i].cn; if (pa < min_count) oov = 1; // pa is the frequency of the previous word if (pb < min_count) oov = 1; // pb is the frequency of the current word if (oov) score = 0; else score = (pab - min_count) / (real)pa / (real)pb * (real)train_words; // PMI if (score > threshold) { fprintf(fo, "_%s", word); pb = 0; } else fprintf(fo, " %s", word); pa = pb; } fclose(fo); fclose(fin); }
// Concatenate words from corpus following a left-to-right greedy way. // Generate unigrams and bigrams only. // According to Tomas Mikolov, "The easiest way how to obtain longer phrases // is to run word2phrase iteratively, although forming the phrases using // higher-order counts might work better. The vectors are very good even // if they represent phrase that contains several words, as long as you have a lot of training data.
Concatenate words from corpus following a left-to-right greedy way. Generate unigrams and bigrams only. According to Tomas Mikolov, "The easiest way how to obtain longer phrases is to run word2phrase iteratively, although forming the phrases using higher-order counts might work better. The vectors are very good even if they represent phrase that contains several words, as long as you have a lot of training data.
[ "Concatenate", "words", "from", "corpus", "following", "a", "left", "-", "to", "-", "right", "greedy", "way", ".", "Generate", "unigrams", "and", "bigrams", "only", ".", "According", "to", "Tomas", "Mikolov", "\"", "The", "easiest", "way", "how", "to", "obtain", "longer", "phrases", "is", "to", "run", "word2phrase", "iteratively", "although", "forming", "the", "phrases", "using", "higher", "-", "order", "counts", "might", "work", "better", ".", "The", "vectors", "are", "very", "good", "even", "if", "they", "represent", "phrase", "that", "contains", "several", "words", "as", "long", "as", "you", "have", "a", "lot", "of", "training", "data", "." ]
void TrainModel() { long long pa = 0, pb = 0, pab = 0, oov, i, li = -1, cn = 0; char word[MAX_STRING], last_word[MAX_STRING], bigram_word[MAX_STRING * 2]; real score; FILE *fo, *fin; printf("Starting training using file %s\n", train_file); LearnVocabFromTrainFile(); fin = fopen(train_file, "rb"); fo = fopen(output_file, "wb"); word[0] = 0; while (1) { strcpy(last_word, word); ReadWord(word, fin); if (feof(fin)) break; if (!strcmp(word, "</s>")) { fprintf(fo, "\n"); continue; } cn++; if ((debug_mode > 1) && (cn % 100000 == 0)) { printf("Words written: %lldK%c", cn / 1000, 13); fflush(stdout); } oov = 0; i = SearchVocab(word); if (i == -1) oov = 1; else pb = vocab[i].cn; if (li == -1) oov = 1; li = i; sprintf(bigram_word, "%s_%s", last_word, word); bigram_word[MAX_STRING - 1] = 0; i = SearchVocab(bigram_word); if (i == -1) oov = 1; else pab = vocab[i].cn; if (pa < min_count) oov = 1; if (pb < min_count) oov = 1; if (oov) score = 0; else score = (pab - min_count) / (real)pa / (real)pb * (real)train_words; if (score > threshold) { fprintf(fo, "_%s", word); pb = 0; } else fprintf(fo, " %s", word); pa = pb; } fclose(fo); fclose(fin); }
[ "void", "TrainModel", "(", ")", "{", "long", "long", "pa", "=", "0", ",", "pb", "=", "0", ",", "pab", "=", "0", ",", "oov", ",", "i", ",", "li", "=", "-1", ",", "cn", "=", "0", ";", "char", "word", "[", "MAX_STRING", "]", ",", "last_word", "[", "MAX_STRING", "]", ",", "bigram_word", "[", "MAX_STRING", "*", "2", "]", ";", "real", "score", ";", "FILE", "*", "fo", ",", "*", "fin", ";", "printf", "(", "\"", "\\n", "\"", ",", "train_file", ")", ";", "LearnVocabFromTrainFile", "(", ")", ";", "fin", "=", "fopen", "(", "train_file", ",", "\"", "\"", ")", ";", "fo", "=", "fopen", "(", "output_file", ",", "\"", "\"", ")", ";", "word", "[", "0", "]", "=", "0", ";", "while", "(", "1", ")", "{", "strcpy", "(", "last_word", ",", "word", ")", ";", "ReadWord", "(", "word", ",", "fin", ")", ";", "if", "(", "feof", "(", "fin", ")", ")", "break", ";", "if", "(", "!", "strcmp", "(", "word", ",", "\"", "\"", ")", ")", "{", "fprintf", "(", "fo", ",", "\"", "\\n", "\"", ")", ";", "continue", ";", "}", "cn", "++", ";", "if", "(", "(", "debug_mode", ">", "1", ")", "&&", "(", "cn", "%", "100000", "==", "0", ")", ")", "{", "printf", "(", "\"", "\"", ",", "cn", "/", "1000", ",", "13", ")", ";", "fflush", "(", "stdout", ")", ";", "}", "oov", "=", "0", ";", "i", "=", "SearchVocab", "(", "word", ")", ";", "if", "(", "i", "==", "-1", ")", "oov", "=", "1", ";", "else", "pb", "=", "vocab", "[", "i", "]", ".", "cn", ";", "if", "(", "li", "==", "-1", ")", "oov", "=", "1", ";", "li", "=", "i", ";", "sprintf", "(", "bigram_word", ",", "\"", "\"", ",", "last_word", ",", "word", ")", ";", "bigram_word", "[", "MAX_STRING", "-", "1", "]", "=", "0", ";", "i", "=", "SearchVocab", "(", "bigram_word", ")", ";", "if", "(", "i", "==", "-1", ")", "oov", "=", "1", ";", "else", "pab", "=", "vocab", "[", "i", "]", ".", "cn", ";", "if", "(", "pa", "<", "min_count", ")", "oov", "=", "1", ";", "if", "(", "pb", "<", "min_count", ")", "oov", "=", "1", ";", "if", "(", "oov", ")", "score", "=", "0", ";", "else", "score", "=", "(", "pab", "-", "min_count", ")", "/", "(", "real", ")", "pa", "/", "(", "real", ")", "pb", "*", "(", "real", ")", "train_words", ";", "if", "(", "score", ">", "threshold", ")", "{", "fprintf", "(", "fo", ",", "\"", "\"", ",", "word", ")", ";", "pb", "=", "0", ";", "}", "else", "fprintf", "(", "fo", ",", "\"", "\"", ",", "word", ")", ";", "pa", "=", "pb", ";", "}", "fclose", "(", "fo", ")", ";", "fclose", "(", "fin", ")", ";", "}" ]
Concatenate words from corpus following a left-to-right greedy way.
[ "Concatenate", "words", "from", "corpus", "following", "a", "left", "-", "to", "-", "right", "greedy", "way", "." ]
[ "// rx: unigram and bigrams only.", "// oov is whether this bigram should be output as bigram", "// \"li\" is the index of the last word", "// pa is the frequency of the previous word", "// pb is the frequency of the current word", "// PMI" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f0887953fa4bd3ea1b4d2f6cdaac27837d9cf0be
libretro-mirrors/clove
src/joystick.c
[ "MIT" ]
C
joystick_close
void
void joystick_close() { for (int i = 0; i < moduleData.joystick_count; i++) { joystick_Joystick* js = joystick_get(i); if (SDL_JoystickGetAttached(js->joystick)) SDL_JoystickClose(js->joystick); free(js); } }
// Close all devices when clove quits
Close all devices when clove quits
[ "Close", "all", "devices", "when", "clove", "quits" ]
void joystick_close() { for (int i = 0; i < moduleData.joystick_count; i++) { joystick_Joystick* js = joystick_get(i); if (SDL_JoystickGetAttached(js->joystick)) SDL_JoystickClose(js->joystick); free(js); } }
[ "void", "joystick_close", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "moduleData", ".", "joystick_count", ";", "i", "++", ")", "{", "joystick_Joystick", "*", "js", "=", "joystick_get", "(", "i", ")", ";", "if", "(", "SDL_JoystickGetAttached", "(", "js", "->", "joystick", ")", ")", "SDL_JoystickClose", "(", "js", "->", "joystick", ")", ";", "free", "(", "js", ")", ";", "}", "}" ]
Close all devices when clove quits
[ "Close", "all", "devices", "when", "clove", "quits" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ac1ba4907ca4e406419dd73209144d9158a76c3a
libretro-mirrors/clove
src/net/net.c
[ "MIT" ]
C
net_init_ipv4
int
int net_init_ipv4(struct sockaddr_in* dest, const char* address, int port) { memset(dest, 0, sizeof(&dest)); moduleData.is_ipv4 = true; dest->sin_family = AF_INET; if (strcmp(address, "localhost") == 0) //INADDR_ANY = local address dest->sin_addr.s_addr = htonl(INADDR_ANY); else dest->sin_addr.s_addr = inet_addr(address); /* set destination address */ dest->sin_port = htons(port); if (moduleData.debug) printf("net.c - net_init - done \n"); return 1; }
//Note: All ports below 1024 are RESERVED (unless you're the superuser)! You can have any port number above that, right up to 65535
All ports below 1024 are RESERVED (unless you're the superuser). You can have any port number above that, right up to 65535
[ "All", "ports", "below", "1024", "are", "RESERVED", "(", "unless", "you", "'", "re", "the", "superuser", ")", ".", "You", "can", "have", "any", "port", "number", "above", "that", "right", "up", "to", "65535" ]
int net_init_ipv4(struct sockaddr_in* dest, const char* address, int port) { memset(dest, 0, sizeof(&dest)); moduleData.is_ipv4 = true; dest->sin_family = AF_INET; if (strcmp(address, "localhost") == 0) dest->sin_addr.s_addr = htonl(INADDR_ANY); else dest->sin_addr.s_addr = inet_addr(address); dest->sin_port = htons(port); if (moduleData.debug) printf("net.c - net_init - done \n"); return 1; }
[ "int", "net_init_ipv4", "(", "struct", "sockaddr_in", "*", "dest", ",", "const", "char", "*", "address", ",", "int", "port", ")", "{", "memset", "(", "dest", ",", "0", ",", "sizeof", "(", "&", "dest", ")", ")", ";", "moduleData", ".", "is_ipv4", "=", "true", ";", "dest", "->", "sin_family", "=", "AF_INET", ";", "if", "(", "strcmp", "(", "address", ",", "\"", "\"", ")", "==", "0", ")", "dest", "->", "sin_addr", ".", "s_addr", "=", "htonl", "(", "INADDR_ANY", ")", ";", "else", "dest", "->", "sin_addr", ".", "s_addr", "=", "inet_addr", "(", "address", ")", ";", "dest", "->", "sin_port", "=", "htons", "(", "port", ")", ";", "if", "(", "moduleData", ".", "debug", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "1", ";", "}" ]
Note: All ports below 1024 are RESERVED (unless you're the superuser)!
[ "Note", ":", "All", "ports", "below", "1024", "are", "RESERVED", "(", "unless", "you", "'", "re", "the", "superuser", ")", "!" ]
[ "//INADDR_ANY = local address", "/* set destination address */" ]
[ { "param": "dest", "type": "struct sockaddr_in" }, { "param": "address", "type": "char" }, { "param": "port", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dest", "type": "struct sockaddr_in", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "address", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "port", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ac1ba4907ca4e406419dd73209144d9158a76c3a
libretro-mirrors/clove
src/net/net.c
[ "MIT" ]
C
net_connect_to_ipv4
int
int net_connect_to_ipv4(struct sockaddr_in* dest, int socket) { int err = connect(socket, (struct sockaddr *)dest, sizeof(struct sockaddr_in)); if (err < 0) { printf("%s \n","Error connecting!"); net_close_connection(socket); return -1; } if (moduleData.debug) printf("net.c - net_connect_to - done \n"); return 1; }
/* * When connecting to a server the kernel will choose a local port for us. * This means you don't have to call net_bind_socket() ! */
When connecting to a server the kernel will choose a local port for us. This means you don't have to call net_bind_socket() !
[ "When", "connecting", "to", "a", "server", "the", "kernel", "will", "choose", "a", "local", "port", "for", "us", ".", "This", "means", "you", "don", "'", "t", "have", "to", "call", "net_bind_socket", "()", "!" ]
int net_connect_to_ipv4(struct sockaddr_in* dest, int socket) { int err = connect(socket, (struct sockaddr *)dest, sizeof(struct sockaddr_in)); if (err < 0) { printf("%s \n","Error connecting!"); net_close_connection(socket); return -1; } if (moduleData.debug) printf("net.c - net_connect_to - done \n"); return 1; }
[ "int", "net_connect_to_ipv4", "(", "struct", "sockaddr_in", "*", "dest", ",", "int", "socket", ")", "{", "int", "err", "=", "connect", "(", "socket", ",", "(", "struct", "sockaddr", "*", ")", "dest", ",", "sizeof", "(", "struct", "sockaddr_in", ")", ")", ";", "if", "(", "err", "<", "0", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "net_close_connection", "(", "socket", ")", ";", "return", "-1", ";", "}", "if", "(", "moduleData", ".", "debug", ")", "printf", "(", "\"", "\\n", "\"", ")", ";", "return", "1", ";", "}" ]
When connecting to a server the kernel will choose a local port for us.
[ "When", "connecting", "to", "a", "server", "the", "kernel", "will", "choose", "a", "local", "port", "for", "us", "." ]
[]
[ { "param": "dest", "type": "struct sockaddr_in" }, { "param": "socket", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dest", "type": "struct sockaddr_in", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "socket", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ac1ba4907ca4e406419dd73209144d9158a76c3a
libretro-mirrors/clove
src/net/net.c
[ "MIT" ]
C
net_send_data
int
int net_send_data(int new_socket, void* data, int len) { int err = send(new_socket, data, len, 0); if (err < 0) { printf("%s \n", "Error, could not send data!"); net_close_connection(new_socket); return -1; } // return the number of bytes sent return err; }
//NOTE: a write() call made to a socket behaves in exactly the same way as send() with flags set to zero.
a write() call made to a socket behaves in exactly the same way as send() with flags set to zero.
[ "a", "write", "()", "call", "made", "to", "a", "socket", "behaves", "in", "exactly", "the", "same", "way", "as", "send", "()", "with", "flags", "set", "to", "zero", "." ]
int net_send_data(int new_socket, void* data, int len) { int err = send(new_socket, data, len, 0); if (err < 0) { printf("%s \n", "Error, could not send data!"); net_close_connection(new_socket); return -1; } return err; }
[ "int", "net_send_data", "(", "int", "new_socket", ",", "void", "*", "data", ",", "int", "len", ")", "{", "int", "err", "=", "send", "(", "new_socket", ",", "data", ",", "len", ",", "0", ")", ";", "if", "(", "err", "<", "0", ")", "{", "printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ")", ";", "net_close_connection", "(", "new_socket", ")", ";", "return", "-1", ";", "}", "return", "err", ";", "}" ]
NOTE: a write() call made to a socket behaves in exactly the same way as send() with flags set to zero.
[ "NOTE", ":", "a", "write", "()", "call", "made", "to", "a", "socket", "behaves", "in", "exactly", "the", "same", "way", "as", "send", "()", "with", "flags", "set", "to", "zero", "." ]
[ "// return the number of bytes sent" ]
[ { "param": "new_socket", "type": "int" }, { "param": "data", "type": "void" }, { "param": "len", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "new_socket", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }