void onoff(int ac, char **av, int cmd, char *cmdstr, char *prstr, int usage) { if (ac > 1) prusage(usage, 1); if (ac == 1) { if (strcmp(av[0], "on") == 0) tc.tc_int = 1; else if (strcmp(av[0], "off") == 0) tc.tc_int = 0; else prusage(usage, 1); } else tc.tc_int = -1; if (ioctl(ctlfd, cmd, &tc) < 0) err(1, "%s on %s", cmdstr, Devname); switch (ac) { case 0: printf("%s: ", Devname); case -1: printf("%s ", prstr); if (tc.tc_int) printf("on\n"); else printf("off\n"); } }
/* * R E A D _ T I M E R * */ double read_timer(char *str, int len) { struct timeval timedol; struct rusage ru1; struct timeval td; struct timeval tend, tstart; char line[132]; getrusage(RUSAGE_SELF, &ru1); gettimeofday(&timedol, (struct timezone *)0); prusage(&ru0, &ru1, &timedol, &time0, line); /* XXX: buffer overflow if len > sizeof(line) */ (void)strncpy(str, line, len); /* Get real time */ tvsub(&td, &timedol, &time0); realt = td.tv_sec + ((double)td.tv_usec) / 1000000; /* Get CPU time (user+sys) */ tvadd(&tend, &ru1.ru_utime, &ru1.ru_stime); tvadd(&tstart, &ru0.ru_utime, &ru0.ru_stime); tvsub(&td, &tend, &tstart); cput = td.tv_sec + ((double)td.tv_usec) / 1000000; if (cput < 0.00001) cput = 0.00001; return(cput); }
/* * debug * debug [[set|add|del debug_lvls] | [off]] */ void debug(int ac, char **av) { int level; if (ac > 2) prusage(U_DEBUG, 1); if (alldev) { if (ioctl(ctlfd, TCSIGDBG_ALL, &tc.tc_dbglvl) < 0) err(1, "TCSIGDBG_ALL on %s", Devname); } else { if (ioctl(ctlfd, TCSIGDBG_LEVEL, &tc) < 0) err(1, "TCSIGDBG_LEVEL on %s", Devname); } switch (ac) { case 0: printf("%s: debug levels - ", Devname); prlevels(tc.tc_dbglvl); return; case 1: if (strcmp(av[0], "off") == 0) { tc.tc_dbglvl = 0; break; } prusage(U_DEBUG, 1); /* no return */ case 2: level = lvls2bits(av[1]); if (strcmp(av[0], "add") == 0) tc.tc_dbglvl |= level; else if (strcmp(av[0], "del") == 0) tc.tc_dbglvl &= ~level; else if (strcmp(av[0], "set") == 0) tc.tc_dbglvl = level; else prusage(U_DEBUG, 1); } if (alldev) { if (ioctl(ctlfd, TCSISDBG_ALL, &tc.tc_dbglvl) < 0) err(1, "TCSISDBG_ALL on %s", Devname); } else { if (ioctl(ctlfd, TCSISDBG_LEVEL, &tc) < 0) err(1, "TCSISDBG_LEVEL on %s", Devname); } }
int main(int argc, char **argv) { struct opt *op; void (*func)(int, char **) = NULL; if (argc < 2) prusage(U_ALL, 1); Devname = argv[1]; if (strcmp(Devname, "-") == 0) { alldev = 1; } else { sidev_t dev; int n; int card, port; n = sscanf(Devname, "%d:%d", &card, &port); if (n != 2) errx(1, "Devname must be in form card:port. eg: 0:7"); dev.sid_card = card; dev.sid_port = port; tc.tc_dev = dev; } ctlfd = opencontrol(); if (argc == 2) { dostat(); exit(0); } argc--; argv++; for (op = opt; op->o_name; op++) { if (strcmp(argv[1], op->o_name) == 0) { func = op->o_func; break; } } if (func == NULL) prusage(U_ALL, 1); argc -= 2; argv += 2; (*func)(argc, argv); exit(0); }
/* * dotime is only called if it is truly a builtin function and not a * prefix to another command */ dotime() { struct timeval timedol; struct rusage ru1, ruch; (void) getrusage(RUSAGE_SELF, &ru1); (void) getrusage(RUSAGE_CHILDREN, &ruch); ruadd(&ru1, &ruch); (void) gettimeofday(&timedol, (struct timezone *)0); prusage(&ru0, &ru1, &timedol, &time0); }
void nport(int ac, char **av) { int ports; if (ac != 0) prusage(U_NPORT, 1); if (ioctl(ctlfd, TCSIPORTS, &ports) < 0) err(1, "TCSIPORTS on %s", Devname); printf("SLXOS: total of %d ports\n", ports); }
/* * dotime is only called if it is truly a builtin function and not a * prefix to another command */ void /*ARGSUSED*/ dotime(Char **v, struct command *t) { struct timespec timedol; struct rusage ru1, ruch; (void) getrusage(RUSAGE_SELF, &ru1); (void) getrusage(RUSAGE_CHILDREN, &ruch); ruadd(&ru1, &ruch); (void) clock_gettime(CLOCK_MONOTONIC, &timedol); prusage(&ru0, &ru1, &timedol, &time0); }
/* * dotime is only called if it is truly a builtin function and not a * prefix to another command */ void /*ARGSUSED*/ dotime(Char **v, struct command *t) { struct timeval timedol; struct rusage ru1, ruch; (void) getrusage(RUSAGE_SELF, &ru1); (void) getrusage(RUSAGE_CHILDREN, &ruch); ruadd(&ru1, &ruch); (void) gettimeofday(&timedol, NULL); prusage(&ru0, &ru1, &timedol, &time0); }
void ccb_stat(int ac, char **av) { struct si_pstat sip; #define CCB sip.tc_ccb if (ac != 0) prusage(U_STAT_CCB, 1); sip.tc_dev = tc.tc_dev; if (ioctl(ctlfd, TCSI_CCB, &sip) < 0) err(1, "TCSI_CCB on %s", Devname); printf("%s: ", Devname); /* WORD next - Next Channel */ /* WORD addr_uart - Uart address */ /* WORD module - address of module struct */ printf("\tuart_type 0x%x\n", CCB.type); /* BYTE type - Uart type */ /* BYTE fill - */ printf("\tx_status 0x%x %s\n", CCB.x_status, s_xstat(CCB.x_status)); /* BYTE x_status - XON / XOFF status */ printf("\tc_status 0x%x %s\n", CCB.c_status, s_cstat(CCB.c_status)); /* BYTE c_status - cooking status */ printf("\thi_rxipos 0x%x\n", CCB.hi_rxipos); /* BYTE hi_rxipos - stuff into rx buff */ printf("\thi_rxopos 0x%x\n", CCB.hi_rxopos); /* BYTE hi_rxopos - stuff out of rx buffer */ printf("\thi_txopos 0x%x\n", CCB.hi_txopos); /* BYTE hi_txopos - Stuff into tx ptr */ printf("\thi_txipos 0x%x\n", CCB.hi_txipos); /* BYTE hi_txipos - ditto out */ printf("\thi_stat 0x%x %s\n", CCB.hi_stat, s_stat(CCB.hi_stat));/* BYTE hi_stat - Command register */ printf("\tdsr_bit 0x%x\n", CCB.dsr_bit); /* BYTE dsr_bit - Magic bit for DSR */ printf("\ttxon 0x%x\n", CCB.txon); /* BYTE txon - TX XON char */ printf("\ttxoff 0x%x\n", CCB.txoff); /* BYTE txoff - ditto XOFF */ printf("\trxon 0x%x\n", CCB.rxon); /* BYTE rxon - RX XON char */ printf("\trxoff 0x%x\n", CCB.rxoff); /* BYTE rxoff - ditto XOFF */ printf("\thi_mr1 0x%x %s\n", CCB.hi_mr1, s_mr1(CCB.hi_mr1)); /* BYTE hi_mr1 - mode 1 image */ printf("\thi_mr2 0x%x %s\n", CCB.hi_mr2, s_mr2(CCB.hi_mr2)); /* BYTE hi_mr2 - mode 2 image */ printf("\thi_csr 0x%x in:%s out:%s\n", CCB.hi_csr, s_clk(CCB.hi_csr >> 4), s_clk(CCB.hi_csr)); /* BYTE hi_csr - clock register */ printf("\thi_op 0x%x %s\n", CCB.hi_op, s_op(CCB.hi_op)); /* BYTE hi_op - Op control */ printf("\thi_ip 0x%x %s\n", CCB.hi_ip, s_ip(CCB.hi_ip)); /* BYTE hi_ip - Input pins */ printf("\thi_state 0x%x %s\n", CCB.hi_state, s_state(CCB.hi_state)); /* BYTE hi_state - status */ printf("\thi_prtcl 0x%x %s\n", CCB.hi_prtcl, s_prtcl(CCB.hi_prtcl)); /* BYTE hi_prtcl - Protocol */ printf("\thi_txon 0x%x\n", CCB.hi_txon); /* BYTE hi_txon - host copy tx xon stuff */ printf("\thi_txoff 0x%x\n", CCB.hi_txoff); /* BYTE hi_txoff - */ printf("\thi_rxon 0x%x\n", CCB.hi_rxon); /* BYTE hi_rxon - */ printf("\thi_rxoff 0x%x\n", CCB.hi_rxoff); /* BYTE hi_rxoff - */ printf("\tclose_prev 0x%x\n", CCB.close_prev); /* BYTE close_prev - Was channel previously closed */ printf("\thi_break 0x%x %s\n", CCB.hi_break, s_break(CCB.hi_break)); /* BYTE hi_break - host copy break process */ printf("\tbreak_state 0x%x\n", CCB.break_state); /* BYTE break_state - local copy ditto */ printf("\thi_mask 0x%x\n", CCB.hi_mask); /* BYTE hi_mask - Mask for CS7 etc. */ printf("\tmask_z280 0x%x\n", CCB.mask_z280); /* BYTE mask_z280 - Z280's copy */ /* BYTE res[0x60 - 36] - */ /* BYTE hi_txbuf[SLXOS_BUFFERSIZE] - */ /* BYTE hi_rxbuf[SLXOS_BUFFERSIZE] - */ /* BYTE res1[0xA0] - */ }
/* * dotime is only called if it is truly a builtin function and not a * prefix to another command */ void dotime(void) { struct timeval timedol; struct rusage ru1, ruch; #ifdef TRACE tprintf("TRACE- dotime()\n"); #endif (void) getrusage(RUSAGE_SELF, &ru1); (void) getrusage(RUSAGE_CHILDREN, &ruch); ruadd(&ru1, &ruch); (void) gettimeofday(&timedol, (struct timezone *)0); prusage(&ru0, &ru1, &timedol, &time0); }
void port_stat(int ac, char **av) { struct si_pstat sip; #define PRT sip.tc_siport if (ac != 0) prusage(U_STAT_PORT, 1); sip.tc_dev = tc.tc_dev; if (ioctl(ctlfd, TCSI_PORT, &sip) < 0) err(1, "TCSI_PORT on %s", Devname); printf("%s: ", Devname); printf("\tsp_pend 0x%x %s\n", PRT.sp_pend, s_stat(PRT.sp_pend)); printf("\tsp_last_hi_ip 0x%x %s\n", PRT.sp_last_hi_ip, s_ip(PRT.sp_last_hi_ip)); printf("\tsp_state 0x%x %s\n", PRT.sp_state, sp_state(PRT.sp_state)); printf("\tsp_delta_overflows 0x%d\n", PRT.sp_delta_overflows); }
void mstate(int ac, char **av) { switch (ac) { case 0: printf("%s: ", Devname); case -1: break; default: prusage(U_MSTATE, 1); } if (ioctl(ctlfd, TCSISTATE, &tc) < 0) err(1, "TCSISTATE on %s", Devname); printf("modem bits state - (0x%x)", tc.tc_int); if (tc.tc_int & IP_DCD) printf(" DCD"); if (tc.tc_int & IP_DTR) printf(" DTR"); if (tc.tc_int & IP_RTS) printf(" RTS"); printf("\n"); }
void txint(int ac, char **av) { tc.tc_port = 0; switch (ac) { case 0: printf("%s: ", Devname); case -1: if (ioctl(ctlfd, TCSIGIT, &tc) < 0) err(1, "TCSIGIT"); printf("aggregate interrupt throttle: %d\n", tc.tc_int); break; case 1: tc.tc_int = getnum(av[0]); if (ioctl(ctlfd, TCSIIT, &tc) < 0) err(1, "TCSIIT on %s at %d", Devname, tc.tc_int); break; default: prusage(U_TXINT, 1); } }
void rxint(int ac, char **av) { tc.tc_port = 0; switch (ac) { case 0: printf("%s: ", Devname); case -1: if (ioctl(ctlfd, TCSIGRXIT, &tc) < 0) err(1, "TCSIGRXIT"); printf("RX interrupt throttle: %d msec\n", tc.tc_int*10); break; case 1: tc.tc_int = getnum(av[0]) / 10; if (tc.tc_int == 0) tc.tc_int = 1; if (ioctl(ctlfd, TCSIRXIT, &tc) < 0) err(1, "TCSIRXIT on %s at %d msec", Devname, tc.tc_int*10); break; default: prusage(U_RXINT, 1); } }
/* * R E A D _ T I M E R */ double read_timer (char *str, int len) { struct itimerval itimedol; struct rusage ru1; struct timeval td; struct timeval tend, tstart; char line[132]; getrusage (RUSAGE_SELF, &ru1); fprintf(stdout, "final user time = %d sec and %d usec\n", ru1.ru_utime.tv_sec, ru1.ru_utime.tv_usec); fprintf(stdout, "final sys time = %d sec and %d usec\n", ru1.ru_stime.tv_sec, ru1.ru_stime.tv_usec); if (getitimer (ITIMER_REAL, &itimedol)) { perror ("Getting 'itimer' REAL failed"); return (0.0); } fprintf(stdout, "End transaction time = %d sec and %d usec\n", itimedol.it_value.tv_sec, itimedol.it_value.tv_usec); prusage (&ru0, &ru1, &itime0.it_value, &itimedol.it_value, line); (void) strncpy (str, line, len); /* Get real time */ tvsub (&td, &itime0.it_value, &itimedol.it_value); realt = td.tv_sec + ((double) td.tv_usec) / 1000000; /* Get CPU time (user+sys) */ tvadd (&tend, &ru1.ru_utime, &ru1.ru_stime); tvadd (&tstart, &ru0.ru_utime, &ru0.ru_stime); tvsub (&td, &tend, &tstart); cput = td.tv_sec + ((double) td.tv_usec) / 1000000; if (cput < 0.00001) cput = 0.00001; return (cput); }
int main(int argc, char *argv[]) { register int i; int c; char *p; char path[MAXPATHLEN]; pmOptions opts = { .short_options = allflags, .flags = PM_OPTFLAG_BOUNDARIES, }; /* ** preserve command arguments to allow restart of other version */ argvp = argv; /* ** read defaults-files /etc/atoprc en $HOME/.atoprc (if any) */ readrc("/etc/atoprc", 1); if ( (p = getenv("HOME")) ) { snprintf(path, sizeof(path), "%s/.atoprc", p); path[sizeof(path)-1] = '\0'; readrc(path, 0); } /* ** check if we are supposed to behave as 'atopsar' ** i.e. system statistics only */ __pmSetProgname(argv[0]); if (strcmp(pmProgname, "pcp-atopsar") == 0) return atopsar(argc, argv); __pmStartOptions(&opts); if (opts.narchives > 0) rawreadflag++; /* ** interpret command-line arguments & flags */ if (argc > 1) { /* ** gather all flags for visualization-functions ** ** generic flags will be handled here; ** unrecognized flags are passed to the print-routines */ i = 0; while (i < MAXFL-1 && (c = pmgetopt_r(argc, argv, &opts)) != EOF) { switch (c) { case '?': /* usage wanted ? */ prusage(pmProgname); break; case 'V': /* version wanted ? */ printf("%s\n", getstrvers()); exit(0); case 'w': /* writing of raw data ? */ rawname = opts.optarg; rawwriteflag++; break; case 'r': /* reading of raw data ? */ rawarchive(&opts, opts.optarg); rawreadflag++; break; case 'S': /* midnight limit ? */ midnightflag++; break; case 'a': /* all processes per sample ? */ deviatonly = 0; break; case 'R': /* all processes per sample ? */ calcpss = 1; break; case 'b': /* begin time ? */ opts.start_optarg = abstime(opts.optarg); break; case 'e': /* end time ? */ opts.finish_optarg = abstime(opts.optarg); break; case 'P': /* parseable output? */ if ( !parsedef(opts.optarg) ) prusage(pmProgname); vis.show_samp = parseout; break; case 'L': /* line length */ if ( !numeric(opts.optarg) ) prusage(pmProgname); linelen = atoi(opts.optarg); break; default: /* gather other flags */ flaglist[i++] = c; } } /* ** get optional interval-value and optional number of samples */ if (opts.optind < argc && opts.optind < MAXFL) { char *endnum, *arg; arg = argv[opts.optind++]; if (pmParseInterval(arg, &opts.interval, &endnum) < 0) { pmprintf( "%s: %s option not in pmParseInterval(3) format:\n%s\n", pmProgname, arg, endnum); free(endnum); opts.errors++; } else interval = opts.interval; if (opts.optind < argc) { arg = argv[opts.optind]; if (!numeric(arg)) prusage(pmProgname); if ((opts.samples = atoi(arg)) < 1) prusage(pmProgname); nsamples = opts.samples; } } } __pmEndOptions(&opts); if (opts.errors) prusage(pmProgname); /* ** find local host details (no privileged access required) */ setup_globals(&opts); /* ** check if we are in data recording mode */ if (rawwriteflag) { rawwrite(&opts, rawname, &interval, nsamples, midnightflag); cleanstop(0); } /* ** catch signals for proper close-down */ signal(SIGHUP, cleanstop); signal(SIGTERM, cleanstop); /* ** switch-on the process-accounting mechanism to register the ** (remaining) resource-usage by processes which have finished */ acctreason = acctswon(); /* ** determine properties (like speed) of all interfaces */ initifprop(); /* ** open socket to the IP layer to issue getsockopt() calls later on */ netatop_ipopen(); /* ** start the engine now ..... */ engine(); cleanstop(0); return 0; /* never reached */ }
int main(int argc, char *argv[]) { register int i; int c; char *p; struct rlimit rlim; /* ** since priviliged actions will be done later on, at this stage ** the root-priviliges are dropped by switching effective user-id ** to real user-id (security reasons) */ if (! droprootprivs() ) { fprintf(stderr, "not possible to drop root privs\n"); exit(42); } /* ** preserve command arguments to allow restart of other version */ argvp = argv; /* ** read defaults-files /etc/atoprc en $HOME/.atoprc (if any) */ readrc("/etc/atoprc"); if ( (p = getenv("HOME")) ) { char path[1024]; snprintf(path, sizeof path, "%s/.atoprc", p); readrc(path); } /* ** check if we are supposed to behave as 'atopsar' ** i.e. system statistics only */ if ( (p = strrchr(argv[0], '/'))) p++; else p = argv[0]; if ( memcmp(p, "atopsar", 7) == 0) return atopsar(argc, argv); /* ** interpret command-line arguments & flags */ if (argc > 1) { /* ** gather all flags for visualization-functions ** ** generic flags will be handled here; ** unrecognized flags are passed to the print-routines */ i = 0; while (i < MAXFL-1 && (c=getopt(argc, argv, allflags)) != EOF) { switch (c) { case '?': /* usage wanted ? */ prusage(argv[0]); break; case 'V': /* version wanted ? */ printf("%s\n", getstrvers()); exit(0); case 'w': /* writing of raw data ? */ if (optind >= argc) prusage(argv[0]); strncpy(rawname, argv[optind++], RAWNAMESZ-1); vis.show_samp = rawwrite; break; case 'r': /* reading of raw data ? */ if (optind < argc && *(argv[optind]) != '-') strncpy(rawname, argv[optind++], RAWNAMESZ-1); rawreadflag++; break; case 'S': /* midnight limit ? */ midnightflag++; break; case 'a': /* all processes per sample ? */ deviatonly=0; break; case 'b': /* begin time ? */ if ( !hhmm2secs(optarg, &begintime) ) prusage(argv[0]); break; case 'e': /* end time ? */ if ( !hhmm2secs(optarg, &endtime) ) prusage(argv[0]); break; case 'j': /* show disk partitions statistics */ diskpartview = 1; break; case 'P': /* parseable output? */ if ( !parsedef(optarg) ) prusage(argv[0]); vis.show_samp = parseout; break; case 'L': /* line length */ if ( !numeric(optarg) ) prusage(argv[0]); linelen = atoi(optarg); break; default: /* gather other flags */ flaglist[i++] = c; } } /* ** get optional interval-value and optional number of samples */ if (optind < argc && optind < MAXFL) { if (!numeric(argv[optind])) prusage(argv[0]); interval = atoi(argv[optind]); optind++; if (optind < argc) { if (!numeric(argv[optind]) ) prusage(argv[0]); if ( (nsamples = atoi(argv[optind])) < 1) prusage(argv[0]); } } } /* ** determine the name of this node (without domain-name) ** and the kernel-version */ (void) uname(&utsname); if ( (p = strchr(utsname.nodename, '.')) ) *p = '\0'; utsnodenamelen = strlen(utsname.nodename); sscanf(utsname.release, "%d.%d.%d", &osrel, &osvers, &ossub); /* ** determine the clock rate and memory page size for this machine */ hertz = sysconf(_SC_CLK_TCK); pagesize = sysconf(_SC_PAGESIZE); /* ** check if raw data from a file must be viewed */ if (rawreadflag) { rawread(); cleanstop(0); } /* ** determine start-time for gathering current statistics */ curtime = getboot() / hertz; /* ** catch signals for proper close-down */ signal(SIGHUP, cleanstop); signal(SIGTERM, cleanstop); /* ** regain the root-priviliges that we dropped at the beginning ** to do some priviliged work */ regainrootprivs(); /* ** lock ATOP in memory to get reliable samples (also when ** memory is low); ** ignored if not running under superuser priviliges! */ rlim.rlim_cur = RLIM_INFINITY; rlim.rlim_max = RLIM_INFINITY; (void) setrlimit(RLIMIT_MEMLOCK, &rlim); (void) mlockall(MCL_CURRENT|MCL_FUTURE); /* ** increment CPU scheduling-priority to get reliable samples (also ** during heavy CPU load); ** ignored if not running under superuser priviliges! */ if ( nice(-20) == -1) ; /* ** switch-on the process-accounting mechanism to register the ** (remaining) resource-usage by processes which have finished */ acctreason = acctswon(); /* ** determine properties (like speed) of all interfaces */ initifprop(); /* ** open socket to the IP layer to issue getsockopt() calls later on */ netatop_ipopen(); /* ** since priviliged activities are finished now, there is no ** need to keep running under root-priviliges, so switch ** effective user-id to real user-id */ if (! droprootprivs() ) cleanstop(42); /* ** start the engine now ..... */ engine(); cleanstop(0); return 0; /* never reached */ }
void main(int argc, char **argv) { Word *w; char *s, *temp; char *files[256], **f = files, **ff; int sflag = 0; int i; int tfd = -1; Biobuf tb; Bufblock *buf; Bufblock *whatif; /* * start with a copy of the current environment variables * instead of sharing them */ Binit(&bout, 1, OWRITE); buf = newbuf(); whatif = 0; USED(argc); for(argv++; *argv && (**argv == '-'); argv++) { bufcpy(buf, argv[0], strlen(argv[0])); insert(buf, ' '); switch(argv[0][1]) { case 'a': aflag = 1; break; case 'd': if(*(s = &argv[0][2])) while(*s) switch(*s++) { case 'p': debug |= D_PARSE; break; case 'g': debug |= D_GRAPH; break; case 'e': debug |= D_EXEC; break; } else debug = 0xFFFF; break; case 'e': explain = &argv[0][2]; break; case 'f': if(*++argv == 0) badusage(); *f++ = *argv; bufcpy(buf, argv[0], strlen(argv[0])); insert(buf, ' '); break; case 'i': iflag = 1; break; case 'k': kflag = 1; break; case 'n': nflag = 1; break; case 's': sflag = 1; break; case 't': tflag = 1; break; case 'u': uflag = 1; break; case 'w': if(whatif == 0) whatif = newbuf(); else insert(whatif, ' '); if(argv[0][2]) bufcpy(whatif, &argv[0][2], strlen(&argv[0][2])); else { if(*++argv == 0) badusage(); bufcpy(whatif, &argv[0][0], strlen(&argv[0][0])); } break; default: badusage(); } } #ifdef PROF { extern etext(); monitor(main, etext, buf, sizeof buf, 300); } #endif if(aflag) iflag = 1; usage(); syminit(); initenv(); usage(); /* assignment args become null strings */ temp = 0; for(i = 0; argv[i]; i++) if(utfrune(argv[i], '=')){ bufcpy(buf, argv[i], strlen(argv[i])); insert(buf, ' '); if(tfd < 0){ temp = maketmp(); if(temp == 0) { perror("temp file"); Exit(); } close(create(temp, OWRITE, 0600)); if((tfd = open(temp, 2)) < 0){ perror(temp); Exit(); } Binit(&tb, tfd, OWRITE); } Bprint(&tb, "%s\n", argv[i]); *argv[i] = 0; } if(tfd >= 0){ Bflush(&tb); LSEEK(tfd, 0L, 0); parse("command line args", tfd, 1); remove(temp); } if (buf->current != buf->start) { buf->current--; insert(buf, 0); } symlook("MKFLAGS", S_VAR, (void *) stow(buf->start)); buf->current = buf->start; for(i = 0; argv[i]; i++){ if(*argv[i] == 0) continue; if(i) insert(buf, ' '); bufcpy(buf, argv[i], strlen(argv[i])); } insert(buf, 0); symlook("MKARGS", S_VAR, (void *) stow(buf->start)); freebuf(buf); if(f == files){ if(access(MKFILE, 4) == 0) parse(MKFILE, open(MKFILE, 0), 0); } else for(ff = files; ff < f; ff++) parse(*ff, open(*ff, 0), 0); if(DEBUG(D_PARSE)){ dumpw("default targets", target1); dumpr("rules", rules); dumpr("metarules", metarules); dumpv("variables"); } if(whatif){ insert(whatif, 0); timeinit(whatif->start); freebuf(whatif); } execinit(); /* skip assignment args */ while(*argv && (**argv == 0)) argv++; catchnotes(); if(*argv == 0){ if(target1) for(w = target1; w; w = w->next) mk(w->s); else { fprint(2, "mk: nothing to mk\n"); Exit(); } } else { if(sflag){ for(; *argv; argv++) if(**argv) mk(*argv); } else { Word *head, *tail, *t; /* fake a new rule with all the args as prereqs */ tail = 0; t = 0; for(; *argv; argv++) if(**argv){ if(tail == 0) tail = t = newword(*argv); else { t->next = newword(*argv); t = t->next; } } if(tail->next == 0) mk(tail->s); else { head = newword("command line arguments"); addrules(head, tail, strdup(""), VIR, mkinline, 0); mk(head->s); } } } if(uflag) prusage(); exits(0); }