Print this page
2926 lex ignores -Y

@@ -17,21 +17,21 @@
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
  */
 /*
+ * Copyright (c) 2014 Gary Mills
+ *
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /* Copyright (c) 1988 AT&T */
 /* All Rights Reserved */
 
 /* Copyright 1976, Bell Telephone Laboratories, Inc. */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 #include <string.h>
 #include "once.h"
 #include "sgs.h"
 #include <locale.h>
 #include <limits.h>

@@ -49,11 +49,12 @@
 int
 main(int argc, char **argv)
 {
         int i;
         int c;
-        char *path = NULL;
+        char *apath = NULL;
+        char *ypath;
         Boolean eoption = 0, woption = 0;
 
         sargv = argv;
         sargc = argc;
         (void) setlocale(LC_ALL, "");

@@ -81,13 +82,17 @@
                                 if (*v_stmp != 'y' && *v_stmp != 'n')
                                         error(
                                         "lex: -Q should be followed by [y/n]");
                                 break;
                         case 'Y':
-                                path = (char *)malloc(strlen(optarg) +
+                                apath = (char *)malloc(strlen(optarg) +
                                     sizeof ("/nceucform") + 1);
-                                path = strcpy(path, optarg);
+                                if (apath == NULL)
+                                        error("No available memory "
+                                            "for directory name.");
+                                else
+                                        apath = strcpy(apath, optarg);
                                 break;
                         case 'c':
                                 ratfor = FALSE;
                                 break;
                         case 't':

@@ -111,11 +116,12 @@
                                 handleeuc = 1;
                                 widecio = 0;
                                 break;
                         default:
                                 (void) fprintf(stderr,
-                                "Usage: lex [-ewctvnVY] [-Q(y/n)] [file]\n");
+                                "Usage: lex [-ewctvnV] [-Y directory] "
+                                "[-Q(y/n)] [file]\n");
                                 exit(1);
                 }
         }
         if (woption && eoption) {
                 error(

@@ -219,22 +225,25 @@
 #endif
 
         if (handleeuc) {
                 if (ratfor)
                         error("Ratfor is not supported by -w or -e option.");
-                path = EUCNAME;
+                ypath = EUCNAME;
         }
         else
-                path = ratfor ? RATNAME : CNAME;
+                ypath = ratfor ? RATNAME : CNAME;
 
-        fother = fopen(path, "r");
+        if (apath != NULL)
+                ypath = strcat(apath, strrchr(ypath, '/'));
+        fother = fopen(ypath, "r");
         if (fother == NULL)
-                error("Lex driver missing, file %s", path);
+                error("Lex driver missing, file %s", ypath);
         while ((i = getc(fother)) != EOF)
                 (void) putc((char)i, fout);
         (void) fclose(fother);
         (void) fclose(fout);
+        free(apath);
         if (report == 1)
                 statistics();
         (void) fclose(stdout);
         (void) fclose(stderr);
         return (0);     /* success return code */