Пример #1
0
/* insert this line into program */
void
insert(dbref player, const char *line)
{
	dbref program;
	int i;
	struct line *curr;
	struct line *new_line;

	program = PLAYER_CURR_PROG(player);
	if (!string_compare(line, EXIT_INSERT)) {
		PLAYER_SET_INSERT_MODE(player, 0);	/* turn off insert mode */
		notify_nolisten(player, "Exiting insert mode.", 1);
		return;
	}
	i = PROGRAM_CURR_LINE(program) - 1;
	for (curr = PROGRAM_FIRST(program); curr && i && i + 1; i--)
		curr = curr->next;
	new_line = get_new_line();	/* initialize line */
	if (!*line) {
		new_line->this_line = alloc_string(" ");
	} else {
		new_line->this_line = alloc_string(line);
	}
	if (!PROGRAM_FIRST(program)) {	/* nothing --- insert in front */
		PROGRAM_SET_FIRST(program, new_line);
		PROGRAM_SET_CURR_LINE(program, 2);	/* insert at the end */
		/* DBDIRTY(program); */
		return;
	}
	if (!curr) {				/* insert at the end */
		i = 1;
		for (curr = PROGRAM_FIRST(program); curr->next; curr = curr->next)
			i++;				/* count lines */
		PROGRAM_SET_CURR_LINE(program, i + 2);
		new_line->prev = curr;
		curr->next = new_line;
		/* DBDIRTY(program); */
		return;
	}
	if (!PROGRAM_CURR_LINE(program)) {	/* insert at the
										   * beginning */
		PROGRAM_SET_CURR_LINE(program, 1);	/* insert after this new
											   * line */
		new_line->next = PROGRAM_FIRST(program);
		PROGRAM_SET_FIRST(program, new_line);
		/* DBDIRTY(program); */
		return;
	}
	/* inserting in the middle */
	PROGRAM_SET_CURR_LINE(program, PROGRAM_CURR_LINE(program) + 1);
	new_line->prev = curr;
	new_line->next = curr->next;
	if (new_line->next)
		new_line->next->prev = new_line;
	curr->next = new_line;
	/* DBDIRTY(program); */
}
Пример #2
0
/*---------------------------------------------------------- * 
* func name: check_upgrade_configfile() 
* function : 分析版本配置文件.检查是否需要更新. 
* calllist :            
*            
*
* calledlist:  
* input    :  
* output   :  
* parameter: buffer 版本config文件的地址
             buf_len版本文件的长度
* 			 
* return   : NULL  失败
* 			 成功  版本信息的sw_version的地址
* 			 
* 	 
* 
* notice   : 使用前get_system_version_info()必需先调用成功.
*--------------------------------------------------------*/
static int  check_netupgrade_configfile(unsigned char* buffer, 
    int buf_len,CHUNK_HEADER* pbootloadversion,CHUNK_HEADER* psystemversion)
{
   //firstly split with "\r\n"
	char *line;
	int   ver = 0, maxver;
	char *sfile = NULL;
	char *stmpfile = NULL;
	char *sver = NULL, *stmpver = NULL;
	char *ptr = buffer;
    char strTmp[30];
    char strTmp1[30];

	if (buf_len <= 0)
	{
		return -1;
    }
	
	maxver = 0;	
	line = get_new_line(&ptr, "\n");
	while(line != NULL)
	{		
		//split the items
		if(0 !=  check_config_version(line, &stmpver, &stmpfile, 
		               pbootloadversion->version,psystemversion->version))
		{
			ver = calcheck_version(stmpver);
			
			if(maxver < ver)
			{
				maxver = ver;
				sver = stmpver;
				sfile = stmpfile;
				if (sfile)
	            {
	                return 1;//need to updata;
                }
			}
		}
		line = get_new_line(&ptr, "\n");
	}
	return 0;
}
Пример #3
0
struct line *
read_program(dbref i)
{
        char buf[BUFFER_LEN];
        struct line *first;
        struct line *prev = NULL;
        struct line *nu;
        FILE *f;
        int len;

        first = NULL;
        snprintf(buf, sizeof(buf), "muf/%d.m", (int) i);
        f = fopen(buf, "rb");
        if (!f)
                return 0;

        while (fgets(buf, BUFFER_LEN, f)) {
                nu = get_new_line();
                len = strlen(buf);
                if (len > 0 && buf[len - 1] == '\n') {
                        buf[len - 1] = '\0';
                        len--;
                }
                if (len > 0 && buf[len - 1] == '\r') {
                        buf[len - 1] = '\0';
                        len--;
                }
                if (!*buf)
                        strcpyn(buf, sizeof(buf), " ");
                nu->this_line = alloc_string(buf);
                if (!first) {
                        prev = nu;
                        first = nu;
                } else {
                        prev->next = nu;
                        nu->prev = prev;
                        prev = nu;
                }
        }

        fclose(f);
        return first;
}
Пример #4
0
static gssize
xedit_document_input_stream_read (GInputStream  *stream,
				  void          *buffer,
				  gsize          count,
				  GCancellable  *cancellable,
				  GError       **error)
{
	XeditDocumentInputStream *dstream;
	GtkTextIter iter;
	gssize space_left, read, n;

	dstream = XEDIT_DOCUMENT_INPUT_STREAM (stream);

	if (count < 6)
	{
		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE,
				     "Not enougth space in destination");
		return -1;
	}

	if (g_cancellable_set_error_if_cancelled (cancellable, error))
		return -1;

	/* Initialize the mark to the first char in the text buffer */
	if (!dstream->priv->is_initialized)
	{
		gtk_text_buffer_get_start_iter (dstream->priv->buffer, &iter);
		dstream->priv->pos = gtk_text_buffer_create_mark (dstream->priv->buffer,
								 NULL,
								 &iter,
								 FALSE);

		dstream->priv->is_initialized = TRUE;
	}

	space_left = count;
	read = 0;

	do
	{
		n = read_line (dstream, buffer + read, space_left);
		read += n;
		space_left -= n;
	} while (space_left > 0 && n != 0 && dstream->priv->bytes_partial == 0);

	/* Make sure that non-empty files are always terminated with \n (see bug #95676).
	 * Note that we strip the trailing \n when loading the file */
	gtk_text_buffer_get_iter_at_mark (dstream->priv->buffer,
					  &iter,
					  dstream->priv->pos);

	if (gtk_text_iter_is_end (&iter) &&
	    !gtk_text_iter_is_start (&iter))
	{
		gssize newline_size;

		newline_size = get_new_line_size (dstream);

		if (space_left >= newline_size &&
		    !dstream->priv->newline_added)
		{
			const gchar *newline;

			newline = get_new_line (dstream);

			memcpy (buffer + read, newline, newline_size);

			read += newline_size;
			dstream->priv->newline_added = TRUE;
		}
	}

	return read;
}
Пример #5
0
static gsize
read_line (XeditDocumentInputStream *stream,
	   gchar                    *outbuf,
	   gsize                     space_left)
{
	GtkTextIter start, next, end;
	gchar *buf;
	gint bytes; /* int since it's what iter_get_offset returns */
	gsize bytes_to_write, newline_size, read;
	const gchar *newline;
	gboolean is_last;

	gtk_text_buffer_get_iter_at_mark (stream->priv->buffer,
					  &start,
					  stream->priv->pos);

	if (gtk_text_iter_is_end (&start))
		return 0;

	end = next = start;
	newline = get_new_line (stream);

	/* Check needed for empty lines */
	if (!gtk_text_iter_ends_line (&end))
		gtk_text_iter_forward_to_line_end (&end);

	gtk_text_iter_forward_line (&next);

	buf = gtk_text_iter_get_slice (&start, &end);

	/* the bytes of a line includes also the newline, so with the
	   offsets we remove the newline and we add the new newline size */
	bytes = gtk_text_iter_get_bytes_in_line (&start) - stream->priv->bytes_partial;

	/* bytes_in_line includes the newlines, so we remove that assuming that
	   they are single byte characters */
	bytes = bytes - (gtk_text_iter_get_offset (&next) - gtk_text_iter_get_offset (&end));
	is_last = gtk_text_iter_is_end (&end);

	/* bytes_to_write contains the amount of bytes we would like to write.
	   This means its the amount of bytes in the line (without the newline
	   in the buffer) + the amount of bytes for the newline we want to
	   write (newline_size) */
	bytes_to_write = bytes;

	/* do not add the new newline_size for the last line */
	newline_size = get_new_line_size (stream);
	if (!is_last)
		bytes_to_write += newline_size;

	if (bytes_to_write > space_left)
	{
		gchar *ptr;
		gint char_offset;
		gint written;
		gsize to_write;

		/* Here the line does not fit in the buffer, we thus write
		   the amount of bytes we can still fit, storing the position
		   for the next read with the mark. Do not try to write the
		   new newline in this case, it will be handled in the next
		   iteration */
		to_write = MIN (space_left, bytes);
		ptr = buf;
		written = 0;
		char_offset = 0;

		while (written < to_write)
		{
			gint w;

			ptr = g_utf8_next_char (ptr);
			w = (ptr - buf);
			if (w > to_write)
			{
				break;
			}
			else
			{
				written = w;
				++char_offset;
			}
		}

		memcpy (outbuf, buf, written);

		/* Note: offset is one past what we wrote */
		gtk_text_iter_forward_chars (&start, char_offset);
		stream->priv->bytes_partial += written;
		read = written;
	}
	else
	{
		/* First just copy the bytes without the newline */
		memcpy (outbuf, buf, bytes);

		/* Then add the newline, but not for the last line */
		if (!is_last)
		{
			memcpy (outbuf + bytes, newline, newline_size);
		}

		start = next;
		stream->priv->bytes_partial = 0;
		read = bytes_to_write;
	}

	gtk_text_buffer_move_mark (stream->priv->buffer,
				   stream->priv->pos,
				   &start);

	g_free (buf);
	return read;
}
Пример #6
0
/*---------------------------------------------------------- * 
* func name: check_upgrade_configfile() 
* function : 分析版本配置文件.检查是否需要更新. 
* calllist :            
*            
*
* calledlist:  
* input    :  
* output   :  
* parameter: line 
             sver
* 			 sfile
             model
* return   : NULL  失败
* 			 成功  版本信息的sw_version的地址
* 			 
* 	 
* 
* notice   : 使用前get_system_version_info()必需先调用成功.
*--------------------------------------------------------*/
static int check_config_version(char *line, char **sver, char **sfile, const char *model,const char* swversion)
{
	int i;
	char *sitems[] = {NULL, NULL, NULL, NULL,NULL}; /* model,softversion, version, file */

	i = 0;
	char *token = get_new_line(&line, ";");
	while(token)
	{
		sitems[i++] = token;
		if(i == 3)
			break;
		token = get_new_line(&line, ";");
	}

	if(i != 3)
	{
		//not enough field, return 0
		return 0;		
	}

	//split the STB model version
	//1=35001-01001
	char *s = sitems[0];
	token = get_new_line(&s, "=");
	if(token == 0)
	{
		//not follow the format 
		return 0;
	}
	//check with the ver in bootloader
	/*
	CHUNK_HEADER blk_header;
	unsigned long id = 0;
	sto_chunk_goto(&id, 0, 1);
	sto_get_chunk_header(id, &blk_header);
	*/
	
	//libc_printf("STB module = %s\n",s);
    //libc_printf("updata System softversion = %s\n",sitems[1]);
	//libc_printf("updataversion = %s, %d\n", sitems[2], calcheck_version(sitems[2]));
	//libc_printf("file = %s\n", sitems[3]);
    
	//libc_printf("System bootload version = %s\n", model);
	//libc_printf("System soft version = %s\n", swversion);
	if(STRCMP(s, (char *)model) != 0)
	{
		//not for the model
		return 0;
	}
    
	if(STRCMP(get_svn_version(sitems[1]),get_svn_version((char *)swversion)) <= 0)
	{
		//have no new version.
		return 0;
	}

    
	if(sver) 
		*sver =  sitems[1];
	if(sfile) 
		*sfile = sitems[2];
	
	return 1;
}