/* * Displaying the stopwatch value in HHhMM'SS"t format */ static void display_stopwatch() { char buf[13]; char exponent[3]; char message[13]; char display_rcl_message; fill_exponent(exponent); stopwatch_to_string(StopWatch, buf); display_rcl_message=StopWatchStatus.rcl_mode || StopWatchStatus.sigma_display_mode || RclMemory>=0; if(display_rcl_message) { char* rp=scopy(message, StopWatchStatus.sigma_display_mode?"\221+\006":"RCL\006\006"); if(StopWatchStatus.sigma_display_mode) { rp=num_arg(rp, RclMemory); } else { if(RclMemory>=0) { rp=num_arg_0(rp, RclMemory, 2); } else { if(StopWatchMemoryFirstDigit>=0) { *rp++='0'+StopWatchMemoryFirstDigit; } *rp++='_'; } } *rp=0; } else if(TotalFirstTicker>0) { stopwatch_to_string(TotalStopWatch, message); display_rcl_message=1; } stopwatch_message(display_rcl_message?message:STOPWATCH_MESSAGE, buf, StopWatchStatus.sigma_display_mode, StopWatchStatus.show_memory?exponent:(char*)NULL); }
void date_alphatime(enum nilop op) { char buf[16], *p; int h, m, s; const char *suffix; if (extract_time(&h, &m, &s, 100)) return; xset(buf, '\0', sizeof(buf)); if (UState.t12) { if (h >= 12) { h -= 12; suffix = " PM"; } else suffix = " AM"; if (h == 0) h = 12; } else suffix = ""; p = num_arg(buf, h); *p++ = ':'; p = num_arg_0(p, m, 2); *p++ = ':'; p = num_arg_0(p, s, 2); scopy(p, suffix); add_string(buf); }
/* Date and times to the Alpha register */ void date_alphadate(enum nilop op) { decNumber x; int d, m, y; char buf[16]; char *p; getX(&x); xset(buf, '\0', sizeof(buf)); if (extract_date(&x, &y, &m, &d)) { err(ERR_BAD_DATE); return; } switch (UState.date_mode) { default: p = num_arg(buf, y); *p++ = '-'; p = num_arg_0(p, m, 2); *p++ = '-'; num_arg_0(p, d, 2); break; case DATE_DMY: p = num_arg(buf, d); *p++ = '.'; p = num_arg_0(p, m, 2); *p++ = '.'; num_arg_0(p, y, 4); break; case DATE_MDY: p = num_arg(buf, m); *p++ = '/'; p = num_arg_0(p, d, 2); *p++ ='/'; num_arg_0(p, y, 4); break; } add_string(buf); }
int main(int argc, char **argv) { int ch, mode; char *ptr; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); while ((ch = getopt(argc, argv, "skf:n:")) != EOF) { switch (ch) { case 'f': (void) strcpy(file, optarg); if ((ptr = strrchr(optarg, '/')) == NULL) ptr = optarg; else ptr++; break; case 'n': /* POSIX.2 */ for (ptr = optarg; *ptr != NULL; ptr++) if (!isdigit((int)*ptr)) fatal("-n num\n", NULL); fiwidth = atoi(optarg); break; case 'k': keep++; break; case 's': silent++; break; case '?': errflg++; } } argv = &argv[optind]; argc -= optind; if (argc <= 1 || errflg) usage(); if (strcmp(*argv, "-") == 0) { infile = tmpfile(); while (fread(tmpbuf, 1, BUFSIZ, stdin) != 0) { if (fwrite(tmpbuf, 1, BUFSIZ, infile) == 0) if (errno == ENOSPC) { (void) fprintf(stderr, "csplit: "); (void) fprintf(stderr, gettext( "No space left on device\n")); exit(1); } else { (void) fprintf(stderr, "csplit: "); (void) fprintf(stderr, gettext( "Bad write to temporary " "file\n")); exit(1); } /* clear the buffer to get correct size when writing buffer */ (void) memset(tmpbuf, '\0', sizeof (tmpbuf)); } rewind(infile); } else if ((infile = fopen(*argv, "r")) == NULL) fatal("Cannot open %s\n", *argv); ++argv; curline = (offset_t)1; (void) signal(SIGINT, sig); /* * The following for loop handles the different argument types. * A switch is performed on the first character of the argument * and each case calls the appropriate argument handling routine. */ for (; *argv; ++argv) { targ = *argv; switch (**argv) { case '/': mode = EXPMODE; create = TRUE; re_arg(*argv); break; case '%': mode = EXPMODE; create = FALSE; re_arg(*argv); break; case '{': num_arg(*argv, mode); mode = FALSE; break; default: mode = LINMODE; create = TRUE; line_arg(*argv); break; } } create = TRUE; to_line(LAST); return (0); }
int strn_len(const char *buffer, unsigned int maxlen) { int i=0; for(; i<maxlen;i++) switch(buffer[i]) { case '\"': case '\n': case '\r': case '\t': case ' ': goto done_str; default: } done_str: return i; } int proc_pg_write(struct file *file, const char *buffer, unsigned long count, void *data) { int i=0, max, len; char name[16], valstr[32]; unsigned long value = 0; if (count < 1) { sprintf(pg_result, "Wrong command format"); return -EINVAL; } max = count -i; i += count_trail_chars(&buffer[i], max); /* Read variable name */ len = strn_len(&buffer[i], sizeof(name)-1); memset(name, 0, sizeof(name)); strncpy(name, &buffer[i], len); i += len; max = count -i; len = count_trail_chars(&buffer[i], max); i += len; if (debug) printk("pg: %s,%lu\n", name, count); /* Only stop is allowed when we are running */ if(!strcmp(name, "stop")) { forced_stop=1; if (pg_busy) strcpy(pg_result, "Stopping"); return count; } if (pg_busy) { strcpy(pg_result, "Busy"); return -EINVAL; } if(!strcmp(name, "pkt_size")) { len = num_arg(&buffer[i], 10, &value); i += len; if (value < 14+20+8) value = 14+20+8; pkt_size = value; sprintf(pg_result, "OK: pkt_size=%u", pkt_size); return count; } if(!strcmp(name, "frags")) { len = num_arg(&buffer[i], 10, &value); i += len; nfrags = value; sprintf(pg_result, "OK: frags=%u", nfrags); return count; } if(!strcmp(name, "ipg")) { len = num_arg(&buffer[i], 10, &value); i += len; pg_ipg = value; sprintf(pg_result, "OK: ipg=%u", pg_ipg); return count; } if(!strcmp(name, "count")) { len = num_arg(&buffer[i], 10, &value); i += len; pg_count = value; sprintf(pg_result, "OK: count=%u", pg_count); return count; } if(!strcmp(name, "odev")) { len = strn_len(&buffer[i], sizeof(pg_outdev)-1); memset(pg_outdev, 0, sizeof(pg_outdev)); strncpy(pg_outdev, &buffer[i], len); i += len; sprintf(pg_result, "OK: odev=%s", pg_outdev); return count; } if(!strcmp(name, "dst")) { len = strn_len(&buffer[i], sizeof(pg_dst)-1); memset(pg_dst, 0, sizeof(pg_dst)); strncpy(pg_dst, &buffer[i], len); if(debug) printk("pg: dst set to: %s\n", pg_dst); i += len; sprintf(pg_result, "OK: dst=%s", pg_dst); return count; } if(!strcmp(name, "dstmac")) { char *v = valstr; unsigned char *m = pg_dstmac; len = strn_len(&buffer[i], sizeof(valstr)-1); memset(valstr, 0, sizeof(valstr)); strncpy(valstr, &buffer[i], len); i += len; for(*m = 0;*v && m < pg_dstmac+6;v++) { if(*v >= '0' && *v <= '9') { *m *= 16; *m += *v - '0'; } if(*v >= 'A' && *v <= 'F') { *m *= 16; *m += *v - 'A' + 10; } if(*v >= 'a' && *v <= 'f') { *m *= 16; *m += *v - 'a' + 10; } if(*v == ':') { m++; *m = 0; } } sprintf(pg_result, "OK: dstmac"); return count; } if (!strcmp(name, "inject") || !strcmp(name, "start") ) { MOD_INC_USE_COUNT; pg_busy = 1; strcpy(pg_result, "Starting"); pg_inject(); pg_busy = 0; MOD_DEC_USE_COUNT; return count; } sprintf(pg_result, "No such parameter \"%s\"", name); return -EINVAL; }