File: winfun.c

package info (click to toggle)
audacity 1.2.4b-2.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 24,136 kB
  • ctags: 20,445
  • sloc: ansic: 139,567; cpp: 55,998; sh: 24,963; lisp: 3,772; makefile: 1,683; python: 272
file content (204 lines) | stat: -rw-r--r-- 6,142 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* winfun.c - windows user interface functions for xlisp */
/* Written by Brian Kendig. */
/*Windows Console and DirectSound code added by Morgan Green and Chris Tchou*/

//#include <Quickdraw.h>
//#include <Windows.h>
//#include <Memory.h>
#include <windows.h>
#include <switches.h>
#include "xlisp.h"
#include "sound.h"



/* osbgetc - get a character from a binary file ======  added for console*/
/* int osbgetc(fp) FILE *fp; {return (getc(fp));} */
int osbgetc(FILE *fp) 
{ 
  int c; c = (getc(fp));
/*  if (dbgflg) printf("osbgetc: got %d from FILE %x\n", c, fp); */
  return c;
}



LVAL xsystem (V) { return NIL; }
LVAL xgetkey (V) { return NIL; }


void ossymbols() 
{
    HWND mywin;
    HANDLE myhandle;
    COORD winsize, origin;
    WORD textattrib;
    DWORD n;
    mywin = GetForegroundWindow();
    SetConsoleTitle("Nyquist");

#ifdef WIN32_SNAZZY_CONSOLE     // -eub
    myhandle = GetStdHandle(STD_OUTPUT_HANDLE);
    origin.X = 0;
    origin.Y = 0;
    winsize.X = 100;
    winsize.Y = 40;
    textattrib = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;

    FillConsoleOutputAttribute(myhandle, textattrib, winsize.X * winsize.Y, origin, &n);
    SetConsoleScreenBufferSize(myhandle, winsize);
    FillConsoleOutputAttribute(myhandle, textattrib, winsize.X * winsize.Y, origin, &n);
    SetConsoleTextAttribute(myhandle, textattrib); 
#endif

    setvbuf(stdout, NULL, _IONBF, 0);   // makes it work under NT emacs 20.3   -eub

}


LVAL xsetupconsole()
{
    HWND mywin;
    HANDLE myhandle;
    COORD winsize, origin;
    WORD textattrib;
    DWORD n;
    mywin = GetForegroundWindow();
    SetConsoleTitle("Nyquist");

    myhandle = GetStdHandle(STD_OUTPUT_HANDLE);
    origin.X = 0;
    origin.Y = 0;
    winsize.X = 100;
    winsize.Y = 40;
    textattrib = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;

    FillConsoleOutputAttribute(myhandle, textattrib, winsize.X * winsize.Y, origin, &n);
    SetConsoleScreenBufferSize(myhandle, winsize);
    FillConsoleOutputAttribute(myhandle, textattrib, winsize.X * winsize.Y, origin, &n);
    SetConsoleTextAttribute(myhandle, textattrib);
    return NIL;
}


void get_xlisp_path(char *p, long p_max)
{
    HKEY hkey;
    DWORD dwType;

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ, &hkey) !=
        ERROR_SUCCESS) {
        *p = 0;
        return;
    }
    if (RegOpenKeyEx(hkey, "CMU", 0, KEY_READ, &hkey) !=
        ERROR_SUCCESS) {
        *p = 0;
        return;
    }
    if (RegOpenKeyEx(hkey, "Nyquist", 0, KEY_READ, &hkey) !=
        ERROR_SUCCESS) {
        *p = 0;
        return;
    }
    if (RegQueryValueEx(hkey, "XLISPPATH", NULL, &dwType, p, &p_max) !=
           ERROR_SUCCESS) {
           *p = 0;	
        return;
    }
}

#ifdef WINGUI
/* NOTE: define WINGUI in the Project Settings for the NyqWin projects.
 * Do not define WINGUI for console versions of Nyquist
 */

/****************************************************************************
*               fileopen
* Inputs:
*    char *deflt: the default file name (e.g. from command line)
*    char *extension: default extension
*    char *mode: read ("r") or write ("w")
*    char *prompt: prompt for user
* Returns:
*    opened file pointer
* Effect: 
*    opens file, prompts for user input if necessary and warns about
*    possible confusion.  If deflt is a null string or NULL, the user will
*    be prompted for a name.     The routine loops until a file is opened.
*    If the mode is "r", a check is made to see if the file exists
*    with and without the extension.     If both exist a warning is given.
*    For mode "w", a check is made to see if the file will be overwritten.
*    The extension is automatically added if the default or user-typed
*    file has no "."     At the bottom of the loop body, if no file has
*    been opened, the user is prompted for another file name.
****************************************************************************/

char fileopen_name[100];        /* name of the opened file */

HINSTANCE hInst;            /* current instance */
HWND hMainWindow;           /* main window handle */


char *getfilename(char *deflt, char *extension, char *mode, char *prompt)
{
    char filter[64];
    char *filter_ptr = NULL;
    OPENFILENAME open_file_name;

    if (extension && extension[0] == 0) extension = NULL;
    if (strcmp(extension, "lsp") == 0) {
        strcpy(filter, "Lisp files");
    } else if (extension) {
        sprintf(filter, "%s files", extension);
    }
    if (extension) {
        sprintf(filter + strlen(filter), "%c*.%s%cAll files%c*.*%c",
                0, extension, 0, 0, 0);
        filter_ptr = filter;
    }
    if (!deflt) deflt = "";     /* treat NULL as the empty string */
    strcpy(fileopen_name, deflt);

    open_file_name.lStructSize = sizeof(OPENFILENAME);
    open_file_name.hwndOwner = hMainWindow;

    open_file_name.hInstance = hInst;
    open_file_name.lpstrFilter = filter_ptr; 
    open_file_name.lpstrCustomFilter = NULL; 
    open_file_name.nMaxCustFilter = 0; 
    open_file_name.nFilterIndex = 0; 
    open_file_name.lpstrFile = fileopen_name; 
    open_file_name.nMaxFile = 100; 
    open_file_name.lpstrFileTitle = NULL;
    open_file_name.nMaxFileTitle = 0; 
    open_file_name.lpstrInitialDir = NULL; 
    open_file_name.lpstrTitle = prompt;
    open_file_name.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; 
    open_file_name.nFileOffset = 0; 
    open_file_name.nFileExtension = 0; 
    open_file_name.lpstrDefExt = extension; 
    open_file_name.lCustData = 0; 
    open_file_name.lpfnHook = 0; 
    open_file_name.lpTemplateName = 0;
    if (((*mode == 'r') && GetOpenFileName(&open_file_name)) ||
        ((*mode == 'w') && GetSaveFileName(&open_file_name))) {
        return open_file_name.lpstrFile;
    }
    return NULL;
}



FILE *fileopen(char *deflt, char *extension, char *mode, char *prompt)
{
    FILE *fp = NULL;            /* file corresponding to filename */
    if (getfilename(deflt, extension, mode, prompt)) {
        fp = fopen(fileopen_name, mode);
    }
    return fp;
}

#endif