Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
depend.c File Reference
#include "as.h"

Go to the source code of this file.

Classes

struct  dependency

Defines

#define MAX_COLUMNS   72

Functions

static int quote_string_for_make (FILE *, char *)
static void wrap_output (FILE *, char *, int)
void start_dependencies (char *filename)
void register_dependency (char *filename)
void print_dependencies (void)

Variables

static char * dep_file = NULL
static struct dependencydep_chain = NULL
static int column = 0

Class Documentation

struct dependency

Definition at line 26 of file depend.c.

Collaboration diagram for dependency:
Class Members
char * file
struct dependency * next

Define Documentation

#define MAX_COLUMNS   72

Definition at line 42 of file depend.c.


Function Documentation

void print_dependencies ( void  )

Definition at line 182 of file depend.c.

{
  FILE *f;
  struct dependency *dep;

  if (dep_file == NULL)
    return;

  f = fopen (dep_file, FOPEN_WT);
  if (f == NULL)
    {
      as_warn (_("can't open `%s' for writing"), dep_file);
      return;
    }

  column = 0;
  wrap_output (f, out_file_name, ':');
  for (dep = dep_chain; dep != NULL; dep = dep->next)
    wrap_output (f, dep->file, ' ');

  putc ('\n', f);

  if (fclose (f))
    as_warn (_("can't close `%s'"), dep_file);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int quote_string_for_make ( FILE *  file,
char *  src 
) [static]

Definition at line 82 of file depend.c.

{
  char *p = src;
  int i = 0;

  for (;;)
    {
      char c = *p++;

      switch (c)
       {
       case '\0':
       case ' ':
       case '\t':
         {
           /* GNU make uses a weird quoting scheme for white space.
              A space or tab preceded by 2N+1 backslashes represents
              N backslashes followed by space; a space or tab
              preceded by 2N backslashes represents N backslashes at
              the end of a file name; and backslashes in other
              contexts should not be doubled.  */
           char *q;

           for (q = p - 1; src < q && q[-1] == '\\'; q--)
             {
              if (file)
                putc ('\\', file);
              i++;
             }
         }
         if (!c)
           return i;
         if (file)
           putc ('\\', file);
         i++;
         goto ordinary_char;

       case '$':
         if (file)
           putc (c, file);
         i++;
         /* Fall through.  This can mishandle things like "$(" but
            there's no easy fix.  */
       default:
       ordinary_char:
         /* This can mishandle characters in the string "\0\n%*?[\\~";
            exactly which chars are mishandled depends on the `make' version.
            We know of no portable solution for this;
            even GNU make 3.76.1 doesn't solve the problem entirely.
            (Also, '\0' is mishandled due to our calling conventions.)  */
         if (file)
           putc (c, file);
         i++;
         break;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void register_dependency ( char *  filename)

Definition at line 56 of file depend.c.

{
  struct dependency *dep;

  if (dep_file == NULL)
    return;

  for (dep = dep_chain; dep != NULL; dep = dep->next)
    {
      if (!strcmp (filename, dep->file))
       return;
    }

  dep = (struct dependency *) xmalloc (sizeof (struct dependency));
  dep->file = xstrdup (filename);
  dep->next = dep_chain;
  dep_chain = dep;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void start_dependencies ( char *  filename)

Definition at line 48 of file depend.c.

Here is the caller graph for this function:

static void wrap_output ( FILE *  f,
char *  string,
int  spacer 
) [static]

Definition at line 144 of file depend.c.

{
  int len = quote_string_for_make (NULL, string);

  if (len == 0)
    return;

  if (column
      && (MAX_COLUMNS
         - 1 /* spacer */
         - 2 /* ` \'   */
         < column + len))
    {
      fprintf (f, " \\\n ");
      column = 0;
      if (spacer == ' ')
       spacer = '\0';
    }

  if (spacer == ' ')
    {
      putc (spacer, f);
      ++column;
    }

  quote_string_for_make (f, string);
  column += len;

  if (spacer == ':')
    {
      putc (spacer, f);
      ++column;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int column = 0 [static]

Definition at line 36 of file depend.c.

Definition at line 33 of file depend.c.

char* dep_file = NULL [static]

Definition at line 24 of file depend.c.