Exemplo n.º 1
0
int cmd_dir(char *rest)
{
  char **argv;
  int argc, opts;
  int rv;                       /* return value */

  /* initialize options */
  optS = optP = optW = optB = optA = optL = 0;

  /* read the parameters from env */
  if ((argv = scanCmdline(getEnv("DIRCMD"), opt_dir, NULL, &argc, &opts))
   == NULL)
    return 1;
  freep(argv);    /* ignore any parameter from env var */

  line = 0;
  /* read the parameters */
  if ((argv = scanCmdline(rest, opt_dir, NULL, &argc, &opts)) == NULL)
    return 1;

  if(argc)
    for(opts = 0
     ; opts < argc && (rv = dir_print_body(argv[opts])) == 0
     ; ++opts)
      ;
  else
    rv = dir_print_body(".");

  if(!rv)
    rv = dir_print_free();

  freep(argv);
  return rv;
}
Exemplo n.º 2
0
int mk_rd_dir(char *param, int (*func) (const char *), char *fctname)
#endif
{       char **argv;
        int argc, opts;
        int rv;

        assert(func);

        if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
                return 1;

        if(argc != 1) {
                error_syntax(0);
                rv = 1;
        } else {
                cutBackslash(argv[0]);

                dprintf(("%s: '%s'\n", fctname, argv[0]));
#ifdef FEATURE_LONG_FILENAMES
        if((rv = lfn_mrc_dir( getshortfilename( argv[0] ), lfnfunc )) != 0)
#else
                if((rv = func(argv[0])) != 0)
#endif
                        error_dirfct_failed(fctname, argv[0]);
        }

        freep(argv);
        return rv;
}
Exemplo n.º 3
0
int cmd_arg(char *param)
{
	char **argv;
	int argc, opts;
	unsigned to_del, base, shiftlevel;

	if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
		return 1;

	/* Because no option was passed into scanCmdline() no
		option can have been processed */
	assert(opts == 0);

	shiftlevel = base = to_del = 0;		/* for argc == 0 */
	if(argc == 0 
	 || argc == 3 && is_num(argv[0], &base) && is_num(argv[1], &to_del)
	     && is_num(argv[2], &shiftlevel) && base <= to_del) {
	     	ctxtPopTo(CTXT_TAG_ARG, to_del);
			gflag_shiftlevel = shiftlevel;
			gflag_base_shiftlevel = base;
			freep(argv);
			return 0;
	}

	error_syntax(0);
	freep(argv);
	return 1;
}
Exemplo n.º 4
0
Arquivo: type.c Projeto: FDOS/freecom
int cmd_type(char *param)
{
    char buf[256];
    char **argv;
    int argc, opts, ec = E_None;
    int fd, len;

    if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
        return 1;

    /* Because no option was passed into scanCmdline() no
    	option can have been processed */
    assert(opts == 0);

    if(!argc) {
        error_req_param_missing();
        ec = E_Useage;
        goto errRet;
    }

    for(argc = 0; argv[argc]; ++argc) {
        if((fd = devopen(argv[argc], O_RDONLY)) == 0) {
            error_sfile_not_found(argv[argc]);
            ec = E_Other;
            break;
        }

        while((len = dos_read(fd, buf, sizeof(buf))) >= 0) {
            char *bufp, *p;
            if(cbreak) {
                dos_close(fd);
                ec = E_CBreak;
                goto errRet;
            }
            bufp = buf;
            for(p = buf; p < buf+len; p++) {
                if(*p == 26) break; /* CTRL-Z */
                if(*p == '\r' || *p == '\n') {
                    if(p > bufp) dos_write(1, bufp, p - bufp);
                    if(*p == '\n') dos_write(1, "\r\n", 2);
                    bufp = p + 1;
                }
            }
            dos_write(1, bufp, p - bufp);
            if (len < sizeof(buf) || *p == 26) break;
        }
        dos_close(fd);
        if(cbreak) {
            ec = E_CBreak;
            break;
        }
    }

errRet:
    freep(argv);

    return ec;
}
Exemplo n.º 5
0
int cmd_ver(char *rest)
{
  char **argv;
  int argc, opts, ec = E_None;

  short_version();

	optR = optW = optD = optC = 0;

  if((argv = scanCmdline(rest, opt_ver, NULL, &argc, &opts)) == NULL)
    return 1;

  /* arguments are simply ignored */

  if(!opts)      /* Basic copyright notice */
    displayString(TEXT_MSG_VER_BASIC);
  else {
  if(optR)
      {                         /* version information */
        union REGS regs;
        regs.h.ah = 0x30;
        intdos(&regs, &regs);
        printf("DOS version %u.%u\n", regs.h.al, regs.h.ah);

        if (regs.h.bh == 0xfd)
        {
          if (regs.h.bl == 0xff)
          {
            printf("FreeDOS kernel (build 1933 or prior)\n",
                   regs.h.ch, regs.h.cl, regs.h.bl);
          }
          else
          {
            printf("FreeDOS kernel version %d.%d.%d\n",
                   regs.h.ch, regs.h.cl, regs.h.bl);
          }
        }
      }
      if (optW)
      {                         /* Warranty notice */
        displayString(TEXT_MSG_VER_WARRANTY);
      }
      if (optD)
      {                         /* Redistribution notice */
        displayString(TEXT_MSG_VER_REDISTRIBUTION);
      }
      if (optC)
      {                         /* Developer listing */
        displayString(TEXT_MSG_VER_DEVELOPERS);
      }
  }

  freep(argv);
  return ec;
}
Exemplo n.º 6
0
int cmd_ver(char *rest)
{
  char **argv;
  int argc, opts, ec = E_None;

  short_version(0);

	optR = optW = optD = optC = 0;

  if((argv = scanCmdline(rest, opt_ver, 0, &argc, &opts)) == 0)
    return 1;

  /* arguments are simply ignored */

  if(optR) {                         /* version information */
        union {
			struct REGPACK r;
			struct BYTEREGS h;
		} regs;
        regs.h.ah = 0x30;
        intr(0x21, &regs.r);
        displayString(TEXT_MSG_VER_DOS_VERSION, regs.h.al, regs.h.ah);

        if (regs.h.bh == 0xfd)
        {
          if (regs.h.bl == 0xff)
          {
          	displayString(TEXT_MSG_VER_EARLY_FREEDOS);
          }
          else
          {
            displayString(TEXT_MSG_VER_LATER_FREEDOS
             , regs.h.ch, regs.h.cl, regs.h.bl);
          }
        }
      }
      if (optW)
      {                         /* Warranty notice */
        displayString(TEXT_MSG_VER_WARRANTY);
      }
      if (optD)
      {                         /* Redistribution notice */
        displayString(TEXT_MSG_VER_REDISTRIBUTION);
      }
      if (optC)
      {                         /* Developer listing */
        displayString(TEXT_MSG_VER_DEVELOPERS);
      }

  freep(argv);
  return ec;
}
Exemplo n.º 7
0
int cmd_type(char *rest)
{
  char buf[256];
  char **argv;
  int argc, opts, ec = E_None;
  FILE *f;

  if((argv = scanCmdline(rest, 0, 0, &argc, &opts)) == 0)
    return 1;

  /* Because no option was passed into scanCmdline() no
    option can have been processed */
  assert(opts == 0);

  if(!argc) {
    error_req_param_missing();
    ec = E_Useage;
    goto errRet;
  }

  for(argc = 0; argv[argc]; ++argc) {
    if ((f = fdevopen(rest, "rt")) == 0)
    {
    error_sfile_not_found(rest);
    ec = E_Other;
    break;
    }

    while (fgets(buf, sizeof(buf), f))
    {
      if(cbreak) {
      fclose(f);
        ec = E_CBreak;
      goto errRet;
    }
    fputs(buf, stdout);
    }
    fclose(f);
    if(cbreak) {
      ec = E_CBreak;
      break;
    }
  }

errRet:
  freep(argv);

  return ec;
}
Exemplo n.º 8
0
static int directory_handler(char *rest,
                      int (*func) (const char *), char *fctname)
{ char **argv, *dir;
  int argc, opts;

  assert(func);

  if((argv = scanCmdline(rest, NULL, NULL, &argc, &opts)) == NULL)
    return 1;


  /* if doing a CD and no parameters given, print out current directory */
  if (func == chdir && argc == 0)
  {
    if((dir = dfnpath(0)) == NULL) {
      error_out_of_memory();
      freep(argv);
      return 1;
    }
    else {
      puts(dir);
      free(dir);
    }
  } else if(argc != 1) {
  error_req_param_missing();
    freep(argv);
    return 1;
  }
  else {
    assert(argv[0]);
    dir = strchr(argv[0], '\0');
  /* take off trailing \ if any, but ONLY if dir is not the root dir */
    if(dir > &argv[0][1] && *--dir == '\\' && dir[-1] != ':')
      *dir = '\0';

    dprintf(("%s: '%s'\n", fctname, argv[0]));
    if (func(argv[0]) != 0)
    {
      perror(fctname);
      freep(argv);
      return 1;
    }
  }

  freep(argv);
  return 0;
}
Exemplo n.º 9
0
int cmd_rename(char *rest)
{ char **argv;
  int argc, opts, ec = E_None;

  if((argv = scanCmdline(rest, 0, 0, &argc, &opts)) == 0)
    return 1;

  if(argc < 2) {
    error_req_param_missing();
    ec = E_Useage;
  }
  else if(argc > 2) {
    error_too_many_parameters(rest);
    ec = E_Useage;
  }
  else if (rename(argv[0], argv[1]) != 0)
  {
    perror("rename");
    ec = E_Other;
  }

  freep(argv);
  return ec;
}
Exemplo n.º 10
0
int cmd_del(char *rest)
{
  int ec = E_None;    /* exit code */
  int i;
  unsigned count = 0;

  struct ffblk f;

  /* Make fullname somewhat larger to ensure that appending
     a matched name, one backslash and one hope. */
  char fullname[MAXPATH + sizeof(f.ff_name) + 2],
   *p, *q;
  int len;

  char **arg;
  int argc, optc;

  /* initialize options */
  optP = 0;

  if((arg = scanCmdline(rest, opt_del, 0, &argc, &optc)) == 0)
    return E_Other;

  if(!argc) {
      error_req_param_missing();
      ec = E_Useage;
     }
  else {
    i = 0;
    do {
      assert(arg[i]);

    /* Get the pattern fully-qualified */
    /* Note: An absolute path always contains:
       A:\\
       --> It's always three bytes long at minimum
       and always contains a backslash */
    p = dfnexpand(arg[i], 0);
    assert(strlen(p) >= 3);
    if ((len = strlen(p)) >= MAXPATH)
    {
      error_filename_too_long(p);
      free(p);
     ec = E_Other;
     goto errRet;
    }
    strcpy(fullname, p);        /* Operating over a local buffer simplifies
                     the process; rather than keep the pattern
                     within dynamic memory */
    free(p);
    p = fullname + len;

    /* check if it is a directory */
    if(dfnstat(fullname) & DFN_DIRECTORY)
    {
      if (p[-1] != '\\')
      *p++ = '\\';
    }

    if (p[-1] == '\\')    /* delete a whole directory */
      p = stpcpy(p, "*.*");

    /* p := address to copy the filename to to form the fully-qualified
     filename */
    /* There is at least one backslash within fullname, because of dfnexpand() */
    while (*--p != '\\') ;
    ++p;

    /* make sure user is sure if all files are to be
     * deleted */
    if (!optP && *p == '*' && ((q = strchr(p, '.')) == 0 || q[1] == '*'))
    {
    displayString(TEXT_MSG_DELETE_ALL);
    if (vcgetcstr("YN\n\r") != 'Y')
    {
      ec = E_Other;
      goto errRet;
    }
    }

    if (FINDFIRST(fullname, &f, FA_ARCH))
    {
    error_sfile_not_found(fullname);
    }
    else do {
    strcpy(p, f.ff_name);       /* Make the full path */

    if (optP)
    {
      printf("%s, Delete(Y/N)?", fullname);
      switch (vcgetcstr("YN\n\r"))
      {
      case '\3':             /* ^Break pressed */
        ec = E_CBreak;
        goto errRet;
      case 'Y':
        break;                /* yes, delete */
      default:
        continue;             /* no, don't delete */
      }
    }
    else if (cbreak) {           /* is also probed for in vcgetstr() */
        ec = E_CBreak;
      goto errRet;
    }

#ifdef NODEL
  /* define NODEL if you want to debug */
    puts(fullname);
#else
    if (unlink(fullname) != 0)
    {
      perror(fullname);   /* notify the user */
    }
    else ++count;
#endif

    } while (FINDNEXT(&f) == 0);
    } while(++i < argc);
  }

errRet:

    if(echo) {
      dispCount(count, "no file", "one file", "%u files");
      puts(" removed.");
    }

    freep(arg);
  return ec;
}
Exemplo n.º 11
0
int cmd_copy(char *rest)
{ char **argv, *p;
  int argc, opts, argi;
  int freeDestFile = 0;
  struct CopySource *h;

  /* Initialize options */
  optA = optB = optV = optY = 0;

  /* read the parameters from env */
  if ((argv = scanCmdline(getEnv("COPYCMD"), opt_copy, 0, &argc, &opts))
   == 0)
    return 1;
  freep(argv);    /* ignore any parameter from env var */

  if((argv = scanCmdline(rest, opt_copy, 0, &argc, &opts)) == 0)
    return 1;

  /* scan the trailing '/a' and '/b' options */
  while(argc > 0 && isoption(argv[argc - 1])) {
    p = argv[--argc];     /* argv[] must not be changed */
    if(leadOptions(&p, opt_copy1, 0) != E_None) {
      freep(argv);
      return 1;
    }
  }

  initContext();

  /* Now parse the remaining arguments into the copy file
    structure */
  for(argi = 0; argi < argc; ++argi)
    if(isoption(p = argv[argi])) {    /* infix /a or /b */
      if(leadOptions(&p, opt_copy1, 0) != E_None) {
        killContext();
        freep(argv);
        return 1;
      }
      /* Change the flags of the previous argument */
      if(lastApp)
        lastApp->flags = cpyFlags();
    } else {            /* real argument */
      if(*p == '+') {       /* to previous argument */
        appendToFile = 1;
        while(*++p == '+');
        if(!*p)
          continue;
      }

      if(!addSource(p)) {
        killContext();
        freep(argv);
        return 1;
      }

    }

  if(appendToFile) {
    error_trailing_plus();
    killContext();
    freep(argv);
    return 1;
  }

  if(!last) {   /* Nothing to do */
    error_nothing_to_do();
    killContext();
    freep(argv);
    return 1;
  }

  assert(head);

  /* Now test if a destination was specified */
  if(head != last && !last->app) {  /* Yeah */
    destFile = dfnexpand(last->fnam, 0);
    if(!destFile) {
      error_out_of_memory();
      goto errRet;
    }
    freeDestFile = 1;
    h = head;         /* remove it from argument list */
    while(h->nxt != last) {
      assert(h->nxt);
      h = h->nxt;
    }
    free(last);
    (last = h)->nxt = 0;
    p = strchr(destFile, '\0') - 1;
    if(*p == '\\' || *p == '/')		/* must be a directory */
    	destIsDir = 1;
    else destIsDir = dfnstat(destFile) & DFN_DIRECTORY;
  } else {              /* Nay */
    destFile = ".";
    destIsDir = 1;
  }

  /* Now copy the files */
  h = head;
  while(copyFiles(h) && (h = h->nxt) != 0);

  if(freeDestFile)
    free(destFile);
errRet:
  killContext();
  freep(argv);
  return 0;
}
Exemplo n.º 12
0
int cd_dir(char *param, int cdd, const char * const fctname)
{	char **argv, *dir;
	int argc, opts;
	int rv, freeDir;

	if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
		return 1;

	freeDir = 0;
	rv = 1;

	/* if doing a CD and no parameters given, print out current directory */
	if(argc == 0) {
		if((dir = cwd(0)) != 0) {
			puts(dir);
			freeDir = 1;
			goto okRet;
		}
		goto errRet;
	} else if(argc != 1) {
		error_syntax(0);
		goto errRet;
	}
	else {
		assert(argv[0]);

#ifdef FEATURE_CDD_FNAME
		/* if path refers to an existing file and not directory, ignore filename portion */
            if (cdd && (dfnstat(argv[0]) & DFN_FILE))
		{
			dir = strrchr(argv[0], '\\');
			if (dir == NULL)
			{
				dir = argv[0];
				if (dir[1] == ':') dir[2]='\0';  /* change drive only, no path */
				else goto okRet;                 /* no drive, no path, so exit early */
			}
			else /* includes a path or refers to root dir */
			{
				*(dir+1) = '\0';
			}
		}
#endif

		dir = strchr(argv[0], '\0');
		/* take off trailing \ if any, but ONLY if dir is not the root dir */
		while(dir > &argv[0][1] && *--dir == '\\' && dir[-1] != ':')
			*dir = '\0';

		dir = argv[0];

#ifdef FEATURE_LAST_DIR
		if(strcmp(dir, "-") == 0) {
			assert(!freeDir);
			/* change to last directory */
			lastDirGet(&dir);
			freeDir = 1;
		}

		lastDirSet();
		if(!dir) 	/* "CD -" without a CD before at all */
			goto okRet;
#endif
		if(*dir && dir[1] == ':') {
			if(cdd) {
				if(changeDrive(*dir) != 0)
					goto errRet;
				if(!dir[2])		/* only change drive */
					goto okRet;
			} else if(!dir[2]) {	/* Real CHDIR displays CWD of
										specified drive */
				assert(freeDir == 0);

				if((dir = cwd(*dir)) != 0) {
					puts(dir);
					freeDir = 1;
					goto okRet;
				}
				goto errRet;
			}
		}
		dprintf(("%s: '%s'\n", fctname, dir));
		if(chdir(dir) != 0) {
			error_dirfct_failed(fctname, dir);
			goto errRet;
		}
	}

okRet:
	rv = 0;
errRet:
	freep(argv);
	if(freeDir)
		free(dir);
	return rv;
}