DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T c

⟦91d16802e⟧ TextFile

    Length: 5735 (0x1667)
    Types: TextFile
    Names: »ccmd.c«

Derivation

└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
    └─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z« 
        └─⟦946c717da⟧ 
            └─⟦this⟧ »ccmd.c« 

TextFile

/* 
 * Copyright (c) 1988 Michael A. Cooper, University of Southern California.
 * This program may be used, copied, modified, and redistributed freely
 * for noncommercial purposes, so long as this notice remains intact.
 */

#ifndef lint
static char *RCSid = "$Header: ccmd.c,v 4.2 88/07/05 15:58:40 mcooper Exp $";
#endif

/*
 *------------------------------------------------------------------
 *
 * $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/ccmd.c,v $
 * $Revision: 4.2 $
 * $Date: 88/07/05 15:58:40 $
 * $State: Exp $
 *
 *------------------------------------------------------------------
 *
 * Michael A. Cooper
 * Research and Development Group
 * University Computing Services 
 * University of Southern California
 * (mcooper@oberon.USC.EDU)
 *
 *------------------------------------------------------------------
 *
 * $Log:	ccmd.c,v $
 * Revision 4.2  88/07/05  15:58:40  mcooper
 * Added copyright notice.
 * 
 * Revision 4.1  88/06/08  12:38:06  mcooper
 * Shorten opening banner.
 * 
 * Revision 4.0  88/04/20  15:41:38  mcooper
 * Version 4.
 * 
 * Revision 3.2  88/03/02  16:09:39  mcooper
 * Cleanup time.
 * 
 * Revision 3.1  88/03/01  15:48:21  mcooper
 * Cleaned up header files.
 * 
 * Revision 3.0  87/07/24  14:14:45  mcooper
 * Version 3.
 * 
 *------------------------------------------------------------------
 */


#include "defs.h"
#include <signal.h>
#include <sys/file.h>
#include "parse.h"

keywrd ynkeys[] = {
  { "YES", 0, YES },
  { "NO",  0, NO  },
};
keytab yntab = { (sizeof(ynkeys)/sizeof(keywrd)), ynkeys };
fdb ynfdb = { _CMKEY, 0, NULL, (pdat) &yntab, "Answer, ", NULL, NULL };

keywrd ofkeys[] = {
  { "ON",  0, ON  },
  { "OFF", 0, OFF },
};
keytab oftab = { (sizeof(ofkeys)/sizeof(keywrd)), ofkeys };
fdb offdb = { _CMKEY, 0, NULL, (pdat) &oftab, "Boolean, ", NULL, NULL };

fdb tok1fdb = { _CMTOK, 0, NULL, (pdat) "/", NULL, "/", NULL };
fdb tok2fdb = { _CMTOK, 0, NULL, (pdat) ":", NULL, ":", NULL };
fdb tok3fdb = { _CMTOK, 0, NULL, (pdat) "-", NULL, "-", NULL };
fdb tok4fdb = { _CMTOK, 0, NULL, (pdat) "=", NULL, "=", NULL };
fdb numfdb = { _CMNUM, CM_SDH, NULL, (pdat) 10, NULL, NULL, NULL };
fdb cfmfdb = { _CMCFM, 0, NULL, NULL, NULL, NULL, NULL };
fdb wrdfdb = { _CMFLD, CM_SDH, NULL, NULL, NULL, NULL, NULL };
fdb txtfdb = { _CMTXT, CM_SDH, NULL, NULL, NULL, NULL, NULL };


int done = FALSE;

int c_add(), c_list(), c_check(), c_set(), c_help(), c_delete();
int Quit(), Version(), Take();

keywrd full[] = {
  { "Add", KEY_INV, (int) c_add },
  { "Shutdown", 0, (int) c_add },
  { "Check", 0, (int) c_check },
  { "Delete", KEY_INV, (int) c_delete },
  { "Cancel", 0, (int) c_delete },
  { "Help", 0, (int) c_help },
  { "List", 0, (int) c_list },
  { "Quit", 0, (int) Quit },
  { "Exit", KEY_INV, (int) Quit },
  { "Set", 0, (int) c_set },
  { "Take", 0, (int) Take },
  { "Version", 0, (int) Version },
};
keytab fulltab = { (sizeof(full)/sizeof(keywrd)), full };


