You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pi...@apache.org on 2001/07/13 04:59:29 UTC

cvs commit: jakarta-tomcat-connectors/webapp/support formatfile.c

pier        01/07/12 19:59:29

  Added:       webapp/support formatfile.c
  Log:
  Added a simple and stupid proggie that:
  - Reads your source file
  - Trims all the white-space on the right of each line
  - Converts tabs-to-spaces (1 tab = 4 spaces) on the left of each line
  - Tells you if one of the lines is longer than 80 columns
  This is what I use for checking/cleaning sources before commits (and
  sometimes after, when I forget!) and it's kinda useful.
  
  DO NOT USE ON MAKEFILES: Makefiles REQUIRE tab characters.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-connectors/webapp/support/formatfile.c
  
  Index: formatfile.c
  ===================================================================
  #include <stdio.h>
  
  int main(void) {
      char buf[1024];
      char *ret=NULL;
      int x=0;
      int y=0;
      int k=0;
      int s=0;
      int l=0;
  
      while ((ret=fgets(buf,1024,stdin))!=NULL) {
          for (x=strlen(ret); x>=0; x--) {
              if((ret[x]=='\0')||(ret[x]=='\t')||(ret[x]=='\n')||(ret[x]==' '))
                  ret[x]='\0';
              else break;
          }
  
          k=0;
          for (x=0; x<strlen(ret); x++) {
              if (ret[x]=='\t') {
                  fprintf(stdout," ");
                  k++;
                  s=((((k/4)+1)*4)-k);
                  if (s==4) s=0;
                  for (y=0; y<s; y++) fprintf(stdout," ");
                  k+=s;
              } else {
                  fprintf(stdout,"%c",ret[x]);
                  k++;
              }
          }
          fprintf(stdout,"\n");
          l++;
          if (k>=80) fprintf(stderr,"line %4d (%4d) [%s]\n",l,k,ret);
      }
  }