88 lines
1.5 KiB
C
88 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "spinix.h"
|
|
#include "varsubs.h"
|
|
|
|
static char retvalstr[16];
|
|
|
|
void sprintdec(char *str, int val)
|
|
{
|
|
int scale;
|
|
int zeroflag = 0;
|
|
|
|
if (val < 0)
|
|
{
|
|
*str++ = '-';
|
|
val = -val;
|
|
}
|
|
|
|
for (scale = 1000000000; scale > 1; scale /= 10)
|
|
{
|
|
if (val >= scale)
|
|
{
|
|
*str++ = '0' + val/scale;
|
|
val %= scale;
|
|
zeroflag = 1;
|
|
}
|
|
else if (zeroflag)
|
|
*str++ = '0';
|
|
}
|
|
|
|
*str++ = '0' + val;
|
|
*str = 0;
|
|
}
|
|
|
|
char *varsubs_FindVar(char *str)
|
|
{
|
|
char *ptr = (char *)spinix_environ_vars;
|
|
while (*ptr)
|
|
{
|
|
if (!strcmp(str, ptr + 1))
|
|
{
|
|
if (*ptr != varsubs_ALIAS_FLAG)
|
|
{
|
|
return ptr;
|
|
}
|
|
}
|
|
ptr += strlen(ptr) + 1;
|
|
ptr += strlen(ptr) + 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
char *varsubs_GetVarVal(char *name)
|
|
{
|
|
char *ptr;
|
|
if (!strcmp(name, "?"))
|
|
{
|
|
sprintdec(retvalstr, *(int *)spinix_return_value);
|
|
return retvalstr;
|
|
}
|
|
if ((ptr = varsubs_FindVar(name)))
|
|
{
|
|
return ptr + strlen(ptr) + 1;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
void enter(void)
|
|
{
|
|
char *mode;
|
|
char *ptr = varsubs_GetVarVal("PWD");
|
|
if (ptr) chdir(ptr);
|
|
ptr = varsubs_GetVarVal("<");
|
|
if (*ptr)
|
|
printf("stdin = %s\n", ptr);
|
|
ptr = varsubs_GetVarVal(">");
|
|
if (*ptr)
|
|
mode = ">";
|
|
else
|
|
{
|
|
ptr = varsubs_GetVarVal(">>");
|
|
if (*ptr)
|
|
mode = ">>";
|
|
}
|
|
printf("stdout = %s %s\n", mode, ptr);
|
|
}
|
|
|