Esempio n. 1
0
int cmd_verify(char *param)
{
  if (!param || !*param)
    displayString(TEXT_MSG_VERIFY_STATE, getverify()? D_ON : D_OFF);
  else if (stricmp(param, D_OFF) == 0)
    setverify(0);
  else if (stricmp(param, D_ON) == 0)
    setverify(1);
  else
    displayString(TEXT_ERROR_ON_OR_OFF);

  return 0;
}
Esempio n. 2
0
int cmd_verify(char *param)
{
  switch(onoffStr(param)) {
  	default:
		displayString(TEXT_ERROR_ON_OR_OFF);
		return 1;
	case OO_Null:	case OO_Empty:
		displayString(TEXT_MSG_VERIFY_STATE, getverify() ? D_ON : D_OFF);
		break;
  	case OO_Off:	setverify(0);	break;
  	case OO_On:		setverify(1);	break;
	}
  return 0;
}
Esempio n. 3
0
File: xcopy.c Progetto: FDOS/xcopy
/*-------------------------------------------------------------------------*/
int main(int argc, const char **argv) {
  int fileargc, 
	  switchargc;
  char *fileargv[255],
       *switchargv[255],
       env_prompt[MAXSWITCH],
       tmp_switch[MAXSWITCH] = "",
       src_pathname[MYMAXPATH] = "",
       src_filename[MAXFILE + MAXEXT] = "",
       dest_pathname[MYMAXPATH] = "",
       dest_filename[MAXFILE + MAXEXT] = "",
       *ptr,
       ch;
  int i, length;
  THEDATE dt;
#ifdef __WATCOMC__
  struct dostime_t tm;
#else
  struct time tm;
#endif

  cat = catopen ("xcopy", 0);	/* initialize kitten */

  classify_args(argc, argv, &fileargc, fileargv, &switchargc, switchargv);

  if (fileargc < 1 || switchargv[0] == "?") {
    print_help();
    catclose(cat);
    exit(4);
  }

  if (fileargc > 2) {
    printf("%s\n",catgets(cat, 1, 1, "Invalid number of parameters"));
    catclose(cat);
    exit(4);
  }

  /* activate termination function */
  /* (writes no. of copied files at exit) */
  atexit(exit_fn);

  /* read environment variable COPYCMD to set confirmation switch */
  strmcpy(env_prompt, getenv("COPYCMD"), sizeof(env_prompt));
  if (env_prompt[0] != '\0') {
    strupr(env_prompt);
    if (strcmp(env_prompt, "/Y") == 0)
      /* overwrite existing file(s) */
      switch_confirm = 0;
    else if (strcmp(env_prompt, "/N") == 0)
      /* skip existing file(s) */
      switch_confirm = 1;
    else
      /* ask for confirmation */
      switch_confirm = 2;
  }

  /* get switches */
  for (i = 0; i < switchargc; i++) {
    strmcpy(tmp_switch, switchargv[i], sizeof(tmp_switch));
    strupr(tmp_switch);
    if (strcmp(tmp_switch, "A") == 0)
      switch_archive = -1;
    else if (strcmp(tmp_switch, "C") == 0)
      switch_continue = -1;
    else if (strcmp(tmp_switch, "D") == 0)
      switch_date = -1;
    else if (strncmp(tmp_switch, "D:", 2) == 0) {
      if (strtodate(tmp_switch+2, &dt) != 0 ||
          !datevalid(&dt)) {
        printf("%s\n",catgets(cat, 1, 2, "Invalid date"));
        catclose(cat);
        exit(4);
      }
#ifdef __WATCOMC__
      memset((void *)&tm, 0, sizeof(struct dostime_t));
      /* tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_hund = 0; */
#else
      memset((void *)&tm, 0, sizeof(struct time));
      /* tm.ti_hour = 0; tm.ti_min = 0; tm.ti_sec = 0; tm.ti_hund = 0; */
#endif
      switch_date = dostounix(&dt, &tm);
    }
    else if (strcmp(tmp_switch, "E") == 0)
      switch_emptydir = -1;
    else if (strcmp(tmp_switch, "F") == 0)
      switch_fullnames = -1;
    else if (strcmp(tmp_switch, "H") == 0)
      switch_hidden = -1;
    else if (strcmp(tmp_switch, "I") == 0)
      switch_intodir = -1;
    else if (strcmp(tmp_switch, "L") == 0)
      switch_listmode = -1;
    else if (strcmp(tmp_switch, "M") == 0)
      switch_archive_reset = -1;
    else if (strcmp(tmp_switch, "N") == 0)
      switch_confirm = 1;
    else if (strcmp(tmp_switch, "P") == 0)
      switch_prompt = -1;
    else if (strcmp(tmp_switch, "Q") == 0)
      switch_quiet = -1;
    else if (strcmp(tmp_switch, "R") == 0)
      switch_readonly = -1;
    else if (strcmp(tmp_switch, "S") == 0)
      switch_subdir = -1;
    else if (strcmp(tmp_switch, "T") == 0)
      switch_tree = -1;
    else if (strcmp(tmp_switch, "V") == 0) {
      switch_verify = -1;
      bak_verify = getverify();
      setverify(1);
    }
    else if (strcmp(tmp_switch, "W") == 0)
      switch_wait = -1;
    else if (strcmp(tmp_switch, "Y") == 0)
      switch_confirm = 0;
    else if (strcmp(tmp_switch, "-Y") == 0)
      switch_confirm = 2;
    else {
      printf("%s - %s\n", catgets(cat, 1, 3, "Invalid switch"), switchargv[i]);
      catclose(cat);
      exit(4);
    }
  }

  /* get source pathname (with trailing backspace) and filename/-pattern */
  length = strlen(fileargv[0]);
  if (length > (MAXPATH - 1)) {
    printf("%s\n", catgets(cat, 1, 4, "Source path too long"));
    catclose(cat);
    exit(4);
  }
  _fullpath(src_pathname, fileargv[0], MYMAXPATH);
  if (src_pathname[0] == '\0') {
    printf("%s\n", catgets(cat, 1, 5, "Invalid source drive specification"));
    catclose(cat);
    exit(4);
  }
  /* check source path */
  if (!dir_exists(src_pathname)) {
    /* source path contains a filename/-pattern -> separate it */
    ptr = strrchr(src_pathname, *DIR_SEPARATOR);
    ptr++;
    strmcpy(src_filename, ptr, sizeof(src_filename));
    *ptr = '\0';
    if (!dir_exists(src_pathname)) {
      printf("%s - %s\n", catgets(cat, 1, 6, "Source path not found"), src_pathname);
      catclose(cat);
      exit(4);
    }
  }
  else {
    /* source is a directory -> filepattern = "*.*" */
    strmcpy(src_filename, "*.*", sizeof(src_filename));
  }
  cat_separator(src_pathname);
  length = strlen(src_pathname);
  if (length > (MAXDRIVE - 1 + MAXDIR - 1)) {
    printf("%s\n", catgets(cat, 1, 7, "Source path too long"));
    catclose(cat);
    exit(4);
  }

  /* get destination pathname (with trailing backspace) and */
  /* filename/-pattern */
  if (fileargc < 2) {
    /* no destination path specified -> use current */
    getcwd(dest_pathname, MAXPATH);
    strmcpy(dest_filename, "*.*", sizeof(dest_filename));
  }
  else {
    /* destination path specified */
    length = strlen(fileargv[1]);
    if (length > (MAXPATH - 1)) {
      printf("%s\n", catgets(cat, 1, 8, "Destination path too long"));
      catclose(cat);
      exit(4);
    }
    _fullpath(dest_pathname, fileargv[1], MYMAXPATH);
    if (dest_pathname[0] == '\0') {
      printf("%s\n", catgets(cat, 1, 9, "Invalid destination drive specification"));
      catclose(cat);
      exit(4);
    }
    /* check destination path */
    if (fileargv[1][length - 1] != *DIR_SEPARATOR &&
        !dir_exists(dest_pathname)) {
      ptr = strrchr(dest_pathname, *DIR_SEPARATOR);
      ptr++;
      strmcpy(dest_filename, ptr, sizeof(dest_filename));
      *ptr = '\0';
      if ((ptr = strchr(dest_filename, '*')) == NULL &&
          (ptr = strchr(dest_filename, '?')) == NULL) {
        /* last destination entry is not a filepattern -> does it specify */
        /* a file or directory? */
        if (((ptr = strchr(src_filename, '*')) == NULL &&
             (ptr = strchr(src_filename, '?')) == NULL) ||
            !switch_intodir) {
          /* source is a single file or switch /I was not specified -> ask */
          /* user if destination should be a file or a directory */
          printf("%s %s %s\n",
            catgets(cat, 1, 10, "Does"),
            dest_filename,
            catgets(cat, 1, 11, "specify a file name"));
          ch = confirm(
            catgets(cat, 1, 12, "or directory name on the target"),
            catgets(cat, 1, 13, "File"),
            catgets(cat, 1, 14, "Directory"), NULL, NULL);
          switch (ch) {
            case 1: /* 'F' */
              /* file */
              switch_file = -1;
              break;
            case 2: /* 'D' */
              /* directory */
              switch_intodir = -1;
              break;
          }
        }
        if (switch_intodir) {
          /* destination is a directory -> filepattern = "*.*" */
          strmcat(dest_pathname, dest_filename, sizeof(dest_pathname));
          strmcpy(dest_filename, "*.*", sizeof(dest_filename));
        }
      }
    }
    else {
      /* destination is a directory -> filepattern = "*.*" */
      strmcpy(dest_filename, "*.*", sizeof(dest_filename));
    }
  }
  cat_separator(dest_pathname);
  length = strlen(dest_pathname);
  if (length > (MAXDRIVE - 1 + MAXDIR - 1)) {
    printf("%s\n",catgets(cat, 1, 15, "Destination path too long"));
    catclose(cat);
    exit(4);
  }

  /* check for cyclic path */
  if ((switch_emptydir || switch_subdir) &&
      cyclic_path(src_pathname, dest_pathname)) {
    printf("%s\n",catgets(cat, 1, 16, "Cannot perform a cyclic copy"));
    catclose(cat);
    exit(4);
  }

  /* get destination drive (1 = A, 2 = B, 3 = C, ...) */
  dest_drive = toupper(dest_pathname[0]) - 64;

  if (switch_wait) {
    printf("%s\n",catgets(cat, 1, 17, "Press enter to continue..."));
    (void)getchar(); /* getch(); would need conio.h */
    fflush(stdin);
  }

  xcopy_files(src_pathname, src_filename, dest_pathname, dest_filename);
  if (!file_found) {
    printf("%s - %s\n",catgets(cat, 1, 18, "File not found"), src_filename);
    catclose(cat);
    exit(1);
  }

  catclose(cat);
  return 0;
}