Esempio n. 1
0
		// return full path for user log filename
		// if (force_create_path == true) then create dirs in path if not exist
		extern char * userlog_filename(const char * username, bool force_create_path)
		{
			char * filepath;

			// lowercase username
			std::string lusername = std::string(username); 
			std::transform(lusername.begin(), lusername.end(), lusername.begin(), ::tolower);
			// get first 3 symbols of account and use it in path
			// it will improve performance with large count of files
			std::string dir_prefix = lusername.substr(0, 3);

			filepath = buildpath(prefs_get_userlogdir(), dir_prefix.c_str());
			// create directories in path
			if (force_create_path)
			{
				struct stat statbuf;
				// create inside user dir
				if (stat(filepath, &statbuf) == -1) {
					p_mkdir(filepath, S_IRWXU | S_IRWXG | S_IRWXO);
					eventlog(eventlog_level_info, __FUNCTION__, "created user directory: %s", filepath);
				}
			}

			char *tmp = new char[std::strlen(filepath) + 1];
			strcpy(tmp, filepath);
			xfree(filepath);

			filepath = buildpath(tmp, lusername.c_str());
			delete[] tmp;

			std::strcat(filepath, ".log");

			return filepath;
		}
Esempio n. 2
0
int IOopen (char *kind, char *name, char *mode, char *fmt) {
    io_t *p;
    int type;
    char *path, *command;
    int i;
    int count = 0;

    if (strcmp (kind, "file") == 0)
        type = IO_FILE;
    else if (strcmp (kind, "pipe") == 0)
        type = IO_PIPE;
    else
        return -1;

    for (i = 0; i < ion; i++)
        if (!iop[i].inuse)
            break;
    if (i == ion) {
        iop = Marraygrow (iop, (long) (ion + IOINCR) * IOSIZE);
        for (i = ion + IOINCR - 1; i >= ion; i--)
            iop[i].inuse = FALSE;
        i++, ion += IOINCR;
    }
    p = &iop[i];
    p->type = type;
    if (!(p->buf = malloc (IOBUFSIZE)))
        panic1 (POS, "IOopen", "malloc failed");
    p->buf[0] = 0;
    switch (type) {
    case IO_FILE:
        if (!(p->ifp = p->ofp = fopen (name, mode))) {
            path = buildpath (name, FALSE);
            if (!path || !(p->ifp = p->ofp = fopen (path, mode)))
                return -1;
        }
        break;
    case IO_PIPE:
        if (!fmt)
            fmt = "%e";
        if (
            !(path = buildpath (name, TRUE)) ||
            !(command = buildcommand (path, NULL, -1, -1, fmt))
        )
            return -1;
        pipeopen (command, &p->ifp, &p->ofp, &p->pid);
        if (!p->ifp || !p->ofp)
            return -1;
        break;
    }
    p->inuse = TRUE;
    return i;
}
Esempio n. 3
0
int Iload (int argc, lvar_t *argv) {
    Psrc_t src;
    char *fn;
    FILE *fp;
    Tobj co;

    if ((fn = Tgetstring (argv[0].o))) {
        if (fn[0] == '-' && fn[1] == '\000')
            fp = stdin;
        else {
            fp = NULL;
            if ((fn = buildpath (fn, FALSE)))
                fp = fopen (fn, "r");
        }
        if (fp) {
            src.flag = FILESRC, src.s = NULL, src.fp = fp;
            src.tok = -1, src.lnum = 1;
            while ((co = Punit (&src)))
                Eoktorun = TRUE, Eunit (co);
            if (fp != stdin)
                fclose (fp);
        } else
            return L_FAILURE;
    }
    return L_SUCCESS;
}
Esempio n. 4
0
std::shared_ptr<corresp> symmodel::getcorresp( const std::shared_ptr<symmodel>& targ )
    {

      std::shared_ptr<corresp> c;
      
      fprintf(stdout, "Looking for corresp between [%s] and [%s]\n", buildpath().c_str(), targ->buildpath().c_str());
      std::shared_ptr<symmodel> thistop = get_toplevel_model();
      std::shared_ptr<symmodel> targtop = targ->get_toplevel_model();

      //Just make it identity by default? NO F**K...when I try to "add" it will check first...
      //if( thistop == targtop )
      //{
      //  fprintf(stdout, "Found the corresp (identity)!\n");
      c = std::make_shared<identity_corresp>( targtop, thistop );
      //return true; //it will try to add it? F**k...
      //	}
      for(size_t x=0; x<thistop->correspondences.size(); ++x)
	{
	  if( thistop->correspondences[x]->targmodel == targtop )
	    {
	      fprintf(stdout, "Found a real corresp!\n");
	      c = thistop->correspondences[x];
	    }
	}



      return c;
      
    } //end getcorresp
