Esempio n. 1
0
/////////////////////////////////////////////////////////////////////////////
//
// hefile emucall handler
//
sint32 EMU_CALL psx_emucall(
  void   *state,
  uint8  *ram_native,
  uint32  ram_size,
  sint32  type,
  sint32  emufd,
  sint32  ofs,
  sint32  arg1,
  sint32  arg2
) {
  if(type == 0) {
    if(PSXSTATE->console_callback) {
      sint32 i;
      for(i = 0; i < arg1; i++) {
        char c = ram_native[ofs & (ram_size-1)]; ofs++;
        if(c == 'H') { PSXSTATE->console_enable = 1; }
        if(PSXSTATE->console_enable) {
          (PSXSTATE->console_callback)(PSXSTATE->console_context, c);
        }
      }
    }
    return arg1;
  }
  if(!(HAVE_VFS)) return -5;
  switch(type) {
  case 3: return vopen (VFSSTATE, ram_native, ram_size, ofs);
  case 4: return vclose(VFSSTATE, emufd);
  case 5: return vread (VFSSTATE, ram_native, ram_size, emufd, ofs, arg1);
  case 6: return -13; // EACCES permission denied
  case 7: return vlseek(VFSSTATE, emufd, arg1, arg2);
  default: return -5;
  }
}
Esempio n. 2
0
VSP::VSP(char *fname)
{
	VFILE *f = vopen(fname);
	if (!f)
		err("VSP::VSP() - couldn't find VSP file %s", fname);
	LoadVSP(f);
	vclose(f);
}
Esempio n. 3
0
moduser()
{
  if (!( AdminType==DOMAIN_ADMIN ||
        (AdminType==USER_ADMIN && strcmp(ActionUser,Username)==0))){
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }
  send_template( "mod_user.html" );
} 
Esempio n. 4
0
delusergo()
{
 static char forward[200];
 static char forwardto[200];
 FILE *fs;
 int i;
 struct vqpasswd *pw;
     
  if ( AdminType!=DOMAIN_ADMIN ) {
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }

  vdeluser( ActionUser, Domain );

  /* Start create forward when delete - 
   * Code added by Eugene Teo 6 June 2000 
   */

  GetValue(TmpCGI,forward, "forward=", MAX_BUFF);

#ifdef DEBUG
  fprintf(actout, "Forward: %s\n<br>", forward);
#endif

  if (strcmp(forward, "on") == 0) {

    /* replace "." in name with ":" */    

    sprintf(TmpBuf2, ".qmail-%s", ActionUser);
    for(i=6;TmpBuf2[i]!=0;++i) if ( TmpBuf2[i] == '.' ) TmpBuf2[i] = ':';
    
    if ((fs=fopen(TmpBuf2,"w")) == NULL) ack("Failed to open passwd file",21);
    
    GetValue(TmpCGI, forwardto, "forwardto=", MAX_BUFF);
        
#ifdef DEBUG        
    fprintf(actout, "Forward to: %s\n<br>", forwardto);
#endif

    fprintf(fs, "&%s", forwardto);
    fclose(fs);
        
    /* End create forward when delete - 
     * Code added by Eugene Teo 6 June 2000 
     */
  }
    
  sprintf(StatusMessage, "%s %s", ActionUser, get_html_text("141"));
    
  call_hooks(HOOK_DELUSER);
  show_users(Username, Domain, Mytime);

}
Esempio n. 5
0
adduser()
{
  count_users();
  load_limits();

  if ( AdminType!=DOMAIN_ADMIN ) {
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }
                                                
  if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) {
    sprintf(StatusMessage, "%s %d\n", get_html_text("199"),
      MaxPopAccounts);
    show_menu();
    vclose();
    exit(0);
  }

  send_template( "add_user.html" );

}
Esempio n. 6
0
static void
vcleanup( video_module_t *m )
{
	if( dga.is_open )
		vclose();

	/* is this safe? */
	if( xdga_module.modes ) {
		free( xdga_module.modes );
		xdga_module.modes = NULL;
	}
	dga.initialized = 0;
}
Esempio n. 7
0
static void
fbdev_cleanup( video_module_t *m ) 
{
	if( cv->is_open )
		vclose();
	if( cv->fd != -1 )
		close( cv->fd );
	if( cv->color_table )
		free( cv->color_table );
	free_vmodes();

	console_cleanup();
}
Esempio n. 8
0
corona::Image* load_image_from_packfile(const char* filename)
{
	VFILE* vf = vopen(filename);
	if (!vf)
	{
		err("loadimage: couldn't load image %s; couldnt find a file or a vfile", filename);
	}
	int l = filesize(vf);
	std::auto_ptr<char> buffer(new char[l]);
	vread(buffer.get(), l, vf);
	vclose(vf);
	std::auto_ptr<corona::File> memfile(corona::CreateMemoryFile(buffer.get(), l));
	return corona::OpenImage(memfile.get(), corona::FF_AUTODETECT, corona::PF_DONTCARE);
}
Esempio n. 9
0
void deleteall()
{
 FILE *fs;

  if ( (fs = fopen(".qmail-default", "w")) == NULL ) {
    fprintf(actout,"%s %s<br>\n", get_html_text("144"), ".qmail-default");
  } else {
    fprintf(fs,"| %s/bin/vdelivermail '' delete\n",VPOPMAILDIR);
    fclose(fs);
  }
  show_users(Username, Domain, Mytime);
  vclose();
  exit(0);
}
Esempio n. 10
0
int
rcv_file (struct wnn_file *wf, int mode)
{
  FILE *fp;
  int x;

/*    if(wf->localf == REMOTE){
      }
*/
  if (fopen_write_cur (wf->name) == 0)
    {
      log_err ("receive_file:No file %s.", wf->name);
      wnn_errorno = WNN_FILE_WRITE_ERROR;
      return (-1);
    }
  fp = NULL;
  x = write_file_real (wf, fp, mode);
  vclose (fp);
  return (x);
}
Esempio n. 11
0
/*
  OPEN, LOCK, UNLOCK
*/
void ivopen()
{
    int obj_cnt, item;

    for (item = 1, obj_cnt = 0; item < MAXOBJ; item++) {
	if ((g.place[item] == g.loc) && (hinged(item))) {
	    object = item;
	    obj_cnt++;
	}
    }
    if (obj_cnt != 1)
	needobj();
    else if (verb == LOCK)
	vlock();
    else if (verb == UNLOCK)
	vunlock();
    else if (verb == SHUT)
	vclose();
    else
	vopen();
}
Esempio n. 12
0
int get_catchall(void)
{
 int i,j;
 FILE *fs;

  /* Get the default catchall box name */
  if ((fs=fopen(".qmail-default","r")) == NULL) {
    fprintf(actout,"<tr><td colspan=\"5\">%s %s</td><tr>\n", 
      get_html_text("144"), ".qmail-default");
    vclose();
    exit(0);
  }
  fgets( TmpBuf, MAX_BUFF, fs);
  fclose(fs);

  if (strstr(TmpBuf, "bounce-no-mailbox") != NULL) {
    fprintf(actout,"<b>%s</b>", get_html_text("130"));

  } else if (strstr(TmpBuf, "delete") != NULL) {
    fprintf(actout,"<b>%s</b>", get_html_text("236"));

  } else if ( strstr(TmpBuf, "@") != NULL ) {
    i=strlen(TmpBuf);
    for(;TmpBuf[i]!=' ';--i);
    fprintf(actout,"<b>%s %s</b>", get_html_text("062"), &TmpBuf[i]);

  } else {
    i = strlen(TmpBuf) - 1;
    for(;TmpBuf[i]!='/';--i);
    for(++i,j=0;TmpBuf[j]!=0;++j,++i) TmpBuf2[j] = TmpBuf[i];
    TmpBuf2[j--] = '\0';

    /* take off newline */
    i = strlen(TmpBuf2); --i; TmpBuf2[i] = 0;/* take off newline */
    fprintf(actout,"<b>%s %s</b>", get_html_text("062"), TmpBuf2);
  }
  return 0;
}
Esempio n. 13
0
void Garlick_vf_close(void *handle) { vclose((VFILE*)handle); }
Esempio n. 14
0
 ~Varray(void)   { vclose(); }
Esempio n. 15
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;

	joe_locale();

	mainenv = (unsigned char **)envv;
	
	vmem = vtmp();
	startup_log = bfind_scratch(USTR "* Startup Log *");
	startup_log->internal = 1;

#ifdef __MSDOS__
	_fmode = O_BINARY;
	zlcpy(stdbuf, sizeof(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

	if ((s = (unsigned char *)getenv("LINES")) != NULL)
		sscanf((char *)s, "%d", &lines);
	if ((s = (unsigned char *)getenv("COLUMNS")) != NULL)
		sscanf((char *)s, "%d", &columns);
	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))) {
		logerror_0((char *)joe_gettext(_("Couldn't load termcap/terminfo entry\n")));
		goto exit_errors;
	}
#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) {
		logerror_1((char *)joe_gettext(_("There were errors in '%s'.  Falling back on default.\n")), s);
	}

	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)
		goto donerc;
	if (c == 1) {
		logerror_1((char *)joe_gettext(_("There were errors in '%s'.  Falling back on default.\n")), s);
	}
#else

	/* Name of system joerc file.  Try to find one with matching language... */
	
	/* Try full language: like joerc.de_DE */
	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
				time_rc = 0;
		}
	}

	/* User's joerc file */
	s = (unsigned char *)getenv("HOME");
	if (s) {
		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) {
				logmessage_2((char *)joe_gettext(_("Warning: %s is newer than your %s.\n")),t,s);
			}
		}

		c = procrc(cap, s);
		if (c == 0) {
			vsrm(t);
			goto donerc;
		}
		if (c == 1) {
			logerror_1((char *)joe_gettext(_("There were errors in '%s'.  Falling back on default.\n")), s);
		}
	}

	vsrm(s);
	s = t;
	c = procrc(cap, s);
	if (c == 0)
		goto donerc;
	if (c == 1) {
		logerror_1((char *)joe_gettext(_("There were errors in '%s'.  Falling back on default.\n")), s);
	}

	/* Try built-in joerc */
	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 *fancyjoerc not present, use *joerc which is always there */
		s = vstrunc(s, 0);
		s = vsncpy(sv(s),sc("*joerc"));
		c = procrc(cap, s);
	}
	if (c == 0)
		goto donerc;
	if (c == 1) {
		logerror_1((char *)joe_gettext(_("There were errors in '%s'.  Falling back on default.\n")), s);
	}
#endif

	logerror_1((char *)joe_gettext(_("Couldn't open '%s'\n")), s);
	goto exit_errors;
	return 1;

	donerc:

	if (validate_rc()) {
		logerror_0((char *)joe_gettext(_("rc file has no :main key binding section or no bindings.  Bye.\n")));
		goto exit_errors;
	}

	{
		unsigned char buf[10];
		int x;
		zlcpy(buf, sizeof(buf), USTR "\"`\"	`  ");
		type_backtick = mparse(0, buf, &x, 0);
	}

	shell_kbd = mkkbd(kmap_getcontext(USTR "shell"));

	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:
					logerror_1((char *)joe_gettext(_("Unknown option '%s'\n")), argv[c]);
					break;
				case 1:
					break;
				case 2:
					++c;
					break;
			} else
				idleout = 0;
		}
	}

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

	if (!(n = nopen(cap)))
		goto exit_errors;
	maint = screate(n);

	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(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 inserts the window before maint->curwin */
			if (!orphan || !opened) {
				bw = wmktw(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));
				p_goto_bol(b->oldcur);
				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(maint, bfind(USTR ""));

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

	if (logerrors) {
		B *copied = bcpy(startup_log->bof, startup_log->eof);
		BW *bw = wmktw(maint, copied);
		copied->name = zdup(startup_log->name);
		copied->internal = 1;
		maint->curwin = bw->parent;
		wshowall(maint);
	}

	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 2015 **\\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, NULL, 0);
		}
	}

	edloop(0);

	save_state();

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

	vclose(vmem);
	nclose(n);

	if  (noexmsg) {
		if (notite)
			fprintf(stderr, "\n");
	} else {
		if (exmsg)
			fprintf(stderr, "\n%s\n", exmsg);
		else if (notite)
			fprintf(stderr, "\n");
	}

	return 0;

