/svarcom/cmd/set.c |
---|
0,0 → 1,20 |
/* |
* |
*/ |
static int cmd_set(int argc, char const **argv, unsigned short env_seg) { |
char far *env = MK_FP(env_seg, 0); |
char buff[256]; |
int i; |
while (*env != 0) { |
/* copy string to local buff for display */ |
for (i = 0;; i++) { |
buff[i] = *env; |
env++; |
if (buff[i] == 0) break; |
} |
puts(buff); |
} |
return(0); |
} |
/svarcom/cmd.c |
---|
0,0 → 1,19 |
/* entry point for internal commands |
* matches internal commands and executes them |
* returns exit code or -1 if not processed */ |
#include <i86.h> |
#include <stdio.h> |
#include "helpers.h" |
#include "cmd/set.c" |
#include "cmd.h" |
int cmd_process(int argc, const char **argv, unsigned short env_seg) { |
if (imatch(argv[0], "set")) return(cmd_set(argc, argv, env_seg)); |
return(-1); |
} |
/svarcom/cmd.h |
---|
0,0 → 1,6 |
#ifndef CMD_H |
#define CMD_H |
int cmd_process(int argc, const char **argv, unsigned short env_seg); |
#endif |
/svarcom/command.c |
---|
53,6 → 53,8 |
#include <process.h> |
#include "cmd.h" |
#include "helpers.h" |
#include "rmodinit.h" |
struct config { |
62,17 → 64,6 |
} cfg; |
/* returns zero if s1 starts with s2 */ |
static int strstartswith(const char *s1, const char *s2) { |
while (*s2 != 0) { |
if (*s1 != *s2) return(-1); |
s1++; |
s2++; |
} |
return(0); |
} |
static void parse_argv(struct config *cfg, int argc, char **argv) { |
int i; |
memset(cfg, 0, sizeof(*cfg)); |
114,20 → 105,6 |
} |
static void cmd_set(int argc, char const **argv, unsigned short env_seg) { |
char far *env = MK_FP(env_seg, 0); |
char buff[256]; |
int i; |
while (*env != 0) { |
/* copy string to local buff for display */ |
for (i = 0;; i++) { |
buff[i] = *env; |
env++; |
if (buff[i] == 0) break; |
} |
puts(buff); |
} |
} |
int main(int argc, char **argv) { |
134,6 → 111,7 |
struct config cfg; |
unsigned short rmod_seg; |
unsigned short far *rmod_envseg; |
int ecode = 0; |
parse_argv(&cfg, argc, argv); |
220,13 → 198,14 |
printf("arg #%d = '%s'\r\n", i, argvlist[i]); |
} |
/* TODO is it an internal command? */ |
if (strcmp(argvlist[0], "set") == 0) { |
cmd_set(argcount, argvlist, *rmod_envseg); |
continue; |
} |
if (strcmp(argvlist[0], "exit") == 0) break; |
/* is it about quitting? */ |
if (imatch(argvlist[0], "exit")) break; |
/* try running it as an internal command */ |
ecode = cmd_process(argcount, argvlist, *rmod_envseg); |
if (ecode >= 0) continue; |
/* must be an external command then */ |
execvp(argvlist[0], argvlist); |
/* execvp() replaces the current process by the new one |
/svarcom/helpers.c |
---|
0,0 → 1,33 |
/* |
* a variety of helper functions |
* Copyright (C) 2021 Mateusz Viste |
*/ |
#include "helpers.h" |
/* case-insensitive comparison of strings, returns non-zero on equality */ |
int imatch(const char *s1, const char *s2) { |
for (;;) { |
char c1, c2; |
c1 = *s1; |
c2 = *s2; |
if ((c1 >= 'a') && (c1 <= 'z')) c1 -= ('a' - 'A'); |
if ((c2 >= 'a') && (c2 <= 'z')) c2 -= ('a' - 'A'); |
/* */ |
if (c1 != c2) return(0); |
if (c1 == 0) return(1); |
s1++; |
s2++; |
} |
} |
/* returns zero if s1 starts with s2 */ |
int strstartswith(const char *s1, const char *s2) { |
while (*s2 != 0) { |
if (*s1 != *s2) return(-1); |
s1++; |
s2++; |
} |
return(0); |
} |
/svarcom/helpers.h |
---|
0,0 → 1,10 |
#ifndef HELPERS_H |
#define HELPERS_H |
/* case-insensitive comparison of strings, returns non-zero on equality */ |
int imatch(const char *s1, const char *s2); |
/* returns zero if s1 starts with s2 */ |
int strstartswith(const char *s1, const char *s2); |
#endif |
/svarcom/makefile |
---|
20,8 → 20,8 |
all: command.com |
command.com: rmod.h command.c rmodinit.c |
wcl $(CFLAGS) command.c rmodinit.c |
command.com: rmod.h command.c cmd.c rmodinit.c helpers.c |
wcl $(CFLAGS) command.c cmd.c rmodinit.c helpers.c |
rmod.h: file2c.com rmod.com |
file2c rmod.com rmod.h rmod |