Esempio n. 1
0
/*
 * Grab the filename of COMMAND.COM
 *
 *  If warn != 0, warnings can be issued; otherwise this functions
 *  is silent.
 */
void grabComFilename(int warn, char far *fnam)
{
  char *buf;
  size_t len;

  assert(fnam);

  /* Copy the filename into the local heap */
  len = _fstrlen(fnam);
  if(len >= INT_MAX || len < 1) {
    /* no filename specified */
    if(warn)
      error_syntax(NULL);
    return;
  }

  if((buf = malloc(len + 1)) == NULL) {
    if(warn) error_out_of_memory();
    return ;
  }
  _fmemcpy((char far*)buf, fnam, len);
  buf[len] = '\0';

    if (buf[1] != ':' || buf[2] != '\\')
    { char *p;

        /* expand the string for the user */
      p = dfnexpand(buf, NULL);
      free(buf);
      if((buf = p) == NULL) {
		  if(warn) error_out_of_memory();
		  return;
      }
      if(warn)
          error_init_fully_qualified(buf);
    }

    if(dfnstat(buf) & DFN_DIRECTORY) {
      /* The user specified a directory, try if we can find the
        COMMAND.COM with the standard name in there */
      char *p;

      if((p = realloc(buf, len + sizeof(COM_NAME) + 1)) == NULL) {
        if(warn) error_out_of_memory();
        free(buf);
        return;
      }
      buf = p;
      strcpy(&buf[len], "\\" COM_NAME);
    }

    if(!(dfnstat(buf) & DFN_FILE)) {
      /* not found */
      if(warn) error_open_file(buf);
      free(buf);
      return;
    }

  free(ComPath);    /* Save the found file */
  ComPath = buf;
}
Esempio n. 2
0
int grabComFilename(const int warn, const char far * const fnam)
{
    char *buf;
    size_t len;
    int rc;

    dprintf( ("[INIT: grabComFilename(%s)]\n", fnam) );
    if(!fnam)
        return 4;

    /* Copy the filename into the local heap */
    len = _fstrlen(fnam);
    if(len >= INT_MAX || len < 1) {
        /* no filename specified */
        if(warn)
            error_syntax(0);
        return 4;
    }

    if((buf = malloc(len + 1)) == 0) {
        if(warn) error_out_of_memory();
        return 4;
    }
    _fmemcpy((char far*)buf, fnam, len);
    buf[len] = '\0';

    if (buf[1] != ':' || buf[2] != '\\')
    {   char *p;

        /* expand the string for the user */
        p = abspath(buf, warn);
        free(buf);
        if((buf = p) == 0)
            return 4;
        if(warn)
            error_init_fully_qualified(buf);

        len = strlen(buf);
    }

    while(buf[len - 1] == '\\')
        --len;
    buf[len] = 0;

    if(dfnstat(buf) & DFN_DIRECTORY) {
        /* The user specified a directory, try if we can find the
          COMMAND.COM with the standard name in there */
        char *p;

        if((p = realloc(buf, len + sizeof(COM_NAME) + 1)) == 0) {
            if(warn) error_out_of_memory();
            free(buf);
            return 4;
        }
        buf = p;
        strcpy(&buf[len], "\\" COM_NAME);
    }


    if(0 != (rc = validResFile(buf))) {
        if(warn) switch(rc) {
            default:
#ifdef NDEBUG
                assert(0);
#endif
            case 1:
                error_open_file(buf);
                break;
            case 2:
                error_fcom_is_device(buf);
                break;
            case 3:
                error_fcom_invalid(buf);
                break;
            }

        free(buf);
        return rc;
    }

    free(ComPath);    /* Save the found file */
    ComPath = buf;
    dprintf(("[INIT: new resource file name: %s]\n", ComPath));

    isSwapFile = 0;
    buf = dfnfilename(ComPath);
    assert(buf);
    if((buf = strchr(buf, '.')) != 0
            && stricmp(buf, ".swp") == 0) {
        dprintf(("[INIT: VSpawn file found: %s]\n", ComPath));
        memcpy(++buf, "COM", 3);
        isSwapFile = buf - ComPath;
    }

    return 0;
}