toplevel()
{
  static fdb cmdfdb = { _CMKEY, 0, NULL, NULL, "Command, ", 
        NULL, NULL };
  extern char command[];
  static int first = TRUE;
  char host[MAXHOSTNAMELEN], *p;

  if (first) {

    cmdfdb._cmdat = (pdat) &(fulltab);

    if (!*command) {
      /* cmcls();  /* clear the screen */
      gethostname(host, sizeof(host));
      p = index(host, '.');
      if (p != NULL) {
	*p = NULL;
      }
      upstr(host);
      printf("UNIX %s on %s -- Version %s.\n", prog, host, version);
    }
  }
    
  while (done == FALSE) {
    cmseter();
    if (cmcsb._cmerr == CMxEOF)
      break;
    if (!*command) {
      prompt(PROMPT);
    } else {
      prompt("");
      fopen("/dev/null", "w+");
      if (cmsti(command, CC_NEC) != CMxOK)
	fprintf(stderr, "Can't stuff buffer\n");
      cmcsb._cmflg |= CM_CFM;	/* mark buffer as confirmed */
      cmcsb._cmbkc = '\n';	/* and this is the confirm char */
    }

    cmsetrp();
    if (*command && !first)
      return;
    first = FALSE;
    parse(&cmdfdb,&val,&used);
    (* (procptr) val._pvint)(FALSE);
    if (*command)
      return;
  }
}

/*
 * Quit - Exit the program.
 */

Quit()
{
  if (iflag) {
    if (prog != NULL)
      noise(prog);
    confirm();
    cmdone();
  }
  exit(0);
}

/*
 * Version - print the version information.
 */

Version()
{
  char buf[BUFSIZ];
  extern char *version;

  strcpy(buf, "of ");
  strcat(buf, prog);
  noise(buf);

  confirm();
  
  prversion();
}

/*
 * Take - take input from file
 */

Take()
{
  cmtake(toplevel);
}

/*
 * c_list - Ccmd list() command 
 */
c_list()
{
  noise("all downtime entries");
  confirm();
  return(listall());
}

/*
 * c_check - Ccmd interface to checktime().
 */
c_check()
{
  noise("all downtime entries");
  confirm();
  return(checktime());
}

/*
 * yes - See if the answer is Yes.
 */
yes(what)
char *what;
{
  char p[BUFSIZ];

  sprintf(p, "%s this entry? ", what);
  prompt(p);
  cmsetrp();
  parse(&ynfdb, &val, &used);

  confirm();

  if (val._pvint == YES) {
    return(TRUE);
  }
  return(FALSE);
}

keywrd dtkeys[MAXENTRIES];
int numdtkeys = 0;
keytab dttab = { 0, dtkeys };
fdb dtfdb = { _CMKEY, 0, NULL, (pdat) &dttab, "Entry Number, ", NULL, NULL };

/*
 * mkdtfdb - Makes a keywrd structure containing all downtime entries.
 */
fdb *
mkdtfdb()
{
  char buf[BUFSIZ];
  int found = FALSE;
  struct downtime *d;

  dtrewind();

  numdtkeys = 0;
  while (d = getdtent()) {
    found = TRUE;
    sprintf(buf, "%d-%s", numdtkeys + 1,
	    mkdate(d->dt_down, D_CCMD));

    dtkeys[numdtkeys]._kwkwd = (char *) xmalloc(strlen(buf)+1);
    strcpy(dtkeys[numdtkeys]._kwkwd, buf);
    dtkeys[numdtkeys]._kwval = (int) d;
    ++numdtkeys;
    dtkeys[numdtkeys]._kwkwd = NULL;
  }

  dttab._ktcnt = numdtkeys;

  if (!found)
    return(NULL);

  return(&dtfdb);
}