Пример #1
0
int main(){
	history_remove();
	history_load();
	history_add(__T("abcd"));
	assert( _tcscmp(history_get(0),__T("abcd"))==0 );
	history_add(__T("qwerrr"));
	assert( _tcscmp(history_get(0),__T("qwerrr"))==0 );
	history_add(__T("zxcv"));
	assert( _tcscmp(history_get(0),__T("zxcv"))==0 );
	history_save();
	history_load();
	history_add(__T("zxcv1"));
	assert( _tcscmp(history_get(0),__T("zxcv1"))==0 );
	assert( _tcscmp(history_get(1),__T("zxcv"))==0 );
	assert( _tcscmp(history_get(2),__T("qwerrr"))==0 );
	assert( _tcscmp(history_get(3),__T("abcd"))==0 );
	history_delete(1);
	history_save();
	history_load();
	assert( _tcscmp(history_get(0),__T("zxcv1"))==0 );
	assert( _tcscmp(history_get(1),__T("zxcv"))!=0 );
	assert( _tcscmp(history_get(2),__T("qwerrr"))==0 );
	assert( _tcscmp(history_get(3),__T("abcd"))==0 );
	history_pin(2);
	check_ni_wi();
	history_add(__T("asdff"));
	history_add(__T("asdfff"));
	history_add(__T("asdffff"));
	assert( _tcscmp(history_get(0),__T("asdffff"))==0 );
	assert( _tcscmp(history_get(1),__T("asdfff"))==0 );
	assert( _tcscmp(history_get(2),__T("qwerrr"))==0 );
	assert( _tcscmp(history_get(3),__T("asdff"))==0 );
	history_pin(3);
	check_ni_wi();
	history_unpin(2);
	check_ni_wi();
	history_pin(11);
	history_pin(13);
	check_ni_wi();
	history_pin(5);
	history_pin(6);
	check_ni_wi();
	history_delete(4);
	history_delete(5);
	check_ni_wi();
	{
		TCHAR buffer[VIEW_HISTORY*MAX_PATH];
		int len = history_to_json(buffer);
		buffer[len+1] = __T('\0');
		_tprintf(__T("\n%d,%s\n"),len,buffer);
	}
	return 0;
}
Пример #2
0
static void history_add(t_tokenline *tl)
{
	int size, entry, part1;

	size = strlen(tl->buf) + 1;
	if (tl->hist_begin == tl->hist_end) {
		/* First entry, both are 0. */
		memcpy(tl->hist_buf, tl->buf, size);
	} else if (tl->hist_begin < tl->hist_end) {
		if (TL_MAX_HISTORY_SIZE - tl->hist_end >= size) {
			memcpy(tl->hist_buf + tl->hist_end, tl->buf, size);
		} else {
			part1 = TL_MAX_HISTORY_SIZE - tl->hist_end;
			entry = tl->hist_begin;
			tl->hist_begin = history_delete(tl, entry, size - part1);
			memcpy(tl->hist_buf + tl->hist_end, tl->buf, part1);
			memcpy(tl->hist_buf, tl->buf + part1, size - part1);
		}
	} else {
		part1 = tl->hist_begin - tl->hist_end;
		if (part1 <= size) {
			/* Not enough room between end and begin. */
			tl->hist_begin = history_delete(tl, tl->hist_begin, size - part1);
			part1 = TL_MAX_HISTORY_SIZE - tl->hist_end;
			if (part1 < size) {
				memcpy(tl->hist_buf + tl->hist_end, tl->buf, part1);
				memcpy(tl->hist_buf, tl->buf + part1, size - part1);
			} else {
				memcpy(tl->hist_buf + tl->hist_end, tl->buf, size);
			}
		} else {
			/* Enough room between end and begin. */
			memcpy(tl->hist_buf + tl->hist_end, tl->buf, size);
		}
	}
	tl->hist_end += size;
	if (tl->hist_end >= TL_MAX_HISTORY_SIZE)
		tl->hist_end -= TL_MAX_HISTORY_SIZE;
	if (tl->hist_begin == tl->hist_end)
		tl->hist_begin = history_delete(tl, tl->hist_begin,
				strlen(tl->hist_buf + tl->hist_begin));
}
Пример #3
0
Файл: cpu.c Проект: SiGe/argos
void cpu_snapshot_delete(cpu_snapshot *snap) {
    for (unsigned i = 0; i < MAX_CPU; ++i) {
        cpu_history_delete(snap->cpus[i]);
    }
    cpu_history_delete(snap->main);

    history_save(snap->ctxt);
    history_delete(snap->ctxt);

    free(snap);
}
Пример #4
0
Файл: cpu.c Проект: SiGe/argos
static void
cpu_history_delete(cpu_history *cpu) {
    history_save(cpu->cpu);
    history_save(cpu->sys);
    history_save(cpu->user);
    history_save(cpu->iowait);
    history_save(cpu->steal);
    history_save(cpu->idle);

    history_delete(cpu->cpu);
    history_delete(cpu->sys);
    history_delete(cpu->user);
    history_delete(cpu->iowait);
    history_delete(cpu->steal);
    history_delete(cpu->idle);
}