File: hist_get.c

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (37 lines) | stat: -rw-r--r-- 911 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* $Id: hist_get.c,v 1.1 2001/04/12 00:33:53 skaus Exp $

	Set a specific item of the history

	Useage: histGet(num, buflen, string)

	num == 0 -> add a "newest" entry to the history
	num <  0 -> change the num'th newest entry of the history
	num >  0 -> change the num'th oldest entry of the history
		positive num's correspond to item ID (not relative to nummin!)
		negative ones are added to nummax
*/

#include "../config.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "../include/context.h"
#include "../include/misc.h"

int histGet(const int num, char * const str, const unsigned len)
{	char *p;

	assert(str);
	assert(len);

	if(ctxtGet(0, CTXT_TAG_HISTORY, realNum(CTXT_TAG_HISTORY, num), &p) == 0) {
		assert(p);
		strncpy(str, p, len);
		str[len - 1] = 0;		/* Make sure the string is terminated */
		free(p);
		return 1;
	}
	return 0;
}