home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / random.zip / backdrop.cmd next >
OS/2 REXX Batch file  |  1994-05-30  |  4KB  |  111 lines

  1. /* BACKDROP.CMD - A character-based program to read the BACKDROP.INI file
  2.    created by the GUI BACKSET.EXE program.  This program should be added
  3.    to the STARTUP.CMD file with the command:
  4.  
  5.    [path]BACKDROP
  6.  
  7.    If I get energetic then I will add code to create a program object for
  8.    this file and add the object to the STARTUP folder.  */
  9.  
  10. /* First make sure the INI file has been created -- in the directory in which this
  11.    program exists -- not necessarily the current directory when it was called */
  12.  
  13. parse source environment executive command
  14. /* E.g., command now might = c:\utils\backdrop\backdrop.cmd */
  15. IniFile = FILESPEC('D', command) || FILESPEC('P', command) || 'BACKDROP.INI'
  16.  
  17. if STREAM(IniFile, 'C', 'QUERY EXISTS') = '' then do
  18.   say 'You must run the BACKSET program to setup the bitmaps to'
  19.   say 'display before the randomizer can work.'
  20.   say
  21.   say 'Press ENTER to exit the randomizer'
  22.   call BEEP 350, 100
  23.   pull dummy
  24.   end
  25.  else do
  26.   /* Load RexxUtil functions */
  27.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  28.   call SysLoadFuncs
  29.  
  30.   /* Find out how often the bitmap should be changed, and when
  31.      it changed last */
  32.   Frequency = SysIni(IniFile, 'BackDrop', 'Frequency')
  33.   LastChanged = SysIni(IniFile, 'BackDrop', 'LastChanged')
  34.   parse var LastChanged LastMonth '/' LastDay '/' LastYear
  35.   Today = DATE(U)
  36.   parse var Today NowMonth '/' NowDay '/' NowYear
  37.   SELECT
  38.     when Frequency = 'Boot' then signal Randomize
  39.  
  40.     when Frequency = 'Daily' then
  41.       if LastChanged \= Today then signal Randomize
  42.  
  43.     when Frequency = 'Weekly' then do
  44.     /* This is the trickiest of the bunch, requiring conversion to Julian
  45.        dates for best processing. */
  46.       call JulianDates
  47.       if NowJulian - 7 >= LastJulian then signal Randomize
  48.       end /* when Weekly */
  49.  
  50.     when Frequency = 'Monthly' then do
  51.       /* Note that I don't bother counting the number of days per month
  52.          and all that rot.  The first of the month is the day to change */
  53.       if NowYear \= LastYear then signal Randomize
  54.       if NowMonth \= LastMonth then signal Randomize
  55.       end  /* when Monthly */
  56.  
  57.     end  /* select */
  58.  
  59.   end  /* else (STREAM...) */
  60. exit  /* end program */
  61.  
  62. JulianDates:
  63.   /* This procedure simplifies date arithmetic by converting the values to
  64.      Julian (yyddd).  It would have been nice to use the Julian date
  65.      functions in Personal REXX, but I couldn't afford to buy runtime
  66.      licenses for all of CompuServe. I'm also not going to bother with the
  67.      odd number of days per month, assuming they are all 30. */
  68.  
  69.   If NowYear > LastYear then do
  70.     NowYear = NowYear - 1
  71.     NowMonth = NowMonth + 12
  72.     end
  73.   NowJulian = NowYear * 1000
  74.   LastJulian = LastYear * 1000
  75.   NowJulian = NowJulian + ((NowMonth - 1) * 30)
  76.   LastJulian = LastJulian + ((LastMonth - 1) * 30)
  77.   NowJulian = NowJulian + NowDay
  78.   LastJulian = LastJulian + LastDay
  79.  
  80.   exit /* JulianDates */
  81.  
  82. Randomize:
  83.   /* This procedure changes the current desktop bitmap to a different
  84.      one from those selected in the BACKSET program */
  85.  
  86.   /* First change the date last changed to today */
  87.   call SysIni IniFile, 'BackDrop', 'LastChanged', Today
  88.  
  89.   /* Now find out how many bitmaps there are to choose from, and
  90.      which one is being displayed currently */
  91.   NumberAvailable = SysIni(IniFile, 'BackDrop', 'Count')
  92.  
  93.   /* Find out which bitmap is being shown now */
  94.   CurrentBitmap = SysIni(IniFile, 'BackDrop', 'CurrentBitmap')
  95.   NextBitmap = CurrentBitmap
  96.  
  97.   /* Select a random bitmap from those available, making sure it
  98.      isn't the one already being displayed */
  99.   do until CurrentBitmap \= NextBitmap
  100.     NextBitmap = 'File' || RANDOM(1, NumberAvailable)  /* Build INI key */
  101.     NextBitmap = SysIni(IniFile, 'BackDrop', NextBitmap)
  102.     end
  103.  
  104.   /* Make this the current bitmap */
  105.   call SysSetObjectData '<WP_DESKTOP>', 'BACKGROUND =' NextBitmap
  106.  
  107.   /* And store the new bitmap in the INI file */
  108.   call SysIni IniFile, 'BackDrop', 'CurrentBitmap', NextBitmap
  109.  
  110.   exit
  111.