* AT&T Research, Florham Park NJ *
**********************************************************/
-
-/* Lefteris Koutsofios - AT&T Bell Laboratories */
+/* Lefteris Koutsofios - AT&T Labs Research */
#include "common.h"
jmp_buf exitljbuf;
int idlerunmode;
fd_set inputfds;
-#ifdef FEATURE_NETSCAPE
static int innetscape;
static char *nswin;
-#endif
#ifndef FEATURE_MS
#define PATHDEL '/'
#endif
#ifdef FEATURE_X11
#define WINSYS "LEFTYWINSYS=X11"
-#endif
-#ifdef FEATURE_MS
-#define WINSYS "LEFTYWINSYS=mswin"
-#endif
-#ifdef FEATURE_GTK
-#ifdef FEATURE_MS
-#define WINSYS "LEFTYWINSYS=mswin"
#else
-#define WINSYS "LEFTYWINSYS=X11"
-#endif
+#define WINSYS "LEFTYWINSYS=mswin"
#endif
#include "g.h"
#include "gcommon.h"
-#ifdef FEATURE_GTK
-static int Gnocallbacks;
-#else
#ifdef FEATURE_MS
extern int Gnocallbacks;
-/* #else */
-/* static int Gnocallbacks; */
-#endif
+#else
+static int Gnocallbacks;
#endif
static char *pathp;
static char *lpathp;
-int init(char *aout)
-{
- char *s1, *s2, c = 0;
+int init (char *aout) {
+ char *s1, *s2, c;
int k;
#ifdef FEATURE_WIN32
-#ifndef FEATURE_GTK
- extern HANDLE hinstance;
- char buf[260];
-#endif
+ extern HANDLE hinstance;
+ char buf[260];
#endif
-#ifdef FEATURE_NETSCAPE
- if (getenv("INNETSCAPE"))
- innetscape = TRUE, nswin = getenv("NSWIN");
-#endif
- if (!(pathp = malloc(PATHINCR * PATHSIZE)))
- panic(POS, "init", "pathp malloc failed");
- if (!(cmdp = malloc(CMDINCR * CMDSIZE)))
- panic(POS, "init", "cmdp malloc failed");
- shellpath = getenv("PATH");
-#if defined(FEATURE_GTK) || defined(FEATURE_X11)
- if (!strchr(aout, PATHDEL)) {
- leftypath = "";
- if ((s1 = buildpath(aout, TRUE)))
- aout = strdup(s1);
- } else
- aout = strdup(aout);
-#else
- GetModuleFileName(hinstance, buf, 260);
+ c = 0;
+ if (getenv ("INNETSCAPE"))
+ innetscape = TRUE, nswin = getenv ("NSWIN");
+ if (!(pathp = malloc (PATHINCR * PATHSIZE)))
+ panic (POS, "init", "pathp malloc failed");
+ if (!(cmdp = malloc (CMDINCR * CMDSIZE)))
+ panic (POS, "init", "cmdp malloc failed");
+ shellpath = getenv ("PATH");
+#ifdef FEATURE_WIN32
+ GetModuleFileName (hinstance, buf, 260);
aout = buf;
+#else
+ if (!strchr (aout, PATHDEL)) {
+ leftypath = "";
+ if ((s1 = buildpath (aout, TRUE)))
+ aout = strdup (s1);
+ } else
+ aout = strdup (aout);
#endif
- if (!(s1 = strrchr(aout, PATHDEL)))
- s1 = aout;
+ if (!(s1 = strrchr (aout, PATHDEL)))
+ s1 = aout;
*s1 = 0;
- if (!(leftypath = malloc(PATHINCR * PATHSIZE)))
- panic(POS, "init", "leftypath malloc failed");
+ if (!(leftypath = malloc (PATHINCR * PATHSIZE)))
+ panic (POS, "init", "leftypath malloc failed");
leftypath[0] = 0;
- if ((s1 = getenv("LEFTYPATH")))
- strcat(leftypath, s1), strcat(leftypath, PATHSEPSTR);
+ if ((s1 = getenv ("LEFTYPATH")))
+ strcat (leftypath, s1), strcat (leftypath, PATHSEPSTR);
if (*aout)
- strcat(leftypath, aout), strcat(leftypath, PATHSEPSTR);
+ strcat (leftypath, aout), strcat (leftypath, PATHSEPSTR);
for (k = 0; k < 2; k++) {
- if (k == 0)
- s1 = aout;
- else
- s1 = shellpath;
- while (s1) {
- if ((s2 = strchr(s1, PATHSEP)))
- c = *s2, *s2 = 0;
- strcat(leftypath, s1);
- strcat(leftypath, PATHLEFTY);
- if (s2) {
- *s2 = c, s1 = s2 + 1;
- strcat(leftypath, PATHSEPSTR);
- } else
- s1 = NULL;
- }
- if (leftypath[0])
- strcat(leftypath, PATHSEPSTR);
+ if (k == 0)
+ s1 = aout;
+ else
+ s1 = shellpath;
+ while (s1) {
+ if ((s2 = strchr (s1, PATHSEP)))
+ c = *s2, *s2 = 0;
+ strcat (leftypath, s1);
+ strcat (leftypath, PATHLEFTY);
+ if (s2) {
+ *s2 = c, s1 = s2 + 1;
+ strcat (leftypath, PATHSEPSTR);
+ } else
+ s1 = NULL;
+ }
+ if (leftypath[0])
+ strcat (leftypath, PATHSEPSTR);
}
-#ifdef LEFTYPATH
- strcat(leftypath, LEFTYPATH), strcat(leftypath, PATHSEPSTR);
-#endif
- if (!(leftyoptions = getenv("LEFTYOPTIONS")))
- leftyoptions = "";
- putenv(WINSYS);
+ if (!(leftyoptions = getenv ("LEFTYOPTIONS")))
+ leftyoptions = "";
+ putenv (WINSYS);
return 0;
}
-void term(void)
-{
+void term (void) {
if (lpathp)
- free(lpathp);
+ free (lpathp);
if (pathp)
- free(pathp);
+ free (pathp);
if (cmdp)
- free(cmdp);
+ free (cmdp);
}
-/* given a file name, it looks for this file in LEFTYPATH
- (and if flag == TRUE in PATH)
+/* given a file name, it looks for this file in LEFTYPATH
+ (and if flag == TRUE in PATH)
- returns the first occurance of that file or NULL
+ returns the first occurance of that file or NULL
*/
-char *buildpath(char *file, int flag)
-{
+char *buildpath (char *file, int flag) {
struct stat statbuf;
char *s1, *s2;
int mode, pathi, i;
#ifdef FEATURE_NETSCAPE
if (flag == FALSE && innetscape) {
#ifdef FEATURE_WIN32
- HWND hwnd;
- char *s;
-
- if (!nswin) {
- MessageBox((HWND) NULL, "error: no peer window",
- "Lefty Warning", MB_APPLMODAL);
- return NULL;
- }
- hwnd = atol(nswin);
- fprintf(stdout, "file %s\n", file);
- if (fflush(stdout) == -1) {
- MessageBox((HWND) NULL, "Lost Connection to Netscape",
- "Lefty Warning", MB_APPLMODAL);
- return NULL;
- }
- SendMessage(hwnd, WM_USER, 12, 34);
- fgets(pathp, PATHINCR - 1, stdin);
- pathp[strlen(pathp) - 1] = 0;
- if (pathp[0] == 0)
- return NULL;
- return pathp;
+ HWND hwnd;
+ char *s;
+
+ if (!nswin) {
+ MessageBox (
+ (HWND) NULL, "error: no peer window",
+ "Lefty Warning", MB_APPLMODAL
+ );
+ return NULL;
+ }
+ hwnd = atol (nswin);
+ fprintf (stdout, "file %s\n", file);
+ if (fflush (stdout) == -1) {
+ MessageBox (
+ (HWND) NULL, "Lost Connection to Netscape",
+ "Lefty Warning", MB_APPLMODAL
+ );
+ return NULL;
+ }
+ SendMessage (hwnd, WM_USER, 12, 34);
+ fgets (pathp, PATHINCR - 1, stdin);
+ pathp[strlen (pathp) - 1] = 0;
+ if (pathp[0] == 0)
+ return NULL;
+ return pathp;
#else
- Window window;
- static XButtonEvent ev;
-
- if (!nswin) {
- fprintf(stderr, "error: no peer window\n");
- return NULL;
- }
- window = strtol(nswin, NULL, 16);
- fprintf(stdout, "file %s\n", file);
- if (fflush(stdout) == -1) {
- fprintf(stderr, "Lost Connection to Netscape\n");
- return NULL;
- }
- ev.type = ButtonPress;
- ev.window = window;
- ev.x = -123, ev.y = -123;
- XSendEvent(Gdisplay, window, False, 0, (XEvent *) & ev);
- XFlush(Gdisplay);
- fgets(pathp, PATHINCR - 1, stdin);
- pathp[strlen(pathp) - 1] = 0;
- if (pathp[0] == 0)
- return NULL;
- return pathp;
+ Window window;
+ static XButtonEvent ev;
+
+ if (!nswin) {
+ fprintf (stderr, "error: no peer window\n");
+ return NULL;
+ }
+ window = strtol (nswin, NULL, 16);
+ fprintf (stdout, "file %s\n", file);
+ if (fflush (stdout) == -1) {
+ fprintf (stderr, "Lost Connection to Netscape\n");
+ return NULL;
+ }
+ ev.type = ButtonPress;
+ ev.window = window;
+ ev.x = -123, ev.y = -123;
+ XSendEvent (Gdisplay, window, False, 0, (XEvent *) &ev);
+ XFlush (Gdisplay);
+ fgets (pathp, PATHINCR - 1, stdin);
+ pathp[strlen (pathp) - 1] = 0;
+ if (pathp[0] == 0)
+ return NULL;
+ return pathp;
#endif
}
#endif
#ifndef FEATURE_MS
- if (file && file[0] && strchr(file, PATHDEL))
- return file;
+ if (file && file[0] && strchr (file, PATHDEL))
+ return file;
mode = S_IRUSR | (flag ? S_IXUSR : 0);
for (i = 0; i < 2; i++) {
- if (i == 0)
- s1 = leftypath;
- else
- s1 = shellpath;
- while (*s1) {
- pathi = 0;
- while (*s1 && *s1 != PATHSEP)
- if (pathi < PATHINCR)
- pathp[pathi++] = *s1++;
- if (*s1)
- s1++;
- if (pathi + 3 + strlen(file) >= PATHINCR)
- continue;
- pathp[pathi++] = PATHDEL;
- for (s2 = file; *s2; s2++)
- pathp[pathi++] = *s2;
- pathp[pathi] = '\000';
- if (stat(pathp, &statbuf) == 0 && (statbuf.st_mode & mode))
- return pathp;
- }
+ if (i == 0)
+ s1 = leftypath;
+ else
+ s1 = shellpath;
+ while (*s1) {
+ pathi = 0;
+ while (*s1 && *s1 != PATHSEP)
+ if (pathi < PATHINCR)
+ pathp[pathi++] = *s1++;
+ if (*s1)
+ s1++;
+ if (pathi + 3 + strlen (file) >= PATHINCR)
+ continue;
+ pathp[pathi++] = PATHDEL;
+ for (s2 = file; *s2; s2++)
+ pathp[pathi++] = *s2;
+ pathp[pathi] = '\000';
+ if (stat (pathp, &statbuf) == 0 && (statbuf.st_mode & mode))
+ return pathp;
+ }
}
#else
- if (file && file[0] && strchr(file, PATHDEL))
- return file;
+ if (file && file[0] && strchr (file, PATHDEL))
+ return file;
mode = ~0;
for (i = 0; i < 2; i++) {
- if (i == 0)
- s1 = leftypath;
- else
- s1 = shellpath;
- while (*s1) {
- pathi = 0;
- while (*s1 && *s1 != PATHSEP)
- if (pathi < PATHINCR)
- pathp[pathi++] = *s1++;
- if (*s1)
- s1++;
- if (pathi + 7 + strlen(file) >= PATHINCR)
- continue;
- pathp[pathi++] = PATHDEL;
- for (s2 = file; *s2; s2++)
- pathp[pathi++] = *s2;
- if (flag) {
- pathp[pathi++] = '.';
- pathp[pathi++] = 'e';
- pathp[pathi++] = 'x';
- pathp[pathi++] = 'e';
- }
- pathp[pathi] = '\000';
- if (stat(pathp, &statbuf) == 0 && (statbuf.st_mode & mode))
- return pathp;
- }
+ if (i == 0)
+ s1 = leftypath;
+ else
+ s1 = shellpath;
+ while (*s1) {
+ pathi = 0;
+ while (*s1 && *s1 != PATHSEP)
+ if (pathi < PATHINCR)
+ pathp[pathi++] = *s1++;
+ if (*s1)
+ s1++;
+ if (pathi + 7 + strlen (file) >= PATHINCR)
+ continue;
+ pathp[pathi++] = PATHDEL;
+ for (s2 = file; *s2; s2++)
+ pathp[pathi++] = *s2;
+ if (flag) {
+ pathp[pathi++] = '.';
+ pathp[pathi++] = 'e';
+ pathp[pathi++] = 'x';
+ pathp[pathi++] = 'e';
+ }
+ pathp[pathi] = '\000';
+ if (stat (pathp, &statbuf) == 0 && (statbuf.st_mode & mode))
+ return pathp;
+ }
}
#endif
return NULL;
}
-/* given a file name (path) and an optional format (fmt)
- it builds a shell command.
+/* given a file name (path) and an optional format (fmt)
+ it builds a shell command.
- %e is replaced by the command path
- %i ... the input channel descriptor
- %o ... the output channel descriptor
- %h ... the hostname
+ %e is replaced by the command path
+ %i ... the input channel descriptor
+ %o ... the output channel descriptor
+ %h ... the hostname
- returns the complete command string or NULL
+ returns the complete command string or NULL
*/
-char *buildcommand(char *path, char *host, int infd, int outfd, char *fmt)
-{
+char *buildcommand (char *path, char *host, int infd, int outfd, char *fmt) {
char buf[10];
char *s1, *s2;
int bufi;
cmdp[0] = '\000';
for (bufi = 0, s1 = fmt; *s1; s1++) {
- if (*s1 == '%') {
- if (*(s1 + 1) == 'e') {
- s1++;
- if (bufi + strlen(path) >= CMDINCR)
- return NULL;
- for (s2 = path; *s2; s2++)
- cmdp[bufi++] = *s2;
- continue;
- } else if (*(s1 + 1) == 'i') {
- if (infd == -1)
- buf[0] = '%', buf[1] = 'd', buf[2] = '\000';
- else
- sprintf(buf, "%d", infd);
- s1++;
- if (bufi + strlen(buf) >= CMDINCR)
- return NULL;
- for (s2 = buf; *s2; s2++)
- cmdp[bufi++] = *s2;
- continue;
- } else if (*(s1 + 1) == 'o') {
- if (outfd == -1)
- buf[0] = '%', buf[1] = 'd', buf[2] = '\000';
- else
- sprintf(buf, "%d", outfd);
- s1++;
- if (bufi + strlen(buf) >= CMDINCR)
- return NULL;
- for (s2 = buf; *s2; s2++)
- cmdp[bufi++] = *s2;
- continue;
- } else if (*(s1 + 1) == 'h') {
- s1++;
- if (bufi + strlen(host) >= CMDINCR)
- return NULL;
- for (s2 = host; *s2; s2++)
- cmdp[bufi++] = *s2;
- continue;
- }
- }
- if (bufi + 1 >= CMDINCR)
- return NULL;
- cmdp[bufi++] = *s1;
+ if (*s1 == '%') {
+ if (*(s1 + 1) == 'e') {
+ s1++;
+ if (bufi + strlen (path) >= CMDINCR)
+ return NULL;
+ for (s2 = path; *s2; s2++)
+ cmdp[bufi++] = *s2;
+ continue;
+ } else if (*(s1 + 1) == 'i') {
+ if (infd == -1)
+ buf[0] = '%', buf[1] = 'd', buf[2] = '\000';
+ else
+ sprintf (buf, "%d", infd);
+ s1++;
+ if (bufi + strlen (buf) >= CMDINCR)
+ return NULL;
+ for (s2 = buf; *s2; s2++)
+ cmdp[bufi++] = *s2;
+ continue;
+ } else if (*(s1 + 1) == 'o') {
+ if (outfd == -1)
+ buf[0] = '%', buf[1] = 'd', buf[2] = '\000';
+ else
+ sprintf (buf, "%d", outfd);
+ s1++;
+ if (bufi + strlen (buf) >= CMDINCR)
+ return NULL;
+ for (s2 = buf; *s2; s2++)
+ cmdp[bufi++] = *s2;
+ continue;
+ } else if (*(s1 + 1) == 'h') {
+ s1++;
+ if (bufi + strlen (host) >= CMDINCR)
+ return NULL;
+ for (s2 = host; *s2; s2++)
+ cmdp[bufi++] = *s2;
+ continue;
+ }
+ }
+ if (bufi + 1 >= CMDINCR)
+ return NULL;
+ cmdp[bufi++] = *s1;
}
if (bufi + 1 >= CMDINCR)
- return NULL;
+ return NULL;
cmdp[bufi] = '\000';
return &cmdp[0];
}
/* varargs function for printing a warning */
-void warning(char *file, int line, char *func, char *fmt, ...)
-{
+void warning (char *file, int line, char *func, char *fmt, ...) {
va_list args;
#ifndef FEATURE_MS
if (!warnflag)
- return;
+ return;
va_start(args, fmt);
- /* Gnocallbacks = TRUE; */
- fprintf(stderr, "warning: (file %s, line %d, func %s) ", file, line,
- func);
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
- /* Gnocallbacks = FALSE; */
+ Gnocallbacks = TRUE;
+ fprintf (stderr, "warning: (file %s, line %d, func %s) ", file, line, func);
+ vfprintf (stderr, fmt, args);
+ fprintf (stderr, "\n");
+ Gnocallbacks = FALSE;
va_end(args);
#else
char buf[256];
if (!warnflag)
- return;
+ return;
va_start(args, fmt);
- vsprintf(buf, fmt, args);
+ vsprintf (buf, fmt, args);
Gnocallbacks = TRUE;
- MessageBox((HWND) NULL, buf, "Lefty Warning", MB_APPLMODAL);
+ MessageBox ((HWND) NULL, buf, "Lefty Warning", MB_APPLMODAL);
Gnocallbacks = FALSE;
va_end(args);
#endif
}
/* varargs function for printing an error message and aborting */
-void panic(char *file, int line, char *func, char *fmt, ...)
-{
+void panic (char *file, int line, char *func, char *fmt, ...) {
va_list args;
#ifndef FEATURE_MS
va_start(args, fmt);
- /* Gnocallbacks = TRUE; */
- fprintf(stderr, "panic: (file %s, line %d, func %s) ", file, line,
- func);
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
- fflush(stdout);
- /* Gnocallbacks = FALSE; */
+ Gnocallbacks = TRUE;
+ fprintf (stderr, "panic: (file %s, line %d, func %s) ", file, line, func);
+ vfprintf (stderr, fmt, args);
+ fprintf (stderr, "\n");
+ fflush (stdout);
+ Gnocallbacks = FALSE;
va_end(args);
#else
char buf[256];
va_start(args, fmt);
- vsprintf(buf, fmt, args);
+ vsprintf (buf, fmt, args);
Gnocallbacks = TRUE;
- MessageBox((HWND) NULL, buf, "Lefty PANIC", MB_APPLMODAL);
+ MessageBox ((HWND) NULL, buf, "Lefty PANIC", MB_APPLMODAL);
Gnocallbacks = FALSE;
va_end(args);
#endif
- abort();
+ abort ();
}
-/* varargs function for printing an error message, and the
- error message corresponding to errno and aborting
+/* varargs function for printing an error message, and the
+ error message corresponding to errno and aborting
*/
-void panic2(char *file, int line, char *func, char *fmt, ...)
-{
+void panic2 (char *file, int line, char *func, char *fmt, ...) {
va_list args;
#ifndef FEATURE_MS
va_start(args, fmt);
- /* Gnocallbacks = TRUE; */
- fprintf(stderr, "panic: (file %s, line %d, func %s) ", file, line,
- func);
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
- perror("");
- fflush(stdout);
- /* Gnocallbacks = FALSE; */
+ Gnocallbacks = TRUE;
+ fprintf (stderr, "panic: (file %s, line %d, func %s) ", file, line, func);
+ vfprintf (stderr, fmt, args);
+ fprintf (stderr, "\n");
+ perror ("");
+ fflush (stdout);
+ Gnocallbacks = FALSE;
va_end(args);
#else
char buf[256];
va_start(args, fmt);
- vsprintf(buf, fmt, args);
+ vsprintf (buf, fmt, args);
Gnocallbacks = TRUE;
- MessageBox((HWND) NULL, buf, "Lefty PANIC", MB_APPLMODAL);
+ MessageBox ((HWND) NULL, buf, "Lefty PANIC", MB_APPLMODAL);
Gnocallbacks = FALSE;
va_end(args);
#endif
- abort();
+ abort ();
}
#ifdef FEATURE_MS
-int printf(const char *fmt, ...)
-{
+int printf (const char *fmt, ...) {
va_list args;
- char buf[256];
+ char buf[10240];
int l;
va_start(args, fmt);
- vsprintf(buf, fmt, args);
- l = strlen(buf);
- if (l > 0) {
- if (buf[l - 1] == '\n')
- buf[l - 1] = 0;
- }
+ vsprintf (buf, fmt, args);
+ l = strlen (buf);
+ if (buf[l - 1] == '\n')
+ buf[l - 1] = 0;
if (buf[0]) {
- Gnocallbacks = TRUE;
- MessageBox((HWND) NULL, buf, "Lefty printf", MB_APPLMODAL);
- Gnocallbacks = FALSE;
+ Gnocallbacks = TRUE;
+ MessageBox ((HWND) NULL, buf, "Lefty printf", MB_APPLMODAL);
+ Gnocallbacks = FALSE;
}
va_end(args);
- return l;
}
#endif
* AT&T Research, Florham Park NJ *
**********************************************************/
-
-/* Lefteris Koutsofios - AT&T Bell Laboratories */
+/* Lefteris Koutsofios - AT&T Labs Research */
#include "common.h"
#include "mem.h"
#include "display.h"
typedef struct dnode_t {
- Ttype_t ttype;
+ int ttype;
Tobj ko, vo;
char *path;
} dnode_t;
static int indent, afternl;
-static void update(dnode_t *);
-static int cmp(const void *, const void *);
-static seennode_t *findseen(dnode_t *);
-static void add2seen(dnode_t *);
-static void pr(char *);
+static void update (dnode_t *);
+static int cmp (const void *, const void *);
+static seennode_t *findseen (dnode_t *);
+static void add2seen (dnode_t *);
+static void pr (char *);
-void Dinit(void)
-{
- seenp = Marrayalloc((long) SEENINCR * SEENSIZE);
+void Dinit (void) {
+ seenp = Marrayalloc ((long) SEENINCR * SEENSIZE);
seeni = 0;
seenn = SEENINCR;
}
-void Dterm(void)
-{
- Marrayfree(seenp);
+void Dterm (void) {
+ Marrayfree (seenp);
seeni = seenn = 0;
}
-void Dtrace(Tobj to, int offset)
-{
+void Dtrace (Tobj to, int offset) {
dnode_t dnode;
char *s;
int i;
indent = offset - 2;
afternl = TRUE;
- if (Tgettype(to) != T_TABLE) {
- pr((s = Ssfull(NULL, to))), free(s);
- return;
+ if (Tgettype (to) != T_TABLE) {
+ pr ((s = Ssfull (NULL, to))), free (s);
+ return;
}
seeni = 0;
dnode.vo = to;
dnode.path = "";
- update(&dnode);
+ update (&dnode);
for (i = 0; i < seeni; i++)
- free(seenp[i].path), seenp[i].path = NULL;
+ free (seenp[i].path), seenp[i].path = NULL;
}
-static void update(dnode_t * pnode)
-{
+static void update (dnode_t *pnode) {
Tkvindex_t tkvi;
dnode_t *list, *cnode;
seennode_t *seennode;
indent += 2;
n = ((Ttable_t *) pnode->vo)->n;
- if (!(list = malloc(n * sizeof(dnode_t))))
- panic(POS, "update", "list malloc failed");
- for (cnode = &list[0], Tgetfirst(pnode->vo, &tkvi); tkvi.kvp;
- cnode++, Tgetnext(&tkvi)) {
- cnode->ko = tkvi.kvp->ko;
- cnode->vo = tkvi.kvp->vo;
- cnode->ttype = Tgettype(cnode->vo);
+ if (!(list = malloc (n * sizeof (dnode_t))))
+ panic (POS, "update", "list malloc failed");
+ for (
+ cnode = &list[0], Tgetfirst (pnode->vo, &tkvi); tkvi.kvp;
+ cnode++, Tgetnext (&tkvi)
+ ) {
+ cnode->ko = tkvi.kvp->ko;
+ cnode->vo = tkvi.kvp->vo;
+ cnode->ttype = Tgettype (cnode->vo);
}
- qsort((char *) list, n, sizeof(dnode_t), cmp);
+ qsort ((char *) list, n, sizeof (dnode_t), cmp);
for (i = 0, cnode = &list[0]; i < n; i++, cnode++) {
- cnode->path = Spath(pnode->path, cnode->ko);
- seennode = findseen(cnode);
- if (seennode) {
- pr((s = Sseen(cnode->ko, seennode->path))), free(s);
- } else {
- add2seen(cnode);
- if (cnode->ttype == T_TABLE) {
- pr((s = Stfull(cnode->ko))), free(s);
- update(cnode);
- pr("];");
- } else {
- pr((s = Ssfull(cnode->ko, cnode->vo))), free(s);
- }
- }
+ cnode->path = Spath (pnode->path, cnode->ko);
+ seennode = findseen (cnode);
+ if (seennode) {
+ pr ((s = Sseen (cnode->ko, seennode->path))), free (s);
+ } else {
+ add2seen (cnode);
+ if (cnode->ttype == T_TABLE) {
+ pr ((s = Stfull (cnode->ko))), free (s);
+ update (cnode);
+ pr ("];");
+ } else {
+ pr ((s = Ssfull (cnode->ko, cnode->vo))), free (s);
+ }
+ }
}
- free(list);
+ free (list);
indent -= 2;
}
-static int cmp(const void *a, const void *b)
-{
- Ttype_t atype, btype;
+static int cmp (const void *a, const void *b) {
+ int atype, btype;
dnode_t *anode, *bnode;
- double d1 = 0.0, d2 = 0.0;
+ double d1, d2;
+ d1 = 0.0, d2 = 0.0;
anode = (dnode_t *) a, bnode = (dnode_t *) b;
- atype = Tgettype(anode->ko), btype = Tgettype(bnode->ko);
+ atype = Tgettype (anode->ko), btype = Tgettype (bnode->ko);
if (atype != btype)
- return (atype - btype);
+ return (atype - btype);
if (atype == T_STRING)
- return Strcmp(Tgetstring(anode->ko), Tgetstring(bnode->ko));
+ return strcmp (Tgetstring (anode->ko), Tgetstring (bnode->ko));
if (atype == T_INTEGER)
- d1 = Tgetinteger(anode->ko), d2 = Tgetinteger(bnode->ko);
+ d1 = Tgetinteger (anode->ko), d2 = Tgetinteger (bnode->ko);
else if (atype == T_REAL)
- d1 = Tgetreal(anode->ko), d2 = Tgetreal(bnode->ko);
+ d1 = Tgetreal (anode->ko), d2 = Tgetreal (bnode->ko);
if (d1 < d2)
- return -1;
+ return -1;
else if (d1 > d2)
- return 1;
+ return 1;
else
- return 0; /* but this should never happen since keys are unique */
+ return 0; /* but this should never happen since keys are unique */
}
-static seennode_t *findseen(dnode_t * cnode)
-{
+static seennode_t *findseen (dnode_t *cnode) {
int i;
for (i = 0; i < seeni; i++)
- if (seenp[i].vo == cnode->vo)
- return &seenp[i];
+ if (seenp[i].vo == cnode->vo)
+ return &seenp[i];
return NULL;
}
-static void add2seen(dnode_t * cnode)
-{
+static void add2seen (dnode_t *cnode) {
if (seeni >= seenn) {
- seenp = Marraygrow(seenp, (long) (seenn + SEENINCR) * SEENSIZE);
- seenn += SEENINCR;
+ seenp = Marraygrow (seenp, (long) (seenn + SEENINCR) * SEENSIZE);
+ seenn += SEENINCR;
}
seenp[seeni].vo = cnode->vo;
seenp[seeni++].path = cnode->path;
}
-static void pr(char *s)
-{
+static void pr (char *s) {
char *s1;
int i;
for (s1 = s; *s1; s1++) {
- if (afternl) {
- for (i = 0; i < indent; i++)
- putchar(' ');
- afternl = FALSE;
- }
- if (*s1 == '\n')
- afternl = TRUE;
- putchar((*s1)); /* HACK: to keep proto happy */
+ if (afternl) {
+ for (i = 0; i < indent; i++)
+ putchar (' ');
+ afternl = FALSE;
+ }
+ if (*s1 == '\n')
+ afternl = TRUE;
+ putchar ((*s1)); /* HACK: to keep proto happy */
}
- putchar('\n');
+ putchar ('\n');
afternl = TRUE;
}