void GarbledCct3::com_init(const vector<Bytes> &ot_keys, const Bytes &gen_inp_mask, const Bytes &seed) { gen_init(ot_keys, gen_inp_mask, seed); m_bufr.reserve(CIRCUIT_HASH_BUFFER_SIZE); m_bufr.clear(); m_hash.init(); }
INT cd_gen(INT cmd, EQUIPMENT * pequipment) { INT status; switch (cmd) { case CMD_INIT: status = gen_init(pequipment); break; case CMD_START: status = gen_start(pequipment); break; case CMD_STOP: status = gen_stop(pequipment); break; case CMD_EXIT: status = gen_exit(pequipment); break; case CMD_IDLE: status = gen_idle(pequipment); break; default: cm_msg(MERROR, "Generic class driver", "Received unknown command %d", cmd); status = FE_ERR_DRIVER; break; } return status; }
/** Generates the GUI class * */ void PyGuiWriter::generate(const vector<symbol::Argument *> &args) { indent() << "class GUI:\n"; indent_inc(); gen_init(args); gen_update(); gen_delete(); gen_destroy(); gen_save_methods(); gen_menu_callbacks(); gen_main(); gen_create_methods(); }
static void system_init(bool overseas, bool PAL, bool overseas_reported, bool PAL_reported) { gen_running = 1; z80_init(); z80_readbyte = MD_Z80_ReadByte; z80_writebyte = MD_Z80_WriteByte; z80_readport = MD_Z80_ReadPort; z80_writeport = MD_Z80_WritePort; gen_init(); MDIO_Init(overseas, PAL, overseas_reported, PAL_reported); MainVDP.SetSettings(PAL, PAL_reported, MDFN_GetSettingB("md.correct_aspect")); #ifdef WANT_DEBUGGER MDDBG_Init(); #endif }
int CSP_EXTERNAL csp_parse(uint8_t *prog_buffer, int prog_size) { char lex_buf[CSP_LEX_BUFSIZE]; struct csp_names global, functions, local; struct ragel_lexer_t lex; int res; _csp_clear_error(); gen_init(prog_buffer, prog_size); scanner_init(&lex, lex_buf, CSP_LEX_BUFSIZE); global.idx = 0; global.tail = 0; global.size = CSP_NS_GLOBAL_NAMES_SIZE; global.buf = alloca(global.size); global.buf[0] = 0; functions.idx = env_functions->idx + MACRO_OP_BUILTIN_COUNT; functions.tail = env_functions->tail; functions.size = functions.tail + CSP_NS_FUNCTIONS_NAMES_SIZE; functions.buf = alloca(functions.size); memcpy(functions.buf, env_functions->buf, functions.tail+1); /* copy '\0' char too */ local.idx = 0; local.tail = 0; local.size = CSP_NS_LOCAL_NAMES_SIZE; local.buf = alloca(local.size); local.buf[0] = 0; gen_set_namespaces(&global, &functions, &local); res = yyparse(&lex); if (res == 0) program_finish(); return res; }
// copy constructor gen_sudoku::gen_sudoku(const gen_sudoku& gs) : sudoku(gs){ gen_init(gs.ggrid); }
// constructor from file gen_sudoku::gen_sudoku(const char* filename) : sudoku(filename, false){ gen_init(); read_from_file(filename); }
// constructor gen_sudoku::gen_sudoku(const uint digits) : sudoku(digits){ gen_init(); gen_init(); }
int main(int argc, char *argv[]) { const char *tmpdir; size_t tdlen; (void) setlocale(LC_ALL, ""); listf = stderr; /* * Keep a reference to cwd, so we can always come back home. */ cwdfd = open(".", O_RDONLY | O_CLOEXEC); if (cwdfd < 0) { syswarn(0, errno, "Can't open current working directory."); return(exit_val); } /* * Where should we put temporary files? */ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; tdlen = strlen(tmpdir); while (tdlen > 0 && tmpdir[tdlen - 1] == '/') tdlen--; tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE)); if (tempfile == NULL) { paxwarn(1, "Cannot allocate memory for temp file name."); return(exit_val); } if (tdlen) memcpy(tempfile, tmpdir, tdlen); tempbase = tempfile + tdlen; *tempbase++ = '/'; /* * parse options, determine operational mode, general init */ options(argc, argv); if ((gen_init() < 0) || (tty_init() < 0)) return(exit_val); /* * select a primary operation mode */ switch (act) { case EXTRACT: extract(); break; case ARCHIVE: archive(); break; case APPND: if (gzip_program != NULL) err(1, "can not gzip while appending"); append(); break; case COPY: copy(); break; default: case LIST: list(); break; } return(exit_val); }
int main(int argc, char **argv) { char *tmpdir; size_t tdlen; /* * Keep a reference to cwd, so we can always come back home. */ cwdfd = open(".", O_RDONLY | O_CLOEXEC); if (cwdfd < 0) { syswarn(1, errno, "Can't open current working directory."); return(exit_val); } /* * Where should we put temporary files? */ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; tdlen = strlen(tmpdir); while (tdlen > 0 && tmpdir[tdlen - 1] == '/') tdlen--; tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE)); if (tempfile == NULL) { paxwarn(1, "Cannot allocate memory for temp file name."); return(exit_val); } if (tdlen) memcpy(tempfile, tmpdir, tdlen); tempbase = tempfile + tdlen; *tempbase++ = '/'; /* * parse options, determine operational mode, general init */ options(argc, argv); if ((gen_init() < 0) || (tty_init() < 0)) return(exit_val); /* * pmode needs to restore setugid bits when extracting or copying, * so can't pledge at all then. */ if (pmode == 0 || (act != EXTRACT && act != COPY)) { if (pledge("stdio rpath wpath cpath fattr dpath getpw proc exec tape", NULL) == -1) err(1, "pledge"); /* Copy mode, or no gzip -- don't need to fork/exec. */ if (gzip_program == NULL || act == COPY) { if (pledge("stdio rpath wpath cpath fattr dpath getpw tape", NULL) == -1) err(1, "pledge"); } } /* * select a primary operation mode */ switch (act) { case EXTRACT: extract(); break; case ARCHIVE: archive(); break; case APPND: if (gzip_program != NULL) errx(1, "can not gzip while appending"); append(); break; case COPY: copy(); break; default: case LIST: list(); break; } return(exit_val); }
int main(int argc, char **argv) { const char *tmpdir; size_t tdlen; int rval; setprogname(argv[0]); listf = stderr; /* * parse options, determine operational mode */ options(argc, argv); /* * general init */ if ((gen_init() < 0) || (tty_init() < 0)) return exit_val; /* * Keep a reference to cwd, so we can always come back home. */ cwdfd = open(".", O_RDONLY); if (cwdfd < 0) { syswarn(1, errno, "Can't open current working directory."); return exit_val; } if (updatepath() == -1) return exit_val; /* * Where should we put temporary files? */ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; tdlen = strlen(tmpdir); while(tdlen > 0 && tmpdir[tdlen - 1] == '/') tdlen--; tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE)); if (tempfile == NULL) { tty_warn(1, "Cannot allocate memory for temp file name."); return exit_val; } if (tdlen) memcpy(tempfile, tmpdir, tdlen); tempbase = tempfile + tdlen; *tempbase++ = '/'; (void)time(&starttime); #ifdef SIGINFO (void)signal(SIGINFO, ar_summary); #endif /* * select a primary operation mode */ switch (act) { case EXTRACT: rval = extract(); break; case ARCHIVE: rval = archive(); break; case APPND: if (gzip_program != NULL) err(1, "cannot gzip while appending"); rval = append(); /* * Check if we tried to append on an empty file and * turned into ARCHIVE mode. */ if (act == -ARCHIVE) { act = ARCHIVE; rval = archive(); } break; case COPY: rval = copy(); break; default: case LIST: rval = list(); break; } if (rval != 0) exit_val = 1; return exit_val; }
void set_buf_mode (buffer * buf, char *reqname) { DIR *dir; char *pathpos, *nextcolon; void *handle = NULL; int found; if ((reqname) && (!strcmp (reqname, "genmode"))) { buf->mode.handle = NULL; buf->mode.init = gen_init; buf->mode.uninit = NULL; buf->mode.enter = NULL; buf->mode.leave = NULL; buf->mode.extkey = NULL; buf->mode.flashbrace = NULL; buf->mode.highlight = NULL; buf->mode.indent = NULL; gen_init (buf); return; } pathpos = getenv ("LPE_MODULE_PATH"); if (pathpos == NULL) pathpos = cfg_get_global_string_with_default ("module_path", DEF_MODULE_PATH); found = 0; do { char *name = NULL; struct dirent *ent; if (*pathpos == '~') { char *home = getenv ("HOME"); if (home == NULL) name = strdup("/"); else name = strdup(home); pathpos++; } else name = strdup(""); nextcolon = strchr (pathpos, ':'); if (nextcolon != NULL) { int len = (nextcolon - pathpos) + strlen(name) + 2 + 8; name = realloc(name, len); strncat (name, pathpos, nextcolon - pathpos); name[len-2-8] = '\0'; pathpos += (nextcolon - pathpos) + 1; } else { int len = strlen(pathpos) + strlen(name) + 2 + 8; name = realloc(name, len); strcat (name, pathpos); } if (name[strlen(name)-1] != '/') { int pos = strlen(name); name[pos++] = '/'; name[pos] = '\0'; } if (reqname != NULL) { struct stat st; name = realloc(name, strlen(name) + strlen(reqname) + 3 + 1); strcat (name, reqname); strcat (name, ".so"); stat (name, &st); if (S_ISREG (st.st_mode)) { handle = dlopen (name, RTLD_LAZY); if (handle != NULL) found = 1; } } else { dir = opendir (name); if (dir == NULL) continue; int basename_len = 0; int basename_off = strlen(name); char *basename = name + basename_off; while ((!found) && ((ent = readdir (dir)) != NULL)) { struct stat st; int (*accept) (buffer *); if (strlen(ent->d_name) > basename_len) { basename_len = strlen(ent->d_name); name = realloc(name, (basename-name) + basename_len + 1); basename = name + basename_off; } strcpy (basename, ent->d_name); stat (name, &st); if (!S_ISREG (st.st_mode)) continue; handle = dlopen (name, RTLD_LAZY); if (handle == NULL) continue; accept = (int (*)(buffer *)) dlsym (handle, "mode_accept"); if ((accept == NULL) || !(*accept) (buf)) { dlclose (handle); continue; } found = 1; } closedir (dir); } free(name); } while ((!found) && (nextcolon != NULL)); if (found) { buf->mode.handle = handle; buf->mode.data = NULL; buf->mode.init = (void (*)(buffer *)) dlsym (handle, "mode_init"); buf->mode.uninit = (void (*)(buffer *)) dlsym (handle, "mode_uninit"); buf->mode.enter = (void (*)(buffer *)) dlsym (handle, "mode_enter"); buf->mode.leave = (void (*)(buffer *)) dlsym (handle, "mode_leave"); buf->mode.extkey = (void (*)(buffer *, int)) dlsym (handle, "mode_extkey"); buf->mode.flashbrace = (int (*)(buffer *)) dlsym (handle, "mode_flashbrace"); buf->mode.highlight = (int (*)(buffer *, buf_line *, int, int *, int *)) dlsym (handle, "mode_highlight"); buf->mode.indent = (int (*)(buffer *, char)) dlsym (handle, "mode_indent"); } else { buf->mode.handle = NULL; buf->mode.data = NULL; buf->mode.init = gen_init; buf->mode.uninit = NULL; buf->mode.enter = NULL; buf->mode.leave = NULL; buf->mode.extkey = NULL; buf->mode.flashbrace = NULL; buf->mode.highlight = NULL; buf->mode.indent = NULL; } if (buf->mode.init != NULL) (*buf->mode.init) (buf); }
int main(void) { gen_init("hello"); gen_declare_var("name"); gen_declare_var("currentYear"); gen_function_prepare("main"); gen_function_begin(); gen_assign_string("name", "James Brown"); gen_assign_int("currentYear",2005); gen_prepare_call("display"); gen_add_param_int(555); gen_execute_call(); gen_function_end(); gen_function_prepare("display"); gen_function_begin(); gen_prepare_call("fatorial2"); gen_add_param_int(8); gen_execute_call(); gen_prepare_call("printf"); gen_add_param_generic("%eax"); gen_add_param_var("currentYear"); gen_add_param_var("name"); gen_add_param_mem(8); gen_add_param_char("[%d %s %d %d]"); gen_execute_call(); gen_function_end(); gen_function_prepare("fatorial"); // TODO: symbol table gen_function_add_param("param1"); gen_function_begin(); // if (param == 0) gen_if_prepare(); gen_exp_eval_var(8); gen_exp_eval_operator_eq(); gen_exp_eval_int(0); gen_if_condition_end(); gen_return_prepare(); gen_exp_eval_int(1); gen_return_execute(); // else fprintf(fpSaida, "_$else_%d:\n", i_if); // return param * fatorial(param-1) gen_prepare_call("fatorial"); fprintf(fpSaida, "\tsubl $1,%%esi\n"); gen_add_param_generic("%esi"); gen_execute_call(); fprintf(fpSaida, "\timull 8(%%ebp),%%eax\n"); gen_function_end(); gen_function_prepare("fatorial2"); // TODO: symbol table gen_function_add_param("param1"); gen_function_begin(); // int result = 1 // fprintf(fpSaida, "\tmovl $1,-4(%%ebp)\n"); gen_assignment_left_side(-4); gen_assignment_operator(); gen_exp_eval_int(1); gen_exp_eval_end(); // while (param1 > 1) { gen_while_prepare(); gen_exp_eval_var(8); gen_exp_eval_operator_gt(); gen_exp_eval_int(1); gen_boolexp_eval_end(); gen_while_condition_end(); // result := result * param1; gen_assignment_left_side(-4); gen_assignment_operator(); gen_exp_eval_var(-4); gen_exp_eval_operator_mul(); gen_exp_eval_var(8); gen_exp_eval_end(); // param1 = param1 - 1 gen_assignment_left_side(8); gen_assignment_operator(); gen_exp_eval_var(8); gen_exp_eval_operator_sub(); gen_exp_eval_int(1); gen_exp_eval_end(); gen_while_end(); gen_return_prepare(); gen_exp_eval_var(-4); gen_return_execute(); gen_function_end(); gen_end(); printf("Gerando codigo"); return 0; }
int main(int argc, char **argv) { const char *tmpdir; size_t tdlen; /* may not be a constant, thus initialising early */ listf = stderr; now = time(NULL); /* * Keep a reference to cwd, so we can always come back home. */ cwdfd = binopen2(BO_CLEXEC, ".", O_RDONLY); if (cwdfd < 0) { syswarn(1, errno, "Cannot open current working directory."); return(exit_val); } /* * Where should we put temporary files? */ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; tdlen = strlen(tmpdir); while (tdlen > 0 && tmpdir[tdlen - 1] == '/') tdlen--; tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE)); if (tempfile == NULL) { paxwarn(1, "%s for %s", "Out of memory", "temp file name"); return (exit_val); } if (tdlen) memcpy(tempfile, tmpdir, tdlen); tempbase = tempfile + tdlen; *tempbase++ = '/'; #if HAVE_SETPGENT /* * keep passwd and group files open for faster lookups. */ setpassent(1); setgroupent(1); #endif /* * parse options, determine operational mode, general init */ options(argc, argv); if ((gen_init() < 0) || (tty_init() < 0)) return(exit_val); #if HAVE_PLEDGE /* * pmode needs to restore setugid bits when extracting or copying, * so can't pledge at all then. */ if (pmode == 0 || (act != EXTRACT && act != COPY)) { if (pledge("stdio rpath wpath cpath fattr dpath getpw proc exec tape", NULL) == -1) err(1, "pledge"); /* Copy mode, or no gzip -- don't need to fork/exec. */ if (compress_program == NULL || act == COPY) { if (pledge("stdio rpath wpath cpath fattr dpath getpw tape", NULL) == -1) err(1, "pledge"); } } #endif /* make list fd independent and line-buffered */ if ((listfd = dup(fileno(listf))) < 0 || !(listf = fdopen(listfd, "wb"))) { syswarn(1, errno, "Cannot open list file descriptor"); return (exit_val); } if (fcntl(listfd, F_SETFD, FD_CLOEXEC) == -1) syswarn(0, errno, "%s on list file descriptor", "Failed to set the close-on-exec flag"); setlinebuf(listf); /* * select a primary operation mode */ switch (act) { case EXTRACT: extract(); break; case ARCHIVE: archive(); break; case APPND: if (compress_program != NULL) errx(1, "cannot compress while appending"); append(); break; case COPY: copy(); break; default: /* for ar_io.c etc. */ act = LIST; /* FALLTHROUGH */ case LIST: list(); break; } return(exit_val); }