home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d552 / taskpri.lha / TaskPri / TaskPri.c < prev    next >
C/C++ Source or Header  |  1991-10-28  |  5KB  |  147 lines

  1. /**
  2.    TASKPRI - lets the user change task priorities by specifying the
  3.    task NAME.
  4.  
  5.    Author:  Steve Anderson
  6.  
  7.    Date:  August 3, 1991
  8.  
  9.    This program and the accompanying source is freeware and can be used,
  10.    altered and ripped however you like.  Enjoy!
  11. **/
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <exec/types.h>
  16. #include <exec/execbase.h>
  17. #include <exec/tasks.h>
  18.  
  19. #ifdef LATTICE
  20. #include <proto/exec.h>
  21. int CXBRK(void) { return(0); }      /*  Disable Lattice CTRL/C handling  */
  22. int chkabort(void) { return(0); }   /*  really  */
  23. #endif
  24.  
  25. #define NAME_LIMIT 30
  26. #define LIMIT 60
  27.  
  28. extern struct ExecBase *SysBase;
  29. short main( int argc, char *argv[] );
  30.  
  31. short main( int argc, char *argv[] )
  32.    {
  33.       struct Task *task;
  34.       char *name;
  35.       char taskname[LIMIT][NAME_LIMIT];
  36.       short taskpri[LIMIT];
  37.       short pri;
  38.       short acount = 1;
  39.       short tcount;
  40.       short tlimit;
  41.       short nlimit = 0;
  42.       short t;
  43.       short DEFAULT = 0;  /*  0 = standard, 1 = no args, list tasks  */
  44.       short LIST = 0;     /*  0 = TaskWait list, 1 = TaskReady list  */
  45.  
  46.       if ( argc == 1 )
  47.          {
  48.             DEFAULT = 1;    /*  no argument case  */
  49.             --acount;       /*  set acount equal to zero  */
  50.          }
  51.       else if ( ((argc == 2) && (strcmp( argv[1], "?") == 0)) || (argc%2 != 1) )
  52.          {
  53.             puts("\n Usage:  TaskPri NAME PRIORITY [ [NAME PRIORITY] ... ]\n");
  54.             exit(1);
  55.          }
  56.  
  57.       while (acount < argc)                /*  while there are still arguments to process  */
  58.          {
  59.            /*  normal execution  */
  60.             if (DEFAULT == 0)              /*  standard  */
  61.                {
  62.                  /*  set name string  */
  63.                   name = argv[acount];
  64.  
  65.                  /*  convert pri argument to an integer  */
  66.                   pri = (short)strtol( argv[acount+1], NULL, 10 );
  67.  
  68.                  /*  find task # in task list  */
  69.                   tcount = acount/2 + 1;
  70.                   tlimit = tcount - 1;
  71.  
  72.                  /*  find # of previous tasks with same name  */
  73.                   for( t = tlimit; t > 0; t-- )
  74.                      if ( strcmp(argv[tcount],argv[t]) )
  75.                         --tcount;
  76.  
  77.                }  /*  end if  */
  78.  
  79.                Forbid();  /*  shut off task switching  */
  80.  
  81.               /*  search TaskWait/ThisTask lists for task names  */
  82.                task = (struct Task *)SysBase->TaskWait.lh_Head;
  83.  
  84.                while ( task->tc_Node.ln_Succ )
  85.                   {
  86.                      if (DEFAULT == 1)                  /*  if there are no command line arguments */
  87.                         {
  88.                            if(strlen(task->tc_Node.ln_Name) > (NAME_LIMIT-1))
  89.                               strncpy((char *)&taskname[nlimit][0],task->tc_Node.ln_Name,(NAME_LIMIT-1));
  90.                            else
  91.                               strcpy((char *)&taskname[nlimit][0],task->tc_Node.ln_Name);
  92.                            taskpri[nlimit] = task->tc_Node.ln_Pri;
  93.                            nlimit++;
  94.                         }
  95.                      else if ( !strcmp(name,task->tc_Node.ln_Name) )  /*  GOOD  */
  96.                         {
  97.                            if ( tcount > 1 )
  98.                               {
  99.                                  --tcount;
  100.                               }
  101.                            else
  102.                               {
  103.                                  SetTaskPri( task, pri );  /*  set new priority  */
  104.                                  Permit();                 /*  re-activate task switching  */
  105.                                  printf(" Name:  %-30s     Priority:  %3d\n", name, pri );
  106.                                  Forbid();                 /* shut off task switching  */
  107.                                  break;
  108.                               }
  109.  
  110.                         }  /*  end else if  */
  111.  
  112.                     /*  increment to next item in list  */
  113.                      task = (struct Task *)task->tc_Node.ln_Succ;
  114.  
  115.                     /*  check to see if TaskWait list is done  */
  116.                      if ( !task->tc_Node.ln_Succ )
  117.                         switch ( LIST )
  118.                            {
  119.                               case 0:
  120.                                  LIST++;
  121.                                  task = (struct Task *)SysBase->ThisTask;
  122.                                  break;
  123.                               case 1:
  124.                                  LIST++;
  125.                                  task = (struct Task *)SysBase->TaskReady.lh_Head;
  126.                                  break;
  127.  
  128.                            }  /*  end if-switch  */
  129.  
  130.                   }  /*  end while loop  */
  131.  
  132.             Permit();           /*  re-activate task switching  */
  133.             acount += 2;        /*  increment to next task  */
  134.  
  135.          }  /*  end while loop  */
  136.  
  137.       while ( (DEFAULT==1) && (nlimit>0) )      /*  PRINT tasks if no args  */
  138.          {
  139.             nlimit--;
  140.             printf(" Name:  %-30s     Priority:  %3d\n", &taskname[nlimit][0], taskpri[nlimit] );
  141.  
  142.          }  /*  end while loop  */
  143.  
  144.    }  /*  end main loop  */
  145.  
  146.   /****************************  EOF  *********************************/
  147.