void game_loop(t_env *e) { int before_check_die; before_check_die = 0; print_board(e); refresh(); while (e->nb_proc_in_life > 0 && e->nb_cycle < e->nb_cycle_max) { ++e->nb_cycle; if (before_check_die >= e->c_to_die) { check_champ_cycle(e); check_proc_cycle(e); before_check_die = 0; if (e->nb_proc_in_life == 0) return ; } ++before_check_die; if (e->verbose & VERBOSE_CYCLE) ft_printf("It is now cycle %d\n", e->nb_cycle); proc_loop(e); if (have_opt('c', e->opt)) ncurses_loop(e); } if (!have_opt('c', e->opt) && have_opt('d', e->opt)) print_memory(e->mem); }
int main (int argc, char* argv[]) { args_t args = { 0, }; crypt_data_t crypt_data = { 0, }; ssize_t count = 0; crypt_init_t init_func = NULL; crypt_update_t update_func = NULL; crypt_final_t final_func = NULL; parse_args (argc, argv, &args); if (check_sanity (argv[0], &args)) exit (EXIT_FAILURE); /* set global flag */ verbose = args.verbose; if (verbose) dump_args (&args); crypt_data.keysize = get_key (args.keyfile, crypt_data.keybuf, EVP_MAX_KEY_LENGTH); if (crypt_data.keysize == -1) exit (EXIT_FAILURE); crypt_data.ivsize = crypt_data.keysize; if (args.encrypt) { crypt_data.ivsize = iv_write (&crypt_data, STDOUT_FILENO); if (crypt_data.ivsize == -1) exit (EXIT_FAILURE); init_func = &EVP_EncryptInit_ex; update_func = &EVP_EncryptUpdate; final_func = &EVP_EncryptFinal_ex; } if (args.decrypt) { crypt_data.ivsize = iv_read (&crypt_data, STDIN_FILENO); if (crypt_data.ivsize == -1) exit (EXIT_FAILURE); init_func = &EVP_DecryptInit_ex; update_func = &EVP_DecryptUpdate; final_func = &EVP_DecryptFinal_ex; } count = aes_init (&crypt_data, init_func); if (count == -1) exit (EXIT_FAILURE); count = proc_loop (&crypt_data, update_func, final_func); if (count == -1) exit (EXIT_FAILURE); if (verbose) fprintf (stderr, "successfully %s %d bytes of data\n", args.encrypt ? "encrypted" : "decrypted", count); exit (EXIT_SUCCESS); }
/* . . \`-"'"-'/ } 6 6 { =. Y ,= (""-'***`-"") ------ Main ------ `-/ \-' ( )-( )===' "" "" */ int main(int argc, char **argv) { /* Initialize the XPRP process */ if (xpr_init(argc,argv) == FAILURE) { log_and_exit(XPRMOD, (char *)"Process %s, server %s: Unable to initalize, exiting ...", arb_get_process_id(), Server_id); if(ModLog) {delete ModLog; ModLog = NULL;} if(ModConn) {delete ModConn; ModConn = NULL;} module_std_terminate(NULL); return 0; } proc_loop(); ModLog->batchLog(XPRMOD, XPR_END_MSG, arb_get_current_state()); proc_wrap_up(); fflush(stdout); fflush(stderr); return 0; }
int main(int argc, char *argv[]) { int rc = 0; /* Setup syslog logging */ openlog(MODULE_NAME, LOG_PID, LOG_LOCAL5); /* already a daemon */ if (getppid() == 1) { return 0; } /* command line parsing... */ config_def(); log_info("Starting\n"); config_set(argc, argv); /* Daemonize */ if (0 == daemon_cfg.opt.mode) { daemonize(); } /* Change the file mode mask */ umask(0); /* Set name of the process */ #if HAVE_SYS_PRCTL_H if (prctl(PR_SET_NAME, MODULE_NAME, NULL, NULL, NULL) < 0) { log_error("cannot set process name to %s, errno=%d (%s)\n", MODULE_NAME, errno, strerror(errno)); goto err; } #endif /* Ensure only one copy */ if (daemon_cfg.lock_file[0]) { char str[10]; daemon_cfg.lock_fd = open(daemon_cfg.lock_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP); if (daemon_cfg.lock_fd < 0) { log_error("could not open PID lock file %s, errno=%d (%s)\n", daemon_cfg.lock_file, errno, strerror(errno)); goto err; } if (lockf(daemon_cfg.lock_fd, F_TLOCK, 0) < 0) { log_error("could not lock PID lock file %s, errno=%d (%s)\n", daemon_cfg.lock_file, errno, strerror(errno)); goto err; } /* Write pid to lockfile */ sprintf(str,"%d\n", getpid()); if (write(daemon_cfg.lock_fd, str, strlen(str)) < 0) { log_error("could not write to PID lock file %s, errno=%d (%s)\n", daemon_cfg.lock_file, errno, strerror(errno)); goto err; } } /* Main loop */ rc = proc_loop(); /* Finish up */ close(daemon_cfg.lock_fd); unlink(daemon_cfg.lock_file); log_info("Terminated with code %d\n", rc); closelog(); return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS); err: return EXIT_FAILURE; }
/**************************************************************************** * Program entry point. */ int main (int argc, char **argv) { int i, j, len, samp; FILE *ifd = stdin; char ch, cmdline[SZ_CMD], method[SZ_CMD]; char arg1[SZ_CMD], arg2[SZ_CMD], arg3[SZ_CMD], arg4[SZ_CMD]; /* Process commandline arguments. */ memset (cmdline, 0, SZ_CMD); for (i=1; i < argc; i++) { if (argv[i][0] == '-' && !(isdigit(argv[i][1]))) { len = strlen (argv[i]); for (j=1; j < len; j++) { ch = argv[i][j]; switch (ch) { case 'c': if ((ifd = fopen (argv[++i], "r")) == (FILE *) NULL) { fprintf (stderr, "Error opening '%s'\n", argv[i]); exit (1); } break; case 'D': debug++; break; case 'g': generics++; break; case 'd': descr = argv[++i]; break; case 'n': name = argv[++i]; break; case 's': interactive++; break; case 'v': verbose++; break; default: fprintf (stderr, "Unknown option '%c'\n", ch); break; } j = len; /* skip remainder */ } } else { if (access (argv[i], F_OK) == 0) { if (! (ifd = fopen (argv[i], "r"))) { /* argument is a file */ fprintf (stderr, "Error opening '%s'\n", argv[i]); exit (1); } } else { strcat (cmdline, argv[i]); strcat (cmdline, " "); } break; } } /* Initialize the SAMP interface. */ samp = sampInit (name, descr); /* Set up some local metadata values. */ samp_Metadata (samp, "samp.description.html", "<none/>"); samp_Metadata (samp, "samp.icon.url", "http://iraf.noao.edu/icon.png"); samp_Metadata (samp, "samp.documentation.url", ""); samp_Metadata (samp, "author.email", "Will E Coyote"); samp_Metadata (samp, "author.name", "*****@*****.**"); /* Subscribe to various message types, we also install the local * message handlers defined above. */ samp_Subscribe (samp, "samp.app.ping", ping_handler); samp_Subscribe (samp, "samp.app.status", status_handler); samp_Subscribe (samp, "image.load.fits", imload_handler); if (generics) samp_Subscribe (samp, "table.load.*", tblload_handler); samp_Subscribe (samp, "table.load.fits", tblFITS_handler); samp_Subscribe (samp, "table.load.votable", tblVOT_handler); samp_Subscribe (samp, "table.highlight.row", tbrow_handler); samp_Subscribe (samp, "table.select.rowList", tbsel_handler); samp_Subscribe (samp, "coord.pointAt.sky", pointat_handler); samp_Subscribe (samp, "client.cmd.exec", cmdExec_handler); samp_Subscribe (samp, "client.env.set", envSet_handler); samp_Subscribe (samp, "client.env.get", envGet_handler); samp_Subscribe (samp, "client.param.set", paramSet_handler); samp_Subscribe (samp, "client.param.get", paramGet_handler); samp_Subscribe (samp, "bibcode.load", bibcode_handler); /* samp_Subscribe (samp, "spectrum.load.*", NULL); samp_Subscribe (samp, "voresource.loadlist.*", NULL); samp_Subscribe (samp, "samp.app.event.*", NULL); samp_Subscribe (samp, "*", generic_handler); */ samp_Subscribe (samp, "samp.hub.event.*", hub_handler); sampStartup (samp); /* Process the commands. */ if (cmdline[0] == 0) { proc_loop (ifd, samp); } else { nscan = sscanf (cmdline, "%s %s %s %s %s", method, arg1, arg2, arg3, arg4); proc_cmd (samp, method, arg1, arg2, arg3, arg4); } /* Clean up. */ if (registered && samp_UnRegister (samp) != OK) fprintf (stderr, "UnRegistration fails\n"); return (0); }
int main(int argc, char*argv[]) { /* The Sample format to use */ static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, .channels = proc_size_out }; LOG("channels = %d\n", ss.channels); pa_simple *s = NULL; int ret = 1; int error; #if defined(proc_param_samplerate) && 0 == proc_param_samplerate LOG("samplerate = %d\n", ss.rate); param.samplerate = ss.rate; #endif #if defined(proc_param_timestep) && 0 == proc_param_timestep param.timestep = 1 / (float)ss.rate; LOG("timestep = %f\n", param.timestep); #endif /* Output buffers. FIXME: a_in: currently no inputs supported. */ int nframes = 1024; // does this matter? for (int i=0; i < ss.channels; i++) a_out[i] = calloc(nframes, sizeof(float)); uint16_t buf[nframes * ss.channels]; /* Create a new playback stream */ if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, "pa_simple_new() failed: %d\n", error); goto exit; } /* Start reader */ pthread_t thread; pthread_create(&thread, NULL, thread_main, NULL); unsigned int stamp = 0; for(;;) { // FIXME: exit? proc_loop((void*)&state, &in, ¶m, &out, &store, nframes); for (int i=0; i<nframes; i++) { for(int c=0; c<ss.channels; c++) { buf[i*ss.channels+c] = ((float)0x7FFF) * a_out[c][i]; } } if (pa_simple_write(s, buf, (size_t) sizeof(buf), &error) < 0) goto exit; // for live coding: exit when source file changed. if (argc >= 2) { struct stat s; stat(argv[1], &s); if (stamp && (stamp != s.st_mtime)) goto exit; stamp = s.st_mtime; } } exit: pa_simple_drain(s, &error); // ignore error if (s) pa_simple_free(s); return 0; }