home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / game / think / chaos / src / nonamiga.c < prev    next >
C/C++ Source or Header  |  1994-03-23  |  6KB  |  241 lines

  1. /*  Chaos:            The Chess HAppening Organisation System    V5.3
  2.     Copyright (C)   1993    Jochen Wiedmann
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     $RCSfile: NonAmiga.c $
  20.     $Revision: 1.1 $
  21.     $Date: 1994/01/26 22:47:25 $
  22.  
  23.     This file contains some functions which are Amiga specific and which
  24.     I used in the system independent source, as I like them very much and
  25.     its rather easy to rebuild them on other systems.
  26.  
  27.     Some of this functions will be similar or even quite the same as other
  28.     functions on other systems. It depends on you, to use either yours or
  29.     mine.
  30.  
  31.     Computer:    Amiga 1200            Compiler:    Dice 2.07.54 (3.0)
  32.  
  33.     Author:    Jochen Wiedmann
  34.         Am Eisteich 9
  35.       72555 Metzingen
  36.         Tel. 07123 / 14881
  37.         Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
  38. */
  39.  
  40.  
  41. #ifndef NONAMIGA_H
  42. #include <NonAmiga.h>
  43. #endif
  44.  
  45.  
  46. #ifndef AMIGA
  47.  
  48.  
  49. /*
  50.     Stricmp is like strcmp, except that it ignores Upper-/Lowercase
  51.     and handles local letters (for example the german "Umlaute") too
  52.     on the Amiga. We ignore this here.
  53. */
  54. int Stricmp(const char *str1, const char *str2)
  55.  
  56. { char c1, c2;
  57.  
  58.   for(;;)
  59.   { c1 = tolower(*str1);
  60.     c2 = tolower(*str2);
  61.     if (c1 == '\0'  ||  c1 != c2)
  62.     { return(c1-c2);
  63.     }
  64.   }
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. /*
  72.     Strnicmp is like strnicmp, except that it ignores Upper-/Lowercase
  73.     and handles local letters (for example the german "Umlaute") too
  74.     on the Amiga. We ignore this here.
  75. */
  76. int Strnicmp(const char *str1, const char *str2, int len)
  77.  
  78. { char c1, c2;
  79.  
  80.   for(;;)
  81.   { if (len-- == 0)
  82.     { return(0);
  83.     }
  84.     c1 = tolower(*str1);
  85.     c2 = tolower(*str2);
  86.     if (c1 == '\0'  ||  c1 != c2)
  87.     { return(c1-c2);
  88.     }
  89.   }
  90. }
  91.  
  92.  
  93.  
  94.  
  95. /*
  96.     StrToLong is similar to atol, except that it ignores leading blanks and
  97.     tabs.
  98.  
  99.     Inputs: string  - the string holding the number to be converted.
  100.         value   - a pointer to an int receiving the value found.
  101.  
  102.     Result: The number of characters that were read (the leading blanks and
  103.         the value itself) or 0, if no decimal value was found.
  104. */
  105. int StrToLong(char *str, int *value)
  106.  
  107. { int len;
  108.   int val;
  109.  
  110.   len = 0;
  111.   while(*str == ' '  &&  *str == '\t')  /*  Ignore leading blanks   */
  112.   { ++str;
  113.     ++len;
  114.   }
  115.   if (*str < '0'  ||  *str > '9')
  116.   { *value = -1;
  117.     return(0);
  118.   }
  119.  
  120.   val = 0;
  121.   while (*str >= '0'  &&  *str <= '9')
  122.   { val = val*10 + *str - '0';
  123.     ++str;
  124.     ++len;
  125.   }
  126.   *value = val;
  127.   return(len);
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. /*
  136.     Here come the list functions. The elements of the list are called
  137.     nodes.
  138.  
  139.     Lists are always double linked lists and seem to have at least two
  140.     elements: The head and the tail. (See NewList for details.) The
  141.     elements of the (This is strange and I don't know, why the Amiga-OS
  142.     is implemented in that way. I suppose it is used to avoid if's and
  143.     hence fast. Additionally it allows to find the list, if you have
  144.     the node only.)
  145. */
  146.  
  147.  
  148. /*
  149.     NewList is used to initialize a list. The lh_Head and lh_Tail
  150.     fields are used as the head of the list and the lh_Tail and
  151.     lh_TailPred fields work as the tail of the list.
  152.  
  153.     Inputs: list    - a pointer to the list to be initialized.
  154. */
  155. void NewList(struct List *list)
  156.  
  157. {
  158.   list->lh_Head = (struct Node *) &(list->lh_Tail);
  159.   list->lh_Tail = NULL;
  160.   list->lh_TailPred = (struct Node *) list;
  161. }
  162.  
  163.  
  164.  
  165.  
  166.  
  167. /*
  168.     AddHead is used to add a node to the head of a list.
  169.  
  170.     Inputs: list    - the list, where a node should be added
  171.         node    - the node to add.
  172. */
  173. void AddHead(struct List *list, struct Node *node)
  174.  
  175. { node->ln_Succ = list->lh_Head;
  176.   node->ln_Pred = (struct Node *) list;
  177.   list->lh_Head = node;
  178.   node->ln_Succ->ln_Pred = node;
  179. }
  180.  
  181.  
  182.  
  183.  
  184. /*
  185.     AddTail is used to add a node to the end of the list.
  186.  
  187.     Inputs: list    - the list, where a node should be added
  188.         node    - the node to add.
  189. */
  190. void AddTail(struct List *list, struct Node *node)
  191.  
  192. { node->ln_Pred = list->lh_TailPred;
  193.   node->ln_Succ = (struct Node *) &(list->lh_Tail);
  194.   list->lh_TailPred = node;
  195.   node->ln_Pred->ln_Succ = node;
  196. }
  197.  
  198.  
  199.  
  200.  
  201. /*
  202.     The Insert() functions is used to add a node to a certain position in
  203.     the list.
  204.  
  205.     Inputs: list    - the list where a node should be added.
  206.         node    - the node that should be added
  207.         listnode    - the node, after which to insert. (May be NULL or
  208.               equal to list, in which case this is the same
  209.               as AddHead().)
  210. */
  211. void Insert(struct List *list, struct Node *node, struct Node *listnode)
  212.  
  213. {
  214.   if (listnode == NULL)
  215.   { listnode = (struct Node *) list;
  216.   }
  217.   node->ln_Succ = listnode->ln_Succ;
  218.   listnode->ln_Succ = node;
  219.   node->ln_Pred = listnode;
  220.   node->ln_Succ->ln_Pred = node;
  221. }
  222.  
  223.  
  224.  
  225.  
  226. /*
  227.     The Remove() function allows to remove a node from a list.
  228.     This is done by linking the ln_Succ field of the nodes predecessor
  229.     to the nodes successor and, vice versa, the ln_Pred field of the nodes
  230.     predecessor to the successor.
  231.  
  232.     Inputs: node    - the node, that should be removed
  233. */
  234. void Remove(struct Node *node)
  235.  
  236. {
  237.   node->ln_Succ->ln_Pred = node->ln_Pred;
  238.   node->ln_Pred->ln_Succ = node->ln_Succ;
  239. }
  240. #endif /* !AMIGA */
  241.