コード例 #1
0
ファイル: hb.c プロジェクト: solt87/hbc
int main ( int argc, char* argv[] )
{
    int w, h, a;
    char* sex;

    if ( argc == 1 ) {
        disp_help () ;
        return 1;
    }
    if ( argv[1][0] != 'm' && argv[1][0] != 'f' ) {
        disp_help () ;
        return 1;
    }

    w = atoi ( argv[2] );
    h = atoi ( argv[3] );
    a = atoi ( argv[4] );
    sex = argv[1];

    printf ( "%.2f kcal/day\n", ( sex[0] == 'm' ) ? ( BF_M + ( WF_M * w ) + ( HF_M * h ) - ( AF_M * a ) ) : 
                                                    ( BF_F + ( WF_F * w ) + ( HF_F * h ) - ( AF_F * a ) ) );

    return 0;
}
コード例 #2
0
ファイル: csplit.c プロジェクト: Eric-Schnipke/snippets
int main (int argc, char *argv[])
{
  char     sepchar = SEP_CDEF;
  char     outfile[MAXFSPEC + 1];
  char    *sptr    = 0;
  int      argndx  = 1;
  int      chr     = 0;
  int      extract = B_FALSE;
  int      length  = LENDEF;
  int      retc    = 0;
  int      tabstop = TABDEF;
  int      width   = WIDDEF;


  setbuf (stdout, 0);                  /* DN2: buffered output fix */
  printf ("\nCSplit %s  (pd) 1993-1996 by Fred Cole\n", VERSION);
  printf ("This executable program is public domain.\n\n");

  if (1 == argc)
  {
    disp_help ();
    return SYNTAX;
  }

  while (('/' == argv[argndx][0]) || ('-' == argv[argndx][0]))
  {
    chr = toupper (argv[argndx][1]);

    switch (chr)
    {
      case '?':
      case 'H':                   /* /H,/? help option */
        disp_help ();
        return SYNTAX;

      case 'X':                   /* /X extract option */
        extract = B_TRUE;
        break;

      case 'T':                   /* /T tab option */
        tabstop = atoi (&argv[argndx][2]);

        if ((tabstop < TABMIN) || (tabstop > TABMAX))
          printf ("Invalid tab parameter \"%s\" (%d-%d).\n", argv[argndx], TABMIN, TABMAX);

        if (tabstop < TABMIN)
          tabstop = TABMIN;
        else if (tabstop > TABMAX)
          tabstop = TABMAX;

        break;

      case 'W':                   /* /W width option */
        width = atoi (&argv[argndx][2]);

        if ((width < WIDMIN) || (width > WIDMAX))
          printf ("Invalid width parameter \"%s\" (%d-%d).\n", argv[argndx], WIDMIN, WIDMAX);

        if (width < WIDMIN)
          width = WIDMIN;
        else if (width > WIDMAX)
          width = WIDMAX;

        break;

      case 'L':                   /* /L length option */
        if (('0' == argv[argndx][2]) && ('\0' == argv[argndx][3]))
          length = 0;
        else
        {
          length = atoi (&argv[argndx][2]);

          if ((length < LENMIN) || ((unsigned)length > LENMAX))
            printf ("Invalid length parameter \"%s\" (0,%d-%d).\n", argv[argndx], LENMIN, LENMAX);

          if (length < LENMIN)
            length = LENDEF;
          else if ((unsigned)length > LENMAX)
            length = LENMAX;
        }

        break;

      case 'S':                   /* /S separator character option */
        sscanf (&argv[argndx][2], "%c", &sepchar);

        if (0 == isgraph (sepchar))
        {
          printf ("Invalid input parameter \"%s\".\n", argv[argndx]);
          sepchar = SEP_CDEF;
        }
        break;

      default:
        printf ("Ignoring unknown input parameter \"%s\".\n", argv[argndx]);
    }
    ++argndx;
  }

  if (B_TRUE == extract)
  {
    if (argndx == argc)
    {
      printf ("No file argument specified for extraction.\n");
      return SYNTAX;
    }

    /* AR: handle multiple files; break on error */
    for ( ; argndx < argc; ++argndx)
      if (NOERR != (retc = extr_file (argv[argndx], sepchar)))
        break;

    cleanup ();
    return retc;
  }

  if ((argc - argndx) < 2)
  {
    printf ("Missing input and/or output file name arguments.\n");
    disp_help ();
    return SYNTAX;
  }

  if (NULL != (sptr = strrchr (argv[argndx], '\\')))  /* ignore path */
  {
    if (NULL != (sptr = strchr (sptr, '.')))
      *sptr = '\0';                              /* truncate any ext */
  }
  else if (NULL != (sptr = strchr (argv[argndx], '.')))
  {
    *sptr = '\0';                                /* truncate any ext */
  }

  if (strlen (argv[argndx]) > MAXFSPEC)
  {
    printf ("Output file name argument too long.\n");
    return SYNTAX;
  }

  strncpy (outfile, argv[argndx], MAXFSPEC);
  outfile[MAXFSPEC] = '\0';                      /* ensure termination */

  if (NOERR != (retc = init_list (argc, argv, ++argndx)))
  {
    cleanup ();
    return retc;
  }

  retc = split_src (head, outfile, length, width, tabstop, sepchar);
  cleanup ();
  return retc;
}
コード例 #3
0
ファイル: ohelp.cpp プロジェクト: mecirt/7k2
//----------- Begin of function Help::disp --------//
//
// Display help message on the given screen location.
//
void Help::disp()
{
	//---- first check if we should disp the help now ------//

	if( !should_disp() )
	{
		disp_short_help(&vga_back);  // check if we need the short one instead
		help_code[0] = NULL;	// reset it everytime after displaying, if the mouse is still on the button, help_code will be set again.
		custom_help_title[0] = NULL;
		return;
	}

	int i;
	HelpInfo* helpInfo = NULL;

	// ------ button help -------//

	if( help_code[0] )
	{
		//--------- locate the help and display it ----------//

		helpInfo = help_info_array + (i = first_help_by_help_code);
		for( ; i<last_help_by_help_code; i++, helpInfo++ )
		{
			if( helpInfo->help_code[0] == help_code[0] &&
				 strcmp( helpInfo->help_code, help_code )==0 )
			{
				break;
			}
		}

		if( i >= last_help_by_help_code )		// not found
			helpInfo = NULL;
	}

	//-------- custom help ---------//

	else if( custom_help_title[0] )
	{
	}

	//-------- other interface help ---------//

	else
	{
		//--------- locate the help and display it ----------//

		helpInfo = help_info_array + (i = first_help_by_area);
		for( ; i<last_help_by_area ; i++, helpInfo++ )
		{
			if( !helpInfo->help_code[0] && mouse.in_area( helpInfo->calc_x1(), helpInfo->area_y1,
				helpInfo->calc_x2(), helpInfo->area_y2) && 
				( (helpInfo->monster_human_interface == 1 && config.race_id < 0) ||
					(helpInfo->monster_human_interface == 2 && config.race_id > 0) ||
					(helpInfo->monster_human_interface == 0) ) )
			{
				break;
			}
		}

		if( i >= last_help_by_area )		// not found
			helpInfo = NULL;
	}

	//-------- button help ---------//

	if( help_code[0] && helpInfo )
	{
		disp_help( help_x, help_y,
			helpInfo->help_title, helpInfo->help_text_ptr );

//		help_code[0] = NULL;		// reset it everytime after displaying, if the mouse is still on the button, help_code will be set again.
	}

	//-------- custom help ---------//

	else if( custom_help_title[0] )
	{
		disp_help(help_x, help_y, custom_help_title, custom_help_detail);
//		custom_help_title[0] = NULL;
	}

	//-------- other interface help ---------//

	else if( helpInfo )
	{
		disp_help( (helpInfo->calc_x1()+helpInfo->calc_x2())/2,
					(helpInfo->area_y1+helpInfo->area_y2)/2,
					 helpInfo->help_title, helpInfo->help_text_ptr );
	}
}
コード例 #4
0
ファイル: Ohelp.cpp プロジェクト: ndilday/virtualu
//----------- Begin of function Help::disp --------//
//!
//! Display help message on the given screen location.
//!
void Help::disp() {
    //---- first check if we should disp the help now ------//

    if( !should_disp() ) {
	// display short help here  // begin ##chwg031199
	//		disp_short_help(&vga_front);
	///////////////////////////////// end ##chwg031199
	help_code[0] = NULL;                          // reset it everytime after displaying, if the mouse is still on the button, help_code will be set again.
	custom_help_title[0] = NULL;
	return;
    }

    int i;
    HelpInfo* helpInfo = NULL;

    // ------ button help -------//

    if( help_code[0] ) {
	//--------- locate the help and display it ----------//

	helpInfo = help_info_array + (i = first_help_by_help_code);
	for( ; i<last_help_by_help_code; i++, helpInfo++ ) {
	    if( helpInfo->help_code[0] == help_code[0] &&
		strcmp( helpInfo->help_code, help_code )==0 ) {
		break;
	    }
	}

	if( i >= last_help_by_help_code )             // not found
	    helpInfo = NULL;
    }

    //-------- custom help ---------//

    else if( custom_help_title[0] ) {
    }

    //-------- other interface help ---------//

    else {
	//--------- locate the help and display it ----------//

	//		switch( current_display_mode.mode_id )
	//		{
	//		case MODE_ID_800x600x16:
	helpInfo = help_info_array + (i = first_help_by_area);
	for( ; i<last_help_by_area ; i++, helpInfo++ ) {
	    if( !helpInfo->help_code[0] && mouse.in_area( helpInfo->area800x600_x1, helpInfo->area800x600_y1,
							  helpInfo->area800x600_x2, helpInfo->area800x600_y2)
		//					( (helpInfo->monster_human_interface == 1 && config.race_id < 0) ||
		//						(helpInfo->monster_human_interface == 2 && config.race_id > 0) ||
		//						(helpInfo->monster_human_interface == 0) )
		) {
		break;
	    }
	}
	/*			break;

				case MODE_ID_1024x768x16:
				helpInfo = help_info_array + (i = first_help_by_area);
				for( ; i<last_help_by_area ; i++, helpInfo++ )
				{
				if( !helpInfo->help_code[0] && mouse.in_area( helpInfo->area1024x768_x1, helpInfo->area1024x768_y1,
				helpInfo->area1024x768_x2, helpInfo->area1024x768_y2) &&
				( (helpInfo->monster_human_interface == 1 && config.race_id < 0) ||
				(helpInfo->monster_human_interface == 2 && config.race_id > 0) ||
				(helpInfo->monster_human_interface == 0) ) )
				{
				break;
				}
				}
				break;
				default:
				err_here();
				}
	*/
	if( i >= last_help_by_area )                  // not found
	    helpInfo = NULL;
    }

    //-------- button help ---------//

    if( help_code[0] && helpInfo ) {
	disp_help( help_x, help_y,
		   helpInfo->help_title, helpInfo->help_text_ptr );

	help_code[0] = NULL;                          // reset it everytime after displaying, if the mouse is still on the button, help_code will be set again.
    }

    //-------- custom help ---------//

    else if( custom_help_title[0] ) {
	disp_help(help_x, help_y, custom_help_title, custom_help_detail);
	custom_help_title[0] = NULL;
    }

    //-------- other interface help ---------//

    else if( helpInfo ) {
	/*		switch( current_display_mode.mode_id )
			{
			case MODE_ID_800x600x16:
	*/
	disp_help( (helpInfo->area800x600_x1+helpInfo->area800x600_x2)/2,
		   (helpInfo->area800x600_y1+helpInfo->area800x600_y2)/2,
		   helpInfo->help_title, helpInfo->help_text_ptr );
	/*			break;

				case MODE_ID_1024x768x16:
				disp_help( (helpInfo->area1024x768_x1+helpInfo->area1024x768_x2)/2,
				(helpInfo->area1024x768_y1+helpInfo->area1024x768_y2)/2,
				helpInfo->help_title, helpInfo->help_text_ptr );
				break;

				default:
				err_here();
				}
	*/
    }
}
コード例 #5
0
ファイル: uidisp.c プロジェクト: smcameron/corewar
void display_cycle(void)
{
    unsigned long counter;
    int ch;

    counter = loopDelay;
    while (--counter);

    if (!(cycle & keyDelay)) {

#if defined(DJGPP) || defined(WATCOM)
#if defined(DOSALLGRAPHX)
	if (displayMode == TEXT)
#ifdef CONIOGRAPHX
	    CacheScreenUpdate(Screen[CORE_PAGE]);
#else
	    ScreenUpdate((void *) Screen[CORE_PAGE]);
#endif
#else
#if defined(DOSTXTGRAPHX)
#ifdef CONIOGRAPHX
	CacheScreenUpdate(Screen[CORE_PAGE]);
#else
	ScreenUpdate((void *) Screen[CORE_PAGE]);
#endif
#endif				/* DOSTXTGRAPHX */
#endif				/* DOSALLGRAPHX */
#endif				/* DJGPP */

#if defined(DOSALLGRAPHX)
	if (displayMode != TEXT)
	    bgi_update_cycle_meter();
#else
#if defined(DOSGRXGRAPHX)
	bgi_update_cycle_meter();
#endif
#endif
	if (KEYPRESSED && !inputRedirection) {
	    switch (ch = getch()) {
	    case '0':
		displayLevel = 0;
		break;
	    case '1':
		displayLevel = 1;
		break;
	    case '2':
		displayLevel = 2;
		break;
	    case '3':
		displayLevel = 3;
		break;
	    case '4':
		displayLevel = 4;
		break;
	    case 'd':
		debugState = STEP;
		/* stepping = FALSE; */ break;
	    case '>':
		if (displaySpeed > 0) {
		    --displaySpeed;
		    loopDelay = loopDelayAr[displaySpeed];
		    keyDelay = keyDelayAr[displaySpeed];
		}
		break;
	    case '<':
		if (displaySpeed < SPEEDLEVELS - 1) {
		    ++displaySpeed;
		    loopDelay = loopDelayAr[displaySpeed];
		    keyDelay = keyDelayAr[displaySpeed];
		}
		break;
	    case ' ':
	    case 'r':
#if defined(DOSALLGRAPHX)
		if (displayMode == TEXT)
		    text_display_clear();
		else
		    bgi_clear_arena();
#else
#if defined(DOSTXTGRAPHX)
		text_display_clear();
#else
		bgi_clear_arena();
#endif
#endif
		break;
	    case 27:		/* escape */
	    case 'q':
		display_close();
		Exit(USERABORT);
#if defined(DOSALLGRAPHX)
	    case 'v':
		if (displayMode == TEXT)
		    displayMode = GRX;
		else
		    bgi_display_close(NOWAIT);
		display_init();
		break;
#endif
#if 0
#if defined(DOSALLGRAPHX)
	    case '?':
	    case 'h':
		if (displayMode == TEXT)
		    disp_help();
		break;
#else
#if defined(DOSTXTGRAPHX)
	    case '?':
	    case 'h':
		disp_help();
		break;
#endif
#endif
#endif				/* 0 */
	    default:
		if (ch > 32 && ch < 128)
		    ch += 128;
		ungetch(ch);
		debugState = STEP;
		break;
	    }
#if defined(DOSALLGRAPHX)
	    if (displayMode != TEXT)
		write_menu();
#else
#if defined(DOSGRXGRAPHX)
	    write_menu();
#endif
#endif
	}
    }
}
コード例 #6
0
ファイル: main.c プロジェクト: rinrinne/getcdaudio
int
main(int argc, char *argv[])
{
  int BUF_FRAMES = 44100 * 600;

  GCA_T gca;
  SF_INFO sinfo;
  sf_count_t st_frame, ed_frame, cnt_frames;
  sf_count_t frames;
  int datasize;
  int optchar;
  int mode_info = 0;
  opterr = 0;

  memset(&gca, 0, sizeof(GCA_T));

  while((optchar = getopt(argc, argv, "b:e:o:ih")) != -1) {
    switch(optchar) {
      case 'b':
      case 'e':
        if(check_frame_format(optarg) != 0) {
          fprintf(stderr, "\"%s\" is invalid format for -%c", optarg, optchar);
          exit(EXIT_FAILURE);
        } else {
          if (optchar == 'b') {
            gca.st = strdup(optarg);
          } else {
            gca.ed = strdup(optarg);
          }
        }
        break;
      case 'o':
        gca.fname = strdup(optarg);
        break;
      case 'i':
        mode_info = 1;
        break;
      case 'h':
      case '?':
      default:
        disp_help();
        exit(EXIT_SUCCESS);
        break;
    }
  }

  if (argv[optind] == NULL) {
    fprintf(stderr, "File is not specified.\n");
    exit(EXIT_FAILURE);
  }

  // open input sound file
  gca.sf = sf_open(argv[optind], SFM_READ, &sinfo);

  // decode frame
  st_frame = str2frame(gca.st, sinfo.samplerate);
  ed_frame = str2frame(gca.ed, sinfo.samplerate);
  cnt_frames = ed_frame - st_frame;

  if (cnt_frames < 0) {
    fprintf(stderr, "Begin frame is later than end.\n");
    close_handles(&gca);
    exit(EXIT_FAILURE);
  }
  
  if (mode_info == 1) {
    disp_info(&sinfo);
    printf("Specified count of frames: %d\n", (int)cnt_frames);
    close_handles(&gca);
    exit(EXIT_SUCCESS);
  }


  // get buffer
  datasize = sizeof(short) * sinfo.channels * BUF_FRAMES;
  gca.audiodata = (short *)malloc(datasize);

  // seek frames
  sf_seek(gca.sf, st_frame, SEEK_SET);

  // open output sndfile
  if (gca.fname != NULL) {
    gca.fp = fopen(gca.fname, "w");
    if (gca.fp == NULL) {
      fprintf(stderr, "%s\n", strerror(errno));
      close_handles(&gca);
      exit(EXIT_FAILURE);
    }
  } else {
    gca.fp = stdout;
  }

  // read frame
  while(cnt_frames > 0) {
    frames = sf_readf_short(gca.sf, gca.audiodata, BUF_FRAMES);
    if (frames > cnt_frames) {
      fwrite(gca.audiodata, sizeof(short), cnt_frames * sinfo.channels, gca.fp);
    } else {
      fwrite(gca.audiodata, sizeof(short), frames * sinfo.channels, gca.fp);
    }
    cnt_frames -= frames;
  }

  close_handles(&gca);

  return 0;
}