1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-01-26 15:03:47 +01:00

Move library tree where it belongs

This commit is contained in:
ra
2010-01-24 09:19:39 +00:00
parent e74978ba77
commit 58caf78a86
6020 changed files with 2790154 additions and 0 deletions

View File

@@ -0,0 +1 @@
#include "sndwin32.h"

View File

@@ -0,0 +1,175 @@
/* switches.h -- conditional compilation features for WIN32 systems */
/* CHANGE LOG
* --------------------------------------------------------------------
* 28Apr03 dm major reorganization of conditional compilation in Nyquist
*/
#ifdef SWITCHES
Error: switches.h included more than once.
#endif
#define HAS_STDLIB_H 1
#define HAS_SYS_TYPES_H 1
#define HAS_SYS_STAT_H 1
#undef HAS_STAT_H
#undef HAS_MALLOC_H
/* define one of HAS_GETTIMEOFDAY, HAS_FTIME, */
#undef HAS_GETTIMEOFDAY
#undef HAS_FTIME
#undef READ_LINE
#undef USE_RANDOM
#define USE_RAND 1
/* since there are 2 versions Nyquist for windows: nyquist and nyqwin,
we use WINGUI to decide which to compile
*/
#ifndef WINGUI
/* use C library printf as nyquist_printf() */
#define USE_PRINTF 1
#endif
/* define this to be printf, or define your own fn of the form
void nyquist_printf(char *format, ...);
(for a GUI)
*/
void nyquist_printf(char *format, ...);
#define NEED_ULONG 1
#define NEED_USHORT 1
#define NEED_BYTE 1
#define NEED_ROUND 1
#undef NEED_DEFINE_MALLOC
/* definitions for libsndfile */
/* Target processor clips on negative float to int conversion */
/* (true on i386) */
#define CPU_CLIPS_NEGATIVE 1
/* Target processor clips on positive float to int conversion */
/* (true on i386) */
#define CPU_CLIPS_POSITIVE 1
/* Target processor is little endian. */
#define CPU_IS_LITTLE_ENDIAN 1
/* Target processor is big endian. */
#define CPU_IS_BIG_ENDIAN 0
/* Set to 1 if S_IRGRP is defined */
#define HAVE_DECL_S_IRGRP 0
/* Set to 1 if the compiler supports the struct hack. */
#define HAVE_FLEXIBLE_ARRAY 1
/* Define to 1 if you have the `fsync' function. */
#define HAVE_FSYNC 1
/* Define to 1 if you have the `gmtime' function. */
#define HAVE_GMTIME 1
/* Define to 1 if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 0
/* Define if you have C99's lrint function. */
#define HAVE_LRINT 0
/* Define if you have C99's lrintf function. */
#define HAVE_LRINTF 0
/* Define to 1 if you have the `snprintf' function. */
#define snprintf _snprintf
#define HAVE_SNPRINTF 1
/* Define to 1 if the system has the type `ssize_t'. */
#define ssize_t SSIZE_T
#define HAVE_SSIZE_T 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 0
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
#define HAVE_SYS_WAIT_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 0
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
/* Set to 1 if compiling for MacOSX */
#define OS_IS_MACOSX 0
/* Set to 1 if compiling for Win32 */
#define OS_IS_WIN32 1
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Set to 1 to use the native windows API */
#define USE_WINDOWS_API 1
/* The size of `int64_t', as computed by sizeof. */
/* Omit this if int64_t is not a type */
#undef SIZEOF_INT64_T
/* The size of long as computed by sizeof. */
#define SIZEOF_LONG 4
/* Set to long if unknown */
#define SIZEOF_SF_COUNT_T 8
/* explicitly choose a platform */
#undef UNIX
#ifndef WINDOWS
#define WINDOWS 1
#endif
#ifndef WIN32
#define WIN32 1
#endif
#ifndef MICROSOFT
#define MICROSOFT 1
#endif
#ifndef DOS
#define DOS 1
#endif
#undef MACINTOSH
// Under Windows, we do not want synchronous input because then we do not
// get the break character (^G) while XLISP is busy. Actually, there is a
// way to send a message to the process, but the Java IDE cannot send
// Windows messages, so we have to check for console character input
// using the _kbhit function.
//#define BUFFERED_SYNCHRONOUS_INPUT 1
#define SPACE_FOR_PLAY 10000
#define MAX_CHANNELS 16
/* this will enable code to read midi files, etc. */
#define CMTSTUFF 1
/* NYQUIST tells some CMT code that we're really in
* XLISP and NYQUIST
*/
#define NYQUIST 1
#include "swlogic.h"

