Exemplo n.º 1
0
static void act_paste (void) {
    fileoffset_t cutsize, new_top;

    if (!cutbuffer)
	return;
    cutsize = buf_length (cutbuffer);
    if (!insert_mode) {
	if (cur_pos + cutsize > file_size) {
	    display_beep();
	    strcpy (message, "Too close to end of file to paste");
	    return;
	}
	buf_delete (filedata, cutsize, cur_pos);
	file_size -= cutsize;
    }
    buf_paste (filedata, cutbuffer, cur_pos);
    modified = TRUE;
    cur_pos += cutsize;
    file_size += cutsize;
    edit_type = !!edit_type;
    new_top = cur_pos - (scrlines-1) * width;
    if (new_top < 0)
	new_top = 0;
    new_top = begline(new_top);
    if (top_pos < new_top)
	top_pos = new_top;
}
Exemplo n.º 2
0
/*
 * Send header information which includes current working direcotry,
 * command line arguments, and CLASSPATH environment variable
 * to the server.
 */
void send_header(int fd, int argc, char** argv, char* authtoken)
{
    char path_buffer[MAXPATHLEN];
    buf read_buf = buf_new(BUFFER_SIZE, NULL);
    int i;

    // send current working directory.
    buf_printf(&read_buf, "%s: ", HEADER_KEY_CURRENT_WORKING_DIR);
    char* cwd = getcwd(path_buffer, MAXPATHLEN);
    if (cwd == NULL) {
        perror("ERROR: getcwd");
        exit(1);
    }

    buf_add(&read_buf, cwd);
    buf_add(&read_buf, "\n");

    buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_AUTHTOKEN, authtoken);

    // send command line arguments.
    char *encoded_ptr, *encoded_work;
    for (i = 1; i < argc; i++) {
        if (argv[i] != NULL) {
            // base64 encoded data is less "(original size) * 1.5 + 5" as much as raw data
            // "+5" is a extra space for '=' padding and NULL as the end of string
            encoded_ptr = malloc(sizeof(char) * strlen(argv[i]) * 1.5 + 5);
            if (encoded_ptr == NULL) {
                perror("ERROR: failed to malloc");
                exit(1);
            }
            encoded_work = encoded_ptr; // copy for free
            base64_encode(encoded_work, (unsigned char*) argv[i]);
            buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_ARG, encoded_work);
            free(encoded_ptr);
        }
    }

    // send envvars.
    if (client_option.env_include_mask != NULL) {
        make_env_headers(&read_buf,
                         environ,
                         client_option.env_include_mask,
                         client_option.env_exclude_mask);
    }

    char* cp = getenv("CLASSPATH");
    if (cp != NULL) {
        buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_CP, cp);
    }

    buf_printf(&read_buf, "\n");
    read_buf.size--; /* remove trailing '\0' */

#ifdef WINDOWS
    send(fd, read_buf.buffer, read_buf.size, 0);
#else
    write(fd, read_buf.buffer, read_buf.size);
