[BACK]Return to indent.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / indent

Diff for /src/usr.bin/indent/indent.c between version 1.8 and 1.9

version 1.8, 2000/07/25 17:08:12 version 1.9, 2001/01/08 07:14:42
Line 1 
Line 1 
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
   
 /*  /*
  * Copyright (c) 1985 Sun Microsystems, Inc.   * Copyright (c) 1980, 1993
  * Copyright (c) 1980 The Regents of the University of California.   *      The Regents of the University of California.
  * Copyright (c) 1976 Board of Trustees of the University of Illinois.   * Copyright (c) 1976 Board of Trustees of the University of Illinois.
    * Copyright (c) 1985 Sun Microsystems, Inc.
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 38 
Line 39 
 #ifndef lint  #ifndef lint
 char copyright[] =  char copyright[] =
 "@(#) Copyright (c) 1985 Sun Microsystems, Inc.\n\  "@(#) Copyright (c) 1985 Sun Microsystems, Inc.\n\
  @(#) Copyright (c) 1980 The Regents of the University of California.\n\   @(#) Copyright (c) 1980, 1993\n\
            The Regents of the University of California.\n\
  @(#) Copyright (c) 1976 Board of Trustees of the University of Illinois.\n\   @(#) Copyright (c) 1976 Board of Trustees of the University of Illinois.\n\
  All rights reserved.\n";   All rights reserved.\n";
 #endif /* not lint */  #endif /* not lint */
   
 #ifndef lint  #ifndef lint
 /*static char sccsid[] = "from: @(#)indent.c    5.16 (Berkeley) 2/26/91";*/  /*static char sccsid[] = "@(#)indent.c  5.17 (Berkeley) 6/7/93";*/
 static char rcsid[] = "$OpenBSD$";  static char rcsid[] = "$OpenBSD$";
 #endif /* not lint */  #endif /* not lint */
   
Line 101 
Line 103 
     \*-----------------------------------------------*/      \*-----------------------------------------------*/
   
   
       hd_type = 0;
     ps.p_stack[0] = stmt;       /* this is the parser's stack */      ps.p_stack[0] = stmt;       /* this is the parser's stack */
     ps.last_nl = true;          /* this is true if the last thing scanned was      ps.last_nl = true;          /* this is true if the last thing scanned was
                                  * a newline */                                   * a newline */
Line 109 
Line 112 
     labbuf = (char *) malloc(bufsize);      labbuf = (char *) malloc(bufsize);
     codebuf = (char *) malloc(bufsize);      codebuf = (char *) malloc(bufsize);
     tokenbuf = (char *) malloc(bufsize);      tokenbuf = (char *) malloc(bufsize);
       if (combuf == NULL || labbuf == NULL || codebuf == NULL ||
           tokenbuf == NULL)
               errx(1, "out of memory");
     l_com = combuf + bufsize - 5;      l_com = combuf + bufsize - 5;
     l_lab = labbuf + bufsize - 5;      l_lab = labbuf + bufsize - 5;
     l_code = codebuf + bufsize - 5;      l_code = codebuf + bufsize - 5;
Line 123 
Line 129 
     s_token = e_token = tokenbuf + 1;      s_token = e_token = tokenbuf + 1;
   
     in_buffer = (char *) malloc(10);      in_buffer = (char *) malloc(10);
       if (in_buffer == NULL)
               errx(1, "out of memory");
     in_buffer_limit = in_buffer + 8;      in_buffer_limit = in_buffer + 8;
     buf_ptr = buf_end = in_buffer;      buf_ptr = buf_end = in_buffer;
     line_no = 1;      line_no = 1;
