home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / vms / 20482 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  14.6 KB

  1. Path: sparky!uunet!portal!cup.portal.com!Chris_F_Chiesa
  2. From: Chris_F_Chiesa@cup.portal.com
  3. Newsgroups: comp.os.vms
  4. Subject: Long-awaited $IMGACT example program, part 1 of 2
  5. Message-ID: <73055@cup.portal.com>
  6. Date: Wed,  6 Jan 93 18:51:45 PST
  7. Organization: The Portal System (TM)
  8. Distribution: world
  9. References: <9301041627.AA20066@uu3.psi.com> <72934@cup.portal.com>
  10. Lines: 372
  11.  
  12. $! ------------------ CUT HERE -----------------------
  13. $ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
  14. $!
  15. $! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
  16. $!   On 17-DEC-1992 15:38:06.33   By user CHIESA 
  17. $!
  18. $! This VMS_SHARE Written by:
  19. $!    Andy Harper, Kings College London UK
  20. $!
  21. $! Acknowledgements to:
  22. $!    James Gray       - Original VMS_SHARE
  23. $!    Michael Bednarek - Original Concept and implementation
  24. $!
  25. $!+ THIS PACKAGE DISTRIBUTED IN 2 PARTS, TO KEEP EACH PART
  26. $!  BELOW 30 BLOCKS
  27. $!
  28. $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
  29. $! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
  30. $!
  31. $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
  32. $!       1. README.TXT;7
  33. $!       2. TRYIT.MAR;22
  34. $!       3. TRYIT.OPT;1
  35. $!       4. TRYIT.CLD;7
  36. $!
  37. $set="set"
  38. $set symbol/scope=(nolocal,noglobal)
  39. $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
  40. $e="write sys$error  ""%UNPACK"", "
  41. $w="write sys$output ""%UNPACK"", "
  42. $ if f$trnlnm("SHARE_LOG") then $ w = "!"
  43. $ ve=f$getsyi("version")
  44. $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
  45. $ e "-E-OLDVER, Must run at least VMS 4.4"
  46. $ v=f$verify(v)
  47. $ exit 44
  48. $UNPACK: SUBROUTINE ! P1=filename, P2=checksum
  49. $ if f$search(P1) .eqs. "" then $ goto file_absent
  50. $ e "-W-EXISTS, File ''P1' exists. Skipped."
  51. $ delete 'f'*
  52. $ exit
  53. $file_absent:
  54. $ if f$parse(P1) .nes. "" then $ goto dirok
  55. $ dn=f$parse(P1,,,"DIRECTORY")
  56. $ w "-I-CREDIR, Creating directory ''dn'."
  57. $ create/dir 'dn'
  58. $ if $status then $ goto dirok
  59. $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
  60. $ delete 'f'*
  61. $ exit
  62. $dirok:
  63. $ w "-I-PROCESS, Processing file ''P1'."
  64. $ if .not. f$verify() then $ define/user sys$output nl:
  65. $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
  66. PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
  67. SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
  68. CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
  69. LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
  70. BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
  71. IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
  72. MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
  73. ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
  74. 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
  75. POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
  76. ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
  77. COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
  78. "output_file"));ENDPROCEDURE;Unpacker;QUIT;
  79. $ delete/nolog 'f'*
  80. $ CHECKSUM 'P1'
  81. $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
  82. $ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
  83. $ ENDSUBROUTINE
  84. $START:
  85. $ create 'f'
  86. XREADME.TXT for "Call VMS COPY" demo, December 17, 1992
  87. XChris Chiesa
  88. XChris_F_Chiesa@cup.portal.com
  89. X
  90. XPosted to "comp.os.vms" aka "INFO-VAX" newsgroup.
  91. X-------
  92. X
  93. XINTRODUCTION:
  94. X
  95. XSeveral weeks ago I posted that I wished to recreate or incorporate the`20
  96. Xfunctionality of the DCL COPY command into a program of my own that added`20
  97. Xsome "front end" criteria to the file-accessibility check phase.  In a`20
  98. Xnutshell, I wanted the "callable COPY" facility so often asked for, and to`2
  99. V0
  100. Xdate omitted, in VMS.
  101. X
  102. XTo make a long story short, when I found that there was no supported way to`
  103. V20
  104. Xcall DCL COPY (SYS$SYSTEM:COPY.EXE) from within a program, I naturally had`2
  105. V0
  106. Xto develop my own.  In this I succeeded, with a little help from the Net,`20
  107. Xand a number of Netters have since expressed interest in seeing the`20
  108. Xresulting "little demo program."  This posting is that program, in a`20
  109. Xpackage with some additional relevant information.
  110. X
  111. X
  112. XOVERVIEW:
  113. X
  114. XTRYIT.MAR is a program which invokes the actual VMS COPY utility -- the`20
  115. Xsame one invoked by the DCL COPY command -- to copy files.  TRYIT is`20
  116. Xinvoked by the command verb TRYIT, whose syntax is, for all intents and`20
  117. Xpurposes, the same as the DCL COPY command.  (The sharp-eyed reader will`20
  118. Xnote, however, that TRYIT's "Command Language Definition" is nearly`20
  119. Xtrivial.  <wink>)
  120. X
  121. XTRYIT accomplishes this amazing feat by using several of what I consider`20
  122. Xthe more esoteric capabilities of VMS, including one or two which aren't`20
  123. Xofficially "supported."  They exist, though, and can be used as long as you`
  124. V20
  125. Xdon't mind being outside the graces of Digital...
  126. X
  127. XBUILDING AND TRYING "TRYIT":
  128. X
  129. XSetting up to see TRYIT do its thing is a -step process.  First you have to`
  130. V20
  131. Xextract the various files which comprise the package, which you've already`2
  132. V0
  133. Xdone if you're reading this!  The shipping manifest looks like this:
  134. X
  135. X`09README.TXT `09- this file
  136. X`09TRYIT.MAR`09- Macro-32 source code
  137. X`09TRYIT.OPT`09- Linker options file
  138. X`09TRYIT.CLD`09- TRYIT command definition
  139. X
  140. XFor best results, leave all of these files in your default directory.
  141. X
  142. XSecond, assemble TRYIT.MAR to form the object TRYIT.OBJ:
  143. X
  144. X`09$ MACRO TRYIT
  145. X
  146. XThird, link TRYIT.OBJ to form the executable image TRYIT.EXE:
  147. X
  148. X`09$ LINK TRYIT,TRYIT/OPT
  149. X
  150. X... yes, that's right, the word TRYIT appears TWICE.  It's not a typo.
  151. X
  152. XFourth, give yourself the TRYIT command:
  153. X
  154. X`09$ SET COMMAND TRYIT
  155. X
  156. XFifth, define the logical name "TESTDIR" to point to your current default
  157. Xdirectory (or wherever you've placed TRYIT.EXE).  If this IS your current
  158. Xdirectory, the following command will do the deed:
  159. X
  160. X`09$ DEFINE TESTDIR 'F$ENV("DEFAULT")
  161. X
  162. XFinally, try it!  (Hence the name.)  Make up a DCL COPY command you'd like
  163. Xto execute, but instead of the verb COPY, use the verb TRYIT!  You'll see
  164. Xa message from TRYIT, then your copy will take place (to see it happen, use`
  165. V20
  166. Xthe /LOG qualifier), then you'll see another message fom TRYIT, showing`20
  167. Xthat it regained control after the COPY operation.  That's all, folks!
  168. X
  169. X
  170. XAPPENDIX A: FACILITIES AND TOOLS USED
  171. X
  172. XFor details as to the step-by-step operation of the program, see the`20
  173. Xcomments in source file TRYIT.MAR.  If that still doesn't do it for you,`20
  174. Xwrite me at the Internet mail address given at the start of this document.
  175. X
  176. XThe facilities and tools which went into the creation of TRYIT are as`20
  177. Xfollows:
  178. X
  179. X`09VMS Utilities:
  180. X`09`09ANALYZE/IMAGE`09
  181. X`09`09`09- before writing the TRYIT.MAR source code, to`20
  182. X`09`09`09  discover the Universal symbol (DCL$AL_TAB_VEC)`20
  183. X`09`09`09  representing the address of the command table in
  184. X`09`09`09  a DCL table image file`20
  185. X
  186. X`09System Services:
  187. X
  188. X`09`09$GETJPI`09- to obtain the Username of the process running`20
  189. X`09`09`09  TRYIT, as food for $GETUAI
  190. X`09`09$GETUAI - to obtain the name of the default DCL command`20
  191. X`09`09`09  table of the process running TRYIT
  192. X`09`09$IMGACT`09- UNDOCUMENTED/UNSUPPORTED! to merge SYS$SYSTEM:
  193. X`09`09`09  COPY.EXE into TRYIT's address space where it
  194. X`09`09`09  could be invoked as a procedure call
  195. X`09`09$IMGFIX`09- UNDOCUMENTED/UNSUPPORTED! goes with $IMGACT
  196. X
  197. X
  198. X`09Run-Time Library Routines:
  199. X
  200. X`09`09LIB$FIND_IMAGE_SYMBOL -
  201. X`09`09`09  to find the command table that defines the DCL`20
  202. X`09`09`09  COPY command, and bring that table into TRYIT's`20
  203. X`09`09`09  address space for the CLI$ routines to use
  204. X`09`09LIB$PUT_OUTPUT -
  205. X`09`09`09  to display a message before and after calling
  206. X`09`09`09  VMS COPY, to prove that TRYIT has control both
  207. X`09`09`09  before and after that event
  208. X`09`09STR$CONCAT -
  209. X`09`09`09  to construct a fake command line, by prefixing
  210. X`09`09`09  the COPY verb to the tail of the TRYIT command`20
  211. X`09`09`09  line
  212. X`09`09
  213. X
  214. X`09Utility Routines:
  215. X
  216. X`09`09CLI$DCL_PARSE -
  217. X`09`09`09  to operate on the fake COPY command as DCL would
  218. X`09`09`09  normally do for a real one, before calling`20
  219. X`09`09`09  COPY.EXE
  220. X`09`09CLI$GET_VALUE -
  221. X`09`09`09  to obtain command-line values, first from the
  222. X`09`09`09  real DCL command line, then from a fake command
  223. X`09`09`09  line constructed to fool COPY into being happy
  224. X
  225. XNote that all but the $IMGACT / $IMGFIX system service usages here are`20
  226. Xfully documented and supported; it's a shame that this technique should be`2
  227. V0
  228. X"so near and yet so far" from full supportability.
  229. X
  230. XAPPENDIX B: SOURCE OF INSPIRATION
  231. X
  232. XI believe my first posting on this subject may have mentioned that the idea`
  233. V20
  234. Xfor this program came "from a posting in this very newsgroup a long time`20
  235. Xago," whose date, author, etc. were now lost to me.  Well, you're all in`20
  236. Xfor a special treat, because guess what I found this morning while cleaning`
  237. V20
  238. Xout an old notebook?  That original "posting... (from) a long time ago!"`20
  239. XI find that it first appeared on the Net nearly four and a half years ago;`2
  240. V0
  241. Xat the time I first read it I was still a college student, and lacked much`2
  242. V0
  243. Xof the background necessary to understand what it was talking about.  But I`
  244. V20
  245. Xsaved it, and over the subsequent four years gained enough VMS knowledge to`
  246. V20
  247. Xfinally put all the pieces together and make it work.  Without further ado,`
  248. V20
  249. Xthen, I here reproduce that inspirational "original posting," in its`20
  250. Xentirety.  Thanks very much to you, Garry Wiegand, if you're reading this!
  251. X
  252. X---- INCLUDED TEXT BEGINS ----
  253. X
  254. XFrom: garry@batcomputer.tn.cornell.edu (Garry Wiegand)
  255. XNewsgroups: comp.os.vms
  256. XSubject: Re: Chaining images... THE source
  257. XDate: 28 Mar 88 02:17:22 GMT
  258. XOrganization: Cornell Engineering && Ithaca Software, Inc.
  259. X
  260. XIn a recent article carl@CITHEX.CALTECH.EDU (Carl J Lydick) wrote:
  261. X>I'm one of the people who referred you to LIB$FIND_IMAGE_SYMBOL.  Let me po
  262. Vint
  263. X>out again that this works only with SHAREABLE images.  This means that you
  264. X>can't chain most images that are linked to be run via a command from the DC
  265. VL
  266. X>level...
  267. X
  268. XNow, if you want to be a real wiz, what you do is:
  269. X
  270. XA) get your DCL command line from wherever and nibble off the command verb.
  271. X   Either use a hard lookup table (ie, "DELE" -> SYS$SYSTEM:DELETE) or
  272. X   a program like Verb as a subroutine to find the right image to activate.
  273. XB) Activate that image with SYS$IMGACT - it doesn't have to be a shareable
  274. X   image.
  275. XC) call Find_Image_Symbol on DCLTABLES.EXE to get the address of the real
  276. X   DCL tables (the name I forget, use ANAL/IMAGE to see it) (the tables are
  277. X   up in P1 space too, I think, if you prefer)
  278. XD) Tell CLI to parse up the command line please
  279. XE) Call the entry point of DELETE, DIRECTORY, or whoever the image turned
  280. X   out to be *as a subroutine*.  It don't know/can't tell that it isn't
  281. X   running as a normal DCL call, calls CLI like usual, and everything works
  282. X   out.
  283. X
  284. XI leave trapping out possible SYS$EXIT calls from the called program as an
  285. Xexercise for the reader.
  286. X
  287. XI used to have the code for this and a bunch of other nonsense 3-4 years,
  288. Xbut I just looked around in all the dusty places and don't see it
  289. Xanymore.  ((Before we got involved in graphics, we were playing some`20
  290. Xideas for some new VMS utilities.  I got involved in the above in the`20
  291. Xcourse of adding an some new switches/abilities to existing VMS commands -
  292. XI could have just duplicated the previous VMS functionality and gone
  293. Xon, but that was tedious and I also didn't want to have to *keep*`20
  294. Xduplicating DEC's functionality.  So we just used Dec's programs as
  295. Xsubroutines of our own.))
  296. X
  297. XOh, the functionality involved was the "UNDELETE" command, with related
  298. Xswitches DIR/DELETED, DELETE/REALLY, etc etc etc.  All blended in
  299. Xnicely. Cute.  (Normal-delete became a surreptious Rename to an invisible
  300. Xparallel directory tree.)
  301. X
  302. XNever did get around to trying to sell the various things - people still
  303. Xare just barely interested in non-Dec *hardware* - VMS add-on software
  304. Xwas/is an even tougher row to hoe.
  305. X
  306. Xgarry wiegand   (garry@oak.cadif.cornell.edu - ARPA)
  307. X                (garry@crnlthry - BITNET)
  308. X
  309. X----- END INCLUDED TEXT -----
  310. X
  311. X
  312. XAPPENDIX C: $IMGACT AND $IMGFIX
  313. X
  314. XNaturally, I suppose you'll want to know how I found out, or figured out,`20
  315. Xhow to use $IMGACT if it's not documented.  Well, it turns out that $IMGACT`
  316. V20
  317. X_is_ documented, sort of.  The FORTRAN header files for system symbol`20
  318. Xdefinition turn out to contain a little paragraph about $IMGACT (and`20
  319. X$IMGFIX), and there's a word or two in the various releases of the VAX/VMS`2
  320. V0
  321. XInternals And Data Structures books that have come out over time.
  322. X
  323. XFor the sake of your enlightenment, appended find a copy of *all* the`20
  324. Xinformation I have ever received about $IMGACT / $IMGFIX.
  325. X
  326. X----- INCLUDED TEXT BEGINS -----
  327. X---- IMGACT_1.TXT ----
  328. X!   $IMGACT
  329. X!`20
  330. X!     Image Activation
  331. X!`20
  332. X!      $IMGACT`09name,`5Bdflnam`5D,hdrbuf,`5Bimgctl`5D,`5Binadr`5D,
  333. X! `09`09`5Bretadr`5D, `5Bident`5D, `5Bacmode`5D
  334. X!`20
  335. X!`20
  336. X!      name`09= address of descriptor for file name string
  337. X!`20
  338. X!      dflnam`09= descriptor for file name string
  339. X!`20
  340. X!      hdrbuf`09= address of 512 byte buffer to write in
  341. X!`20
  342. X!      imgctl`09= image activation control flags
  343. X!`20
  344. X!      inadr`09= address of quadword specifying virtual address
  345. X! `09`09  range to be mapped
  346. X!`20
  347. X!      retadr`09= address of quadword specifying virtual address
  348. X! `09`09  range actually mapped
  349. X!                                    `20
  350. X!      ident`09= address of quadword holding image section match
  351. X! `09`09  control and identifier
  352. X!`20
  353. X!      acmode`09= access mode to be the owner of the created pages
  354. X!`20
  355. X`09INTEGER*4 SYS$IMGACT
  356. X`09EXTERNAL  SYS$IMGACT
  357. X!   $IMGFIX
  358. X!`20
  359. X!     Image Address Fixup Service
  360. X!`20
  361. X!      $IMGFIX                       `20
  362. X!`20
  363. X`09INTEGER*4 SYS$IMGFIX
  364. X`09EXTERNAL  SYS$IMGFIX
  365. X
  366. X---- IMGACT_2.TXT ----
  367. X
  368. X--- Begin Quoting VAX/VMS Internals and Data Structures, CH 21.1, pp 465-467
  369. V ---
  370. Xname`09string descriptor of image that is being activated
  371. Xdflnam`09string descriptor for default file name
  372. Xhdrbuf`09Address of 512-byte buffer in which the image header and image
  373. X`09file descriptor are returned. The first two longwords in the buffer
  374. X`09are the addresses (within the buffer) of the image header and the
  375. X`09image file descriptor respectively
  376. Ximgctl`09Image activation control flags. These flags control the form the th
  377. Ve
  378. X`09activation file will take. The options are the following:
  379. X`09Flag`09`09Meaning
  380. X`09IAC$V_NOACT`09If set, the image activator is not to activate the
  381. X`09`09`09image. This flag is used by the Install Utility to
  382. X`09`09`09complete the installation of known file entries
  383. +-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-
  384.