]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/captoinfo.c
ncurses 4.2
[ncurses.git] / ncurses / captoinfo.c
index a70c768772db841addc6a51a1f551c5487cd3af0..387fabd36888db434db4e0fd8c5a9a50d10ca731 100644 (file)
@@ -1,23 +1,35 @@
-
-/***************************************************************************
-*                            COPYRIGHT NOTICE                              *
-****************************************************************************
-*                ncurses is copyright (C) 1992-1995                        *
-*                          Zeyd M. Ben-Halim                               *
-*                          zmbenhal@netcom.com                             *
-*                          Eric S. Raymond                                 *
-*                          esr@snark.thyrsus.com                           *
-*                                                                          *
-*        Permission is hereby granted to reproduce and distribute ncurses  *
-*        by any means and for any fee, whether alone or as part of a       *
-*        larger distribution, in source or in binary form, PROVIDED        *
-*        this notice is included with any such distribution, and is not    *
-*        removed from any of its header files. Mention of ncurses in any   *
-*        applications linked with it is highly appreciated.                *
-*                                                                          *
-*        ncurses comes AS IS with no warranty, implied or expressed.       *
-*                                                                          *
-***************************************************************************/
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "Software"), to deal in the Software without restriction, including      *
+ * without limitation the rights to use, copy, modify, merge, publish,      *
+ * distribute, distribute with modifications, sublicense, and/or sell       *
+ * copies of the Software, and to permit persons to whom the Software is    *
+ * furnished to do so, subject to the following conditions:                 *
+ *                                                                          *
+ * The above copyright notice and this permission notice shall be included  *
+ * in all copies or substantial portions of the Software.                   *
+ *                                                                          *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
+ *                                                                          *
+ * Except as contained in this notice, the name(s) of the above copyright   *
+ * holders shall not be used in advertising or otherwise to promote the     *
+ * sale, use or other dealings in this Software without prior written       *
+ * authorization.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
 
 
 
@@ -82,7 +94,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-MODULE_ID("$Id: captoinfo.c,v 1.15 1996/12/21 14:24:06 tom Exp $")
+MODULE_ID("$Id: captoinfo.c,v 1.17 1998/02/11 12:13:54 tom Exp $")
 
 #define MAX_PUSHED     16      /* max # args we can push onto the stack */
 #define MAX_ENTRY      2048    /* maximum chars in a translated capability */
@@ -152,7 +164,7 @@ static void pop(void)
     param++;
 }
 
-static int cvtchar(register char *sp)
+static int cvtchar(register const char *sp)
 /* convert a character to a terminfo push */
 {
     unsigned char c = 0;
@@ -252,12 +264,12 @@ static void getparm(int parm, int n)
 
 char *_nc_captoinfo(
 /* convert a termcap string to terminfo format */
-register char *const cap,      /* relevant terminfo capability index */
-register char *s,              /* string value of the capability */
+register const char *cap,      /* relevant terminfo capability index */
+register const char *s,                /* string value of the capability */
 int const parametrized)                /* do % translations if 1, pad translations if >=0 */
 {
     static char line[MAX_ENTRY];
-    char *capstart;
+    const char *capstart;
 
     stackptr = 0;
     onstack = 0;
@@ -269,7 +281,7 @@ int const parametrized)             /* do % translations if 1, pad translations if >=0 */
     dp = line;
 
     /* skip the initial padding (if we haven't been told not to) */
-    capstart = (char *)NULL;
+    capstart = 0;
     if (s == 0)
        s = "";
     if (parametrized >= 0 && isdigit(*s))
@@ -541,12 +553,14 @@ int const parametrized)           /* do % translations if 1, pad translations if >=0 */
 
 char *_nc_infotocap(
 /* convert a terminfo string to termcap format */
-register char *const cap GCC_UNUSED, /* relevant termcap capability index */
-register char *str,            /* string value of the capability */
+register const char *cap GCC_UNUSED, /* relevant termcap capability index */
+register const char *str,      /* string value of the capability */
 int const parametrized)                /* do % translations if 1, pad translations if >=0 */
 {
     int        seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
-    char *padding, ch1 = 0, ch2 = 0;
+    const char *padding;
+    const char *trimmed = 0;
+    char ch1 = 0, ch2 = 0;
     char *bufptr = init_string();
     char temp[256];
 
@@ -558,14 +572,14 @@ int const parametrized)           /* do % translations if 1, pad translations if >=0 */
        while (isdigit(*padding) || *padding == '.' || *padding == '*')
            padding--;
        if (*padding == '<' && *--padding == '$')
-           *padding = '\0';
+           trimmed = padding;
        padding += 2;
 
        while (isdigit(*padding) || *padding == '.' || *padding == '*')
            bufptr = save_char(bufptr, *padding++);
     }
 
-    for (; *str; str++)
+    for (; *str && str != trimmed; str++)
     {
        int     c1, c2;
        char    *cp;
@@ -723,7 +737,7 @@ int const parametrized)             /* do % translations if 1, pad translations if >=0 */
                    }
                }
                else if (*str >= '3')
-                   return((char *)NULL);
+                   return(0);
                break;
 
            case 'i':
@@ -732,7 +746,7 @@ int const parametrized)             /* do % translations if 1, pad translations if >=0 */
                break;
 
            default:
-               return((char *)NULL);
+               return(0);
 
            } /* endswitch (*str) */
        } /* endelse (*str == '%') */
@@ -767,7 +781,7 @@ int main(int argc, char *argv[])
        char    buf[BUFSIZ];
 
        ++curr_line;
-       if (fgets(buf, sizeof(buf), stdin) == (char *)NULL)
+       if (fgets(buf, sizeof(buf), stdin) == 0)
            break;
        buf[strlen(buf) - 1] = '\0';
        _nc_set_source(buf);