Пример #1
0
int main(int argc, char **argv) {
    int i;
    char *old_sys_dir, *new_sys_dir;
    
    if (argc < 4) {
        printf("Usage: kswapsys <old_sys_dir> <new_sys_dir> <swap_path_1>, <swap_path_2>, ...\n");
        return 1;
    }
    
    old_sys_dir = argv[1];
    new_sys_dir = argv[2];
    
    for (i = 0; i < argc - 3; i++) {
        char *swap_dir = argv[i + 3];
        char tmp[512], old_path[512], new_path[512], *swap_name;
        strcpy(tmp, swap_dir);
        swap_name = basename(tmp);
        sprintf(old_path, "%s/%s", old_sys_dir, swap_name);
        sprintf(new_path, "%s/%s", new_sys_dir, swap_name);
        do_swap(swap_dir, old_path);
        do_swap(new_path, swap_dir);
    }
    
    return 0;
}
Пример #2
0
/*
17.6.1.2212 SLITERAL
STRING
Interpretation: Interpretation semantics for this word are undefined.
Compilation: ( c-addr1 u -- )
Append the run-time semantics given below to the current definition.
Run-time: ( -- c-addr2 u )
Return c-addr2u describing a string consisting of the characters specified by c-addr1 u
during compilation. A program shall not alter the returned string.
See: A.17.6.112.0 SLITERAL.
*/
static void do_sliteral(void)
{
/*
: sliteral ( c-addr u -- )
	postpone ahead rot rot
	( save a pointer to the string at runtime)
	here >r
	( copy string to data space)
	2dup here swap cmove
	dup allot align
	rot postpone then
	( compile runtime string address)
	r> postpone literal
	( compile runtime string length)
	postpone literal
	drop ( c-addr)
	; immediate

: str s" sample string" ;
str type cr cr
: stest [ str ] sliteral ;
: stest [ str ] sliteral 1- swap 1+ swap ." string is:" cr cr type cr cr ;

 */
do_ahead(); do_rot(); do_rot();
do_here(); do_to_r();
do_two_dup(); do_here(); do_swap(); do_cmove();
do_dup(); do_allot(); do_align();
do_rot(); do_then();
do_r_from(); do_literal();
do_literal();
do_drop();

}
Пример #3
0
/* "Float down" the element with 1-based index I in ARRAY of CNT
   elements of SIZE bytes each, using COMPARE to compare
   elements, passing AUX as auxiliary data. */
static void
heapify (unsigned char *array, size_t i, size_t cnt, size_t size,
         int (*compare) (const void *, const void *, void *aux),
         void *aux) 
{
  for (;;) 
    {
      /* Set `max' to the index of the largest element among I
         and its children (if any). */
      size_t left = 2 * i;
      size_t right = 2 * i + 1;
      size_t max = i;
      if (left <= cnt && do_compare (array, left, max, size, compare, aux) > 0)
        max = left;
      if (right <= cnt
          && do_compare (array, right, max, size, compare, aux) > 0) 
        max = right;

      /* If the maximum value is already in element I, we're
         done. */
      if (max == i)
        break;

      /* Swap and continue down the heap. */
      do_swap (array, i, max, size);
      i = max;
    }
}
Пример #4
0
    virtual void compress(BufferAllocated& buf, const bool hint)
    {
      // skip null packets
      if (!buf.size())
	return;

      // indicate that we didn't compress
      if (support_swap)
	do_swap(buf, NO_COMPRESS_SWAP);
      else
	buf.push_front(NO_COMPRESS);
    }
Пример #5
0
void swapconf()
{
    register struct file_list *fl;
    struct file_list *do_swap();

    fl = conf_list;
    while (fl) {
        if (fl->f_type != SYSTEMSPEC) {
            fl = fl->f_next;
            continue;
        }
        fl = do_swap(fl);
    }
}
Пример #6
0
// Read block data. Returns:
//   0 ... reading performed normally
//   1 ... reading failed
// Arguments:
//   f           ... pointer to file for reading
//   fileName    ... name of the file
//   debugMode   ... debug messages flag
//   ptr         ... pointer to reserved space for data
//   offset      ... pointer to reserved space size,
//                   increased for current block size
//   itemSize    ... size of one item in block
//   numOfItems  ... number of items in block
//   swap        ... perform endian swap flag
int readBlockData(FILE *f, const char *fileName, int debugMode, void *ptr,
        int *offset, int itemSize, int numOfItems, int swap)
{
    int num = fread(ptr, itemSize, numOfItems, f);
    if(num != numOfItems)
    {
        if(debugMode) fprintf(debugFile,
                "HSpiceRead: failed to read block from file %s.\n",
                fileName);
        return 1;    // Error.
    }
    *offset = *offset + numOfItems;
    if(swap > 0) do_swap((char *)ptr, numOfItems, itemSize);    // Endian swap.
    return 0;
}
/* Possible points : 10
 *
 * Param playlist : a list of songs
 * Param len : the number of songs in the playlist array
 *
 * Sorts the playlist based off of artist, then album, and then title.
 * The do_swap method should be used to determine if two songs should be swapped
 */
