Print this page
make: translate using gettext, rather than the unmaintainable catgets


  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <string.h>
  29 #include <sys/param.h>
  30 #include <sys/wait.h>
  31 #include <unistd.h>

  32 
  33 #include <vroot/report.h>
  34 #include <vroot/vroot.h>
  35 #include <mksdmsi18n/mksdmsi18n.h>
  36 #include <avo/intl.h>     /* for NOCATGETS */
  37 #include <mk/defs.h>      /* for tmpdir */
  38 
  39 static  FILE    *report_file;
  40 static  FILE    *command_output_fp;
  41 static  char    *target_being_reported_for;
  42 static  char    *search_dir;
  43 static  char    command_output_tmpfile[30];
  44 static  int     is_path = 0;
  45 static  char    sfile[MAXPATHLEN];
  46 extern "C" {
  47 static  void    (*warning_ptr) (char *, ...) = (void (*) (char *, ...)) NULL;
  48 }
  49 
  50 FILE *
  51 get_report_file(void)
  52 {
  53         return(report_file);
  54 }
  55 
  56 char *


  93 close_file(void)
  94 {
  95         char            line[MAXPATHLEN+2];
  96         char            buf[MAXPATHLEN+2];
  97         FILE            *nse_depinfo_fp;
  98         FILE            *merge_fp;
  99         char            nse_depinfo_file[MAXPATHLEN];
 100         char            merge_file[MAXPATHLEN];
 101         char            lock_file[MAXPATHLEN];
 102         int             err;
 103         int             len;
 104         int             changed = 0;
 105         int             file_locked;
 106 
 107         fprintf(command_output_fp, "\n");
 108         fclose(command_output_fp);
 109         if ((command_output_fp = fopen(command_output_tmpfile, "r")) == NULL) {
 110                 return;
 111         }
 112         sprintf(nse_depinfo_file, "%s/%s", search_dir, NSE_DEPINFO);
 113         sprintf(merge_file, NOCATGETS("%s/.tmp%s.%d"), search_dir, NSE_DEPINFO, getpid());
 114         sprintf(lock_file, "%s/%s", search_dir, NSE_DEPINFO_LOCK);
 115         err = file_lock(nse_depinfo_file, lock_file, &file_locked, 0);
 116         if (err) {
 117                 if (warning_ptr != (void (*) (char *, ...)) NULL) {
 118                         (*warning_ptr)(catgets(libmksdmsi18n_catd, 1, 147, "Couldn't write to %s"), nse_depinfo_file);
 119                       }
 120                 unlink(command_output_tmpfile);
 121                 return;
 122         }
 123         /* If .nse_depinfo file doesn't exist */
 124         if ((nse_depinfo_fp = fopen(nse_depinfo_file, "r+")) == NULL) {
 125                 if (is_path) {
 126                         if ((nse_depinfo_fp = 
 127                              fopen(nse_depinfo_file, "w")) == NULL) {
 128                                 fprintf(stderr, catgets(libmksdmsi18n_catd, 1, 148, "Cannot open `%s' for writing\n"),
 129                                     nse_depinfo_file);
 130                                 unlink(command_output_tmpfile);
 131 
 132                                 unlink(lock_file);
 133                                 return;
 134                         }
 135                         while (fgets(line, MAXPATHLEN+2, command_output_fp) 
 136                                != NULL) {
 137                                 fprintf(nse_depinfo_fp, "%s", line);
 138                         }
 139                         fclose(command_output_fp);
 140                 }
 141                 fclose(nse_depinfo_fp);
 142                 if (file_locked) {
 143                         unlink(lock_file);
 144                 }
 145                 unlink(command_output_tmpfile);
 146                 return;
 147         }
 148         if ((merge_fp = fopen(merge_file, "w")) == NULL) {
 149                 fprintf(stderr, catgets(libmksdmsi18n_catd, 1, 149, "Cannot open %s for writing\n"), merge_file);
 150                 if (file_locked) {
 151                         unlink(lock_file);
 152                 }
 153                 unlink(command_output_tmpfile);
 154                 return;
 155         }
 156         len = strlen(sfile);
 157         while (fgets(line, MAXPATHLEN+2, nse_depinfo_fp) != NULL) {
 158                 if (strncmp(line, sfile, len) == 0 && line[len] == ':') {
 159                         while (fgets(buf, MAXPATHLEN+2, command_output_fp) 
 160                                != NULL) {
 161                                 if (is_path) {
 162                                         fprintf(merge_fp, "%s", buf);
 163                                         if (strcmp(line, buf)) {
 164                                                 /* changed */
 165                                                 changed = 1;
 166                                         }
 167                                 }
 168                                 if (buf[strlen(buf)-1] == '\n') {
 169                                         break;


 191         /* Entry never found.  Add it if there is a search path */
 192         if (is_path) {
 193                 while (fgets(line, MAXPATHLEN+2, command_output_fp) != NULL) {
 194                         fprintf(nse_depinfo_fp, "%s", line);
 195                 }
 196         }
 197         clean_up(nse_depinfo_fp, merge_fp, nse_depinfo_file, merge_file, 1);
 198         if (file_locked) {
 199                 unlink(lock_file);
 200         }
 201 }
 202 
 203 } // extern "C"
 204 
 205 static void
 206 report_dep(char *iflag, char *filename)
 207 {
 208 
 209         if (command_output_fp == NULL) {
 210                 sprintf(command_output_tmpfile, 
 211                         NOCATGETS("%s/%s.%d.XXXXXX"), tmpdir, NSE_DEPINFO, getpid());
 212                 int fd = mkstemp(command_output_tmpfile);
 213                 if ((fd < 0) || (command_output_fp = fdopen(fd, "w")) == NULL) {
 214                         return;
 215                 }
 216                 if ((search_dir = getenv(NOCATGETS("NSE_DEP"))) == NULL) {
 217                         return;
 218                 }
 219                 atexit(close_file);
 220                 strcpy(sfile, filename);
 221                 if (iflag == NULL || *iflag == '\0') {
 222                         return;
 223                 }
 224                 fprintf(command_output_fp, "%s:", sfile);
 225         }
 226         fprintf(command_output_fp, " ");
 227         fprintf(command_output_fp, iflag);
 228         if (iflag != NULL) {
 229                 is_path = 1;
 230         }
 231 }
 232 
 233 void
 234 report_libdep(char *lib, char *flag)
 235 {
 236         char            *ptr;


 240         if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
 241                 return;
 242         }
 243         ptr = strchr(p, ' ');
 244         if(ptr) {
 245                 sprintf(filename, "%s-%s", ptr+1, flag);
 246                 is_path = 1;
 247                 report_dep(lib, filename);
 248         }
 249 }
 250 
 251 void
 252 report_search_path(char *iflag)
 253 {
 254         char            curdir[MAXPATHLEN];
 255         char            *sdir;
 256         char            *newiflag;
 257         char            filename[MAXPATHLEN];
 258         char            *p, *ptr;
 259 
 260         if ((sdir = getenv(NOCATGETS("NSE_DEP"))) == NULL) {
 261                 return;
 262         }
 263         if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
 264                 return;
 265         }
 266         ptr = strchr(p, ' ');
 267         if( ! ptr ) {
 268                 return;
 269         }
 270         sprintf(filename, NOCATGETS("%s-CPP"), ptr+1);
 271         getcwd(curdir, sizeof(curdir));
 272         if (strcmp(curdir, sdir) != 0 && strlen(iflag) > 2 && 
 273             iflag[2] != '/') {
 274                 /* Makefile must have had an "cd xx; cc ..." */
 275                 /* Modify the -I path to be relative to the cd */
 276                 newiflag = (char *)malloc(strlen(iflag) + strlen(curdir) + 2);
 277                 sprintf(newiflag, "-%c%s/%s", iflag[1], curdir, &iflag[2]);
 278                 report_dep(newiflag, filename);
 279         } else {
 280                 report_dep(iflag, filename);
 281         }
 282 }
 283 
 284 void
 285 report_dependency(const char *name)
 286 {
 287         register char   *filename;
 288         char            buffer[MAXPATHLEN+1];
 289         register char   *p;
 290         register char   *p2;




  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <string.h>
  29 #include <sys/param.h>
  30 #include <sys/wait.h>
  31 #include <unistd.h>
  32 #include <libintl.h>
  33 
  34 #include <vroot/report.h>
  35 #include <vroot/vroot.h>


  36 #include <mk/defs.h>      /* for tmpdir */
  37 
  38 static  FILE    *report_file;
  39 static  FILE    *command_output_fp;
  40 static  char    *target_being_reported_for;
  41 static  char    *search_dir;
  42 static  char    command_output_tmpfile[30];
  43 static  int     is_path = 0;
  44 static  char    sfile[MAXPATHLEN];
  45 extern "C" {
  46 static  void    (*warning_ptr) (char *, ...) = (void (*) (char *, ...)) NULL;
  47 }
  48 
  49 FILE *
  50 get_report_file(void)
  51 {
  52         return(report_file);
  53 }
  54 
  55 char *


  92 close_file(void)
  93 {
  94         char            line[MAXPATHLEN+2];
  95         char            buf[MAXPATHLEN+2];
  96         FILE            *nse_depinfo_fp;
  97         FILE            *merge_fp;
  98         char            nse_depinfo_file[MAXPATHLEN];
  99         char            merge_file[MAXPATHLEN];
 100         char            lock_file[MAXPATHLEN];
 101         int             err;
 102         int             len;
 103         int             changed = 0;
 104         int             file_locked;
 105 
 106         fprintf(command_output_fp, "\n");
 107         fclose(command_output_fp);
 108         if ((command_output_fp = fopen(command_output_tmpfile, "r")) == NULL) {
 109                 return;
 110         }
 111         sprintf(nse_depinfo_file, "%s/%s", search_dir, NSE_DEPINFO);
 112         sprintf(merge_file, "%s/.tmp%s.%d", search_dir, NSE_DEPINFO, getpid());
 113         sprintf(lock_file, "%s/%s", search_dir, NSE_DEPINFO_LOCK);
 114         err = file_lock(nse_depinfo_file, lock_file, &file_locked, 0);
 115         if (err) {
 116                 if (warning_ptr != (void (*) (char *, ...)) NULL) {
 117                         (*warning_ptr)(gettext("Couldn't write to %s"), nse_depinfo_file);
 118                       }
 119                 unlink(command_output_tmpfile);
 120                 return;
 121         }
 122         /* If .nse_depinfo file doesn't exist */
 123         if ((nse_depinfo_fp = fopen(nse_depinfo_file, "r+")) == NULL) {
 124                 if (is_path) {
 125                         if ((nse_depinfo_fp = 
 126                              fopen(nse_depinfo_file, "w")) == NULL) {
 127                                 fprintf(stderr, gettext("Cannot open `%s' for writing\n"),
 128                                     nse_depinfo_file);
 129                                 unlink(command_output_tmpfile);
 130 
 131                                 unlink(lock_file);
 132                                 return;
 133                         }
 134                         while (fgets(line, MAXPATHLEN+2, command_output_fp) 
 135                                != NULL) {
 136                                 fprintf(nse_depinfo_fp, "%s", line);
 137                         }
 138                         fclose(command_output_fp);
 139                 }
 140                 fclose(nse_depinfo_fp);
 141                 if (file_locked) {
 142                         unlink(lock_file);
 143                 }
 144                 unlink(command_output_tmpfile);
 145                 return;
 146         }
 147         if ((merge_fp = fopen(merge_file, "w")) == NULL) {
 148                 fprintf(stderr, gettext("Cannot open %s for writing\n"), merge_file);
 149                 if (file_locked) {
 150                         unlink(lock_file);
 151                 }
 152                 unlink(command_output_tmpfile);
 153                 return;
 154         }
 155         len = strlen(sfile);
 156         while (fgets(line, MAXPATHLEN+2, nse_depinfo_fp) != NULL) {
 157                 if (strncmp(line, sfile, len) == 0 && line[len] == ':') {
 158                         while (fgets(buf, MAXPATHLEN+2, command_output_fp) 
 159                                != NULL) {
 160                                 if (is_path) {
 161                                         fprintf(merge_fp, "%s", buf);
 162                                         if (strcmp(line, buf)) {
 163                                                 /* changed */
 164                                                 changed = 1;
 165                                         }
 166                                 }
 167                                 if (buf[strlen(buf)-1] == '\n') {
 168                                         break;


 190         /* Entry never found.  Add it if there is a search path */
 191         if (is_path) {
 192                 while (fgets(line, MAXPATHLEN+2, command_output_fp) != NULL) {
 193                         fprintf(nse_depinfo_fp, "%s", line);
 194                 }
 195         }
 196         clean_up(nse_depinfo_fp, merge_fp, nse_depinfo_file, merge_file, 1);
 197         if (file_locked) {
 198                 unlink(lock_file);
 199         }
 200 }
 201 
 202 } // extern "C"
 203 
 204 static void
 205 report_dep(char *iflag, char *filename)
 206 {
 207 
 208         if (command_output_fp == NULL) {
 209                 sprintf(command_output_tmpfile, 
 210                         "%s/%s.%d.XXXXXX", tmpdir, NSE_DEPINFO, getpid());
 211                 int fd = mkstemp(command_output_tmpfile);
 212                 if ((fd < 0) || (command_output_fp = fdopen(fd, "w")) == NULL) {
 213                         return;
 214                 }
 215                 if ((search_dir = getenv("NSE_DEP")) == NULL) {
 216                         return;
 217                 }
 218                 atexit(close_file);
 219                 strcpy(sfile, filename);
 220                 if (iflag == NULL || *iflag == '\0') {
 221                         return;
 222                 }
 223                 fprintf(command_output_fp, "%s:", sfile);
 224         }
 225         fprintf(command_output_fp, " ");
 226         fprintf(command_output_fp, iflag);
 227         if (iflag != NULL) {
 228                 is_path = 1;
 229         }
 230 }
 231 
 232 void
 233 report_libdep(char *lib, char *flag)
 234 {
 235         char            *ptr;


 239         if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
 240                 return;
 241         }
 242         ptr = strchr(p, ' ');
 243         if(ptr) {
 244                 sprintf(filename, "%s-%s", ptr+1, flag);
 245                 is_path = 1;
 246                 report_dep(lib, filename);
 247         }
 248 }
 249 
 250 void
 251 report_search_path(char *iflag)
 252 {
 253         char            curdir[MAXPATHLEN];
 254         char            *sdir;
 255         char            *newiflag;
 256         char            filename[MAXPATHLEN];
 257         char            *p, *ptr;
 258 
 259         if ((sdir = getenv("NSE_DEP")) == NULL) {
 260                 return;
 261         }
 262         if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
 263                 return;
 264         }
 265         ptr = strchr(p, ' ');
 266         if( ! ptr ) {
 267                 return;
 268         }
 269         sprintf(filename, "%s-CPP", ptr+1);
 270         getcwd(curdir, sizeof(curdir));
 271         if (strcmp(curdir, sdir) != 0 && strlen(iflag) > 2 && 
 272             iflag[2] != '/') {
 273                 /* Makefile must have had an "cd xx; cc ..." */
 274                 /* Modify the -I path to be relative to the cd */
 275                 newiflag = (char *)malloc(strlen(iflag) + strlen(curdir) + 2);
 276                 sprintf(newiflag, "-%c%s/%s", iflag[1], curdir, &iflag[2]);
 277                 report_dep(newiflag, filename);
 278         } else {
 279                 report_dep(iflag, filename);
 280         }
 281 }
 282 
 283 void
 284 report_dependency(const char *name)
 285 {
 286         register char   *filename;
 287         char            buffer[MAXPATHLEN+1];
 288         register char   *p;
 289         register char   *p2;