Esempio n. 5
0
ssize_t canonpath(char *dst,size_t dstSize,const char *src) {
	char tmp[MAX_PATH_LEN];
	ssize_t len = readlink(src,tmp,sizeof(tmp));
	if(len < 0)
		return len;
	return buildpath(dst,dstSize,tmp);
}
Esempio n. 6
0
File: ui-plain.c Progetto: ifzz/cgit
static void print_dir(const unsigned char *sha1, const char *base,
		      int baselen, const char *path)
{
	char *fullpath, *slash;
	size_t len;

	fullpath = buildpath(base, baselen, path);
	slash = (fullpath[0] == '/' ? "" : "/");
	ctx.page.etag = sha1_to_hex(sha1);
	cgit_print_http_headers();
	htmlf("<html><head><title>%s", slash);
	html_txt(fullpath);
	htmlf("</title></head>\n<body>\n<h2>%s", slash);
	html_txt(fullpath);
	html("</h2>\n<ul>\n");
	len = strlen(fullpath);
	if (len > 1) {
		fullpath[len - 1] = 0;
		slash = strrchr(fullpath, '/');
		if (slash)
			*(slash + 1) = 0;
		else {
			free(fullpath);
			fullpath = NULL;
		}
		html("<li>");
		cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
				fullpath);
		html("</li>\n");
	}
	free(fullpath);
}
Esempio n. 7
0
void
setup(void) {
	char *proxy;
	char *new_proxy;
	SoupURI *puri;
	SoupSession *s;

	/* clean up any zombies immediately */
	sigchld(0);
	gtk_init(NULL, NULL);
	if (!g_thread_supported())
		g_thread_init(NULL);

	dpy = GDK_DISPLAY();
	s = webkit_get_default_session();

	/* atoms */
	atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
	atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
	atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);

	/* dirs and files */
	cookiefile = buildpath(cookiefile);
	scriptfile = buildpath(scriptfile);
	stylefile = buildpath(stylefile);

	/* request handler */
	s = webkit_get_default_session();
	soup_session_remove_feature_by_type(s, soup_cookie_get_type());
	soup_session_remove_feature_by_type(s, soup_cookie_jar_get_type());
	g_signal_connect_after(G_OBJECT(s), "request-started", G_CALLBACK(newrequest), NULL);

	/* proxy */
	if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
		new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
			g_strdup_printf("http://%s", proxy);
		puri = soup_uri_new(new_proxy);
		g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
		soup_uri_free(puri);
		g_free(new_proxy);
	}


	XSetErrorHandler(&xerrorhandler);
}
Esempio n. 8
0
void
setup(void) {
	SoupSession *s;
	char *proxy;
	char *new_proxy;
	SoupURI *puri;

	/* clean up any zombies immediately */
	sigchld(0);
	gtk_init(NULL, NULL);
	if (!g_thread_supported())
		g_thread_init(NULL);

	dpy = GDK_DISPLAY();
	session = webkit_get_default_session();
	uriprop = XInternAtom(dpy, "_SURF_URI", False);
	findprop = XInternAtom(dpy, "_SURF_FIND", False);

	/* create dirs and files */
	cookiefile = buildpath(cookiefile);
	dldir = buildpath(dldir);
	scriptfile = buildpath(scriptfile);
	stylefile = buildpath(stylefile);

	/* cookie persistance */
	s = webkit_get_default_session();
	cookies = soup_cookie_jar_new();
	soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies));
	g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL);
	if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
		new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
			    g_strdup_printf("http://%s", proxy);

		puri = soup_uri_new(new_proxy);
		g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
		soup_uri_free(puri);
		g_free(new_proxy);
	}
	reloadcookies();
}
Esempio n. 9
0
 vector<vector<string>> findLadders(string start, string end, unordered_set<string> &dict) {
     vector<vector<string> > paths;
     
     unordered_map<string, vector<string> > prevs;
     prevs[start] = vector<string>();
     
     unordered_map<string, int> dists;
     dists[start] = 1;
     
     queue<string> q;
     q.push(start);
     
     dict.insert(start);
     dict.insert(end);
   
     while(!q.empty())
     {
         string head = q.front();
         q.pop();
         int dist = dists[head];
         for(int i = 0; i < head.length(); i++)
         {
             for(int j = 0; j < 26; j++)
             {
                 if(j + 'a' == head[i])
                     continue;
                 string temp = head;
                 temp[i] = j + 'a';
                 if(dict.find(temp) == dict.end())
                     continue;
                     
                 if(dists.find(temp) == dists.end()) 
                 {
                     q.push(temp);
                     dists[temp] = dist + 1;
                 }
                 if(dists[temp] > dist)
                 {
                     if(prevs.find(temp) == prevs.end())
                         prevs[temp] = vector<string>();
                     prevs[temp].push_back(head);
                 }
             }
         }
     }
     if(prevs[end].empty())
         return paths;
     vector<string> path;
     buildpath(prevs, end, path, paths);
     return paths;
 }
Esempio n. 10
0
void h_mfmt(struct context *ctx, char *arg)
{
    char *t;
    struct stat st;
    struct tm tm;

    DebugIn(DEBUG_COMMAND);

    t = arg;

    while (*arg && !isspace((int) *arg))
	arg++;

    if (!isspace((int) *arg)) {
	reply(ctx, MSG_500_arguments_required);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    memset(&tm, 0, sizeof(tm));
    *arg++ = 0;

    if (*arg && 6 == sscanf(t, "%4d%2d%2d%2d%2d%2d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec)) {
	struct utimbuf ut;
	tm.tm_year -= 1900;
	tm.tm_mon--;
	ut.modtime = mktime(&tm);

	if ((t = buildpath(ctx, arg)) && (!pickystat(ctx, &st, t))
	    && (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))
	    && st.st_uid == ctx->uid) {
	    ut.actime = st.st_atime;
	    if (utime(t, &ut))
		reply(ctx, MSG_550_Permission_denied);
	    else {
		struct stat sst;
		char u[40];
		if (stat(t, &sst))
		    sst.st_mtime = ut.modtime;
		strftime(u, sizeof(u), "213 Modify=%Y%m%d%H%M%S; ", gmtime(&sst.st_mtime));
		replyf(ctx, "%s%s\r\n", u, t);
	    }
	} else
	    reply(ctx, MSG_550_Permission_denied);
    } else
	reply(ctx, MSG_500_missing_filename);

    DebugOut(DEBUG_COMMAND);
}
Esempio n. 11
0
File: ui-plain.c Progetto: ifzz/cgit
static void print_dir_entry(const unsigned char *sha1, const char *base,
			    int baselen, const char *path, unsigned mode)
{
	char *fullpath;

	fullpath = buildpath(base, baselen, path);
	if (!S_ISDIR(mode) && !S_ISGITLINK(mode))
		fullpath[strlen(fullpath) - 1] = 0;
	html("  <li>");
	if (S_ISGITLINK(mode)) {
		cgit_submodule_link(NULL, fullpath, sha1_to_hex(sha1));
	} else
		cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
				fullpath);
	html("</li>\n");
	free(fullpath);
}
Esempio n. 12
0
static char const * file_get_info(char const * rawname, unsigned int * len, bn_long * modtime)
{
    char *filename;
    t_bnettime   bt;
    struct stat sfile;

    if (!rawname) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL rawname");
	return NULL;
    }

    if (!len) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL len");
	return NULL;
    }

    if (!modtime) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL modtime");
	return NULL;
    }

    if (std::strchr(rawname,'/') || std::strchr(rawname,'\\')) {
	eventlog(eventlog_level_warn,__FUNCTION__,"got rawname containing '/' or '\\' \"%s\"",rawname);
	return NULL;
    }

    filename = buildpath(prefs_get_filedir(), rawname);

    if (stat(filename, &sfile)<0) { /* if it doesn't exist, try to replace with default file */
	xfree((void*)filename);
	filename = file_find_default(rawname);
	if (!filename) return NULL; /* no default version */

	if (stat(filename, &sfile)<0) { /* try again */
	    /* FIXME: check for lower-case version of filename */
	    xfree(filename);
	    return NULL;
	}
    }

    *len = (unsigned int)sfile.st_size;
    bt = time_to_bnettime(sfile.st_mtime,0);
    bnettime_to_bn_long(bt,modtime);

    return filename;
}
Esempio n. 13
0
		static char const * file_get_info(char const * rawname, unsigned int * len, bn_long * modtime)
		{
			const char *filename;
			t_bnettime   bt;
			struct stat sfile;

			if (!rawname) {
				eventlog(eventlog_level_error, __FUNCTION__, "got NULL rawname");
				return NULL;
			}

			if (!len) {
				eventlog(eventlog_level_error, __FUNCTION__, "got NULL len");
				return NULL;
			}

			if (!modtime) {
				eventlog(eventlog_level_error, __FUNCTION__, "got NULL modtime");
				return NULL;
			}

			if (std::strchr(rawname, '/') || std::strchr(rawname, '\\')) {
				eventlog(eventlog_level_warn, __FUNCTION__, "got rawname containing '/' or '\\' \"%s\"", rawname);
				return NULL;
			}


			filename = file_find_localized(rawname);
			// if localized file not found in "i18n"
			if (!filename || stat(filename, &sfile) < 0)
			{
				// try find it in "files"
				filename = buildpath(prefs_get_filedir(), rawname);
				if (stat(filename, &sfile) < 0) { /* try again */
					/* FIXME: check for lower-case version of filename */
					return NULL;
				}
			}

			*len = (unsigned int)sfile.st_size;
			bt = time_to_bnettime(sfile.st_mtime, 0);
			bnettime_to_bn_long(bt, modtime);

			return filename;
		}