#endif
    buf_delete(&read_buf);
}
Exemplo n.º 3
0
int __cdecl main( int argc, char *argv[] )
{
   lex ilex;
   plexitem pil;
   buf in;
   str fn;
   arr out;
   uint i;
   uint fout;

   gentee_init();
   printf("Start\n");
   str_init( &fn );

   str_copyzero( &fn, "gttbl.dat");
   fout = os_fileopen( &fn, FOP_CREATE );
   printf("Fout=%i %s\n", fout, str_ptr( &fn ));
   os_filewrite( fout, ( pubyte )&tbl_gt, 97 * sizeof( uint ));
   os_fileclose( ( pvoid )fout );

   str_copyzero( &fn, "gtdotbl.dat");
   fout = os_fileopen( &fn, FOP_CREATE );
   printf("Fout=%i %s\n", fout, str_ptr( &fn ));
   str_delete( &fn );
   os_filewrite( fout, ( pubyte )&tbl_gtdo, 81 * sizeof( uint ));
   os_fileclose( ( pvoid )fout );

   arr_init( &out, sizeof( lexitem ));
   buf_init( &in );
   buf_copyzero( &in, 
      "</r/&xfa;&#10;&#3;&#1&xfa; #ap/dfield( 'qwer ()ty' , \"my , name\" , qqq)#asdf.fgwsw/# se# &xaa;"
      "<2 qqq> </2><1 a2345=&xf0;> 223&</1><-qwe-rty->"
      "<mygt /asd = \"qwerty sese'\" qq21 = 'dedxd' 'esese;' aqaq=325623/>"
      "<a asdff /a>   <mygtdd><a /><-ooops-><ad />< qq</>"
      "xxx  </r/nm <_aa aqaqa /_aaaa /_a/_aa><a22222/ >"
      "<*abc ></abc><|*aaa = qqqq></aaa>ooops aaa</eee>\"\r\n</>");
//   buf_copyzero( &in, "<mygt > <aaa asdff>qqqq</>      </mygtdd>qq </> xxx  </r/nm <_aa aqaqa /_aaaa /_aa> <a22222/ /> </ >  ");
   printf("lex_init\n");
   lex_init( &ilex, (puint)&tbl_gtdo );
   printf("gentee_lex\n");
   gentee_lex( &in, &ilex, &out );
   if (arr_count(&ilex.state))
      printf("================= State=%x/%i \n", arr_getuint( &ilex.state,
          arr_count(&ilex.state) - 1 ), arr_count(&ilex.state));
   for ( i = 0; i < arr_count( &out ); i++ )
   {
      pil = ( plexitem )arr_ptr( &out, i );
      printf("ID=%x pos=%i len=%i \n", pil->type, pil->pos, pil->len,
             buf_ptr( &in ) + pil->pos );
   }
//   gentee_compile();
   lex_delete( &ilex );
   buf_delete( &in );
   arr_delete( &out );
   gentee_deinit();
   printf("OK\n");
   getch();
   return 0;
}
Exemplo n.º 4
0
void test_offs_ncopy_extend() {
  buf b = buf_new(3, NULL);
  buf_offs_ncopy(&b, 0, "abcd", 4);
  assert(memcmp(b.buffer, "abcd", 4) == 0);
  assert(b.size == 4);
  assert(b.buffer_size == 6);
  buf_delete(&b);
}
Exemplo n.º 5
0
void test_offs_ncopy_extend3() {
  buf b = buf_new(4, NULL);
  buf_offs_ncopy(&b, 0, "abcdefg", 7);
  assert(memcmp(b.buffer, "abcdefg\0", 8) == 0);
  assert(b.buffer_size == 8);
  assert(b.size == 7);
  buf_delete(&b);
}
Exemplo n.º 6
0
/*
 * 0 1 2 3 4 5 6 7 8 9
 * ? ? ? ? ? a b c d \0
 */
void test_offs_ncopy_extend4() {
  buf b = buf_new(2, NULL);
  buf_offs_ncopy(&b, 5, "abcd", 5);
  assert(memcmp(b.buffer+5, "abcd\0", 5) == 0);
  assert(b.buffer_size == 16);
  assert(b.size == 10);
  buf_delete(&b);
}
Exemplo n.º 7
0
void test_offs_ncopy2() {
  buf b = buf_new(10, NULL);
  buf_offs_ncopy(&b, 0, "abc", 3);
  assert(memcmp(b.buffer, "abc\0", 4) == 0); /* extra \0 added */
  assert(b.buffer_size == 10);
  assert(b.size == 3);  /* still size == 3 (a,b,c) */
  buf_delete(&b);
}
Exemplo n.º 8
0
void test_offs_ncopy() {
  buf b = buf_new(4, NULL);
  buf_offs_ncopy(&b, 0, "abc", 4);
  assert(memcmp(b.buffer, "abc\0", 4) == 0);
  assert(b.buffer_size == 4);
  assert(b.size == 4); /* a,b,c + \0 */
  buf_delete(&b);
}
Exemplo n.º 9
0
void test_offs_ncopy3() {
  buf b = buf_new(3, NULL);
  buf_offs_ncopy(&b, 0, "abc", 3);
  assert(memcmp(b.buffer, "abc\0", 4) == 0);
  assert(b.buffer_size == 3); /* auto extended */
  assert(b.size == 3);  /* still size == 3 (a,b,c) */
  buf_delete(&b);
}
Exemplo n.º 10
0
/*
 * 0 1 2 3 4
 * ? a b c \0
 */
void test_offs_ncopy5() {
  buf b = buf_new(10, NULL);
  buf_offs_ncopy(&b, 1, "abcd", 3);
  assert(memcmp(b.buffer+1, "abc\0", 3) == 0); /* extra \0 added */
  assert(b.buffer_size == 10);
  assert(b.size == 4);
  buf_delete(&b);
}
Exemplo n.º 11
0
/*
 * 0 1 2 3 4 5 6
 * ? ? a b c d \0
 */
