Пример #1
0
DIR *win_open(char *pname) 
{
    char    *fixedname = win_fixname(pname);
    DIR     *pdir      = (DIR *)malloc(sizeof(DIR));
    int32_t  fixednamelen;

    if (pdir && fixedname) {
        memset(pdir, 0, sizeof(DIR));
        pdir->fh = _findfirst(fixedname, &(pdir->fileinfo));
        if (pdir->fileinfo.attrib & _A_SUBDIR) {
            _findclose( pdir->fh );
            fixednamelen = strlen(fixedname);
            assert(fixednamelen > 0); // a 0 length name is not ok, nor is an int overflow
            if (fixedname[fixednamelen - 1] != '\\') {
                memcpy(fixedname + fixednamelen, "\\", 2);
                fixednamelen++;
            }
            memcpy(fixedname + fixednamelen, "*.*", 4);
            fixednamelen += 3;
            pdir->fh = _findfirst(fixedname, &(pdir->fileinfo));
            if (pdir->fh == -1) {
                win_close(pdir);
                pdir = NULL;
            }
        }
        else {
            // we only go on if this is a directory
            win_close(pdir);
            pdir = NULL;
        }
    }

    return pdir;
}
Пример #2
0
/* Open the win_dib driver */
static int
win_dib_open(gx_device * dev)
{
    int code = win_open(dev);

    if (code < 0)
	return code;

#ifdef __WIN32__
    if (!is_win32s)
	wdev->hmtx = CreateMutex(NULL, FALSE, NULL);	/* unnamed mutex, initially unowned */
#endif
    if (gdev_mem_device_for_bits(dev->color_info.depth) == 0) {
	win_close(dev);
	return gs_error_rangecheck;
    }
    code = win_dib_alloc_bitmap((gx_device_win *) dev, dev);
    if (code < 0) {
	win_close(dev);
	return code;
    }
    /* notify caller about new device */
    if (pgsdll_callback) {
	(*pgsdll_callback) (GSDLL_DEVICE, (unsigned char *)dev, 1);
	(*pgsdll_callback) (GSDLL_SIZE, (unsigned char *)dev,
			(dev->width & 0xffff) +
			((ulong) (dev->height & 0xffff) << 16));
    }
    return code;
}
Пример #3
0
// --------------------------------------------------------------------------------
// ODBCSourceList
// Crea una lista con ARMAKER delle Sorgenti di dati presenti nel sistema
// Filtra i dati cercando la parola passata con *lpDriver nel driver collegato
// alla sorgente 
// --------------------------------------------------------------------------------
SINT ODBCDriverList(CHAR *lpDriver)
{
	SQLCHAR szServerName[180];
	SQLCHAR szServerDesc[180];
	SQLSMALLINT iServerName;
	SQLSMALLINT iServerDesc;
	SQLRETURN sqlReturn;
//	CHAR Buffer[500];

	// -------------------------------
	// Elenco server disponibili
	//
	
	ARMaker(WS_OPEN,NULL);
	win_open(EHWP_SCREENCENTER,50,232,59,-1,3,ON,"Lettura Data Source Name");

	sqlReturn=SQLDataSources(EhOdbc.hEnv,SQL_FETCH_FIRST,
							szServerName,sizeof(szServerName)-1,&iServerName,
							szServerDesc,sizeof(szServerDesc)-1,&iServerDesc);
	do 
	{
		if (!strstr(szServerDesc,lpDriver)) continue;
//		sprintf(Buffer,"%s - %s",szServerName,szServerDesc);
		ARMaker(WS_ADD,szServerDesc);
	} while (SQLDataSources(EhOdbc.hEnv,SQL_FETCH_NEXT,
							szServerName,
							sizeof(szServerName)-1,&iServerName,
							szServerDesc,
							sizeof(szServerDesc)-1,&iServerDesc)==SQL_SUCCESS);

	win_close();
	return ARMaker(WS_CLOSE,"ODBCSource");
}
Пример #4
0
void cleanup(void) {
	static bool in = false;

	if (!in) {
		in = true;
		img_close(&img, false);
		tns_free(&tns);
		win_close(&win);
	}
}
Пример #5
0
/*
 * Show dialog with two buttons; returns the botton that was selected.
 */