Line 212 
Line 220 
         fprintf(stderr, "usage: indent file [ outfile ] [ options ]\n");          fprintf(stderr, "usage: indent file [ outfile ] [ options ]\n");
         exit(1);          exit(1);
     }      }
     if (output == NULL)      if (output == NULL) {
         if (troff)          if (troff)
             output = stdout;              output = stdout;
         else {          else {
             out_name = in_name;              out_name = in_name;
             bakcopy();              bakcopy();
         }          }
       }
     if (ps.com_ind <= 1)      if (ps.com_ind <= 1)
         ps.com_ind = 2;         /* dont put normal comments before column 2 */          ps.com_ind = 2;         /* dont put normal comments before column 2 */
     if (troff) {      if (troff) {
Line 251 
Line 260 
   
     parse(semicolon);      parse(semicolon);
     {      {
         register char *p = buf_ptr;          char *p = buf_ptr;
         register    col = 1;          int   col = 1;
   
         while (1) {          while (1) {
             if (*p == ' ')              if (*p == ' ')
Line 774 
Line 783 
                 /* ?            dec_ind = 0; */                  /* ?            dec_ind = 0; */
             }              }
             else {              else {
                 ps.decl_on_line = false;        /* we cant be in the middle of                  ps.decl_on_line = false;
                                                  * a declaration, so dont do                  /* we can't be in the middle of a declaration, so don't do
                                                  * special indentation of                   * special indentation of comments */
                                                  * comments */  
                 if (blanklines_after_declarations_at_proctop                  if (blanklines_after_declarations_at_proctop
                         && ps.in_parameter_declaration)                          && ps.in_parameter_declaration)
                     postfix_blankline_requested = 1;                      postfix_blankline_requested = 1;
Line 908 
Line 916 
                     *e_code++ = ' ';                      *e_code++ = ' ';
                 ps.want_blank = false;                  ps.want_blank = false;
                 if (is_procname == 0 || !procnames_start_line) {                  if (is_procname == 0 || !procnames_start_line) {
                     if (!ps.block_init)                      if (!ps.block_init) {
                         if (troff && !ps.dumped_decl_indent) {                          if (troff && !ps.dumped_decl_indent) {
                             sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);                              sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
                             ps.dumped_decl_indent = 1;                              ps.dumped_decl_indent = 1;
Line 919 
Line 927 
                                 CHECK_SIZE_CODE;                                  CHECK_SIZE_CODE;
                                 *e_code++ = ' ';                                  *e_code++ = ' ';
                             }                              }
                       }
                 }                  }
                 else {                  else {
                     if (dec_ind && s_code != e_code)                      if (dec_ind && s_code != e_code)
Line 1071 
Line 1080 
   
             if (strncmp(s_lab, "#if", 3) == 0) {              if (strncmp(s_lab, "#if", 3) == 0) {
                 if (blanklines_around_conditional_compilation) {                  if (blanklines_around_conditional_compilation) {
                     register    c;                      int    c;
                     prefix_blankline_requested++;                      prefix_blankline_requested++;
                     while ((c = getc(input)) == '\n');                      while ((c = getc(input)) == '\n');
                     ungetc(c, input);                      ungetc(c, input);
Line 1142 
Line 1151 
     int         n,      int         n,
                 bakchn;                  bakchn;
     char        buff[8 * 1024];      char        buff[8 * 1024];
     register char *p;      char       *p;
   
     /* construct file name .Bfile */      /* construct file name .Bfile */
     for (p = in_name; *p; p++); /* skip to end of string */      for (p = in_name; *p; p++); /* skip to end of string */
Line 1150 
Line 1159 
         p--;          p--;
     if (*p == '/')      if (*p == '/')
         p++;          p++;
     sprintf(bakfile, "%s.BAK", p);      if (snprintf(bakfile, MAXPATHLEN, "%s.BAK", p) >= MAXPATHLEN)
               errx(1, "%s.BAK: %s", p, strerror(ENAMETOOLONG));
   
     /* copy in_name to backup file */      /* copy in_name to backup file */
     bakchn = creat(bakfile, 0600);      bakchn = creat(bakfile, 0600);

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9