Esempio n. 1
0
int FrameFileScript::ReadPathName (istream& in, void* addr1, void* addr2, void* addr3, void* addr4) {
    FrameFileComp* filecomp = (FrameFileComp*)addr1;

    char pathname[BUFSIZ];
    if (ParamList::parse_pathname(in, pathname, BUFSIZ, filecomp->GetBaseDir()) != 0)
	return -1;

    /* check pathname for recursion */
    OverlayComp* parent = (OverlayComp*) filecomp->GetParent();
    while (parent != nil) {
	if (parent->GetPathName() && strcmp(parent->GetPathName(), pathname) == 0) {
	    cerr << "framefile recursion not allowed (" << pathname << ")\n";
	    return -1;
	}
	parent = (OverlayComp*) parent->GetParent();
    }

    filecomp->SetPathName(pathname);
    FrameIdrawComp* child = nil;
    FrameCatalog* catalog = (FrameCatalog*)unidraw->GetCatalog();
    catalog->SetParent(filecomp);
    if( catalog->FrameCatalog::Retrieve(pathname, (Component*&)child)) {
	catalog->SetParent(nil);
	catalog->Forget(child);
	filecomp->Append(child);
	return 0;
    } else {
	catalog->SetParent(nil);
	return -1;
    }
}
Esempio n. 2
0
int OverlayFileScript::ReadPathName (istream& in, void* addr1, void* addr2, void* addr3, void* addr4) {
    OverlayFileComp* filecomp = (OverlayFileComp*)addr1;

    const char* paramname = ParamList::CurrParamStruct()->name();
    filecomp->SetPopenFlag(strcmp(paramname, "popen")==0);

    char pathname[BUFSIZ];
    if (filecomp->GetPopenFlag()) {
      if (ParamList::parse_string(in, pathname, BUFSIZ) != 0)
	return -1;
    } else {
      if (ParamList::parse_pathname(in, pathname, BUFSIZ, filecomp->GetBaseDir()) != 0)
	return -1;
    }


    /* check pathname for recursion */
    OverlayComp* parent = (OverlayComp*) filecomp->GetParent();
    while (!filecomp->GetPopenFlag() && parent != nil) {
	if (parent->GetPathName() && strcmp(parent->GetPathName(), pathname) == 0) {
	    cerr << "pathname recursion not allowed (" << pathname << ")\n";
	    return -1;
	}
	parent = (OverlayComp*) parent->GetParent();
    }

    filecomp->SetPathName(pathname);
    if (!filecomp->GetPopenFlag()) {
      OverlayIdrawComp* child = nil;
      OverlayCatalog* catalog = (OverlayCatalog*) unidraw->GetCatalog();
      catalog->SetParent(filecomp);
      if( catalog->OverlayCatalog::Retrieve(pathname, (Component*&)child)) {
	catalog->SetParent(nil);
	catalog->Forget(child);
	filecomp->Append(child);
	return 0;
      } else {
	catalog->SetParent(nil);
	return -1;
      }
    } else {
      OvImportCmd impcmd((Editor*)nil);
      FILE* fptr = popen(pathname, "r");
      if (fptr) {
	FILEBUF(fbuf, fptr, ios_base::in);
	istream ifs(&fbuf);
	OverlayComp* child = (OverlayComp*) impcmd.Import(ifs);
	if (child) {
	  filecomp->Append(child);
	  return 0;
	}
	fclose(fptr);
      }	
      return -1;
    }
}