int main(int argc, char *argv[]) { const char *options_error = "no input file"; int i; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (arg[0] != '-') { process_file(arg); options_error = NULL; continue; } options_error = "options must be specified before the input file"; #define is_opt(c) (arg[1] == c && arg[2] == '\0') if (is_opt('s')) set_song(argv[++i]); else if (strncmp(arg, "--song=", 7) == 0) set_song(arg + 7); else if (is_opt('h') || strcmp(arg, "--help") == 0) { print_help(); options_error = NULL; } else if (is_opt('v') || strcmp(arg, "--version") == 0) { printf("asap-sdl " ASAPInfo_VERSION "\n"); options_error = NULL; } else fatal_error("unknown option: %s", arg); } if (options_error != NULL) { fprintf(stderr, "asap-sdl: %s\n", options_error); print_help(); return 1; } return 0; }
static int is_options(t_getopt *opt, char **p, char **av, const char *opt_str) { if (*p == NULL) { *p = av[opt->ind]; if (**p == '-') { if ((*p)[1] == '\0') { ++(*p); opt->opt = '-'; return (0); } (*p)++; return (is_opt(opt, p, opt_str)); } return (0); } else { if (!is_opt(opt, p, opt_str)) opt->ret = '?'; return (1); } }
Bool Timer_start( Handle self) { if ( is_opt( optActive)) return true; opt_assign( optActive, apc_timer_start( self)); return is_opt( optActive); }
void Drawable_cleanup( Handle self) { if ( is_opt( optInDrawInfo)) my-> end_paint_info( self); if ( is_opt( optInDraw)) my-> end_paint( self); inherited cleanup( self); }
char * Printer_printer( Handle self, Bool set, char * printerName) { if ( !set) return apc_prn_get_selected( self); if ( is_opt( optInDraw)) my-> end_paint( self); if ( is_opt( optInDrawInfo)) my-> end_paint_info( self); return apc_prn_select( self, printerName) ? "1" : ""; }
int Drawable_get_paint_state( Handle self) { if ( is_opt( optInDraw)) return psEnabled; else if ( is_opt( optInDrawInfo)) return psInformation; else return psDisabled; }
Bool Drawable_begin_paint_info( Handle self) { if ( var-> stage > csFrozen) return false; if ( is_opt( optInDraw)) return true; if ( is_opt( optInDrawInfo)) return false; opt_set( optInDrawInfo); var-> splinePrecision_saved = var-> splinePrecision; return true; }
Bool Window_modalHorizon( Handle self, Bool set, Bool modalHorizon) { if ( !set) return is_opt( optModalHorizon); if ( is_opt( optModalHorizon) == modalHorizon) return false; my-> cancel_children( self); opt_assign( optModalHorizon, modalHorizon); return modalHorizon; }
Bool Widget_packPropagate( Handle self, Bool set, Bool propagate) { Bool repack; if ( !set) return is_opt( optPackPropagate); repack = !(is_opt( optPackPropagate)) && propagate; opt_assign( optPackPropagate, propagate); if ( repack) geometry_reset(self,-1); return is_opt( optPackPropagate); }
// Processes the command line arguments. Returns true on success. static bool process_args(int argc, char **argv, struct Environment *env) { if (argc == 2 && is_opt(argv[1], 'h', "help")) { fputs(usage_message, stdout); return true; } bool tty = isatty(0); bool prelude = true; for (int i = 1; i < argc; i++) { if (is_opt(argv[i], 'n', "no-prelude")) { prelude = false; argv[i] = NULL; break; } } if (prelude) { execute(PRELUDE_FILENAME, prelude_source, env, false); } if (argc == 1 || (argc == 2 && !prelude)) { repl(env, tty); return true; } for (int i = 1; i < argc; i++) { if (argv[i] == NULL) { continue; } if (strcmp(argv[i], "-") == 0) { repl(env, tty); } else if (is_opt(argv[i], 'e', "expression")) { // Execute the next argument. if (i == argc - 1) { print_error(argv[i], err_opt_argument); return false; } if (!execute(argv_filename, argv[++i], env, true)) { return false; } } else { // Assume the argument is a filename. char *text = read_file(argv[i]); if (!text) { print_file_error(argv[i]); return false; } bool success = execute(argv[i], text, env, false); free(text); if (!success) { return false; } } } return true; }
Bool Window_ownerIcon( Handle self, Bool set, Bool ownerIcon) { if ( !set) return is_opt( optOwnerIcon); opt_assign( optOwnerIcon, ownerIcon); if ( is_opt( optOwnerIcon) && var-> owner) { Handle icon = ( var-> owner == application) ? CApplication( application)-> get_icon( application) : CWindow( var-> owner)-> get_icon( var-> owner); my-> set_icon( self, icon); opt_set( optOwnerIcon); } return false; }
string View::formatList(list_t &list, const string d1, const string sep, const string d2) { string output = ""; if(list.empty()) return output; FOR_l(i,list) output = output + (i==0 || is_dir(list[i-1]) || is_opt(list[i-1]) ? "" : sep) + list.at(i); return d1 + output + d2; }
void Printer_end_paint_info( Handle self) { if ( !is_opt( optInDrawInfo)) return; apc_prn_end_paint_info( self); inherited end_paint_info( self); }
int option_parser::parse(int argc, char *argv[]) { int idx = 1; while (idx < argc) { std::string opt = argv[idx]; bool found = false; if (!opt.size() || opt[0] != '-') { for (size_t i = 0; i < m_positions.size(); ++i) { if (m_positions[i].limit > 0) { m_positions[i].limit --; m_positions[i].func(opt); found = true; break; } } if (!found) help_at(idx); continue; } if (opt == "--") return idx + 1; while (opt.size() && opt[0] == '-') opt = opt.substr(1); if (!opt.size()) help_at(idx); for (size_t i = 0; i < m_options.size(); ++i) { auto &option = m_options[i]; if (is_opt(opt, option.choices)) { idx = option.func(idx, argc, argv); found = true; break; } } if (found) continue; break; } return idx; }
SV * Widget_hint( Handle self, Bool set, SV *hint) { enter_method; if ( set) { if ( var-> stage > csFrozen) return nilSV; my-> first_that( self, (void*)hint_notify, (void*)hint); free( var-> hint); var-> hint = duplicate_string( SvPV_nolen( hint)); opt_assign( optUTF8_hint, prima_is_utf8_sv(hint)); if ( application && (( PApplication) application)-> hintVisible && (( PApplication) application)-> hintUnder == self) { SV * hintText = my-> get_hint( self); Handle hintWidget = (( PApplication) application)-> hintWidget; if ( strlen( var-> hint) == 0) my-> set_hintVisible( self, 0); if ( hintWidget) CWidget(hintWidget)-> set_text( hintWidget, hintText); sv_free( hintText); } opt_clear( optOwnerHint); } else { hint = newSVpv( var-> hint ? var-> hint : "", 0); if ( is_opt( optUTF8_hint)) SvUTF8_on( hint); return hint; } return nilSV; }
void Application_end_paint_info( Handle self) { if ( !is_opt( optInDrawInfo)) return; apc_application_end_paint_info( self); CDrawable-> end_paint_info( self); }
void Printer_abort_doc( Handle self) { if ( !is_opt( optInDraw)) return; inherited end_paint( self); apc_prn_abort_doc( self); }
void Timer_stop( Handle self) { if ( !is_opt( optActive)) return; apc_timer_stop( self); opt_clear( optActive); }
SV * Window_text( Handle self, Bool set, SV * text) { SV *ret = inherited text( self, set, text); if (set) apc_window_set_caption( self, var-> text, is_opt( optUTF8_text)); return ret; }
Bool Window_mainWindow( Handle self, Bool set, Bool mainWindow) { if ( !set) return is_opt( optMainWindow); opt_assign( optMainWindow, mainWindow); return false; }
Handle Widget_get_selectee( Handle self) { if ( var-> stage > csFrozen) return nilHandle; if ( is_opt( optSelectable)) return self; else if ( var-> currentWidget) { PWidget w = ( PWidget) var-> currentWidget; if ( w-> options. optSystemSelectable && !w-> self-> get_clipOwner(( Handle) w)) return ( Handle) w; else return w-> self-> get_selectee(( Handle) w); } else if ( is_opt( optSystemSelectable)) return self; else return find_tabfoc( self); }
Bool Printer_new_page( Handle self) { Bool ok; if ( !is_opt( optInDraw)) return false; ok = apc_prn_new_page( self); if ( !ok) perl_error(); return ok; }
RepoAuthType make_repo_type(UnitEmitter& ue, const Type& t) { using T = RepoAuthType::Tag; if (t.strictSubtypeOf(TObj) || (is_opt(t) && t.strictSubtypeOf(TOptObj))) { auto const dobj = dobj_of(t); auto const tag = is_opt(t) ? (dobj.type == DObj::Exact ? T::OptExactObj : T::OptSubObj) : (dobj.type == DObj::Exact ? T::ExactObj : T::SubObj); ue.mergeLitstr(dobj.cls.name()); return RepoAuthType { tag, dobj.cls.name() }; } #define ASSERTT_OP(x) if (t.subtypeOf(T##x)) return RepoAuthType{T::x}; ASSERTT_OPS #undef ASSERTT_OP return RepoAuthType{}; }
Bool Printer_end_doc( Handle self) { Bool ret; if ( !is_opt( optInDraw)) return false; ret = apc_prn_end_doc( self); inherited end_paint( self); if ( !ret) perl_error(); return ret; }
Bool apc_timer_destroy( Handle self) { objCheck false; if ( is_opt( optActive) && var handle && IsWindow(( HWND)(( PWidget) var owner)-> handle)) { if ( !KillTimer(( HWND)(( PWidget) var owner)-> handle, var handle)) apiErr; } remove_timer( self, var owner); return true; }
bool could_have_magic_bool_conversion(Type t) { if (!t.couldBe(TObj)) return false; if (t.strictSubtypeOf(TObj)) { return has_magic_bool_conversion(dobj_of(t).cls); } if (is_opt(t) && unopt(t).strictSubtypeOf(TObj)) { return has_magic_bool_conversion(dobj_of(t).cls); } return true; }
Bool Printer_begin_doc( Handle self, char * docName) { Bool ok; char buf[ 256]; if ( is_opt( optInDraw)) return false; if ( !docName || *docName == '\0') { snprintf( buf, 256, "APC: %s", (( PComponent) application)-> name); docName = buf; } if ( is_opt( optInDrawInfo)) my-> end_paint_info( self); if ( !inherited begin_paint( self)) return false; if ( !( ok = apc_prn_begin_doc( self, docName))) { inherited end_paint( self); perl_error(); } return ok; }
/* counts the number of non-option (i.e. non -char or --string) arguments in argv after the i-th element, until the next option, or until the end of argv is reached */ int args_to_next_opt(int i,int argc, char **argv) { int j=0; i++; while(i<argc && is_opt(argv[i]) == 0 ) { i++; j++; } return(j); }
Bool Printer_begin_paint_info( Handle self) { Bool ok; if ( is_opt( optInDraw)) return true; if ( !inherited begin_paint_info( self)) return false; if ( !( ok = apc_prn_begin_paint_info( self))) { inherited end_paint_info( self); if ( !ok) perl_error(); } return ok; }
Bool Application_begin_paint_info( Handle self) { Bool ok; if ( is_opt( optInDraw)) return true; if ( !CDrawable-> begin_paint_info( self)) return false; if ( !( ok = apc_application_begin_paint_info( self))) { CDrawable-> end_paint_info( self); perl_error(); } return ok; }