Source code for /engineering/bos/rewrite/LINE.CPPOriginal file LINE.CPP
   1 /*
   2 	BattleOS : Engage battling programs.
   3 
   4 	Copyright (C) 1993 Erich P Gatejen    ALL RIGHTS RESERVED
   5 
   6 
   7 	File     : LINE.CPP
   8 	Purpose  : Program code for the BattleOS Assembler
   9 
  10 	!! Program code for the line processing class members 	    !!
  11 	!! Must be linked to the BOA				    !!
  12 
  13 */
  14 
  15 
  16 // --------------------------------------------------------------------------
  17 // ---- INCLUDE files -------------------------------------------------------
  18 #include<stdlib.h>
  19 #include<alloc.h>
  20 #include<ctype.h>
  21 #include<string.h>
  22 #include "defines.h"
  23 #include "line.h"
  24 
  25 
  26 // --------------------------------------------------------------------------
  27 // ---- Global Variables ----------------------------------------------------
  28 // NONE
  29 
  30 
  31 // --------------------------------------------------------------------------
  32 // |||| Member function code ||||||||||||||||||||||||||||||||||||||||||||||||
  33 // --------------------------------------------------------------------------
  34 
  35 // <<-- CLASS  : Element -------------------------------------------------->>
  36 
  37 // ---- MEMBER : constructor ----
  38    Element::Element( char* String, int Size ) {
  39 
  40    // Point to nothing!
  41    Next = NULL;
  42 
  43    // Get the memory block
  44    Text = new char[Size + 1];
  45 
  46    // Stuff the data
  47    strcpy( Text, String ); 
  48 
  49    // Determine the type
  50    switch( *String ) {
  51 
  52      case '/' : Type = COMMENT;
  53 		break;
  54 
  55      case '!' : Type = PROGNAME;
  56 		break;
  57 
  58      case '=' : Type = ASSIGN;
  59 		break;
  60 
  61 
  62      case '[' : Type = REFERENCE;
  63 		break;
  64 
  65      case '$' : Type = IMMEDIATEV;
  66 		break;
  67 
  68      case '-' : Type = ADDRESSM;
  69 		break;
  70 
  71      case '+' : Type = ADDRESSP;
  72 		break;
  73 
  74      case '@' : Type = LABEL;
  75 		break;
  76 
  77      case '"' : Type = TAUNTDEFINE;
  78 		break;
  79 
  80      case '<' : Type = TAUNTIMBED;
  81 		break;
  82 
  83      default  : Type = TEXT;
  84 
  85    }; // end swtich
  86 
  87 }; // end constructor
  88 
  89 
  90 // <<-- CLASS  : Line ----------------------------------------------------->>
  91 
  92 // ---- MEMBER : constructor ----
  93    Line::Line( char*  Input ) {
  94 
  95    // Local data
  96    char	    Buffer[80];
  97    int	    Step;		// Iterator
  98    Element* Node;
  99 
 100    // Clear list pointers
 101    Head = NULL;
 102    Tail = NULL;
 103 
 104    // Find first none white-space in line
 105    while( isspace( *Input ) ) {
 106       ++Input;
 107    }; // end while
 108 
 109    // Load element list
 110    while ( *Input ) {
 111 
 112       // Peal into buffer until white-space
 113       Step = 0;
 114       while( !isspace(*Input) ) {
 115 
 116 	 Buffer[Step] = *Input;
 117 	 ++Step;
 118 	 ++Input;
 119 
 120       }; // end while . Step retains the length of the buffer.
 121       Buffer[Step] = NULL;
 122 
 123      // -- Log as an element
 124       // Create the element
 125       Node = new Element( Buffer, Step );
 126 
 127       // Is it the first label?
 128       if ( Head == NULL ) {
 129 
 130 	 // Yes!  Add it to the list as the first node
 131 	 Tail = Node;
 132 	 Head = Node;
 133 
 134       } else {
 135 
 136          // -- No!
 137 	 Tail->Next = Node; // Link last to new
 138 	 Tail	    = Node; // Point tail to new
 139 
 140       }; // end if 
 141 
 142       // Find next none white-space in line
 143       while( isspace( *Input ) ) {
 144          ++Input;
 145       }; // end while
 146 
 147    }; // end while
 148 
 149 }; // end constructor
 150 
 151 
 152 // ---- MEMBER : destructor ----
 153    Line::~Line( void ) {
 154 
 155    // Release all the nodes back to the heap
 156    while ( Head != NULL ) {
 157 
 158 	Tail = Head; 		// Save this node to delete
 159 	Head = Head->Next;  // Point to the next node
 160 
 161 	delete Tail;		// Delete the node
 162 
 163    }; // end while
 164 
 165 }; // end destructor
 166 
 167 
 168 // ---- MEMBER : HasElement ----
 169 inline  BOOLEAN Line::HasElement( void ) {
 170 
 171    if ( Head == NULL ) return FALSE;
 172    else return TRUE;
 173 
 174 }; // end HasElement
 175 
 176 
 177 // ---- MEMBER : PopNext ----
 178 Element*  Line::PopNext( void ) {
 179 
 180   Element*   Node;
 181 
 182   // Get and delink node
 183   Node  = Head;
 184   Head  = Node->Next;
 185 
 186   return Node;
 187 
 188 }; // end PopNext
 189 
 190 
 191 
 192