Exemplo n.º 1
0
/* a method that handels "LABELS:" in a given line*/
char *HandleLabel(char* label,char *line,int* loc)
{
	char *temp,*address_10=NULL,*address_12=NULL;
	enum Directive dir;
	label[strlen(label)-1]='\0';
	temp=line+(*loc);
	temp=StringTrim(temp);
	/*ALLOCATE_STRING(address_10,1);
	ALLOCATE_STRING(address_12,1);*/
	FIX_NULL_STRING(address_10);
	FIX_NULL_STRING(address_12);

	if(strlen(temp)==0) /* Label only */
	{
		strcpy(address_10,ConvertIntToCharByBase(IC,ConversionToAddress,10));
		strcpy(address_12,ConvertIntToCharByBase(IC,ConversionToAddress,12));
		AddLabelItem(_labels,label,address_10,address_12,'c');
		IC++;
	}
	else if(temp[0]=='.') /* Label with Directive */
	{
			dir=WhatDirective(temp);
			temp=StringMoveToNextItem(temp);
			temp=StringTrim(temp);
			switch(dir)
			{
			case STRING:
				strcpy(address_10,ConvertIntToCharByBase(DC,ConversionToAddress,10));
				strcpy(address_12,ConvertIntToCharByBase(DC,ConversionToAddress,12));
				AddLabelItem(_labels,label,address_10,address_12,'d');
				break;
				
				break;

			case DATA:
				strcpy(address_10,ConvertIntToCharByBase(DC,ConversionToAddress,10));
				strcpy(address_12,ConvertIntToCharByBase(DC,ConversionToAddress,12));
				AddLabelItem(_labels,label,address_10,address_12,'d');
				break;
			case EXTERN:
			case ENTRY:
				FIX_NULL_STRING(label);
				break;
			case NONE:
				strcpy(address_10,ConvertIntToCharByBase(IC,ConversionToAddress,10));
				strcpy(address_12,ConvertIntToCharByBase(IC,ConversionToAddress,12));
				AddLabelItem(_labels,label,address_10,address_12,'c');
				return NULL;
				break;
			default:
				break;
			}
	}
	else
	{
		AnalyzeCommand(line);
		*loc=strlen(line);
	}
	return label;
}
Exemplo n.º 2
0
void FileListBox::PopulateFileList(const std::string& path)
{
  new_path = path;
  if (path.compare(path.size()-1, sizeof(PATH_SEPARATOR), PATH_SEPARATOR))
    new_path += PATH_SEPARATOR;
  MSG_DEBUG("file", "Searching in %s\n", new_path.c_str());

  FolderSearch *f = OpenFolder(new_path);

  // Now that we have made use of new_path, it can be freed:
  // clearing the list is now possible
  Clear();

  if (f) {
    bool is_file = list_files;
    const char *name;

    while ((name = FolderSearchNext(f, is_file)) != NULL) {
      if (is_file) {
        // We have a file, check that it validates the list
        if (MatchFilter(name)) {
          std::string* filename = new std::string(new_path);
          *filename += name;
          MSG_DEBUG("file", "Adding file %s\n", name);
          AddLabelItem(false, ANSIToUTF8(new_path, name), filename, Font::FONT_MEDIUM);
        } else {
          MSG_DEBUG("file", "NOT adding file %s, invalid extension\n", name);
        }
      } else if (strcmp(name, ".")) {
        std::string* filename;
        if (!strcmp(name, "..")) {
          // Are we at the root?
          if (!strcmp(name, PATH_SEPARATOR))
            break;
          size_t pos = new_path.find_last_of(PATH_SEPARATOR, new_path.size()-2, sizeof(PATH_SEPARATOR));
          filename = new std::string(new_path.substr(0, pos+1));
        } else
          filename = new std::string(new_path);
        *filename += name;
        MSG_DEBUG("file", "Adding directory %s\n", name);
        AddLabelItem(false, std::string("[") + ANSIToUTF8(new_path, name) + "]", filename,
                     Font::FONT_MEDIUM, Font::FONT_NORMAL, c_yellow);
      } else
        MSG_DEBUG("file", "Rejecting %s\n", name);

      // Prepare again for searching files
      is_file = list_files;
    }

    CloseFolder(f);
    Pack();
    NeedRedrawing();
  } else {
    MSG_DEBUG("file", "Search failed?\n");
  }

  // Store last time to drop fast clicks
  last_time = SDL_GetTicks();
}
Exemplo n.º 3
0
/* a function that analyzes what the comman is ought to do and if its legal */
char *AnalyzeCommand(char *temp)
{
	char *word,*label=NULL,*cmd=NULL;
	enum Boolean cmdFound=FALSE;
	int *curPos,pos=0;
	opcode op;
	curPos=&pos;
	while(cmdFound==FALSE)
	{
		word=ReadWord(temp,curPos,' ');

		if(word==NULL || strlen(word)==0)
			return NULL;
		if(word[strlen(word)-1]==':')
		{
			ALLOCATE_STRING(label,strlen(word));
			strcpy(label,word);
			label[strlen(label)-1]='\0';
			AddLabelItem(_labels,label,ConvertIntToCharByBase(IC,ConversionToAddress,10),ConvertIntToCharByBase(IC,ConversionToAddress,12),'c');
			continue;
		}
		ALLOCATE_STRING(cmd,strlen(word));
		strcpy(cmd,word);
		cmdFound=TRUE;

	}

	op=GetOpcodeDefinition(cmd,opcodes);
	if(strcmp(op.op,"?")==0)
	{
		ErrorHandler(CompilingError,"command not recognized:"); /* add command to error */
			return NULL;
	}
	else
	{
		HandleCommand(temp,curPos,op,label);
	}
	return op.op;
}