Refactor atoi
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
c4714fe772
commit
730145a7c8
|
@ -12,7 +12,7 @@ void backspace();
|
||||||
char getChar();
|
char getChar();
|
||||||
void putChar(char c);
|
void putChar(char c);
|
||||||
int abs();
|
int abs();
|
||||||
int atoi(char * buffer, int len);
|
int atoi(char * buffer);
|
||||||
int strlen(const char * s);
|
int strlen(const char * s);
|
||||||
void scanf(char * buffer, int maxLen);
|
void scanf(char * buffer, int maxLen);
|
||||||
int strcmp(const char * s1, const char * s2);
|
int strcmp(const char * s1, const char * s2);
|
||||||
|
|
|
@ -153,7 +153,7 @@ char *itoa(int value, char *buffer, int base) {
|
||||||
return reverse(buffer, 0, i - 1);
|
return reverse(buffer, 0, i - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int atoi(char *str, int length) {
|
int atoi(char *str) {
|
||||||
int i = 0, sign = 1, val = 0;
|
int i = 0, sign = 1, val = 0;
|
||||||
while (str[i] != '\0') {
|
while (str[i] != '\0') {
|
||||||
if (str[i] == '-') {
|
if (str[i] == '-') {
|
||||||
|
|
|
@ -8,7 +8,7 @@ void block(int argc, char ** argv) {
|
||||||
// sys_exit();
|
// sys_exit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pid = atoi(argv[1], MAX_LEN);
|
int pid = atoi(argv[1]);
|
||||||
|
|
||||||
sys_block(pid);
|
sys_block(pid);
|
||||||
// sys_exit();
|
// sys_exit();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ void help(int argc, char *argv[]) {
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int page = atoi(argv[1], 10);
|
int page = atoi(argv[1]);
|
||||||
int pages = getCurrentPages();
|
int pages = getCurrentPages();
|
||||||
|
|
||||||
if (page < 1 || page > pages) {
|
if (page < 1 || page > pages) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ void kill(int argc, char ** argv) {
|
||||||
// sys_exit();
|
// sys_exit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pid = atoi(argv[1], MAX_LEN);
|
int pid = atoi(argv[1]);
|
||||||
|
|
||||||
sys_kill(pid);
|
sys_kill(pid);
|
||||||
// sys_exit();
|
// sys_exit();
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#define PUAN -1
|
|
||||||
|
|
||||||
void loop(int argc, char *argv[]) {
|
void loop(int argc, char *argv[]) {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
printStringLen("loop receives an amount of seconds and a text\n", 47);
|
printStringLen("loop receives an amount of seconds and a text\n", 47);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
int pid = sys_getPid(), secs = atoi(argv[1], PUAN);
|
int pid = sys_getPid(), secs = atoi(argv[1]);
|
||||||
char * str = argv[2];
|
char * str = argv[2];
|
||||||
char * buffer = sys_malloc(MAX_PID_LEN);
|
char * buffer = sys_malloc(MAX_PID_LEN);
|
||||||
buffer = strcat(strcat(itoa(pid, buffer, 10), " "), str);
|
buffer = strcat(strcat(itoa(pid, buffer, 10), " "), str);
|
||||||
|
|
|
@ -7,8 +7,8 @@ void nice(int argc, char ** argv) {
|
||||||
printStringLen("nice receives a pid and an offset\n", 35);
|
printStringLen("nice receives a pid and an offset\n", 35);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
int pid = atoi(argv[1], MAX_LEN);
|
int pid = atoi(argv[1]);
|
||||||
char offset = (char) atoi(argv[2], MAX_LEN);
|
char offset = (char) atoi(argv[2]);
|
||||||
|
|
||||||
sys_nice(pid, offset);
|
sys_nice(pid, offset);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
|
|
|
@ -33,6 +33,7 @@ void addPhilo() {
|
||||||
new->buffer = sys_malloc(sizeof(char) * BUFF_SIZE);
|
new->buffer = sys_malloc(sizeof(char) * BUFF_SIZE);
|
||||||
new->state = THINKING;
|
new->state = THINKING;
|
||||||
char * aux = sys_malloc(sizeof(char) * 20);
|
char * aux = sys_malloc(sizeof(char) * 20);
|
||||||
|
aux[0] = '\0';
|
||||||
aux = strcat(aux, "filosofo");
|
aux = strcat(aux, "filosofo");
|
||||||
char buffer[2] = {0};
|
char buffer[2] = {0};
|
||||||
aux = strcat(aux, itoa(philoCount, buffer, 10));
|
aux = strcat(aux, itoa(philoCount, buffer, 10));
|
||||||
|
@ -93,7 +94,7 @@ void philosopher(int argc, char ** argv) {
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
philosopher_t * i = (philosopher_t *) ((uint64_t) atoi(argv[1], -1));
|
philosopher_t * i = (philosopher_t *) ((uint64_t) atoi(argv[1]));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sys_sleep(1);
|
sys_sleep(1);
|
||||||
|
@ -113,7 +114,7 @@ void phylo(int argc, char ** argv) {
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
philoCount = STARTING;
|
philoCount = STARTING;
|
||||||
else if (argc == 2) {
|
else if (argc == 2) {
|
||||||
philoCount = atoi(argv[1], -1);
|
philoCount = atoi(argv[1]);
|
||||||
if (philoCount < 1 || philoCount > MAX_PHILO_SIZE) {
|
if (philoCount < 1 || philoCount > MAX_PHILO_SIZE) {
|
||||||
printStringLen("amount of philosofers must be between 1 and 10\n", 48);
|
printStringLen("amount of philosofers must be between 1 and 10\n", 48);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
|
@ -130,6 +131,7 @@ void phylo(int argc, char ** argv) {
|
||||||
phil->buffer = sys_malloc(20);
|
phil->buffer = sys_malloc(20);
|
||||||
phil->state = THINKING;
|
phil->state = THINKING;
|
||||||
char * aux = sys_malloc(sizeof(char) * 20);
|
char * aux = sys_malloc(sizeof(char) * 20);
|
||||||
|
aux[0] = '\0';
|
||||||
aux = strcat(aux, "filosofo");
|
aux = strcat(aux, "filosofo");
|
||||||
char buffer[2] = {0};
|
char buffer[2] = {0};
|
||||||
aux = strcat(aux, itoa(i, buffer, 10));
|
aux = strcat(aux, itoa(i, buffer, 10));
|
||||||
|
@ -173,9 +175,6 @@ void phylo(int argc, char ** argv) {
|
||||||
else if (c == 'q') {
|
else if (c == 'q') {
|
||||||
end();
|
end();
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// end();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ void printmem(int argc, char *argv[]) {
|
||||||
|
|
||||||
int buffer[8];
|
int buffer[8];
|
||||||
|
|
||||||
getMem(buffer, atoi(argv[1], strlen(argv[1])));
|
getMem(buffer, atoi(argv[1]));
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
char bufferAux[8];
|
char bufferAux[8];
|
||||||
|
|
|
@ -22,9 +22,9 @@ void inc(int argc, char ** argv) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t semDir = (uint64_t) atoi(argv[1], 14);
|
uint64_t semDir = (uint64_t) atoi(argv[1]);
|
||||||
int64_t value = atoi(argv[2], 10);
|
int64_t value = atoi(argv[2]);
|
||||||
uint64_t N = atoi(argv[3], 10);
|
uint64_t N = atoi(argv[3]);
|
||||||
uint64_t i;
|
uint64_t i;
|
||||||
|
|
||||||
for (i = 0; i < N; i++){
|
for (i = 0; i < N; i++){
|
||||||
|
|
|
@ -7,7 +7,7 @@ void unblock(int argc, char ** argv) {
|
||||||
printStringLen("unblock receives a pid\n", 21);
|
printStringLen("unblock receives a pid\n", 21);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
int pid = atoi(argv[1], MAX_LEN);
|
int pid = atoi(argv[1]);
|
||||||
|
|
||||||
sys_unblock(pid);
|
sys_unblock(pid);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
|
|
Loading…
Reference in New Issue