-
-set_option(arg)
- char *arg;
-{
- if (!eqin("-npro", arg))
- if (eqin("-lc", arg)) /* comment line length */
- block_comment_max_col = atoi(param_start);
- else if (eqin("-lp", arg))
- lineup_to_parens = 1;
- else if (eqin("-nlp", arg))
- lineup_to_parens = 0;
- else if (eqin("-l", arg)) /* line length */
- max_col = atoi(param_start);
- else if (eqin("-psl", arg)) /* if true, the names of
- * procedures being defined get
- * placed in column 1 (ie. a
- * newline is placed between the
- * type of the procedure and its
- * name) */
- procnames_start_line = 1;
- else if (eqin("-npsl", arg))
- procnames_start_line = 0;
- else if (eqin("-fc1", arg))
- format_col1_comments = 1;
- else if (eqin("-nfc1", arg))
- format_col1_comments = 0;
- else if (eqin("-pcs", arg)) /* If true, procedure calls look
- * like: foo(bar) rather than foo
- * (bar) */
- proc_calls_space = 1;
- else if (eqin("-npcs", arg))
- proc_calls_space = 0;
- else if (eqin("-ip", arg)) /* indent parameters */
- ps.indent_parameters = 1;
- else if (eqin("-nip", arg)) /* no indent parameters */
- ps.indent_parameters = 0;
- else if (eqin("-cli", arg)) { /* case label indent */
- extern float atof();
-
- ps.case_indent = atof(param_start);
- }
- else if (eqin("-ci",arg))
- continuation_indent = atoi(param_start);
- else if (eqin("-cdb", arg)) /* comment delimiters should be on
- * lines by themselves */
- comment_delimiter_on_blankline = 1;
- else if (eqin("-ncdb", arg)) /* comment delimiters shouldnt be
- * on lines by themselves */
- comment_delimiter_on_blankline = 0;
- else if (eqin("-i", arg)) /* indent width */
- ps.ind_size = atoi(param_start);
- else if (eqin("-cd", arg)) /* indent for comments on
- * declarations */
- ps.decl_com_ind = atoi(param_start);
- else if (eqin("-ce", arg)) /* true iff 'else' should cuddle
- * up to '}' */
- cuddle_else = 1;
- else if (eqin("-c", arg)) /* comment indent */
- ps.com_ind = atoi(param_start);
- else if (eqin("-v", arg)) /* spew out rubbish */
- verbose = true;
- else if (eqin("-nv", arg)) /* keep quiet */
- verbose = false;
- else if (eqin("-dj", arg))
- ps.ljust_decl = true;
- else if (eqin("-ndj", arg))
- ps.ljust_decl = false;
- else if (eqin("-nbc", arg)) /* dont break after commas in
- * declarations */
- ps.leave_comma = true;
- else if (eqin("-bc", arg)) /* break after commas in
- * declarations */
- ps.leave_comma = false;
- else if (eqin("-di", arg)) /* indent from type to varname in
- * a declaration */
- ps.decl_indent = atoi(param_start);
- else if (eqin("-d", arg))
- ps.unindent_displace = atoi(param_start);
- else if (eqin("-br", arg))
- btype_2 = true;
- else if (eqin("-bl", arg))
- btype_2 = false;
- else if (eqin("-st", arg)) { /* input and output on standard IO */
- if (input == 0)
- input = stdin;
- if (output == 0)
- output = stdout;
- } else if (eqin("-ei", arg)) /* else-ifs should be stuck
- * together */
- ps.else_if = 1;
- else if (eqin("-nei", arg)) /* else-ifs should be broken apart */
- ps.else_if = 0;
- else if (eqin("-nce", arg)) /* else should always start a line */
- cuddle_else = 0;
- else if (eqin("-sc", arg)) /* comment continuations should
- * start with a * */
- star_comment_cont = 1;
- else if (eqin("-nsc", arg))
- star_comment_cont = 0; /* comments shouldnt start with a
- * star */
- else if (eqin("-bap", arg)) /* blanklines after procedures */
- blanklines_after_procs = 1;
- else if (eqin("-nbap", arg)) /* blanklines after procedures */
- blanklines_after_procs = 0;
- else if (eqin("-sob", arg)) /* swallow optional blanklines */
- swallow_optional_blanklines = 1;
- else if (eqin("-nsob", arg)) /* swallow optional blanklines */
- swallow_optional_blanklines = 0;
- else if (eqin("-bad", arg)) /* blanklines after declarations */
- blanklines_after_declarations = 1;
- else if (eqin("-nbad", arg)) /* blanklines after declarations */
- blanklines_after_declarations = 0;
- else if (eqin("-bbb", arg)) /* blanklines before blockcomments */
- blanklines_before_blockcomments = 1;
- else if (eqin("-nbbb", arg)) /* blanklines before blockcomments */
- blanklines_before_blockcomments = 0;
- else if (eqin("-troff", arg))
- troff = 1;
- else if (arg[0] == '-' && arg[1] == 'T') /* -Ttypename */
- addkey(arg + 2, 4);
- else { /* illegal arg given */
- printf("Unknown parameter: %s\n", arg);
- exit();
- }
-}
-
-
-/*
- * GETPRO - get profile file profile file is max 127 characters
- */
-getpro(name, buf, len)
- char *name, /* profile file name, as in '.indent.pro' */
- *buf; /* will receive contents of .pro file */
-{
- register chn,
- n;
- char file[100];
-
- file[0] = 0;
- strcat(file, getenv("HOME"));
- strcat(file, "/");
- strcat(file, name);
- if ((chn = open(name, 0)) < 0)
- chn = open(file, 0);
- if (chn < 0)
- return (-1);
- n = read(chn, buf, len);
- if (n < 0)
- return (-1);
- buf[n--] = 0; /* null terminate line */
- if (buf[n] == '\n')
- buf[n] = 0;
- close(chn);
- return (0);
-}
-
-
-/*
- * strip off arguments in a string: p is address of a character pointer
- * nextchr returns pointer to front of first arg arg is null terminated. p
- * is reset to after arg for subsequent calls
- */
-char *
-nxtarg(p)
- char **p;
-{
- register char *f,
- *b;
-
- f = *p;
- while (*f && *f <= ' ')
- f++;
- b = f;
- while (*b > ' ')
- b++;
- if (*b != 0)
- *b++ = 0;
- *p = b;
- return (f);
-}
-
-
-set_profile()
-{
- char line[1000],
- *b;
- register char *f;
- extern char *nxtarg();
-
- if (getpro(".indent.pro", line, sizeof line) < 0)
- return;
- b = line;
- if (verbose)
- printf("profile: %s\n", b);
- while (*(f = nxtarg(&b)))
- set_option(f);