home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / System / EASys / EASys!_update_47x_to_481 / StartSys / bin / Extract-User-Startup.rexx
OS/2 REXX Batch file  |  2000-06-30  |  7KB  |  293 lines

  1. /*
  2.     ModAS © TNE) Jun.2000
  3.  
  4.     Extracting Application Config from s:user-startup automatically
  5.     to SYS:StartSys/c_Prepare/<AppName>
  6.  
  7.     <AppName> is automatically determined according to the entries'
  8.     ;BEGIN ... Statement.
  9.  
  10.     Notification for invoking this script when user-startup
  11.     is being write-accessed is realized by usage of
  12.     EASys!_bin:MultiNotify
  13. */
  14. PARSE ARG msg_flag
  15.  
  16. IF GetClip('ModAS_Extracting')=1 THEN EXIT 0
  17. CALL SetClip('ModAS_Extracting',1)
  18.  
  19. ADDRESS COMMAND 'EASys!_bin:CLIexchange MultiNotify DISABLE'
  20.  
  21. CALL Init
  22. StartupDir='SYS:StartSys/c_Prepare/'
  23. /*StartupDir='T:'*/
  24. Startup='s:user-startup'
  25. StartupTmp='T:New_UserStartup'
  26. unassigned_script=StartupDir'1_User-Specific_parts'
  27. unassigned_tmp='T:UnassignedTMP'
  28. unassigned=0
  29.  
  30. CALL BackupFile(startup)
  31.  
  32. header.1=';Backwards-compatibility-Script S:user-startup'
  33. header.2=';    * New Standard complies to ModAS'
  34. header.3=';    * All Entries are automatically checked out'
  35. header.4=';      to SYS:StartSys/c_Profile/<AppName>'
  36. header.5=';      by EASys!_bin:MultiNotify'
  37.  
  38. IF Open(fStartupTmp,StartupTmp,'W') THEN
  39. DO
  40.   DO i=1 TO 5
  41.     r=WriteLn(fStartupTmp,header.i)
  42.   END
  43.   r=Close(fStartupTmp)
  44. END
  45.  
  46. IF Open(fStartup,Startup,'R') THEN startupOpen=1
  47. IF Open(fUnassignedTMP,unassigned_tmp,'W') THEN Unassigned_tmp_Open=1
  48.  
  49. origLine=ReadLn(fStartup)
  50.  
  51. DO i=1 TO 5
  52.   IF (header.i=origLine) THEN
  53.   DO
  54.     origLine=ReadLn(fStartup)
  55.     IF EOF(fStartup) THEN CALL ExitMe
  56.   END
  57.   ELSE LEAVE i
  58. END
  59.  
  60. leave_next=0
  61.  
  62. DO FOREVER
  63.   drop i
  64.   drop j
  65.   drop Line
  66.   i=0
  67.   j=0
  68.  
  69.   IF (LEFT(UPPER(origLine),6)=';BEGIN' | LEFT(UPPER(origLine),7)='; BEGIN' | LEFT(UPPER(origLine),8)=';  BEGIN' ) THEN
  70.   DO
  71.     i=i+1
  72.     IF LEFT(UPPER(origLine),6)=';BEGIN' THEN
  73.     DO
  74.       App=Word(origLine,2)
  75.       Comment=RIGHT(origLine,LENGTH(origLine)-6)
  76.     END
  77.  
  78.     IF (LEFT(UPPER(origLine),7)='; BEGIN' | LEFT(UPPER(origLine),8)=';  BEGIN')  THEN
  79.     DO
  80.       App=Word(origLine,3)
  81.       Comment=RIGHT(origLine,LENGTH(origLine)-7)
  82.     END
  83.  
  84.     App=STRIP(App,'B','"')
  85.     IF ~(RIGHT(msg_flag,6)='NOECHO') THEN Line.i=CreateStartupMessage(Comment)
  86.  
  87.     DO FOREVER
  88.       r=ReadLn(fStartup)
  89.       IF EOF(fStartup) THEN leave_next=1
  90.       IF leave_next=1 | (LEFT(UPPER(r),4)=';END' | LEFT(UPPER(r),5)='; END' | LEFT(UPPER(r),6)=';  END') THEN LEAVE
  91.       i=i+1
  92.       Line.i=r
  93.     END
  94.  
  95.     DevicePos=POS(':',App)
  96.     SlashPos=POS('/',App)
  97.     DollPos=POS('$',App)
  98.     len=Length(App)
  99.     IF (DevicePos>0) THEN App=LEFT(App,DevicePos-1)
  100.     IF (SlashPos>0) THEN App=LEFT(App,SlashPos-1)
  101.     IF (DollPos>0) THEN App=LEFT(App,DollPos-1)
  102.     IF (App='') | (App=' ') | (App='   ') THEN
  103.     DO
  104.      u=0
  105.      DO FOREVER
  106.       u=u+1
  107.       App='PleaseRename_'u
  108.       IF ~EXISTS(StartupDir''App) THEN LEAVE
  109.      END
  110.     END
  111.  
  112.     u=0
  113.     AppScript=StartupDir''App
  114.     BaseName=AppScript
  115.     DO FOREVER
  116.       IF EXISTS(AppScript) THEN
  117.       DO
  118.        u=u+1
  119.        AppScript=BaseName'_'u
  120.       END
  121.       ELSE LEAVE
  122.     END
  123.  
  124.     IF Open(fPrepare,AppScript, 'W') THEN
  125.     DO
  126.       IF ~(RIGHT(msg_flag,6)='NOECHO') THEN
  127.       DO
  128.        e=WriteLn(fPrepare,'failat 30')
  129.        e=WriteLn(fPrepare,'stack 8192')
  130.       END
  131.  
  132.       DO j=1 to i
  133.           IF ~(Line.j='LINE.'j) THEN e=WriteLn(fPrepare,Line.j)
  134.       END
  135.       e=Close(fPrepare)
  136.     END
  137.  
  138.     CALL Message(AppScript)
  139.  
  140.     IF leave_next=1 THEN LEAVE
  141.   END
  142.   ELSE
  143.   DO
  144.     IF ~(origLine='' | origLine=' ' | origLine='  ' | origLine='   ' | origLine='    ' | origLine=';' | origLine='; ' | origLine=';  '  | origLine=';   ') THEN
  145.     DO
  146.       App='User specific parts'
  147.       unassigned=1
  148.       IF ~EXISTS(unassigned_script) & ~(unassigned_exists=1) THEN
  149.       DO
  150.         unassigned_exists=1
  151.         IF ~(RIGHT(msg_flag,6)='NOECHO') THEN 
  152.         DO
  153.           StartupMsg=CreateStartupMessage(' User specific parts')
  154.           r=WriteLn(fUnassignedTMP,'failat 21'CR''StartupMsg''CR CR''origLine)
  155.         END
  156.       END
  157.       ELSE
  158.         r=WriteLn(fUnassignedTMP,origLine)
  159.     END
  160.   END
  161.  
  162.   origLine=ReadLn(fStartup)
  163.   IF EOF(fStartup) THEN LEAVE
  164. END
  165.  
  166.  
  167. /* -------------------------- */
  168. ExitMe:
  169.  
  170. IF (StartupOpen=1) THEN e=Close(fStartup)
  171. IF (Unassigned_tmp_Open=1) THEN e=Close(fUnassignedTmp)
  172.  
  173. IF (unassigned=1) THEN
  174. DO
  175.  ADDRESS COMMAND 'type >>'unassigned_script' 'unassigned_tmp
  176.  CALL Message(unassigned_script)
  177. END
  178.  
  179. ADDRESS COMMAND
  180. 'copy "'StartupTmp'" "'Startup'" CLONE QUIET'
  181. 'EASys!_bin:CLIexchange MultiNotify ENABLE'
  182.  
  183. CALL DELAY(100)
  184. CALL SetClip('ModAS_Extracting',0)
  185.  
  186. EXIT 0
  187.  
  188. /* -------------------------- */
  189. Message:
  190. PARSE ARG Script
  191.  
  192. IF LEFT(msg_flag,5)='QUIET' THEN RETURN
  193.  
  194. Msg=CR'ModAS Extractor:' CR'_______________________________'CR CR CR'Module: 'App CR CR'extracted from  S:User-Startup'CR'into  'Script CR
  195. rtBtns='  ok! | Edit '
  196. e = rtezrequest(Msg,rtBtns,AppName,PosTags)
  197. IF (e=0) THEN ADDRESS COMMAND '${RefTable/Text-Editor} "'Script'"'
  198. RETURN
  199.  
  200. /* -------------------------- */
  201. CreateStartupMessage:
  202. PARSE ARG Comments
  203.  
  204. StartMsg='IF ${Flags/StartVerbose} EQ 1'CR' echo " Preparing..'Comments'"'CR'EndIf'
  205. RETURN StartMsg
  206.  
  207. /* -------------------------- */
  208. BackupFile:
  209. PARSE ARG bakFile
  210.  
  211. n=10
  212. DO i=1 to n
  213.  IF EXISTS(bakFile'.'n) THEN
  214.  DO
  215.    ADDRESS COMMAND 'copy "'bakFile'" "'bakFile'.'n'" CLONE QUIET'
  216.    LEAVE
  217.  END
  218.  
  219.  IF ~EXISTS(bakFile'.'i) THEN ADDRESS COMMAND 'copy "'bakFile'" "'bakFile'.'i'" CLONE QUIET'
  220. END
  221. RETURN
  222.  
  223. /*--------------------------------------------*/
  224. MyGetENV:     PROCEDURE
  225. PARSE ARG name
  226.  
  227.  TheFile="ENV:" || name
  228.  IF (Open(TEMPFILE, TheFile, 'read')) THEN
  229.    DO
  230.      ENVvalue=ReadLn(TEMPFILE)
  231.      Result=Close(TEMPFILE)
  232.    END
  233.   ELSE
  234.      ENVvalue=''
  235.  
  236. RETURN ENVvalue
  237.  
  238. /*--------------------------------------------*/
  239. Init:
  240.  
  241. AppName = "© TNE) ModAS User-Startup-Extractor"
  242.  
  243. CR = '0a'x
  244.  
  245. /* CALL GetLanguage */
  246.  
  247. IF ~show('L','rexxreqtools.library') THEN Result=ADDLIB('rexxreqtools.library',0,-30,0)
  248. IF ~show('L','rexxsupport.library') THEN Result=ADDLIB('rexxsupport.library',0,-30,0)
  249.  
  250. ProcessNumber=PRAGMA('ID')
  251.  
  252.  
  253. CALL FORBID
  254.  
  255. Intui  = showlist(l, 'intuition.library',, a)
  256. Screen = next(intui, 56)
  257. Font   = next(screen, 136)
  258. FontSize = c2d(import(offset(font, 20), 2))
  259.  
  260. CALL PERMIT
  261.  
  262.  
  263. MaxTitleChars = MyGetENV("RefTable/GUI-ShellTitleChars")
  264.  
  265. ConsoleType = MyGetENV("RefTable/GUI-ConsoleType")
  266. IF (ConsoleType = "") THEN ConsoleType = "CON:"
  267.  
  268. ConsoleSize = MyGetENV("SHELLsize")
  269. IF (ConsoleSize = "") THEN ConsoleSize = "40/50/600/200"
  270.  
  271. ReqLE = MyGetENV("RefTable/GUI-ReqLE")  /* Main Window */
  272. ReqTE = MyGetENV("RefTable/GUI-ReqTE")
  273.  
  274. ReqHeight = MyGetENV("RefTable/GUI-ReqHeight")
  275.  
  276. rt_TE1 = ReqTE + FontSize + 4  /* Requester-Windows */
  277. rt_LE1 = ReqLE + 6
  278.  
  279. PosTags = "rt_reqpos=reqpos_topleftscr rt_leftoffset=" ReqLE " rt_topoffset=" ReqTE
  280. EZtags = PosTags
  281. GLtags = PosTags || "rtgl_min=0 rtgl_max=1500 rtgl_backfill=true "
  282. GStags = PosTags || " rtgs_backfill=false rtgs_width=300"
  283.  
  284. POINTER_TAGS = "rt_reqpos=reqpos_pointer"
  285. DIR_TAGS = PosTags || " rtfi_flags=freqf_nofiles|freqf_save rtfi_height=" ReqHeight
  286. FILE_TAGS = PosTags || " rtfi_flags=freqf_multiselect|freqf_selectdirs" || " rtfi_height=" ReqHeight
  287. ONEFILE_TAG = PosTags || " rtfi_height=" ReqHeight
  288.  
  289. Console = '>"'ConsoleType || ConsoleSize'/'AppName' Messages.../AUTO/NOClose/ALT'ReqLE'/'ReqTE'/500/40"'
  290.  
  291. RETURN
  292.  
  293.