void sort(Song playlist[], int len) { 
    int i;
	int j;
	Song temp;
	
	for(i=0;i<len;i++){
		for(j=0;j<len-1;j++){
			if(do_swap(playlist[j], playlist[j+1])==1){
				temp= playlist[ j ];   
				playlist[j]=playlist[ j+1 ]; 
				playlist[j+1]=temp;              
                           	
			}
		}
	}
}
Пример #8
0
int
SimpleSwitch::receive(int port_num, const char *buffer, int len) {
  static int pkt_id = 0;

  // this is a good place to call this, because blocking this thread will not
  // block the processing of existing packet instances, which is a requirement
  if (do_swap() == 0) {
    check_queueing_metadata();
  }

  // we limit the packet buffer to original size + 512 bytes, which means we
  // cannot add more than 512 bytes of header data to the packet, which should
  // be more than enough
  auto packet = new_packet_ptr(port_num, pkt_id++, len,
                               bm::PacketBuffer(len + 512, buffer, len));

  BMELOG(packet_in, *packet);

  PHV *phv = packet->get_phv();
  // many current P4 programs assume this
  // it is also part of the original P4 spec
  phv->reset_metadata();

  // setting standard metadata

  phv->get_field("standard_metadata.ingress_port").set(port_num);
  // using packet register 0 to store length, this register will be updated for
  // each add_header / remove_header primitive call
  packet->set_register(PACKET_LENGTH_REG_IDX, len);
  phv->get_field("standard_metadata.packet_length").set(len);
  Field &f_instance_type = phv->get_field("standard_metadata.instance_type");
  f_instance_type.set(PKT_INSTANCE_TYPE_NORMAL);

  if (phv->has_field("intrinsic_metadata.ingress_global_timestamp")) {
    phv->get_field("intrinsic_metadata.ingress_global_timestamp")
        .set(get_ts().count());
  }

  input_buffer.push_front(std::move(packet));
  return 0;
}
Пример #9
0
/* Sorts ARRAY, which contains CNT elements of SIZE bytes each,
   using COMPARE to compare elements, passing AUX as auxiliary
   data.  When COMPARE is passed a pair of elements A and B,
   respectively, it must return a strcmp()-type result, i.e. less
   than zero if A < B, zero if A == B, greater than zero if A >
   B.  Runs in O(n lg n) time and O(1) space in CNT. */
