Exemple #1
0
void
xtr_flac_c::create_file(xtr_base_c *_master,
                        KaxTrackEntry &track) {
  KaxCodecPrivate *priv = FINDFIRST(&track, KaxCodecPrivate);
  if (NULL == priv)
    mxerror(boost::format(Y("Track %1% with the CodecID '%2%' is missing the \"codec private\" element and cannot be extracted.\n")) % m_tid % m_codec_id);

  xtr_base_c::create_file(_master, track);

  memory_cptr mpriv = decode_codec_private(priv);
  m_out->write(mpriv);
}
Exemple #2
0
void
xtr_oggbase_c::create_standard_file(xtr_base_c *master,
                                    KaxTrackEntry &track) {
  KaxCodecPrivate *priv = FINDFIRST(&track, KaxCodecPrivate);
  if (NULL == priv)
    mxerror(boost::format(Y("Track %1% with the CodecID '%2%' is missing the \"codec private\" element and cannot be extracted.\n")) % m_tid % m_codec_id);

  init_content_decoder(track);
  memory_cptr mpriv = decode_codec_private(priv);

  std::vector<memory_cptr> header_packets;
  try {
    header_packets = unlace_memory_xiph(mpriv);

    if (header_packets.empty())
      throw false;

    header_packets_unlaced(header_packets);

  } catch (...) {
    mxerror(boost::format(Y("Track %1% with the CodecID '%2%' does not contain valid headers.\n")) % m_tid % m_codec_id);
  }

  xtr_oggbase_c::create_file(master, track);

  ogg_packet op;
  for (m_packetno = 0; header_packets.size() > m_packetno; ++m_packetno) {
    // Handle all the header packets: ID header, comments, etc
    op.b_o_s      = (0 == m_packetno ? 1 : 0);
    op.e_o_s      = 0;
    op.packetno   = m_packetno;
    op.packet     = header_packets[m_packetno]->get_buffer();
    op.bytes      = header_packets[m_packetno]->get_size();
    op.granulepos = 0;
    ogg_stream_packetin(&m_os, &op);

    if (0 == m_packetno) /* ID header must be alone on a separate page */
      flush_pages();
  }

  /* flush at last header, data must start on a new page */
  flush_pages();
}
Exemple #3
0
void complete_filename(char *str, unsigned charcount)
{
  /* variables found within code */
  struct ffblk file;
  #undef ffblk

  int found_dot = 0;
  int curplace = 0;
  int start;
  int count;
  int perfectmatch = 1;
  int makelower;
  char path[128];
  char fname[14];
  char maxmatch[13] = "";
  char directory[128];

  assert(str);

  /* expand current file name */
  count = charcount - 1;
  if (count < 0)
    makelower = count = 0;
  else
  {
    /* if last character is lower case, then make lookup lower case. */
    makelower = islower(str[count]);
  }

  while (count > 0 && str[count] != ' ')  /* find front of word */

    count--;

  if (str[count] == ' ')        /* if not at beginning, go forward 1 */

    count++;

  start = count;

  /* extract directory from word */
  strcpy(directory, &str[start]);
  curplace = strlen(directory) - 1;
  while (curplace >= 0 && directory[curplace] != '\\' &&
         directory[curplace] != ':')
  {
    directory[curplace] = 0;
    curplace--;
  }

  strcpy(path, &str[start]);

  /* look for a . in the filename */
  for (count = strlen(directory); path[count] != 0; count++)
    if (path[count] == '.')
    {
      found_dot = 1;
      break;
    }
  if (found_dot)
    strcat(path, "*");
  else
    strcat(path, "*.*");

  curplace = 0;                 /* current fname */

#ifdef FEATURE_LONG_FILENAMES
  if( lfncomplete ? lfnfindfirst( path, &file, FILE_SEARCH_MODE ) == 0 :
                    findfirst( path, ( struct ffblk * )&file, FILE_SEARCH_MODE )
                    == 0 )
#else
  if (FINDFIRST(path, &file, FILE_SEARCH_MODE) == 0)
#endif
  {                             /* find anything */

    do
    {
      if (file.ff_name[0] == '.' &&
          (!file.ff_name[1] ||
          (file.ff_name[1] == '.' && !file.ff_name[2]))) /* ignore . and .. */

        continue;

      strcpy(fname, file.ff_name);
      if (makelower)
        strlwr(fname);

      if (file.ff_attrib == FA_DIREC)
        strcat(fname, "\\");
      else
        strcat(fname, " ");

      if (!maxmatch[0] && perfectmatch)
        strcpy(maxmatch, fname);

      else
      {
        for (count = 0; maxmatch[count] && fname[count]; count++)
          if (maxmatch[count] != fname[count])
          {
            perfectmatch = 0;
            maxmatch[count] = 0;
            break;
          }
      }
    }
#ifdef FEATURE_LONG_FILENAMES
    while( lfncomplete ? lfnfindnext( &file ) == 0 :
                         findnext( ( struct ffblk * )&file ) == 0 );
#else
    while (FINDNEXT(&file) == 0);
#endif
    FINDSTOP(&file);

    strcpy(&str[start], directory);
    strcat(&str[start], maxmatch);

    if (!perfectmatch)
      beep();
  }
  else                          /* no match found */
    beep();
}
Exemple #4
0
char *readbatchline(int *eflag, char *textline, int size)
{
  /*
   * Read and return the next executable line from the current batch file
   *
   * If no batch file is current or no further executable lines are found
   * return NULL.
   *
   * Here we also look out for FOR bcontext structures which trigger the
   * FOR expansion code.
   *
   * Set eflag to 0 if line is not to be echoed else 1
   */

  char *first;
  char *ip;

  if (bc == 0)               /* No batch */
    return 0;

  dprintf(("readbatchline ()\n"));
  assert(textline);
  assert(size > 1);
  assert(eflag);

  ip = "";                      /* make sure ip != NULL in the first
  									iteration of the loop */
  while (bc)
  {
    first = 0;               /* by default return "no file" */

    if (bc->forvar)             /* If its a FOR context... */
    {
      int forvarlen;
      char
       *fv1,
       *sp,      /* pointer to prototype command */
       *dp,          /* Place to expand protoype */
       *fv;				       /* Next list element */

      if (chkCBreak(BREAK_FORCMD) || bc->shiftlevel > bc->numParams)
        /* End of list or User break so... */
      {
        exit_batch();           /* just exit this context */
        continue;
      }

      fv1 = fv = getArgCur(0);

	if (bc->ffind) {          /* First already done fo do next */
		if(FINDNEXT(bc->ffind) != 0) {		/* no next file */
          free(bc->ffind);      /* free the buffer */
          bc->ffind = 0;
          bc->shiftlevel++;     /* On to next list element */
          continue;
        }
	  fv = bc->ffind->ff_name;
	} else
	{
      if (strpbrk(fv, "?*") == 0) {      /* element is not wild file */
        bc->shiftlevel++;       /* No -> use it and shift list */
        fv1 = "";				/* No additional info */
      } else
        /* Wild file spec, find first (or next) file name */
      {

	  /*  For first find, allocate a find first block */
          if ((bc->ffind = (struct ffblk *)malloc(sizeof(struct ffblk)))
           == 0)
          {
            error_out_of_memory();
            exit_batch();		/* kill this FOR context */
            break;
          }

         if(FINDFIRST(fv, bc->ffind, FA_NORMAL) == 0) {
         	/* found a file */
         	*dfnfilename(fv) = '\0';	/* extract path */
        	fv = bc->ffind->ff_name;
         } else {			/* if not found use the string itself */
#if 0
			/* To use the pattern is not compatible with MS COMMAND */
			++bc->shiftlevel;
			fv1 = "";				/* No additional info */
#else
          free(bc->ffind);      /* free the buffer */
          bc->ffind = 0;
          bc->shiftlevel++;     /* On to next list element */
          continue;
#endif
        }

      }
      }

      /* At this point, fv points to parameter string */
      /* fv1 is the string usually set to the path to the
      	found file, otherwise it points to "" */

       sp = bc->forproto;      /* pointer to prototype command */
       dp = textline;          /* Place to expand protoype */

       assert(sp);
       assert(bc->forvar);

      forvarlen = strlen(bc->forvar);
      while (*sp)
      {
        if (memcmp(sp, bc->forvar, forvarlen) == 0)
          dp = stpcpy(stpcpy(dp, fv1), fv), sp += forvarlen;
        else
          *dp++ = *sp++;        /* Else just copy */
      }

      *dp = '\0';

      assert(dp - textline <= size);

      *eflag = echo;

      first = textline;
      break;
    }

    if (!bc->bfile)
    {                           /* modifyable batchfiles */
      if ((bc->bfile = fopen(bc->bfnam, "rt")) == 0)
      {
        error_bfile_vanished(bc->bfnam);
        exit_batch();
        continue;
      }
      bc->bclose = 1;
      if (bc->brewind)
      {
        bc->brewind = 0;        /* fopen() position at start of file */
        bc->blinecnt = 0;
      }
      else if (fsetpos(bc->bfile, &bc->bpos))
      {                         /* end of file reached */
        /* so says MS COMMAND */
        exit_batch();
        continue;
      }
    }
    else if(bc->brewind) {
    	rewind(bc->bfile);
    	bc->brewind = 0;
    	bc->blinecnt = 0;
    }

    assert(ip != 0);
    ++bc->blinecnt;
    if (chkCBreak(BREAK_BATCHFILE)      /* User break */
        || fgets(textline, size, bc->bfile) == 0     /* End of file.... */
        || (ip = textlineEnd(textline, size)) == 0)  /* line too long */
    {
      if (!ip)
        error_long_batchline(bc->bfnam, bc->blinecnt);

      exit_batch();

      continue;
    }

    /* Strip leading spaces and trailing space/control chars */
    rtrimsp(textline);
    first = ltrimcl(textline);

    assert(first);

    /* ignore empty lines */
    if (!*first)
      continue;

    if (*first == ':')
    {
      /* if a label is searched for test if we reached it */
      if(bc->blabel) {
        /* label: the 1st word immediately following the colon ':' */
		for(ip = ++first; isgraph(*ip); ++ip)
			;
        *ip = '\0';
        if (stricmp(first, bc->blabel) == 0)
        {                       /* OK found */
          free(bc->blabel);
          bc->blabel = 0;
        }
      }
      continue;                 /* ignore label */
    }

    if (bc->blabel)
      continue;                 /* we search for a label! */

    if (*first == '@')          /* don't echo this line */
    {
    	first = ltrimcl(first + 1);
      *eflag = 0;
    }
    else
      *eflag = echo;

    break;
  }

  if (bc && bc->bclose)
  {                             /* modifyable batchfiles - ska */
    fgetpos(bc->bfile, &bc->bpos);
    fclose(bc->bfile);
    bc->bfile = 0;
    bc->bclose = 0;
  }

  return first;
}
Exemple #5
0
void
header_editor_frame_c::handle_tracks(kax_analyzer_data_c *data) {
    m_e_tracks = m_analyzer->read_element(data);
    if (!m_e_tracks)
        return;

    KaxTracks *kax_tracks = static_cast<KaxTracks *>(m_e_tracks.get_object());
    int track_type        = -1;
    size_t i;
    for (i = 0; kax_tracks->ListSize() > i; ++i) {
        KaxTrackEntry *k_track_entry = dynamic_cast<KaxTrackEntry *>((*kax_tracks)[i]);
        if (NULL == k_track_entry)
            continue;

        KaxTrackType *k_track_type = dynamic_cast<KaxTrackType *>(FINDFIRST(k_track_entry, KaxTrackType));
        if (NULL == k_track_type)
            continue;

        unsigned int track_number = 0;
        KaxTrackNumber *k_track_number = dynamic_cast<KaxTrackNumber *>(FINDFIRST(k_track_entry, KaxTrackNumber));
        if (NULL != k_track_number)
            track_number = uint64(*k_track_number);

        wxString title;
        track_type = uint64(*k_track_type);

        he_track_type_page_c *page = new he_track_type_page_c(this, track_type, track_number, m_e_tracks);
        page->init();

        he_value_page_c *child_page;

        child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxTrackNumber::ClassInfos, YT("Track number"),
                YT("The track number as used in the Block Header."));
        child_page->init();

        child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxTrackUID::ClassInfos, YT("Track UID"),
                YT("A unique ID to identify the Track. This should be\nkept the same when making a direct stream copy\nof the Track to another file."));
        child_page->init();

        child_page = new he_bool_value_page_c(this, page, k_track_entry, KaxTrackFlagDefault::ClassInfos, YT("'Default track' flag"),
                                              YT("Set if that track (audio, video or subs) SHOULD\nbe used if no language found matches the\nuser preference."));
        child_page->init();

        child_page = new he_bool_value_page_c(this, page, k_track_entry, KaxTrackFlagEnabled::ClassInfos, YT("'Track enabled' flag"), YT("Set if the track is used."));
        child_page->init();

        child_page = new he_bool_value_page_c(this, page, k_track_entry, KaxTrackFlagForced::ClassInfos, YT("'Forced display' flag"),
                                              YT("Set if that track MUST be used during playback.\n"
                                                      "There can be many forced track for a kind (audio,\nvideo or subs). "
                                                      "The player should select the one\nwhose language matches the user preference or the\ndefault + forced track."));
        child_page->init();

        child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxTrackMinCache::ClassInfos, YT("Minimum cache"),
                YT("The minimum number of frames a player\nshould be able to cache during playback.\n"
                   "If set to 0, the reference pseudo-cache system\nis not used."));
        child_page->init();

        child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxTrackMaxCache::ClassInfos, YT("Maximum cache"),
                YT("The maximum number of frames a player\nshould be able to cache during playback.\n"
                   "If set to 0, the reference pseudo-cache system\nis not used."));
        child_page->init();

        child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxTrackDefaultDuration::ClassInfos, YT("Default duration"),
                YT("Number of nanoseconds (not scaled) per frame."));
        child_page->init();

        child_page = new he_float_value_page_c(this, page, k_track_entry, KaxTrackTimecodeScale::ClassInfos, YT("Timecode scaling"),
                                               YT("The scale to apply on this track to work at normal\nspeed in relation with other tracks "
                                                       "(mostly used\nto adjust video speed when the audio length differs)."));
        child_page->init();

        child_page = new he_string_value_page_c(this, page, k_track_entry, KaxTrackName::ClassInfos, YT("Name"), YT("A human-readable track name."));
        child_page->init();

        child_page = new he_language_value_page_c(this, page, k_track_entry, KaxTrackLanguage::ClassInfos, YT("Language"),
                YT("Specifies the language of the track in the\nMatroska languages form."));
        child_page->init();

        child_page = new he_ascii_string_value_page_c(this, page, k_track_entry, KaxCodecID::ClassInfos, YT("Codec ID"), YT("An ID corresponding to the codec."));
        child_page->init();

        child_page = new he_string_value_page_c(this, page, k_track_entry, KaxCodecName::ClassInfos, YT("Codec name"), YT("A human-readable string specifying the codec."));
        child_page->init();

        if (track_video == track_type) {
            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoPixelWidth::ClassInfos,
                    YT("Video pixel width"), YT("Width of the encoded video frames in pixels."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoPixelHeight::ClassInfos,
                    YT("Video pixel height"), YT("Height of the encoded video frames in pixels."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoDisplayWidth::ClassInfos,
                    YT("Video display width"), YT("Width of the video frames to display."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoDisplayHeight::ClassInfos,
                    YT("Video display height"), YT("Height of the video frames to display."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoDisplayUnit::ClassInfos,
                    YT("Video display unit"), YT("Type of the unit for DisplayWidth/Height\n(0: pixels, 1: centimeters, 2: inches)."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoPixelCropLeft::ClassInfos,
                    YT("Video crop left"), YT("The number of video pixels to remove\non the left of the image."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoPixelCropTop::ClassInfos,
                    YT("Video crop top"), YT("The number of video pixels to remove\non the top of the image."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoPixelCropRight::ClassInfos,
                    YT("Video crop right"), YT("The number of video pixels to remove\non the right of the image."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoPixelCropBottom::ClassInfos,
                    YT("Video crop bottom"), YT("The number of video pixels to remove\non the bottom of the image."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoAspectRatio::ClassInfos, YT("Video aspect ratio type"),
                    YT("Specify the possible modifications to the aspect ratio\n(0: free resizing, 1: keep aspect ratio, 2: fixed)."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxVideoStereoMode::ClassInfos, YT("Video stereo mode"), YT("Stereo-3D video mode (0 - 11, see documentation)."));
            child_page->set_sub_master_callbacks(KaxTrackVideo::ClassInfos);
            child_page->init();

        } else if (track_audio == track_type) {
            child_page = new he_float_value_page_c(this, page, k_track_entry, KaxAudioSamplingFreq::ClassInfos, YT("Audio sampling frequency"), YT("Sampling frequency in Hz."));
            child_page->set_sub_master_callbacks(KaxTrackAudio::ClassInfos);
            child_page->init();

            child_page = new he_float_value_page_c(this, page, k_track_entry, KaxAudioOutputSamplingFreq::ClassInfos,
                                                   YT("Audio output sampling frequency"), YT("Real output sampling frequency in Hz."));
            child_page->set_sub_master_callbacks(KaxTrackAudio::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxAudioChannels::ClassInfos, YT("Audio channels"), YT("Numbers of channels in the track."));
            child_page->set_sub_master_callbacks(KaxTrackAudio::ClassInfos);
            child_page->init();

            child_page = new he_unsigned_integer_value_page_c(this, page, k_track_entry, KaxAudioBitDepth::ClassInfos, YT("Audio bit depth"), YT("Bits per sample, mostly used for PCM."));
            child_page->set_sub_master_callbacks(KaxTrackAudio::ClassInfos);
            child_page->init();
        }

        // m_tc_tree->ExpandAllChildren(page->m_page_id);
    }
}
Exemple #6
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;
}
Exemple #7
0
int copy(char *dst, char *pattern, struct CopySource *src
  , int openMode)
{ char mode[3], *p;
  struct ffblk ff;
  struct CopySource *h;
  char *rDest, *rSrc;
  FILE *fin, *fout;
  int rc, asc;
  char *buf;
  size_t len;

  assert(dst);
  assert(pattern);
  assert(src);

  if(FINDFIRST(pattern, &ff, FA_RDONLY | FA_ARCH) != 0) {
    error_sfile_not_found(pattern);
    return 0;
  }

  mode[2] = '\0';

  do {
    if((rDest = fillFnam(dst, ff.ff_name)) == 0)
      return 0;
    h = src;
    do {  /* to prevent to open a source file for writing, e.g.
          for COPY *.c *.?    */
      if((rSrc = fillFnam(h->fnam, ff.ff_name)) == 0) {
        free(rDest);
        return 0;
      }
      rc = samefile(rDest, rSrc);
      free(rSrc);
      if(rc < 0) {
        error_out_of_memory();
        free(rDest);
        return 0;
      } else if(rc) {
        error_selfcopy(rDest);
        free(rDest);
        return 0;
      }
    } while((h = h->app) != 0);

    if(interactive_command		/* Suppress prompt if in batch file */
     && openMode != 'a' && !optY && (fout = fopen(rDest, "rb")) != 0) {
    	int destIsDevice = isadev(fileno(fout));

      fclose(fout);
      if(!destIsDevice) {	/* Devices do always exist */
      	switch(userprompt(PROMPT_OVERWRITE_FILE, rDest)) {
		default:	/* Error */
		case 4:	/* Quit */
			  free(rDest);
			  return 0;
		case 3:	/* All */
			optY = 1;
		case 1: /* Yes */
			break;
		case 2:	/* No */
			free(rDest);
			continue;
		}
	  }
    }
    if(cbreak) {
      free(rDest);
      return 0;
    }
    mode[0] = openMode;
    mode[1] = 'b';
    if((fout = fdevopen(rDest, mode)) == 0) {
      error_open_file(rDest);
      free(rDest);
      return 0;
    }
    mode[0] = 'r';
    h = src;
    do {
      if((rSrc = fillFnam(h->fnam, ff.ff_name)) == 0) {
        fclose(fout);
        free(rDest);
        return 0;
      }
      mode[1] = (asc = h->flags & ASCII) != 0? 't': 'b';
    reOpenIn:
      if((fin = fdevopen(rSrc, mode)) == 0) {
        error_open_file(rSrc);
        fclose(fout);
        free(rSrc);
        free(rDest);
        return 0;
      }
      if(isadev(fileno(fin)) && mode[1] != 't'
       && (h->flags & BINARY) == 0) {
        /* character devices are opened in textmode
          by default */
        fclose(fin);
        mode[1] = 't';
        goto reOpenIn;
      }

      dispCopy(rSrc, rDest, openMode == 'a' || h != src);
      if(cbreak) {
        fclose(fin);
        fclose(fout);
        free(rSrc);
        free(rDest);
        return 0;
      }

      /* Now copy the file */
      rc = 1;
      if(mode[1] != 't') {    /* binary file */
        if(Fcopy(fout, fin) != 0) {
          if(ferror(fin)) {
            error_read_file(rSrc);
          } else if(ferror(fout)) {
            error_write_file(rDest);
          } else error_copy();
          rc = 0;
        }
      } else {      /* text file, manually transform '\n' */
        if(Fmaxbuf((byte**)&buf, &len) == 0) {
          if(len > INT_MAX)
            len = INT_MAX;
          while(fgets(buf, len, fin)) {
            p = strchr(buf, '\0');
            if(*--p == '\n') {
              *p = '\0';
              fputs(buf, fout);
              putc('\r', fout);
              putc('\n', fout);
            } else
              fputs(buf, fout);
          }
          free(buf);
        } else {
          error_out_of_memory();
          rc = 0;
        }
      }
      if(rc)
        if(ferror(fin)) {
          error_read_file(rSrc);
          rc = 0;
        } else if(ferror(fout)) {
          error_write_file(rDest);
          rc = 0;
        }
      if(cbreak)
        rc = 0;
      fclose(fin);
      free(rSrc);
      if(!rc) {
        fclose(fout);
        free(rDest);
        return 0;
      }
    } while((h = h->app) != 0);
    if(asc) {   /* append the ^Z as we copied in ASCII mode */
      putc(0x1a, fout);
    }
    rc = ferror(fout);
    fclose(fout);
    if(rc) {
      error_write_file(rDest);
      free(rDest);
      return 0;
    }
    free(rDest);
  } while(FINDNEXT(&ff) == 0);

  return 1;
}
Exemple #8
0
void complete_filename(char *str, unsigned charcount)
{
  // variables found within code
  struct ffblk file;

  int found_dot = 0;
  int curplace = 0;
  int start;
  int count;
  int perfectmatch = 1;
  int makelower;
  char path[128];
  char fname[14];
  char maxmatch[13] = "";
  char directory[128];

  assert(str);

  // expand current file name
  count = charcount - 1;
  if (count < 0)
    makelower = count = 0;
  else
  {
    // if last character is lower case, then make lookup lower case.
    makelower = islower(str[count]);
  }

  while (count > 0 && str[count] != ' ')  // find front of word

    count--;

  if (str[count] == ' ')        // if not at beginning, go forward 1

    count++;

  start = count;

  // extract directory from word
  strcpy(directory, &str[start]);
  curplace = strlen(directory) - 1;
  while (curplace >= 0 && directory[curplace] != '\\' &&
         directory[curplace] != ':')
  {
    directory[curplace] = 0;
    curplace--;
  }

  strcpy(path, &str[start]);

  // look for a . in the filename
  for (count = strlen(directory); path[count] != 0; count++)
    if (path[count] == '.')
    {
      found_dot = 1;
      break;
    }
  if (found_dot)
    strcat(path, "*");
  else
    strcat(path, "*.*");

  curplace = 0;                 // current fname

  if (FINDFIRST(path, &file, FILE_SEARCH_MODE) == 0)
  {                             // find anything

    do
    {
      if (file.ff_name[0] == '.') // ignore . and ..

        continue;

      strcpy(fname, file.ff_name);
      if (makelower)
        strlwr(fname);

      if (file.ff_attrib == FA_DIREC)
        strcat(fname, "\\");
      else
        strcat(fname, " ");

      if (!maxmatch[0] && perfectmatch)
        strcpy(maxmatch, fname);

      else
      {
        for (count = 0; maxmatch[count] && fname[count]; count++)
          if (maxmatch[count] != fname[count])
          {
            perfectmatch = 0;
            maxmatch[count] = 0;
            break;
          }
      }
    }
    while (FINDNEXT(&file) == 0);

    strcpy(&str[start], directory);
    strcat(&str[start], maxmatch);

    if (!perfectmatch)
      beep();
  }
  else                          /* no match found */
    beep();
}
Exemple #9
0
/*
 * dir_list
 *
 * list the files in the directory
 */
int dir_list(int pathlen
  , char *pattern
  , unsigned long *dcnt
  , unsigned long *fcnt
  , unsigned long *bcnt
  )
{
  struct ffblk file;
  unsigned long bytecount = 0;
  unsigned long filecount = 0;
  unsigned long dircount = 0;
  int time;
  int count;
  unsigned mode = FA_RDONLY | FA_ARCH | FA_DIREC;
  int rv = E_None;

  assert(path);
  assert(pattern);
  assert(pathlen >= 2);   /* at least root */

  /* if the user wants all files listed */
  if (optA)
    mode |= FA_HIDDEN | FA_SYSTEM;

  /* Search for matching entries */
  path[pathlen - 1] = '\\';
  strcpy(&path[pathlen], pattern);

  if (FINDFIRST(path, &file, mode) == 0) {
  /* moved down here because if we are recursively searching and
   * don't find any files, we don't want just to print
   * Directory of C:\SOMEDIR
   * with nothing else
   */

  if (!optB)
  {
    rv = flush_nl();
    if(rv == E_None) {
	   	/* path without superflous '\' at its end */
	   if(pathlen == 3)     /* root directory */
		 path[pathlen] = '\0';    /* path := path w/o filename */
	   else path[pathlen - 1] = '\0';
            /* /// Changed to exactly match DOS's formatting.  - Ron Cemer */
        printf("%sDirectory of %s\n", (optS ? "" : " "), path);
        if((rv = incline()) == E_None) {
        putchar('\n');
        rv = incline();
    }
   }
  }

/* For counting columns of output */
  count = WIDE_COLUMNS;
  /* if optB && optS the path with trailing backslash is needed,
  	also for optS below do {} while */
  strcpy(&path[pathlen - 1], "\\");

  if(rv == E_None) do {
    assert(strlen(file.ff_name) < 13);

    if (cbreak)
      rv = E_CBreak;
    else {

    if (optL)
      strlwr(file.ff_name);

    if (optW)
    {
      char buffer[sizeof(file.ff_name) + 3];

      if (file.ff_attrib & FA_DIREC)
      {
        sprintf(buffer, "[%s]", file.ff_name);
        dircount++;
      }
      else
      {
        strcpy(buffer, file.ff_name);
        filecount++;
      bytecount += file.ff_fsize;
      }
      printf("%-15s", buffer);
      if (!--count)
      {
        /* outputted 5 columns */
        putchar('\n');
        rv = incline();
        count = WIDE_COLUMNS;
      }
    }
    else if (optB)
    {
      if (strcmp(file.ff_name, ".") == 0 || strcmp(file.ff_name, "..") == 0)
        continue;
      if (optS)
        fputs(path, stdout);
      printf("%-13s\n", file.ff_name);
      if (file.ff_attrib & FA_DIREC)
        dircount++;
      else {
        filecount++;
      bytecount += file.ff_fsize;
      }
      rv = incline();
    }
    else
    {
      char buffer[sizeof(long) * 4 + 2], *ext;

      if (file.ff_name[0] == '.')
        printf("%-13s", file.ff_name);
      else
      {
        ext = strrchr(file.ff_name, '.');
        if (!ext)
          ext = "";
        else
          *ext++ = '\0';

        printf("%-8s %-3s ", file.ff_name, ext);
      }

      if (file.ff_attrib & FA_DIREC)
      {
        printf("%-14s", "  <DIR>");
        dircount++;
      }
      else
      {
        convert(file.ff_fsize, buffer);
        printf("   %10s ", buffer);
        bytecount += file.ff_fsize;
        filecount++;
      }

      printf(" %.2d-%.2d-%02d", ((file.ff_fdate >> 5) & 0x000f),
             (file.ff_fdate & 0x001f), ((file.ff_fdate >> 9) + 80) % 100);
      time = file.ff_ftime >> 5 >> 6;
      printf(" %2d:%.2u%c\n",
             (time == 0 ? 12 : (time <= 12 ? time : time - 12)),
             ((file.ff_ftime >> 5) & 0x003f),
             (time <= 11 ? 'a' : 'p'));

      rv = incline();
    }
   }
  }
  while (rv == E_None && FINDNEXT(&file) == 0);
  }

  if (rv == E_None && optW && (count != 0))
  {
    putchar('\n');
    rv = incline();
  }

  if (rv == E_None)
    if(filecount || dircount)
    {
    /* The code that was here is now in print_summary */
    rv = print_summary(filecount, bytecount);
    }
    else if(!optS)
    {
    error_file_not_found();
    rv = E_Other;
    }

  if(rv == E_None       /* no error */
   && optS) {            /* do recursively */
      /* already set for optB && optS before do {} while above 
		  path[pathlen - 1] = '\\';		*/
      strcpy(&path[pathlen], "*.*");
      if (FINDFIRST(path, &file, mode) == 0) do {
        if((file.ff_attrib & FA_DIREC) != 0 /* is directory */
         && strcmp(file.ff_name, ".") != 0  /* not cur dir */
         && strcmp(file.ff_name, "..") != 0) {  /* not parent dir */
        if (optL)
          strlwr(file.ff_name);
          strcpy(&path[pathlen], file.ff_name);
          rv = dir_list(pathlen + strlen(file.ff_name) + 1, pattern
           , &dircount, &filecount, &bytecount
           );
        }
      } while (rv == E_None && FINDNEXT(&file) == 0);
  }

    *dcnt += dircount;
    *fcnt += filecount;
    *bcnt += bytecount;

  return rv;
}
Exemple #10
0
/*
 * dir_print_header
 *
 * print the header for the dir command
 */
int dir_print_header(int drive)
{
	/* one byte alignment */
#pragma -a-
  struct media_id
  {
    int info_level;
    int serial1;
    int serial2;
    char vol_id[11];
    char file_sys[8];
  }
  media;
	/* standard alignment */
#pragma -a.
  struct ffblk f;
  struct SREGS s;
  union REGS r;
  int currDisk;
  int rv;

  if (cbreak)
    return E_CBreak;

  if (optB)
    return 0;

  currDisk = getdisk();
  if(changeDrive(drive+1) != 0) {
    setdisk(currDisk);
    return 1;
  }

  /* get the media ID of the drive */
/*
   Format of disk info:
   Offset  Size    Description     (Table 01766)
   00h    WORD    0000h (info level)
   02h    DWORD   disk serial number (binary)
   06h 11 BYTEs   volume label or "NO NAME    " if none present
   11h  8 BYTEs   (AL=00h only) filesystem type (see #01767)

 */

  r.x.ax = 0x6900;
  r.x.bx = drive + 1;
  s.ds = FP_SEG(&media);
  r.x.dx = FP_OFF(&media);
  int86x(0x21, &r, &r, &s);

  /* print drive info */
  printf("\n Volume in drive %c", drive + 'A');

  if (FINDFIRST("\\*.*", &f, FA_LABEL) == 0)
  {
        /* Added to remove "." from labels which are longer than
               8 characters (as DOS does). */
    char *dotptr = strchr(f.ff_name, '.');
    if (dotptr != NULL)
    	if(strlen(dotptr + 1))
			memmove(dotptr, dotptr + 1, strlen(dotptr));
		else *dotptr = '\0';		/* dot at end of name */
    printf(" is %s\n", f.ff_name);
  }
  else
  {
    printf(" has no label\n");
  }

  setdisk(currDisk);

  if ((rv = incline()) == 0) {

  /* print the volume serial number if the return was successful */
  if (!r.x.cflag)
  {
    printf(" Volume Serial Number is %04X-%04X\n", media.serial2, media.serial1);
    rv = incline();
  }
  }

        /* Added to exactly match DOS's formatting. */
  if ( (optS) && (rv == 0) ) {
      printf("\n");
      rv = incline();
  }

  return rv;
}
Exemple #11
0
/*
 * dir_print_header
 *
 * print the header for the dir command
 */
int dir_print_header(int drive)
{
#pragma -a-
  struct media_id
  {
    int info_level;
    int serial1;
    int serial2;
    char vol_id[11];
    char file_sys[8];
  }
  media;
#pragma -a.
  struct REGPACK r;
  struct ffblk f;
  int disk;
  int rv;

  if (cbreak)
    return E_CBreak;

  if (optB)
    return 0;

  disk = getdisk();
  if(changeDrive(drive + 1) != 0)
  	return 1;

  /* get the media ID of the drive */
/*
   Format of disk info:
   Offset  Size    Description     (Table 01766)
   00h    WORD    0000h (info level)
   02h    DWORD   disk serial number (binary)
   06h 11 BYTEs   volume label or "NO NAME    " if none present
   11h  8 BYTEs   (AL=00h only) filesystem type (see #01767)

 */

  r.r_ax = 0x6900;
  r.r_bx = 0;
  r.r_ds = FP_SEG(&media);
  r.r_dx = FP_OFF(&media);
  intr(0x21, &r);

  /* print drive info */
  printf("\n Volume in drive %c", drive + 'A');

  if (FINDFIRST("\\*.*", &f, FA_LABEL) == 0)
  {
    printf(" is %s\n", f.ff_name);
  }
  else
  {
    printf(" has no label\n");
  }

  setdisk(disk);

  if ((rv = incline()) == 0) {
	  /* print the volume serial number if the return was successful */
	  if (!r.r_flags & 1)
	  {
		printf(" Volume Serial Number is %04X-%04X\n"
		 , media.serial2, media.serial1);
		rv = incline();
	  }
  }

  return rv;
}