Пример #1
0
int main (int argc, char *argv[])
{
  test_threads ();
  init_bufs ();

  return f1 (1, 2);
}
Пример #2
0
static
void init(FILE *peer)
{
	enum velo2_ret ret;
	pp_info_msg_t lmsg, rmsg;

	ret = velo2_open(&velo2_port);
	extoll_ret_check(ret, "velo2_open()");

	init_bufs();

	/* Get local peer information */
	pp_info_get(&lmsg);

	if (is_server) {
		pp_info_write(peer, &lmsg);
		pp_info_read(peer, &rmsg);
	} else {
		pp_info_read(peer, &rmsg);
		pp_info_write(peer, &lmsg);
	}

	pp_info_set(&rmsg);

	ret = velo2_connect(&velo2_port, &remote_connection,
			    remote_nodeid, remote_vpid);
	extoll_ret_check(ret, "velo2_connect()");

	printf("I'm the %s\n", is_server ? "server" : "client");
	sleep(1);
}
Пример #3
0
Файл: find.c Проект: 5kg/gdb
int
main ()
{
  init_bufs ();

  stop_here ();

  /* Reference variables.  */
  x = int8_search_buf[0];
  x = int16_search_buf[0];
  x = int32_search_buf[0];
  x = int64_search_buf[0];

  return 0;
}
Пример #4
0
void do_getpeer(void)
{
	int i = 0, ret;
	size_t addrlen;
	void *addr;
	struct gnix_ep_name *dest_addr, rebuilt;
	struct fid_ep *ep_fid;

	ret = fi_getpeer(get_fid_ep(0, NULL, NULL, NULL), NULL, NULL);
	cr_assert(ret == -FI_EINVAL, "fi_getpeer returned: %s",
		  fi_strerror(-ret));

	for (i = 0; i < NUMEPS; i++) {
		ep_fid = get_fid_ep(i, NULL, (void **) &dest_addr, NULL);
		addrlen = ep_name_len[i];
		addr = malloc(addrlen);
		ret = errno;
		cr_assert_not_null(addr, "malloc returned: %s", strerror(ret));
		init_bufs(&addr, 1, addrlen);

		addrlen = 0;
		ret = fi_getpeer(ep_fid, addr, &addrlen);
		cr_assert(ret == -FI_ETOOSMALL, "fi_getpeer returned: %s",
			  fi_strerror(-ret));

		ret = fi_getpeer(ep_fid, addr, &addrlen);
		cr_assert(ret == FI_SUCCESS, "fi_getpeer returned: %s",
			  fi_strerror(-ret));

		if (use_str_fmt) {
			dbg_printf(BLUE "strlen(addr) = %lu\n" COLOR_RESET,
				   strlen(addr));

			fas_to_ep_name(addr, &rebuilt);
			check_ep_name(*dest_addr, rebuilt);
		} else {
			check_ep_name(*dest_addr,
				      ((struct gnix_ep_name *) addr)[0]);
		}

		free(addr);
	}
}
Пример #5
0
void do_setname(void)
{
	int i, ret;
	void *addr;
	struct gnix_ep_name *src_addr = NULL, rebuilt;
	struct fi_info *info = NULL;

	ret = fi_setname(get_fid[ep_type](0), NULL, 0xbabbbcbd);
	cr_assert(ret == -FI_EINVAL, "fi_setname returned: %s",
		  fi_strerror(-ret));

	for (i = 0; i < NUMEPS; i++) {
		addr = malloc(ep_name_len[i]);
		ret = errno;
		cr_assert_not_null(addr, "malloc returned: %s", strerror(ret));

		if (use_str_fmt)
			generate_rand_fas((char **) &addr);
		else
			init_bufs(&addr, 1, ep_name_len[i]);

		ret = fi_setname(get_fid[ep_type](i), addr, ep_name_len[i]);
		cr_assert(ret == FI_SUCCESS, "fi_setname returned: %s",
			  fi_strerror(-ret));

		get_fid_ep(i, (void **) &info, (void **) NULL, (void **)
			&src_addr);

		/* Ensure that the address was set properly. */
		if (use_str_fmt) {
			fas_to_ep_name(addr, &rebuilt);
			check_ep_name(rebuilt, *src_addr);
		} else {
			check_ep_name(((struct gnix_ep_name *)addr)[0],
				      *src_addr);
		}


		free(addr);
	}
}
Пример #6
0
static
void init(void)
{
	int rc;
	if (!getenv("LIBELAN_MACHINES_FILE")) {
		printf("set?\nexport LIBELAN_MACHINES_FILE=elanidmap\n\n");
	}

	base = elan_baseInit(0);
	my_rank = base->state->vp;
	printf("My Rank:%2u from %2u\n", my_rank, base->state->nvp);
	assert(base->state->nvp >= 2);

	init_bufs();

	printf("r_buf:           %p\n", r_buf);
	printf("remote r_buf?\n");
	rc = scanf("%p", &remote_rbuf);
	assert(rc == 1);

	printf("Accept r_buf: %p\n", remote_rbuf);
}
Пример #7
0
void do_sep_send_recv_iter(int idx, int len)
{
	ssize_t sz;
	int i = 0;
	uint64_t cntr;
	ssize_t ret, src_done, dest_done;
	struct fi_cq_tagged_entry s_cqe = {(void *) -1, UINT_MAX, UINT_MAX,
					   (void *) -1, UINT_MAX, UINT_MAX};
	struct fi_cq_tagged_entry d_cqe = {(void *) -1, UINT_MAX, UINT_MAX,
					   (void *) -1, UINT_MAX, UINT_MAX};
	struct fi_cq_tagged_entry s_expected_cqe, d_expected_cqe;

	init_bufs((void **) source, NUMEPS, len);
	init_bufs((void **) target, NUMEPS, len);

	for (i = 0; i < NUMEPS; i++) {
		dbg_printf(BLUE
				   "From ep(%d) to ep(%d) of xfer size %d\n"
				   COLOR_RESET, i, NUMEPS - 1 - i, len);

		s_expected_cqe.buf = NULL;
		s_expected_cqe.data = 0;
		s_expected_cqe.flags = (FI_MSG | FI_TRANSMIT/*FI_SEND*/);
		s_expected_cqe.len = 0;
		s_expected_cqe.op_context = target[NUMEPS - 1 - i];
		s_expected_cqe.tag = 0;

		sz = fi_send(tx_ep[i][idx], source[i], len, NULL,
			     gni_addr[NUMEPS - 1 - i], target[NUMEPS - 1 - i]);

		cr_assert(sz == FI_SUCCESS, "Invalid return value: %s",
			  fi_strerror((int) -sz));

		d_expected_cqe.buf = NULL;
		d_expected_cqe.data = 0;
		d_expected_cqe.flags = (FI_MSG | FI_RECV);
		d_expected_cqe.len = len;
		d_expected_cqe.op_context = source[i];
		d_expected_cqe.tag = 0;

		sz = fi_recv(rx_ep[NUMEPS - 1 - i][idx],
			     target[NUMEPS - 1 - i], len,
			     NULL, gni_addr[i], source[i]);

		cr_assert(sz == FI_SUCCESS, "Invalid return value: %s",
			  fi_strerror((int) -sz));

		src_done = dest_done = 0;
		/* Progress sender and receiver */
		do {
			ret = fi_cq_read(tx_cq[i][idx], &s_cqe, 1);
			if (ret == 1)
				src_done = 1;

			ret = fi_cq_read(rx_cq[NUMEPS - 1 - i][idx],
					 &d_cqe, 1);
			if (ret == 1)
				dest_done = 1;
		} while (src_done != 1 || dest_done != 1);

		cntr = fi_cntr_read(send_cntr[i]);
		cr_assert(cntr == ++sends[i],
			  "Invalid send counter: actual(%lu), expected(%lu)",
			  cntr, sends[i]);

		cntr = fi_cntr_read(recv_cntr[NUMEPS - 1 - i]);
		cr_assert(cntr == ++recvs[NUMEPS - 1 - i],
			  "Invalid recv counter: actual(%lu), expected(%lu)",
			  cntr, recvs[NUMEPS - 1 - i]);

		check_tagged_cqe(s_expected_cqe, s_cqe);
		check_tagged_cqe(d_expected_cqe, d_cqe);

		check_buf(source[i], target[NUMEPS - 1 - i], len);
	}
}
Пример #8
0
MpBufPoolPtr MpBufPool_MpBufPool(int poolSize, int maxBufferLen,
      int numBuffers, int cacheAlign)
{
        int i;
        int n;
        int totalBytes;
        int numBufs;
        int numBytes;
        int bufBytes;
        char *b;
        char *storage;
        MpBufPoolPtr pool;
        MpBufPtr bufs;

#ifdef BUFFER_INSTRUMENTATION /* [ */
        if (20 > bufferPoolCreates++) {
            Zprintf("MpBufPool_MpBufPool(%d, %d, %d, %d)\n",
                poolSize, maxBufferLen, numBuffers, cacheAlign, 0,0);
        }
#endif /* BUFFER_INSTRUMENTATION ] */

        pool = (MpBufPoolPtr) malloc(sizeof(MpBufPool));
        if (NULL == pool) {
            Zprintf("MpBufPool: unable to malloc %d bytes!\n",
                sizeof(MpBufPool), 0,0,0,0,0);
            return NULL;
        }
        memset((char *) pool, 0, sizeof(MpBufPool));
        pool->cacheAlignment = cacheAlign;

        pool->mpMutex = new OsMutex(OsMutex::Q_PRIORITY);
        if (NULL == pool->mpMutex) {
            Zprintf("MpBufPool: unable to create Mutex!\n", 0,0,0,0,0,0);
            free(pool);
            return NULL;
        }

        pool->mpMutex->acquire();

        numBufs = poolSize / maxBufferLen;
        if (numBufs < MIN_BUFFER_COUNT) {
            numBufs = numBuffers;
        }
        if (numBufs < MIN_BUFFER_COUNT) {
            Zprintf("MpBufPool: request to create %d buffers: too few (<%d)\n",
                numBufs, MIN_BUFFER_COUNT, 0,0,0,0);
            pool->mpMutex->release();
            delete pool->mpMutex;
            free(pool);
            return NULL;
        }

        totalBytes = numBufs * sizeof(MpBuf);
        bufs = (MpBufPtr) malloc(totalBytes);
        if (NULL == bufs) {
            Zprintf("MpBufPool: unable to malloc %d bytes!\n",
                numBufs * sizeof(MpBuf), 0,0,0,0,0);
            pool->mpMutex->release();
            delete pool->mpMutex;
            free(pool);
            return NULL;
        }
        memset((char *) bufs, 0, totalBytes);
        pool->table = bufs;

        if (((unsigned int) bufs) < LowBufTable) {
            LowBufTable = (unsigned int) bufs;
        }

        if (((unsigned int) (bufs + numBufs)) > HighBufTable) {
            HighBufTable = (unsigned int) (bufs + numBufs);
        }

        if (0 == cacheAlign) {
            bufBytes = maxBufferLen;
            numBytes = numBufs * bufBytes;
        } else {

            /*
             * The number of bytes in each buffer must be a
             * multiple of the data cache line size
             */

             /* round up the buffer size, and the total buffer space */
            i = (maxBufferLen + cacheAlign - 1) / cacheAlign;
            bufBytes = cacheAlign * i;
            numBytes = numBufs * bufBytes + cacheAlign - 1;
        }
        storage = (char *) malloc(numBytes);
        if (NULL == storage) {
            Zprintf("MpBufPool: unable to malloc %d bytes!\n",
                numBytes, 0,0,0,0,0);
            free(bufs);
            pool->mpMutex->release();
            delete pool->mpMutex;
            free(pool);
            return NULL;
        }
        pool->MpBufPoolData = storage;
        totalBytes += numBytes;

        pool->eachLen = bufBytes;
        pool->size = sizeof(MpBufPool);
        pool->allocCnt = numBufs;
        pool->allocSize = totalBytes;
        pool->maxAllocCnt = 0;
        pool->maxAllocSize = 0;
        pool->lastTaken = 0;

        if (0 == cacheAlign) {
            b = storage;
        } else {

             /* round up the base of the first buffer */

            i = (unsigned int) storage;
            n = i % cacheAlign;
            if (0 != n) {
                n = cacheAlign - n;
            }
            b = storage + n;
        }

#ifdef BUFFER_INSTRUMENTATION /* [ */
        if (20 > bufferPoolCreates) {
           Zprintf("buffer data base address = 0x%X (0x%X) (%d)\n",
              (int) b, (int) (pool->MpBufPoolData),
              b - (char *)(pool->MpBufPoolData), 0,0,0);
        }
#endif /* BUFFER_INSTRUMENTATION ] */

        init_bufs(numBufs, bufBytes, pool, b, bufs);

#ifdef BUFFER_INSTRUMENTATION /* [ */
        pool->nfree = numBufs;
        pool->minfree = numBufs;
        if (20 > bufferPoolCreates) {
#ifdef _VXWORKS /* [ */
            int x;
            x = StartLogging();
#endif /* _VXWORKS ] */
            dumpBufs(1);
#ifdef _VXWORKS /* [ */
            if (0 == x) StopLogging(0);
#endif /* _VXWORKS ] */
        }
#endif /* BUFFER_INSTRUMENTATION ] */

        pool->mpMutex->release();
        return pool;
}
Пример #9
0
int main(int argc, char **real_argv, char **envv)
{
	CAP *cap;
	unsigned char **argv = (unsigned char **)real_argv;
	struct stat sbuf;
	unsigned char *s;
	unsigned char *t;
	long time_rc;
	unsigned char *run;
#ifdef __MSDOS__
	unsigned char *rundir;
#endif
	SCRN *n;
	int opened = 0;
	int omid;
	int backopt;
	int c;

	init_bufs();

	for (c = 1; argv[c] != NULL; ++c) {
		if (0 == zcmp((unsigned char*)argv[c], USTR "-nosys")) {
			read_sys_configs = 0;
		} else if (0 == zcmp((unsigned char*)argv[c], USTR "-nouser")) {
			read_user_configs = 0;
		} else {
			argv[--c] = argv[0];
			argv += c;
			argc -= c;
			break;
		}
	}

	if (read_user_configs) {
		s = (unsigned char *)getenv("HOME");
		if (s) {
			s = vsncpy(NULL, 0, sz(s));
			s = vsncpy(sv(s), sc("/.joe-p37/only.rc"));
			if (!stat((char*)s, &sbuf)) read_sys_configs = 0;
			vsrm(s);
		}
	}

	joe_locale();

	mainenv = (unsigned char **)envv;

#ifdef __MSDOS__
	_fmode = O_BINARY;
	zcpy(stdbuf, argv[0]);
	joesep(stdbuf);
	run = namprt(stdbuf);
	rundir = dirprt(stdbuf);
	for (c = 0; run[c]; ++c)
		if (run[c] == '.') {
			run = vstrunc(run, c);
			break;
		}
#else
	run = namprt(argv[0]);
#endif

	env_lines = 0;
	if ((s = (unsigned char *)getenv("LINES")) != NULL &&
	    sscanf((char *)s, "%d", &env_lines) != 1)
		env_lines = 0;
	env_columns = 0;
	if ((s = (unsigned char *)getenv("COLUMNS")) != NULL &&
	    sscanf((char *)s, "%d", &env_columns) != 1)
		env_columns = 0;
	if ((s = (unsigned char *)getenv("BAUD")) != NULL)
		sscanf((char *)s, "%u", (unsigned *)&Baud);
	if (getenv("DOPADDING"))
		dopadding = 1;
	if (getenv("NOXON"))
		noxon = 1;
	if ((s = (unsigned char *)getenv("JOETERM")) != NULL)
		joeterm = s;

#ifndef __MSDOS__
	if (!(cap = my_getcap(NULL, 9600, NULL, NULL))) {
		fprintf(stderr, (char *)joe_gettext(_("Couldn't load termcap/terminfo entry\n")));
		return 1;
	}
#endif

#ifdef __MSDOS__

	s = vsncpy(NULL, 0, sv(run));
	s = vsncpy(sv(s), sc("rc"));
	c = procrc(cap, s);
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr, (char *)joe_gettext(_("There were errors in '%s'.  Use it anyway?")), s);
		fflush(stderr);
		if (NULL == fgets(buf, 8, stdin) || yn_checks(yes_key, buf))
			goto donerc;
	}

	vsrm(s);
	s = vsncpy(NULL, 0, sv(rundir));
	s = vsncpy(sv(s), sv(run));
	s = vsncpy(sv(s), sc("rc"));
	c = procrc(cap, s);
	if (c != 0 && c != 1) {
		/* If built-in *fancyjoerc not present, process builtin *joerc,
		 * which is always present.
		 */
		s = vstrunc(s, 0);
		s = vsncpy(sv(s), sc("*joerc"));
		c = procrc(cap, s);
	}
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr, (char *)joe_gettext(_("There were errors in '%s'.  Use it anyway?")), s);
		fflush(stderr);
		if (NULL == fgets(buf, 8, stdin) || yn_checks(yes_key, buf))
			goto donerc;
	}
