home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / cshar_sc.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  115.6 KB  |  4,583 lines

  1. 18-Jun-88 14:43:04-MDT,122930;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:40:11 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22566; Sat, 18 Jun 88 14:40:04 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24739; Sat, 18 Jun 88 14:39:51 MDT
  8. Date: Sat, 18 Jun 88 14:39:51 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182039.AA24739@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: SciHelper.c.shar
  13.  
  14. #! /bin/sh
  15. #
  16. # This is a shell archive.  Save this into a file, edit it
  17. # and delete all lines above this comment.  Then give this
  18. # file to sh by executing the command "sh file".  The files
  19. # will be extracted into the current directory owned by
  20. # you with default permissions.
  21. #
  22. # The files contained herein are:
  23. #
  24. #    2 SHInfo
  25. #    1 DiskContents
  26. #   12 regcmdloop.c
  27. #   11 reggauss.c
  28. #    7 reggraph.c
  29. #   19 regio.c
  30. #   21 regmain.c
  31. #   20 regmanip.c
  32. #    4 regmenu.c
  33. #   14 regprim.c
  34. #    1 regtab.m
  35. #
  36. echo 'Extracting SHInfo'
  37. if test -f SHInfo; then echo 'shar: will not overwrite SHInfo'; else
  38. sed 's/^X//' << '________This_Is_The_END________' > SHInfo
  39. XSubject: "Scientist's Helper" program source.          File 1 of 7
  40. X
  41. XScientist's Helper is a data-analysis and graphing program written
  42. Xby William Menke of the Oceanography Department of Oregon State
  43. XUniversity.  While it isn't StatView, the source is available.
  44. XIt's written in Aztec C.  Conversion to other formats is encouraged.
  45. X
  46. XBesides simple graphing and data reduction, it will do multiple
  47. Xregressions, filtering, Fourier transforms, and other stuff too;
  48. Xand operations on the output of those operations.
  49. X
  50. XMail to me, or to Dr. Menke, by USENET or USSnail, respectively.
  51. X
  52. X***All files have been processed by BinHex 4.0 and PackIt_II.***
  53. X
  54. XFiles:        ***    1: Description, and odds & ends
  55. X        2: Include file "all.h"
  56. X        3: Sources: reg{cmdloop,gauss,graph,io}.c
  57. X        4: Sources: reg{main,manip,menu,prim}.c
  58. X        5: Sources: reg{proc,series,spline,table,wnd}.c
  59. X        6. Scientist's Helper appl. v2.7, 1st Half
  60. X        7: Scientist's Helper appl. v2.7, 2nd Half
  61. X
  62. XNathan C. Myers        {tektronix|hplabs!hp-pcd}!orstcs!nathan
  63. X780 NW 11th St.        nathan@oregon-state
  64. XCorvallis, OR 97330    (503) 753-5110
  65. X
  66. ________This_Is_The_END________
  67. if test `wc -l < SHInfo` -ne 27; then
  68.     echo 'shar: SHInfo was damaged during transit'
  69.   echo '      (should have been 27 bytes)'
  70. fi
  71. fi        ; : end of overwriting check
  72. echo 'Extracting DiskContents'
  73. if test -f DiskContents; then echo 'shar: will not overwrite DiskContents'; else
  74. sed 's/^X//' << '________This_Is_The_END________' > DiskContents
  75. XDiskette Contents:
  76. X
  77. X
  78. X
  79. X1) A series of text files with names of the form reg___.c which are the
  80. Xsource code of scientists helper.  These are written in Manx Aztec C and
  81. Xshould be compiled with the statement:  cc -z3000 reg___.c
  82. X
  83. X
  84. X
  85. X2) Three include files, that define the toolkit utilities and the special data
  86. Xstructures used by Scientist's Helper
  87. X
  88. X
  89. X
  90. X3) An input file for the Resource Compiler (RGEN) called regtab.r
  91. X
  92. X
  93. X
  94. X4) A shell script, regtab.m, that links and rgen's the object code into a
  95. Xclickable program.
  96. X
  97. X
  98. X
  99. X5) A program called SetBundle, that lets you set the bundle bit of a file so
  100. Xthat its icon will appear in the desktop.  This program will only work if
  101. Xthe Aztec terminal driver is installed in your system.
  102. X
  103. X
  104. X
  105. X6) Edit, a text editor suitable for examining and editing programs (it's
  106. Xsimilar to MacWrite, except it doesn't wrap text and processes files of
  107. Xresource type TEXT (not MACA).
  108. X
  109. X
  110. X
  111. ________This_Is_The_END________
  112. if test `wc -l < DiskContents` -ne 36; then
  113.     echo 'shar: DiskContents was damaged during transit'
  114.   echo '      (should have been 36 bytes)'
  115. fi
  116. fi        ; : end of overwriting check
  117. echo 'Extracting regcmdloop.c'
  118. if test -f regcmdloop.c; then echo 'shar: will not overwrite regcmdloop.c'; else
  119. sed 's/^X//' << '________This_Is_The_END________' > regcmdloop.c
  120. X#include "all.h"
  121. X#include "regtabext.h"
  122. X
  123. XCmdFromWnd(c, fromCommandWindow)
  124. Xchar c[];
  125. Xint fromCommandWindow;
  126. X{
  127. X    if( c[0]=='>' ) { /* get rid of prompt */
  128. X        c[0]=' ';
  129. X        }
  130. X    RegTabCmd( c, fromCommandWindow );
  131. X}
  132. X
  133. XRegTabCmd( c, fromCommandWindow )
  134. Xchar c[];
  135. Xint fromCommandWIndow;
  136. X{
  137. X    int i, j, k, ii, jj;
  138. X    float x, y;
  139. X    char s[cmdWordLen];
  140. X    
  141. X    strncpy( command.cmdStr, c, cmdWordLen-1 );
  142. X    command.cmdStr[cmdWordLen-1] = '\0'; /*just in case*/
  143. X    if( !SBreak(&command, TRUE) ) {
  144. X        WriteLine("bad command line");
  145. X        ErrMsg(command.cmdStr);
  146. X        }
  147. X    strcpy( cmdWord0, command.cmdWord[0] );
  148. X    
  149. X    /*special code to handle case of pending input*/
  150. X    /*several commands ask for input, including the cursor and input commands*/
  151. X    if( pendingFlag ) {
  152. X        pendingFlag=FALSE;
  153. X        NoPendingInput();
  154. X        if( strlen(pentName)!=0 ) {
  155. X            if( !SetVar(pentName,cmdWord0) ) {
  156. X                ErrMsg("couldnt set input variable");
  157. X                }
  158. X            }
  159. X        }
  160. X    else {
  161. X        
  162. X    if( (strlen(cmdWord0)==0) || (strcmp(cmdWord0,"label")==0) ) {
  163. X        ; /*do nothing*/
  164. X        }
  165. X    else if( strcmp(cmdWord0,"quit")==0 ) {
  166. X        doneFlag = TRUE;
  167. X        }
  168. X    else if( (strcmp(cmdWord0,"p")==0) || (strcmp(cmdWord0,"prompt")==0) ) {
  169. X        for( i=1; i<(numCmdWds-1); i++ ) {
  170. X            if(strlen(command.cmdWord[i])!=0) WritePhrase( command.cmdWord[i] );
  171. X            }
  172. X        WriteLine( command.cmdWord[numCmdWds-1] );
  173. X        }
  174. X    else if ( strcmp(cmdWord0,"beep")==0 ) {
  175. X        SysBeep(5);
  176. X        }
  177. X    else if( strcmp(cmdWord0,"setvar")==0 ) {
  178. X        if( !SetVar( command.cmdWord[1], command.cmdWord[2] ) ) {
  179. X            ErrMsg("couldnt create variable");
  180. X            }
  181. X        }
  182. X    else if( strcmp(cmdWord0,"delete")==0 ) {
  183. X        if( (strcmp(command.cmdWord[1],"v")==0) || (strcmp(command.cmdWord[1],"variable")==0) ){
  184. X            if( !DelVar( command.cmdWord[2] ) ) {
  185. X                ErrMsg("couldnt delete variable");
  186. X                }
  187. X            }
  188. X        else {
  189. X            DelCommand();
  190. X            RedoEditWindow();
  191. X            }
  192. X        }
  193. X    else if( (strcmp(cmdWord0,"t")==0) || (strcmp(cmdWord0,"type")==0) ) {
  194. X        if( (strcmp(command.cmdWord[1],"v")==0) || (strcmp(command.cmdWord[1],"variables")==0) ) {
  195. X            ListVars();
  196. X            }
  197. X        else if( (strcmp(command.cmdWord[1],"c")==0) || (strcmp(command.cmdWord[1],"col")==0) ) {
  198. X            SToI( command.cmdWord[2], &i );
  199. X            if( GoodCol(i)!=0 ) {
  200. X                ErrMsg( noSuchColumn );
  201. X                }
  202. X            WriteLine( table.header.colName[i-1] );
  203. X            for( j=1; j<=table.header.rows; j++ ) {
  204. X                CheckAbortMenu();
  205. X                GetTable( j, i, &x );
  206. X                IToS( j, s );
  207. X                strcat( s, "   " );
  208. X                WritePhrase( s );
  209. X                RToS( x, s );
  210. X                WriteLine( s );
  211. X                }
  212. X            }
  213. X    
  214. X        else {
  215. X            ErrMsg( noSuchModifier );
  216. X            }
  217. X        }
  218. X    else if( strcmp(cmdWord0,"allocate")==0 ) {
  219. X        SToI( command.cmdWord[1], &i );
  220. X        SToI( command.cmdWord[2], &j );
  221. X        AllocTable( i, j );
  222. X        RedoEditWindow();
  223. X        }
  224. X    else if( strcmp(cmdWord0,"title")==0 ) {
  225. X        strcpy( table.header.title, command.cmdWord[1] );
  226. X        Header2Vars();
  227. X        }
  228. X    else if( strcmp(cmdWord0,"interpolated")==0 ) {
  229. X        if( (strlen(command.cmdWord[1])==0) || (strcmp(command.cmdWord[1],"true")==0) ) {
  230. X            table.header.interpolated = TRUE;
  231. X            }
  232. X        else if( strcmp(command.cmdWord[1],"false")==0 ) {
  233. X            table.header.interpolated = FALSE;
  234. X            }
  235. X        else {
  236. X            ErrMsg( noSuchModifier );
  237. X            }
  238. X        Header2Vars();
  239. X        CreateCol1();
  240. X        RedoEditWindow();
  241. X        }
  242. X    else if( strcmp(cmdWord0,"rows")==0 ) {
  243. X        SToI( command.cmdWord[1], &i );
  244. X        if( GoodRow(i)==2 ) {
  245. X            ErrMsg( noSuchRow );
  246. X            }
  247. X        else {
  248. X            j = table.header.rows;
  249. X            table.header.rows = i;
  250. X            Header2Vars();
  251. X            if( j<i ) {
  252. X                CreateCol1();
  253. X                }
  254. X            RedoEditWindow();
  255. X            }
  256. X        }
  257. X    else if( strcmp(cmdWord0,"cols")==0 ) {
  258. X        SToI( command.cmdWord[1], &i );
  259. X        if( GoodCol(i)==2 ) {
  260. X            ErrMsg( noSuchCol );
  261. X            }
  262. X        else {
  263. X            table.header.cols = i;
  264. X            Header2Vars();
  265. X            RedoEditWindow();
  266. X            }
  267. X        }
  268. X    else if( strcmp(cmdWord0,"start")==0 ) {
  269. X        SToR( command.cmdWord[1], &x, FALSE );
  270. X        table.header.start = x;
  271. X        Header2Vars();
  272. X        CreateCol1();
  273. X        RedoEditWindow();
  274. X        }
  275. X    else if( strcmp(cmdWord0,"samp")==0 ) {
  276. X        SToR( command.cmdWord[1], &x, FALSE );
  277. X        if( x==0.0 ) {
  278. X            ErrMsg("samp cant be zero");
  279. X            }
  280. X        table.header.samp = x;
  281. X        Header2Vars();
  282. X        CreateCol1();
  283. X        RedoEditWindow();
  284. X        }
  285. X    else if( strcmp(cmdWord0,"colname")==0 ) {
  286. X        SToI( command.cmdWord[1], &i );
  287. X        if( GoodCol(i)!=0 ) {
  288. X            ErrMsg( noSuchCol );
  289. X            }
  290. X        strcpy( s, command.cmdWord[2] );
  291. X        s[10] = '\0'; /*just in case its too long*/
  292. X        strcpy( table.header.colName[i-1], s );
  293. X        RedoEditWindow();
  294. X        }
  295. X    else if( strcmp(cmdWord0,"table")==0 ) {
  296. X        SToI( command.cmdWord[1], &i );
  297. X        SToI( command.cmdWord[2], &j );
  298. X        if( strlen(command.cmdWord[3])==0 ) {
  299. X            GetTable(i, j, &x);
  300. X            RToS( x, s );
  301. X            WriteLine( s );
  302. X            }
  303. X        else {
  304. X            SToR( command.cmdWord[3], &x, TRUE );
  305. X            SetTable( i, j, x, FALSE );
  306. X            RedoEditWindow();
  307. X            }
  308. X        }
  309. X    else if( strcmp(cmdWord0,"set")==0 ) {
  310. X        if( strcmp(command.cmdWord[2],"table")==0 ) {
  311. X            SToI( command.cmdWord[3], &i );
  312. X            SToI( command.cmdWord[4], &j );
  313. X            GetTable(i, j, &x);
  314. X            RToS( x, s );
  315. X            if( !SetVar( command.cmdWord[1],s) ) {
  316. X                ErrMsg("couldnt create variable");
  317. X                }
  318. X            }
  319. X        else if( strcmp(command.cmdWord[2],"colname")==0 ) {
  320. X            SToI( command.cmdWord[3], &i );
  321. X            if( GoodCol(i)!=0 ) {
  322. X                ErrMsg( noSuchColumn );
  323. X                }
  324. X            if( !SetVar(command.cmdWord[1],table.header.colName[i-1]) ) {
  325. X                ErrMsg("couldnt create variable");
  326. X                }
  327. X            }
  328. X        else if( strcmp(command.cmdWord[2],"coefficient")==0 ) {
  329. X            SToI( command.cmdWord[3], &i );
  330. X            if( (i<0) || (i>nCoeffs) ) {
  331. X                ErrMsg( "no such coefficient" );
  332. X                }
  333. X            RToS( coeffs[i], s );
  334. X            if( !SetVar(command.cmdWord[1],s )) {
  335. X                ErrMsg("couldnt create variable");
  336. X                }
  337. X            }
  338. X        else {
  339. X            ErrMsg( noSuchModifier );
  340. X            }
  341. X        }
  342. X    else if ( (strcmp(cmdWord0,"x")==0) || (strcmp(cmdWord0,"execute")==0) ) {
  343. X        if( !mem.active ) {     /*calls from console construct new label list*/
  344. X            ListLabels();   /*calls from within procedure cannot change procedure memory*/
  345. X            PendingInput();
  346. X            mem.active = TRUE;
  347. X            }
  348. X        if( !FindLabel(command.cmdWord[1],&i) ) {
  349. X            ErrMsg( "cant find label" );
  350. X            }
  351. X        else if( mem.stackPtr >= (stackLen-1) ) {
  352. X            ErrMsg( "too many levels of procedures" );
  353. X            }
  354. X        mem.stackPtr++;
  355. X        mem.stack[mem.stackPtr] = i;
  356. X        i =  SetVar("arg1",command.cmdWord[2] ) && SetVar("arg2",command.cmdWord[3] )
  357. X            && SetVar("arg3",command.cmdWord[4] ) && SetVar("arg4",command.cmdWord[5] );
  358. X        if (!i) {
  359. X            ErrMsg("not enough space for argument variables");
  360. X            }
  361. X        }
  362. X    else if( strcmp(cmdWord0,"goto")==0 ) {
  363. X        if( !mem.active ) {
  364. X            ErrMsg("cant goto from console");
  365. X            }
  366. X        if( !FindLabel(command.cmdWord[1],&i) ) {
  367. X            ErrMsg( "cant find label" );
  368. X            }
  369. X        mem.stack[mem.stackPtr] = i;
  370. X        }
  371. X    else if( strcmp(cmdWord0,"return")==0 ) {
  372. X        ReturnCommand();
  373. X        }
  374. X    else if( strcmp(cmdWord0,"for")==0 ) {
  375. X        ForCommand();
  376. X        }
  377. X    else if( strcmp(cmdWord0,"next")==0 ) {
  378. X        NextCommand();
  379. X        }
  380. X    else if( strcmp(cmdWord0,"if")==0 ) {
  381. X        IfCommand();
  382. X        }
  383. X    else if( (strcmp(cmdWord0,"vm")==0) || (strcmp(cmdWord0,"vmath")==0) ) {
  384. X        VMathCommand();
  385. X        }
  386. X    else if( (strcmp(cmdWord0,"vf")==0) || (strcmp(cmdWord0,"vfunction")==0) ) {
  387. X        VFunctionCommand();
  388. X        }
  389. X    else if( strcmp(cmdWord0,"concat")==0 ) {
  390. X        strcpy(s,command.cmdWord[2]);
  391. X        for( i=3; i<numCmdWds; i++ ) {
  392. X            j=cmdWordLen - strlen(s) - 1;
  393. X            strncat(s,command.cmdWord[i],j);
  394. X            }
  395. X        if( !SetVar(command.cmdWord[1],s) ) {
  396. X            ErrMsg("couldnt create variable");
  397. X            }
  398. X        }
  399. X    else if( strcmp(cmdWord0,"sleep")==0 ) {
  400. X        SToR( command.cmdWord[1], &x, FALSE );
  401. X        i = (int)(x*60.0);
  402. X        Delay( (long)i, (long*)(&x));
  403. X        }
  404. X    else if( strcmp(cmdWord0,"input")==0 ) {
  405. X        WriteLine( command.cmdWord[2] );
  406. X        strcpy( pentName, command.cmdWord[1] );
  407. X        pendingFlag=TRUE;
  408. X        PendingInput();
  409. X        }
  410. X    else if( strcmp(cmdWord0,"cursor")==0 ) {
  411. X        WriteLine( command.cmdWord[1] );
  412. X        pentName[0]='\0';
  413. X        pendingFlag=TRUE;
  414. X        PendingInput();
  415. X        SelectWindow(theWindow[grWindow]);
  416. X        }
  417. X    else if( strcmp(cmdWord0,"xaxis")==0 ) {
  418. X        SToR( command.cmdWord[1], &x, FALSE);
  419. X        SToR( command.cmdWord[2], &y, FALSE);
  420. X        if( x<y ) {
  421. X            graph.xMin=x;
  422. X            graph.xMax=y;
  423. X            }
  424. X        else {
  425. X            ErrMsg("xmin > xmax");
  426. X            }
  427. X        Graph2Vars();
  428. X        }
  429. X    else if( strcmp(cmdWord0,"yaxis")==0 ) {
  430. X        SToR( command.cmdWord[1], &x, FALSE);
  431. X        SToR( command.cmdWord[2], &y, FALSE);
  432. X        if( x<y ) {
  433. X            graph.yMin=x;
  434. X            graph.yMax=y;
  435. X            }
  436. X        else {
  437. X            ErrMsg("ymin > ymax");
  438. X            }
  439. X        Graph2Vars();
  440. X        }
  441. X    else if( strcmp(cmdWord0,"plot")==0 ) {
  442. X        PlotCol();
  443. X        }
  444. X    else if( strcmp(cmdWord0,"clear")==0 ) {
  445. X        ClearGraph();
  446. X        }
  447. X    else if( strcmp(cmdWord0,"axes")==0 ) {
  448. X        PlotAxes();
  449. X        }
  450. X    else if( strcmp(cmdWord0,"insert")==0 ) {
  451. X        InsCommand();
  452. X        RedoEditWindow();
  453. X        }
  454. X    else if( strcmp(cmdWord0,"trend")==0 ) {
  455. X        Trend();
  456. X        RedoEditWindow();
  457. X        }
  458. X    else if( strcmp(cmdWord0,"interpolate")==0 ) {
  459. X        TabInterpolate();
  460. X        RedoEditWindow();
  461. X        }
  462. X    else if( strcmp(cmdWord0,"spline")==0 ) {
  463. X        SplInterpolate();
  464. X        RedoEditWindow();
  465. X        }
  466. X    else if( strcmp(cmdWord0,"sort")==0 ) {
  467. X        SortTable();
  468. X        RedoEditWindow();
  469. X        }
  470. X    else if( strcmp(cmdWord0,"polyfit")==0 ) {
  471. X        polyfit();
  472. X        RedoEditWindow();
  473. X        }
  474. X    else if( strcmp(cmdWord0,"multifit")==0 ) {
  475. X        multifit();
  476. X        RedoEditWindow();
  477. X        }
  478. X    else if( strcmp(cmdWord0,"noise")==0 ) {
  479. X        noise();
  480. X        RedoEditWindow();
  481. X        }
  482. X
  483. X    else if( strcmp(cmdWord0,"mean")==0 ) {
  484. X        Mean();
  485. X        RedoEditWindow();
  486. X        }
  487. X    else if( strcmp(cmdWord0,"swap")==0 ) {
  488. X        SwapCommand();
  489. X        RedoEditWindow();
  490. X        }
  491. X    else if( strcmp(cmdWord0,"copy")==0 ) {
  492. X        CopyCommand();
  493. X        RedoEditWindow();
  494. X        }
  495. X    else if( strcmp(cmdWord0,"scale")==0 ) {
  496. X        GScan();
  497. X        Graph2Vars();
  498. X        }
  499. X    else if( (strcmp(cmdWord0,"cm")==0) || (strcmp(cmdWord0,"cmath")==0) ) {
  500. X        ColMath();
  501. X        RedoEditWindow();
  502. X        }
  503. X    else if( (strcmp(cmdWord0,"cf")==0) || (strcmp(cmdWord0,"cfunction")==0) ) {
  504. X        ColFunction();
  505. X        RedoEditWindow();
  506. X        }
  507. X    else if( strcmp(cmdWord0,"min")==0 ) {
  508. X        SToI( command.cmdWord[1], &i );
  509. X        ColMin( i, &x );
  510. X        RToS( x, s ); 
  511. X        WriteLine(s);
  512. X        if( !SetVar("min",s) ) {
  513. X            ErrMsg("couldnt set variable");
  514. X            }
  515. X        }
  516. X    else if( strcmp(cmdWord0,"max")==0 ) {
  517. X        SToI( command.cmdWord[1], &i );
  518. X        ColMax( i, &x );
  519. X        RToS( x, s ); 
  520. X        WriteLine(s);
  521. X        if( !SetVar("max",s) ) {
  522. X            ErrMsg("couldnt set variable");
  523. X            }
  524. X        }
  525. X    else if( strcmp(cmdWord0,"constant")==0 ) {
  526. X        SToR( command.cmdWord[1], &x, TRUE );
  527. X        SToI( command.cmdWord[2], &j );
  528. X        if( strlen(command.cmdWord[3])==0 ) {
  529. X            ii=1;
  530. X            }
  531. X        else {
  532. X            SToI( command.cmdWord[3], &ii );
  533. X            }
  534. X        if( strlen(command.cmdWord[4])==0 ) {
  535. X            jj=table.header.rows;
  536. X            }
  537. X        else {
  538. X            SToI( command.cmdWord[4], &jj );
  539. X            }
  540. X        for( i=ii; i<=jj; i++ ) {
  541. X            SetTable( i, j, x, FALSE );
  542. X            }
  543. X        RedoEditWindow();
  544. X        }
  545. X    else if( strcmp(cmdWord0,"bandpass")==0 ) {
  546. X        bandpass();
  547. X        RedoEditWindow();
  548. X        }
  549. X    else if( strcmp(cmdWord0,"spectrum")==0 ) {
  550. X        spect();
  551. X        RedoEditWindow();
  552. X        }
  553. X
  554. X    else if( strcmp(cmdWord0,"integrate")==0 ) {
  555. X        integrate();
  556. X        RedoEditWindow();
  557. X        }
  558. X    else if( (strcmp(cmdWord0,"diff")==0) || (strcmp(cmdWord0,"differentiate")==0) ) {
  559. X        differentiate();
  560. X        RedoEditWindow();
  561. X        }
  562. X    else if( strcmp(cmdWord0,"sum")==0 ) {
  563. X        summation();
  564. X        RedoEditWindow();
  565. X        }
  566. X    else if( strcmp(cmdWord0,"histogram")==0 ) {
  567. X        histogram();
  568. X        RedoEditWindow();
  569. X        }
  570. X    else if( strcmp(cmdWord0,"taper")==0 ) {
  571. X        taper();
  572. X        RedoEditWindow();
  573. X        }
  574. X    else if( (strcmp(cmdWord0,"conv")==0) || (strcmp(cmdWord0,"convolve")==0) ) {
  575. X        convolve();
  576. X        RedoEditWindow();
  577. X        }
  578. X
  579. X    else {
  580. X        ErrMsg("no such command");
  581. X        }
  582. X        
  583. X    } /*end if not pending*/
  584. X        
  585. X    if( (!mem.active) && (!pendingFlag) ) { /*prompt to command window*/
  586. X        currentWindow = coWindow;
  587. X        whichWindow = theWindow[currentWindow];
  588. X        SelectWindow( whichWindow );
  589. X        SetPort(whichWindow);
  590. X        TEInsert( "> ", 2L, coText );
  591. X        IfOutScroll( coText );
  592. X        }
  593. X
  594. X}
  595. ________This_Is_The_END________
  596. if test `wc -l < regcmdloop.c` -ne 475; then
  597.     echo 'shar: regcmdloop.c was damaged during transit'
  598.   echo '      (should have been 475 bytes)'
  599. fi
  600. fi        ; : end of overwriting check
  601. echo 'Extracting reggauss.c'
  602. if test -f reggauss.c; then echo 'shar: will not overwrite reggauss.c'; else
  603. sed 's/^X//' << '________This_Is_The_END________' > reggauss.c
  604. X#include "all.h"
  605. X#include "regtabext.h"
  606. X
  607. Xmultifit()
  608. X{
  609. X    int indList[32], nInd, i, j, k, n, inWord, yCol, zCol, anyNaN, nstore, ierror, counts, flag;
  610. X    char c, str[80];
  611. X    float t, x[33], y, z, vec[33], *a;
  612. X    if( (strcmp(command.cmdWord[1],"type")!=0) &&
  613. X         (strcmp(command.cmdWord[1],"keep")!=0) &&
  614. X         (strcmp(command.cmdWord[1],"remove")!=0) &&
  615. X         (strcmp(command.cmdWord[1],"compute")!=0)  ) {
  616. X             ErrMsg(badModifier);
  617. X        }
  618. X    /*decode independent column list*/
  619. X    n = strlen( command.cmdWord[2] );
  620. X    command.cmdWord[2][n]=' ';
  621. X    command.cmdWord[2][n+1]='\0';
  622. X    n++;
  623. X    nInd = 0;
  624. X    inWord = FALSE;
  625. X    for( i=0; i<n; i++ ) {
  626. X        c = command.cmdWord[2][i];
  627. X        if( (c=='\t') || (c==',') ) c=' ';
  628. X        if( (!inWord) && (c!=' ') ) {
  629. X            inWord=TRUE;
  630. X            nInd++;
  631. X            if( nInd>32 ) ErrMsg("too many independent columns");
  632. X            j=0;
  633. X            str[0]=c;
  634. X            }
  635. X        else if( inWord &&  (c==' ')  ) {
  636. X            j++;
  637. X            str[j]='\0';
  638. X            SToI( str, &(indList[nInd]) );
  639. X            if( GoodCol(indList[nInd])!=0 ) ErrMsg("bad independent column");
  640. X            inWord=FALSE;
  641. X            }
  642. X        else if( inWord && (c!=' ') ) {
  643. X            j++;
  644. X            str[j]=c;
  645. X            } /*end if*/
  646. X        } /*end for i*/
  647. X    if (nInd<1) ErrMsg("too few independent columns");
  648. X        
  649. X    SToI( command.cmdWord[3], &yCol );
  650. X    if( GoodCol(yCol)!=0 ) ErrMsg("bad dependent column");
  651. X    
  652. X    /*allocate matrix and zero it*/
  653. X    nstore = nInd+1;
  654. X    a = NewPtr( 4L * (long)(nstore*nstore) );
  655. X    if( MemError()!=noErr ) ErrMsg("not enough memory");
  656. X    for( i=0; i<nstore; i++ ) {
  657. X        vec[i]=0.0;
  658. X        for( j=0; j<nstore; j++ ) {
  659. X            *(a+i*nstore+j)=0.0;
  660. X            } /*end for j*/
  661. X        } /*end for i*/
  662. X    
  663. X    counts = 0;
  664. X    for( i=1; i<=table.header.rows; i++ ) {
  665. X        x[0]=1.0;
  666. X        anyNaN = FALSE;
  667. X        for( j=1; j<=nInd; j++ ) {
  668. X            GetTable( i, indList[j], &(x[j]) );
  669. X            if( NaN(&x[j]) ) {
  670. X                anyNaN = TRUE;
  671. X                break;
  672. X                } /*end if*/
  673. X            } /*end for j*/
  674. X        GetTable( i, yCol, &y );
  675. X        if( anyNaN || NaN(&y) ) break;
  676. X        counts++;
  677. X        for( j=0; j<nstore; j++ ) {
  678. X            vec[j] += y*x[j];
  679. X            for( k=0; k<nstore; k++ ) {
  680. X                *(a+j*nstore+k) += x[j]*x[k];
  681. X                } /*end for k*/
  682. X            } /*end for j*/
  683. X        } /*end for i*/
  684. X            
  685. X    gauss(a,vec,nstore,nstore,1.0e-6,&ierror,TRUE); /*solve normal equations*/
  686. X    if( ierror!=0 ) {
  687. X        WriteLine( "Warning! singular matrix detected" );
  688. X        }
  689. X    DisposPtr( a );
  690. X        
  691. X    if (strcmp(command.cmdWord[1],"type")==0) {
  692. X        WriteLine("constant term");
  693. X        RToS( vec[0], str );
  694. X        WriteLine( str );
  695. X        WriteLine("coefficients of the indepencent columns");
  696. X        for( i=1; i<=nInd; i++ ) {
  697. X            IToS( indList[i], str );
  698. X            WritePhrase( str );
  699. X            WritePhrase( "  " );
  700. X            RToS( vec[i], str );
  701. X            WriteLine( str );
  702. X            } /*end for i*/
  703. X        } /*end if*/
  704. X    else if( (strcmp(command.cmdWord[1],"keep")==0)  ||
  705. X             (strcmp(command.cmdWord[1],"remove")==0)  ) {
  706. X        if(strcmp(command.cmdWord[1],"remove")==0) {
  707. X            flag=TRUE;
  708. X            }
  709. X        else {
  710. X            flag=FALSE;
  711. X            }
  712. X        SToI( command.cmdWord[4], &zCol );
  713. X        for( i=1; i<=table.header.rows; i++ ) {
  714. X            z=vec[0];
  715. X            for( j=1; j<=nInd; j++ )  {
  716. X                GetTable( i, indList[j], &t );
  717. X                z+=vec[j]*t;
  718. X                } /*end for j*/
  719. X            if (flag) {
  720. X                GetTable( i, yCol, &y );
  721. X                z = y-z;
  722. X                } /*end if*/
  723. X            SetTable( i, zCol, z, FALSE );
  724. X            } /*end for i*/
  725. X        } /*end if*/
  726. X        
  727. X    /*save coefficients, etc*/
  728. X    nCoeffs=nstore;
  729. X    for( i=0; i<=nstore; i++ ) coeffs[i]=vec[i];
  730. X    IToS( counts, str );
  731. X    if( !SetVar( "counts", str ) ) {
  732. X        ErrMsg("couldnt set variable");
  733. X        }
  734. X}
  735. X
  736. Xnoise()
  737. X{
  738. X    float a, d, r;
  739. X    double xnse();
  740. X    int xCol, i;
  741. X    SToR( command.cmdWord[1], &a, FALSE );
  742. X    SToR( command.cmdWord[2], &d, FALSE );
  743. X    if( d<=0.0 ) ErrMsg("std dev cant be non-positive");
  744. X    SToI( command.cmdWord[3], &xCol );
  745. X    for( i=1; i<=table.header.rows; i++ ) {
  746. X        r = (float) xnse(a,d);
  747. X        SetTable( i, xCol, r, FALSE );
  748. X        }
  749. X}
  750. X
  751. Xdouble xnse(a,d)
  752. Xfloat a, d;
  753. X/* returns a random number in a sequence with mean a and standard deviation d */
  754. X{
  755. X    double sum, t, ss;
  756. X    int i, n=10;
  757. X    sum = 0.0;
  758. X    t = sqrt( (double) (12.0*d*d/n) )/65536.0;
  759. X    for( i=0; i<n; i++ ) {
  760. X        sum +=  ran();
  761. X        }
  762. X    return( (sum*t + (double)a) );
  763. X}
  764. X
  765. Xpolyfit()
  766. X{
  767. X    int order, i, j, k, xCol, yCol, zCol, counts, ierror, flag;
  768. X    float a[7][7], vec[7], xn[14], x, y, z, t;
  769. X    char str[40];
  770. X    
  771. X    SToI( command.cmdWord[1], &order );
  772. X    if( (order<1) || (order>6) ) {
  773. X        ErrMsg("order must be in range 1-6");
  774. X        }
  775. X    if( (strcmp(command.cmdWord[2],"type")!=0) &&
  776. X         (strcmp(command.cmdWord[2],"keep")!=0) &&
  777. X         (strcmp(command.cmdWord[2],"remove")!=0) &&
  778. X         (strcmp(command.cmdWord[2],"compute")!=0)  ) {
  779. X             ErrMsg(badModifier);
  780. X        }
  781. X    SToI( command.cmdWord[3], &xCol );
  782. X    SToI( command.cmdWord[4], &yCol );
  783. X    if( (GoodCol(xCol)!=0) || (GoodCol(yCol)!=0) ) {
  784. X        ErrMsg( "bad input column");
  785. X        }
  786. X        
  787. X    for( j=0; j<=order; j++ ) { /*zero matrix and vector*/
  788. X            vec[j] = 0.0;
  789. X            for( k=0; k<=order; k++ ) {
  790. X                a[j][k] = 0.0;
  791. X                } /*end for k*/
  792. X            } /*end for k*/
  793. X
  794. X    counts=0;
  795. X    i=1;
  796. X    while( NextNotNaN( i, xCol, yCol, &i ) ) {
  797. X        counts++;
  798. X        GetTable( i, xCol, &x );
  799. X        GetTable( i, yCol, &y );
  800. X        xn[0]=1.0;  /*compute powers of x*/
  801. X        for( j=1; j<=(2*order); j++ )  {
  802. X            xn[j] = x * xn[j-1];
  803. X            } /*end for j*/
  804. X        for( j=0; j<=order; j++ ) { /*zero matrix and vector*/
  805. X            vec[j] +=  y*xn[j];
  806. X            for( k=0; k<=order; k++ ) {
  807. X                a[j][k] += xn[k+j];
  808. X                } /*end for k*/
  809. X            } /*end for k*/
  810. X        i++;
  811. X        } /*end while*/
  812. X        
  813. X    gauss(a,vec,(order+1),7,1.0e-6,&ierror,TRUE); /*solve normal equations*/
  814. X    if( ierror!=0 ) {
  815. X        WriteLine( "Warning! singular matrix detected" );
  816. X        }
  817. X        
  818. X    if (strcmp(command.cmdWord[2],"type")==0) {
  819. X        WriteLine("coefficients of x to the n, starting with n=0");
  820. X        for( i=0; i<=order; i++ ) {
  821. X            RToS( vec[i], str );
  822. X            WriteLine( str );
  823. X            } /*end for i*/
  824. X        } /*end if*/
  825. X    else if( (strcmp(command.cmdWord[2],"keep")==0)  ||
  826. X             (strcmp(command.cmdWord[2],"remove")==0)  ) {
  827. X        if(strcmp(command.cmdWord[2],"remove")==0) {
  828. X            flag=TRUE;
  829. X            }
  830. X        else {
  831. X            flag=FALSE;
  832. X            }
  833. X        SToI( command.cmdWord[5], &zCol );
  834. X        for( i=1; i<=table.header.rows; i++ ) {
  835. X            GetTable( i, xCol, &x );
  836. X            xn[0]=1.0;
  837. X            z=vec[0];
  838. X            for( j=1; j<=order; j++ )  {
  839. X                xn[j]=x*xn[j-1];
  840. X                z+=xn[j]*vec[j];
  841. X                } /*end for j*/
  842. X            if (flag) {
  843. X                GetTable( i, yCol, &y );
  844. X                z = y-z;
  845. X                } /*end if*/
  846. X            SetTable( i, zCol, z, FALSE );
  847. X            } /*end for i*/
  848. X        } /*end if*/
  849. X        
  850. X    /*save coefficients, etc*/
  851. X    nCoeffs=order;
  852. X    for( i=0; i<=order; i++ ) coeffs[i]=vec[i];
  853. X    IToS( counts, str );
  854. X    if( !SetVar( "counts", str ) ) {
  855. X        ErrMsg("couldnt set variable");
  856. X        }
  857. X
  858. X}
  859. X
  860. Xgauss(a,vec,n,nstore,test,ierror,itriag)
  861. Xfloat *a, vec[], test;
  862. Xint n, nstore, *ierror, itriag;
  863. X{
  864. X/*subroutine gauss, by william menke, july 1978 (modified feb 1983, nov 85) */
  865. X/* a subroutine to solve a system of n linear equations in n unknowns, where n doesn't exceed 32 */
  866. X/*gaussian reduction with partial pivoting is used                 */
  867. X/*     a        (sent, destroyed)    n by n matrix                    */
  868. X/*    vec        (sent, overwritten)    n vector, replaced with solution    */
  869. X/*     nstore    (sent)            dimension of a                    */
  870. X/*    test        (sent)            small pos no for div by zero check    */
  871. X/*    ierror    (returned)        error code. zero on no error        */
  872. X/*    itriag    (sent)            matrix triangularized only on TRUE    */
  873. X/*                            useful when solving multiple        */
  874. X/*                            systems with same a             */
  875. X    static int isub[32], l1;
  876. X    int line[32], iet, ieb, i, j, k, l, j2;
  877. X    float big, testa, b, sum;
  878. X    
  879. X
  880. X    iet=0;    /* initial error flags, one for triagularization*/
  881. X    ieb=0;    /* one for backsolving */
  882. X
  883. X/* triangularize the matrix a, replacing the zero elements of the triangularized matrix */
  884. X/* with the coefficients needed to transform the vector vec */
  885. X
  886. X    if (itriag) {    /* triangularize matrix */
  887. X         for( j=0; j<n; j++ ) {      /*line is an array of flags*/
  888. X            line[j]=0;   /* elements of a are not moved during pivoting. line=0 flags unused lines */
  889. X            }    /*end for j*/
  890. X            
  891. X        for( j=0; j<n-1; j++ ) { /*  triangularize matrix by partial pivoting */
  892. X                       big = 0.0;     /* find biggest element in j-th column of unused portion of matrix*/
  893. X               for( l1=0; l1<n; l1++ ) {
  894. X                               if( line[l1]==0 ) {
  895. X                                       testa=(float) fabs( (double) (*(a+l1*nstore+j)) );
  896. X                                       if (testa>big) {
  897. X                        i=l1;
  898. X                        big=testa;
  899. X                        } /*end if*/
  900. X                    } /*end if*/
  901. X                } /*end for l1*/
  902. X                       if( big<=test) {   /* test for div by 0 */
  903. X                               iet=1;
  904. X                               } /*end if*/
  905. X                       line[i]=1;  /* selected unused line becomes used line */
  906. X                       isub[j]=i;  /* isub points to j-th row of triang. matrix */
  907. X                       sum=1.0/(*(a+i*nstore+j));  /* reduce matrix towards triangle */
  908. X               for( k=0; k<n; k++ ) {
  909. X                if( line[k]==0 ) {
  910. X                    b=(*(a+k*nstore+j))*sum;
  911. X                           for( l=j+1; l<n; l++ ) {
  912. X                                               *(a+k*nstore+l)=(*(a+k*nstore+l))-b*(*(a+i*nstore+l));
  913. X                           } /*end for l*/
  914. X                                       *(a+k*nstore+j)=b;
  915. X                    } /*end if*/
  916. X                } /*end for k*/
  917. X            } /*end for j*/
  918. X               for( j=0; j<n; j++ ) { /*find last unused row and set its pointer*/
  919. X            /*  this row contians the apex of the triangle*/
  920. X            if( line[j]==0) {
  921. X                l1=j;   /*apex of triangle*/
  922. X                isub[n-1]=j;
  923. X                break;
  924. X                } /*end if*/
  925. X            } /*end for j*/
  926. X        } /*end if itriag true*/
  927. X        
  928. X    /*start backsolving*/
  929. X    
  930. X    for( i=0; i<n; i++ ) {        /* invert pointers. line(i) now gives row no in triang matrix */
  931. X                        /* of i-th row of actual matrix */
  932. X        line[isub[i]] = i;
  933. X        } /*end for i*/
  934. X      for( j=0; j<n-1; j++) {  /* transform the vector to match triang. matrix*/
  935. X               b=vec[isub[j]];
  936. X               for( k=0; k<n; k++ ) {
  937. X                      if (line[k]>j) {    /* skip elements outside of triangle*/
  938. X                                vec[k]=vec[k]-(*(a+k*nstore+j))*b;
  939. X                } /*end if*/
  940. X            } /*end for k*/
  941. X        } /*end for j*/
  942. X      b = *(a+l1*nstore+(n-1));   /*apex of triangle*/
  943. X      if( ((float)fabs( (double) b))<=test) {  /*check for div by zero in backsolving*/
  944. X        ieb=2;
  945. X        } /*end if*/
  946. X      vec[isub[n-1]]=vec[isub[n-1]]/b;
  947. X      for( j=n-2; j>=0; j-- ) {    /* backsolve rest of triangle*/
  948. X        sum=vec[isub[j]];
  949. X        for( j2=j+1; j2<n; j2++ ) {
  950. X            sum = sum - vec[isub[j2]] * (*(a+isub[j]*nstore+j2));
  951. X            } /*end for j2*/
  952. X            b = *(a+isub[j]*nstore+j);
  953. X               if( ((float)fabs((double)b))<=test) {    /* test for div by 0 in backsolving */
  954. X            ieb=2;
  955. X            } /*end if*/
  956. X        vec[isub[j]]=sum/b;   /*solution returned in vec*/
  957. X        } /*end for j*/
  958. X
  959. X/*put the solution vector into the proper order*/
  960. X
  961. X      for( i=0; i<n; i++ ) {    /* reorder solution */
  962. X        for( k=i; k<n; k++ ) {  /* search for i-th solution element */
  963. X            if( line[k]==i ) {
  964. X                j=k;
  965. X                break;
  966. X                } /*end if*/
  967. X            } /*end for k*/
  968. X               b = vec[j];       /* swap solution and pointer elements*/
  969. X               vec[j] = vec[i];
  970. X               vec[i] = b;
  971. X               line[j] = line[i];
  972. X        } /*end for i*/
  973. X      *ierror = iet + ieb;   /* set final error flag*/
  974. ________This_Is_The_END________
  975. if test `wc -l < reggauss.c` -ne 383; then
  976.     echo 'shar: reggauss.c was damaged during transit'
  977.   echo '      (should have been 383 bytes)'
  978. fi
  979. fi        ; : end of overwriting check
  980. echo 'Extracting reggraph.c'
  981. if test -f reggraph.c; then echo 'shar: will not overwrite reggraph.c'; else
  982. sed 's/^X//' << '________This_Is_The_END________' > reggraph.c
  983. X#include "all.h"
  984. X#include "regtabext.h"
  985. X
  986. XNextNotNan(startRow, x, y, foundRow)
  987. Xint startRow,  x,  y,  *foundRow;
  988. X/*searches through two columns of table, and returns first row after*/
  989. X/*and including startRow that has no Nans in the columns*/
  990. X{
  991. X    int i, bothNaN;
  992. X    float fx, fy;
  993. X
  994. X    *foundRow = 0;
  995. X    bothNaN=TRUE;
  996. X    for (i=startRow;  ((i<=table.header.rows) && bothNaN); i++ ) {
  997. X        GetTable( i, x, &fx );
  998. X        GetTable( i, y, &fy );
  999. X        if( (!NaN(&fx)) && (!NaN(&fy))  ) {
  1000. X            *foundRow = i;
  1001. X            bothNaN = FALSE;
  1002. X            } /* end if */
  1003. X        } /*end for*/
  1004. X    return(!bothNaN);
  1005. X}
  1006. X
  1007. XGraphScale( x, y, ix, iy ) /*to pixel coordinates*/
  1008. Xfloat x, y;
  1009. Xint *ix, *iy;
  1010. X{
  1011. X    float xs, ys;
  1012. X    xs  = ((float)(grXMax-grXMin))*(x-graph.xMin)/(graph.xMax-graph.xMin);
  1013. X    ys  = ((float)(grYMin-grYMax))*(y-graph.yMin)/(graph.yMax-graph.yMin);
  1014. X    xs  = xs + (float)grXMin;
  1015. X    ys  = (float)grYMin-ys;
  1016. X    
  1017. X    if( (xs>=(-32760.0)) && (xs<=32760.0) ) {
  1018. X        *ix=(int)xs;
  1019. X        }
  1020. X    else if( xs<(-32760.0) ) {
  1021. X        *ix = -32760;
  1022. X        }
  1023. X    else {
  1024. X        *ix = 32760;
  1025. X        }
  1026. X
  1027. X    if( (ys>=(-32760.0)) && (ys<32760.0) ) {
  1028. X        *iy=(int)ys;
  1029. X        }
  1030. X    else if( ys<(-32760) ) {
  1031. X        *iy  =  -32760;
  1032. X        }
  1033. X    else {
  1034. X        *iy = 32760;
  1035. X        }
  1036. X}
  1037. X
  1038. XInvGraphScale( ix, iy, x, y)   /*pixels to graph coordinates*/
  1039. Xint ix, iy;
  1040. Xfloat *x, *y;
  1041. X{
  1042. X    ix = ix-grXMin;
  1043. X    iy = grYMin-iy;
  1044. X    *x  =( ( (float)(ix) / ((float)(grXMax-grXMin)) ) * (graph.xMax-graph.xMin) ) + graph.xMin;
  1045. X    *y  =( ( (float)(iy) / ((float)(grYMin-grYMax)) ) * (graph.yMax-graph.yMin) ) + graph.yMin;
  1046. X}
  1047. X
  1048. XPlotCol()
  1049. X{
  1050. X    int xcol, ycol, firstRow, nextRow, i, j, oldWindow, width;
  1051. X    int startRow, endRow, dx, dy, continuous, pat, refresh;
  1052. X    float x1, y1;
  1053. X    char symbol, s[cmdWordLen];
  1054. X    GrafPtr oldPort;
  1055. X    
  1056. X    SToI( command.cmdWord[1], &xcol );
  1057. X    SToI( command.cmdWord[2], &ycol );
  1058. X    if (GoodCol(xcol)!=0) {
  1059. X        ErrMsg("bad x col");
  1060. X        }
  1061. X    if (GoodCol(ycol)!=0) {
  1062. X        ErrMsg("bad y col");
  1063. X        }
  1064. X        
  1065. X    if( table.header.rows >= 1000 ) {
  1066. X        refresh = 100;
  1067. X        }
  1068. X    else {
  1069. X        refresh = 10;
  1070. X        }
  1071. X        
  1072. X    strcpy( s, command.cmdWord[3] );
  1073. X    pat=0;
  1074. X    width=1;
  1075. X    if( (strlen(s)==0) || (strcmp(s,"solid")==0) ){
  1076. X        continuous =TRUE;
  1077. X        pat=0; /*black*/
  1078. X        width=1;
  1079. X        }
  1080. X    else if (strcmp(s,"dashed")==0) {
  1081. X        continuous =TRUE;
  1082. X        width=2;
  1083. X        pat=1; /*gray*/
  1084. X        }
  1085. X    else if (strcmp(s,"dotted")==0) {
  1086. X        continuous = TRUE;
  1087. X        pat=2; /*ltGray*/;
  1088. X        width=2;
  1089. X        }
  1090. X    else if (strcmp(s,"bold")==0) {
  1091. X        continuous = TRUE;
  1092. X        pat=0; /*black*/
  1093. X        width=2;
  1094. X        }
  1095. X    else if (strcmp(s,"dots")==0) {
  1096. X        continuous =FALSE;
  1097. X        dx=2;
  1098. X        dy =1;
  1099. X        symbol='.';
  1100. X        }
  1101. X    else if (strcmp(s,"crosses")==0) {
  1102. X        continuous=FALSE;
  1103. X        symbol = '+';
  1104. X        dx=2;
  1105. X        dy=5;
  1106. X        }
  1107. X    else if (strcmp(s,"circles")==0) {
  1108. X        continuous = FALSE;
  1109. X        symbol = 'o';
  1110. X        dx = 3;
  1111. X        dy = 3;
  1112. X        }
  1113. X    else if (strcmp(s,"stars")==0) {
  1114. X        continuous = FALSE;
  1115. X        symbol = '*';
  1116. X        dx = 2;
  1117. X        dy = 5;
  1118. X        }
  1119. X    else if (strcmp(s,"x")==0) {
  1120. X        continuous = FALSE;
  1121. X        symbol = 'x';
  1122. X        dx =  2;
  1123. X        dy =  3;
  1124. X        }
  1125. X    else {
  1126. X        ErrMsg("bad plotting symbol");
  1127. X        }
  1128. X        
  1129. X    GetPort( &oldPort );
  1130. X    oldWindow=currentWindow;
  1131. X    
  1132. X    SetPort(grPortPtr);
  1133. X    TextFont(monaco);
  1134. X    TextSize(9);
  1135. X    
  1136. X    if( pat==1 ) {
  1137. X        PenPat( gray );
  1138. X        }
  1139. X    else if( pat==2 ) {
  1140. X        PenPat( ltGray );
  1141. X        }
  1142. X    else {
  1143. X        PenPat( black );
  1144. X        }
  1145. X    PenSize( width, width );
  1146. X
  1147. X    /*determine limits: dont plot interpolated data outside box*/
  1148. X    if( (table.header.interpolated) && (xcol==1) ) {
  1149. X        x1=1.0 + (graph.xMin-table.header.start)/table.header.samp;
  1150. X        if ((x1-1.0)<1.0) {
  1151. X            startRow =1;
  1152. X            }
  1153. X        else if ((x1-1.0)>((float)table.header.rows)) {
  1154. X            startRow = table.header.rows;
  1155. X            }
  1156. X        else {
  1157. X            startRow =  (int)(x1-1.0);
  1158. X            }
  1159. X        x1 = 1.0 + (graph.xMax-table.header.start)/table.header.samp;
  1160. X        if( (x1+1.0)<1.0 ) {
  1161. X            endRow=1;
  1162. X            }
  1163. X        else if( (x1+1.0)>((float)table.header.rows) ) {
  1164. X            endRow=table.header.rows;
  1165. X            }
  1166. X        else {
  1167. X            endRow = (int)(x1+1.0);
  1168. X            }
  1169. X        }
  1170. X    else {
  1171. X        startRow =1;
  1172. X        endRow = table.header.rows;
  1173. X        }
  1174. X
  1175. X    if( NextNotNan(startRow,xcol,ycol, &firstRow) ) {
  1176. X        GetTable( firstRow, xcol, &x1 );
  1177. X        GetTable( firstRow, ycol, &y1 );
  1178. X        GraphScale( x1, y1, &i, &j );
  1179. X        if (continuous) {
  1180. X            MoveTo( i, j );
  1181. X            }
  1182. X        else {
  1183. X            MoveTo( i-dx, j+dy );
  1184. X            DrawText(&symbol, 0, 1);
  1185. X            }
  1186. X        firstRow++;
  1187. X        while( (firstRow<=endRow) && NextNotNan(firstRow,xcol,ycol,&nextRow)  ) {
  1188. X            GetTable( nextRow, xcol, &x1 );
  1189. X            GetTable( nextRow, ycol, &y1 );
  1190. X            GraphScale( x1, y1, &i, &j );
  1191. X            if (continuous) {
  1192. X                LineTo( i, j );
  1193. X                }
  1194. X            else {
  1195. X                MoveTo( i-dx, j+dy );
  1196. X                DrawText(&symbol,0,1);
  1197. X                }
  1198. X            firstRow=nextRow + 1;
  1199. X            if( (nextRow%refresh)==0) {
  1200. X                CheckAbortMenu();
  1201. X                currentWindow=grWindow;
  1202. X                whichWindow=theWindow[grWindow];
  1203. X                SetPort( whichWindow );
  1204. X                DrawWindow();
  1205. X                SetPort( grPortPtr );
  1206. X                }
  1207. X            } /*end while*/
  1208. X        } /*end if*/
  1209. X
  1210. X    SetPort( theWindow[grWindow] );
  1211. X    InvalRect( &(theWindow[grWindow]->portRect) );
  1212. X    
  1213. X    SetPort( oldPort );
  1214. X    currentWindow=oldWindow;
  1215. X    whichWindow=theWindow[currentWindow];
  1216. X}
  1217. X
  1218. XClearGraph()
  1219. X{
  1220. X    int oldWindow;
  1221. X    GrafPtr oldPort;
  1222. X    
  1223. X    GetPort( &oldPort );
  1224. X    oldWindow=currentWindow;
  1225. X
  1226. X    SetPort( grPortPtr );
  1227. X    EraseRect( &(grPort.portRect) );
  1228. X    FrameRect(&(grPort.portRect) );
  1229. X    
  1230. X    SetPort( theWindow[grWindow] );
  1231. X    InvalRect( &(theWindow[grWindow]->portRect) );
  1232. X    
  1233. X    SetPort( oldPort );
  1234. X    currentWindow=oldWindow;
  1235. X    whichWindow=theWindow[currentWindow];
  1236. X}
  1237. X
  1238. XPlotAxes()
  1239. X{
  1240. X    int i, ii, j, k, width, slen;
  1241. X    float x, interval;
  1242. X    char s[cmdWordLen];
  1243. X    int oldWindow;
  1244. X    GrafPtr oldPort;
  1245. X    Rect tRect;
  1246. X
  1247. X    GetPort( &oldPort );
  1248. X    oldWindow=currentWindow;
  1249. X
  1250. X    SetPort( grPortPtr );
  1251. X    PenPat( black );
  1252. X    PenSize(1,1);
  1253. X    TextFont(monaco);
  1254. X    TextSize(9);
  1255. X    
  1256. X    SetRect( &tRect,  1, 1, (grXMin-1), (windowHeight-1) );
  1257. X    EraseRect(&tRect);
  1258. X    
  1259. X    SetRect( &tRect, 1, (grYMin+1), (windowWidth-1), (windowHeight-1) );
  1260. X    EraseRect(&tRect);
  1261. X
  1262. X    MoveTo( grXMin,  grYMin ); /*x axis*/
  1263. X    LineTo(   grXMax, grYMin );
  1264. X    
  1265. X    MoveTo( grXMin, grYMin); /*y axis*/
  1266. X    LineTo(   grXMin, grYMax);
  1267. X        
  1268. X    interval = (graph.yMax-graph.yMin)/5.0;
  1269. X    for( i=0; i<=5; i++ ) {
  1270. X        x=graph.yMin + (float)(i)*interval;
  1271. X        GraphScale(graph.xMin,x,&k,&j);
  1272. X        MoveTo( grXMin, j );
  1273. X        LineTo( (grXMin+6), j );
  1274. X        RToS( x, s );
  1275. X        MoveTo( 5,  (j+4) );
  1276. X        DrawText( s, 0, strlen(s) );
  1277. X        }
  1278. X    
  1279. X    interval = (graph.xMax-graph.xMin)/5.0;
  1280. X    for (i=0; i<=5; i++ ) {
  1281. X        x=graph.xMin + (float)(i)*interval;
  1282. X        GraphScale(x,graph.yMin,&j,&k);
  1283. X        MoveTo( j, grYMin);
  1284. X        LineTo(   j, (grYMin-6) );
  1285. X        RToS( x, s );
  1286. X        width=0;
  1287. X        slen=strlen(s);
  1288. X        for( ii=0; ii<slen; ii++) {
  1289. X            width+=CharWidth(s[ii]);
  1290. X            }
  1291. X        MoveTo( (j-(width/2)),  (grYMin+15) );
  1292. X        DrawText( s, 0, slen );
  1293. X        }
  1294. X
  1295. X    SetPort( theWindow[grWindow] );
  1296. X    InvalRect( &(theWindow[grWindow]->portRect) );
  1297. X    
  1298. X    SetPort( oldPort );
  1299. X    currentWindow=oldWindow;
  1300. X    whichWindow=theWindow[currentWindow];
  1301. ________This_Is_The_END________
  1302. if test `wc -l < reggraph.c` -ne 318; then
  1303.     echo 'shar: reggraph.c was damaged during transit'
  1304.   echo '      (should have been 318 bytes)'
  1305. fi
  1306. fi        ; : end of overwriting check
  1307. echo 'Extracting regio.c'
  1308. if test -f regio.c; then echo 'shar: will not overwrite regio.c'; else
  1309. sed 's/^X//' << '________This_Is_The_END________' > regio.c
  1310. X#include "all.h"
  1311. X#include "regtabext.h"
  1312. X
  1313. XWriteGraph(reply)
  1314. XSFReply *reply;
  1315. X{
  1316. X    int f, i, j, k, vsize, hsize;
  1317. X    char str[256];
  1318. X    long count, bytesAvailable, pntg, mpnt, dstBytes;
  1319. X    Finfo info;
  1320. X    char dstbuf[512], srcbuf[512];
  1321. X    char *srcPtr, *dstPtr, *mypointer;
  1322. X    
  1323. X    if( !(reply->good) ) {
  1324. X        return;
  1325. X        }
  1326. X
  1327. X    strncpy( &pntg, "PNTG", 4 );
  1328. X    strncpy( &mpnt, "MPNT", 4 );
  1329. X    
  1330. X    if( GetFInfo( reply->fName, reply->vRefNum, &info )==noErr ) { /*delete old file, if any*/
  1331. X        if(  info.fdType!=pntg ) {
  1332. X            ErrMsg("cant overwrite a non-Paint file");
  1333. X            }
  1334. X        else {
  1335. X            if( FSDelete(reply->fName, reply->vRefNum)!=noErr ) {
  1336. X                ErrMsg("couldnt delete existing file");
  1337. X                }
  1338. X            }
  1339. X        }
  1340. X        
  1341. X    bytesAvailable = 0;
  1342. X    for( i=0; i<10; i++ ) {
  1343. X        k=GetVInfo( i, str, &j, &count );
  1344. X        if( (k==noErr) && (j==reply->vRefNum) ) {
  1345. X            bytesAvailable=count;
  1346. X            break;
  1347. X            }
  1348. X        }
  1349. X        
  1350. X    /* I really should check here if there is enough space on disk */
  1351. X    /* but I dont really see how to do this without compressing the entire bit map first*/
  1352. X        
  1353. X    if( Create(reply->fName, reply->vRefNum, mpnt, pntg)!=noErr ) {
  1354. X        ErrMsg("couldnt create file");
  1355. X        }
  1356. X        
  1357. X    if( FSOpen(reply->fName, reply->vRefNum, &f )!=noErr ) {
  1358. X        ErrMsg("couldnt open file");
  1359. X        }
  1360. X
  1361. X    if( SetFPos( f, fsFromStart, 0L )!=noErr ) {
  1362. X        ErrMsg("couldnt find beginning of file");
  1363. X        }
  1364. X
  1365. X    for( i=0; i<512; i++ ) { /*header is block of 512 nulls*/
  1366. X        dstbuf[i]=0;
  1367. X        }
  1368. X    count=512L;
  1369. X    k = FSWrite(f, &count, &dstbuf[0] );
  1370. X    if( (k!=noErr) || (count!=512L) ){
  1371. X        FSClose(f);
  1372. X        ErrMsg("couldnt write graph");
  1373. X        }
  1374. X        
  1375. X    mypointer = grMap.baseAddr;
  1376. X    hsize = grMap.rowBytes;
  1377. X    vsize = grMap.bounds.bottom - grMap.bounds.top;
  1378. X    
  1379. X    for( j=1; j<=720; j++ ) {
  1380. X        srcPtr = &srcbuf[0];
  1381. X        dstPtr = &dstbuf[0];
  1382. X        for( i=0; i<72; i++ ) {
  1383. X            if( (i<hsize) && (j<=vsize) ) {
  1384. X                srcbuf[i]=*mypointer;
  1385. X                mypointer++;
  1386. X                }
  1387. X            else {
  1388. X                srcbuf[i] = 0;
  1389. X                }
  1390. X            }
  1391. X        PackBits( &srcPtr, &dstPtr,72);
  1392. X        dstBytes = (long)(dstPtr-&dstbuf[0]);
  1393. X        count = dstBytes;
  1394. X        k = FSWrite(f, &count, &dstbuf[0] );
  1395. X        if( (k!=noErr) || (count!=dstBytes) ){
  1396. X            FSClose(f);
  1397. X            ErrMsg("couldnt write graph");
  1398. X            }
  1399. X        } /*end for*/
  1400. X
  1401. X    if( FSClose(f)!=noErr ) {
  1402. X        ErrMsg("couldnt close file");
  1403. X        }
  1404. X        
  1405. X    FlushVol( str, reply->vRefNum );
  1406. X}
  1407. X
  1408. XReadProcedure(reply)
  1409. XSFReply *reply;
  1410. X{
  1411. X    char        str[512];
  1412. X    int        i, j, k, f, oldWindow;
  1413. X    long        regTabType, count;
  1414. X    Finfo     info;
  1415. X    GrafPtr    oldPort;
  1416. X    
  1417. X    if( !(reply->good) ) {
  1418. X        return;
  1419. X        }
  1420. X    
  1421. X    strncpy( (char*)(®TabType), "TEXT", 4 );
  1422. X    
  1423. X    if( GetFInfo( reply->fName, reply->vRefNum, &info )!=noErr ) {
  1424. X        ErrMsg("couldnt get file info");
  1425. X        }
  1426. X    if(  info.fdType!=regTabType ) {
  1427. X        ErrMsg("not a Text file");
  1428. X        }
  1429. X
  1430. X    /*open file*/
  1431. X    
  1432. X    if( FSOpen( reply->fName, reply->vRefNum, &f)!=noErr ) {
  1433. X        ErrMsg("couldnt open file");
  1434. X        }
  1435. X    SetFPos( f, fsFromStart, 0L );
  1436. X    
  1437. X    GetPort(&oldPort);
  1438. X    oldWindow=currentWindow;
  1439. X    
  1440. X    currentWindow=prWindow;
  1441. X    whichWindow=theWindow[prWindow];
  1442. X    SetPort(whichWindow);
  1443. X    
  1444. X    TESetSelect( (long)((*prText)->teLength),(long)((*prText)->teLength),prText);
  1445. X    TEKey( '\r', prText );
  1446. X    TEKey( '\r', prText );
  1447. X    
  1448. X    for( i=0; i<63; i++ ) {
  1449. X        count=512L;
  1450. X        k=FSRead(f,&count,str);
  1451. X        if( (k==noErr) || (k==eofErr) ) {
  1452. X            TEInsert( str, count, prText );
  1453. X            }
  1454. X        else {
  1455. X            break;
  1456. X            }
  1457. X        if( count<512L ) {
  1458. X            break;
  1459. X            }
  1460. X        } /*end for*/
  1461. X    FSClose(f);
  1462. X    IfOutScroll(prText);
  1463. X    
  1464. X    SetPort( oldPort );
  1465. X    currentWindow=oldWindow;
  1466. X    whichWindow=theWindow[currentWindow];
  1467. X}
  1468. X
  1469. X
  1470. XWriteProcedure(reply)
  1471. XSFReply *reply;
  1472. X{
  1473. X    int f, i, j, k;
  1474. X    char str[256];
  1475. X    long count, bytesNeeded, bytesAvailable, regTabType;
  1476. X    Finfo info;
  1477. X    
  1478. X    if( !(reply->good) ) {
  1479. X        return;
  1480. X        }
  1481. X
  1482. X    strncpy( ®TabType, "TEXT", 4 );
  1483. X    
  1484. X    if( GetFInfo( reply->fName, reply->vRefNum, &info )==noErr ) { /*delete old file, if any*/
  1485. X        if(  info.fdType!=regTabType ) {
  1486. X            ErrMsg("cant overwrite a non-Text file");
  1487. X            }
  1488. X        else {
  1489. X            if( FSDelete(reply->fName, reply->vRefNum)!=noErr ) {
  1490. X                ErrMsg("couldnt delete existing file");
  1491. X                }
  1492. X            }
  1493. X        }
  1494. X        
  1495. X    bytesNeeded = (*prText)->teLength;
  1496. X    bytesAvailable = 0;
  1497. X    for( i=0; i<10; i++ ) {
  1498. X        k=GetVInfo( i, str, &j, &count );
  1499. X        if( (k==noErr) && (j==reply->vRefNum) ) {
  1500. X            bytesAvailable=count;
  1501. X            break;
  1502. X            }
  1503. X        }
  1504. X    if( bytesAvailable<bytesNeeded ) {
  1505. X        ErrMsg( "not enough space on disk" );
  1506. X        }
  1507. X        
  1508. X    if( Create(reply->fName, reply->vRefNum, regTabType, regTabType)!=noErr ) {
  1509. X        ErrMsg("couldnt create file");
  1510. X        }
  1511. X        
  1512. X    if( FSOpen(reply->fName, reply->vRefNum, &f )!=noErr ) {
  1513. X        ErrMsg("couldnt open file");
  1514. X        }
  1515. X
  1516. X    if( SetFPos( f, fsFromStart, 0L )!=noErr ) {
  1517. X        ErrMsg("couldnt find beginning of file");
  1518. X        }
  1519. X
  1520. X    count=bytesNeeded;
  1521. X    HLock( (*prText)->hText );
  1522. X    k = FSWrite(f, &count, *((*prText)->hText) );
  1523. X    HUnlock( (*prText)->hText );
  1524. X    
  1525. X    if( (k!=noErr) || (count!=bytesNeeded) ){
  1526. X        FSClose(f);
  1527. X        ErrMsg("couldnt write procedure");
  1528. X        }
  1529. X
  1530. X    if( FSClose(f)!=noErr ) {
  1531. X        ErrMsg("couldnt close file");
  1532. X        }
  1533. X        
  1534. X    FlushVol( str, reply->vRefNum );
  1535. X}
  1536. X
  1537. XReadAsciiTable(reply)
  1538. XSFReply *reply;
  1539. X{
  1540. X    char        cLast, str[512], s[80];
  1541. X    int        i, j, k, f, lines, columns, firstReturn;
  1542. X    long        regTabType, count;
  1543. X    Finfo     info;
  1544. X    float    x;
  1545. X    GrafPtr    oldPort;
  1546. X    
  1547. X    if( !(reply->good) ) {
  1548. X        return;
  1549. X        }
  1550. X        
  1551. X    GetPort(&oldPort);
  1552. X    SetPort( theWindow[edWindow] );
  1553. X    InvalRect( &(theWindow[edWindow]->portRect) );
  1554. X    SetPort( oldPort );
  1555. X    
  1556. X    strncpy( (char*)(®TabType), "TEXT", 4 );
  1557. X    
  1558. X    if( GetFInfo( reply->fName, reply->vRefNum, &info )!=noErr ) {
  1559. X        ErrMsg("couldnt get file info");
  1560. X        }
  1561. X    if(  info.fdType!=regTabType ) {
  1562. X        ErrMsg("not a Text file");
  1563. X        }
  1564. X
  1565. X    /*open file*/
  1566. X    
  1567. X    if( FSOpen( reply->fName, reply->vRefNum, &f)!=noErr ) {
  1568. X        ErrMsg("couldnt open file");
  1569. X        }
  1570. X    SetFPos( f, fsFromStart, 0L );
  1571. X    
  1572. X    /* determine size of table*/
  1573. X    lines = 0;
  1574. X    columns = 0;
  1575. X    i=0;  /*counts tabs per line*/
  1576. X    j=0; /*counts characters*/
  1577. X    cLast='\0';
  1578. X    firstReturn=TRUE;
  1579. X    while( lines<=4097 ) {    /*loop over lines in file */
  1580. X        count=1L;
  1581. X        k=FSRead(f,&count,str);
  1582. X        if( (count!=1L) || (k!=noErr) ) {
  1583. X            if( (cLast=='\r') || (!firstReturn) ) {
  1584. X                break;
  1585. X                }
  1586. X            else {
  1587. X                str[0]='\r';
  1588. X                firstReturn=FALSE;
  1589. X                }
  1590. X            }
  1591. X        j++;
  1592. X        cLast=str[0];
  1593. X        if( str[0]=='\t') {
  1594. X            i++;
  1595. X            }
  1596. X        else if( str[0]=='\r' ) {
  1597. X            lines++;
  1598. X            if( i>columns ) {
  1599. X                columns=i;
  1600. X                }
  1601. X            i=0;
  1602. X            } /*end if*/
  1603. X        } /*end while*/
  1604. X        columns++; /*since tabs were counted*/
  1605. X        if( columns>32 ) {
  1606. X            columns=32;
  1607. X            }
  1608. X        lines--;  /*since first line is colnames*/
  1609. X    FSClose(f);
  1610. X    
  1611. X    /* set up table header */
  1612. X    if( (lines>table.header.rows) || (columns>table.header.cols) ) {
  1613. X        AllocTable( lines, columns );
  1614. X        WriteLine("Warning: table allocation changed");
  1615. X        }
  1616. X    else {
  1617. X        table.header.rows = lines;
  1618. X        table.header.cols = columns;
  1619. X        }
  1620. X    table.header.interpolated = FALSE;
  1621. X    for( i=1; i<=table.header.cols; i++ ) {
  1622. X        strcpy( s, "Col " );
  1623. X        IToS( i, &(s[4]) );
  1624. X        strcpy( table.header.colName[i-1], s );
  1625. X        } /*end for*/
  1626. X    for( i=1; i<=table.header.rows; i++ ) {
  1627. X    for( j=1; j<=table.header.cols; j++ ) {
  1628. X        SetTable(i,j,infinity,FALSE);
  1629. X        }} /*end fors*/
  1630. X    
  1631. X    /* now read in the data */
  1632. X    if( FSOpen( reply->fName, reply->vRefNum, &f)!=noErr ) {
  1633. X        ErrMsg("couldnt open file");
  1634. X        }
  1635. X    SetFPos( f, fsFromStart, 0L );
  1636. X    
  1637. X    /*read colnames*/
  1638. X    i=1;
  1639. X    s[0]='\0';
  1640. X    while( i<=table.header.cols ) {
  1641. X        count=1L;
  1642. X        k=FSRead(f,&count,str);
  1643. X        if( (count!=1L) || (k!=noErr) ) {
  1644. X            break;
  1645. X            }
  1646. X        str[1]='\0';
  1647. X        if( (str[0]=='\t') || (str[0]=='\r')  ) {
  1648. X            strcpy( table.header.colName[i-1], s );
  1649. X            i++;
  1650. X            s[0]='\0';
  1651. X            if( str[0]=='\r' ) {
  1652. X                break;
  1653. X                }
  1654. X            }
  1655. X        else {
  1656. X            strcat( s, str );
  1657. X            }
  1658. X        } /*end while*/
  1659. X            
  1660. X    /*read table entries*/
  1661. X    i=1;
  1662. X    s[0]='\0';
  1663. X    cLast='\0';
  1664. X    firstReturn=TRUE;
  1665. X    while( i<=table.header.rows ) {
  1666. X        j=1;
  1667. X        while( j<=table.header.cols ) {
  1668. X            count=1L;
  1669. X            k=FSRead(f,&count,str);
  1670. X            if( (count!=1L) || (k!=noErr) ) {
  1671. X                if( (cLast=='\r') || (!firstReturn) ) {
  1672. X                    break;
  1673. X                    }
  1674. X                else {
  1675. X                    str[0]='\r';
  1676. X                    firstReturn=FALSE;
  1677. X                    }
  1678. X                }
  1679. X            str[1]='\0';
  1680. X            cLast=str[0];
  1681. X            if( (str[0]=='\t') || (str[0]=='\r')  ) {
  1682. X                SToR( s, &x, TRUE );
  1683. X                SetTable(i,j,x,TRUE);
  1684. X                j++;
  1685. X                s[0]='\0';
  1686. X                if( str[0]=='\r' ) {
  1687. X                    i++;
  1688. X                    break;
  1689. X                    }
  1690. X                }
  1691. X            else {
  1692. X                strcat( s, str );
  1693. X                }
  1694. X            } /*end while j*/
  1695. X        } /*end while i*/
  1696. X    FSClose(f);
  1697. X    Header2Vars();
  1698. X}
  1699. X
  1700. XWriteAsciiTable(reply)
  1701. XSFReply *reply;
  1702. X{
  1703. X    int f, i, j, k;
  1704. X    char str[256];
  1705. X    long count, bytesNeeded, regTabType;
  1706. X    Finfo info;
  1707. X    float x;
  1708. X    
  1709. X    if( !(reply->good) ) {
  1710. X        return;
  1711. X        }
  1712. X
  1713. X    strncpy( ®TabType, "TEXT", 4 );
  1714. X    
  1715. X    if( GetFInfo( reply->fName, reply->vRefNum, &info )==noErr ) { /*delete old file, if any*/
  1716. X        if(  info.fdType!=regTabType ) {
  1717. X            ErrMsg("cant overwrite a non-Text file");
  1718. X            }
  1719. X        else {
  1720. X            if( FSDelete(reply->fName, reply->vRefNum)!=noErr ) {
  1721. X                ErrMsg("couldnt delete existing file");
  1722. X                }
  1723. X            }
  1724. X        }
  1725. X        
  1726. X    if( Create(reply->fName, reply->vRefNum, regTabType, regTabType)!=noErr ) {
  1727. X        ErrMsg("couldnt create file");
  1728. X        }
  1729. X        
  1730. X    if( FSOpen(reply->fName, reply->vRefNum, &f )!=noErr ) {
  1731. X        ErrMsg("couldnt open file");
  1732. X        }
  1733. X
  1734. X    if( SetFPos( f, fsFromStart, 0L )!=noErr ) {
  1735. X        ErrMsg("couldnt find beginning of file");
  1736. X        }
  1737. X
  1738. X    for( i=1; i<=table.header.cols; i++ ) {
  1739. X        strcpy( str, table.header.colName[i-1] );
  1740. X        if( i<table.header.cols ) {
  1741. X            strcat( str, "\t" );
  1742. X            }
  1743. X        else {
  1744. X            strcat( str, "\r" );
  1745. X            }
  1746. X        bytesNeeded =  (long) strlen( str );
  1747. X        count=bytesNeeded;        
  1748. X        k = FSWrite(f, &count, str );
  1749. X        if( (k!=noErr) || (count!=bytesNeeded) ){
  1750. X            FSClose(f);
  1751. X            ErrMsg("couldnt write colnames");
  1752. X            }
  1753. X        } /*end for*/
  1754. X
  1755. X    for( i=1; i<=table.header.rows; i++ ) {
  1756. X    for( j=1; j<=table.header.cols; j++ ) {
  1757. X        GetTable(i,j,&x);
  1758. X        RToS( x, str );
  1759. X        if( j<table.header.cols ) {
  1760. X            strcat( str, "\t" );
  1761. X            }
  1762. X        else {
  1763. X            strcat( str, "\r" );
  1764. X            }
  1765. X        bytesNeeded =  (long) strlen( str );
  1766. X        count=bytesNeeded;        
  1767. X        k = FSWrite(f, &count, str );
  1768. X        if( (k!=noErr) || (count!=bytesNeeded) ){
  1769. X            FSClose(f);
  1770. X            ErrMsg("couldnt write table");
  1771. X            } /*end if*/
  1772. X        } } /*end fors*/
  1773. X
  1774. X    if( FSClose(f)!=noErr ) {
  1775. X        ErrMsg("couldnt close file");
  1776. X        }
  1777. X        
  1778. X    FlushVol( str, reply->vRefNum );
  1779. X}
  1780. X
  1781. XMean()
  1782. X{
  1783. X    int i, colx, coly, stat;
  1784. X    float sum, sum2, x, mean, stdDev, n;
  1785. X    char str1[cmdWordLen], str2[cmdWordLen];
  1786. X    
  1787. X    SToI( command.cmdWord[2], &colx );
  1788. X    sum = 0.0;
  1789. X    sum2 = 0.0;
  1790. X    n = 0.0;
  1791. X    i = 1;
  1792. X    
  1793. X    while ( NextNotNan(i,colx,colx,&i) ) {                   
  1794. X        GetTable(i,colx,&x);
  1795. X        sum  += x;
  1796. X        sum2 +=  x*x;
  1797. X        n += 1.0;
  1798. X        i++;
  1799. X        }
  1800. X        
  1801. X    mean = sum / n;
  1802. X    stdDev  = sqrt( (n*sum2 - sum*sum)/(n*(n-1)) );
  1803. X
  1804. X    strcpy(str2,"mean ");
  1805. X    RToS( mean, str1 );
  1806. X    stat = SetVar("mean",str1);
  1807. X    strcat( str2, str1 );
  1808. X    
  1809. X    RToS( stdDev, str1 );
  1810. X    stat = stat && SetVar("stddev",str1);
  1811. X    strcat(str2, " stddev ");
  1812. X    strcat(str2, str1 );
  1813. X    
  1814. X    RToS( n, str1 );
  1815. X    stat = stat && SetVar("counts",str1);
  1816. X    strcat( str2, " counts ");
  1817. X    strcat( str2, str1 );
  1818. X
  1819. X    if( strcmp(command.cmdWord[1],"type")==0 ) {
  1820. X        WriteLine(str2);
  1821. X        }                   
  1822. X    else if( strcmp(command.cmdWord[1],"keep")==0 ) {
  1823. X        SToI( command.cmdWord[3], &coly );
  1824. X        for( i=1; i<=table.header.rows; i++ ) {
  1825. X            SetTable(i,coly,mean,FALSE);
  1826. X            }
  1827. X        }
  1828. X    else if( strcmp(command.cmdWord[1],"remove")==0 ) {
  1829. X        SToI( command.cmdWord[3], &coly );
  1830. X        for( i=1; i<=table.header.rows; i++ ) {
  1831. X            GetTable(i,colx,&x);
  1832. X            SetTable(i,coly,(x-mean),FALSE);
  1833. X            }
  1834. X    }
  1835. X    else if( strcmp(command.cmdWord[1],"compute")==0 ) {
  1836. X        ;
  1837. X        }
  1838. X    else {
  1839. X        ErrMsg(badModifier);
  1840. X        }
  1841. X
  1842. X    if( !stat ) {
  1843. X        ErrMsg("couldnt set variables");
  1844. X        }
  1845. X}
  1846. X
  1847. X
  1848. XTrend()
  1849. X{
  1850. X    int i, colx, coly, colz, stat;
  1851. X    float x, y, sumX, sumY, sumX2, sumY2, sumXY, idata;
  1852. X    float s0, intercept, slope, errIntercept, errSlope;
  1853. X    char str1[cmdWordLen], str2[cmdWordLen];
  1854. X
  1855. X    SToI( command.cmdWord[2], &colx );
  1856. X    SToI( command.cmdWord[3], &coly );
  1857. X    sumX = 0.0;
  1858. X    sumY = 0.0;
  1859. X    sumX2 = 0.0;
  1860. X    sumY2 = 0.0;
  1861. X    sumXY = 0.0;
  1862. X    idata = 0.0;
  1863. X    
  1864. X    i = 1;
  1865. X    while( NextNotNan(i,colx,coly,&i) ) {
  1866. X        GetTable(i,colx,&x);
  1867. X        GetTable(i,coly,&y);
  1868. X        sumX  += x;
  1869. X        sumY  += y;
  1870. X        sumX2  += x*x;
  1871. X        sumY2  += y*y;
  1872. X        sumXY  += x*y;
  1873. X        idata += 1.0;
  1874. X        i++;
  1875. X        }
  1876. X
  1877. X    slope = (sumXY - (sumX*sumY/idata)) / (sumX2-(sumX*sumX/idata));
  1878. X    intercept = (sumY/idata) - (slope*(sumX/idata));
  1879. X
  1880. X    s0 = sumY2 - (sumY*sumY/idata) - (slope*(sumXY - sumX*(sumY/idata)));
  1881. X    s0 = s0 / (idata-2.0);
  1882. X    errIntercept = sqrt( (double)(s0 * sumX2 / (idata*(sumX2 - (sumX*sumX/idata)))) );
  1883. X    errSlope = sqrt( (double) (s0 / (sumX2 - (sumX*sumX/idata))) );
  1884. X
  1885. X    RToS(slope,str2);
  1886. X    stat = SetVar("slope",str2);
  1887. X    strcpy( str1,"slope ");
  1888. X    strcat( str1, str2 );
  1889. X
  1890. X    RToS( intercept, str2 );
  1891. X    stat = stat && SetVar("intercept",str2);
  1892. X    strcat( str1, " intercept ");
  1893. X    strcat( str1, str2 );
  1894. X
  1895. X    RToS( idata, str2 );
  1896. X    stat = stat && SetVar("counts", str2);
  1897. X    strcat( str1, " counts ");
  1898. X    strcat( str1, str2 );
  1899. X
  1900. X    if( strcmp(command.cmdWord[1],"type")==0 ) {
  1901. X        WriteLine(str1);
  1902. X        }
  1903. X
  1904. X    RToS(errSlope,str2);
  1905. X    stat = stat && SetVar("errslope",str2);
  1906. X    strcpy( str1, "errslope ");
  1907. X    strcat( str1, str2 );
  1908. X
  1909. X    RToS( errIntercept, str2 );
  1910. X    stat = stat&& SetVar("errintercept",str2);
  1911. X    strcat( str1, " errintercept ");
  1912. X    strcat( str1, str2 );
  1913. X
  1914. X    if (strcmp(command.cmdWord[1],"type")==0 ) {
  1915. X        WriteLine(str1);
  1916. X        }
  1917. X    else if (strcmp(command.cmdWord[1],"keep")==0 ) {
  1918. X        SToI( command.cmdWord[4], &colz );
  1919. X        for ( i=1; i<=table.header.rows; i++ ) {
  1920. X            GetTable(i,colx,&x);
  1921. X            SetTable(i,colz,(intercept+(slope*x)),FALSE);
  1922. X            }
  1923. X        }
  1924. X    else if (strcmp(command.cmdWord[1],"remove")==0 ) {
  1925. X                     SToI( command.cmdWord[4], &colz );
  1926. X            for ( i=1; i<=table.header.rows; i++ ) {
  1927. X                GetTable(i,colx,&x);
  1928. X                GetTable(i,coly,&y);
  1929. X                SetTable(i,colz,y-(intercept+(slope*x)),FALSE);
  1930. X                }
  1931. X        }                   
  1932. X    else if (strcmp(command.cmdWord[1],"compute")==0 ) {
  1933. X        ;
  1934. X        }                   
  1935. X    else {
  1936. X        ErrMsg(badModifier);
  1937. X        }
  1938. X        
  1939. X    if( !stat ) {
  1940. X        ErrMsg("couldnt set variables");
  1941. X        }
  1942. X}
  1943. X
  1944. XSortTable()
  1945. X{
  1946. X    int sortCol, i, j, k, cmp();
  1947. X    sortRec *s;
  1948. X    long bytesNeeded;
  1949. X    float x;
  1950. X    
  1951. X    SToI( command.cmdWord[1], &sortCol );
  1952. X    if (table.header.interpolated) {
  1953. X        ErrMsg("cant sort interpolated table");
  1954. X        }
  1955. X    if( GoodCol(sortCol)!=0 ) {
  1956. X        ErrMsg("column not in table");
  1957. X        }
  1958. X    bytesNeeded = 6L * (3L + (long)(table.header.rows));
  1959. X    if( (s=NewPtr(bytesNeeded)) == 0L ) {
  1960. X        ErrMsg("not enough free memory");
  1961. X        }
  1962. X    for( i=1; i<=table.header.rows; i++ ) {
  1963. X        (s+i)->r = i;
  1964. X        GetTable( i, sortCol, &x );
  1965. X        if( NaN(&x) ) {
  1966. X            (s+i)->v = minfinity; /*nan's sorted to bottom of table*/
  1967. X            }
  1968. X        else {
  1969. X            (s+i)->v = x;
  1970. X            }
  1971. X        } /*end for*/
  1972. X    qsort( (s+1), table.header.rows, 6,  cmp );
  1973. X    for( j=1; j<=table.header.cols; j++ ) {
  1974. X        for( i=1; i<=table.header.rows; i++ ) {
  1975. X            GetTable( (s+i)->r, j, &x );
  1976. X            (s+i)->v = x;
  1977. X            }
  1978. X        for( i=1; i<=table.header.rows; i++ ) {
  1979. X            SetTable( i, j, (s+i)->v, FALSE );
  1980. X            }
  1981. X        } /* end for j */
  1982. X    DisposPtr(s);
  1983. X}
  1984. X
  1985. Xcmp(a,b)
  1986. XsortRec *a, *b;
  1987. X{
  1988. X    if( (a->v) < (b->v) ) {
  1989. X        return(-1);
  1990. X        }
  1991. X    else if( (a->v) == (b->v) ) {
  1992. X        return(0);
  1993. X        }
  1994. X    else {
  1995. X        return(1);
  1996. X        }
  1997. X}
  1998. X
  1999. XTabInterpolate()
  2000. X{
  2001. X    int *ix, *ixy;    /*ix, iy, and z are temporary arrays created on the heap*/
  2002. X    float *z;
  2003. X    
  2004. X    int ndata, npair, col, i, j, k, il, ir, newRows, oldRows;
  2005. X    int first, found;
  2006. X    float x, y, t, u, v, w;
  2007. X    long bytesNeeded;
  2008. X    char str[cmdWordLen];
  2009. X
  2010. X    if( table.header.interpolated ) {
  2011. X        ErrMsg("table already interpolated");
  2012. X        }
  2013. X    if( table.header.rows < 2 ) {
  2014. X        ErrMsg("not enough rows");
  2015. X        }
  2016. X    if( table.header.cols < 2 ) {
  2017. X        ErrMsg("not enough cols");
  2018. X        }
  2019. X        
  2020. X    SToR( command.cmdWord[1], &(table.header.samp), FALSE );
  2021. X    if (table.header.samp<=0)  {
  2022. X        table.header.samp = 1.0;
  2023. X        ErrMsg("samp must be > 0");
  2024. X        }
  2025. X
  2026. X    bytesNeeded = 2L * (3+table.header.maxRows);
  2027. X    if( (ix=NewPtr(bytesNeeded)) == 0L ) {
  2028. X        ErrMsg("not enough free memory");
  2029. X        }
  2030. X    if( (ixy=NewPtr(bytesNeeded)) == 0L ) {
  2031. X        DisposPtr(ix);
  2032. X        ErrMsg("not enough free memory");
  2033. X        }
  2034. X    bytesNeeded = 4L * (3+table.header.maxRows);
  2035. X    if( (z=NewPtr(bytesNeeded)) == 0L ) {
  2036. X        DisposPtr(ix);
  2037. X        DisposPtr(ixy);
  2038. X        ErrMsg("not enough free memory");
  2039. X        }
  2040. X        
  2041. X    ndata = 0;
  2042. X    first = TRUE;
  2043. X    for( i=1; i<=table.header.rows; i++ ) {
  2044. X        GetTable(i,1,&x);
  2045. X        if (!NaN(&x))  {
  2046. X            if( first ) {
  2047. X                ndata++;
  2048. X                *(ix+ndata) = i;
  2049. X                first = FALSE;
  2050. X                } /*end if first*/
  2051. X            else { /*not first*/
  2052. X                ndata++;
  2053. X                *(ix+ndata) = i;
  2054. X                GetTable( *(ix+ndata-1), 1, &y );
  2055. X                if( x<=y ) {
  2056. X                    DisposPtr(ix);
  2057. X                    DisposPtr(ixy);
  2058. X                    DisposPtr(z);
  2059. X                    ErrMsg("col 1 does not monotonically increase");
  2060. X                    } /*end if x<=y*/
  2061. X                } /*end if not first*/
  2062. X            } /*end if not NaN */
  2063. X        } /*end for*/
  2064. X
  2065. X    if (ndata<2) {
  2066. X        DisposPtr(ix);
  2067. X        DisposPtr(ixy);
  2068. X        DisposPtr(z);
  2069. X        ErrMsg("not enough good x-values");
  2070. X        }
  2071. X        
  2072. X    GetTable(*(ix+1),1,&(table.header.start));
  2073. X    GetTable( *(ix+ndata), 1, &t );
  2074. X    x = 1.0 + ((t-table.header.start)/table.header.samp);
  2075. X    oldRows = table.header.rows;
  2076. X    if (   ((long)x)    >   ((long)table.header.maxRows)  ) {                   
  2077. X        WriteLine("warning. some data lost from end of columns");
  2078. X        newRows = table.header.maxRows;
  2079. X        } /*end if*/
  2080. X    else {
  2081. X        newRows= (int)x;
  2082. X        } /*end if*/
  2083. X
  2084. X    for (col=2;  col<=table.header.cols; col++ ) {
  2085. X        npair = 0;
  2086. X        for( i=1; i<=ndata; i++ ) {
  2087. X            GetTable( *(ix+i), col, &x );
  2088. X                     if (!NaN(&x)) {
  2089. X                npair++;
  2090. X                *(ixy+npair) = *(ix+i);
  2091. X                } /*end if not NaN*/
  2092. X            } /*end for*/
  2093. X            
  2094. X        if (npair<2) {
  2095. X            IToS( col, str );
  2096. X            WritePhrase("warning: not enough data in col ");
  2097. X            WriteLine(str);
  2098. X            table.header.rows = newRows;
  2099. X            for( j=1; j<=table.header.rows; j++ ) {
  2100. X                SetTable(j,col,infinity,FALSE);
  2101. X                }
  2102. X            table.header.rows=oldRows;
  2103. X            } /*end if pairs<2*/
  2104. X        else { /*npairs>=2*/
  2105. X            il = 1;
  2106. X            ir = 2;
  2107. X            for( i=1; i<=newRows; i++ ) {
  2108. X                x = table.header.start + table.header.samp*((float)(i-1));
  2109. X                if( GetTable(*(ixy+il),1,&t) || (x<t) )  {                   
  2110. X                    *(z+i) =infinity;
  2111. X                    } /*end if (x<t)*/
  2112. X                else if( GetTable(*(ixy+npair),1,&t) || (x>t) ) {
  2113. X                    *(z+i) = infinity;
  2114. X                    }
  2115. X                else if( GetTable(*(ixy+il),1,&t) ||  GetTable(*(ixy+ir),1,&u) || ((x>=t)&&(x<=u)) ) {
  2116. X                    GetTable( *(ixy+il), col, &t );
  2117. X                    GetTable( *(ixy+ir),col, &u );
  2118. X                    GetTable( *(ixy+il), 1, &v );
  2119. X                    GetTable( *(ixy+ir), 1, &w );
  2120. X                    *(z+i) = t + (((u-t)/(w-v))*(x-v));
  2121. X                    }
  2122. X                else { /*search*/
  2123. X                    j = il+1;
  2124. X                    found = FALSE;
  2125. X                    while( (!found) && (j<=(npair-1)) ) {
  2126. X                        il = j;
  2127. X                        ir = j+1;
  2128. X                        GetTable( *(ixy+il), 1, &t );
  2129. X                        GetTable( *(ixy+ir), 1, &u );
  2130. X                        if( (x>=t) && (x<=u) ) {
  2131. X                            found = TRUE;
  2132. X                            } /*end in interval*/
  2133. X                        j++;
  2134. X                        } /*end while*/
  2135. X                    GetTable( *(ixy+il), col, &t );
  2136. X                    GetTable( *(ixy+ir),col, &u );
  2137. X                    GetTable( *(ixy+il), 1, &v );
  2138. X                    GetTable( *(ixy+ir), 1, &w );
  2139. X                    *(z+i) = t + (((u-t)/(w-v))*(x-v));
  2140. X                    } /*end else search*/
  2141. X                } /*end for i*/
  2142. X            
  2143. X            table.header.rows = newRows;
  2144. X            for( i=1; i<=table.header.rows; i++ ) {
  2145. X                SetTable( i, col, *(z+i), FALSE );
  2146. X                } /*end for i*/
  2147. X            table.header.rows = oldRows;
  2148. X
  2149. X            } /*end if pairs>=2*/
  2150. X    } /*end for col*/
  2151. X    
  2152. X    table.header.interpolated=TRUE;
  2153. X    table.header.rows = newRows;
  2154. X    Header2Vars();
  2155. X    CreateCol1();
  2156. X    DisposPtr(ix);
  2157. X    DisposPtr(ixy);
  2158. X    DisposPtr(z);
  2159. X}
  2160. ________This_Is_The_END________
  2161. if test `wc -l < regio.c` -ne 850; then
  2162.     echo 'shar: regio.c was damaged during transit'
  2163.   echo '      (should have been 850 bytes)'
  2164. fi
  2165. fi        ; : end of overwriting check
  2166. echo 'Extracting regmain.c'
  2167. if test -f regmain.c; then echo 'shar: will not overwrite regmain.c'; else
  2168. sed 's/^X//' << '________This_Is_The_END________' > regmain.c
  2169. X#include "all.h"
  2170. X#include "regtabint.h"
  2171. X
  2172. Xmain()
  2173. X{
  2174. X    int    t, i, j, k, ii, jj, kk, tBoolean, itop, ileft;
  2175. X    Handle TEScrH;
  2176. X    int    lastEvCoChar, lastEvPrChar;
  2177. X    long    nBytes, offsetTE, lengthTE;
  2178. X    float x, y;
  2179. X    char    c;
  2180. X    GrafPtr    savePort;
  2181. X    void    ScrollUp(), ScrollDown();
  2182. X    void    TScrollUp(), TScrollDown();
  2183. X    Rect    tRect, tRect2;
  2184. X    char    s[cmdWordLen], *gaddr;
  2185. X    
  2186. X    infinity = 0.0;
  2187. X    minfinity = -1.0 / infinity;
  2188. X    infinity = 1.0/infinity;
  2189. X    nCoeffs = 0;
  2190. X    for( i=0; i<33; i++ ) coeffs[i]=0.0;
  2191. X    
  2192. X    lastEvCoChar = FALSE;
  2193. X    lastEvPrChar = FALSE;
  2194. X
  2195. X    macVars.numVars = 0;
  2196. X
  2197. X    InitGraf(&thePort);  /* sets global variables thePort to nil and screenBits to Mac screen */
  2198. X    InitFonts();
  2199. X    FlushEvents(everyEvent,0);
  2200. X    InitWindows();
  2201. X    
  2202. X    /* set up menus */
  2203. X    InitMenus();
  2204. X    myMenu[apMenu] = GetMenu(apMenuRes);
  2205. X    AddResMenu(myMenu[apMenu],'DRVR'); /* desk accesories */
  2206. X    myMenu[fiMenu] = GetMenu(fiMenuRes);
  2207. X    myMenu[edMenu] = GetMenu(edMenuRes);
  2208. X    myMenu[wiMenu] = GetMenu(wiMenuRes);
  2209. X    myMenu[abMenu] = GetMenu(abMenuRes);
  2210. X    for ( i = 0; i < lastMenu; i++ )
  2211. X        InsertMenu(myMenu[i],0);
  2212. X    DrawMenuBar();
  2213. X
  2214. X    TEInit();
  2215. X    InitDialogs(0L);
  2216. X    InitAllPacks();
  2217. X    InitPack(stdFile);    
  2218. X    SetCursor(&arrow);
  2219. X    SetRect(&dragRect, 0, 40, 700, 344);
  2220. X    SetRect(&growRect, 50, 50, windowWidth, windowHeight);
  2221. X    SetRect(&abortRect, 180, 0, 220, 20 );
  2222. X    SetRect(&wayOffScreen,1000,1000,1100,1100);
  2223. X    doneFlag = FALSE;
  2224. X    pendingFlag = FALSE;
  2225. X    InitCursor();
  2226. X    
  2227. X    /* set up graphics window */
  2228. X    grPortPtr = &grPort;
  2229. X    OpenPort( grPortPtr );
  2230. X    SetPort( grPortPtr );
  2231. X    grMap.rowBytes = windowWidth / 8 + 1;
  2232. X    if( (grMap.rowBytes & 1) != 0 ) grMap.rowBytes++;  /* make sure its even */
  2233. X    SetRect( &(grMap.bounds), 0, 0, windowWidth, windowHeight );
  2234. X    nBytes = grMap.rowBytes * (grMap.bounds.bottom - grMap.bounds.top);
  2235. X    grMap.baseAddr = NewPtr(nBytes);
  2236. X    grPort.portBits = grMap;
  2237. X    grPort.portRect = grMap.bounds;
  2238. X    SetPort( grPortPtr );
  2239. X    gaddr = (char*) grMap.baseAddr;
  2240. X    for( i=0; i<nBytes; i++ ) {
  2241. X        *gaddr = '\0';
  2242. X        gaddr++;
  2243. X        } /*end for*/
  2244. X    EraseRect( &(grPort.portRect) );
  2245. X    FrameRect( &(grPort.portRect) );
  2246. X    
  2247. X    SetPort( thePort );
  2248. X            
  2249. X    /* define windows */
  2250. X
  2251. X    theWindow[edWindow] = GetNewWindow( edWndRes, &wRecord[0], -1L );
  2252. X    theWindow[prWindow] = GetNewWindow( prWndRes, &wRecord[1], -1L );
  2253. X    theWindow[grWindow] = GetNewWindow( grWndRes, &wRecord[2], -1L );
  2254. X    theWindow[coWindow] = GetNewWindow( coWndRes, &wRecord[3], -1L );
  2255. X    for( i=0; i<lastWindow; i++ ) {
  2256. X        theWindow[i]->txFont = 2;
  2257. X             vScroll[i] = GetNewControl( 256, theWindow[i]);
  2258. X        hScroll[i] = GetNewControl( 257, theWindow[i]);
  2259. X        theOrigin[i].h = 0; 
  2260. X        theOrigin[i].v = 0;
  2261. X        topPixel[i] = 1;
  2262. X        leftPixel[i] = 1;
  2263. X        }  /* end for */
  2264. X    
  2265. X    /* command window */
  2266. X    SetPort(theWindow[coWindow]);
  2267. X    SetRect(&tRect, 4, 4, 720, 364);
  2268. X    tRect2 = theWindow[coWindow]->portRect;
  2269. X    IndentRect( &tRect2 );
  2270. X    coText = TENew( &tRect, &tRect2 );
  2271. X    (*coText)->crOnly = -1;
  2272. X    TEInsert("Scientist\'s Helper, Version 2.7, by William Menke\r",50L,coText);
  2273. X    TEInsert("Caveat Emptor\r",14L,coText);
  2274. X    TEInsert("\r",1L,coText);
  2275. X    
  2276. X    /* procedure window */
  2277. X    SetPort(theWindow[prWindow]);
  2278. X    SetRect(&tRect, 4, 4, 720, 364);
  2279. X    tRect2 = theWindow[prWindow]->portRect;
  2280. X    IndentRect( &tRect2 );
  2281. X    prText = TENew( &tRect, &tRect2 );
  2282. X    (*prText)->crOnly = -1;
  2283. X    TEInsert("label sample\r",13L,prText);
  2284. X    TEInsert("prompt \'hi there\'\r",18L,prText);
  2285. X    TEInsert("return\r",7L,prText);
  2286. X
  2287. X    /*table edit window */
  2288. X    SetPort(theWindow[edWindow]);
  2289. X    edText = TENew( &wayOffScreen, &wayOffScreen );
  2290. X    (*edText)->crOnly = -1;
  2291. X    (*edText)->txSize = 10;
  2292. X    (*edText)->txFont = geneva;
  2293. X    TextFont(geneva);
  2294. X    TextSize(10);
  2295. X    for( i=0; i<4; i++ ) {
  2296. X        SetRect( &(tabEd.name[i]), ((i+1)*100)+1, 1, (i+2)*100, 15 );
  2297. X        }
  2298. X    for( i=0; i<19; i++ ) {
  2299. X        SetRect( &(tabEd.row[i]), 1, ((i+1)*15)+1, 100, (i+2)*15 );
  2300. X        }
  2301. X    for( i=0; i<19; i++ ) {
  2302. X    for( j=0; j<4; j++ ) {
  2303. X        SetRect( &(tabEd.entry[i][j]), ((j+1)*100)+1,  ((i+1)*15)+1,  (j+2)*100,  (i+2)*15  );
  2304. X        } }
  2305. X    tabEd.activeEntry = FALSE;
  2306. X    tabEd.activeName = FALSE;
  2307. X    
  2308. X    LoadSg1(); /*force load of all segments of program*/
  2309. X    LoadSg2();
  2310. X    LoadSg3();
  2311. X    
  2312. X    InitTable(); /*initialize table*/
  2313. X    WritePhrase("> ");
  2314. X    
  2315. X    /* initialize procedure info */
  2316. X    mem.active = FALSE;
  2317. X    mem.stackPtr = -1;
  2318. X    mem.numLabels = 0;
  2319. X    loops.numLoops = 0;
  2320. X    
  2321. X    graph.xMin = 0.0;
  2322. X    graph.xMax = 1.0;
  2323. X    graph.yMin = 0.0;
  2324. X    graph.yMax = 1.0;
  2325. X    Graph2Vars();
  2326. X
  2327. X    currentWindow = -1;
  2328. X    scrapIndex = -1;
  2329. X    SelectWindow(theWindow[coWindow]);
  2330. X    ZeroScrap();
  2331. X    setjmp(envbuf);
  2332. X    
  2333. X
  2334. X    do {
  2335. X    
  2336. X        SystemTask();
  2337. X        
  2338. X        if( scrapIndex != (InfoScrap())->scrapCount ) {
  2339. X            scrapIndex = (InfoScrap())->scrapCount;
  2340. X            lengthTE = GetScrap( TEScrapHndl(), 'TEXT', &offsetTE );
  2341. X            if (lengthTE>0) (*((short *) 0x0AB0)) = lengthTE;
  2342. X            }
  2343. X            
  2344. X        GetNextEvent(everyEvent,&myEvent);
  2345. X        
  2346. X        while ( (*coText)->teLength > maxCoChars ) { /*nips top off of command window if too big*/
  2347. X            TECalText(coText);
  2348. X            i = (*coText)->selStart;
  2349. X            j = (*coText)->selEnd;
  2350. X            ii = (*coText)->lineStarts[0];
  2351. X            jj = (*coText)->lineStarts[1];
  2352. X            t = currentWindow;
  2353. X            GetPort( &oldPort );
  2354. X            SetPort( theWindow[coWindow] );
  2355. X            currentWindow = coWindow;
  2356. X            whichWindow = theWindow[currentWindow];
  2357. X            TESetSelect( (long)ii, (long)jj, coText );
  2358. X            TEDelete( coText );
  2359. X            kk = jj - ii;
  2360. X            TESetSelect( (long)(i-kk), (long)(j-kk), coText );
  2361. X            IfOutScroll(coText);
  2362. X            SetPort( oldPort );
  2363. X            currentWindow=t;
  2364. X            whichWindow = theWindow[currentWindow];
  2365. X            }
  2366. X            
  2367. X        if (mem.active && (!pendingFlag) && (myEvent.what==nullEvent) ) {   /*get command line from procedure memory*/
  2368. X            mem.stack[ mem.stackPtr ] ++;
  2369. X                    if (mem.stack[mem.stackPtr] >= (*prText)->nLines ) {                   
  2370. X                ErrMsg(    "attempt to read past end of procedure" );
  2371. X                } /*end if error*/
  2372. X            HLock((*prText)->hText);
  2373. X            j=(*prText)->lineStarts[mem.stack[mem.stackPtr]];
  2374. X            k=(*prText)->teLength;
  2375. X            ExtractLine( *((*prText)->hText), j, k, s );
  2376. X            HUnlock((*prText)->hText);
  2377. X            CmdFromWnd(s,FALSE);
  2378. X            } /*end if procedure is running*/
  2379. X                
  2380. X        TEIdle(coText);
  2381. X        TEIdle(prText);
  2382. X        TEIdle(edText);
  2383. X
  2384. X        switch(myEvent.what) {
  2385. X            case activateEvt:
  2386. X                lastEvCoChar=FALSE;
  2387. X                lastEvPrChar=FALSE;
  2388. X                   /* activate events return a window pointer as their message */
  2389. X                   /* find the window that corresponds to this pointer (if any) */
  2390. X                
  2391. X                /*cant activate procedure or edit window if procedure is running*/
  2392. X                whichWindow = (WindowPtr)myEvent.message;
  2393. X                GetWndNumber(whichWindow);
  2394. X                if( currentWindow < 0 )  /* window not found */
  2395. X                    break;
  2396. X                SetPort(theWindow[currentWindow]);
  2397. X                if (myEvent.modifiers&1) {
  2398. X                    ShowControl(vScroll[currentWindow]);
  2399. X                    ShowControl(hScroll[currentWindow]);
  2400. X                    DrawControls(theWindow[currentWindow]);
  2401. X                    DrawGrowIcon(theWindow[currentWindow]);
  2402. X                    if( currentWindow == coWindow ) {
  2403. X                        TEActivate( coText );
  2404. X                             }
  2405. X                    else if( currentWindow == prWindow ) {
  2406. X                        TEActivate( prText );
  2407. X                        }
  2408. X                    else if( (currentWindow==edWindow) &&
  2409. X                                (tabEd.activeName||tabEd.activeEntry) ) {
  2410. X                        TEActivate( edText );
  2411. X                        }
  2412. X                }
  2413. X                else {
  2414. X                    if( currentWindow == coWindow ) {
  2415. X                        TEDeactivate( coText );
  2416. X                        }
  2417. X                    else if( currentWindow == prWindow ) {
  2418. X                        TEDeactivate( prText );
  2419. X                        }
  2420. X                    else if( currentWindow == edWindow ) {
  2421. X                        TEDeactivate( edText );
  2422. X                        ClipRect( &(whichWindow->portRect) );
  2423. X                        }
  2424. X                    HideControl(vScroll[currentWindow]);
  2425. X                    HideControl(hScroll[currentWindow]);
  2426. X                }
  2427. X                break;
  2428. X                
  2429. X            case updateEvt :
  2430. X                lastEvCoChar=FALSE;
  2431. X                lastEvPrChar=FALSE;
  2432. X
  2433. X                GetPort(&savePort);
  2434. X                whichWindow = (WindowPtr)myEvent.message;
  2435. X                GetWndNumber(whichWindow);
  2436. X                if( currentWindow < 0 )  /* window not found */
  2437. X                    break;
  2438. X                SetPort(theWindow[currentWindow]);
  2439. X                BeginUpdate(theWindow[currentWindow]);
  2440. X                EraseRect(&theWindow[currentWindow]->portRect);
  2441. X                DrawWindow();
  2442. X                EndUpdate(theWindow[currentWindow]);
  2443. X                SetPort(savePort);
  2444. X                break;
  2445. X                
  2446. X            case mouseDown : 
  2447. X                lastEvCoChar=FALSE;
  2448. X                lastEvPrChar=FALSE;
  2449. X
  2450. X                /* code returns what type of window */
  2451. X                code = FindWindow(pass(myEvent.where), &whichWindow);
  2452. X                GetWndNumber(whichWindow);
  2453. X                    
  2454. X                /* determine if this window is up front */
  2455. X                if ( whichWindow == FrontWindow() )
  2456. X                    frontFlag = TRUE;
  2457. X                else
  2458. X                    frontFlag = FALSE;
  2459. X
  2460. X                switch(code) {
  2461. X                    case inMenuBar :
  2462. X                        DoCommand(MenuSelect(pass(myEvent.where)));
  2463. X                        break;    
  2464. X                    case inSysWindow :
  2465. X                        SystemClick(&myEvent,whichWindow);
  2466. X                        break;
  2467. X                    case inDrag :
  2468. X                        if( frontFlag ) {
  2469. X                            DragWindow(whichWindow,pass(myEvent.where),
  2470. X                                    &dragRect);
  2471. X                            }
  2472. X                        else {
  2473. X                            if( !( (mem.active||pendingFlag) &&
  2474. X                              ( (currentWindow==prWindow) ||
  2475. X                                (currentWindow==edWindow) ) ) ) {
  2476. X                              SelectWindow(whichWindow);
  2477. X                              }
  2478. X                              }
  2479. X                        break;
  2480. X                    case inGrow :
  2481. X                        if (frontFlag) {
  2482. X                            GrowWnd(whichWindow);
  2483. X                            }
  2484. X                        else {
  2485. X                            if( !( (mem.active||pendingFlag) &&
  2486. X                              ( (currentWindow==prWindow) ||
  2487. X                                (currentWindow==edWindow) ) ) ) {
  2488. X                              SelectWindow(whichWindow);
  2489. X                              }
  2490. X                            }
  2491. X                        break;
  2492. X                    case inContent :
  2493. X                        if (frontFlag && (currentWindow==coWindow)) {
  2494. X                            GlobalToLocal(&myEvent.where);
  2495. X                            MyControl = FindControl(pass(myEvent.where),
  2496. X                                            whichWindow,&whichControl);
  2497. X                            switch(MyControl) {
  2498. X                            case inUpButton :
  2499. X                              TrackControl(whichControl,pass(myEvent.where),
  2500. X                                       TScrollUp);
  2501. X                              break;
  2502. X                            case inDownButton :
  2503. X                              TrackControl(whichControl,pass(myEvent.where),
  2504. X                                       TScrollDown);
  2505. X                              break;
  2506. X                            case inPageUp :
  2507. X                              TPageScroll(MyControl,-6400);
  2508. X                              break;
  2509. X                            case inPageDown :
  2510. X                              TPageScroll(MyControl,6400);
  2511. X                              break;
  2512. X                            case inThumb :
  2513. X                              t = TrackControl(whichControl,pass(myEvent.where),
  2514. X                                       0L);
  2515. X                              ScrollBits();
  2516. X                              break;
  2517. X                            default:
  2518. X                                  if( (myEvent.modifiers&shiftKey) == 1 )
  2519. X                                     tBoolean = TRUE;
  2520. X                                  else
  2521. X                                       tBoolean = FALSE;
  2522. X                                  TEClick(pass(myEvent.where),tBoolean,coText);
  2523. X                                  } /*end switch MyControl*/
  2524. X                            } /*end if coWindow*/
  2525. X                        else if (frontFlag && (currentWindow==grWindow)) {
  2526. X                            GlobalToLocal(&myEvent.where);
  2527. X                            MyControl = FindControl(pass(myEvent.where),
  2528. X                                            whichWindow,&whichControl);
  2529. X                            switch(MyControl) {
  2530. X                            case inUpButton :
  2531. X                              TrackControl(whichControl,pass(myEvent.where),
  2532. X                                       ScrollUp);
  2533. X                              break;
  2534. X                            case inDownButton :
  2535. X                              TrackControl(whichControl,pass(myEvent.where),
  2536. X                                       ScrollDown);
  2537. X                              break;
  2538. X                            case inPageUp :
  2539. X                              PageScroll(MyControl,-6400);
  2540. X                              break;
  2541. X                            case inPageDown :
  2542. X                              PageScroll(MyControl,6400);
  2543. X                              break;
  2544. X                            case inThumb :
  2545. X                              t = TrackControl(whichControl,pass(myEvent.where),
  2546. X                                       0L);
  2547. X                              ScrollBits();
  2548. X                              break;
  2549. X                            default:
  2550. X                               i = (myEvent.where.h+theOrigin[grWindow].h);
  2551. X                               j = (myEvent.where.v+theOrigin[grWindow].v);
  2552. X                               InvGraphScale( i, j, &x, &y );
  2553. X                               RToS( x, s );
  2554. X                               currentWindow=coWindow;
  2555. X                               whichWindow=theWindow[coWindow];
  2556. X                               SetPort(theWindow[currentWindow]);
  2557. X                               if(!SetVar("xpos",s)){
  2558. X                                 ErrMsg("couldnt set xpos variable");
  2559. X                                 }
  2560. X                               WritePhrase(s);
  2561. X                               WritePhrase(" ");
  2562. X                               RToS( y, s );
  2563. X                               if(!SetVar("ypos",s)){
  2564. X                                 ErrMsg("couldnt set ypos variable");
  2565. X                                 }
  2566. X                               WriteLine(s);
  2567. X                               currentWindow=grWindow;
  2568. X                               whichWindow=theWindow[grWindow];
  2569. X                               SetPort(theWindow[currentWindow]);
  2570. X                               if(pendingFlag) {
  2571. X                                   currentWindow=grWindow;
  2572. X                                 whichWindow=theWindow[coWindow];
  2573. X                                 SelectWindow(theWindow[coWindow]);
  2574. X                                 PostEvent(keyDown,(long)'\r');
  2575. X                                 longjmp(envbuf,-1);
  2576. X                                 }
  2577. X                            } /*end switch MyControl */
  2578. X                            } /*end if grWindow*/
  2579. X                        else if (frontFlag && (currentWindow==prWindow)) {
  2580. X                            GlobalToLocal(&myEvent.where);
  2581. X                            MyControl = FindControl(pass(myEvent.where),
  2582. X                                            whichWindow,&whichControl);
  2583. X                            switch(MyControl) {
  2584. X                                case inUpButton :
  2585. X                              TrackControl(whichControl,pass(myEvent.where),
  2586. X                                       TScrollUp);
  2587. X                              break;
  2588. X                            case inDownButton :
  2589. X                              TrackControl(whichControl,pass(myEvent.where),
  2590. X                                       TScrollDown);
  2591. X                              break;
  2592. X                            case inPageUp :
  2593. X                              TPageScroll(MyControl,-6400);
  2594. X                              break;
  2595. X                            case inPageDown :
  2596. X                              TPageScroll(MyControl,6400);
  2597. X                              break;
  2598. X                            case inThumb :
  2599. X                              t = TrackControl(whichControl,pass(myEvent.where),
  2600. X                                       0L);
  2601. X                              ScrollBits();
  2602. X                              break;
  2603. X                            default:
  2604. X                                  if( (myEvent.modifiers&shiftKey) == 1 )
  2605. X                                     tBoolean = TRUE;
  2606. X                                  else
  2607. X                                       tBoolean = FALSE;
  2608. X                                  TEClick(pass(myEvent.where),tBoolean,prText);
  2609. X                                  } /*end switch MyControl*/
  2610. X                            }/*end if prWindow*/
  2611. X                        else if (frontFlag && (currentWindow==edWindow)) {
  2612. X                            GlobalToLocal(&myEvent.where);
  2613. X                            MyControl = FindControl(pass(myEvent.where),
  2614. X                                            whichWindow,&whichControl);
  2615. X                            switch(MyControl) {
  2616. X                            case inUpButton :
  2617. X                              TrackControl(whichControl,pass(myEvent.where),
  2618. X                                       TScrollUp);
  2619. X                              break;
  2620. X                            case inDownButton :
  2621. X                              TrackControl(whichControl,pass(myEvent.where),
  2622. X                                       TScrollDown);
  2623. X                              break;
  2624. X                            case inPageUp :
  2625. X                              TPageScroll(MyControl,-6400);
  2626. X                              break;
  2627. X                            case inPageDown :
  2628. X                              TPageScroll(MyControl,6400);
  2629. X                              break;
  2630. X                            case inThumb :
  2631. X                              t = TrackControl(whichControl,pass(myEvent.where),
  2632. X                                       0L);
  2633. X                              ScrollBits();
  2634. X                              break;
  2635. X                            default:
  2636. X                               ileft = (GetCtlValue(hScroll[edWindow])/1024)+1;
  2637. X                               itop = (GetCtlValue(vScroll[edWindow])/8)+1;
  2638. X                               ResizePRect();
  2639. X                                   ClipRect( &pRect );
  2640. X                               if( tabEd.activeName || tabEd.activeEntry ) {
  2641. X                                    /*get text from edit record and delete the text*/
  2642. X                                   HLock((*edText)->hText);
  2643. X                                i=(*edText)->teLength;
  2644. X                                ExtractLine( *((*edText)->hText), 0, (i-1), s );
  2645. X                                HUnlock((*edText)->hText);
  2646. X                                TEDeactivate(edText);
  2647. X                                TESetSelect( 0L, (long)i, edText );
  2648. X                                TEDelete(edText);
  2649. X                                }
  2650. X                              if( tabEd.activeName ) {
  2651. X                                    if( GoodCol(tabEd.c)==0 ) {
  2652. X                                  strcpy( table.header.colName[tabEd.c-1], s );
  2653. X                                  }
  2654. X                                else {
  2655. X                                  SysBeep(5);
  2656. X                                  strcpy( s, " ");
  2657. X                                  }
  2658. X                                EraseRect( &(tabEd.name[tabEd.c-ileft]) );
  2659. X                                MoveTo( (tabEd.name[tabEd.c-ileft]).left+1,
  2660. X                                         (tabEd.name[tabEd.c-ileft]).bottom-2 );
  2661. X                                DrawText( s, 0, strlen(s) );
  2662. X                                }
  2663. X                              else if( tabEd.activeEntry ) {
  2664. X                                     if( (GoodCol(tabEd.c)==0) && (GoodRow(tabEd.r)==0) ) {
  2665. X                                        if( table.header.interpolated && (tabEd.c==1) ) {
  2666. X                                            SysBeep(5);
  2667. X                                        GetTable( tabEd.r, 1, &x );
  2668. X                                        RToS(x,s);
  2669. X                                                }
  2670. X                                         else {
  2671. X                                                SToR( s, &x, TRUE );
  2672. X                                        RToS( x, s, TRUE );
  2673. X                                            SetTable( tabEd.r, tabEd.c, x, FALSE );
  2674. X                                            }
  2675. X                                     }
  2676. X                                  else {
  2677. X                                     SysBeep(5);
  2678. X                                     strcpy(s,"");
  2679. X                                     }
  2680. X                                 EraseRect( &(tabEd.entry[tabEd.r-itop][tabEd.c-ileft]) );
  2681. X                                 MoveTo( (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).left+1,
  2682. X                                         (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).bottom-2 );
  2683. X                                 DrawText( s, 0, strlen(s) );
  2684. X                                }
  2685. X                                  tabEd.activeName=FALSE;
  2686. X                              tabEd.activeEntry=FALSE;
  2687. X                              for( j=0; j<4; j++ ) {
  2688. X                                  if( PtInRect( pass(myEvent.where), &(tabEd.name[j]) ) ){
  2689. X                                    tabEd.c=ileft+j;
  2690. X                                    tabEd.activeName=TRUE;
  2691. X                                    jj=j;
  2692. X                                    break;
  2693. X                                    } /*end if*/
  2694. X                                } /*end for*/
  2695. X                              for( i=0; (i<19)&&(!tabEd.activeName);i++ ) {
  2696. X                              for( j=0; j<4; j++ ) {
  2697. X                                  if( PtInRect( pass(myEvent.where), &(tabEd.entry[i][j]) ) ) {
  2698. X                                    tabEd.r=itop+i;
  2699. X                                    tabEd.c=ileft+j;
  2700. X                                    tabEd.activeEntry=TRUE;
  2701. X                                    ii=i;
  2702. X                                    jj=j;
  2703. X                                    break;
  2704. X                                    } /*end if*/
  2705. X                                } } /*end fors*/
  2706. X                              if( tabEd.activeName ) {
  2707. X                                   if( GoodCol(tabEd.c)!=0 ) {
  2708. X                                         SysBeep(5);
  2709. X                                     tabEd.activeName=FALSE;
  2710. X                                     break;
  2711. X                                     }
  2712. X                                     (*edText)->destRect=tabEd.name[jj];
  2713. X                                 ResizeEdBox();
  2714. X                                 TESetSelect( 0L, (long)(*edText)->teLength, edText );
  2715. X                                 TEDelete(edText);
  2716. X                                 TEInsert( table.header.colName[tabEd.c-1], 
  2717. X                                        (long)strlen(table.header.colName[tabEd.c-1]), edText );
  2718. X                                 TESetSelect( 0L, (long)((*edText)->teLength), edText );
  2719. X                                 TEActivate( edText );
  2720. X                                 TEUpdate(&((*edText)->viewRect),edText);
  2721. X                                  }
  2722. X                              else if( tabEd.activeEntry ) {
  2723. X                                     if( (GoodRow(tabEd.r)!=0) || (GoodCol(tabEd.c)!=0)
  2724. X                                      || ((tabEd.c==1)&&table.header.interpolated) ) {
  2725. X                                      SysBeep(5);
  2726. X                                      tabEd.activeEntry=FALSE;
  2727. X                                      break;
  2728. X                                      }
  2729. X                                     (*edText)->destRect=tabEd.entry[ii][jj];
  2730. X                                 ResizeEdBox();
  2731. X                                 GetTable( tabEd.r, tabEd.c, &x );
  2732. X                                 RToS( x, s );
  2733. X                                 TESetSelect( 0L, (long)(*edText)->teLength, edText );
  2734. X                                 TEDelete(edText);
  2735. X                                 TEInsert( s, (long)strlen(s), edText );
  2736. X                                 TESetSelect( 0L, (long)((*edText)->teLength), edText );
  2737. X                                 TEActivate( edText );
  2738. X                                 TEUpdate(&((*edText)->viewRect),edText);
  2739. X                                  }
  2740. X                              else {
  2741. X                                  SysBeep(5);
  2742. X                                }
  2743. X                              } /*end switch MyControl*/
  2744. X                            }/*end if edWindow*/
  2745. X                        else {
  2746. X                            if( !( (mem.active||pendingFlag) &&
  2747. X                              ( (currentWindow==prWindow) ||
  2748. X                                (currentWindow==edWindow) ) ) ) {
  2749. X                              SelectWindow(whichWindow);
  2750. X                              }
  2751. X                              }
  2752. X                        break;
  2753. X                    } /* end switch code */
  2754. X                break;
  2755. X                
  2756. X            case keyDown:
  2757. X            case autoKey:
  2758. X                if( mem.active && (!pendingFlag) ) {
  2759. X                    break;
  2760. X                    }
  2761. X                c = (char) (myEvent.message & charCodeMask);
  2762. X                whichWindow = FrontWindow();
  2763. X                GetWndNumber(whichWindow);
  2764. X                SetPort(whichWindow);
  2765. X                if( ((myEvent.modifiers & cmdKey) != 0) 
  2766. X                  && ((currentWindow==coWindow) || (currentWindow==prWindow)
  2767. X                  || (currentWindow==grWindow)  || (currentWindow==edWindow) )
  2768. X                  ) {
  2769. X                       DoCommand( MenuKey(c) );
  2770. X                       } /*end if cmdkey down*/
  2771. X                else if (currentWindow == coWindow) {
  2772. X                          if( c==(char)3 ) c='\r'; /*enter key is return*/
  2773. X                          TEKey( c, coText );
  2774. X                      if( (!lastEvCoChar) || (c=='\r') ) IfOutScroll( coText);
  2775. X                      if( (c=='\r') &&
  2776. X                          ((*coText)->selEnd >= ((*coText)->teLength-1)) ) {
  2777. X                              HLock((*coText)->hText);
  2778. X                        j=(*coText)->lineStarts[(*coText)->nLines-1];
  2779. X                        k=(*coText)->teLength-2;
  2780. X                        ExtractLine( *((*coText)->hText), j, k, s );
  2781. X                        HUnlock((*coText)->hText);
  2782. X                        CmdFromWnd(s,TRUE);
  2783. X                            } /*end if return*/
  2784. X                      lastEvCoChar=TRUE;
  2785. X                          lastEvPrChar=FALSE;
  2786. X                              } /* end if coWindow and frontwindow */
  2787. X                else if( (currentWindow==prWindow) && (!pendingFlag) ){
  2788. X                          if( c==(char)3 ) c='\r'; /*enter key is return*/
  2789. X                          TEKey( c, prText );
  2790. X                      if( (!lastEvPrChar) || (c=='\r') ) IfOutScroll( prText );
  2791. X                          lastEvCoChar=FALSE;
  2792. X                          lastEvPrChar=TRUE;
  2793. X                          } /*end if prWindow and frontwindow*/
  2794. X                else if( currentWindow==grWindow) {
  2795. X                    lastEvCoChar=FALSE;
  2796. X                    lastEvPrChar=FALSE;
  2797. X                    SysBeep(5);
  2798. X                    }
  2799. X                else if( (currentWindow==edWindow) && (tabEd.activeEntry||tabEd.activeName) ){
  2800. X                    lastEvCoChar=FALSE;
  2801. X                    lastEvPrChar=FALSE;
  2802. X                      ResizePRect();
  2803. X                      ClipRect( &pRect );
  2804. X                          if( c==(char)3 ) c='\r'; /*enter key is return*/
  2805. X                          TEKey( c, edText );
  2806. X                      if( c=='\r' ) {
  2807. X                              HLock((*edText)->hText);
  2808. X                        ExtractLine( *((*edText)->hText), 0, (*edText)->teLength-1, s );
  2809. X                        HUnlock((*edText)->hText);
  2810. X                        if( tabEd.activeName ) {
  2811. X                            strcpy( table.header.colName[tabEd.c-1], s );
  2812. X                            tabEd.activeName=FALSE;
  2813. X                            strcpy(s,"");
  2814. X                            }
  2815. X                         else if( tabEd.activeEntry ) {
  2816. X                             SToR( s, &x );
  2817. X                             SetTable( tabEd.r, tabEd.c, x, FALSE );
  2818. X                             if (GoodRow(tabEd.r+1)==0) {
  2819. X                                tabEd.r++;
  2820. X                                GetTable(tabEd.r,tabEd.c,&x);
  2821. X                            RToS( x, s );
  2822. X                            }
  2823. X                                 else {
  2824. X                                tabEd.activeEntry=FALSE;
  2825. X                                strcpy(s,"");
  2826. X                            }
  2827. X                             SetCtlValue(vScroll[edWindow],GetCtlValue(vScroll[edWindow])+8);
  2828. X                             }
  2829. X                         ClipRect( &(whichWindow->portRect) );
  2830. X                         InvalRect(&(whichWindow->portRect));
  2831. X                         (*edText)->destRect = wayOffScreen;
  2832. X                         (*edText)->viewRect = wayOffScreen;
  2833. X                         TESetSelect( 0L, (long)(*edText)->teLength, edText );
  2834. X                         TEDelete(edText);
  2835. X                         TEInsert(s,(long)strlen(s),edText);
  2836. X                         TESetSelect( 0L, (long)(*edText)->teLength, edText );
  2837. X                         TEActivate(edText);
  2838. X                         } /*end if return*/
  2839. X                          } /* end if edWindow and frontwindow */
  2840. X                break;
  2841. X    
  2842. X            } /* end switch what event */
  2843. X        } while ( !(doneFlag=done()) ) ;
  2844. X        
  2845. X    TEScrH=TEScrapHndl();
  2846. X    HLock(TEScrH);
  2847. X    ZeroScrap();
  2848. X    PutScrap( TEGetScrpLen(), 'TEXT', *TEScrH );
  2849. X    HUnlock(TEScrH);
  2850. X    scrapIndex = (InfoScrap())->scrapCount;
  2851. X
  2852. X    ExitToShell();
  2853. X} /* end main */
  2854. ________This_Is_The_END________
  2855. if test `wc -l < regmain.c` -ne 685; then
  2856.     echo 'shar: regmain.c was damaged during transit'
  2857.   echo '      (should have been 685 bytes)'
  2858. fi
  2859. fi        ; : end of overwriting check
  2860. echo 'Extracting regmanip.c'
  2861. if test -f regmanip.c; then echo 'shar: will not overwrite regmanip.c'; else
  2862. sed 's/^X//' << '________This_Is_The_END________' > regmanip.c
  2863. X#include "all.h"
  2864. X#include "regtabext.h"
  2865. X
  2866. XLoadSg1() /*force load of segment*/
  2867. X{
  2868. X    ;
  2869. X}
  2870. X
  2871. XColMin(col, min)
  2872. Xint col;
  2873. Xfloat *min;
  2874. X{
  2875. X    int i;
  2876. X    float x, y;
  2877. X    if (!NextNotNan( 1, col, col, &i ) ){
  2878. X        *min=infinity;
  2879. X        }
  2880. X    else {
  2881. X        GetTable(i,col,&x);
  2882. X        i++;
  2883. X        while( NextNotNan(i,col,col,&i) ) {
  2884. X            GetTable(i,col,&y);
  2885. X            if (y<x) {
  2886. X                x = y;
  2887. X                }
  2888. X            i++;
  2889. X            } /*end while*/
  2890. X        *min=x;
  2891. X        }
  2892. X}
  2893. X
  2894. XColMax(col,max)
  2895. Xint col;
  2896. Xfloat *max;
  2897. X{
  2898. X    int i;
  2899. X    float x, y;
  2900. X
  2901. X    if (!NextNotNan( 1, col, col, &i ) ) {                   
  2902. X        *max=infinity;
  2903. X        }                   
  2904. X    else {
  2905. X        GetTable(i,col,&x);
  2906. X        i++;
  2907. X        while (NextNotNan(i,col,col,&i)) {                   
  2908. X            GetTable(i,col,&y);
  2909. X            if (y>x) {
  2910. X                x = y;
  2911. X                }
  2912. X            i++;
  2913. X            } /*end while*/
  2914. X        *max=x;
  2915. X        } /*end if*/
  2916. X}
  2917. X
  2918. XGScan()
  2919. X{
  2920. X    int i, j; 
  2921. X    
  2922. X    SToI( command.cmdWord[1], &i );
  2923. X    SToI( command.cmdWord[2], &j );
  2924. X    if( (GoodCol(i)!=0) || (GoodCol(j)!=0) ) {
  2925. X        ErrMsg(noSuchColumn);
  2926. X        }
  2927. X    ColMin(i,&(graph.xMin));
  2928. X    ColMax(i,&(graph.xMax));
  2929. X    ColMin(j,&(graph.yMin));
  2930. X    ColMax(j,&(graph.yMax));
  2931. X}
  2932. X
  2933. XColMath()
  2934. X{
  2935. X    int xcol, ycol, result, i, rows;
  2936. X    float x, y;
  2937. X
  2938. X    SToI( command.cmdWord[5], &result );
  2939. X    rows=table.header.rows;
  2940. X    if( (strcmp(command.cmdWord[2],"+")==0) || (strcmp(command.cmdWord[2],"-")==0) ||
  2941. X         (strcmp(command.cmdWord[2],"*")==0) || (strcmp(command.cmdWord[2],"/")==0)  )  {                   
  2942. X        SToI( command.cmdWord[1], &xcol );
  2943. X        SToI( command.cmdWord[3], &ycol );
  2944. X        if( strcmp(command.cmdWord[2],"+")==0 ) {
  2945. X            for(  i=1; i<=rows; i++ ) {
  2946. X                GetTable(i,xcol,&x);
  2947. X                GetTable(i,ycol,&y);
  2948. X                SetTable(i,result,(x+y),FALSE);
  2949. X                } /*end for*/
  2950. X            }
  2951. X        else if( strcmp(command.cmdWord[2],"-")==0 ) {
  2952. X            for(  i=1; i<=rows; i++ ) {
  2953. X                GetTable(i,xcol,&x);
  2954. X                GetTable(i,ycol,&y);
  2955. X                SetTable(i,result,(x-y),FALSE);
  2956. X                } /*end for*/
  2957. X            }
  2958. X        else if( strcmp(command.cmdWord[2],"*")==0 ) {
  2959. X            for(  i=1; i<=rows; i++ ) {
  2960. X                GetTable(i,xcol,&x);
  2961. X                GetTable(i,ycol,&y);
  2962. X                if( NaN(&y) ) {
  2963. X                    SetTable(i,result,infinity,FALSE);
  2964. X                    }
  2965. X                else {
  2966. X                    SetTable(i,result,(x*y),FALSE);
  2967. X                    }
  2968. X                } /*end for*/
  2969. X            }
  2970. X        else if( strcmp(command.cmdWord[2],"/")==0 ) {
  2971. X            for(  i=1; i<=rows; i++ ) {
  2972. X                GetTable(i,xcol,&x);
  2973. X                GetTable(i,ycol,&y);
  2974. X                SetTable(i,result,(x/y),FALSE);
  2975. X                } /*end for*/
  2976. X            }
  2977. X        }
  2978. X    else if( (strcmp(command.cmdWord[2],"+#")==0) || (strcmp(command.cmdWord[2],"-#")==0) ||
  2979. X                (strcmp(command.cmdWord[2],"*#")==0) || (strcmp(command.cmdWord[2],"/#")==0)  )  {                   
  2980. X        SToI( command.cmdWord[1], &xcol );
  2981. X        SToR( command.cmdWord[3], &y, TRUE );
  2982. X        if (strcmp(command.cmdWord[2],"+#")==0)  {                   
  2983. X            for (i=1; i<=rows; i++) {                   
  2984. X                GetTable(i,xcol,&x);
  2985. X                SetTable(i,result,(x+y),FALSE);
  2986. X                } /*end for*/
  2987. X            }
  2988. X        else if (strcmp(command.cmdWord[2],"-#")==0)  {                   
  2989. X            for (i=1; i<=rows; i++) {                   
  2990. X                GetTable(i,xcol,&x);
  2991. X                SetTable(i,result,(x-y),FALSE);
  2992. X                } /*end for*/
  2993. X            }
  2994. X        else if (strcmp(command.cmdWord[2],"*#")==0)  {                   
  2995. X            for (i=1; i<=rows; i++) {                   
  2996. X                GetTable(i,xcol,&x);
  2997. X                SetTable(i,result,(x*y),FALSE);
  2998. X                } /*end for*/
  2999. X            }
  3000. X        else if (strcmp(command.cmdWord[2],"/#")==0)  {                   
  3001. X            for (i=1; i<=rows; i++) {                   
  3002. X                GetTable(i,xcol,&x);
  3003. X                if( NaN(&y) ) {
  3004. X                    SetTable(i,result,infinity,FALSE);
  3005. X                    }
  3006. X                else {
  3007. X                    SetTable(i,result,(x/y),FALSE);
  3008. X                    }
  3009. X                } /*end for*/
  3010. X            }
  3011. X        }
  3012. X    else if( (strcmp(command.cmdWord[2],"#+")==0) || (strcmp(command.cmdWord[2],"#-")==0) ||
  3013. X                (strcmp(command.cmdWord[2],"#*")==0) || (strcmp(command.cmdWord[2],"#/")==0)  )  {                   
  3014. X        SToR( command.cmdWord[1], &x );
  3015. X        SToI( command.cmdWord[3], &ycol, TRUE );
  3016. X        if (strcmp(command.cmdWord[2],"#+")==0)  {                   
  3017. X            for (i=1; i<=rows; i++) {                   
  3018. X                GetTable(i,ycol,&y);
  3019. X                SetTable(i,result,(x+y),FALSE);
  3020. X                } /*end for*/
  3021. X            }
  3022. X        else if (strcmp(command.cmdWord[2],"#-")==0)  {                   
  3023. X            for (i=1; i<=rows; i++) {                   
  3024. X                GetTable(i,ycol,&y);
  3025. X                SetTable(i,result,(x-y),FALSE);
  3026. X                } /*end for*/
  3027. X            }
  3028. X        else if (strcmp(command.cmdWord[2],"#*")==0)  {                   
  3029. X            for (i=1; i<=rows; i++) {                   
  3030. X                GetTable(i,ycol,&y);
  3031. X                SetTable(i,result,(x*y),FALSE);
  3032. X                } /*end for*/
  3033. X            }
  3034. X        else if (strcmp(command.cmdWord[2],"#/")==0)  {                   
  3035. X            for (i=1; i<=rows; i++) {                   
  3036. X                GetTable(i,ycol,&y);
  3037. X                if( NaN(&y) ) {
  3038. X                    SetTable(i,result,infinity,FALSE);
  3039. X                    }
  3040. X                else {
  3041. X                    SetTable(i,result,(x/y),FALSE);
  3042. X                    }
  3043. X                } /*end for*/
  3044. X            }
  3045. X        }
  3046. X    else {                   
  3047. X                 ErrMsg(noSuchModifier);
  3048. X        }
  3049. X}
  3050. XColFunction()
  3051. X{
  3052. X    float x, y;
  3053. X    int xcol, ycol, i, rows;
  3054. X
  3055. X    SToI( command.cmdWord[2], &xcol );
  3056. X    SToI( command.cmdWord[3], &ycol );
  3057. X    rows=table.header.rows;
  3058. X    if (strcmp(command.cmdWord[1],"sin")==0) {
  3059. X        for (i=1; i<=rows; i++) {
  3060. X            GetTable( i, xcol, &x );
  3061. X            errno = 0;
  3062. X            x = (float) sin( (double)x );
  3063. X            ToNaN( &x );
  3064. X            SetTable( i, ycol, x, FALSE );
  3065. X            } /*end for*/
  3066. X        }
  3067. X    else if (strcmp(command.cmdWord[1],"cos")==0) {
  3068. X        for (i=1; i<=rows; i++) {
  3069. X            GetTable( i, xcol, &x );
  3070. X            errno = 0;
  3071. X            x = (float) cos( (double)x );
  3072. X            ToNaN( &x );
  3073. X            SetTable( i, ycol, x, FALSE );
  3074. X            } /*end for*/
  3075. X        }
  3076. X    else if (strcmp(command.cmdWord[1],"tan")==0) {
  3077. X        for (i=1; i<=rows; i++) {
  3078. X            GetTable( i, xcol, &x );
  3079. X            errno = 0;
  3080. X            x = (float) tan( (double)x );
  3081. X            ToNaN( &x );
  3082. X            SetTable( i, ycol, x, FALSE );
  3083. X            } /*end for*/
  3084. X        }
  3085. X    else if (strcmp(command.cmdWord[1],"asin")==0) {
  3086. X        for (i=1; i<=rows; i++) {
  3087. X            GetTable( i, xcol, &x );
  3088. X            errno = 0;
  3089. X            x = (float) asin( (double)x );
  3090. X            ToNaN( &x );
  3091. X            SetTable( i, ycol, x, FALSE );
  3092. X            } /*end for*/
  3093. X        }
  3094. X    else if (strcmp(command.cmdWord[1],"acos")==0) {
  3095. X        for (i=1; i<=rows; i++) {
  3096. X            GetTable( i, xcol, &x );
  3097. X            errno = 0;
  3098. X            x = (float) acos( (double)x );
  3099. X            ToNaN( &x );
  3100. X            SetTable( i, ycol, x, FALSE );
  3101. X            } /*end for*/
  3102. X        }
  3103. X    else if (strcmp(command.cmdWord[1],"atan")==0) {
  3104. X        for (i=1; i<=rows; i++) {
  3105. X            GetTable( i, xcol, &x );
  3106. X            errno = 0;
  3107. X            x = (float) atan( (double)x );
  3108. X            ToNaN( &x );
  3109. X            SetTable( i, ycol, x, FALSE );
  3110. X            } /*end for*/
  3111. X        }
  3112. X    else if (strcmp(command.cmdWord[1],"exp")==0) {
  3113. X        for (i=1; i<=rows; i++) {
  3114. X            GetTable( i, xcol, &x );
  3115. X            errno = 0;
  3116. X            x = (float) exp( (double)x );
  3117. X            ToNaN( &x );
  3118. X            SetTable( i, ycol, x, FALSE );
  3119. X            } /*end for*/
  3120. X        }
  3121. X    else if (strcmp(command.cmdWord[1],"erf")==0) {
  3122. X        for (i=1; i<=rows; i++) {
  3123. X            GetTable( i, xcol, &x );
  3124. X            errno = 0;
  3125. X            errfcn( x, &x,&y,&y,&y,&y );
  3126. X            ToNaN( &x );
  3127. X            SetTable( i, ycol, x, FALSE );
  3128. X            } /*end for*/
  3129. X        }
  3130. X    else if (strcmp(command.cmdWord[1],"erfc")==0) {
  3131. X        for (i=1; i<=rows; i++) {
  3132. X            GetTable( i, xcol, &x );
  3133. X            errno = 0;
  3134. X            errfcn( x, &y,&x,&y,&y,&y );
  3135. X            ToNaN( &x );
  3136. X            SetTable( i, ycol, x, FALSE );
  3137. X            } /*end for*/
  3138. X        }
  3139. X    else if (strcmp(command.cmdWord[1],"ln")==0) {
  3140. X        for (i=1; i<=rows; i++) {
  3141. X            GetTable( i, xcol, &x );
  3142. X            errno = 0;
  3143. X            x = (float) log( (double)x );
  3144. X            ToNaN( &x );
  3145. X            SetTable( i, ycol, x, FALSE );
  3146. X            } /*end for*/
  3147. X        }
  3148. X    else if (strcmp(command.cmdWord[1],"sqrt")==0) {
  3149. X        for (i=1; i<=rows; i++) {
  3150. X            GetTable( i, xcol, &x );
  3151. X            errno = 0;
  3152. X            x = (float) sqrt( (double)x );
  3153. X            ToNaN( &x );
  3154. X            SetTable( i, ycol, x, FALSE );
  3155. X            } /*end for*/
  3156. X        }
  3157. X    else if (strcmp(command.cmdWord[1],"row")==0) {
  3158. X        y = (float)table.header.rows;
  3159. X        for (i=1; i<=rows; i++) {
  3160. X            GetTable( i, xcol, &x );
  3161. X            x = 1.0 + ((x-table.header.start)/table.header.samp);
  3162. X            if( x<1.0 ) {
  3163. X                x=1.0;
  3164. X                }
  3165. X            else if( x>y ) {
  3166. X                x=y;
  3167. X                }
  3168. X            SetTable( i, ycol, x, FALSE );
  3169. X            } /*end for*/
  3170. X        }
  3171. X    else {
  3172. X                 ErrMsg(badModifier);
  3173. X        }
  3174. X}
  3175. XInsCommand()
  3176. X{
  3177. X    int i, j;
  3178. X    SToI( command.cmdWord[2], &i );
  3179. X    if( strlen(command.cmdWord[3])==0 ) {
  3180. X        strcpy( command.cmdWord[3],"1" );
  3181. X        }
  3182. X    SToI( command.cmdWord[3], &j );
  3183. X    
  3184. X    if( strcmp(command.cmdWord[1],"col")==0 ) {
  3185. X        InsertCol(i,j);
  3186. X        }
  3187. X    else if( strcmp(command.cmdWord[1],"row")==0 ) {
  3188. X        InsertRow(i,j);
  3189. X        }
  3190. X    else {
  3191. X        ErrMsg( badModifier );
  3192. X        }
  3193. X}    
  3194. X
  3195. XInsertRow( jRow, many )
  3196. Xint jRow, many;
  3197. X{
  3198. X    int nRow, nCol, mRow, mCol, iRow, iCol;
  3199. X    float x;
  3200. X    
  3201. X    nRow = table.header.rows;
  3202. X    nCol = table.header.cols;
  3203. X    mRow = table.header.maxRows;
  3204. X    mCol = table.header.maxCols;
  3205. X    
  3206. X    if( (nRow+many)>mRow ) {
  3207. X        ErrMsg("table would exceed allocated space");
  3208. X        }
  3209. X    else if (many<=0) {
  3210. X        ErrMsg("bad number of rows");
  3211. X        }
  3212. X    else if (table.header.interpolated) { 
  3213. X        ErrMsg("cant change row 1 of interpolated table");
  3214. X        }                   
  3215. X    else if( GoodRow(jRow)!=0 ) {
  3216. X        ErrMsg(noSuchRow);
  3217. X        }                   
  3218. X    else { 
  3219. X        nRow += many;
  3220. X        table.header.rows=nRow;
  3221. X        for (iRow=nRow;  iRow>=(jRow+many); iRow-- ) {
  3222. X        for (iCol=1; iCol<=nCol; iCol++) {
  3223. X            GetTable((iRow-many),iCol,&x);
  3224. X            SetTable(iRow,iCol,x,FALSE);
  3225. X            } /*end for iCol*/
  3226. X            } /*end for iRow*/
  3227. X        for (iRow=1; iRow<=many; iRow++) {
  3228. X        for (iCol=1;  iCol<=nCol; iCol++) {
  3229. X            SetTable( (jRow+iRow-1), iCol, infinity, FALSE );
  3230. X            } /*end for iCol*/
  3231. X            } /*end for iRow*/
  3232. X        Header2Vars();
  3233. X        } /*end if*/
  3234. X}
  3235. X
  3236. X
  3237. XInsertCol( jCol, many)
  3238. Xint jCol, many;
  3239. X{
  3240. X    int nRow, nCol, mRow, mCol, iRow, iCol;
  3241. X    float x;
  3242. X
  3243. X    nRow = table.header.rows;
  3244. X    nCol = table.header.cols;
  3245. X    mRow = table.header.maxRows;
  3246. X    mCol = table.header.maxCols;
  3247. X    
  3248. X    if( (nCol+many)>mCol ) {
  3249. X        ErrMsg("table would exceed allocated space");
  3250. X        }
  3251. X    else if (many<=0) {
  3252. X        ErrMsg("bad number of rows");
  3253. X        }
  3254. X    else if( table.header.interpolated && (jCol=1) ) {
  3255. X        ErrMsg("cant change row 1 of interpolated table");
  3256. X        }
  3257. X    else if( GoodCol(jCol)!=0 ) {
  3258. X        ErrMsg( noSuchColumn );
  3259. X        }
  3260. X    else {
  3261. X        nCol += many;
  3262. X        table.header.cols=nCol;
  3263. X        for (iCol=nCol; iCol>=(jCol+many); iCol--) {
  3264. X            strcpy(table.header.colName[iCol-1],table.header.colName[iCol-many-1]);
  3265. X            for (iRow=1; iRow<=nRow; iRow++) {    
  3266. X                GetTable(iRow,(iCol-many),&x);
  3267. X                SetTable(iRow,iCol,x,FALSE);
  3268. X                } /*end for iRow*/
  3269. X            } /*end for iCol*/
  3270. X        for (iCol=jCol; iCol<=(jCol+many-1); iCol++ ) {                   
  3271. X            strcpy(table.header.colName[iCol-1],"");
  3272. X            for (iRow=1; iRow<=nRow; iRow++) {                   
  3273. X                SetTable( iRow, iCol, infinity, FALSE );
  3274. X                } /*end for iRow*/
  3275. X            } /*end for iCol*/
  3276. X        Header2Vars();
  3277. X        } /*end if*/
  3278. X}
  3279. X
  3280. XDelCommand()
  3281. X{
  3282. X    int i, j;
  3283. X    SToI( command.cmdWord[2], &i );
  3284. X    if( strlen(command.cmdWord[3])==0 ) {
  3285. X        strcpy( command.cmdWord[3],"1" );
  3286. X        }
  3287. X    SToI( command.cmdWord[3], &j );
  3288. X    
  3289. X    if( strcmp(command.cmdWord[1],"col")==0 ) {
  3290. X        DeleteCol(i,j);
  3291. X        }
  3292. X    else if( strcmp(command.cmdWord[1],"row")==0 ) {
  3293. X        DeleteRow(i,j);
  3294. X        }
  3295. X    else {
  3296. X        ErrMsg( badModifier );
  3297. X        }
  3298. X}
  3299. X
  3300. XDeleteRow( jRow, many)
  3301. Xint jRow, many;
  3302. X{
  3303. X    int nRow, nCol, mRow, mCol, iRow, iCol;
  3304. X    float x;
  3305. X    nRow = table.header.rows;
  3306. X    nCol = table.header.cols;
  3307. X    mRow = table.header.maxRows;
  3308. X    mCol = table.header.maxCols;
  3309. X    
  3310. X    if (many<=0)  {
  3311. X        ErrMsg("bad number of rows");
  3312. X        }
  3313. X    else if( (nRow-jRow+1)<many ) {
  3314. X        ErrMsg("attempt to delete off bottom of table");
  3315. X        }
  3316. X    else if( (nRow-many)<1 ) {
  3317. X        ErrMsg("resulting table would have no rows");
  3318. X        }
  3319. X    else if (table.header.interpolated) {
  3320. X        ErrMsg("cant change row 1 of interpolated table");
  3321. X        }
  3322. X    else if( GoodRow(jRow)!=0 ) {
  3323. X        ErrMsg(noSuchRow);
  3324. X        }
  3325. X    else {
  3326. X        nRow -= many;
  3327. X        for (iRow=jRow; iRow<=nRow; iRow++) {                   
  3328. X        for (iCol=1; iCol<=nCol; iCol++) {
  3329. X            GetTable((iRow+many),iCol,&x);
  3330. X            SetTable(iRow,iCol, x,FALSE);
  3331. X            } /*end for iCol*/
  3332. X            } /*end for iRow*/
  3333. X        table.header.rows = nRow;
  3334. X        Header2Vars();
  3335. X        } /*end if*/
  3336. X}
  3337. X
  3338. XDeleteCol( jCol, many)
  3339. Xint jCol, many;
  3340. X{
  3341. X    int nRow, nCol, mRow, mCol, iRow, iCol;
  3342. X    float x;
  3343. X
  3344. X    nRow = table.header.rows;
  3345. X    nCol = table.header.cols;
  3346. X    mRow = table.header.maxRows;
  3347. X    mCol = table.header.maxCols;
  3348. X    
  3349. X    if (many<=0) {
  3350. X        ErrMsg("bad number of Cols");
  3351. X        }
  3352. X    else if( (nCol-many)<1 ) {
  3353. X        ErrMsg("resulting table would have no columns");
  3354. X        }
  3355. X    else if( (nCol-jCol+1)<many ) {
  3356. X        ErrMsg("attempt to delete of edge of table");
  3357. X        }
  3358. X    else if( table.header.interpolated && (jCol=1) ) {
  3359. X        ErrMsg("cant change row 1 of interpolated table");
  3360. X        }
  3361. X    else if( GoodCol(jCol)!=0 ) {
  3362. X        ErrMsg(noSuchColumn);
  3363. X        }
  3364. X    else {
  3365. X        nCol -= many;
  3366. X        for (iCol=jCol; iCol<= nCol; iCol++)  {
  3367. X            strcpy(table.header.colName[iCol-1],table.header.colName[iCol+many-1]);
  3368. X            for( iRow=1; iRow<=nRow; iRow++) {
  3369. X                GetTable(iRow,(iCol+many),&x);
  3370. X                SetTable(iRow,iCol,x,FALSE);
  3371. X                } /*end for iRow*/
  3372. X            } /*end for iCol*/
  3373. X        table.header.cols = nCol;
  3374. X        Header2Vars();
  3375. X        } /*end if*/
  3376. X}
  3377. X
  3378. XSwapCommand()
  3379. X{
  3380. X    int i, j;
  3381. X    SToI( command.cmdWord[2], &i );
  3382. X    SToI( command.cmdWord[3], &j );
  3383. X    if( strcmp(command.cmdWord[1],"col")==0 ) {
  3384. X        SwapCol(i,j);
  3385. X        }
  3386. X    else if( strcmp(command.cmdWord[1],"row")==0 ) {
  3387. X        SwapRow(i,j);
  3388. X        }
  3389. X    else {
  3390. X        ErrMsg( badModifier );
  3391. X        }
  3392. X}    
  3393. X
  3394. XSwapRow( i, j )
  3395. Xint i, j;
  3396. X{
  3397. X    float x, y;
  3398. X    int k;
  3399. X    
  3400. X    for( k=1; k<=table.header.cols; k++ ) {
  3401. X        GetTable(i,k,&x);
  3402. X        GetTable(j,k,&y);
  3403. X        SetTable(i,k,y,FALSE);
  3404. X        SetTable(j,k,x,FALSE);
  3405. X        }
  3406. X}
  3407. X
  3408. XSwapCol( i, j )
  3409. Xint i, j;
  3410. X{
  3411. X    float x, y;
  3412. X    int k;
  3413. X    char s[cmdWordLen];
  3414. X
  3415. X    for( k=1; k<=table.header.rows; k++) {
  3416. X        GetTable(k,i,&x);
  3417. X        GetTable(k,j,&y);
  3418. X        SetTable(k,i,y,FALSE);
  3419. X        SetTable(k,j,x,FALSE);
  3420. X        }
  3421. X    strcpy(s,table.header.colName[i-1]);
  3422. X    strcpy(table.header.colName[i-1],table.header.colName[j-1]);
  3423. X    strcpy(table.header.colName[j-1],s);
  3424. X}
  3425. X
  3426. XCopyCommand()
  3427. X{
  3428. X    int i, j;
  3429. X    
  3430. X    SToI( command.cmdWord[2], &i );
  3431. X    SToI( command.cmdWord[3], &j );
  3432. X    if( strcmp(command.cmdWord[1],"col")==0 ) {
  3433. X        CopyCol(i,j);
  3434. X        }
  3435. X    else if( strcmp(command.cmdWord[1],"row")==0 ) {
  3436. X        CopyRow(i,j);
  3437. X        }
  3438. X    else {
  3439. X        ErrMsg( badModifier );
  3440. X        }
  3441. X}
  3442. X
  3443. XCopyRow( fromRow, toRow)
  3444. Xint fromRow, toRow;
  3445. X{
  3446. X    int k;
  3447. X    float x;
  3448. X    
  3449. X    for( k=1; k<=table.header.cols; k++ ) {
  3450. X        GetTable(fromRow,k,&x);
  3451. X        SetTable(toRow,k,x,FALSE);
  3452. X        }
  3453. X}
  3454. X
  3455. XCopyCol( fromCol, toCol )
  3456. Xint fromCol, toCol;
  3457. X{
  3458. X    int k;
  3459. X    float x;
  3460. X
  3461. X    for( k=1; k<=table.header.rows; k++ ) {
  3462. X        GetTable(k,fromCol,&x);
  3463. X        SetTable(k,toCol,x,FALSE);
  3464. X        }
  3465. X    strcpy( table.header.colName[toCol-1],table.header.colName[fromCol-1]);
  3466. X}
  3467. XHeader2Vars() /*copy some header variables to macro sub variable table*/
  3468. X          /* also redo title of edit window */
  3469. X{
  3470. X    int status;
  3471. X    char str[120];
  3472. X    
  3473. X    strcpy( str, "Edit Window for " );
  3474. X    strcat( str, table.header.title );
  3475. X    if( strlen(str)>35 ) {
  3476. X        str[31]='.';
  3477. X        str[32]='.';
  3478. X        str[33]='.';
  3479. X        str[34]='\0';
  3480. X        }
  3481. X    SetWTitle( theWindow[edWindow], ctop(str) );
  3482. X         
  3483. X    status = TRUE;
  3484. X    if (table.header.interpolated) strcpy( str, "true"); else strcpy( str, "false");
  3485. X    status  = status && SetVar("interpolated",str);
  3486. X    
  3487. X    IToS( table.header.rows, str );
  3488. X    status  = status && SetVar("rows",str);
  3489. X    
  3490. X    IToS( table.header.cols, str );
  3491. X    status  = status && SetVar("cols",str);
  3492. X    
  3493. X    RToS( table.header.start, str );
  3494. X    status = status && SetVar("start",str);
  3495. X    
  3496. X    RToS( table.header.samp, str );
  3497. X    status = status && SetVar("samp",str);
  3498. X    
  3499. X    status = status && SetVar("title",table.header.title);
  3500. X    
  3501. X    if (!status) {
  3502. X        ErrMsg("no space to create header variables");
  3503. X        }
  3504. X}
  3505. X
  3506. XCreateCol1()  /*fills in column 1*/
  3507. X{
  3508. X    int row;
  3509. X    
  3510. X    if (table.header.interpolated) {
  3511. X        for (row=1; row<=table.header.rows; row++ ) { 
  3512. X            SetTable( row, 1, (table.header.start+table.header.samp*(row-1)), TRUE );
  3513. X            } /*end for*/
  3514. X        } /*end if*/
  3515. X}
  3516. X
  3517. XInitHeader() /*initializes some header variables*/
  3518. X{
  3519. X    int i;
  3520. X    char str[80];
  3521. X     
  3522. X    table.header.interpolated  = FALSE;
  3523. X    table.header.start = 0.0;
  3524. X    table.header.samp = 1.0;
  3525. X    strcpy( table.header.title, "");
  3526. X    for (i=0; i<table.header.cols; i++ ) {                   
  3527. X        IToS( i, str );
  3528. X        strcpy( table.header.colName[i], "Col " );
  3529. X        strcat( table.header.colName[i], str );
  3530. X        }
  3531. X    Header2Vars();
  3532. X}
  3533. X
  3534. XIToS( i, s ) /*integer to string conversion*/
  3535. Xint i;
  3536. Xchar s[];
  3537. X{
  3538. X    int j, k;
  3539. X    sprintf( s, "%-6d", i );
  3540. X    k = strlen( s );
  3541. X    for( j=0; j<k; j++ ) { /*clip trailing blanks*/
  3542. X        if( s[j]==' ' ) {
  3543. X            s[j]='\0';
  3544. X            break;
  3545. X            }
  3546. X        }
  3547. X}
  3548. X
  3549. XRToS( f, s ) /*float to string conversion*/
  3550. Xfloat f;
  3551. Xchar s[];
  3552. X{
  3553. X    int j, k;
  3554. X    if( (f>-10000.0) && (f<10000.0) ) {
  3555. X        ftoa( (double)f, s, 5, 2 );
  3556. X        }
  3557. X    else {
  3558. X        ftoa( (double)f, s, 4, 0 );
  3559. X        }
  3560. X    for( j=0; j<80; j++ ) { /*clip trailing blanks*/
  3561. X        if( s[j]=='\0' ) {
  3562. X            break;
  3563. X            }
  3564. X        else if( s[j]==' ' ) {
  3565. X            s[j]='\0';
  3566. X            break;
  3567. X            } /*end if*/
  3568. X        } /*end for*/
  3569. X    if( ((s[0]=='+') && (s[1]=='+')) || ((s[0]=='-') && (s[1]=='-')) ) {
  3570. X        strcpy( s, "NaN");
  3571. X        }
  3572. X}
  3573. X
  3574. XSToR( s, f, NaNsOK ) /*string to float conversion*/
  3575. Xchar s[];
  3576. Xfloat *f;
  3577. Xint NaNsOK;
  3578. X{
  3579. X    *f = infinity;
  3580. X    sscanf( s, "%e", f );
  3581. X    if( (!NaNsOK) && NaN(f) ) {
  3582. X        ErrMsg("string to real conversion error");
  3583. X        }
  3584. X}
  3585. X
  3586. XSToI( s, i ) /*string to integer conversion*/
  3587. Xchar s[];
  3588. Xint *i;
  3589. X{
  3590. X    int error;
  3591. X    float f;
  3592. X    
  3593. X    SToR( s, &f, TRUE );
  3594. X    if( (NaN(&f)) || (f<-32767.0) || (f>32767.0) ) {
  3595. X        ErrMsg("string to integer conversion error");
  3596. X        }
  3597. X    else {
  3598. X        if( f>0.0 ) {
  3599. X            *i = (int)(f+0.5);
  3600. X            }
  3601. X        else {
  3602. X            *i = (int)f;
  3603. X            }
  3604. X        }
  3605. X}
  3606. X
  3607. XNaN( f ) /*returns TRUE if f is a NaN or +/- Inf*/
  3608. Xfloat *f;
  3609. X{
  3610. X    unsigned long mask=017740000000;
  3611. X    int e;
  3612. X    union bb {
  3613. X        unsigned long i;
  3614. X        float y;
  3615. X        } b;
  3616. X        
  3617. X    b.y = (*f);
  3618. X    e = (int)((b.i&mask)>>23);
  3619. X
  3620. X    if( e==255 ) {
  3621. X        return(TRUE);
  3622. X        }
  3623. X    else {
  3624. X        return(FALSE);
  3625. X        }
  3626. X}
  3627. XVFunctionCommand()
  3628. X{
  3629. X    float x, y, z;
  3630. X    char vValue[cmdWordLen];
  3631. X    
  3632. X    SToR( command.cmdWord[2], &x, TRUE );
  3633. X    
  3634. X    errno = 0;
  3635. X    
  3636. X    if( strcmp(command.cmdWord[1],"sin")==0 ) {
  3637. X        z= sin(x);
  3638. X        }
  3639. X    else if( strcmp(command.cmdWord[1],"cos")==0 ) {
  3640. X        z= cos(x);
  3641. X        }
  3642. X    else if( strcmp(command.cmdWord[1],"tan")==0 ) {
  3643. X        z= tan(x);
  3644. X        }
  3645. X    else if( strcmp(command.cmdWord[1],"asin")==0 ) {
  3646. X        z= asin(x);
  3647. X        }
  3648. X    else if( strcmp(command.cmdWord[1],"acos")==0 ) {
  3649. X        z= acos(x);
  3650. X        }
  3651. X    else if( strcmp(command.cmdWord[1],"atan")==0 ) {
  3652. X        z= atan(x);
  3653. X        }
  3654. X    else if( strcmp(command.cmdWord[1],"sqrt")==0 ) {
  3655. X        z= sqrt(x);
  3656. X        }
  3657. X    else if( strcmp(command.cmdWord[1],"ln")==0 ) {
  3658. X        z= log(x);
  3659. X        }
  3660. X    else if( strcmp(command.cmdWord[1],"exp")==0 ) {
  3661. X        z= exp(x);
  3662. X        }
  3663. X    else if( strcmp(command.cmdWord[1],"erf")==0 ) {
  3664. X        errfcn( x, &z,&y,&y,&y,&y );
  3665. X        }
  3666. X    else if( strcmp(command.cmdWord[1],"erfc")==0 ) {
  3667. X        errfcn( x, &y,&z,&y,&y,&y );
  3668. X        }
  3669. X    else if( strcmp(command.cmdWord[1],"row")==0 ) {
  3670. X        z= ((x-table.header.start)/table.header.samp) + 1.0;
  3671. X        if( z<1.0 ) {
  3672. X            z=1.0;
  3673. X            }
  3674. X        else if (z>(float)table.header.rows) {
  3675. X            z = (float)table.header.rows;
  3676. X            }
  3677. X        }
  3678. X    else {
  3679. X        ErrMsg( noSuchModifier );
  3680. X        }
  3681. X    if( (errno==EDOM) || (errno==ERANGE) ) {
  3682. X        z = infinity;
  3683. X        errno=0;
  3684. X        }
  3685. X    RToS(z, vValue);
  3686. X    if( !SetVar(command.cmdWord[3],vValue) ){
  3687. X        ErrMsg("couldnt create variable");
  3688. X        }
  3689. X}
  3690. X
  3691. XIfCommand()
  3692. X{
  3693. X    int i, numLines, comparison;
  3694. X    float x, y;
  3695. X    comparison = FALSE;
  3696. X    
  3697. X    if( strlen(command.cmdWord[4])==0 ) {
  3698. X        strcpy(command.cmdWord[4],"1");
  3699. X        }
  3700. X    SToI( command.cmdWord[4], &numLines );
  3701. X    if( strcmp(command.cmdWord[2],"s=")==0 ) {
  3702. X        if( strcmp(command.cmdWord[1],command.cmdWord[3])==0 ) {
  3703. X            comparison=TRUE;
  3704. X            }
  3705. X        }
  3706. X    else if( strcmp(command.cmdWord[2],"s<>")==0 ) {
  3707. X        if( strcmp(command.cmdWord[1],command.cmdWord[3])!=0 ) {
  3708. X            comparison=TRUE;
  3709. X            }
  3710. X        }
  3711. X    else if( strcmp(command.cmdWord[2],"=")==0 ) {
  3712. X        SToR( command.cmdWord[1], &x, TRUE );
  3713. X        SToR( command.cmdWord[3], &y, TRUE );
  3714. X        if ( NaN(&x) ) x=infinity;
  3715. X        if ( NaN(&y) ) y=infinity;
  3716. X        if( x==y ) {
  3717. X            comparison=TRUE;
  3718. X            }
  3719. X        }
  3720. X    else if( strcmp(command.cmdWord[2],"<>")==0 ) {
  3721. X        SToR( command.cmdWord[1], &x, TRUE );
  3722. X        SToR( command.cmdWord[3], &y, TRUE );
  3723. X        if ( NaN(&x) ) x=infinity;
  3724. X        if ( NaN(&y) ) y=infinity;
  3725. X        if( x!=y ) {
  3726. X            comparison=TRUE;
  3727. X            }
  3728. X        }
  3729. X    else if( strcmp(command.cmdWord[2],"<")==0 ) {
  3730. X        if ( NaN(&x) ) x=infinity;
  3731. X        if ( NaN(&y) ) y=infinity;
  3732. X        SToR( command.cmdWord[1], &x, TRUE );
  3733. X        SToR( command.cmdWord[3], &y, TRUE);
  3734. X        if( x<y ) {
  3735. X            comparison=TRUE;
  3736. X            }
  3737. X        }
  3738. X    else if( strcmp(command.cmdWord[2],">")==0 ) {
  3739. X        if ( NaN(&x) ) x=infinity;
  3740. X        if ( NaN(&y) ) y=infinity;
  3741. X        SToR( command.cmdWord[1], &x, TRUE );
  3742. X        SToR( command.cmdWord[3], &y, TRUE );
  3743. X        if( x>y ) {
  3744. X            comparison=TRUE;
  3745. X            }
  3746. X        }
  3747. X    else if( strcmp(command.cmdWord[2],"<=")==0 ) {
  3748. X        if ( NaN(&x) ) x=infinity;
  3749. X        if ( NaN(&y) ) y=infinity;
  3750. X        SToR( command.cmdWord[1], &x, TRUE );
  3751. X        SToR( command.cmdWord[3], &y, TRUE );
  3752. X        if( x<=y ) {
  3753. X            comparison=TRUE;
  3754. X            }
  3755. X        }
  3756. X    else if( strcmp(command.cmdWord[2],">=")==0 ) {
  3757. X        if ( NaN(&x) ) x=infinity;
  3758. X        if ( NaN(&y) ) y=infinity;
  3759. X        SToR( command.cmdWord[1], &x, TRUE );
  3760. X        SToR( command.cmdWord[3], &y, TRUE );
  3761. X        if( x>=y ) {
  3762. X            comparison=TRUE;
  3763. X            }
  3764. X        }
  3765. X    if( !comparison ) {
  3766. X        i = mem.stack[ mem.stackPtr ] + numLines;
  3767. X        if( i>=(*prText)->nLines ) {
  3768. X            ErrMsg("attempt to jump off end of procedure memory");
  3769. X            }
  3770. X        mem.stack[mem.stackPtr] = i;
  3771. X        }
  3772. X}
  3773. ________This_Is_The_END________
  3774. if test `wc -l < regmanip.c` -ne 910; then
  3775.     echo 'shar: regmanip.c was damaged during transit'
  3776.   echo '      (should have been 910 bytes)'
  3777. fi
  3778. fi        ; : end of overwriting check
  3779. echo 'Extracting regmenu.c'
  3780. if test -f regmenu.c; then echo 'shar: will not overwrite regmenu.c'; else
  3781. sed 's/^X//' << '________This_Is_The_END________' > regmenu.c
  3782. X#include "all.h"
  3783. X#include "regtabext.h"
  3784. X
  3785. XDoCommand(mResult)
  3786. Xunsigned long mResult;
  3787. X{
  3788. X    int moveToScrap;
  3789. X    Handle TEScrH;
  3790. X    char name[30];
  3791. X    short theMenu, theItem;
  3792. X    Point p;
  3793. X    SFReply reply;
  3794. X    WindowPtr oldWindow;
  3795. X    GrafPtr    oldPort;
  3796. X
  3797. X    theMenu = mResult >> 16;
  3798. X    theItem = mResult;
  3799. X    
  3800. X    p.h = 100;
  3801. X    p.v = 100;
  3802. X    
  3803. X    moveToScrap = FALSE;
  3804. X
  3805. X    switch (theMenu) {
  3806. X    
  3807. X        case apMenuRes :
  3808. X            GetItem(myMenu[0],theItem,name);
  3809. X            OpenDeskAcc(name);
  3810. X            break;
  3811. X            
  3812. X        case fiMenuRes :
  3813. X            switch(theItem) {
  3814. X                case 1: /*read table*/
  3815. X                    strcpy(name,"RGTB");
  3816. X                    SFGetFile( pass(p), "\P ", 0L, 1, name, 0L, &reply );
  3817. X                    ReadTable(&reply);
  3818. X                    break;
  3819. X                case 2: /*write table*/
  3820. X                    SFPutFile( pass(p), "\PSave Table as . . .", "\PUntitled Table",
  3821. X                        0L, &reply );
  3822. X                    WriteTable(&reply);
  3823. X                    break;
  3824. X                case 4: /*read ascii table*/
  3825. X                    strcpy( name,  "TEXT" );
  3826. X                    SFGetFile( pass(p), "\P ", 0L, 1, name, 0L, &reply );
  3827. X                    ReadAsciiTable(&reply);
  3828. X                    break;
  3829. X                case 5: /*write ascii table table*/
  3830. X                    SFPutFile( pass(p), "\PSave Table as . . . ", "\PUntitled Ascii Table",
  3831. X                        NULL, &reply );
  3832. X                    WriteAsciiTable(&reply);
  3833. X                    break;
  3834. X                case 7: /*load procedure*/
  3835. X                    strcpy( name,  "TEXT" );
  3836. X                    SFGetFile( pass(p), "\P ", 0L, 1, name, 0L, &reply );
  3837. X                    ReadProcedure(&reply);
  3838. X                    break;
  3839. X                case 8: /*save procedure as*/
  3840. X                    SFPutFile( pass(p), "\PSave Procedure as . . . ", "\PUntitled Procedure",
  3841. X                        NULL, &reply );
  3842. X                    WriteProcedure(&reply);
  3843. X                    break;
  3844. X                case 10: /*MacWrite Graph*/
  3845. X                    SFPutFile( pass(p), "\PSave graph as . . . ", "\PUntitled Graph",
  3846. X                        NULL, &reply );
  3847. X                    WriteGraph(&reply);
  3848. X                    break;
  3849. X                case 12:  /* quit */
  3850. X                        doneFlag = TRUE;
  3851. X                    break;
  3852. X                } /*end switch theItem*/
  3853. X            break;
  3854. X            
  3855. X        case edMenuRes :
  3856. X            if( SystemEdit(theItem-1) ) break;
  3857. X            oldWindow = whichWindow;
  3858. X            whichWindow = FrontWindow();
  3859. X            GetPort( &oldPort );
  3860. X            GetWndNumber(whichWindow);
  3861. X            SetPort( whichWindow );
  3862. X            switch(theItem) {
  3863. X            
  3864. X                case 1: /*undo*/
  3865. X                    /*undo does nothing*/
  3866. X                    break;
  3867. X                    
  3868. X                case 3: /*cut*/
  3869. X                    if( whichWindow == theWindow[coWindow] ) {
  3870. X                        TECut( coText );
  3871. X                        moveToScrap=TRUE;
  3872. X                        }
  3873. X                    else if (whichWindow == theWindow[prWindow]) {
  3874. X                        TECut( prText );
  3875. X                        moveToScrap=TRUE;
  3876. X                        }
  3877. X                    else if (whichWindow == theWindow[edWindow]) {
  3878. X                        TECut( edText );
  3879. X                        moveToScrap=TRUE;
  3880. X                        }
  3881. X                    break;
  3882. X
  3883. X                case 4: /*copy*/
  3884. X                    if( whichWindow == theWindow[coWindow] ) {
  3885. X                        TECopy( coText );
  3886. X                        moveToScrap=TRUE;
  3887. X                        }
  3888. X                    else if ( whichWindow == theWindow[prWindow]) {
  3889. X                        TECopy( prText );
  3890. X                        moveToScrap=TRUE;
  3891. X                        }
  3892. X                    else if ( whichWindow == theWindow[edWindow]) {
  3893. X                        TECopy( edText );
  3894. X                        moveToScrap=TRUE;
  3895. X                        }
  3896. X                    break;
  3897. X                    
  3898. X                case 5: /*paste*/
  3899. X                    if( whichWindow == theWindow[coWindow] ) {
  3900. X                        TEPaste( coText );
  3901. X                        IfOutScroll(coText);
  3902. X                        }
  3903. X                    else if (whichWindow == theWindow[prWindow]) {
  3904. X                        TEPaste( prText );
  3905. X                        IfOutScroll(prText);
  3906. X                        }
  3907. X                    else if (whichWindow == theWindow[edWindow]) {
  3908. X                        TEPaste( edText );
  3909. X                        }
  3910. X                    break;
  3911. X                    
  3912. X                case 6: /*clear*/
  3913. X                    /*clear does nothing*/
  3914. X                    break;
  3915. X                    
  3916. X                } /*end switch theItem*/
  3917. X                
  3918. X            whichWindow = oldWindow;
  3919. X            SetPort( oldPort );
  3920. X            GetWndNumber(whichWindow);
  3921. X            break;
  3922. X            
  3923. X        case wiMenuRes :
  3924. X            switch(theItem) {
  3925. X                case 1:
  3926. X                    SelectWindow(theWindow[coWindow]);
  3927. X                    break;
  3928. X                case 2:
  3929. X                    SelectWindow(theWindow[grWindow]);
  3930. X                    break;
  3931. X                case 3:
  3932. X                    SelectWindow(theWindow[prWindow]);
  3933. X                    break;
  3934. X                case 4:
  3935. X                    SelectWindow(theWindow[edWindow]);
  3936. X                    break;
  3937. X                } /*end switch theItem*/
  3938. X            break;
  3939. X                
  3940. X        case abMenuRes :
  3941. X            switch(theItem) {
  3942. X                case 1:
  3943. X                    ErrMsg("Abort!");
  3944. X                    break;
  3945. X                } /*end switch theItem*/
  3946. X            break;
  3947. X    } /*end switch theMenu*/
  3948. X    
  3949. X    if (moveToScrap) {
  3950. X        TEScrH=TEScrapHndl();
  3951. X        HLock(TEScrH);
  3952. X        ZeroScrap();
  3953. X        PutScrap( TEGetScrpLen(), 'TEXT', *TEScrH );
  3954. X        HUnlock(TEScrH);
  3955. X        scrapIndex = (InfoScrap())->scrapCount;
  3956. X        }
  3957. X        
  3958. X    HiliteMenu(0);
  3959. X}
  3960. ________This_Is_The_END________
  3961. if test `wc -l < regmenu.c` -ne 178; then
  3962.     echo 'shar: regmenu.c was damaged during transit'
  3963.   echo '      (should have been 178 bytes)'
  3964. fi
  3965. fi        ; : end of overwriting check
  3966. echo 'Extracting regprim.c'
  3967. if test -f regprim.c; then echo 'shar: will not overwrite regprim.c'; else
  3968. sed 's/^X//' << '________This_Is_The_END________' > regprim.c
  3969. X#include "all.h"
  3970. X#include "regtabext.h"
  3971. X
  3972. Xerrfcn( x, erf,erfc,erfci,erfci2, deriv )
  3973. Xfloat x, *erf,*erfc,*erfci,*erfci2, *deriv;
  3974. X/* ERROR FUNCTION AND ASSOCIATED FUNCTIONS                */
  3975. X/*           X - ARGUMENT OF ERROR FUNCTION. POSITIVE OR NEGATIVE    */
  3976. X
  3977. X/*                             X                    */
  3978. X/*           ERF = 2/SQRT(PI) S  EXP( - T**2 ) DT            */
  3979. X/*                             0                    */
  3980. X
  3981. X/*           ERFC = 1.0 - ERF                        */
  3982. X/*           ERFCI IS  IERFC(X)                        */
  3983. X/*           ERFCI =  (1.0/SQRT(PI))*EXP(-X**2)-X(ERFC(X))        */
  3984. X
  3985. X/*           ERFCI2 IS I**2ERFC(X)                    */
  3986. X/*                 ERFCI2 =  1/4 ((1+2*X**2)ERFC(X)- 2/SQRT(PI)*X*EXP(-X**2))    */
  3987. X/*                 OR  ALTERNATIVELY                        */
  3988. X/*                 ERFCI2 = 1/4 (ERCF(X)-2*X*ERFCI(X))                */
  3989. X
  3990. X/*           DERIV - D/DX OF ERF(X)                        */
  3991. X
  3992. X/* METHOD:      RATIONAL APPROXIMATION                        */
  3993. X
  3994. X/* SOURCE:   ABRAMOWITZ AND STEGUN, P.299, HANDBOOK OF                */
  3995. X/*           MATHEMATICAL FUNCTIONS AND CARSLAW AND JAEGER            */
  3996. X/*           CONDUCTION OF HEAT IN SOLIDS  P. 482                */
  3997. X{
  3998. X    double t, xx, rat, dexpxx;
  3999. X    double derf, dderiv, derfc, derfci, derfci2;
  4000. X    double t2,t3,t4;
  4001. X      
  4002. X    double p=0.3275911, a1=0.254829592, a2=-0.284496736;
  4003. X    double a3=1.421413741, a4=-1.453152027, a5=1.061405429;
  4004. X    double sqrtpi=1.772453851, pi=3.141592654;
  4005. X
  4006. X    xx = fabs( (double) x);
  4007. X    dexpxx = exp( -(xx*xx) );
  4008. X    if( xx<1.0e-7 ) { /*use first two terms of taylor series expansion*/
  4009. X        derf = (2.0 / sqrtpi) * xx * (1.0 - (xx*xx/3.0) );
  4010. X        if( x<0.0 ) derf=(-derf);
  4011. X        derfc = 1.0 - derf;
  4012. X        }
  4013. X    else { /*use rational approximation*/
  4014. X        t = 1.0 / ( 1.0 + p*xx );
  4015. X        t2 = t*t;
  4016. X        t3 = t2*t;
  4017. X        t4 = t2*t2;
  4018. X        rat = (a5*t4 + a4*t3 + a3*t2 + a2*t + a1);
  4019. X        derf = 1.0 - t*rat*dexpxx;
  4020. X        if (x<0.0) {
  4021. X            derf = (-derf);
  4022. X            derfc =  2.0 - t*rat*dexpxx;
  4023. X            }
  4024. X        else {
  4025. X            derfc =  t*rat*dexpxx;
  4026. X            } /*end if*/
  4027. X        } /*end if*/
  4028. X    xx = (double) x;
  4029. X    derfci = (1.0/sqrtpi)*dexpxx-xx*derfc;
  4030. X    derfci2 = 0.25 * (derfc-2.0*xx*derfci);
  4031. X    dderiv =  (2.0*dexpxx)/sqrtpi;
  4032. X
  4033. X    *erf = (float) ( derf );
  4034. X    *erfc = (float) ( derfc );
  4035. X    *erfci = (float)  (derfci);
  4036. X    *erfci2 =  (float)  (derfci2);
  4037. X    *deriv = (float) ( dderiv );
  4038. X} 
  4039. X
  4040. XToNaN(f)
  4041. Xfloat *f;
  4042. X{
  4043. X    if( (errno==EDOM) || (errno==ERANGE) ) {
  4044. X        *f=infinity;
  4045. X        }
  4046. X}
  4047. XSetVar( vName, vValue )
  4048. Xchar vName[], vValue[];
  4049. X/*create entry in macro substitution table and set value*/
  4050. X/*if variable previously exists, it is overwritten */
  4051. X/* returns false if the list is full or if not a valid variable name */
  4052. X/* valid variable names must not contain spaces */
  4053. X
  4054. X{
  4055. X    int i, inList;
  4056. X    char *index();
  4057. X                
  4058. X    if (  (strlen(vName)==0) || ((long)index(vName, ' ')!=0L) ) { 
  4059. X        return(FALSE);
  4060. X        }
  4061. X    else {
  4062. X        inList = FALSE;
  4063. X        i = 0;
  4064. X        while (  (!inList) && (i<macVars.numVars) )  {                   
  4065. X            if ( strcmp(vName,macVars.inStr[i]) == 0 ) {
  4066. X                inList = TRUE;
  4067. X                } /*end if inList*/
  4068. X            i++;
  4069. X            } /*end while*/
  4070. X        if (inList) { 
  4071. X            strcpy( macVars.outStr[i-1], vValue );
  4072. X            return( TRUE );
  4073. X            }      
  4074. X        else {
  4075. X            if ( (macVars.numVars+1) >= maxVars ) {
  4076. X                return( FALSE );
  4077. X                }
  4078. X            else {                   
  4079. X                strcpy( macVars.inStr[macVars.numVars], vName );
  4080. X                strcpy( macVars.outStr[macVars.numVars], vValue );
  4081. X                macVars.numVars++;
  4082. X                return( TRUE );
  4083. X                } /*end if enough space*/
  4084. X            } /*end if not inList*/
  4085. X        } /*end if valid name*/
  4086. X    }
  4087. X            
  4088. XDelVar( vName )
  4089. Xchar vName[];
  4090. X/* deletes macro substitution variable from table*/
  4091. X{
  4092. X
  4093. X    int i, j, inList; 
  4094. X    
  4095. X    if (macVars.numVars==0) {
  4096. X        return( FALSE );
  4097. X        }
  4098. X    else {                   
  4099. X        inList  = FALSE;
  4100. X        i  = 0;
  4101. X        while ( (!inList) && (i<macVars.numVars)  ) {                   
  4102. X            if ( strcmp(vName,macVars.inStr[i])==0 ) {
  4103. X                inList = TRUE;
  4104. X                } /*end if match*/
  4105. X            i++;
  4106. X            }
  4107. X        i--; /*i now points to selected variable*/
  4108. X        if (inList) { 
  4109. X            if (i != (macVars.numVars-1) ) { /*if not last in list, move others*/             
  4110. X                for ( j=(i+1); j<macVars.numVars; j++ ) {
  4111. X                    strcpy( macVars.inStr[j-1],   macVars.inStr[j]   );
  4112. X                    strcpy( macVars.outStr[j-1], macVars.outStr[j] );
  4113. X                    }
  4114. X                } /*end if*/
  4115. X            macVars.numVars--;
  4116. X            return( TRUE );
  4117. X            } /*end if inList*/                 
  4118. X        else {
  4119. X            return( FALSE );
  4120. X            } /*end if not inList */
  4121. X        } /*end if list not empty*/
  4122. X}
  4123. X
  4124. XListVars()
  4125. X/* list macro substitution table */
  4126. X{
  4127. X    int i;
  4128. X    
  4129. X    for( i=0; i<macVars.numVars; i++ ) {                   
  4130. X        CheckAbortMenu();
  4131. X        WritePhrase( "\'" );
  4132. X        WritePhrase( macVars.inStr[i] );
  4133. X        WritePhrase( "\' \'" );
  4134. X        WritePhrase( macVars.outStr[i] );
  4135. X        WriteLine( "\'" );
  4136. X        } /* end for */
  4137. X}
  4138. X
  4139. XSBreak( command, macrosOn )
  4140. XcommandRec *command;
  4141. Xint macrosOn;
  4142. X/* breaks command string into command words that are separated by blanks */
  4143. X/* quoted blanks not broken */
  4144. X/* macro substitutions performed on all command words if macrosOn true */
  4145. X{
  4146. X    int i, j, ibuf, len;
  4147. X    char c[2];
  4148. X    int quote, word, error, status;
  4149. X
  4150. X       for(  i=0;  i<numCmdWds;  i++ ) {                   
  4151. X        strcpy( command->cmdWord[i], "" );  /*set command words to null*/
  4152. X        }
  4153. X
  4154. X    i  = 0;
  4155. X    j  = 0;
  4156. X    quote = FALSE;
  4157. X    word  = FALSE;
  4158. X    error  = FALSE;
  4159. X    ibuf  =  0;
  4160. X    if( (len=strlen(command->cmdStr))==0) {
  4161. X        return(TRUE);
  4162. X        }
  4163. X
  4164. X    c[1] = '\0';
  4165. X    while ( (ibuf<len) && (!error) ) {                   
  4166. X        if ( i >= cmdWordLen ) {
  4167. X            error  = TRUE;
  4168. X            }                   
  4169. X        else {  
  4170. X                     c[0] = command->cmdStr[ibuf];
  4171. X            if( j >= numCmdWds ) {
  4172. X                error = TRUE;
  4173. X                }
  4174. X                    else if ( ((c[0]==' ')||(c[0]=='\t')) && (!quote) ) {                   
  4175. X                if (word)  {                   
  4176. X                    word  = FALSE;
  4177. X                    i  =  0;
  4178. X                    j++;
  4179. X                    }
  4180. X                }
  4181. X                    else if ( (c[0]==' ')||(c[0]=='\t') && quote ) {                   
  4182. X                word  = TRUE;
  4183. X                strcat( command->cmdWord[j], c );
  4184. X                i++;
  4185. X                }
  4186. X                     else if ( (c[0]=='\'') && (!quote) ) {                   
  4187. X                word  = TRUE;
  4188. X                quote  = TRUE;
  4189. X                }
  4190. X                     else if ( (c[0]=='\'') && quote )  {                   
  4191. X                word = FALSE;
  4192. X                quote = FALSE;
  4193. X                i = 0;
  4194. X                j++;
  4195. X                }
  4196. X                     else {                   
  4197. X                word  = TRUE;
  4198. X                strcat( command->cmdWord[j], c ); 
  4199. X                i++;
  4200. X                } /*end if on characters*/;
  4201. X                     }  /*end if cmdWordLen*/
  4202. X            ibuf++;
  4203. X        } /*end while*/;
  4204. X    
  4205. X    status = FALSE;
  4206. X    if ( !error ) {
  4207. X        i = 0;
  4208. X        status = TRUE;
  4209. X        while ( (i<numCmdWds) && status && macrosOn )  {                   
  4210. X            status  = GetVar( command->cmdWord[i], command->cmdWord[i] );
  4211. X            i++;
  4212. X            } /*while numCmdWds*/;
  4213. X        } /*if not error*/
  4214. X        
  4215. X    return(  (!error) && status );
  4216. X}
  4217. X
  4218. XGetVar( vName,  vValue)
  4219. Xchar vName[], vValue[];
  4220. X/* does macro-substitution on a variable reference*/
  4221. X/* does not change the value of VValue on no-match*/
  4222. X/* returns false only if no match occurs on a valid variable name*/
  4223. X/* where a valid variable reference*/
  4224. X/* a) starts with a @ */
  4225. X/* b) contains no spaces */
  4226. X
  4227. X{
  4228. X    int i, len;
  4229. X    int inList;
  4230. X    char *index();
  4231. X    
  4232. X    if( ((long)index(vName,' ')!=0L) || ((long)index(vName,'@')!=(long)vName) ) { 
  4233. X        /*not a variable reference*/
  4234. X        return(TRUE);
  4235. X        }
  4236. X    else if ( (len=strlen(vName)) < 2 ) { /*string consisting only of @ is invalid*/
  4237. X        return(FALSE);
  4238. X        }
  4239. X    else if (macVars.numVars==0) {  /*is valid reference but no variables defined*/
  4240. X        return(FALSE);
  4241. X        }                   
  4242. X    else {  /* is a valid variable reference */
  4243. X        inList  = FALSE;
  4244. X        i  = 0;
  4245. X        while ( (!inList) && (i<macVars.numVars) ) {                   
  4246. X            if (strcmp( &(vName[1]) , macVars.inStr[i] ) == 0) {
  4247. X                inList = TRUE;
  4248. X                } /*end if*/
  4249. X                     i++; 
  4250. X                     }  /*end while*/
  4251. X        if (inList)  {
  4252. X                     strcpy( vValue, macVars.outStr[i-1] );
  4253. X             return(TRUE);
  4254. X                     } /*end if inList*/                 
  4255. X        else {                   
  4256. X            return(FALSE);
  4257. X            } /*end if not inList*/
  4258. X        } /* end if valid reference*/
  4259. X} 
  4260. X
  4261. Xdone()
  4262. X{
  4263. X    if( doneFlag ) {
  4264. X        if( CautionAlert(quitAlertRes, NULL)==1 ) {
  4265. X            return(TRUE);
  4266. X            }
  4267. X        else {
  4268. X            return(FALSE);
  4269. X            }
  4270. X    }
  4271. X    else {
  4272. X        return(FALSE);
  4273. X        }
  4274. X}
  4275. X
  4276. XGoodRow( row ) /* returns 0 if 1<=row<=rows,  1 if rows<row<=maxrows, 2 otherwise */
  4277. Xint row;
  4278. X{
  4279. X    if( (row>=1) && (row<=table.header.rows) ) {
  4280. X        return(0);
  4281. X        }
  4282. X    else if( (row>table.header.rows) && (row<=table.header.maxRows) ) {
  4283. X        return(1);
  4284. X        }
  4285. X    else {
  4286. X        return(2);
  4287. X        }
  4288. X}
  4289. X
  4290. XGoodCol( col ) /* returns 0 if 1<=col<=cols,  1 if cols<col<=maxcols, 2 otherwise */
  4291. Xint col;
  4292. X{
  4293. X    if( (col>=1) && (col<=table.header.cols) ) {
  4294. X        return(0);
  4295. X        }
  4296. X    else if( (col>table.header.cols) && (col<=table.header.maxCols) ) {
  4297. X        return(1);
  4298. X        }
  4299. X    else {
  4300. X        return(2);
  4301. X        }
  4302. X}
  4303. X
  4304. XErrMsg( message )
  4305. Xchar message[];
  4306. X{
  4307. X    int i;
  4308. X    char s[80];
  4309. X    
  4310. X    HiliteMenu(0);
  4311. X    RedoEditWindow();
  4312. X    if( currentWindow!=coWindow ) {
  4313. X        SetPort(theWindow[coWindow]);
  4314. X        SelectWindow( theWindow[coWindow] );
  4315. X        currentWindow = coWindow;
  4316. X        whichWindow = theWindow[coWindow];
  4317. X        }
  4318. X    (*coText)->selStart = (*coText)->teLength;
  4319. X    (*coText)->selEnd = (*coText)->teLength;
  4320. X    TEInsert( "Error: ", 7L, coText );
  4321. X    TEInsert( message, (long)strlen(message), coText );
  4322. X    TEInsert( "\r", 1L, coText );
  4323. X    if( mem.active ) { /*turn off procedure*/
  4324. X        TESetSelect( (long)((*prText)->lineStarts[mem.stack[mem.stackPtr]]),
  4325. X                 (long)((*prText)->lineStarts[mem.stack[mem.stackPtr]+1]),
  4326. X                 prText );
  4327. X        pendingFlag=FALSE;
  4328. X        NoPendingInput();
  4329. X        for (i=mem.stackPtr; i>=0; i-- ) {
  4330. X            IToS( mem.stack[i]+1, s );
  4331. X            TEInsert("called from line ",17L,coText);
  4332. X            TEInsert(s, (long)strlen(s), coText );
  4333. X            TEInsert("\r", 1L, coText);
  4334. X            }
  4335. X        mem.active=FALSE;
  4336. X        mem.stackPtr=-1;
  4337. X        loops.numLoops=0;
  4338. X        }
  4339. X    TEInsert( "> ", 2L, coText );
  4340. X    IfOutScroll( coText );
  4341. X    SysBeep(5);
  4342. X    longjmp(envbuf,-1);
  4343. X}
  4344. X
  4345. XWriteLine( message )
  4346. Xchar message[];
  4347. X{
  4348. X    if( currentWindow!=coWindow ) {
  4349. X        SetPort(theWindow[coWindow]);
  4350. X        SelectWindow( theWindow[coWindow] );
  4351. X        currentWindow = coWindow;
  4352. X        whichWindow = theWindow[coWindow];
  4353. X        }
  4354. X    (*coText)->selStart = (*coText)->teLength;
  4355. X    (*coText)->selEnd = (*coText)->teLength;
  4356. X    TEInsert( &message[0], (long)strlen(message), coText );
  4357. X    TEInsert( "\r", 1L, coText );
  4358. X    IfOutScroll( coText );
  4359. X}
  4360. X
  4361. XWritePhrase( message )
  4362. Xchar message[];
  4363. X{
  4364. X    if( currentWindow!=coWindow ) {
  4365. X        SetPort(theWindow[coWindow]);
  4366. X        SelectWindow( theWindow[coWindow] );
  4367. X        currentWindow = coWindow;
  4368. X        whichWindow = theWindow[coWindow];
  4369. X        }
  4370. X    (*coText)->selStart = (*coText)->teLength;
  4371. X    (*coText)->selEnd = (*coText)->teLength;
  4372. X    TEInsert( &message[0], (long)strlen(message), coText );
  4373. X    IfOutScroll( coText );
  4374. X}
  4375. X
  4376. X
  4377. XCheckAbortMenu()
  4378. X{
  4379. X    Point mPoint;
  4380. X    if (Button() != 0) {
  4381. X        GetMouse( &mPoint );
  4382. X        LocalToGlobal( &mPoint );
  4383. X            if( PtInRect( pass(mPoint), &abortRect ) != 0 ) {
  4384. X                SysBeep(20);
  4385. X                SetPort(theWindow[coWindow]);
  4386. X                SelectWindow( theWindow[coWindow] );
  4387. X                currentWindow = coWindow;
  4388. X                whichWindow = theWindow[coWindow];
  4389. X                if( mem.active ) { /*turn off procedure*/
  4390. X                    mem.active=FALSE;
  4391. X                    mem.stackPtr=-1;
  4392. X                    loops.numLoops=0;
  4393. X                    pendingFlag=FALSE;
  4394. X                    NoPendingInput();
  4395. X                    }
  4396. X                TEInsert( "Abort!\r",7L,coText);
  4397. X                TEInsert( "> ", 2L, coText );
  4398. X                IfOutScroll( coText );
  4399. X                RedoEditWindow();
  4400. X                HiliteMenu(0);
  4401. X                longjmp(envbuf,-1);
  4402. X                } /*end if abort menu and item*/
  4403. X        } /*end if mouse is down*/
  4404. X    HiliteMenu(0);
  4405. X}
  4406. XPendingInput()
  4407. X{
  4408. X    DisableItem( myMenu[apMenu], 0 );
  4409. X    DisableItem( myMenu[fiMenu], 1 );
  4410. X    DisableItem( myMenu[fiMenu], 4 );
  4411. X    DisableItem( myMenu[fiMenu], 7 );
  4412. X    DisableItem( myMenu[edMenu], 0 );
  4413. X    DisableItem( myMenu[wiMenu], 3 );
  4414. X    DisableItem( myMenu[wiMenu], 4 );
  4415. X}
  4416. X
  4417. XNoPendingInput()
  4418. X{
  4419. X    EnableItem( myMenu[apMenu], 0 );
  4420. X    EnableItem( myMenu[fiMenu], 1 );
  4421. X    EnableItem( myMenu[fiMenu], 4 );
  4422. X    EnableItem( myMenu[fiMenu], 7 );
  4423. X    EnableItem( myMenu[edMenu], 0 );
  4424. X    EnableItem( myMenu[wiMenu], 3 );
  4425. X    EnableItem( myMenu[wiMenu], 4 );
  4426. X}
  4427. X
  4428. XGraph2Vars()
  4429. X{
  4430. X    int status;
  4431. X    char s[cmdWordLen];
  4432. X    
  4433. X    RToS( graph.xMin, s );
  4434. X    status = SetVar( "xmin", s );
  4435. X    
  4436. X    RToS( graph.xMax, s );
  4437. X    status = status && SetVar( "xmax", s );
  4438. X    
  4439. X    RToS( graph.yMin, s );
  4440. X    status = status && SetVar( "ymin", s );
  4441. X    
  4442. X    RToS( graph.yMax, s );
  4443. X    status = status && SetVar( "ymax", s );
  4444. X    
  4445. X    if( !status ) {
  4446. X        ErrMsg("couldnt create graphics variables");
  4447. X        }
  4448. X}
  4449. X
  4450. XFindLabel( s, line) /*search for particular label and return its line number*/
  4451. Xchar s[];
  4452. Xint *line;
  4453. X{
  4454. X    commandRec tCommand;
  4455. X    int i, j, k, match;
  4456. X    
  4457. X    match = FALSE;
  4458. X    *line = 0;
  4459. X    for( i=0; (i<mem.numLabels && (!match)); i++) { /*search label list*/
  4460. X        j=(*prText)->lineStarts[mem.labels[i]];
  4461. X        k=((*prText)->teLength)-1;
  4462. X        HLock((*prText)->hText);
  4463. X        ExtractLine( *((*prText)->hText), j, k, tCommand.cmdStr );
  4464. X        HUnlock((*prText)->hText);
  4465. X        if( !SBreak( &tCommand, FALSE ) ) {
  4466. X            WriteLine("(find) bad line in procedure:");
  4467. X            /*ErrMsg(tCommand.cmdStr);*/
  4468. X            }
  4469. X        if (strcmp(tCommand.cmdWord[1],s)==0) {
  4470. X            match = TRUE;
  4471. X            *line  = mem.labels[i];
  4472. X            }
  4473. X        } /*end for*/
  4474. X    return( match );
  4475. X}
  4476. X
  4477. XListLabels() /*constructs label list from current contents of procedure memory*/
  4478. X{
  4479. X    commandRec tCommand;
  4480. X    int i, j, k, badLine;
  4481. X    
  4482. X    mem.numLabels = 0;
  4483. X    badLine=FALSE;
  4484. X    for( i=0; i<(*prText)->nLines; i++) {/*scan memory sequentially*/
  4485. X        j=(*prText)->lineStarts[i];
  4486. X        k=((*prText)->teLength)-1;
  4487. X        HLock((*prText)->hText);
  4488. X        ExtractLine( *((*prText)->hText), j, k, tCommand.cmdStr );
  4489. X        HUnlock((*prText)->hText);
  4490. X        if( !SBreak( &tCommand, FALSE ) ) {
  4491. X            TESetSelect( (long)((*prText)->lineStarts[i]), (long)((*prText)->lineStarts[i+1]),
  4492. X                 prText );
  4493. X            WriteLine("bad line in procedure:");
  4494. X            WriteLine(tCommand.cmdStr);
  4495. X            badLine=TRUE;
  4496. X            }
  4497. X        if( strcmp(tCommand.cmdWord[0],"label")==0 ) {
  4498. X            mem.labels[mem.numLabels] = i;
  4499. X            mem.numLabels++;
  4500. X            }
  4501. X        } /*end for*/
  4502. X    if( badLine ) {
  4503. X        ErrMsg("procedure aborted");
  4504. X        }
  4505. X}
  4506. X
  4507. XExtractLine(c, start, end, cc)
  4508. Xchar c[];
  4509. Xint start, end;
  4510. Xchar cc[];
  4511. X{
  4512. X    int i;
  4513. X    for( i=0; ( (i<(end-start+1)) && (i<(cmdWordLen-1)) ); i++ ) {
  4514. X        cc[i] = c[i+start];
  4515. X        if (cc[i]=='\r') {
  4516. X            cc[i] = '\0';
  4517. X            break;
  4518. X            }
  4519. X        }
  4520. X    cc[i] = '\0';
  4521. X}
  4522. X
  4523. XRedoEditWindow()
  4524. X{
  4525. X    GrafPtr oldPort;
  4526. X    int oldWindow;
  4527. X    
  4528. X    GetPort( &oldPort );
  4529. X    oldWindow=currentWindow;
  4530. X    
  4531. X    SetPort( theWindow[edWindow] );
  4532. X    InvalRect( &(theWindow[edWindow]->portRect) );
  4533. X    tabEd.activeName=FALSE;
  4534. X    tabEd.activeEntry=FALSE;
  4535. X    
  4536. X    SetPort( oldPort );
  4537. X    currentWindow=oldWindow;
  4538. X    whichWindow=theWindow[currentWindow];
  4539. X}
  4540. X
  4541. X
  4542. X
  4543. X
  4544. X
  4545. ________This_Is_The_END________
  4546. if test `wc -l < regprim.c` -ne 577; then
  4547.     echo 'shar: regprim.c was damaged during transit'
  4548.   echo '      (should have been 577 bytes)'
  4549. fi
  4550. fi        ; : end of overwriting check
  4551. echo 'Extracting regtab.m'
  4552. if test -f regtab.m; then echo 'shar: will not overwrite regtab.m'; else
  4553. sed 's/^X//' << '________This_Is_The_END________' > regtab.m
  4554. Xln regmain.o regcmdloop.o regproc.o regmenu.o regtable.o lib/sacroot.o -lm -lc \
  4555. X+O regmanip.o regprim.o -lm -lc \
  4556. X+O reggauss.o regspline.o -lm -lc \
  4557. X+O regwnd.o regio.o reggraph.o regseries.o -lm -lc -o regtab.code
  4558. Xrgen regtab.r
  4559. Xsetbundle
  4560. X    
  4561. X        
  4562. ________This_Is_The_END________
  4563. if test `wc -l < regtab.m` -ne 8; then
  4564.     echo 'shar: regtab.m was damaged during transit'
  4565.   echo '      (should have been 8 bytes)'
  4566. fi
  4567. fi        ; : end of overwriting check
  4568. exit 0
  4569.