/********************************************************************* * 文字列 *buf から、パラメータを読み取り、( adrs , memcnt ) を決める ********************************************************************* */ int get_arg(char *buf) { arena = AREA_RAM; if(*buf == 'p') { buf++; arena = AREA_PGMEM; }else if(*buf == 'r') { buf++; arena = AREA_EEPROM; } memcnt = 64; adrs2 = (-1); buf = sp_skip(buf); if(*buf==0) return 0; arg_cnt = split_str(buf,',',arg_ptr); scan_args(arg_cnt); if(arg_cnt>=1) { adrs = arg_hex[0]; } if(arg_cnt>=2) { adrs2 = arg_hex[1]; if(adrs2 != (-1) ) { memcnt = adrs2 - adrs + 1; } if( memcnt < 0) { memcnt = adrs2; } } return arg_cnt; }
void common_init (int argc,char** argv,char* version) { if (argc==2 && strcmp(argv[1],"--version")==0) { print("%s\n",version); exit(0); } { char* cwebinputs=getenv("CWEBINPUTS"); at_h_path[0].name=at_i_path.name=NULL; /* defaults */ #ifdef CWEBHEADERS at_h_path[0].name=CWEBHEADERS; at_h_path[0].length=(int)strlen(CWEBHEADERS); #endif if (cwebinputs!=NULL) { at_i_path.length=(int)strlen(cwebinputs); at_i_path.name=strcpy(byte_ptr,cwebinputs); byte_ptr+=at_i_path.length+1; } else { #ifdef CWEBINPUTS at_i_path.name=CWEBINPUTS; at_i_path.length=(int)strlen(CWEBINPUTS); #endif } } { int i=hash_size; do hash[--i]=NULL; while(i>0); } *byte_ptr++='\0'; mod_text[0]=' '; show_banner=show_happiness=show_progress=true; scan_args(argc,argv); }
int ENMIME_main(int ac,const char *av[]) { ac = scan_args(ac,av); if( do_b64 ) MIME_to64(infile,stdout); else if( do_qp ) MIME_toQP(infile,stdout); else PGPencodeMIMEX(infile,stdout,filter); exit(0); return 0; }
int DEMIME_main(int ac,const char *av[]) { int do_conv; ac = scan_args(ac,av); do_conv = codeconv_get(NULL,NULL,NULL); if( do_b64 ) MIME_from64(infile,stdout); else if( do_qp ) MIME_fromQP(infile,stdout); else PGPdecodeMIME(infile,stdout,NULL,filter,do_conv,0); exit(0); return 0; }
int main(int argc, char *argv[]) { char *filename = NULL; struct display_info disp; int ret; /* set defaults */ memset(&disp, '\0', sizeof(disp)); disp.flags = FDT_REG_SUPERNODES; /* Default flags */ scan_args(&disp, argc, argv); /* Show matched lines in colour if we can */ disp.colour = disp.all && isatty(0); /* Any additional arguments can match anything, just like -g */ while (optind < argc - 1) { if (value_add(&disp, &disp.value_head, FDT_IS_ANY, 1, argv[optind++])) usage("Cannot add value"); } if (optind < argc) filename = argv[optind++]; if (!filename) usage("Missing filename"); /* If a valid .dtb is required, set flags to ensure we get one */ if (disp.output == OUT_DTB) { disp.header = 1; disp.flags |= FDT_REG_ADD_MEM_RSVMAP | FDT_REG_ADD_STRING_TAB; } if (disp.output_fname) { disp.fout = fopen(disp.output_fname, "w"); if (!disp.fout) usage("Cannot open output file"); } else { disp.fout = stdout; } /* Run the grep and output the results */ ret = do_fdtgrep(&disp, filename); if (disp.output_fname) fclose(disp.fout); if (ret) return 1; return 0; }
void LOCAL2MIME_main(int ac,const char *av[]) { FILE *fp; CStr(line,1024); ac = scan_args(ac,av); if( getenv("TMPTEST") ){ printf("COMMENT: TMPTEST\n"); fp = (FILE*)MIME_tmpHeaderEncode(infile); while(fgets(line,sizeof(line),fp) != NULL) fputs(line,stdout); fclose(fp); }else MIME_headerEncode(infile,stdout); exit(0); }
/********************************************************************* * 文字列 *buf から、パラメータを読み取り、( adrs , memcnt ) を決める ********************************************************************* */ int get_arg(char *buf) { #if 0 arena = AREA_RAM; if(*buf == 'p') { buf++; arena = AREA_PGMEM; }else if(*buf == 'r') { buf++; arena = AREA_EEPROM; } #endif arena=MEM_BYTE; if(*buf == 'b') { buf++; }else if(*buf == 'h') { buf++; arena = MEM_HALF; }else if(*buf == 'w') { buf++; arena = MEM_WORD; } // memcnt = 64; memcnt = 256; adrs2 = (-1); buf = sp_skip(buf); if(*buf==0) return 0; arg_cnt = split_str(buf,',',arg_ptr); scan_args(arg_cnt); if(arg_cnt>=1) { adrs = arg_hex[0]; } if(arg_cnt>=2) { adrs2 = arg_hex[1]; if(adrs2 != (-1) ) { memcnt = adrs2 - adrs + 1; } if( memcnt < 0) { memcnt = adrs2; } } return arg_cnt; }
/* * Main parse routine. Scans for '-', then scan for arguments and * delete from the argv[] array if so. */ BOOLEAN parse_args(int *argc, char *argv[], BOOLEAN case_sensitive) { int pos = 0; BOOLEAN retval = TRUE; use_case = case_sensitive; while (++pos < *argc) { if ((argv[pos][0] == ARG_SEPSWITCH) || (argv[pos][0] == ARG_SEPFALSE) || (argv[pos][0] == ARG_SEPTRUE)) { if (argv[pos][1] == '!') { // skip the silence arg } else { int argmode; int index = 1; BOOLEAN done = FALSE; do { /* Scan the present arg */ if (pos < *argc - 1) argmode = scan_args(argv[pos], index, argv[pos + 1]); else argmode = scan_args(argv[pos], index, 0); switch (argmode) { case ARG_NEXTCHAR: /* If it was a char, go to the next one */ if (!argv[pos][++index]) done = TRUE; break; case ARG_NEXTNOCAT: /* Otherwise if it was a nocat, remove the extra arg */ remove_arg(pos, argc, argv); /* Fall through to NEXTARG */ case ARG_NEXTARG: /* Just a next arg, go do it */ done = TRUE; break; case ARG_NOMATCH: /* No such arg, spit an error */ #ifndef CPREPROCESSOR #ifdef XXXXX switch( parseParam(argv[pos][index] != ARG_SEPFALSE, &argv[pos][index + 1])) { case 0: #endif #endif fprintf(stderr, "Invalid Arg: %s\n", argv[pos]); retval = FALSE; done = TRUE; #ifndef CPREPROCESSORXX #ifdef XXXXX break ; case 1: if (!argv[pos][++index]) done = TRUE; break ; case 2: done = TRUE; break; } #endif #endif break; case ARG_NOARG: /* Missing the arg for a CONCAT type, spit the error */ fprintf(stderr, "Missing string for Arg %s\n", argv[pos]); done = TRUE; retval = FALSE; break; }; } while (!done); } /* We'll always get rid of the present arg * And back up one */ remove_arg(pos--, argc, argv); } } return (retval); }
void #line 50 "./cwebdir/comm-w2c.ch" common_init P1H(void) #line 92 "./cwebdir/common.w" { #line 56 "./cwebdir/comm-w2c.ch" /*32:*/ #line 621 "./cwebdir/common.w" name_dir->byte_start= byte_ptr= byte_mem; name_ptr= name_dir+1; name_ptr->byte_start= byte_mem; /*:32*//*36:*/ #line 655 "./cwebdir/common.w" for(h= hash;h<=hash_end;*h++= NULL); /*:36*//*43:*/ #line 737 "./cwebdir/common.w" root= NULL; /*:43*/ #line 56 "./cwebdir/comm-w2c.ch" ; /*24:*/ #line 187 "./cwebdir/comm-w2c.ch" kpse_set_program_name(argv[0],"cweb"); #line 473 "./cwebdir/common.w" /*:24*/ #line 57 "./cwebdir/comm-w2c.ch" ; #line 94 "./cwebdir/common.w" /*70:*/ #line 1233 "./cwebdir/common.w" #line 486 "./cwebdir/comm-w2c.ch" show_banner= show_happiness= show_progress= 1; kpathsea_debug= 0; #line 1235 "./cwebdir/common.w" /*:70*/ #line 94 "./cwebdir/common.w" ; /*80:*/ #line 1377 "./cwebdir/common.w" scan_args(); if(program==ctangle){ if((C_file= fopen(C_file_name,"w"))==NULL) fatal("! Cannot open output file ",C_file_name); } else{ if((tex_file= fopen(tex_file_name,"w"))==NULL) fatal("! Cannot open output file ",tex_file_name); } /*:80*/ #line 95 "./cwebdir/common.w" ; }
int main(int argc, char *argv[]) { int i, n, fdflags; struct sigaction sa; FILE *iffile; char *p; struct passwd *pw; struct timeval timo; sigset_t mask; struct protent *protp; struct stat statbuf; int connect_attempts = 0; char numbuf[16]; phase = PHASE_INITIALIZE; p = ttyname(0); if (p) strcpy(devnam, p); strcpy(default_devnam, devnam); script_env = NULL; /* Initialize syslog facilities */ #ifdef ULTRIX openlog("pppd", LOG_PID); #else openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP); setlogmask(LOG_UPTO(LOG_INFO)); #endif if (gethostname(hostname, MAXNAMELEN) < 0 ) { option_error("Couldn't get hostname: %m"); die(1); } hostname[MAXNAMELEN-1] = 0; uid = getuid(); privileged = uid == 0; sprintf(numbuf, "%d", uid); script_setenv("UID", numbuf); /* * Initialize to the standard option set, then parse, in order, * the system options file, the user's options file, * the tty's options file, and the command line arguments. */ for (i = 0; (protp = protocols[i]) != NULL; ++i) (*protp->init)(0); progname = *argv; if (!options_from_file(_PATH_SYSOPTIONS, !privileged, 0, 1) || !options_from_user()) exit(1); scan_args(argc-1, argv+1); /* look for tty name on command line */ if (!options_for_tty() || !parse_args(argc-1, argv+1)) exit(1); /* * Check that we are running as root. */ if (geteuid() != 0) { option_error("must be root to run %s, since it is not setuid-root", argv[0]); die(1); } if (!ppp_available()) { option_error(no_ppp_msg); exit(1); } /* * Check that the options given are valid and consistent. */ sys_check_options(); auth_check_options(); for (i = 0; (protp = protocols[i]) != NULL; ++i) if (protp->check_options != NULL) (*protp->check_options)(); if (demand && connector == 0) { option_error("connect script required for demand-dialling\n"); exit(1); } script_setenv("DEVICE", devnam); sprintf(numbuf, "%d", baud_rate); script_setenv("SPEED", numbuf); /* * If the user has specified the default device name explicitly, * pretend they hadn't. */ if (!default_device && strcmp(devnam, default_devnam) == 0) default_device = 1; if (default_device) nodetach = 1; /* * Initialize system-dependent stuff and magic number package. */ sys_init(); magic_init(); if (debug) setlogmask(LOG_UPTO(LOG_DEBUG)); /* * Detach ourselves from the terminal, if required, * and identify who is running us. */ if (nodetach == 0) detach(); pid = getpid(); p = getlogin(); stime = time(NULL); if (p == NULL) { pw = getpwuid(uid); if (pw != NULL && pw->pw_name != NULL) p = pw->pw_name; else p = "(unknown)"; } syslog(LOG_NOTICE, "pppd %s.%d%s started by %s, uid %d", VERSION, PATCHLEVEL, IMPLEMENTATION, p, uid); /* * Compute mask of all interesting signals and install signal handlers * for each. Only one signal handler may be active at a time. Therefore, * all other signals should be masked when any handler is executing. */ sigemptyset(&mask); sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGCHLD); #define SIGNAL(s, handler) { \ sa.sa_handler = handler; \ if (sigaction(s, &sa, NULL) < 0) { \ syslog(LOG_ERR, "Couldn't establish signal handler (%d): %m", s); \ die(1); \ } \ } sa.sa_mask = mask; sa.sa_flags = 0; SIGNAL(SIGHUP, hup); /* Hangup */ SIGNAL(SIGINT, term); /* Interrupt */ SIGNAL(SIGTERM, term); /* Terminate */ SIGNAL(SIGCHLD, chld); SIGNAL(SIGUSR1, toggle_debug); /* Toggle debug flag */ SIGNAL(SIGUSR2, open_ccp); /* Reopen CCP */ /* * Install a handler for other signals which would otherwise * cause pppd to exit without cleaning up. */ SIGNAL(SIGABRT, bad_signal); SIGNAL(SIGALRM, bad_signal); SIGNAL(SIGFPE, bad_signal); SIGNAL(SIGILL, bad_signal); SIGNAL(SIGPIPE, bad_signal); SIGNAL(SIGQUIT, bad_signal); SIGNAL(SIGSEGV, bad_signal); #ifdef SIGBUS SIGNAL(SIGBUS, bad_signal); #endif #ifdef SIGEMT SIGNAL(SIGEMT, bad_signal); #endif #ifdef SIGPOLL SIGNAL(SIGPOLL, bad_signal); #endif #ifdef SIGPROF SIGNAL(SIGPROF, bad_signal); #endif #ifdef SIGSYS SIGNAL(SIGSYS, bad_signal); #endif #ifdef SIGTRAP SIGNAL(SIGTRAP, bad_signal); #endif #ifdef SIGVTALRM SIGNAL(SIGVTALRM, bad_signal); #endif #ifdef SIGXCPU SIGNAL(SIGXCPU, bad_signal); #endif #ifdef SIGXFSZ SIGNAL(SIGXFSZ, bad_signal); #endif /* * Apparently we can get a SIGPIPE when we call syslog, if * syslogd has died and been restarted. Ignoring it seems * be sufficient. */ signal(SIGPIPE, SIG_IGN); /* * If we're doing dial-on-demand, set up the interface now. */ if (demand) { /* * Open the loopback channel and set it up to be the ppp interface. */ open_ppp_loopback(); syslog(LOG_INFO, "Using interface ppp%d", ifunit); sprintf(ifname, "ppp%d", ifunit); script_setenv("IFNAME", ifname); create_pidfile(); /* write pid to file */ /* * Configure the interface and mark it up, etc. */ demand_conf(); } for (;;) { need_holdoff = 1; if (demand) { /* * Don't do anything until we see some activity. */ phase = PHASE_DORMANT; kill_link = 0; demand_unblock(); for (;;) { wait_loop_output(timeleft(&timo)); calltimeout(); if (kill_link) { if (!persist) die(0); kill_link = 0; } if (get_loop_output()) break; reap_kids(); } /* * Now we want to bring up the link. */ demand_block(); syslog(LOG_INFO, "Starting link"); } /* * Lock the device if we've been asked to. */ if (lockflag && !default_device) { if (lock(devnam) < 0) goto fail; locked = 1; } /* * Open the serial device and set it up to be the ppp interface. * First we open it in non-blocking mode so we can set the * various termios flags appropriately. If we aren't dialling * out and we want to use the modem lines, we reopen it later * in order to wait for the carrier detect signal from the modem. */ while ((ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0)) < 0) { if (errno != EINTR) syslog(LOG_ERR, "Failed to open %s: %m", devnam); if (!persist || errno != EINTR) goto fail; } if ((fdflags = fcntl(ttyfd, F_GETFL)) == -1 || fcntl(ttyfd, F_SETFL, fdflags & ~O_NONBLOCK) < 0) syslog(LOG_WARNING, "Couldn't reset non-blocking mode on device: %m"); hungup = 0; kill_link = 0; /* * Do the equivalent of `mesg n' to stop broadcast messages. */ if (fstat(ttyfd, &statbuf) < 0 || fchmod(ttyfd, statbuf.st_mode & ~(S_IWGRP | S_IWOTH)) < 0) { syslog(LOG_WARNING, "Couldn't restrict write permissions to %s: %m", devnam); } else tty_mode = statbuf.st_mode; /* run connection script */ if (connector && connector[0]) { MAINDEBUG((LOG_INFO, "Connecting with <%s>", connector)); /* * Set line speed, flow control, etc. * On most systems we set CLOCAL for now so that we can talk * to the modem before carrier comes up. But this has the * side effect that we might miss it if CD drops before we * get to clear CLOCAL below. On systems where we can talk * successfully to the modem with CLOCAL clear and CD down, * we can clear CLOCAL at this point. */ set_up_tty(ttyfd, 1); /* drop dtr to hang up in case modem is off hook */ if (!default_device && modem) { setdtr(ttyfd, FALSE); sleep(1); setdtr(ttyfd, TRUE); } if (device_script(connector, ttyfd, ttyfd) < 0) { syslog(LOG_ERR, "Connect script failed"); setdtr(ttyfd, FALSE); connect_attempts++; goto fail; } syslog(LOG_INFO, "Serial connection established."); sleep(1); /* give it time to set up its terminal */ } connect_attempts = 0; /* we made it through ok */ /* set line speed, flow control, etc.; clear CLOCAL if modem option */ set_up_tty(ttyfd, 0); /* reopen tty if necessary to wait for carrier */ if (connector == NULL && modem) { while ((i = open(devnam, O_RDWR)) < 0) { if (errno != EINTR) syslog(LOG_ERR, "Failed to reopen %s: %m", devnam); if (!persist || errno != EINTR || hungup || kill_link) goto fail; } close(i); } /* run welcome script, if any */ if (welcomer && welcomer[0]) { if (device_script(welcomer, ttyfd, ttyfd) < 0) syslog(LOG_WARNING, "Welcome script failed"); } /* set up the serial device as a ppp interface */ establish_ppp(ttyfd); if (!demand) { syslog(LOG_INFO, "Using interface ppp%d", ifunit); sprintf(ifname, "ppp%d", ifunit); create_pidfile(); /* write pid to file */ /* write interface unit number to file */ for (n = strlen(devnam); n > 0 ; n--) if (devnam[n] == '/') { n++; break; } sprintf(iffilename, "%s%s.if", _PATH_VARRUN, &devnam[n]); if ((iffile = fopen(iffilename, "w")) != NULL) { fprintf(iffile, "ppp%d\n", ifunit); fclose(iffile); } else { syslog(LOG_ERR, "Failed to create if file %s: %m", iffilename); iffilename[0] = 0; } script_setenv("IFNAME", ifname); } /* * Start opening the connection and wait for * incoming events (reply, timeout, etc.). */ syslog(LOG_NOTICE, "Connect: %s <--> %s", ifname, devnam); stime = time(NULL); lcp_lowerup(0); lcp_open(0); /* Start protocol */ for (phase = PHASE_ESTABLISH; phase != PHASE_DEAD; ) { wait_input(timeleft(&timo)); calltimeout(); get_input(); if (kill_link) { lcp_close(0, "User request"); kill_link = 0; } if (open_ccp_flag) { if (phase == PHASE_NETWORK) { ccp_fsm[0].flags = OPT_RESTART; /* clears OPT_SILENT */ (*ccp_protent.open)(0); } open_ccp_flag = 0; } reap_kids(); /* Don't leave dead kids lying around */ } /* * If we may want to bring the link up again, transfer * the ppp unit back to the loopback. Set the * real serial device back to its normal mode of operation. */ clean_check(); if (demand) restore_loop(); disestablish_ppp(ttyfd); /* * Run disconnector script, if requested. * XXX we may not be able to do this if the line has hung up! */ if (disconnector && !hungup) { set_up_tty(ttyfd, 1); if (device_script(disconnector, ttyfd, ttyfd) < 0) { syslog(LOG_WARNING, "disconnect script failed"); } else { syslog(LOG_INFO, "Serial link disconnected."); } } fail: if (ttyfd >= 0) close_tty(); if (locked) { unlock(); locked = 0; } if (!demand) { if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) syslog(LOG_WARNING, "unable to delete pid file: %m"); pidfilename[0] = 0; if (iffile) if (unlink(iffilename) < 0 && errno != ENOENT) syslog(LOG_WARNING, "unable to delete if file: %m"); iffilename[0] = 0; } /* limit to retries? */ if (max_con_attempts) if (connect_attempts >= max_con_attempts) break; if (!persist) die(1); if (demand) demand_discard(); if (holdoff > 0 && need_holdoff) { phase = PHASE_HOLDOFF; TIMEOUT(holdoff_end, NULL, holdoff); do { wait_time(timeleft(&timo)); calltimeout(); if (kill_link) { if (!persist) die(0); kill_link = 0; phase = PHASE_DORMANT; /* allow signal to end holdoff */ } reap_kids(); } while (phase == PHASE_HOLDOFF); } } die(0); return 0; }
void MIME2LOCAL_main(int ac,const char *av[]) { ac = scan_args(ac,av); MIME_headerDecode(infile,stdout,1); exit(0); }