#else

	/* Name of system joerc file.  Try to find one with matching language... */
	
	/* Try full language: like joerc.de_DE */
	time_rc = 0;
        if (!read_sys_configs) { t = NULL; goto skip_joerc; }
        t = vsncpy(NULL, 0, sc(JOERC));
	t = vsncpy(sv(t), sv(run));
	t = vsncpy(sv(t), sc("rc."));
	t = vsncpy(sv(t), sz(locale_msgs));
	if (!stat((char *)t,&sbuf))
		time_rc = sbuf.st_mtime;
	else {
		/* Try generic language: like joerc.de */
		if (locale_msgs[0] && locale_msgs[1] && locale_msgs[2]=='_') {
			vsrm(t);
			t = vsncpy(NULL, 0, sc(JOERC));
			t = vsncpy(sv(t), sv(run));
			t = vsncpy(sv(t), sc("rc."));
			t = vsncpy(sv(t), locale_msgs, 2);
			if (!stat((char *)t,&sbuf))
				time_rc = sbuf.st_mtime;
			else
				goto nope;
		} else {
			nope:
			vsrm(t);
			/* Try Joe's bad english */
			t = vsncpy(NULL, 0, sc(JOERC));
			t = vsncpy(sv(t), sv(run));
			t = vsncpy(sv(t), sc("rc"));
			if (!stat((char *)t,&sbuf))
				time_rc = sbuf.st_mtime;
			else {
				/* If built-in *fancyjoerc not present, process builtin *joerc,
				 * which is always present.
				 */
				t = vstrunc(s, 0);
				t = vsncpy(sv(s), sc("*joerc"));
				time_rc = stat((char *)t,&sbuf) ? 0 : sbuf.st_mtime;
			}
		}
	}
	skip_joerc:

	/* User's joerc file */
	s = (unsigned char *)getenv("HOME");
	if (s && !read_sys_configs) {
		if (read_user_configs) {  /* TODO(pts): Don't read /dev/null */
			s = vsncpy(NULL, 0, sz(s));
			s = vsncpy(sv(s), sc("/.joe-p37/rc"));
		} else {
			s = vsncpy(NULL, 0, sc("/dev/null/missing"));
		}
		goto process_user_rc;
	} else if (!read_user_configs) {
		s = vsncpy(NULL, 0, sc("/dev/null/missing"));
		goto process_user_rc;
	} else if (s) {
		unsigned char buf[8];

		s = vsncpy(NULL, 0, sz(s));
		s = vsncpy(sv(s), sc("/."));
		s = vsncpy(sv(s), sv(run));
		s = vsncpy(sv(s), sc("rc"));

		if (!stat((char *)s,&sbuf)) {
			if (sbuf.st_mtime < time_rc) {
				fprintf(stderr,(char *)joe_gettext(_("Warning: %s is newer than your %s.\n")),t,s);
				fprintf(stderr,(char *)joe_gettext(_("You should update or delete %s\n")),s);
				fprintf(stderr,(char *)joe_gettext(_("Hit enter to continue with %s ")),t);
				fflush(stderr);
				(void)!fgets((char *)buf, 8, stdin);
				goto use_sys;
			}
		}

	      process_user_rc:
		c = procrc(cap, s);
		if (c == 0) {
			vsrm(t);
			goto donerc;
		}
		if (c == 1) {
			fprintf(stderr,(char *)joe_gettext(_("There were errors in '%s'.  Use it anyway (y,n)? ")), s);
			fflush(stderr);
			if (NULL == fgets((char *)buf, 8, stdin) || ynchecks(yes_key, buf)) {
				vsrm(t);
				goto donerc;
			}
		}
	}

	use_sys:
	vsrm(s);
	s = t;
	c = s ? procrc(cap, s) : -1;
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr,(char *)joe_gettext(_("There were errors in '%s'.  Use it anyway (y,n)? ")), s);
		fflush(stderr);
		if (NULL == fgets((char *)buf, 8, stdin) || ynchecks(yes_key, buf))
			goto donerc;
	}

	/* Try built-in *fancyjoerc, e.g. "*joe-p37rc" */
	vsrm(s);
	s = vsncpy(NULL, 0, sc("*"));
	s = vsncpy(sv(s), sv(run));
	s = vsncpy(sv(s), sc("rc"));
	c = procrc(cap, s);
	if (c != 0 && c != 1) {
		/* If built-in *fancyjoerc not present, process builtin "*joerc",
		 * which is always present.
		 */
		s = vstrunc(s, 0);
		s = vsncpy(sv(s), sc("*joerc"));
		c = procrc(cap, s);
	}
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr,(char *)joe_gettext(_("There were errors in '%s'.  Use it anyway (y,n)? ")), s);
		fflush(stderr);
		if (NULL == fgets((char *)buf, 8, stdin) || ynchecks(yes_key, buf))
			goto donerc;
	}
