home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / misc / edu / WhirlDisc.lha / WhirlDisc / Source / sequence.c < prev    next >
C/C++ Source or Header  |  2000-08-13  |  3KB  |  138 lines

  1. /*
  2.  
  3. File: sequence.c
  4. Author: Neil Cafferkey
  5. Copyright (C) 2000 Neil Cafferkey
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (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; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  20. MA 02111-1307, USA.
  21.  
  22. */
  23.  
  24. #include "viewer.h"
  25. #include <exec/memory.h>
  26. #include <stdio.h>
  27.  
  28. #include "sequence_protos.h"
  29. #include "general_protos.h"
  30. #include <proto/exec.h>
  31.  
  32.  
  33. /* Function: CreateSequence
  34.  * ========================
  35.  * Creates a new Sequence.
  36.  */
  37.  
  38. Sequence CreateSequence(ULONG length,UBYTE *data)
  39. {
  40.    Sequence sequence=AllocMem(sizeof(Sequence_imp),MEMF_CLEAR);
  41.  
  42.    if(sequence)
  43.    {
  44.       sequence->length=length;
  45.       sequence->data=data;
  46.    }
  47.    else
  48.    {
  49.       ReportError(NULL,ERROR_REPORT_MEM,NULL,0);
  50.    }
  51.  
  52.    return sequence;
  53. }
  54.  
  55.  
  56. /* Function: ReadSequence
  57.  * ======================
  58.  * Makes a sequence from the contents of a file.
  59.  */
  60. /*
  61. Sequence ReadSequence(TEXT *file_name)
  62. {
  63. UBYTE *buffer;
  64. FILE *file;
  65. ULONG length;
  66. Sequence sequence;
  67.  
  68. if((file=fopen(file_name,"rb"))==NULL)
  69.    {
  70.    NoMoreMem();
  71.    printf("Couldn't open \"%s\" for reading. Exiting...\n",file_name);
  72.    exit(20);
  73.    }
  74.  
  75. fseek(file,0,SEEK_END);
  76. length=ftell(file);
  77. rewind(file);
  78.  
  79. buffer=Malloc(length*sizeof(UBYTE));
  80.  
  81. fread(buffer,sizeof(UBYTE),length,file);
  82. fclose(file);
  83.  
  84. sequence=CreateSequence(length,buffer);
  85.  
  86. return sequence;
  87. }
  88. */
  89.  
  90. /* Function: GetSequenceLength
  91.  * ===========================
  92.  */
  93.  
  94. ULONG GetSequenceLength(Sequence sequence)
  95. {
  96.    return sequence->length;
  97. }
  98.  
  99.  
  100. /* Function: GetSequenceContents
  101.  * =============================
  102.  */
  103.  
  104. UBYTE *GetSequenceContents(Sequence sequence,ULONG offset)
  105. {
  106.    return sequence->data+offset;
  107. }
  108.  
  109.  
  110. /* Function: IsSubsequence
  111.  * =======================
  112.  */
  113. /*
  114. BOOL IsSubsequence(Sequence sub_seq,UBYTE *main_data)
  115. {
  116.    ULONG i,length=GetSequenceLength(sub_seq);
  117.    UBYTE *sub_data=sub_seq->data;
  118.  
  119.    for(i=0;(i<length)&&(*(sub_data++)==*(main_data++));i++);
  120.  
  121.    return (i==length);
  122. }
  123. */
  124.  
  125. /* Function: KillSequence
  126.  * ======================
  127.  */
  128.  
  129. VOID KillSequence(Sequence sequence)
  130. {
  131. /*   FreeMem(sequence->data,sequence->length);*/
  132.    FreeMem(sequence,sizeof(Sequence_imp));
  133.  
  134.    return;
  135. }
  136.  
  137.  
  138.