ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

deptool.c
Go to the documentation of this file.
00001 //
00002 // deptool.c
00003 // Copyright (C) 2002 by Brian Palmer <brianp@sginet.com>
00004 //
00005 
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 
00010 #define ERROR_SUCCESS               0
00011 #define ERROR_NOTENOUGHPARAMS       1
00012 #define ERROR_DEPENDFILENOTFOUND    2
00013 #define ERROR_OUTOFMEMORY           3
00014 #define ERROR_READERROR             4
00015 #define ERROR_WRITEERROR            5
00016 
00017 int main(int argc, char *argv[])
00018 {
00019     FILE*   DependFile;
00020     int     DependFileSize;
00021     char*   DependFileData;
00022     char*   NewDependFileData;
00023     int     CurIdx;
00024     int     CurIdx2;
00025     int     RuleDependencySplit = 0;
00026 
00027     // Make sure they passed enough command line parameters
00028     if (argc < 2)
00029     {
00030         printf("Usage: deptool srcfile.d\n");
00031         return ERROR_NOTENOUGHPARAMS;
00032     }
00033 
00034     // Try to open the dependency file
00035     DependFile = fopen(argv[1], "r+t");
00036     if (DependFile == NULL)
00037     {
00038         printf("deptool: No such dependency file: %s\n", argv[1]);
00039         return ERROR_DEPENDFILENOTFOUND;
00040     }
00041 
00042     // Get the file size
00043     fseek(DependFile, 0, SEEK_END);
00044     DependFileSize = ftell(DependFile);
00045     rewind(DependFile);
00046 
00047     // Allocate memory
00048     DependFileData = (char *)malloc(DependFileSize);
00049     NewDependFileData = (char *)malloc(DependFileSize * 3);
00050     if (!DependFileData || !NewDependFileData)
00051     {
00052         printf("deptool: Out of memory!\n");
00053         if (DependFileData != NULL)
00054             free(DependFileData);
00055         if (NewDependFileData != NULL)
00056             free(NewDependFileData);
00057         fclose(DependFile);
00058         return ERROR_OUTOFMEMORY;
00059     }
00060     memset(DependFileData, 0, DependFileSize);
00061     memset(NewDependFileData, 0, DependFileSize * 3);
00062 
00063     // Read in file data
00064     fread(DependFileData, 1, DependFileSize, DependFile);
00065     if (ferror(DependFile))
00066     {
00067         printf("deptool: Dependency file read error.\n");
00068         free(DependFileData);
00069         free(NewDependFileData);
00070         fclose(DependFile);
00071         return ERROR_READERROR;
00072     }
00073 
00074     // Loop through the dependency file data and
00075     // insert the rule for the dependency file itself
00076     for (CurIdx=0,CurIdx2=0; DependFileData[CurIdx]; CurIdx++,CurIdx2++)
00077     {
00078         // Find the first colon ':' in the file and insert
00079         // the rule right before it
00080         if (DependFileData[CurIdx] == ':')
00081         {
00082             NewDependFileData[CurIdx2] = ' ';
00083             CurIdx2++;
00084             strcat(&NewDependFileData[CurIdx2], argv[1]);
00085             CurIdx2 += strlen(argv[1]);
00086             NewDependFileData[CurIdx2] = ' ';
00087             CurIdx2++;
00088             strcat(NewDependFileData, &DependFileData[CurIdx]);
00089             CurIdx2 += 2;
00090             RuleDependencySplit = CurIdx + 2;
00091             break;
00092         }
00093         else
00094         {
00095             NewDependFileData[CurIdx2] = DependFileData[CurIdx];
00096         }
00097     }
00098 
00099     // Now loop through all the rule dependencies and
00100     // turn them into rules themselves
00101     strcat(NewDependFileData, "\n\n");
00102     CurIdx = RuleDependencySplit;
00103     CurIdx2 = strlen(NewDependFileData);
00104     for (; DependFileData[CurIdx]; CurIdx++,CurIdx2++)
00105     {
00106         // If it's a line continuation char '\' then skip over it
00107         if (DependFileData[CurIdx] == '\\')
00108         {
00109             CurIdx2--;
00110             continue;
00111         }
00112 
00113         // If it's a new line char '\n' then insert a colon ':' to make it a rule
00114         if (DependFileData[CurIdx] == '\n')
00115         {
00116             NewDependFileData[CurIdx2] = ':';
00117             CurIdx2++;
00118         }
00119 
00120         NewDependFileData[CurIdx2] = DependFileData[CurIdx];
00121     }
00122 
00123     // Write out file data
00124     rewind(DependFile);
00125     fwrite(NewDependFileData, 1, strlen(NewDependFileData), DependFile);
00126     if (ferror(DependFile))
00127     {
00128         printf("deptool: Dependency file write error.\n");
00129         fclose(DependFile);
00130         free(DependFileData);
00131         free(NewDependFileData);
00132         return ERROR_WRITEERROR;
00133     }
00134 
00135     fclose(DependFile);
00136     free(DependFileData);
00137     free(NewDependFileData);
00138     return ERROR_SUCCESS;
00139 }

Generated on Sat May 26 2012 04:18:07 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.