home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / autopsp.zip / LOC / LOC4CPP.BAK < prev    next >
Text File  |  1994-01-24  |  7KB  |  266 lines

  1. /* MAIN object*/
  2. // This program counts the lines of code in a project by reading
  3. //   each source file in a directory, determining which object
  4. //   that files contains a part of and then totaling all the object
  5. //   lines of code, reporting them, and from that finding the
  6. //   total lines of code and reporting it.
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11.  
  12. /* ARG!!! Hack Hack Hack!!!*/
  13. char ReadDir[80];
  14.  
  15. #include "e:\pspsrc\llist.h"
  16. #include "oi.h"
  17.  
  18. int  FoundObjectInList(LList *ObjL, char *name);
  19. void BuildList(LList *ObjL);
  20. int  CountList(LList *ObjL);
  21. void PrintList(LList *ObjL, int TLOC);
  22.  
  23. LList       ObjectList;         // List of Objects
  24. void main(int argc,char *argv[])
  25. {
  26.   int         TLOC=0;
  27.  
  28.   if (argc==0){
  29.     printf("Please supply the directory to scan as a parameter.\n");
  30.     exit (0);
  31.   }
  32.  
  33.   strcpy(ReadDir,argv[1]);        // Just slip the parm in here.
  34.  
  35.                                   // Scan all files in said directory,
  36.                                   //   Everything with the proper extension
  37.                                   //   is assigned to an object.
  38.   BuildList(&ObjectList);
  39.  
  40.                                   // Go through all objects and inform
  41.                   //   them that they should count their
  42.                                   //   OLOC.  Returns total counted.
  43.   TLOC=CountList(&ObjectList);
  44.  
  45.                   // Have each object print it's name and count,
  46.                                   //   and then prints the total.
  47.   PrintList(&ObjectList, TLOC);
  48. }
  49.  
  50. int  FoundObjectInList(LList *ObjL, char *name)
  51. {
  52.   CObjectInfo *temp;              // Pointer to an Object Info class
  53.  
  54.   if (ObjL->NumNodes==0){
  55.     return(0);
  56.   }
  57.  
  58.   ObjL->Restart();                    // Start at start of list.
  59.   do{
  60.     temp=(CObjectInfo*)ObjL->Retrieve(LL_DATA);
  61.     if (0==strcmp(temp->WhatIsYourName(),name)){
  62.       return(1);
  63.     }
  64.     ObjL->Next();
  65.                                   // Check objects until out of objects
  66.                                   // or name is found.
  67.   } while (ObjL->AtEnd == FALSE);
  68.   return(0);
  69. }
  70.  
  71. void BuildList(LList *ObjL)
  72. {
  73.   char   dirtemp[60];
  74.   char   dirname[60];
  75.   char   opnfile[60];
  76.   char   tempfile[60];
  77.   int    readtype=0;
  78.  
  79. //  DIR    *dir;
  80. //  struct dirent *ent;
  81.   struct find_t ffblk;
  82.  
  83.   FILE   *srcfile;
  84.   char   *ext;
  85.   char   *name;
  86.   char   *endname;
  87.  
  88.   char   Object[35];
  89.   char   line[80];
  90.   char   fullfile[60];
  91.   int    done;
  92.   int    flag=0;
  93.  
  94.   char   cmntchrs[55]="\t\n /*`~!@#$%^&*()[]{}\|;':<?>,.";
  95.  
  96.   CObjectInfo *temp;        // Pointer to an Object Info class
  97.  
  98. /*
  99.   if(-1==getcurdir(0,dirtemp)){
  100.     printf("Error reading the current directory.\n");
  101.   }
  102.   sprintf(dirname,"\\%s",dirtemp);
  103.  
  104. //  strcpy(dirname,ReadDir);        // Slid the parm in here.
  105.  
  106.   if ((dir = opendir(dirname)) == NULL)  {
  107.     perror("Unable to access directory!\n");
  108.     exit(1);
  109.   }
  110. */
  111.  
  112.   strcpy(dirname,ReadDir);        // Slid the parm in here.
  113.   strcat(dirname,"\\*.h");
  114.  
  115.   done = _dos_findfirst(dirname,_A_NORMAL,&ffblk);
  116.   while (readtype<4){
  117.     while ((done!=0)&&(flag==0)){
  118.       readtype++;
  119.       if (readtype==1){
  120.     strcpy(dirname,ReadDir);        // Slid the parm in here.
  121.     strcat(dirname,"\\*.hpp");
  122.     done = _dos_findfirst(dirname,_A_NORMAL,&ffblk);
  123.       }
  124.       if (readtype==2){
  125.     strcpy(dirname,ReadDir);        // Slid the parm in here.
  126.     strcat(dirname,"\\*.c");
  127.     done = _dos_findfirst(dirname,_A_NORMAL,&ffblk);
  128.       }
  129.       if (readtype==3){
  130.     strcpy(dirname,ReadDir);        // Slid the parm in here.
  131.     strcat(dirname,"\\*.cpp");
  132.     done = _dos_findfirst(dirname,_A_NORMAL,&ffblk);
  133.       }
  134.       if (readtype==4) flag=1;
  135.     }
  136.  
  137.     if (done==0){
  138.       strupr(ffblk.name);
  139.       strcpy(tempfile,ffblk.name);
  140.  
  141.       ext=tempfile;
  142.       if (ext!=NULL){
  143.     ext=strchr( ext,'.');
  144.       }
  145.     }
  146.     else {
  147.       ext=NULL;
  148.     }
  149.  
  150.     if( ext != NULL &&
  151.        (0==strcmp(ext,".C")   ||
  152.     0==strcmp(ext,".CPP") ||
  153.     0==strcmp(ext,".H")   ||
  154.     0==strcmp(ext,".HPP") )){
  155.  
  156.       strcpy(opnfile,ReadDir);
  157.       strcat(opnfile,"\\");
  158.       strcat(opnfile,ffblk.name);
  159.  
  160.  
  161.       if(NULL==(srcfile=fopen(opnfile,"rt"))){
  162.     printf("Unable to open file %s.",opnfile);
  163.       }
  164.       else{
  165.  
  166.     name=NULL;
  167.     while (name==NULL && !feof(srcfile)){
  168.       fgets(line,80,srcfile);
  169.       name=line;
  170.  
  171. //          what=strcspn(line,"\t\n /*");// Points to first non-comment character
  172.       while (NULL!=strchr(cmntchrs,*name) && name!=NULL){
  173.         name++;
  174.       }
  175.     }
  176.  
  177.     if (name!=NULL){
  178.       endname=name;
  179.       while (NULL==strchr(cmntchrs,*endname) && endname!=NULL){
  180.         endname++;
  181.       }
  182.  
  183.       *endname=NULL;          // Null terminate the name.
  184.  
  185.       strcpy(Object,name);    // Copy the name into Object.
  186.  
  187.                   // Check if there is already an object,
  188.                   //   of this name...
  189.  
  190.                   // Found Object returns 1 if the object is
  191.                   //   in the list and 0 if not.  The list
  192.                   //   cur pointer is left pointing to the
  193.                   //   correct object.
  194.       if(1==FoundObjectInList(ObjL, name)){
  195.                   // Add this file name to the object
  196.         temp=(CObjectInfo*)ObjL->Retrieve(LL_DATA);
  197.         strcpy(fullfile,ReadDir);
  198.         strcat(fullfile,"\\");
  199.         strcat(fullfile,ffblk.name);
  200.         temp->AddFile(fullfile);
  201.       }
  202.       else{
  203.                   // Create this object & add the file name.
  204.         ObjL->Add(new CObjectInfo,LL_ADD_AFTER);
  205.         ObjL->Next();
  206.         temp=(CObjectInfo*)ObjL->Retrieve(LL_DATA);
  207.  
  208.         strcpy(fullfile,ReadDir);
  209.         strcat(fullfile,"\\");
  210.         strcat(fullfile,ffblk.name);
  211.         temp->AddFile(fullfile);
  212.         temp->YourNameIs(Object);
  213.       }
  214.     }
  215.     fclose(srcfile);
  216. //        printf("%15s holds object %s...\n",ent->d_name,name);
  217.       }
  218.     }
  219.     if (readtype != 4){
  220.       done = _dos_findnext(&ffblk);
  221.     }
  222.   }
  223. }
  224.  
  225. int  CountList(LList *ObjL)
  226. {
  227.   CObjectInfo *temp;              // Pointer to an Object Info class
  228.   int TLOC=0;
  229.  
  230.   ObjectList.Restart();                    // Start at start of list.
  231.   do{
  232.     temp=(CObjectInfo*)ObjectList.Retrieve(LL_DATA);
  233.  
  234.     TLOC += temp->Count_OLOC();
  235.  
  236.     ObjectList.Next();
  237.                   // Count objects until out of objects
  238.   } while (ObjectList.AtEnd == FALSE);
  239.  
  240.   return(TLOC);                   // Return the total.
  241. }
  242.  
  243. void PrintList(LList *ObjL, int TLOC)
  244. {
  245.   CObjectInfo *temp;              // Pointer to an Object Info class
  246.   FILE *out;
  247.  
  248.   if(NULL==(out=fopen("data2.dat","wt"))){
  249.     printf("Error:  Can't write results.");
  250.     exit(1);
  251.   }
  252.  
  253.   ObjL->Restart();                    // Start at start of list.
  254.   do{
  255.     temp=(CObjectInfo*)ObjL->Retrieve(LL_DATA);
  256.  
  257.     temp->Print_OLOC(out);
  258.  
  259.     ObjL->Next();
  260.                                   // Count objects until out of objects
  261.   } while (ObjL->AtEnd == FALSE);
  262.  
  263.   fprintf(out,"\nTotal LOC:     %d\n",TLOC);
  264.   fclose(out);
  265. }
  266.