[683] | 1 | #include <SIOUX.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 | #include <string.h>
|
---|
| 5 | #include "unixmac.h"
|
---|
| 6 | #include "Files.h"
|
---|
| 7 | #include <LowMem.h>
|
---|
| 8 | #include "sys/time.h"
|
---|
| 9 | #include "console.h"
|
---|
| 10 |
|
---|
| 11 | int _wakeup = 0;
|
---|
| 12 | int macSleepTicks = 10;
|
---|
| 13 | int macRunTicks = 5;
|
---|
| 14 | static long int macLastTicks = 0;
|
---|
| 15 |
|
---|
| 16 | /*int utimes(char* fn, void*)
|
---|
| 17 | {
|
---|
| 18 | FileParam pb;
|
---|
| 19 | char pfn[256];
|
---|
| 20 | strncpy(pfn, fn, 255);
|
---|
| 21 | c2pstr(pfn);
|
---|
| 22 |
|
---|
| 23 | pb.ioCompletion = NULL;
|
---|
| 24 | pb.ioVRefNum = NULL;
|
---|
| 25 | pb.ioFVersNum = 0;
|
---|
| 26 | pb.ioFDirIndex = 0;
|
---|
| 27 | pb.ioNamePtr = (StringPtr) &pfn;
|
---|
| 28 |
|
---|
| 29 | PBGetFInfo((ParmBlkPtr)&pb, FALSE);
|
---|
| 30 |
|
---|
| 31 | GetDateTime(&(pb.ioFlMdDat));
|
---|
| 32 |
|
---|
| 33 | PBSetFInfo((ParmBlkPtr)&pb, FALSE);
|
---|
| 34 | return 0;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | */
|
---|
| 38 | /*
|
---|
| 39 | unsigned int sleep(unsigned int secs)
|
---|
| 40 | {
|
---|
| 41 | unsigned long int startTime, endTime, sleepTime, time;
|
---|
| 42 | EventRecord theEvent;
|
---|
| 43 | GetDateTime(&startTime);
|
---|
| 44 | endTime = startTime + secs;
|
---|
| 45 | time = startTime;
|
---|
| 46 | while ((time < endTime) && !_wakeup) {
|
---|
| 47 | sleepTime = 60 * (endTime - time);
|
---|
| 48 | if (WaitNextEvent(everyEvent, &theEvent,sleepTime,0))
|
---|
| 49 | SIOUXHandleOneEvent(&theEvent);
|
---|
| 50 | GetDateTime(&time);
|
---|
| 51 | }
|
---|
| 52 | return 0;
|
---|
| 53 | }
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | void yield()
|
---|
| 57 | {
|
---|
| 58 | EventRecord theEvent;
|
---|
| 59 | long int ticks = LMGetTicks();
|
---|
| 60 | if (ticks - macLastTicks >= macRunTicks) {
|
---|
| 61 | if (WaitNextEvent(everyEvent, &theEvent,macSleepTicks,0))
|
---|
| 62 | SIOUXHandleOneEvent(&theEvent);
|
---|
| 63 | macLastTicks = LMGetTicks();
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | pid_t fork()
|
---|
| 68 | {
|
---|
| 69 | return 0;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | int link(char*, char*) {return 0;}
|
---|
| 73 | char* sys_errlist[1];
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | void InitToolBox()
|
---|
| 77 | {
|
---|
| 78 | InitGraf(&qd.thePort); // Toolbox Managers
|
---|
| 79 | InitFonts();
|
---|
| 80 | InitWindows();
|
---|
| 81 | InitMenus();
|
---|
| 82 | TEInit();
|
---|
| 83 | InitDialogs(nil);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | #ifdef __mac__
|
---|
| 87 | #define SEP ':'
|
---|
| 88 | #else
|
---|
| 89 | #define SEP '/'
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
| 92 | char * basename(char * path)
|
---|
| 93 | {
|
---|
| 94 | char* p = path;
|
---|
| 95 | while (*p) p++;
|
---|
| 96 | while (p>=path && *p != SEP) p--;
|
---|
| 97 | p++;
|
---|
| 98 | return p;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | int kill(int , int ) {return 0;}
|
---|
| 102 |
|
---|
| 103 | int gettimeofday(struct timeval *tp, struct timezone */*tzp*/)
|
---|
| 104 | {
|
---|
| 105 | tp->tv_usec = 0;
|
---|
| 106 | tp->tv_sec = time(NULL);
|
---|
| 107 | return 0;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | #define MAX_ARGS 100
|
---|
| 111 |
|
---|
| 112 | static char argStr[65535];
|
---|
| 113 | static char *argv[MAX_ARGS + 1];
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | static int ParseArgs(char *s)
|
---|
| 117 | {
|
---|
| 118 | int n = 1, Quote = 0;
|
---|
| 119 | char *p = s, *p1, c;
|
---|
| 120 |
|
---|
| 121 | p1 = (char *) argStr;
|
---|
| 122 | while ((c = *p++) != 0) {
|
---|
| 123 | if (c==' ') continue;
|
---|
| 124 | argv[n++] = p1;
|
---|
| 125 | if (n > MAX_ARGS) /* mm 970404 */
|
---|
| 126 | return (n-1); /* mm 970404 */
|
---|
| 127 | do {
|
---|
| 128 | if (c=='\\' && *p++)
|
---|
| 129 | c = *p++;
|
---|
| 130 | else
|
---|
| 131 | if ((c=='"') || (c == '\'')) {
|
---|
| 132 | if (!Quote) {
|
---|
| 133 | Quote = c;
|
---|
| 134 | continue;
|
---|
| 135 | }
|
---|
| 136 | if (c == Quote) {
|
---|
| 137 | Quote = 0;
|
---|
| 138 | continue;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | *p1++ = c;
|
---|
| 142 | } while (*p && ((c = *p++) != ' ' || Quote));
|
---|
| 143 | *p1++ = 0;
|
---|
| 144 |
|
---|
| 145 | }
|
---|
| 146 | return n;
|
---|
| 147 |
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | int xccommand(char ***arg)
|
---|
| 151 | {
|
---|
| 152 | long len;
|
---|
| 153 | char* argument;
|
---|
| 154 | int n = ccommand(arg);
|
---|
| 155 | if (n==1 && (*arg)[1][0] == '@') {
|
---|
| 156 | FILE* f = fopen((*arg)[1]+1,"r");
|
---|
| 157 | fseek(f, 0, SEEK_END);
|
---|
| 158 | len = ftell(f);
|
---|
| 159 | fseek(f, 0, SEEK_SET);
|
---|
| 160 | argument = (char*) malloc(len+1);
|
---|
| 161 | fread(argument, 1, len, f);
|
---|
| 162 | n = ParseArgs(argument);
|
---|
| 163 | }
|
---|
| 164 | return n;
|
---|
| 165 | }
|
---|
| 166 |
|
---|