home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CLIPB52.ZIP / ACKER.ZIP / SPENCE2.PRG < prev   
Encoding:
Text File  |  1990-05-31  |  11.6 KB  |  627 lines

  1. * Windows.prg
  2. *
  3. * Windows class
  4.  
  5. #include "system.h"
  6.  
  7. * CHARACTER win_save(t, l, b, r)
  8. *
  9. * NUMERIC t, l, b, r   - Window coordinates. Optional, default to
  10. *                        0, 0, 24, 79 (full screen)
  11. *
  12. * Return combined coordinates and screen area
  13.  
  14. FUNCTION win_save
  15.  
  16.    PARAM t, l, b, r
  17.  
  18.    * Assign defaults to optional parameters
  19.    P_DEF(t, 0)
  20.    P_DEF(l, 0)
  21.    P_DEF(b, 24)
  22.    P_DEF(r, 79)
  23.  
  24. RETURN chr(t) + chr(l) + chr(b) + chr(r) + ;
  25. savescreen(t, l, b, r)
  26.  
  27.  
  28.  
  29.  
  30. * Windows.h
  31. *
  32. * Windows class
  33.  
  34. #define GET_T(win_str) asc(substr(win_str, 1, 1))
  35. #define GET_L(win_str) asc(substr(win_str, 2, 1))
  36. #define GET_B(win_str) asc(substr(win_str, 3, 1))
  37. #define GET_R(win_str) asc(substr(win_str, 4, 1))
  38.  
  39.  
  40. * Windows.h
  41. *
  42. * Windows class
  43. *
  44. * GET_WIN() Return window from window structure
  45.  
  46. * Number of characters occupied by the coordinates
  47. #define COORD_SIZE 4
  48.  
  49. * The actual window
  50. #define GET_WIN(win_str) substr(win_str, COORD_SIZE + 1)
  51.  
  52.  
  53.  
  54. * Windows.prg
  55. *
  56. * Windows class
  57.  
  58. #include "system.h"
  59. #include "windows.h"
  60.  
  61. * VOID win_rest(scr_str)
  62. *
  63. * CHARACTER scr_str    - A character string returned from win_save
  64. *
  65. * Restore sceeen from a packed screen structure ...
  66.  
  67. FUNCTION win_rest
  68.  
  69.    PARAM scr_str
  70.  
  71.    restscreen(GET_T(scr_str), GET_L(scr_str), ;
  72.    GET_B(scr_str), GET_R(scr_str), ;
  73.    GET_WIN(scr_str))
  74.  
  75. RETURN VOID
  76.  
  77.  
  78.  
  79. * Windows.prg
  80. *
  81. * Windows class
  82.  
  83. #include "system.h"
  84. #include "windows.h"
  85.  
  86.  
  87. * NUMERIC win_size(win_coords)
  88. *
  89. * CHARACTER win_coords
  90. *
  91. * Return size of window defined by win_coords
  92. *
  93. * This could be a compiler macro, but the line would be too long ...
  94.  
  95. FUNCTION win_size
  96.  
  97.    PARAM win_coords
  98.  
  99. RETURN ((GET_B(win_coords) - GET_T(win_coords) + 1) * ;
  100. (GET_R(win_coords) - GET_L(win_coords) + 1)) * 2 + ;
  101. COORD_SIZE
  102.  
  103.  
  104.  
  105.  
  106. * Windows.prg
  107. *
  108. * Windows class
  109.  
  110. #include "system.h"
  111. #include "windows.h"
  112.  
  113.  
  114. * VOID win_init()
  115. *
  116. * Initialization of screen stack
  117.  
  118. FUNCTION win_init
  119.  
  120.    PUBLIC scr_stk                                && The stack variable
  121.  
  122.    scr_stk = NULLC                               && Empty character string
  123.  
  124. RETURN VOID
  125.  
  126.  
  127. * VOID win_end()
  128. *
  129. * Release this Class's data
  130.  
  131. FUNCTION win_end
  132.  
  133.    RELEASE scr_stk
  134.  
  135. RETURN VOID
  136.  
  137.  
  138. * VOID win_push(t, l, b, r)
  139. *
  140. * NUMERIC t, l, b, r   - Window coordinates. Optional.
  141. *                      - Default to 0, 0, 24, 79 (full screen)
  142. *
  143. *
  144. * Push a screen structure on scr_stk
  145.  
  146. FUNCTION win_push
  147.  
  148.    PARAM t, l, b, r
  149.  
  150.    * Assign defaults to optional parameters
  151.    P_DEF(t, 0)
  152.    P_DEF(l, 0)
  153.    P_DEF(b, 24)
  154.    P_DEF(r, 79)
  155.  
  156.    * Push on stack (LHS of string)
  157.    scr_stk = win_save(t, l, b, r) + scr_stk
  158.  
  159. RETURN VOID
  160.  
  161.  
  162. * VOID win_pop()
  163. *
  164. * Pop a screen structure off scr_stk, restoring screen
  165.  
  166. FUNCTION win_pop
  167.  
  168.    PRIVATE saved_scr_len
  169.  
  170.    saved_scr_len = win_size(scr_stk)
  171.  
  172.    win_rest(substr(scr_stk, 1, saved_scr_len))
  173.  
  174.    * pop off stack
  175.    scr_stk = substr(scr_stk, saved_scr_len + 1)
  176.  
  177. RETURN VOID
  178.  
  179.  
  180. #ifdef WIN_TEST
  181. * Initialize windows class
  182. win_init()
  183.  
  184. SET CURSOR OFF
  185. CLEAR
  186. inkey(0)
  187.  
  188. * save the empty screen
  189. win_push()
  190.  
  191. * draw the first window and pause
  192. @ 10, 10 TO 20, 20 DOUBLE
  193. @ 11, 11 SAY "WIN 1"
  194. inkey(0)
  195.  
  196. * Push this window onto the stack
  197. win_push(10, 10, 20, 20)
  198.  
  199. * Draw the second window and pause
  200. @ 12, 12 TO 18, 19
  201. @ 13, 13 SAY "WIN 2"
  202. inkey(0)
  203.  
  204. * restore the first window and pause
  205. win_pop()
  206. inkey(0)
  207.  
  208. * restore the empty screen and pause
  209. win_pop()
  210. inkey(0)
  211.  
  212. * Close the windows class
  213. win_end()
  214. #endif
  215.  
  216.  
  217.  
  218. * files.h
  219. *
  220. * Header file for low level file handling primitives
  221.  
  222. #define OPEN_RDONLY    0
  223. #define OPEN_WRONLY    1
  224. #define OPEN_RDWR      2
  225.  
  226. #define CREAT_RDWR     0
  227. #define CREAT_RDONLY   1
  228. #define CREAT_HIDDEN   2
  229. #define CREAT_SYSTEM   4
  230. #define CREAT_LABEL    8
  231. #define CREAT_SUBDIR  16
  232. #define CREAT_ARCHIVE 32
  233.  
  234. #define SEEK_BOF 0
  235. #define SEEK_CUR 1
  236. #define SEEK_EOF 2
  237.  
  238. * Return current file position
  239. #define FTELL(f_handle) fseek(f_handle, 0, SEEK_CUR)
  240.  
  241.  
  242.  
  243.  
  244. * VOID win_init()
  245. *
  246. * Initialization of screen stack
  247.  
  248. FUNCTION win_init
  249.  
  250.    PUBLIC f_handle, ;                            && The file handle
  251.    f_ptrs                                        && File pointers stack
  252.  
  253.    f_handle = fcreate("_fwindow")
  254.    f_ptrs = NULLC
  255.  
  256. RETURN VOID
  257.  
  258.  
  259. * VOID win_end()
  260. *
  261. * Release this Class's data
  262.  
  263. FUNCTION win_end
  264.  
  265.    fclose(f_handle)
  266.    RELEASE f_handle, f_ptrs
  267.  
  268. RETURN VOID
  269.  
  270.  
  271.  
  272. #define LEN_PTR 5
  273.  
  274. * VOID win_push(t, l, b, r)
  275. *
  276. * NUMERIC t, l, b, r   - Window coordinates. Optional.
  277. *                      - Default to 0, 0, 24, 79 (full screen)
  278. *
  279. *
  280. * Push a screen structure on scr_stk
  281.  
  282. FUNCTION win_push
  283.  
  284.    PARAM t, l, b, r
  285.  
  286.    * Assign defaults to optional parameters
  287.    P_DEF(t, 0)
  288.    P_DEF(l, 0)
  289.    P_DEF(b, 24)
  290.    P_DEF(r, 79)
  291.  
  292.    * Push current file position onto pointers stack
  293.    f_ptrs = str(FTELL(f_handle), LEN_PTR) + f_ptrs
  294.  
  295.    * Write to file
  296.    fwrite(f_handle, win_save(t, l, b, r))
  297.  
  298. RETURN VOID
  299.  
  300.  
  301.  
  302. * VOID win_pop()
  303. *
  304. * Pop a screen structure off scr_stk, restoring screen
  305.  
  306. FUNCTION win_pop
  307.  
  308.    PRIVATE f_ptr, saved_scr_len, win
  309.  
  310.    * Pop pointers
  311.    f_ptr = val(substr(f_ptrs, 1, LEN_PTR))
  312.    f_ptrs = substr(f_ptrs, LEN_PTR + 1)
  313.  
  314.    * Seek to start of this saved entry
  315.    fseek(f_handle, f_ptr)
  316.  
  317.    * Determine size so we can allocate space and read it
  318.    saved_scr_len = win_size()
  319.  
  320.    * Now read this window. Note, we cannot use freadstr here, because
  321.    * it stops with a NULL (chr(0))
  322.    win = space(saved_scr_len)
  323.    fread(f_handle, @win, len(win))
  324.  
  325.    * Restore this window
  326.    win_rest(win)
  327.  
  328.    * Now reposition file pointer
  329.    fseek(f_handle, f_ptr)
  330.  
  331. RETURN VOID
  332.  
  333.  
  334.  
  335. * NUMERIC win_size()
  336. *
  337. * PARAM win_coords
  338. *
  339. * Return size of window at current file position
  340.  
  341. FUNCTION win_size
  342.  
  343.    PRIVATE save_pos, win_coords
  344.  
  345.    * we can't disturb current file position. Save it first ...
  346.    save_pos = FTELL(f_handle)
  347.  
  348.    * allocate space for coordinates and read them
  349.    win_coords = space(COORD_SIZE)
  350.    fread(f_handle, @win_coords, len(win_coords))
  351.  
  352.    * now reposition file pointer
  353.    fseek(f_handle, save_pos)
  354.  
  355. RETURN ((GET_B(win_coords) - GET_T(win_coords) + 1) * ;
  356. (GET_R(win_coords) - GET_L(win_coords) + 1)) * 2 + ;
  357. COORD_SIZE
  358.  
  359.  
  360.  
  361.  
  362. * PRG.....: windows
  363. * CLASS...: windows
  364. * DESC....: Stack based windows save and restore, for 5.0
  365. * PREFIX..: win
  366. * EXPORT..: win_init()
  367. *           win_end()
  368. *           win_push()
  369. *           win_pop()
  370. * USES....:
  371. * NOTES...: Must call win_init before any pushes
  372.  
  373. #include "system.h"
  374. #include "windows.h"
  375.  
  376. STATIC scr_stk := NULLC
  377.  
  378. * NUMERIC win_size(win_coords)
  379. *
  380. * CHARACTER win_coords
  381. *
  382. * Return size of window defined by win_coords
  383. *
  384. * This could be a compiler macro, but the line would be too long ...
  385.  
  386. STATIC FUNCTION win_size(win_coords)
  387.  
  388. RETURN ((GET_B(win_coords) - GET_T(win_coords) + 1) * ;
  389. (GET_R(win_coords) - GET_L(win_coords) + 1)) * 2 + ;
  390. COORD_SIZE
  391.  
  392. * CHARACTER win_save(t, l, b, r)
  393. *
  394. * NUMERIC t, l, b, r   - Window coordinates. Optional, default to
  395. *                        0, 0, 24, 79 (full screen)
  396. *
  397. * Return combined coordinates and screen area
  398.  
  399. STATIC FUNCTION win_save(t, l, b, r)
  400.  
  401. * Assign defaults to optional parameters
  402. P_DEF(t, 0)
  403. P_DEF(l, 0)
  404. P_DEF(b, 24)
  405. P_DEF(r, 79)
  406.  
  407. RETURN chr(t) + chr(l) + chr(b) + chr(r) + ;
  408. savescreen(t, l, b, r)
  409.  
  410.  
  411. * VOID win_rest(scr_str)
  412. *
  413. * CHARACTER scr_str    - A character string returned from win_save
  414. *
  415. * Restore sceeen from a packed screen structure ...
  416.  
  417. STATIC FUNCTION win_rest(scr_str)
  418.  
  419. restscreen(GET_T(scr_str), GET_L(scr_str), ;
  420. GET_B(scr_str), GET_R(scr_str), ;
  421. GET_WIN(scr_str))
  422.  
  423. RETURN VOID
  424.  
  425.  
  426. * VOID win_push(t, l, b, r)
  427. *
  428. * NUMERIC t, l, b, r   - Window coordinates. Optional.
  429. *                      - Default to 0, 0, 24, 79 (full screen)
  430. *
  431. *
  432. * Push a screen structure on scr_stk
  433.  
  434. FUNCTION win_push(t, l, b, r)
  435.  
  436.    * Assign defaults to optional parameters
  437.    P_DEF(t, 0)
  438.    P_DEF(l, 0)
  439.    P_DEF(b, 24)
  440.    P_DEF(r, 79)
  441.  
  442.    * Push on stack (LHS of string)
  443.    scr_stk = win_save(t, l, b, r) + scr_stk
  444.  
  445. RETURN VOID
  446.  
  447.  
  448. * VOID win_pop()
  449. *
  450. * Pop a screen structure off scr_stk, restoring screen
  451.  
  452. FUNCTION win_pop
  453.  
  454.    LOCAL saved_scr_len
  455.  
  456.    saved_scr_len = win_size(scr_stk)
  457.  
  458.    win_rest(substr(scr_stk, 1, saved_scr_len))
  459.  
  460.    * pop off stack
  461.    scr_stk = substr(scr_stk, saved_scr_len + 1)
  462.  
  463. RETURN VOID
  464.  
  465.  
  466.  
  467.  
  468. * PRG.....: fwindows
  469. * CLASS...: windows
  470. * DESC....: File based windows save and restore
  471. * PREFIX..: win
  472. * EXPORT..: win_init()
  473. *           win_end()
  474. *           win_push()
  475. *           win_pop()
  476. * USES....:
  477. * NOTES...: Must call win_init before any pushes
  478.  
  479. #include "system.h"
  480. #include "windows.h"
  481. #include "files.h"
  482.  
  483. #define LEN_PTR 5
  484. #define FTELL(f_handle) fseek(f_handle, 0, SEEK_CUR)
  485.  
  486. STATIC f_ptrs := NULLC                           && The pointers stack
  487. STATIC f_handle                                  && The file handle
  488.  
  489. * CHARACTER win_save(t, l, b, r)
  490. *
  491. * NUMERIC t, l, b, r   - Window coordinates. Optional, default to
  492. *                        0, 0, 24, 79 (full screen)
  493. *
  494. * Return combined coordinates and screen area
  495.  
  496. STATIC FUNCTION win_save(t, l, b, r)
  497.  
  498. * Assign defaults to optional parameters
  499. P_DEF(t, 0)
  500. P_DEF(l, 0)
  501. P_DEF(b, 24)
  502. P_DEF(r, 79)
  503.  
  504. RETURN chr(t) + chr(l) + chr(b) + chr(r) + ;
  505. savescreen(t, l, b, r)
  506.  
  507.  
  508. * VOID win_rest(scr_str)
  509. *
  510. * CHARACTER scr_str    - A character string returned from win_save
  511. *
  512. * Restore sceeen from a packed screen structure ...
  513.  
  514. STATIC FUNCTION win_rest(scr_str)
  515.  
  516. restscreen(GET_T(scr_str), GET_L(scr_str), ;
  517. GET_B(scr_str), GET_R(scr_str), ;
  518. GET_WIN(scr_str))
  519.  
  520. RETURN VOID
  521.  
  522.  
  523. * NUMERIC win_size()
  524. *
  525. * PARAM win_coords
  526. *
  527. * Return size of window at current file position
  528.  
  529. STATIC FUNCTION win_size
  530.  
  531. LOCAL save_pos, win_coords
  532.  
  533. * we can't disturb current file position. Save it first ...
  534. save_pos = FTELL(f_handle)
  535.  
  536. * allocate space for coordinates and read them
  537. win_coords = space(COORD_SIZE)
  538. fread(f_handle, @win_coords, len(win_coords))
  539.  
  540. * now reposition file pointer
  541. fseek(f_handle, save_pos)
  542.  
  543. RETURN ((GET_B(win_coords) - GET_T(win_coords) + 1) * ;
  544. (GET_R(win_coords) - GET_L(win_coords) + 1)) * 2 + ;
  545. COORD_SIZE
  546.  
  547.  
  548. * VOID win_init()
  549. *
  550. * Initialization of screen stack
  551.  
  552. FUNCTION win_init
  553.  
  554.    f_handle = fcreate("_fwindow")
  555.  
  556. RETURN VOID
  557.  
  558.  
  559. * VOID win_end()
  560. *
  561. * Release this Class's data
  562.  
  563. FUNCTION win_end
  564.  
  565.    fclose(f_handle)
  566.  
  567. RETURN VOID
  568.  
  569.  
  570. * VOID win_push(t, l, b, r)
  571. *
  572. * NUMERIC t, l, b, r   - Window coordinates. Optional.
  573. *                      - Default to 0, 0, 24, 79 (full screen)
  574. *
  575. *
  576. * Push a screen structure on scr_stk
  577.  
  578. FUNCTION win_push(t, l, b, r)
  579.  
  580.    * Assign defaults to optional parameters
  581.    P_DEF(t, 0)
  582.    P_DEF(l, 0)
  583.    P_DEF(b, 24)
  584.    P_DEF(r, 79)
  585.  
  586.    * Push current file position onto pointers stack
  587.    f_ptrs = str(FTELL(f_handle), LEN_PTR) + f_ptrs
  588.  
  589.    * Write to file
  590.    fwrite(f_handle, win_save(t, l, b, r))
  591.  
  592. RETURN VOID
  593.  
  594.  
  595. * VOID win_pop()
  596. *
  597. * Pop a screen structure off scr_stk, restoring screen
  598.  
  599. FUNCTION win_pop
  600.  
  601.    LOCAL f_ptr, saved_scr_len, win
  602.  
  603.    * Pop pointers
  604.    f_ptr = val(substr(f_ptrs, 1, LEN_PTR))
  605.    f_ptrs = substr(f_ptrs, LEN_PTR + 1)
  606.  
  607.    * Seek to start of this saved entry
  608.    fseek(f_handle, f_ptr)
  609.  
  610.    * Determine size so we can allocate space and read it
  611.    saved_scr_len = win_size()
  612.  
  613.    * Now read this window. Note, we cannot use freadstr here, because
  614.    * it stops with a NULL (chr(0))
  615.    win = space(saved_scr_len)
  616.    fread(f_handle, @win, len(win))
  617.  
  618.    * Restore this window
  619.    win_rest(win)
  620.  
  621.    * Now reposition file pointer
  622.    fseek(f_handle, f_ptr)
  623.  
  624. RETURN VOID
  625.  
  626.  
  627.