//--------------------------------------------------------------- void parser(int argc, char **argv) { int arg; if(argc < 2) output_help(); while ((arg = getopt(argc, argv, "i:o:bme")) != -1) { switch (arg) { case 'i': input_filename = optarg; break; case 'o': output_filename = optarg; break; case 'b': bilateral_filter = true; break; case 'm': median_filter = true; break; case 'e': edge_on = true; break; case 'h': output_help(); case '?': output_help(); } } }
/* Get next line */ cip = 0; #if 1 if (smg$enable) { SMG$ERASE_LINE(&disp2_id, &i1, &i1); SMG$SET_CURSOR_ABS(&disp2_id,&i1,&i1); status = SMG$READ_COMPOSED_LINE(&keyb_id,&key_tab,&input_line, &prompt,&out_len,&disp2_id,0,0,0,0,0); /*Get next command */ cip = 1; } else status = SMG$READ_COMPOSED_LINE(&keyb_id,0,&input_line, &prompt,&out_len,0,0,0,0,0,0); /*Get next command */ #else printf("%s",prompt.dsc$a_pointer); out_len = read(0,command_line,254); out_len--; command_line[out_len]=0; if (strncmp(command_line,"exit",4)==0) return 0; #endif } } /* END of MAIN */ int help_command(int mask) /* HELP Purpose : call on-line help Output : contents of DFUHLP helplib. */ { unsigned int x,flag=1,tmp=0; #if 0 static char help[80]; $DESCRIPTOR(help_key ,help); $DESCRIPTOR(help_item, "helpkey"); $DESCRIPTOR(help_lib,"dfuhlp"); $DESCRIPTOR(item,"DFU "); $DESCRIPTOR(hlp_txt,"< DFU Help Screen >"); /* Check if a help item was entered */ if (cli$present(&help_item) == CLI$_PRESENT) cli$get_value(&help_item,&help_key,&help_key); else help_key.dsc$w_length=0; /* Add 'DFU ' to the help key */ help_key.dsc$w_length +=4; str$concat(&help_key,&item,&help_key); x = rows - 4; /* Reenable line editing... */ status = SYS$QIOW(0,tchan, IO$_SETMODE,0,0,0,&orgttchar,12,0,0,0,0); if (smg$enable) { SMG$CREATE_VIRTUAL_DISPLAY(&x, &colls, &help_id, 0 , 0, 0); SMG$LABEL_BORDER(&help_id, &hlp_txt, 0, 0,&SMG$M_BOLD); SMG$PASTE_VIRTUAL_DISPLAY(&help_id, &paste_id, &i2,&i2,0); status = SMG$PUT_HELP_TEXT(&help_id, &keyb_id, &help_key, &help_lib,0,0); SMG$UNPASTE_VIRTUAL_DISPLAY(&help_id, &paste_id); SMG$DELETE_VIRTUAL_DISPLAY(&help_id); } else status = lbr$output_help(lib$put_output,0,&help_key, &help_lib,&flag,lib$get_input); if (status != SS$_NORMAL) { sprintf(outbuf,"%%DFU-E-HELPERR, Error opening help library,"); put_disp(); singlemsg(0,status); } #endif return(1); } /*END help_command */
static int varg_do_help(char *help_library, char *help_command) { $DESCRIPTOR(lib_desc, ""); $DESCRIPTOR(command_desc, ""); int status; lib_desc.dsc$w_length = strlen(help_library); lib_desc.dsc$a_pointer = help_library; command_desc.dsc$w_length = strlen(help_command); command_desc.dsc$a_pointer = help_command; status = lbr$output_help(&lib$put_output, 0, &command_desc, &lib_desc, 0, &lib$get_input); return status; }
int main(int argc, char *argv[]) { init(); if (process_arguments(argc, argv) || help_flag) { output_help(); return !help_flag; } read_input(); Timer::start(); vector<Move> list_moves = calculate(); Timer::stop(); output_result(list_moves); /* if (!Board::win(initial_board, 0)) printf("no!!!\n"); if (Board::win(make_pair((1 << 65)-1, 0LL), 0)) printf("yay white wins!!!\n");*/ return 0; }
/**************************** * ExecuteHelp - create a statement, execute the SQL, and get rid of the statement * - show results as per request; bHTMLTable has precedence over other options ***************************/ static int ExecuteHelp( SQLHDBC hDbc, char *szSQL, char cDelimiter, int bColumnNames, int bHTMLTable ) { SQLHSTMT hStmt; SQLLEN nRows = 0; SQLRETURN nReturn; SQLCHAR *szSepLine; char *args[10]; int n_args; if (!(szSepLine = calloc(1, 32001))) { fprintf(stderr, "[ISQL]ERROR: Failed to allocate line"); return 0; } /**************************** * EXECUTE SQL ***************************/ if ( version3 ) { if ( SQLAllocHandle( SQL_HANDLE_STMT, hDbc, &hStmt ) != SQL_SUCCESS ) { if ( bVerbose ) DumpODBCLog( hEnv, hDbc, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLAllocHandle( SQL_HANDLE_STMT )\n" ); free(szSepLine); return 0; } } else { if ( SQLAllocStmt( hDbc, &hStmt ) != SQL_SUCCESS ) { if ( bVerbose ) DumpODBCLog( hEnv, hDbc, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLAllocStmt\n" ); free(szSepLine); return 0; } } n_args = get_args(szSQL, &args[0], sizeof(args) / sizeof(args[0])); if (n_args == 2 ) { if (strcmp(args[1], "help") == 0) { output_help(); free(szSepLine); return 0; } /* COLUMNS */ nReturn = SQLColumns( hStmt, NULL, 0, NULL, 0, (SQLCHAR*)args[1], SQL_NTS, NULL, 0 ); if ( (nReturn != SQL_SUCCESS) && (nReturn != SQL_SUCCESS_WITH_INFO) ) { if ( bVerbose ) DumpODBCLog( hEnv, hDbc, hStmt ); fprintf( stderr, "[ISQL]ERROR: Could not SQLColumns\n" ); SQLFreeStmt( hStmt, SQL_DROP ); free(szSepLine); return 0; } } else { SQLCHAR *catalog = NULL; SQLCHAR *schema = NULL; SQLCHAR *table = NULL; SQLCHAR *type = NULL; if (n_args > 2) { catalog = (SQLCHAR*)args[1]; schema = (SQLCHAR*)args[2]; table = (SQLCHAR*)args[3]; type = (SQLCHAR*)args[4]; } /* TABLES */ nReturn = SQLTables( hStmt, catalog, SQL_NTS, schema, SQL_NTS, table, SQL_NTS, type, SQL_NTS ); if ( (nReturn != SQL_SUCCESS) && (nReturn != SQL_SUCCESS_WITH_INFO) ) { if ( bVerbose ) DumpODBCLog( hEnv, hDbc, hStmt ); fprintf( stderr, "[ISQL]ERROR: Could not SQLTables\n" ); SQLFreeStmt( hStmt, SQL_DROP ); free(szSepLine); free_args(args, sizeof(args) / sizeof(args[0])); return 0; } } /**************************** * WRITE HEADER ***************************/ if ( bHTMLTable ) WriteHeaderHTMLTable( hStmt ); else if ( cDelimiter == 0 ) WriteHeaderNormal( hStmt, szSepLine ); else if ( cDelimiter && bColumnNames ) WriteHeaderDelimited( hStmt, cDelimiter ); /**************************** * WRITE BODY ***************************/ if ( bHTMLTable ) WriteBodyHTMLTable( hStmt ); else if ( cDelimiter == 0 ) nRows = WriteBodyNormal( hStmt ); else WriteBodyDelimited( hStmt, cDelimiter ); /**************************** * WRITE FOOTER ***************************/ if ( bHTMLTable ) WriteFooterHTMLTable( hStmt ); else if ( cDelimiter == 0 ) WriteFooterNormal( hStmt, szSepLine, nRows ); /**************************** * CLEANUP ***************************/ SQLFreeStmt( hStmt, SQL_DROP ); free(szSepLine); free_args(args, sizeof(args) / sizeof(args[0])); return 1; }
/* * parse_commandline * read our args, parse them * and return a struct of the data */ argdata_t *parse_commandline (int argc, char **argv) { argdata_t *data; extern char *optarg; extern int optind, opterr, optopt; int done, fail; int quota_type; int opt; if (argc == 1) { output_help (); return NULL; } data = (argdata_t *) calloc (1,sizeof(argdata_t)); if ( ! data ) { output_error ("Insufficient memory"); exit (ERR_MEM); } quota_type = _PARSE_UNDEF; optarg = NULL; opterr = 0; done = fail = 0; while ( ! done && ! fail ) { opt = getopt(argc, argv, OPTSTRING); if (opt > 0) output_debug ("option: '%c', argument: '%s'", opt, optarg); switch (opt) { case EOF: done = 1; break; case 'h': output_help (); exit (0); case 'V': output_version(); exit (0); case 'v': output_level++; break; case 'n': data->noaction = 1; break; case 'u': /* set username */ if ( data->id_type ) { output_error("Only one quota (user or group) can be set"); fail = 1; continue; } data->id_type = QUOTA_USER; #if HAVE_GNU_GETOPT /* -uuser */ if ( optarg ) { output_debug ("not mangling: optarg='%s', next='%s'", optarg, argv[optind]); data->id = optarg; } /* -u [-next-opt] */ else if ( ! argv[optind] || argv[optind][0] == '-' ) { output_debug ("not mangling: NULL user"); data->id = NULL; } /* -u user */ else { output_debug ("mangling everything: next='%s'", argv[optind]); data->id = argv[optind]; optind++; } #else if (optarg && ((data->block_grace || data->inode_grace) || (optarg[0] == '-'))) { /* -u [-next-opt] */ optind--; data->id = NULL; } else { /* -u user */ data->id = optarg; } #endif output_info ("using uid %s", data->id); break; case 'g': /* set groupname */ if ( data->id_type ) { output_error("Only one quota (user or group) can be set"); fail = 1; continue; } data->id_type = QUOTA_GROUP; #if HAVE_GNU_GETOPT if ( optarg ) { output_debug ("not mangling: optarg='%s', next='%s'", optarg, argv[optind]); data->id = optarg; } else if ( ! argv[optind] || argv[optind][0] == '-' ) { output_debug ("not mangling: NULL user"); data->id = NULL; } else { output_debug ("mangling everything: next='%s', argv[optind]"); data->id = argv[optind]; optind++; } #else data->id = optarg; #endif output_info ("using gid %s", data->id); break; case 'b': // Work with block limits output_info ("working with block limits"); quota_type = _PARSE_BLOCK; break; case 'i': // Work with inode limits output_info ("working with inode limits"); quota_type = _PARSE_INODE; break; case 'q': // soft limit switch ( quota_type ) { case _PARSE_UNDEF: output_error ("Must specify either block (-b) or inode (-i) before -q"); fail = 1; break; case _PARSE_BLOCK: data->block_soft = optarg; break; case _PARSE_INODE: data->inode_soft = optarg; break; default: output_error ("Impossible error #42q: evacuate the building!"); break; } output_info ("setting soft limit to %s", optarg); break; case 'l': // hard limit switch ( quota_type ) { case _PARSE_UNDEF: output_error ("Must specify either block (-b) or inode (-i) before -l"); fail = 1; break; case _PARSE_BLOCK: data->block_hard = optarg; break; case _PARSE_INODE: data->inode_hard = optarg; break; default: output_error ("Impossible error #42l: evacuate the building!"); break; } output_info ("setting hard limit to %s", optarg); break; case 't': // set grace period data->id = NULL; switch ( quota_type ) { case _PARSE_UNDEF: output_error ("Must specify either block (-b) or inode (-i) before -t"); fail = 1; break; case _PARSE_BLOCK: data->block_grace = optarg; break; case _PARSE_INODE: data->inode_grace = optarg; break; default: output_error ("Impossible error #42t: evacuate the building!"); break; } break; case 'r': // reset grace time switch ( quota_type ) { case _PARSE_UNDEF: output_error ("Must specify either block (-b) or inode (-i) before -r"); fail = 1; break; case _PARSE_BLOCK: data->block_reset = 1; break; case _PARSE_INODE: data->inode_reset = 1; break; default: output_error ("Impossible error #42r: evacuate the building!"); break; } break; case 'd': data->dump_info = 1; break; case 'R': data->raise_only = 1; break; case ':': output_error ("Option '%c' requires an argument", optopt); break; case '?': output_error ("Unrecognized option: '%c'", optopt); __attribute__ ((fallthrough)); default: output_help(); fail = 1; break; } } if ( fail ) { free (data); return NULL; } if ( ! data->id_type ) { output_error ("Must specify either user or group quota"); return NULL; } if ( data->dump_info) { output_info("Option 'd' => just dumping quota-info for %s", data->id_type == QUOTA_USER ? "user" : "group"); } /* the remaining arg is the filesystem */ data->qfile = argv[optind]; if ( ! data->qfile || strlen(data->qfile) == 0) { output_error ("No filesystem specified"); return NULL; } /* remove trailing slash(es) except for / filesystem */ while (strlen(data->qfile) > 1) { if (data->qfile[strlen(data->qfile) - 1] != '/') break; data->qfile[strlen(data->qfile) - 1] = '\0'; } /* check for mixing -t with other options in the wrong way */ if (data->block_grace || data->inode_grace) { if (data->block_hard || data->block_soft || data->inode_hard || data->inode_soft || data->id) { output_error("Wrong options for -t, please see manpage for usage instructions!"); return NULL; } } /* check for mixing -r with other options in the wrong way */ if (data->block_reset || data->inode_reset) { if (data->block_hard || data->block_soft || data->inode_hard || data->inode_soft) { output_error("Wrong options for -r, please see manpage for usage instructions!"); return NULL; } } output_info ("using filesystem %s", data->qfile); return data; }
int main(int argc, const char **argv) { const char *source = NULL; int output_insts = 0; --argc; ++argv; while (argc) { const char *arg = *argv; if (arg[0] == '-') { switch (arg[1]) { case 'v': { printf( "Cript version %s\n" "Clarkok Zhang([email protected])\n", CRIPT_VERSION ); return 0; } case 'c': { output_insts = 1; break; } case 'h': output_help(); return 0; default: { printf( "Unknown argument: %s\n", arg ); output_help(); return -1; } } } else { if (source) { error("Multiple source file\n Use import instead\n"); return -1; } else { source = arg; } } --argc; ++argv; } if (!source) { error("No source file\n"); return -1; } ParseState *parse_state = parse_state_new_from_file(source); parse(parse_state); VMState *vm = cvm_state_new_from_parse_state(parse_state); if (output_insts) { output_vm_state(stdout, vm); } lib_register(vm); cvm_state_run(vm); return 0; }
int main(int argc, char *argv[]) { EB_Error_Code error_code; char out_path[PATH_MAX + 1]; char book_path[PATH_MAX + 1]; char subbook_name_list[EB_MAX_SUBBOOKS][EB_MAX_DIRECTORY_NAME_LENGTH + 1]; int subbook_name_count = 0; int ch; invoked_name = argv[0]; strcpy(out_path, DEFAULT_OUTPUT_DIRECTORY); /* * Initialize locale data. */ #ifdef ENABLE_NLS #ifdef HAVE_SETLOCALE setlocale(LC_ALL, ""); #endif bindtextdomain(TEXT_DOMAIN_NAME, LOCALEDIR); textdomain(TEXT_DOMAIN_NAME); #endif /* * Initialize `book'. */ error_code = eb_initialize_library(); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(error_code)); goto die; } /* * Parse command line options. */ for (;;) { ch = getopt_long(argc, argv, short_options, long_options, NULL); if (ch == -1) break; switch (ch) { case 'h': /* * Option `-h'. Display help message, then exit. */ output_help(); exit(0); case 'o': /* * Option `-o'. Output files under DIRECOTRY. * The length of the file name * "<out_path>/catalogs.bak;1" * must not exceed PATH_MAX. */ if (PATH_MAX < strlen(optarg)) { fprintf(stderr, _("%s: too long output directory path\n"), invoked_name); exit(1); } strcpy(out_path, optarg); canonicalize_path(out_path); if (PATH_MAX < strlen(out_path) + (1 + EB_MAX_DIRECTORY_NAME_LENGTH + 6)) { fprintf(stderr, _("%s: too long output directory path\n"), invoked_name); goto die; } break; case 'S': /* * Option `-S'. Specify target subbooks. */ if (parse_subbook_name_argument(invoked_name, optarg, subbook_name_list, &subbook_name_count) < 0) exit(1); break; case 'v': /* * Option `-v'. Display version number, then exit. */ output_version(program_name, program_version); exit(0); default: output_try_help(invoked_name); goto die; } } /* * Check the number of rest arguments. */ if (1 < argc - optind) { fprintf(stderr, _("%s: too many arguments\n"), invoked_name); output_try_help(invoked_name); goto die; } /* * Set a book path. */ if (argc == optind) strcpy(book_path, DEFAULT_BOOK_DIRECTORY); else strcpy(book_path, argv[optind]); if (is_ebnet_url(book_path)) { fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(EB_ERR_EBNET_UNSUPPORTED)); goto die; } canonicalize_path(book_path); if (PATH_MAX < strlen(book_path) + (1 + EB_MAX_DIRECTORY_NAME_LENGTH + 6)) { fprintf(stderr, _("%s: too long book directory path\n"), invoked_name); goto die; } /* * Set signals. */ #ifdef SIGHUP signal(SIGHUP, trap); #endif signal(SIGINT, trap); #ifdef SIGQUIT signal(SIGQUIT, trap); #endif #ifdef SIGTERM signal(SIGTERM, trap); #endif /* * Refile a catalog. */ if (refile_book(out_path, book_path, subbook_name_list, subbook_name_count) < 0) goto die; eb_finalize_library(); return 0; /* * A critical error occurs... */ die: eb_finalize_library(); exit(1); }