⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 args.c

📁 代码格式化工具。 其实就是linux下indent的windows版本。
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) 1999, 2000 Carlo Wood.  All rights reserved. * Copyright (c) 1994 Joseph Arceneaux.  All rights reserved. * Copyright (c) 1992 Free Software Foundation, Inc.  All rights reserved. * * Copyright (c) 1985 Sun Microsystems, Inc. * Copyright (c) 1980 The Regents of the University of California. * Copyright (c) 1976 Board of Trustees ofthe University of Illinois. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that * the above copyright notice and this paragraph are duplicated in all such * forms and that any documentation, advertising materials, and other * materials related to such distribution and use acknowledge that the * software was developed by the University of California, Berkeley, the * University of Illinois, Urbana, and Sun Microsystems, Inc.  The name of * either University or Sun Microsystems may not be used to endorse or * promote products derived from this software without specific prior written * permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.* * * HISTORY * 2002-03-14 DI restructured scan_profile and fixed bug handling comments * 2002-06-13 DI fixed handling of missing int parameter. * 2002-08-05 Matthias <moh@itec.uni-klu.ac.at> and Eric Lloyd <ewlloyd@neta.com> *            Added support for -brf to place function opening brace after function *            declaration. * 2002-11-10 Cristalle Azundris Sabon <cristalle@azundris.com> *            Added --preprocessor-indentation (ppi)   if set, will indent nested *            preprocessor-statements with n spaces per level.  overrides -lps. *//* Argument scanning and profile reading code.  Default parameters are set * here as well. */#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "sys.h"#include "indent.h"#include "args.h"#include "globs.h"RCSTAG_CC ("$Id: args.c,v 1.42 2002/11/10 21:02:48 david Exp $");#define KR_SETTINGS_STRING (int *) \     "-nbad\0-bap\0-nbc\0-bbo\0-hnl\0-br\0-brs\0-c33\0-cd33\0" \     "-ncdb\0-ce\0-ci4\0-cli0\0-d0\0-di1\0-nfc1\0-i4\0-ip0\0-l75\0-lp\0" \     "-npcs\0-nprs\0-npsl\0-sai\0-saf\0-saw\0-cs\0-nsc\0-nsob\0-nfca\0-cp33\0-nss\0"#define GNU_SETTINGS_STRING  (int *) \     "-nbad\0-bap\0-bbo\0-hnl\0-nbc\0-bl\0-bls\0-ncdb\0-cs\0-nce\0" \     "-di2\0-ndj\0-nfc1\0-i2\0-ip5\0-lp\0-pcs\0-nprs\0-psl\0-nsc\0-sai\0-saf\0-saw\0-nsob\0" \     "-bli2\0-cp1\0-nfca\0"#define ORIG_SETTINGS_STRING (int *) \     "-nbap\0-nbad\0-bbo\0-hnl\0-bc\0-br\0-brs\0-c33\0-cd33\0-cdb\0" \     "-ce\0-ci4\0-cli0\0-cp33\0-di16\0-fc1\0-fca\0-i4\0-l75\0-lp\0-npcs\0-nprs\0" \     "-psl\0-sc\0-sai\0-saf\0-saw\0-nsob\0-nss\0-ts8\0"/* profile types */typedef enum profile{  PRO_BOOL,			/* boolean */  PRO_INT,			/* integer */  PRO_IGN,			/* ignore it */  PRO_KEY,			/* -T switch */  PRO_SETTINGS,			/* bundled set of settings */  PRO_PRSTRING,			/* Print string and exit */  PRO_FUNCTION			/* Call the associated function. */} profile_ty;/* profile specials for booleans */typedef enum on_or_off{  ONOFF_NA,			/* Not applicable.  Used in table for				 * non-booleans.  */  OFF,				/* This option turns on the boolean variable				 * in question.  */  ON				/* it turns it off */} on_or_off_ty;/* Explicit flags for each option.  */static int exp_T = 0;static int exp_bacc = 0;static int exp_badp = 0;static int exp_bad = 0;static int exp_bap = 0;static int exp_bbb = 0;static int exp_bbo = 0;static int exp_bc = 0;static int exp_bl = 0;static int exp_blf = 0;static int exp_bli = 0;static int exp_bls = 0;static int exp_bs = 0;static int exp_c = 0;static int exp_cbi = 0;static int exp_cdb = 0;static int exp_cd = 0;static int exp_cdw = 0;static int exp_ce = 0;static int exp_ci = 0;static int exp_cli = 0;static int exp_cp = 0;static int exp_cpp = 0;static int exp_cs = 0;static int exp_d = 0;static int exp_bfda = 0;static int exp_bfde = 0;static int exp_di = 0;static int exp_dj = 0;static int exp_eei = 0;static int exp_fc1 = 0;static int exp_fca = 0;static int exp_gnu = 0;static int exp_hnl = 0;static int exp_i = 0;static int exp_ip = 0;static int exp_kr = 0;static int exp_l = 0;static int exp_lc = 0;static int exp_lp = 0;static int exp_lps = 0;static int exp_nip = 0;static int exp_o = 0;static int exp_orig = 0;static int exp_pcs = 0;static int exp_pi = 0;static int exp_pmt = 0;static int exp_pro = 0;static int exp_prs = 0;static int exp_psl = 0;static int exp_ppi = 0;		/* force preprocessor indent at width... */static int exp_sai = 0;static int exp_saf = 0;static int exp_saw = 0;static int exp_sbi = 0;static int exp_sc = 0;static int exp_sob = 0;static int exp_ss = 0;static int exp_st = 0;static int exp_ts = 0;static int exp_ut = 0;static int exp_v = 0;static int exp_version = 0;/* The following structure is controlled by command line parameters and * their meaning is explained in indent.h.  */user_options_ty settings = { 0 };static void usage (void);/* N.B.: because of the way the table here is scanned, options whose names * are substrings of other options must occur later; that is, with -lp vs -l, * -lp must be first.  Also, while (most) booleans occur more than once, the * last default value is the one actually assigned. */typedef struct pro{  char *p_name;			/* option name, e.g. "bl", "cli" */  profile_ty p_type;		/* profile type */  int p_default;		/* the default value (if PRO_BOOL or PRO_INT) */  on_or_off_ty p_special;	/* If p_type == PRO_BOOL, ON or OFF to tell how				 * this switch affects the variable. Not used				 * for other p_type's.  */  int *p_obj;			/* if p_type == PRO_SETTINGS, a (char *) pointing				 *    to a list of the switches to set, separated by				 *    NULLs, terminated by 2 NULLs.				 * if p_type ==PRO_BOOL or PRO_INT, the address of				 *     the variable that gets set by the option.				 * if p_type == PRO_PRSTRING, a (char *) pointing				 *     to the string.				 * if p_type == PRO_FUNCTION, a pointer to a				 *     function to be called. */  int *p_explicit;		/* Points to a nonzero value (allocated statically				 * for all options) if the option has been specified				 * explicitly.  This is necessary because for				 * boolean options, the options to set and reset the				 * variable must share the explicit flag.  */} pro_ty;#ifdef BERKELEY_DEFAULTS/* Settings for original defaults */const pro_ty pro[] = {  {"version", PRO_PRSTRING, 0, ONOFF_NA, (int *) VERSION, &exp_version},  {"v", PRO_BOOL, false, ON, &settings.verbose, &exp_v},  {"ut", PRO_BOOL, true, ON, &settings.use_tabs, &exp_ut},  {"ts", PRO_INT, 8, ONOFF_NA, &settings.tabsize, &exp_ts},  {"st", PRO_BOOL, false, ON, &settings.use_stdout, &exp_st},  {"ss", PRO_BOOL, false, ON, &settings.space_sp_semicolon, &exp_ss},  {"sob", PRO_BOOL, false, ON, &settings.swallow_optional_blanklines,   &exp_sob},  {"sc", PRO_BOOL, true, ON, &settings.star_comment_cont, &exp_sc},  {"sbi", PRO_INT, 0, ONOFF_NA, &settings.struct_brace_indent, &exp_sbi},  {"saw", PRO_BOOL, true, ON, &settings.space_after_while, &exp_saw},  {"sai", PRO_BOOL, true, ON, &settings.space_after_if, &exp_sai},  {"saf", PRO_BOOL, true, ON, &settings.space_after_for, &exp_saf},  {"psl", PRO_BOOL, true, ON, &settings.procnames_start_line, &exp_psl},  {"prs", PRO_BOOL, false, ON, &settings.parentheses_space, &exp_prs},#ifdef PRESERVE_MTIME  {"pmt", PRO_BOOL, false, ON, &settings.preserve_mtime, &exp_pmt},#endif  {"pi", PRO_INT, -1, ONOFF_NA, &settings.paren_indent, &exp_pi},  {"pcs", PRO_BOOL, false, ON, &settings.proc_calls_space, &exp_pcs},  {"o", PRO_BOOL, false, ON, &settings.expect_output_file, &exp_o},  {"nv", PRO_BOOL, false, OFF, &settings.verbose, &exp_v},  {"nut", PRO_BOOL, true, OFF, &settings.use_tabs, &exp_ut},  {"nss", PRO_BOOL, false, OFF, &settings.space_sp_semicolon, &exp_ss},  {"nsob", PRO_BOOL, false, OFF, &settings.swallow_optional_blanklines,   &exp_sob},  {"nsc", PRO_BOOL, true, OFF, &settings.star_comment_cont, &exp_sc},  {"nsaw", PRO_BOOL, true, OFF, &settings.space_after_while, &exp_saw},  {"nsai", PRO_BOOL, true, OFF, &settings.space_after_if, &exp_sai},  {"nsaf", PRO_BOOL, true, OFF, &settings.space_after_for, &exp_saf},  {"npsl", PRO_BOOL, true, OFF, &settings.procnames_start_line, &exp_psl},  {"nprs", PRO_BOOL, false, OFF, &settings.parentheses_space, &exp_prs},  {"npro", PRO_IGN, 0, ONOFF_NA, 0, &exp_pro},#ifdef PRESERVE_MTIME  {"npmt", PRO_BOOL, false, OFF, &settings.preserve_mtime, &exp_pmt},#endif  {"npcs", PRO_BOOL, false, OFF, &settings.proc_calls_space, &exp_pcs},  {"nlps", PRO_BOOL, false, OFF, &settings.leave_preproc_space, &exp_lps},  {"nlp", PRO_BOOL, true, OFF, &settings.lineup_to_parens, &exp_lp},  {"nip", PRO_SETTINGS, 0, ONOFF_NA, (int *) "-ip0", &exp_nip},  {"nhnl", PRO_BOOL, true, OFF, &settings.honour_newlines, &exp_hnl},  {"nfca", PRO_BOOL, true, OFF, &settings.format_comments, &exp_fca},  {"nfc1", PRO_BOOL, true, OFF, &settings.format_col1_comments, &exp_fc1},  {"neei", PRO_BOOL, false, OFF, &settings.extra_expression_indent, &exp_eei},  {"ndj", PRO_BOOL, false, OFF, &settings.ljust_decl, &exp_dj},  {"ncs", PRO_BOOL, true, OFF, &settings.cast_space, &exp_cs},  {"nce", PRO_BOOL, true, OFF, &settings.cuddle_else, &exp_ce},  {"ncdw", PRO_BOOL, false, OFF, &settings.cuddle_do_while, &exp_cdw},  {"ncdb", PRO_BOOL, true, OFF, &settings.comment_delimiter_on_blankline,   &exp_cdb},  {"nbs", PRO_BOOL, false, OFF, &settings.blank_after_sizeof, &exp_bs},  {"nbfda", PRO_BOOL, false, OFF, &settings.break_function_decl_args,   &exp_bfda},  {"nbfde", PRO_BOOL, false, OFF, &settings.break_function_decl_args_end,   &exp_bfde},  {"nbc", PRO_BOOL, true, ON, &settings.leave_comma, &exp_bc},  {"nbbo", PRO_BOOL, true, OFF, &settings.break_before_boolean_operator,   &exp_bbo},  {"nbbb", PRO_BOOL, false, OFF, &settings.blanklines_before_blockcomments,   &exp_bbb},  {"nbap", PRO_BOOL, false, OFF, &settings.blanklines_after_procs, &exp_bap},  {"nbadp", PRO_BOOL, false, OFF,   &settings.blanklines_after_declarations_at_proctop, &exp_badp},  {"nbad", PRO_BOOL, false, OFF, &settings.blanklines_after_declarations,   &exp_bad},  {"nbacc", PRO_BOOL, false, OFF,   &settings.blanklines_around_conditional_compilation, &exp_bacc},  {"lps", PRO_BOOL, false, ON, &settings.leave_preproc_space, &exp_lps},  {"lp", PRO_BOOL, true, ON, &settings.lineup_to_parens, &exp_lp},  {"lc", PRO_INT, DEFAULT_RIGHT_COMMENT_MARGIN, ONOFF_NA,   &settings.comment_max_col, &exp_lc},  {"l", PRO_INT, DEFAULT_RIGHT_MARGIN, ONOFF_NA, &settings.max_col, &exp_l},  {"kr", PRO_SETTINGS, 0, ONOFF_NA, KR_SETTINGS_STRING, &exp_kr},  {"ip", PRO_INT, 4, ONOFF_NA, &settings.indent_parameters, &exp_ip},  {"i", PRO_INT, 4, ONOFF_NA, &settings.ind_size, &exp_i},  {"hnl", PRO_BOOL, true, ON, &settings.honour_newlines, &exp_hnl},  {"h", PRO_FUNCTION, 0, ONOFF_NA, (int *) usage, &exp_version},  {"gnu", PRO_SETTINGS, 0, ONOFF_NA, GNU_SETTINGS_STRING, &exp_gnu},  {"fca", PRO_BOOL, true, ON, &settings.format_comments, &exp_fca},  {"fc1", PRO_BOOL, true, ON, &settings.format_col1_comments, &exp_fc1},  {"eei", PRO_BOOL, false, ON, &settings.extra_expression_indent, &exp_eei},  {"dj", PRO_BOOL, false, ON, &settings.ljust_decl, &exp_dj},  {"di", PRO_INT, 16, ONOFF_NA, &settings.decl_indent, &exp_di},  {"d", PRO_INT, 0, ONOFF_NA, &settings.unindent_displace, &exp_d},  {"cs", PRO_BOOL, true, ON, &settings.cast_space, &exp_cs},  {"cp", PRO_INT, 33, ONOFF_NA, &settings.else_endif_col, &exp_cp},  {"cli", PRO_INT, 0, ONOFF_NA, &settings.case_indent, &exp_cli},  {"ci", PRO_INT, 4, ONOFF_NA, &settings.continuation_indent, &exp_ci},  {"ce", PRO_BOOL, true, ON, &settings.cuddle_else, &exp_ce},  {"cdw", PRO_BOOL, false, ON, &settings.cuddle_do_while, &exp_cdw},  {"cdb", PRO_BOOL, true, ON, &settings.comment_delimiter_on_blankline,   &exp_cdb},  {"cd", PRO_INT, 33, ONOFF_NA, &settings.decl_com_ind, &exp_cd},  {"cbi", PRO_INT, -1, ONOFF_NA, &settings.case_brace_indent, &exp_cbi},  {"c++", PRO_BOOL, false, ON, &settings.c_plus_plus, &exp_cpp},  {"c", PRO_INT, 33, ONOFF_NA, &settings.com_ind, &exp_c},  {"bs", PRO_BOOL, false, ON, &settings.blank_after_sizeof, &exp_bs},  {"brs", PRO_BOOL, true, ON, &settings.braces_on_struct_decl_line, &exp_bls},  {"brf", PRO_BOOL, false, ON, &settings.braces_on_func_def_line, &exp_blf},  {"br", PRO_BOOL, true, ON, &settings.btype_2, &exp_bl},  {"bls", PRO_BOOL, true, OFF, &settings.braces_on_struct_decl_line,   &exp_bls},  {"blf", PRO_BOOL, false, OFF, &settings.braces_on_func_def_line, &exp_blf},  {"bli", PRO_INT, 0, ONOFF_NA, &settings.brace_indent, &exp_bli},  {"bl", PRO_BOOL, true, OFF, &settings.btype_2, &exp_bl},  {"bfda", PRO_BOOL, false, ON, &settings.break_function_decl_args,   &exp_bfda},  {"bfde", PRO_BOOL, false, ON, &settings.break_function_decl_args_end,   &exp_bfde},  {"bc", PRO_BOOL, true, OFF, &settings.leave_comma, &exp_bc},  {"bbo", PRO_BOOL, true, ON, &settings.break_before_boolean_operator,   &exp_bbo},  {"bbb", PRO_BOOL, false, ON, &settings.blanklines_before_blockcomments,   &exp_bbb},  {"bap", PRO_BOOL, false, ON, &settings.blanklines_after_procs, &exp_bap},  {"badp", PRO_BOOL, false, ON,   &settings.blanklines_after_declarations_at_proctop, &exp_badp},  {"bad", PRO_BOOL, false, ON, &settings.blanklines_after_declarations,   &exp_bad},  {"bacc", PRO_BOOL, false, ON,   &settings.blanklines_around_conditional_compilation, &exp_bacc},  {"T", PRO_KEY, 0, ONOFF_NA, 0, &exp_T},  {"ppi", PRO_INT, 0, ONOFF_NA, &settings.force_preproc_width, &exp_ppi},  /* Signify end of structure.  */  {0, PRO_IGN, 0, ONOFF_NA, 0, 0}};#else /* Default to GNU style *//* Changed to make GNU style the default. */const pro_ty pro[] = {  {"version", PRO_PRSTRING, 0, ONOFF_NA, (int *) VERSION, &exp_version},  {"v", PRO_BOOL, false, ON, &settings.verbose, &exp_v},  {"ut", PRO_BOOL, true, ON, &settings.use_tabs, &exp_ut},  {"ts", PRO_INT, 8, ONOFF_NA, &settings.tabsize, &exp_ts},  {"st", PRO_BOOL, false, ON, &settings.use_stdout, &exp_st},  {"ss", PRO_BOOL, false, ON, &settings.space_sp_semicolon, &exp_ss},  {"sob", PRO_BOOL, false, ON, &settings.swallow_optional_blanklines,   &exp_sob},  {"sc", PRO_BOOL, false, ON, &settings.star_comment_cont, &exp_sc},  {"sbi", PRO_INT, 0, ONOFF_NA, &settings.struct_brace_indent, &exp_sbi},  {"saw", PRO_BOOL, true, ON, &settings.space_after_while, &exp_saw},  {"sai", PRO_BOOL, true, ON, &settings.space_after_if, &exp_sai},  {"saf", PRO_BOOL, true, ON, &settings.space_after_for, &exp_saf},  {"psl", PRO_BOOL, true, ON, &settings.procnames_start_line, &exp_psl},  {"prs", PRO_BOOL, false, ON, &settings.parentheses_space, &exp_prs},#ifdef PRESERVE_MTIME  {"pmt", PRO_BOOL, false, ON, &settings.preserve_mtime, &exp_pmt},#endif  {"pi", PRO_INT, -1, ONOFF_NA, &settings.paren_indent, &exp_pi},  {"pcs", PRO_BOOL, true, ON, &settings.proc_calls_space, &exp_pcs},  {"orig", PRO_SETTINGS, 0, ONOFF_NA, ORIG_SETTINGS_STRING, &exp_orig},  {"o", PRO_BOOL, false, ON, &settings.expect_output_file, &exp_o},  {"nv", PRO_BOOL, false, OFF, &settings.verbose, &exp_v},  {"nut", PRO_BOOL, true, OFF, &settings.use_tabs, &exp_ut},  {"nss", PRO_BOOL, false, OFF, &settings.space_sp_semicolon, &exp_ss},  {"nsob", PRO_BOOL, false, OFF, &settings.swallow_optional_blanklines,   &exp_sob},  {"nsc", PRO_BOOL, false, OFF, &settings.star_comment_cont, &exp_sc},  {"nsaw", PRO_BOOL, true, OFF, &settings.space_after_while, &exp_saw},  {"nsai", PRO_BOOL, true, OFF, &settings.space_after_if, &exp_sai},  {"nsaf", PRO_BOOL, true, OFF, &settings.space_after_for, &exp_saf},  {"npsl", PRO_BOOL, true, OFF, &settings.procnames_start_line, &exp_psl},  {"nprs", PRO_BOOL, false, OFF, &settings.parentheses_space, &exp_prs},  {"npro", PRO_IGN, 0, ONOFF_NA, 0, &exp_pro},#ifdef PRESERVE_MTIME  {"npmt", PRO_BOOL, false, OFF, &settings.preserve_mtime, &exp_pmt},#endif  {"npcs", PRO_BOOL, true, OFF, &settings.proc_calls_space, &exp_pcs},  {"nlps", PRO_BOOL, false, OFF, &settings.leave_preproc_space, &exp_lps},  {"nlp", PRO_BOOL, true, OFF, &settings.lineup_to_parens, &exp_lp},  {"nip", PRO_SETTINGS, 0, ONOFF_NA, (int *) "-ip0\0", &exp_nip},  {"nhnl", PRO_BOOL, true, OFF, &settings.honour_newlines, &exp_hnl},  {"nfca", PRO_BOOL, false, OFF, &settings.format_comments, &exp_fca},  {"nfc1", PRO_BOOL, false, OFF, &settings.format_col1_comments, &exp_fc1},  {"neei", PRO_BOOL, false, OFF, &settings.extra_expression_indent, &exp_eei},  {"ndj", PRO_BOOL, false, OFF, &settings.ljust_decl, &exp_dj},  {"ncs", PRO_BOOL, true, OFF, &settings.cast_space, &exp_cs},  {"nce", PRO_BOOL, false, OFF, &settings.cuddle_else, &exp_ce},  {"ncdw", PRO_BOOL, false, OFF, &settings.cuddle_do_while, &exp_cdw},  {"ncdb", PRO_BOOL, false, OFF, &settings.comment_delimiter_on_blankline,   &exp_cdb},  {"nbs", PRO_BOOL, false, OFF, &settings.blank_after_sizeof, &exp_bs},  {"nbfda", PRO_BOOL, false, OFF, &settings.break_function_decl_args,   &exp_bfda},  {"nbfde", PRO_BOOL, false, OFF, &settings.break_function_decl_args_end,   &exp_bfde},  {"nbc", PRO_BOOL, true, ON, &settings.leave_comma, &exp_bc},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -