Exemplo n.º 1
0
AddProjectForm::AddProjectForm(int rows, int cols,  Srv* srv, const char* projname, bool userexist) : NForm(rows,cols)
{
    this->srv = srv;
    settitle(projname);
    this->projname = projname;
    this->userexist = userexist;
    Item* project = NULL;
    if (srv !=NULL)
	project = srv->findprojectbynamefromall(projname);
    int row = 0;
    //поля
    try
    {
	genfields(row,project);
    }
    catch(const char* err)
    {
	kLogPrintf("ERROR EXCAPTION %s\n",err);
    }
    //пересчитываем высоту формы, чтобы влезли все поля и центрируем
    int r,c =0;
    scale_form(frm, &r, &c);
    kLogPrintf("field_count=%d scale_form()->%d,%d\n", field_count(frm), r, c);
    resize(r+3,c+2);
    post_form(frm);
    this->refresh();
}
Exemplo n.º 2
0
void 
wrapup(int signo) {
  char *msg = "\n\rconsoled is being killed\n\r";
  settitle("consoled: wrapping up");
  if (verbosesignalhandlers) kprintf("wrapup signo: %d pid %d\n",signo, getpid());

  if (getpid() == progpid) exit(0);
  write(console,msg,strlen(msg));
  settitle("consoled: killing helper");
  killhelper();
  settitle("consoled: killing prog");
  killprog();
  if (verbose) printf("exiting %d\n",getpid());
  settitle("consoled: exiting");
  exit(0);
}
Exemplo n.º 3
0
/* initialization plot struct --------------------------------------------------
* set value to plot struct
* args   : sdrplt_t *acq    I/0 plot struct for acquisition
*          sdrplt_t *trk    I/0 plot struct for tracking
*          sdrch_t  *sdr    I   sdr channel struct
* return : int                  0:okay -1:error
*-----------------------------------------------------------------------------*/
extern int initpltstruct(sdrplt_t *acq, sdrplt_t *trk, sdrch_t *sdr)
{
    double scale=1.0;

    /* acquisition */
    if (sdrini.pltacq) {
        setsdrplotprm(acq,PLT_SURFZ,sdr->acq.nfreq,sdr->nsamp,3,OFF,1,
            PLT_H,PLT_W,PLT_MH,PLT_MW,sdr->no);
        if (initsdrplot(acq)<0) return -1;
        settitle(acq,sdr->satstr);
        setlabel(acq,"Frequency (Hz)","Code Offset (sample)");
    }
    /* tracking */
    if (sdrini.plttrk) {
        setsdrplotprm(trk,PLT_XY,1+2*sdr->trk.corrn,0,0,ON,0.001,
            PLT_H,PLT_W,PLT_MH,PLT_MW,sdr->no);
        if(initsdrplot(trk)<0) return -1;
        settitle(trk,sdr->satstr);
        setlabel(trk,"Code Offset (sample)","Correlation Output");
        
        switch (sdrini.fend) {
            case FEND_GN3SV2:
            case FEND_GN3SV3:
            case FEND_FGN3SV2:
            case FEND_FGN3SV3:
                scale=1.5; break;
            case FEND_BLADERF:
            case FEND_FBLADERF:
                scale=5.0; break;
            case FEND_RTLSDR:
            case FEND_FRTLSDR:
                scale=3.5; break;
        }
        setyrange(trk,0,sdr->trk.loop*sdr->nsamp/4000*scale);
    }

    if (sdrini.fend==FEND_FILE||sdrini.fend==FEND_FSTEREO||
        sdrini.fend==FEND_FGN3SV2||sdrini.fend==FEND_FGN3SV2||
        sdrini.fend==FEND_FRTLSDR||sdrini.fend==FEND_FBLADERF) {
        trk->pltms=PLT_MS_FILE;
    } else {
        trk->pltms=PLT_MS;
    }
    return 0;
}
Exemplo n.º 4
0
int CodesObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = TSqlObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getid(); break;
        case 1: *reinterpret_cast< QString*>(_v) = gettitle(); break;
        case 2: *reinterpret_cast< QString*>(_v) = getcode(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getcode_url(); break;
        case 4: *reinterpret_cast< int*>(_v) = getstatus(); break;
        case 5: *reinterpret_cast< QDateTime*>(_v) = getcreated_at(); break;
        case 6: *reinterpret_cast< QDateTime*>(_v) = getupdated_at(); break;
        case 7: *reinterpret_cast< int*>(_v) = geteditable(); break;
        case 8: *reinterpret_cast< int*>(_v) = getuser_id(); break;
        case 9: *reinterpret_cast< QString*>(_v) = getshow_from(); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setid(*reinterpret_cast< int*>(_v)); break;
        case 1: settitle(*reinterpret_cast< QString*>(_v)); break;
        case 2: setcode(*reinterpret_cast< QString*>(_v)); break;
        case 3: setcode_url(*reinterpret_cast< QString*>(_v)); break;
        case 4: setstatus(*reinterpret_cast< int*>(_v)); break;
        case 5: setcreated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 6: setupdated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 7: seteditable(*reinterpret_cast< int*>(_v)); break;
        case 8: setuser_id(*reinterpret_cast< int*>(_v)); break;
        case 9: setshow_from(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 10;
    } else if (_c == QMetaObject::RegisterPropertyMetaType) {
        if (_id < 10)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 10;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemplo n.º 5
0
// constructor
PicEditWindow::PicEditWindow(const QString& fileName, QScrollArea *parent) :QScrollArea(parent){
    // file name
    curFile = new QString;
    fulCurFile = new QString;

    // set title and icon
    settitle(fileName);
    setBackgroundRole(QPalette::Dark);

    // once close, delete all heap memory
    setAttribute(Qt::WA_DeleteOnClose);
}
Exemplo n.º 6
0
/* returns process id of new process, prompts for username and starts /bin/login */
pid_t 
start_login(int slavefd) {
  pid_t pid;
  static char *username;

  assert(slavefd >= 0);

  if ((pid = fork()) == 0) {
    char *argv[10];
    char *envp[2];
    int argc = 0;
    /* child */
    close(master);
    close(console);

    dup2(slavefd,0);
    dup2(slavefd,1);
    dup2(slavefd,2);
    if (slave > 2) close(slavefd);
    settitle("consoled: login");

    if (setsid() == -1) {
      fprintf(stderr,"setsid failed: errno %d\n",errno);
      exit(-1);
    }
    if (ioctl(0, TIOCSCTTY, (char *)0) < 0) {
      fprintf(stderr,"ioctl slave TIOSCTTY failed: %d,%d\n",pid,errno);
      exit(-1);
    }
    print_banner();
    username = getloginname();
    if (username == NULL) exit(-1);
    envp[0] = "TERM=pc3";
    envp[1] = NULL;
    
    argv[argc++] = "login";
    argv[argc++] = "-p";	/* preserve environment */
    argv[argc++] = "-h";
    argv[argc++] = "localhost";
    argv[argc++] = username;
    argv[argc] = NULL;
    if (execve(LOGIN,argv,envp) == -1) {
      fprintf(stderr,"exec failed\n");
      exit(-1);
    }
    /* never reached */
  }
  return pid;
}
int PostObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = TSqlObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getid(); break;
        case 1: *reinterpret_cast< int*>(_v) = getblog_id(); break;
        case 2: *reinterpret_cast< QString*>(_v) = gettitle(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getcontent(); break;
        case 4: *reinterpret_cast< QDateTime*>(_v) = getcreated_at(); break;
        case 5: *reinterpret_cast< QDateTime*>(_v) = getupdated_at(); break;
        case 6: *reinterpret_cast< int*>(_v) = getlock_revision(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setid(*reinterpret_cast< int*>(_v)); break;
        case 1: setblog_id(*reinterpret_cast< int*>(_v)); break;
        case 2: settitle(*reinterpret_cast< QString*>(_v)); break;
        case 3: setcontent(*reinterpret_cast< QString*>(_v)); break;
        case 4: setcreated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 5: setupdated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 6: setlock_revision(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemplo n.º 8
0
/*--------------------------------------- Private functions -----------------------------------------*/
bool PicEditWindow::saveFile(const QString &fileName){
    // !!! if here the cursor state change hasn't been used, the program will announce abnormal ending
    // once close the program ??? why
    // set cursor as wait state
    QApplication::setOverrideCursor(Qt::WaitCursor);

    // emit save file signal
    emit saveImgFile(fileName);
    settitle(fileName);

    // restore cursor state
    QApplication::restoreOverrideCursor();

    // restore window modify state
    setWindowModified(false);

    return true;
}
Exemplo n.º 9
0
AddProjectForm::AddProjectForm(int rows, int cols,  Srv* srv, const char* projname, bool userexist) : NForm(rows,cols)
{
    this->srv = srv;
    settitle(projname);
    this->projname = projname;
    this->userexist = userexist;
    Item* project = NULL;
    if (srv !=NULL)
	project = srv->findprojectbynamefromall(projname);
    int row = 1;
    //поля
    genfields(row,project);
    //пересчитываем высоту формы, чтобы влезли все поля и центрируем
    resize(row + 2,getwidth());
    move(getmaxy(stdscr)/2-getheight()/2,getmaxx(stdscr)/2-getwidth()/2);

    set_form_fields(frm, fields);
    set_current_field(frm, fields[0]); //фокус на поле

    post_form(frm);
    this->refresh();
}
Exemplo n.º 10
0
static JSBool
js_conio_settitle(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	char *	str;
	jsrefcount	rc;

	if(argc==1) {
		JSVALUE_TO_MSTRING(cx, argv[0], str, NULL);
		HANDLE_PENDING(cx);
		if(str != NULL) {
			rc=JS_SUSPENDREQUEST(cx);
			settitle(str);
			free(str);
			JS_RESUMEREQUEST(cx, rc);
			JS_SET_RVAL(cx, arglist,JSVAL_TRUE);
			return(JS_TRUE);
		}
	}

	return(JS_FALSE);
}
Exemplo n.º 11
0
AddAccMgrForm::AddAccMgrForm(int rows, int cols,  Srv* srv, const char* mgrname) : NForm(rows,cols)
{
    this->srv = srv;
    settitle(mgrname);
    this->mgrname = mgrname;
    Item* account_manager = NULL;
    if (srv !=NULL)
	account_manager = srv->findaccountmanager(mgrname);
    //поля
    int row = 0;
    genfields(row,account_manager);
    //пересчитываем высоту формы, чтобы влезли все поля и центрируем
    int r,c =0;
    scale_form(frm, &r, &c);
    kLogPrintf("field_count=%d scale_form()->%d,%d\n", field_count(frm), r, c);
    resize(r+3,c+2);

    set_current_field(frm, fields[0]); //фокус на поле

    post_form(frm);
    this->refresh();
}
Exemplo n.º 12
0
void init_edit(HWND hwnd) {
    struct strl *e;
    int n = 0;

    makefonts();

    e = editfiles;
    if (e)
    {
        do {
            char buff[MAX_PATH];
            int line_nr;
            getfile(buff, e->str, &line_nr);

            if (n == 0)
            {
                if (0 == set_currentdir(buff))
                    GetCurrentDirectory(256, currentdir);
                //dbg_printf("currentdir <%s> <%s>", currentdir, buff);
            }

            if (LoadFile(buff))
            {
                ed_cmd(EK_INIT, 0, 0, 0);
                if (line_nr) {
                    ed_cmd(EK_GOTOLINE,line_nr-1);
                    //ed_cmd(EK_MARK,lpos,imin(lpos+1,nextline(lpos,1)));
                }
            }
            e=e->next;
            ++n;
        } while (e);
        edp = ed0;
    }

    SetCurrentDirectory(strcpy(projectdir, currentdir));

    settitle();
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
	puts("conlib测试程序:");
	T(conlib_init(),"初始化控制台库");
	 
	T(gotoxy(5,5),"现在光标在这里了");
	T(hide_cursor(),"光标不见了"); 
	T(show_cursor(50),"显示一半光标"); 
	T(show_cursor(100),"显示完整光标"); 
	T(settitle("conlib test program"),"设置标题");
	T(set_text_color(ConRed),"设置文字颜色");
	T(set_background_color(ConWhite),"设置背景颜色");
	
	clrscr();
	
	const ConKey* ck;
	const ConMouse* cm;
	const ConControlKeyState *cks; 

	char spaceLine[80] = {[0 ... 78] = ' ',[79] = '\0'};

	

	puts("按键测试:");
	hide_cursor();
#define Tand(v,t)	if(v & t)printf(#t "  ");
#define Teq(v,t)	if(v == t)printf(#t "  ");
	while(1)
	{
		gotoxy(12,0);
		printf("clock: %d\t", (int)clock()); 
		
		ck = getkey();
		cm = getmouse();
		cks = NULL; 
		gotoxy(0,1);
		printf("key value: %p", ck);
		gotoxy(0,2);
		printf("mouse value: %p", cm);
		
		gotoxy(0,3);
		if(ck != NULL)
		{
			cks = ck->ctrl_key_state;
			printf("key code: %d is %s", ck->key, ck->state? "按下": "释放");			
		}
			
		gotoxy(0,4);
		if(cm != NULL)
		{
			cks = cm->ctrl_key_state;
			printf("mouse position: %2d, %2d\n", cm->x, cm->y);
			printf(spaceLine);
			printf(spaceLine);
			printf(spaceLine);
			printf(spaceLine);
			gotoxy(0,5);
			if(cm->event != ConMOUSE_WHEELED && cm->event != ConMOUSE_HWHEELED)
			{
				Tand(cm->button,ConMOUSE_1ST_BUTTON);
				Tand(cm->button,ConMOUSE_2ND_BUTTON);
				Tand(cm->button,ConMOUSE_3RD_BUTTON);
				Tand(cm->button,ConMOUSE_4TH_BUTTON);
				Tand(cm->button,ConMOUSE_RIGHT_BUTTON);
				printf(" 被 按下了\n");
			}else
				printf("鼠标向 [%s] 滚\n", cm->button > 0? "前":"后");
			Teq(cm->event,ConMOUSE_CLICK);
			Teq(cm->event,ConMOUSE_DBCLICK);
			Teq(cm->event,ConMOUSE_MOVED);
			Teq(cm->event,ConMOUSE_WHEELED);
			Teq(cm->event,ConMOUSE_HWHEELED);
			printf(" 被 触发了\n");
		}

		gotoxy(0,10);
#define S(c)	(c? "ON": "OFF")

		if(cks != NULL)
			printf("NUM[%3s]  SCROLL[%3s]  CAPS[%3s]\n"
					"LCTRL[%3s]  LALT[%3s]  RALT[%3s]  RCTRL[%3s]\n"
					"SHIFT[%3s]  ENHANCED[%3s]"
					, S(cks->numlock), S(cks->scrolllock), S(cks->capslock)
					, S(cks->left_ctrl), S(cks->left_alt), S(cks->right_alt), S(cks->right_ctrl)
					, S(cks->shift), S(cks->enhanced));
		console_test();
	}	
	
return EXIT_SUCCESS;
}
Exemplo n.º 14
0
 int CreateTopWindow(void)
 {
#ifdef MOUSE_POINTER_CHANGE

	#ifdef WIN32

		static const gchar *cr[CURSOR_MODE_3270] = {	"arrow",
														"wait",
														"arrow",

														"sizenwse",	// Top-left
														"sizenesw",	// Top-right
														"sizens",	// Top
														"sizenesw",	// Bottom-left
														"sizenwse",	// Bottom-right
														"sizens",	// Bottom
														"sizewe",	// Left
														"sizewe",	// Right
														"sizeall"	// Inside

													};

	#else

		static int 		cr[CURSOR_MODE_3270] = { 	GDK_XTERM,
														GDK_WATCH,
														GDK_X_CURSOR,

														GDK_TOP_LEFT_CORNER, 		// Top-left
														GDK_TOP_RIGHT_CORNER,		// Top-right
														GDK_TOP_SIDE,				// Top
														GDK_BOTTOM_LEFT_CORNER,		// Bottom-left
														GDK_BOTTOM_RIGHT_CORNER,	// Bottom-right
														GDK_BOTTOM_SIDE,			// Bottom
														GDK_LEFT_SIDE,				// Left
														GDK_RIGHT_SIDE,				// Right
														GDK_FLEUR					// Inside

													};

	#endif // WIN32

	int f;

#endif // MOUSE_POINTER_CHANGE

	 static const struct ui_menu_setup_table widget_setup[] =
	 {
		{ "fontselect",		setup_font_select_menu		},
		{ "inputmethod",	setup_input_methods_menu	},
		{ "screensizes",	setup_screen_size_menu		},
	 	{ NULL,				NULL						}
	 };

	gchar		*ptr;

	init_actions();

#ifdef MOUSE_POINTER_CHANGE

	// Load mouse pointers
	#ifdef WIN32
		for(f=0;f<CURSOR_MODE_3270;f++)
			wCursor[f] = gdk_cursor_new_from_name(gdk_display_get_default(), cr[f]);
	#else
		for(f=0;f<CURSOR_MODE_3270;f++)
			wCursor[f] = gdk_cursor_new(cr[f]);
	#endif

#endif // MOUSE_POINTER_CHANGE

	if(!CreateTerminalWindow())
		return -1;

	// Load UI - Create toplevel window
	ptr = g_build_filename(program_data,"ui",NULL);
	topwindow = create_window_from_ui_files(ptr,terminal,widget_setup);
	g_free(ptr);

	// Load program logo
	load_icon();

/*
	if(program_logo && g_file_test(program_logo,G_FILE_TEST_IS_REGULAR))
	{
		pix = gdk_pixbuf_new_from_file(program_logo,NULL);
	}
	else
	{
		gchar *filename = g_build_filename(program_data,PROGRAM_LOGO,NULL);

		if(g_file_test(filename,G_FILE_TEST_IS_REGULAR))
			pix = gdk_pixbuf_new_from_file(filename, NULL);

		Trace("pixbuf(%s): %p",filename,pix);
		g_free(filename);
	}

	if(pix)
	{
		gtk_window_set_icon(GTK_WINDOW(topwindow),pix);
		g_object_set_data_full(G_OBJECT(topwindow),"logo",pix,g_object_unref);

#if defined( HAVE_IGEMAC )
		gtk_osxapplication_set_dock_icon_pixbuf(osxapp,pix);
#endif

	}
*/

	gtk_action_set_sensitive(action_by_id[ACTION_RESELECT],FALSE);

	g_signal_connect(G_OBJECT(topwindow),"destroy",G_CALLBACK(action_quit),0);

//	gtk_window_set_icon_list(GTK_WINDOW(topwindow),main_icon);

	gtk_window_set_default_size(GTK_WINDOW(topwindow),590,430);
	ptr = GetString("TopWindow","Title","");
	settitle(ptr);
	g_free(ptr);

	action_restore(0);

	gtk_window_set_position(GTK_WINDOW(topwindow),GTK_WIN_POS_CENTER);

	return 0;
 }
Exemplo n.º 15
0
int main(int argc, char **argv)
{
	struct text_info	ti;
	FILE	*f;
	char	buf[BUF_SIZE*2];	/* Room for lfexpand */
	int		len;
	int		speed;
	char	*scrollbuf;
	char	*infile=NULL;
	char	title[MAX_PATH+1];
	int		expand=0;
	int		i;

	textmode(C80);
	gettextinfo(&ti);
	if((scrollbuf=malloc(SCROLL_LINES*ti.screenwidth*2))==NULL) {
		cprintf("Cannot allocate memory\n\n\rPress any key to exit.");
		getch();
		return(-1);
	}
	
	/* Parse command line */
	for(i=1; i<argc; i++) {
		if(argv[i][0]=='-') {
			if(argv[i][1]=='l' && argv[i][2]==0)
				expand=1;
			else
				goto usage;
		}
		else {
			if(infile==NULL)
				infile=argv[i];
			else
				goto usage;
		}
	}

	cterm_init(ti.screenheight, ti.screenwidth, 0, 0, SCROLL_LINES, scrollbuf);
	if(infile) {
		if((f=fopen(infile,"r"))==NULL) {
			cprintf("Cannot read %s\n\n\rPress any key to exit.",argv[1]);
			getch();
			return(-1);
		}
		sprintf(title,"SyncView: %s",getfname(argv[1]));
	}
	else {
		f=stdin;
		strcpy(title,"SyncView: [stdin]");
	}
	settitle(title);
	while((len=fread(buf, 1, BUF_SIZE, f))!=0) {
		if(expand)
			lfexpand(buf, &len);
		cterm_write(buf, len, NULL, 0, &speed);
	}
	viewscroll();
	return(0);

usage:
	cprintf("Usage: %s [-l] [filename]\r\n\r\n"
			"Displays the ANSI file filename expanding \\n to \\r\\n if -l is specified.\r\n"
			"If no filename is specified, reads input from stdin\r\n"
			"\r\n"
			"Press any key to exit.");
	getch();
	return(-1);
}
Exemplo n.º 16
0
LRESULT CALLBACK EditProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){

    char bstr[MAX_PATH];
    char *p,c;
    int i,k,n,o,r,f;
    POINT pt;
    struct edvars *ev;

    r = 0;

    //if (domove(GetParent(hwnd),message,wParam,lParam)) return 0;

    switch (message) {
    case WM_COPYDATA:
        if (0x4F4E4242 == ((PCOPYDATASTRUCT)lParam)->dwData)
        {
            char buff[MAX_PATH];
            int line_nr;
            const char *file = (const char*)((PCOPYDATASTRUCT)lParam)->lpData;
            getfile(buff, file, &line_nr);
            set_currentdir(buff);
            LoadFile(buff);
            if (line_nr) {
                ed_cmd(EK_GOTOLINE,line_nr-1);
                //ed_cmd(EK_MARK,lpos,imin(lpos+1,nextline(lpos,1)));
            }

            r = TRUE;
            goto p0r;
        }

        return bbn_receive_data(hwnd, lParam);

    default:
        if (bb_broadcast_msg == message && message)
        {
            if (bb_register(hwnd) && bb_getstyle(hwnd))
               goto reconfig1;
            return 0;
        }
        break;

    case BB_RECONFIGURE:
        if (bb_getstyle(hwnd))
            goto reconfig1;
        return 0;


    reconfig1:
        bb_close_dlg();
        makedlgfont();

    reconfig:
        zy0 = title_h + FRM-1;
        setsize(hwnd);
        new_back();
        InvalidateRect(hwnd, NULL, FALSE);
        return 0;

    case BB_SETSTYLESTRUCT:
    {
        StyleStruct *d = (StyleStruct *)wParam;
        StyleStruct *s = (StyleStruct *)lParam;
        memset(d, 0, sizeof *d);
        memcpy(d, s, sizeof *d);
        break;
    }

    case BB_SETSTYLE:
    {
        char *d = (char *)wParam;
        char *s = (char *)lParam;
        strcpy(d, s);
        break;
    }

    case WM_CREATE:
        zy0 = title_h + FRM-1;
        setsize(ewnd=hwnd);
        dragC  = LoadCursor(hInst,MAKEINTRESOURCE(101));
        dragCp = LoadCursor(hInst,MAKEINTRESOURCE(102));
        pointC = hCurs = LoadCursor(NULL,IDC_ARROW);
        init_edit(hwnd);
        DragAcceptFiles(hwnd,TRUE);
        if (false == bb_register(hwnd) || false == bb_getstyle(hwnd))
            readstyle(defstyle);
        goto reconfig1;


    case WM_DROPFILES: {
        POINT pt;
        HDROP hDrop = (HDROP)wParam; int n,f;
        ev=edp;
        f=0;

        GetCursorPos(&pt);
        if (GetAsyncKeyState(VK_CONTROL)<0) f=1;
        if (GetAsyncKeyState(VK_SHIFT)<0)   f=2;
        if (f) ScreenToClient(hwnd,&pt);

        for (i=-1, k=0; i<k; i++)
        {
            n=DragQueryFile (hDrop, i, p=bstr, 255);
            if (i<0)
            {
                k=n;
            }
            else
            if (f==0)
            {
                LoadFile(p);
            }
            else
            if (f==2)
            {
                if (readstyle(p))
                {
                    CopyFile(p, defstyle, FALSE);
                }
                break;
            }
            else
            {
                if (i == 0 && -1 == getmoupos(pt.x ,pt.y))
                    break;

                ed_cmd(EK_SETVAR);
                ed_cmd(EK_INSERT, p);
                ed_cmd(KEY_RET);
            }
        }
        DragFinish(hDrop);
        SetForegroundWindow(hwnd);
        if (f==0) goto showf;
        if (f==2) goto reconfig1;
        goto p0;
        }

    case WM_QUERYENDSESSION:
        return (1 == QueryDiscard(hwnd,1));

    case WM_ENDSESSION:
    {
        //void savecfg(void); savecfg();
        return 0;
    }

    case WM_DESTROY:
        exit_edit();
        DragAcceptFiles(hwnd,FALSE);
        bb_unregister(hwnd);
        PostQuitMessage(0);
        return 0 ;


    case WM_ACTIVATE:
        i=LOWORD(wParam);
        if (i==WA_ACTIVE)
            clickflag=0;

        return 0;

    case WM_ACTIVATEAPP:
        if (wParam) {
            clickflag=2;
        }
        return 0;

    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
        if (alt_f) alt_f=2;

    case WM_MOUSEMOVE:
#if 0
    {
        static int wm;
        i = (short)HIWORD(lParam)/2;
        n = wm;
        wm = i;
        wParam = MAKELPARAM(0,(n-i)*30);
        goto mwhl;

    }
#endif
    case WM_LBUTTONDBLCLK:
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
    case WM_MBUTTONUP:
    case WM_MBUTTONDOWN:

        if (drag==0 && domove (hwnd, message, wParam, lParam))
            return 0;

        do_mouse(hwnd, wParam, lParam, message);

        if (message==WM_MOUSEMOVE && 0==(wParam & (MK_LBUTTON | MK_RBUTTON)))
            return 0;

        goto p0;

    case WM_TIMER:

        if (wParam==2) {
            resetmsg(hwnd);
            goto p0;
        }

        if (wParam==4) {
            mousewheelaccu=0;
        t0:
            KillTimer(hwnd, wParam);
            return 0;
        }

        GetCursorPos(&pt);
        ScreenToClient(hwnd,&pt);
        o=getmoupos(pt.x ,pt.y);
        if (o!=tcmd) {
            settimer(hwnd, o, SCROLL_INTERVAL);
            return 0;
        }

        if (tcmd==0) goto t0;
        c=ltup; ltup=0;
        ed_cmd(tcmd);
        ed_cmd(tcmd);
        upd=1;
        ltup=c;
        k=GetAsyncKeyState(VK_SHIFT)&0x8000;
        domarking(k!=0 || (0==moumrk && 0==drag));
        goto p0;


    case WM_SIZE:
        if (SIZE_MINIMIZED == wParam)
            return 0;

        if (edp) upd=1;
        ed_cmd(EK_SIZE);
        new_back();

    case WM_MOVE:
        setsize(hwnd);
        goto p0;

/*
   case WM_WINDOWPOSCHANGED:
        ewx0 = ((LPWINDOWPOS) lParam)->x;
        ewy0 = ((LPWINDOWPOS) lParam)->y;
        ewxl = ((LPWINDOWPOS) lParam)->cx;
        ewyl = ((LPWINDOWPOS) lParam)->cy;
        cfg_f |= 1;
        break; //process wm_move/wm_size

    case WM_WINDOWPOSCHANGING:
        SnapWindowToEdge((WINDOWPOS*)lParam, 10, 0);
        setsize(hwnd);
        return 0;
*/

    case WM_VSCROLL:
        vscroll(wParam);
        goto p0;

    case WM_HSCROLL:
        hscroll(wParam);
        goto p0;

    case WM_SETFOCUS:
        k_alt = 0>GetAsyncKeyState(VK_MENU);
        k_shft= 0>GetAsyncKeyState(VK_SHIFT);
        k_ctrl= 0>GetAsyncKeyState(VK_CONTROL);
        CreateCaret(hwnd,NULL,My_CaretSize,zy);
        caret=1;
        checkftime(hwnd);
        goto f1;

    case WM_KILLFOCUS:
        DestroyCaret();
        caret=0;
    f1:
        if (edp) upd=1;
        goto p0;

p0:
        r=0;
p0r:
        set_update(hwnd);
        return r;


    case WM_ERASEBKGND:
        return 1;

    case WM_PAINT:
        paint_window (hwnd);
        return 0;


    case WM_COMMAND:
        switch (LOWORD(wParam)) {

        case CMD_HELP:
#if 0
            bbnote_help();
            return 0;
#else
            if (fileexist(set_my_path(bstr, "bbnote.txt")))
                LoadFile(bstr);
            else if (fileexist(set_my_path(bstr, "docs/bbnote.txt")))
                LoadFile(bstr);
            goto p0;
#endif


        case CMD_EXIT:
            goto quit;

        case CMD_MENU_2:
        filemenu:
            if (ed0)
            {
                struct edvars *e = ed0;
                struct strl   *s = NULL;
                while (e)
                {
                    char temp[MAX_PATH];
                    sprintf(temp, "&%s", fname(e->sfilename));
                    appendstr(&s, temp);
                    e = e->next;
                }
                bb_file_menu (hwnd, lParam, s);
            }
            return 0;

        case CMD_MENU_1:
            bb_menu(hwnd, lParam);
            return 0;

        case CMD_COLOR:
            goto reconfig;

        case CMD_UPD:
            settitle();
            if (edp) upd=1;
            goto p0;


        case CMD_ZOOM:
    zoom:
            ShowWindow(hwnd, IsZoomed(hwnd) ? SW_SHOWNORMAL : SW_MAXIMIZE);
            return 0;

        case CMD_SEARCH:
        search:
            if (edp) bb_search_dialog(hwnd);
            return 0;

        case CMD_CLOSE:
        closefile:
            if (edp)
            {
                if (1 != QueryDiscard_1(hwnd, 1)) goto p0;
                if (ed0->next==NULL)
                {
                    extern HWND mwnd;
                    SendMessage(mwnd, WM_KEYDOWN, VK_ESCAPE, 0);
                    //DestroyWindow(mwnd);
                }
                CloseFile();
            }
            goto p0;

        case CMD_OPEN:
        openfile:
            ev=edp;
            DoFileOpenSave(hwnd, 0);
showf:
            if (ev==NULL || ev->next)
            {
                edp = ev ? ev->next : ed0;
                settitle();
            }
            goto p0;

        case CMD_RELOAD:
        reload:
            if (edp) f_reload(1);
            goto p0;


        case CMD_LIST:
            lParam = 2;
            goto filemenu;

        case CMD_NEW:
        newfile:
            NewFile();
            goto p0;

        case CMD_SAVE:
        savefile:
            if (edp) DoFileOpenSave(hwnd, 2);
            goto p0;

        case CMD_SAVEAS:
            if (edp!=NULL) DoFileOpenSave(hwnd, 1);
            break;

        case CMD_SAVEALL:
        //saveall:
            return QueryDiscard(hwnd, 0);

        case CMD_UNDO:
            ed_cmd(KEY_C_Z);
            goto p0;

        case CMD_REDO:
            ed_cmd(KEY_CS_Z);
            goto p0;

        case CMD_ABOUT:
            oyncan_msgbox(
              VERSION_STRING
              "\n"
              "\nediting with style"
              "\n04/2003 by grischka"
              "\n"
              "\[email protected]"
              , NULL, 1);
              return 0;


        case CMD_OPTIONS:
            goto config;

        case CMD_INFO:
            resetmsg(hwnd);
            p=(char*)lParam;
            if (p[0]==1) p++;
            else infoflg=1,infotimer=SetTimer(hwnd,2,666,NULL);
            strcpy(infomsg,p);
            if (edp) upd=1;
            goto p0;


        case CMD_FILECHG:
        {
            struct edvars *p=edp;
            edp=(struct edvars*)lParam;
            settitle();
            set_update(hwnd);
            f_reload(0);
            edp=p;
            settitle();
            goto p0;
        }

        default:
            i = LOWORD(wParam);
            if (i>=CMD_FILE && i< CMD_FILE_M)
            {
                struct edvars *p=ed0;
                i-=CMD_FILE;
                for (;i && p!=NULL; p=p->next,i--);
                if (p) {
                    //edp = p; settitle();
                    insfile(p);
                    goto p0;
                }
                return 0;
            }
            break;

        }
        break;

quit:
    if (1 == QueryDiscard(hwnd, 1))
        DestroyWindow(hwnd);
    return 0;

    case WM_SYSKEYDOWN:
        f=3; goto k1;

    case WM_SYSKEYUP:
        f=2; goto k1;

    case WM_KEYUP:
        if (wParam==VK_CONTROL && drag==3)  setdragc(2);
        f=0; goto k1;

    case WM_KEYDOWN:
        if (wParam==VK_CONTROL && drag==2)  setdragc(3);
        if (wParam==VK_SCROLL) { scroll_lock^=1; goto p0; }

        f=1; k1:

        n=LOWORD(wParam);

#if 0
        sprintf(bstr,"key %d  stat %d",n,f);
        if (n!=VK_MENU) MessageBox(NULL, bstr, "", MB_OK|MB_TOPMOST|MB_SETFOREGROUND);
#endif
        n=trans_keys(n, f);
        //if (0==n) goto p0;
        if (0==n) return 0;

        if (n>=2110 && n<=2117) {
        vmark=k_alt!=0;
        domarking(1);
        ed_cmd(n-100);
        domarking(1);
        goto p0;
        }

        switch (n) {

        case KEY_F8: return 0;
        case KEY_A_RIGHT:
        case KEY_F6:   nextfile(); goto p0;
        case KEY_A_LEFT:
        case KEY_C_F6: prevfile(); goto p0;

        case KEY_F10:  goto zoom;
        case KEY_F3:
        case KEY_C_F:  goto search;
        case KEY_C_F4: goto closefile;
        case KEY_C_O:  goto openfile;
        //case KEY_A_F3: goto reload;
        case KEY_C_N:  goto newfile;
        case KEY_C_L:  lParam = 0; goto filemenu;

        case KEY_F4:
            QueryDiscard(hwnd, 0);
            bb_reconfig();
            return 0;

        case KEY_S_F4:
            if (IDOK == oyncan_msgbox("Do you want to write all files?", "", 1+8))
                QueryDiscard(hwnd, 4);
            return 0;


        case KEY_C_S:  goto savefile;
        case KEY_A_F4: goto quit;

        case KEY_A_F2:
config:
            n = tabs;
            bb_config_dialog(hwnd);
            if (n!=tabs) goto reload;
            return 0;

        case KEY_ESC:
            if (drag==0) goto quit;
            dragmove=0;
            do_mouse(hwnd, 0,0,WM_LBUTTONUP);
            goto p0;

        case KEY_UP:
        case KEY_DOWN:
            if (scroll_lock) n+=200;
            goto defkey;

        case KEY_LEFT:
        case KEY_RIGHT:
            if (scroll_lock) n=(n^1)+204;
            goto defkey;
        }

    defkey:
        domarking(0);
        ed_cmd(n);
        i=n;
        if (i!=KEY_C_A
         && i!=KEY_C_U
         && i!=KEY_C_7
         && i!=KEY_C_8
         && i!=KEY_C_9
         && i!=KEY_C_0
         && i!=KEY_TAB
         && i!=KEY_S_TAB
         )
            unmark();
        goto p0;


    case WM_MOUSEWHEEL:
        i = mousewheelaccu + mousewheelfac * (short)HIWORD(wParam);
        while (i < -300)
            ed_cmd(KEY_C_DOWN), i+=600;
        while (i >  300)
            ed_cmd(KEY_C_UP),   i-=600;

        mousewheelaccu=i;
        unmark();
        SetTimer(hwnd, 4, 200, NULL);
        goto p0;


    case WM_NCPAINT:
        return 0;


    case WM_CHAR:
        n = LOWORD(wParam);
        if (n<32||n==127) return 0;

        resetmsg(hwnd);
        ed_cmd(EK_CHAR, n);
        goto p0;



    case CMD_GOTOLINE:
        ed_cmd(EK_GOTOLINE,wParam-1);
        ed_cmd(EK_MARK,lpos,imin(lpos+1,nextline(lpos,1)));
        lmf=2;
        goto p0;

    case CMD_LOADFILE:
        r=LoadFile((char*)wParam);
        goto p0r;

    case CMD_NSEARCH:
        resetmsg(hwnd);
        if (wParam&8) {
            ed_cmd(EK_REPLACE,(char *)lParam);
            if (wParam&1)
               ed_cmd(EK_GOTO,fpos+strlen((char*)lParam));
            goto p0;
        }
        unmark();
        if (wParam!=0) {
            struct sea *s=(struct sea *)lParam;
            struct edvars *ev0;

            for (ev0=edp;;) {
                r=ed_search(s);
                if (r || 0==(s->sf&128)) break;
                s->sf &= ~4;
                if (s->sf & 1) {
                    if (edp->next==NULL) break;
                    nextfile();
                    s->from=0;
                    continue;
                }
                if (s->sf & 2) {
                    if (edp==ed0) break;
                    prevfile();
                    s->from=flen;
                    continue;
                }}
            if (r<=0) {
                edp=ev0;
                settitle();
            } else {
               ed_cmd(KEY_HOME);
               ed_cmd(EK_MARK,s->a,s->e);
               ed_cmd(EK_GOTO,s->a);
            }
        }
        goto p0r;

    }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Exemplo n.º 17
0
int main(int argc, char **argv)
{
	struct text_info	ti;
	FILE	*f;
	char	buf[BUF_SIZE*2];	/* Room for lfexpand */
	int		len;
	int		speed=0;
	char	*scrollbuf;
	char	*infile=NULL;
	char	title[MAX_PATH+1];
	int		expand=0;
	int		ansi=0;
	int		i;

	/* Parse command line */
	for(i=1; i<argc; i++) {
		if(argv[i][0]=='-') {
			if(argv[i][1]=='l' && argv[i][2]==0)
				expand=1;
			else if(argv[i][1]=='a' && argv[i][2]==0)
				ansi=1;
			else
				goto usage;
		}
		else {
			if(infile==NULL)
				infile=argv[i];
			else
				goto usage;
		}
	}

	if(ansi) {
		initciolib(CIOLIB_MODE_ANSI);
		puts("START OF ANSI...");
	}

	textmode(C80);
	gettextinfo(&ti);
	if((scrollbuf=malloc(SCROLL_LINES*ti.screenwidth*2))==NULL) {
		cprintf("Cannot allocate memory\n\n\rPress any key to exit.");
		getch();
		return(-1);
	}

	cterm=cterm_init(ti.screenheight, ti.screenwidth, 1, 1, SCROLL_LINES, scrollbuf, CTERM_EMULATION_ANSI_BBS);
	if(!cterm) {
		fputs("ERROR Initializing CTerm!\n", stderr);
		return 1;
	}
	if(infile) {
		if((f=fopen(infile,"r"))==NULL) {
			cprintf("Cannot read %s\n\n\rPress any key to exit.",argv[1]);
			getch();
			return(-1);
		}
		sprintf(title,"SyncView: %s",getfname(argv[1]));
	}
	else {
		f=stdin;
		strcpy(title,"SyncView: [stdin]");
	}
	settitle(title);
	while((len=fread(buf, 1, BUF_SIZE, f))!=0) {
		if(expand)
			lfexpand(buf, &len);
		cterm_write(cterm, buf, len, NULL, 0, &speed);
	}
	if(ansi) {
		puts("");
		puts("END OF ANSI");
		gettext(1,1,ti.screenwidth,ti.screenheight,scrollbuf);
		puttext_can_move=1;
		puts("START OF SCREEN DUMP...");
		clrscr();
		puttext(1,1,ti.screenwidth,ti.screenheight,scrollbuf);
	}
	else
		viewscroll();
	return(0);

usage:
	cprintf("Usage: %s [-l] [-a] [filename]\r\n\r\n"
			"Displays the ANSI file filename expanding \\n to \\r\\n if -l is specified.\r\n"
			"If no filename is specified, reads input from stdin\r\n"
			"If -a is specified, outputs ANSI to stdout\r\n"
			"\r\n"
			"Press any key to exit.");
	getch();
	return(-1);
}
Exemplo n.º 18
0
/* MAIN */
int 
main(int argc, char **argv) {
  pid_t pid;
  struct sigaction sa;

  if (argc < 1) {
    fprintf(stderr,"Usage: echocon program args...\n");
    exit(-1);
  }
  if (geteuid() != 0) {
    fprintf(stderr,"You must be root in order to run %s\n",argv[0]);
    exit(-1);
  }

  if (fork()) exit(0);		/* decouple from terminal */
  pid = setsid();
  if (pid == -1) {
    fprintf(stderr,"setsid failed: %d,%d\n",pid,errno);
    exit(-1);
  }

  setjmp(env);
  settitle("consoled");
  
  if ((console = open("/dev/console",O_RDWR,0)) < 0) {
    fprintf(stderr,"could not open /dev/console\n");
    exit(-1);
  }

  if (openpty(&master,&slave,0,0,0) < 0) {
    fprintf(stderr,"out of ptys\n");
    return -1;
  }

  /* child signal handler */
  sa.sa_handler = pchild;
  sa.sa_flags = SA_NOCLDSTOP;
  sa.sa_mask = 0xffffffff;
  if (sigaction(SIGCHLD,&sa,NULL) != 0) {
    fprintf(stderr,"sigaction child failed\n");
    exit(-1);
  }
  /* kill consoled, kills it children and exits. */
  sa.sa_handler = wrapup;
  sa.sa_flags = 0;
  sa.sa_mask = 0xffffffff;
  if (sigaction(SIGHUP,&sa,NULL) != 0) {
    fprintf(stderr,"sigaction child failed\n");
    exit(-1);
  }
  sa.sa_handler = wrapup;
  sa.sa_flags = 0;
  sa.sa_mask = 0xffffffff;
#if 0
  if (sigaction(SIGTERM,&sa,NULL) != 0) {
    fprintf(stderr,"sigaction child failed\n");
    exit(-1);
  }
#endif
  progpid = start_login(slave);
  if (progpid == -1) {
    fprintf(stderr,"start login failed\n");
    exit(-1);
  }
  close(slave);
  do_console(master,console);
  /* Never reached */
  assert(0);
  return 0;
}
Exemplo n.º 19
0
/* Start helper daemon, and enter into helping mode ourselves */
int 
do_console(int master, int console) {
  fd_set fdsetw;
  fd_set fdsetr;
  int status;
  char buf[SZ];

  if ((helperpid = fork())) {
    struct sigaction sa;
    /* parent */
    settitle("consoled master (m->c)");
    sa.sa_handler = wrapup;
    sa.sa_flags = 0;
    sa.sa_mask = 0xffffffff;
    if (sigaction(SIGHUP,&sa,NULL) != 0) {
      fprintf(stderr,"sigaction child failed\n");
      exit(-1);
    }
    if (sigaction(SIGTERM,&sa,NULL) != 0) {
      fprintf(stderr,"sigaction child failed\n");
      exit(-1);
    }
    for (;;) {
      FD_ZERO(&fdsetr);
      FD_ZERO(&fdsetw);
      FD_SET(master,&fdsetr);
      status = select(32,&fdsetr,0,0,0);
      
      FD_SET(console,&fdsetw);	
      status = select(32,0,&fdsetw,0,0);
      
      status = read(master,buf,SZ);
      if (status < 0) {
	fprintf(stderr,"read master status: %d, errno: %d\n",status,errno);
	break;
      }
      write(console,buf,status);
    }
    {
      /* wait for a signal */
      sigset_t sig;
      sigemptyset(&sig);
      sigaddset(&sig,SIGCHLD);
      sigaddset(&sig,SIGTERM);
      sigaddset(&sig,SIGHUP);
      sigsuspend(&sig);
    }
    /* never reached */
    return 0;
  } else {
    /* child */
    {
      struct sigaction sa;
      sa.sa_handler = pdone;
      sa.sa_flags = 0;
      sa.sa_mask = 0;
      if (sigaction(SIGUSR2,&sa,NULL) != 0) {
	fprintf(stderr,"sigaction child failed\n");
	exit(-1);
      }
    }
    settitle("consoled helper (c->m)");
    for (;;) {
      FD_ZERO(&fdsetr);
      FD_ZERO(&fdsetw);
      FD_SET(console,&fdsetr);
      status = select(32,&fdsetr,0,0,0);
      
      FD_SET(master,&fdsetw);	
      status = select(32,0,&fdsetw,0,0);
      
      status = read(console,buf,SZ);
      if (status <= 0) {
	fprintf(stderr,"read console status: %d, errno: %d\n",status,errno);
	break;
      }
      status = write(master,buf,status);
      if (status <= 0) {
	fprintf(stderr,"write master status: %d, errno: %d\n",status,errno);
	break;
      }
    }
    close(console);
    close(master);
    exit(0);
  }
  /* never reached */
}
Exemplo n.º 20
0
Arquivo: buffer.c Projeto: ec429/quIRC
int init_buffer(int buf, btype type, const char *bname, int nlines)
{
	bufs[buf].type=type;
	bufs[buf].bname=strdup(bname);
	if(type==SERVER)
		bufs[buf].serverloc=strdup(bname);
	else
		bufs[buf].serverloc=NULL;
	bufs[buf].realsname=NULL;
	bufs[buf].nlist=NULL;
	bufs[buf].us=NULL;
	bufs[buf].ilist=NULL;
	bufs[buf].handle=0;
	bufs[buf].server=0;
	bufs[buf].nick=NULL;
	bufs[buf].topic=NULL;
	bufs[buf].logf=NULL;
	bufs[buf].nlines=nlines;
	bufs[buf].ptr=0;
	bufs[buf].scroll=0;
	bufs[buf].ascroll=0;
	bufs[buf].lm=malloc(nlines*sizeof(mtype));
	bufs[buf].lq=malloc(nlines*sizeof(prio));
	bufs[buf].lp=malloc(nlines);
	bufs[buf].ls=malloc(nlines*sizeof(bool));
	bufs[buf].lt=malloc(nlines*sizeof(char *));
	int i;
	for(i=0;i<bufs[buf].nlines;i++)
	{
		bufs[buf].lt[i]=NULL;
	}
	bufs[buf].ltag=malloc(nlines*sizeof(char *));
	for(i=0;i<bufs[buf].nlines;i++)
	{
		bufs[buf].ltag[i]=NULL;
	}
	bufs[buf].lpl=malloc(nlines*sizeof(int));
	bufs[buf].lpc=malloc(nlines*sizeof(colour));
	bufs[buf].lpt=malloc(nlines*sizeof(char **));
	for(i=0;i<nlines;i++)
	{
		bufs[buf].lpl[i]=0;
		bufs[buf].lpc[i]=(colour){.fore=7, .back=0, .hi=false, .ul=false};
		bufs[buf].lpt[i]=NULL;
	}
	bufs[buf].dirty=false;
	bufs[buf].ts=malloc(nlines*sizeof(time_t));
	bufs[buf].filled=false;
	bufs[buf].alert=false;
	bufs[buf].hi_alert=0;
	bufs[buf].ping=0;
	bufs[buf].last=time(NULL);
	bufs[buf].namreply=false;
	bufs[buf].live=false;
	bufs[buf].conninpr=false;
	initibuf(&bufs[buf].input);
	bufs[buf].casemapping=RFC1459;
	if(type==SERVER)
	{
		bufs[buf].npfx=2;
		bufs[buf].prefixes=malloc(2*sizeof(prefix));
		bufs[buf].prefixes[0]=(prefix){.letter='o', .pfx='@'};
		bufs[buf].prefixes[1]=(prefix){.letter='v', .pfx='+'};
	}
	else
	{
		bufs[buf].npfx=0;
		bufs[buf].prefixes=NULL;
	}
	bufs[buf].autoent=NULL;
	bufs[buf].conf=conf;
	bufs[buf].key=NULL;
	bufs[buf].lastkey=NULL;
	return(0);
}

int free_buffer(int buf)
{
	if(bufs[buf].live)
	{
		add_to_buffer(buf, ERR, NORMAL, 0, false, "Buffer is still live!", "free_buffer:");
		return(1);
	}
	else
	{
		free(bufs[buf].bname);
		free(bufs[buf].serverloc);
		free(bufs[buf].realsname);
		n_free(bufs[buf].nlist);
		bufs[buf].nlist=NULL;
		n_free(bufs[buf].ilist);
		bufs[buf].ilist=NULL;
		free(bufs[buf].nick);
		free(bufs[buf].topic);
		if(bufs[buf].logf)
			fclose(bufs[buf].logf);
		free(bufs[buf].lm);
		free(bufs[buf].lq);
		free(bufs[buf].lp);
		free(bufs[buf].ls);
		int l;
		if(bufs[buf].lt)
		{
			for(l=0;l<bufs[buf].nlines;l++)
				free(bufs[buf].lt[l]);
			free(bufs[buf].lt);
		}
		if(bufs[buf].ltag)
		{
			for(l=0;l<bufs[buf].nlines;l++)
				free(bufs[buf].ltag[l]);
			free(bufs[buf].ltag);
		}
		if(bufs[buf].lpt)
		{
			for(l=0;l<bufs[buf].nlines;l++)
			{
				if(bufs[buf].lpt[l])
				{
					if(bufs[buf].lpl)
					{
						int p;
						for(p=0;p<bufs[buf].lpl[l];p++)
						{
							free(bufs[buf].lpt[l][p]);
						}
					}
					free(bufs[buf].lpt[l]);
				}
			}
			free(bufs[buf].lpt);
		}
		free(bufs[buf].lpl);
		free(bufs[buf].lpc);
		free(bufs[buf].ts);
		freeibuf(&bufs[buf].input);
		free(bufs[buf].prefixes);
		free(bufs[buf].key);
		free(bufs[buf].lastkey);
		if(cbuf>=buf)
			cbuf--;
		nbufs--;
		int b;
		for(b=buf;b<nbufs;b++)
		{
			bufs[b]=bufs[b+1];
		}
		for(b=0;b<nbufs;b++)
		{
			if(bufs[b].server==buf)
			{
				bufs[b].server=0; // orphaned; should not happen
				bufs[b].live=false;
				bufs[b].handle=0; // just in case
			}
			else if(bufs[b].server>buf)
			{
				bufs[b].server--;
			}
		}
		if(nbufs) redraw_buffer();
		return(0);
	}
}

int add_to_buffer(int buf, mtype lm, prio lq, char lp, bool ls, const char *lt, const char *ltag)
{
	if(buf>=nbufs)
	{
		if(bufs&&buf)
		{
			add_to_buffer(0, ERR, NORMAL, 0, false, "Line was written to bad buffer!  Contents below.", "add_to_buffer(): ");
			add_to_buffer(0, lm, NORMAL, lp, ls, lt, ltag);
		}
		return(1);
	}
	if(!debug&&(lq==DEBUG))
	{
		if(!d_buf.nlines)
		{
			init_ring(&d_buf);
			d_buf.loop=true;
		}
		return(add_to_ring(&d_buf, lm, lt, ltag));
	}
	int optr=bufs[buf].ptr;
	bool scrollisptr=(bufs[buf].scroll==bufs[buf].ptr)&&(bufs[buf].ascroll==0);
	bufs[buf].lm[bufs[buf].ptr]=lm;
	bufs[buf].lq[bufs[buf].ptr]=lq;
	bufs[buf].lp[bufs[buf].ptr]=lp;
	bufs[buf].ls[bufs[buf].ptr]=ls;
	free(bufs[buf].lt[bufs[buf].ptr]);
	bufs[buf].lt[bufs[buf].ptr]=strdup(lt);
	free(bufs[buf].ltag[bufs[buf].ptr]);
	bufs[buf].ltag[bufs[buf].ptr]=strdup(ltag);
	time_t ts=bufs[buf].ts[bufs[buf].ptr]=time(NULL);
	bufs[buf].ptr=(bufs[buf].ptr+1)%bufs[buf].nlines;
	if(scrollisptr)
	{
		bufs[buf].scroll=bufs[buf].ptr;
		bufs[buf].ascroll=0;
	}
	if(bufs[buf].ptr==0)
		bufs[buf].filled=true;
	render_line(buf, optr);
	if(buf==cbuf)
	{
		int e=redraw_buffer();
		if(e) return(e);
	}
	else
	{
		if(!(
			(bufs[buf].conf&&((lm==JOIN)||(lm==PART)||(lm==NICK)||(lm==MODE)||(lm==QUIT)))
			||
				(quiet&&(lq==QUIET))
			||
				(!debug&&(lq==DEBUG))
			))
		bufs[buf].alert=true;
	}
	if(bufs[buf].logf)
	{
		int e=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
		if(e) return(e);
	}
	return(0);
}

int redraw_buffer(void)
{
	if(bufs[cbuf].dirty)
	{
		int e=render_buffer(cbuf);
		if(e) return(e);
		if(bufs[cbuf].dirty) return(1);
	}
	int uline=bufs[cbuf].scroll;
	int pline=bufs[cbuf].ascroll;
	while(pline<0)
	{
		uline--;
		if((bufs[cbuf].filled)&&(uline==bufs[cbuf].ptr))
		{
			uline++;
			pline=0;
			break;
		}
		if(uline<0)
		{
			if(bufs[cbuf].filled)
				uline+=bufs[cbuf].nlines;
			else
			{
				uline=0;
				pline=0;
				break;
			}
		}
		pline+=bufs[cbuf].lpl[uline];
	}
	if(uline==bufs[cbuf].ptr)
	{
		pline=0;
	}
	while(pline>=bufs[cbuf].lpl[uline])
	{
		pline-=bufs[cbuf].lpl[uline];
		if(bufs[cbuf].filled)
		{
			if(uline==bufs[cbuf].ptr)
			{
				pline=0;
				break;
			}
			uline=(uline+1)%bufs[cbuf].nlines;
		}
		else
		{
			if(uline>=bufs[cbuf].ptr)
			{
				uline=bufs[cbuf].ptr;
				pline=0;
				break;
			}
			uline++;
		}
	}
	bufs[cbuf].scroll=uline;
	bufs[cbuf].ascroll=pline;
	int row=height-2;
	//setcolour(bufs[cbuf].lpc[uline]);
	while(row>(tsb?1:0))
	{
		bool breakit=false;
		pline--;
		while(pline<0)
		{
			uline--;
			if(uline<0)
			{
				if(bufs[cbuf].filled)
					uline+=bufs[cbuf].nlines;
				else
				{
					breakit=true;
					pline=0;
					break;
				}
			}
			if(uline==bufs[cbuf].ptr)
			{
				breakit=true;
				break;
			}
			pline+=bufs[cbuf].lpl[uline];
		}
		if(breakit) break;
		locate(row, 0);
		fputs(bufs[cbuf].lpt[uline][pline], stdout);
		if(!full_width_colour) resetcol();
		clr();
		row--;
	}
	resetcol();
	while(row>(tsb?1:0))
	{
		locate(row--, 0);
		clr();
	}
	switch(bufs[cbuf].type)
	{
		case STATUS:
			settitle("quIRC - status");
		break;
		case SERVER: // have to scope it for the cstr 'variably modified type'
			{
				char cstr[16+strlen(bufs[cbuf].bname)];
				sprintf(cstr, "quIRC - %s", bufs[cbuf].bname);
				settitle(cstr);
			}
		break;
		case CHANNEL: // have to scope it for the cstr 'variably modified type'
			{
				char cstr[16+strlen(bufs[cbuf].bname)+strlen(SERVER(cbuf).bname)];
				sprintf(cstr, "quIRC - %s on %s", bufs[cbuf].bname, SERVER(cbuf).bname);
				settitle(cstr);
			}
		break;
		case PRIVATE: // have to scope it for the cstr 'variably modified type'
			{
				char cstr[16+strlen(bufs[cbuf].bname)+strlen(SERVER(cbuf).bname)];
				sprintf(cstr, "quIRC - <%s> on %s", bufs[cbuf].bname, SERVER(cbuf).bname);
				settitle(cstr);
			}
		break;
		default:
			settitle("quIRC");
		break;
	}
	if(tsb)
		titlebar();
	bufs[cbuf].alert=false;
	return(0);
}

int mark_buffer_dirty(int buf)
{
	bufs[buf].dirty=true;
	return(0);
}