exit_errors:

	/* Write out error log to console if we are exiting with errors. */
	if (startup_log && startup_log->eof->byte)
		bsavefd(startup_log->bof, 2, startup_log->eof->byte);
	
	return 1;
}
Esempio n. 16
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;
}
Esempio n. 17
0
modusergo()
{
 char crypted[20]; 
 char *tmpstr;
 int i;
 int ret_code;
 int password_updated = 0;
 struct vqpasswd *vpw=NULL;
 static char box[50];
 static char NewBuf[156];
 int count;
 FILE *fs;
#ifdef SQWEBMAIL_PASS
 uid_t uid;
 gid_t gid;
#endif

  vpw = vauth_getpw(ActionUser, Domain); 

  if (!( AdminType==DOMAIN_ADMIN ||
         (AdminType==USER_ADMIN && strcmp(ActionUser,Username)==0))){
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }

  if (strlen(Password1)>0 && strlen(Password2)>0 ) {
    if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) {
      sprintf(StatusMessage, "%s\n", get_html_text("200"));
      moduser();
      vclose();
      exit(0);
    }
    if (strlen(Password1) > MAX_PW_CLEAR_PASSWD) {
      sprintf(StatusMessage,"%s %s@%s %s", 
        get_html_text("139"), ActionUser, Domain, VA_PASSWD_TOO_LONG );
      moduser();
      vclose();
      exit(0);
    } else if (vpw->pw_gid & NO_PASSWD_CHNG) {
      sprintf(StatusMessage, "%s", get_html_text("140"));
      moduser();
      vclose();
      exit(0);
    } else {
        sprintf(StatusMessage,"%s %s@%s", 
            get_html_text("139"), ActionUser, Domain);
    }

    mkpasswd3(Password1,Crypted, MAX_BUFF);
    vpw->pw_passwd = Crypted;

#ifdef CLEAR_PASS
      vpw->pw_clear_passwd = Password1;
#endif
#ifdef SQWEBMAIL_PASS
      vget_assign(Domain, NULL, 0, &uid, &gid );
      vsqwebmail_pass( vpw->pw_dir, Crypted, uid, gid);
#endif

  }

  GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF);
  if ( strlen( Gecos ) != 0 ) {
    vpw->pw_gecos = Gecos;
  }
  vauth_setpw(vpw, Domain);

  /* get the value of the cforward radio button */
  GetValue(TmpCGI,box, "cforward=", MAX_BUFF);

  /* if they want to disable everything */
  if ( strcmp(box,"disable") == 0 ) {

    /* unlink the .qmail file */
    if ( vpw == NULL ) vpw = vauth_getpw(ActionUser, Domain); 
    snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir);
    unlink(NewBuf);

    /* delete any vacation directory */
    snprintf(NewBuf,156,"%s/vacation", vpw->pw_dir);
    vdelfiles(NewBuf);

  /* if they want to forward */
  } else if (strcmp(box,"forward") == 0 ) {

    /* get the value of the foward */
    GetValue(TmpCGI,box, "nforward=", MAX_BUFF);

    /* If nothing was entered, error */
    if ( box[0] == 0 ) {
      sprintf(StatusMessage, "%s\n", get_html_text("215"));
      moduser();
      vclose();
      exit(0);

    /* check it for a valid email address
    } else if ( check_email_addr( box ) == 1 )  {
      sprintf(StatusMessage, "%s\n", get_html_text("148"));
      moduser();
    */
    }

    /* everything looks good, open the file */
    if ( vpw == NULL ) {
      vpw = vauth_getpw(ActionUser, Domain); 
    }
    snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir);

    fs = fopen(NewBuf,"w+");
    tmpstr = strtok(box," ,;\n");

    count=0;
    while( tmpstr != NULL && count < 2) {
      fprintf(fs,"&%s\n", tmpstr);
      tmpstr = strtok(NULL," ,\n");
      ++count;
    }

    /* if they want to save a copy */
    GetValue(TmpCGI,box, "fsaved=", MAX_BUFF);
    if ( strcmp(box,"on") == 0 ) {
      fprintf(fs,"%s/Maildir/\n", vpw->pw_dir);
    } 
    fclose(fs);

  /* they want vacation */
  } else if (strcmp(box,"vacation") == 0 ) {

    /* get the subject */
    GetValue(TmpCGI,box, "vsubject=", MAX_BUFF);

    /* if no subject, error */
    if ( box[0] == 0 ) {
      sprintf(StatusMessage, "%s\n", get_html_text("216"));
      moduser();
      vclose();
      exit(0);
    }
 
    /* make the vacation directory */
    if ( vpw == NULL ) vpw = vauth_getpw(ActionUser, Domain); 
    snprintf(NewBuf,156,"%s/vacation", vpw->pw_dir);
    mkdir(NewBuf, 448);

    /* open the .qmail file */
    snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir);
    fs = fopen(NewBuf,"w+");
    fprintf(fs, "| %s/autorespond 86400 3 %s/vacation/message %s/vacation\n",
      AUTORESPOND_BIN, vpw->pw_dir, vpw->pw_dir );

    /* save a copy for the user */
    fprintf(fs,"%s/Maildir/\n", vpw->pw_dir);
    fclose(fs);

    /* set up the message file */
    snprintf(NewBuf,156,"%s/vacation/message", vpw->pw_dir);
    GetValue(TmpCGI,Message, "vmessage=",MAX_BIG_BUFF);

    if ( (fs = fopen(NewBuf, "w")) == NULL ) ack("123", 123);
    fprintf(fs, "From: %s@%s\n", ActionUser,Domain);
    fprintf(fs, "Subject: %s\n\n", box);
    fprintf(fs, "%s", Message);
    fclose(fs);

    /* save the forward for vacation too */
    GetValue(TmpCGI,box,"nforward=", MAX_BUFF);
    snprintf(NewBuf, 156, "%s/.qmail", vpw->pw_dir);
    fs = fopen(NewBuf, "a+");
    tmpstr = strtok(box, " ,;\n");
    count = 0;
    while( tmpstr != NULL && count < 2 ) {
      fprintf(fs, "&%s\n", tmpstr);
      tmpstr = strtok(NULL, " ,;\n");
      ++count;
    }
    fclose(fs);

  } else {
    printf("nothing\n");
  }

  call_hooks(HOOK_MODUSER);
  show_users(Username, Domain, Mytime);
}
Esempio n. 18
0
int show_user_lines(char *user, char *dom, time_t mytime, char *dir)
{
 int  i,j,k,startnumber,moreusers = 1;
 FILE *fs;
 struct vqpasswd *pw;
 int totalpages;
 int bounced;

  if (MaxPopAccounts == 0) return 0;

  /* Get the default catchall box name */
  if ((fs=fopen(".qmail-default","r")) == NULL) {
    fprintf(actout,"<tr><td colspan=\"5\">%s .qmail-default</tr></td>", 
      get_html_text("144"));
    vclose();
    exit(0);
  }

  fgets(TmpBuf, MAX_BUFF, fs);
  fclose(fs);

  if (*SearchUser) {
    pw = vauth_getall(dom,1,1);
    for (k=0; pw!=NULL; k++) {
      if ((!SearchUser[1] && *pw->pw_name >= *SearchUser) ||
          ((!strcmp(SearchUser, pw->pw_name)))) {
        break;
      }

      pw = vauth_getall(dom,0,0);
    }

    if (k == 0) sprintf(Pagenumber, "1");
    else sprintf(Pagenumber, "%d", (k/MAXUSERSPERPAGE)+1);
  }

  /* Determine number of pages */
  pw = vauth_getall(dom,1,1);
  for (k=0; pw!=NULL; k++) pw = vauth_getall(dom, 0, 0);

  if (k == 0) totalpages = 1;
  else totalpages = ((k/MAXUSERSPERPAGE)+1);

  /* End determine number of pages */
  if (atoi(Pagenumber)==0) *Pagenumber='1';

  if ( strstr(TmpBuf, "bounce-no-mailbox") != NULL ) {
    bounced = 1;
  } else if ( strstr(TmpBuf, "@") != NULL ) {
    bounced = 0;
  } else {
    bounced = 0;
    i = strlen(TmpBuf); --i; TmpBuf[i] = 0; /* take off newline */
    for(;TmpBuf[i]!='/';--i);
    for(j=0,++i;TmpBuf[i]!=0;++j,++i) TmpBuf3[j] = TmpBuf[i];
    TmpBuf3[j]=0;
  }

  startnumber = MAXUSERSPERPAGE * (atoi(Pagenumber) - 1);

  /*
   * check to see if there are any users to list, 
   * otherwise repeat previous page
   *  
   */
  pw = vauth_getall(dom,1,1);
  if ( AdminType==DOMAIN_ADMIN ||
       (AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)){

    for (k = 0; k < startnumber; ++k) { 
      pw = vauth_getall(dom,0,0); 
    }
  }

  if (pw == NULL) {
    fprintf(actout, "<tr><td colspan=\"5\" bgcolor=%s>%s</td></tr>\n", 
      get_color_text("000"), get_html_text("131"));
      moreusers = 0;
    } else {
      while ((pw != NULL) && ((k < MAXUSERSPERPAGE + startnumber) ||  
              (AdminType!=DOMAIN_ADMIN || AdminType!=DOMAIN_ADMIN || 
              (AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)))) {
        if (AdminType==DOMAIN_ADMIN || 
            (AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)) {

          fprintf(actout, "<tr bgcolor=%s>", get_color_text("000"));
          fprintf(actout, "<td align=\"left\">%s</td>", pw->pw_name);
          fprintf(actout, "<td align=\"left\">%s</td>", pw->pw_gecos);
          fprintf(actout, "<td align=\"center\">");
          fprintf(actout, "<a href=\"%s/com/moduser?user=%s&dom=%s&time=%d&moduser=%s\">",
            CGIPATH,user,dom,mytime,pw->pw_name);
          fprintf(actout, "<img src=\"/images/qmailadmin/delete.png\" border=\"0\"></a>");
          fprintf(actout, "</td>");
            

          /* if the user is postmaster, or has admin privileges, 
           * prevent deleting 
           */

          if (strncmp(pw->pw_name, "postmaster", 11) == 0 ||
              (strncmp(pw->pw_name, Username, strlen(pw->pw_name)) == 0 
                && strlen(pw->pw_name) == strlen(Username)
                && AdminType==DOMAIN_ADMIN)) {
            fprintf(actout, "<td align=\"center\">");
            fprintf(actout, "<img src=\"/images/qmailadmin/disabled.png\" border=\"0\">");
            fprintf(actout, "</td>");

            /* if the user has admin privileges and pw->pw_name is not 
             * the user or postmaster, allow deleting 
             */
          } else if (AdminType==DOMAIN_ADMIN && 
                   strncmp(pw->pw_name, Username, strlen(pw->pw_name)) != 0 ) {
            fprintf(actout, "<td align=\"center\">");
            fprintf(actout, "<a href=\"%s/com/deluser?user=%s&dom=%s&time=%d&deluser=%s\">",
              CGIPATH,user,dom,mytime,pw->pw_name);
            fprintf(actout, "<img src=\"/images/qmailadmin/delete.png\" border=\"0\"></a>");
            fprintf(actout, "</td>");

          /* special case when pw->pw_name contains the user's name, but 
           * is not the user or postmaster, allow deleting 
           */
          } else if (AdminType==DOMAIN_ADMIN && 
                     strncmp(pw->pw_name, Username, strlen(pw->pw_name)) == 0 
                     && strlen(pw->pw_name) != strlen(Username)) {
            fprintf(actout, "<td align=\"center\">");
            fprintf(actout, "<a href=\"%s/com/deluser?user=%s&dom=%s&time=%d&deluser=%s\">",
              CGIPATH,user,dom,mytime,pw->pw_name);
            fprintf(actout, "<img src=\"/images/qmailadmin/delete.png\" border=\"0\"></a>");
              fprintf(actout, "</td>");

          /* else, don't allow deleting */
          } else {
            fprintf(actout, "<td align=\"center\">");
            fprintf(actout, "<img src=\"/images/qmailadmin/disabled.png\" border=\"0\">");
            fprintf(actout, "</td>");
          }

          if (bounced==0 && strncmp(pw->pw_name,TmpBuf3,MAX_BUFF) == 0) {
            fprintf(actout, "<td align=\"center\">%s</td>", 
              get_html_text("132"));
          } else if (AdminType==DOMAIN_ADMIN) {
            fprintf(actout, "<td align=\"center\">");
            fprintf(actout, "<a href=\"%s/com/setdefault?user=%s&dom=%s&time=%d&deluser=%s&page=%s\">",
              CGIPATH,user,dom,mytime,pw->pw_name,Pagenumber);
            fprintf(actout, "<img src=\"/images/qmailadmin/delete.png\" border=\"0\"></a>");
            fprintf(actout, "</td>");
          } else {
            fprintf(actout, "<td align=\"center\">");
            fprintf(actout, "<img src=\"/images/qmailadmin/disabled.png\" border=\"0\">");
            fprintf(actout, "</td>");
          }

          fprintf(actout, "</tr>\n");
        }        
        pw = vauth_getall(dom,0,0);
        ++k;
      }
    }

    if (AdminType == DOMAIN_ADMIN) {
#ifdef USER_INDEX
      fprintf(actout, "<tr bgcolor=%s>", get_color_text("000"));
      fprintf(actout, "<td colspan=\"5\" align=\"center\">");
      fprintf(actout, "<hr>");
      fprintf(actout, "<b>%s</b>", get_html_text("133"));
      fprintf(actout, "<br>");
      for (k = 97; k < 123; k++) {
        fprintf(actout, "<a href=\"%s/com/showusers?user=%s&dom=%s&time=%d&searchuser=%c\">%c</a>\n",
          CGIPATH,user,dom,mytime,k,k);
      }
      fprintf(actout, "<br>");
      for (k = 0; k < 10; k++) {
        fprintf(actout, "<a href=\"%s/com/showusers?user=%s&dom=%s&time=%d&searchuser=%d\">%d</a>\n",
          CGIPATH,user,dom,mytime,k,k);
      }
      fprintf(actout, "</td>");
      fprintf(actout, "</tr>\n");

      fprintf(actout, "<tr bgcolor=%s>", get_color_text("000"));
      fprintf(actout, "<td colspan=\"5\">");
      fprintf(actout, "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"center\"><br>");
      fprintf(actout, "<form method=\"get\" action=\"%s/com/showusers\">", 
        CGIPATH);
      fprintf(actout, "<input type=\"hidden\" name=\"user\" value=\"%s\">", 
        user);
      fprintf(actout, "<input type=\"hidden\" name=\"dom\" value=\"%s\">", 
        dom);
      fprintf(actout, "<input type=\"hidden\" name=\"time\" value=\"%d\">", 
        mytime);
      fprintf(actout, "<input type=\"text\" name=\"searchuser\" value=\"%s\">&nbsp;", SearchUser);
      fprintf(actout, "<input type=\"submit\" value=\"%s\">", 
        get_html_text("204"));
      fprintf(actout, "</form>");
      fprintf(actout, "</td></tr></table>");
      fprintf(actout, "<hr>");
      fprintf(actout, "</td></tr>\n");
#endif

      fprintf(actout, "<tr bgcolor=%s>", get_color_text("000"));
      fprintf(actout, "<td colspan=\"5\" align=\"right\">");
#ifdef USER_INDEX
      fprintf(actout, "<font size=\"2\"><b>");
      fprintf(actout, "[&nbsp;");
      /* only display "previous page" if pagenumber > 1 */
      if (atoi(Pagenumber) > 1) {
        fprintf(actout, "<a href=\"%s/com/showusers?user=%s&dom=%s&time=%d&page=%d\">%s</a>",
          CGIPATH,user,dom,mytime,
          atoi(Pagenumber)-1 ? atoi(Pagenumber)-1 : atoi(Pagenumber), 
          get_html_text("135"));
        fprintf(actout, "&nbsp;|&nbsp");
      }
/*
        fprintf(actout, "<a href=\"%s/com/showusers?user=%s&dom=%s&time=%d&page=%s\">%s</a>",
            CGIPATH,user,dom,mytime,Pagenumber,get_html_text("136"));
*/

      if (moreusers && atoi(Pagenumber) < totalpages) {
        fprintf(actout,"<a href=\"%s/com/showusers?user=%s&dom=%s&time=%d&page=%d\">%s</a>",
          CGIPATH,user,dom,mytime,atoi(Pagenumber)+1,
          get_html_text("137"));
        fprintf(actout, "&nbsp;|&nbsp");
      }
/*        fprintf(actout, "&nbsp;|&nbsp");*/
#endif
      fprintf(actout, "<a href=\"%s/com/deleteall?user=%s&dom=%s&time=%d\">%s</a>", 
        CGIPATH,user,dom,mytime,get_html_text("235"));
      fprintf(actout, "&nbsp;|&nbsp");
      fprintf(actout, "<a href=\"%s/com/bounceall?user=%s&dom=%s&time=%d\">%s</a>", 
        CGIPATH,user,dom,mytime,get_html_text("134"));
      fprintf(actout, "&nbsp;|&nbsp");
      fprintf(actout, "<a href=\"%s/com/setremotecatchall?user=%s&dom=%s&time=%d\">%s</a>", 
        CGIPATH,user,dom,mytime,get_html_text("206"));
      fprintf(actout, "&nbsp]");
      fprintf(actout, "</b></font>");
      fprintf(actout, "</td></tr>\n");
  }
  return 0;
}
Esempio n. 19
0
MAP::MAP(char *fname)
{
	VFILE *f = vopen(fname);
	if (!f)
		err("MAP::MAP() - could not load map %s", fname);

	strcpy(mapfname, fname);
	strlwr(mapfname);

	char signature[8];
	vread(signature, 6, f);
	if (strcmp(signature, maptag))
		err("MAP::MAP() - %s is not a valid mapfile!", fname);

	int version;
	vread(&version, 4, f);
	if (version != MAP_VERSION)
		err("MAP::MAP() - %s is not the correct MAP format version!", fname);
	vread(&version, 4, f); // skip vc offset

	vread(mapname, 256, f);
	vread(vspname, 256, f);
	strcpy(savevspname, vspname); // Overkill 2006-05-21
	vread(musicname, 256, f);
	vread(renderstring, 256, f);
	vread(startupscript, 256, f);

	PlayMusic(musicname);

	startx = starty = 0;
	vread(&startx, 2, f);
	vread(&starty, 2, f);

	std::string s = std::string(fname);
	int offs = s.rfind('\\');
	if (offs >= 0)
	{
		s.replace(offs+1,strlen(fname),vspname);
		tileset = new VSP((char *)s.c_str());
	}
	else
	{
		offs = s.rfind('/');
		if (offs >= 0)
		{
			s.replace(offs+1,strlen(fname),vspname);
			tileset = new VSP((char *)s.c_str());
		}
		else
			tileset = new VSP(vspname);
	}

	vread(&numlayers, 4, f);

	//layers = new Layer*[numlayers];
	layers.resize(numlayers);
	int i;
	for (i=0; i<numlayers; i++)
		layers[i] = new Layer(f);

	mapwidth = layers[0]->width;
	mapheight = layers[0]->height;

	obslayer = new byte[mapwidth*mapheight];
	zonelayer = new word[mapwidth*mapheight];
	cvread(obslayer, mapwidth*mapheight, f);
	cvread(zonelayer, mapwidth*mapheight*2, f);

	vread(&numzones, 4, f);
	zones.resize(numzones);
	for (i=0; i<numzones; i++)
	{
		zones[i] = new Zone;
		zones[i]->percent = zones[i]->method = zones[i]->delay = 0;
		vread(zones[i]->name, 256, f);
		vread(zones[i]->script, 256, f);
		vread(&zones[i]->percent, 1, f);
		vread(&zones[i]->delay, 1, f);
		vread(&zones[i]->method, 1, f);
	}

	vread(&mapentities, 4, f);

	for (i=0; i<mapentities; i++)
	{
		int t=0, x1=0, y1=0, x2=0, y2=0;
		char movescript[256], chrname[256], script[256], description[256];

		vread(&x1, 2, f);
		vread(&y1, 2, f);
		int o1 = vtell(f);
		vseek(f, 22, 1);
		vread(movescript, 256, f);
		vread(chrname, 256, f);
		vread(description, 256, f); // this is actually the description which we dont care about
		vread(script, 256, f); // this is the actual script
		vseek(f, o1, 0);

		int i = AllocateEntity(x1*16, y1*16, chrname);

		entity[i]->description = description;
		entity[i]->script = script;
		vread(&t, 1, f);
		if (!t) t = SOUTH;
		entity[i]->setface(t); t=0;
		vread(&t, 1, f);
		entity[i]->obstructable = t ? true : false; t=0;
		vread(&t, 1, f);
		entity[i]->obstruction = t ? true : false; t=0;
		vread(&t, 1, f);
		entity[i]->autoface = (t!=0); t=0;
		vread(&t, 2, f);
		entity[i]->setspeed(t); t=0;
		vread(&t, 1, f);
		// activation mode FIXME
		vread(&t, 1, f);

		vread(&x1, 2, f);
		vread(&y1, 2, f);
		vread(&x2, 2, f);
		vread(&y2, 2, f);
		switch(t)
		{
			case 0: entity[i]->SetMotionless(); break;
			case 1: entity[i]->SetWanderZone(); break;
			case 2: entity[i]->SetWanderBox(x1, y1, x2, y2); break; //FIXME
			case 3: entity[i]->SetMoveScript(movescript); break;
		}
		t=0; vread(&t, 2, f);
		entity[i]->SetWanderDelay(t);
		vread(&t, 4, f);
		vseek(f, 1024, 1);
		/*
		vread(&tlen, 4, f);
		vread(ename, tlen+1, f);
		// chr filename
		vread(&tlen, 4, f);
		vread(chrfn, tlen+1, f);
		// script
		vread(&tlen, 4, f);
		vread(escript, tlen+1, f);
		// movescript
		vread(&tlen, 4, f);
		vread(emovescript, tlen+1, f);

		vread(&tlen, 4, f);
		vread(&tlen, 4, f);
		int eface, speed, tx, ty;
		vread(&eface, 4, f);
		vread(&speed, 4, f);
		vread(&tx, 4, f);
		vread(&ty, 4, f);

		vread(&x1, 4, f);
		vread(&y1, 4, f);
		vread(&x2, 4, f);
		vread(&y2, 4, f);

		int idx = AllocateEntity(tx*16, ty*16, chrfn);
		entity[idx]->setface(eface);
		entity[idx]->setspeed(speed);
		entity[idx]->script = escript;
		entity[idx]->autoface = (eflags & ENT_AUTOFACE) ? true : false;
		entity[idx]->obstructable = (eflags & ENT_OBSTRUCTED) ? true : false;
		entity[idx]->obstruction = (eflags & ENT_OBSTRUCTS) ? true : false;

		if (method == ENT_MOVESCRIPT) entity[idx]->SetMoveScript(emovescript);
		if (method == ENT_WANDERZONE) entity[idx]->SetWanderZone();
		if (method == ENT_WANDERBOX) entity[idx]->SetWanderBox(x1, y1, x2, y2);*/
	}
	current_map = this;
	se->LoadMapScript(f, mapfname);
	vclose(f);
	se->ExecuteFunctionString(startupscript);
}
Esempio n. 20
0
// Build and pop up a buffer containing a list of all screens and their associated buffers.  Render buffer and return status.
int showScreens(Value *rp,int n) {
	Buffer *slistp;
	EScreen *scrp;			// Pointer to current screen to list.
	EWindow *winp;			// Pointer into current screens window list.
	uint wnum;
	StrList rpt;
	int windcol = 7;
	int filecol = 37;
	char *strp,wkbuf[filecol + 16];

	// Get a buffer and open a string list.
	if(sysbuf(text160,&slistp) != SUCCESS)
			// "Screens"
		return rc.status;
	if(vopen(&rpt,NULL,false) != 0)
		return vrcset();

	// Construct the header lines.
	if(vputs(text89,&rpt) != 0 || vputc('\n',&rpt) != 0 ||
	    // "Screen Window      Buffer                File"
	 vputs("------ ------  --------------------  -------------------------------",&rpt) != 0)
		return vrcset();

	// For all screens...
	scrp = sheadp;
	do {
		// Store the screen number.
		sprintf(wkbuf,"\n%4hu   ",scrp->s_num);
		strp = strchr(wkbuf,'\0');

		// List screen's window numbers and buffer names.
		wnum = 0;
		winp = scrp->s_wheadp;
		do {
			Buffer *bufp = winp->w_bufp;

			// Indent if not first time through.
			if(wnum != 0) {
				wkbuf[0] = '\n';
				strp = wkbuf + 1;
				do {
					*strp++ = ' ';
					} while(strp <= wkbuf + windcol);
				}

			// Store window number, buffer name, and filename.
			sprintf(strp,"%4u   %c%s",++wnum,(bufp->b_flags & BFCHGD) ? '*' : ' ',bufp->b_bname);
			strp = strchr(strp,'\0');
			if(bufp->b_fname != NULL)			// Pad if filename exists.
				do {
					*strp++ = ' ';
					} while(strp <= wkbuf + filecol);
			*strp = '\0';					// Save buffer and add filename.
			if(vputs(wkbuf,&rpt) != 0 ||
			 (bufp->b_fname != NULL && vputs(bufp->b_fname,&rpt) != 0))
				return vrcset();

			// On to the next window.
			} while((winp = winp->w_nextp) != NULL);

		// On to the next screen.
		} while((scrp = scrp->s_nextp) != NULL);

	// Add the results to the buffer.
	if(vclose(&rpt) != 0)
		return vrcset();
	if(bappend(slistp,rpt.sl_vp->v_strp) != SUCCESS)
		return rc.status;

	// Display results.
	return render(rp,n < 0 ? -2 : n,slistp,RENDRESET | (n != INT_MIN && n < -1 ? RENDALTML : 0));
	}
