"Fossies" - the Fresh Open Source Software Archive

Member "seed7/src/wrdepend.c" (24 Nov 2019, 5876 Bytes) of package /linux/misc/seed7_05_20210223.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "wrdepend.c" see the Fossies "Dox" file reference documentation.

    1 /********************************************************************/
    2 /*                                                                  */
    3 /*  wrdepend.c    Write the C header file dependencies.             */
    4 /*  Copyright (C) 2014  Thomas Mertes                               */
    5 /*                                                                  */
    6 /*  This program is free software; you can redistribute it and/or   */
    7 /*  modify it under the terms of the GNU General Public License as  */
    8 /*  published by the Free Software Foundation; either version 2 of  */
    9 /*  the License, or (at your option) any later version.             */
   10 /*                                                                  */
   11 /*  This program is distributed in the hope that it will be useful, */
   12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of  */
   13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   */
   14 /*  GNU General Public License for more details.                    */
   15 /*                                                                  */
   16 /*  You should have received a copy of the GNU General Public       */
   17 /*  License along with this program; if not, write to the           */
   18 /*  Free Software Foundation, Inc., 51 Franklin Street,             */
   19 /*  Fifth Floor, Boston, MA  02110-1301, USA.                       */
   20 /*                                                                  */
   21 /*  Module: Wrdepend                                                */
   22 /*  File: seed7/src/wrdepend.c                                      */
   23 /*  Changes: 2014  Thomas Mertes                                    */
   24 /*  Content: Write the C header file dependencies.                  */
   25 /*                                                                  */
   26 /********************************************************************/
   27 
   28 #include "version.h"
   29 
   30 /**
   31  *  From version.h the following defines are used (for details see: read_me.txt):
   32  *
   33  *  C_COMPILER:
   34  *      Contains the command to call the stand-alone C compiler and linker.
   35  *  INCLUDE_OPTIONS:
   36  *      Options to specify include directories.
   37  *  DB2_INCLUDE_OPTION:
   38  *      Option to specify the include directory of DB2.
   39  *  SQL_SERVER_INCLUDE_OPTION:
   40  *      Option to specify the include directory of SQL Server.
   41  */
   42 
   43 #include "stdlib.h"
   44 #include "string.h"
   45 #include "stdio.h"
   46 
   47 #include "config.h"
   48 
   49 /**
   50  *  From config.h the following defines are used (for details see: read_me.txt):
   51  *
   52  *  MAP_ABSOLUTE_PATH_TO_DRIVE_LETTERS
   53  *      Map absolute paths to operating system paths with drive letter.
   54  */
   55 
   56 
   57 #define COMMAND_SIZE 16384
   58 
   59 static char c_compiler[COMMAND_SIZE];
   60 
   61 
   62 
   63 static void prepareCompileCommand (void)
   64 
   65   {
   66     int pos;
   67     int quote_command = 0;
   68     int len;
   69 
   70   /* prepareCompileCommand */
   71     strcpy(c_compiler, C_COMPILER);
   72 #if MAP_ABSOLUTE_PATH_TO_DRIVE_LETTERS
   73     if (c_compiler[0] == '/') {
   74       c_compiler[0] = c_compiler[1];
   75       c_compiler[1] = ':';
   76     } /* if */
   77 #endif
   78     for (pos = 0; c_compiler[pos] != '\0'; pos++) {
   79       if (c_compiler[pos] == '/') {
   80         c_compiler[pos] = PATH_DELIMITER;
   81       } else if (c_compiler[pos] == ' ') {
   82         quote_command = 1;
   83       } /* if */
   84     } /* for */
   85     if (quote_command) {
   86       len = strlen(c_compiler);
   87       memmove(&c_compiler[1], c_compiler, len);
   88       c_compiler[0] = '\"';
   89       c_compiler[len + 1] = '\"';
   90       c_compiler[len + 2] = '\0';
   91     } /* if */
   92   } /* prepareCompileCommand */
   93 
   94 
   95 
   96 const char *writeOption (const char *option, char *command)
   97 
   98   {
   99     const char *nlPtr;
  100     unsigned long length;
  101     unsigned long cmdLen;
  102     const char *nextOption;
  103 
  104   /* writeOption */
  105     nlPtr = strchr(option, '\n');
  106     if (nlPtr != NULL) {
  107       length = nlPtr - option;
  108       nextOption = nlPtr + 1;
  109     } else {
  110       length = strlen(option);
  111       nlPtr = &option[length];
  112       nextOption = NULL;
  113     } /* if */
  114     if (length != 0) {
  115       strcat(command, " ");
  116       cmdLen = strlen(command);
  117       memcpy(&command[cmdLen], option, length);
  118       command[cmdLen + length] = '\0';
  119     } /* if */
  120     return nextOption;
  121   } /* writeOption */
  122 
  123 
  124 
  125 void writeOptionList (const char *optionList, char *command)
  126 
  127   { /* writeOptionList */
  128     do {
  129       optionList = writeOption(optionList, command);
  130     } while (optionList != NULL);
  131   } /* writeOptionList */
  132 
  133 
  134 
  135 /**
  136  *  Program to write the C header file dependencies.
  137  */
  138 int main (int argc, char **argv)
  139 
  140   {
  141     int idx = 1;
  142     char *curr_arg;
  143     char *include_option;
  144     char command[COMMAND_SIZE];
  145 
  146   /* main */
  147     prepareCompileCommand();
  148     sprintf(command, "%s", c_compiler);
  149     curr_arg = argv[idx];
  150     if (memcmp(curr_arg, "OPTION=", 7 * sizeof(char)) == 0 &&
  151         (curr_arg)[7] != '\0') {
  152       /* fprintf(stderr, "arg[%d]: %s\n", idx, curr_arg); */
  153       include_option = &(curr_arg)[7];
  154       if (strcmp(include_option, "DB2_INCLUDE_OPTION") == 0 &&
  155           DB2_INCLUDE_OPTION[0] != '\0') {
  156         writeOptionList(DB2_INCLUDE_OPTION, command);
  157       } else if (strcmp(include_option, "SQL_SERVER_INCLUDE_OPTION") == 0 &&
  158           SQL_SERVER_INCLUDE_OPTION[0] != '\0') {
  159         writeOptionList(SQL_SERVER_INCLUDE_OPTION, command);
  160       } else if (strcmp(include_option, "INCLUDE_OPTIONS") == 0 &&
  161           INCLUDE_OPTIONS[0] != '\0') {
  162         writeOptionList(INCLUDE_OPTIONS, command);
  163       } /* if */
  164       idx++;
  165     } /* if */
  166     for (; idx < argc; idx++) {
  167       curr_arg = argv[idx];
  168       strcat(command, " ");
  169       if (strchr(curr_arg, ' ') != NULL && curr_arg[0] != '>') {
  170         strcat(command, "\"");
  171         strcat(command, curr_arg);
  172         strcat(command, "\"");
  173       } else {
  174         strcat(command, curr_arg);
  175       } /* if */
  176       /* fprintf(stderr, "arg[%d]: %s\n", idx, curr_arg); */
  177     } /* for */
  178     /* fprintf(stderr, "command: %s\n", command); */
  179     system(command);
  180     return 0;
  181   } /* main */