Esempio n. 14
0
void buildpath(int x, int y, int step){
    if(x<0 || y<0) return;
    int origx,origy;
    origx = x;
    origy = y;
    int i,min=table[x][y],pos;
    int aux,action=-1;
    for(i=0;i<3;i++){
        if(origx+vec[i].x >= 0 && origy+vec[i].y >= 0){
            aux = table[origx+vec[i].x][origy+vec[i].y];
            if(min > aux){
                x = origx + vec[i].x;
                y = origy + vec[i].y;
                min = aux;
                action = i;
            }
        }
    }
    switch(action){
        case 0:
            /*printf("C%c%02d",tar[origy-1],origx);*/
            printf("%d Replace %d,%c\n",step, origx, tar[origy-1]);
            step++;
            break;
        case 1:
            /*printf("D%c%02d",src[origx-1],origx);*/
            printf("%d Delete %d\n",step , origx);
            step++;
            break;
        case 2: 
            /*printf("I%c%02d",tar[origy-1],origx+1);*/
            printf("%d Insert %d,%c\n",step ,origx+1, tar[origy-1]);
            step++;
            break;
        default:
            /* equals */
            x--;
            y--;
            break;
    }
    buildpath(x,y, step);
}
Esempio n. 15
0
void symmodel::notify_filled_corresp( const std::shared_ptr<symmodel>& targ )
  {
    //Call this to "mirror" from large-small on othe side.
    fprintf(stdout, "In notify filled....will get\n");
    auto tmp = getcorresp( targ );
    //bool correspexists = 

    fprintf(stdout, "Got it...\n");
    if( !tmp )
      {
	fprintf(stderr, "notify filled corresp, coudln't find it \n");
	exit(1);
      }

    fprintf(stdout, "Will call fill corresp...\n");
    targ->fill_corresp( tmp );
    tmp->markinit(); //I better be init haha;
    fprintf(stdout, "Notifying that correspondence [%s] was filled!\n", tmp->buildpath().c_str() );
    return;
  }
Esempio n. 16
0
 void buildpath(unordered_map<string, vector<string> >& prevs,
                 string word, vector<string> &path,  vector<vector<string> > &paths)
 {
     if(prevs[word].empty())
     {
         path.push_back(word);
         vector<string> tpath = path;
         reverse(tpath.begin(), tpath.end());
         paths.push_back(tpath);
         path.pop_back();
         return;
     }
     vector<string> v = prevs[word];
     path.push_back(word);
     for(int i = 0; i < v.size(); i++)
     {
         buildpath(prevs, v[i], path, paths);
     }
     path.pop_back();
 }
Esempio n. 17
0
void symmodel::sanity_check()
{
  for(size_t x=0; x<vars.size(); ++x)
    {
      if( !vars[x] )
	{
	  fprintf(stderr, "REV: Model [%s]'s [%lu]-th VAR is NULL\n", buildpath().c_str(), x ); 
	}
    }
  for(size_t x=0; x<models.size(); ++x)
    {
      if( !models[x] )
	{
	  fprintf(stderr, "REV: SANITY CHECK WARNING, MODEL [%s]'s [%lu]-th model is NULL\n", buildpath().c_str(), x);
	}
      else
	{
	  models[x]->sanity_check();
	}
    }
}
Esempio n. 18
0
bool symmodel::checkvarsready()
  {
    bool varsready=true;
    for(size_t v=0; v<vars.size(); ++v)
      {
	if( !vars[v]->isinit() )
	  {
	    fprintf(stderr, "WARNING: checkvarsready(): model [%s] var [%s] not ready\n", buildpath().c_str(), vars[v]->name.c_str() );
	    varsready=false;
	  }
      }
    //for all vars, for all corresp, are init?
    for( size_t m=0; m<models.size(); ++m)
      {
	if( !models[m]->checkvarsready() )
	  {
	    varsready=false;
	  }
      }
    return varsready;
  }
