int main(int argc, char *argv[]) { if(argc!=3 && argc!=4){ printf("Usage: ./shfs <mountpoint> <backing file> <flags> \n"); return 0; } int flag=(argc==4)?1:0; filename = malloc(strlen(argv[argc-1-flag])); strcpy(filename, argv[argc-1-flag]); root = init_parse(filename, backing_path); char *ptr = realpath(filename, backing_path); if(argc==4){ argv[argc-2] = argv[argc-1]; } argv[argc-1] = NULL; argc--; int f = fuse_main(argc, argv, &sh_oper, NULL); int d = sf_deparse(root, filename, 1); return f; }
void read_blif(char* blif_file, int lut_size) { char buffer[BUFSIZE]; int pass, done, doall; blif = my_fopen(blif_file, "r", 0); for (doall = 0; doall <= 1; doall++) { init_parse(doall); /* Three passes to ensure inputs are first blocks, outputs second and * * LUTs and latches third. Just makes the output netlist more readable. */ for (pass = 1; pass <= 3; pass++) { linenum = 0; /* Reset line number. */ done = 0; while ((my_fgets(buffer, BUFSIZE, blif) != NULL) && !done) { get_tok(buffer, pass, doall, &done, lut_size); } rewind(blif); /* Start at beginning of file again */ } } fclose(blif); check_net(lut_size); free_parse(); }
void exec_process(t_shell *sh, t_job *job, int *iofile) { t_parse *parse; parse = init_parse(sh, job->process->cmd); if (check_builtins(parse->argv[0])) { if (iofile[0] != 0) job->process->stdio[0] = iofile[0]; if (iofile[1] != 1) job->process->stdio[1] = iofile[1]; launch_builtin(sh, parse, job); } else if ((job->process->pid = fork()) == 0) { if (iofile[0] != 0) job->process->stdio[0] = iofile[0]; if (iofile[1] != 1) job->process->stdio[1] = iofile[1]; launch_bin(parse, job); } free_parse(&parse); if (iofile[0] != 0) close(iofile[0]); if (iofile[1] != 1) close(iofile[1]); }
int main(int argc, char **argv) { tintin_exec=argv[0]; init_locale(); user_setdriver(isatty(0)?1:0); parse_options(argc, argv); init_bind(); hist_num=-1; init_parse(); strcpy(status, EMPTY_LINE); user_init(); /* read_complete(); no tab-completion */ srand((getpid()*0x10001)^time0); lastdraft=0; if (ui_own_output || tty) { /* Legal crap does _not_ belong here. Anyone interested in the license can check the files accompanying KBtin, without any need of being spammed every time. It is not GNU bc or something similar, we don't want half a screenful of all-uppercase (cAPS kEY IS STUCK AGAIN?) text that no one ever wants to read -- that is what docs are for. */ tintin_printf(0, "~2~##########################################################"); tintin_printf(0, "#~7~ ~12~K B ~3~t i n~7~ v %-25s ~2~#", VERSION); tintin_printf(0, "# #"); tintin_printf(0, "#~7~ current developer: ~9~Adam Borowski ([email protected]~7~) ~2~#"); tintin_printf(0, "# #"); tintin_printf(0, "#~7~ based on ~12~tintin++~7~ v 2.1.9 by Peter Unold, Bill Reiss, ~2~#"); tintin_printf(0, "#~7~ David A. Wagner, Joann Ellsworth, Jeremy C. Jack, ~2~#"); tintin_printf(0, "#~7~ Ulan@GrimneMUD and Jakub Narębski ~2~#"); tintin_printf(0, "##########################################################~7~"); tintin_printf(0, "~15~#session <name> <host> <port> ~7~to connect to a remote server"); tintin_printf(0, " ~8~#ses t2t t2tmud.org 9999"); tintin_printf(0, "~15~#run <name> <command> ~7~to run a local command"); tintin_printf(0, " ~8~#run advent adventure"); tintin_printf(0, " ~8~#run sql mysql"); tintin_printf(0, "~15~#help ~7~to get the help index"); } user_mark_greeting(); setup_signals(); #ifdef PROFILING setup_prof(); #endif PROF("initializing"); setup_ulimit(); init_nullses(); PROF("other"); apply_options(); tintin(); return 0; }
int main (int argc, char **argv) { char eml_file[1024] = {0}; // ---------------- int ch; const char *args = "f:h"; while ((ch = getopt(argc, argv, args)) != -1) { switch (ch) { case 'f': snprintf(eml_file, sizeof(eml_file), "%s", optarg); break; case 'h': default: usage(argv[0]); break; } } if (*eml_file == '\0') { usage(argv[0]); } int ret = 0; struct parsed_message_info_s parsed_mail_info; init_parse(&parsed_mail_info); ret = parse_mail_for_file(eml_file, &parsed_mail_info); if (ret > 0) { fprintf(stderr, "parse email fail\n"); return 0; } printf("------------------------------------\n"); printf("from: [%d]%s\n", parsed_mail_info.header_from.len, parsed_mail_info.header_from.pdata); printf("to: [%d]%s\n", parsed_mail_info.header_to.len, parsed_mail_info.header_to.pdata); printf("cc: [%d]%s\n", parsed_mail_info.header_cc.len, parsed_mail_info.header_cc.pdata); printf("bcc: [%d]%s\n", parsed_mail_info.header_bcc.len, parsed_mail_info.header_bcc.pdata); printf("subject: [%d]%s\n", parsed_mail_info.header_subject.len, parsed_mail_info.header_subject.pdata); printf("\n"); printf("body: [%d]\n%s\n", parsed_mail_info.body.len, parsed_mail_info.body.pdata); printf("------------------------------------\n"); clean_parse(&parsed_mail_info); return 0; }
void init() { if (level_indent[0] == NULL) level_indent[0] = " "; /* 4 spaces */ if (level_indent[1] == NULL) level_indent[1] = level_indent[0]; if (level_end[0] == NULL) level_end[0] = ""; if (level_end[1] == NULL) level_end[1] = ""; init_lex(debug > 2); init_parse(); }
void read_blif(char *blif_file, boolean sweep_hanging_nets_and_inputs, t_model *user_models, t_model *library_models) { char buffer[BUFSIZE]; int pass, doall; boolean done; boolean add_truth_table; t_model *inpad_model, *outpad_model, *logic_model, *latch_model; blif = fopen(blif_file, "r"); if(blif == NULL) { printf("Failed to open blif file %s\n", blif_file); exit(1); } load_default_models(library_models, &inpad_model, &outpad_model, &logic_model, &latch_model); /* doall = 0 means do a counting pass, doall = 1 means allocate and load data structures */ for(doall = 0; doall <= 1; doall++) { init_parse(doall); /* Three passes to ensure inputs are first blocks, outputs second and * * LUTs and latches third, subckts last. Just makes the output netlist more readable. */ for(pass = 0; pass <= 4; pass++) { linenum = 0; /* Reset line number. */ done = FALSE; add_truth_table = FALSE; model_lines = 0; while(my_fgets(buffer, BUFSIZE, blif) != NULL) { get_tok(buffer, pass, doall, &done, &add_truth_table, inpad_model, outpad_model, logic_model, latch_model, user_models); } rewind(blif); /* Start at beginning of file again */ } } fclose(blif); check_net(sweep_hanging_nets_and_inputs); free_parse(); }
int main(int argc, char**argv) { printf("hi there\n"); char dir[] = "Grammar"; char dict_file[] = ""; char grammar_file[] = "EX.net"; char frames_file[] = ""; char priority_file[] = ""; char line[] = "I want to fly from new york to los angeles"; init_parse(dir, dict_file, grammar_file, frames_file, priority_file); printf("grammar ok"); parse(line, gram); return 0; }
void read_net (char *net_file, t_subblock_data *subblock_data_ptr) { /* Main routine that parses a netlist file in my (.net) format. */ char buf[BUFSIZE], *ptr; int doall; FILE *fp_net; /* Make two variables below accessible anywhere in the module because I'm * * too lazy to pass them all over the place. */ max_subblocks_per_block = subblock_data_ptr->max_subblocks_per_block; subblock_lut_size = subblock_data_ptr->subblock_lut_size; fp_net = my_fopen (net_file, "r", 0); /* First pass builds the symbol table and counts the number of pins * * on each net. Then I allocate exactly the right amount of storage * * for each net. Finally, the second pass loads the block and net * * arrays. */ for (doall=0;doall<=1;doall++) { /* Pass number. */ init_parse(doall); linenum = 0; /* Reset line number. */ ptr = my_fgets (buf, BUFSIZE, fp_net); while (ptr != NULL) { ptr = get_tok (buf, doall, fp_net); } rewind (fp_net); /* Start at beginning of file again */ } fclose(fp_net); /* Return the three data structures below through subblock_data_ptr. */ subblock_data_ptr->subblock_inf = subblock_inf; subblock_data_ptr->num_subblocks_per_block = num_subblocks_per_block; subblock_data_ptr->chunk_head_ptr = ch_subblock_head_ptr; check_netlist (subblock_data_ptr, num_driver); free_parse(); }
void *_GalSS_init_server(Gal_Server *s, int argc, char **argv) { char *config_file = NULL; if (GalUtil_OACheckUsage(argc, argv, oas, NULL) == 0) exit(1); GalUtil_OAExtract(argc, argv, oas, "-config", GAL_OA_STRING, &config_file); if (config_file == NULL){ printf("No config file specified... exiting\n"); exit(1); } /* set config file parms */ config(argc, argv); /* initialize parser, malloc space, etc */ init_parse(dir, dict_file, grammar_file, frames_file, priority_file); return (void *) NULL; }
void exec_env(t_shell *sh, char *arg, char **env_cpy) { t_parse *parse; t_job *job; parse = init_parse(sh, arg); job = NULL; if (check_builtins(parse->argv[0])) do_builtins(sh, job, parse); else if ((parse->pid = fork()) == 0) { if (execve(parse->right_path, parse->argv, env_cpy) < 0) { ft_putstr_fd("42sh: command not found: ", 2); ft_putendl_fd(parse->argv[0], 2); exit(127); } } wait(0); free_parse(&parse); }
/** * Loads the specified keymap file using convertStringToSymbol to convert strings to client constants. **/ void bx_keymap_c::loadKeymap(u32 stringToSymbol (const char*), const char *filename) { FILE* keymapFile; char baseSym[256]; char modSym[256]; char hostSym[256]; s32 ascii = 0; u32 baseKey; u32 modKey; u32 hostKey; if((keymapFile = fopen(filename, "r")) == NULL) { BX_PANIC(("Can not open keymap file '%s'.", filename)); return; } BX_INFO(("Loading keymap from '%s'", filename)); init_parse(); // Read keymap file one line at a time while(1) { if(get_next_keymap_line(keymapFile, baseSym, modSym, &ascii, hostSym) < 0) { break; } // convert X_KEY_* symbols to values baseKey = convertStringToBXKey(baseSym); modKey = convertStringToBXKey(modSym); hostKey = 0; if(stringToSymbol != NULL) hostKey = stringToSymbol(hostSym); BX_DEBUG(( "baseKey='%s' (%d), modSym='%s' (%d), ascii=%d, guisym='%s' (%d)", baseSym, baseKey, modSym, modKey, ascii, hostSym, hostKey)); // Check if data is valid if(baseKey == BX_KEYMAP_UNKNOWN) { BX_PANIC(("line %d: unknown BX_KEY constant '%s'", lineCount, baseSym)); continue; } if(hostKey == BX_KEYMAP_UNKNOWN) { BX_PANIC(( "line %d: unknown host key name '%s' (wrong keymap ?)", lineCount, hostSym)); continue; } CHECK_REALLOCATION(keymapTable, realloc(keymapTable, (keymapCount + 1) * sizeof(BXKeyEntry)), BXKeyEntry); if(keymapTable == NULL) BX_PANIC(("Can not allocate memory for keymap table.")); keymapTable[keymapCount].baseKey = baseKey; keymapTable[keymapCount].modKey = modKey; keymapTable[keymapCount].ascii = ascii; keymapTable[keymapCount].hostKey = hostKey; keymapCount++; } BX_INFO(("Loaded %d symbols", keymapCount)); fclose(keymapFile); }
int main(int argc, char *argv[]) { int run_as_daemon; int debug; pid_t pid = 0; FILE *file_out; struct sigaction sv; #if WITH_MALLOC_BOEHM_GC GC_find_leak = 1; GC_set_warn_proc(gc_warn_proc); GC_enable_incremental(); #endif run_as_daemon = 1; debug = 0; tools_init(); /* set up some signal handlers */ memset(&sv, 0, sizeof(sv)); sigemptyset(&sv.sa_mask); sv.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sv, NULL); sv.sa_handler = sigaction_rehash; sigaction(SIGHUP, &sv, NULL); sv.sa_handler = sigaction_writedb; sigaction(SIGINT, &sv, NULL); sv.sa_handler = sigaction_exit; sigaction(SIGQUIT, &sv, NULL); sv.sa_handler = sigaction_wait; sigaction(SIGCHLD, &sv, NULL); if (argc > 1) { /* parse command line, if any */ int c; struct option options[] = { {"config", 1, 0, 'c'}, {"debug", 0, 0, 'd'}, {"foreground", 0, 0, 'f'}, {"help", 0, 0, 'h'}, {"check", 0, 0, 'k'}, {"replay", 1, 0, 'r'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) { switch (c) { case 'c': services_config = optarg; break; case 'k': if (conf_read(services_config)) { printf("%s appears to be a valid configuration file.\n", services_config); } else { printf("%s is an invalid configuration file.\n", services_config); } exit(0); case 'r': replay_file = fopen(optarg, "r"); if (!replay_file) { fprintf(stderr, "Could not open %s for reading: %s (%d)\n", optarg, strerror(errno), errno); exit(0); } break; case 'd': debug = 1; break; case 'f': run_as_daemon = 0; break; case 'v': version(); license(); exit(0); case 'h': default: usage(argv[0]); exit(0); } } } version(); if (replay_file) { /* We read a line here to "prime" the replay file parser, but * mostly to get the right value of "now" for when we do the * irc_introduce. */ replay_read_line(); } else { now = time(NULL); } boot_time = now; fprintf(stdout, "Initializing daemon...\n"); if (!conf_read(services_config)) { fprintf(stderr, "Unable to read %s.\n", services_config); exit(1); } conf_register_reload(uplink_compile); if (run_as_daemon) { /* Attempt to fork into the background if daemon mode is on. */ pid = fork(); if (pid < 0) { fprintf(stderr, "Unable to fork: %s\n", strerror(errno)); } else if (pid > 0) { fprintf(stdout, "Forking into the background (pid: %d)...\n", pid); exit(0); } setsid(); } file_out = fopen(PID_FILE, "w"); if (file_out == NULL) { /* Create the main process' pid file */ fprintf(stderr, "Unable to create PID file: %s", strerror(errno)); } else { fprintf(file_out, "%i\n", (int)getpid()); fclose(file_out); } if (run_as_daemon) { /* Close these since we should not use them from now on. */ fclose(stdin); fclose(stdout); fclose(stderr); } services_argc = argc; services_argv = argv; atexit(call_exit_funcs); reg_exit_func(main_shutdown, NULL); log_init(); MAIN_LOG = log_register_type("x3", "file:main.log"); if (debug) log_debug(); ioset_init(); init_structs(); init_parse(); modcmd_init(); saxdb_init(); sar_init(); gline_init(); shun_init(); mail_init(); helpfile_init(); conf_globals(); /* initializes the core services */ conf_rlimits(); modules_init(); message_register_table(msgtab); modcmd_finalize(); saxdb_finalize(); helpfile_finalize(); modules_finalize(); /* The first exit func to be called *should* be saxdb_write_all(). */ reg_exit_func(saxdb_write_all, NULL); if (replay_file) { char *msg; log_module(MAIN_LOG, LOG_INFO, "Beginning replay..."); srand(now); replay_event_loop(); if ((msg = dict_sanity_check(clients))) { log_module(MAIN_LOG, LOG_ERROR, "Clients insanity: %s", msg); free(msg); } if ((msg = dict_sanity_check(channels))) { log_module(MAIN_LOG, LOG_ERROR, "Channels insanity: %s", msg); free(msg); } if ((msg = dict_sanity_check(servers))) { log_module(MAIN_LOG, LOG_ERROR, "Servers insanity: %s", msg); free(msg); } } else { now = time(NULL); srand(now); ioset_run(); } return 0; }
int main(int argc,char **argv) { int i; for(i=1; i<argc; i++) { if(argv[i][0]=='-'&&argv[i][1]=='F') { output_format=argv[i]+2; argv[i][0]=0; } if(!strcmp("-quiet",argv[i])) { verbose=0; argv[i][0]=0; } } if(!init_output(output_format)) general_error(16,output_format); if(!init_main()) general_error(10,"main"); if(verbose) printf("%s\n%s\n%s\n%s\n",copyright,cpu_copyright,syntax_copyright,output_copyright); for(i=1; i<argc; i++) { if(argv[i][0]==0) continue; if(argv[i][0]!='-') { if(inname) general_error(11); inname=argv[i]; continue; } if(!strcmp("-o",argv[i])&&i<argc-1) { if(outname) general_error(28,'o'); outname=argv[++i]; continue; } if(!strcmp("-L",argv[i])&&i<argc-1) { if(listname) general_error(28,'L'); listname=argv[++i]; produce_listing=1; continue; } if(!strcmp("-Lnf",argv[i])) { listformfeed=0; continue; } if(!strcmp("-Lns",argv[i])) { listnosyms=1; continue; } if(!strncmp("-Ll",argv[i],3)) { sscanf(argv[i]+3,"%i",&listlinesperpage); continue; } if(!strncmp("-D",argv[i],2)) { char *def=NULL; expr *val; if(argv[i][2]) def=&argv[i][2]; else if (i<argc-1) def=argv[++i]; if(def) { char *s=def; if(ISIDSTART(*s)) { s++; while(ISIDCHAR(*s)) s++; def=cnvstr(def,s-def); if(*s=='=') { s++; val=parse_expr(&s); } else val=number_expr(1); if(*s) general_error(23,'D'); /* trailing garbage after option */ new_abs(def,val); myfree(def); continue; } } } if(!strncmp("-I",argv[i],2)) { char *path=NULL; if(argv[i][2]) path=&argv[i][2]; else if (i<argc-1) path=argv[++i]; if(path) { new_include_path(path); continue; } } if(!strcmp("-unnamed-sections",argv[i])) { unnamed_sections=1; continue; } if(!strcmp("-ignore-mult-inc",argv[i])) { ignore_multinc=1; continue; } if(!strcmp("-nocase",argv[i])) { nocase=1; continue; } if(!strcmp("-noesc",argv[i])) { esc_sequences=0; continue; } if(!strcmp("-nosym",argv[i])) { no_symbols=1; continue; } if(!strncmp("-nowarn=",argv[i],8)) { int wno; sscanf(argv[i]+8,"%i",&wno); disable_warning(wno); continue; } else if(!strcmp("-w",argv[i])) { no_warn=1; continue; } if(!strncmp("-maxerrors=",argv[i],11)) { sscanf(argv[i]+11,"%i",&max_errors); continue; } else if(!strcmp("-pic",argv[i])) { pic_check=1; continue; } if(cpu_args(argv[i])) continue; if(syntax_args(argv[i])) continue; if(output_args(argv[i])) continue; if (!strncmp("-x",argv[i],2)) { auto_import=0; continue; } general_error(14,argv[i]); } if(inname) { setfilename(inname); setdebugname(inname); include_source(inname); } else general_error(15); if(!init_parse()) general_error(10,"parse"); if(!init_syntax()) general_error(10,"syntax"); if(!init_cpu()) general_error(10,"cpu"); parse(); if(errors==0||produce_listing) resolve(); if(errors==0||produce_listing) assemble(); if(errors==0&&!auto_import) undef_syms(); if(!listname) listname="a.lst"; if(produce_listing) write_listing(listname); if(!outname) outname="a.out"; if(errors==0) { if(verbose) statistics(); outfile=fopen(outname,"wb"); if(!outfile) general_error(13,outname); write_object(outfile,first_section,first_symbol); } leave(); return 0; /* not reached */ }
int main(int argc, char *argv[]){ init_parse(); // Parses the commandline arguments parse_opts(argc, argv); // IE: ./server -cserver.cfg --name "My Server" // server config ReadServerCfg(cfg_file ? :"server.cfg"); // init sockets struct sockaddr_in newclient; unsigned char buffer[MAX_BUF]; int size; fd_set descriptor; //I don't know sock = create_socket(); bind_socket(&sock, INADDR_ANY, sv_hostport); // on termination atexit(&cleanup); signal(SIGABRT, &exit); signal(SIGTERM, &exit); signal(SIGINT, &exit); // initialize rest of stuff OnServerStart(); #ifndef _WIN32 // fps control const int inc = NS_PER_S / sv_fps; int frame = 0; int previous = 0; struct timespec current, next; clock_gettime(CLOCK_MONOTONIC, &next); #endif // timeval for select struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0; //main loop while (1) { #ifndef _WIN32 frame++; next.tv_nsec += inc; while (next.tv_nsec > NS_PER_S) { //happens exactly once a second next.tv_nsec -= NS_PER_S; next.tv_sec++; fpsnow = frame - previous; previous = frame; OnSecond(); } #endif OnFrame(); FD_ZERO(&descriptor); FD_SET(sock, &descriptor); select(sock + 1, &descriptor, NULL, NULL, &timeout); if (FD_ISSET(sock, &descriptor)){ size = udp_receive(sock, buffer, MAX_BUF, &newclient); if (size < 3) { perror("Invalid packet! (size < 3)\n"); } else { stream *packet = init_stream(NULL); Stream.write(packet, buffer+2, size-2); // There's a chance that the guy left before all of the packet has been processed. while(1){ int id = IsPlayerKnown(newclient.sin_addr, newclient.sin_port); if (id){ if (ValidatePacket(buffer,id)){ PacketConfirmation(buffer,id); //If the numbering is even, send a confirmation player[id].lastpacket = mtime(); int pid = Stream.read_byte(packet); known_handler h = known_table[pid]; if (!h){ printf("Unhandled packet originating from %s (id:%d)\n", player[id].name, id); //stream *lolbuf = init_stream(NULL); //Stream.write(lolbuf, buffer, size); //unknown(lolbuf, pid); unknown(packet, pid); } else h(packet, id); } }else{ int pid = Stream.read_byte(packet); unknown_handler h = unknown_table[pid]; if (!h) unknown(packet, pid); else h(packet, &newclient); } if (EMPTY_STREAM(packet)){ free(packet); break; } } } } check_sendqueue(); #ifdef _WIN32 Sleep(1000 / sv_fps); //who cares about windows :D #else clock_gettime(CLOCK_MONOTONIC, ¤t); if (((current.tv_sec == next.tv_sec) && (current.tv_nsec < next.tv_nsec)) || (current.tv_sec < next.tv_sec)) { clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL); } else { next.tv_nsec = current.tv_nsec + (current.tv_sec - next.tv_sec) * NS_PER_S; } #endif } return EXIT_SUCCESS; }