]>
git.refcnt.org Git - colorize.git/blob - colorize.c
2 * colorize - Read text from standard input stream or file and print
3 * it colorized through use of ANSI escape sequences
5 * Copyright (c) 2011-2014 Steven Schubiger
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #define _POSIX_C_SOURCE 200809L
32 #include <sys/types.h>
42 #define to_str(arg) str(arg)
44 #define streq(s1, s2) (strcmp (s1, s2) == 0)
47 # define xmalloc(size) malloc_wrap_debug(size, __FILE__, __LINE__)
48 # define xcalloc(nmemb, size) calloc_wrap_debug(nmemb, size, __FILE__, __LINE__)
49 # define xrealloc(ptr, size) realloc_wrap_debug(ptr, size, __FILE__, __LINE__)
51 # define xmalloc(size) malloc_wrap(size)
52 # define xcalloc(nmemb, size) calloc_wrap(nmemb, size)
53 # define xrealloc(ptr, size) realloc_wrap(ptr, size)
56 #define free_null(ptr) free_wrap((void **)&ptr)
57 #define xstrdup(str) strdup_wrap(str)
63 # define BUF_SIZE 4096
69 #define SKIP_LINE_ENDINGS(flags) (((flags) & CR) && ((flags) & LF) ? 2 : 1)
71 #define VALID_FILE_TYPE(mode) (S_ISREG (mode) || S_ISLNK (mode) || S_ISFIFO (mode))
73 #define STACK_VAR(ptr) do { \
74 stack_var (&vars_list, &stacked_vars, stacked_vars, ptr); \
77 #define RELEASE_VAR(ptr) do { \
78 release_var (vars_list, stacked_vars, (void **)&ptr); \
81 #define MEM_ALLOC_FAIL_DEBUG(file, line) do { \
82 fprintf (stderr, "Memory allocation failure in source file %s, line %u\n", file, line); \
85 #define MEM_ALLOC_FAIL() do { \
86 fprintf (stderr, "%s: memory allocation failure\n", program_name); \
90 #define ABORT_TRACE() \
91 fprintf (stderr, "Aborting in source file %s, line %u\n", __FILE__, __LINE__); \
94 #define CHECK_COLORS_RANDOM(color1, color2) \
95 streq (color_names[color1]->name, "random") \
96 && (streq (color_names[color2]->name, "none") \
97 || streq (color_names[color2]->name, "default")) \
99 #define COLOR_SEP_CHAR '/'
101 #define VERSION "0.53"
103 typedef enum { false, true } bool;
110 static struct color_name
*color_names
[3] = { NULL
, NULL
, NULL
};
117 static const struct color fg_colors
[] = {
124 { "magenta", "35m" },
127 { "default", "39m" },
129 static const struct color bg_colors
[] = {
136 { "magenta", "45m" },
139 { "default", "49m" },
151 static const char *formats
[] = {
153 "%s `%s' %s", /* quote */
154 "%s color '%s' %s", /* color */
155 "%s color '%s' %s '%s'", /* random */
156 "less than %u bytes %s", /* error */
158 "%s: %s: %s", /* type */
161 enum { FOREGROUND
, BACKGROUND
};
163 static const struct {
164 struct color
const *entries
;
168 { fg_colors
, sizeof (fg_colors
) / sizeof (struct color
), "foreground" },
169 { bg_colors
, sizeof (bg_colors
) / sizeof (struct color
), "background" },
172 static FILE *stream
= NULL
;
174 static unsigned int stacked_vars
= 0;
175 static void **vars_list
= NULL
;
177 static bool clean
= false;
178 static bool clean_all
= false;
180 static char *exclude
= NULL
;
182 static const char *program_name
;
184 static void print_hint (void);
185 static void print_help (void);
186 static void print_version (void);
187 static void cleanup (void);
188 static void free_color_names (struct color_name
**);
189 static void process_args (unsigned int, char **, bool *, const struct color
**, const char **, FILE **);
190 static void process_file_arg (const char *, const char **, FILE **);
191 static void read_print_stream (bool, const struct color
**, const char *, FILE *);
192 static void find_color_entries (struct color_name
**, const struct color
**);
193 static void find_color_entry (const struct color_name
*, unsigned int, const struct color
**);
194 static void print_line (bool, const struct color
**, const char * const, unsigned int);
195 static void print_clean (const char *);
196 static void print_free_offsets (const char *, char ***, unsigned int);
197 static void *malloc_wrap (size_t);
198 static void *calloc_wrap (size_t, size_t);
199 static void *realloc_wrap (void *, size_t);
200 static void *malloc_wrap_debug (size_t, const char *, unsigned int);
201 static void *calloc_wrap_debug (size_t, size_t, const char *, unsigned int);
202 static void *realloc_wrap_debug (void *, size_t, const char *, unsigned int);
203 static void free_wrap (void **);
204 static char *strdup_wrap (const char *);
205 static char *str_concat (const char *, const char *);
206 static char *get_file_type (mode_t
);
207 static bool has_color_name (const char *, const char *);
208 static void vfprintf_diag (const char *, ...);
209 static void vfprintf_fail (const char *, ...);
210 static void stack_var (void ***, unsigned int *, unsigned int, void *);
211 static void release_var (void **, unsigned int, void **);
213 #define SET_OPT_TYPE(type) \
221 static int opt_type
= 0;
224 main (int argc
, char **argv
)
226 unsigned int arg_cnt
= 0;
237 struct option long_opts
[] = {
238 { "clean", no_argument
, &opt_type
, OPT_CLEAN
},
239 { "clean-all", no_argument
, &opt_type
, OPT_CLEAN_ALL
},
240 { "exclude-random", required_argument
, &opt_type
, OPT_EXCLUDE_RANDOM
},
241 { "help", no_argument
, &opt_type
, OPT_HELP
},
242 { "version", no_argument
, &opt_type
, OPT_VERSION
},
243 { NULL
, 0, NULL
, 0 },
248 const struct color
*colors
[2] = {
249 NULL
, /* foreground */
250 NULL
, /* background */
253 const char *file
= NULL
;
255 program_name
= argv
[0];
258 setvbuf (stdout
, NULL
, _IOLBF
, 0);
260 while ((opt
= getopt_long (argc
, argv
, "hv", long_opts
, NULL
)) != -1)
265 case 0: /* long opts */
274 case OPT_EXCLUDE_RANDOM
: {
277 exclude
= xstrdup (optarg
);
279 for (i
= 1; i
< tables
[FOREGROUND
].count
- 1; i
++) /* skip color none and default */
281 const struct color
*entry
= &tables
[FOREGROUND
].entries
[i
];
282 if (streq (exclude
, entry
->name
))
289 vfprintf_fail (formats
[FMT_GENERIC
], "--exclude-random switch must be provided a plain color");
298 default: /* never reached */
303 SET_OPT_TYPE (OPT_HELP
);
305 SET_OPT_TYPE (OPT_VERSION
);
309 default: /* never reached */
314 arg_cnt
= argc
- optind
;
316 if (clean
|| clean_all
)
318 if (clean
&& clean_all
)
319 vfprintf_fail (formats
[FMT_GENERIC
], "--clean and --clean-all switch are mutually exclusive");
322 const char *format
= "%s %s";
323 const char *message
= "switch cannot be used with more than one file";
325 vfprintf_fail (format
, "--clean", message
);
327 vfprintf_fail (format
, "--clean-all", message
);
332 if (arg_cnt
== 0 || arg_cnt
> 2)
334 vfprintf_diag ("%u arguments provided, expected 1-2 arguments or clean option", arg_cnt
);
340 if (clean
|| clean_all
)
341 process_file_arg (argv
[optind
], &file
, &stream
);
343 process_args (arg_cnt
, &argv
[optind
], &bold
, colors
, &file
, &stream
);
344 read_print_stream (bold
, colors
, file
, stream
);
346 RELEASE_VAR (exclude
);
354 fprintf (stderr
, "Type `%s --help' for help screen.\n", program_name
);
362 printf ("Usage: %s (foreground) OR (foreground)%c(background) OR --clean[-all] [-|file]\n\n", program_name
, COLOR_SEP_CHAR
);
363 printf ("\tColors (foreground) (background)\n");
364 for (i
= 0; i
< tables
[FOREGROUND
].count
; i
++)
366 const struct color
*entry
= &tables
[FOREGROUND
].entries
[i
];
367 const char *name
= entry
->name
;
368 const char *code
= entry
->code
;
370 printf ("\t\t{\033[%s#\033[0m} [%c%c]%s%*s%s\n",
371 code
, toupper (*name
), *name
, name
+ 1, 10 - (int)strlen (name
), " ", name
);
373 printf ("\t\t{-} %s%*s%s\n", name
, 13 - (int)strlen (name
), " ", name
);
375 printf ("\t\t{*} [Rr]%s%*s%s [--exclude-random=<foreground color>]\n", "andom", 10 - (int)strlen ("random"), " ", "random");
377 printf ("\n\tFirst character of color name in upper case denotes increased intensity,\n");
378 printf ("\twhereas for lower case colors will be of normal intensity.\n");
380 printf ("\n\tOptions\n");
381 printf ("\t\t --clean\n");
382 printf ("\t\t --clean-all\n");
383 printf ("\t\t --exclude-random\n");
384 printf ("\t\t-h, --help\n");
385 printf ("\t\t-v, --version\n\n");
394 c_flags
= to_str (CFLAGS
);
403 printf ("%s v%s (compiled at %s, %s)\n", "colorize", VERSION
, __DATE__
, __TIME__
);
404 printf ("Compiler flags: %s\n", c_flags
);
405 printf ("Buffer size: %u bytes\n", BUF_SIZE
);
406 printf ("Debugging: %s\n", debug
? "yes" : "no");
412 free_color_names (color_names
);
414 if (stream
&& fileno (stream
) != STDIN_FILENO
)
420 for (i
= 0; i
< stacked_vars
; i
++)
422 free_null (vars_list
[i
]);
424 free_null (vars_list
);
429 free_color_names (struct color_name
**color_names
)
432 for (i
= 0; color_names
[i
]; i
++)
434 free_null (color_names
[i
]->name
);
435 free_null (color_names
[i
]->orig
);
436 free_null (color_names
[i
]);
441 process_args (unsigned int arg_cnt
, char **arg_strings
, bool *bold
, const struct color
**colors
, const char **file
, FILE **stream
)
445 char *color
, *p
, *str
;
448 const char *color_string
= arg_cnt
>= 1 ? arg_strings
[0] : NULL
;
449 const char *file_string
= arg_cnt
== 2 ? arg_strings
[1] : NULL
;
451 assert (color_string
);
453 if (streq (color_string
, "-"))
456 vfprintf_fail (formats
[FMT_GENERIC
], "hyphen cannot be used as color string");
458 vfprintf_fail (formats
[FMT_GENERIC
], "hyphen must be preceeded by color string");
461 ret
= lstat (color_string
, &sb
);
463 /* Ensure that we don't fail if there's a file with one or more
464 color names in its path. */
469 const char *color
= color_string
;
470 const mode_t mode
= sb
.st_mode
;
472 for (c
= 1; c
<= 2 && *color
; c
++)
474 bool matched
= false;
476 for (i
= 0; i
< tables
[FOREGROUND
].count
; i
++)
478 const struct color
*entry
= &tables
[FOREGROUND
].entries
[i
];
479 if (has_color_name (color
, entry
->name
))
481 color
+= strlen (entry
->name
);
486 if (!matched
&& has_color_name (color
, "random"))
488 color
+= strlen ("random");
491 if (matched
&& *color
== COLOR_SEP_CHAR
&& *(color
+ 1))
497 have_file
= (*color
!= '\0');
502 vfprintf_fail (formats
[FMT_QUOTE
], get_file_type (mode
), color_string
, "cannot be used as color string");
505 if (VALID_FILE_TYPE (mode
))
506 vfprintf_fail (formats
[FMT_QUOTE
], get_file_type (mode
), color_string
, "must be preceeded by color string");
508 vfprintf_fail (formats
[FMT_QUOTE
], get_file_type (mode
), color_string
, "is not a valid file type");
513 if ((p
= strchr (color_string
, COLOR_SEP_CHAR
)))
515 if (p
== color_string
)
516 vfprintf_fail (formats
[FMT_GENERIC
], "foreground color missing");
517 else if (p
== color_string
+ strlen (color_string
) - 1)
518 vfprintf_fail (formats
[FMT_GENERIC
], "background color missing");
519 else if (strchr (++p
, COLOR_SEP_CHAR
))
520 vfprintf_fail (formats
[FMT_GENERIC
], "one color pair allowed only");
523 str
= xstrdup (color_string
);
526 for (index
= 0, color
= str
; *color
; index
++, color
= p
)
531 if ((sep
= strchr (color
, COLOR_SEP_CHAR
)))
537 p
= color
+ strlen (color
);
540 for (ch
= color
; *ch
; ch
++)
542 vfprintf_fail (formats
[FMT_COLOR
], tables
[index
].desc
, color
, "cannot be made of non-alphabetic characters");
544 for (ch
= color
+ 1; *ch
; ch
++)
546 vfprintf_fail (formats
[FMT_COLOR
], tables
[index
].desc
, color
, "cannot be in mixed lower/upper case");
548 if (streq (color
, "None"))
549 vfprintf_fail (formats
[FMT_COLOR
], tables
[index
].desc
, color
, "cannot be bold");
551 if (isupper (*color
))
559 vfprintf_fail (formats
[FMT_COLOR
], tables
[BACKGROUND
].desc
, color
, "cannot be bold");
561 default: /* never reached */
566 color_names
[index
] = xcalloc (1, sizeof (struct color_name
));
568 color_names
[index
]->orig
= xstrdup (color
);
570 for (ch
= color
; *ch
; ch
++)
573 color_names
[index
]->name
= xstrdup (color
);
578 assert (color_names
[FOREGROUND
]);
580 if (color_names
[BACKGROUND
])
583 unsigned int color_sets
[2][2] = { { FOREGROUND
, BACKGROUND
}, { BACKGROUND
, FOREGROUND
} };
584 for (i
= 0; i
< 2; i
++)
586 unsigned int color1
= color_sets
[i
][0];
587 unsigned int color2
= color_sets
[i
][1];
588 if (CHECK_COLORS_RANDOM (color1
, color2
))
589 vfprintf_fail (formats
[FMT_RANDOM
], tables
[color1
].desc
, color_names
[color1
]->orig
, "cannot be combined with", color_names
[color2
]->orig
);
593 find_color_entries (color_names
, colors
);
594 free_color_names (color_names
);
596 if (!colors
[FOREGROUND
]->code
&& colors
[BACKGROUND
] && colors
[BACKGROUND
]->code
)
598 struct color_name color_name
;
599 color_name
.name
= color_name
.orig
= "default";
601 find_color_entry (&color_name
, FOREGROUND
, colors
);
604 process_file_arg (file_string
, file
, stream
);
608 process_file_arg (const char *file_string
, const char **file
, FILE **stream
)
612 if (streq (file_string
, "-"))
617 const char *file
= file_string
;
622 ret
= lstat (file
, &sb
);
625 vfprintf_fail (formats
[FMT_FILE
], file
, strerror (errno
));
627 if (!VALID_FILE_TYPE (sb
.st_mode
))
628 vfprintf_fail (formats
[FMT_TYPE
], file
, "unrecognized type", get_file_type (sb
.st_mode
));
632 s
= fopen (file
, "r");
634 vfprintf_fail (formats
[FMT_FILE
], file
, strerror (errno
));
649 #define MERGE_PRINT_LINE(part_line, line, flags, check_eof) do { \
650 char *current_line, *merged_line = NULL; \
653 merged_line = str_concat (part_line, line); \
654 free_null (part_line); \
656 current_line = merged_line ? merged_line : (char *)line; \
657 if (!check_eof || *current_line != '\0') \
658 print_line (bold, colors, current_line, flags); \
659 free (merged_line); \
663 read_print_stream (bool bold
, const struct color
**colors
, const char *file
, FILE *stream
)
665 char buf
[BUF_SIZE
+ 1], *part_line
= NULL
;
666 unsigned int flags
= 0;
668 while (!feof (stream
))
673 memset (buf
, '\0', BUF_SIZE
+ 1);
674 bytes_read
= fread (buf
, 1, BUF_SIZE
, stream
);
675 if (bytes_read
!= BUF_SIZE
&& ferror (stream
))
676 vfprintf_fail (formats
[FMT_ERROR
], BUF_SIZE
, "read");
678 while ((eol
= strpbrk (line
, "\n\r")))
685 if (*(eol
+ 1) == '\n')
688 else if (*eol
== '\n')
691 vfprintf_fail (formats
[FMT_FILE
], file
, "unrecognized line ending");
692 p
= eol
+ SKIP_LINE_ENDINGS (flags
);
694 MERGE_PRINT_LINE (part_line
, line
, flags
, false);
698 MERGE_PRINT_LINE (part_line
, line
, 0, true);
700 else if (*line
!= '\0')
702 if (!clean
&& !clean_all
) /* efficiency */
703 print_line (bold
, colors
, line
, 0);
705 part_line
= xstrdup (line
);
708 char *merged_line
= str_concat (part_line
, line
);
710 part_line
= merged_line
;
717 find_color_entries (struct color_name
**color_names
, const struct color
**colors
)
723 gettimeofday (&tv
, NULL
);
724 srand (tv
.tv_usec
* tv
.tv_sec
);
726 for (index
= 0; color_names
[index
]; index
++)
728 const char *color_name
= color_names
[index
]->name
;
730 const unsigned int count
= tables
[index
].count
;
731 const struct color
*const color_entries
= tables
[index
].entries
;
733 if (streq (color_name
, "random"))
739 i
= rand() % (count
- 2) + 1; /* omit color none and default */
743 /* --exclude-random */
744 if (exclude
&& streq (exclude
, color_entries
[i
].name
))
746 else if (color_names
[BACKGROUND
] && streq (color_names
[BACKGROUND
]->name
, color_entries
[i
].name
))
750 if (streq (colors
[FOREGROUND
]->name
, color_entries
[i
].name
))
753 default: /* never reached */
756 } while (excludable
);
757 colors
[index
] = (struct color
*)&color_entries
[i
];
760 find_color_entry (color_names
[index
], index
, colors
);
765 find_color_entry (const struct color_name
*color_name
, unsigned int index
, const struct color
**colors
)
770 const unsigned int count
= tables
[index
].count
;
771 const struct color
*const color_entries
= tables
[index
].entries
;
773 for (i
= 0; i
< count
; i
++)
774 if (streq (color_name
->name
, color_entries
[i
].name
))
776 colors
[index
] = (struct color
*)&color_entries
[i
];
781 vfprintf_fail (formats
[FMT_COLOR
], tables
[index
].desc
, color_name
->orig
, "not recognized");
785 print_line (bool bold
, const struct color
**colors
, const char *const line
, unsigned int flags
)
788 if (clean
|| clean_all
)
792 /* Foreground color code is guaranteed to be set when background color code is present. */
793 if (colors
[BACKGROUND
] && colors
[BACKGROUND
]->code
)
794 printf ("\033[%s", colors
[BACKGROUND
]->code
);
795 if (colors
[FOREGROUND
]->code
)
796 printf ("\033[%s%s%s\033[0m", bold
? "1;" : "", colors
[FOREGROUND
]->code
, line
);
798 printf (formats
[FMT_GENERIC
], line
);
807 print_clean (const char *line
)
810 char ***offsets
= NULL
;
811 unsigned int count
= 0, i
= 0;
816 if (*p
== 27 && *(p
+ 1) == '[')
818 const char *begin
= p
;
822 while (isdigit (*p
) || *p
== ';')
828 unsigned int iter
= 0;
831 check_values
= false;
840 else /* check range */
845 const unsigned int digits
= p
- digit
;
846 for (i
= 0; i
< digits
; i
++)
850 if (value
== 0) /* reset */
856 else if (value
== 1) /* bold */
858 bool discard
= false;
868 else if ((value
>= 30 && value
<= 37) || value
== 39) /* foreground colors */
870 else if ((value
>= 40 && value
<= 47) || value
== 49) /* background colors */
879 } while (iter
== 1 && check_values
);
883 const char *end
= p
++;
885 offsets
= xmalloc (++count
* sizeof (char **));
887 offsets
= xrealloc (offsets
, ++count
* sizeof (char **));
888 offsets
[i
] = xmalloc (2 * sizeof (char *));
889 offsets
[i
][0] = (char *)begin
; /* ESC */
890 offsets
[i
][1] = (char *)end
; /* m */
901 print_free_offsets (line
, offsets
, count
);
903 printf (formats
[FMT_GENERIC
], line
);
906 #define SET_CHAR(offset, new, old) \
910 #define RESTORE_CHAR(offset, old) \
914 print_free_offsets (const char *line
, char ***offsets
, unsigned int count
)
919 SET_CHAR (offsets
[0][0], '\0', &ch
);
920 printf (formats
[FMT_GENERIC
], line
);
921 RESTORE_CHAR (offsets
[0][0], ch
);
923 for (i
= 0; i
< count
; i
++)
926 bool next_offset
= false;
929 SET_CHAR (offsets
[i
+ 1][0], '\0', &ch
);
932 printf (formats
[FMT_GENERIC
], offsets
[i
][1] + 1);
934 RESTORE_CHAR (offsets
[i
+ 1][0], ch
);
936 for (i
= 0; i
< count
; i
++)
937 free_null (offsets
[i
]);
942 malloc_wrap (size_t size
)
944 void *p
= malloc (size
);
951 calloc_wrap (size_t nmemb
, size_t size
)
953 void *p
= calloc (nmemb
, size
);
960 realloc_wrap (void *ptr
, size_t size
)
962 void *p
= realloc (ptr
, size
);
969 malloc_wrap_debug (size_t size
, const char *file
, unsigned int line
)
971 void *p
= malloc (size
);
973 MEM_ALLOC_FAIL_DEBUG (file
, line
);
978 calloc_wrap_debug (size_t nmemb
, size_t size
, const char *file
, unsigned int line
)
980 void *p
= calloc (nmemb
, size
);
982 MEM_ALLOC_FAIL_DEBUG (file
, line
);
987 realloc_wrap_debug (void *ptr
, size_t size
, const char *file
, unsigned int line
)
989 void *p
= realloc (ptr
, size
);
991 MEM_ALLOC_FAIL_DEBUG (file
, line
);
996 free_wrap (void **ptr
)
1003 strdup_wrap (const char *str
)
1005 const size_t len
= strlen (str
) + 1;
1006 char *p
= xmalloc (len
);
1007 strncpy (p
, str
, len
);
1012 str_concat (const char *str1
, const char *str2
)
1014 const size_t len
= strlen (str1
) + strlen (str2
) + 1;
1017 p
= str
= xmalloc (len
);
1018 strncpy (p
, str1
, strlen (str1
));
1020 strncpy (p
, str2
, strlen (str2
));
1028 get_file_type (mode_t mode
)
1032 else if (S_ISDIR (mode
))
1034 else if (S_ISCHR (mode
))
1035 return "character device";
1036 else if (S_ISBLK (mode
))
1037 return "block device";
1038 else if (S_ISFIFO (mode
))
1039 return "named pipe";
1040 else if (S_ISLNK (mode
))
1041 return "symbolic link";
1042 else if (S_ISSOCK (mode
))
1049 has_color_name (const char *str
, const char *name
)
1053 assert (strlen (str
));
1054 assert (strlen (name
));
1056 if (!(*str
== *name
|| *str
== toupper (*name
)))
1058 else if (*(name
+ 1) != '\0'
1059 && !((p
= strstr (str
+ 1, name
+ 1)) && p
== str
+ 1))
1065 #define DO_VFPRINTF(fmt) \
1067 fprintf (stderr, "%s: ", program_name); \
1068 va_start (ap, fmt); \
1069 vfprintf (stderr, fmt, ap); \
1071 fprintf (stderr, "\n"); \
1074 vfprintf_diag (const char *fmt
, ...)
1080 vfprintf_fail (const char *fmt
, ...)
1083 exit (EXIT_FAILURE
);
1087 stack_var (void ***list
, unsigned int *stacked
, unsigned int index
, void *ptr
)
1089 /* nothing to stack */
1093 *list
= xmalloc (sizeof (void *));
1097 for (i
= 0; i
< *stacked
; i
++)
1101 return; /* reused */
1103 *list
= xrealloc (*list
, (*stacked
+ 1) * sizeof (void *));
1105 (*list
)[index
] = ptr
;
1110 release_var (void **list
, unsigned int stacked
, void **ptr
)
1113 /* nothing to release */
1116 for (i
= 0; i
< stacked
; i
++)
1117 if (list
[i
] == *ptr
)