View File

@@ -0,0 +1,131 @@
; machine.lsp -- machine/system-dependent definitions
; Windows
;; default behavior is to call SETUP-CONSOLE to get large white typescript
;;
;; set *setup-console* to nil in your personal init.lsp to override this behavior
;; (this may be necessary to work with emacs)
;;
(if (not (boundp '*setup-console*)) (setf *setup-console* t))
(if *setup-console* (setup-console))
(if (not (boundp '*default-sf-format*))
(setf *default-sf-format* snd-head-Wave))
(if (not (boundp '*default-sound-file*))
(compute-default-sound-file))
(if (not (boundp '*default-sf-dir*))
(setf *default-sf-dir* ""))
(if (not (boundp '*default-sf-mode*))
(setf *default-sf-mode* snd-mode-pcm))
(if (not (boundp '*default-sf-bits*))
(setf *default-sf-bits* 16))
(if (not (boundp '*default-plot-file*))
(setf *default-plot-file* "points.dat"))
;(if (not (boundp '*plotscript-file*))
; (setf *plotscript-file* "sys/unix/rs6k/plotscript"))
; local definition for play
(defmacro play (expr)
`(s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*))
(defun r ()
(s-save (s-read *default-sound-file*) NY:ALL "" :play t)
)
; PLAY-FILE -- play a file
(defun play-file (name)
(s-save (s-read name) NY:ALL "" :play t))
; FULL-NAME-P -- test if file name is a full path or relative path
;
; (otherwise the *default-sf-dir* will be prepended
;
(defun full-name-p (filename)
(or (eq (char filename 0) #\\)
(eq (char filename 0) #\/)
(eq (char filename 0) #\.)
(and (> (length filename) 2)
(both-case-p (char filename 0))
(equal (char filename 1) #\:))))
; RELATIVE-PATH-P -- test if filename or path is a relative path
;
; note that properly converting a Windows path from relative to
; absolute is complicated by paths like: E:MYFILE.LSP
; Nyquist assumes that if there is a drive letter, the path is
; absolute, e.g. E:\TMP\MYFILE.LSP and if there is no drive,
; the path is relative, e.g. you cannot have \TMP\MYFILE.LSP
;
(defun relative-path-p (filename)
(or (< (length filename) 2)
(not (both-case-p (char filename 0)))
(not (equal (char filename 1) #\:))))
(setf *file-separator* #\\)
(defun ny:load-file () (load "*.*"))
(defun ny:reload-file () (load "*"))
; save the standard function to write points to a file
;
;(setfn s-plot-points s-plot)
;(defun array-max-abs (points)
; (let ((m 0.0))
; (dotimes (i (length points))
; (setf m (max m (abs (aref points i)))))
; m))
;(setf graph-width 600)
;(setf graph-height 220)
;(defun s-plot (snd &optional (n 600))
; (show-graphics)
; (clear-graphics)
; (cond ((soundp snd)
; (s-plot-2 snd n (/ graph-height 2) graph-height))
; (t
; (let ((gh (/ graph-height (length snd)))
; hs)
; (dotimes (i (length snd))
; (setf hs (s-plot-2 (aref snd i) n (+ (/ gh 2) (* i gh)) gh hs)))))))
;
;
;(defun s-plot-2 (snd n y-offset graph-height horizontal-scale)
; (prog ((points (snd-samples snd n))
; maxpoint horizontal-scale vertical-scale)
; (setf maxpoint (array-max-abs points))
; (moveto 0 y-offset)
; (lineto graph-width y-offset)
; (moveto 0 y-offset)
; (cond ((null horizontal-scale)
; (setf horizontal-scale (/ (float graph-width) (length points)))))
; (setf vertical-scale (- (/ (float graph-height) 2 maxpoint)))
; (dotimes (i (length points))
; (lineto (truncate (* horizontal-scale i))
; (+ y-offset (truncate (* vertical-scale (aref points i))))))
; (format t "X Axis: ~A to ~A (seconds)\n" (snd-t0 snd) (/ (length points) (snd-srate snd)))
; (format t "Y Axis: ~A to ~A\n" (- maxpoint) maxpoint)
; (format t "~A samples plotted.\n" (length points))
; (return horizontal-scale)
; ))
;
; S-EDIT - run the audio editor on a sound
;
;(defmacro s-edit (&optional expr)
; `(prog ()
; (if ,expr (s-save ,expr 1000000000 *default-sound-file*))
; (system (format nil "audio_editor ~A &"
; (soundfilename *default-sound-file*)))))

View File

@@ -0,0 +1,272 @@
/* 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"
/* Added by Ning Hu May.2001
xsetdir - set current directory of the process */
LVAL xsetdir() {
TCHAR ssCurDir[MAX_PATH], szCurDir[MAX_PATH];
strcpy(ssCurDir, getstring(xlgastring()));
xllastarg();
if (SetCurrentDirectory(ssCurDir)) {
if (GetCurrentDirectory(
sizeof(szCurDir)/sizeof(TCHAR), szCurDir)) {
return cvstring(szCurDir);
/* create the result string
stdputstr("Current Directory: ");
stdputstr(szCurDir);
stdputstr("\n"); */
}
}
stdputstr("Directory Setting Error\n");
/* return nil on error*/
return NIL;
}
/* xget_temp_path -- get a path to create temp files */
LVAL xget_temp_path()
{
char *p;
char szDir[MAX_PATH];
char szDirLC[MAX_PATH];
int rslt = GetTempPath(MAX_PATH, szDir);
if (rslt > MAX_PATH || rslt <= 0) {
return cvstring("");
} else {
/* Vista apparently treats c:\windows with
* special semantics, so just don't allow
* GetTempPath to put us in c:\windows...
*/
strcpy(szDirLC, szDir); /* convert to lower case */
for (p = szDirLC; *p; p++) {
*p = tolower(*p);
}
if (strstr(szDirLC, "c:\\windows")) {
/* c:\windows is bad. */
return cvstring("");
}
return cvstring(szDir);
}
}
//Updated End
/* 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;
#ifdef WIN32_SNAZZY_CONSOLE
HANDLE myhandle;
COORD winsize, origin;
WORD textattrib;
DWORD n;
#endif
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;
LVAL lval;
extern LVAL s_search_path;
*p = 0; /* for simplicity, we assume if !*p that path was not found */
/* therefore, no path is equivalent to an empty string path */
/* first, look for path in global variable *SEARCH-PATH* */
lval = getvalue(s_search_path);
if (lval && stringp(lval)) {
strncpy(p, getstring(lval), p_max);
p[p_max - 1] = 0; /* make sure string is terminated, even if truncated */
}
if (*p) return; /* we got search path, so don't look in registry */
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ, &hkey) !=
ERROR_SUCCESS) {
return;
}
if (RegOpenKeyEx(hkey, "CMU", 0, KEY_READ, &hkey) !=
ERROR_SUCCESS) {
return;
}
if (RegOpenKeyEx(hkey, "Nyquist", 0, KEY_READ, &hkey) !=
ERROR_SUCCESS) {
return;
}
if (RegQueryValueEx(hkey, "XLISPPATH", NULL, &dwType, p, &p_max) !=
ERROR_SUCCESS) {
*p = 0;
return;
}
}
LVAL xget_user()
{
// not implemented for Windows, just use "nyquist"
return cvstring("nyquist");
}
#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

View File

@@ -0,0 +1,11 @@
#ifdef __cplusplus
extern "C" {
#endif
void get_xlisp_path(char *p, long p_max);
char *getfilename(char *deflt, char *extension, char *mode, char *prompt);
FILE *fileopen(char *deflt, char *extension, char *mode, char *prompt);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,398 @@
/* winstuff.c - windows interface routines for xlisp */
/* Written by Chris Tchou. */
/* This file contains the stuff that the other xlisp files call directly. */
/* Changes by Roger Dannenberg, Jan 2006:
Previously, the input thread would block on input, so if a command line
instantiation of Nyquist called (EXIT), the process would still block
in getchar() until the user typed a newline. Now, I only start the
input thread if ostgetc is called (input is really needed). This will
still read ahead and block, but only in cases where you are already
interactive.
/* Changes by Roger Dannenberg, April 2004:
To support interrupts to Lisp processing, XLISP call oscheck frequently to
test for an abort or break condition. This condition can be activated by
special handlers, e.g. if a software interrupt is generated by Ctrl-C.
Alternatively, the application can read ahead and look for break characters
in the input stream. A third approach, implemented by Ning Hu for her
Delphi-based IDE, is to send a Windows message to the process. Unfortunately,
the Java IDE does not support sending a Windows message, nor can console
IO be used to read ahead (console IO does not work because, when started by
Java, Nyquist standard IO is redirected through pipes). The two solutions
to enable break character prcessing seem to be:
1) extend Java with C code to find the process and send Windows messages
2) add a thread to perform read ahead and break character processing
Option 2 contains the ugliness to Nyquist IO, which is already big and ugly,
and leaves Java alone, which is something I don't know much about anyway,
so I have chosen option 2: create a thread and read ahead. This uses only
about 50 lines of code.
A shortcoming of this approach is that, except for Ctrl-C, break characters
like ^P, ^B, and ^U require the user to type RETURN to end the input line
and allow the character to be processed.
The thread will set a signal whenever a line of input is delivered so that
Nyquist can block waiting for input. The signal will also be set when a
^C or ^G is detected.
For flexibility, compatibility with the Delphi IDE (NyqIDE) is retained by
continuing to check for Windows process messages.
*/
#include <windows.h> /* Added by Ning Hu Apr.2001 */
#include <process.h> /* Added by Dannenberg Apr 2004 */
#include <signal.h> /* Added by Dannneberg, Apr 2004 */
#include "exitpa.h" /* Added by Dannneberg, Apr 2004 */
const char os_pathchar = '\\';
const char os_sepchar = ',';
#undef ERROR
#include <stdio.h>
//#include <QuickDraw.h> /* for Random */
#include <memory.h> /* for DisposPtr */
#include <string.h>
//#include <SegLoad.h> /* for ExitToShell */
#include "xlisp.h"
#include "cext.h"
#include "userio.h"
#include "sliders.h"
#include "sound.h" /* define nosc_enabled */
/* externals */
extern FILE *tfp; /* transcript file pointer */
extern int cursorPos;
extern char *macgets (void);
//Added by Ning Hu Apr.2001
extern int _isatty(int);
extern int redirect_flag;
//Add end
/* local variables */
int lposition;
static char *linebuf = NULL, *lineptr;
static int numChars;
/* input thread */
unsigned long input_thread_handle = -1;
#define NEED_INPUT if (input_thread_handle == -1) start_input_thread();
#define input_buffer_max 1024
#define input_buffer_mask (input_buffer_max - 1)
char input_buffer[1024];
volatile int input_buffer_head = 0;
volatile int input_buffer_tail = 0;
volatile int buffer_eof = 0;
HANDLE input_buffer_ready = NULL;
BOOL WINAPI ctrl_c_handler(DWORD dwCtrlType)
{
if (dwCtrlType == CTRL_C_EVENT) {
abort_flag = ABORT_LEVEL;
return TRUE;
}
return FALSE;
}
#ifdef DEBUG_INPUT
extern FILE *to_input_buffer;
#endif
void input_thread_run(void *args)
{
int c;
/* this gets called, possible later, in io_init() in userio.c, but
* that doesn't seem to prevent this thread from being killed by
* CTRL-C, so call it here to be safe.
*/
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
/* printf("input_thread_run\n"); */
while (!buffer_eof) {
int head;
c = getchar();
if (c == EOF && abort_flag) {
// when user types ^C, an EOF is generated for some reason.
// Ignore it...
if (abort_flag == ABORT_LEVEL) c = ABORT_CHAR;
else c = BREAK_CHAR;
} else if (c == ABORT_CHAR) {
abort_flag = ABORT_LEVEL;
} else if (!abort_flag && c == BREAK_CHAR) {
// notice that a break will be ignored until XLISP
// handles the ABORT_LEVEL
abort_flag = BREAK_LEVEL;
} else if (c == BREAK_CHAR) {
; // ignore this because abort_flag is set to ABORT_LEVEL
} else if (c == '\005' || c == '\006') { // control-e or control-f
; // ignore these. IDE will send control-f to turn off echo, but
// under Windows, echo is already turned off. We filter control-f
// here to avoid generating an error message. Maybe the IDE should
// not send control-f in the first place, but the IDE is cross-platform
// and does not know it's running under Windows, whereas this file
// is platform dependent.
} else if (c == '\016') { // begin hidden message
#define MSGBUF_MAX 64
char msgbuf[MSGBUF_MAX];
int msgbufx = 0;
char type_char = getchar(); // read message type character
printf("begin hidden message: %c\n", type_char);
if (type_char == EOF) buffer_eof = TRUE;
else {
// message is terminated by '\021'
while ((c = getchar()) != '\021' &&
c != EOF &&
msgbufx < MSGBUF_MAX - 1) {
msgbuf[msgbufx++] = c;
}
msgbuf[msgbufx++] = 0;
printf("message: %s\n", msgbuf);
if (c == EOF) buffer_eof = TRUE;
else if (msgbufx < MSGBUF_MAX) {
if (type_char == 'S') { // slider change message
// message format is index<space>value
int index;
float value;
if (sscanf(msgbuf, "%d %g", &index, &value) == 2) {
set_slider(index, value);
printf("set_slider %d %g\n", index, value);
}
}
}
}
} else if (c == EOF) {
buffer_eof = TRUE;
} else {
// insert character into the FIFO
head = (input_buffer_head + 1) & input_buffer_mask;
while (head == input_buffer_tail) Sleep(100);
input_buffer[input_buffer_head] = c;
#ifdef DEBUG_INPUT
if (to_input_buffer) putc(c, to_input_buffer);
#endif
input_buffer_head = head;
}
if (c == '\n' || abort_flag || buffer_eof) {
SetEvent(input_buffer_ready);
// wake up Nyquist if it is waiting for input
}
}
// printf("Input thread exiting\n");
}
//int isascii (char c) { return 1; } /* every char is an ascii char, isn't it? */
void start_input_thread()
{
// create thread to process input
input_thread_handle = _beginthread(input_thread_run, 0, NULL);
if (input_thread_handle == -1) {
printf("Unable to create input thread, errno = %d\n", errno);
EXIT(1);
}
}
void osinit (char *banner)
{
printf(banner);
if (_isatty( _fileno( stdin ) ) ){
redirect_flag = 0;
#ifdef DEBUG
printf( "stdout has not been redirected to a file\n" ); //for debugging use
#endif
} else {
redirect_flag = 1;
#ifdef DEBUG
printf( "stdout has been redirected to a file\n"); //for debugging use
#endif
}
// signal when input is ready
input_buffer_ready = CreateEvent(NULL, FALSE, FALSE, NULL);
if (input_buffer_ready == NULL) {
printf("Unable to create Event object\n");
EXIT(1);
}
}
FILE *osaopen (char *name, char *mode) {
return fopen (name, mode);
}
FILE *osbopen (char *name, char *mode) {
char nmode[4];
strcpy (nmode, mode); strcat (nmode, "b");
return (fopen (name, nmode));
}
int osclose (FILE *fp) { return (fclose (fp)); }
int osaputc (int ch, FILE *fp) { return (putc (ch, fp)); }
int osbputc (int ch, FILE *fp) { return (putc (ch, fp)); }
void osoutflush(FILE *fp) { fflush(fp); }
/* osagetc - get a character from an ascii file */
int osagetc(fp)
FILE *fp;
{
return (getc(fp));
}
extern int abort_flag;
extern int redirect_flag; //Added by Ning Hu Apr.2001
int ostgetc (void)
{
int c;
NEED_INPUT;
while (!buffer_eof && (input_buffer_tail == input_buffer_head)) {
oscheck();
WaitForSingleObject(input_buffer_ready, INFINITE);
}
if (buffer_eof) c = EOF;
else {
c = input_buffer[input_buffer_tail];
input_buffer_tail = (input_buffer_tail + 1) & input_buffer_mask;
}
if (c == '\025') { // control-u
xlcleanup();
} else if (c == '\020') { // control-p
xlcontinue();
} else if (c == '\024') { // control-t
xinfo();
}
return c;
}
void ostputc (int ch) {
// macputc (ch);
putchar(ch); // console
if (tfp) osaputc (ch, tfp);
}
void ostoutflush()
{
if (tfp) fflush(tfp);
fflush(stdout);
}
void osflush (void) {
lineptr = linebuf;
numChars = 0;
lposition = 0;
}
void oscheck (void) {
MSG lpMsg;
#if OSC
if (nosc_enabled) nosc_poll();
#endif
// check_aborted(); -- call to userio.c superceded by code here in winstuff.c
// printf("Current Thread: %d\n", GetCurrentThreadId()); //for debugging use
// look for Windows messages from NyqIDE (a Delphi program)
if ((redirect_flag) && (PeekMessage(&lpMsg, NULL, 0, 0, PM_REMOVE)!=0)) {
if (lpMsg.message == WM_CHAR) {
switch (lpMsg.wParam) {
case ABORT_CHAR: abort_flag = ABORT_LEVEL;
break;
case BREAK_CHAR: // for nyquist, defined to be 2
case 7: // NyqIDE sends 7 (BEL) as break character
abort_flag = BREAK_LEVEL;
break;
}
// printf("Get message: %d %d %d\n", lpMsg.wParam, BREAK_CHAR, abort_flag); //for debugging use
}
}
if (abort_flag == ABORT_LEVEL) {
abort_flag = 0;
osflush();
xltoplevel();
} else if (abort_flag == BREAK_LEVEL) {
abort_flag = 0;
osflush();
xlbreak("BREAK", s_unbound);
}
}
//Update end
void oserror (char *msg) {
char line[100], *p;
sprintf (line,"error: %s\n",msg);
for (p = line; *p != '\0'; ++p) ostputc (*p);
}
void osfinish(void) {
portaudio_exit();
/* dispose of everything... */
// if (linebuf) DisposPtr (linebuf);
// MacWrapUp ();
// ExitToShell ();
}
int renamebackup (char *filename) { return 0; }
static WIN32_FIND_DATA FindFileData;
static HANDLE hFind = INVALID_HANDLE_VALUE;
#define OSDIR_LIST_READY 0
#define OSDIR_LIST_STARTED 1
#define OSDIR_LIST_DONE 2
static int osdir_list_status = OSDIR_LIST_READY;
#define OSDIR_MAX_PATH 256
static char osdir_path[OSDIR_MAX_PATH];
// osdir_list_start -- prepare to list a directory
int osdir_list_start(char *path)
{
if (strlen(path) >= OSDIR_MAX_PATH - 2) {
xlcerror("LISTDIR path too big", "return nil", NULL);
return FALSE;
}
strcpy(osdir_path, path);
strcat(osdir_path, "/*"); // make a pattern to match all files
if (osdir_list_status != OSDIR_LIST_READY) {
osdir_list_finish(); // close previously interrupted listing
}
hFind = FindFirstFile(osdir_path, &FindFileData); // get the "."
if (hFind == INVALID_HANDLE_VALUE) return FALSE;
if (FindNextFile(hFind, &FindFileData) == 0) return FALSE; // get the ".."
osdir_list_status = OSDIR_LIST_STARTED;
return TRUE;
}
char *osdir_list_next()
{
if (FindNextFile(hFind, &FindFileData) == 0) {
osdir_list_status = OSDIR_LIST_DONE;
return NULL;
}
return FindFileData.cFileName;
}
void osdir_list_finish()
{
if (osdir_list_status != OSDIR_LIST_READY) {
FindClose(hFind);
}
osdir_list_status = OSDIR_LIST_READY;
}
/* xechoenabled -- set/clear echo_enabled flag (unix only) */
LVAL xechoenabled()
{
int flag = (xlgetarg() != NULL);
xllastarg();
// echo_enabled = flag; -- do nothing in Windows
return NULL;
}