示例#1
0
int inv(int n,elem_t* a){
	int l=n>>1,r=n-l,i,j;
	int ret=(r>1?(inv(l,a)+inv(r,a+l)):0);
	for (i=j=0;i<=l;_tmp[i+j]=a[i],i++)
		for (ret+=j;j<r&&(i==l||!_cp(a[i],a[l+j]));_tmp[i+j]=a[l+j],j++);
	memcpy(a,_tmp,sizeof(elem_t)*n);
	return ret;
}
示例#2
0
int subseq(int n,elem_t* a){
	int b[MAXN],i,l,r,m,ret=0;
	for (i=0;i<n;b[l]=i++,ret+=(l>ret))
		for (m=((l=1)+(r=ret))>>1;l<=r;m=(l+r)>>1)
			if (_cp(a[b[m]],a[i]))
				l=m+1;
			else
				r=m-1;
	return ret;
}
示例#3
0
文件: cmd.c 项目: lkunemail/coutune
int cp_proc(const char *buf, int fileNo) {
	char arg1[CMDBUF] = "";
	char arg2[CMDBUF] = "";
	
	if (_cp_Arg(buf, arg1, arg2) == -1)
		return(-1);
	if (_cp(arg1, arg2, fileNo) == -1)
		return(-1);
	
	return(0);
}
示例#4
0
int subseq(int n,elem_t* a,elem_t* ans){
	int b[MAXN],p[MAXN],i,l,r,m,ret=0;
	for (i=0;i<n;p[b[l]=i++]=b[l-1],ret+=(l>ret))
		for (m=((l=1)+(r=ret))>>1;l<=r;m=(l+r)>>1)
			if (_cp(a[b[m]],a[i]))
				l=m+1;
			else
				r=m-1;
	for (m=b[i=ret];i;ans[--i]=a[m],m=p[m]);
	return ret;
}
示例#5
0
int cp ()
{
  if (!out[1])
  {
    printf("Usage: cp SRC DEST\n");
    return -1;
  }
  if (!out[2])
  {
    printf("Missing target destination.\n");
    return -2;
  }
  if (strcmp(out[1], out[2]) == 0)
  {
    printf("Cannot copy a file to itself.\n");
    return -3;
  }

  return _cp(out[1], out[2]);
}
示例#6
0
文件: bpdl.c 项目: claytonkb/Babel
mword *inline_bpdl_label_list(bvm_cache *this_bvm, mword *sexpr){ // inline_bpdl_label_list#

    mword *sexpr_label = (mword*)icar(sexpr);

    if(bpdl_is_label_nil(sexpr_label)){
        return nil;
    }

    mword *macro_code_list;
    mword *bpdl_list;
    mword *result = nil;
    mword *bpdl_label = _lf2by(this_bvm, sexpr_label);
    mword *bpdl_label_hash = _hash8(this_bvm,bpdl_label);

    if(trie_exists(this_bvm, bpdl_macro_table, bpdl_label_hash, nil)){

        bpdl_list = inline_bpdl_list_list(this_bvm, (mword *)icdr(sexpr));

        macro_code_list =
            _cons( this_bvm, 
                    _cp( this_bvm, _ith( this_bvm, trie_lookup_hash(this_bvm, bpdl_macro_table, bpdl_label_hash, nil), 2) ),
                    nil);

//        result = lib_babelc(this_bvm, (mword*)icar(macro_code_list), bpdl_list); 
        result = lib_babelcs(this_bvm, (mword*)icar(macro_code_list), bpdl_list, this_bvm->soft_root); 

    }
    else{

        _fatal("Unrecognized label-list"); //FIXME Throw exception

    }

    return result;

}
示例#7
0
void QGIPiece::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
{
    if(0)
    { // for me this only works in GL mode
	QPen linePen(Qt::red, 4, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
	paintLinesToChildren( this, painter, linePen );
    }
    /**
       Using a pixmap cache for the rendering saves a lot of repainting,
       but it causes rounding errors because QPixmap is int-based.
       The borders don't show up properly (off-by-one errors) at certain
       sizes and scales.
    */

    QRectF bounds( this->boundingRect().normalized() );
#define AMSG if(0) qDebug() << "QGIPixmap::paint():"
    if( 
#if QGIPiece_USE_PIXCACHE
       impl->pixcache.isNull()
#else
       1
#endif
       )
    {
	++impl->countRepaint;
	QPainter * cp = 0;
#if QGIPiece_USE_PIXCACHE
	QPixmap captcha( bounds.size().toSize() );
	AMSG << "bounds="<<bounds<<", pixcache.size ="<<captcha.size();
	captcha.fill( Qt::transparent );
	QPainter _cp( &captcha );
	cp = &_cp;
#else
	cp = painter;
#endif
	if( 1 ) // Background color
	{
	    QColor col = impl->pen.color();
	    if( col.isValid() )
	    {
		cp->fillRect( bounds, col );
	    }
	}
	const qreal bs = impl->penB.widthF();
	qreal xl = bs / 2.0;

	if( ! impl->pixmap.isNull() ) // Draw pixmap
	{
	    // Weird: if i use impl->pixmap.rect() i get (0.5,0.5,W,H)
	    QRectF pmr( QPointF(0,0), impl->pixmap.size() );
	    //QRectF pmr( impl->pixmap.rect() );
	    AMSG << "drawPixmap("<<pmr<<"...)";
	    cp->drawPixmap(pmr, impl->pixmap, impl->pixmap.rect() );
	}

	if( bs && impl->penB.color().isValid() ) // Draw border
	{
	    QRectF br( bounds );
	    br.adjust( xl, xl, -xl, -xl );
#if QGIPiece_USE_PIXCACHE
 	    if( (int(bs+0.49) % 2) == 1 )
 	    { // kludge to avoid some off-by-one unsightlyness
		qreal fudge = 0.5;
 		br.adjust( -fudge, -fudge, -fudge, -fudge );
 	    }
#endif
	    cp->save();
	    cp->setPen( impl->penB );
	    AMSG << "drawRect("<<br<<"...) bs ="<<bs<<", xl ="<<xl;;
	    cp->drawRect( br );
	    cp->restore();
	}
#if QGIPiece_USE_PIXCACHE
	impl->pixcache = captcha;
#endif
    }
    else
    {
	++impl->countPaintCache;
	if(0) AMSG << "using cached image.";
    }
#if QGIPiece_USE_PIXCACHE
    painter->drawPixmap( bounds, impl->pixcache, bounds );
#endif
    // Let parent draw selection borders and such:
    this->QGraphicsPixmapItem::paint(painter,option,widget);
#undef AMSG
}
示例#8
0
cUser::cUser(const cUser& __o) : cRecord()
{
    _cp(__o);
    _privilegeLevel = __o._privilegeLevel;
}
示例#9
0
int mv ()
{
  if (!out[1])
  {
    printf("Usage: cp SRC DEST\n");
    return -1;
  }
  if (!out[2])
  {
    printf("Missing target destination.\n");
    return -2;
  }
  if (strcmp(out[1], out[2]) == 0)
  {
    printf("Cannot move a file into itself.\n");
    return -3;
  }

  int ino, p_ino, sp_ino, src_dev = running->cwd->dev, dest_dev = running->cwd->dev, src_parent_dev = src_dev;
  char src[INODE_NAME*2], dest[INODE_NAME*2], dest_parent_path[INODE_NAME*2], src_parent_path[INODE_NAME*2];

  strcpy(src, out[1]);
  strcpy(dest, out[2]);
  strcpy(src_parent_path, dirname(out[1]));
  strcpy(dest_parent_path, dirname(out[2]));

  if (out[2][0] == '/')
  {
    src_parent_dev = src_dev = root->dev;
    dest_dev = root->dev;
  }


  p_ino = get_inode(dest_parent_path, &dest_dev, FALSE); // Make sure that the destination's parent exists
  if (p_ino < 0)
  {
    printf("\"%s\" : parent directory does not exist.\n", basename(dest_parent_path));
    return -4;
  }
  ino = get_inode(dest, &dest_dev, TRUE);       // Make sure that the destination file does not already exist
  if (ino > 0)                                    // Destination file already exists
  {
    printf("\"%s\" : file already exists with this name.\n", dest);
    return -4;
  }
  ino = get_inode(src, &src_dev, FALSE);       // Make sure that the source file does exist
  if (ino < 0)
  {
    return ino;
  }

  sp_ino = get_inode(src_parent_path, &src_parent_dev, TRUE);

  MINODE *mip   = iget(src_dev, ino);
  MINODE *d_pip = iget(dest_dev, p_ino);
  MINODE *s_pip = iget(src_dev, sp_ino);

  if (src_dev == dest_dev) // the source and destination are on the same device
  {
    enter_name(d_pip, ino, basename(dest), mip->Inode.i_mode);

    d_pip->dirty = TRUE;
    mip->dirty = TRUE;

    remove_name(s_pip, mip->ino, basename(src));
  }
  else
  {
    _cp(src, dest);

    mip->Inode.i_links_count--;
    if (mip->Inode.i_links_count == 0)
    {
      __unlink(mip, s_pip, basename(src));
    }

    remove_name(s_pip, mip->ino, basename(src));

    if (DEBUGGING)
      debug_dir(s_pip);

    s_pip->Inode.i_atime = time(0L);
    s_pip->dirty = TRUE;
    mip->dirty = TRUE;
  }
  // TODO: moving files across devices
  iput(mip);
  iput(d_pip);
  iput(s_pip);

  return 0;
}
示例#10
0
文件: bpdl.c 项目: claytonkb/Babel
mword *inline_bpdl_code_list(bvm_cache *this_bvm, mword *sexpr){ // inline_bpdl_code_list#

#ifdef BPDL_TRACE
_trace;
#endif

    // 1. string
    // 2. number
    // 3. built-in (opcodes)
    // 3. label (lookup in sym-table)
    // 4. recurse inline_bpdl
    mword entry_type;
    mword *list_head = nil;
    mword *list_curr = nil;
    mword *new_entry;
    mword *bpdl_label;
    mword *bpdl_label_hash;

    while(!is_nil(sexpr)){

        entry_type = get_bpdl_list_entry_type((mword*)icar(sexpr));

        switch(entry_type){

            case BPDL_LIST_ENTRY_DNUMBER:
            case BPDL_LIST_ENTRY_HNUMBER:
            case BPDL_LIST_ENTRY_DQUOTE:
            case BPDL_LIST_ENTRY_SQUOTE:

                new_entry = 
                    _cons( this_bvm,
                        _cons( this_bvm,
                            bpdl_const_to_bstruct(
                                this_bvm, 
                                (mword*)icar(sexpr), 
                                entry_type),
                            nil), nil);

                if(is_nil(list_head)){
                    list_head = list_curr = new_entry;
                }
                else{
                    _append_direct(this_bvm, list_curr, new_entry);
                    list_curr = (mword*)icdr(list_curr); // Save unnecessary traversal
                }

                break;

            case BPDL_LIST_ENTRY_LABEL:
                if(_arcmp((mword*)icar(sexpr), SEXPR_NIL_SYMBOL) == 0){
                        new_entry =
                            _cons( this_bvm, 
                                    _cons( this_bvm,
                                        nil,
                                        nil), nil);
                }
                else{

                    // if built-in:
                    //   substitute opcode-value
                    bpdl_label = _lf2by(this_bvm, (mword*)icar(sexpr));
                    bpdl_label_hash = _hash8(this_bvm,bpdl_label);

                    if(trie_exists(this_bvm, bpdl_opcode_table, bpdl_label_hash, nil)){
                        new_entry =
                            _cons( this_bvm, 
                                    _cp( this_bvm, _ith( this_bvm, trie_lookup_hash(this_bvm, bpdl_opcode_table, bpdl_label_hash, nil), 2) ),
                                    nil);
                    }
                    else{

                        new_entry =
                            _cons( this_bvm, 
                                tptr_new(this_bvm, bpdl_label_hash, nil),
                                nil);

                    }

                }

                if(is_nil(list_head)){
                    list_head = list_curr = new_entry;
                }
                else{
                    _append_direct(this_bvm, list_curr, new_entry);
                    list_curr = (mword*)icdr(list_curr); // Save unnecessary traversal
                }

                break;

            case BPDL_LIST_ENTRY_INTE:

                new_entry =
                    _cons( this_bvm,
                        _cons( this_bvm,
                            inline_bpdl(this_bvm, (mword*)icar(sexpr)),
                            nil), nil);

                if(is_nil(list_head)){
                    list_head = list_curr = new_entry;
                }
                else{
                    _append_direct(this_bvm, list_curr, new_entry);
                    list_curr = (mword*)icdr(list_curr); // Save unnecessary traversal
                }

                break;

            default:
                _d(entry_type);
                _fatal("Unrecognized bpdl list entry"); //FIXME Throw exception

        }

        sexpr = (mword*)icdr(sexpr);

    }

    return list_head;

}
示例#11
0
	int delmin(int& i,elem_t& e){
		if (n<1) return 0;i=ind[1];
		for (e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);
		h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;
	}
示例#12
0
文件: coprissi.c 项目: kjiwa/coprissi
/**
 * Analyzes a file and copies it if it contains image data.
 * @param fpath The filename of the current entry.
 * @param sb A pointer to the stat structure.
 * @param typeflag The current entry type.
 */
static int
_ftw_callback(char const* fpath, struct stat const* sb, int typeflag)
{
  int rc;
  ExifData* exif_data;
  ExifEntry* exif_entry;
  char exif_entry_val[20];
  struct tm tm;

  // The current entry is not a file. Skip it.
  if (!S_ISREG(sb->st_mode)) {
    return 0;
  }

  // The current entry has no EXIF data. Skip it.
  exif_data = exif_data_new_from_file(fpath);
  if (exif_data == NULL) {
    return 0;
  }

  rc = 0;
  exif_entry = exif_content_get_entry(*(exif_data->ifd), EXIF_TAG_DATE_TIME);

  if (exif_entry != NULL
      && exif_entry_get_value(exif_entry, exif_entry_val, 20) != NULL
      && strptime(exif_entry_val, "%Y:%m:%d %H:%M:%S", &tm) != 0) {
    size_t dst_size;
    char* dst;

    dst_size = strlen(_DST) + 12;
    dst = (char*) malloc(dst_size);

    // Create the destination path.
    if (snprintf(dst, dst_size, "%s/%d/%02d/%02d", _DST, tm.tm_year + 1900,
                 tm.tm_mon + 1, tm.tm_mday) >= 0
        && _mkdir_recursive(dst) == 0) {
      size_t offset;
      char* dst_fpath;

      offset = strlen(fpath);
      while (offset > 0 && fpath[offset - 1] != '/') {
        --offset;
      }

      // Copy the file.
      dst_fpath = (char*) malloc(strlen(dst) + strlen(fpath + offset) + 2);
      sprintf(dst_fpath, "%s/%s", dst, fpath + offset);
      rc = _cp(dst_fpath, fpath);
      free(dst_fpath);

      if (rc == -1 && errno == EEXIST) {
        rc = 0;
      }
    }

    free(dst);
  }

  exif_data_unref(exif_data);
  return rc;
}
示例#13
0
int main(int argc, char * argv[], char * env[])
{
	char line[128], command[128], pathname[128];
	int ID;
	
	// DEVICE SELECT
	get_device();

	// INITIALIZE 
	init();
	
	// MOUNT ROOT
	mount_root();

	// PROCESS LOOP
	while(1)
	{
		strcpy(line, "");
		strcpy(command, "");
		strcpy(pathname, "");
		strcpy(completePath, "");

		printf("\n\ninput a command (type help for more info): ");
		//read a line containting  command [pathname]; // [ ] means optional
		fgets(line, 256, stdin);
		line[strlen(line)-1] = '\0';

		//Find the command string and call the corresponding function;
		parseString(line, arg1, command, pathname);

		compPath(pathname);
		
		
		printf("PATHNAME: %s\n", pathname);
		ID = findCommand(command);
		switch(ID)
		{
			case -1 : printDir(running->cwd->ino);	break;
			case  0 : _menu  (arg1, pathname);	break;
			case  1 : _ls    (arg1, pathname);	break;
			case  2 : _cd    (arg1, pathname);	break;
			case  3 : _mkdir (arg1, pathname);	break;
			case  4 : _rmdir (arg1, pathname);	break;
			case  5 : _pwd   (arg1, pathname);	break;
			case  6 : _creat0(arg1, pathname);	break;
			case  7 : _rm    (arg1, pathname);	break;
			case  8 : _stat  (arg1, pathname);	break;
			case  9 : compPath(arg1); _link(arg1, pathname); break;
			case  10: _unlink(arg1, pathname); break;
			case  11: compPath(arg1); _symlink(arg1, pathname); break;
			case  12: _touch (arg1, pathname);	break;
			case  13: _chmod (arg1, pathname);	break;
			case  14: _chown (arg1, pathname);	break;
			case  15: _chgrp (arg1, pathname);	break;
			case  16: _open  (arg1, pathname);	break;
			case  17: _close (arg1, pathname);	break;
			case  18: _read  (arg1, pathname);	break;
			case  19: _write (arg1, pathname);	break;
			case  20: _pfd   (arg1, pathname);	break;
			case  21: _lseek (arg1, pathname);	break;
			case  22: _cat   (arg1, pathname);	break;
			case  23: _cp    (arg1, pathname);	break;
			case  24: _mv    (arg1, pathname);	break;
			case  25: __exit (arg1, pathname);	break;
		}
	}
	
	quit();
	return 0;
}