int dia_binary(char *txt, char *button0_txt, char *button1_txt, int def)
{
  window_t win;
  button_t button0, button1;
  button_t *buttons[2] = { &button0, &button1 };
  int width, answer;
  int len0, len1, len_max;

  if (config.linemode)
    {
      int current_ii;

      for (;;)
	{
	  putchar('\n');
	  dia_printformatted(txt, 0, max_x_ig - 1, 1);
	  putchar('\n');
          printf("0) <-- Back <--\n");
	  printf("1) %s\n", button0_txt);
	  printf("2) %s\n", button1_txt);
	  printf("\n> ");fflush(stdout);
	  current_ii = dia_readnum();
	  if(current_ii == -'x') dia_handle_ctrlc();
	  if (current_ii < 0 || current_ii > 2)
	    continue;
	  return current_ii - 1;
	}
    }
  disp_toggle_output(DISP_OFF);
  memset(&win, 0, sizeof win);
  win.bg_color = colors_prg->choice_win;
  win.fg_color = colors_prg->choice_fg;
  width = dia_win_open(&win, txt, 0);

  len0 = utf8_strwidth(button0_txt);
  len1 = utf8_strwidth(button1_txt);
  len_max = len0 > len1 ? len0 : len1;

  util_generate_button(buttons[0], button0_txt, len_max);
  util_generate_button(buttons[1], button1_txt, len_max);

  len0 = utf8_strwidth(button0.text);
  len1 = utf8_strwidth(button1.text);

  win_add_button(&win, buttons[0], width / 3 - len0 / 2 - 3, len0);
  win_add_button(&win, buttons[1], width - width / 3 - len1 / 2 + 2, len1);

  disp_flush_area(&win);
  answer = win_choose_button(buttons, 2, def + 1) - 1;
  win_close(&win);

  return answer;
}
Пример #6
0
// -------------------------------------------------
// ODBCConnect()
//
BOOL ODBCConnect(CHAR *lpServerName,CHAR *lpUserName,CHAR *lpPassword)
{
	win_open(EHWP_SCREENCENTER,50,300,59,-1,3,ON,"Connessione a ...");
	dispfm(10,27,1,-1,STYLE_BOLD,"#Arial",25,lpServerName);
	
	// --------------------------------------------------------------------
	// Mi connetto al server
	//
	EhOdbc.sqlLastError=SQLConnect(EhOdbc.hConn,    // Handle della connessione
								   lpServerName,    // Nome del server
								   SQL_NTS, // Nome del file / Driver da usare
								   lpUserName,SQL_NTS, // UserName
								   lpPassword,SQL_NTS); // Password
	if (EhOdbc.sqlLastError!=SQL_SUCCESS&&EhOdbc.sqlLastError!=SQL_SUCCESS_WITH_INFO) 
		{if (!EhOdbc.fNoErrorView) ODBCError("Connect"); 
		 win_close();
	     return TRUE;
		}

	// --------------------------------------------------------------------
	// Alloca memoria per comandi (ritorna puntatore in hStmt)
	//
	// sqlReturn=SQLAllocStmt(EhOdbc.hConn, &EhOdbc.hStmt);
	//
	EhOdbc.sqlLastError=SQLAllocHandle(SQL_HANDLE_STMT, EhOdbc.hConn, &EhOdbc.hStmt);
	if (EhOdbc.sqlLastError!=SQL_SUCCESS) {ODBCError("SQLAllocHandle/Env");  PRG_end("Ambiente stantment:?");}

	SQLSetStmtAttr(EhOdbc.hStmt, SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_READ_ONLY, 0);
	SQLSetStmtAttr(EhOdbc.hStmt, SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_SCROLLABLE , 0);
	SQLSetCursorName(EhOdbc.hStmt, "SQL_CURSOR", SQL_NTS);

	SQLTRY(SQL_HANDLE_STMT,"SET1",EhOdbc.hStmt,SQLSetStmtAttr(EhOdbc.hStmt, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0));
	SQLTRY(SQL_HANDLE_STMT,"SET2",EhOdbc.hStmt,SQLSetStmtAttr(EhOdbc.hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) 1, 0));
	SQLTRY(SQL_HANDLE_STMT,"SET3",EhOdbc.hStmt,SQLSetStmtAttr(EhOdbc.hStmt, SQL_ATTR_ROW_STATUS_PTR, NULL, 0));
	SQLTRY(SQL_HANDLE_STMT,"SET4",EhOdbc.hStmt,SQLSetStmtAttr(EhOdbc.hStmt, SQL_ATTR_ROWS_FETCHED_PTR, NULL, 0));

	win_close();
	return FALSE;
}
int win_truncate(const char *path, off_t length)
{
    int fd, ret, saved_errno;

    fd = win_open(path, O_WRONLY);
    if (fd < 0)
	return -1;
    ret = chsize(fd, length);
    saved_errno = errno;
    win_close(fd);
    errno = saved_errno;

    return ret;
}
Пример #8
0
/* Close the win_ddb driver */
static int
win_ddb_close(gx_device * dev)
{
    /* Free resources */

    win_destroytools(wdev);
    DeleteDC(wdev->hdcmono);
    win_ddb_free_bitmap((gx_device_win *) dev);
    DeleteObject(wdev->hpalette);
    DeleteObject(wdev->hbmmono);
    gs_free((char *)(wdev->lpalette), 1, sizeof(LOGPALETTE) +
	    (1 << (wdev->color_info.depth)) * sizeof(PALETTEENTRY),
	    "win_ddb_close");

    return win_close(dev);
}
Пример #9
0
void mod_load_module_manual(char *module, int show)
{
  module_t *ml;
  char *s, buf[256];
  window_t win;
  int i;

  if(!(ml = mod_get_entry(module))) {
    mod_insmod(module, NULL);

    return;
  }

  if(!config.win) show = 0;

  if(show && !ml->dontask) {
    s = mod_get_params(ml);
  }
  else {
    s = ml->param && (ml->autoload || ml->dontask) ? ml->param : "";
  }

  if(show) {
    if(s) {
      sprintf(buf, "Trying to load module \"%s\"...\n\n"
                   "During loading, you may want to watch the kernel messages on virtual console 4 (ALT-F4). Use ALT-F1 to switch back to this menu.",
                   ml->name);
      dia_info(&win, buf, MSGTYPE_INFO);
      mod_insmod(ml->name, s);
      win_close(&win);
      i = mod_is_loaded(ml->name);
      if(i) {
        sprintf(buf, "Module \"%s\" loaded successfully.", ml->name);
        dia_message(buf, MSGTYPE_INFO);
      }
      else {
        util_beep(FALSE);
        sprintf(buf, "Failed to load module \"%s\".", ml->name);
        dia_message(buf, MSGTYPE_ERROR);
      }
    }
  }
  else {
    mod_insmod(ml->name, s);
  }
}
Пример #10
0
/* Close the win_dib driver */
static int
win_dib_close(gx_device * dev)
{
    int code;

    /* wait until bitmap is not being used by caller */
    win_dib_lock_device((unsigned char *)dev, 1);
    if (pgsdll_callback)
	(*pgsdll_callback) (GSDLL_DEVICE, (unsigned char *)dev, 0);
    win_dib_lock_device((unsigned char *)dev, 0);
    win_dib_free_bitmap((gx_device_win *) dev);
#ifdef __WIN32__
    if (!is_win32s)
	CloseHandle(wdev->hmtx);
#endif
    code = win_close(dev);
    return code;
}
Пример #11
0
void 
HariMain(void)
{
  char* buf;
  int win;
  int i;

  init_mem();

  buf = (char*)malloc(160 * 100);
  win = win_open(buf, 160, 100, -1, "Win-Lines");
  for (i = 0; i < 8; ++i) {
    win_line(win + 1, 8, 26, 77, i * 9 + 26, i);
    win_line(win + 1, 88, 26, i * 9 + 88, 89, i);
  }
  win_refresh(win, 6, 26, 154, 90);

  win_close(win);

  api_end();
}
Пример #12
0
int
PicBuf_to_X11 ( const GEN_PAR * pg,  OUT_PAR * po)
/**
 ** Interface to higher-level routines,
 **   similar in structure to other previewers
 **/
{
  int row_c, x, y;
  int saved_col=0,saved_row=0;
  int xref = 0, yref = 0;
  const RowBuf *row;
  const PicBuf *pb;
  struct timeval tv;
  tv.tv_usec = 10;

  if (pg == NULL || po == NULL)
    return ERROR;
  pb = po->picbuf;
  if (pb == NULL)
    return ERROR;

  if (!pg->quiet)
    {
      Eprintf ("\nX11 preview follows.\n");
      Eprintf ("Press any key to end graphics mode\n");
    }

  if (win_open (pg, po->outfile, (int) (po->xoff * po->dpi_x / 25.4),
		(int) (po->yoff * po->dpi_y / 25.4), pb->nb << 3, pb->nr))
    return ERROR;
REDRAW:
  /* Backward since highest index is lowest line on screen! */
  for (row_c = row_start, y = MIN (height-row_start, pb->nr - 1);
       row_c < pb->nr; row_c++, y--)
    {
   row =NULL;
   if (row_c>=0) row = get_RowBuf (pb, row_c);
      /*if (row == NULL)
	return 0;*/
      for (x = col_start; x < pb->nc; x++)
	{
        if (row_c <0 || x < 0) setXcolor(GRAY);
         else
	  switch (index_from_RowBuf (row, x, pb))
	    {

	    case xxBackground:
	      continue;
/*	    case xxForeground:
	      setXcolor (WHITE);
	      break;*/
	    default:
	      setXcolor (index_from_RowBuf (row, x, pb));
	      break;
	    }
	  XDrawPoint (XDisplay, XWin, XGcWin, x - col_start, y + row_start);
	}
    }

/* Wait for KeyPress or mouse Button  - exit on keypress or button 3 */
  do
    {
      XNextEvent (XDisplay, &WaitEvent);
      if (WaitEvent.type == ButtonPress)
	{
	  if (WaitEvent.xbutton.button == Button1)
	    {
	      xref = WaitEvent.xbutton.x;
	      yref = WaitEvent.xbutton.y;
	    }
	  if (WaitEvent.xbutton.button == Button2)
	    {
	    if (!zoomed){
	      zoomed=1;
	       po->HP_to_xdots *=2;
	       po->HP_to_ydots *=2;
	       po->dpi_x *=2;
	       po->dpi_y *=2;
		saved_row=row_start;
		saved_col=col_start;
		  row_start = height-WaitEvent.xbutton.y+2*saved_row;
		  if (height < scr_height) row_start = height-WaitEvent.xbutton.y;
		  col_start =  WaitEvent.xbutton.x+col_start;
	    } else {
	      zoomed=0;
	      po->dpi_x = po->dpi_x/2;
	      po->dpi_y = po->dpi_y/2;
	       po->HP_to_xdots = po->HP_to_xdots/2;
	       po->HP_to_ydots = po->HP_to_ydots/2;
		row_start=saved_row;
		col_start=saved_col;

		}	
		free(po->picbuf);
		po->picbuf=NULL;    
	      TMP_to_BUF(pg, po);
	      pb=po->picbuf;
	    }
	  if (WaitEvent.xbutton.button == Button3) {win_close();return(0);}
	}
      else if (WaitEvent.type == ButtonRelease)
	{
	  if (WaitEvent.xbutton.button == Button1)
	    {
	      if (oversized)
		{
		  row_start += WaitEvent.xbutton.y - yref;
		  col_start += xref - WaitEvent.xbutton.x;
		}
	      XSetForeground (XDisplay, XGcWin,
			      WhitePixel (XDisplay, XScreen));
	      XFillRectangle (XDisplay, XWin, XGcWin, 0, 0, scr_width,
			      scr_height);
	      goto REDRAW;	/* yes, goto in C is ugly */
	    }
	  if (WaitEvent.xbutton.button == Button2){
	      XSetForeground (XDisplay, XGcWin,
			      WhitePixel (XDisplay, XScreen));
	      XFillRectangle (XDisplay, XWin, XGcWin, 0, 0, scr_width,
			      scr_height);
	      goto REDRAW;	/* yes, goto in C is ugly */
		} 	
	  break;
/*	  select (0, NULL, NULL, NULL, &tv);*/
	}
    }
  while (WaitEvent.type != KeyPress );

  win_close ();
  return 0;
}
Пример #13
0
int dia_message (char *txt_tv, int msgtype_iv)
    {
    window_t  win_ri;
    int       width_ii;
    button_t  button_ri;
    int       key_ii;
    char *s;

    if(!config.win) util_disp_init();

    if (config.linemode)
      {
	putchar('\n');
	if (msgtype_iv == MSGTYPE_ERROR || msgtype_iv == MSGTYPE_REBOOT)
	  printf("*** ");
        dia_printformatted(txt_tv, 0, max_x_ig - 5, 1);
	if (msgtype_iv == MSGTYPE_INFOENTER)
	  {
	    int c;
	    do
	      c = lgetchar();
	    while (c != '\n' && c != '\r' && c != EOF);
	  }
	return 0;
      }
    disp_toggle_output (DISP_OFF);
    kbd_clear_buffer ();
    memset (&win_ri, 0, sizeof (window_t));
    if (msgtype_iv == MSGTYPE_ERROR || msgtype_iv == MSGTYPE_REBOOT)
        {
        win_ri.bg_color = colors_prg->error_win;
        win_ri.fg_color = colors_prg->error_fg;
        }
    else
        {
        win_ri.bg_color = colors_prg->msg_win;
        win_ri.fg_color = colors_prg->msg_fg;
        }
    width_ii = dia_win_open (&win_ri, txt_tv, 0);
    s = msgtype_iv == MSGTYPE_REBOOT ? "Reboot" : "OK";
    util_generate_button (&button_ri, s, utf8_strwidth(s));
    win_add_button (&win_ri, &button_ri,
                    width_ii / 2 - utf8_strwidth (button_ri.text) / 2 - 1,
                    utf8_strwidth (button_ri.text));
/*    win_button_select (&button_ri); */

    disp_flush_area (&win_ri);
    do
        {
        key_ii = kbd_getch (TRUE);
        if (key_ii == KEY_CTRL_C)
            dia_handle_ctrlc ();

        if (key_ii == KEY_ENTER)
            win_button_pressed (&button_ri, FALSE);
        }
    while (
      key_ii != KEY_ENTER &&
      key_ii != KEY_ESC &&
      key_ii != 'q' &&
      key_ii != 'r' &&
      key_ii != 's' &&
      key_ii != 'i' &&
      key_ii != 'f' &&
      key_ii != 'c'
    );

    win_close (&win_ri);

    if (key_ii == KEY_ENTER)
        return (0);
    else if (key_ii == KEY_ESC)
        return (-1);
    else if (key_ii == 'r')
        return (-69);
    else if (key_ii == 'f')
        return (-70);
    else if (key_ii == 'i')
        return (-71);
    else if (key_ii == 'c')
        return (-73);
    else if (key_ii == 's')
        return (-74);
    else
        return (-42);
    }