#endif

	fprintf(stderr,(char *)joe_gettext(_("Couldn't open '%s'\n")), s);
	vsrm(s);
	return 1;

	donerc:
	vsrm(s);

	if (validate_rc()) {
		fprintf(stderr,(char *)joe_gettext(_("rc file has no :main key binding section or no bindings.  Bye.\n")));
		return 1;
	}


	if (!isatty(fileno(stdin)))
		idleout = 0;

	for (c = 1; argv[c]; ++c) {
		if (argv[c][0] == '-') {
			if (argv[c][1])
				switch (glopt(argv[c] + 1, argv[c + 1], NULL, 1)) {
				case 0:
					fprintf(stderr,(char *)joe_gettext(_("Unknown option '%s'\n")), argv[c]);
					break;
				case 1:
					break;
				case 2:
					++c;
					break;
			} else
				idleout = 0;
		}
	}
	if (!dspasis) {  /* Open all files as ASCII by default if `joe --asis' is specified. This is to avoid writing control characters to the UTF-8 terminal. */
		fdefault.charmap = pdefault.charmap = find_charmap(USTR "ascii");
		fdefault.map_name = pdefault.map_name = USTR "ascii";
	}


	/* initialize mouse support */
	if (xmouse && (s=(unsigned char *)getenv("TERM")) && strstr((char *)s,"xterm"))
		usexmouse=1;

	if (!(n = nopen(cap)))
		return 1;
	maint = screate(n);
	vmem = vtmp();

	startup_log = bfind_scratch_incref(USTR "* Startup Log *");
	startup_log->internal = 1;

	load_state();

	/* It would be better if this ran uedit() to load files */

	/* The business with backopt is to load the file first, then apply file
	 * local options afterwords */

	/* orphan is not compatible with exemac()- macros need a window to exist */
	for (c = 1, backopt = 0; argv[c]; ++c)
		if (argv[c][0] == '+' && argv[c][1]>='0' && argv[c][1]<='9') {
			if (!backopt)
				backopt = c;
		} else if (argv[c][0] == '-' && argv[c][1]) {
			if (!backopt)
				backopt = c;
			if (glopt(argv[c] + 1, argv[c + 1], NULL, 0) == 2)
				++c;
		} else {
			B *b = bfind_incref(argv[c]);
			BW *bw = NULL;
			int er = berror;

			/* This is too annoying */
			/* set_current_dir(argv[c],1); */

			setup_history(&filehist);
			append_history(filehist,sz(argv[c]));

			/* wmktw_takeref() inserts the window before maint->curwin */
			if (!orphan || !opened) {
				bw = wmktw_takeref(maint, b);
				if (er)
					msgnwt(bw->parent, joe_gettext(msgs[-er]));
			} else {
				long line;
				b->orphan = 1;
				b->oldcur = pdup(b->bof, USTR "main");
				pline(b->oldcur, get_file_pos(b->name));
				line = b->oldcur->line - (maint->h - 1) / 2;
				if (line < 0)
					line = 0;
				b->oldtop = pdup(b->oldcur, USTR "main");
				pline(b->oldtop, line);
				p_goto_bol(b->oldtop);
			}
			if (bw) {
				long lnum = 0;

				bw->o.readonly = bw->b->rdonly;
				if (backopt) {
					while (backopt != c) {
						if (argv[backopt][0] == '+') {
							sscanf((char *)(argv[backopt] + 1), "%ld", &lnum);
							++backopt;
						} else {
							if (glopt(argv[backopt] + 1, argv[backopt + 1], &bw->o, 0) == 2)
								backopt += 2;
							else
								backopt += 1;
							lazy_opts(bw->b, &bw->o);
						}
					}
				}
				bw->b->o = bw->o;
				bw->b->rdonly = bw->o.readonly;
				/* Put cursor in window, so macros work properly */
				maint->curwin = bw->parent;
				/* Execute macro */
				if (er == -1 && bw->o.mnew)
					exmacro(bw->o.mnew,1);
				if (er == 0 && bw->o.mold)
					exmacro(bw->o.mold,1);
				/* Hmm... window might not exist any more... depends on what macro does... */
				if (lnum > 0)
					pline(bw->cursor, lnum - 1);
				else
					pline(bw->cursor, get_file_pos(bw->b->name));
				p_goto_bol(bw->cursor);
				/* Go back to first window so windows are in same order as command line  */
				if (opened)
					wnext(maint);
				
			}
			opened = 1;
			backopt = 0;
		}

	

	if (opened) {
		wshowall(maint);
		omid = mid;
		mid = 1;
		dofollows();
		mid = omid;
	} else {
		BW *bw = wmktw_takeref(maint, bfind_incref(USTR ""));

		if (bw->o.mnew)
			exmacro(bw->o.mnew,1);
	}
	maint->curwin = maint->topwin;

	if (startup_log->eof->byte) {
		BW *bw = wmktw_takeref(maint, startup_log);
		startup_log = NULL;
		maint->curwin = bw->parent;
		wshowall(maint);
		uparserr(bw);
	}

	if (help) {
		help_on(maint);
	}
	if (!nonotice) {
		joe_snprintf_3(msgbuf,JOE_MSGBUFSIZE,joe_gettext(_("\\i** Joe's Own Editor v%s ** (%s) ** Copyright %s 2008 **\\i")),VERSION,locale_map->name,(locale_map->type ? "©" : "(C)"));

		msgnw(((BASE *)lastw(maint)->object)->parent, msgbuf);
	}

	if (!idleout) {
		if (!isatty(fileno(stdin)) && modify_logic(maint->curwin->object, ((BW *)maint->curwin->object)->b)) {
			/* Start shell going in first window */
			unsigned char **a;
			unsigned char *cmd;

			a = vamk(10);
			cmd = vsncpy(NULL, 0, sc("/bin/sh"));
			a = vaadd(a, cmd);
			cmd = vsncpy(NULL, 0, sc("-c"));
			a = vaadd(a, cmd);
			cmd = vsncpy(NULL, 0, sc("/bin/cat"));
			a = vaadd(a, cmd);
			
			cstart (maint->curwin->object, USTR "/bin/sh", a, NULL, NULL, 0, 1);
		}
	}

	edloop(0);

	save_state();

	/* Delete all buffer so left over locks get eliminated */
	brmall();

	vclose(vmem);
	nclose(n);

	if (exmsg)
		fprintf(stderr, "\n%s\n", exmsg);
	return 0;
}