void test_offs_ncopy6() {
  buf b = buf_new(10, NULL);
  buf_offs_ncopy(&b, 2, "abcd", 5);
  assert(memcmp(b.buffer+2, "abcd\0", 5) == 0);
  assert(b.buffer_size == 10);
  assert(b.size == 7);
  buf_delete(&b);
}
Exemplo n.º 12
0
void test_ncopy2() {
  buf b = buf_new(2, NULL);
  buf_nstrcopy(&b, "abcde", 5);
  assert(memcmp(b.buffer, "abcde", 5) == 0);
  assert(b.buffer_size == 8);
  assert(b.size == 5);
  buf_delete(&b);
}
Exemplo n.º 13
0
void test_ncopy() {
  buf b = buf_new(0, NULL);
  buf_nstrcopy(&b, "abcde", 6);
  assert(memcmp(b.buffer, "abcde\0", 6) == 0);
  assert(b.buffer_size == DEFAULT_BUFFER_SIZE);
  assert(b.size == 6);
  buf_delete(&b);
}
Exemplo n.º 14
0
void test_add() {
  buf b = buf_new(0, NULL);
  buf_add(&b, "abcde");
  assert(memcmp(b.buffer, "abcde\0", 6) == 0);
  buf_add(&b, "fghij");
  assert(memcmp(b.buffer, "abcdefghij\0", 11) == 0);
  assert(b.buffer_size == DEFAULT_BUFFER_SIZE);
  assert(b.size == 11);
  buf_delete(&b);
}
Exemplo n.º 15
0
void test_buf_printf2() {
  buf b = buf_new(2, NULL);
  buf_printf(&b, "[%d, %02x]", 10, 10);
  assert(memcmp(b.buffer, "[10, 0a]\0", 9) == 0);
  buf_printf(&b, "[%s, %5s]", "abc", "def");
  assert(memcmp(b.buffer, "[10, 0a][abc,   def]\0", 21) == 0);
  assert(b.buffer_size == 32);
  assert(b.size == 21);
  buf_delete(&b);
}
Exemplo n.º 16
0
void test_add_extend() {
  buf b = buf_new(2, NULL);
  buf_add(&b, "abcde");
  assert(memcmp(b.buffer, "abcde\0", 6) == 0);
  buf_add(&b, "fghij");
  assert(memcmp(b.buffer, "abcdefghij\0", 11) == 0);
  assert(b.buffer_size == 16);
  assert(b.size == 11);
  buf_delete(&b);
}
Exemplo n.º 17
0
static void cmdline_mode_key_pressed(struct editor *editor, struct tb_event *ev) {
  char ch;
  struct cmdline_mode *mode = (struct cmdline_mode*) editor->mode;
  switch (ev->key) {
  case TB_KEY_ESC: case TB_KEY_CTRL_C:
    buf_clear(editor->status);
    editor_pop_mode(editor);
    return;
  // FIXME(ibadawi): termbox doesn't support shift + arrow keys.
  // vim uses <S-Left>, <S-Right> for moving cursor to prev/next WORD.
  case TB_KEY_ARROW_LEFT:
    editor->status_cursor = max(editor->status_cursor - 1, 1);
    return;
  case TB_KEY_ARROW_RIGHT:
    editor->status_cursor = min(editor->status_cursor + 1, editor->status->len);
    return;
  case TB_KEY_CTRL_B: case TB_KEY_HOME:
    editor->status_cursor = 1;
    return;
  case TB_KEY_CTRL_E: case TB_KEY_END:
    editor->status_cursor = editor->status->len;
    return;
  case TB_KEY_BACKSPACE2:
    buf_delete(editor->status, --editor->status_cursor, 1);
    if (editor->status->len == 0) {
      editor_pop_mode(editor);
      return;
    } else if (mode->char_cb) {
      char *command = xstrdup(editor->status->buf + 1);
      mode->char_cb(editor, command);
      free(command);
    }
    return;
  case TB_KEY_ENTER: {
    char *command = xstrdup(editor->status->buf + 1);
    editor_pop_mode(editor);
    mode->done_cb(editor, command);
    free(command);
    return;
  }
  case TB_KEY_SPACE:
    ch = ' ';
    break;
  default:
    ch = (char) ev->ch;
  }
  char s[2] = {ch, '\0'};
  buf_insert(editor->status, s, editor->status_cursor++);
  if (mode->char_cb) {
    char *command = xstrdup(editor->status->buf + 1);
    mode->char_cb(editor, command);
    free(command);
  }
}
Exemplo n.º 18
0
static void act_delch(void) {
    if (!insert_mode) {
	display_beep();
	strcpy (message, "Can't delete while not in Insert mode");
    } else if (cur_pos < file_size) {
	buf_delete (filedata, 1, cur_pos);
	file_size--;
	edit_type = !!edit_type;
	modified = TRUE;
    }
}
Exemplo n.º 19
0
static void act_delete(void) {
    if (!insert_mode || (edit_type!=2 && cur_pos==0)) {
	display_beep();
	strcpy (message, "Can't delete while not in Insert mode");
    } else if (cur_pos > 0 || edit_type == 2) {
	act_left();
	buf_delete (filedata, 1, cur_pos);
	file_size--;
	edit_type = !!edit_type;
	modified = TRUE;
    }
}
Exemplo n.º 20
0
void test_buf_printf() {
  buf b = buf_new(2, NULL);
  buf_printf(&b, "abcde");
  assert(memcmp(b.buffer, "abcde\0", 6) == 0);
  buf_printf(&b, "fghij");
  printf("%s\n", b.buffer);
  assert(memcmp(b.buffer, "abcdefghij\0", 11) == 0);
  assert(b.buffer_size == 16);
  printf("%d\n", b.size);
  assert(b.size == 11);
  buf_delete(&b);
}
Exemplo n.º 21
0
void STDCALL gesave_finish( pvmEngine pThis )
{
   buf  bt;
   pbuf pb = pThis->gesave;
   uint size = buf_len( pThis, pb ) - pThis->gesaveoff;

   if ( size <= 187 )
      *( pubyte )(( pubyte )buf_ptr( pThis, pThis->gesave ) + pThis->gesaveoff + 5 ) = ( ubyte )size;
   else
   {
      buf_init( pThis, &bt );
      pThis->gesave = &bt;
      if ( size < 16800 )
      {
         size++;
         gesave_bwd( pThis, size );
      }
      else
         if ( size < 0xFFF0 ) 
         {
            gesave_addubyte( pThis, 0xFE );
            size += 2;
            gesave_addushort( pThis, size );
         }
         else
         {
            gesave_addubyte( pThis, 0xFF );
            size += 4;
            gesave_adduint( pThis, size );
         }
      // Write the size
      // We have already had one byte, so -1
      buf_insert( pThis, pb, pThis->gesaveoff + 5, ( pubyte )&size /*any*/, buf_len( pThis, pThis->gesave ) - 1 );
      mem_copy( pThis, buf_ptr( pThis, pb ) + pThis->gesaveoff + 5, buf_ptr( pThis, pThis->gesave ), buf_len( pThis, pThis->gesave ));

      buf_delete( pThis, &bt );
      pThis->gesave = pb;
   }
}
Exemplo n.º 22
0
void STDCALL gesave_finish( void )
{
   buf  bt;
   pbuf pb = gesave;
   uint size = buf_len( pb ) - gesaveoff;

   if ( size <= 187 )
      *( pubyte )(( pubyte )buf_ptr( gesave ) + gesaveoff + 5 ) = ( ubyte )size;
   else
   {
      buf_init( &bt );
      gesave = &bt;
      if ( size < 16800 )
      {
         size++;
         gesave_bwdi( size );
      }
      else
         if ( size < 0xFFF0 ) 
         {
            gesave_addubyte( 0xFE );
            size += 2;
            gesave_addushort( size );
         }
         else
         {
            gesave_addubyte( 0xFF );
            size += 4;
            gesave_adduint( size );
         }
      // Write the size
      // We have already had one byte, so -1
      buf_insert( pb, gesaveoff + 5, ( pubyte )&size /*any*/, buf_len( gesave ) - 1 );
      mem_copy( buf_ptr( pb ) + gesaveoff + 5, buf_ptr( gesave ), buf_len( gesave ));

      buf_delete( &bt );
      gesave = pb;
   }
}
Exemplo n.º 23
0
/*
 * Make screen dump to buffer
 */
