x2p/hash.h Public declarations for the above
x2p/INTERN.h Same as above
x2p/Makefile.SH Precursor to Makefile
-x2p/proto.h Dummy header
x2p/s2p.PL Sed to perl translator
x2p/str.c String handling package
x2p/str.h Public declarations for the above
-/* $RCSfile: EXTERN.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:05 $
+/* EXTERN.h
*
* Copyright (C) 1991, 1992, 1993, 1994, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: EXTERN.h,v $
*/
#undef EXT
-/* $RCSfile: INTERN.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:06 $
+/* INTERN.h
*
* Copyright (C) 1993, 1994, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: INTERN.h,v $
*/
#undef EXT
-/* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
+/* a2p.h
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
* 2000, 2001, 2002, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: a2p.h,v $
*/
#define VOIDUSED 1
EXT char *Yes INIT("1");
EXT char *No INIT("");
-#define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
-
-#define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%"NVgf")",Str->str_nval),buf) : "" )))
#define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
-#define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
EXT STR *Str;
#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
-/* $RCSfile: a2py.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:14 $
+/* a2py.c
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
* 2000, 2001, 2002, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: a2py.c,v $
*/
#if defined(OS2) || defined(WIN32) || defined(NETWARE)
-/* $RCSfile: hash.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:20 $
+/* hash.c
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2002,
- * by Larry Wall and others
+ * 2005 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: hash.c,v $
*/
#include <stdio.h>
return FALSE;
}
-#ifdef NOTUSED
-bool
-hdelete(register HASH *tb, char *key)
-{
- register char *s;
- register int i;
- register int hash;
- register HENT *entry;
- register HENT **oentry;
-
- if (!tb)
- return FALSE;
- for (s=key, i=0, hash = 0;
- /* while */ *s;
- s++, i++, hash *= 5) {
- hash += *s * coeff[i];
- }
-
- oentry = &(tb->tbl_array[hash & tb->tbl_max]);
- entry = *oentry;
- i = 1;
- for (; entry; i=0, oentry = &entry->hent_next, entry = entry->hent_next) {
- if (entry->hent_hash != hash) /* strings can't be equal */
- continue;
- if (strNE(entry->hent_key,key)) /* is this it? */
- continue;
- safefree((char*)entry->hent_val);
- safefree(entry->hent_key);
- *oentry = entry->hent_next;
- safefree((char*)entry);
- if (i)
- tb->tbl_fill--;
- return TRUE;
- }
- return FALSE;
-}
-#endif
-
void
hsplit(HASH *tb)
{
- int oldsize = tb->tbl_max + 1;
+ const int oldsize = tb->tbl_max + 1;
register int newsize = oldsize * 2;
register int i;
register HENT **a;
return tb;
}
-#ifdef NOTUSED
-hshow(register HASH *tb)
-{
- fprintf(stderr,"%5d %4d (%2d%%)\n",
- tb->tbl_max+1,
- tb->tbl_fill,
- tb->tbl_fill * 100 / (tb->tbl_max+1));
-}
-#endif
-
int
hiterinit(register HASH *tb)
{
tb->tbl_eiter = Null(HENT*);
return tb->tbl_fill;
}
-
-HENT *
-hiternext(register HASH *tb)
-{
- register HENT *entry;
-
- entry = tb->tbl_eiter;
- do {
- if (entry)
- entry = entry->hent_next;
- if (!entry) {
- tb->tbl_riter++;
- if (tb->tbl_riter > tb->tbl_max) {
- tb->tbl_riter = -1;
- break;
- }
- entry = tb->tbl_array[tb->tbl_riter];
- }
- } while (!entry);
-
- tb->tbl_eiter = entry;
- return entry;
-}
-
-char *
-hiterkey(register HENT *entry)
-{
- return entry->hent_key;
-}
-
-STR *
-hiterval(register HENT *entry)
-{
- return entry->hent_val;
-}
-/* $RCSfile: hash.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:21 $
+/* hash.h
*
- * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2000,
+ * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2005
* by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: hash.h,v $
*/
#define FILLPCT 60 /* don't make greater than 99 */
#ifdef DOINIT
-char coeff[] = {
+char const coeff[] = {
61,59,53,47,43,41,37,31,29,23,17,13,11,7,3,1,
61,59,53,47,43,41,37,31,29,23,17,13,11,7,3,1,
61,59,53,47,43,41,37,31,29,23,17,13,11,7,3,1,
61,59,53,47,43,41,37,31,29,23,17,13,11,7,3,1,
61,59,53,47,43,41,37,31,29,23,17,13,11,7,3,1};
#else
-extern char coeff[];
+extern const char coeff[];
#endif
typedef struct hentry HENT;
HENT *tbl_eiter; /* current entry of iterator */
};
-bool hdelete (HASH *tb, char *key);
STR * hfetch ( HASH *tb, char *key );
int hiterinit ( HASH *tb );
-char * hiterkey ( HENT *entry );
-HENT * hiternext ( HASH *tb );
-STR * hiterval ( HENT *entry );
HASH * hnew ( void );
void hsplit ( HASH *tb );
bool hstore ( HASH *tb, char *key, STR *val );
+++ /dev/null
-/* proto.h
- *
- * Copyright (C) 1991, 1996, by Larry Wall
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the README file.
- *
- */
-/* $RCSfile: str.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:26 $
+/* str.c
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
- * 2001, 2002, by Larry Wall and others
+ * 2001, 2002, 2005 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: str.c,v $
*/
#include "EXTERN.h"
return str->str_ptr;
}
-double
-str_2num(register STR *str)
-{
- if (!str)
- return 0.0;
- if (str->str_len && str->str_pok)
- str->str_nval = atof(str->str_ptr);
- else
- str->str_nval = 0.0;
- str->str_nok = 1;
-#ifdef DEBUGGING
- if (debug & 32)
- fprintf(stderr,"0x%lx num(%g)\n",(unsigned long)str,str->str_nval);
-#endif
- return str->str_nval;
-}
-
void
str_sset(STR *dstr, register STR *sstr)
{
}
void
-str_chop(register STR *str, register char *ptr) /* like set but assuming ptr is in str */
-
-
-{
- if (!(str->str_pok))
- str_2ptr(str);
- str->str_cur -= (ptr - str->str_ptr);
- memcpy(str->str_ptr, ptr, str->str_cur + 1);
- str->str_nok = 0; /* invalidate number */
- str->str_pok = 1; /* validate pointer */
-}
-
-void
str_ncat(register STR *str, register char *ptr, register int len)
{
if (!(str->str_pok))
str->str_pok = 1; /* validate pointer */
}
-char *
-str_append_till(register STR *str, register char *from, register int delim, char *keeplist)
-{
- register char *to;
- register int len;
-
- if (!from)
- return Nullch;
- len = strlen(from);
- GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + len + 1);
- str->str_nok = 0; /* invalidate number */
- str->str_pok = 1; /* validate pointer */
- to = str->str_ptr+str->str_cur;
- for (; *from; from++,to++) {
- if (*from == '\\' && from[1] && delim != '\\') {
- if (!keeplist) {
- if (from[1] == delim || from[1] == '\\')
- from++;
- else
- *to++ = *from++;
- }
- else if (strchr(keeplist,from[1]))
- *to++ = *from++;
- else
- from++;
- }
- else if (*from == delim)
- break;
- *to = *from;
- }
- *to = '\0';
- str->str_cur = to - str->str_ptr;
- return from;
-}
-
STR *
str_new(int len)
{
return str;
}
-void
-str_grow(register STR *str, int len)
-{
- if (len && str)
- GROWSTR(&(str->str_ptr), &(str->str_len), len + 1);
-}
-
/* make str point to what nstr did */
void
-str_replace(register STR *str, register STR *nstr)
-{
- safefree(str->str_ptr);
- str->str_ptr = nstr->str_ptr;
- str->str_len = nstr->str_len;
- str->str_cur = nstr->str_cur;
- str->str_pok = nstr->str_pok;
- if ((str->str_nok = nstr->str_nok))
- str->str_nval = nstr->str_nval;
- safefree((char*)nstr);
-}
-
-void
str_free(register STR *str)
{
if (!str)
return str->str_cur ? str->str_ptr : Nullch;
}
-void
-str_inc(register STR *str)
-{
- register char *d;
-
- if (!str)
- return;
- if (str->str_nok) {
- str->str_nval += 1.0;
- str->str_pok = 0;
- return;
- }
- if (!str->str_pok) {
- str->str_nval = 1.0;
- str->str_nok = 1;
- return;
- }
- for (d = str->str_ptr; *d && *d != '.'; d++) ;
- d--;
- if (!isDIGIT(*str->str_ptr) || !isDIGIT(*d) ) {
- str_numset(str,atof(str->str_ptr) + 1.0); /* punt */
- return;
- }
- while (d >= str->str_ptr) {
- if (++*d <= '9')
- return;
- *(d--) = '0';
- }
- /* oh,oh, the number grew */
- GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + 2);
- str->str_cur++;
- for (d = str->str_ptr + str->str_cur; d > str->str_ptr; d--)
- *d = d[-1];
- *d = '1';
-}
-
-void
-str_dec(register STR *str)
-{
- register char *d;
-
- if (!str)
- return;
- if (str->str_nok) {
- str->str_nval -= 1.0;
- str->str_pok = 0;
- return;
- }
- if (!str->str_pok) {
- str->str_nval = -1.0;
- str->str_nok = 1;
- return;
- }
- for (d = str->str_ptr; *d && *d != '.'; d++) ;
- d--;
- if (!isDIGIT(*str->str_ptr) || !isDIGIT(*d) || (*d == '0' && d == str->str_ptr)) {
- str_numset(str,atof(str->str_ptr) - 1.0); /* punt */
- return;
- }
- while (d >= str->str_ptr) {
- if (--*d >= '0')
- return;
- *(d--) = '9';
- }
-}
-
-/* make a string that will exist for the duration of the expression eval */
-
-STR *
-str_mortal(STR *oldstr)
-{
- register STR *str = str_new(0);
- static long tmps_size = -1;
-
- str_sset(str,oldstr);
- if (++tmps_max > tmps_size) {
- tmps_size = tmps_max;
- if (!(tmps_size & 127)) {
- if (tmps_size)
- tmps_list = (STR**)saferealloc((char*)tmps_list,
- (tmps_size + 128) * sizeof(STR*) );
- else
- tmps_list = (STR**)safemalloc(128 * sizeof(char*));
- }
- }
- tmps_list[tmps_max] = str;
- return str;
-}
-
STR *
str_make(char *s)
{
return str;
}
-STR *
-str_nmake(double n)
-{
- register STR *str = str_new(0);
-
- str_numset(str,n);
- return str;
-}
-/* $RCSfile: str.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:27 $
+/* str.h
*
- * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2000,
+ * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2005
* by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: str.h,v $
*/
struct string {
EXT STR **tmps_list;
EXT long tmps_max INIT(-1);
-double str_2num ( STR *str );
char * str_2ptr ( STR *str );
-char * str_append_till ( STR *str, char *from, int delim, char *keeplist );
void str_cat ( STR *str, char *ptr );
-void str_chop ( STR *str, char *ptr );
-void str_dec ( STR *str );
void str_free ( STR *str );
char * str_gets ( STR *str, FILE *fp );
-void str_grow ( STR *str, int len );
-void str_inc ( STR *str );
int str_len ( STR *str );
STR * str_make ( char *s );
-STR * str_mortal ( STR *oldstr );
void str_ncat ( STR *str, char *ptr, int len );
STR * str_new ( int len );
-STR * str_nmake ( double n );
void str_nset ( STR *str, char *ptr, int len );
void str_numset ( STR *str, double num );
-void str_replace ( STR *str, STR *nstr );
void str_scat ( STR *dstr, STR *sstr );
void str_set ( STR *str, char *ptr );
void str_sset ( STR *dstr, STR *sstr );
-/* $RCSfile: util.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:29 $
+/* util.c
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
- * 2000, 2001, by Larry Wall and others
+ * 2000, 2001, 2005 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: util.c,v $
*/
#include "EXTERN.h"
#include <stdarg.h>
#define FLUSH
-static char nomem[] = "Out of memory!\n";
+static const char nomem[] = "Out of memory!\n";
/* paranoid version of malloc */
free(where);
}
-/* safe version of string copy */
-
-char *
-safecpy(char *to, register char *from, register int len)
-{
- register char *dest = to;
-
- if (from != Nullch)
- for (len--; len && (*dest++ = *from++); len--) ;
- *dest = '\0';
- return to;
-}
-
/* copy a string up to some (non-backslashed) delimiter, if any */
char *
char *
savestr(char *str)
{
- register char *newaddr = (char *) safemalloc((MEM_SIZE)(strlen(str)+1));
+ register char * const newaddr = (char *) safemalloc((MEM_SIZE)(strlen(str)+1));
(void)strcpy(newaddr,str);
return newaddr;
}
void
-croak(const char *pat,...)
-{
-#if defined(HAS_VPRINTF)
- va_list args;
-
- va_start(args, pat);
- vfprintf(stderr,pat,args);
- va_end(args);
-#else
- fprintf(stderr,pat,a1,a2,a3,a4);
-#endif
- exit(1);
-}
-
-void
fatal(const char *pat,...)
{
#if defined(HAS_VPRINTF)
-/* $RCSfile: util.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:30 $
+/* util.h
*
- * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000,
+ * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2005
* by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: util.h,v $
*/
/* is the string for makedir a directory name or a filename? */
char * cpytill ( char *to, char *from, int delim );
void growstr ( char **strptr, int *curlen, int newlen );
char * instr ( char *big, char *little );
-char * safecpy ( char *to, char *from, int len );
char * savestr ( char *str );
-void croak ( const char *pat, ... );
void fatal ( const char *pat, ... );
void warn ( const char *pat, ... );
int prewalk ( int numit, int level, int node, int *numericptr );
Malloc_t safemalloc (MEM_SIZE nbytes);
-Malloc_t safecalloc (MEM_SIZE elements, MEM_SIZE size);
Malloc_t saferealloc (Malloc_t where, MEM_SIZE nbytes);
Free_t safefree (Malloc_t where);
-/* $RCSfile: walk.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:31 $
+/* walk.c
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999,
* 2000, 2001, 2002, 2005 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
- *
- * $Log: walk.c,v $
*/
#include "EXTERN.h"
STR *
walk(int useval, int level, register int node, int *numericptr, int minprec)
-
-
-
-
- /* minimum precedence without parens */
{
register int len;
register STR *str;