Import backup from 2004-12-30
This commit is contained in:
1 parent
6bad3f2b96
commit
76a243d894
18 files changed
+408
-158
No files matched your search
@@ -1,6 +1,7 @@
|
||||
// conv.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 12/30/04
|
||||
|
||||
#include "conv.h"
|
||||
#include "hos_defines.h"
|
||||
@@ -34,6 +35,21 @@ int itox(u32_t num, char *buf)
|
||||
}
|
||||
|
||||
|
||||
// convert integer to an octal string
|
||||
int itoo(u32_t num, char *buf)
|
||||
{
|
||||
int s, i = 0;
|
||||
for (s = 30; s >= 0; s -= 3)
|
||||
{
|
||||
u32_t val = (num >> s) & 0x7;
|
||||
if (i || val || (!s))
|
||||
buf[i++] = val + '0';
|
||||
}
|
||||
buf[i] = 0;
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
|
||||
// convert signed integer to decimal string
|
||||
int itoa(int num, char *buf)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// conv.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 12/30/04
|
||||
|
||||
#ifndef __HOS_CONV__
|
||||
#define __HOS_CONV__ __HOS_CONV__
|
||||
@@ -9,6 +10,7 @@
|
||||
|
||||
int bcdtoa(u32_t bcd, char *buf);
|
||||
int itox(u32_t num, char *buf);
|
||||
int itoo(u32_t num, char *buf);
|
||||
int itoa(int num, char *buf);
|
||||
int utoa(u32_t num, char *buf);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; asmfuncs.asm
|
||||
; lang.asm
|
||||
; Josh Holtrop
|
||||
; Created: 10/23/03
|
||||
; Modified: 07/11/04
|
||||
; Modified: 12/30/04
|
||||
|
||||
|
||||
%macro jzfar 1
|
||||
@@ -58,38 +58,6 @@ _read_cr3:
|
||||
ret
|
||||
|
||||
|
||||
;compares one string to another
|
||||
;returns 0 if the strings are different
|
||||
;extern dword strcmp(char *str1, char *str2);
|
||||
[global _strcmp]
|
||||
_strcmp:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
|
||||
mov esi, [ebp+8]
|
||||
mov edi, [ebp+12]
|
||||
strcmp_loop1:
|
||||
lodsb
|
||||
mov ah, [edi]
|
||||
inc edi
|
||||
cmp ah, al
|
||||
jnz strcmp_ne
|
||||
or al, al
|
||||
jz strcmp_e
|
||||
jmp strcmp_loop1
|
||||
strcmp_e:
|
||||
mov eax, 1
|
||||
jmp short strcmp_done
|
||||
strcmp_ne:
|
||||
xor eax, eax
|
||||
strcmp_done:
|
||||
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
;copies a string from the source to the destination parameter
|
||||
;extern void strcpy(char *dest, char *src);
|
||||
@@ -0,0 +1,93 @@
|
||||
// lang.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 12/30/04
|
||||
// Modified: 12/30/04
|
||||
|
||||
#include "lang.h"
|
||||
|
||||
|
||||
/* strcmp compares two strings
|
||||
* Returns:
|
||||
* 0 if the strings are equal
|
||||
* <0 if the second string is less than the first
|
||||
* >0 if the second string is greater than the first
|
||||
*/
|
||||
int strcmp(char *str1, char *str2)
|
||||
{
|
||||
while (*str1 || *str2)
|
||||
{
|
||||
if (*str1 != *str2)
|
||||
return *str2 - *str1;
|
||||
str1++;
|
||||
str2++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* strncmp compares up to n characters of two strings
|
||||
* Returns:
|
||||
* 0 if the strings are equal
|
||||
* <0 if the second string is less than the first
|
||||
* >0 if the second string is greater than the first
|
||||
*/
|
||||
int strncmp(char *str1, char *str2, int n)
|
||||
{
|
||||
while (n > 0 && (*str1 || *str2))
|
||||
{
|
||||
if (*str1 != *str2)
|
||||
return *str2 - *str1;
|
||||
str1++;
|
||||
str2++;
|
||||
n--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// counts the occurrences of lookfor in str
|
||||
int str_count(char *str, char lookfor)
|
||||
{
|
||||
int count = 0;
|
||||
while (*str)
|
||||
{
|
||||
if (*str == lookfor)
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// split the string into substrings by the splitchar, return number of substrings
|
||||
int str_split(char *str, char splitchar)
|
||||
{
|
||||
int subs = 1;
|
||||
while (*str)
|
||||
{
|
||||
if (*str == splitchar)
|
||||
{
|
||||
*str = 0;
|
||||
subs++;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return subs;
|
||||
}
|
||||
|
||||
// advance the string pointer to the next substring, return a pointer to the next substring
|
||||
char *str_advance(char *str)
|
||||
{
|
||||
char *next = str;
|
||||
while (*next)
|
||||
next++; // advance pointer to end of this substring (null character)
|
||||
return next + 1;
|
||||
}
|
||||
|
||||
|
||||
// concatentate src onto the end of dest
|
||||
void strcat(char *dest, char *src)
|
||||
{
|
||||
while (*dest)
|
||||
dest++;
|
||||
strcpy(dest, src);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// asmfuncs.h
|
||||
// lang.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Modified: 07/11/04
|
||||
// Modified: 12/30/04
|
||||
|
||||
#ifndef __HOS_ASMFUNCS__
|
||||
#define __HOS_ASMFUNCS__ __HOS_ASMFUNCS__
|
||||
#ifndef __HOS_LANG__
|
||||
#define __HOS_LANG__ __HOS_LANG__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
/* lang.asm */
|
||||
u32_t write_cr0(u32_t cr0);
|
||||
u32_t read_cr0();
|
||||
u32_t write_cr3(u32_t cr3);
|
||||
@@ -23,6 +26,14 @@ void *memsetd(void *buffer, int c, int num);
|
||||
u32_t strlen(const char *str);
|
||||
void invlpg_(u32_t addr);
|
||||
|
||||
/* lang.c */
|
||||
int strcmp(char *str1, char *str2);
|
||||
int strncmp(char *str1, char *str2, int n);
|
||||
int str_count(char *str, char lookfor);
|
||||
int str_split(char *str, char splitchar);
|
||||
char *str_advance(char *str);
|
||||
void strcat(char *dest, char *src);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user