static struct bitmask *numactl_parse_nodestring(char *s) { static char *last; if (s[0] == 's' && !strcmp(s, "same")) { if (!last) usage_msg("same needs previous node specification"); s = last; } else { last = s; } return numa_parse_nodestring(s); }
static void parse_cmdline( char **cmdline ) /*****************************************/ { char msgbuf[80]; int level = 0; if( cmdline == NULL || *cmdline == NULL || **cmdline == 0 ) { usage_msg(); } for( ;*cmdline != NULL; ++cmdline ) { ProcOptions( *cmdline, &level ); } if( AsmFiles.fname[ASM] == NULL ) { MsgGet( NO_FILENAME_SPECIFIED, msgbuf ); Fatal( MSG_CANNOT_OPEN_FILE, msgbuf ); } }
int main(int argc, char* argv[]) { int c; while( (c = getopt(argc, argv, "hs:r:dp:")) != -1 ) switch( c ) { case 'h': usage_msg(stdout); exit(0); break; case 'd': cfg_delegated = 1; break; case 's': cfg_tx_size = atoi(optarg); break; case 'r': cfg_rx_size = atoi(optarg); break; case 'p': cfg_port = optarg; break; case '?': usage_err(); break; default: TEST(0); break; } argc -= optind; argv += optind; if( argc != 2 ) usage_err(); const char* interface = argv[0]; const char* server = argv[1]; struct client_state* cs = calloc(1, sizeof(*cs)); init(cs, interface, server, cfg_port); pthread_t tid; TEST( pthread_create(&tid, NULL, alarm_thread, cs) == 0 ); ev_loop(cs); return 0; }
static void HelpUsage( void ) { usage_msg();}
int main(int argc, char* argv[]) { int c; while( (c = getopt(argc, argv, "hr:n:i:w:sl:p:")) != -1 ) switch( c ) { case 'h': usage_msg(stdout); exit(0); break; case 'r': cfg_send_rate = atoi(optarg); break; case 'n': cfg_measure_nth = atoi(optarg); break; case 'i': cfg_iter = atoi(optarg); break; case 'w': cfg_warm_n = atoi(optarg); break; case 's': cfg_hw_ts = false; break; case 'l': cfg_log_level = atoi(optarg); break; case 'p': cfg_port = optarg; break; case '?': usage_err(); break; default: TEST(0); break; } argc -= optind; argv += optind; if( argc != 1 ) usage_err(); const char* mcast_intf = argv[0]; if( onload_is_present() ) { if( cfg_hw_ts ) { TRY( onload_stack_opt_set_int("EF_RX_TIMESTAMPING", 3) ); TRY( onload_stack_opt_set_int("EF_TX_TIMESTAMPING", 3) ); } } else if( cfg_hw_ts ) { fprintf(stderr, "ERROR: Cannot use hardware timestamp because Onload is " "not being used. You can use -s to use software timestamps, but " "they are much less accurate.\n"); exit(4); } else { msg(1, "Using software timestamps\n"); cfg_hw_ts = false; } struct server_state ss; init(&ss, mcast_intf); wait_for_client(&ss); event_loop(&ss); return 0; }
static void usage_err(void) { usage_msg(stderr); exit(1); }
static void process_opts (int argc, char* argv[], const char* shortopts, struct option longopts[], GEN_PAR* pg, IN_PAR* pi, OUT_PAR* po) { int c, i,j, longind; char *p, cdummy; while ((c=getopt_long(argc,argv, shortopts, longopts, &longind)) != EOF) switch (c) /* Easy addition of options ... */ { case 'a': pi->aspectfactor = atof (optarg); if (pi->aspectfactor <= 0.0) { Eprintf("Aspect factor: %g illegal\n", pi->aspectfactor); exit(ERROR); } break; case 'c': i = strlen(optarg); if ((i<1) || (i>8)) { Eprintf("Invalid pencolor string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { switch (*p-'0') { case xxBackground:pt.color[j] = xxBackground; break; case xxForeground:pt.color[j] = xxForeground; break; case xxRed: pt.color[j] = xxRed; break; case xxGreen: pt.color[j] = xxGreen; break; case xxBlue: pt.color[j] = xxBlue; break; case xxCyan: pt.color[j] = xxCyan; break; case xxMagenta: pt.color[j] = xxMagenta; break; case xxYellow: pt.color[j] = xxYellow; break; default : Eprintf( "Invalid color of pen %d: %c\n", j, *p); exit(ERROR); } if (pt.color[j] != xxBackground && pt.color[j] != xxForeground) pg->is_color = TRUE; } pi->hwcolor=TRUE; break; case 'C': pi->center_mode = TRUE; break; case 'd': switch (po->dpi_x = atoi (optarg)) { case 75: break; case 100: case 150: case 300: case 600: if ((!pg->quiet) && (strcmp(pg->mode,"pcl")==0) && po->specials == 0) Eprintf( "Warning: DPI setting is no PCL level 3 feature!\n"); break; default: if ((!pg->quiet) && (strcmp(pg->mode,"pcl")==0)) Eprintf( "Warning: DPI value %d is invalid for PCL mode\n", po->dpi_x); break; } break; case 'D': po->dpi_y = atoi (optarg); if ((!pg->quiet) && strcmp(pg->mode,"pcl")==0 && po->specials==0) Eprintf("Warning: %s\n", "Different DPI for x & y is invalid for PCL mode"); break; case 'F': po->formfeed = TRUE; break; case 'f': po->outfile = optarg; break; case 'h': pi->height = atof (optarg); if (pi->height < 0.1) Eprintf("Warning: Small height: %g mm\n", pi->height); if (pi->height > 300.0) Eprintf("Warning: Huge height: %g mm\n", pi->height); break; case 'i': po->init_p = TRUE; break; case 'l': pg->logfile = optarg; if (freopen(pg->logfile, "w", stderr) == NULL) { PError ("Cannot open log file"); Eprintf("Error redirecting stderr\n"); Eprintf("Continuing with output to stderr\n"); } else Logfile_flag = TRUE; break; case 'm': pg->mode = optarg; for (i=0; ModeList[i].mode != XX_TERM; i++) if (strcmp(ModeList[i].modestr, pg->mode) == 0) break; if (ModeList[i].mode == XX_TERM) { Eprintf("'%s': unknown mode!\n", pg->mode); Eprintf("Supported are:\n\t"); print_supported_modes(); Send_Copyright(); } break; case 'n': pg->nofill = TRUE; break; case 'N': pg->no_ps = TRUE; break; case 'o': pi->xoff = atof (optarg); if (pi->xoff < 0.0) { Eprintf("Illegal X offset: %g < 0\n", pi->xoff); exit(ERROR); } if (pi->xoff > 210.0) /* About DIN A4 width */ { Eprintf("Illegal X offset: %g > 210\n", pi->xoff); exit(ERROR); } break; case 'O': pi->yoff = atof (optarg); if (pi->yoff < 0.0) { Eprintf("Illegal Y offset: %g < 0\n", pi->yoff); exit(ERROR); } if (pi->yoff > 300.0) /* About DIN A4 height */ { Eprintf("Illegal Y offset: %g > 300\n", pi->yoff); exit(ERROR); } break; case 'p': i = strlen(optarg); if ((i<1) || (i>8)) { Eprintf("Invalid pensize string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { if ((*p < '0') || (*p > '9')) { Eprintf("Invalid size of pen %d: %c\n", j, *p); exit(ERROR); } pt.width[j] = *p - '0'; if (pg->maxpensize < pt.width[j]) pg->maxpensize = pt.width[j]; } pi->hwsize=TRUE; break; case 'P': if (*optarg == ':') { pi->first_page = 0; optarg++; if (sscanf(optarg,"%d", &pi->last_page) != 1) pi->last_page = 0; } else switch (sscanf(optarg,"%d%c%d", &pi->first_page, &cdummy, &pi->last_page)) { case 1: pi->last_page = pi->first_page; break; case 2: if (cdummy == ':') { pi->last_page = 0; break; } /* not ':' Syntax error -- drop through */ case 3: if (cdummy == ':') break; /* not ':' Syntax error -- drop through */ default: Eprintf("Illegal page range.\n"); usage_msg (pg, pi, po); exit(ERROR); } break; case 'q': pg->quiet = TRUE; break; case 'r': pi->rotation = atof(optarg); break; case 'S': po->specials = atoi (optarg); break; case 's': pg->swapfile = optarg; break; case 't': pi->truesize = TRUE; break; case 'V': po->vga_mode = atoi (optarg); break; case 'w': pi->width = atof (optarg); if (pi->width < 0.1) Eprintf("Warning: Small width: %g mm\n", pi->width); if (pi->width > 300.0) Eprintf("Warning: Huge width: %g mm\n", pi->width); break; case 'v': Send_version(); exit (NOERROR); case 'x': pi->x0 = atof (optarg); break; case 'X': pi->x1 = atof (optarg); break; case 'y': pi->y0 = atof (optarg); break; case 'Y': pi->y1 = atof (optarg); break; case 'H': case '?': default: usage_msg (pg, pi, po); exit (ERROR); } }
int main(int argc, char *argv[]) { // Usage message if (argc < 3) { usage_msg(); return EXIT_FAILURE; } int mode; // mode of output char *a, *b; if (strcmp("components",argv[2]) == 0) { mode = MODE_COMPONENTS; } else if (strcmp("degrees",argv[2]) == 0) { mode = MODE_DEGREES; } else if (strcmp("path",argv[2]) == 0) { mode = MODE_PATH; } else if (strcmp("stats",argv[2]) == 0) { mode = MODE_STATS; } else if (strcmp("diameter",argv[2]) == 0) { mode = MODE_DIAMETER; } else { usage_msg(); } if (mode & MODE_PATH) { if (argc < 5 || strlen(argv[3]) < 3 || strlen(argv[4]) < 3) { fprintf(stderr, "Please specify two 3-letter words\nExample: 3words path bus car\n"); return EXIT_FAILURE; } a = argv[3]; b = argv[4]; if (a[0]<'a'||a[0]>'z'||a[1]<'a'||a[1]>'z'||a[2]<'a'||a[2]>'z'||b[0]<'a'||b[0]>'z'||b[1]<'a'||b[1]>'z'||b[2]<'a'||b[2]>'z') { fprintf(stderr, "Please only use lower case 3-letter words\nExample: 3words path bus car\n"); return EXIT_FAILURE; } } // Open file FILE *f_input = fopen(argv[1], "r"); if (!f_input) { fprintf(stderr, "File could not be opened: %s\n", argv[1]); return EXIT_FAILURE; } NODE nodes[LEN3]; init(nodes); // Read lines INT wordCount = readWords(nodes, f_input); fclose(f_input); // Init navigation structure on the nodes initNav(nodes, 0); initNav(nodes, 1); initNav(nodes, 2); INT componentCount = findComponents(nodes, mode & MODE_COMPONENTLIST); if (mode & MODE_COMPONENTSTAT) printf("%d components\n", componentCount - 1); calcDegrees(nodes, mode & MODE_DEGREESTAT, mode & MODE_DEGREELIST); if (mode & MODE_PATH) shortestPath(nodes, a[0]-'a',a[1]-'a',a[2]-'a',b[0]-'a',b[1]-'a',b[2]-'a', TRUE); if (mode & MODE_DIAMETER) diameter(fopen(argv[1], "r"), wordCount, nodes); }
void needshm(char *opt) { if (!shmattached) usage_msg("%s must be after shared memory specification", opt); }
void dontshm(char *opt) { if (shmoption) usage_msg("%s shm option is not allowed before %s", shmoption, opt); }
void noshm(char *opt) { if (shmattached) usage_msg("%s must be before shared memory specification", opt); shmoption = opt; }
void check_cpubind(int flag) { if (flag) usage_msg("cannot do --cpubind on shared memory\n"); }
void nopolicy(void) { if (set_policy >= 0) usage_msg("specify policy after --shm/--file"); }
void setpolicy(int pol) { if (set_policy != -1) usage_msg("Conflicting policies"); set_policy = pol; }
int main(int argc, char** argv) { gpio_device *dev; int num = -1, target_num = -1, delete_flag = 0, i = 0 ; char *file_prefix=NULL, *port=NULL, *filename, *srcnamebuffer, *dstnamebuffer; #if HAVE_GETOPT || HAVE_GETOPT_LONG int value, opt = 0, error_flag = 0; extern int opterr, optind; extern char* optarg; #if HAVE_GETOPT_LONG static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"delete", no_argument, 0, 'd'}, {"file-prefix", required_argument, 0, 'f'}, {"number", required_argument, 0, 'n'}, {"port",required_argument, 0, 'p'}, {0, 0, 0, 0} }; opterr = 0; while ((opt = getopt_long(argc, argv, "adf:n:p:", long_options, NULL)) != EOF) #elif HAVE_GETOPT opterr = 0; while ((opt = getopt(argc, argv, "adf:n:p:")) != EOF) #endif /* HAVE_GETOPT_LONG */ { switch (opt) { case 'a': if ( target_num == -1 ) { target_num = 0; } else { usage_msg(argv[0]); fprintf(stderr, "Cannot select both all images and specific images\n"); fflush(stderr); return 1; } break; case 'd': delete_flag = 1; break; case 'f': file_prefix = optarg; break; case 'n': if ( target_num == -1 ) { target_num = atoi(optarg); } else { usage_msg(argv[0]); fprintf(stderr, "Cannot select both all images and specific images\n"); fflush(stderr); return 1; } break; case 'p': port = optarg; break; case '?': default: error_flag++; break; } } #endif /* HAVE_GETOPT || HAVE_GETOPT_LONG */ #if DIMAGE_V_DEBUG debug=fopen("debug.log","w"); #endif if ( port == NULL ) { usage_msg(argv[0]); fprintf(stderr, "Must specify a value for port\n"); fflush(stderr); return 1; } if ( file_prefix == NULL ) { fprintf(stderr, "Using file as default file prefix\n"); fflush(stderr); if ( ( file_prefix = malloc(5) ) == NULL ) { perror("Unable to allocate file_prefix"); return 1; } snprintf(file_prefix, 5, "file"); } if ( strlen(port) >= 20 ) { fprintf(stderr, "Bad value for port, using /dev/dimagev\n"); fflush(stderr); snprintf(serial_port, 20, "/dev/dimagev"); } else { snprintf(serial_port, 20, port); } dev = dimage_v_open(serial_port); if ( dev == NULL ) { fprintf(stderr, "Got a null pointer back from dimage_v_open\n"); return 1; } num = dimage_v_number_of_pictures(); if ( num > 0 ) { printf("Number of pictures is %d\n", num); sleep(3); } if ( target_num == 0 ) { for ( i = 1 ; i <= num ; i++ ) { printf("Picture will be named %s%04d.jpg\n", file_prefix, i); filename = dimage_v_write_picture_to_file(i); printf("filename %d is %s\n", i, filename); if ( dstnamebuffer == NULL ) { perror("Error mallocing memory for name buffers"); gpio_close(dev); } /* There must be a better way to see if the camera is ready... */ sleep(3); } } else { /* Just get the specific image. */ printf("Picture will be named %s%04d.jpg\n", file_prefix, target_num); filename = dimage_v_write_picture_to_file(target_num); printf("filename %d is %s\n", target_num, filename); } gpio_close(dev); gpio_free(dev); return 0; }
int main(int argc, char* argv[]) { struct rtt_options opts; opts.ping_frame_len = 42; opts.pong_frame_len = 42; opts.n_warm_ups = 10000; opts.n_iters = 100000; opts.inter_iter_gap_ns = 0; int c; while( (c = getopt(argc, argv, "i:w:f:g:h")) != -1 ) switch( c ) { case 'i': opts.n_iters = atoi(optarg); break; case 'w': opts.n_warm_ups = atoi(optarg); break; case 'f': opts.ping_frame_len = atoi(optarg); opts.pong_frame_len = atoi(optarg); break; case 'g': opts.inter_iter_gap_ns = atoi(optarg); break; case 'h': usage_msg(stdout); exit(0); break; case '?': usage_err(); default: RTT_TEST( 0 ); } argc -= optind; argv += optind; if( argc < 2 || argc > 3 ) usage_err(); const char* action = argv[0]; const char* tx_ep_spec = argv[1]; const char* rx_ep_spec = (argc >= 3) ? argv[2] : NULL; struct rtt_endpoint* tx_ep; if( spec_to_endpoint(&tx_ep, &opts, RTT_DIR_TX | ((rx_ep_spec) ? 0 : RTT_DIR_RX), tx_ep_spec) < 0 ) return 2; struct rtt_endpoint* rx_ep; if( rx_ep_spec != NULL ) { if( spec_to_endpoint(&rx_ep, &opts, RTT_DIR_RX, rx_ep_spec) < 0 ) return 3; } else { rx_ep = tx_ep; } if( ! strcmp(action, "ping") ) do_pinger(&opts, tx_ep, rx_ep); else if( ! strcmp(action, "pong") ) do_ponger(&opts, tx_ep, rx_ep); else usage_err(); do_cleanup(tx_ep, rx_ep); return 0; }
static __attribute__ ((__noreturn__)) void usage_err(void) { usage_msg(stderr); exit(1); }
int main(int ac, char **av) { int c, i, nnodes=0; long node=-1; char *end; char shortopts[array_len(opts)*2 + 1]; struct bitmask *mask = NULL; get_short_opts(opts,shortopts); while ((c = getopt_long(ac, av, shortopts, opts, NULL)) != -1) { switch (c) { case 's': /* --show */ show(); exit(0); case 'H': /* --hardware */ nopolicy(); hardware(); exit(0); case 'i': /* --interleave */ checknuma(); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; setpolicy(MPOL_INTERLEAVE); if (shmfd >= 0) numa_interleave_memory(shmptr, shmlen, mask); else numa_set_interleave_mask(mask); checkerror("setting interleave mask"); break; case 'N': /* --cpunodebind */ case 'c': /* --cpubind */ dontshm("-c/--cpubind/--cpunodebind"); checknuma(); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; check_cpubind(do_shm); did_cpubind = 1; numa_run_on_node_mask(mask); checkerror("sched_setaffinity"); break; case 'C': /* --physcpubind */ { struct bitmask *cpubuf; dontshm("-C/--physcpubind"); cpubuf = numa_parse_cpustring(optarg); if (!cpubuf) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; check_cpubind(do_shm); did_cpubind = 1; numa_sched_setaffinity(0, cpubuf); checkerror("sched_setaffinity"); free(cpubuf); break; } case 'm': /* --membind */ checknuma(); setpolicy(MPOL_BIND); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; numa_set_bind_policy(1); if (shmfd >= 0) { numa_tonodemask_memory(shmptr, shmlen, mask); } else { numa_set_membind(mask); } numa_set_bind_policy(0); checkerror("setting membind"); break; case 'p': /* --preferred */ checknuma(); setpolicy(MPOL_PREFERRED); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } for (i=0; i<mask->size; i++) { if (numa_bitmask_isbitset(mask, i)) { node = i; nnodes++; } } if (nnodes != 1) usage(); numa_bitmask_free(mask); errno = 0; numa_set_bind_policy(0); if (shmfd >= 0) numa_tonode_memory(shmptr, shmlen, node); else numa_set_preferred(node); checkerror("setting preferred node"); break; case 'l': /* --local */ checknuma(); setpolicy(MPOL_DEFAULT); errno = 0; if (shmfd >= 0) numa_setlocal_memory(shmptr, shmlen); else numa_set_localalloc(); checkerror("local allocation"); break; case 'S': /* --shm */ check_cpubind(did_cpubind); nopolicy(); attach_sysvshm(optarg, "--shm"); shmattached = 1; break; case 'f': /* --file */ check_cpubind(did_cpubind); nopolicy(); attach_shared(optarg, "--file"); shmattached = 1; break; case 'L': /* --length */ noshm("--length"); shmlen = memsize(optarg); break; case 'M': /* --shmmode */ noshm("--shmmode"); shmmode = strtoul(optarg, &end, 8); if (end == optarg || *end) usage(); break; case 'd': /* --dump */ if (shmfd < 0) complain( "Cannot do --dump without shared memory.\n"); dump_shm(); do_dump = 1; break; case 'D': /* --dump-nodes */ if (shmfd < 0) complain( "Cannot do --dump-nodes without shared memory.\n"); dump_shm_nodes(); do_dump = 1; break; case 't': /* --strict */ did_strict = 1; numa_set_strict(1); break; case 'I': /* --shmid */ shmid = strtoul(optarg, &end, 0); if (end == optarg || *end) usage(); break; case 'u': /* --huge */ noshm("--huge"); shmflags |= SHM_HUGETLB; break; case 'o': /* --offset */ noshm("--offset"); shmoffset = memsize(optarg); break; case 'T': /* --touch */ needshm("--touch"); check_shmbeyond("--touch"); numa_police_memory(shmptr, shmlen); break; case 'V': /* --verify */ needshm("--verify"); if (set_policy < 0) complain("Need a policy first to verify"); check_shmbeyond("--verify"); numa_police_memory(shmptr, shmlen); if (!mask) complain("Need a mask to verify"); else verify_shm(set_policy, mask); break; default: usage(); } } av += optind; ac -= optind; if (shmfd >= 0) { if (*av) usage(); exit(exitcode); } if (did_strict) fprintf(stderr, "numactl: warning. Strict flag for process ignored.\n"); if (do_dump) usage_msg("cannot do --dump|--dump-shm for process"); if (shmoption) usage_msg("shm related option %s for process", shmoption); if (*av == NULL) usage(); execvp(*av, av); complain("execution of `%s': %s\n", av[0], strerror(errno)); return 0; /* not reached */ }
int main(int argc, char **argv) { char *line = NULL; size_t len = 0; ssize_t read = 0; bool flush_at_end = false; int n = 0; while (n >= 0) { n = getopt_long(argc, argv, "hfV", options, NULL); if (n < 0) continue; switch (n) { case 'f': flush_at_end = true; break; case 'V': fprintf(stdout, "%s\n\n%s\n", version_string, authors); exit(EXIT_SUCCESS); case 'h': usage_msg(stdout); exit(EXIT_SUCCESS); case '?': usage_msg(stderr); exit(EXIT_FAILURE); } } struct sigaction new_action; memset(&new_action, 0, sizeof(new_action)); new_action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &new_action, 0); if(optind == argc - 1) { long s = 0; char *end = NULL; s = strtol(argv[optind], &end, 10); if(end && *end == 0) { buffer_count = s; } } if(buffer_count < 0) { usage_msg(stderr); exit(EXIT_FAILURE); } else if(buffer_count == 0) { // Don't buffer anything, just write each line as it appears while((read = getline(&line, &len, stdin)) != -1) { buffer_write(line, len); } exit(EXIT_SUCCESS); } buffers.resize(buffer_count); while((read = getline(&line, &len, stdin)) != -1) { char *prev = buffers[next_buffer].data; size_t prev_length = buffers[next_buffer].length; size_t prev_buffer_length = buffers[next_buffer].buffer_length; if(prev) { buffer_write(prev, prev_length); } buffers[next_buffer].data = line; buffers[next_buffer].length = read; buffers[next_buffer].buffer_length = len; //re-use spent buffers line = prev; len = prev_buffer_length; advance_buffer(); } if(flush_at_end) { for(size_t i = 0; i < buffers.size(); i++) { if(buffers[next_buffer].data) { buffer_write(buffers[next_buffer].data, buffers[next_buffer].length); } advance_buffer(); } } exit(EXIT_SUCCESS); }
void main (int argc, char *argv[]) { PAR par; double width, height; int c, i,j, longind; char *p; FILE *hd; char *shortopts = "a:c:d:D:f:h:l:m:o:O:p:P:r:s:S:V:w:x:X:y:Y:FHiqt"; struct option longopts[] = { {"mode", 1, NULL, 'm'}, {"pencolors", 1, NULL, 'c'}, {"pensizes", 1, NULL, 'p'}, {"pages", 1, NULL, 'P'}, {"quiet", 0, NULL, 'q'}, {"DPI", 1, NULL, 'd'}, {"DPI_x", 1, NULL, 'd'}, {"DPI_y", 1, NULL, 'D'}, {"PCL_formfeed",0, NULL, 'F'}, {"PCL_init", 0, NULL, 'i'}, {"PCL_Deskjet", 1, NULL, 'S'}, {"outfile", 1, NULL, 'f'}, {"logfile", 1, NULL, 'l'}, {"swapfile", 1, NULL, 's'}, {"aspectfactor",1, NULL, 'a'}, {"height", 1, NULL, 'h'}, {"width", 1, NULL, 'w'}, {"truesize", 0, NULL, 't'}, {"x0", 1, NULL, 'x'}, {"x1", 1, NULL, 'X'}, {"y0", 1, NULL, 'y'}, {"y1", 1, NULL, 'Y'}, {"xoffset", 1, NULL, 'o'}, {"yoffset", 1, NULL, 'O'}, #ifdef DOS {"VGAmodebyte",1, NULL, 'V'}, #endif {"help", 0, NULL, 'H'} }; preset_par (&par); width = par.width; /* Copy defaults */ height= par.height; if (argc == 1) { usage_msg (&par); exit (0); } while ((c=getopt_long(argc,argv, shortopts, longopts, &longind)) != EOF) switch (c) /* Easy addition of options ... */ { case 'a': par.aspectfactor = atof (optarg); if (par.aspectfactor <= 0.0) { fprintf(stderr,"Aspect factor: %g illegal\n", par.aspectfactor); exit(ERROR); } break; case 'c': i = strlen(optarg); if ((i<1) || (i>8)) { fprintf(stderr,"Invalid pencolor string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { switch (*p-'0') { case xxBackground:par.pencolor[j] = xxBackground; break; case xxForeground:par.pencolor[j] = xxForeground; break; case xxRed: par.pencolor[j] = xxRed; break; case xxGreen: par.pencolor[j] = xxGreen; break; case xxBlue: par.pencolor[j] = xxBlue; break; case xxCyan: par.pencolor[j] = xxCyan; break; case xxMagenta: par.pencolor[j] = xxMagenta; break; case xxYellow: par.pencolor[j] = xxYellow; break; default : fprintf(stderr, "Invalid color of pen %d: %c\n", j, *p); exit(ERROR); } if (par.pencolor[j] != xxBackground && par.pencolor[j] != xxForeground) par.is_color = TRUE; } break; case 'd': switch (par.dpi_x = atoi (optarg)) { case 75: break; case 100: case 150: case 300: if ((!par.quiet) && (strcmp(par.mode,"pcl")==0)) fprintf(stderr, "Warning: DPI setting is no PCL level 3 feature!\n"); break; default: if ((!par.quiet) && (strcmp(par.mode,"pcl")==0)) fprintf(stderr, "Warning: DPI value %d is invalid for PCL mode\n", par.dpi_x); break; } break; case 'D': par.dpi_y = atoi (optarg); if ((!par.quiet) && (strcmp(par.mode,"pcl")==0)) fprintf(stderr,"Warning: %s\n", "Different DPI for x & y is invalid for PCL mode"); break; case 'F': par.formfeed = TRUE; break; case 'f': par.outfile = optarg; break; case 'h': par.height = height = atof (optarg); if (height < 0.1) fprintf(stderr, "Warning: Small height: %g mm\n", height); if (height > 300.0) fprintf(stderr, "Warning: Huge height: %g mm\n", height); break; case 'i': par.init_p = TRUE; break; case 'l': par.logfile = optarg; if (freopen(par.logfile, "w", stderr) == NULL) { perror ("Cannot open log file"); fprintf(stderr, "Error redirecting stderr\n"); fprintf(stderr, "Continuing with output to stderr\n"); } else Logfile_flag = TRUE; break; case 'm': par.mode = optarg; for (i=0; ModeList[i].mode != XX_TERM; i++) if (strcmp(ModeList[i].modestr, par.mode) == 0) break; if (ModeList[i].mode == XX_TERM) { fprintf(stderr, "'%s': unknown mode!\n", par.mode); fprintf(stderr,"Supported are: "); print_supported_modes(); Send_Copyright(); } break; case 'o': par.xoff = atof (optarg); if (par.xoff < 0.0) { fprintf(stderr,"Illegal X offset: %g < 0\n", par.xoff); exit(ERROR); } if (par.xoff > 210.0) /* About DIN A4 width */ { fprintf(stderr,"Illegal X offset: %g > 210\n", par.xoff); exit(ERROR); } break; case 'O': par.yoff = atof (optarg); if (par.yoff < 0.0) { fprintf(stderr,"Illegal Y offset: %g < 0\n", par.yoff); exit(ERROR); } if (par.yoff > 300.0) /* About DIN A4 height */ { fprintf(stderr,"Illegal Y offset: %g > 300\n", par.yoff); exit(ERROR); } break; case 'p': i = strlen(optarg); if ((i<1) || (i>8)) { fprintf(stderr,"Invalid pensize string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { if ((*p < '0') || (*p > '9')) { fprintf(stderr,"Invalid size of pen %d: %c\n", j, *p); exit(ERROR); } par.pensize[j] = *p - '0'; if (par.maxpensize < par.pensize[j]) par.maxpensize = par.pensize[j]; } break; case 'P': if (*optarg == ':') { par.first_page = 0; optarg++; if (sscanf(optarg,"%d", &par.last_page) != 1) par.last_page = 0; } else switch (sscanf(optarg,"%d%*c%d", &par.first_page, &par.last_page)) { case 1: par.last_page = 0; break; case 2: break; default: fprintf(stderr,"Illegal page range.\n"); usage_msg (&par); exit(ERROR); } break; case 'q': par.quiet = TRUE; break; case 'r': par.rotation = atof(optarg); break; case 'S': par.specials = atoi (optarg); break; case 's': par.swapfile = optarg; break; case 't': par.truesize = TRUE; break; case 'V': par.vga_mode = atoi (optarg); break; case 'w': par.width = width = atof (optarg); if (width < 0.1) fprintf(stderr, "Warning: Small width: %g mm\n", width); if (width > 300.0) fprintf(stderr, "Warning: Huge width: %g mm\n", width); break; case 'x': par.x0 = atof (optarg); break; case 'X': par.x1 = atof (optarg); break; case 'y': par.y0 = atof (optarg); break; case 'Y': par.y1 = atof (optarg); break; case 'H': case '?': default: usage_msg (&par); exit (ERROR); } /** ** Place consistency checks here ** - I'm just not in the mood for writing them myself ... **/ if (par.dpi_y == 0) par.dpi_y = par.dpi_x; if (optind == argc) /* No filename: use stdin */ { autoset_outfile_name (&par, argv[optind]); action (&par, stdin); } else for ( ; optind < argc; optind++) { /* Multiple-input file handling: */ autoset_outfile_name (&par, argv[optind]); if ((hd=fopen (argv[optind], READ_BIN)) == NULL) { perror("hp2xx"); exit (ERROR); } action (&par, hd); /* action() closes file */ reset_par (&par); par.width = width; /* Restore width/height */ par.height= height; /* Changed in hpgl.c ! */ } if (*par.logfile) fclose (stderr); exit (0); }
int main (int argc, char *argv[]) { GEN_PAR Pg; IN_PAR Pi; OUT_PAR Po; int i; char *shortopts = "a:c:d:D:f:h:l:m:o:O:p:P:r:s:S:V:w:x:X:y:Y:CFHinqtvN"; struct option longopts[] = { {"mode", 1, NULL, 'm'}, {"pencolors", 1, NULL, 'c'}, {"pensizes", 1, NULL, 'p'}, {"pages", 1, NULL, 'P'}, {"quiet", 0, NULL, 'q'}, {"nofill", 0, NULL, 'n'}, {"no_ps", 0, NULL, 'N'}, {"DPI", 1, NULL, 'd'}, {"DPI_x", 1, NULL, 'd'}, {"DPI_y", 1, NULL, 'D'}, {"PCL_formfeed",0, NULL, 'F'}, {"PCL_init", 0, NULL, 'i'}, {"PCL_Deskjet", 1, NULL, 'S'}, {"outfile", 1, NULL, 'f'}, {"logfile", 1, NULL, 'l'}, {"swapfile", 1, NULL, 's'}, {"aspectfactor",1, NULL, 'a'}, {"height", 1, NULL, 'h'}, {"width", 1, NULL, 'w'}, {"truesize", 0, NULL, 't'}, {"x0", 1, NULL, 'x'}, {"x1", 1, NULL, 'X'}, {"y0", 1, NULL, 'y'}, {"y1", 1, NULL, 'Y'}, {"xoffset", 1, NULL, 'o'}, {"yoffset", 1, NULL, 'O'}, {"center", 0, NULL, 'C'}, #ifdef DOS {"VGAmodebyte", 1, NULL, 'V'}, #endif {"help", 0, NULL, 'H'}, {"version", 0, NULL, 'v'}, {NULL, 0, NULL, '\0'} }; preset_par (&Pg, &Pi, &Po); if (argc == 1) { usage_msg (&Pg, &Pi, &Po); exit (ERROR); } #ifdef WIN32 /* set stdin and stdout to binary mode: */ _setmode( _fileno(stdin), _O_BINARY ); _setmode( _fileno(stdout), _O_BINARY ); #endif /* WIN32 */ process_opts (argc, argv, shortopts, longopts, &Pg, &Pi, &Po); /** ** Determine internal mode code **/ for (i=0; ModeList[i].mode != XX_TERM; i++) /* if (strncmp(Pg.mode, ModeList[i].modestr, strlen(ModeList[i].modestr)) == 0)*/ if (strcmp(Pg.mode, ModeList[i].modestr)==0) { Pg.xx_mode = ModeList[i].mode; break; } /** ** Place consistency checks & adjustments here if you like **/ if (Po.dpi_y == 0) Po.dpi_y = Po.dpi_x; /** ** Action loop over all input files **/ if (optind == argc) /* No filename: use stdin */ { Pi.in_file = "-"; autoset_outfile_name (Pg.mode, Pi.in_file, &Po.outfile); action_oldstyle (&Pg, &Pi, &Po); } else for ( ; optind < argc; optind++) { /* Multiple-input file handling: */ Pi.in_file = argv[optind]; autoset_outfile_name (Pg.mode, Pi.in_file, &Po.outfile); action_oldstyle (&Pg, &Pi, &Po); reset_par (&Pi); } cleanup (&Pg, &Pi, &Po); if (*Pg.logfile) fclose (stderr); return NOERROR; }
int main(int argc, char **argv) #endif { int haltAfterwards = 0; /* If true, put 's erlang halt' at the end * of the arguments. */ int isdistributed = 0; int no_epmd = 0; int i; char* s; char *epmd_prog = NULL; char *malloc_lib; int process_args = 1; int print_args_exit = 0; int print_qouted_cmd_exit = 0; erts_cpu_info_t *cpuinfo = NULL; #ifdef __WIN32__ this_module_handle = module; run_werl = windowed; /* if we started this erl just to get a detached emulator, * the arguments are already prepared for beam, so we skip * directly to start_emulator */ s = get_env("ERL_CONSOLE_MODE"); if (s != NULL && strcmp(s, "detached")==0) { free_env_val(s); s = get_env("ERL_EMULATOR_DLL"); if (s != NULL) { argv[0] = strsave(s); } else { argv[0] = strsave(EMULATOR_EXECUTABLE); } ensure_EargsSz(argc + 1); memcpy((void *) Eargsp, (void *) argv, argc * sizeof(char *)); Eargsp[argc] = NULL; emu = argv[0]; start_emulator_program = strsave(argv[0]); goto skip_arg_massage; } free_env_val(s); #else int reset_cerl_detached = 0; s = get_env("CERL_DETACHED_PROG"); if (s && strcmp(s, "") != 0) { emu = s; start_detached = 1; reset_cerl_detached = 1; ensure_EargsSz(argc + 1); memcpy((void *) Eargsp, (void *) argv, argc * sizeof(char *)); Eargsp[argc] = emu; Eargsp[argc] = NULL; goto skip_arg_massage; } free_env_val(s); #endif initial_argv_massage(&argc, &argv); /* Merge with env; expand -args_file */ i = 1; #ifdef __WIN32__ /* Not used? /rickard */ if ((argc > 2) && (strcmp(argv[i], "-regkey") == 0)) { key_val_name = strsave(argv[i+1]); i = 3; } #endif get_parameters(argc, argv); /* * Construct the path of the executable. */ cpuinfo = erts_cpu_info_create(); /* '-smp auto' is default */ #ifdef ERTS_HAVE_SMP_EMU if (erts_get_cpu_configured(cpuinfo) > 1) emu_type |= EMU_TYPE_SMP; #endif #if defined(__WIN32__) && defined(WIN32_ALWAYS_DEBUG) emu_type_passed |= EMU_TYPE_DEBUG; emu_type |= EMU_TYPE_DEBUG; #endif /* We need to do this before the ordinary processing. */ malloc_lib = get_env("ERL_MALLOC_LIB"); while (i < argc) { if (argv[i][0] == '+') { if (argv[i][1] == 'M' && argv[i][2] == 'Y' && argv[i][3] == 'm') { if (argv[i][4] == '\0') { if (++i < argc) malloc_lib = argv[i]; else usage("+MYm"); } else malloc_lib = &argv[i][4]; } } else if (argv[i][0] == '-') { if (strcmp(argv[i], "-smp") == 0) { if (i + 1 >= argc) goto smp; if (strcmp(argv[i+1], "auto") == 0) { i++; smp_auto: emu_type_passed |= EMU_TYPE_SMP; #ifdef ERTS_HAVE_SMP_EMU if (erts_get_cpu_configured(cpuinfo) > 1) emu_type |= EMU_TYPE_SMP; else #endif emu_type &= ~EMU_TYPE_SMP; } else if (strcmp(argv[i+1], "enable") == 0) { i++; smp_enable: emu_type_passed |= EMU_TYPE_SMP; #ifdef ERTS_HAVE_SMP_EMU emu_type |= EMU_TYPE_SMP; #else usage_notsup("-smp enable"); #endif } else if (strcmp(argv[i+1], "disable") == 0) { i++; smp_disable: emu_type_passed |= EMU_TYPE_SMP; emu_type &= ~EMU_TYPE_SMP; } else { smp: emu_type_passed |= EMU_TYPE_SMP; #ifdef ERTS_HAVE_SMP_EMU emu_type |= EMU_TYPE_SMP; #else usage_notsup("-smp"); #endif } } else if (strcmp(argv[i], "-smpenable") == 0) { goto smp_enable; } else if (strcmp(argv[i], "-smpauto") == 0) { goto smp_auto; } else if (strcmp(argv[i], "-smpdisable") == 0) { goto smp_disable; #ifdef __WIN32__ } else if (strcmp(argv[i], "-debug") == 0) { emu_type_passed |= EMU_TYPE_DEBUG; emu_type |= EMU_TYPE_DEBUG; #endif } else if (strcmp(argv[i], "-hybrid") == 0) { emu_type_passed |= EMU_TYPE_HYBRID; #ifdef ERTS_HAVE_HYBRID_EMU emu_type |= EMU_TYPE_HYBRID; #else usage_notsup("-hybrid"); #endif } else if (strcmp(argv[i], "-extra") == 0) { break; } } i++; } erts_cpu_info_destroy(cpuinfo); cpuinfo = NULL; if ((emu_type & EMU_TYPE_HYBRID) && (emu_type & EMU_TYPE_SMP)) { /* * We have a conflict. Only using explicitly passed arguments * may solve it... */ emu_type &= emu_type_passed; if ((emu_type & EMU_TYPE_HYBRID) && (emu_type & EMU_TYPE_SMP)) { usage_msg("Hybrid heap emulator with SMP support selected. The " "combination hybrid heap and SMP support is currently " "not supported."); } } if (malloc_lib) { if (strcmp(malloc_lib, "libc") != 0) usage("+MYm"); } emu = add_extra_suffixes(emu, emu_type); sprintf(tmpStr, "%s" DIRSEP "%s" BINARY_EXT, bindir, emu); emu = strsave(tmpStr); add_Eargs(emu); /* Will be argv[0] -- necessary! */ /* * Add the bindir to the path (unless it is there already). */ s = get_env("PATH"); if (!s) { sprintf(tmpStr, "%s" PATHSEP "%s" DIRSEP "bin", bindir, rootdir); } else if (strstr(s, bindir) == NULL) { sprintf(tmpStr, "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP "%s", bindir, rootdir, s); } else { sprintf(tmpStr, "%s", s); } free_env_val(s); set_env("PATH", tmpStr); i = 1; #ifdef __WIN32__ #define ADD_BOOT_CONFIG \ if (boot_script) \ add_args("-boot", boot_script, NULL); \ if (config_script) \ add_args("-config", config_script, NULL); #else #define ADD_BOOT_CONFIG #endif get_home(); add_args("-home", home, NULL); add_epmd_port(); add_arg("--"); while (i < argc) { if (!process_args) { /* Copy arguments after '-extra' */ add_arg(argv[i]); i++; } else { switch (argv[i][0]) { case '-': switch (argv[i][1]) { #ifdef __WIN32__ case 'b': if (strcmp(argv[i], "-boot") == 0) { if (boot_script) error("Conflicting -start_erl and -boot options"); if (i+1 >= argc) usage("-boot"); boot_script = strsave(argv[i+1]); i++; } else { add_arg(argv[i]); } break; #endif case 'c': if (strcmp(argv[i], "-compile") == 0) { /* * Note that the shell script erl.exec does an recursive call * on itself here. We'll avoid doing that. */ add_args("-noshell", "-noinput", "-s", "c", "lc_batch", NULL); add_Eargs("-B"); haltAfterwards = 0; } #ifdef __WIN32__ else if (strcmp(argv[i], "-config") == 0){ if (config_script) error("Conflicting -start_erl and -config options"); if (i+1 >= argc) usage("-config"); config_script = strsave(argv[i+1]); i++; } #endif else { add_arg(argv[i]); } break; case 'd': if (strcmp(argv[i], "-detached") != 0) { add_arg(argv[i]); } else { start_detached = 1; add_args("-noshell", "-noinput", NULL); } break; case 'i': if (strcmp(argv[i], "-instr") == 0) { add_Eargs("-Mim"); add_Eargs("true"); } else add_arg(argv[i]); break; case 'e': if (strcmp(argv[i], "-extra") == 0) { process_args = 0; ADD_BOOT_CONFIG; add_arg(argv[i]); } else if (strcmp(argv[i], "-emu_args") == 0) { /* -emu_args */ verbose = 1; } else if (strcmp(argv[i], "-emu_args_exit") == 0) { print_args_exit = 1; } else if (strcmp(argv[i], "-emu_qouted_cmd_exit") == 0) { print_qouted_cmd_exit = 1; } else if (strcmp(argv[i], "-env") == 0) { /* -env VARNAME VARVALUE */ if (i+2 >= argc) usage("-env"); set_env(argv[i+1], argv[i+2]); i += 2; } else if (strcmp(argv[i], "-epmd") == 0) { if (i+1 >= argc) usage("-epmd"); epmd_prog = argv[i+1]; ++i; } else { add_arg(argv[i]); } break; case 'k': if (strcmp(argv[i], "-keep_window") == 0) { keep_window = 1; } else add_arg(argv[i]); break; case 'm': /* * Note that the shell script erl.exec does an recursive call * on itself here. We'll avoid doing that. */ if (strcmp(argv[i], "-make") == 0) { add_args("-noshell", "-noinput", "-s", "make", "all", NULL); add_Eargs("-B"); haltAfterwards = 1; i = argc; /* Skip rest of command line */ } else if (strcmp(argv[i], "-man") == 0) { #if defined(__WIN32__) error("-man not supported on Windows"); #else argv[i] = "man"; sprintf(tmpStr, "%s/man", rootdir); set_env("MANPATH", tmpStr); execvp("man", argv+i); error("Could not execute the 'man' command."); #endif } else add_arg(argv[i]); break; case 'n': if (strcmp(argv[i], "-name") == 0) { /* -name NAME */ if (i+1 >= argc) usage("-name"); /* * Note: Cannot use add_args() here, due to non-defined * evaluation order. */ add_arg(argv[i]); add_arg(argv[i+1]); isdistributed = 1; i++; } else if (strcmp(argv[i], "-noinput") == 0) { add_args("-noshell", "-noinput", NULL); } else if (strcmp(argv[i], "-nohup") == 0) { add_arg("-nohup"); nohup = 1; } else if (strcmp(argv[i], "-no_epmd") == 0) { add_arg("-no_epmd"); no_epmd = 1; } else { add_arg(argv[i]); } break; case 's': /* -sname NAME */ if (strcmp(argv[i], "-sname") == 0) { if (i+1 >= argc) usage("-sname"); add_arg(argv[i]); add_arg(argv[i+1]); isdistributed = 1; i++; } #ifdef __WIN32__ else if (strcmp(argv[i], "-service_event") == 0) { add_arg(argv[i]); add_arg(argv[i+1]); i++; } else if (strcmp(argv[i], "-start_erl") == 0) { if (i+1 < argc && argv[i+1][0] != '-') { get_start_erl_data(argv[i+1]); i++; } else get_start_erl_data((char *) NULL); } #endif else add_arg(argv[i]); break; case 'v': /* -version */ if (strcmp(argv[i], "-version") == 0) { add_Eargs("-V"); } else { add_arg(argv[i]); } break; default: add_arg(argv[i]); break; } /* switch(argv[i][1] */ break; case '+': switch (argv[i][1]) { case '#': case 'a': case 'A': case 'b': case 'h': case 'i': case 'P': case 'S': case 'T': case 'R': case 'W': case 'K': if (argv[i][2] != '\0') goto the_default; if (i+1 >= argc) usage(argv[i]); argv[i][0] = '-'; add_Eargs(argv[i]); add_Eargs(argv[i+1]); i++; break; case 'B': argv[i][0] = '-'; if (argv[i][2] != '\0') { if ((argv[i][2] != 'i') && (argv[i][2] != 'c') && (argv[i][2] != 'd')) { usage(argv[i]); } else { add_Eargs(argv[i]); break; } } if (i+1 < argc) { if ((argv[i+1][0] != '-') && (argv[i+1][0] != '+')) { if (argv[i+1][0] == 'i') { add_Eargs(argv[i]); add_Eargs(argv[i+1]); i++; break; } else { usage(argv[i]); } } } add_Eargs(argv[i]); break; case 'M': { int x; for (x = 0; plusM_au_allocs[x]; x++) if (plusM_au_allocs[x] == argv[i][2]) break; if ((plusM_au_allocs[x] && is_one_of_strings(&argv[i][3], plusM_au_alloc_switches)) || is_one_of_strings(&argv[i][2], plusM_other_switches)) { if (i+1 >= argc || argv[i+1][0] == '-' || argv[i+1][0] == '+') usage(argv[i]); argv[i][0] = '-'; add_Eargs(argv[i]); add_Eargs(argv[i+1]); i++; } else goto the_default; break; } case 's': if (!is_one_of_strings(&argv[i][2], pluss_val_switches)) goto the_default; else { if (i+1 >= argc || argv[i+1][0] == '-' || argv[i+1][0] == '+') usage(argv[i]); argv[i][0] = '-'; add_Eargs(argv[i]); add_Eargs(argv[i+1]); i++; } break; default: the_default: argv[i][0] = '-'; /* Change +option to -option. */ add_Eargs(argv[i]); } break; default: add_arg(argv[i]); } /* switch(argv[i][0] */ i++; } } if (process_args) { ADD_BOOT_CONFIG; } #undef ADD_BOOT_CONFIG /* Doesn't conflict with -extra, since -make skips all the rest of the arguments. */ if (haltAfterwards) { add_args("-s", "erlang", "halt", NULL); } if (isdistributed && !no_epmd) start_epmd(epmd_prog); #if (! defined(__WIN32__)) && defined(DEBUG) if (start_detached) { /* Start the emulator within an xterm. * Move up all arguments and insert * "xterm -e " first. * The path must be searched for this * to work, i.e execvp() must be used. */ ensure_EargsSz(EargsCnt+2); for (i = EargsCnt; i > 0; i--) Eargsp[i+1] = Eargsp[i-1]; /* Two args to insert */ EargsCnt += 2; /* Two args to insert */ Eargsp[0] = emu = "xterm"; Eargsp[1] = "-e"; } #endif add_Eargs("--"); add_Eargs("-root"); add_Eargs(rootdir); add_Eargs("-progname"); add_Eargs(progname); add_Eargs("--"); ensure_EargsSz(EargsCnt + argsCnt + 1); for (i = 0; i < argsCnt; i++) Eargsp[EargsCnt++] = argsp[i]; Eargsp[EargsCnt] = NULL; if (print_qouted_cmd_exit) { printf("\"%s\" ", emu); for (i = 1; i < EargsCnt; i++) printf("\"%s\" ", Eargsp[i]); printf("\n"); exit(0); } if (print_args_exit) { for (i = 1; i < EargsCnt; i++) printf("%s ", Eargsp[i]); printf("\n"); exit(0); } if (verbose) { printf("Executing: %s", emu); for (i = 0; i < EargsCnt; i++) printf(" %s", Eargsp[i]); printf("\n\n"); } #ifdef __WIN32__ if (EargsSz != EargsCnt + 1) Eargsp = (char **) erealloc((void *) Eargsp, (EargsCnt + 1) * sizeof(char *)); efree((void *) argsp); skip_arg_massage: /*DebugBreak();*/ if (run_werl) { if (start_detached) { char *p; /* transform werl to erl */ p = start_emulator_program+strlen(start_emulator_program); while (--p >= start_emulator_program && *p != '/' && *p != '\\' && *p != 'W' && *p != 'w') ; if (p >= start_emulator_program && (*p == 'W' || *p == 'w') && (p[1] == 'E' || p[1] == 'e') && (p[2] == 'R' || p[2] == 'r') && (p[3] == 'L' || p[3] == 'l')) { memmove(p,p+1,strlen(p)); } } return start_win_emulator(emu, start_emulator_program, Eargsp, start_detached); } else { return start_emulator(emu, start_emulator_program, Eargsp, start_detached); } #else skip_arg_massage: if (start_detached) { int status = fork(); if (status != 0) /* Parent */ return 0; if (reset_cerl_detached) putenv("CERL_DETACHED_PROG="); /* Detach from controlling terminal */ #ifdef HAVE_SETSID setsid(); #elif defined(TIOCNOTTY) { int fd = open("/dev/tty", O_RDWR); if (fd >= 0) { ioctl(fd, TIOCNOTTY, NULL); close(fd); } } #endif status = fork(); if (status != 0) /* Parent */ return 0; /* * Grandchild. */ close(0); open("/dev/null", O_RDONLY); close(1); open("/dev/null", O_WRONLY); close(2); open("/dev/null", O_WRONLY); #ifdef DEBUG execvp(emu, Eargsp); /* "xterm ..." needs to search the path */ #endif } #ifdef DEBUG else #endif { execv(emu, Eargsp); } error("Error %d executing \'%s\'.", errno, emu); return 1; #endif }