Component* OverlayFileComp::Copy () { OverlayFileComp* ovfile = new OverlayFileComp(new Picture(GetGraphic())); if (attrlist()) ovfile->SetAttributeList(new AttributeList(attrlist())); ovfile->SetPathName(GetPathName()); Iterator i; First(i); if (!Done(i)) ovfile->Append((GraphicComp*)GetComp(i)->Copy()); return ovfile; }
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; } }