void session_interface::set_session_cookie(int64_t age,string const &data,string const &key) { if(data.empty()) age=-1; string cookie_name=worker.app.config.sval("session.cookies_prefix","cppcms_session"); if(!key.empty()) { cookie_name+="_"; cookie_name+=key; } if(age < 0) { cookie cook(cookie_name,"","", worker.app.config.sval("session.cookies_domain",""), 0, worker.app.config.sval("session.cookies_path","/"), worker.app.config.ival("session.cookies_secure",0)); cook.remove(); ostringstream out; out<<cook; worker.add_header(out.str()); } else { cgicc::HTTPCookie cook( cookie_name, // name (age >= 0 ? urlencode(data) : ""), // value "", // comment worker.app.config.sval("session.cookies_domain",""), // domain ( age < 0 ? 0 : age ), worker.app.config.sval("session.cookies_path","/"), worker.app.config.ival("session.cookies_secure",0)); worker.set_cookie(cook); } }
int main() { aquarium spherical, hexagonal; fish aquarium::*ingredient = pick_dinner(); cook(spherical.*ingredient); cook(hexagonal.*ingredient); }
boost::shared_ptr< Array> execute(std::vector< boost::shared_ptr< Array> >& inputArrays,boost::shared_ptr< Query> query) { boost::shared_ptr<Array> inputArray = inputArrays[0]; const ArrayDesc &arrayDesc = inputArray->getArrayDesc(); DimensionDesc xDim= arrayDesc.getDimensions()[2]; DimensionDesc yDim= arrayDesc.getDimensions()[1]; DimensionDesc zDim= arrayDesc.getDimensions()[0]; AttributeID aid = 0; // default attribute pix TypeId attType = TID_INT32; int32_t threshold = 1000; // default threashold Value value = ((boost::shared_ptr<OperatorParamPhysicalExpression>&)_parameters[1])->getExpression()->evaluate(); if (!value.isNull()) { threshold = value.getInt32(); } Attributes attributes = arrayDesc.getAttributes(); aid = ((boost::shared_ptr<OperatorParamReference>&)_parameters[0])->getObjectNo(); attType = attributes[aid].getType(); boost::shared_ptr<ConstArrayIterator> aItr = inputArray->getConstIterator(aid); boost::shared_ptr<MemArray> outputArray = boost::shared_ptr<MemArray>(new MemArray(_schema,query)); ImageProvider provider(aItr, outputArray, aid); Cook cook(provider, threshold); while(!aItr->end()) { cook.cookRawImage(); LOG4CXX_DEBUG(logger, "Cooking image: " << aItr->getPosition()[0]); ++(*aItr); } provider.onFinalize(); return outputArray; }
/// Just an easy interface around cookie() Part use(const Slice &name) { Cookie cookie {}; if (cook(name, cookie).ok()) { return use(cookie); } else { return {}; } }
int main() { int nVariable; nVariable = 0; read(&nVariable); cook(&nVariable); write(&nVariable, "Result: nVariable = "); return 0; }
int main(int argc, char **argv) { int retval; /* * Some versions of cron(8) and at(1) set SIGCHLD to SIG_IGN. * This is kinda dumb, because it breaks assumprions made in * libc (like pclose, for instance). It also blows away most * of Cook's process handling. We explicitly set the SIGCHLD * signal handling to SIG_DFL to make sure this signal does what * we expect no matter how we are invoked. */ #ifdef SIGCHLD signal(SIGCHLD, SIG_DFL); #else signal(SIGCLD, SIG_DFL); #endif /* * initialize things * (order is critical here) */ progname_set(argv[0]); str_initialize(); id_initialize(); lex_initialize(); /* * parse the COOK environment variable */ arglex_init_from_env(argv[0], argtab); argparse(OPTION_LEVEL_ENVIRONMENT); /* * parse the command line */ arglex_init(argc, argv, argtab); argparse(OPTION_LEVEL_COMMAND_LINE); option_tidy_up(); log_open(); /* * turn on progress stars if they asked for them */ if (option_test(OPTION_STAR)) star_enable(); /* * If we were asked to update the fingerprints, do it here. * We don't actually ant to read in the cookbook. */ if (option.fingerprint_update) { fp_tweak(); quit(0); } /* * read in the cook book * * If there are #include-cooked directives, * we may need to do it more than once. */ if (!option.o_book) fatal_intl(0, i18n("no book found")); for (;;) { int status; size_t j; builtin_initialize(); /* * instanciate the command line variable assignments */ for (j = 0; j < option.o_vardef.nstrings; ++j) { char *s; char *cp; string_ty *name; string_ty *value; string_list_ty wl; opcode_context_ty *ocp; s = option.o_vardef.string[j]->str_text; cp = strchr(s, '='); assert(cp); if (!cp) continue; name = str_n_from_c(s, cp - s); value = str_from_c(cp + 1); str2wl(&wl, value, (char *)0, 0); str_free(value); ocp = opcode_context_new(0, 0); opcode_context_id_assign(ocp, name, id_variable_new(&wl), 0); opcode_context_delete(ocp); str_free(name); string_list_destructor(&wl); } set_command_line_goals(); parse(option.o_book); status = cook_auto_required(); if (status < 0) quit(1); if (!status) break; id_reset(); cook_reset(); } /* * work out what to cook. * If no targets have been given, use the first explicit recipe. */ set_command_line_goals(); if (!option.o_target.nstrings) cook_find_default(&option.o_target); assert(option.o_target.nstrings); /* * cook the target */ if (option.pairs) retval = cook_pairs(&option.o_target); else if (option.script) retval = cook_script(&option.o_target); else if (option.web) retval = cook_web(&option.o_target); else retval = cook(&option.o_target); #ifdef DEBUG fflush_slowly_report(); #endif quit(retval); /*NOTREACHED*/ return 0; }
// Show prompt according to current mode static void show_isearch() { XmTextPosition start = start_of_line(); if (start == XmTextPosition(-1)) return; string prompt; switch (isearch_state) { case ISEARCH_NONE: prompt = gdb->prompt(); break; case ISEARCH_NEXT: prompt = isearch_prompt; break; case ISEARCH_PREV: prompt = reverse_isearch_prompt; break; } if (isearch_state != ISEARCH_NONE) prompt += "`" + cook(isearch_string) + "': "; string input = current_line(); string line = prompt + input; bool old_private_gdb_output = private_gdb_output; private_gdb_output = true; XmTextReplace(gdb_w, start, XmTextGetLastPosition(gdb_w), XMST(line.chars())); promptPosition = start + prompt.length(); XmTextPosition pos = promptPosition; int index = input.index(isearch_string); if (isearch_state == ISEARCH_NONE || index < 0) { XmTextSetHighlight(gdb_w, 0, XmTextGetLastPosition(gdb_w), XmHIGHLIGHT_NORMAL); } else { XmTextSetHighlight(gdb_w, 0, pos + index, XmHIGHLIGHT_NORMAL); XmTextSetHighlight(gdb_w, pos + index, pos + index + isearch_string.length(), XmHIGHLIGHT_SECONDARY_SELECTED); XmTextSetHighlight(gdb_w, pos + index + isearch_string.length(), XmTextGetLastPosition(gdb_w), XmHIGHLIGHT_NORMAL); } if (index >= 0) pos += index; XmTextSetInsertionPosition(gdb_w, pos); XmTextShowPosition(gdb_w, pos); have_isearch_line = false; private_gdb_output = old_private_gdb_output; }
void file2control(struct context *ctx, char *arg, char *file) { Debug((DEBUG_PROC, "+ %s (%s)\n", __func__, file ? file : "(NULL)")); if (file && ctx->multiline_banners) { int i = -1; struct stat st; int is_banner = file == ctx->welcome || file == ctx->banner || file == ctx->goodbye; char form[PATH_MAX + 1], path[PATH_MAX + 1]; char *l, *t, llang[10]; if (!is_banner && ctx->readme_once && (!pickystat(ctx, &st, ctx->cwd)) && dir_visited(ctx, &st)) { Debug((DEBUG_PROC, "already visited\n")); DebugOut(DEBUG_PROC); return; } l = llang, t = lang[ctx->lang]; *l++ = '-'; while (*t) *l++ = tolower((int) *t++); *l = 0; if ((sizeof(form) <= (size_t) snprintf(form, sizeof(form), "%s/%s", (is_banner || file[0] == '/') ? "" : ctx->cwd, file)) || (sizeof(path) <= (size_t) snprintf(path, sizeof(path), form, llang))) { DebugOut(DEBUG_PROC); return; } if (is_banner) { i = open(path, O_RDONLY); if (i < 0 && strstr(form, "%s")) { if (sizeof(path) <= (size_t) snprintf(path, sizeof(path), form, "")) { DebugOut(DEBUG_PROC); return; } i = open(path, O_RDONLY); } } else { if (((pickystat(ctx, &st, path) || (i = open(path, O_RDONLY)) < 0)) && strstr(form, "%s")) { if (sizeof(path) <= (size_t) snprintf(path, sizeof(path), form, "")) { DebugOut(DEBUG_PROC); return; } if (!pickystat(ctx, &st, path)) i = open(path, O_RDONLY); } if (i > -1 && ctx->readme_notify) { long days_ago = (io_now.tv_sec - st.st_mtime) / 86400; char tb[2 * PATH_MAX]; close(i); replyf(ctx, "%s-", arg); replyf(ctx, MSG_Readme_notify_1, file); strftime(tb, sizeof(tb), MSG_Readme_notify_2, localtime(&st.st_mtime)); replyf(ctx, "%s-%s", arg, tb); if (days_ago == 1) reply(ctx, MSG_Readme_notify_31); else replyf(ctx, MSG_Readme_notify_3n, days_ago); DebugOut(DEBUG_PROC); return; } } if (i > -1) { char tbuf[BUFSIZE]; char *lineend, *linestart = NULL; size_t offset = 0; ssize_t inlength; while ((inlength = read(i, tbuf + offset, sizeof(tbuf) - 1 - offset)) > 0) { inlength += offset; tbuf[inlength] = 0; linestart = tbuf; while ((lineend = strchr(linestart, '\n'))) { *lineend = 0; chomp(linestart); replyf(ctx, "%s-%s\r\n", arg, cook(ctx, linestart, NULL, NULL, 0)); linestart = lineend + 1; } #ifdef README_LOOP /* * Don't allow arbitrary sized README files. Noone's able or willing to * read thousands of lines rushing by. BUFSIZE is our upper limit. For * unlimited file sizes, #define README_LOOP. Yes, that could be made * a configuration option. No, I don't think it makes sense. */ if ((offset = tbuf + inlength - linestart)) memmove(tbuf, linestart, offset); else #endif break; } close(i); } } DebugOut(DEBUG_PROC); }
/** * @ingroup VuoTransform * Encodes @c value as a JSON object. */ json_object * VuoTransform_jsonFromValue(const VuoTransform value) { if (VuoTransform_isIdentity(value)) return json_object_new_string("identity"); json_object *js = json_object_new_object(); { json_object * o = json_object_new_array(); json_object_array_add(o,json_object_new_double(cook(value.translation.x))); json_object_array_add(o,json_object_new_double(cook(value.translation.y))); json_object_array_add(o,json_object_new_double(cook(value.translation.z))); json_object_object_add(js, "translation", o); } // Don't store value.rotation, since we can calculate it from the source rotation. if (value.type == VuoTransformTypeQuaternion) { json_object * o = json_object_new_array(); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.quaternion.x))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.quaternion.y))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.quaternion.z))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.quaternion.w))); json_object_object_add(js, "quaternionRotation", o); } else if (value.type == VuoTransformTypeEuler) { json_object * o = json_object_new_array(); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.euler.x))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.euler.y))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.euler.z))); json_object_object_add(js, "eulerRotation", o); } else { json_object * o = json_object_new_array(); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.target.x))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.target.y))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.target.z))); json_object_object_add(js, "target", o); o = json_object_new_array(); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.upDirection.x))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.upDirection.y))); json_object_array_add(o,json_object_new_double(cook(value.rotationSource.upDirection.z))); json_object_object_add(js, "upDirection", o); } if (value.type != VuoTransformTypeTargeted) { json_object * o = json_object_new_array(); json_object_array_add(o,json_object_new_double(cook(value.scale.x))); json_object_array_add(o,json_object_new_double(cook(value.scale.y))); json_object_array_add(o,json_object_new_double(cook(value.scale.z))); json_object_object_add(js, "scale", o); } return js; }