|
|||||||
|
|
|
|||||
|
|
|||||||
1) Crear el archivo filesys/myLib.h
// myLib.h
// ----------------------------------------------------------------------------
// int MyAtoi(char *str, int length); recibe un arreglo de caracteres str con su largo
// length y retorna un numero entero.
// ej : int num = MyAtoi("7893",4);
// -----------------------------------------------------------------------------
#ifndef MYLIB_H
#define MYLIB_H
int MyAtoi(char *str, int length)
{
static char num[10] = {'0', '1', '2', '3', '4', '5','6', '7', '8', '9'};
int vret = 0;
int i = 0;
int k = 0;
for(; i < length; i++)
for(k = 0; k < 10; k++)
if ( str[i] == num[k] )
{
vret = vret * 10 + k;
break;
}
return vret;
}
// aquí se insertan nuevas funciones
#endif
2) Modificar el archivo build.linux/Makefile , agregando a la lista siguiente, la ruta del archivo .h
FILESYS_H =../filesys/directory.h \
../filesys/filehdr.h\
../filesys/filesys.h \
../filesys/openfile.h\
../filesys/pbitmap.h\
../filesys/synchdisk.h\
../filesys/myLib.h
3) Compilar NACHOS con : buil.linux/make depend y posteriormente build.linux/make
4)Crear el programa test/pruebaMyLib.c, que llame a la función MyAtoi( ) y que después imprima el resultado usando la función prinInt de la biblioteca io_lib.h.
#include "io_lib.h"
#include "../filesys/myLib.h"
int main()
{
int num = 0;
print("\nPrueba de funcion MyAtoi del archivo /filesys/myLib.h");
num = MyAtoi("1004",4);
print("\nMyAtoi(\"1004\",4) : ");
printInt(num);
return 0;
}
5) Luego debemos modificar el archivo build.linux/Makefile de la siguiente manera :
PROGRAMS = halt shell holamundo llamada01 procTriangulo pruebaMyLib
pruebaMyLib.o: pruebaMyLib.c io_lib.h ../filesys/myLib.h
$(CC) $(CFLAGS) -c pruebaMyLib.c
pruebaMyLib: pruebaMyLib.o start.o io_lib.o
$(LD) $(LDFLAGS) start.o io_lib.o pruebaMyLib.o -o pruebaMyLib.coff
$(COFF2NOFF) pruebaMyLib.coff pruebaMyLib
6) Por el último compilamos con el comando test/make y posteriormente ejecutamos el programa
linux:~/usr/local/nachos/code/test # ./nachos -x pruebaMyLib
Prueba de funcion MyAtoi del archivo /filesys/myLib.h
MyAtoi("1004",4) : 1004
*nota : Para mayor información de cómo incluir archivos .h y .cc ver el archivo build.linux/MakeFile; además
es factible crear archivos en otros directorios también.