void
sort (void *array, size_t cnt, size_t size,
      int (*compare) (const void *, const void *, void *aux),
      void *aux) 
{
  size_t i;

  ASSERT (array != NULL || cnt == 0);
  ASSERT (compare != NULL);
  ASSERT (size > 0);

  /* Build a heap. */
  for (i = cnt / 2; i > 0; i--)
    heapify (array, i, cnt, size, compare, aux);

  /* Sort the heap. */
  for (i = cnt; i > 1; i--) 
    {
      do_swap (array, 1, i, size);
      heapify (array, 1, i - 1, size, compare, aux); 
    }
}
Пример #10
0
// Read block header. Returns:
//   -1 ... block header corrupted
//    0 ... endian swap not performed
//    1 ... endian swap performed
// Arguments:
//   f           ... pointer to file for reading
//   fileName    ... name of the file
//   debugMode   ... debug messages flag
//   blockHeader ... array of four integers consisting block header
//   size        ... size of items in block
int readBlockHeader(FILE *f, const char *fileName, int debugMode, int *blockHeader,
        int size)
{
    int swap, num = fread(blockHeader, sizeof(int), blockHeaderSize, f);
    if(num != blockHeaderSize)
    {
        if(debugMode) fprintf(debugFile,
                "HSpiceRead: failed to read block header from file %s.\n",
                fileName);
        return -1;    // Error.
    }

    // Block header check and swap.
    if(blockHeader[0] == 0x00000004 && blockHeader[2] == 0x00000004) swap = 0;
    else if(blockHeader[0] == 0x04000000 && blockHeader[2] == 0x04000000) swap = 1;
    else
    {
        if(debugMode) fprintf(debugFile, "HSpiceRead: corrupted block header.\n");
        return -1;
    }
    if(swap == 1) do_swap((char *)blockHeader, blockHeaderSize, sizeof(int));
    blockHeader[0] = blockHeader[blockHeaderSize - 1] / size;
    return swap;
}
Пример #11
0
// Read block trailer. Returns:
//   0 ... reading performed normally
//   1 ... block trailer corrupted
// Arguments:
//   f           ... pointer to file for reading
//   fileName    ... name of the file
//   debugMode   ... debug messages flag
//   swap        ... perform endian swap flag
//   header      ... block size from header
int readBlockTrailer(FILE *f, const char *fileName, int debugMode, int swap,
        int header)
{
    int trailer, num;
    num = fread(&trailer, sizeof(int), 1, f);
    if(num != 1)
    {
        if(debugMode) fprintf(debugFile,
                "HSpiceRead: failed to read block trailer from file %s.\n",
                fileName);
        return 1;    // Error.
    }
    if(swap > 0) do_swap((char *)(&trailer), 1, sizeof(int));    // Endian swap.

    // Block header and trailer match check.
    if(header != trailer)
    {
        if(debugMode)
            fprintf(debugFile, "HSpiceRead: block header and trailer mismatch.\n");
        return 1;    // Error.
    }

    return 0;
}
Пример #12
0
static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
{
    do_swap(inpicref);
    return ff_filter_frame(link->dst->outputs[0], inpicref);
}
Пример #13
0
static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
{
    AVFrame *picref = ff_default_get_video_buffer(link, w, h);
    do_swap(picref);
    return picref;
}
Пример #14
0
 void swap( factory& other ) { do_swap( other ); }
Пример #15
0
static void do_bracket_defined(void)
{
	/*: [defined] bl word find swap drop 0<> ; immediate */
	do_bl(); do_word(); do_find(); do_swap(); do_drop(); do_zero_not_equals();
}
Пример #16
0
static void do_gcd(void)
/* implements the FORTH word:
: gcd ( n1 n2 | n) begin over mod swap over 0= until nip ;
*/
{ do { do_over(); do_mod(); do_swap(); do_over(); do_zero_not_equals(); } while (sf_pop()); do_nip(); }
  struct X;
  struct Y;
  struct Z;
}

template<class T>
void do_swap(T& t) noexcept(xstd::is_nothrow_swappable<T>::value);

namespace u {
  struct X { };
  struct Y { Y(const Y&); };
  struct Z { Z(Z&&); Z& operator=(Z&&); };
  void swap(Z&, Z&) noexcept;
}

static_assert(noexcept(do_swap(std::declval<u::X&>())), "Error");
static_assert(!noexcept(do_swap(std::declval<u::Y&>())), "Error");
static_assert(noexcept(do_swap(std::declval<u::Z&>())), "Error");

namespace m {
  struct Some {
    friend void swap(Some&, Some&){}
  };

  struct Proxy {
    friend void swap(Some&, Proxy) noexcept {}
  };
  void swap(Proxy, Some&) noexcept;
}

static_assert(!xstd::is_nothrow_swappable<m::Some>::value, "Error");
Пример #18
0
/* Name:    do_mv()
 *
 * Description:
 *
 * This function reads the command line arguments and moves or renames files
 * in an ext2fs file system
 *
 * Algorithm:
 *
 * Read any command line switches
 * Get the first source file specification
 * If we are performing a file swap, call do_swap()
 * Open the file system
 * Get the destination and determine if it is a directory
 *    If not, then get the destination's directory and basename
 *    Also check that the number of source files are no more than one
 * For each source file
 *    Get the directory and basename of the source file
 *    Determine the inode number for the source file
 *    Create the link
 *    Unlink the original source file.
 *
 * Global Variables:
 *
 * None
 *
 * Arguments:
 *
 * int argc;             The number of arguments
 * char *argv[];         The command line arguments
 *
 * Return Values:
 *
 * 0 - the file was move successfully
 * an error occurred.
 *
 * Author: Keith W. Sheffield
 * Date:   03/20/2002
 *
 * Modification History:
 *
 * MM/DD/YY      Name               Description
 */