Пример #14
0
Файл: main.c Проект: trylle/sxiv
void cleanup(void)
{
	img_close(&img, false);
	tns_free(&tns);
	win_close(&win);
}
Пример #15
0
// -------------------------------------------------
// ODBCFileOpen()
// Apre un file ODBC
// Ricerca in base all'estensione il driver da utilizzare
// 
BOOL ODBCFileOpen(CHAR *lpFileName)
{
	CHAR *lpBuf;
	SQLCHAR szConnStr[255];
    SWORD cbConnStr;
	SINT a,Hdl;
	CHAR **Driver;
	CHAR *lpExt;
	SINT nDriver=-1;
	
	win_open(EHWP_SCREENCENTER,50,300,59,-1,3,ON,"Connessione a ...");
	dispfm(10,27,1,-1,STYLE_BOLD,"#Arial",25,file_name(lpFileName));
	
	lpExt=rstrstr(lpFileName,"."); 
	if (lpExt==NULL) 
	{
		win_infoarg("Il file non contiene estensione [%s]",lpFileName);
		win_close(); return TRUE;
	}

	Hdl=ODBCDriverList("");
	Driver=memo_heap(Hdl);

	nDriver=-1;
	for (a=0;;a++)
	{
		if (Driver[a]==NULL) break;
		if (strstr(Driver[a],lpExt)) {nDriver=a; break;}
	}

	if (nDriver==-1)
	{
		memo_libera(Hdl,"?");
		win_infoarg("Driver sconosciuto per [%s]",lpExt);
		win_close();
	    return TRUE;
	}
/*
	sqlReturn=SQLConnect(EhOdbc.hConn,    // Handle della connessione
						 lpFileName,    // Handle della Windows
						 SQL_NTS, // Nome del file / Driver da usare
						 "",SQL_NTS, // UserName
						 "",SQL_NTS); // Password

	if (sqlReturn!=SQL_SUCCESS) 
		{ODBCError("Connect",sqlReturn); 
		 win_close();
	     return TRUE;
		}
iCheck=ODBCConnect("DBQ=C:\\Convert\\pa.xls;DRIVER={Microsoft Excel Driver (*.xls)}");
 */
	lpBuf=malloc(1024);
	sprintf(lpBuf,"DBQ=%s;DRIVER={%s}",lpFileName,Driver[nDriver]);
	EhOdbc.sqlLastError=SQLDriverConnect(EhOdbc.hConn,    // Handle della connessione
			                  NULL,    // Handle della Windows
							  lpBuf, // Nome del file / Driver da usare
							  (SQLSMALLINT) strlen(lpBuf), // Lunghezza
							  szConnStr, // Connection string di ritorno
							  (SQLSMALLINT) sizeof(szConnStr), 
							  &cbConnStr, 
							  SQL_DRIVER_NOPROMPT);
	free(lpBuf);

	if (EhOdbc.sqlLastError!=SQL_SUCCESS) 
		{
		 memo_libera(Hdl,"?");
		 if (!EhOdbc.fNoErrorView) ODBCError("ODBCFileOpen"); 
		 win_close();
	     return TRUE;
		}

	// --------------------------------------------------------------------
	// Alloca memoria per comandi (ritorna puntatore in hStmt)
	//
	//sqlReturn=SQLAllocStmt(EhOdbc.hConn, &EhOdbc.hStmt);
	EhOdbc.sqlLastError=SQLAllocHandle(SQL_HANDLE_STMT, EhOdbc.hConn, &EhOdbc.hStmt);
	if (EhOdbc.sqlLastError!=SQL_SUCCESS) {ODBCError("SQLAllocHandle/Env");  PRG_end("Ambiente stantment:?");}
	memo_libera(Hdl,"?");

	win_close();
	return FALSE;

/*
 iCheck=ODBCConnect("DBQ=C:\\Convert\\pa.xls;DRIVER={Microsoft Excel Driver (*.xls)}");
   // Alloca Ambiente ODBC
	SQLTRY("SQLAllocEnv", SQLAllocEnv(&EhOdbc->hEnv),EhOdbc);

    // Alloca Memoria per la connessione
	SQLTRY("SQLAllocConnect", SQLAllocConnect(EhOdbc->hEnv, &EhOdbc->hDBC),EhOdbc);

    // Carica il driver 
	SQLTRY("SQLDriverConnect", 
	        SQDriverConnect(EhOdbc->hDBC,    // Handle della connessione
			                 NULL,    // Handle della Windows
							 File, // Nome del file / Driver da usare
							 strlen(File), // Lunghezza
							 szConnStr, // Connection string di ritorno
							 sizeof(szConnStr), 
							 &cbConnStr, 
							 SQL_DRIVER_NOPROMPT),
							 EhOdbc);

	// Alloca memoria per i comandi (ritorna puntatore in hStmt)
	SQLTRY("SQLAllocStmt", SQLAllocStmt(EhOdbc->hDBC, &EhOdbc->hStmt),EhOdbc);
	return NULL;
}
*/
}
Пример #16
0
int main(int argc, char *argv[])
{
    byte keypress;

    client_init();

    if( argc > 1 )    /* Command line arguments */
	handle_cl_args(argc, argv);

    srand( time(NULL) );
    calc_lookup_tables(DEGREES);
    win_init();
    entity_init();
    if( (ent_img_loaded = (char *)malloc(num_entity_types)) == NULL ) {
	perror("Malloc");
	ERR_QUIT("Error allocating ent_img_loaded array", 1);
    } else {
	memset(ent_img_loaded, 0, num_entity_types);
    }

    /* Load client preferences from file */
    read_config_file( &client );
    /* Set view dimensions, which are calculated by tile width & heights */
    client.view_w = client.x_tiles * TILE_W;
    client.view_h = client.y_tiles * TILE_H;
    /* What the client WISHES their dimensions were (this may not be what
       it actually is, ie in demo's etc */
    client.desired_w = client.view_w;
    client.desired_h = client.view_h;

    weapon_type_init();
    particle_init();
    menu_init();

    cl_network_init();

    client.state = MENU;

    if( client.demo == DEMO_PLAY ) {
	cl_network_connect(NULL, 42);
	client.state = GAME_LOAD;
    }

    for( ; ; ) {
	switch( client.state ) {
	case MENU:
	    win_ungrab_pointer();
	    menu_driver();
	    break;

	case GAME_LOAD:
	    win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H);
	    wait_till_expose(5);

	    /* Finished loading, we are ready to play */
	    cl_change_map(client.map, client.gamemode);
	    break;

	case GAME_RESUME: /* Resume game from menu */
	    win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H);
	    wait_till_expose(5);
	    input_clear();
	    draw_status_bar();
	    cl_netmsg_send_ready(); /* Tell server new details */
	    cl_net_finish(); /* Send the NETMSG_READY to the server */
	    client.state = GAME_JOIN;

	    break;

	case GAME_JOIN:

        win_set_cursor( client.mousemode!=MOUSEMODE_ROTATE );
        win_set_cursor( 1 );


	    if( client.mousemode ) {
		win_grab_pointer();
	    }

	    text_buf_clear();
	    particle_clear();

	case GAME_PLAY:
	    cl_net_update();

	    if( client.state == GAME_PLAY ) { /* Maybe changed in net_update */
		draw_crosshair( my_entity );
		if( client.map_target_active )
		    draw_map_target( my_entity );

		text_buf_update();
		if( client.netstats )
		    cl_net_stats();

		win_update();

		/* Keyboard Input */
		client.dir = my_entity.dir;
		keypress = get_input();
		cl_netmsg_send_cl_update(keypress, client.dir);
	    }

	    cl_net_finish(); /* Send things that need sending */
	    cap_fps(client.fps);
	    break;

	case QUIT:
	    game_close();
	    image_close(); /* Free all the images */
	    win_close();
	    write_config_file(&client);
	    if( ent_img_loaded != NULL )
		free(ent_img_loaded);
	    exit(EXIT_SUCCESS);
	    break;
	}

    }

    return EXIT_SUCCESS;

}