home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / PEX / cp / psl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-19  |  6.3 KB  |  283 lines

  1. /* $XConsortium: psl.c,v 5.1 91/02/16 09:48:36 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. /* Initialise phigs state list */
  28.  
  29. #include "phg.h"
  30.  
  31. Psl_handle
  32. phg_psl_init()
  33. {
  34.     register int i;
  35.     register Psl_handle psl;
  36.    
  37.     if ( !(psl = (Psl_handle) malloc(sizeof(Phg_state_list))) )
  38.         return(NULL);                        /* RETURN */
  39.     psl->phg_sys_state = PSYS_ST_PHCL;
  40.     psl->phg_ws_state = PWS_ST_WSCL;
  41.     psl->phg_struct_state = PSTRUCT_ST_STCL;
  42.     psl->phg_ar_state = PST_ARCL;
  43.     for ( i = 0; i < MAX_NO_OPEN_WS; i++)
  44.     psl->open_ws[i].used = 0;
  45.     for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++) {
  46.         psl->ar_files[i].used = 0;
  47.     }
  48.     psl->ar_res = PRES_UPD;
  49.     psl->retr_res = PRES_ABANDON;
  50.     psl->more_simultev = PSIMULT_NO_MORE;
  51.     psl->edit_mode = PEDIT_INSERT;
  52.     return(psl);   
  53. }
  54.  
  55. void
  56. phg_psl_destroy( psl )
  57.     Psl_handle    psl;
  58. {
  59.     if ( psl ) {
  60.     PSL_CLEAR_CUR_EVENT(psl)
  61.     free( (char *)psl);
  62.     }
  63. }
  64.  
  65. int
  66. phg_psl_inq_ws_open( psl, wsid)
  67.     register Psl_handle        psl;
  68.     register Pint        wsid;
  69.     /* return 1 if wsid is in psl's open workstation list, else 0 */
  70. {
  71.     register int    i;
  72.     int            status = 0;
  73.  
  74.     for ( i = 0; i < MAX_NO_OPEN_WS; i++) {
  75.     if ( psl->open_ws[i].used && psl->open_ws[i].wsid == wsid) {
  76.         status = 1;
  77.         break;
  78.     }
  79.     }
  80.     return status;
  81. }
  82.  
  83. int
  84. phg_psl_inq_wsids( psl, wsids)
  85.     register Psl_handle        psl;
  86.     register Pint        *wsids;
  87. {
  88.     register int    i;
  89.     int            cnt = 0;
  90.  
  91.     for ( i = 0; i < MAX_NO_OPEN_WS; i++) {
  92.     if ( psl->open_ws[i].used) {
  93.         *wsids++ = psl->open_ws[i].wsid;
  94.         ++cnt;
  95.     }
  96.     }
  97.     return cnt;
  98. }
  99.  
  100. Psl_ws_info*
  101. phg_psl_get_ws_info( psl, wsid)
  102.     register Psl_handle        psl;
  103.     register Pint        wsid;
  104. {
  105.     register int    i;
  106.     Psl_ws_info        *ws = NULL;
  107.  
  108.     for ( i = 0; i < MAX_NO_OPEN_WS; i++) {
  109.     if ( psl->open_ws[i].used && psl->open_ws[i].wsid == wsid) {
  110.         ws = &psl->open_ws[i];
  111.         break;
  112.     }
  113.     }
  114.     return ws;
  115. }
  116.  
  117. int
  118. phg_psl_ws_free_slot( psl)
  119.     register Psl_handle        psl;
  120.     /* return 1 if free slot exists, else 0 */
  121. {
  122.     register int     i;
  123.     int            status = 0;
  124.  
  125.     for ( i = 0; i < MAX_NO_OPEN_WS; i++) {
  126.     if ( !psl->open_ws[i].used) {
  127.         status = 1;
  128.         break;
  129.     }
  130.     }
  131.     return status;
  132. }
  133.  
  134. int
  135. phg_psl_add_ws( psl, wsid, connid, type) /* add ws to list of those open */
  136.     register Psl_handle        psl;
  137.     Pint            wsid;
  138.     char            *connid;
  139.     Wst                *type;
  140.     /* return 1 if wsid could be added, else 0 */
  141. {
  142.     register int     i;
  143.     int            status = 0;
  144.  
  145.     for ( i = 0; i < MAX_NO_OPEN_WS; i++) {
  146.     if ( !psl->open_ws[i].used) {
  147.         psl->open_ws[i].used = 1;
  148.         psl->open_ws[i].wsid = wsid;
  149.         psl->open_ws[i].connid = connid;
  150.         psl->open_ws[i].wstype = type;
  151.         status = 1;
  152.         break;
  153.     }
  154.     }
  155.     return status;
  156. }
  157.  
  158. void
  159. phg_psl_rem_ws( psl, wsid)    /* remove the wsid from the open ws list */
  160.     register Psl_handle        psl;
  161.     register Pint        wsid;
  162. {
  163.     register int     i,
  164.             cnt;    /* number of open workstations left */
  165.  
  166.     for ( i = 0, cnt = 0; i < MAX_NO_OPEN_WS; i++) {
  167.     if ( psl->open_ws[i].used) {
  168.         if ( psl->open_ws[i].wsid == wsid)
  169.         psl->open_ws[i].used = 0;
  170.         else
  171.         ++cnt;
  172.     }
  173.     }
  174.  
  175.     /* set the ws state if no more workstations open */
  176.     if (!cnt)
  177.     PSL_WS_STATE( psl) = PWS_ST_WSCL;
  178. }
  179.  
  180. /* Archive Functions */
  181.  
  182. int
  183. phg_psl_inq_ar_open( psl, arid)
  184.     register Psl_handle        psl;
  185.     register Pint        arid;
  186.     /* return 1 if arid is in psl's open archive list, else 0 */
  187. {
  188.     register int    i;
  189.     int            status = 0;
  190.  
  191.     if ( psl ) {
  192.     for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++) {
  193.         if ( psl->ar_files[i].used && psl->ar_files[i].arid == arid) {
  194.         status = 1;
  195.         break;
  196.         }
  197.     }
  198.     }
  199.     return status;
  200. }
  201.  
  202. Psl_ar_info*
  203. phg_psl_get_ar_info( psl, arid)
  204.     register Psl_handle        psl;
  205.     register Pint        arid;
  206. {
  207.     register int    i;
  208.     Psl_ar_info        *ar = NULL;
  209.  
  210.     if ( psl ) {
  211.     for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++) {
  212.         if ( psl->ar_files[i].used && psl->ar_files[i].arid == arid) {
  213.         ar = &psl->ar_files[i];
  214.         break;
  215.         }
  216.     }
  217.     }
  218.     return ar;
  219. }
  220.  
  221. int
  222. phg_psl_ar_free_slot( psl)
  223.     register Psl_handle        psl;
  224.     /* return 1 if free slot exists, else 0 */
  225. {
  226.     register int     i;
  227.     int            status = 0;
  228.  
  229.     for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++) {
  230.     if ( !psl->ar_files[i].used) {
  231.         status = 1;
  232.         break;
  233.     }
  234.     }
  235.     return status;
  236. }
  237.  
  238. int
  239. phg_psl_add_ar( psl, arid, fname) /* add ar to list of those open */
  240.     register Psl_handle        psl;
  241.     Pint            arid;
  242.     char            *fname;
  243.     /* return 1 if arid could be added, else 0 */
  244. {
  245.     register int     i;
  246.     int            status = 0;
  247.  
  248.     for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++) {
  249.     if ( !psl->ar_files[i].used) {
  250.         psl->ar_files[i].used = 1;
  251.         psl->ar_files[i].arid = arid;
  252.         psl->ar_files[i].fname = fname;
  253.         status = 1;
  254.         break;
  255.     }
  256.     }
  257.     return status;
  258. }
  259.  
  260. void
  261. phg_psl_rem_ar( psl, arid)    /* remove the arid from the open ar list */
  262.     register Psl_handle        psl;
  263.     register Pint        arid;
  264. {
  265.     register int     i,
  266.             cnt;    /* number of open archives left */
  267.  
  268.     for ( i = 0, cnt = 0; i < MAX_NO_OPEN_ARFILES; i++) {
  269.     if ( psl->ar_files[i].used) {
  270.         if ( psl->ar_files[i].arid == arid) {
  271.         psl->ar_files[i].used = 0;
  272.         free( (char *)psl->ar_files[i].fname);
  273.         } else {
  274.         ++cnt;
  275.         }
  276.     }
  277.     }
  278.  
  279.     /* set the ar state if no more archives open */
  280.     if (!cnt)
  281.     PSL_AR_STATE( psl) = PST_ARCL;
  282. }
  283.