home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / e20313in.zip / emacs / 20.3.1 / emx / instemacs.cmd < prev    next >
OS/2 REXX Batch file  |  1996-01-29  |  8KB  |  304 lines

  1. /* instemacs.cmd -- create program icons for emacs and emacsclient
  2.                     Copyright (c) 1993, 1995 by Harald Bögeholz
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21. parse arg args
  22.  
  23. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  24. call SysLoadFuncs
  25.  
  26. say "instemacs.cmd 1.2 (c) 1993, 1995 by Harald Bögeholz"
  27.  
  28. OptionStartup=0
  29. OptionInstall=0
  30. OptionAssociate=0
  31. OptionKeepvio=0
  32. OptionMakedefault=0
  33.  
  34. do while args \== ""
  35.   parse upper var args arg args
  36.  
  37.   select
  38.     when arg="INSTALL" then
  39.       OptionInstall=1
  40.     when arg="STARTUP" then
  41.       OptionStartup=1
  42.     when arg="KEEPVIO" then
  43.       OptionKeepvio=1
  44.     when arg="ASSOCIATE" then
  45.       OptionAssociate=1
  46.     when arg="MAKEDEFAULT" then
  47.       OptionMakedefault=1
  48.     otherwise
  49.       do
  50.         say "*** Unknown option:" arg
  51.         call Usage
  52.       end
  53.   end
  54.  
  55. end
  56.  
  57. if \OptionInstall then 
  58. do
  59.   say "*** Nothing to do!"
  60.   call Usage
  61. end
  62.  
  63. if OptionMakedefault then OptionAssociate=1
  64.  
  65. if OptionKeepVio then
  66.   MinimizeEmacs=";PROGTYPE=WINDOWABLEVIO;MINIMIZED=YES"
  67. else
  68.   MinimizeEmacs=";PROGTYPE=PM"
  69.  
  70. if OptionAssociate then
  71. do
  72.   call FindAssoc
  73.   Associate=MakeAssocString()
  74. end
  75. else
  76.   Associate=""
  77.  
  78.  
  79. emacsfspec=LocateEmacs("emacs.exe",1)
  80. emacsiconfspec=LocateEmacs("emacs.ico",1)
  81. emacsclientfspec=LocateEmacs("emacsclient.exe",0)
  82.  
  83. /* create a folder for the new objects */
  84. call SysCreateObject "WPFolder", "New Things", "<WP_DESKTOP>", ,
  85.      "OBJECTID=<HWB_NEWTHINGS>", "fail"
  86.  
  87. /* create the program object for Emacs */
  88. EmacsOk=SysCreateObject("WPProgram", "Emacs", "<HWB_NEWTHINGS>", ,
  89.      "EXENAME="emacsfspec";PARAMETERS=-pm %*"MinimizeEmacs";"||,
  90.      "ICONFILE="emacsiconfspec";OBJECTID=<HWB_GNUEMACS>", "update")
  91. if EmacsOk then
  92.   say "Program object for Emacs created successfully."
  93. else
  94.   say "*** Could not create program object for Emacs."
  95.  
  96. /* create the program object for Emacsclient */
  97. if emacsclientfspec \== "" then
  98.   EmacsclientOk=SysCreateObject("WPProgram", "Emacsclient", "<HWB_NEWTHINGS>",,
  99.        "EXENAME="emacsclientfspec";PARAMETERS=-w %*;MINIMIZED=YES;"||,
  100.        "ICONFILE="emacsiconfspec||Associate|| ,
  101.        ";OBJECTID=<HWB_GNUEMACSCLIENT>", "update")
  102. else
  103.   EmacsclientOk=0
  104.  
  105. if EmacsclientOk then
  106.   say "Program object for Emacsclient created successfully."
  107. else
  108.   say "*** Could not create program object for Emacsclient."
  109.  
  110. if OptionStartup then
  111. do
  112.   ShadowOk=SysCreateObject("WPShadow", "Emacs", "<WP_START>", ,
  113.        "SHADOWID=<HWB_GNUEMACS>", "update")
  114.   if ShadowOk then
  115.     say "Shadow object for Emacs created successfully."
  116.   else
  117.     say "*** Could not create shadow object for Emacs."
  118. end
  119.  
  120. if OptionMakedefault then
  121. do
  122.   if EmacsclientOk then
  123.     call Makedefault
  124.   else
  125.     say "*** Sorry, can't make Emacsclient the default editor"
  126. end
  127.  
  128. signal on syntax /* the following call will fail under OS/2 2.0, so trap it */
  129.  
  130. call SysSetObjectData "<HWB_NEWTHINGS>", "OPEN=DEFAULT"
  131.  
  132. exit
  133.  
  134. SYNTAX:
  135. say "You can find the new objects in the folder 'New Things' on your desktop."
  136. exit
  137.  
  138. /* ---------------------------------------------------------------------- */
  139. LocateEmacs: procedure
  140.  
  141. parse arg fname, required
  142.  
  143. fspec=SysSearchPath("EMACSPATH", fname)
  144. if fspec=="" then fspec=SysSearchPath("PATH", fname)
  145. if fspec=="" then
  146. do
  147.   say "*** Can't locate "fname". Be sure to have set your PATH or EMACSPATH"
  148.   say "    variables correctly!"
  149.   if required then
  150.     exit
  151. end
  152. else say "Found "fspec"."
  153.  
  154. return fspec
  155.  
  156. /* ---------------------------------------------------------------------- */
  157. FindAssoc: procedure expose key. assoc.
  158.  
  159. key.1="PMWP_ASSOC_TYPE"
  160. assoc.1="Plain Text"
  161. key.2="PMWP_ASSOC_TYPE"
  162. assoc.2="OS/2 Command File"
  163. key.3="PMWP_ASSOC_TYPE"
  164. assoc.3="DOS Command File"
  165. key.4="PMWP_ASSOC_FILTER"
  166. assoc.4="*.DOC"
  167. key.5="PMWP_ASSOC_FILTER"
  168. assoc.5="*.TXT"
  169. key.0=5
  170.  
  171. /* Find the object handle of the System Editor */
  172. SEHandleBin=SysIni(, "PM_Workplace:Location", "<WP_SYSED>")
  173. if SEHandleBin="ERROR:" then
  174.   return                            /* fail silently if this doesn't work */
  175.  
  176. /* convert to 0-terminated decimal string */
  177. SEHandle=c2d(reverse(SEHandleBin)) || "00"x
  178.  
  179. IniApp.1="PMWP_ASSOC_TYPE"
  180. IniApp.2="PMWP_ASSOC_FILTER"
  181.  
  182. do i=1 to 2
  183.   call SysIni , IniApp.i, "All:", "IniKeys"
  184.   if Result \= "ERROR:" then
  185.   do
  186.     do j=1 to IniKeys.0
  187.       Handles=SysIni(, IniApp.i, IniKeys.j)
  188.       if Handles \= "ERROR:" then
  189.       do
  190.         if pos(SEHandle, Handles) > 0 then
  191.         do
  192.           Found=0
  193.           do k=1 to key.0
  194.             if (key.k == IniApp.i) & (assoc.k == IniKeys.j) then
  195.             do
  196.               Found=1
  197.               leave k
  198.             end
  199.           end
  200.           if \Found then
  201.           do
  202.             key.0=key.0+1
  203.             new=key.0
  204.             key.new=IniApp.i
  205.             assoc.new=IniKeys.j
  206.           end
  207.         end
  208.       end
  209.     end
  210.   end
  211. end
  212.  
  213. return
  214.  
  215. /* ---------------------------------------------------------------------- */
  216. MakeAssocString: procedure expose key. assoc.
  217.  
  218. AssocTypes=""
  219. do i=1 to key.0
  220.   if key.i=="PMWP_ASSOC_TYPE" then
  221.     AssocTypes=AssocTypes","assoc.i
  222. end
  223. AssocTypes=substr(AssocTypes,2)
  224.  
  225. AssocFilters=""
  226. do i=1 to key.0
  227.   if key.i=="PMWP_ASSOC_FILTER" then
  228.     AssocFilters=AssocFilters","assoc.i
  229. end
  230. AssocFilters=substr(AssocFilters,2)
  231.  
  232. return ";ASSOCTYPE="AssocTypes";ASSOCFILTER="AssocFilters
  233.  
  234.  
  235. /* ---------------------------------------------------------------------- */
  236. Makedefault: procedure expose key. assoc.
  237. /* WARNING: This procedure changes Workplace Shell associations in an 
  238.             undocumented way by directly manipulating OS2.INI.
  239.             This only works by magic.
  240.             Use at your own risk.                                         */
  241.  
  242. ECHandleBin="ERROR:"
  243. do i=1 to 10 until ECHandleBin \== "ERROR:"
  244. /* Find the object handle of Emacsclient */
  245.   ECHandleBin=SysIni(, "PM_Workplace:Location", "<HWB_GNUEMACSCLIENT>")
  246.   if ECHandleBin=="ERROR:" then
  247.   do
  248.     say "Waiting for the Workplace Shell. Stay tuned..."
  249.     call SysSleep i
  250.   end
  251. end
  252. if ECHandleBin=="ERROR:" then
  253. do
  254.   say "*** Can't determine object handle for <HWB_GNUEMACSCLIENT>"
  255.   exit
  256. end
  257.  
  258. /* convert to 0-terminated decimal string */
  259. ECHandle=c2d(reverse(ECHandleBin)) || "00"x
  260.  
  261. do i=1 to key.0
  262.   AssocHandles=GetIni(key.i, assoc.i)
  263.   ECPos=pos(ECHandle, AssocHandles)
  264.   if ECPos=0 then
  265.   do
  266.     say "*** Can't find association of "assoc.i" with Emacsclient."
  267.     exit
  268.   end
  269.   NewHandles=ECHandle||left(AssocHandles,ECPos-1)||,
  270.       substr(AssocHandles, ECPos+Length(ECHandle))
  271.   if SysIni(, key.i, assoc.i, NewHandles)="ERROR:" then
  272.   do
  273.     say "*** Can't store new value for "key.i","assoc.i" in OS2.INI"
  274.     exit
  275.   end
  276. end
  277.  
  278. return 1
  279.  
  280. /* ---------------------------------------------------------------------- */
  281. GetIni: procedure        /* get a value from OS2.INI and check for errors */
  282.  
  283. parse arg app, key
  284.  
  285. IniString=SysIni(, app, key)
  286. if IniString=="ERROR:" then
  287. do
  288.   say "*** Can't find "app","key" in OS2.INI."
  289.   exit
  290. end
  291.  
  292. return IniString
  293.  
  294. /* ---------------------------------------------------------------------- */
  295. Usage: procedure
  296.  
  297. say "Usage: instemacs install [options...]"
  298. say "Options:"
  299. say "  startup      create a shadow of Emacs in your startup folder"
  300. say "  keepvio      don't start the non-PM part of Emacs as a PM program"
  301. say "  associate    associate emacsclient with plain text files etc."
  302. say "  makedefault  make Emacsclient the OS/2 default editor"
  303. exit
  304.