📄 args.c
字号:
{ *(p->p_explicit) = 1; } switch (p->p_type) { case PRO_PRSTRING: /* This is not really an error, but zero exit values are returned only when code has been successfully formatted. */ printf (_("GNU indent %s\n"), (char *) p->p_obj); exit (invocation_error); case PRO_FUNCTION: ((void (*)()) p->p_obj) (); break; case PRO_SETTINGS: { char *t; /* current position */ t = (char *) p->p_obj; do { set_option (t, 0, 0); /* advance to character following next NUL */ while (*t++) { } } while (*t); } case PRO_IGN: break; case PRO_KEY: { char *str; if (*param_start == 0) { if (!(param_start = param)) { arg_missing (option); } else { val = 1; } } str = (char *) xmalloc (strlen (param_start) + 1); strcpy (str, param_start); addkey (str, rw_decl); } break; case PRO_BOOL: if (p->p_special == OFF) { *p->p_obj = false; } else { *p->p_obj = true; } break; case PRO_INT: if (*param_start == '\0') { param_start = param; if (param_start == NULL) { arg_missing (option); } else { val = 1; } } if (isdigit (*param_start) || ((*param_start == '-') && isdigit (*(param_start + 1)))) { *p->p_obj = atoi (param_start); } else { fprintf (stderr, _ ("indent: option ``%s'' requires a numeric parameter\n"), option - 1); exit (invocation_error); } break; default: fprintf (stderr, _("indent: set_option: internal error: p_type %d\n"), (int) p->p_type); exit (invocation_error); } } } return val;}/* The first 2 characters of a c++ comment have been read skip the remainder of the line * and return the first character from the next line. */static int skip_cpp_comment (FILE * f){ int i; do { i = getc (f); } while ((i != EOF) && (i != EOL)); if (i == EOL) { i = getc (f); } return i;}/* * the first 2 characters of a c comment have been read. Read past the * remainder of the comment and return the first character after the * comment. */static int skip_c_comment (FILE * f){ int i = getc (f); do { /* skip to the next '*' character */ while ((i != EOF) && (i != '*')) { i = getc (f); } if (i == EOF) { WARNING (_("Profile contains an unterminated comment"), 0, 0); break; } /* current char is '*' so skip over it. */ i = getc (f); /* If the current character is a '/' the comment is over. */ } while (i != '/'); if (i != EOF) { i = getc (f); } return i;}/* The starting / of a comment has been read. * skip over the rest of the comment and return the * first character after the comment. */static int skip_comment (FILE * f){ int i = getc (f); switch (i) { case '/': i = skip_cpp_comment (f); break; case '*': i = skip_c_comment (f); break; default: WARNING (_("Profile contains unpalatable characters"), 0, 0); } return i;}/* * Skip a sequence of space and control characters and return the * first character after the sequence. */static int skip_spaces (FILE * f, int first){ int i = first; while ((i <= ' ') && (i != EOF)) { i = getc (f); } return i;}/* Read a string from the input until the next control character, space or /. * Return the first character after the read string. */static int read_string (FILE * f, char *buff, int first){ int i = first; char *p = buff; while ((i != EOF) && (i > ' ') && (i != '/') && (p < buff + BUFSIZ)) { *(p++) = i; i = getc (f); } *p = EOS; return i;}/* Scan the options in the file f. */static void scan_profile (FILE * f){ char b0[BUFSIZ]; char b1[BUFSIZ]; char *current = b0; int i = skip_spaces (f, ' '); while (i != EOF) { if (i == '/') { /* The start of a comment. */ i = skip_comment (f); } else { i = read_string (f, current, i); /* We've scanned something... */ if (current == b0) { /* Second buffer still has to be filled. */ current = b1; } else if (set_option (b0, b1, 1) == 1) { /* The option had a parameter, thus both values * have been consumed. * Reset the 2 buffers to 'empty' */ current = b0; } else { /* Set option consumed one value. Move the * other value to the first buffer and go get a new * second value. */ strcpy (b0, b1); current = b1; } } i = skip_spaces (f, i); } if (current != b0) { set_option (b0, NULL, 1); }}/* Some operating systems don't allow more than one dot in a filename. */#if defined (ONE_DOT_PER_FILENAME)#define INDENT_PROFILE "indent.pro"#else#define INDENT_PROFILE ".indent.pro"#endif#ifndef PROFILE_FORMAT#define PROFILE_FORMAT "%s/%s"#endif#define PROFILE_ENV_NAME "INDENT_PROFILE"/* set_profile looks for ./.indent.pro or $HOME/.indent.pro, in * that order, and reads the options given in that file. Return the * path of the file read. * * Note that as of version 1.3, indent only reads one file. */char *set_profile (void){ FILE *f = NULL; char *fname = NULL; static char prof[] = INDENT_PROFILE; char *homedir = NULL; char *envname = getenv (PROFILE_ENV_NAME); if (envname != NULL) { f = fopen (envname, "r"); } if (f != NULL) { scan_profile (f); (void) fclose (f); fname = strdup (envname); } else { f = fopen (INDENT_PROFILE, "r"); if (f != NULL) { int len = strlen (INDENT_PROFILE) + 3; scan_profile (f); (void) fclose (f); fname = xmalloc (len); strcpy (fname, "./"); (void) strcat (fname, INDENT_PROFILE); } else { homedir = getenv ("HOME"); if (homedir) { fname = xmalloc (strlen (homedir) + strlen (PROFILE_FORMAT) + sizeof (prof)); sprintf (fname, PROFILE_FORMAT, homedir, prof); if ((f = fopen (fname, "r")) != NULL) { scan_profile (f); (void) fclose (f); } else { free (fname); fname = NULL; } } } } return fname;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -