home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / EDITOR / MG2A_SRC.ZIP / SYS / VMS / MG.COM < prev    next >
Encoding:
Text File  |  1988-08-23  |  3.0 KB  |  90 lines

  1. $    Verify = 'F$Verify(0)
  2. $!
  3. $! MG.COM
  4. $!
  5. $! Usage:
  6. $! @MG [file1 [file2 [...]]]        ! To start up MG
  7. $! @MG [file]                ! To reattach to MG after ^Z
  8. $!
  9. $! MG.COM implements a "kept-fork" capability for MG, allowing you to pop
  10. $! in and out of the editor without reloading it all the time.  If a
  11. $! process called user_MG (where user is your username) exists, this
  12. $! command file attempts to attach to it.  If not, it silently spawns a
  13. $! subjob to run Emacs for you. 
  14. $!
  15. $! To `keep' MG around once you get into it, use "suspend-emacs" (bound
  16. $! to C-z by default) to suspend MG and attach back to the process
  17. $! pointed to by MG$AttachTo. 
  18. $!
  19. $! To get back into MG from DCL enter @MG again.  You may optionally
  20. $! specify *one* new file name, in which case MG will attempt to
  21. $! visit that file when you re-attach. 
  22. $!
  23. $!----------------------------------------------------------------
  24. $!
  25. $! Set things up.  Change the definition of MG_Name to whatever you like.
  26. $! You'll *have* to redefine MG_PROG, of course...
  27. $!
  28. $    MG_Name = F$Edit(F$Getjpi("","USERNAME"),"TRIM") + "_MG"
  29. $    MG_Prog = "Disk$Staff:[Ccep001.Proj.Mg3]MG.Exe"
  30. $    MG_Base = MG_Name            ! Used for additions
  31. $    If F$Length(MG_Base) .GT. 13 Then -    ! Truncate base for _1,_2...
  32. $        MG_Base = F$Extract(0,13,MG_Base)
  33. $    Proc = F$GetJpi("","PRCNAM")
  34. $    Master_Pid = F$Getjpi("","MASTER_PID")
  35. $!
  36. $! Define logical names used for communicating with MG
  37. $!
  38. $    Define/Nolog/Job MG$AttachTo    "''Proc'"
  39. $    Define/Nolog/Job MG$File    " "    ! No file by default
  40. $    If P1 .Nes. "" Then -
  41.         Define/Nolog/Job MG$File "''P1'"
  42. $!
  43. $! Attempt to find MG subprocess in current tree.  If found, attach
  44. $! to it, else spawn a new MG process
  45. $!
  46. $    Save_Priv = F$SetPrv("NOWORLD,NOGROUP")    ! Only look in job tree
  47. $    Try_Count = 1
  48. $Search:
  49. $    Context = ""            ! Set up process search context
  50. $ProcLoop:
  51. $    Pid = F$Pid(Context)        ! Get next PID
  52. $    If Pid .Eqs. "" Then -
  53.          Goto Spawn        ! No MG_Name found; spawn a process
  54. $    If F$GetJpi(Pid,"PRCNAM") .Nes. MG_Name Then -
  55.         Goto Procloop        ! Try next process
  56. $! Process name matches; see if it's in our job
  57. $    If F$GetJpi(Pid,"MASTER_PID") .Eqs. Master_Pid Then -
  58.         Goto Attach        ! Found process in our job!
  59. $! Process name matches, but isn't in our job.  Re-start search
  60. $    MG_Name = MG_Base + "_" + F$String(Try_Count)
  61. $    Try_Count = Try_Count + 1
  62. $    Goto Search
  63. $!
  64. $! Here to attach to a process in our tree. Set message to
  65. $! turn off the "Attaching to..." message
  66. $!
  67. $Attach:
  68. $    Message = F$Environment("MESSAGE")
  69. $    Set Proc/Priv=('Save_Priv')        ! Restore privileges
  70. $    Set Message/NoFacility/NoIdentification/NoSeverity/NoText
  71. $    Attach "''MG_Name'"
  72. $    Set Message/Facility/Identification/Severity/Text
  73. $    Goto Done
  74. $!
  75. $! Here if can't attach.  Spawn a new MG process
  76. $!
  77. $Spawn:
  78. $    Set Process/Priv=('Save_Priv')        ! Restore privileges
  79. $    MG$MG :== $'MG_Prog'            ! Avoid recursion
  80. $    Spawn/NoLog/Proc="''MG_Name'" MG$MG 'P1' 'P2' 'P3' 'P4' 'P5' 'P6' 'P7' 'P8'
  81. $    Delete/Symbol/Global MG$MG        ! Get rid of it 
  82. $Done:
  83. $!
  84. $! Here once we reconnect from MG, whether we detached or exited.
  85. $!
  86. $    Deassign/Job MG$File
  87. $    Deassign/Job MG$AttachTo
  88. $    If Verify Then -
  89.         Set Verify
  90.