Esempio n. 21
0
// Overkill (2006-07-20): Saver functions!
void MAP::save(FILE *f)
{
	int i;
	char tempfn[16] = "$$v3map.tmp";
	FILE *out = fopen(tempfn, "wb");
	if (!out) err("Unable to open %s for writing!", tempfn);
	// Map signature.
	char signature[8];
	strcpy(signature, maptag);
	fwrite(&signature, 1, 6, f);

	// Version
	int version = MAP_VERSION;
	fwrite(&version, 1, 4, f);

	// USE OUTPUT BUFFER FROM THIS POINT ON.
	fwrite(mapname, 1, 256, out);
	//log("mapname: %s", mapname);
	// savevspname, not vspname because it's what the vsp file WILL be,
	// not necessarily what it IS at that moment.
	// So, you can set it then FileSaveVSP() down the line.
	fwrite(savevspname, 1, 256, out);
	//log("savevspname: %s", savevspname);
	fwrite(musicname, 1, 256, out);
	//log("musicname: %s", musicname);
	fwrite(renderstring, 1, 256, out);
	//log("renderstring: %s", renderstring);
	fwrite(startupscript, 1, 256, out);
	//log("startupscript: %s", startupscript);
	fwrite(&startx, 1, 2, out);
	fwrite(&starty, 1, 2, out);

	fwrite(&numlayers, 1, 4, out);
	for (i = 0; i < numlayers; i++)
	{
		layers[i]->save(out);
	}

	// Obs.
	cfwrite(obslayer, 1, mapwidth*mapheight, out);
	// Zones
	cfwrite(zonelayer, 1, mapwidth*mapheight*2, out);

	fwrite(&numzones, 1, 4, out);
	for (i=0; i<numzones; i++)
	{
		fwrite(zones[i]->name, 1, 256, out);
		fwrite(zones[i]->script, 1, 256, out);
		fwrite(&zones[i]->percent, 1, 1, out);
		fwrite(&zones[i]->delay, 1, 1, out);
		fwrite(&zones[i]->method, 1, 1, out);
	}

	// ENTITIES! <3.
	fwrite(&entities, 1, 4, out);
	for (i=0; i<entities; i++)
	{
		//log("ENT %d of %d", i, entities);
		// Tile coords.
		int x = entity[i]->x / 16;
		int y = entity[i]->y / 16;
		fwrite(&x, 1, 2, out);
		fwrite(&y, 1, 2, out);
		fwrite(&entity[i]->face, 1, 1, out);
		fwrite(&entity[i]->obstructable, 1, 1, out);
		fwrite(&entity[i]->obstruction, 1, 1, out);
		fwrite(&entity[i]->autoface, 1, 1, out);
		fwrite(&entity[i]->speed, 1, 2, out);
		//log("HERE?");
		// FIXME: ACTIVATION MODE
		int activationMode = 0;
		fwrite(&activationMode, 1, 1, out);
		// Movecode and wandering.
		fwrite(&entity[i]->movecode, 1, 1, out);
		fwrite(&entity[i]->wx1, 1, 2, out);
		fwrite(&entity[i]->wy1, 1, 2, out);
		fwrite(&entity[i]->wx2, 1, 2, out);
		fwrite(&entity[i]->wy2, 1, 2, out);
		fwrite(&entity[i]->wdelay, 1, 2, out);
		//log("YAR?");
		// Expand! whatever, man.
		int expand = 0;
		fwrite(&expand, 1, 4, out);

		// h8 u STD::string.
		char tempchar[256];

		//log("movestr: %s", entity[i]->movestr);
		fwrite(entity[i]->movestr, 1, 256, out);
		strcpy(tempchar, entity[i]->chr->name.c_str());
		fwrite(tempchar, 1, 256, out);
		strcpy(tempchar, entity[i]->description.c_str());
		fwrite(tempchar, 1, 256, out); // description
		strcpy(tempchar, entity[i]->script.c_str());
		fwrite(tempchar, 1, 256, out); // The actual script position.
	}
	// NO LONGER NEED TO USE THE OUTPUT BUFFER
	fclose(out);
	
	// Why vopen instead? I... don't know!
	// Now that we've finished the buffer though, we can
	// use this to fill in the unknown map information.
	
	VFILE *tmp = vopen(tempfn);
	if (!tmp) err("Could not open %s for reading!", tempfn);
	int bufferlength = filesize(tmp);
	byte* buf = new byte[bufferlength];
	vread(buf, bufferlength, tmp);
	vclose(tmp);
	// Delete the temporary buffer, we've gotten what we wanted.
	remove(tempfn);

	// Alright... finally, all this to get the offset for the VC stuffs.
	int vcofs = 14 + bufferlength;
	fwrite(&vcofs, 1, 4, f);
	// Write the buffer into the map now.
	fwrite(buf, 1, bufferlength, f);
	// VC funcs are waaay down here.
	int vcfuncs = 0; // number compiled should be none.
	//log("VCOFS: %d CURRENT POS: %d", vcofs, ftell(f));
	fwrite(&vcfuncs, 1, 4, f);
}
Esempio n. 22
0
int
read_file (struct wnn_file *wf)
{
  FILE *fp;
  struct wnn_file_head fh;
  if (wf->localf == REMOTE)
    {
      if (fopen_read_cur (wf->name) == 0)
        {
          wnn_errorno = WNN_FILE_READ_ERROR;
          log_err ("read_file:could not open file %s.", wf->name);
          return (-1);
        }
      fp = NULL;
    }
  else
    {
#ifdef WRITE_CHECK
      check_backup (wf->name);
#endif
      if ((fp = fopen (wf->name, "r")) == NULL)
        {
          wnn_errorno = WNN_FILE_READ_ERROR;
          log_err("read_file:could not open file %s.", wf->name);
          return (-1);
        }
    }
  if (input_file_header (fp, &fh) == -1)
    {
      wnn_errorno = WNN_NOT_A_FILE;
      goto ERROR_RET;
    }
  bcopy ((char *) &(fh.file_uniq), (char *) &(wf->f_uniq), WNN_F_UNIQ_LEN);
  bcopy ((char *) &(fh.file_uniq_org), (char *) &(wf->f_uniq_org), WNN_F_UNIQ_LEN);
  strncpy (wf->passwd, fh.file_passwd, WNN_PASSWD_LEN);
  wf->file_type = fh.file_type;
  wf->ref_count = 0;

  switch (fh.file_type)
    {
    case WNN_FT_DICT_FILE:
      wf->area = (char *) readdict (fp);
      if (wf->area == NULL)
        goto ERROR_RET;
      break;
    case WNN_FT_HINDO_FILE:
      wf->area = (char *) readhindo (fp);
      if (wf->area == NULL)
        goto ERROR_RET;
      break;
    case WNN_FT_FUZOKUGO_FILE:
      wf->area = (char *) fzk_read (fp);
      if (wf->area == NULL)
        goto ERROR_RET;
      break;
    }
  vclose (fp);
  return (0);
ERROR_RET:
  vclose (fp);
  return (-1);
}
Esempio n. 23
0
addusernow()
{
 char pw[50];
 int cnt=0, num;
 char *c_num;
 char **mailingListNames;
 char *tmp;
 char *email;
 char **arguments;
 int pid;
 int i;
 int error;
 struct vqpasswd *mypw;


  c_num = malloc(MAX_BUFF);
  email = malloc(128);
  tmp = malloc(MAX_BUFF);
  arguments = (char **)malloc(MAX_BUFF);

  count_users();
  load_limits();

  if ( AdminType!=DOMAIN_ADMIN ) {
    sprintf(StatusMessage,"%s", get_html_text("142"));
    vclose();
    exit(0);
  }

  if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) {
    sprintf(StatusMessage, "%s %d\n", get_html_text("199"),
      MaxPopAccounts);
    show_menu();
    vclose();
    exit(0);
  }
 
  GetValue(TmpCGI,Newu, "newu=", MAX_BUFF);

  if ( fixup_local_name(Newu) ) {
    sprintf(StatusMessage, "%s %s\n", get_html_text("148"), Newu);
    adduser();
    vclose();
    exit(0);
  } 

  if ( check_local_user(Newu) ) {
    sprintf(StatusMessage, "%s %s\n", get_html_text("175"), Newu);
    adduser();
    vclose();
    exit(0);
  } 
  GetValue(TmpCGI,Password1, "password1=", MAX_BUFF);
  GetValue(TmpCGI,Password2, "password2=", MAX_BUFF);
  if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) {
    sprintf(StatusMessage, "%s\n", get_html_text("200"));
    adduser();
    vclose();
    exit(0);
  }

  if ( strlen(Password1) <= 0 ) {
    sprintf(StatusMessage, "%s\n", get_html_text("234"));
    adduser();
    vclose();
    exit(0);
  }

  strcpy(email, "");
  strcat(email,Newu);
  strcat(email,"@");
  strcat(email,Domain);
    
  GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF);
  if ( strlen( Gecos ) == 0 ) {
    strcpy(Gecos, Newu);
  }

  GetValue(TmpCGI, c_num, "number_of_mailinglist=", MAX_BUFF);
  num = atoi(c_num);
  if(!(mailingListNames = malloc(sizeof(char *) * num))) {
    sprintf(StatusMessage, "%s\n", get_html_text("201"));
    vclose();
    exit(0);

  } else {
    for(cnt = 0; cnt < num; cnt++) {
      if(!(mailingListNames[cnt] = malloc(MAX_BUFF))) {
        sprintf(StatusMessage, "%s\n", get_html_text("201"));
        vclose();
        exit(0);
      }
    }

    for(cnt = 0; cnt < num; cnt++) {
      sprintf(tmp, "subscribe%d=", cnt);
      error = GetValue(TmpCGI, mailingListNames[cnt], tmp, MAX_BUFF);
      if( error != -1 ) {
        pid=fork();

        if (pid==0) {
          sprintf(TmpBuf1, "%s/ezmlm-sub", EZMLMDIR);
          sprintf(TmpBuf2, "%s/%s", RealDir, mailingListNames[cnt]);
          execl(TmpBuf1, "ezmlm-sub", TmpBuf2, email, NULL);
          exit(127);
        } else {
          wait(&pid);
        }
      } 
    }
  }

  /* add the user then get the vpopmail password structure */
  if ( vadduser( Newu, Domain, Password1, Gecos, USE_POP ) == 0 && 
#ifdef MYSQL_REPLICATION
    !sleep(2) &&
#endif
    (mypw = vauth_getpw( Newu, Domain )) != NULL ) {

    /* from the load_limits() function, set user flags */
    if( DisablePOP > 0 )     mypw->pw_gid |= NO_POP; 
    if( DisableIMAP > 0 )    mypw->pw_gid |= NO_IMAP; 
    if( DisableDialup > 0 )  mypw->pw_gid |= NO_DIALUP; 
    if( DisablePasswordChanging > 0 ) mypw->pw_gid |= NO_PASSWD_CHNG; 
    if( DisableWebmail > 0 ) mypw->pw_gid |= NO_WEBMAIL; 
    if( DisableRelay > 0 )  mypw->pw_gid |= NO_RELAY; 
    if( DefaultQuota[0]!= 0 ) mypw->pw_shell = DefaultQuota;

    /* update the user information */
    if ( vauth_setpw( mypw, Domain ) != VA_SUCCESS ) {

      /* report error */
      sprintf(StatusMessage, "%s %s@%s (%s) %s",
        get_html_text("002"), Newu, Domain, Gecos,
        get_html_text("120"));

    } else {

      /* report success */
      sprintf(StatusMessage, "%s %s@%s (%s) %s",
        get_html_text("002"), Newu, Domain, Gecos,
        get_html_text("119"));
      }

    /* otherwise, report error */
  } else {
    sprintf(StatusMessage, "<font color=\"red\">%s %s@%s (%s) %s</font>", 
      get_html_text("002"), Newu, Domain, Gecos, get_html_text("120"));
  }

  call_hooks( HOOK_ADDUSER );

  /* After we add the user, show the user page
   * people like to visually verify the results
   */
  show_users(Username, Domain, Mytime);

}
Esempio n. 24
0
// Display a pop-up window and page it for the user.  If altmodeline is true, display buffer name and filename (only) on bottom
// mode line.  If endprompt is true, wait for user to press a key before returning (regardless of page size).  Current bindings
// (if any) for backPage, forwPage, backLine, and forwLine commands are recognized as well as 'b' (backward page), 'f' or space
// (forward page), 'u' (backward half page), 'd' (forward half page), 'g' (goto first page), 'G' (goto last page), ESC or 'q'
// (exit), and '?' (help).  Any non-navigation key gets pushed back into the input stream to be interpeted later as a command. 
// Return status.
int bpop(Buffer *bufp,bool altmodeline,bool endprompt) {
	Line *lnp1,*lnp,*lpmax;
	int crow;		// Current screen row number.
	int disprows;		// Total number of display rows.
	int halfpage;		// Rows in a half page.
	int n;			// Rows to move.
	ushort ek;		// Input extended key.
	char *strp,*strpz;	// Line text pointers.
	char *hprompt = NULL;	// Help prompt;
	bool firstpass = true;

	// Display special mode line if requested.
	if(altmodeline) {

		// Find last window on screen and rewrite its mode line.
		wupd_modeline(wnextis(NULL),bufp);
		}

	// Set up and display a pop-up "window".
	disprows = term.t_nrow - 2;

	// Check if buffer will fit on one page and if not, set lpmax to first line of last page.
	lpmax = NULL;
	n = 0;
	for(lnp = lforw(bufp->b_hdrlnp); lnp != bufp->b_hdrlnp; lnp = lforw(lnp)) {
		if(++n > disprows) {

			// Find beginning of last page.
			lpmax = bufp->b_hdrlnp;
			n = disprows;
			do {
				lpmax = lback(lpmax);
				} while(--n > 0);
			break;
			}
		}

	// Begin at the beginning.
	lnp1 = lforw(bufp->b_hdrlnp);
	halfpage = disprows / 2;
	n = 0;

	// Display a page (beginning at line lnp1 + n) and prompt for a naviagtion command.  Loop until exit key entered or
	// endprompt is false and buffer fits on one page (lpmax is NULL).
	for(;;) {
		lnp = lnp1;

		// Moving backward?
		if(n < 0) {
			do {
				// At beginning of buffer?
				if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp))
					break;

				// No, back up one line.
				lnp1 = lback(lnp1);
				} while(++n < 0);
			}

		// Moving forward?
		else if(n > 0) {
			do {
				// At end of buffer or max line?
				if(lpmax == NULL || lnp1 == bufp->b_hdrlnp || lnp1 == lpmax)
					break;

				// No, move forward one line.
				lnp1 = lforw(lnp1);
				} while(--n > 0);
			}

		// Illegal command?
		if(n != 0 && lnp1 == lnp)

			// Yes, ignore it.
			n = 0;
		else {
			// Found first row ... display page.
			lnp = lnp1;
			crow = 0;
			do {
				// At end of buffer?
				if(lnp == bufp->b_hdrlnp) {

					// Yes, erase remaining lines on physical screen.
					while(crow < disprows) {
						vtmove(crow,0);
						vteeol();
#if COLOR
						vscreen[crow]->v_rfcolor = gfcolor;
						vscreen[crow]->v_rbcolor = gbcolor;
#endif
						vscreen[crow]->v_left = FARRIGHT;
						vscreen[crow]->v_right = 0;
#if COLOR
						vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR;
#else
						vscreen[crow++]->v_flags |= VFCHGD;
#endif
						}
					break;
					}

				// Update the virtual screen image for this line.  Characters past right edge of screen won't be
				// displayed, so ignore those.
				vtmove(crow,0);
				strpz = (strp = ltext(lnp)) + (lused(lnp) <= (int) term.t_ncol ? lused(lnp) : term.t_ncol);
				while(strp < strpz)
					vtputc(*strp++);
				vteeol();
#if COLOR
				vscreen[crow]->v_rfcolor = gfcolor;
				vscreen[crow]->v_rbcolor = gbcolor;
#endif
				vscreen[crow]->v_left = FARRIGHT;
				vscreen[crow]->v_right = 0;
#if COLOR
				vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR;
#else
				vscreen[crow++]->v_flags |= VFCHGD;
#endif
				// On to the next line.
				lnp = lforw(lnp);
				} while(crow < disprows);

			// Screen is full.  Copy the virtual screen to the physical screen.
			if(pupd_all(false) != SUCCESS)
				return rc.status;

			// Bail out if called from terminp() and one-page buffer.
			if(firstpass && !endprompt && lpmax == NULL)
				goto uexit;
			firstpass = false;
			}

		// Display prompt.
		mlputs(MLHOME | MLFORCE,hprompt != NULL ? hprompt : lpmax == NULL || lnp1 == lpmax ? text201 : ": ");
													// "End: "
		if(TTflush() != SUCCESS)
			return rc.status;

		// Get response.
		for(;;) {
			// Get a keystroke and decode it.
			if(getkey(&ek) != SUCCESS)
				return rc.status;

			// Exit?
			if(ek == (CTRL | '[') || ek == 'q')
				goto uexit;

			// Forward whole page?
			if(ek == ' ' || ek == 'f' || iscmd(ek,forwPage)) {
				n = disprows - overlap;
				break;
				}

			// Forward half page?
			if(ek == 'd') {
				n = halfpage;
				break;
				}

			// Backward whole page?
			if(ek == 'b' || iscmd(ek,backPage)) {
				n = overlap - disprows;
				break;
				}

			// Backward half page?
			if(ek == 'u') {
				n = -halfpage;
				break;
				}

			// Forward a line?
			if(iscmd(ek,forwLine)) {
				n = 1;
				break;
				}

			// Backward a line?
			if(iscmd(ek,backLine)) {
				n = -1;
				break;
				}

			// First page?
			if(ek == 'g') {
				if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp))
					n = -1;			// Force beep.
				else {
					lnp1 = lforw(bufp->b_hdrlnp);
					n = 0;
					}
				break;
				}

			// Last page?
			if(ek == 'G') {
				if(lpmax == NULL || lnp1 == lpmax)
					n = 1;			// Force beep.
				else {
					lnp1 = lpmax;
					n = 0;
					}
				break;
				}

			// Help?
			if(ek == '?') {
				StrList msg;

				// Get string list...
				if(vopen(&msg,NULL,false) != 0)
					return vrcset();

				// build prompt...
				if(vputs(text202,&msg) != 0)
						// "(<SPC>,f"
					return vrcset();
				if(hkey(&msg,forwPage,0) != SUCCESS)
					return rc.status;
				if(vputs(text203,&msg) != 0)
						// ") +page (b"
					return vrcset();
				if(hkey(&msg,backPage,0) != SUCCESS)
					return rc.status;
				if(vputs(text204,&msg) != 0)
						// ") -page (d) +half (u) -half"
					return vrcset();
				if(hkey(&msg,forwLine,'+') != SUCCESS || hkey(&msg,backLine,'-') != SUCCESS)
					return rc.status;
				if(vputs(text206,&msg) != 0)
						// " (g) first (G) last (ESC,q) quit (?) help: "
					return vrcset();

				// and display it.
				if(vclose(&msg) != 0)
					return vrcset();
				mlputs(MLHOME | MLFORCE,msg.sl_vp->v_strp);
				}
			else {
				// Other key.  "Unget" the key for reprocessing and return.
				tungetc(ek);
				goto uexit;
				}
			}
		}
uexit:
	uphard();
	if(endprompt)
		mlerase(MLFORCE);

	return rc.status;
	}