"changes to support save/restore of graphics by Unix command"
Brought to you by:
johnston
From: <ivt...@li...> - 2001-02-13 01:09:10
|
Patch: ivtools-010212-johnston-004 For: ivtools-0.9.1 Author: joh...@us... Subject: changes to support save/restore of graphics by Unix command Requires: This is an intermediate patch to ivtools-0.9.1. To apply, cd to the top-level directory of the ivtools source tree (the directory with src and config subdirs), and apply like this: patch -p0 <ThisFile Summary of Changes: - set of changes to allow save/restore of graphics files internal to a drawing by the Unix command line used to generate them. For example, if "xwdtopnm temp.xwd" was used to import a raster file (with "from command" checked on the import dialog box), a subsequent save would write this command (and only this command) to the document on disk, and a subsequent restore would re-run the command to regenerate the contents. Should work equally well for rasters, PostScript, and ivtools drawtool files. Index: Attribute/paramlist.c diff -c Attribute/paramlist.c:1.1 Attribute/paramlist.c:1.2 *** Attribute/paramlist.c:1.1 Thu Jan 4 15:31:38 2001 --- src/Attribute/paramlist.c Mon Feb 12 17:04:21 2001 *************** *** 120,125 **** --- 120,126 ---- /*****************************************************************************/ LexScan* ParamList::_lexscan = nil; + ParamStruct* ParamList::_currstruct = nil; ParamList::ParamList (ParamList* s) { _alist = new AList; *************** *** 345,351 **** } } ! ParamStruct* ParamList::GetStruct (ALIterator i) { return Struct(Elem(i)); } void ParamList::SetStruct (ParamStruct* gv, ALIterator& i) { i.SetValue(_alist->Find(gv)); --- 346,352 ---- } } ! ParamStruct* ParamList::GetStruct (ALIterator i) { _currstruct = Struct(Elem(i)); return _currstruct;} void ParamList::SetStruct (ParamStruct* gv, ALIterator& i) { i.SetValue(_alist->Find(gv)); Index: Attribute/paramlist.h diff -c Attribute/paramlist.h:1.1 Attribute/paramlist.h:1.2 *** Attribute/paramlist.h:1.1 Thu Jan 4 15:31:38 2001 --- src/Attribute/paramlist.h Mon Feb 12 17:04:21 2001 *************** *** 235,240 **** --- 235,243 ---- static char octal(const char* p); // convert string of three octal digits to a character. + static ParamStruct* CurrParamStruct() { return _currstruct; } + // last ParamStruct from ::GetStruct + protected: void insert(ParamStruct*); void insert_first(ParamStruct*); *************** *** 270,275 **** --- 273,279 ---- int _other_count; static LexScan* _lexscan; + static ParamStruct* _currstruct; }; #include <IV-2_6/_leave.h> Index: OverlayUnidraw/ovfile.c diff -c OverlayUnidraw/ovfile.c:1.1 OverlayUnidraw/ovfile.c:1.2 *** OverlayUnidraw/ovfile.c:1.1 Thu Jan 4 15:33:06 2001 --- src/OverlayUnidraw/ovfile.c Mon Feb 12 17:04:28 2001 *************** *** 24,29 **** --- 24,30 ---- #include <OverlayUnidraw/ovcatalog.h> #include <OverlayUnidraw/ovclasses.h> #include <OverlayUnidraw/ovfile.h> + #include <OverlayUnidraw/ovimport.h> #include <OverlayUnidraw/paramlist.h> #include <Unidraw/Commands/command.h> *************** *** 37,42 **** --- 38,44 ---- #include <stdio.h> #include <stream.h> #include <string.h> + #include <fstream.h> /*****************************************************************************/ *************** *** 67,74 **** } void OverlayFileComp::GrowParamList(ParamList* pl) { ! pl->add_param("pathname", ParamStruct::required, &OverlayFileScript::ReadPathName, this, this); OverlaysComp::GrowParamList(pl); } --- 69,78 ---- } void OverlayFileComp::GrowParamList(ParamList* pl) { ! pl->add_param("path", ParamStruct::optional, &OverlayFileScript::ReadPathName, this, this); + pl->add_param("popen", ParamStruct::keyword, &OverlayFileScript::ReadPathName, + this, this); OverlaysComp::GrowParamList(pl); } *************** *** 175,187 **** int OverlayFileScript::ReadPathName (istream& in, void* addr1, void* addr2, void* addr3, void* addr4) { OverlayFileComp* filecomp = (OverlayFileComp*)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 << "pathname recursion not allowed (" << pathname << ")\n"; return -1; --- 179,200 ---- 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; *************** *** 190,206 **** } filecomp->SetPathName(pathname); ! 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; } } --- 203,235 ---- } 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) { + ifstream ifs; + ifs.rdbuf()->attach(fileno(fptr)); + OverlayComp* child = (OverlayComp*) impcmd.Import(ifs); + if (child) { + filecomp->Append(child); + return 0; + } + fclose(fptr); + } + return -1; } } Index: OverlayUnidraw/ovfile.h diff -c OverlayUnidraw/ovfile.h:1.1 OverlayUnidraw/ovfile.h:1.2 *** OverlayUnidraw/ovfile.h:1.1 Thu Jan 4 15:33:06 2001 --- src/OverlayUnidraw/ovfile.h Mon Feb 12 17:04:28 2001 *************** *** 59,64 **** --- 59,70 ---- // return point to underlying top-level component. virtual boolean operator == (OverlayComp&); + + void SetPopenFlag(boolean flg) { _popenflg = flg; } + // set flag that indicates whether to read from command pipe. + boolean GetPopenFlag() { return _popenflg; } + // get flag that indicates whether to read from command pipe. + virtual void AdjustBaseDir(const char* oldpath, const char* newpath); // adjust base directory used for generating pathnames for this component, // done when a document is saved to a new location. *************** *** 67,72 **** --- 73,79 ---- void GrowParamList(ParamList*); static ParamList* _overlay_file_params; char * _pathname; + boolean _popenflg; CLASS_SYMID("OverlayFileComp"); }; Index: OverlayUnidraw/ovimport.c diff -c OverlayUnidraw/ovimport.c:1.1 OverlayUnidraw/ovimport.c:1.2 *** OverlayUnidraw/ovimport.c:1.1 Thu Jan 4 15:33:06 2001 --- src/OverlayUnidraw/ovimport.c Mon Feb 12 17:04:28 2001 *************** *** 1520,1529 **** --- 1520,1536 ---- if (pathname && !return_fd) { char buffer[BUFSIZ]; + #if 0 if (compressed) sprintf(buffer, "cm=`ivtmpnam`;stdcmapppm>$cm;gzip -c %s | djpeg -map $cm -dither fs -pnm;rm $cm", pathname); else sprintf(buffer, "cm=`ivtmpnam`;stdcmapppm>$cm;djpeg -map $cm -dither fs -pnm %s;rm $cm", pathname); + #else + if (compressed) + sprintf(buffer, "cm=`ivtmpnam`;stdcmapppm>$cm;gzip -c %s | djpeg -pnm;rm $cm", pathname); + else + sprintf(buffer, "cm=`ivtmpnam`;stdcmapppm>$cm;djpeg -pnm %s;rm $cm", pathname); + #endif FILE* pptr = popen(buffer, "r"); helper.add_pipe(pptr); if (pptr) { Index: OverlayUnidraw/ovraster.c diff -c OverlayUnidraw/ovraster.c:1.1 OverlayUnidraw/ovraster.c:1.2 *** OverlayUnidraw/ovraster.c:1.1 Thu Jan 4 15:33:06 2001 --- src/OverlayUnidraw/ovraster.c Mon Feb 12 17:04:28 2001 *************** *** 329,338 **** if (graphic == nil) { OverlayRasterRect* rr = GetRasterOvComp()->GetOverlayRasterRect(); ! OverlayRaster* r = rr->GetOverlayRaster(); ! OverlayRaster* or = rr->GetOverlayRaster(); ! graphic = or ? (new OverlayRasterRect(or, rr)) : ! (new OverlayRasterRect(r, rr)); SetGraphic(graphic); } --- 329,336 ---- if (graphic == nil) { OverlayRasterRect* rr = GetRasterOvComp()->GetOverlayRasterRect(); ! OverlayRaster* r = rr ? rr->GetOverlayRaster() : nil; ! graphic = r ? new OverlayRasterRect(r, rr) : nil; SetGraphic(graphic); } Index: OverlayUnidraw/scriptview.c diff -c OverlayUnidraw/scriptview.c:1.1 OverlayUnidraw/scriptview.c:1.2 *** OverlayUnidraw/scriptview.c:1.1 Thu Jan 4 15:33:06 2001 --- src/OverlayUnidraw/scriptview.c Mon Feb 12 17:04:28 2001 *************** *** 524,530 **** } else { Transformer* t = new Transformer(a00, a01, a10, a11, a20, a21); ! gs->SetTransformer(t); Unref(t); return 0; } --- 524,531 ---- } else { Transformer* t = new Transformer(a00, a01, a10, a11, a20, a21); ! if (gs) gs->SetTransformer(t); ! else fprintf(stderr, "OverlayScript::ReadTransform: no graphic for transformer\n"); Unref(t); return 0; } *** /dev/null Mon Feb 12 17:04:36 PST 2001 --- patches/ivtools-010212-johnston-004 *************** patches/ivtools-010212-johnston-004 *** 0 **** --- 1 ---- + ivtools-010212-johnston-004 |