fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <curses.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sdbc_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_u.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sd_bcache.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sd_conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void total_display(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void display_cache(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void wrefresh_file(WINDOW *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int is_dirty(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int dual_stats(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid checkbuf(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid setup_ranges(char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid prheading(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int zero_nic(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef m88k
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define USEC_INIT() usec_ptr = (unsigned int *)timer_init()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define USEC_READ() (*usec_ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !m88k */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define USEC_INIT() USEC_START()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct timeval Usec_time;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int Usec_started = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int higher(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int is_dirty();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int dual_stats();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void total_display();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void display_cache();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void wrefresh_file(WINDOW *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid setup_ranges(char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid prheading(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid checkbuf(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid quit(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid leave(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma does_not_return(quit, leave)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_max_devices = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteUSEC_START()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!Usec_started) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) gettimeofday(&Usec_time, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Usec_started = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic unsigned int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteUSEC_READ()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval tv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!Usec_started)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte USEC_START();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) gettimeofday(&tv, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (unsigned)((tv.tv_sec - Usec_time.tv_sec) * 1000000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte + (tv.tv_usec - Usec_time.tv_usec));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* m88k */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rev_flag = 0; /* Reverse video flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint bold_flg = 0; /* Bold flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint under_flg = 0; /* Underline flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint errflg = 0; /* Error flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint node_sw = 0; /* Per node switch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint toggle_total_sw = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint mirror_sw = 0; /* Dual copy switch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint kmemfd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint delay = 1; /* Display delay (seconds) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetime_t *usec_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetime_t currtime = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint lasttime = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint Elapsed_Time = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *range;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int had_r_option = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint logfd = -1; /* screen output logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int range_num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int screen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int dual_screen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint *on_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint *dual_on_off;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint *updates_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedouble *rate_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint *samples;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_stats_t *cs_cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_stats_t *cs_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_stats_t *cs_persec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lb, ub;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} range_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern range_t ranges[];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_stats_lintmain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_info_t ustats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval tout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd_set readfds;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *errmessage, *ch;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int c, period, prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count = 0, dflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd = fileno(stdin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errmessage = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(argv[0], "sd_stats") != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errmessage = getenv("SD_STATS_USAGE");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errmessage == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errmessage = gettext("Usage: sd_stats [-Mz] "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "[-d delay_time] [-l logfile] [-r range]");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_IOCTL(SDBC_MAXFILES, &sdbc_max_devices,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0, 0, &ustats) == SPCS_S_ERROR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ustats) { /* if SPCS_S_ERROR */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_report(ustats, stderr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&ustats);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("cannot get maxfiles\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte on_off = calloc(sdbc_max_devices, sizeof (int));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dual_on_off = calloc(sdbc_max_devices, sizeof (int));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte updates_prev = calloc(sdbc_max_devices, sizeof (int));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte samples = calloc(sdbc_max_devices, sizeof (int));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rate_prev = calloc(sdbc_max_devices, sizeof (double));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cs_cur = malloc(sizeof (_sd_stats_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cs_prev = malloc(sizeof (_sd_stats_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cs_persec = malloc(sizeof (_sd_stats_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte range = malloc(100);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!on_off || !dual_on_off || !updates_prev || !samples ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !rate_prev || !cs_cur || !cs_prev || !cs_persec || !range) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("no free memory\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *range = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((c = getopt(argc, argv, "DMzd:l:r:h")) != EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev = c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (c) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'd':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay = atoi(optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch = optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*ch != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isdigit(*ch))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'l':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte logfd = open(optarg, O_CREAT|O_WRONLY|O_TRUNC, 0644);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'r':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch = optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*ch != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!isdigit(*ch)) && (*ch != ',') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*ch != ':'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ch++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errflg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte range = realloc((char *)range,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strlen(range) + strlen(optarg) + 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sizeof (char));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (had_r_option)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(range, ",");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(range, optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte had_r_option = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'z':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_IOCTL(SDBC_ZAP_STATS, 0, 0, 0, 0, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &ustats) == SPCS_S_ERROR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ustats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_report(ustats, stderr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&ustats);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'D':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dflag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'M':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror_sw = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'h':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '?':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errflg++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errflg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s\n", errmessage);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (!prev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s\n", errmessage);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(is_dirty());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A few curses routines to setup screen and tty interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) initscr();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) cbreak();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) noecho();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nonl();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) erase();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) clear();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) refresh();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setup_ranges(range);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set signal handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sigset(SIGPIPE, leave);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sigset(SIGINT, leave);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sigset(SIGQUIT, leave);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) signal(SIGFPE, leave);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) signal(SIGSEGV, leave);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte USEC_INIT();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte currtime = USEC_READ();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wait one second before reading the new values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*CONSTCOND*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lasttime = currtime;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte currtime = USEC_READ();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If less that 1 second, force it to one second
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((period = (currtime - lasttime) / 1000000) <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte period = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calculate new per/period values for statistics
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Elapsed_Time += period;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Display new statistics
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prheading(++count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mirror_sw) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dual_stats() < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror_sw = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (toggle_total_sw)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_display();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte display_cache();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) move(0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) refresh();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (logfd > -1) wrefresh_file(stdscr, logfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FD_ZERO(&readfds);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FD_SET(fd, &readfds);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tout.tv_sec = delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tout.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (select(fd + 1, &readfds, (fd_set *)0, (fd_set *)0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &tout) <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((c = getch()) == EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(delay);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte checkbuf(c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tout.tv_sec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) erase();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma error_messages(off, E_STATEMENT_NOT_REACHED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma error_messages(default, E_STATEMENT_NOT_REACHED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecheckbuf(int c)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_info_t ustats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (c) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'b' : /* ctrl b or b -- scroll backward */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 2 :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mirror_sw == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dual_screen > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dual_screen--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (screen > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte screen--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'f' : /* ctrl f or f -- scroll forward */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 6 :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mirror_sw == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dual_screen++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte screen++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 't':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'T':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mirror_sw == 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror_sw = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte toggle_total_sw ^= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '-':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_DOWN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (delay > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) beep();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '+':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_UP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'C':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0xc:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) clearok(stdscr, TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'B':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bold_flg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bold_flg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) attroff(A_BOLD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bold_flg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) attron(A_BOLD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'R':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rev_flag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rev_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) attroff(A_REVERSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rev_flag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) attron(A_REVERSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'z':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_IOCTL(SDBC_ZAP_STATS, 0, 0, 0, 0, 0,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki &ustats) == SPCS_S_ERROR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ustats) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_report(ustats, stderr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&ustats);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'm':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'M':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror_sw = mirror_sw ? 0 : 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) clear();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprheading(int count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_t tim;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print sample count in upper left corner
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) mvprintw(0, 0, "SAMPLE %-8d", count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get time and print it in upper right corner
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tim = time((time_t *)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) mvprintw(0, 79 - 10, "%-8.8s\n", &(ctime(&tim)[11]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteleave(int status)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sigignore(SIGPIPE);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sigignore(SIGALRM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear(); */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) move(LINES, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) refresh();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (logfd > -1) wrefresh_file(stdscr, logfd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte quit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortequit(int status)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) resetterm();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) endwin();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesetup_ranges(char *range)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char chr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char prev_chr = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int after_got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int got_comma = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int after_got_comma = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int number = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prev_num = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (range == NULL || (strlen(range) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].lb = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].ub = sdbc_max_devices - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndx = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_comma = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((chr1 = (range[ndx++])) != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (chr1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '0':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '1':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '2':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '3':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '4':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '5':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '6':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '7':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '8':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case '9':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = number*10 + (chr1 - '0');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ':':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_colon = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ',':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_comma = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default: /* ignore any unknown characters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* switch */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (got_comma && after_got_colon) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte after_got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_comma = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (number >= sdbc_max_devices)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = sdbc_max_devices - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].lb = prev_num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].ub = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (range_num == 99) break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte range_num++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (got_colon && after_got_comma) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte after_got_colon = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte after_got_comma = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (number >= sdbc_max_devices)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = sdbc_max_devices - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_num = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (got_colon) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte after_got_colon = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prev_chr != '\0') && (prev_chr != ':')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (number >= sdbc_max_devices)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = sdbc_max_devices - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_num = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (got_comma) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte got_comma = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte after_got_comma = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte after_got_colon = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (number >= sdbc_max_devices)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = sdbc_max_devices -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((prev_chr != '\0') && (prev_chr != ',')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].lb = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].ub = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (range_num == 99) break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte range_num++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* if */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_chr = chr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (number >= sdbc_max_devices)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte number = sdbc_max_devices - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (after_got_colon) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].lb = prev_num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].ub = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((after_got_comma) && (prev_chr == ','))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte range_num--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].lb = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ranges[range_num].ub = number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}