home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / SWI100.ZIP / SWITCH.C next >
C/C++ Source or Header  |  1991-06-25  |  5KB  |  153 lines

  1. /*----------------------------------------------------------------------*
  2.  * Switch                                                               *
  3.  *                                                                      *
  4.  * This program allows you to modify the 'Jump' toggle in the Session   *
  5.  * Task List kept by OS/2.                                              *
  6.  *                                                                      *
  7.  * I wrote this primarily because I wanted to be able to confine the    *
  8.  * Round Robin effect of the Alt+Esc keys sequence to certain sessions. *
  9.  *                                                                      *
  10.  * This program is public domain.  All I ask is that if you modify this *
  11.  * program and make it available to the public that you do *not* modify *
  12.  * this header nor remove my copyright logo from the program, but only  *
  13.  * extend the history modification list.  Also-- please send me a       *
  14.  * copy!!                                                               *
  15.  *                                                                      *
  16.  * Modification History                                                 *
  17.  *                                                                      *
  18.  * 25-Jun-1991  Dave Fisher, 1:170/110@fidonet                          *
  19.  *    1.00 : Original version release.                                  *
  20.  *                                                                      *
  21.  *----------------------------------------------------------------------*/
  22.  
  23. #define INCL_WINSWITCHLIST
  24. #define INCL_WINPROGRAMLIST
  25.  
  26. #include <os2.h>
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <malloc.h>
  31. #include <string.h>
  32.  
  33. #define VERSION "1.00"
  34.  
  35. void display_tasklist( SWBLOCK *tasklist, int numitems );
  36. static void logo( void );
  37.  
  38. void main( int argc, char **argv, char **envp )
  39. {
  40.     HAB hab;
  41.     int numitems;
  42.     int status;
  43.     SWBLOCK *tasklist;
  44.     int tasklistsize;
  45.     char optionstr[80];
  46.     int num;
  47.  
  48.     logo();
  49.  
  50.     hab = WinInitialize(0);     /* get anchor block handle */
  51.  
  52.     numitems = WinQuerySwitchList( hab, (SWBLOCK *) 0, 0 );
  53.  
  54.     if ( numitems <= 0 )
  55.         {
  56.         printf("No items found in Task List\n");
  57.         exit(1);
  58.         }
  59.  
  60.     tasklistsize = (numitems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  61.  
  62.     tasklist = (SWBLOCK *) malloc( tasklistsize );
  63.  
  64.     if ( !tasklist )
  65.         {
  66.         printf("Could not memory allocate task list\n");
  67.         exit(1);
  68.         }
  69.  
  70.     status = WinQuerySwitchList( hab, tasklist, tasklistsize );
  71.  
  72.     if ( !status )
  73.         {
  74.         printf("Could not query Task List\n");
  75.         exit(1);
  76.         }
  77.  
  78.     while( 1 )
  79.         {
  80.         display_tasklist( tasklist, numitems );
  81.  
  82.         printf("\n\nPress number to toggle jump status (Enter=quit): ");
  83.         gets( optionstr );
  84.  
  85.         num = atoi(optionstr);
  86.  
  87.         if ( num <= 0 )
  88.             break;
  89.  
  90.         if ( num > numitems )
  91.             continue;
  92.  
  93.         num--;
  94.  
  95.         switch( tasklist->aswentry[num].swctl.fbJump )
  96.             {
  97.             case SWL_JUMPABLE :
  98.                 tasklist->aswentry[num].swctl.fbJump = SWL_NOTJUMPABLE;
  99.                 break;
  100.             case SWL_NOTJUMPABLE :
  101.                 tasklist->aswentry[num].swctl.fbJump = SWL_JUMPABLE;
  102.                 break;
  103.             }
  104.  
  105.         status = WinChangeSwitchEntry( tasklist->aswentry[num].hswitch,
  106.                                        &(tasklist->aswentry[num].swctl) );
  107.  
  108.         if ( status != 0 )
  109.             {
  110.             printf("Could not modify entry '%s'\n",
  111.                             tasklist->aswentry[num].swctl.szSwtitle );
  112.             }
  113.         }
  114.  
  115.     WinTerminate(hab);
  116.  
  117.     exit(0);
  118. }
  119.  
  120.  
  121. void display_tasklist( SWBLOCK* tasklist, int numitems )
  122. {
  123.     register int i;
  124.     char jumpstr[40];
  125.  
  126.     printf("\n");
  127.  
  128.     for( i=0; i < numitems; i++ )
  129.         {
  130.         switch( tasklist->aswentry[i].swctl.fbJump )
  131.             {
  132.             case SWL_JUMPABLE :
  133.                 strcpy( jumpstr, "Jumpable" );
  134.                 break;
  135.             case SWL_NOTJUMPABLE :
  136.                 strcpy( jumpstr, "Not Jumpable" );
  137.                 break;
  138.             default :
  139.                 strcpy( jumpstr, "???" );
  140.                 break;
  141.             }
  142.  
  143.         printf("[%02d] [%12s] %s\n", i+1, jumpstr,
  144.             tasklist->aswentry[i].swctl.szSwtitle );
  145.         }
  146. }
  147.  
  148. static void logo( void )
  149. {
  150.     printf( "\nSwitch - Session Task List Utility, Version %s\n", VERSION);
  151.     printf( "Copyright 1991 by Dave Fisher, 1:170/110@fidonet.  All rights reserved.\n");
  152. }
  153.