home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Harvest C 1.3 / Source Code / CErrorLog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-20  |  9.9 KB  |  377 lines  |  [TEXT/KAHL]

  1. /*
  2.     Harvest C
  3.     Copyright 1992 Eric W. Sink.  All rights reserved.
  4.     
  5.     This file is part of Harvest C.
  6.     
  7.     Harvest C is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU Generic Public License as published by
  9.     the Free Software Foundation; either version 2, or (at your option)
  10.     any later version.
  11.     
  12.     Harvest C is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.     
  17.     You should have received a copy of the GNU General Public License
  18.     along with Harvest C; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.     
  21.     Harvest C is not in any way a product of the Free Software Foundation.
  22.     Harvest C is not GNU software.
  23.     Harvest C is not public domain.
  24.  
  25.     This file may have other copyrights which are applicable as well.
  26.  
  27. */
  28.  
  29. /******************************************************************************
  30.  CErrorLog.c
  31.  
  32.         
  33.     SUPERCLASS = CDLOGDirector
  34.     
  35.     Copyright © 1991 Symantec Corporation. All rights reserved.
  36.     
  37.  
  38.  ******************************************************************************/
  39.  
  40. #include "CErrorLog.h"
  41. #include "CStringTable.h"
  42. #include "CStringArray.h"
  43. #include "CScrollPane.h"
  44. #include "CDialogText.h"
  45. #include "CDialog.h"
  46. #include "CPaneBorder.h"
  47. #include "CApplication.h"
  48. #include "CDecorator.h"
  49. #include "CHarvestApp.h"
  50. #include "CHarvestDoc.h"
  51. #include "CDataFile.h"
  52. #include "CSourceFile.h"
  53. #include "Commands.h"
  54. #include "HarvestCommands.h"
  55. #include "AppleEvents.h"
  56. #include "Aliases.h"
  57. #include "stdarg.h"
  58.  
  59. #define    kDemoDlgID            1030
  60. #define openFileTCLID        5000
  61.  
  62. enum        /* window item numbers    */
  63. {
  64.     kListScrollPaneItem = 1,
  65.     kEditItem
  66. };
  67.  
  68. extern CHarvestApp    *gApplication;
  69. extern CHarvestDoc    *gProject;
  70. extern tSystem gSystem;
  71. extern CSourceFile *gCurSourceFile;
  72. extern CErrorLog *gErrs;
  73. extern    CDecorator    *gDecorator;    /* Window dressing object    */
  74.  
  75. extern Boolean FindAProcess(OSType signature,ProcessSerialNumber *process,
  76.                         ProcessInfoRec *InfoRec,
  77.                         FSSpecPtr aFSSpecPtr);
  78. char *GetPathName(char *s,char *name,short vRefNum,long dirID);
  79.  
  80. /******************************************************************************
  81.  IErrorLog
  82. ******************************************************************************/
  83.  
  84. #define maxStringLen 255
  85.  
  86. void CErrorLog::IErrorLog( void)
  87. {
  88.     CScrollPane    *scrollPane;
  89.     CPaneBorder *listBorder;
  90.     Rect    margin;
  91.     Cell    aCell;
  92.     
  93.     ErrorCount = 0;
  94.  
  95.     if (gProject) {
  96.         CDLOGDirector::IDLOGDirector( kDemoDlgID, gProject);
  97.     }
  98.     else {
  99.         CDLOGDirector::IDLOGDirector( kDemoDlgID, gApplication);
  100.     }
  101.     
  102.     itsEditItem = (CDialogText*) itsWindow->FindViewByID( kEditItem);
  103.     itsEditItem->SetFontNumber(geneva);
  104.     
  105.     scrollPane = (CScrollPane*) itsWindow->FindViewByID( kListScrollPaneItem);
  106.     
  107.     if (scrollPane)
  108.     {                
  109.         itsStringTable = new( CStringTable);
  110.         itsStringTable->IStringTable( scrollPane, itsWindow, 0, 0, 0, 0,
  111.             sizELASTIC, sizELASTIC);
  112.         itsStringTable->FitToEnclosure( TRUE, TRUE);
  113.         itsStringTable->SetDrawActiveBorder( TRUE);
  114.         itsStringTable->SetDblClickCmd(cmdOpenErrorLine);
  115.         
  116.         itsStringTable->SetID( 10);
  117.  
  118.         listBorder = new( CPaneBorder);
  119.         listBorder->IPaneBorder( kBorderFrame);
  120.         itsStringTable->SetBorder( listBorder);
  121.                 
  122.         itsStringTable->SetSelectionFlags( selOnlyOne);
  123.         
  124.         scrollPane->InstallPanorama( itsStringTable);
  125.         
  126.         itsStrings = new( CStringArray);
  127.         itsStrings->IStringArray(maxStringLen);
  128.         itsStringTable->SetArray( itsStrings, FALSE);
  129.         
  130.         SetCell( aCell, 0, 0);
  131.         itsStringTable->SelectCell( aCell, FALSE, FALSE);
  132.     }
  133.     
  134.     SetupItems();
  135.     gDecorator->StaggerWindow(itsWindow);
  136. }    /* CErrorLog::IErrorLog */
  137.  
  138. void CErrorLog::Hprintf(char *s, ...)
  139. {
  140.     va_list ap;
  141.     char *m;
  142.     va_start(ap,s);
  143.     m = (char *) icemalloc(maxStringLen+1);
  144.     vsprintf(m,s,ap);
  145.     va_end(ap);
  146.     c2pstr(m);
  147.     ErrorCount++;
  148.     itsStrings->InsertAtIndex((Ptr) m,ErrorCount);
  149. }
  150.  
  151. /******************************************************************************
  152.  DoCommand
  153. ******************************************************************************/
  154.  
  155. void CErrorLog::DoCommand( long aCmd)
  156. {
  157.     Cell    selectedCell;
  158.     Str255    string;
  159.     Boolean haveSelection;
  160.     
  161.     SetCell( selectedCell, 0, 0);
  162.     haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
  163.     
  164.     switch (aCmd)
  165.     {
  166.         case cmdClose:
  167.             gErrs = NULL;
  168.             gProject->ResetGopher();
  169.             inherited::DoCommand(aCmd);
  170.             break;
  171.     /* The functionality of opening error messages in Alpha has been removed */
  172. #ifdef OLDM
  173.         case cmdOpenErrorLine:
  174.             /* Now we send an open message to Alpha */
  175.             gApplication->InspectSystem();
  176.             if (gSystem.hasAppleEvents && gCurSourceFile)
  177.             {
  178.                 AERecord ae;
  179.                 AEDescList aeList;
  180.                 AEDesc docDesc;
  181.                 AEAddressDesc alfa;
  182.                 OSType theSig = 'ALFA';
  183.                 OSErr err;
  184.                 FSSpec theSpec;
  185.                 char theScript[512];
  186.                 char theName[64];
  187.                 char justName[64];
  188.                 short itsVol;
  189.                 long itsDir;
  190.                 long theLine;
  191.                 int ndx;
  192.                 char path[512];
  193.                 Cell aCell = {0,0};
  194.                 Boolean thereIsASelection = false;
  195.                 StringHandle    openScript;
  196.  
  197.                 if (itsStringTable->GetSelect(false,&aCell)) {
  198.                     thereIsASelection = true;
  199.                 }
  200.                 else if (itsStringTable->GetSelect(true,&aCell)) {
  201.                     thereIsASelection = true;
  202.                 }
  203.                 itsStringTable->GetCellText(aCell,63,(StringPtr) theName);
  204.                 p2cstr(theName);
  205.                 if (theName[0] == '<') {
  206.                     /* Error appears in System Header */
  207.                     ndx = 1;
  208.                     while (theName[ndx] != '>') {
  209.                         justName[ndx-1] = theName[ndx];
  210.                         ndx++;
  211.                     }
  212.                     justName[ndx] = 0;
  213.                     itsVol = gApplication->StdIncludeVol;
  214.                     itsDir = gApplication->StdIncludeDir;
  215.                 }
  216.                 else if (theName[0] == '\"') {
  217.                     /* Error appears in user header or file */
  218.                     ndx = 1;
  219.                     while (theName[ndx] != '\"') {
  220.                         justName[ndx-1] = theName[ndx];
  221.                         ndx++;
  222.                     }
  223.                     justName[ndx] = 0;
  224.                     itsVol = gProject->itsFile->volNum;
  225.                     itsDir = gProject->itsFile->dirID;
  226.                 }
  227.                 else {
  228.                     justName[0] = 0;
  229.                 }
  230. #ifdef USE_TCL
  231.                 if (justName[0] && gSystem.hasAppleEvents) {
  232.                     GetPathName(path,justName,itsVol,itsDir);
  233.                     p2cstr(path);
  234.                     while (!isdigit(theName[ndx])) ndx++; /* skip the colon */
  235.                     theLine = atoi(theName+ndx);
  236.             
  237.                     openScript = GetString(openFileTCLID);
  238.                     FailNILRes( openScript);
  239.                     HLock(openScript);
  240.                     sprintf(theScript,(char *) (*openScript),path,theLine);
  241.                     HUnlock(openScript);
  242.                     
  243.                     err = AECreateDesc(typeApplSignature,(Ptr) &theSig,(Size) sizeof(theSig),&alfa);
  244.                     FailOSErr(err);
  245.                     err = AECreateAppleEvent(kTclClass,kAEEval,&alfa,kAutoGenerateReturnID,
  246.                         kAnyTransactionID,&ae);
  247.                     FailOSErr(err);
  248.                     err = AECreateList(NULL,0,FALSE,&aeList);
  249.                     FailOSErr(err);
  250.                     err = AECreateDesc(typeCString,(Ptr) theScript, strlen(theScript)+1,
  251.                         &docDesc);
  252.                     FailOSErr(err);
  253.                     err = AEPutDesc(&aeList,0,&docDesc);
  254.                     FailOSErr(err);
  255.                     err = AEPutParamDesc(&ae,keyDirectObject,&aeList);
  256.                     FailOSErr(err);
  257.                     err = AESend(&ae,NULL,kAENoReply,kAENormalPriority,0,NULL,NULL);
  258.                     FailOSErr(err);
  259.                     if (!err) {
  260.                         ProcessSerialNumber process;
  261.                         ProcessInfoRec InfoRec;
  262.                         FSSpec theSpec;
  263.                         if (FindAProcess('ALFA',&process,&InfoRec,&theSpec)) {
  264.                             SetFrontProcess(&process);
  265.                         }
  266.                     }
  267.                 }
  268. #else
  269.                 if (justName[0]) {
  270.                 if (gSystem.hasAppleEvents && theSig)
  271.                 {
  272.                     AliasHandle withThis;
  273.                     
  274.                     GetPathName(path,justName,itsVol,itsDir);
  275.                     FSMakeFSSpec(itsVol,
  276.                                 itsDir,
  277.                                 path,
  278.                                 &theSpec);
  279.                     err = AECreateDesc(typeApplSignature,(Ptr) &theSig,(Size) sizeof(theSig),&alfa);
  280.                     FailOSErr(err);
  281.                     err = AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&alfa,kAutoGenerateReturnID,
  282.                         kAnyTransactionID,&ae);
  283.                     FailOSErr(err);
  284.                     err = AECreateList(NULL,0,FALSE,&aeList);
  285.                     FailOSErr(err);
  286.                     NewAlias(NULL,&theSpec,&withThis);
  287.                     HLock((Handle) withThis);
  288.                     err = AECreateDesc(typeAlias,(Ptr) *withThis, GetHandleSize((Handle) withThis),
  289.                         &docDesc);
  290.                     FailOSErr(err);
  291.                     HUnlock((Handle) withThis);
  292.                     err = AEPutDesc(&aeList,0,&docDesc);
  293.                     FailOSErr(err);
  294.                     err = AEPutParamDesc(&ae,keyDirectObject,&aeList);
  295.                     FailOSErr(err);
  296.                     err = AESend(&ae,NULL,kAENoReply,kAENormalPriority,0,NULL,NULL);
  297.                     FailOSErr(err);
  298.                     if (!err) {
  299.                         ProcessSerialNumber process;
  300.                         ProcessInfoRec InfoRec;
  301.                         FSSpec theSpec;
  302.                         if (FindAProcess(theSig,&process,&InfoRec,&theSpec)) {
  303.                             SetFrontProcess(&process);
  304.                         }
  305.                     }
  306.                 }
  307.                 }
  308. #endif
  309.                 }
  310. #endif /* OLDM */
  311.             break;
  312.         default: 
  313.                 inherited::DoCommand( aCmd);
  314.                 break;
  315.     }
  316.                 
  317. }    /* CErrorLog::DoCommand */
  318.  
  319. /******************************************************************************
  320.  SetupItems
  321. ******************************************************************************/
  322.  
  323. void CErrorLog::SetupItems( void)
  324. {
  325.     Cell    selectedCell;
  326.     Boolean haveSelection;
  327.     CDialog    *dialog;
  328.     Str255    str;
  329.  
  330.     /* determine if any cells are now selected    */
  331.     
  332.     SetCell( selectedCell, 0, 0);
  333.     haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
  334.     
  335.     dialog = (CDialog*) itsWindow;
  336.     
  337.     if (haveSelection)
  338.         itsStrings->GetItem( str, selectedCell.v+1);
  339.     else
  340.         str[0] = 0;
  341.  
  342.     itsEditItem->SetTextString( str);
  343.     itsEditItem->SelectAll( kRedraw);
  344.  
  345. }    /* CErrorLog::SetupItems */
  346.  
  347. /******************************************************************************
  348.  ProviderChanged
  349. ******************************************************************************/
  350.  
  351. void CErrorLog::ProviderChanged( CCollaborator *aProvider, long reason,
  352.                                         void *info)
  353. {
  354.     Cell    selectedCell;
  355.     Boolean haveSelection;
  356.  
  357.     if ((aProvider == itsStringTable) && (reason == tableSelectionChanged))
  358.     {
  359.         SetupItems();
  360.     }
  361.     else
  362.         inherited::ProviderChanged( aProvider, reason, info);
  363.  
  364. }    /* CErrorLog::ProviderChanged */
  365.  
  366. /******************************************************************************
  367.  Dispose
  368. ******************************************************************************/
  369.  
  370. void CErrorLog::Dispose( void)
  371. {
  372.     ForgetObject( itsStrings);
  373.     ForgetObject( itsStringTable);
  374.     inherited::Dispose();
  375. }
  376.  
  377.