Powered by GeSHi

Source code for calendar.bat

(view source code of calendar.bat as plain text)

  1. @ECHO OFF
  2.  
  3. :: Xp batch for generating calendars
  4. :: Chances look good for win 2000 and above(untested)
  5. :: By Judago, August 2009
  6.  
  7. IF "%~1"=="/?" (
  8.     ECHO START "%~NX0" WITHOUT ARGUMENTS AND THEN ENTER THE YEAR.
  9.     ECHO "%~NX0" WILL OPEN IN IT'S OWN WINDOW TO AVOID RESIZING
  10.     ECHO AN EXISTING WINDOW.
  11.     ECHO.
  12.     ECHO A SCREEN RESOLUTION AND/OR FONT SIZE THAT CAN DISPLAY
  13.     ECHO CMD WINDOWS OF 96 COLUMNS AND 39 LINES IS REQUIRED.
  14.     ECHO SOME CONFIGURATIONS MAY USE SCROLL BARS TO ACHIEVE
  15.     ECHO THIS.
  16.     EXIT /B
  17. )
  18.  
  19. :: The current codepage is stored in variable %CodePage%,
  20. :: then changed to 850 to facilitate box drawing characters.....
  21.  
  22. FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
  23. CHCP 850 >NUL 2>&1
  24.  
  25. :: The title can be used to falicitate custom window
  26. :: positioning via the properties menu of "calendars..."
  27. :: /max is used so as much content as possible is visable
  28. :: without moving the window. /max must be removed for
  29. :: custom window positing.....
  30.  
  31. IF NOT "%~1 %~2"=="WINDOW SIZE" (
  32. 	START "CALENDARS..." /MAX CMD /C "%~F0" WINDOW SIZE
  33.  
  34. 	REM Restore the original codepage before exiting.....
  35.  
  36. 	CHCP %CodePage% >NUL 2>&1
  37. 	EXIT /B
  38. )
  39. MODE CON:COLS=96 LINES=39
  40. SETLOCAL ENABLEDELAYEDEXPANSION
  41.  
  42. :loop
  43. FOR %%Z IN (jan feb mar apr may jun jul aug sep oct nov dec year day leap noleap length test) DO SET %%Z=
  44. SET /P year=Enter a year to see it's calendar, or nothing to exit, then press enter: 
  45. IF NOT DEFINED year (
  46.  
  47. 	REM Restore the original codepage before exiting.....
  48.  
  49. 	CHCP %CodePage% >NUL 2>&1
  50. 	EXIT /B
  51. )
  52.  
  53. ::Test that the input is only numbers...
  54.  
  55. SET test=!year!
  56. FOR /l %%Z IN (0 1 9) DO IF DEFINED test SET "test=!test:%%Z=!"
  57. IF DEFINED test CLS&GOTO loop
  58. :zero
  59. IF NOT DEFINED year (
  60. 	:error
  61. 	cls
  62. 	echo The year entered can not be accepted.
  63. 	echo.
  64. 	pause
  65. 	CLS
  66. 	GOTO loop
  67. )
  68.  
  69. :: remove leading zeros, if any...
  70.  
  71. IF "%year:~0,1%"=="0" SET year=%year:~1%&&GOTO zero
  72.  
  73. :: The %processor_architecture% test is used to test
  74. :: limits of caculations, if the variable is undefined
  75. :: or unrecognised the test will fall through and complete
  76. :: anyway, if the limit is surpassed this way the results may
  77. :: not be valid. The tested number is ~80% of the limit of the
  78. :: os so that year + year / 4 yields a valid result.
  79.  
  80. IF /I "!processor_architecture!"=="x86" (
  81. 	IF !year! gtr 1717986917 GOTO :error
  82. ) else (
  83. 	IF NOT "!processor_architecture:64=!"=="!processor_architecture!" (
  84. 		IF !year! gtr 7378697629483820645 GOTO :error
  85. 	)
  86. )
  87.  
  88. :: Generate the first day of the year, 0=sun, 1=mon,...,6=sat
  89. :: A 365 day year ofsets by one day, so the next year will start
  90. :: the next day (i.e. 2009 starts on thr and 2010 starts on fri)
  91. :: an extra day must be added for every leapyear. Using modulo
  92. :: 7 on the total of offset days reviels the starting day of the
  93. :: year. one day must also be removed if the year is a leap year
  94. :: because the below will add one for it, the remainder for non
  95. :: leap years is not an issue because set /a only returns whole
  96. :: numbers.
  97.  
  98. SET /A day=(year + year / 4) - (year / 100 - year / 400)
  99. SET /A leap=year %% 400
  100. SET /A noleap=year %% 100
  101. IF !leap! GTR 0 (
  102. 	IF !noleap! NEQ 0 SET /A leap=year %% 4
  103. )
  104. IF %leap%==0 SET /A day-=1
  105. SET /A day%%=7
  106.  
  107. :: For each year every month is padded to is starting offset
  108. :: with spaces, january has the original offset generated above.
  109. :: each additional offset is generated by adding the total days of
  110. :: the previous month then processing it by modulo 7.
  111. :: The days are stored in a varianle to display later, these variables
  112. :: are padded to 111 characters using spaces for display purposes.
  113.  
  114. FOR %%U IN (jan feb mar apr may jun jul aug sep oct nov dec) DO (
  115. 	FOR %%V IN (jan mar may jul aug oct dec) DO IF /I %%U==%%V SET length=31
  116. 	FOR %%W IN (apr jun sep nov) DO IF /I %%U==%%W SET length=30
  117. 	IF /I %%U==feb (
  118. 		IF !leap!==0 (
  119. 			SET length=29
  120. 		) else (
  121. 			SET length=28
  122. 		)
  123. 	)
  124. 	FOR /l %%X IN (1 1 !day!) DO SET "%%U=!%%U!   "
  125. 	FOR /l %%Y IN (1 1 !length!) DO (
  126. 		IF %%Y lss 10 (
  127. 			SET "%%U=!%%U!%%Y  "
  128. 		) else (
  129. 			SET "%%U=!%%U!%%Y "
  130. 		)
  131. 	)
  132. 	FOR /l %%Z IN (!length! 1 54) DO IF "!%%U:~110!"=="" SET "%%U=!%%U! "
  133. 	SET /A day=^(day + length^) %% 7
  134. )
  135. :test
  136.  
  137. :: The results are displayed below using substrings of each month's 
  138. variable.
  139.  
  140. cls
  141. TITLE THE CALENDAR FOR THE YEAR OF %YEAR%
  142. echo. 浜様様様様様様様様様融  浜様様様様様様様様様融  浜様様様様様様様様様融  浜様様様様様様様様様融
  143. echo.       JANUARY               FEBUARY                MARCH                 APRIL        
  144. echo. 麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵
  145. echo. S  M  T  W  T  F  S   S  M  T  W  T  F  S   S  M  T  W  T  F  S   S  M  T  W  T  F  S 
  146. echo. 麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵
  147. echo. %JAN:~0,20%  %FEB:~0,20%  %MAR:~0,20%  %APR:~0,20%
  148. echo. %JAN:~21,20%  %FEB:~21,20%  %MAR:~21,20%  %APR:~21,20%
  149. echo. %JAN:~42,20%  %FEB:~42,20%  %MAR:~42,20%  %APR:~42,20%
  150. echo. %JAN:~63,20%  %FEB:~63,20%  %MAR:~63,20%  %APR:~63,20%
  151. echo. %JAN:~84,20%  %FEB:~84,20%  %MAR:~84,20%  %APR:~84,20%
  152. echo. %JAN:~105%                %FEB:~105%                %MAR:~105%                %APR:~105%              
  153. echo. 藩様様様様様様様様様夕  藩様様様様様様様様様夕  藩様様様様様様様様様夕  藩様様様様様様様様様夕
  154. echo.
  155. echo. 浜様様様様様様様様様融  浜様様様様様様様様様融  浜様様様様様様様様様融  浜様様様様様様様様様融
  156. echo.         MAY                   JUNE                  JULY                 AUGUST       
  157. echo. 麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵
  158. echo. S  M  T  W  T  F  S   S  M  T  W  T  F  S   S  M  T  W  T  F  S   S  M  T  W  T  F  S 
  159. echo. 麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵
  160. echo. %MAY:~0,20%  %JUN:~0,20%  %JUL:~0,20%  %AUG:~0,20%
  161. echo. %MAY:~21,20%  %JUN:~21,20%  %JUL:~21,20%  %AUG:~21,20%
  162. echo. %MAY:~42,20%  %JUN:~42,20%  %JUL:~42,20%  %AUG:~42,20%
  163. echo. %MAY:~63,20%  %JUN:~63,20%  %JUL:~63,20%  %AUG:~63,20%
  164. echo. %MAY:~84,20%  %JUN:~84,20%  %JUL:~84,20%  %AUG:~84,20%
  165. echo. %MAY:~105%                %JUN:~105%                %JUL:~105%                %AUG:~105%              
  166. echo. 藩様様様様様様様様様夕  藩様様様様様様様様様夕  藩様様様様様様様様様夕  藩様様様様様様様様様夕
  167. echo.
  168. echo. 浜様様様様様様様様様融  浜様様様様様様様様様融  浜様様様様様様様様様融  浜様様様様様様様様様融
  169. echo.      SEPTEMBER              OCTOBER               NOVEMBER              DECEMBER      
  170. echo. 麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵
  171. echo. S  M  T  W  T  F  S   S  M  T  W  T  F  S   S  M  T  W  T  F  S   S  M  T  W  T  F  S 
  172. echo. 麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵  麺様様様様様様様様様郵
  173. echo. %SEP:~0,20%  %OCT:~0,20%  %NOV:~0,20%  %DEC:~0,20%
  174. echo. %SEP:~21,20%  %OCT:~21,20%  %NOV:~21,20%  %DEC:~21,20%
  175. echo. %SEP:~42,20%  %OCT:~42,20%  %NOV:~42,20%  %DEC:~42,20%
  176. echo. %SEP:~63,20%  %OCT:~63,20%  %NOV:~63,20%  %DEC:~63,20%
  177. echo. %SEP:~84,20%  %OCT:~84,20%  %NOV:~84,20%  %DEC:~84,20%
  178. echo. %SEP:~105%                %OCT:~105%                %NOV:~105%                %DEC:~105%              
  179. echo. 藩様様様様様様様様様夕  藩様様様様様様様様様夕  藩様様様様様様様様様夕  藩様様様様様様様様様夕
  180. GOTO loop
  181.