123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160 |
- From jpff@maths.bath.ac.uk Sat Apr 24 23:37:05 1999
- Date: Sat, 24 Apr 99 22:35:07 BST
- From: jpff@maths.bath.ac.uk
- To: acn1@cam.ac.uk
- Subject: sysstmac.c
- Message written at 24 Apr 1999 17:21:34 +0100
- This is a better sysstmac.c. I still need to deal with the help
- system, but the dialogs are greatly improved in this version.
- ==John
- ------------------------------------------------------------------------
- #include "machine.h"
- #include <stdarg.h>
- #include <stddef.h>
- #include <string.h>
- #include <ctype.h>
- #include "tags.h"
- #include "externs.h"
- #include <unix.h>
- #include <files.h>
- #include <unix.h>
- #include <retrace.h>
- #include <timer.h>
- #include <ansi_private.h>
- #include "macwin.h"
- #include <Dialogs.h>
- #undef nil
- int get_home_directory(char *b, int length);
- int get_users_home_directory(char *b, int length);
- #include "filename.c"
- char *get_truename(char *filename, char *old, size_t n)
- {
- char *w;
- process_file_name(filename, old, n);
- if (*filename == 0)
- { aerror("truename");
- return NULL;
- }
- w = (char *)malloc(1+strlen(filename));
- if (w == NULL) return w;
- strcpy(w, filename);
- return w;
- }
- CSLbool file_exists(char *filename, char *old, size_t n, char *tt)
- {
- FileParam pb;
- char buf[FILENAME_MAX];
-
- process_file_name(filename, old, n);
- pb.ioNamePtr = __c2p((const char*)filename, buf);
- pb.ioFRefNum = 0;
- pb.ioFVersNum = 0;
- pb.ioFDirIndex = 0;
- if (PBGetFInfo((ParmBlkPtr)&pb, 0) != noErr) return NO;
- strcpy(tt, ctime(&(pb.ioFlMdDat)));
- return YES;
- }
-
- char *my_getenv(char *s)
- {
- return getenv(s);
- }
- int
- myexec(char *filename, ...)
- {
- int i;
- short ans;
- EventRecord event;
- #if 1
- FSSpec fsp;
- LaunchParamBlockRec lpb;
-
- C2PStr(filename);
- ans = FSMakeFSSpec( 0,0,(unsigned char*)filename,&fsp);
- P2CStr((unsigned char*)filename);
- if (!ans) {
- lpb.launchBlockID = extendedBlock;
- lpb.launchEPBLength = extendedBlockLen;
- lpb.launchFileFlags = 0;
- lpb.launchControlFlags = launchContinue + launchNoFileFlags;
- lpb.launchAppSpec = &fsp;
- lpb.launchAppParameters = 0;
- ans = LaunchApplication(&lpb);
- }
- #else
- static struct {
- unsigned char *name;
- short memuse;
- char lc[2];
- long extBlocLen;
- short fFlags;
- long launchFlags;
- } buf;
- unsigned char pname[255];
- extern void _Launch();
- buf.name = __c2p(filename, (char *)pname);
- buf.memuse = 0;
- buf.lc[0] = 'L'; buf.lc[1] = 'C';
- buf.extBlocLen = 6;
- buf.fFlags = 128;
- buf.launchFlags = 0xC0000000;
- asm {
- lea buf,a0
- dc.w _Launch
- move.w d0,ans;
- }
- #endif
- if (ans==0)
- for (i=0; i<20; i++) WaitNextEvent(everyEvent, &event, 10, 0L);
- return ans;
- }
- int my_system(char *s)
- {
- return myexec(s);
- }
- void my_pclose(FILE *a)
- {
- return;
- }
- int create_directory(char *filename, char *old, size_t n)
- {
- process_file_name(filename, old, n);
- if (*filename==0) return 1;
- return 1;
- }
- int delete_file(char *filename, char *old, size_t n)
- {
- process_file_name(filename, old, n);
- if (*filename==0) return 1;
- return remove(filename);
- }
- int get_home_directory(char *b, int length)
- {
- char *w = my_getenv("home");
- if (w != NULL) strcpy(b, w);
- else
- strcpy(b, ":");
- return strlen(b);
- }
- static int get_users_home_directory(char *b, int length)
- {
- char *w, h[LONGEST_LEGAL_FILENAME];
- sprintf(h, "home$%s", b);
- w = my_getenv(h);
- if (w != NULL) strcpy(b, w);
- else
- strcpy(b, ":");
- return strlen(b);
- }
- int batchp(void)
- {
- return !isatty(fileno(stdin));
- }
- char *find_image_directory(int argc, char *argv[])
- {
- char image[LONGEST_LEGAL_FILENAME];
- char pgmname[LONGEST_LEGAL_FILENAME];
- char *w;
- WDPBRec pb1;
- CInfoPBRec pb2;
- int i, j, r, p = LONGEST_LEGAL_FILENAME;
- long id;
- pgmname[--p] = 0;
-
- sprintf(image, "%#s", LMGetCurApName());
- strcpy(program_name, image);
- i = strlen(image);
- strcpy(image+i, " Image");
- i += 6;
- p -= i;
- memcpy(&pgmname[p], image, i);
- pb1.ioNamePtr = (unsigned char *)image;
- PBHGetVolSync(&pb1);
- id = pb1.ioWDDirID;
- while (id != 0) {
- pb2.dirInfo.ioFDirIndex = -1;
- pb2.dirInfo.ioVRefNum = pb1.ioVRefNum;
- pb2.dirInfo.ioDrDirID = id;
- pb2.dirInfo.ioNamePtr = (unsigned char *)image;
- r = PBGetCatInfoSync(&pb2);
- if (r != 0) break;
- id = pb2.dirInfo.ioDrParID;
- i = image[0] & 0xff;
- pgmname[--p] = ':';
- p -= i;
- if (p < 10) {
- fprintf(stderr, "\nPlease re-install this package nearer the top of\n");
- fprintf(stderr, "your directory hierarchy. It will not work this far down\n");
- abort();
- }
- memcpy(&pgmname[p], &image[1], i);
- }
- strcpy(image, &pgmname[p]);
- w = (char *)malloc(1+strlen(&pgmname[p]));
- if (w == NULL)
- { fprintf(stderr, "\n+++ Panic - run out of space\n");
- exit(EXIT_FAILURE);
- }
- strcpy(w, &pgmname[p]);
- return w;
- }
- int truncate_file(FILE *f, long int where)
- {
- short a;
- short ff = f->refnum;
- if (fflush(f) != 0) return 1;
- a = SetEOF(ff, where);
- return (int)a;
- }
- static CSLbool ticker_active = NO;
- int32 software_ticks = INITIAL_SOFTWARE_TICKS;
- int32 software_tick_count = 0, prev_software_tick_count = 0;
- void add_ticker(void)
- {
- if (ticker_active) return;
- if (countdown<0) countdown = SOFTWARE_TICKS;
- ticker_active = YES;
- }
- void remove_ticker(void)
- {
-
- ticker_active = NO;
- }
- int file_readable(char *filename, char *old, size_t n)
- {
- FILE *fp;
- process_file_name(filename, old, n);
- if (*filename == 0) return 0;
-
- fp = fopen(filename,"r");
- if (fp == NULL) return 0;
- else
- { fclose(fp);
- return 1;
- }
- }
- int file_writeable(char *filename, char *old, size_t n)
- {
- FILE *fp;
- process_file_name(filename, old, n);
- if (*filename == 0) return 0;
- fp = fopen(filename,"a");
- if (fp == NULL) return 0;
- else
- { fclose(fp);
- return 1;
- }
- }
- int rename_file(char *from_name, char *from_old, size_t from_size,
- char *to_name, char *to_old, size_t to_size)
- {
- process_file_name(from_name, from_old, from_size);
- process_file_name(to_name, to_old, to_size);
- if (*from_name == 0 || *to_name == 0) return 0;
- return rename(from_name,to_name);
- }
- int change_directory(char *filename, char *old, size_t n)
- {
- WDPBRec P;
- Str255 pname;
- process_file_name(filename, old, n);
- if (*filename==0) return 1;
- strcpy((char*)pname, filename);
- C2PStr((char*)pname);
- P.ioNamePtr = pname;
- return PBHSetVol(&P, 0);
- }
- int directoryp(char *filename, char *old, size_t n)
- {
- struct stat statrec;
- process_file_name(filename, old, n);
- stat(filename, &statrec);
- return S_ISDIR(statrec.st_mode);
- }
- int get_current_directory(char *s, int n)
- {
- return 0;
- }
- #include "scandir.c"
- void list_directory_members(char *filename, char *old,
- size_t n, directory_callback *fn)
- {
- process_file_name(filename, old, n);
- scan_files(filename, fn);
- }
- #include "stdwin.h"
- #include "tools.h"
- #include "editwin.h"
- #include "text.h"
- static WINDOW *CSL_window;
- static EDITWIN *CSL_ew;
- static EDITWIN *help_ew;
- int max_nlines = 250;
- #ifndef HELP_DATA
- #define HELP_DATA "help.data"
- #endif
- #ifndef HELP_INDEX
- #define HELP_INDEX "help.index"
- #endif
- static MENU *adminmenu;
- static MENU *editmenu;
- static MENU *loadmenu;
- static MENU *libmenu;
- static MENU *switchmenu;
- static MENU *helpmenu;
- #define ADMIN_MENU (1001)
- #define MMFile 0
- #define MMSaveas 1
- #define MMHelp 2
- #define MMHelpSel 3
- #define MMHelpAsk 4
- #define MMInt 5
- #define MMAbort 6
- #define MMPause 7
- #define MMDummy 8
- #define MMTime 9
- #define MMSpace 10
- #define MMOTime 11
- #define EDIT_MENU (1002)
- #define MMCut 0
- #define MMCopy 1
- #define MMPaste 2
- #define MMClear 3
- #define MMSelAll 4
- #define HELP_LEN (36)
- #define HELP_MENU (1003)
- static struct hlp {
- char name[HELP_LEN];
- long offset;
- int length;
- } *hlp;
- int help_length;
- int helpstamp;
- #define LOAD_MENU (1004)
- static char *loads[] = {
- (char*)NULL};
- #define LIB_MENU (1005)
- static char *libraries[] = {
- (char*)NULL};
- #define SWITCH_MENU (1006)
- static struct sw {
- char *name;
- int state;
- } switches[] = {
- {(char*)NULL, 0}};
- get_full_name(char *name, FSSpec *spec)
- {
- char nn[LONGEST_LEGAL_FILENAME];
- char mm[LONGEST_LEGAL_FILENAME];
- char *w;
- int i, r;
- int p = LONGEST_LEGAL_FILENAME;
- long id;
- CInfoPBRec pb2;
- nn[--p] = 0;
- i = spec->name[0];
- p -= i;
- memcpy(&nn[p], &(spec->name[1]), i);
- id = spec->parID;
- while (id != 0) {
- pb2.dirInfo.ioFDirIndex = -1;
- pb2.dirInfo.ioVRefNum = spec->vRefNum;
- pb2.dirInfo.ioDrDirID = id;
- pb2.dirInfo.ioNamePtr = (unsigned char *)mm;
- if (PBGetCatInfoSync(&pb2)) break;
-
- id = pb2.dirInfo.ioDrParID;
- i = mm[0] & 0xff;
- nn[--p] = ':';
- p -= i;
- if (p < 10) {
- fprintf(stderr, "\nCannot access file so far from root\n");
- strcpy(name, "");
- return FALSE;
- }
- memcpy(&nn[p], &mm[1], i);
- }
- strcpy(name, &nn[p]);
- return TRUE;
- }
- static void menusetup(void)
- {
- MENU *mp;
- int i;
- adminmenu= mp= wmenucreate(ADMIN_MENU, "Admin");
-
- wmenuadditem(mp, "Input file...", 'F');
- wmenuadditem(mp, "Saveas...", -1);
- wmenuadditem(mp, "Help Window", 'H');
- wmenuadditem(mp, "Help Selection", 'S');
- wmenuadditem(mp, "Help Topic...", -1);
- wmenuadditem(mp, "Interrupt", 'I');
- wmenuadditem(mp, "Quit", 'Q');
- wmenuadditem(mp, "Pause", 'P');
- wmenuadditem(mp, "---------", -1);
- wmenuadditem(mp, "0.00", -1);
- wmenuadditem(mp, "[GC 0]", -1);
- wmenuadditem(mp, "", -1);
- wmenuadditem(mp, "", -1);
- wmenuenable(mp, MMDummy, NO);
- wmenuenable(mp, MMTime, NO);
- wmenuenable(mp, MMSpace, NO);
- wmenuenable(mp, MMOTime, NO);
- editmenu= mp= wmenucreate(EDIT_MENU, "Edit");
- wmenuadditem(mp, "Cut", 'X');
- wmenuadditem(mp, "Copy", 'C');
- wmenuadditem(mp, "Paste", 'V');
- wmenuadditem(mp, "Clear", 'B');
- wmenuadditem(mp, "Select All", 'A');
-
- helpmenu = mp = (MENU*)GetMenu(HELP_MENU);
- if (mp != 0)
- InsertMenu((MenuHandle)mp, 0); DrawMenuBar();
- {
- FILE* hlpindx = fopen(HELP_INDEX, "r");
- if (hlpindx != NULL) {
- fscanf(hlpindx, "%d\n", &helpstamp);
- fscanf(hlpindx, "%d", &help_length);
- hlp = (struct hlp*) calloc(1+help_length, sizeof(struct hlp));
- if (hlp == NULL) {
- help_length = 0;
- goto loader;
- }
- for (i=0; i<help_length; i++) {
- int ch, p=0;
- fscanf(hlpindx, "%d %d ", &(hlp[i].offset), &(hlp[i].length));
- while (p<HELP_LEN-1) {
- ch = getc(hlpindx);
- if (ch == '\n') break;
- hlp[i].name[p++] = ch;
- }
- while (ch != '\n') ch = getc(hlpindx);
- hlp[i].name[p] = '\0';
-
- }
- fclose(hlpindx);
- }
- else {
- help_length = 0;
- strcpy(hlp[0].name, "No help");
- hlp[0].offset = -1;
- hlp[0].length = 0;
- }
- }
- loader:
- loadmenu= mp= wmenucreate(LOAD_MENU, "Load");
- for (i=0; loads[i]!= NULL; i++)
- wmenuadditem(mp, loads[i], -1);
- libmenu= mp= wmenucreate(LIB_MENU, "Library");
- for (i=0; libraries[i]!= NULL; i++)
- wmenuadditem(mp, libraries[i], -1);
- switchmenu= mp= wmenucreate(SWITCH_MENU, "Switch");
- for (i=0; switches[i].name!= NULL; i++) {
- wmenuadditem(mp, switches[i].name, -1);
- wmenucheck(mp, i, switches[i].state);
- }
- }
- static void fixmenus(void)
- {
- CSLbool focus;
- focus= (CSL_ew->tp->foclen != 0);
- wmenuenable(editmenu, MMCut, focus);
- wmenuenable(editmenu, MMCopy, focus);
- wmenuenable(editmenu, MMClear, focus);
- wmenuenable(adminmenu, MMHelpSel, focus);
- if (help_ew != NULL) {
- focus= (help_ew->tp->foclen != 0);
- if (focus) {
- wmenuenable(editmenu, MMCut, focus);
- wmenuenable(editmenu, MMCopy, focus);
- wmenuenable(editmenu, MMClear, focus);
- wmenuenable(adminmenu, MMHelpSel, focus);
- }
- }
- }
- #define TTYBUF_SIZE 256
- static char tty_buff[TTYBUF_SIZE];
- static int tty_index = 0;
- static CSLbool tty_ready = NO;
- static int tty_nnl = 0;
- static int tty_offset;
- #define STDOUT_BUFSIZE 1024
- #define LONGEST_PRINTF 120
- static char stdout_buffer[STDOUT_BUFSIZE];
- static char *stdout_p;
- static int stdout_n;
- extern int _w_font;
- void start_up_window_manager(int use_wimp)
- {
- int CSL_width, CSL_height;
- _w_font = 4;
- menusetup();
- wsetdefwinsize(82*wcharwidth('0'), 25*wlineheight());
- CSL_ew = ewcreate(NULL);
- CSL_window = CSL_ew->win;
- wsettitle(CSL_window, "Reduce 3.7");
- fixmenus();
- wmenuenable(editmenu, MMTime, NO);
- wmenuenable(editmenu, MMOTime, NO);
- wmenuenable(editmenu, MMSpace, NO);
- wmenudetach(CSL_window, loadmenu);
- wmenudetach(CSL_window, libmenu);
- wmenudetach(CSL_window, switchmenu);
- stdout_n = 0;
- stdout_p = stdout_buffer;
- help_ew = NULL;
- }
- static char *help_buff;
- CSLbool
- helpwindow(int index)
- {
- FILE* help = fopen(HELP_DATA, "r");
- int ch;
- int width, height;
- int size = hlp[index].length;
- if (help == NULL) return FALSE;
- fscanf(help, "%d\n", &ch);
- if (ch != helpstamp) return FALSE;
- fseek(help, hlp[index].offset, SEEK_SET);
- if (help_ew) {
- free(help_buff);
- tesetfocus(help_ew->tp, 0, tegetlen(help_ew->tp));
- ewreplace(help_ew, "");
- }
- else {
- help_ew = ewcreate(NULL);
- wsettitle(help_ew->win, "Help for Reduce 3.7");
- }
- help_buff = malloc(size+1);
- if (help_buff == NULL) {
- dprintf("Insufficient memory");
- wfleep();
- return FALSE;
- }
- fread(help_buff, size, 1, help);
- help_buff[size] = '\0';
- wmenudetach(help_ew->win, loadmenu);
- wmenudetach(help_ew->win, libmenu);
- wmenudetach(help_ew->win, switchmenu);
- ewreplace(help_ew, help_buff);
- tesetfocus(help_ew->tp, 0, 0);
- fclose(help);
- return TRUE;
- }
- void help_buffer(char *buf, int len)
- {
- int i;
- for (i=0; i<help_length; i++) {
-
- if (strncmp(hlp[i].name, buf, len) == 0) {
- helpwindow(i);
- break;
- }
- }
- if (i == help_length) wfleep();
- }
- void help_selection(EDITWIN *ew)
- {
- int i;
- char *text;
- TEXTEDIT *tp = ew->tp;
- if (tp->foclen == 0) {
- wfleep();
- return;
- }
- text= tegettext(tp);
- help_buffer(text+tp->foc, tp->foclen);
- }
- extern int pause_set = 0;
- void event_loop(void)
- {
- for (;;) {
- EVENT e;
- EDITWIN *ew;
- CSLbool closed;
-
- wgetevent(&e);
-
- ew= ewfind(e.window);
- if (ew == CSL_ew) {
- switch (e.type) {
- case WE_CHAR:
- switch(e.u.character) {
- case 'A'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- tesetfocus(tp,
- zsubgap(tp->start[tewhichline(tp,
- zaddgap(tp->foc),
- tp->focprev)]),
- -1);
- break;
- }
- case 'B'-'@':
- tearrow(CSL_ew->tp, WC_LEFT);
- break;
- case 127:
- case 'D'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- tearrow(tp, WC_RIGHT);
- {
- int f1 = tp->foc;
- int i;
- int ss = tp->start[tp->nlines-tty_nnl];
- int ee = ss + tty_offset;
- if (ss <= f1 && f1 < ee) {
- if (tty_offset>0) tty_offset--;
- }
- e.type = WE_COMMAND;
- e.u.command = WC_BACKSPACE;
- ewevent(ew,&e, NULL);
- break;
- }
- }
- case 'E'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
- int xxx = zsubgap(tetextround(tp, line, tp->right));
- tesetfocus(tp, xxx, -1);
- break;
- }
- case 'F'-'@':
- tearrow(CSL_ew->tp, WC_RIGHT);
- break;
- case 'K'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int f1;
- int i;
- int ss;
- int ee;
- tesetfocus(tp,
- tp->foc,
- zsubgap(tetextround(tp,
- tewhichline(tp, zaddgap(tp->foc),
- tp->focprev),
- tp->right)));
- f1 = tp->foc;
- ss = tp->start[tp->nlines-tty_nnl];
- ee = ss + tty_offset;
- for (i=0; i<tp->foclen; i++)
- if (ss <= f1+i && f1+i < ee) {
- if (tty_offset>0) tty_offset--;
- }
- ewreplace(ew, "");
- break;
- }
- case 'N'-'@':
- tearrow(CSL_ew->tp, WC_DOWN);
- break;
- case 'P'-'@':
- tearrow(CSL_ew->tp, WC_UP);
- break;
- case 'Z'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- break;
- }
- default:
- ewevent(ew, &e, &closed);
- if (tty_ready == YES && !pause_set) return;
- }
- break;
- case WE_COMMAND:
- switch (e.u.command) {
- case WC_CANCEL:
- interrupt_pending = YES;
- break;
- case WC_CLOSE:
- pause_for_user();
- exit(1);
- case WC_RETURN:
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int f1 = zaddgap(tp->foc);
- int ee = tp->start[tp->nlines-tty_nnl] + tty_offset;
- if (f1 >= ee) {
- tty_nnl++;
- if (f1 == tp->buflen) {
- ewevent(ew, &e, &closed);
- tty_ready = YES;
- if (!pause_set) return;
- }
- }
- }
- break;
- case WC_DEL:
- case WC_BACKSPACE:
-
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int f1 = tp->foc;
- int i;
- int ss = tp->start[tp->nlines-tty_nnl];
- int ee = ss + tty_offset;
- if (tp->foclen == 0) {
- if (ss < f1 && f1 <= ee && tty_offset>0) tty_offset--;
- }
- else {
- for (i=0; i<tp->foclen; i++) {
- if (ss <= f1+i && f1+i < ee && tty_offset>0) tty_offset--;
- }
- }
- }
- break;
- case WC_LEFT:
- case WC_RIGHT:
- default:
- break;
- }
- ewevent(ew, &e, &closed);
- break;
- case WE_MENU:
- switch (e.u.m.id) {
- case ADMIN_MENU:
- switch (e.u.m.item) {
- case MMFile:
- {
- short wd;
- TEXTEDIT *tp = CSL_ew->tp;
- struct StandardFileReply sfr;
- StandardGetFile(NULL, -1, NULL, &sfr);
- if (sfr.sfGood && !sfr.sfIsFolder && !sfr.sfIsVolume) {
- char name[256];
- if (!get_full_name(name, &(sfr.sfFile))) break;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- ewreplace(CSL_ew, "in \"");
- ewreplace(CSL_ew, name);
- ewreplace(CSL_ew, "\"");
-
- }
- break;
- }
- case MMSaveas:
- ewsaveas(CSL_ew);
- break;
- case MMHelp:
- helpwindow(0);
- break;
- case MMHelpSel:
- help_selection(ew);
- break;
- case MMHelpAsk:
- {
- char buf[40];
- int len;
- if (waskstr("Help on topic", buf, 40)) {
- len = strlen(buf);
- help_buffer(buf, len);
- }
- }
- break;
- case MMAbort:
- pause_for_user();
- exit(1);
- case MMInt:
- interrupt_pending = YES;
- return;
- case MMPause:
- pause_set = !pause_set;
- wmenucheck(adminmenu, MMPause, pause_set);
- if (pause_set) wsettitle(CSL_window, "<Paused> Reduce 3.7");
- else wsettitle(CSL_window, "Reduce 3.7");
- break;
- }
- break;
- case EDIT_MENU:
- switch (e.u.m.item) {
- case MMCopy:
- ewcopy(ew);
- break;
- case MMPaste:
- {
- char* text = wgetclip();
- char* tt = text;
- int valid = YES;
- if (text == NULL) wfleep();
- else {
- TEXTEDIT *tp = CSL_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- while (*tt != '\0')
- if (*tt++=='\n') valid = NO;
- if (valid) ewreplace(ew, text);
- else
- Alert(129, NULL);
- }
- }
- break;
- case MMCut:
- ewcopy(ew);
- case MMClear:
-
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int f1 = tp->foc;
- int i;
- int ss = tp->start[tp->nlines-tty_nnl];
- int ee = ss + tty_offset;
- for (i=0; i<tp->foclen; i++)
- if (ss <= f1+i && f1+i < ee) {
- if (tty_offset>0) tty_offset--;
- }
- }
- ewreplace(ew, "");
- break;
- case MMSelAll:
- tesetfocus(ew->tp, 0, tegetlen(ew->tp));
- break;
- }
- break;
- case LOAD_MENU:
- {
- char *load = "load_package ";
- char *tt = loads[e.u.m.item];
- TEXTEDIT *tp = CSL_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- tp->aim= UNDEF;
- tp->focprev= FALSE;
- ewreplace(CSL_ew, load);
- ewreplace(CSL_ew, tt);
- tty_ready = YES;
- ewreplace(CSL_ew, ";\n");
- tty_nnl++;
- wmenuenable(loadmenu, e.u.m.item, NO);
- return;
- }
- case LIB_MENU:
- {
- char *load = "load_package ";
- char *tt = libraries[e.u.m.item];
- TEXTEDIT *tp = CSL_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- tp->aim= UNDEF;
- tp->focprev= FALSE;
- ewreplace(CSL_ew, load);
- ewreplace(CSL_ew, tt);
- tty_ready = YES;
- ewreplace(CSL_ew, ";\n");
- tty_nnl++;
- wmenuenable(loadmenu, e.u.m.item, NO);
- return;
- }
- case SWITCH_MENU:
- {
- char *load = (switches[e.u.m.item].state ? "off " : "on ");
- char *tt = switches[e.u.m.item].name;
- TEXTEDIT *tp = CSL_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- ewreplace(CSL_ew, load);
- ewreplace(CSL_ew, tt);
- tty_ready = YES;
- ewreplace(CSL_ew, ";\n");
- tty_nnl++;
- switches[e.u.m.item].state = ~ switches[e.u.m.item].state;
- wmenucheck(switchmenu, e.u.m.item, switches[e.u.m.item].state);
- return;
- }
- case HELP_MENU:
- helpwindow(e.u.m.item);
- break;
- }
- break;
- case WE_CLOSE:
- pause_for_user();
- exit(1);
- default:
- ewevent(ew, &e, &closed);
- break;
- }
- }
- else if (ew == help_ew) {
-
- switch (e.type) {
- case WE_MOUSE_UP:
- if (!ew->tp->mdown) break;
- ew->tp->mdown= FALSE;
- if (e.u.where.clicks > 1) {
- teclicknew(ew->tp, e.u.where.h, e.u.where.v, FALSE, TRUE);
- help_selection(ew);
- }
- break;
- case WE_CHAR:
- switch(e.u.character) {
- case 'A'-'@':
- {
- TEXTEDIT* tp = help_ew->tp;
- tesetfocus(tp,
- zsubgap(tp->start[tewhichline(tp,
- zaddgap(tp->foc),
- tp->focprev)]),
- -1);
- break;
- }
- case 'B'-'@':
- tearrow(help_ew->tp, WC_LEFT);
- break;
- case 'E'-'@':
- {
- TEXTEDIT* tp = help_ew->tp;
- int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
- int xxx = zsubgap(tetextround(tp, line, tp->right));
- tesetfocus(tp, xxx, -1);
- break;
- }
- case 'F'-'@':
- tearrow(help_ew->tp, WC_RIGHT);
- break;
- case 'K'-'@':
- {
- int i;
- int j;
- wgetdefwinsize(&i, &j);
- j = j/wlineheight() -1;
- for (i=0; i<j; i++) tearrow(help_ew->tp, WC_UP);
- break;
- }
- case 'N'-'@':
- tearrow(help_ew->tp, WC_DOWN);
- break;
- case 'P'-'@':
- tearrow(help_ew->tp, WC_UP);
- break;
- case 'Z'-'@':
- {
- TEXTEDIT* tp = help_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- break;
- }
- case 'V'-'@':
- case ' ':
- case 'L'-'@':
- {
- int i;
- int j;
- wgetdefwinsize(&i, &j);
- j = j/wlineheight() -1;
- for (i=0; i<j; i++) tearrow(help_ew->tp, WC_DOWN);
- break;
- }
- case 'i':
- case 'I':
- {
- char buf[40];
- int len;
- if (waskstr("Help on topic", buf, 40)) {
- len = strlen(buf);
- help_buffer(buf, len);
- }
- break;
- }
- case 'n':
- case 'N':
- {
- extern char *strstr(const char*, const char*);
- char *p = strstr((const char*)help_buff, (const char*)"Next: ");
- int i = 0;
- if (p == NULL) {
- wfleep(); break;
- }
- p += 6;
- while (p[i]!= ',') i++;
- help_buffer(p,i);
- break;
- }
- case 'p':
- case 'P':
- {
- extern char *strstr(const char*, const char*);
- char *p = strstr((const char*)help_buff, "Prev: ");
- int i = 0;
- if (p == NULL) {
- wfleep(); break;
- }
- p += 6;
- while (p[i]!= ',') i++;
- help_buffer(p,i);
- break;
- }
- case 'q':
- case 'Q':
- help_ew->saved = TRUE;
- free(help_buff);
- ewclose(help_ew);
- help_ew = 0;
- break;
- case 'u':
- case 'U':
- {
- extern char *strstr(const char*, const char*);
- char *p = strstr((const char*)help_buff, "Up: ");
- int i = 0;
- if (p == NULL) {
- wfleep(); break;
- }
- p += 4;
- while (p[i]!= '\n') i++;
- help_buffer(p,i);
- break;
- }
- }
- break;
- case WE_MENU:
- switch (e.u.m.id) {
- case ADMIN_MENU:
- switch (e.u.m.item) {
- case MMSaveas:
- ewsaveas(help_ew);
- break;
- case MMHelp:
- if (help_length) helpwindow(0);
- break;
- case MMHelpSel:
- help_selection(ew);
- break;
- case MMHelpAsk:
- {
- char buf[40];
- int len;
- if (waskstr("Help on topic", buf, 40)) {
- len = strlen(buf);
- help_buffer(buf, len);
- }
- break;
- }
- case MMAbort:
- help_ew->saved = TRUE;
- free(help_buff);
- ewclose(help_ew);
- help_ew = 0;
- break;
- }
- break;
- case EDIT_MENU:
- switch (e.u.m.item) {
- case MMCopy:
- ewcopy(ew);
- break;
- case MMSelAll:
- tesetfocus(ew->tp, 0, tegetlen(ew->tp));
- break;
- }
- break;
- case HELP_MENU:
- helpwindow(e.u.m.item);
- break;
- }
- break;
- case WE_COMMAND:
- switch (e.u.command) {
- case WC_CANCEL:
- interrupt_pending=YES;
- break;
- case WC_RETURN:
- help_selection(ew);
- break;
- case WC_DEL:
- case WC_BACKSPACE:
- helpwindow(0);
- break;
- default:
- ewevent(ew, &e, &closed);
- break;
- }
- if (e.u.command != WC_CLOSE) {
- break;
- }
- case WE_CLOSE:
- help_ew->saved = TRUE;
- free(help_buff);
- ewclose(help_ew);
- help_ew = 0;
- break;
- default:
- ewevent(ew, &e, &closed);
- if (closed) {
- help_ew->saved = TRUE;
- free(help_buff);
- ewclose(help_ew);
- help_ew = 0;
- }
- break;
- }
- }
- else if (ew != NULL) ewevent(ew, &e, &closed);
- else wfleep();
- fixmenus();
- }
- }
- void poll_for_attn(void)
- {
- for (;;) {
- EVENT e;
- EDITWIN *ew;
- CSLbool closed;
- if (!pause_set) {
- if (!wpollevent(&e)) return;
- }
- else wgetevent(&e);
-
- ew= ewfind(e.window);
- if (ew == CSL_ew) {
- switch (e.type) {
- case WE_CHAR:
- switch(e.u.character) {
- case 'A'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- tesetfocus(tp,
- zsubgap(tp->start[tewhichline(tp,
- zaddgap(tp->foc),
- tp->focprev)]),
- -1);
- break;
- }
- case 'B'-'@':
- tearrow(CSL_ew->tp, WC_LEFT);
- break;
- case 'D'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- tearrow(tp, WC_RIGHT);
- e.type = WE_COMMAND;
- e.u.command = WC_BACKSPACE;
- ewevent(ew,&e, NULL);
- break;
- }
- case 'E'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
- int xxx = zsubgap(tetextround(tp, line, tp->right));
- tesetfocus(tp, xxx, -1);
- break;
- }
- case 'F'-'@':
- tearrow(CSL_ew->tp, WC_RIGHT);
- break;
- case 'K'-'@':
- tty_index = 0;
- break;
- case 'N'-'@':
- tearrow(CSL_ew->tp, WC_DOWN);
- break;
- case 'P'-'@':
- tearrow(CSL_ew->tp, WC_UP);
- break;
- case 'Z'-'@':
- {
- TEXTEDIT* tp = CSL_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- break;
- }
- case 'V'-'@':
- case ' ':
- {
- int i;
- int j;
- wgetdefwinsize(&i, &j);
- j = j/wlineheight() -1;
- for (i=0; i<j; i++) tearrow(help_ew->tp, WC_DOWN);
- break;
- }
- default:
- if (tty_index > TTYBUF_SIZE-2) wfleep();
- else tty_buff[tty_index++] = e.u.character;
- break;
- }
- break;
- case WE_COMMAND:
- switch (e.u.command) {
- case WC_CANCEL:
- interrupt_pending = YES;
- break;
- case WC_CLOSE:
- pause_for_user();
- exit(1);
- case WC_RETURN:
- if (tty_index > TTYBUF_SIZE-2) wfleep();
- else tty_buff[tty_index++] = '\n';
- break;
- case WC_TAB:
- if (tty_index > TTYBUF_SIZE-2) wfleep();
- else tty_buff[tty_index++] = '\t';
- break;
- case WC_DEL:
- case WC_BACKSPACE:
- if (tty_index>0) tty_index--;
- break;
- }
- break;
- case WE_MENU:
- switch (e.u.m.id) {
- case ADMIN_MENU:
- switch (e.u.m.item) {
- case MMHelp:
- helpwindow(0);
- break;
- case MMHelpSel:
- help_selection(ew);
- break;
- case MMAbort:
- pause_for_user();
- exit(1);
- case MMInt:
- interrupt_pending = YES;
- return;
- case MMPause:
- pause_set = !pause_set;
- wmenucheck(adminmenu, MMPause, pause_set);
- if (pause_set) wsettitle(CSL_window, "<Paused> Reduce 3.7");
- else wsettitle(CSL_window, "Reduce 3.7");
- break;
- }
- break;
- case EDIT_MENU:
- switch (e.u.m.item) {
- case MMCopy:
- ewcopy(ew);
- break;
- case MMPaste:
- break;
- case MMCut:
- ewcopy(ew);
- case MMClear:
- ewreplace(ew, "");
- break;
- case MMSelAll:
- tesetfocus(ew->tp, 0, tegetlen(ew->tp));
- break;
- }
- break;
- case HELP_MENU:
- helpwindow(e.u.m.item);
- break;
- }
- break;
- case WE_CLOSE:
- pause_for_user();
- exit(1);
- default:
- ewevent(ew, &e, &closed);
- break;
- }
- }
- else if (ew == help_ew) {
- switch (e.type) {
- case WE_MOUSE_UP:
- if (!ew->tp->mdown)
- break;
- ew->tp->mdown= FALSE;
- if (e.u.where.clicks > 1) {
- teclicknew(ew->tp, e.u.where.h, e.u.where.v, FALSE, TRUE);
- help_selection(ew);
- }
- break;
- case WE_CHAR:
- switch(e.u.character) {
- case 'A'-'@':
- {
- TEXTEDIT* tp = help_ew->tp;
- tesetfocus(tp,
- zsubgap(tp->start[tewhichline(tp,
- zaddgap(tp->foc),
- tp->focprev)]),
- -1);
- break;
- }
- case 'B'-'@':
- tearrow(help_ew->tp, WC_LEFT);
- break;
- case 'E'-'@':
- {
- TEXTEDIT* tp = help_ew->tp;
- int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
- int xxx = zsubgap(tetextround(tp, line, tp->right));
- tesetfocus(tp, xxx, -1);
- break;
- }
- case 'F'-'@':
- tearrow(help_ew->tp, WC_RIGHT);
- break;
- case 'N'-'@':
- tearrow(help_ew->tp, WC_DOWN);
- break;
- case 'P'-'@':
- tearrow(help_ew->tp, WC_UP);
- break;
- case 'Z'-'@':
- {
- TEXTEDIT* tp = help_ew->tp;
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- break;
- }
- case 'L'-'@':
- case 'V'-'@':
- case ' ':
- {
- int i;
- int j;
- wgetdefwinsize(&i, &j);
- j = j/wlineheight() -1;
- for (i=0; i<j; i++) tearrow(help_ew->tp, WC_DOWN);
- break;
- }
- case 'K'-'@':
- {
- int i;
- int j;
- wgetdefwinsize(&i, &j);
- j = j/wlineheight() -1;
- for (i=0; i<j; i++) tearrow(help_ew->tp, WC_UP);
- break;
- }
- }
- break;
- case WE_MENU:
- switch (e.u.m.id) {
- case ADMIN_MENU:
- switch (e.u.m.item) {
- case MMHelp:
- if (help_length) helpwindow(0);
- break;
- case MMHelpSel:
- help_selection(ew);
- break;
- }
- break;
- case EDIT_MENU:
- switch (e.u.m.item) {
- case MMCopy:
- ewcopy(ew);
- break;
- case MMSelAll:
- tesetfocus(ew->tp, 0,
- tegetlen(ew->tp));
- break;
- }
- break;
- case HELP_MENU:
- helpwindow(e.u.m.item);
- break;
- }
- break;
- case WE_COMMAND:
- switch (e.u.command) {
- case WC_CANCEL:
- interrupt_pending = YES;
- break;
- case WC_RETURN:
- help_selection(ew);
- break;
- case WC_DEL:
- case WC_BACKSPACE:
- helpwindow(0);
- break;
- default:
- ewevent(ew, &e, &closed);
- break;
- }
- if (e.u.command != WC_CLOSE) {
- break;
- }
- case WE_CLOSE:
- help_ew->saved = TRUE;
- free(help_buff);
- ewclose(help_ew);
- help_ew = 0;
- break;
- default:
- ewevent(ew, &e, &closed);
- if (closed) {
- help_ew->saved = TRUE;
- free(help_buff);
- ewclose(help_ew);
- help_ew = 0;
- }
- break;
- }
- }
- else if (ew != NULL) ewevent(ew, &e, &closed);
- else wfleep();
- fixmenus();
- }
- }
- void flush_screen(void)
- {
- TEXTEDIT* tp = CSL_ew->tp;
- if (stdout_n != 0) {
-
- ewreplace(CSL_ew, stdout_buffer);
- stdout_n = 0; stdout_p = stdout_buffer;
- }
- if (tp->nlines > max_nlines+5) {
- techangefocus(tp, 0, zsubgap(tp->start[tp->nlines-max_nlines]));
- tp->aim= UNDEF;
- tp->focprev= FALSE;
- tereplace(tp, "");
-
-
- tesetfocus(tp, tp->buflen - tp->gaplen, -1);
- }
- wupdate(CSL_window);
- }
- static clock_t prev_clock = 0;
- void accept_tick(void)
- {
- clock_t t0 = clock();
- #ifdef SOFTWARE_TICKS_PER_SECOND
- software_tick_count++;
- #endif
- #ifdef SOFTWARE_TICKS_PER_SECOND
- if (prev_clock != 0)
- { double t1 = (double)(t0-prev_clock)/(double)CLOCKS_PER_SEC;
- double ratio =
- (double)(software_tick_count - prev_software_tick_count)/t1;
- int32 w;
- ratio = ratio / (double)SOFTWARE_TICKS_PER_SECOND;
- prev_software_tick_count = software_tick_count;
- ratio = sqrt(ratio);
- w = (int)(1000.0 * ratio);
- if (w > 3000) w = 3000;
- else if (w < 300) w = 300;
- if (software_ticks < (0x7fffffff/3000) &&
- software_ticks > 50)
- software_ticks = (w*software_ticks)/1000;
- }
- #endif
- t0 = clock();
- remove_ticker();
- if (t0 > prev_clock + CLOCKS_PER_SEC) {
- if (clock_stack == &consolidated_time[0]) {
- consolidated_time[0] +=
- ((double)(clock_t)(t0 - base_time))/((double)CLOCKS_PER_SEC);
- base_time = clock();
- }
- report_time((int32)(100.0*consolidated_time[0]), (int32)(100.0*gc_time));
- }
- push_clock();
- wupdate(CSL_window);
- poll_for_attn();
- polltick_pending = NO;
- ensure_screen();
- add_ticker();
- pop_clock();
- return;
- }
- static char time_string[32], space_string[32];
- void report_time(int32 t, int32 gct)
- {
- sprintf(time_string, "%d.%.2d secs", t/100, t%100);
- wmenusetitem(adminmenu, MMTime, time_string);
- sprintf(time_string, "+ %d.%.2d secs", gct/100, gct%100);
- wmenusetitem(adminmenu, MMOTime, time_string);
- }
- void report_space(int gc_count, double percent)
- {
- sprintf(space_string, "[GC %d]:%.2f%%", gc_count, percent);
- wmenusetitem(adminmenu, MMSpace, space_string);
- }
- #ifndef HAVE_UNIVERSAL_HEADERS
- #define ModalFilterUPP ProcPtr
- #define NewModalFilterProc(x) ((ProcPtr)x)
- #endif
- extern pascal Boolean
- filter_addnl(DialogPtr, EventRecord, short *);
- void pause_for_user(void)
- {
- ModalFilterUPP filterupp = NewModalFilterProc(filter_addnl);
- remove_ticker();
- ensure_screen();
- CSL_ew->saved = TRUE;
- if (spool_file != NULL) return;
- set_arrow();
- Alert(128, filterupp);
- ewclose(CSL_ew);
- wdone();
- }
- int wimpget(char *tty_buffer)
- {
- TEXTEDIT* tp = CSL_ew->tp;
- int i;
- int n;
- int lineno;
- tty_nnl = 1;
- push_clock();
- remove_ticker();
- if (stdout_n != 0) flush_screen();
- wmenuattach(CSL_window, loadmenu);
- wmenuattach(CSL_window, libmenu);
- wmenuattach(CSL_window, switchmenu);
- lineno = tp->nlines-1;
- tty_offset = tp->foc - tp->start[lineno];
- if (tty_offset<0) tty_offset += tp->gaplen;
- wmenuenable(adminmenu, MMPause, NO);
- if(tty_index>0) {
- int i = 0;
- for (; i<tty_index; i++)
- if (tty_buff[i] == '\n') tty_nnl++;
- tty_buff[tty_index] = '\0';
- ewreplace(CSL_ew, tty_buff);
- tty_index = 0;
- }
- event_loop();
-
- lineno = tp->nlines-tty_nnl;
-
- memcpy(tty_buffer, tegettext(tp)+tp->start[lineno]+tty_offset,
- tp->foc- tp->start[lineno]-tty_offset);
- wmenudetach(CSL_window, loadmenu);
- wmenudetach(CSL_window, libmenu);
- wmenudetach(CSL_window, switchmenu);
- wmenuenable(adminmenu, MMPause, YES);
- add_ticker();
- n = tp->foc- tp->start[lineno]-tty_offset;
- if (n<0) {
- n += tp->gaplen;
- fprintf(stderr, "N correction\n");
- }
- tty_ready = NO;
- pop_clock();
- return n;
- }
- int char_cnt = 0;
- void putc_stdout(int c)
- {
- *stdout_p++ = c;
- *stdout_p = 0;
- stdout_n++;
- char_cnt++;
- remove_ticker();
- if (c == '\n' || stdout_n > STDOUT_BUFSIZE - LONGEST_PRINTF) {
- push_clock(); flush_screen();
- if (char_cnt>200) {
- poll_for_attn(); char_cnt = 0;
- }
- pop_clock();
- }
- if (polltick_pending) accept_tick();
- add_ticker();
- }
- void vfprintf_stdout(char *fmt, va_list a)
- {
- int n;
- n = vsprintf(stdout_p, fmt, a);
- stdout_p += n;
- stdout_n += n;
- char_cnt += n;
- remove_ticker();
- if (stdout_n > STDOUT_BUFSIZE - LONGEST_PRINTF) {
- push_clock(); flush_screen();
- if (char_cnt>200) {
- poll_for_attn(); char_cnt = 0;
- }
- pop_clock();
- }
- if (polltick_pending) accept_tick();
- add_ticker();
- }
- #define NARGS 25
- static char *argv[NARGS+1];
- static char argbuf[256];
- static char*
- init_command_line(char *buf1, char *buf2)
- {
- register char *s, *t = buf2;
- int c, space = 0, dquote = 0, squote = 0, quote = 0;
-
- sprintf(s = buf1, "%#s", LMGetCurApName());
- while (c = *s++) {
- if (c == ' ')
- space = 1;
- else if (c == '"')
- dquote = 1;
- else if (c == '\'')
- squote = 1;
- }
- if (space || dquote || squote)
- *t++ = quote = dquote && !squote ? '\'' : '"';
- for (s = buf1; c = *s++; *t++ = c) {
- if (c == quote || c == '\\')
- *t++ = '\\';
- }
- if (quote)
- *t++ = quote;
- *t++ = ' ';
- *t++ = 0;
- return t;
- }
- static int
- parse(char *s, char *t)
- {
- int c, quote = 0, argc = 0;
-
- while (c = *s++) {
- if (c == ' ')
- continue;
- if (argc < 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));
- *t++ = 0;
- }
- return(argc);
- }
- #ifdef OLD
- int wgetargs(char ***av)
- {
- short i, argc;
- char buf[256];
- char *t = init_command_line(buf, argbuf);
- if( !waskstr(" Arguments for REDUCE 3.7", t, 256)) exit(1);
- t[-1] = ' ';
- sprintf(buf, "%s", argbuf);
- argc = parse(buf, argbuf);
- *av = argv;
-
- return(argc);
- }
- #else
- enum {
- exDEF = 3,
- exLOG,
- exVER,
- exXTA
- };
- enum {
- exBAT = 3,
- exBAC,
- exTRA,
- exCLD,
- exLAP,
- exQUI,
- exREC,
- exRED,
- exRAN,
- exSIZ,
- exOTH,
- exLGG,
- exDFF,
- exVBE
- };
-
-
- #define START_1 (129)
- #define START_2 (128)
- int DoExtra(char ***av)
- {
- DialogPtr dd;
- short i;
- int verbos = 0;
- int deflt = 0;
- int logging = 0;
- char buff[256];
- char name[256];
- char nams[256];
- Rect box;
- short type;
- Handle item;
- char *t = init_command_line(buff, argbuf);
- char *s = t-1;
- int argc;
- ModalFilterUPP filterupp = NewModalFilterProc(filter_addnl);
- int batch =0, back = 0, cold = 0, lap = 0, quiet = 0;
- int trap = 0, recover = 0, redirect = 0;
- dd = GetNewDialog(START_2, NULL, (WindowPtr)-1);
- GetDItem(dd, 1, &type, &item, &box);
- SetPort(dd);
- InsetRect(&box, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(&box, 16, 16);
- set_arrow();
- do {
- ModalDialog(filterupp, &i);
- switch (i) {
- case cancel:
- DisposDialog(dd);
- exit(0);
- case exBAT:
- batch = !batch;
- GetDItem(dd, exBAT, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, batch);
- break;
- case exBAC:
- back = !back;
- GetDItem(dd, exBAC, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, back);
- break;
- case exTRA:
- trap = !trap;
- GetDItem(dd, exTRA, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, trap);
- break;
- case exCLD:
- cold = !cold;
- GetDItem(dd, exCLD, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, cold);
- break;
- case exLAP:
- lap = !lap;
- GetDItem(dd, exLAP, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, lap);
- break;
- case exQUI:
- quiet = !quiet;
- GetDItem(dd, exQUI, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, quiet);
- break;
- case exREC:
- recover = !recover;
- GetDItem(dd, exREC, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, recover);
- break;
- case exRED:
- redirect = waskfile("Redirection File: ", nams, 256, 1);
- break;
- case exLGG:
- logging = waskfile("Log File: ", name, 256, 1);
- break;
- case exDFF:
- deflt = !deflt;
- GetDItem(dd, exDFF, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, deflt);
- break;
- case exVBE:
- verbos = !verbos;
- GetDItem(dd, exVBE, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, verbos);
- break;
- }
- } while (i != ok);
- if (batch) { strcpy(t, " -b"); t += 3; }
- if (back) { strcpy(t, " -g"); t += 3; }
- if (cold) { strcpy(t, " -z"); t += 3; }
- if (lap) { strcpy(t, " -s"); t += 3; }
- if (quiet) { strcpy(t, " -q"); t += 3; }
- if (recover) { strcpy(t, " -y"); t += 3; }
- if (trap) { strcpy(t, " -x"); t += 3; }
- if (verbos) { strcpy(t, " -v"); t += 3; }
- if (logging) { strcpy(t, " -l"); t += 3;
- strcpy(t, name); t += strlen(name);
- }
- if (redirect) { strcpy(t, " --"); t += 3;
- strcpy(t, nams); t += strlen(nams);
- }
- {
- char bb[256];
- GetDItem(dd, exRAN, &type, &item, &box);
- GetIText(item, (unsigned char *)bb);
- #ifndef CLEVERGLUE
- P2CStr((unsigned char *)bb);
- #endif
- if (bb[0]!='\0') {
- strcpy(t, " -r"); t += 3;
- strcpy(t, bb); t += strlen(bb);
- }
- GetDItem(dd, exSIZ, &type, &item, &box);
- GetIText(item, (unsigned char *)bb);
- #ifndef CLEVERGLUE
- P2CStr((unsigned char *)bb);
- #endif
- if (bb[0]!='\0') {
- strcpy(t, " -k"); t += 3;
- strcpy(t, bb); t += strlen(bb);
- }
- GetDItem(dd, exOTH, &type, &item, &box);
- GetIText(item, (unsigned char *)bb);
- #ifndef CLEVERGLUE
- P2CStr((unsigned char *)bb);
- #endif
- if (bb[0]!='\0') {
- strcpy(t, bb); t += strlen(bb);
- }
- }
- out:
- DisposDialog(dd);
- if (!deflt) *s = ' ';
- sprintf(buff, "%s", argbuf);
- argc = parse(buff, argbuf);
- *av = argv;
- return(argc);
- }
- int wgetargs(char ***av)
- {
- DialogPtr dd;
- short i;
- int verbos = 0;
- int deflt = 0;
- int logging = 0;
- char buff[256];
- char name[256];
- char nams[256];
- int p = 0;
- Rect box;
- short type;
- Handle item;
- char *t = init_command_line(buff, argbuf);
- char *s = t-1;
- int argc;
- ModalFilterUPP filterupp = NewModalFilterProc(filter_addnl);
- dd = GetNewDialog(START_1, NULL, (WindowPtr)-1);
- GetDItem(dd, 1, &type, &item, &box);
- SetPort(dd);
- InsetRect(&box, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(&box, 16, 16);
- set_arrow();
- do {
- ModalDialog(filterupp, &i);
- switch (i) {
- case cancel:
- DisposDialog(dd);
- exit(0);
- case exDEF:
- deflt = !deflt;
- break;
- case exVER:
- verbos = !verbos;
- GetDItem(dd, exVER, &type, &item, &box);
- SetCtlValue((struct ControlRecord **)item, verbos);
- break;
- case exLOG:
- logging = waskfile("Log File: ", name, 256, 1);
- break;
- case exXTA:
- set_watch();
- DisposDialog(dd);
- return DoExtra(av);
- }
- } while (i != ok);
- set_watch();
- {
- char aa[256];
- if (verbos) {
- strcpy(t, " -v");
- t += 3; }
- if (logging) {
- strcpy(t, " -l"); t += 3;
- strcpy(t, name); p += strlen(aa);
- }
- }
- if (!deflt) *s = ' ';
- DisposDialog(dd);
- sprintf(buff, "%s", argbuf);
- argc = parse(buff, argbuf);
- *av = argv;
- return(argc);
- }
- #endif
|