[update] os
This commit is contained in:
3
laos/src/dev/dev.c
Normal file
3
laos/src/dev/dev.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "dev.h"
|
||||
|
||||
char ioports[];
|
||||
@@ -2,27 +2,27 @@
|
||||
#include "memio.h"
|
||||
#include "memlayout.h"
|
||||
#include "spinlock.h"
|
||||
#include "dev.h"
|
||||
|
||||
void consputc(int c) {
|
||||
if (c == '\b') {
|
||||
memb(SERIAL_ADDR) = '\b';
|
||||
memb(SERIAL_ADDR) = ' ';
|
||||
memb(SERIAL_ADDR) = '\b';
|
||||
return;
|
||||
}
|
||||
volatile char *out = &ioports[SERIAL_OFFSET];
|
||||
if (c == '\b') {
|
||||
*out = '\b';
|
||||
*out = ' ';
|
||||
*out = '\b';
|
||||
return;
|
||||
}
|
||||
|
||||
memb(SERIAL_ADDR) = c;
|
||||
*out = c;
|
||||
}
|
||||
|
||||
struct {
|
||||
struct spinlock lock;
|
||||
|
||||
|
||||
// input
|
||||
#define INPUT_BUF_SIZE 128
|
||||
char buf[INPUT_BUF_SIZE];
|
||||
uint r; // Read index
|
||||
uint w; // Write index
|
||||
uint e; // Edit index
|
||||
uint r; // Read index
|
||||
uint w; // Write index
|
||||
uint e; // Edit index
|
||||
} cons;
|
||||
|
||||
|
||||
|
||||
@@ -29,11 +29,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
char *tok = strtok(input, " ");
|
||||
while (tok) {
|
||||
if (*tok != '\n') {
|
||||
args = realloc(args, (argc + 1) * sizeof(char *));
|
||||
args[argc] = tok;
|
||||
argc += 1;
|
||||
}
|
||||
args = realloc(args, (argc + 1) * sizeof(char *));
|
||||
args[argc] = tok;
|
||||
argc += 1;
|
||||
tok = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
|
||||
71
laos/src/util/filepath.c
Normal file
71
laos/src/util/filepath.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "defs.h"
|
||||
|
||||
//
|
||||
// bnm should be large enough to hold basename
|
||||
//
|
||||
char *basename(char *bnm, const char *path) {
|
||||
const char *p = path;
|
||||
const char *last_slash = NULL;
|
||||
while (*p) {
|
||||
if (*p == '/' || *p == '\\') {
|
||||
last_slash = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
char *q = bnm;
|
||||
p = last_slash + 1;
|
||||
while (*p) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
|
||||
return bnm;
|
||||
}
|
||||
|
||||
//
|
||||
// noext should be large enough to hold no-ext name
|
||||
//
|
||||
char *rmext(char *noext, const char *fname) {
|
||||
const char *p = fname;
|
||||
const char *last_dot = NULL;
|
||||
while (*p) {
|
||||
if (*p == '.') {
|
||||
last_dot = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
char *q = noext;
|
||||
p = fname;
|
||||
while (p != last_dot) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
|
||||
return noext;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// bnm should be large enough to hold bearname name
|
||||
//
|
||||
char *bearname(char *bnm, const char *fname) {
|
||||
const char *p = fname;
|
||||
const char *last_slash = NULL;
|
||||
const char *last_dot = NULL;
|
||||
while (*p) {
|
||||
if (*p == '/' || *p == '\\') {
|
||||
last_slash = p;
|
||||
} else if (*p == '.') {
|
||||
last_dot = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
char *q = bnm;
|
||||
p = last_slash + 1;
|
||||
while (p != last_dot) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
|
||||
return bnm;
|
||||
}
|
||||
Reference in New Issue
Block a user