Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /***********************************************************************
  2.  *
  3.  *  avra - Assembler for the Atmel AVR microcontroller series
  4.  *
  5.  *  Copyright (C) 1998-2003 Jon Anders Haugum, Tobias Weber
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; see the file COPYING.  If not, write to
  19.  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20.  *  Boston, MA 02111-1307, USA.
  21.  *
  22.  *
  23.  *  Authors of avra can be reached at:
  24.  *     email: jonah@omegav.ntnu.no, tobiw@suprafluid.com
  25.  *     www: http://sourceforge.net/projects/avra
  26.  */
  27.  
  28. /********************************************************************
  29.  * Extra standard functions
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <ctype.h>
  34.  
  35. #include "misc.h"
  36.  
  37.  
  38. /********************************************************************
  39.  * Case insensetive strcmp()
  40.  */
  41.  
  42. int nocase_strcmp(char *s, char *t)
  43. {
  44.         int i;
  45.  
  46.         for(i = 0; tolower(s[i]) == tolower(t[i]); i++)
  47.                 if(s[i] == '\0')
  48.                         return(0);
  49.         return(tolower(s[i]) - tolower(t[i]));
  50. }
  51.  
  52.  
  53. /********************************************************************
  54.  * Case insensetive strncmp()
  55.  */
  56.  
  57. int nocase_strncmp(char *s, char *t, int n)
  58. {
  59.         int i;
  60.  
  61.         for(i = 0; (tolower(s[i]) == tolower(t[i])); i++, n--)
  62.                 if((s[i] == '\0') || (n == 1))
  63.                         return(0);
  64.         return(tolower(s[i]) - tolower(t[i]));
  65. }
  66.  
  67.  
  68. /********************************************************************
  69.  * Case insensetive strstr()
  70.  */
  71.  
  72. char *nocase_strstr(char *s, char *t)
  73. {
  74.         int i = 0, j, found = False;
  75.  
  76.         while((s[i] != '\0') && !found) {
  77.                 j = 0;
  78.                 while(tolower(t[j]) == tolower(s[i + j])) {
  79.                         j++;
  80.                         if(t[j] == '\0') {
  81.                                 found = True;
  82.                                 break;
  83.                                 }
  84.                         else if(s[i + j] == '\0')
  85.                                 break;
  86.                         }
  87.                 i++;
  88.                 }
  89.         i--;
  90.         if(found)
  91.                 return(&s[i]);
  92.         return(NULL);
  93. }
  94.  
  95.  
  96. /********************************************************************
  97.  * ascii to hex
  98.  * ignores "0x"
  99.  */
  100.  
  101. int atox(char *s)
  102. {
  103.         int i = 0, ret = 0;
  104.  
  105.         while(s[i] != '\0') {
  106.                 ret <<= 4;
  107.                 if((s[i] <= 'F') && (s[i] >= 'A'))
  108.                         ret |= s[i] - 'A' + 10;
  109.                 else if((s[i] <= 'f') && (s[i] >= 'a'))
  110.                         ret |= s[i] - 'a' + 10;
  111.                 else if((s[i] <= '9') && (s[i] >= '0'))
  112.                         ret |= s[i] - '0';
  113.                 i++;
  114.         }
  115.         return(ret);
  116. }
  117.  
  118.  
  119. /********************************************************************
  120.  * n ascii chars to int
  121.  */
  122.  
  123. int atoi_n(char *s, int n)
  124. {
  125.         int i = 0, ret = 0;
  126.  
  127.         while((s[i] != '\0') && n) {
  128.                 ret = 10 * ret + (s[i] - '0');
  129.                 i++;
  130.                 n--;
  131.         }
  132.         return(ret);
  133. }
  134.  
  135.  
  136. /********************************************************************
  137.  * n ascii chars to hex
  138.  * 0 < n <= 8
  139.  * ignores "0x"
  140.  */
  141.  
  142. int atox_n(char *s, int n)
  143. {
  144.         int i = 0, ret = 0;
  145.  
  146.         while((s[i] != '\0') && n) {
  147.                 ret <<= 4;
  148.                 if((s[i] <= 'F') && (s[i] >= 'A'))
  149.                         ret |= s[i] - 'A' + 10;
  150.                 else if((s[i] <= 'f') && (s[i] >= 'a'))
  151.                         ret |= s[i] - 'a' + 10;
  152.                 else if((s[i] <= '9') && (s[i] >= '0'))
  153.                         ret |= s[i] - '0';
  154.                 i++;
  155.                 n--;
  156.         }
  157.         return(ret);
  158. }
  159.  
  160.  
  161. /*
  162.  * My own strlwr function since this one only exists in win
  163.  */
  164.  
  165. char *my_strlwr(char *in)
  166. {
  167.   int i;
  168.  
  169.   for(i = 0; in[i] != '\0'; i++)
  170.     in[i] = tolower(in[i]);
  171.  
  172.   return(in);
  173. }
  174.  
  175.  
  176. /*
  177.  * My own strupr function since this one only exists in win
  178.  */
  179.  
  180. char *my_strupr(char *in)
  181. {
  182.   int i;
  183.  
  184.   for(i = 0; in[i] != '\0'; i++)
  185.     in[i] = toupper(in[i]);
  186.  
  187.   return(in);
  188. }
  189.  
  190. /* stdextra.c */
  191.  
  192.