アットウィキロゴ

vmstat_vmstat.c_main

memo


処理の流れ


   576 int main(int argc, char *argv[]) {
   577   char partition[16];
   578   argc=0; /* redefined as number of integer arguments */
   579   for (argv++;*argv;argv++) {
   580     if ('-' ==(**argv)) {
   581       switch (*(++(*argv))) {
   582
   583       case 'V':
   584         display_version();
   585         exit(0);
   586       case 'd':
   587         statMode |= DISKSTAT;
   588         break;
   589       case 'a':
   590         /* active/inactive mode */
   591         a_option=1;
   592         break;
   593       case 'f':
   594         // FIXME: check for conflicting args
   595         fork_format();
   596         exit(0);
   597       case 'm':
   598         statMode |= SLABSTAT;
   599         break;
   600       case 'D':
   601         statMode |= DISKSUMSTAT;
   602         break;
   603       case 'n':
   604         /* print only one header */
   605         moreheaders=FALSE;
   606         break;
   607       case 'p':
   608         statMode |= PARTITIONSTAT;
   609         if (argv[1]){
   610                    ++argv;
   611                    sprintf(partition, "%s", *argv);
   612          }else{fprintf(stderr, "-p requires an argument\n");
   613                exit(EXIT_FAILURE);
   614         }
   615         break;
   616       case 'S':
   617         if (argv[1]){
   618               ++argv;
   619                 if (!strcmp(*argv, "k")) dataUnit=UNIT_k;
   620                 else if (!strcmp(*argv, "K")) dataUnit=UNIT_K;
   621                 else if (!strcmp(*argv, "m")) dataUnit=UNIT_m;
   622                 else if (!strcmp(*argv, "M")) dataUnit=UNIT_M;
   623                 else {fprintf(stderr, "-S requires k, K, m or M (default is kb)\n");
   624                      exit(EXIT_FAILURE);
   625                 }
   626                 strcpy(szDataUnit, *argv);
   627          }else {fprintf(stderr, "-S requires an argument\n");
   628                 exit(EXIT_FAILURE);
   629          }
   630         break;
   631       case 's':
   632         statMode |= VMSUMSTAT;
   633         break;
   634       default:
   635         /* no other aguments defined yet. */
   636         usage();
   637       }
   638    }else{
   639       argc++;
   640       switch (argc) {
   641       case 1:
   642         if ((sleep_time = atoi(*argv)) == 0)
   643          usage();
   644        num_updates = ULONG_MAX;
   645        break;
   646       case 2:
   647         num_updates = atol(*argv);
   648        break;
   649       default:
   650        usage();
   651       } /* switch */
   652   }
   653 }
   654   if (moreheaders) {
   655       int tmp=winhi()-3;
   656       height=((tmp>0)?tmp:22);
   657   }
   658   setlinebuf(stdout);
   659   switch(statMode){
   660         case(VMSTAT):        new_format();
   661                              break;
   662         case(VMSUMSTAT):     sum_format();
   663                              break;
   664         case(DISKSTAT):      diskformat();
   665                              break;
   666         case(PARTITIONSTAT): if(diskpartition_format(partition)==-1)
   667                                   printf("Partition was not found\n");
   668                              break;
   669         case(SLABSTAT):      slabformat();
   670                              break;
   671         case(DISKSUMSTAT):   disksum_format();
   672                              break;
   673         default:             usage();
   674                              break;
   675   }
   676   return 0;
   677 }
   678
   679

source


   576 int main(int argc, char *argv[]) {
   577   char partition[16];
   578   argc=0; /* redefined as number of integer arguments */
   579   for (argv++;*argv;argv++) {
   580     if ('-' ==(**argv)) {
   581       switch (*(++(*argv))) {
   582
   583       case 'V':
   584         display_version();
   585         exit(0);
   586       case 'd':
   587         statMode |= DISKSTAT;
   588         break;
   589       case 'a':
   590         /* active/inactive mode */
   591         a_option=1;
   592         break;
   593       case 'f':
   594         // FIXME: check for conflicting args
   595         fork_format();
   596         exit(0);
   597       case 'm':
   598         statMode |= SLABSTAT;
   599         break;
   600       case 'D':
   601         statMode |= DISKSUMSTAT;
   602         break;
   603       case 'n':
   604         /* print only one header */
   605         moreheaders=FALSE;
   606         break;
   607       case 'p':
   608         statMode |= PARTITIONSTAT;
   609         if (argv[1]){
   610                    ++argv;
   611                    sprintf(partition, "%s", *argv);
   612          }else{fprintf(stderr, "-p requires an argument\n");
   613                exit(EXIT_FAILURE);
   614         }
   615         break;
   616       case 'S':
   617         if (argv[1]){
   618               ++argv;
   619                 if (!strcmp(*argv, "k")) dataUnit=UNIT_k;
   620                 else if (!strcmp(*argv, "K")) dataUnit=UNIT_K;
   621                 else if (!strcmp(*argv, "m")) dataUnit=UNIT_m;
   622                 else if (!strcmp(*argv, "M")) dataUnit=UNIT_M;
   623                 else {fprintf(stderr, "-S requires k, K, m or M (default is kb)\n");
   624                      exit(EXIT_FAILURE);
   625                 }
   626                 strcpy(szDataUnit, *argv);
   627          }else {fprintf(stderr, "-S requires an argument\n");
   628                 exit(EXIT_FAILURE);
   629          }
   630         break;
   631       case 's':
   632         statMode |= VMSUMSTAT;
   633         break;
   634       default:
   635         /* no other aguments defined yet. */
   636         usage();
   637       }
   638    }else{
   639       argc++;
   640       switch (argc) {
   641       case 1:
   642         if ((sleep_time = atoi(*argv)) == 0)
   643          usage();
   644        num_updates = ULONG_MAX;
   645        break;
   646       case 2:
   647         num_updates = atol(*argv);
   648        break;
   649       default:
   650        usage();
   651       } /* switch */
   652   }
   653 }
   654   if (moreheaders) {
   655       int tmp=winhi()-3;
   656       height=((tmp>0)?tmp:22);
   657   }
   658   setlinebuf(stdout);
   659   switch(statMode){
   660         case(VMSTAT):        new_format();
   661                              break;
   662         case(VMSUMSTAT):     sum_format();
   663                              break;
   664         case(DISKSTAT):      diskformat();
   665                              break;
   666         case(PARTITIONSTAT): if(diskpartition_format(partition)==-1)
   667                                   printf("Partition was not found\n");
   668                              break;
   669         case(SLABSTAT):      slabformat();
   670                              break;
   671         case(DISKSUMSTAT):   disksum_format();
   672                              break;
   673         default:             usage();
   674                              break;
   675   }
   676   return 0;
   677 }
   678
   679
最終更新:2009年02月11日 22:11
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。