static void keys_H(key_info_t key_info, keys_info_t *keys_info) { wchar_t **list, **p; list = list_cmds(NORMAL_MODE); if(list == NULL) { printf("%s\n", "error"); return; } p = list; while(*p != NULL) { printf("%ls\n", *p); free(*p++); } free(list); }
static int handle_options(const char ***argv, int *argc, int *envchanged) { const char **orig_argv = *argv; while (*argc > 0) { const char *cmd = (*argv)[0]; if (cmd[0] != '-') break; /* * For legacy reasons, the "version" and "help" * commands can be written with "--" prepended * to make them look like flags. */ if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version")) break; /* * Check remaining flags. */ if (skip_prefix(cmd, "--exec-path", &cmd)) { if (*cmd == '=') git_set_exec_path(cmd + 1); else { puts(git_exec_path()); exit(0); } } else if (!strcmp(cmd, "--html-path")) { puts(system_path(GIT_HTML_PATH)); exit(0); } else if (!strcmp(cmd, "--man-path")) { puts(system_path(GIT_MAN_PATH)); exit(0); } else if (!strcmp(cmd, "--info-path")) { puts(system_path(GIT_INFO_PATH)); exit(0); } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { use_pager = 1; } else if (!strcmp(cmd, "-P") || !strcmp(cmd, "--no-pager")) { use_pager = 0; if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--no-replace-objects")) { check_replace_refs = 0; setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--git-dir")) { if (*argc < 2) { fprintf(stderr, _("no directory given for --git-dir\n" )); usage(git_usage_string); } setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1); if (envchanged) *envchanged = 1; (*argv)++; (*argc)--; } else if (skip_prefix(cmd, "--git-dir=", &cmd)) { setenv(GIT_DIR_ENVIRONMENT, cmd, 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--namespace")) { if (*argc < 2) { fprintf(stderr, _("no namespace given for --namespace\n" )); usage(git_usage_string); } setenv(GIT_NAMESPACE_ENVIRONMENT, (*argv)[1], 1); if (envchanged) *envchanged = 1; (*argv)++; (*argc)--; } else if (skip_prefix(cmd, "--namespace=", &cmd)) { setenv(GIT_NAMESPACE_ENVIRONMENT, cmd, 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--work-tree")) { if (*argc < 2) { fprintf(stderr, _("no directory given for --work-tree\n" )); usage(git_usage_string); } setenv(GIT_WORK_TREE_ENVIRONMENT, (*argv)[1], 1); if (envchanged) *envchanged = 1; (*argv)++; (*argc)--; } else if (skip_prefix(cmd, "--work-tree=", &cmd)) { setenv(GIT_WORK_TREE_ENVIRONMENT, cmd, 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--super-prefix")) { if (*argc < 2) { fprintf(stderr, _("no prefix given for --super-prefix\n" )); usage(git_usage_string); } setenv(GIT_SUPER_PREFIX_ENVIRONMENT, (*argv)[1], 1); if (envchanged) *envchanged = 1; (*argv)++; (*argc)--; } else if (skip_prefix(cmd, "--super-prefix=", &cmd)) { setenv(GIT_SUPER_PREFIX_ENVIRONMENT, cmd, 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--bare")) { char *cwd = xgetcwd(); is_bare_repository_cfg = 1; setenv(GIT_DIR_ENVIRONMENT, cwd, 0); free(cwd); setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "-c")) { if (*argc < 2) { fprintf(stderr, _("-c expects a configuration string\n" )); usage(git_usage_string); } git_config_push_parameter((*argv)[1]); (*argv)++; (*argc)--; } else if (!strcmp(cmd, "--literal-pathspecs")) { setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "1", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--no-literal-pathspecs")) { setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "0", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--glob-pathspecs")) { setenv(GIT_GLOB_PATHSPECS_ENVIRONMENT, "1", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--noglob-pathspecs")) { setenv(GIT_NOGLOB_PATHSPECS_ENVIRONMENT, "1", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--icase-pathspecs")) { setenv(GIT_ICASE_PATHSPECS_ENVIRONMENT, "1", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--no-optional-locks")) { setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "0", 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--shallow-file")) { (*argv)++; (*argc)--; set_alternate_shallow_file((*argv)[0], 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "-C")) { if (*argc < 2) { fprintf(stderr, _("no directory given for -C\n" )); usage(git_usage_string); } if ((*argv)[1][0]) { if (chdir((*argv)[1])) die_errno("cannot change to '%s'", (*argv)[1]); if (envchanged) *envchanged = 1; } (*argv)++; (*argc)--; } else if (skip_prefix(cmd, "--list-cmds=", &cmd)) { if (!strcmp(cmd, "parseopt")) { struct string_list list = STRING_LIST_INIT_DUP; int i; list_builtins(&list, NO_PARSEOPT); for (i = 0; i < list.nr; i++) printf("%s ", list.items[i].string); string_list_clear(&list, 0); exit(0); } else { exit(list_cmds(cmd)); } } else { fprintf(stderr, _("unknown option: %s\n"), cmd); usage(git_usage_string); } (*argv)++; (*argc)--; } return (*argv) - orig_argv; }
void main (int argc, char *argv []) { FILE *in, *out; int toprg = TRUE, mult = FALSE, lower = TRUE, stomp = FALSE; int filegiven = FALSE, i, k, casemode = TRUE, colmode = FALSE; char fin [MAXPATH], fout [MAXPATH], inmode [3], outmode [3]; char in_ext [MAXEXT], out_ext [MAXEXT], fext [MAXEXT]; kw_list [0] = keywords; kw_list [1] = KW_NULL; get_prog_name (argv [0]); if (argc == 1) usage (); else { for (i = 1; i < argc; i++) { for (k = 0; k < (int)strlen (argv [i]); k++) argv [i][k] = tolower (argv [i][k]); if (argv [i][0] == '/' || argv [i][0] == '-') { if (! strcmp (argv [i], cmds [TOTXT].command)) toprg = FALSE; else if (! strcmp (argv [i], cmds [TOPRG].command)) toprg = TRUE; else if (! strcmp (argv [i], cmds [MULT].command)) mult = TRUE; else if (! strcmp (argv [i], cmds [NOMULT].command)) mult = FALSE; else if (! (strcmp (argv [i], cmds [HELP].command) && strcmp (argv [i], "/h") && strcmp (argv [i], "/?") && strcmp (argv [i], "-h"))) help (); else if (! strcmp (argv [i], cmds [LIST].command)) list_cmds (); else if (! strcmp (argv [i], cmds [KEYWORDS].command)) list_keywords (); else if (! strcmp (argv [i], cmds [SPECIAL].command)) list_special (); else if (! strcmp (argv [i], cmds [EXTENSIONS].command)) list_extensions (); else if (! strcmp (argv [i], cmds [LOWER].command)) lower = TRUE; else if (! strcmp (argv [i], cmds [UPPER].command)) lower = FALSE; else if (! strcmp (argv [i], cmds [LOWCASE].command)) casemode = FALSE; else if (! strcmp (argv [i], cmds [CASE].command)) casemode = TRUE; else if (! strcmp (argv [i], cmds [COL].command)) colmode = TRUE; else if (! strcmp (argv [i], cmds [NOCOL].command)) colmode = FALSE; else if (! strcmp (argv [i], cmds [STOMP].command)) stomp = TRUE; else if (! strcmp (argv [i], cmds [NOSTOMP].command)) stomp = FALSE; else if (! strcmp (argv [i], cmds [FINCART3].command)) { kw_list [0] = final_cart_3; kw_list [1] = keywords; kw_list [2] = KW_NULL; } else if (! strcmp (argv [i], cmds [GRAPH52].command)) { kw_list [0] = graphics_52; kw_list [1] = keywords; kw_list [2] = KW_NULL; } else if (! strcmp (argv [i], cmds [ASM6510PLUS].command)) { kw_list [0] = asm6510plus; kw_list [1] = keywords; kw_list [2] = KW_NULL; } else if (! strcmp (argv [i], cmds [C64].command)) { kw_list [0] = keywords; kw_list [1] = KW_NULL; } else { fprintf (stderr, "%s: invalid command \"%s\".\n", program, argv [i]); exit (EXITBAD); } } else { filegiven = TRUE; if (toprg) { strcpy (in_ext, TXT_EXT); strcpy (out_ext, PRG_EXT); strcpy (inmode, "rt"); strcpy (outmode, "wb"); } else { strcpy (in_ext, PRG_EXT); strcpy (out_ext, TXT_EXT); strcpy (inmode, "rb"); strcpy (outmode, "wt"); } /* get base name and check if there's an extension */ if (! basename (argv [i], fout, MAXPATH - 1)) { /* nope, no extension specified */ strcpy (fin, fout); strncat (fin, in_ext, MAXPATH - 1); } else { strncpy (fin, argv [i], MAXPATH - 1); extension (fin, fext, MAXEXT - 1); if (! strcmp (fext, out_ext)) { fprintf (stderr, "%s: not expecting \"%s\" as input.\n", program, argv [i]); exit (EXITBAD); } } strncat (fout, out_ext, MAXPATH - 1); if ((in = fopen (fin, inmode)) == NULL) { fprintf (stderr, "%s: Can't open %s for input.\n", program, fin); exit (EXITBAD); } else if (mult) { fprintf (stderr, "processing %s ...\n", fin); process_mult (in, stomp, casemode, colmode); fprintf (stderr, "processing of %s complete.\n", fin); } else { if (! exit_exists (stomp, in, fout)) { if ((out = fopen (fout, outmode)) == NULL) { fprintf (stderr, "%s: Can't open %s for output\n", program, fout); exit (EXITBAD); } else { fprintf (stderr, "%s ==> %s ...", fin, fout); if (toprg) txt2prg (in, out, casemode, colmode); else prg2txt (in, out, fin, lower); fclose (out); fprintf (stderr, " done.\n"); } } fclose (in); } /* end can open input file */ } /* end command line arg check */ } /* end for loop thru args */ } /* end if check for args */ if (! filegiven) usage (); exit (EXITOK); } /* end main */