sysstmac.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160
  1. From jpff@maths.bath.ac.uk Sat Apr 24 23:37:05 1999
  2. Date: Sat, 24 Apr 99 22:35:07 BST
  3. From: jpff@maths.bath.ac.uk
  4. To: acn1@cam.ac.uk
  5. Subject: sysstmac.c
  6. Message written at 24 Apr 1999 17:21:34 +0100
  7. This is a better sysstmac.c. I still need to deal with the help
  8. system, but the dialogs are greatly improved in this version.
  9. ==John
  10. ------------------------------------------------------------------------
  11. /* sysstmac.c Copyright (C) 1989-99 Codemist Ltd */
  12. /*
  13. * Macintosh system-specific stuff
  14. */
  15. /* Signature: 5d245215 07-Mar-2000 */
  16. #include "machine.h"
  17. #include <stdarg.h>
  18. #include <stddef.h>
  19. #include <string.h>
  20. #include <ctype.h>
  21. #include "tags.h"
  22. #include "externs.h"
  23. #include <unix.h>
  24. #include <files.h>
  25. #include <unix.h>
  26. #include <retrace.h>
  27. #include <timer.h>
  28. #include <ansi_private.h>
  29. #include "macwin.h"
  30. #include <Dialogs.h>
  31. #undef nil /* #define'd by Think C headers but not wanted (by me) */
  32. int get_home_directory(char *b, int length);
  33. int get_users_home_directory(char *b, int length);
  34. #include "filename.c"
  35. /*
  36. * This is a dummy definition of get_truename, here so that everything
  37. * will link. Both the calling convention used here and the exact
  38. * meaning and implementation may be under gentle review!
  39. */
  40. char *get_truename(char *filename, char *old, size_t n)
  41. {
  42. char *w;
  43. process_file_name(filename, old, n);
  44. if (*filename == 0)
  45. { aerror("truename");
  46. return NULL;
  47. }
  48. w = (char *)malloc(1+strlen(filename));
  49. if (w == NULL) return w;
  50. strcpy(w, filename);
  51. return w;
  52. }
  53. CSLbool file_exists(char *filename, char *old, size_t n, char *tt)
  54. {
  55. FileParam pb;
  56. char buf[FILENAME_MAX];
  57. process_file_name(filename, old, n);
  58. pb.ioNamePtr = __c2p((const char*)filename, buf);
  59. pb.ioFRefNum = 0;
  60. pb.ioFVersNum = 0;
  61. pb.ioFDirIndex = 0;
  62. if (PBGetFInfo((ParmBlkPtr)&pb, 0) != noErr) return NO;
  63. strcpy(tt, ctime(&(pb.ioFlMdDat)));
  64. return YES;
  65. }
  66. char *my_getenv(char *s)
  67. {
  68. return getenv(s);
  69. }
  70. int
  71. myexec(char *filename, ...)
  72. {
  73. int i;
  74. short ans;
  75. EventRecord event;
  76. #if 1 /* __powerc */
  77. FSSpec fsp;
  78. LaunchParamBlockRec lpb;
  79. C2PStr(filename);
  80. ans = FSMakeFSSpec( 0,0,(unsigned char*)filename,&fsp);
  81. P2CStr((unsigned char*)filename);
  82. if (!ans) {
  83. lpb.launchBlockID = extendedBlock;
  84. lpb.launchEPBLength = extendedBlockLen;
  85. lpb.launchFileFlags = 0;
  86. lpb.launchControlFlags = launchContinue + launchNoFileFlags;
  87. lpb.launchAppSpec = &fsp;
  88. lpb.launchAppParameters = 0;
  89. ans = LaunchApplication(&lpb);
  90. }
  91. #else
  92. static struct {
  93. unsigned char *name;
  94. short memuse;
  95. char lc[2];
  96. long extBlocLen;
  97. short fFlags;
  98. long launchFlags;
  99. } buf;
  100. unsigned char pname[255];
  101. extern void _Launch();
  102. buf.name = __c2p(filename, (char *)pname);
  103. buf.memuse = 0;
  104. buf.lc[0] = 'L'; buf.lc[1] = 'C';
  105. buf.extBlocLen = 6;
  106. buf.fFlags = 128; /* RO */
  107. buf.launchFlags = 0xC0000000;
  108. asm {
  109. lea buf,a0
  110. dc.w _Launch
  111. move.w d0,ans;
  112. }
  113. #endif
  114. if (ans==0)
  115. for (i=0; i<20; i++) WaitNextEvent(everyEvent, &event, 10, 0L);
  116. return ans;
  117. }
  118. int my_system(char *s)
  119. {
  120. return myexec(s);
  121. }
  122. void my_pclose(FILE *a)
  123. {
  124. return;
  125. }
  126. int create_directory(char *filename, char *old, size_t n)
  127. {
  128. process_file_name(filename, old, n);
  129. if (*filename==0) return 1;
  130. return 1; /* Unfinished */
  131. }
  132. int delete_file(char *filename, char *old, size_t n)
  133. {
  134. process_file_name(filename, old, n);
  135. if (*filename==0) return 1;
  136. return remove(filename);
  137. }
  138. int get_home_directory(char *b, int length)
  139. {
  140. char *w = my_getenv("home");
  141. if (w != NULL) strcpy(b, w);
  142. else
  143. strcpy(b, ":"); /* Not satisfactory */
  144. return strlen(b);
  145. }
  146. static int get_users_home_directory(char *b, int length)
  147. {
  148. char *w, h[LONGEST_LEGAL_FILENAME];
  149. sprintf(h, "home$%s", b);
  150. w = my_getenv(h);
  151. if (w != NULL) strcpy(b, w);
  152. else
  153. strcpy(b, ":"); /* Not satisfactory */
  154. return strlen(b);
  155. }
  156. int batchp(void)
  157. {
  158. return !isatty(fileno(stdin));
  159. }
  160. /*static char CurApName[64];*/
  161. /*
  162. * The next procedure is responsible for establishing information about
  163. * where the main checkpoint image should be recovered from, and where
  164. * and fasl files should come from.
  165. */
  166. char *find_image_directory(int argc, char *argv[])
  167. {
  168. char image[LONGEST_LEGAL_FILENAME];
  169. char pgmname[LONGEST_LEGAL_FILENAME];
  170. char *w;
  171. /*
  172. * For the Macintosh I use the data fork of the application image as
  173. * a place to store useful stuff.
  174. */
  175. WDPBRec pb1;
  176. CInfoPBRec pb2;
  177. int i, j, r, p = LONGEST_LEGAL_FILENAME;
  178. long id;
  179. pgmname[--p] = 0;
  180. sprintf(image, "%#s", LMGetCurApName()); /* name of current application */
  181. strcpy(program_name, image);
  182. i = strlen(image);
  183. strcpy(image+i, " Image");
  184. i += 6;
  185. p -= i;
  186. memcpy(&pgmname[p], image, i); /* copy to the end of a buffer */
  187. pb1.ioNamePtr = (unsigned char *)image;
  188. PBHGetVolSync(&pb1); /* find current working dir/volume */
  189. id = pb1.ioWDDirID; /* working directory identifier */
  190. while (id != 0) {
  191. pb2.dirInfo.ioFDirIndex = -1; /* use dir ID, not file name/index */
  192. pb2.dirInfo.ioVRefNum = pb1.ioVRefNum; /* look in this volume */
  193. pb2.dirInfo.ioDrDirID = id; /* get info about this directory */
  194. pb2.dirInfo.ioNamePtr = (unsigned char *)image;
  195. r = PBGetCatInfoSync(&pb2); /* Read catalogue - find name & parent */
  196. if (r != 0) break; /* failed - must be at top of tree */
  197. id = pb2.dirInfo.ioDrParID; /* go on up to parent directory */
  198. i = image[0] & 0xff; /* length of name of this directory */
  199. pgmname[--p] = ':';
  200. p -= i;
  201. if (p < 10) {
  202. fprintf(stderr, "\nPlease re-install this package nearer the top of\n");
  203. fprintf(stderr, "your directory hierarchy. It will not work this far down\n");
  204. abort();
  205. }
  206. memcpy(&pgmname[p], &image[1], i); /* stick names together with ':'s */
  207. }
  208. strcpy(image, &pgmname[p]); /* Put complete name in convenient place */
  209. /*
  210. * I copy from local vectors into malloc'd space to hand my
  211. * answer back.
  212. */
  213. w = (char *)malloc(1+strlen(&pgmname[p]));
  214. /*
  215. * The error exit here seem unsatisfactory...
  216. */
  217. if (w == NULL)
  218. { fprintf(stderr, "\n+++ Panic - run out of space\n");
  219. exit(EXIT_FAILURE);
  220. }
  221. strcpy(w, &pgmname[p]);
  222. return w;
  223. }
  224. int truncate_file(FILE *f, long int where)
  225. {
  226. short a;
  227. short ff = f->refnum;
  228. if (fflush(f) != 0) return 1;
  229. a = SetEOF(ff, where); /* Returns zero if successs */
  230. return (int)a;
  231. }
  232. static CSLbool ticker_active = NO;
  233. int32 software_ticks = INITIAL_SOFTWARE_TICKS;
  234. int32 software_tick_count = 0, prev_software_tick_count = 0;
  235. void add_ticker(void)
  236. {
  237. if (ticker_active) return;
  238. if (countdown<0) countdown = SOFTWARE_TICKS; /* Reset if expired */
  239. ticker_active = YES;
  240. }
  241. void remove_ticker(void)
  242. {
  243. /* if (!ticker_active) return; */
  244. ticker_active = NO;
  245. }
  246. int file_readable(char *filename, char *old, size_t n)
  247. {
  248. FILE *fp;
  249. process_file_name(filename, old, n);
  250. if (*filename == 0) return 0;
  251. /* The "correct" way to do this is via stat, but this is much simpler! */
  252. fp = fopen(filename,"r");
  253. if (fp == NULL) return 0;
  254. else
  255. { fclose(fp);
  256. return 1;
  257. }
  258. }
  259. int file_writeable(char *filename, char *old, size_t n)
  260. {
  261. FILE *fp;
  262. process_file_name(filename, old, n);
  263. if (*filename == 0) return 0;
  264. fp = fopen(filename,"a");
  265. if (fp == NULL) return 0;
  266. else
  267. { fclose(fp);
  268. return 1;
  269. }
  270. }
  271. int rename_file(char *from_name, char *from_old, size_t from_size,
  272. char *to_name, char *to_old, size_t to_size)
  273. {
  274. process_file_name(from_name, from_old, from_size);
  275. process_file_name(to_name, to_old, to_size);
  276. if (*from_name == 0 || *to_name == 0) return 0;
  277. return rename(from_name,to_name);
  278. }
  279. int change_directory(char *filename, char *old, size_t n)
  280. {
  281. WDPBRec P;
  282. Str255 pname;
  283. process_file_name(filename, old, n);
  284. if (*filename==0) return 1;
  285. strcpy((char*)pname, filename);
  286. C2PStr((char*)pname);
  287. P.ioNamePtr = pname;
  288. return PBHSetVol(&P, 0);
  289. }
  290. int directoryp(char *filename, char *old, size_t n)
  291. {
  292. struct stat statrec;
  293. process_file_name(filename, old, n);
  294. stat(filename, &statrec);
  295. return S_ISDIR(statrec.st_mode);
  296. }
  297. int get_current_directory(char *s, int n)
  298. {
  299. return 0;
  300. }
  301. #include "scandir.c"
  302. void list_directory_members(char *filename, char *old,
  303. size_t n, directory_callback *fn)
  304. {
  305. process_file_name(filename, old, n);
  306. scan_files(filename, fn);
  307. }
  308. /* ************************************************************ */
  309. /* ********** StdWin Interface ******************************** */
  310. /* ************************************************************ */
  311. /* ************************************************************ */
  312. #include "stdwin.h"
  313. #include "tools.h"
  314. #include "editwin.h"
  315. #include "text.h" /* Rather a cheat as I need to look
  316. * low down in here */
  317. static WINDOW *CSL_window;
  318. static EDITWIN *CSL_ew;
  319. static EDITWIN *help_ew;
  320. int max_nlines = 250;
  321. #ifndef HELP_DATA
  322. #define HELP_DATA "help.data"
  323. #endif
  324. #ifndef HELP_INDEX
  325. #define HELP_INDEX "help.index"
  326. #endif
  327. static MENU *adminmenu;
  328. static MENU *editmenu;
  329. static MENU *loadmenu;
  330. static MENU *libmenu;
  331. static MENU *switchmenu;
  332. static MENU *helpmenu;
  333. /* static MENU *fontmenu; */
  334. /* static MENU *sizemenu; */
  335. #define ADMIN_MENU (1001)
  336. #define MMFile 0
  337. #define MMSaveas 1
  338. #define MMHelp 2 /* main window menu items */
  339. #define MMHelpSel 3
  340. #define MMHelpAsk 4
  341. #define MMInt 5
  342. #define MMAbort 6
  343. #define MMPause 7
  344. #define MMDummy 8
  345. #define MMTime 9
  346. #define MMSpace 10
  347. #define MMOTime 11
  348. #define EDIT_MENU (1002)
  349. #define MMCut 0
  350. #define MMCopy 1
  351. #define MMPaste 2
  352. #define MMClear 3
  353. #define MMSelAll 4
  354. #define HELP_LEN (36)
  355. #define HELP_MENU (1003)
  356. static struct hlp {
  357. char name[HELP_LEN];
  358. long offset;
  359. int length;
  360. } *hlp;
  361. int help_length;
  362. int helpstamp;
  363. #define LOAD_MENU (1004)
  364. static char *loads[] = {
  365. (char*)NULL};
  366. #define LIB_MENU (1005)
  367. static char *libraries[] = {
  368. (char*)NULL};
  369. #define SWITCH_MENU (1006)
  370. static struct sw {
  371. char *name;
  372. int state;
  373. } switches[] = {
  374. {(char*)NULL, 0}};
  375. /* #define FONT_MENU (1007) */
  376. /* static char *fonts[] = { "Monaco", "Courier", NULL}; */
  377. /* static current_font = 0; */
  378. /* #define SIZE_MENU (1008) */
  379. /* static char *sizes[] = { "8", "9", "10", "11", "12", NULL}; */
  380. /* static current_size = 1; */
  381. get_full_name(char *name, FSSpec *spec)
  382. {
  383. char nn[LONGEST_LEGAL_FILENAME];
  384. char mm[LONGEST_LEGAL_FILENAME];
  385. char *w;
  386. int i, r;
  387. int p = LONGEST_LEGAL_FILENAME;
  388. long id;
  389. CInfoPBRec pb2;
  390. nn[--p] = 0;
  391. i = spec->name[0];
  392. p -= i;
  393. memcpy(&nn[p], &(spec->name[1]), i); /* Copy base name */
  394. id = spec->parID;
  395. while (id != 0) {
  396. pb2.dirInfo.ioFDirIndex = -1; /* use dirID, not file name/index */
  397. pb2.dirInfo.ioVRefNum = spec->vRefNum; /* look in this volume */
  398. pb2.dirInfo.ioDrDirID = id; /* get info about this directory */
  399. pb2.dirInfo.ioNamePtr = (unsigned char *)mm;
  400. if (PBGetCatInfoSync(&pb2)) break; /* Read catalogue - find name & parent*/
  401. /* Fail at top of tree? */
  402. id = pb2.dirInfo.ioDrParID; /* go on up to parent directory */
  403. i = mm[0] & 0xff; /* length of name of this directory */
  404. nn[--p] = ':';
  405. p -= i;
  406. if (p < 10) {
  407. fprintf(stderr, "\nCannot access file so far from root\n");
  408. strcpy(name, "");
  409. return FALSE;
  410. }
  411. memcpy(&nn[p], &mm[1], i); /* stick names together with ':'s */
  412. }
  413. strcpy(name, &nn[p]);
  414. return TRUE;
  415. }
  416. static void menusetup(void)
  417. {
  418. MENU *mp;
  419. int i;
  420. adminmenu= mp= wmenucreate(ADMIN_MENU, "Admin");
  421. wmenuadditem(mp, "Input file...", 'F');
  422. wmenuadditem(mp, "Saveas...", -1);
  423. wmenuadditem(mp, "Help Window", 'H');
  424. wmenuadditem(mp, "Help Selection", 'S');
  425. wmenuadditem(mp, "Help Topic...", -1);
  426. wmenuadditem(mp, "Interrupt", 'I');
  427. wmenuadditem(mp, "Quit", 'Q');
  428. wmenuadditem(mp, "Pause", 'P');
  429. wmenuadditem(mp, "---------", -1);
  430. wmenuadditem(mp, "0.00", -1);
  431. wmenuadditem(mp, "[GC 0]", -1);
  432. wmenuadditem(mp, "", -1);
  433. wmenuadditem(mp, "", -1);
  434. wmenuenable(mp, MMDummy, NO);
  435. wmenuenable(mp, MMTime, NO);
  436. wmenuenable(mp, MMSpace, NO);
  437. wmenuenable(mp, MMOTime, NO);
  438. editmenu= mp= wmenucreate(EDIT_MENU, "Edit");
  439. wmenuadditem(mp, "Cut", 'X');
  440. wmenuadditem(mp, "Copy", 'C');
  441. wmenuadditem(mp, "Paste", 'V');
  442. wmenuadditem(mp, "Clear", 'B');
  443. wmenuadditem(mp, "Select All", 'A');
  444. /* fontmenu= mp= wmenucreate(FONT_MENU, "Font"); */
  445. /* for (i=0; fonts[i]!= NULL; i++) wmenuadditem(mp, fonts[i], -1); */
  446. /* wmenucheck(mp, current_font, YES); */
  447. /* sizemenu= mp= wmenucreate(SIZE_MENU, "FontSize"); */
  448. /* for (i=0; sizes[i]!= NULL; i++) wmenuadditem(mp, sizes[i], -1); */
  449. /* wmenucheck(mp, current_size, YES); */
  450. /* helpmenu= mp= wmenucreate(HELP_MENU, "Help"); */
  451. helpmenu = mp = (MENU*)GetMenu(HELP_MENU);
  452. if (mp != 0) /* This checks against problems */
  453. InsertMenu((MenuHandle)mp, 0); DrawMenuBar();
  454. {
  455. FILE* hlpindx = fopen(HELP_INDEX, "r");
  456. if (hlpindx != NULL) {
  457. fscanf(hlpindx, "%d\n", &helpstamp);
  458. fscanf(hlpindx, "%d", &help_length);
  459. hlp = (struct hlp*) calloc(1+help_length, sizeof(struct hlp));
  460. if (hlp == NULL) {
  461. help_length = 0;
  462. goto loader; /* Insufficient memory */
  463. }
  464. for (i=0; i<help_length; i++) {
  465. int ch, p=0;
  466. fscanf(hlpindx, "%d %d ", &(hlp[i].offset), &(hlp[i].length));
  467. while (p<HELP_LEN-1) {
  468. ch = getc(hlpindx);
  469. if (ch == '\n') break;
  470. hlp[i].name[p++] = ch; /* Was toupper here */
  471. }
  472. while (ch != '\n') ch = getc(hlpindx);
  473. hlp[i].name[p] = '\0';
  474. /*wmenuadditem(mp, hlp[i].name, -1);*/
  475. }
  476. fclose(hlpindx);
  477. }
  478. else {
  479. help_length = 0;
  480. strcpy(hlp[0].name, "No help");
  481. hlp[0].offset = -1;
  482. hlp[0].length = 0;
  483. }
  484. }
  485. loader:
  486. loadmenu= mp= wmenucreate(LOAD_MENU, "Load");
  487. for (i=0; loads[i]!= NULL; i++)
  488. wmenuadditem(mp, loads[i], -1);
  489. libmenu= mp= wmenucreate(LIB_MENU, "Library");
  490. for (i=0; libraries[i]!= NULL; i++)
  491. wmenuadditem(mp, libraries[i], -1);
  492. switchmenu= mp= wmenucreate(SWITCH_MENU, "Switch");
  493. for (i=0; switches[i].name!= NULL; i++) {
  494. wmenuadditem(mp, switches[i].name, -1);
  495. wmenucheck(mp, i, switches[i].state);
  496. }
  497. }
  498. static void fixmenus(void)
  499. {
  500. CSLbool focus;
  501. focus= (CSL_ew->tp->foclen != 0);
  502. wmenuenable(editmenu, MMCut, focus);
  503. wmenuenable(editmenu, MMCopy, focus);
  504. wmenuenable(editmenu, MMClear, focus);
  505. wmenuenable(adminmenu, MMHelpSel, focus);
  506. /* wmenuenable(editmenu, MMPaste, YES); */
  507. if (help_ew != NULL) {
  508. focus= (help_ew->tp->foclen != 0);
  509. if (focus) {
  510. wmenuenable(editmenu, MMCut, focus);
  511. wmenuenable(editmenu, MMCopy, focus);
  512. wmenuenable(editmenu, MMClear, focus);
  513. wmenuenable(adminmenu, MMHelpSel, focus);
  514. }
  515. }
  516. }
  517. #define TTYBUF_SIZE 256
  518. static char tty_buff[TTYBUF_SIZE];
  519. static int tty_index = 0;
  520. static CSLbool tty_ready = NO;
  521. static int tty_nnl = 0;
  522. static int tty_offset;
  523. #define STDOUT_BUFSIZE 1024
  524. #define LONGEST_PRINTF 120
  525. static char stdout_buffer[STDOUT_BUFSIZE];
  526. static char *stdout_p;
  527. static int stdout_n;
  528. extern int _w_font;
  529. void start_up_window_manager(int use_wimp)
  530. {
  531. int CSL_width, CSL_height;
  532. _w_font = 4; /* Font family */
  533. menusetup();
  534. wsetdefwinsize(82*wcharwidth('0'), 25*wlineheight());
  535. CSL_ew = ewcreate(NULL);
  536. CSL_window = CSL_ew->win;
  537. wsettitle(CSL_window, "Reduce 3.7");
  538. fixmenus();
  539. /* wmenudetach(CSL_window, helpmenu); */
  540. wmenuenable(editmenu, MMTime, NO); /* These are not selectable */
  541. wmenuenable(editmenu, MMOTime, NO); /* These are not selectable */
  542. wmenuenable(editmenu, MMSpace, NO);
  543. wmenudetach(CSL_window, loadmenu); /* These are only valid when reading */
  544. wmenudetach(CSL_window, libmenu);
  545. wmenudetach(CSL_window, switchmenu);
  546. /* wmessage("Welcome to X-Reduce\n\n"); */
  547. stdout_n = 0;
  548. stdout_p = stdout_buffer;
  549. help_ew = NULL;
  550. }
  551. static char *help_buff;
  552. CSLbool
  553. helpwindow(int index)
  554. {
  555. FILE* help = fopen(HELP_DATA, "r");
  556. int ch;
  557. int width, height;
  558. int size = hlp[index].length;
  559. if (help == NULL) return FALSE;
  560. fscanf(help, "%d\n", &ch);
  561. if (ch != helpstamp) return FALSE; /* not same generation */
  562. /* fprintf(stderr, "Help on index %d offset=%d size=%d\n",
  563. index, hlp[index].offset, hlp[index].length); */
  564. fseek(help, hlp[index].offset, SEEK_SET);
  565. if (help_ew) {
  566. free(help_buff);
  567. tesetfocus(help_ew->tp, 0, tegetlen(help_ew->tp));
  568. ewreplace(help_ew, "");
  569. }
  570. else {
  571. help_ew = ewcreate(NULL);
  572. wsettitle(help_ew->win, "Help for Reduce 3.7");
  573. }
  574. help_buff = malloc(size+1);
  575. if (help_buff == NULL) {
  576. dprintf("Insufficient memory");
  577. wfleep();
  578. return FALSE;
  579. }
  580. /* fprintf(stderr, "reading %d bytes to buffer\n", size); */
  581. fread(help_buff, size, 1, help);
  582. /* fprintf(stderr, "help starts as %.100s\n", help_buff); */
  583. help_buff[size] = '\0';
  584. wmenudetach(help_ew->win, loadmenu);
  585. wmenudetach(help_ew->win, libmenu);
  586. wmenudetach(help_ew->win, switchmenu);
  587. /* wmenudetach(help_ew->win, adminmenu); */
  588. ewreplace(help_ew, help_buff);
  589. tesetfocus(help_ew->tp, 0, 0);
  590. fclose(help);
  591. return TRUE;
  592. }
  593. void help_buffer(char *buf, int len)
  594. {
  595. int i;
  596. for (i=0; i<help_length; i++) {
  597. /* fprintf(stderr, "Check against %s\n", hlp[i].name); */
  598. if (strncmp(hlp[i].name, buf, len) == 0) {
  599. helpwindow(i);
  600. break;
  601. }
  602. }
  603. if (i == help_length) wfleep();
  604. }
  605. void help_selection(EDITWIN *ew)
  606. {
  607. int i;
  608. char *text;
  609. TEXTEDIT *tp = ew->tp;
  610. if (tp->foclen == 0) {
  611. wfleep();
  612. return;
  613. }
  614. text= tegettext(tp);
  615. help_buffer(text+tp->foc, tp->foclen);
  616. }
  617. extern int pause_set = 0;
  618. void event_loop(void)
  619. {
  620. for (;;) { /* Loop while there are events */
  621. EVENT e;
  622. EDITWIN *ew;
  623. CSLbool closed;
  624. wgetevent(&e);
  625. /* fprintf(stderr, "Event: type=%d win=%p data=%d\n", e.type, e.window, e.u.command); */
  626. ew= ewfind(e.window);
  627. if (ew == CSL_ew) {
  628. switch (e.type) {
  629. case WE_CHAR:
  630. switch(e.u.character) {
  631. case 'A'-'@': /* ^A == beginning of line */
  632. {
  633. TEXTEDIT* tp = CSL_ew->tp;
  634. tesetfocus(tp,
  635. zsubgap(tp->start[tewhichline(tp,
  636. zaddgap(tp->foc),
  637. tp->focprev)]),
  638. -1);
  639. break;
  640. }
  641. case 'B'-'@': /* ^B back a character */
  642. tearrow(CSL_ew->tp, WC_LEFT);
  643. break;
  644. case 127: /* Delete character */
  645. case 'D'-'@': /* ^D delete at cursor */
  646. {
  647. TEXTEDIT* tp = CSL_ew->tp;
  648. tearrow(tp, WC_RIGHT);
  649. {
  650. int f1 = tp->foc;
  651. int i;
  652. int ss = tp->start[tp->nlines-tty_nnl];
  653. int ee = ss + tty_offset;
  654. if (ss <= f1 && f1 < ee) {
  655. if (tty_offset>0) tty_offset--;
  656. }
  657. e.type = WE_COMMAND;
  658. e.u.command = WC_BACKSPACE;
  659. ewevent(ew,&e, NULL);
  660. break;
  661. }
  662. }
  663. case 'E'-'@': /* ^E end of line */
  664. {
  665. TEXTEDIT* tp = CSL_ew->tp;
  666. int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
  667. int xxx = zsubgap(tetextround(tp, line, tp->right));
  668. tesetfocus(tp, xxx, -1);
  669. break;
  670. }
  671. case 'F'-'@': /* ^F forward a character */
  672. tearrow(CSL_ew->tp, WC_RIGHT);
  673. break;
  674. case 'K'-'@': /* ^K kill to end of line */
  675. { /* This does not take notice of offset */
  676. TEXTEDIT* tp = CSL_ew->tp;
  677. int f1;
  678. int i;
  679. int ss;
  680. int ee;
  681. tesetfocus(tp,
  682. tp->foc,
  683. zsubgap(tetextround(tp,
  684. tewhichline(tp, zaddgap(tp->foc),
  685. tp->focprev),
  686. tp->right)));
  687. f1 = tp->foc;
  688. ss = tp->start[tp->nlines-tty_nnl];
  689. ee = ss + tty_offset;
  690. for (i=0; i<tp->foclen; i++)
  691. if (ss <= f1+i && f1+i < ee) {
  692. if (tty_offset>0) tty_offset--;
  693. }
  694. ewreplace(ew, "");
  695. break;
  696. }
  697. case 'N'-'@': /* ^N next line */
  698. tearrow(CSL_ew->tp, WC_DOWN);
  699. break;
  700. case 'P'-'@': /* ^P previous line */
  701. tearrow(CSL_ew->tp, WC_UP);
  702. break;
  703. case 'Z'-'@': /* ^Z move to end of buffer */
  704. {
  705. TEXTEDIT* tp = CSL_ew->tp;
  706. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  707. break;
  708. }
  709. default:
  710. ewevent(ew, &e, &closed);
  711. if (tty_ready == YES && !pause_set) return;
  712. }
  713. break;
  714. case WE_COMMAND:
  715. switch (e.u.command) {
  716. case WC_CANCEL:
  717. interrupt_pending = YES;
  718. break;
  719. case WC_CLOSE:
  720. pause_for_user();
  721. exit(1);
  722. case WC_RETURN:
  723. {
  724. TEXTEDIT* tp = CSL_ew->tp;
  725. int f1 = zaddgap(tp->foc);
  726. int ee = tp->start[tp->nlines-tty_nnl] + tty_offset;
  727. /* printf("f1=%d ee=%d offset=%d\n", f1, ee, tty_offset); */
  728. if (f1 >= ee) {
  729. tty_nnl++;
  730. if (f1 == tp->buflen) {
  731. ewevent(ew, &e, &closed);
  732. tty_ready = YES;
  733. if (!pause_set) return;
  734. }
  735. }
  736. }
  737. break;
  738. case WC_DEL:
  739. case WC_BACKSPACE:
  740. /* Need to check to see if we are deleting
  741. * in the offset area */
  742. {
  743. TEXTEDIT* tp = CSL_ew->tp;
  744. int f1 = tp->foc;
  745. int i;
  746. int ss = tp->start[tp->nlines-tty_nnl];
  747. int ee = ss + tty_offset;
  748. if (tp->foclen == 0) {
  749. if (ss < f1 && f1 <= ee && tty_offset>0) tty_offset--;
  750. }
  751. else {
  752. for (i=0; i<tp->foclen; i++) {
  753. if (ss <= f1+i && f1+i < ee && tty_offset>0) tty_offset--;
  754. }
  755. }
  756. }
  757. break;
  758. case WC_LEFT:
  759. case WC_RIGHT:
  760. default:
  761. break;
  762. }
  763. ewevent(ew, &e, &closed);
  764. break;
  765. case WE_MENU:
  766. switch (e.u.m.id) {
  767. case ADMIN_MENU:
  768. switch (e.u.m.item) {
  769. case MMFile:
  770. {
  771. short wd;
  772. TEXTEDIT *tp = CSL_ew->tp;
  773. struct StandardFileReply sfr;
  774. StandardGetFile(NULL, -1, NULL, &sfr);
  775. if (sfr.sfGood && !sfr.sfIsFolder && !sfr.sfIsVolume) {
  776. char name[256];
  777. if (!get_full_name(name, &(sfr.sfFile))) break;
  778. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  779. ewreplace(CSL_ew, "in \"");
  780. ewreplace(CSL_ew, name);
  781. ewreplace(CSL_ew, "\"");
  782. /*tetoend(tp); */
  783. }
  784. break;
  785. }
  786. case MMSaveas:
  787. ewsaveas(CSL_ew);
  788. break;
  789. case MMHelp:
  790. helpwindow(0);
  791. break;
  792. case MMHelpSel:
  793. help_selection(ew);
  794. break;
  795. case MMHelpAsk:
  796. {
  797. char buf[40];
  798. int len;
  799. if (waskstr("Help on topic", buf, 40)) {
  800. len = strlen(buf);
  801. help_buffer(buf, len);
  802. }
  803. }
  804. break;
  805. case MMAbort:
  806. pause_for_user();
  807. exit(1);
  808. case MMInt:
  809. interrupt_pending = YES;
  810. return;
  811. case MMPause:
  812. pause_set = !pause_set;
  813. wmenucheck(adminmenu, MMPause, pause_set);
  814. if (pause_set) wsettitle(CSL_window, "<Paused> Reduce 3.7");
  815. else wsettitle(CSL_window, "Reduce 3.7");
  816. break;
  817. }
  818. break;
  819. case EDIT_MENU:
  820. switch (e.u.m.item) {
  821. case MMCopy:
  822. ewcopy(ew);
  823. break;
  824. case MMPaste:
  825. {
  826. char* text = wgetclip();
  827. char* tt = text;
  828. int valid = YES;
  829. if (text == NULL) wfleep();
  830. else {
  831. TEXTEDIT *tp = CSL_ew->tp;
  832. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  833. while (*tt != '\0')
  834. if (*tt++=='\n') valid = NO;
  835. if (valid) ewreplace(ew, text);
  836. else /*wmessage("Cannot Paste text including new line"); */
  837. Alert(129, NULL);
  838. }
  839. }
  840. break;
  841. case MMCut:
  842. ewcopy(ew);
  843. case MMClear:
  844. /* Need to check to see if we are deleting
  845. * in the offset area */
  846. {
  847. TEXTEDIT* tp = CSL_ew->tp;
  848. int f1 = tp->foc;
  849. int i;
  850. int ss = tp->start[tp->nlines-tty_nnl];
  851. int ee = ss + tty_offset;
  852. for (i=0; i<tp->foclen; i++)
  853. if (ss <= f1+i && f1+i < ee) {
  854. if (tty_offset>0) tty_offset--;
  855. }
  856. }
  857. ewreplace(ew, "");
  858. break;
  859. case MMSelAll:
  860. tesetfocus(ew->tp, 0, tegetlen(ew->tp));
  861. break;
  862. }
  863. break;
  864. case LOAD_MENU:
  865. {
  866. char *load = "load_package ";
  867. char *tt = loads[e.u.m.item];
  868. TEXTEDIT *tp = CSL_ew->tp;
  869. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  870. tp->aim= UNDEF;
  871. tp->focprev= FALSE;
  872. ewreplace(CSL_ew, load);
  873. ewreplace(CSL_ew, tt);
  874. tty_ready = YES;
  875. ewreplace(CSL_ew, ";\n");
  876. tty_nnl++;
  877. wmenuenable(loadmenu, e.u.m.item, NO);
  878. return;
  879. }
  880. case LIB_MENU:
  881. {
  882. char *load = "load_package ";
  883. char *tt = libraries[e.u.m.item];
  884. TEXTEDIT *tp = CSL_ew->tp;
  885. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  886. tp->aim= UNDEF;
  887. tp->focprev= FALSE;
  888. ewreplace(CSL_ew, load);
  889. ewreplace(CSL_ew, tt);
  890. tty_ready = YES;
  891. ewreplace(CSL_ew, ";\n");
  892. tty_nnl++;
  893. wmenuenable(loadmenu, e.u.m.item, NO);
  894. return;
  895. }
  896. case SWITCH_MENU:
  897. {
  898. char *load = (switches[e.u.m.item].state ? "off " : "on ");
  899. char *tt = switches[e.u.m.item].name;
  900. TEXTEDIT *tp = CSL_ew->tp;
  901. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  902. ewreplace(CSL_ew, load);
  903. ewreplace(CSL_ew, tt);
  904. tty_ready = YES;
  905. ewreplace(CSL_ew, ";\n");
  906. tty_nnl++;
  907. switches[e.u.m.item].state = ~ switches[e.u.m.item].state;
  908. wmenucheck(switchmenu, e.u.m.item, switches[e.u.m.item].state);
  909. return;
  910. }
  911. case HELP_MENU:
  912. helpwindow(e.u.m.item);
  913. break;
  914. /* case FONT_MENU: */
  915. /* if (ew == NULL) { */
  916. /* wfleep(); */
  917. /* break; */
  918. /* } */
  919. /* { */
  920. /* int f = wsetfont(fonts[e.u.m.item]); */
  921. /* if (f) { */
  922. /* TEXTATTR attr; */
  923. /* extern void getinfo_(); */
  924. /* wgetwintextattr(CSL_window, &attr); */
  925. /* attr.font = f; */
  926. /* wsetwintextattr(CSL_window, &attr); */
  927. /* getfinfo_(); */
  928. /* wmenucheck(fontmenu, current_font, NO); */
  929. /* wmenucheck(fontmenu, current_font = e.u.m.item, YES); */
  930. /* } */
  931. /* } */
  932. /* break; */
  933. /* case SIZE_MENU: */
  934. /* if (ew == NULL) { */
  935. /* wfleep(); */
  936. /* break; */
  937. /* } */
  938. /* wsetsize(atoi(sizes[e.u.m.item])); */
  939. /* { */
  940. /* TEXTATTR attr; */
  941. /* extern void getinfo_(); */
  942. /* wgetwintextattr(CSL_window, &attr); */
  943. /* attr.size = atoi(sizes[e.u.m.item]); */
  944. /* wsetwintextattr(CSL_window, &attr); */
  945. /* getfinfo_(); */
  946. /* } */
  947. /* wmenucheck(sizemenu, current_size, NO); */
  948. /* wmenucheck(sizemenu, current_size = e.u.m.item, YES); */
  949. /* break; */
  950. }
  951. break;
  952. case WE_CLOSE:
  953. pause_for_user();
  954. exit(1);
  955. default:
  956. ewevent(ew, &e, &closed);
  957. break;
  958. }
  959. }
  960. else if (ew == help_ew) {
  961. /* printf("%d %d\n", e.type, e.u.character); */
  962. switch (e.type) {
  963. case WE_MOUSE_UP: /* Extend to a word on single click */
  964. if (!ew->tp->mdown) break;
  965. ew->tp->mdown= FALSE;
  966. if (e.u.where.clicks > 1) {
  967. teclicknew(ew->tp, e.u.where.h, e.u.where.v, FALSE, TRUE);
  968. help_selection(ew);
  969. }
  970. break;
  971. case WE_CHAR:
  972. switch(e.u.character) {
  973. case 'A'-'@': /* ^A == beginning of line */
  974. {
  975. TEXTEDIT* tp = help_ew->tp;
  976. tesetfocus(tp,
  977. zsubgap(tp->start[tewhichline(tp,
  978. zaddgap(tp->foc),
  979. tp->focprev)]),
  980. -1);
  981. break;
  982. }
  983. case 'B'-'@': /* ^B back a character */
  984. tearrow(help_ew->tp, WC_LEFT);
  985. break;
  986. case 'E'-'@': /* ^E end of line */
  987. {
  988. TEXTEDIT* tp = help_ew->tp;
  989. int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
  990. int xxx = zsubgap(tetextround(tp, line, tp->right));
  991. tesetfocus(tp, xxx, -1);
  992. break;
  993. }
  994. case 'F'-'@': /* ^F forward a character */
  995. tearrow(help_ew->tp, WC_RIGHT);
  996. break;
  997. case 'K'-'@': /* ^K is Page up */
  998. {
  999. int i;
  1000. int j;
  1001. wgetdefwinsize(&i, &j);
  1002. j = j/wlineheight() -1;
  1003. for (i=0; i<j; i++) tearrow(help_ew->tp, WC_UP);
  1004. break;
  1005. }
  1006. case 'N'-'@': /* ^N next line */
  1007. tearrow(help_ew->tp, WC_DOWN);
  1008. break;
  1009. case 'P'-'@': /* ^P previous line */
  1010. tearrow(help_ew->tp, WC_UP);
  1011. break;
  1012. case 'Z'-'@': /* ^Z move to end of buffer */
  1013. {
  1014. TEXTEDIT* tp = help_ew->tp;
  1015. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  1016. break;
  1017. }
  1018. case 'V'-'@': /* ^V page down */
  1019. case ' ':
  1020. case 'L'-'@': /* ^L is Page down */
  1021. {
  1022. int i;
  1023. int j;
  1024. wgetdefwinsize(&i, &j);
  1025. j = j/wlineheight() -1;
  1026. for (i=0; i<j; i++) tearrow(help_ew->tp, WC_DOWN);
  1027. break;
  1028. }
  1029. case 'i':
  1030. case 'I':
  1031. {
  1032. char buf[40];
  1033. int len;
  1034. if (waskstr("Help on topic", buf, 40)) {
  1035. len = strlen(buf);
  1036. help_buffer(buf, len);
  1037. }
  1038. break;
  1039. }
  1040. case 'n':
  1041. case 'N':
  1042. {
  1043. extern char *strstr(const char*, const char*);
  1044. char *p = strstr((const char*)help_buff, (const char*)"Next: ");
  1045. int i = 0;
  1046. if (p == NULL) {
  1047. wfleep(); break;
  1048. }
  1049. p += 6;
  1050. while (p[i]!= ',') i++;
  1051. help_buffer(p,i);
  1052. break;
  1053. }
  1054. case 'p':
  1055. case 'P':
  1056. {
  1057. extern char *strstr(const char*, const char*);
  1058. char *p = strstr((const char*)help_buff, "Prev: ");
  1059. int i = 0;
  1060. if (p == NULL) {
  1061. wfleep(); break;
  1062. }
  1063. p += 6;
  1064. while (p[i]!= ',') i++;
  1065. help_buffer(p,i);
  1066. break;
  1067. }
  1068. case 'q':
  1069. case 'Q':
  1070. help_ew->saved = TRUE; /* Fake it */
  1071. free(help_buff);
  1072. ewclose(help_ew);
  1073. help_ew = 0;
  1074. break;
  1075. case 'u':
  1076. case 'U':
  1077. {
  1078. extern char *strstr(const char*, const char*);
  1079. char *p = strstr((const char*)help_buff, "Up: ");
  1080. int i = 0;
  1081. if (p == NULL) {
  1082. wfleep(); break;
  1083. }
  1084. p += 4;
  1085. while (p[i]!= '\n') i++;
  1086. help_buffer(p,i);
  1087. break;
  1088. }
  1089. }
  1090. break;
  1091. case WE_MENU:
  1092. switch (e.u.m.id) {
  1093. case ADMIN_MENU:
  1094. switch (e.u.m.item) {
  1095. case MMSaveas:
  1096. ewsaveas(help_ew);
  1097. break;
  1098. case MMHelp:
  1099. if (help_length) helpwindow(0);
  1100. break;
  1101. case MMHelpSel:
  1102. help_selection(ew);
  1103. break;
  1104. case MMHelpAsk:
  1105. {
  1106. char buf[40];
  1107. int len;
  1108. if (waskstr("Help on topic", buf, 40)) {
  1109. len = strlen(buf);
  1110. help_buffer(buf, len);
  1111. }
  1112. break;
  1113. }
  1114. case MMAbort:
  1115. help_ew->saved = TRUE; /* Fake it */
  1116. free(help_buff);
  1117. ewclose(help_ew);
  1118. help_ew = 0;
  1119. break;
  1120. }
  1121. break;
  1122. case EDIT_MENU:
  1123. switch (e.u.m.item) {
  1124. case MMCopy:
  1125. ewcopy(ew);
  1126. break;
  1127. case MMSelAll:
  1128. tesetfocus(ew->tp, 0, tegetlen(ew->tp));
  1129. break;
  1130. }
  1131. break;
  1132. case HELP_MENU:
  1133. helpwindow(e.u.m.item);
  1134. break;
  1135. }
  1136. break;
  1137. case WE_COMMAND:
  1138. switch (e.u.command) {
  1139. case WC_CANCEL:
  1140. interrupt_pending=YES;
  1141. break;
  1142. case WC_RETURN:
  1143. help_selection(ew);
  1144. break;
  1145. case WC_DEL:
  1146. case WC_BACKSPACE:
  1147. helpwindow(0);
  1148. break;
  1149. default:
  1150. ewevent(ew, &e, &closed);
  1151. break;
  1152. }
  1153. if (e.u.command != WC_CLOSE) {
  1154. break;
  1155. }
  1156. case WE_CLOSE:
  1157. help_ew->saved = TRUE; /* Fake it */
  1158. free(help_buff);
  1159. ewclose(help_ew);
  1160. help_ew = 0;
  1161. break;
  1162. default:
  1163. ewevent(ew, &e, &closed);
  1164. if (closed) {
  1165. help_ew->saved = TRUE; /* Fake it */
  1166. free(help_buff);
  1167. ewclose(help_ew);
  1168. help_ew = 0;
  1169. }
  1170. break;
  1171. }
  1172. }
  1173. else if (ew != NULL) ewevent(ew, &e, &closed);
  1174. else wfleep();
  1175. fixmenus();
  1176. }
  1177. }
  1178. void poll_for_attn(void)
  1179. {
  1180. for (;;) { /* Loop while there are events */
  1181. EVENT e;
  1182. EDITWIN *ew;
  1183. CSLbool closed;
  1184. if (!pause_set) {
  1185. if (!wpollevent(&e)) return;
  1186. }
  1187. else wgetevent(&e);
  1188. /* fprintf(stderr, "Event: type=%d win=%p data=%d\n", e.type, e.window, e.u.command); */
  1189. ew= ewfind(e.window);
  1190. if (ew == CSL_ew) {
  1191. switch (e.type) {
  1192. case WE_CHAR:
  1193. switch(e.u.character) {
  1194. case 'A'-'@': /* ^A == beginning of line */
  1195. {
  1196. TEXTEDIT* tp = CSL_ew->tp;
  1197. tesetfocus(tp,
  1198. zsubgap(tp->start[tewhichline(tp,
  1199. zaddgap(tp->foc),
  1200. tp->focprev)]),
  1201. -1);
  1202. break;
  1203. }
  1204. case 'B'-'@': /* ^B back a character */
  1205. tearrow(CSL_ew->tp, WC_LEFT);
  1206. break;
  1207. case 'D'-'@': /* ^D delete at cursor */
  1208. {
  1209. TEXTEDIT* tp = CSL_ew->tp;
  1210. tearrow(tp, WC_RIGHT);
  1211. e.type = WE_COMMAND;
  1212. e.u.command = WC_BACKSPACE;
  1213. ewevent(ew,&e, NULL);
  1214. break;
  1215. }
  1216. case 'E'-'@': /* ^E end of line */
  1217. {
  1218. TEXTEDIT* tp = CSL_ew->tp;
  1219. int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
  1220. int xxx = zsubgap(tetextround(tp, line, tp->right));
  1221. tesetfocus(tp, xxx, -1);
  1222. break;
  1223. }
  1224. case 'F'-'@': /* ^F forward a character */
  1225. tearrow(CSL_ew->tp, WC_RIGHT);
  1226. break;
  1227. case 'K'-'@': /* ^K kill all type ahead */
  1228. tty_index = 0;
  1229. break;
  1230. case 'N'-'@': /* ^N next line */
  1231. tearrow(CSL_ew->tp, WC_DOWN);
  1232. break;
  1233. case 'P'-'@': /* ^P previous line */
  1234. tearrow(CSL_ew->tp, WC_UP);
  1235. break;
  1236. case 'Z'-'@': /* ^Z move to end of buffer */
  1237. {
  1238. TEXTEDIT* tp = CSL_ew->tp;
  1239. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  1240. break;
  1241. }
  1242. case 'V'-'@': /* ^V page down */
  1243. case ' ':
  1244. {
  1245. int i;
  1246. int j;
  1247. wgetdefwinsize(&i, &j);
  1248. j = j/wlineheight() -1;
  1249. for (i=0; i<j; i++) tearrow(help_ew->tp, WC_DOWN);
  1250. break;
  1251. }
  1252. default:
  1253. if (tty_index > TTYBUF_SIZE-2) wfleep();
  1254. else tty_buff[tty_index++] = e.u.character;
  1255. break;
  1256. }
  1257. break;
  1258. case WE_COMMAND:
  1259. switch (e.u.command) {
  1260. case WC_CANCEL:
  1261. interrupt_pending = YES;
  1262. break;
  1263. case WC_CLOSE:
  1264. pause_for_user();
  1265. exit(1);
  1266. case WC_RETURN:
  1267. if (tty_index > TTYBUF_SIZE-2) wfleep();
  1268. else tty_buff[tty_index++] = '\n';
  1269. break;
  1270. case WC_TAB:
  1271. if (tty_index > TTYBUF_SIZE-2) wfleep();
  1272. else tty_buff[tty_index++] = '\t';
  1273. break;
  1274. case WC_DEL:
  1275. case WC_BACKSPACE:
  1276. if (tty_index>0) tty_index--;
  1277. break;
  1278. }
  1279. break;
  1280. case WE_MENU:
  1281. switch (e.u.m.id) {
  1282. case ADMIN_MENU:
  1283. switch (e.u.m.item) {
  1284. case MMHelp:
  1285. helpwindow(0);
  1286. break;
  1287. case MMHelpSel:
  1288. help_selection(ew);
  1289. break;
  1290. case MMAbort:
  1291. pause_for_user();
  1292. exit(1);
  1293. case MMInt:
  1294. interrupt_pending = YES;
  1295. return;
  1296. case MMPause:
  1297. pause_set = !pause_set;
  1298. wmenucheck(adminmenu, MMPause, pause_set);
  1299. if (pause_set) wsettitle(CSL_window, "<Paused> Reduce 3.7");
  1300. else wsettitle(CSL_window, "Reduce 3.7");
  1301. break;
  1302. }
  1303. break;
  1304. case EDIT_MENU:
  1305. switch (e.u.m.item) {
  1306. case MMCopy:
  1307. ewcopy(ew);
  1308. break;
  1309. case MMPaste:
  1310. break;
  1311. case MMCut:
  1312. ewcopy(ew);
  1313. case MMClear:
  1314. ewreplace(ew, "");
  1315. break;
  1316. case MMSelAll:
  1317. tesetfocus(ew->tp, 0, tegetlen(ew->tp));
  1318. break;
  1319. }
  1320. break;
  1321. case HELP_MENU:
  1322. helpwindow(e.u.m.item);
  1323. break;
  1324. }
  1325. break;
  1326. case WE_CLOSE:
  1327. pause_for_user();
  1328. exit(1);
  1329. default:
  1330. ewevent(ew, &e, &closed);
  1331. break;
  1332. }
  1333. }
  1334. else if (ew == help_ew) {
  1335. switch (e.type) {
  1336. case WE_MOUSE_UP: /* Extend to a word on single click */
  1337. if (!ew->tp->mdown)
  1338. break;
  1339. ew->tp->mdown= FALSE;
  1340. if (e.u.where.clicks > 1) {
  1341. teclicknew(ew->tp, e.u.where.h, e.u.where.v, FALSE, TRUE);
  1342. help_selection(ew);
  1343. }
  1344. break;
  1345. case WE_CHAR:
  1346. /* fprintf(stderr, "WE_CHAR %d(%c)\n", e.u.character,e.u.character); */
  1347. switch(e.u.character) {
  1348. case 'A'-'@': /* ^A == beginning of line */
  1349. {
  1350. TEXTEDIT* tp = help_ew->tp;
  1351. tesetfocus(tp,
  1352. zsubgap(tp->start[tewhichline(tp,
  1353. zaddgap(tp->foc),
  1354. tp->focprev)]),
  1355. -1);
  1356. break;
  1357. }
  1358. case 'B'-'@': /* ^B back a character */
  1359. tearrow(help_ew->tp, WC_LEFT);
  1360. break;
  1361. case 'E'-'@': /* ^E end of line */
  1362. {
  1363. TEXTEDIT* tp = help_ew->tp;
  1364. int line = tewhichline(tp, zaddgap(tp->foc), tp->focprev);
  1365. int xxx = zsubgap(tetextround(tp, line, tp->right));
  1366. tesetfocus(tp, xxx, -1);
  1367. break;
  1368. }
  1369. case 'F'-'@': /* ^F forward a character */
  1370. tearrow(help_ew->tp, WC_RIGHT);
  1371. break;
  1372. case 'N'-'@': /* ^N next line */
  1373. tearrow(help_ew->tp, WC_DOWN);
  1374. break;
  1375. case 'P'-'@': /* ^P previous line */
  1376. tearrow(help_ew->tp, WC_UP);
  1377. break;
  1378. case 'Z'-'@': /* ^Z move to end of buffer */
  1379. {
  1380. TEXTEDIT* tp = help_ew->tp;
  1381. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  1382. break;
  1383. }
  1384. case 'L'-'@': /* ^L is PgDn */
  1385. case 'V'-'@': /* ^V page down */
  1386. case ' ':
  1387. {
  1388. int i;
  1389. int j;
  1390. wgetdefwinsize(&i, &j);
  1391. j = j/wlineheight() -1;
  1392. for (i=0; i<j; i++) tearrow(help_ew->tp, WC_DOWN);
  1393. break;
  1394. }
  1395. case 'K'-'@': /* ^K is PgUp */
  1396. {
  1397. int i;
  1398. int j;
  1399. wgetdefwinsize(&i, &j);
  1400. j = j/wlineheight() -1;
  1401. for (i=0; i<j; i++) tearrow(help_ew->tp, WC_UP);
  1402. break;
  1403. }
  1404. }
  1405. break;
  1406. case WE_MENU:
  1407. switch (e.u.m.id) {
  1408. case ADMIN_MENU:
  1409. switch (e.u.m.item) {
  1410. case MMHelp:
  1411. if (help_length) helpwindow(0);
  1412. break;
  1413. case MMHelpSel:
  1414. help_selection(ew);
  1415. break;
  1416. }
  1417. break;
  1418. case EDIT_MENU:
  1419. switch (e.u.m.item) {
  1420. case MMCopy:
  1421. ewcopy(ew);
  1422. break;
  1423. case MMSelAll:
  1424. tesetfocus(ew->tp, 0,
  1425. tegetlen(ew->tp));
  1426. break;
  1427. }
  1428. break;
  1429. case HELP_MENU:
  1430. helpwindow(e.u.m.item);
  1431. break;
  1432. }
  1433. break;
  1434. case WE_COMMAND:
  1435. switch (e.u.command) {
  1436. case WC_CANCEL:
  1437. interrupt_pending = YES;
  1438. break;
  1439. case WC_RETURN:
  1440. help_selection(ew);
  1441. break;
  1442. case WC_DEL:
  1443. case WC_BACKSPACE:
  1444. helpwindow(0);
  1445. break;
  1446. default:
  1447. ewevent(ew, &e, &closed);
  1448. break;
  1449. }
  1450. if (e.u.command != WC_CLOSE) {
  1451. break;
  1452. }
  1453. case WE_CLOSE:
  1454. help_ew->saved = TRUE; /* Fake it */
  1455. free(help_buff);
  1456. ewclose(help_ew);
  1457. help_ew = 0;
  1458. break;
  1459. default:
  1460. ewevent(ew, &e, &closed);
  1461. if (closed) {
  1462. help_ew->saved = TRUE; /* Fake it */
  1463. free(help_buff);
  1464. ewclose(help_ew);
  1465. help_ew = 0;
  1466. }
  1467. break;
  1468. }
  1469. }
  1470. else if (ew != NULL) ewevent(ew, &e, &closed);
  1471. else wfleep();
  1472. fixmenus();
  1473. }
  1474. }
  1475. void flush_screen(void)
  1476. {
  1477. TEXTEDIT* tp = CSL_ew->tp;
  1478. if (stdout_n != 0) {
  1479. /* fprintf(stderr, stdout_buffer); */
  1480. ewreplace(CSL_ew, stdout_buffer);
  1481. stdout_n = 0; stdout_p = stdout_buffer;
  1482. }
  1483. if (tp->nlines > max_nlines+5) { /* Allow a five line slop */
  1484. techangefocus(tp, 0, zsubgap(tp->start[tp->nlines-max_nlines]));
  1485. tp->aim= UNDEF;
  1486. tp->focprev= FALSE;
  1487. /* ewreplace(CSL_ew, ""); */
  1488. tereplace(tp, "");
  1489. /* fprintf(stderr, "-> %d\n", tp->nlines); */
  1490. /* focus to end */
  1491. tesetfocus(tp, tp->buflen - tp->gaplen, -1);
  1492. }
  1493. wupdate(CSL_window);
  1494. }
  1495. static clock_t prev_clock = 0;
  1496. void accept_tick(void)
  1497. {
  1498. clock_t t0 = clock();
  1499. #ifdef SOFTWARE_TICKS_PER_SECOND
  1500. software_tick_count++;
  1501. #endif
  1502. #ifdef SOFTWARE_TICKS_PER_SECOND
  1503. if (prev_clock != 0)
  1504. { double t1 = (double)(t0-prev_clock)/(double)CLOCKS_PER_SEC;
  1505. double ratio =
  1506. (double)(software_tick_count - prev_software_tick_count)/t1;
  1507. int32 w;
  1508. /*
  1509. * t1 is how long since I was last here, ratio is the number of
  1510. * ticks per second over that time-span.
  1511. */
  1512. ratio = ratio / (double)SOFTWARE_TICKS_PER_SECOND;
  1513. prev_software_tick_count = software_tick_count;
  1514. /*
  1515. * Now ratio is the extent by which I was taking ticks too fast.
  1516. * To dampen out my correction I will scale software_ticks by the
  1517. * square root of this.
  1518. */
  1519. ratio = sqrt(ratio);
  1520. w = (int)(1000.0 * ratio);
  1521. /*
  1522. * I clamp the correction fator so I never adjust my clock rate by
  1523. * a factor of more than (about) 3.
  1524. */
  1525. if (w > 3000) w = 3000;
  1526. else if (w < 300) w = 300;
  1527. /*
  1528. * Furthermore I attempt to keep software_ticks within integer range.
  1529. */
  1530. if (software_ticks < (0x7fffffff/3000) &&
  1531. software_ticks > 50)
  1532. software_ticks = (w*software_ticks)/1000;
  1533. }
  1534. #endif
  1535. /*
  1536. * This is where I can put things that need to be done regularly.
  1537. * This will need to involve prodding the window manager etc etc.
  1538. * At present I do NOTHING...
  1539. */
  1540. t0 = clock();
  1541. remove_ticker();
  1542. if (t0 > prev_clock + CLOCKS_PER_SEC) {
  1543. /*
  1544. * Time spent doing all of this is counted as "overhead" or "system time"
  1545. * and not included in the times that I will report to my users...
  1546. */
  1547. if (clock_stack == &consolidated_time[0]) {
  1548. consolidated_time[0] +=
  1549. ((double)(clock_t)(t0 - base_time))/((double)CLOCKS_PER_SEC);
  1550. base_time = clock();
  1551. }
  1552. report_time((int32)(100.0*consolidated_time[0]), (int32)(100.0*gc_time));
  1553. }
  1554. push_clock();
  1555. wupdate(CSL_window);
  1556. poll_for_attn();
  1557. polltick_pending = NO;
  1558. ensure_screen();
  1559. add_ticker();
  1560. pop_clock();
  1561. return;
  1562. }
  1563. static char time_string[32], space_string[32];
  1564. void report_time(int32 t, int32 gct)
  1565. {
  1566. sprintf(time_string, "%d.%.2d secs", t/100, t%100);
  1567. wmenusetitem(adminmenu, MMTime, time_string);
  1568. sprintf(time_string, "+ %d.%.2d secs", gct/100, gct%100);
  1569. wmenusetitem(adminmenu, MMOTime, time_string);
  1570. }
  1571. void report_space(int gc_count, double percent)
  1572. {
  1573. sprintf(space_string, "[GC %d]:%.2f%%", gc_count, percent);
  1574. wmenusetitem(adminmenu, MMSpace, space_string);
  1575. }
  1576. #ifndef HAVE_UNIVERSAL_HEADERS
  1577. #define ModalFilterUPP ProcPtr
  1578. #define NewModalFilterProc(x) ((ProcPtr)x)
  1579. #endif
  1580. extern pascal Boolean
  1581. filter_addnl(DialogPtr, EventRecord, short *);
  1582. void pause_for_user(void)
  1583. /*
  1584. * This is called at the end of a run so that the user gets a chance to read
  1585. * the final screen-full of output. It pops up a dialog box that will
  1586. * wait for a button push. I take the view that if output is going to a
  1587. * file then the delay is not needed, since the user can always check for
  1588. * messages there. This has the effect that non-interactive build sequences
  1589. * will often run without the pause - a good thing! Note however that this
  1590. * mean that you MUST use the close box to exit from a wimp session. Just
  1591. * "quit;" or "(stop 0)" will not do.
  1592. */
  1593. {
  1594. ModalFilterUPP filterupp = NewModalFilterProc(filter_addnl);
  1595. remove_ticker();
  1596. ensure_screen();
  1597. CSL_ew->saved = TRUE; /* Fake it */
  1598. if (spool_file != NULL) return;
  1599. /*
  1600. * Here I just loop handling events until the user hits the CLOSE box
  1601. * on my window.
  1602. */
  1603. /* wmessage("Leaving Reduce 3.7"); */
  1604. set_arrow();
  1605. Alert(128, filterupp);
  1606. ewclose(CSL_ew);
  1607. wdone();
  1608. }
  1609. int wimpget(char *tty_buffer)
  1610. /*
  1611. * This is the main call from the body of CSL into the window manager
  1612. * to obtain input from the user. It is expected to copy some input
  1613. * characters into tty_buffer and return the number of characters
  1614. * provided. In this implementation I read the text back from the
  1615. * stdwin textedit buffer, looking rather too low.
  1616. * Any type ahead is handled in here.
  1617. */
  1618. {
  1619. TEXTEDIT* tp = CSL_ew->tp;
  1620. int i;
  1621. int n;
  1622. int lineno;
  1623. tty_nnl = 1; /* Offset from nlines */
  1624. push_clock();
  1625. remove_ticker();
  1626. if (stdout_n != 0) flush_screen();
  1627. wmenuattach(CSL_window, loadmenu);
  1628. wmenuattach(CSL_window, libmenu);
  1629. wmenuattach(CSL_window, switchmenu);
  1630. lineno = tp->nlines-1; /* Need to do this after the toend */
  1631. tty_offset = tp->foc - tp->start[lineno];
  1632. if (tty_offset<0) tty_offset += tp->gaplen;
  1633. wmenuenable(adminmenu, MMPause, NO);
  1634. if(tty_index>0) {
  1635. int i = 0;
  1636. for (; i<tty_index; i++)
  1637. if (tty_buff[i] == '\n') tty_nnl++;
  1638. tty_buff[tty_index] = '\0';
  1639. ewreplace(CSL_ew, tty_buff);
  1640. tty_index = 0;
  1641. }
  1642. event_loop();
  1643. /* fprintf(stderr, "Event loop ended\n"); */
  1644. lineno = tp->nlines-tty_nnl;
  1645. /* fprintf(stderr, "Offset=%d Length=%d\n",
  1646. tty_offset,
  1647. tp->foc- tp->start[lineno]-tty_offset);
  1648. for (i=0; i<tp->foc- tp->start[lineno]-tty_offset; i++) {
  1649. fprintf(stderr, "%c", *(tegettext(tp)+tp->start[lineno]+tty_offset+i));
  1650. }
  1651. fprintf(stderr, "\n"); */
  1652. memcpy(tty_buffer, tegettext(tp)+tp->start[lineno]+tty_offset,
  1653. tp->foc- tp->start[lineno]-tty_offset);
  1654. wmenudetach(CSL_window, loadmenu);
  1655. wmenudetach(CSL_window, libmenu);
  1656. wmenudetach(CSL_window, switchmenu);
  1657. wmenuenable(adminmenu, MMPause, YES);
  1658. add_ticker();
  1659. n = tp->foc- tp->start[lineno]-tty_offset;
  1660. if (n<0) {
  1661. n += tp->gaplen;
  1662. fprintf(stderr, "N correction\n");
  1663. }
  1664. tty_ready = NO;
  1665. pop_clock();
  1666. return n;
  1667. }
  1668. int char_cnt = 0;
  1669. void putc_stdout(int c)
  1670. {
  1671. *stdout_p++ = c;
  1672. *stdout_p = 0;
  1673. stdout_n++;
  1674. char_cnt++;
  1675. remove_ticker();
  1676. if (c == '\n' || stdout_n > STDOUT_BUFSIZE - LONGEST_PRINTF) {
  1677. push_clock(); flush_screen();
  1678. if (char_cnt>200) { /* Where 200 is a random number */
  1679. poll_for_attn(); char_cnt = 0;
  1680. }
  1681. pop_clock();
  1682. }
  1683. if (polltick_pending) accept_tick();
  1684. add_ticker();
  1685. }
  1686. void vfprintf_stdout(char *fmt, va_list a)
  1687. {
  1688. int n;
  1689. /*
  1690. * I have given myself LONGEST_PRINTF locations in the array for
  1691. * this vsprintf to fill in. If it overflows I am in big trouble!
  1692. */
  1693. n = vsprintf(stdout_p, fmt, a);
  1694. stdout_p += n;
  1695. stdout_n += n;
  1696. char_cnt += n;
  1697. remove_ticker();
  1698. if (stdout_n > STDOUT_BUFSIZE - LONGEST_PRINTF) {
  1699. push_clock(); flush_screen();
  1700. if (char_cnt>200) {
  1701. poll_for_attn(); char_cnt = 0;
  1702. }
  1703. pop_clock();
  1704. }
  1705. if (polltick_pending) accept_tick();
  1706. add_ticker();
  1707. }
  1708. #define NARGS 25
  1709. static char *argv[NARGS+1];
  1710. static char argbuf[256];
  1711. /*
  1712. * init_command_line - prepare initial command line
  1713. *
  1714. * The command line is preset to show the name of the program.
  1715. * The program name is quoted as necessary.
  1716. *
  1717. */
  1718. static char*
  1719. init_command_line(char *buf1, char *buf2)
  1720. {
  1721. register char *s, *t = buf2;
  1722. int c, space = 0, dquote = 0, squote = 0, quote = 0;
  1723. sprintf(s = buf1, "%#s", LMGetCurApName());
  1724. while (c = *s++) {
  1725. if (c == ' ')
  1726. space = 1;
  1727. else if (c == '"')
  1728. dquote = 1;
  1729. else if (c == '\'')
  1730. squote = 1;
  1731. }
  1732. if (space || dquote || squote)
  1733. *t++ = quote = dquote && !squote ? '\'' : '"';
  1734. for (s = buf1; c = *s++; *t++ = c) {
  1735. if (c == quote || c == '\\')
  1736. *t++ = '\\';
  1737. }
  1738. if (quote)
  1739. *t++ = quote;
  1740. *t++ = ' ';
  1741. *t++ = 0;
  1742. return t;
  1743. }
  1744. /*
  1745. * parse - divide command line into "words"
  1746. *
  1747. * Words are delimited by one or more spaces. Any characters within
  1748. * matching single (') or double (") quotes are taken literally. Any
  1749. * character preceded by a backslash (\) is taken literally.
  1750. *
  1751. */
  1752. static int
  1753. parse(char *s, char *t)
  1754. {
  1755. int c, quote = 0, argc = 0;
  1756. while (c = *s++) {
  1757. if (c == ' ')
  1758. continue;
  1759. if (argc < NARGS)
  1760. argv[argc++] = t;
  1761. do {
  1762. if (c == '\\' && *s)
  1763. c = *s++;
  1764. else if (c == '"' || c == '\'') {
  1765. if (!quote) {
  1766. quote = c;
  1767. continue;
  1768. }
  1769. if (c == quote) {
  1770. quote = 0;
  1771. continue;
  1772. }
  1773. }
  1774. *t++ = c;
  1775. } while (*s && ((c = *s++) != ' ' || quote));
  1776. *t++ = 0;
  1777. }
  1778. return(argc);
  1779. }
  1780. #ifdef OLD
  1781. int wgetargs(char ***av)
  1782. {
  1783. short i, argc;
  1784. char buf[256];
  1785. char *t = init_command_line(buf, argbuf);
  1786. if( !waskstr(" Arguments for REDUCE 3.7", t, 256)) exit(1);
  1787. t[-1] = ' ';
  1788. sprintf(buf, "%s", argbuf);
  1789. argc = parse(buf, argbuf);
  1790. *av = argv;
  1791. /* for(i=0;i<argc; i++) wmessage(argv[i]); */
  1792. return(argc);
  1793. }
  1794. #else
  1795. enum { /* Dialog names for main box */
  1796. exDEF = 3,
  1797. exLOG,
  1798. exVER,
  1799. exXTA
  1800. };
  1801. enum { /* Dialog names for additional box */
  1802. exBAT = 3,
  1803. exBAC,
  1804. exTRA,
  1805. exCLD,
  1806. exLAP,
  1807. exQUI,
  1808. exREC,
  1809. exRED,
  1810. exRAN,
  1811. exSIZ,
  1812. exOTH,
  1813. exLGG,
  1814. exDFF,
  1815. exVBE
  1816. };
  1817. /*
  1818. * get_args - process "command line"
  1819. *
  1820. */
  1821. /* Dialog numbers */
  1822. #define START_1 (129)
  1823. #define START_2 (128)
  1824. /*Rect bounds = {60, 20, 320, 220};
  1825. Rect boundx = {80, 30, 400, 500};
  1826. */
  1827. int DoExtra(char ***av)
  1828. {
  1829. DialogPtr dd;
  1830. short i;
  1831. int verbos = 0;
  1832. int deflt = 0;
  1833. int logging = 0;
  1834. char buff[256];
  1835. char name[256];
  1836. char nams[256];
  1837. Rect box;
  1838. short type;
  1839. Handle item;
  1840. char *t = init_command_line(buff, argbuf);
  1841. char *s = t-1;
  1842. int argc;
  1843. ModalFilterUPP filterupp = NewModalFilterProc(filter_addnl);
  1844. int batch =0, back = 0, cold = 0, lap = 0, quiet = 0;
  1845. int trap = 0, recover = 0, redirect = 0;
  1846. /* ee = NewDialog(NULL, &boundx, "\p", 1, 1, (WindowPtr)-1, 0, 256L,
  1847. GetResource('DITL',132)); */
  1848. dd = GetNewDialog(START_2, NULL, (WindowPtr)-1);
  1849. GetDItem(dd, 1, &type, &item, &box);
  1850. SetPort(dd);
  1851. InsetRect(&box, -4, -4);
  1852. PenSize(3, 3);
  1853. FrameRoundRect(&box, 16, 16);
  1854. set_arrow();
  1855. do { /* engage in dialog */
  1856. ModalDialog(filterupp, &i);
  1857. switch (i) {
  1858. case cancel:
  1859. DisposDialog(dd);
  1860. exit(0);
  1861. case exBAT:
  1862. batch = !batch;
  1863. GetDItem(dd, exBAT, &type, &item, &box);
  1864. SetCtlValue((struct ControlRecord **)item, batch);
  1865. break;
  1866. case exBAC:
  1867. back = !back;
  1868. GetDItem(dd, exBAC, &type, &item, &box);
  1869. SetCtlValue((struct ControlRecord **)item, back);
  1870. break;
  1871. case exTRA:
  1872. trap = !trap;
  1873. GetDItem(dd, exTRA, &type, &item, &box);
  1874. SetCtlValue((struct ControlRecord **)item, trap);
  1875. break;
  1876. case exCLD:
  1877. cold = !cold;
  1878. GetDItem(dd, exCLD, &type, &item, &box);
  1879. SetCtlValue((struct ControlRecord **)item, cold);
  1880. break;
  1881. case exLAP:
  1882. lap = !lap;
  1883. GetDItem(dd, exLAP, &type, &item, &box);
  1884. SetCtlValue((struct ControlRecord **)item, lap);
  1885. break;
  1886. case exQUI:
  1887. quiet = !quiet;
  1888. GetDItem(dd, exQUI, &type, &item, &box);
  1889. SetCtlValue((struct ControlRecord **)item, quiet);
  1890. break;
  1891. case exREC:
  1892. recover = !recover;
  1893. GetDItem(dd, exREC, &type, &item, &box);
  1894. SetCtlValue((struct ControlRecord **)item, recover);
  1895. break;
  1896. case exRED:
  1897. redirect = waskfile("Redirection File: ", nams, 256, 1);
  1898. break;
  1899. case exLGG:
  1900. logging = waskfile("Log File: ", name, 256, 1);
  1901. break;
  1902. case exDFF:
  1903. deflt = !deflt;
  1904. GetDItem(dd, exDFF, &type, &item, &box);
  1905. SetCtlValue((struct ControlRecord **)item, deflt);
  1906. break;
  1907. case exVBE:
  1908. verbos = !verbos;
  1909. GetDItem(dd, exVBE, &type, &item, &box);
  1910. SetCtlValue((struct ControlRecord **)item, verbos);
  1911. break;
  1912. }
  1913. } while (i != ok);
  1914. if (batch) { strcpy(t, " -b"); t += 3; }
  1915. if (back) { strcpy(t, " -g"); t += 3; }
  1916. if (cold) { strcpy(t, " -z"); t += 3; }
  1917. if (lap) { strcpy(t, " -s"); t += 3; }
  1918. if (quiet) { strcpy(t, " -q"); t += 3; }
  1919. if (recover) { strcpy(t, " -y"); t += 3; }
  1920. if (trap) { strcpy(t, " -x"); t += 3; }
  1921. if (verbos) { strcpy(t, " -v"); t += 3; }
  1922. if (logging) { strcpy(t, " -l"); t += 3;
  1923. strcpy(t, name); t += strlen(name);
  1924. }
  1925. if (redirect) { strcpy(t, " --"); t += 3;
  1926. strcpy(t, nams); t += strlen(nams);
  1927. }
  1928. {
  1929. char bb[256];
  1930. GetDItem(dd, exRAN, &type, &item, &box);
  1931. GetIText(item, (unsigned char *)bb);
  1932. #ifndef CLEVERGLUE
  1933. P2CStr((unsigned char *)bb);
  1934. #endif
  1935. if (bb[0]!='\0') {
  1936. strcpy(t, " -r"); t += 3;
  1937. strcpy(t, bb); t += strlen(bb);
  1938. }
  1939. GetDItem(dd, exSIZ, &type, &item, &box);
  1940. GetIText(item, (unsigned char *)bb);
  1941. #ifndef CLEVERGLUE
  1942. P2CStr((unsigned char *)bb);
  1943. #endif
  1944. if (bb[0]!='\0') {
  1945. strcpy(t, " -k"); t += 3;
  1946. strcpy(t, bb); t += strlen(bb);
  1947. }
  1948. GetDItem(dd, exOTH, &type, &item, &box);
  1949. GetIText(item, (unsigned char *)bb);
  1950. #ifndef CLEVERGLUE
  1951. P2CStr((unsigned char *)bb);
  1952. #endif
  1953. if (bb[0]!='\0') {
  1954. strcpy(t, bb); t += strlen(bb);
  1955. }
  1956. }
  1957. out:
  1958. DisposDialog(dd);
  1959. if (!deflt) *s = ' ';
  1960. sprintf(buff, "%s", argbuf);
  1961. argc = parse(buff, argbuf);
  1962. *av = argv;
  1963. /* for(i=0;i<argc; i++) wmessage(argv[i]); */
  1964. return(argc);
  1965. }
  1966. int wgetargs(char ***av)
  1967. {
  1968. DialogPtr dd;
  1969. short i;
  1970. int verbos = 0;
  1971. int deflt = 0;
  1972. int logging = 0;
  1973. char buff[256];
  1974. char name[256];
  1975. char nams[256];
  1976. int p = 0;
  1977. Rect box;
  1978. short type;
  1979. Handle item;
  1980. char *t = init_command_line(buff, argbuf);
  1981. char *s = t-1;
  1982. int argc;
  1983. ModalFilterUPP filterupp = NewModalFilterProc(filter_addnl);
  1984. /* dd = NewDialog(NULL, &bounds, "\p", 1, 1, (WindowPtr)-1, 0, 256L,
  1985. GetResource('DITL',131)); */
  1986. dd = GetNewDialog(START_1, NULL, (WindowPtr)-1);
  1987. GetDItem(dd, 1, &type, &item, &box);
  1988. SetPort(dd);
  1989. InsetRect(&box, -4, -4);
  1990. PenSize(3, 3);
  1991. FrameRoundRect(&box, 16, 16);
  1992. set_arrow();
  1993. do { /* engage in dialog */
  1994. ModalDialog(filterupp, &i);
  1995. switch (i) {
  1996. case cancel:
  1997. DisposDialog(dd);
  1998. exit(0);
  1999. case exDEF:
  2000. deflt = !deflt;
  2001. break;
  2002. case exVER:
  2003. verbos = !verbos;
  2004. GetDItem(dd, exVER, &type, &item, &box);
  2005. SetCtlValue((struct ControlRecord **)item, verbos);
  2006. break;
  2007. case exLOG:
  2008. logging = waskfile("Log File: ", name, 256, 1);
  2009. break;
  2010. case exXTA:
  2011. set_watch();
  2012. DisposDialog(dd);
  2013. return DoExtra(av);
  2014. }
  2015. } while (i != ok);
  2016. set_watch();
  2017. {
  2018. char aa[256];
  2019. if (verbos) {
  2020. strcpy(t, " -v");
  2021. t += 3; }
  2022. if (logging) {
  2023. strcpy(t, " -l"); t += 3;
  2024. strcpy(t, name); p += strlen(aa);
  2025. }
  2026. }
  2027. if (!deflt) *s = ' ';
  2028. DisposDialog(dd);
  2029. sprintf(buff, "%s", argbuf);
  2030. argc = parse(buff, argbuf);
  2031. *av = argv;
  2032. /* for(i=0;i<argc; i++) wmessage(argv[i]); */
  2033. return(argc);
  2034. }
  2035. #endif
  2036. /* end of sysmac.c */