~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to lneato/mswin32/lneato.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Lefteris Koutsofios - AT&T Bell Laboratories */
 
2
 
 
3
#include <windows.h>
 
4
#include <stdarg.h>
 
5
#include <stdio.h>
 
6
#include <string.h>
 
7
#include <stdlib.h>
 
8
#include <sys/types.h>
 
9
#include <sys/stat.h>
 
10
 
 
11
#ifdef MSWIN32
 
12
#define NEAR
 
13
#else
 
14
#define NEAR __near
 
15
#endif
 
16
 
 
17
static char * NEAR shellpath;
 
18
 
 
19
static char *buildpath (char *);
 
20
static void panic (char *, int, char *, char *, ...);
 
21
 
 
22
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
 
23
        LPSTR lpCmdLine, int nCmdShow) {
 
24
    HANDLE handle;
 
25
    char cmd[256];
 
26
    char *path;
 
27
    char *s;
 
28
 
 
29
    shellpath = getenv ("PATH");
 
30
    if (!shellpath || !(path = buildpath ("lefty"))) {
 
31
        if (!GetModuleFileName (hInstance, cmd, 256) ||
 
32
                !(s = strrchr (cmd, '\\')))
 
33
            exit (1);
 
34
        *s = 0;
 
35
        shellpath = &cmd[0];
 
36
        if (!(path = buildpath ("lefty")))
 
37
            exit (1);
 
38
    }
 
39
    if (lpCmdLine[0] == 0)
 
40
        sprintf (cmd, "%s -e \"load('dotty.lefty');dotty.protogt.lserver='neato';dotty.simple(null);\"", path);
 
41
    else
 
42
        sprintf (cmd, "%s -e \"load('dotty.lefty');dotty.protogt.lserver='neato';dotty.simple('%Ns');\"", path, lpCmdLine);
 
43
 
 
44
    handle = WinExec (cmd, SW_SHOW);
 
45
    exit (0);
 
46
}
 
47
 
 
48
#define PATHDEL '\\'
 
49
#define PATHSEP ';'
 
50
 
 
51
static char pathbuf[1024];
 
52
static char commandbuf[1024];
 
53
 
 
54
static char *buildpath (char *file) {
 
55
    struct stat statbuf;
 
56
    char *s1, *s2;
 
57
    int mode, pathi;
 
58
 
 
59
    if (file && file[0] && (file[0] == '.' || file[0] == PATHDEL))
 
60
        return file;
 
61
    mode = ~0;
 
62
    s1 = shellpath;
 
63
    while (*s1) {
 
64
        pathi = 0;
 
65
        while (*s1 && *s1 != PATHSEP)
 
66
            pathbuf[pathi++] = *s1++;
 
67
        if (*s1)
 
68
            s1++;
 
69
        pathbuf[pathi++] = PATHDEL;
 
70
        for (s2 = file; *s2; s2++)
 
71
            pathbuf[pathi++] = *s2;
 
72
        pathbuf[pathi++] = '.';
 
73
        pathbuf[pathi++] = 'e';
 
74
        pathbuf[pathi++] = 'x';
 
75
        pathbuf[pathi++] = 'e';
 
76
        pathbuf[pathi] = '\000';
 
77
        if (stat (pathbuf, &statbuf) == 0 && (statbuf.st_mode & mode))
 
78
            return pathbuf;
 
79
    }
 
80
    return NULL;
 
81
}
 
82
 
 
83
static void panic (char *file, int line, char *func, char *fmt, ...) {
 
84
    va_list args;
 
85
 
 
86
    va_start(args, fmt);
 
87
    {
 
88
        char buf[256];
 
89
        vsprintf (buf, fmt, args);
 
90
        MessageBox ((HWND) NULL, buf, "dotty PANIC", MB_APPLMODAL);
 
91
    }
 
92
    abort ();
 
93
}