Esempio n. 19
0
vector<size_t> symmodel::get_varloc( const string& s )
{
  vector<size_t> loc;
  fprintf(stdout, "REV: in var loc...for var [%s]\n", s.c_str());
  for(size_t x=0; x<vars.size(); ++x)
    {
      if(!vars[x])
	{
	  fprintf(stderr, "Wtf, var idx [%lu] in model [%s] is a NULL ptr\n", x, buildpath().c_str() );
	  exit(1);
	}
      fprintf(stdout, "REV: in var loc... [%s] vs varname [%s]\n", s.c_str(), vars[x]->name.c_str());
      if( s.compare( vars[x]->name ) == 0 )
	{
	  loc.push_back(x);
	}
    }
  return loc;
  //fprintf(stderr, "REV: ERROR variable [%s] could not be found in this model [%s]\n", s.c_str(), name.c_str() );
  //exit(1);
}
Esempio n. 20
0
int main(){
    int f = 1;
    while(gets(src)){
        gets(tar);
        n=strlen(src);
        m=strlen(tar);
        editdistance();
        /*int i,j;
        for(i=0;i<=n;i++){
            for(j=0;j<=m;j++){
                printf("%d,",table[i][j]);
            }
            printf("\n");
        }*/
        if(!f){
            printf("\n");
        }
        f=0;
        printf("%d\n",table[n][m]);
        buildpath(n,m,1);
    }
    return 0;
}
Esempio n. 21
0
void h_rnfr(struct context *ctx, char *arg)
{
    char *t;
    struct stat st;

    DebugIn(DEBUG_COMMAND);

    if ((t = buildpath(ctx, arg)) && (strlen(t) > ctx->rootlen) && (!pickystat(ctx, &st, t)) && (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))) {
	ctx->last_command_was_rnfr = 1;

	if (strlen(t) >= sizeof(ctx->filename)) {
	    logerr("buffer too small in %s:%d (%s/%s)", __FILE__, __LINE__, ctx->user, t);
	    reply(ctx, MSG_551_Internal_error);
	    cleanup_data(ctx, ctx->dfn);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}
	strcpy(ctx->filename, t);
	reply(ctx, MSG_350_Awaiting_dest);
    } else
	reply(ctx, MSG_550_No_such_file);

    DebugOut(DEBUG_COMMAND);
}
Esempio n. 22
0
size_t cleanpath(char *dst,size_t dstSize,const char *src) {
	return buildpath(dst,dstSize,src);
}
Esempio n. 23
0
static void h_xstor(struct context *ctx, char *arg, int flags)
{
    char *t;
    int f = -1;
    struct stat st;
    int stou = 0;
    char tbuf[PATH_MAX + 1];

    DebugIn(DEBUG_COMMAND);

    if (ctx->transfer_in_progress) {
	reply(ctx, MSG_501_Transfer_in_progress);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    ctx->outgoing_data = 0;
    if (ctx->dfn > -1 && io_get_cb_i(ctx->io, ctx->dfn) == (void *) accept_data) {
	io_set_i(ctx->io, ctx->dfn);
	io_clr_o(ctx->io, ctx->dfn);
	io_set_cb_e(ctx->io, ctx->dfn, (void *) cleanup_data);
	io_set_cb_h(ctx->io, ctx->dfn, (void *) cleanup_data);
    }

    quota_add(ctx, 0);

    if (ctx->quota_path && (ctx->quota_ondisk >= ctx->quota_limit)) {
	reply(ctx, MSG_451_quota_exceeded);
	logmsg("%s: quota limit reached", ctx->user);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    if (!arg) {
	stou = -1;
	snprintf(tbuf, sizeof(tbuf), "%s/stou.XXXXXX", ctx->cwd);
	arg = tbuf;

	t = buildpath(ctx, arg);
    } else if (acl_binary_only(ctx, arg, (t = buildpath(ctx, arg)))) {
	reply(ctx, MSG_504_no_ascii);
	cleanup_data_reuse(ctx, ctx->dfn);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    st.st_size = 0;

    if (t)
	acl_set_umask(ctx, arg, t);

    if (ctx->anonymous || stou)
	flags |= O_EXCL;

    if (t && (!ctx->anonymous || check_incoming(ctx, t, 077)) &&
	!pickystat_path(ctx, &st, t) &&
	(stat(t, &st), (f = myopen(t, O_RDWR | O_CREAT | O_LARGEFILE | O_NOFOLLOW | flags, ctx->chmod_filemask | (0644 & ~ctx->umask), stou)) > -1)) {

	fcntl(f, F_SETFD, FD_CLOEXEC);

	ctx->quota_filesize_before_stor = st.st_size;
	ctx->quota_update_on_close = 1;

	if (ctx->dfn < 0)
	    connect_port(ctx);

	if (ctx->dfn < 0) {
	    reply(ctx, MSG_431_Opening_datacon_failed);
	    close(f);
	    ctx->dbuf = buffer_free_all(ctx->dbuf);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}

	ctx->ffn = f;
	if (strlen(t) >= sizeof(ctx->filename)) {
	    logerr("buffer too small in %s:%d (%s/%s)", __FILE__, __LINE__, ctx->user, t);
	    reply(ctx, MSG_551_Internal_error);
	    close(f);
	    cleanup(ctx, ctx->dfn);
	    ctx->dbuf = buffer_free_all(ctx->dbuf);
	    DebugOut(DEBUG_COMMAND);
	    return;
	}
	strcpy(ctx->filename, t);
	ctx->filesize = 0;
	ctx->bytecount = 0;

	if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer || is_connected(ctx->dfn)) {
	    if (stou)
		replyf(ctx, "125 FILE: %s\r\n", ctx->filename + ctx->rootlen);
	    else
		replyf(ctx, MSG_125_Starting_dc, ctx->use_ascii ? "ASCII" : "BINARY", ctx->use_tls_d ? "TLS " : "");
	} else {
	    if (stou)
		replyf(ctx, "150 FILE: %s\r\n", ctx->filename + ctx->rootlen);
	    else
		replyf(ctx, MSG_150_Opening_dc, ctx->use_ascii ? "ASCII" : "BINARY", ctx->use_tls_d ? "TLS " : "");
	}

	ctx->transfer_in_progress = 1;

	if (ctx->io_offset) {
	    if (ctx->use_ascii) {
		ctx->offset = 0;
		ctx->remaining = st.st_size;
		io_sched_add(ctx->io, ctx, (void *) skipbytes, 0, 0);
#ifdef WITH_MMAP
		if (use_mmap)
		    ctx->iomode = IOMODE_mmap;
		else
#endif
		    ctx->iomode = IOMODE_read, ctx->iomode_fixed = 1;
	    } else {
		lseek(f, ctx->io_offset, SEEK_SET);
		ctx->io_offset = 0;
	    }
	}

	if (io_get_cb_i(ctx->io, ctx->dfn) == (void *) socket2buffer) {
	    /* already connected */
	    io_clr_o(ctx->io, ctx->dfn);
	    io_set_i(ctx->io, ctx->dfn);
	}

	ctx->transferstart = io_now.tv_sec;
	ctx->count_files++;
    } else {
	if (stou && errno == EEXIST)
	    reply(ctx, MSG_451_unique_file_failure);
	else
	    reply(ctx, MSG_550_Permission_denied);
	cleanup_data_reuse(ctx, ctx->dfn);
    }

    DebugOut(DEBUG_COMMAND);
}
Esempio n. 24
0
void symmodel::execute_gen_line( const size_t& line, global_store& globals )
{
  if( !gen )
    {
      fprintf(stderr, "REV: error, trying to execute gen line [%lu] in model [%s], but it does not have a generator!\n", line, buildpath().c_str());
      exit(1);
    }
  else
    {
      gen->execute_line( shared_from_this(), globals, line );
    }
}
Esempio n. 25
0
File: rview.c Progetto: badcodes/c
int  _tmain(int  argc,_TCHAR *argv[])
{
	int  viewrnd=0;
	int  viewprev=0;
	int  viewhelp=0;
	int  viewini=0;
	int  viewlist=0;
	int  viewindex=0;
	int  viewnext=0;
	int  fcount=0;
	int  next=1;
	int  reload=0;
	_TCHAR *pageviewer=(_TCHAR*)malloc(_MAX_FNAME);
	_TCHAR *lastdir=(_TCHAR *)malloc(_MAX_PATH);
	_TCHAR *inifile=_tgetenv(_T("APPDATA"));
	_TCHAR *cmdline=(_TCHAR*)malloc(_MAX_FNAME);
	_TCHAR *defaultfile=(_TCHAR*)malloc(_MAX_FNAME);
	_TCHAR *searchfor=(_TCHAR*)malloc(_MAX_FNAME);
	_TCHAR **filelist;
	FILE *appout;
	APPINI status;

	
	defaultfile[0]=NIL;
	pageviewer[0]=NIL;
	lastdir[0]=NIL;
	cmdline[0]=NIL;
	status.viewer[0]=NIL;
	status.workdir[0]=NIL;
	status.filename[0]=NIL;

#ifdef _DEBUG
	appout=_tfopen(_T("text.txt"),_T("wb"));
#else
	appout=stdout;
#endif

	_tcscat(inifile,_T("\\") _T(APPNAME));
	_tmkdir(inifile);
	_tcscat(inifile,_T("\\rview.ini"));

	while (--argc>0)
	{
		/*if argv start at '-')*/
		if (argv[argc][0]==_T('-')) {
			switch(argv[argc][1]) {
			case _T('r'):
			case _T('R'):
				reload=1;
				break;
			case _T('h'):
			case _T('H'):
				viewhelp=1;
				break;
			case _T('v'):
			case _T('V'):
				viewini=1;
				break;
			case _T('l'):
			case _T('L'):
				viewlist=1;
				break;
			case _T('n'):
			case _T('N'):
				viewnext=1;
				break;
			case _T('p'):
			case _T('P'):
				viewprev=1;
				break;
			case _T('z'):
			case _T('Z'):
				viewrnd=1;
				break;
			case _T('c'):
			case _T('C'):
				_tcscpy(pageviewer,(_TCHAR*)&(argv[argc][2]));
				break;
			case _T('f'):
			case _T('F'):
				_tcscpy(defaultfile,(_TCHAR*)&(argv[argc][2]));
				break;
			}
		}
		else 
			viewindex=_ttoi(argv[argc]);
	}

	if (viewhelp==1) {
		fprintf(appout,"%s\n",APPINFO);
		fprintf(appout,"%s\n",APPHELP);
		return 0;
	}


	_tgetcwd(lastdir,_MAX_PATH);

	if (loadpre(&status,inifile)==0) {
		status.workdir[0] =NIL;// _tcscpy(status.workdir,lastdir);
		status.viewer[0]=NIL;//_tcscpy(status.viewer,pageviewer);
		status.filename[0] = NIL;
	}

#ifndef _DEBUG
	_ftprintf(appout,_T("CURLINE:%d\n"),__LINE__);	
	_ftprintf(appout,_T("Viewer:%s\n"),status.viewer);
	_ftprintf(appout,_T("Workdir:%s\n"),status.workdir);
	_ftprintf(appout,_T("Filename:%s\n"),status.filename);
#endif

	if (status.workdir[0]==NIL)
		_tcscpy(status.workdir ,lastdir);
	if (pageviewer[0]!=NIL)
		_tcscpy(status.viewer,pageviewer);
	else if (status.viewer[0]==NIL) 
		_tcscpy(status.viewer,DEFAULTVIEWER);
	
	if (viewini==1) {
		_ftprintf(appout,_T("DefaultViewer:%s\nWorkDir:%s\nLastFile:%s"),status.viewer,status.workdir,status.filename );
		savecur(&status,inifile);
		return 0; 
	}

	if (reload==1) {
		int  c=0;
		fprintf(appout,"原先目录是:");
		_ftprintf(appout,_T("%s\n"), status.workdir);
		fprintf(appout,"当前目录是:");
		_ftprintf(appout,_T("%s\n"),lastdir);
		fprintf(appout,"确定要将当前目录设定为工作目录?(Y/N)");
		//fflush(stdin);
		c=_fgettchar();
		if (c==_T('Y') || c==_T('y')) {
			_tcscpy(status.workdir,lastdir);
			status.filename[0] = NIL;
			savecur(&status,inifile);
			}
	}

	//_chdir(status.workdir);
	//DEBUGStr(status.workdir)
	
	if (defaultfile[0]!=NIL) _tcscpy(status.filename ,defaultfile);
	if (status.filename[0]==NIL) viewnext=1;

/*	DEBUGInt(viewnext);
	DEBUGInt(viewlist);
	DEBUGInt(viewrnd);
	DEBUGInt(viewindex);*/

	if ((viewlist)||(viewrnd)||(viewindex)||(viewnext)) {
		searchfor=buildpath(searchfor,status.workdir,WILDNAME);
#ifdef _DEBUG
		//DEBUGStr(status.workdir);
		_ftprintf(appout,_T("%s\n"),status.workdir);
		_ftprintf(appout,_T("%s\n"),WILDNAME);
		_ftprintf(appout,_T("%s\n"),searchfor);
#endif
		fcount=countfile(searchfor,_A_ARCH);
		if (fcount<=0) return 0;
		filelist=(_TCHAR **)malloc(sizeof(_TCHAR*)*(fcount+1));
		fcount=findfile(searchfor,_A_ARCH,filelist,fcount);
		qsort((void*)filelist,(size_t) fcount,sizeof(_TCHAR*),(int(_cdecl*)(const void*,const void*))&wcscmp);
		
		//viewlist
		if (viewlist==1) {
			int  i;
			for (i=0;i<fcount;i++){
					_ftprintf(appout,_T("[%4d]:%s\n"),i+1,filelist[i]);
			}
			return(0);
		}
		else if (viewindex>0) {     //viewindex
			next=viewindex-1;
		}
		else if (viewrnd==1) {  //viewrnd
			srand( (unsigned)time( NULL ) );
			next= rand( ) % fcount;
		}
		else if (status.filename[0]==NIL)  {
			next=0;
		}
		else if (viewnext==1) {
			next=getindex(status.filename,filelist,fcount)+1;
		}
		else if (viewprev==1) {
			next=getindex(status.filename,filelist,fcount)-1;
		}
		if ((next>fcount-1) || next<0 ) next=0;
		_tcscpy(status.filename ,filelist[next]); 
	}

	/*DEBUGStr(status.viewer )
	DEBUGStr(status.workdir )
	DEBUGStr(status.filename )*/

	savecur(&status,inifile);
	defaultfile=buildpath(defaultfile,status.workdir ,status.filename );
	_stprintf(cmdline,_T("%s \"%s\""),status.viewer,defaultfile);
	//printf("%s:\n",status.filename);

#ifdef _DEBUG
	_ftprintf(appout,_T("Viewer:%s\n"),status.viewer);
	_ftprintf(appout,_T("Workdir:%s\n"),status.workdir);
	_ftprintf(appout,_T("Filename:%s\n"),status.filename);
	_ftprintf(appout,_T("DefaultFile:%s\n"),defaultfile);
	_ftprintf(appout,_T("Cmdline:%s\n"),cmdline);
#endif

	system(cmdline);
	_ftprintf(appout,_T("[%s]\n"),defaultfile);
	
	fclose(appout);
	return (0);
}
Esempio n. 26
0
void h_site_chmod(struct context *ctx, char *arg)
{
    char *t;
    struct stat st;
    u_int mode;
    u_int mode_add = 0;
    u_int mode_del = 0;
    int numeric = -1;

    DebugIn(DEBUG_COMMAND);

    t = arg;

    while (*arg && !isspace((int) *arg))
	arg++;

    if (!isspace((int) *arg)) {
	reply(ctx, MSG_500_arguments_required);
	DebugOut(DEBUG_COMMAND);
	return;
    }

    *arg++ = 0;

    if (1 != sscanf(t, "%o", &mode)) {
	numeric = 0;
	mode = 0;
	while (*t) {
	    u_int bits_affected = 0;
	    u_int new_mode = 0;
	    char op = 0;

	    for (; *t && *t != ','; t++)
		if (op)
		    switch (*t) {
		    case 'r':
			new_mode |= 0444;
			break;
		    case 'w':
			new_mode |= 0222;
			break;
		    case 'x':
			new_mode |= 0111;
			break;
		    default:
		      invalid_mode:
			reply(ctx, MSG_500_invalid_mode);
			DebugOut(DEBUG_COMMAND);
			return;
		} else
		    switch (*t) {
		    case '+':
		    case '-':
		    case '=':
			op = *t;
			if (!bits_affected)
			    bits_affected = ~ctx->umask & 0777;
			break;
		    case 'u':
			bits_affected |= 0700;
			break;
		    case 'g':
			bits_affected |= 070;
			break;
		    case 'o':
			bits_affected |= 07;
			break;
		    case 'a':
			bits_affected = 0777;
			break;
		    default:
			goto invalid_mode;
		    }

	    new_mode &= bits_affected;
	    switch (op) {
	    case '+':
		mode_add |= new_mode;
		mode_del &= ~new_mode;
		break;
	    case '-':
		mode_del |= new_mode;
		mode_add &= ~new_mode;
		break;
	    case '=':
		mode_add |= new_mode;
		mode_del &= ~new_mode;
		mode_del |= ~new_mode & bits_affected;
		break;
	    default:
		goto invalid_mode;
	    }
	    if (*t)
		t++;
	}
    }

    while (isspace((int) *arg))
	arg++;

    if (!*arg)
	reply(ctx, MSG_500_missing_filename);
    else if ((t = buildpath(ctx, arg)) &&
	     !pickystat(ctx, &st, t) &&
	     (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) &&
	     !chmod(t, numeric ? mode : ((st.st_mode & ~mode_del) | mode_add) | (st.st_mode & (S_ISDIR(st.st_mode)
											       ? ctx->chmod_dirmask : ctx->chmod_filemask))))
	reply(ctx, MSG_200_permissions_changed);
    else
	reply(ctx, MSG_550_Permission_denied);

    DebugOut(DEBUG_COMMAND);
}
Esempio n. 27
0
elemptr symmodel::get_model_widx( const vector<string>& parsed, const vector<size_t>& idx, const vector<elemptr>& trace )
  {
    //I start with it already parsed.
    //If parsed.size() == 0, I simply return this (with an index?)
    //The empty string indicates "this" model? No, when I parse it, I need to sep it, so an empty, will return in a zero-parse, of size zero, or nothing?
    //Either way, would result in same, so return ;)
    if( parsed.size() == 0 || parsed[0].compare("") == 0 )
      {
	fprintf(stdout, "FOUND MODEL! [%s]\n", buildpath().c_str() );
	elemptr t = elemptr( shared_from_this(), idx );
	return t;
      }
    else
      {
	fprintf(stdout, "Model [%s], attempting to find model name [%s] widx (note, trace size is [%lu])\n", buildpath().c_str(), CAT(parsed, "/").c_str(), trace.size());
      }
    //This is the next model I will go into
    string submodel = parsed[0];
    vector<string> remainder( parsed.begin()+1, parsed.end() ); //same as remainder, remainder.erase(0);
    
    //REV: This is where I should iterate up the tree! This is the issue.
    vector<size_t> mlocs = find_model( submodel );
    vector<size_t> hlocs = find_hole( submodel );
    
    //At this point, we are finding the hole etc. normally.
    if( mlocs.size() >= 1 )
      {
	if( mlocs.size() > 1 )
	  {
	    fprintf(stderr, "WTF found more than one in getmodelwidx\n");
	    exit(1);
	  }
	
	size_t mloc = mlocs[0];
	//add model to trace? I guess? It is a submodel, so it is not necessary I guess? But it helps it find submodels I guess? Could this cause a problem?

	fprintf(stdout, "Model [%s], going through submodel [%s] to find [%s]\n", buildpath().c_str(), models[mloc]->localname.c_str(), CAT(remainder, "/").c_str() );
	
	std::shared_ptr<symmodel> nextmodel = models[mloc];

	//Don't add to trace because if same model, parent will cause infinite loop in combin with trace.
	//However
	//Problem is if I go through a hole, and the hole is the same model, that is the main problem
	vector<elemptr> newtrace = trace;
	//size_t idx_in_submodel = idx; //no change, b/c submodel.
	vector<size_t> idx_in_submodel = idx; //no change, b/c submodel.
	//newtrace.push_back( elemptr( shared_from_this(), idx ) );
	
	return nextmodel->get_model_widx( remainder, idx_in_submodel, newtrace );
      }
    else if( hlocs.size() >= 1 )
      {
	if( hlocs.size() > 1)
	  {
	    fprintf(stderr, "WTF more than one HOLE found in getmodelwidx\n");
	    exit(1);
	  }
	

	size_t hloc = hlocs[0];
	fprintf(stdout, "Model [%s], going through hole [%s] to find [%s]\n", buildpath().c_str(), holes[hloc].name.c_str(), CAT(remainder, "/").c_str());
	if( holes[ hloc ].members.size() != 1 )
	  {
	    fprintf(stderr, "ERROR in get_model_widx, getting [%s] from HOLE, but hole [%s] has size [%lu], but it should be 1\n", submodel.c_str(), holes[hloc].name.c_str(), holes[hloc].members.size() );
	    exit(1);
	  }

	//REV: so in the case it does not exist yet, we have a problem?
	std::shared_ptr<symmodel> nextmodel = holes[hloc].members[0];
	
	if( check_same_toplevel_model( nextmodel ) )
	  {
	    //Dont add to trace because its same model so infinite loop with going to parent.x
	    vector<elemptr> newtrace = trace;
	    //size_t idx_in_submodel = idx; //no change, b/c submodel.
	    vector<size_t> idx_in_submodel = idx; //no change, b/c submodel.
	    //newtrace.push_back( elemptr( shared_from_this(), idx ) );
	    
	    return nextmodel->get_model_widx( remainder, idx_in_submodel, newtrace );
	  }
	else //not same toplevel model
	  {
	    //I NEED TO GO THROUGH A CORRESPONDENCE

	    fprintf(stdout, "REV: about to go through a corresp to get a non-same model thing through a hole...\n");
	    //std::shared_ptr<corresp> mycorresp;
	    auto mycorresp  = getcorresp( nextmodel );
	    if( !mycorresp )
	      {
		fprintf(stderr, "REV: getcorresp in get_model_widx, failed, no such corresp exists between [%s] and [%s]\n", buildpath().c_str(), nextmodel->buildpath().c_str());
		exit(1);
	      }
	    
	    
	    //REV; SANITY, if corresp not allocated yet, just return 0.
	    //size_t idx_in_submodel = 0;
	    vector<size_t> idx_in_submodel(1,0);
	    
	    //REV; Don't check this here, check this in the corresp struct? I.e. return dummy data if it is not existing yet (or exit?)
	    if(mycorresp->isinit())
	      {
		fprintf(stdout, "Corresp is INIT!!!! Will attempt a GETALL...\n");
		//REV: TODO HERE, just return it directly, with new IDX_IN_SUBMODEL ;0
		//REV: this is it!!! This is where I 
		vector<size_t> sanity = mycorresp->getall( idx );
		
		fprintf(stdout, "Attempted to GETALL from the corresp!\n");
		/*if( sanity.size() != 1 )
		  {
		  fprintf(stderr, "SANITY check for corresp during access failed! Expected corresp for idx [%lu] of model [%s] to have only 1 corresponding element in model [%s], but it had [%lu]\n", idx, buildpath().c_str(), nextmodel->buildpath().c_str(), sanity.size() );
		  exit(1);
		  }
		  size_t idx_in_submodel = sanity[0]; //no change, b/c submodel.
		*/

		idx_in_submodel = sanity;
	      }
	    
	    vector<elemptr> newtrace = trace;
	    newtrace.push_back( elemptr( shared_from_this(), idx ) );

	    fprintf(stdout, "About to get next model with idx...\n");
	    auto toret = nextmodel->get_model_widx( remainder, idx_in_submodel, newtrace );
	    fprintf(stdout, "FINISHED About to get next model with idx...\n");
	    return toret;
	  }
      } //end if not found in HOLES (or submodels)
    else
      {
	fprintf(stdout, "Model [%s], walking up to parent [%s] to find [%s]\n", buildpath().c_str(), parent->localname.c_str(), CAT(parsed, "/").c_str());
	//Else, try to bubble up to ROOT.
	if( parent && (parent->parent) )
	  {
	    std::shared_ptr<symmodel> nextmodel = parent;
	    
	    vector<elemptr> newtrace = trace;
	    //size_t idx_in_submodel = idx; //no change, b/c submodel.
	    vector<size_t> idx_in_submodel = idx; //no change, b/c submodel.
	    //newtrace.push_back( elemptr( shared_from_this(), idx ) );
	    
	    return nextmodel->get_model_widx( parsed, idx_in_submodel, newtrace );
	  }
	else if(  parent && !(parent->parent) )
	  {
	    //Couldn't find it! Return empty elemptr...bad.
	    elemptr ep;
	    return ep;
	  }
	else
	  {
	    fprintf(stderr, "REV; this should never happen weird, Neither parent nor parent->parent? In searching for model with idx. Exit\n");
	    if( parent )
	      {
		fprintf( stderr, "Parent of me [%s] exists and is [%s]\n", buildpath().c_str(), parent->buildpath().c_str() );
	      }
	    else
	      {
		fprintf( stderr, "Parent does not exist... (note current model is [%s])!\n", buildpath().c_str() );
	      }
	    exit(1);
	  }
      } //couldn't find in "else" (i.e. not in this model, so try bubbling up parents)
    
    if(trace.size() == 0)
      {
	fprintf(stderr, "Trace size zero. This should never happen (should have been caught above)\n");
	exit(1);
      }

    //REV: Did I mess something up? First it should check through all guys directly to see if it is same model? I.e. if target model matches b/c we can use that idx.
    fprintf(stdout, "Couldn't find model [%s] in previous model trace [%s], so moving to next! (trace size is [%lu])\n", CAT(parsed,"/").c_str(), buildpath().c_str(), trace.size() );
    
    //Move back model and try again?
    vector<elemptr> newtrace = trace;
    //size_t idx_in_submodel = newtrace[ newtrace.size() - 1].idx; //end of trace.
    vector<size_t> idx_in_submodel = newtrace[ newtrace.size() - 1].idx; //end of trace.
    std::shared_ptr<symmodel> nextmodel = newtrace[ newtrace.size() - 1].model;
    newtrace.pop_back();

    fprintf(stdout, "Will now try to run with new trace size [%lu]\n", newtrace.size() );
    return nextmodel->get_model_widx( parsed, idx_in_submodel, newtrace );
    
  } //end get_model_widx
Esempio n. 28
0
int init (char *aout) {
    char *s1, *s2, c;
    int k;
#ifdef FEATURE_WIN32
        extern HANDLE hinstance;
        char buf[260];
#endif
#ifdef LEFTYDATADIR
    char *leftdatadir = LEFTYDATADIR;
#else
    char *leftdatadir = NULL;
#endif

    c = 0;
    if (getenv ("INNETSCAPE"))
        innetscape = TRUE, nswin = getenv ("NSWIN");
    if (!(pathp = malloc (PATHINCR * PATHSIZE)))
        panic1 (POS, "init", "pathp malloc failed");
    if (!(cmdp = malloc (CMDINCR * CMDSIZE)))
        panic1 (POS, "init", "cmdp malloc failed");
    shellpath = getenv ("PATH");
#ifdef FEATURE_WIN32
    GetModuleFileName (hinstance, buf, 260);
    aout = buf;
#else
    if (!strchr (aout, PATHDEL)) {
        leftypath = "";
        if ((s1 = buildpath (aout, TRUE)))
            aout = strdup (s1);
    } else
        aout = strdup (aout);
#endif
    if (!(s1 = strrchr (aout, PATHDEL)))
        s1 = aout;
    *s1 = 0;
    if (!(leftypath = malloc (PATHINCR * PATHSIZE)))
        panic1 (POS, "init", "leftypath malloc failed");
    leftypath[0] = 0;
    if ((s1 = getenv ("LEFTYPATH"))) {
        strcat (leftypath, s1);
	strcat (leftypath, PATHSEPSTR);
    }
    if (*aout) {
        strcat (leftypath, aout);
        strcat (leftypath, PATHSEPSTR);
    }
    for (k = 0; k < 2; k++) {
        if (k == 0)
            s1 = aout;
        else
            s1 = shellpath;
        while (s1) {
            if ((s2 = strchr (s1, PATHSEP)))
                c = *s2, *s2 = 0;
            strcat (leftypath, s1);
            strcat (leftypath, PATHLEFTY);
            if (s2) {
                *s2 = c, s1 = s2 + 1;
                strcat (leftypath, PATHSEPSTR);
            } else
                s1 = NULL;
        }
        if (leftypath[0])
            strcat (leftypath, PATHSEPSTR);
    }
    if (leftdatadir) {    /* support a compile-time path as last resort */
	strcat (leftypath, leftdatadir);
	strcat (leftypath, PATHSEPSTR);
    }
    if (!(leftyoptions = getenv ("LEFTYOPTIONS")))
        leftyoptions = "";
    putenv (WINSYS);
    return 0;
}
Esempio n. 29
0
/* copydirectory: copy all regular files in src to dst,
    arg is of form 'src\0dst\0' */
static void *copydirectory(void *arg)
{
	struct iofiles *iofp, *newiofp;
	char *src_dir, *dst_dir;
	char *src_path, *dst_path;
	struct dirent *dirp;
	DIR *dp;
	int infd, outfd;
	pthread_t tid;
	struct stat statbuf;
	copyinfo_t *cip, *newci;

				/* get inputs */
	iofp = (struct iofiles *)arg;
	src_dir = iofp->source;
	dst_dir = iofp->destination;

	fprintf(stderr, "copydirectory got: %s %s\n", src_dir, dst_dir);
	tid = 0;
	if ((dp = opendir(src_dir)) == NULL) {
		err_quit("Failed to opendir: %s", src_dir);
	}
	if (stat(dst_dir, &statbuf) == -1) {
		if (mkdir(dst_dir, DIR_MODE) == -1)
			err_sys("mkdir error");
	}

	while ((dirp = readdir(dp)) != NULL) {
		if ((!strcmp(dirp->d_name, ".")) ||
		    (!strcmp(dirp->d_name, "..")))
			continue;
		src_path = buildpath(src_dir, dirp->d_name);
		if (stat(src_path, &statbuf) == -1)
			err_sys("stat error");
		if ((infd = open(src_path, O_RDONLY)) < 0) 
		    err_sys("failed to open %s", src_path);
		dst_path = buildpath(dst_dir, dirp->d_name);
		if (S_ISDIR(statbuf.st_mode)) {
			newiofp = Malloc(sizeof(struct iofiles));
			newiofp->source = s_dup(src_path);
			newiofp->destination = s_dup(dst_path);
			copydirectory((void *)newiofp);
			continue;
		}
		if ((outfd = open(dst_path, OFLAGS, FILE_MODE)) < 0)
		    err_sys("failed to open %s", dst_path);
	
		newci = ci_init(dst_path, tid);
		newci->sourcefd = infd;
		newci->destinationfd = outfd;
		newci->next = head;
		head = newci;
		Pthread_create(&newci->tid, NULL, copyfilepass, (void *)newci);
		for (cip = head; cip != NULL; cip = cip->next) {
			(void)pthread_join(cip->tid, NULL);			
		}

		free(src_path);
		free(dst_path);
	}
	if (closedir(dp) < 0)
		err_msg("failed to close directory");
	return (void *)0;
}
Esempio n. 30
0
bool symmodel::checkcorrready()
  {
    bool corrready=true;
    for(size_t v=0; v<correspondences.size(); ++v)
      {
	if( !correspondences[v]->isinit() )
	  {
	    fprintf(stderr, "WARNING: checkcorrready(): model [%s] to model [%s] correspondence is not ready (var [%s])\n", buildpath().c_str(), correspondences[v]->targmodel->buildpath().c_str(), vars[v]->name.c_str() );
	    corrready=false;
	  }
      }
    //for all vars, for all corresp, are init?
    for( size_t m=0; m<models.size(); ++m)
      {
	if( !models[m]->checkcorrready() )
	  {
	    corrready=false;
	  }
      }
    return corrready;
  }