Esempio n. 1
0
bool Bookmark::Read(const char* name) {
	Scanner scnr(name);
	if (scnr.InitCheck() == B_OK) {
		BString s; float version; bool ok;
		ok = scnr.ReadName(&s) && scnr.ReadFloat(&version);
		if (!ok || strcmp(s.String(), "Bookmarks") != 0 || (version != 1.0 && version != 2.0) ) {
			REPORT(kError, 0, "Bookmarks (line %d, column %d): '%s' not a bookmarks file or wrong version!", scnr.Line(), scnr.Column(), name);
			return false;
		}
		
		while (!scnr.IsEOF()) {
			float   level, size;
			bool    expanded = false;
			BString family, style, expand;
			if (!(scnr.ReadFloat(&level) && level >= 1.0 && level <= 10.0)) {
				REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid level", scnr.Line(), scnr.Column());
				return false;
			}
			if (!scnr.ReadString(&family)) {
				REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid font family", scnr.Line(), scnr.Column());
				return false;
			}
			if (!scnr.ReadString(&style)) {
				REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid font style", scnr.Line(), scnr.Column());
				return false;
			}
			if (!scnr.ReadFloat(&size)) {
				REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid font size", scnr.Line(), scnr.Column());
				return false;
			}
			if (version == 2.0) {
				if (!scnr.ReadName(&expand) || (strcmp(expand.String(), "expanded") != 0 && strcmp(expand.String(), "collapsed") != 0)) {
					REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid expanded value", scnr.Line(), scnr.Column());
					return false;
				}
				expanded = strcmp(expand.String(), "expanded") == 0;
			}
			
			if (Exists(family.String(), style.String())) {
				BFont font;
				font.SetFamilyAndStyle(family.String(), style.String());
				font.SetSize(size);
			
				AddDefinition((int)level, &font, expanded);
			} else {
				REPORT(kWarning, 0, "Bookmarks (line %d, column %d): Font %s-%s not available!", scnr.Line(), scnr.Column(), family.String(), style.String());
			}
			
			scnr.SkipSpaces();
		}
		return true;
	} else {
		REPORT(kError, 0, "Bookmarks: Could not open bookmarks file '%d'", name);
	}
	return false;
}
Esempio n. 2
0
void run_the_VM() {
  assert(! bootstrapping, "don't get screwed again by this");
  Memory->scavenge();
  SignalInterface::initialize();
  initHProfiler();
  
  IntervalTimer::start_all();

  ResourceMark mark;

  InteractiveScanner scanner;
  VMScanner = &scanner;

  resetTerminal();

  if (startUpSelfFile) { 
    ResourceMark m;
    FileScanner scnr(startUpSelfFile);
    if (scnr.fileError) {
      fatalNoMenu1("Couldn't read file %s!\n\n", startUpSelfFile);
    } else {
      lprintf("Reading %s...", scnr.fileName());
      (void) evalExpressions(&scnr);
      lprintf("done\n");
    }
  }
  
  // After reading a snapshot we need to evaluate the snapshot actions.
  if (postReadSnapshot) {
    postReadSnapshot = false;
    eval("snapshotAction postRead", "<postRead Snapshot>");
  }

  // The read-eval-print loop
  for (;;) {
    ResourceMark m;
    fint line, len;
    const char* source = NULL;
    Parser parser(VMScanner, false);
    resetTerminal();
    VMScanner->start_line("VM# ");
    processes->idle = true;
    if (VMScanner->is_done())
      break;
    processes->idle = false;
   
    Expr* e = parser.readExpr(line, source, len);  // dont fail
    if (e) {
      preservedObj x(e);
      oop res = e->Eval(true, false, true);
      assert(currentProcess->isClean(), "vm process should be clean now");
      if (res == badOop) {
        VMScanner->reset();
        clearerr(stdin);          // don't get hung on ^D
      }
    }
    if (Memory->needs_scavenge()) Memory->scavenge();
  }

  lprintf("\n");
# if TARGET_IS_PROFILED
    lprintf("Writing profile statistics...\n");
# endif
  clearerr(stdin);
  OS::handle_suspend_and_resume(true);            // make sure stdin is in normal mode
  OS::terminate(0);
}
Esempio n. 3
0
bool XRefDefs::Read(const char* name) {
	Scanner scnr(name);

	if (scnr.InitCheck() == B_OK) {

		BString s; float f;
		bool ok = scnr.ReadName(&s) && scnr.ReadFloat(&f);
		if (!ok || strcmp(s.String(), "CrossReferences") != 0 || f != 1.0) {
			REPORT(kError, 0, "XRefs (line %d, column %d): '%s' not a cross references file or wrong version!", scnr.Line(), scnr.Column(), name);
			return false;
		}
		
		while (!scnr.IsEOF()) {
			XRefDef* def = new XRefDef();
			AutoDelete autoDelete(def);
			BString pattern;

			// Links: Pattern {"," Pattern}.
			do {
				if (!scnr.ReadString(&pattern)) {
					REPORT(kError, 0, "XRefs (line %d, column %d): Could not parse 'link' pattern", scnr.Line(), scnr.Column());
					return false;
				}
				LinkPattern* link = new LinkPattern(pattern.String());
				if (link->InitCheck() == B_OK) {
					def->AddLink(link);
				} else {
					delete link;
					REPORT(kError, 0, "XRefs (line %d, column %d): Invalid RegExp '%s'", pattern.String(), scnr.Line(), scnr.Column());
					return false;
				}
			} while (scnr.NextChar(','));

			// "->"
			if (scnr.NextChar('-') && scnr.NextChar('>')) {

				// Dests: Pattern {"," Pattern}.
				do {
					if (!scnr.ReadString(&pattern)) {
						REPORT(kError, 0, "XRefs (line %d, column %d): Could not parse 'destination' pattern", scnr.Line(), scnr.Column());
						return false;
					}
					DestPattern* dest = new DestPattern(pattern.String());
					if (dest->InitCheck() == B_OK) {
						def->AddDest(dest);
					} else {
						delete dest;
						REPORT(kError, 0, "XRefs (line %d, column %d): Invalid RegExp '%s'", scnr.Line(), scnr.Column(), pattern.String());
						return false;
					}
				} while (scnr.NextChar(','));

				// "."
				if (!scnr.NextChar('.')) {
					REPORT(kError, 0, "XRefs (line %d, column %d): '.' expected at end of definition", scnr.Line(), scnr.Column());
					return false;
				}
			} else {
				REPORT(kError, 0, "XRefs (line %d, column %d): '->' expected", scnr.Line(), scnr.Column());
				return false;
			}

			this->Add(def); 
			autoDelete.Release();
			
			scnr.SkipSpaces();
		}
		return true;
	} else {
		REPORT(kError, 0, "XRefs: Could not open cross references file '%d'", name);
	}	
	return false;	
}