shithub: neatroff

ref: 9e1124cb460b1bdfc52c18b299fe0a7d56c5270a
dir: /reg.c/

View raw version
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include "xroff.h"

#define NREGS		(1 << 16)

int nreg[NREGS];
char *sreg[NREGS];

int num_get(int id)
{
	return nreg[id];
}

int num_set(int id, int n)
{
	int o = nreg[id];
	nreg[id] = n;
	return o;
}

void tr_nr(int argc, char **args)
{
	int id;
	if (argc < 3)
		return;
	id = REG(args[1][0], args[1][1]);
	nreg[id] = tr_int(args[2], nreg[id], 'u');
}

void str_set(int id, char *s)
{
	int len = strlen(s) + 1;
	if (sreg[id])
		free(sreg[id]);
	sreg[id] = malloc(len);
	strcpy(sreg[id], s);
}

char *str_get(int id)
{
	return sreg[id];
}