home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
- *
- *
- * Unit containing the Label object.
- *
- * by Adrian Bool in cooperation with Graham Cox.
- *
- * copyright © phantasm coding 1992.
- *
- *
- ************************************************************/
-
- #include "Global.h"
- #include "Label.h"
-
- #include "Label.proto.h"
-
- lHandle newLabelList(void)
- {
- lHandle temp;
-
- temp = (lHandle) NewHandle(sizeof(label));
-
- if (temp != nil)
- {
- (*temp)->next = nil;
- (*temp)->value = 0;
- copyString((*temp)->name,"");
- }
- return(temp);
- }
-
-
- void disposeLabelList(lHandle theList)
- {
- lHandle next;
-
- while (theList != nil)
- {
- next = (*theList)->next;
- DisposHandle((Handle) theList);
- theList = next;
- }
- }
-
-
- lValue getLabelValue(lHandle topLabel , char *labelName)
- {
- lHandle thisLabel;
- short found;
-
- thisLabel = topLabel;
-
- pruneLabel(labelName);
-
- if (labelName[0] == '\0')
- AsmError = SyntaxError;
- else
- {
-
- do
- {
- if (found = (strcmp(labelName,(*thisLabel)->name) == 0)) break;
- if ((*thisLabel)->next == nil) break;
- thisLabel = (*thisLabel)->next;
- }
- while(true);
-
- if (found)
- return((*thisLabel)->value);
- else
- AsmError = LabelNotDefined;
- }
- }
-
-
- void newLabel(pHandle theProgram , char *labelName , lValue value)
- {
- lHandle thisLabel;
- lHandle newLabel;
- short found;
-
- pruneLabel(labelName);
-
- if (labelName[0] == '\0')
- AsmError = SyntaxError;
- else
- {
- /* first check to see if label is already defined */
-
- thisLabel = (*theProgram)->labelHeader;
-
- do
- {
- if (found = (strcmp(labelName,(*thisLabel)->name) == 0)) break;
- if ((*thisLabel)->next == nil) break;
- thisLabel = (*thisLabel)->next;
- }
- while(true);
-
- if (found)
- AsmError = DuplicateIdentifier;
-
- else
- {
- /* Label OK if got to here */
-
- newLabel = (lHandle) NewHandle(sizeof(label));
-
- if (newLabel != nil)
- {
- (*newLabel)->next = nil;
- (*newLabel)->value = value;
- copyString((*newLabel)->name,labelName);
- }
- else
- AsmError = NotEnoughMemory;
-
- (*thisLabel)->next = newLabel;
- }
- }
- }
-
-
- void pruneLabel(char *labelName)
- {
- /* remove colon and make to max of 8 chars */
-
- short nameLength;
-
- nameLength = strlen(labelName);
-
- if (labelName[nameLength-1] == ':') labelName[nameLength-1] = (char) 0;
- if (nameLength > 8) labelName[8] = (char) 0;
- }
-
-
-
-
-