fsplit problems with $ and _

michael sweet sweetmr at SCT60A.SUNYCT.EDU
Wed Mar 27 22:40:46 AEST 1991


In a recent project, I had similar problems, as well as running into other 
problems which the IRIX version of fsplit has...

 - large source files are not completely split (>64k, I think)  Unfortunately,
   most of the code we were porting was 300k or larger source files; one was
   almost 1 Mb!
 - The files created are always all uppercase- a pain in the A**...
 - BLOCK DATA segments didn't get split out of a file.

Anyways, I ended up writing my own quick-and-dirty fsplit; one that didn't
have these problems.  The code is hardly documented, but it works well.
The following is the code for 'splitf'.  'splitf' is equivalent to doing a
'fsplit -s', only it generates lowercase filenames and actually *works*. :)

Hope you like it!

 -Mike

--------BEGIN--splitf.c---------------CUT-HERE----------------
/*
 "splitf.c" - split FORTRASH file into separate files, one per sub...

 by Mike Sweet 3/15/91
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>


void splitfile(filename)
char *filename;
{
 char line[255],*s;
 char name[255],*nm;
 FILE *curfile; /* current output file... */
 FILE *infile;  /* current input file... */


 curfile = NULL;
 if ((infile = fopen(filename,"r")) == NULL)
  {
   fprintf(stderr,"splitf: unable to open \"%s\"!\n",filename);
   return;
  };

 while (fgets(line,255,infile))
  {
   for (s = line;*s && *s == ' ';s++);
   if (strncasecmp(s,"REAL",4) == 0 ||
       strncasecmp(s,"INTEGER",7) == 0 ||
       strncasecmp(s,"CHARACTER",9) == 0)
    {
     while (*s != ' ' && *s)
      s++;
     while (*s == ' ' && *s)
      s++;
    };
   if (strncasecmp(s,"PROGRAM",7) == 0 ||
       strncasecmp(s,"SUBROUTINE",10) == 0 ||
       strncasecmp(s,"FUNCTION",8) == 0 ||
       strncasecmp(s,"BLOCK DATA",10) == 0)
    {
     if (curfile)
      fclose(curfile);
     while (*s != ' ' && *s)
      s++;
     while (*s == ' ' && *s)
      s++;
     nm = name;
     while (isalnum(*s) && *s)
      {
       *nm = tolower(*s);
       nm++;
       s++;
      };
     *nm = 0;
     strcat(name,".f");
     fprintf(stderr,"splitf: new file - \"%s\"\n",name);
     if ((curfile = fopen(name,"w")) == NULL)
      fprintf(stderr,"splitf: unable to create \"%s\"!\n",name);
    };

   line[72] = 0;
   s = line + strlen(line);
   do
    {
     s--;
     if (*s == ' ' || *s == '\n')
      *s = 0;
    }
   while (!*s);

   if (curfile)
    fprintf(curfile,"%s\n",line);
  };

 fclose(infile);
}


main(argc,argv)
int argc;
char *argv[];
{
 int x;


 if (argc < 2)
  fprintf(stderr,"splitf: usage is \'splitf <FORTRAN files>\'\n");
 else
  for (x = 1;x < argc; x++)
   splitfile(argv[x]);

 exit(0);
}
--------END----splitf.c---------------CUT-HERE----------------



More information about the Comp.sys.sgi mailing list