cptr make_screen_dump(void)
{
	BUF *screen_buf;
	int y, x, i;
	cptr ret;

	byte a = 0, old_a = 0;
	char c = ' ';

	static cptr html_head[] = {
		"<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
		"<pre>",
		0,
	};
	static cptr html_foot[] = {
		"</pre>\n",
		"</body>\n</html>\n",
		0,
	};

	bool old_use_graphics = use_graphics;

	int wid, hgt;

	Term_get_size(&wid, &hgt);

	/* Alloc buffer */
	screen_buf = buf_new();
	if (screen_buf == NULL) return (NULL);

	if (old_use_graphics)
	{
		/* Clear -more- prompt first */
		msg_print(NULL);

		use_graphics = FALSE;
		reset_visuals();

		/* Redraw everything */
		p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);

		/* Hack -- update */
		handle_stuff();
	}

	for (i = 0; html_head[i]; i++)
		buf_sprintf(screen_buf, html_head[i]);

	/* Dump the screen */
	for (y = 0; y < hgt; y++)
	{
		/* Start the row */
		if (y != 0)
			buf_sprintf(screen_buf, "\n");

		/* Dump each row */
		for (x = 0; x < wid - 1; x++)
		{
			int rv, gv, bv;
			cptr cc = NULL;
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			switch (c)
			{
			case '&': cc = "&amp;"; break;
			case '<': cc = "&lt;"; break;
			case '>': cc = "&gt;"; break;
#ifdef WINDOWS
			case 0x1f: c = '.'; break;
			case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
#endif
			}

			a = a & 0x0F;
			if ((y == 0 && x == 0) || a != old_a) {
				rv = angband_color_table[a][1];
				gv = angband_color_table[a][2];
				bv = angband_color_table[a][3];
				buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">", 
					    ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
				old_a = a;
			}
			if (cc)
				buf_sprintf(screen_buf, "%s", cc);
			else
				buf_sprintf(screen_buf, "%c", c);
		}
	}
	buf_sprintf(screen_buf, "</font>");

	for (i = 0; html_foot[i]; i++)
		buf_sprintf(screen_buf, html_foot[i]);

	/* Screen dump size is too big ? */
	if (screen_buf->size + 1> SCREEN_BUF_SIZE)
	{
		ret = NULL;
	}
	else
	{
		/* Terminate string */
		buf_append(screen_buf, "", 1);

		ret = string_make(screen_buf->data);
	}

	/* Free buffer */
	buf_delete(screen_buf);

	if (old_use_graphics)
	{
		use_graphics = TRUE;
		reset_visuals();

		/* Redraw everything */
		p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);

		/* Hack -- update */
		handle_stuff();
	}

	return ret;
}
Exemplo n.º 24
0
/*-----------------------------------------------------------------------------
*
* ID: m_func 02.11.06 0.0.A.
*
* Summary: The func, method, operator, property, text processing
*
-----------------------------------------------------------------------------*/
plexem STDCALL m_func( plexem curlex, uint flgextern )
{
#ifdef DOUT
   uint     i;
#endif 


   uint     funckey;  //Вид функции
   uint     flgfunc;  //Флаги функции   

   pflabel  curlabel; // Текущий элемент в таблице меток
   pflabel  endlabel; // Конец таблицы меток
   uint     isreturn; //Есть return

   uint     thistype; //Тип переменной this для методов+
   pubyte   name;     //Имя функции
   plexem   lexname;  //Лексема с именем функции
   plexem   lexprev;

   s_desctype desctype;//Описание типа
   s_descid   descvar; //Описание переменной

   uint off_parcount; //Смещение в заголовке функции на кол. параметров
   uint off_blccount; //Смещение в заголовке функции на кол. блоков

   bcflag     bcf;    //Переменная для получение флагов функции
   pbuf       b;
   pfwith     pwith; 
   pvmobj     funcobj;   
   uint       thisid; //Номер переменной для this в текст функции

D( "Func start\n" );

// Инициализация
   desctype.idtype = 0;
   descvar.idtype = 0;
   descvar.flgdesc = 0;
   mem_zero( &fd, sizeof( fd ) );
   thistype = 0;
   funckey = curlex->key;
   hash_init( &fd.nvars, sizeof( uint ) );
   hash_init( &fd.nlabels, sizeof( uint ) );
   for ( b = &fd.bhead; b <= &fd.bvarsas; b++ )
   {
      buf_init( b );
      buf_reserve( b, 0x200 );
      b->step = 0x200;
   }
   fd.bvars.use = sizeof( fvar );
   fd.blabels.use = sizeof( flabel );
//   _compile->pout = &fd.bhead;   
//   fd.blcount = 0;
//   fd.varcount = 0;
//   fd.curcount = 0;
//   fd.lastcurcount = 0;
//   fd.bllevel = 0;
//   fd.blcycle = 0;
   fd.offlcbreak = -1;
   fd.offlccontinue = -1;   
//   fd.functype = 0;

   switch ( funckey )
   {
      case KEY_METHOD:
         flgfunc = GHBC_METHOD;
         break;
      case KEY_OPERATOR:
         flgfunc = GHBC_OPERATOR;
         break;
      case KEY_PROPERTY:
         flgfunc = GHBC_PROPERTY;
         break;
      case KEY_TEXT:
         flgfunc = GHBC_TEXT;
         break;
      default:
         flgfunc = 0;
   }
   curlex = lexem_next( curlex, LEXNEXT_IGNLINE );

// Получаем тип возвращаемого значения функции/метода если он есть
   if ( curlex->type == LEXEM_NAME )
      curlex = desc_idtype( curlex, &desctype );

   if ( desctype.idtype )
   {
      if ( ( funckey == KEY_METHOD || funckey == KEY_PROPERTY ) &&
           curlex->type == LEXEM_OPER &&
           curlex->oper.operid == OpWith )
      {
         //Возврат на лексему влево текущая лексема тип объекта
         desctype.idtype = 0;
         curlex--;
      }
      else
      {
         fd.functype = desctype.idtype;
         fd.funcoftype = desctype.oftype;
      }
   }
   lexprev = curlex;
   curlex = lexem_next( curlex, LEXNEXT_SKIPLINE );
// Получаем тип объекта для метода
   if ( funckey == KEY_METHOD || funckey == KEY_PROPERTY )
   {
      //Получаем тип объекта
	  if ( curlex->type > 32 )
		 msg( MExptype | MSG_LEXERR, lexprev );
	  if ( thistype = bc_type( curlex ) )
      {
         curlex = lexem_next( curlex, 0 );
         if ( curlex->type == LEXEM_OPER &&
              curlex->oper.operid == OpWith )
         {
            curlex = lexem_next( curlex, 0 );
         }
         else
            msg( MExppoint | MSG_LEXERR, curlex );
      }
      else
         msg( MExptype | MSG_LEXERR, curlex );
   }
// Получение имени функции, метода ...   
   if ( funckey == KEY_OPERATOR )
   {
      if ( curlex->type != LEXEM_OPER )
         msg( MExpoper | MSG_LEXERR, curlex );
      name = ( pubyte )&curlex->oper.name;
   }
   else
   {
      if ( curlex->type != LEXEM_NAME )
         msg( MExpname | MSG_LEXERR, curlex );
      name = lexem_getname( curlex );      
   }
   lexname = curlex;
   _vm.pos = curlex->pos;
   
// Получение списка директив
   curlex = lexem_next( curlex, flgextern ? 0 : LEXNEXT_IGNLINE );   
   curlex = bc_flag( curlex, BFLAG_FUNC, &bcf );   
   flgfunc |= GHCOM_NAME | bcf.value;
   _compile->pout = &fd.bhead;   
   out_head( OVM_BYTECODE, flgfunc, name );

   create_varmode( &fd.bhead, &desctype, 0 );//Возвращаемое значение

   off_parcount = fd.bhead.use;
   out_adduint( 0 );//Количество параметров

   if ( funckey == KEY_METHOD || funckey == KEY_PROPERTY )
   {   //Создание параметра this
      mem_zero( &descvar, sizeof( descvar ));
      descvar.idtype = thistype;
      descvar.name = "this";
      descvar.lex = curlex;
      descvar.flgdesc = DESCID_PARFUNC;

      pwith = ( pfwith )buf_appendtype( &fd.bwith, sizeof( fwith )) ;
      pwith->num = var_checkadd( &descvar );
      pwith->oftype = 0;
      pwith->type = thistype;
   }

//Получение списка параметров
   if ( curlex->type == LEXEM_OPER &&
        curlex->oper.operid == OpLbrack )//Открывающая скобка
   {
      curlex = lexem_next( curlex, LEXNEXT_IGNLINE );
      curlex = var_def( curlex, DESCID_PARFUNC );
      if ( curlex->type != LEXEM_OPER ||//Системная лексема
           curlex->oper.operid != OpRbrack )//Закрывающая скобка
         msg( MExpclosebr | MSG_LEXERR, curlex );

      curlex = lexem_next( curlex, flgextern ? 0 : LEXNEXT_IGNLINE );
   }
   else
   {
      if ( funckey == KEY_OPERATOR )
         msg( MExpopenbr | MSG_LEXERR, curlex );
   }

   fd.flgfunc = flgfunc;
   if ( flgfunc & GHBC_RESULT )
   {   //Создание параметра result
      if ( !fd.functype || fd.functype <= TUlong )
         msg( MResulttype | MSG_LEXERR, curlex );
      mem_zero( &descvar, sizeof( descvar ));
      descvar.idtype = desctype.idtype;
      descvar.oftype = desctype.oftype;
      descvar.flgdesc = DESCID_PARFUNC;
      descvar.name = "result";
      descvar.lex = curlex;
      fd.idresult = var_checkadd( &descvar );
      fd.functype = 0;
   }
   if ( fd.varcount )
   {
      *( puint )( fd.bhead.data + off_parcount ) = fd.varcount;//Кол-во параметров
      if ( flgfunc & ( GHBC_ENTRY | GHBC_MAIN ) )
         msg( MMainpar | MSG_LEXERR, curlex );
      fd.curcount = 0;
   }
   off_blccount = fd.bhead.use;
   out_adduint( 0 );//Количество блоков

   if ( funckey == KEY_PROPERTY )
   {      
      if ( ( fd.functype && fd.varcount > 1 ) ||
           (!fd.functype && fd.varcount != 2 ))
      {
         msg( MProppar | MSG_LEXERR, curlex );//Неверное количество параметров в описании свойства
      }
      if ( type_fieldname( thistype, name ) )
      {
         msg( MPropfield | MSG_LEXERR, curlex );//Свойство совпадает с именем поля
      }
   }
   
   funcobj = load_bytecode( &fd.bhead.data, flgextern ? VMLOAD_EXTERN : VMLOAD_FIRST );   
   if ( bcf.value & GHRT_ALIAS )
   {  
      alias_setid( bcf.alias, funcobj->id );     
   }
   if ( !( flgextern ) )
   {      
      if ( _compile->flag & CMPL_DEBUG )
      {  
         _compile->pout = fd.bout = &fd.bsubout;
         out_adduints( 3,  CDatasize, 
                           str_len( _compile->cur->filename ) + 5,
                           str_pos2line( _compile->cur->src, lexname->pos, 0 ) + 1 );
         out_addptr( str_ptr( _compile->cur->filename ), str_len( _compile->cur->filename ) + 1 );                     
         out_adduint( CDbgFunc );
         _compile->pout = fd.bout = &fd.bfuncout; 
      }
      _compile->pout = fd.bout = &fd.bfuncout;
      if ( funckey == KEY_TEXT )
      {   //Создание параметра this для Text функции
         mem_zero( &descvar, sizeof( descvar ));
         descvar.idtype = TUint;
         descvar.name = "this";
         descvar.lex = curlex;
         descvar.flgdesc = DESCID_VAR;///DESCID_PARFUNC;
         thisid = var_checkadd( &descvar );
         
         /*pwith = ( pfwith )buf_appendtype( &fd.bwith, sizeof( fwith )) ;
         pwith->num = var_checkadd( &descvar );
         //print( "ssssssssss %x %x %x %x", fd.bvars.data, fd.bvars.use, pwith->num, sizeof( fvar ) );
         pwith->oftype = 0;
         pwith->type = TStr;*/
         ((pfvar)(fd.bvars.data + fd.bvars.use - sizeof( fvar )))->type = TStr;
         out_adduints( 4, CVarptrload, thisid, CGetText, CSetI );
         /*buf_appenduint( &fd.bblinit, CVarptrload );
         buf_appenduint( &fd.bblinit, thisid );
         buf_appenduint( &fd.bblinit, CGetText );
         buf_appenduint( &fd.bblinit, CSetI );*/
      }
      curlex = f_body( curlex );
      
      *((puint)(fd.bhead.data+off_blccount)) = fd.blcount;

      curlabel = ( pflabel )( fd.blabels.data ) + 1;
      endlabel = ( pflabel )( fd.blabels.data + fd.blabels.use );
      //Контроль неразрешённых меток и проверка выходов из функции
      isreturn = 0;
      while( curlabel < endlabel )
      {
         if ( curlabel->type & LABT_GT )
         {
            if ( ( curlabel->type & LABT_GTUNDEF ) == LABT_GTUNDEF )
               msg( MUnklabel | MSG_LEXNAMEERR, curlabel->lex );
            *( puint )(fd.bfuncout.data + curlabel->offbout ) = 
                     ((( pflabel )(fd.blabels.data + curlabel->link ))->offbout + 
                      fd.bsubout.use )/sizeof(uint);
            if ( !isreturn )//Помечаем метку как отработавшую (на неё был переход)
               (( pflabel )(fd.blabels.data + curlabel->link ))->type |= LABT_LABELWORK;            
         }
         else
         if ( curlabel->type & LABT_RETURN )
         {
            isreturn = 1;//Устанавливаем флаг
         }
         else
         if ( curlabel->type & LABT_LABELWORK )
            isreturn = 0;//Если была отработавшая метка, то сбрасываем флаг
         curlabel++;
      }
      if ( fd.functype )
      {
         if ( !isreturn )
            msg( MMustret | MSG_LEXNAMEERR, lexname );
      }
      else
         if ( !isreturn )
         {
            if ( fd.flgfunc & GHBC_RESULT )
            {
               out_add2uint( CVarload, fd.idresult );
            }
            out_adduint( CReturn );
         }      
      buf_add( &fd.bhead, &fd.bvardef );
      
      if ( fd.bsubout.use )
      {
         if ( fd.offsubgoto )
         {
            //*((( puint)fd.bsubout.data ) + 1) = fd.bsubout.use/sizeof( uint );
            *( puint )( fd.bsubout.data + fd.offsubgoto ) = fd.bsubout.use / sizeof( uint );
         }
         buf_add( &fd.bhead, &fd.bsubout );
      }
      buf_add( &fd.bhead, &fd.bfuncout );
      _compile->pout = &fd.bhead;
      out_finish();
#ifdef DOUT
   //Тестируемый вывод 
   //if ( name[0] == 'c' && name[1] == 'r' ) getch();
   print( "FUNC OUT %x %s:\n", funcobj->id, name );
   for (i = 0; i < fd.bhead.use ; i++ )
   {
      print( "  %x", fd.bhead.data[i] );
   } 
   print( "\n" );
#endif            
      load_bytecode( &fd.bhead.data, VMLOAD_OK );
    //  print( "funcobjid2 =%x\n", funcobj->id );
   }
   //Очистка памяти
   for ( b = &fd.bhead;/*&fd.bblinit;*/ b <= &fd.bvarsas; b++ )
   {
      buf_delete( b );
   }
   hash_delete( &fd.nvars );
   hash_delete( &fd.nlabels );

D( "Func Stop\n" );
   return curlex;
}
Exemplo n.º 25
0
void test_buf_new() {
  buf b = buf_new(0, NULL);
  assert(b.buffer_size == DEFAULT_BUFFER_SIZE);
  buf_delete(&b);
}
Exemplo n.º 26
0
uint STDCALL ge_save( pvmEngine pThis, char* fileName, char* isSave)
{
    gehead   head;
    pgehead  phead;
    uint     i, ii, count;
    pvmobj   pvmo;
    buf       out;
    str  filename;
    if ( setjmp( pThis->stack_state) == -1 ) 
        return 0;

    str_init( pThis, &filename );
    str_copyzero( pThis, &filename, fileName );
    buf_init( pThis, &out );

    pThis->gesave = &out;
    buf_reserve( pThis, &out, 0x1ffff );

   *( puint )&head.idname = GE_STRING;//0x00004547;   // строка GE
   head.flags = 0;
   head.crc = 0;
   head.headsize = sizeof( gehead );
   head.size = 0;
   head.vermajor = GEVER_MAJOR; 
   head.verminor = GEVER_MINOR; 
   
   buf_append( pThis, &out, ( pubyte )&head, sizeof( gehead ));
   // Save resources at the first !
   gesave_resource(pThis);

   count = arr_count( pThis, &pThis->_vm.objtbl );
   for ( i = KERNEL_COUNT; i < count ; i++ )
   {
      if(isSave && isSave[i] == 0)
      {
         /* gesave_addubyte( pThis, OVM_NONE );
          gesave_adduint( pThis, GHCOM_PACK);
          gesave_bwd( pThis, 6 );*/
          pThis->popravka ++;
          continue;
      }

      pvmo = ( pvmobj )PCMD( i );
      pvmo->id -= pThis->popravka;
      //@init @delete @array @oftype @index -не удалять имена
      if(pThis->isDelName&&(pvmo->flag&GHCOM_NAME)&&pvmo->name&&lstrcmpA("@init",pvmo->name)&&
          lstrcmpA("@delete",pvmo->name)&&lstrcmpA("@array",pvmo->name)&&
          lstrcmpA("@oftype",pvmo->name)&&lstrcmpA("@index",pvmo->name))
      {
          pvmo->flag &= ~GHCOM_NAME;
      }else
          if(pvmo->name)
             pvmo->flag |= ~GHCOM_NAME;

      gesave_head( pThis, pvmo->type, pvmo->flag & GHCOM_NAME ? 
          pvmo->name : NULL, pvmo->flag );
      
      switch ( pvmo->type )
      {
         case OVM_NONE:
            break;
         case OVM_BYTECODE:
            gesave_bytecode( pThis, ( povmbcode )pvmo );
            break;
         case OVM_EXFUNC:
            ((povmfunc)pvmo)->import = ((pvmobj)PCMD(((povmfunc)pvmo)->import))->id;
            gesave_exfunc( pThis, ( povmfunc )pvmo );
            break;
         case OVM_TYPE:
             {
                for(ii = 0; ii<((povmtype)pvmo)->count; ii++)
                {
                    if(pThis->isDelName)
                        ((povmtype)pvmo)->children[ii].flag &=~GHCOM_NAME;
                    else if(((povmtype)pvmo)->children[ii].name)
                        ((povmtype)pvmo)->children[ii].flag |=GHCOM_NAME;
                }
                gesave_type( pThis, ( povmtype )pvmo );
             }break;
         case OVM_GLOBAL:
            gesave_var( pThis, (( povmglobal )pvmo)->type );
            break;
         case OVM_DEFINE:
            gesave_define( pThis, ( povmdefine )pvmo );
            break;
         case OVM_IMPORT:
            gesave_import( pThis, ( povmimport )pvmo );
            break;
         case OVM_ALIAS:
            gesave_bwd( pThis, (( povmalias )pvmo)->idlink );
            break;
      }
      gesave_finish(pThis);
   }
   // Specify the full size and crc
   phead = ( pgehead )buf_ptr( pThis, &out );
   phead->size = buf_len( pThis, &out );
   phead->crc = crc( pThis, ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF );
   buf2file( pThis, &filename, &out );
   buf_delete( pThis, &out );
   str_delete( pThis, &filename );
   return 1;
}