bool try_pk (string family, int size, int dpi, int dsize, tex_font_metric& tfm, font_glyphs& pk) { // cout << "Try pk " << family << size << " at " << dpi << " dpi\n"; #ifdef USE_FREETYPE // Substitute by True Type font ? int tt_size= size<333? size: (size+50)/100; int tt_dpi = size<333? dpi : (size * dpi) / (100 * tt_size); string tt_name= tt_find_name (family, tt_size); if (tt_name != "") { if (font_glyphs::instances -> contains (tt_name)) pk= font_glyphs (tt_name); else pk= tt_font_glyphs (tt_name, tt_size, tt_dpi); return true; } #endif // USE_FREETYPE // Open regular pk font string name_pk= family * as_string (size) * "." * as_string (dpi) * "pk"; if (font_glyphs::instances -> contains (name_pk)) { pk = font_glyphs (name_pk); return true; } if (dsize == 0) { int old_size= size; size= tfm->size; dpi = mag (dpi, old_size, size); } string size_name (dsize==0? string (""): as_string (size)); string name (family * size_name * "." * as_string (dpi) * "pk"); if (DEBUG_STD) debug_fonts << "Open pk " << name << "\n"; url u= resolve_tex (name); if (is_none (u)) { if (exists (url ("$TEXMACS_HOME_PATH/fonts/error", name))) { if (DEBUG_STD) debug_fonts << "Error during " << name << " loading\n"; return false; } if (get_setting ("MAKEPK") != "false") { system_wait ("Generating font file", name); make_tex_pk (family * size_name, dpi, as_int (get_setting ("DPI"))); system_wait (""); u= resolve_tex (name); if (is_none (u)) { reset_pk_path (); u= resolve_tex (name); } } if (is_none (u)) { save_string (url ("$TEXMACS_HOME_PATH/fonts/error", name), ""); if (DEBUG_STD) debug_fonts << "Error during " << name << " loading\n"; return false; } } pk = font_glyphs (tm_new<pk_font_glyphs_rep> (name_pk, tm_new<pk_loader> (u, tfm, dpi))); return true; }
url resolve_tex (url name) { string s= as_string (name); if (is_cached ("font_cache.scm", s)) { url u= url_system (cache_get ("font_cache.scm", s) -> label); if (exists (u)) return u; cache_reset ("font_cache.scm", s); } bench_start ("resolve tex"); url u= url_none (); if (ends (s, "mf" )) { u= resolve_tfm (name); #ifdef OS_WIN32 if (is_none (u)) u= resolve_tfm (replace (s, ".mf", ".tfm")); #endif } if (ends (s, "tfm")) u= resolve_tfm (name); if (ends (s, "pk" )) u= resolve_pk (name); if (ends (s, "pfb")) u= resolve_pfb (name); bench_cumul ("resolve tex"); if (!is_none (u)) cache_set ("font_cache.scm", s, as_string (u)); //cout << "Resolve " << name << " -> " << u << "\n"; return u; }
static void init_main_paths () { #ifdef __MINGW32__ if (is_none (get_env_path ("TEXMACS_HOME_PATH", get_env ("APPDATA") * "/TeXmacs"))) { #else if (is_none (get_env_path ("TEXMACS_HOME_PATH", "~/.TeXmacs"))) { #endif boot_error << "\n"; boot_error << "Installation problem: please send a bug report.\n"; boot_error << "'TEXMACS_HOME_PATH' could not be set to '~/.TeXmacs'.\n"; boot_error << "You may try to set this environment variable manually\n"; boot_error << "\n"; FAILED ("installation problem"); exit (1); } } /****************************************************************************** * Directory for temporary files ******************************************************************************/ static string main_tmp_dir= "$TEXMACS_HOME_PATH/system/tmp"; static void make_dir (url which) { if (!is_directory (which)) { make_dir (head (which)); mkdir (which); } } static url url_temp_dir_sub () { #ifdef __MINGW32__ static url tmp_dir= url_system (main_tmp_dir) * url_system (as_string (time (NULL))); #else static url tmp_dir= url_system (main_tmp_dir) * url_system (as_string ((int) getpid ())); #endif return (tmp_dir); } url url_temp_dir () { static url u; if (u == url_none()) { u= url_temp_dir_sub (); make_dir (u); } return u; } bool process_running (int pid) { string cmd= "ps -p " * as_string (pid); string ret= eval_system (cmd); return occurs ("texmacs", ret) && occurs (as_string (pid), ret); }
/* * Add gtm slave: to be used after all the configuration is done. * * This function only maintains internal configuration, updte configuration file, * and make backup if configured. You should run init_gtm_slave and stat_gtm_slave * separately. */ int add_gtmSlave(char *name, char *host, int port, char *dir) { char port_s[MAXTOKEN+1]; char date[MAXTOKEN+1]; FILE *f; int rc; if (isVarYes(VAR_gtmSlave)) { elog(ERROR, "ERROR: GTM slave is already configured.\n"); return 1; } if (is_none(host)) { elog(ERROR, "ERROR: Cannot add gtm slave with the name \"none\".\n"); return 1; } if (is_none(dir)) { elog(ERROR, "ERROR: Cannot add gtm slave with the directory \"none\".\n"); return 1; } if (checkSpecificResourceConflict(name, host, port, dir, TRUE)) { elog(ERROR, "ERROR: New specified name:%s, host:%s, port:%d and dir:\"%s\" conflicts with existing node.\n", name, host, port, dir); return 1; } assign_sval(VAR_gtmSlave, Strdup("y")); assign_sval(VAR_gtmSlaveServer, Strdup(host)); snprintf(port_s, MAXTOKEN, "%d", port); assign_sval(VAR_gtmSlavePort, Strdup(port_s)); assign_sval(VAR_gtmSlaveDir, Strdup(dir)); makeServerList(); if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL) { /* Should it be panic? */ elog(ERROR, "ERROR: cannot open configuration file \"%s\", %s\n", pgxc_ctl_config_path, strerror(errno)); return 1; } fprintf(f, "#===================================================\n" "# pgxc configuration file updated due to GTM slave addition\n" "# %s\n", timeStampString(date, MAXTOKEN+1)); fprintSval(f, VAR_gtmSlave); fprintSval(f, VAR_gtmSlaveServer); fprintSval(f, VAR_gtmSlavePort); fprintSval(f, VAR_gtmSlaveDir); fprintf(f, "%s","#----End of reconfiguration -------------------------\n"); fclose(f); backup_configuration(); if ((rc = init_gtm_slave()) != 0) return rc; return(start_gtm_slave()); }
url operator | (url u1, url u2) { if (is_none (u1)) return u2; if (is_none (u2)) return u1; if (is_or (u1)) return u1[1] | (u1[2] | u2); if (u1 == u2) return u2; if (is_or (u2) && (u1 == u2[1])) return u2; return as_url (tuple ("or", u1->t, u2->t)); }
/* * Init gtm master ----------------------------------------------------------------- */ static cmd_t * prepare_initGtmMaster(void) { cmd_t *cmdInitGtmMaster, *cmdGtmConf, *cmdGxid; char date[MAXTOKEN+1]; FILE *f; char **fileList = NULL; /* Kill current gtm, bild work directory and run initgtm */ cmdInitGtmMaster = initCmd(sval(VAR_gtmMasterServer)); snprintf(newCommand(cmdInitGtmMaster), MAXLINE, "killall -u %s -9 gtm; rm -rf %s; mkdir -p %s;initgtm -Z gtm -D %s", sval(VAR_pgxcUser), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir)); /* Then prepare gtm.conf file */ /* Prepare local Stdin */ appendCmdEl(cmdInitGtmMaster, (cmdGtmConf = initCmd(sval(VAR_gtmMasterServer)))); if ((f = prepareLocalStdin(newFilename(cmdGtmConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdInitGtmMaster); return(NULL); } fprintf(f, "#===============================================\n" "# Added at initialization, %s\n" "listen_addresses = '*'\n", timeStampString(date, MAXTOKEN)); if (!is_none(sval(VAR_gtmExtraConfig))) AddMember(fileList, sval(VAR_gtmExtraConfig)); if (!is_none(sval(VAR_gtmMasterSpecificExtraConfig))) AddMember(fileList, sval(VAR_gtmMasterSpecificExtraConfig)); appendFiles(f, fileList); CleanArray(fileList); fprintf(f, "port = %s\n" "nodename = '%s'\n" "startup = ACT\n" "# End of addition\n", sval(VAR_gtmMasterPort), sval(VAR_gtmName)); fclose(f); /* other options */ snprintf(newCommand(cmdGtmConf), MAXLINE, "cat >> %s/gtm.conf", sval(VAR_gtmMasterDir)); /* Setup GTM with appropriate GXID value */ appendCmdEl(cmdGtmConf, (cmdGxid = initCmd(sval(VAR_gtmMasterServer)))); snprintf(newCommand(cmdGxid), MAXLINE, "(gtm -x 2000 -D %s &); sleep 1; gtm_ctl stop -Z gtm -D %s", sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir)); return cmdInitGtmMaster; }
/* * Backup configuration files to a remote site as specified. */ int backup_configuration(void) { if ((strcasecmp(sval(VAR_configBackup), "y") != 0) || is_none(sval(VAR_configBackupHost)) || is_none(sval(VAR_configBackupDir)) || is_none(sval(VAR_configBackupFile))) return (2); return(doImmediate(NULL, NULL, "scp %s %s@%s:%s/%s", pgxc_ctl_config_path, sval(VAR_pgxcUser), sval(VAR_configBackupHost), sval(VAR_configBackupDir), sval(VAR_configBackupFile))); }
bool exists_in_path (url u) { #if defined (OS_WIN32) || defined (__MINGW__) || defined (__MINGW32__) return !is_none (resolve_in_path (url (as_string (u) * ".bat"))) ||\ !is_none (resolve_in_path (url (as_string (u) * ".exe"))) ||\ !is_none (resolve_in_path (url (as_string (u) * ".com"))); #else return !is_none (resolve_in_path (u)); #endif }
/* * Assumes Gtm Slave is configured. * Caller should check this. */ static cmd_t * prepare_initGtmSlave(void) { char date[MAXTOKEN+1]; cmd_t *cmdInitGtm, *cmdGtmConf; FILE *f; char **fileList = NULL; if (!isVarYes(VAR_gtmSlave) || (sval(VAR_gtmSlaveServer) == NULL) || is_none(sval(VAR_gtmSlaveServer))) { elog(ERROR, "ERROR: GTM slave is not configured.\n"); return(NULL); } /* Kill current gtm, build work directory and run initgtm */ cmdInitGtm = initCmd(sval(VAR_gtmSlaveServer)); snprintf(newCommand(cmdInitGtm), MAXLINE, "killall -u %s -9 gtm; rm -rf %s; mkdir -p %s; initgtm -Z gtm -D %s", sval(VAR_pgxcUser), sval(VAR_gtmSlaveDir), sval(VAR_gtmSlaveDir), sval(VAR_gtmSlaveDir)); /* Prepare gtm.conf file */ /* Prepare local Stdin */ appendCmdEl(cmdInitGtm, (cmdGtmConf = initCmd(sval(VAR_gtmSlaveServer)))); snprintf(newCommand(cmdGtmConf), MAXLINE, "cat >> %s/gtm.conf", sval(VAR_gtmSlaveDir)); if ((f = prepareLocalStdin(newFilename(cmdGtmConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdInitGtm); return(NULL); } fprintf(f, "#===============================================\n" "# Added at initialization, %s\n" "listen_addresses = '*'\n", timeStampString(date, MAXPATH+1)); if (!is_none(sval(VAR_gtmExtraConfig))) AddMember(fileList, sval(VAR_gtmExtraConfig)); if (!is_none(sval(VAR_gtmMasterSpecificExtraConfig))) AddMember(fileList, sval(VAR_gtmMasterSpecificExtraConfig)); appendFiles(f, fileList); CleanArray(fileList); fprintf(f, "port = %s\n" "nodename = '%s'\n" "startup = STANDBY\n" "active_host = '%s'\n" "active_port = %d\n" "# End of addition\n", sval(VAR_gtmSlavePort), sval(VAR_gtmName), sval(VAR_gtmMasterServer), atoi(sval(VAR_gtmMasterPort))); fclose(f); return (cmdInitGtm); }
uint24_option combine_value (uint8_t const universe_bits, uint24_option const hi, uint24_option const lo) { if (is_none(hi) || is_none(lo)) return none(); uint8_t lo_bits = universe_bits >> 1; uint8_t hi_bits = lo_bits + (universe_bits & 1); uint32_t hi_mask = (1 << hi_bits) - 1; uint32_t lo_mask = (1 << lo_bits) - 1; return ((hi & hi_mask) << lo_bits) + (lo & lo_mask); }
url embedded_name (url name) { static int nr= 0; if (!is_none (name)) return name; nr++; return url (string ("tmfs://aux/TeXmacs-input-" * as_string (nr))); }
static bool void_star_param(ast_t* param_type, ast_t* arg_type) { assert(param_type != NULL); assert(arg_type != NULL); if(!is_pointer(param_type)) return false; ast_t* type_args = ast_childidx(param_type, 2); if(ast_childcount(type_args) != 1 || !is_none(ast_child(type_args))) return false; // Parameter type is Pointer[None] // If the argument is Pointer[A], MaybePointer[A] or USize, allow it while(ast_id(arg_type) == TK_ARROW) arg_type = ast_childidx(arg_type, 1); if(is_pointer(arg_type) || is_maybe(arg_type) || is_literal(arg_type, "USize")) return true; return false; }
void dictionary_rep::load (url u) { if (is_none (u)) return; if (is_or (u)) { load (u[1]); load (u[2]); return; } string s; if (load_string (u, s, false)) return; tree t= block_to_scheme_tree (s); if (!is_tuple (t)) return; int i, n= N(t); for (i=0; i<n; i++) if (is_func (t[i], TUPLE, 2) && is_atomic (t[i][0]) && is_atomic (t[i][1])) { string l= t[i][0]->label; if (is_quoted (l)) l= scm_unquote (l); string r= t[i][1]->label; if (is_quoted (r)) r= scm_unquote (r); if (to == "chinese" || to == "japanese" || to == "german" || to == "korean" || to == "taiwanese" || to == "russian" || to == "ukrainian" || to == "bulgarian") r= utf8_to_cork (r); table (l)= r; } }
int show_config_gtmSlave(int flag, char *hostname) { char lineBuf[MAXLINE+1]; char editBuf[MAXPATH+1]; if (!isVarYes(VAR_gtmSlave) || is_none(VAR_gtmSlaveServer)) { elog(ERROR, "ERROR: gtm slave is not configured.\n"); return 0; } lineBuf[0] = 0; if (flag) strncat(lineBuf, "GTM Slave: ", MAXLINE); if (hostname) { snprintf(editBuf, MAXPATH, "host: %s", hostname); strncat(lineBuf, editBuf, MAXLINE); } if (flag || hostname) strncat(lineBuf, "\n", MAXLINE); lockLogFile(); elog(NOTICE, "%s", lineBuf); print_simple_node_info(sval(VAR_gtmName), sval(VAR_gtmSlavePort), sval(VAR_gtmSlaveDir), sval(VAR_gtmExtraConfig), sval(VAR_gtmSlaveSpecificExtraConfig)); unlockLogFile(); return 0; }
std::string Formats3d::ToString() const { std::string ret; ret = PropertyName::wfd_3d_video_formats + std::string(SEMICOLON)+ std::string(SPACE); if (is_none()) return ret + NONE; MAKE_HEX_STRING_2(native, native_); MAKE_HEX_STRING_2(preferred_display_mode, preferred_display_mode_); ret += native + std::string(SPACE) + preferred_display_mode + std::string(SPACE); auto it = h264_codecs_3d_.begin(); auto end = h264_codecs_3d_.end(); while(it != end) { ret += (*it).ToString(); ++it; if (it != end) ret += ", "; } return ret; }
void fun_defaults(ast_t* ast) { assert(ast != NULL); AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error, body, docstring); // If the receiver cap is not specified, set it to box. if(ast_id(cap) == TK_NONE) ast_setid(cap, TK_BOX); // If the return value is not specified, set it to None. if(ast_id(result) == TK_NONE) { ast_t* type = type_sugar(ast, NULL, "None"); ast_replace(&result, type); } // If the return type is None, add a None at the end of the body, unless it // already ends with an error or return statement if(is_none(result) && (ast_id(body) != TK_NONE)) { ast_t* last_cmd = ast_childlast(body); if(ast_id(last_cmd) != TK_ERROR && ast_id(last_cmd) != TK_RETURN) { BUILD_NO_DEBUG(ref, body, NODE(TK_REFERENCE, ID("None"))); ast_append(body, ref); } } }
static bool verify_any_final(pass_opt_t* opt, ast_t* ast) { AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error, body); if(strcmp(ast_name(id), "_final")) return true; bool ok = true; if((ast_id(opt->check.frame->type) == TK_PRIMITIVE) && (ast_id(ast_childidx(opt->check.frame->type, 1)) != TK_NONE)) { ast_error(opt->check.errors, ast, "a primitive with type parameters cannot have a _final method"); ok = false; } if(ast_id(ast) != TK_FUN) { ast_error(opt->check.errors, ast, "a _final method must be a function"); ok = false; } if(ast_id(cap) != TK_BOX) { ast_error(opt->check.errors, cap, "a _final method must use box as the receiver capability"); ok = false; } if(ast_id(typeparams) != TK_NONE) { ast_error(opt->check.errors, typeparams, "a _final method must not take type parameters"); ok = false; } if(ast_childcount(params) != 0) { ast_error(opt->check.errors, params, "a _final method must take no parameters"); ok = false; } if(!is_none(result)) { ast_error(opt->check.errors, result, "a _final method must return None"); ok = false; } if(ast_id(can_error) != TK_NONE) { ast_error(opt->check.errors, can_error, "a _final method cannot be a partial function"); ok = false; } return ok; }
void tm_server_rep::refresh () { array<url> l= windows_list (); for (int i=0; i<N(l); i++) { url u= window_to_view (l[i]); if (!is_none (u)) concrete_view (u)->win->refresh (); } }
url delta (url base, url u) { if (is_or (u)) return delta (base, u[1]) | delta (base, u[2]); url res= delta_sub (base, u); if (is_none (res)) return u; return res; }
static url get_env_path (string which, url def) { url val= get_env_path (which); if (is_none (val) || (val->t == "")) { set_env_path (which, def); return def; } return val; }
url get_from_ramdisc (url u) { if (!is_ramdisc (u)) return url_none (); url res= get_cache (u); if (!is_none (res)) return (res); url tmp= url_temp (string (".") * suffix (u)); save_string (tmp, u[1][2]->t->label); return set_cache (u, tmp); }
string edit_main_rep::get_metadata (string kind) { string var= "global-" * kind; string val= get_init_string (var); if (val != "") return val; val= search_metadata (subtree (et, rp), kind); if (val != "") return val; if (kind == "title") return as_string (tail (get_name ())); #ifndef __MINGW32__ if (kind == "author" && !is_none (resolve_in_path ("finger")) && !is_none (resolve_in_path ("sed"))) { string val= var_eval_system ("finger `whoami` | sed -e '/Name/!d' -e 's/.*Name: //'"); if (N(val) > 1) return utf8_to_cork (val); } #endif return ""; }
bool try_tfm (string family, int size, int osize, tex_font_metric& tfm, bool make) { // cout << "Try tfm " << family << size << " (" << osize << ")\n"; make= make && get_setting ("MAKETFM") != "false"; string name_tfm = family * as_string (osize) * ".tfm"; if (tex_font_metric::instances -> contains (name_tfm)) { tfm= tex_font_metric (name_tfm); return true; } string name= family * (size==0? string (""): as_string (size)) * ".tfm"; if (DEBUG_STD) debug_fonts << "Try tfm " << name << "\n"; url u= resolve_tex (name); if (is_none (u)) { if (exists (url ("$TEXMACS_HOME_PATH/fonts/error", name))) { if (DEBUG_STD) debug_fonts << "Error during " << name << " loading\n"; return false; } if (make) { system_wait ("Generating font file", name); make_tex_tfm (name); system_wait (""); u= resolve_tex (name); if (is_none (u)) { reset_tfm_path (); u= resolve_tex (name); save_string (url ("$TEXMACS_HOME_PATH/fonts/error", name), ""); } } if (is_none (u)) return false; } // cout << "Tfm " << family << osize << " -> " << family << size << "\n"; tfm= load_tfm (u, family, osize); if (size != osize) cache_set ("font_cache.scm", "tfm:" * family * as_string (osize), as_string (size)); if (size == 0) { size= tfm->size; if (DEBUG_STD) debug_fonts << "Design size = " << size << "\n"; } if (size != osize) tfm->header[1]= mag (tfm->header[1], osize, size); return true; }
static void print_method(compile_t* c, printbuf_t* buf, reach_type_t* t, reach_method_t* m) { if(!emit_fun(m->r_fun)) return; AST_GET_CHILDREN(m->r_fun, cap, id, typeparams, params, rtype, can_error, body, docstring); // Print the docstring if we have one. if(ast_id(docstring) == TK_STRING) { printbuf(buf, "/*\n" "%s" "*/\n", ast_name(docstring) ); } // Print the function signature. if((ast_id(cap) != TK_AT) || !is_none(rtype)) print_type_name(c, buf, rtype); else printbuf(buf, "void"); printbuf(buf, " %s", m->full_name); switch(ast_id(m->r_fun)) { case TK_NEW: case TK_BE: { ast_t* def = (ast_t*)ast_data(t->ast); if(ast_id(def) == TK_ACTOR) printbuf(buf, "__send"); break; } default: {} } printbuf(buf, "("); if(ast_id(cap) != TK_AT) { print_type_name(c, buf, t->ast); printbuf(buf, " self"); print_params(c, buf, params, true); } else { print_params(c, buf, params, false); } printbuf(buf, ");\n\n"); }
void antialias_style_type:: attach ( QRadioButton * p_radio_best , QRadioButton * p_radio_fastest , QRadioButton * p_radio_none , bool init_value_from_holder ) { d_assert( p_radio_best ); d_assert( p_radio_fastest); d_assert( p_radio_none ); d_assert( p_radio_best != p_radio_fastest); d_assert( p_radio_best != p_radio_none ); d_assert( p_radio_fastest != p_radio_none ); if ( init_value_from_holder ) { // Set the init state of the radio buttons from this folder. p_radio_best ->setChecked( is_best( )); p_radio_fastest->setChecked( is_fastest( )); p_radio_none ->setChecked( is_none( )); } else { // Set the init value of this holder from the radio buttons. if ( p_radio_best->isChecked( ) ) { d_assert( ! p_radio_fastest->isChecked( )); d_assert( ! p_radio_none ->isChecked( )); set_best( ); } else if ( p_radio_fastest->isChecked( ) ) { d_assert( ! p_radio_best->isChecked( )); d_assert( ! p_radio_none->isChecked( )); set_fastest( ); } else if ( p_radio_none->isChecked( ) ) { d_assert( ! p_radio_best ->isChecked( )); d_assert( ! p_radio_fastest->isChecked( )); set_none( ); } else { // None of the radio buttons are on! Choose arbitrarily. d_assert( false); set_none( ); /* set the holder value */ p_radio_none->setChecked( true); /* check the radio button */ } } // Tell the radio buttons to update the values here. d_verify( connect( p_radio_best , SIGNAL( toggled( bool)), this, SLOT( set_best( bool)) )); d_verify( connect( p_radio_fastest, SIGNAL( toggled( bool)), this, SLOT( set_fastest( bool)) )); d_verify( connect( p_radio_none , SIGNAL( toggled( bool)), this, SLOT( set_none( bool)) )); // Propagate changes here back to the radio buttons. d_verify( connect( this, SIGNAL( has_changed__best( bool)), p_radio_best , SLOT( setChecked( bool)) )); d_verify( connect( this, SIGNAL( has_changed__fastest( bool)), p_radio_fastest, SLOT( setChecked( bool)) )); d_verify( connect( this, SIGNAL( has_changed__none( bool)), p_radio_none , SLOT( setChecked( bool)) )); }
vm_obj tactic_get_subsingleton_info(vm_obj const & fn, vm_obj const & n, vm_obj const & m, vm_obj const & s) { TRY; type_context ctx = mk_type_context_for(s, m); if (is_none(n)) { return mk_result(get_subsingleton_info(ctx, to_expr(fn)), s); } else { return mk_result(get_subsingleton_info(ctx, to_expr(fn), force_to_unsigned(get_some_value(n), 0)), s); } CATCH; }
static bool check_finaliser(pass_opt_t* opt, ast_t* ast) { AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error, body); if(strcmp(ast_name(id), "_final")) return true; bool ok = true; if((ast_id(opt->check.frame->type) == TK_PRIMITIVE) && (ast_id(ast_childidx(opt->check.frame->type, 1)) != TK_NONE)) { ast_error(opt->check.errors, ast, "a primitive with type parameters cannot have a _final"); ok = false; } if(ast_id(ast) != TK_FUN) { ast_error(opt->check.errors, ast, "_final must be a function"); ok = false; } if(ast_id(cap) != TK_BOX) { ast_error(opt->check.errors, cap, "_final must be box"); ok = false; } if(ast_id(typeparams) != TK_NONE) { ast_error(opt->check.errors, typeparams, "_final must not be polymorphic"); ok = false; } if(ast_childcount(params) != 0) { ast_error(opt->check.errors, params, "_final must not have parameters"); ok = false; } if(!is_none(result)) { ast_error(opt->check.errors, result, "_final must return None"); ok = false; } if(ast_id(can_error) != TK_NONE) { ast_error(opt->check.errors, can_error, "_final cannot raise an error"); ok = false; } return ok; }
/* * Call this function after trying to decrypt a message and pass it if * the decryption was successful or if it wasn't. */ int ratchet_set_last_message_authenticity(ratchet_state *state, bool valid) { //prepare for being able to receive new messages state->received_valid = true; //backup header decryptability ratchet_header_decryptability header_decryptable = state->header_decryptable; state->header_decryptable = NOT_TRIED; //TODO make sure this function aborts if it is called at the wrong time int status; //TODO I can do those if's better. This only happens to be this way because of the specification if ((!is_none(state->receive_header_key, crypto_aead_chacha20poly1305_KEYBYTES)) && (header_decryptable == CURRENT_DECRYPTABLE)) { //still the same message chain //if HKr != <none> and Dec(HKr, header) if (!valid) { //message couldn't be decrypted //clear purported message and header keys header_and_message_keystore_clear(&(state->purported_header_and_message_keys)); return 0; //TODO: Should this really be 0? } } else { //new message chain if (state->ratchet_flag || (header_decryptable != NEXT_DECRYPTABLE) || !valid) { //if ratchet_flag or not Dec(NHKr, header) //clear purported message and header keys header_and_message_keystore_clear(&(state->purported_header_and_message_keys)); return 0; //TODO: Should this really be 0? } //otherwise, received message was valid //accept purported values //RK = RKp memcpy(state->root_key, state->purported_root_key, crypto_secretbox_KEYBYTES); //HKr = HKp memcpy(state->receive_header_key, state->purported_receive_header_key, sizeof(state->receive_header_key)); //NHKr = NHKp memcpy(state->next_receive_header_key, state->purported_next_receive_header_key, sizeof(state->next_receive_header_key)); //DHRr = DHRp memcpy(state->their_public_ephemeral, state->their_purported_public_ephemeral, crypto_box_PUBLICKEYBYTES); //erase(DHRs) sodium_memzero(state->our_private_ephemeral, crypto_box_SECRETKEYBYTES); //ratchet_flag = True state->ratchet_flag = true; } status = commit_skipped_header_and_message_keys(state); if (status != 0) { return status; } //Nr = Np + 1 state->receive_message_number = state->purported_message_number + 1; //CKr = CKp memcpy(state->receive_chain_key, state->purported_receive_chain_key, crypto_secretbox_KEYBYTES); return 0; }
uint24_option lo_value (uint8_t const universe_bits, uint24_option const value) { if (is_none(value)) return none(); uint8_t lo_bits = universe_bits >> 1; uint32_t bit_mask = (1 << lo_bits) - 1; return some(bit_mask & value); }
// Convert the given method into a delegation indirection to the specified // field. static void make_delegation(ast_t* method, ast_t* field, ast_t* delegate_ref, ast_t* body_donor) { assert(method != NULL); assert(field != NULL); assert(delegate_ref != NULL); // Make a redirection method body. ast_t* args = ast_from(delegate_ref, TK_NONE); ast_t* last_arg = NULL; AST_GET_CHILDREN(method, cap, id, t_params, params, result, error, old_body); for(ast_t* p = ast_child(params); p != NULL; p = ast_sibling(p)) { const char* param_name = ast_name(ast_child(p)); BUILD(arg, delegate_ref, NODE(TK_SEQ, NODE(TK_CONSUME, NONE NODE(TK_REFERENCE, ID(param_name))))); ast_list_append(args, &last_arg, arg); ast_setid(args, TK_POSITIONALARGS); } BUILD(body, delegate_ref, NODE(TK_SEQ, NODE(TK_CALL, TREE(args) // Positional args. NODE(TK_NONE) // Named args. NODE(TK_DOT, // Receiver. NODE(TK_REFERENCE, ID(ast_name(ast_child(field)))) ID(ast_name(ast_childidx(method, 1))))))); if(is_none(result)) { // Add None to end of body. Whilst the call generated above will return // None anyway in this case, without this extra None testing is very hard // since a directly written version of this body will have the None. BUILD(none, delegate_ref, NODE(TK_REFERENCE, ID("None"))); ast_append(body, none); } ast_replace(&old_body, body); // Setup method info. method_t* info = (method_t*)ast_data(method); assert(info != NULL); info->body_donor = body_donor; info->delegated_field = field; }