home *** CD-ROM | disk | FTP | other *** search
- /* os_mac_command.c */
- /* 12Jul94 e */
-
- #include "os_mac.h"
- #include "os_mac_eventchk.h"
- #include <stdlib.h>
- #include <errno.h>
- #if defined(THINK_C)
- #include <console.h>
- #elif defined(__MWERKS__)
- #include <stdio.h>
- #include <string.h>
- #include <console.h>
- #endif
-
- /* "stolen" from Symantec... */
-
- /*
- * parse - divide command line into "words"
- *
- * Words are delimited by one or more spaces. Any characters within
- * matching single (') or double (") quotes are taken literally. Any
- * character preceded by a backslash (\) is taken literally.
- *
- */
-
- static int
- parse(unsigned char *s, unsigned char *t, unsigned char *argv[], int max_nargs)
- {
- int c, quote = 0, argc = 0;
-
- while( (c = *s++) != 0 ) {
- if (c <= ' ') // was ==
- continue;
- if (argc < max_nargs)
- argv[argc++] = t;
- do {
- if (c == '\\' && *s)
- c = *s++;
- else if (c == '"' || c == '\'') {
- if (!quote) {
- quote = c;
- continue;
- }
- if (c == quote) {
- quote = 0;
- continue;
- }
- }
- *t++ = c;
- } while (*s && ((c = *s++) > ' ' || quote)); // > was !=
- *t++ = 0;
- }
- return(argc);
- }
-
- #if defined(THINK_C)
- WindowPeek console;
- extern WindowPeek cflush(FILE *fp);
- #endif
-
- #if 0
- SysEnvRec sysenv;
- KeyMap kMap;
- long len;
- short err, i;
- short refNum;
-
- /* make sure System 6 or later is running */
- if ( GetTrapAddress(_SysEnvirons) == GetTrapAddress(_Unimplemented) )
- die("\ppfshell requires at least System 6");
- /* make sure it's a M68020+ and has an FPU */
- SysEnvirons( curSysEnvVers, &sysenv );
- if ( (sysenv.processor < env68020) || (!sysenv.hasFPU) )
- die("\ppfshell requires at least a M68020 and FPU");
- /* added this line for Soren/Quadra... 10Feb92 e */
- SetApplLimit((void *)(((long )&sysenv)-32768L-2000L));
- /* */
- #endif
-
- #define NARGS 255
-
- int
- ecommand(unsigned char ***av)
- {
- short i, argc;
- unsigned char buf[4096];
- unsigned char *argbuf;
- unsigned char *argv[NARGS+1];
-
- #if defined(THINK_C)
- console = cflush(stdout);
- #elif defined(__MWERKS__)
- fputs("? ", stdout);
- fflush(stdout);
- #else
- "unknown compiler"
- #endif
- // done in uio.c now: for (i=0; i<20; i++) os_event_check(); /* let any open apple events in */
- #if defined(THINK_C)
- fputs("? ", stdout);
- cflush(stdout);
- while ( ( i = os_console_read( console, buf, 4095 ) ) == 0 )
- os_event_check();
- #elif defined(__MWERKS__)
- fflush(stdout);
- while ( ( i = ReadCharsFromConsole( (char *)buf, 4095 ) ) == 0 )
- os_event_check();
- #else
- "unknown compiler"
- #endif
- buf[i] = 0;
- /* 18Dec94 e
- for ( argc = 0; argc < i; argc++ )
- if ( buf[argc] < ' ' ) buf[argc] = ' ';
- sprintf(buf, "%s", argbuf);
- */
- argbuf = (unsigned char *)NewPtr(i+1);
- if(argbuf)
- { argc = parse(buf, argbuf, argv, NARGS);
- *av = (unsigned char **)NewPtrClear(4+(argc<<2));
- if (*av)
- { errno = ((argc >= NARGS) ? -108 : 0); memcpy( *av, argv, argc<<2 ); }
- else
- errno = -108;
- }
- else
- { argc = 0;
- *av = 0;
- errno = -108;
- }
- return(argc);
- }
-
- /* end */
-