📄 uparse.c
字号:
/***************************************************************************** uparse.c --** Sample command line parser for Train demo*****************************************************************************/#include <g_sys.h>#include <string.h>#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <g_consts.h>#include <g_file.h>#include <gv_env.h>#include <gv_types.h>#include <gv_user.h>#include <gv_cmd.h>#include <gv_imp.h>#include <g_msg.h>#include <tgifts.h>#include "train.h"#include "hostdata.h"/* Globals */G_Name pcf_train_file = ""; /* If specified, becomes our train */G_Boolean pcf_detail_texture = G_TRUE; /* G_TRUE to allow detail texture */G_Boolean pcf_gfx = G_TRUE; /* Graphics are on by default */G_Boolean pcf_pause = G_FALSE; /* If G_TRUE, runtime will pause */G_Boolean pcf_realtime = G_TRUE; /* G_FALSE to run wo/real-time rates */G_Boolean pcf_record = G_FALSE; /* G_TRUE to record ownship object */#if G_SYS_SGLG_Boolean pcf_cursor = G_TRUE; /* G_TRUE to draw our own mouse cursor */#elseG_Boolean pcf_cursor = G_FALSE; /* System presumably draws its own cursor */#endif/***************************************************************************** print_usage --** Local function to print out intended startup options (usage)*****************************************************************************/static void print_usage( char * program ){ static char str2[] = "----------------- Application specific -------------------------\n"" -h display this information (startup help)\n"#if G_SYS_SGL" -nocursor startup without a software cursor\n"#endif"\n"" -nographics run application without graphics\n"" -nodetail disallow detail (micro) texture\n"; char str1[256]; char * strt; int nchrs; sprintf( str1, "Usage: %s [options] [train_filename]\n\n" "where optional [train_filename] is a database to fly through\n" "and command line options include:\n\n", program ); nchrs = tparse_display_usage( &strt ); if( nchrs > 0 ) { tgprintf( stdout, "%s%s%s", str1, strt, str2 ); G_free( strt ); } else tgprintf( stdout, "%s%s", str1, str2 );}/***************************************************************************** GV_user_parse_cmd --** Parse the Unix command line and perform project specific actions*****************************************************************************/int GV_user_parse_cmd( int argc, char *argv[] ){ int cmds_used ; int argix ; /* Default for this program unless changed with startup option */ G_msg_set_severity_verbosity( G_MSG_SEV_INFO_BRIEF ); cmds_used = 0; for( argix=1; argix<argc; argix++ ) { /* while arguments remain to be processed */ cmds_used++; if (argv[argix][0] == '-') { /* Argument starts with "-" */ char *token; for (token = argv[argix] + 1 ; *token ; token++) { /* See if it is a common token */ int tsts; int nchrs; nchrs = strlen(token); tsts = tparse_cmd( token ); if( tsts ) break; /* Known common token... taken care of... */ if (token[1]) { if (strcmp( token, "nodetail") == 0) pcf_detail_texture = G_FALSE; else if (strcmp( token, "nocursor") == 0) pcf_cursor = G_FALSE; else if (strcmp( token, "nographics") == 0) pcf_gfx = G_FALSE; else fprintf(stderr, "GV_user_parse_cmd: " "Illegal option \"-%s\"\n", token); break ; } else if( nchrs == 1 ) { /* Now check for valid single character tokens (e.g., -a) */ switch (*token) { case 'h': print_usage( argv[0] ); exit( EXIT_SUCCESS ); break; default: fprintf(stderr, "GV_user_parse_cmd: " "Illegal flag \"-%c\"\n", *token); break; } } } } /* argument starts with "-" */ else { /* Argument does not start with "-", so check for valid keywords */ char * pkwd ; char * pscan ; char parent_dir[256]; char device[3] = ""; int nchrs; const char * etrans; /* treat argument as keyword or perhaps keyword=value */ pkwd = argv[argix] ; pscan = pkwd ; while (*pscan && !isspace(*pscan) && (*pscan != '=')) pscan++ ; /* skip past keyword */ while (isspace(*pscan)) pscan++ ; /* skip past blanks */ if (*pscan == '=') { pscan++ ; while (isspace(*pscan)) pscan++ ; /* skip past blanks again */ } /* Assume this is a train database filename */ strcpy( pcf_train_file, argv[argix] ); G_file_head( pcf_train_file, sizeof(parent_dir), parent_dir, &nchrs ); if( nchrs > 1 ) { tenv_txtpath_init( parent_dir, device ); tenv_path_models_init( parent_dir ); } etrans = G_sys_getenv( "G_ROOT" ); if( !etrans ) { /* No translation for G_ROOT; guess where it might be so we can find the license key (if any) plus GV_ROOT for textures, etc. */ tenv_groot_init( device ); } } /* argument does not start with "-" */ } /* while arguments remain to be processed */ /* Now act upon the command line (at least the "common" ones) now that we're done parsing options */ tparse_preinit(); fflush(stdout); fflush(stderr); return cmds_used;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -