Fix: fixing push/pull for commit "Initital beggining of a CLI"
This commit is contained in:
@@ -3,13 +3,23 @@
|
||||
|
||||
#include "types.h"
|
||||
#include <stdarg.h>
|
||||
#include <strings.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define VGA_WIDTH 80
|
||||
#define VGA_HEIGHT 25
|
||||
|
||||
#define VGA_MEMORY_ADDRESS 0xB8000
|
||||
|
||||
/*
|
||||
* FOR INPUT
|
||||
*/
|
||||
|
||||
#define KEYBOARD_BUFFER_SIZE 256
|
||||
|
||||
static char _keyboard_buffer[KEYBOARD_BUFFER_SIZE];
|
||||
static uint16_t _kb_head = 0;
|
||||
static uint16_t _kb_tail = 0;
|
||||
|
||||
/* IN VGA - Video Memory Arrya:
|
||||
* short
|
||||
* 1s byte (left most) -> TEXT COLOR
|
||||
@@ -343,7 +353,109 @@ void scursor(unsigned int column, unsigned int line) {
|
||||
__VGA_set_cursor_internal(column, line);
|
||||
}
|
||||
|
||||
static inline void __keyboard_buffer_push(char __c) {
|
||||
_keyboard_buffer[_kb_head] = __c;
|
||||
_kb_head = (_kb_head + 1) % KEYBOARD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
static inline char __keyboard_buffer_pop() {
|
||||
if (_kb_tail == _kb_head) {
|
||||
return '\0';
|
||||
}
|
||||
|
||||
char __c = _keyboard_buffer[_kb_tail];
|
||||
_kb_tail = (_kb_tail + 1) % KEYBOARD_BUFFER_SIZE;
|
||||
return __c;
|
||||
}
|
||||
|
||||
static inline char __gets_internal(char *buffer, size_t max_length) {
|
||||
size_t index = 0;
|
||||
char __c;
|
||||
|
||||
while (index < max_length - 1) {
|
||||
__c = __keyboard_buffer_pop();
|
||||
if (__c == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (__c == '\n' || __c == '\r') {
|
||||
buffer[index] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
buffer[index++] = __c;
|
||||
}
|
||||
|
||||
buffer[index] = '\0';
|
||||
return index;
|
||||
}
|
||||
|
||||
void gets(char *buffer, size_t max_length) {
|
||||
__gets_internal(buffer, max_length);
|
||||
}
|
||||
|
||||
static inline int __scanf_internal(const char *fmt, va_list args) {
|
||||
|
||||
char buffer[256];
|
||||
__gets_internal(buffer, sizeof(buffer));
|
||||
|
||||
const char* p = fmt;
|
||||
char* in = buffer;
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (*p) {
|
||||
if (*p == '%') {
|
||||
p++;
|
||||
|
||||
if (*p == 'd') {
|
||||
int* out = va_arg(args, int*);
|
||||
int sign = 1;
|
||||
int value = 0;
|
||||
|
||||
if (*in == '-') { sign = -1; in++; }
|
||||
|
||||
while (*in >= '0' && *in <= '9') {
|
||||
value = value * 10 + (*in - '0');
|
||||
in++;
|
||||
}
|
||||
|
||||
*out = value * sign;
|
||||
count++;
|
||||
}
|
||||
|
||||
else if (*p == 's') {
|
||||
char* out = va_arg(args, char*);
|
||||
while (*in == ' ') in++; // skip spaces
|
||||
while (*in && *in != ' ') {
|
||||
*out++ = *in++;
|
||||
}
|
||||
*out = '\0';
|
||||
count++;
|
||||
}
|
||||
|
||||
else if (*p == 'c') {
|
||||
char* out = va_arg(args, char*);
|
||||
*out = *in++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int scanf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int result = __scanf_internal(fmt, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user