long
do_mv(int argc, char *argv[])
{
  int verbose=0;
  int force=0;
  int swap_files=0;
  int errcnt=0;
  char *cur_filesys = NULL;
  ext2_filsys fs = NULL;
  ext2_ino_t root;
  ext2_ino_t srcd;
  ext2_ino_t destd;
  ext2_ino_t source_file;
  char *src_dir;
  char *dest_dir;
  char *src_name;
  char *dest_name;
  char *result_name;
  long retval;
  int c;
  int curidx;

#ifdef HAVE_OPTRESET
  optreset = 1;     /* Makes BSD getopt happy */
#endif
  while ((c = getopt(argc, argv, "vfs")) != EOF)
    {
      switch (c)
        {
        case 'v':
          verbose = 1;
          break;
        case 'f':
          force = E2T_FORCE;
          break;
        case 's':
          swap_files = 1;
          break;
        default:
          errcnt++;
          break;
        }
    }

  curidx = optind;

  force |= E2T_DO_MV;

  if (errcnt || argc < curidx+2)
    {
      fputs(USAGE, stderr);
      return(1);
    }

  if (swap_files)
    return(do_swap(force, verbose, curidx, argc, argv));

  cur_filesys = argv[curidx++];
  if (NULL == (src_dir = strchr(cur_filesys, ':')))
    {
      fprintf(stderr, "Invalid file specification: %s\n", cur_filesys);
      return(1);
    }
  *src_dir++ = '\0';

  if ((retval = open_filesystem(cur_filesys, &fs, &root, 1)))
    {
      return retval;
    }


  /* get the destination directory */
  dest_name = NULL;
  if (strcmp(dest_dir = argv[argc-1], ".") != 0)
    {
      /* check to see if the file name already exists in the current
       * directory  and also see if it is a directory.
       */
      if ((retval = ext2fs_namei(fs, root, root, dest_dir, &destd)) ||
          (retval = ext2fs_check_directory(fs, destd)))
        {
          if (retval != EXT2_ET_FILE_NOT_FOUND &&
              retval != EXT2_ET_NO_DIRECTORY)
            {
              fprintf(stderr, "%s\n",error_message(retval));
              ext2fs_close(fs);
              return(retval);
            }

          /* ok, so it's either not there or it's not a directory, so
           * get the real destination directory and file name.
           */
          if (curidx+1 < argc)
            {
              fprintf(stderr, "%s must be a directory!\n", dest_dir);
              ext2fs_close(fs);
              return(1);
            }

          if (get_file_parts(fs, root, dest_dir, &destd, &dest_dir,
                             &dest_name))
            {
              ext2fs_close(fs);
              return(-1);
            }
        }
      else                  /* we have a directory!!! */
        dest_name = NULL;
    }
  else
    {
      destd = root;
      dest_name = NULL;
    }

  do
    {
      /* move to the source directory */
      if (get_file_parts(fs, root, src_dir, &srcd, &src_dir, &src_name))
        {
          ext2fs_close(fs);
          return(-1);
        }

      /* get the inode number for the source file */
      if ((retval = ext2fs_namei(fs, srcd, srcd, src_name, &source_file)))
        {
          fprintf(stderr, "%s: source file %s\n",error_message(retval),
                  src_name);
          ext2fs_close(fs);
          return(retval);
        }

      result_name = (dest_name) ? dest_name : src_name;

      /* now create the link */
      if ((retval = create_hard_link(fs, destd, source_file, result_name,
                                     force)))
        {
          fprintf(stderr, "Error renaming %s/%s as %s/%s\n",
                  ((src_dir == NULL) ? "." : src_dir), src_name,
                  ((dest_dir == NULL) ? "." : dest_dir), result_name);
          ext2fs_close(fs);
          return(1);
        }

      if ((retval = ext2fs_unlink(fs, srcd, src_name, 0, 0)))
        {
          fprintf(stderr, "%s - %s\n", src_name, error_message(retval));
          ext2fs_close(fs);
          return(retval);
        }

      if (verbose)
        fprintf(stderr, "moved %s/%s as %s/%s\n",
                ((src_dir == NULL) ? "." : src_dir), src_name,
                ((dest_dir == NULL) ? "." : dest_dir), result_name);
      src_dir = argv[curidx++];
    }
  while (curidx < argc);

  ext2fs_close(fs);
  return(0);

} /* end of do_mv */