示例#1
0
文件: cpost.c 项目: pmuellr/cpost
/*------------------------------------------------------------------
 * main program
 *------------------------------------------------------------------*/
int main(
   int   argc,
   char *argv[]
   )
   {
   int        i;
   char       dateStr[30];
   struct tm *tm;
   time_t     t;
   char      *origParms;

   /*---------------------------------------------------------------
    * check for help
    *---------------------------------------------------------------*/
   if ((1 == argc) || ('?' == *(argv[1])))
      Usage();

   /*---------------------------------------------------------------
    * get original parms
    *---------------------------------------------------------------*/
   origParms  = malloc(1);
   *origParms = 0;

   for (i=0; i<argc; i++)
      {
      origParms = realloc(origParms,2 + strlen(origParms) + strlen(argv[i]));
      strcat(origParms," ");
      strcat(origParms,argv[i]);
      }

   /*---------------------------------------------------------------
    * zero out info
    *---------------------------------------------------------------*/
   memset(&info,0,sizeof(info));

   /*---------------------------------------------------------------
    * get options
    *---------------------------------------------------------------*/
   GetOptions(&argc,argv,&info);

   /*---------------------------------------------------------------
    * buffer output
    *---------------------------------------------------------------*/
/* setvbuf(info.oFile,NULL,_IOFBF,32000); */

   /*---------------------------------------------------------------
    * put filenames in a list
    *---------------------------------------------------------------*/
   info.fileList = ListCreate(sizeof(File),
                              (ListCompareFunc *)FileNameCompare,
                              cPostNoMem);
   if (!info.fileList)
      cPostError(1,"error creating list of files");

   for (i=1; i<argc; i++)
      FileSpecAdd(&info,info.fileList,argv[i]);

   /*---------------------------------------------------------------
    * check for no files to process
    *---------------------------------------------------------------*/
   if (!ListCount(info.fileList))
      cPostError(1,"no files to process");

   /*---------------------------------------------------------------
    * intialize rest of info structure
    *---------------------------------------------------------------*/
   info.funcTree  = ListCreate(sizeof(Function),
                               (ListCompareFunc *)FunctionNameCompare,
                               cPostNoMem);
   if (!info.fileList)
      cPostError(1,"error creating list of functions");

   info.identHash   = HashCreate(sizeof(char *),
                                 1000,
                                 (HashFunc *)IdentHash,
                                 (ListCompareFunc *)IdentCompare,
                                 cPostNoMem);


   if (!info.identHash)
      cPostError(1,"error creating global hash table");

   /*---------------------------------------------------------------
    * setup error termination processing
    *---------------------------------------------------------------*/
   atexit(RunAtExit);
   signal(SIGINT,  SignalHandler);
   signal(SIGTERM, SignalHandler);

#if defined(OPSYS_OS2) || defined(OPSYS_OS2V2)
   signal(SIGBREAK,SignalHandler);
#endif

   /*---------------------------------------------------------------
    * print header
    *---------------------------------------------------------------*/
   fprintf(info.oFile,"%%! PostScript file generated by %s %s\n\n",
           PROGRAM_NAME,PROGRAM_VERS);

/*------------------------------------------------------------------
 * a macro to write a line to the output file
 *------------------------------------------------------------------*/
#define p(x) fprintf(info.oFile,"%s\n",x);


   /*---------------------------------------------------------------
    * write command line and environment variable setting
    *---------------------------------------------------------------*/
#if defined(ECHO_COMMAND_LINE)
      {
      p("%%-----------------------------------------------------------------")

      fprintf(info.oFile,"%%%% this file created with the command:\n");
      fprintf(info.oFile,"%%%%   %s\n",origParms);
      fprintf(info.oFile,"%%%% the CPOST environment variable ");
      if (!getenv(PROGRAM_ENVV))
         fprintf(info.oFile,"is not set.\n");
      else
         {
         fprintf(info.oFile,"is set to:\n");
         fprintf(info.oFile,"%%%%   %s\n",getenv(PROGRAM_ENVV));
         }

      p("%%-----------------------------------------------------------------")
      p("");
      }
#endif

   /*---------------------------------------------------------------
    * write wrapper prefix
    *---------------------------------------------------------------*/
   if (info.oWrapB && strlen(info.oWrapB))
      processImbedFile(info.oWrapB);

   /*---------------------------------------------------------------
    * get the time
    *---------------------------------------------------------------*/
   t  = time(NULL);
   tm = localtime(&t);
   strftime(dateStr,sizeof(dateStr)-1,"%m/%d/%y   %H:%M:%S",tm);

   p("%%-----------------------------------------------------------------")
   p("%% runtime options and values")
   p("%%-----------------------------------------------------------------")
   p("")
   fprintf(info.oFile,"/printDate (%s) def\n",dateStr);
   fprintf(info.oFile,"/oSpace %d def\n",info.oSpace);
   fprintf(info.oFile,"/oXlate { %d %d translate } def\n",info.oXlateX,info.oXlateY);
   fprintf(info.oFile,"/oDuplex 1 %d eq def\n",info.oDuplex);
   fprintf(info.oFile,"/oNumber 0 %d ne def\n",info.oSpace);
   p("")

   /*---------------------------------------------------------------
    * write replaced header ...
    *---------------------------------------------------------------*/
   if (info.oRepHdr && strlen(info.oRepHdr))
      {
      processImbedFile(info.oImbed);
      p("");
      processImbedFile(info.oRepHdr);
      p("");
      }

   /*---------------------------------------------------------------
    * or default stuff
    *---------------------------------------------------------------*/
   else
      {
      for (i=0; i< sizeof(Header_1)/sizeof(char *); i++)
         p(Header_1[i]);

      p("");
      processImbedFile(info.oImbed);
      p("");

      for (i=0; i< sizeof(Header_2)/sizeof(char *); i++)
         p(Header_2[i]);

      p("");
      }

   /*---------------------------------------------------------------
    * read the files. make copies
    *---------------------------------------------------------------*/
   fprintf(stderr,"Pass 1\n");
   ListIterate(info.fileList,(ListIterateFunc *)Pass1,&info);

   /*---------------------------------------------------------------
    * read the copies. write the output file
    *---------------------------------------------------------------*/
   fprintf(stderr,"Pass 2\n");
   ListIterate(info.fileList,(ListIterateFunc *)Pass2,&info);

   /*---------------------------------------------------------------*
    * print trailing line feed
    *---------------------------------------------------------------*/
   fprintf(info.oFile,"\n");

   /*---------------------------------------------------------------
    * write wrapper suffix
    *---------------------------------------------------------------*/
   if (info.oWrapA && strlen(info.oWrapA))
      processImbedFile(info.oWrapA);

   /*---------------------------------------------------------------
    * close file (another line feed for luck!)
    *---------------------------------------------------------------*/
   fprintf(info.oFile,"\n");
   fclose(info.oFile);

   AllDone = 1;
   return 0;
   }
示例#2
0
文件: xsm.c 项目: aosm/X11
static void
InteractDoneProc(SmsConn smsConn, SmPointer managerData, Bool cancelShutdown)
{
    ClientRec	*client = (ClientRec *) managerData;
    List	*cl;

    if (verbose)
    {
	printf (
	"Client Id = %s, received INTERACT DONE [Cancel Shutdown = %s]\n",
	client->clientId, cancelShutdown ? "True" : "False");
    }

    if (cancelShutdown)
    {
	ListFreeAllButHead (WaitForInteractList);
	ListFreeAllButHead (WaitForPhase2List);
    }

    if (cancelShutdown)
    {
	if (shutdownCancelled)
	{
	    /* Shutdown was already cancelled */
	    return;
	}

	shutdownCancelled = True;

	for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
	{
	    client = (ClientRec *) cl->thing;

	    SmsShutdownCancelled (client->smsConn);

	    if (verbose) 
	    {
		printf ("Client Id = %s, sent SHUTDOWN CANCELLED\n",
			client->clientId);
	    }
	}
    }
    else
    {
	if ((cl = ListFirst (WaitForInteractList)) != NULL)
	{
	    LetClientInteract (cl);
	}
	else
	{
	    if (verbose)
	    {
		printf ("\n");
		printf ("Done interacting with all clients.\n");
		printf ("\n");
	    }

	    if (ListCount (WaitForPhase2List) > 0)
	    {
		StartPhase2 ();
	    }
	}
    }
}
示例#3
0
文件: xsm.c 项目: aosm/X11
static Bool
OkToEnterPhase2(void)

{
    return (ListCount (WaitForPhase2List) == ListCount (WaitForSaveDoneList));
}
示例#4
0
文件: xsm.c 项目: aosm/X11
void
CloseDownClient(ClientRec *client)
{
    int index_deleted = 0;

    if (verbose) {
	printf ("ICE Connection closed, IceConn fd = %d\n",
		IceConnectionNumber (client->ice_conn));
	printf ("\n");
    }

    SmsCleanUp (client->smsConn);
    IceSetShutdownNegotiation (client->ice_conn, False);
    IceCloseConnection (client->ice_conn);

    client->ice_conn = NULL;
    client->smsConn = NULL;

    if (!shutdownInProgress && client_info_visible)
    {
	for (index_deleted = 0;
	    index_deleted < numClientListNames; index_deleted++)
	{
	    if (clientListRecs[index_deleted] == client)
		break;
	}
    }

    ListSearchAndFreeOne (RunningList, (char *) client);

    if (saveInProgress)
    {
	Status delStatus = ListSearchAndFreeOne (
	    WaitForSaveDoneList, (char *) client);

	if (delStatus)
	{
	    ListAddLast (FailedSaveList, (char *) client);
	    client->freeAfterBadSavePopup = True;
	}

	ListSearchAndFreeOne (WaitForInteractList, (char *) client);
	ListSearchAndFreeOne (WaitForPhase2List, (char *) client);

	if (delStatus && ListCount (WaitForSaveDoneList) == 0)
	{
	    if (ListCount (FailedSaveList) > 0 && !checkpoint_from_signal)
		PopupBadSave ();
	    else
		FinishUpSave ();
	}
	else if (ListCount (WaitForInteractList) > 0 &&
	    OkToEnterInteractPhase ())
	{
	    LetClientInteract (ListFirst (WaitForInteractList));
	}
	else if (!phase2InProgress &&
	    ListCount (WaitForPhase2List) > 0 && OkToEnterPhase2 ())
	{
	    StartPhase2 ();
	}
    }

    if (client->restartHint == SmRestartImmediately && !shutdownInProgress)
    {
	Clone (client, True /* use saved state */);

	ListAddLast (RestartImmedList, (char *) client);
    }
    else if (client->restartHint == SmRestartAnyway)
    {
	ListAddLast (RestartAnywayList, (char *) client);
    }
    else if (!client->freeAfterBadSavePopup)
    {
	FreeClient (client, True /* free props */);
    }

    if (shutdownInProgress)
    {
	if (ListCount (RunningList) == 0)
	    EndSession (0);
    }
    else if (client_info_visible)
    {
	UpdateClientList ();

	if (current_client_selected == index_deleted)
	{
	    if (current_client_selected == numClientListNames)
		current_client_selected--;

	    if (current_client_selected >= 0)
	    {
		XawListHighlight (clientListWidget, current_client_selected);
		ShowHint (clientListRecs[current_client_selected]);
		if (client_prop_visible)
		{
		    DisplayProps (clientListRecs[current_client_selected]);
		}
	    }
	}
	else
	{
	    if (index_deleted < current_client_selected)
		current_client_selected--;
	    XawListHighlight (clientListWidget, current_client_selected);
	}
    }
}
示例#5
0
文件: xsm.c 项目: aosm/X11
static Bool
OkToEnterInteractPhase(void)
{
    return ((ListCount (WaitForInteractList) +
	ListCount (WaitForPhase2List)) == ListCount (WaitForSaveDoneList));
}
示例#6
0
static INT_PTR LinkList_Main(WPARAM wParam, LPARAM)
{
	HANDLE hContact = (HANDLE)wParam;
	HWND hWnd = WindowList_Find(hWindowList, hContact);
	if ( hWnd != NULL ) {
		int len;
		SetForegroundWindow(hWnd);
		SetFocus(hWnd);
		len = GetWindowTextLength(GetDlgItem(hWnd, IDC_MAIN));
		PostMessage(GetDlgItem(hWnd, IDC_MAIN), EM_SETSEL, (WPARAM)len, (LPARAM)len);
		return 0;
	}	
	
	HANDLE hEvent = db_event_first(hContact);
	if (hEvent == NULL) {
		MessageBox(NULL, TXT_EMPTYHISTORY, TXT_PLUGINNAME, MB_OK | MB_ICONINFORMATION );
		return 0;
	}

	int histCount = db_event_count(hContact), actCount = 0;

	DBEVENTINFO dbe = { sizeof(dbe) };
	dbe.cbBlob = db_event_getBlobSize(hEvent);
	dbe.pBlob  = (PBYTE)malloc(dbe.cbBlob+1);
	db_event_get(hEvent, &dbe);
	dbe.pBlob[dbe.cbBlob] = 0;

	RECT DesktopRect;
	GetWindowRect(GetDesktopWindow(), &DesktopRect);
	HWND hWndProgress = CreateWindow(_T("Progressbar"), TranslateT("Processing history..."), WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 350, 45, NULL, NULL, hInst, NULL);
	if ( hWndProgress == 0 ) {
		free(dbe.pBlob);
		MessageBox(NULL, TranslateT("Could not create window!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION );
		return -1;
	}
	SetWindowPos(hWndProgress, HWND_TOP, (int)(DesktopRect.right*0.5)-175, (int)(DesktopRect.bottom*0.5)-22, 0, 0, SWP_NOSIZE);
	ShowWindow(hWndProgress, SW_SHOW);
	SetForegroundWindow(hWndProgress);

	LISTELEMENT *listStart = (LISTELEMENT*)malloc(sizeof(LISTELEMENT));
	ZeroMemory(listStart, sizeof(LISTELEMENT));

	while( 1 ) {
		if ( dbe.eventType == EVENTTYPE_URL || dbe.eventType == EVENTTYPE_MESSAGE ) {
			// Call function to find URIs
			if ( ExtractURI(&dbe, hEvent, listStart) < 0 ) {
				free(dbe.pBlob);
				RemoveList(listStart);
				MessageBox(NULL, TranslateT("Could not allocate memory!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION);
				return -1;
			}
		}
		actCount++;
		if ( ((int)(((float)actCount/histCount)*100.00)) % 10 == 0 )
			SendMessage(hWndProgress, WM_COMMAND, 100, ((int)(((float)actCount/histCount)*100.00)));
		
		hEvent = db_event_next(hEvent);
		if ( hEvent == NULL )
			break;

		free(dbe.pBlob);
		dbe.cbBlob = db_event_getBlobSize(hEvent);
		dbe.pBlob = (PBYTE)malloc(dbe.cbBlob+1);
		db_event_get(hEvent, &dbe);
		dbe.pBlob[dbe.cbBlob] = 0;
	}
	free(dbe.pBlob);
	SendMessage(hWndProgress, WM_CLOSE, 0, 0);
	if ( ListCount(listStart) <= 0 ) {	
		RemoveList(listStart);
		MessageBox(NULL, TXT_NOLINKINHISTORY, TXT_PLUGINNAME, MB_OK | MB_ICONINFORMATION);
		return 0;
	}

	DIALOGPARAM *DlgParam = (DIALOGPARAM*)malloc(sizeof(DIALOGPARAM));
	DlgParam->hContact    = hContact;
	DlgParam->listStart   = listStart;
	DlgParam->findMessage = 0;
	DlgParam->chrg.cpMax  = -1;
	DlgParam->chrg.cpMin  = -1;

	HWND hWndMain = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, MainDlgProc, (LPARAM)DlgParam);
	if (hWndMain == 0) {
		RemoveList(listStart);
		MessageBox(NULL, TranslateT("Could not create window!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION );
		return -1;
	}

	ShowWindow(hWndMain, SW_SHOW);	
	return 0;
}
示例#7
0
int ListHubs(List **list)
{
    AvahiClient *client = NULL;
    AvahiServiceBrowser *sb = NULL;
    int error;

    hublist = ListNew(&CompareHosts, NULL, &free);
    if (!hublist)
    {
        return -1;
    }

    spoll = NULL;
    avahi_handle = NULL;

    RegisterAtExitFunction(&AtExitDlClose);

    if (loadavahi() == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Avahi was not found");
        return -1;
    }

    if (!(spoll = avahi_simple_poll_new_ptr()))
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Failed to create simple poll object.");

        if (spoll)
        {
            avahi_simple_poll_free_ptr(spoll);
        }
        return -1;
    }

    client = avahi_client_new_ptr(avahi_simple_poll_get_ptr(spoll), 0, client_callback, NULL, &error);

    if (!client)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Failed to create client %s", avahi_strerror_ptr(error));

        if (client)
        {
            avahi_client_free_ptr(client);
        }

        if (spoll)
        {
            avahi_simple_poll_free_ptr(spoll);
        }

        return -1;
    }

    if (!(sb = avahi_service_browser_new_ptr(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_cfenginehub._tcp", NULL, 0, browse_callback, client)))
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Failed to create service browser: %s", avahi_strerror_ptr(avahi_client_errno_ptr(client)));
        
        if (spoll)
        {
            avahi_simple_poll_free_ptr(spoll);
        }

        if (client)
        {
            avahi_client_free_ptr(client);
        }

        if (sb)
        {
            avahi_service_browser_free_ptr(sb);
        }

        return -1;
    }

    avahi_simple_poll_loop_ptr(spoll);

    if (sb)
        avahi_service_browser_free_ptr(sb);
    if (client)
        avahi_client_free_ptr(client);
    if (spoll)
        avahi_simple_poll_free_ptr(spoll);
    
    *list = hublist;

    return ListCount(*list);
}
示例#8
0
//-----------------------------------------------------------------------------
int main(int argc, char *argv[]) {

    LISTNODE Head;
    LISTNODE AnotherHead;
    ROOTLIST RootListHead;
    String PutNamesHere;
    String CurrentFileName;
    SIGNATURE Signature;
    ANNOTATEDFORMULA AnnotatedFormula;
    ANNOTATEDFORMULA AnotherAnnotatedFormula;
    ANNOTATEDFORMULA DuplicatedAnnotatedFormula;
    FORMULA Literal;
    FORMULA AnotherLiteral;
    String SomeString;
    char * SymbolUsage;
    char * AnotherSymbolUsage;
    char * VariablesStartHere;
    int SymbolUsageLength = STRINGLENGTH;
    int VarCount,QuantCount;
    StatusType SubStatus;
    TERM ANewTerm;
    int Positive,Negative;
    READFILE Stream;
    ListStatisticsRecordType ListStatistics;
    int Universals,Existentials;
    int NumberRemoved;
    ContextType Context;
    LISTNODE Axioms;
    LISTNODE Conjectures;
    LISTNODE Target;
    String FormulaName;
    String OutputFileName;
    int Result;
    BTREENODE BTreeRoot;
    BTREENODE * SearchResult;
    TERMArray ArrayOfInfoTERMs;
    int NumberOfTerms;
    int Index;
    SZSResultType SZS1,SZS2;
    SZSOutputType SZSO1,SZSO2;

//----One signature for all testing
    Signature = NewSignature();

//----Read from file or stdin
    SetNeedForNonLogicTokens(1);
    SetAllowFreeVariables(0);
//----Test duplicate arity warnings
    SetWarnings(1);
    if (argc > 1) {
        Head = ParseFileOfFormulae(argv[1],NULL,Signature,1,NULL);
    } else {
        Head = ParseFILEOfFormulae(stdin,Signature,1,NULL);
    }
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//-----------------------------------------------------------------------------
//----Test comparison of first two formula for being the same
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    AnotherAnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,2);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    PrintAnnotatedTSTPNode(stdout,AnotherAnnotatedFormula,tptp,1);
    if (SameFormulaInAnnotatedFormulae(AnnotatedFormula,
AnotherAnnotatedFormula,0,1)) {
        printf("They are identical\n");
    } else {
        if (SameFormulaInAnnotatedFormulae(AnnotatedFormula,
AnotherAnnotatedFormula,1,1)) {
            printf("They are renamings\n");
        } else {
            printf("They are quite different\n");
        }
    }
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test list duplication
    AnotherHead = DuplicateListOfAnnotatedFormulae(Head,Signature);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeListOfAnnotatedFormulae(&AnotherHead);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test reading header
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    SetNeedForNonLogicTokens(1);
    Head = ParseFileOfHeader(argv[1]);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    return(EXIT_SUCCESS);

//----Test building root list
    RootListHead = BuildRootList(Head);
    PrintRootList(stdout,RootListHead);
    FreeRootList(&RootListHead,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test randomization
    RandomizeListOfAnnotatedFormulae(&Head,1);
    printf("------------ Randomized ---------------\n");
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test getting root list
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,GetRootList(Head),tptp,1);
    return(EXIT_SUCCESS);

//----Test vine of lemmas extraction
    printf("---- Vine of lemmas ---\n");
    RootListHead = BuildRootList(Head);
    PrintRootList(stdout,RootListHead);
    if (GetRootLemmaList(RootListHead->TheTree,&Axioms,0)) {
        PrintListOfAnnotatedTSTPNodes(stdout,Signature,Axioms,tptp,1);
        FreeListOfAnnotatedFormulae(&Axioms);
    } else {
        printf("Could not extract vine of axioms\n");
    }
    FreeRootList(&RootListHead,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test dequoting
    PrintSignature(Signature);
    printf("---- Dequote ---\n");
    DequoteSymbolsInSignature(Signature);
    PrintSignature(Signature);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test aritizing
    PrintSignature(Signature);
    printf("---- Aritize ---\n");
    AritizeSymbolsInSignature(Signature);
    PrintSignature(Signature);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test expanding assumptions
    printf("---- Expand assumptions ---\n");
    ExpandListAssumptions(Head,Signature);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test formula duplication
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    if (AnnotatedFormula != NULL) {
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        PrintVariableList(AnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables,
NULL);
        PrintSignature(Signature);
        DuplicatedAnnotatedFormula = DuplicateAnnotatedFormula(AnnotatedFormula,
Signature);
        PrintAnnotatedTSTPNode(stdout,DuplicatedAnnotatedFormula,tptp,1);
        PrintVariableList(DuplicatedAnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables,
NULL);
        PrintSignature(Signature);
    } else {
        printf("Could not get formula dv\n");
    }
    return(EXIT_SUCCESS);

//----Test uninterpreting of integers
    UninterpretIntegersInSignature(Signature);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    exit(EXIT_SUCCESS);

//----Test getting inference rule
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if ((SymbolUsage = GetSource(AnnotatedFormula)) != NULL) {
        printf("The source is ==%s==\n",SymbolUsage);
        Free((void **)&SymbolUsage);
    }
    if ((SymbolUsage = GetSourceTerm(AnnotatedFormula,NULL)) != NULL) {
        printf("The source term is ==%s==\n",SymbolUsage);
        Free((void **)&SymbolUsage);
    }
    if ((SymbolUsage = GetInferenceRule(AnnotatedFormula,NULL)) != NULL) {
        printf("The inference rule is ==%s==\n",SymbolUsage);
        Free((void **)&SymbolUsage);
    }
    if ((SymbolUsage = GetParentNames(AnnotatedFormula,NULL)) != NULL) {
        printf("The parents are ==%s==\n",SymbolUsage);
        Free((void **)&SymbolUsage);
    }
    if ((SymbolUsage = GetSourceInfoTerm(AnnotatedFormula,"introduced","status",
NULL)) != NULL) {
        printf("The status term is %s\n",SymbolUsage);
        Free((void **)&SymbolUsage);
    }
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test getting nested inference info
    PrintAnnotatedTSTPNode(stdout,Head->AnnotatedFormula,tptp,1);
    NumberOfTerms = 0;
    ArrayOfInfoTERMs = GetInferenceInfoTERMs(Head->AnnotatedFormula,"assumptions",
&NumberOfTerms);
    for (Index = 0; Index < NumberOfTerms; Index++) {
        PrintTSTPTerm(stdout,ArrayOfInfoTERMs[Index],-1,1);
        printf("\n");
    }
    if (ArrayOfInfoTERMs != NULL) {
        Free((void **)&ArrayOfInfoTERMs);
    }
    return(EXIT_SUCCESS);

//----Test getting file source
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if (GetSource(AnnotatedFormula) != NULL) {
        printf("The source is %s\n",SomeString);
        if ((SymbolUsage = GetFileSourceNameAndNode(AnnotatedFormula,NULL)) != 
NULL) {
            printf("The file and node are %s\n",SymbolUsage);
            Free((void **)&SymbolUsage);
        } else {
            printf("No file and node\n");
        }
    } else {
        printf("No source for file and node\n");
    }
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    exit(EXIT_SUCCESS);

//----Test useful info manipulation
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature,
"useful(1)");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature,
"useful([2,two,2],2-two)");
    AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature,
"useful(3)");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if ((SymbolUsage = GetUsefulInfoTerm(AnnotatedFormula,"useful",2,NULL)) != 
NULL) {
        printf("The second useful term is %s\n",SymbolUsage);
        Free((void **)&SymbolUsage);
    }
    UpdateUsefulInformationInAnnotatedFormula(AnnotatedFormula,Signature,
"useful(4)");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    AddUsefulInformationToAnnotatedFormula(AnnotatedFormula,Signature,
"useful(5)");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    RemoveUsefulInformationFromAnnotatedFormula(AnnotatedFormula,Signature,
"useful");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test sorting by useful info
    SortByUsefulInfoField(&Head,"sortby",'f',0);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    exit(EXIT_SUCCESS);

//----Test binary trees
    printf("---- Binary tree ----\n");
    BTreeRoot = ListToBTree(Head);
    PrintBTreeOfAnnotatedFormulae(BTreeRoot);
    printf("---- Search for %s\n","pel55_5");
    if ((SearchResult = GetNodeFromBTreeByAnnotatedFormulaName(&BTreeRoot,
"pel55_5")) == NULL) {
        printf("Not found\n");
    } else {
        PrintAnnotatedTSTPNode(stdout,(*SearchResult)->AnnotatedFormula,tptp,1);
    }
    FreeBTreeOfAnnotatedFormulae(&BTreeRoot);
    assert(BTreeRoot == NULL);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test negation or universal fofify
    FOFifyList(Head,universal);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    PrintSignature(Signature);
    return(EXIT_SUCCESS);

//----Look at the signature
    PrintSignature(Signature);
    FreeListOfAnnotatedFormulae(&Head);
    FreeSignature(&Signature);
    return(EXIT_SUCCESS);

//----Test external processing
    AnotherHead = ApplyExternalProgram(Head,axiom,NULL,"cat %s",Signature);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1);
    exit(EXIT_SUCCESS);

//----Test set relationships
    AnotherHead = ParseFileOfFormulae(argv[2],NULL,Signature,1,NULL);
    printf("-------------------\n");
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1);
    printf("===================\n");
    Head = MergeInListOfAnnotatedFormulaeByFields(&Head,&AnotherHead,1,0,1);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,tptp,1);
    printf("-------------------\n");
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1);
    exit(EXIT_SUCCESS);

//----Test getting by name
    AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"freddy");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    exit(EXIT_SUCCESS);

//----Testing redirected printing
    PrintStringAnnotatedTSTPNode(SomeString,Head->AnnotatedFormula,tptp,1);
    printf("==%s==\n",SomeString);
    exit(EXIT_SUCCESS);

//----Test negation
    AnnotatedFormula = Head->AnnotatedFormula;
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if (DeDoubleNegate(AnnotatedFormula)) {
        printf("Dedouble negated\n");
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    }
    Negate(AnnotatedFormula,1);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    return(EXIT_SUCCESS);

//----Test selection of nodes with status
    Axioms = GetListOfAnnotatedFormulaeWithType(Head,axiom_like);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Axioms,tptp,1);
    return(EXIT_SUCCESS);

//----Test use of SystemOnTPTP
    if (SystemOnTPTPAvailable()) {
        Axioms = GetListOfAnnotatedFormulaeWithType(Head,axiom_like);
        printf("Axioms are ...\n");
        PrintListOfAnnotatedTSTPNodes(stdout,Signature,Axioms,tptp,1);
        Conjectures = GetListOfAnnotatedFormulaeWithType(Head,conjecture);
        Target = Conjectures;
        while (Target != NULL) {
            printf("Trying to prove %s\n",GetName(Target->AnnotatedFormula,
FormulaName));
//            strcpy(OutputFileName,FormulaName);
//            strcat(OutputFileName,".result");
//            Result = SystemOnTPTP(Axioms,Conjectures->AnnotatedFormula,
//"E---0.9","Theorem",1,"Paradox---1.3","CounterTheorem",30,">>",1,"",
//OutputFileName,OutputFileName);
            Result = SystemOnTPTP(Axioms,Conjectures->AnnotatedFormula,
"E---0.9","Theorem",1,"Paradox---1.3","CounterTheorem",30,"",1,"/tmp","output",
OutputFileName);
//            Result = SystemOnTPTP(Axioms,Conjectures->AnnotatedFormula,
//"E---0.9","Theorem",1,"Paradox---1.3","CounterTheorem",30,"",0,NULL,NULL,NULL);
            printf("The output file name is %s\n",OutputFileName);
            switch (Result) {
                case 1:
                    printf("%s is a theorem\n",FormulaName);
                    break;
                case -1:
                    printf("%s is not a theorem\n",FormulaName);
                    break;
                case 0:
                    printf("%s is unknown\n",FormulaName);
                    break;
                default:
                    CodingError("SystemOnTPTP returned something weird");
                    break;
            }
            Target = Target->Next;
        }
        FreeListOfAnnotatedFormulae(&Axioms);
        FreeListOfAnnotatedFormulae(&Conjectures);
    }
    return(EXIT_SUCCESS);

//----Test freeing
    PrintSignature(Signature);
    FreeListOfAnnotatedFormulae(&Head);
    assert(Head == NULL);
    PrintSignature(Signature);
    RemovedUnusedSymbols(Signature);
    printf("REMOVED THE UNUSED\n");
    fflush(stdout);
    PrintSignature(Signature);
    FreeSignature(&Signature);
    assert(Signature == NULL);
    return(EXIT_SUCCESS);

//----Test Foreign output
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,dfg,1);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,kif,1);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,otter,1);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,Head,xml,1);
    return(EXIT_SUCCESS);

//----Test read-free alternation
    SetNeedForNonLogicTokens(0);
    if ((Stream = OpenReadFile(argv[1],CurrentFileName)) == NULL) {
        printf("Can't open file %s\n",argv[1]);
        return(EXIT_FAILURE);
    }
    while (!CheckTokenType(Stream,endeof)) {
        printf("Start ------------------\n");
        AnnotatedFormula = ParseAndUseAnnotatedFormula(Stream,Signature);
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        PrintSignature(Signature);
        printf("Free ------------------\n");
        FreeAnnotatedFormula(&AnnotatedFormula);
        PrintSignature(Signature);
        printf("End ------------------\n");
    }
    CloseReadFile(Stream);
    return(EXIT_SUCCESS);

//----Test signature iterator
    PrintSignatureTree(Signature->Predicates);
    printf("===========\n");
    ListSignatureBySearch(Signature->Predicates);
    return(EXIT_SUCCESS);

//----Test freeing
    PrintSignature(Signature);
    FreeListOfAnnotatedFormulae(&Head);
    assert(Head == NULL);
    PrintSignature(Signature);
    RemovedUnusedSymbols(Signature);
    printf("REMOVED THE UNUSED\n");
    fflush(stdout);
    PrintSignature(Signature);
    FreeSignature(&Signature);
    assert(Signature == NULL);
    return(EXIT_SUCCESS);

//----Test getting symbol usage in general
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    SymbolUsage = (char *)Malloc(sizeof(String));
    if (GetAnnotatedFormulaSymbolUsage(AnnotatedFormula,&SymbolUsage,
&AnotherSymbolUsage) != NULL) {
        printf("The total symbol usage is \n%s and the functors are \n%s\n",
SymbolUsage,AnotherSymbolUsage);
    } else {
        printf("No total symbol usage collected\n");
    }
    Free((void **)&SymbolUsage);
    return(EXIT_SUCCESS);

//----Test internal formula copying
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    if (AnnotatedFormula != NULL) {
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        PrintVariableList(AnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables,
NULL);
        PrintSignature(Signature);
        Literal = AnnotatedFormula->AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Formula->FormulaUnion.QuantifiedFormula.Formula->FormulaUnion.BinaryFormula.LHS;
        Context.Signature = Signature;
        Context.Variables = &(AnnotatedFormula->AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables);
        AnotherLiteral = DuplicateInternalFormulaWithVariables(
Literal,Context);
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        printf("duplicate is ...\n");
        PrintTSTPFormula(stdout,AnnotatedFormula->Syntax,AnotherLiteral,0,1,
outermost,0);
        printf("\n");
        PrintVariableList(AnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables,
NULL);
        PrintSignature(Signature);
    } else {
        printf("Could not get first formula\n");
    }
    return(EXIT_SUCCESS);

//----Test variable counting
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    if (AnnotatedFormula != NULL) {
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,0);
        VarCount = CountVariableUsageInFormula(AnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Formula,
AnnotatedFormula->AnnotatedFormulaUnion.AnnotatedTSTPFormula.
FormulaWithVariables->Variables,&QuantCount);
        printf("First variable occurs %d times, plus quantified %d times\n",
VarCount,QuantCount);
    } else {
        printf("Could not get first formula\n");
    }
    return(EXIT_SUCCESS);

//----Test getting parents' names
    if (AnnotatedFormula != NULL) {
        printf("Parents are\n%s\n",GetParentNames(AnnotatedFormula,
PutNamesHere));
    } else {
        printf("Formula of that name not found\n");
    }
    return(EXIT_SUCCESS);

//----Test removal of vacuous quantifiers
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,1);
    if (AnnotatedFormula != NULL) {
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,0);
        PrintVariableList(AnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables,
NULL);
        PrintSignature(Signature);
        NumberRemoved = RemoveVacuousQuantifiersFromAnnotatedFormula(
AnnotatedFormula);
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        PrintVariableList(AnnotatedFormula->
AnnotatedFormulaUnion.AnnotatedTSTPFormula.FormulaWithVariables->Variables,
NULL);
        PrintSignature(Signature);
        printf("%d removed\n",NumberRemoved);
    } else {
        printf("Could not get first formula\n");
    }
    return(EXIT_SUCCESS);

//----Test uniqueify variable names
    AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"dv");
    if (AnnotatedFormula != NULL) {
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        PrintSignature(Signature);
        UniqueifyVariableNames(AnnotatedFormula);
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
        PrintSignature(Signature);
    } else {
        printf("Could not get formula dv\n");
    }
    return(EXIT_SUCCESS);

//----Test freeing
    FreeListOfAnnotatedFormulae(&Head);
    assert(Head == NULL);
    return(EXIT_SUCCESS);

//----Test reading another file
    AnotherHead = ParseFileOfFormulae(argv[1],NULL,Signature,1,NULL);
    PrintListOfAnnotatedTSTPNodes(stdout,Signature,AnotherHead,tptp,1);
    return(EXIT_SUCCESS);

//----Test negation or universal fofify
    AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"22");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if (DeDoubleNegate(AnnotatedFormula)) {
        printf("Dedouble negated\n");
        PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    }
    FOFify(AnnotatedFormula,universal);
    if (CheckAnnotatedFormula(AnnotatedFormula,tptp_cnf)) {
        FOFify(AnnotatedFormula,universal);
    } else {
        Negate(AnnotatedFormula,1);
    }
    printf("negated (FOF) or fofified (CNF)\n");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    return(EXIT_SUCCESS);

//----Test stats
    if (GetListStatistics(Head,Signature,&ListStatistics) != NULL) {
        PrintListStatistics(stdout,ListStatistics);
    } else {
        printf("Could not get statistics\n");
    }
    FreeListOfAnnotatedFormulae(&Head);
    assert(Head == NULL);
    return(EXIT_SUCCESS);

    AnnotatedFormula = GetAnnotatedFormulaFromListByName(Head,"pel47_14");
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    Universals = CountAnnotatedFormulaUniqueVariablesByUse(AnnotatedFormula,
-1,-1,universal);
    Existentials = CountAnnotatedFormulaUniqueVariablesByUse(AnnotatedFormula,
-1,-1,existential);
    printf("Universals = %d Existentials = %d\n",Universals,Existentials);
    return(EXIT_SUCCESS);

//----Test parsing of strings
    ANewTerm = ParseStringTerm("hello(there,my(BIG),friend)",nontype,
Signature,0);
    printf("The term is ==");
    PrintTSTPTerm(stdout,ANewTerm,-1,0);
    printf("==\n");

//----Test getting inference status
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,10);
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if (GetSource(AnnotatedFormula) != NULL) {
        printf("The source is %s\n",SomeString);
        if (GetInferenceInfoTerm(AnnotatedFormula,"status",SomeString) != NULL) {
            printf("The status term is %s\n",SomeString);
        } else {
            printf("No status term\n");
        }
    } else {
        printf("No source for status\n");
    }

//----Test getting by count
    printf("There are %d clauses\n",ListCount(Head,cnf_nodes));
    AnnotatedFormula = GetAnnotatedFormulaFromListByNumber(Head,20);
    GetName(AnnotatedFormula,PutNamesHere);
    printf("Got the node for clause named %s\n",PutNamesHere);
    printf("The status is %s\n",StatusToString(GetRole(AnnotatedFormula,
&SubStatus)));
    if (SubStatus != nonstatus) {
        printf("The substatus is %s\n",StatusToString(SubStatus));
    } else {
        printf("It has no substatus\n");
    }
    if (GetInferenceRule(AnnotatedFormula,SomeString) != NULL) {
        printf("The inference rule is %s\n",SomeString);
    } else {
        printf("No inference rule found\n");
    }

//----Print symbol extraction
    PrintAnnotatedTSTPNode(stdout,AnnotatedFormula,tptp,1);
    if (CountLiteralsOfPolarity(AnnotatedFormula,&Positive,&Negative)) {
        printf("The clause has %d literals, %d positive, %d negative\n",
CountAnnotatedFormulaAtomsByPredicate(AnnotatedFormula,""),Positive,Negative);
    }
    if ((Literal = GetLiteralFromAnnotatedClauseByNumber(AnnotatedFormula,1))
!= NULL) {
        printf("The literal is ");
        PrintTSTPFormula(stdout,AnnotatedFormula->Syntax,Literal,0,1,none,0);
        printf("\n");
        SymbolUsage = (char *)Malloc(sizeof(String));
        GetLiteralSymbolUsage(Literal,&SymbolUsage,&VariablesStartHere);
        printf("The literal data is \n%s\n",SymbolUsage);
        printf("The variables are \n%s\n",VariablesStartHere);

        if ((AnotherLiteral = GetLiteralFromAnnotatedClauseByNumber(
AnnotatedFormula,2)) != NULL) {
            printf("The literal is ");
            PrintTSTPFormula(stdout,AnnotatedFormula->Syntax,AnotherLiteral,
0,1,none,0);
            printf("\n");
            AnotherSymbolUsage = (char *)Malloc(sizeof(String));
            if (GetLiteralSymbolUsage(AnotherLiteral,&AnotherSymbolUsage,
NULL) != NULL) {
                printf("The literal data is \n%s\n",AnotherSymbolUsage);
            }
            ExtendString(&SymbolUsage,AnotherSymbolUsage,&SymbolUsageLength);
            NormalizeSymbolUsage(SymbolUsage);
            printf("The combined data is \n%s\n",SymbolUsage);
            Free((void **)&AnotherSymbolUsage);
        } else {
            printf("Could not get literal number 2\n");
        }
        Free((void **)&SymbolUsage);
    } else {
        printf("Could not get literal number 1\n");
    }

    FreeListOfAnnotatedFormulae(&Head);
    assert(Head == NULL);

    return(EXIT_SUCCESS);

//----Test SZS hierarchy
    for (SZS1=SZS;SZS1<nonszsresult;SZS1++) {
        printf("%s (%s,%s) %s\n",SZSResultToString(SZS1),
SZSResultToString(StringToSZSResult(SZSResultToString(SZS1))),
SZSResultToString(StringToSZSResult(SZSResultToUserString(SZS1))),
SZSResultToUserString(SZS1));
        for (SZS2=SZS1;SZS2<nonszsresult;SZS2++) {
            if (SZSIsA(SZS2,SZS1)) {
                printf("%s isa %s\n",SZSResultToString(SZS2),
SZSResultToString(SZS1));
            } else {
                printf("%s nota %s\n",SZSResultToString(SZS2),
SZSResultToString(SZS1));
            }
        }
    }
    for (SZSO1=LDa;SZSO1<nonszsoutput;SZSO1++) {
        printf("%s (%s,%s) %s\n",SZSOutputToString(SZSO1),
SZSOutputToString(StringToSZSOutput(SZSOutputToString(SZSO1))),
SZSOutputToString(StringToSZSOutput(SZSOutputToUserString(SZSO1))),
SZSOutputToUserString(SZSO1));
        for (SZSO2=SZSO1;SZSO2<nonszsoutput;SZSO2++) {
            if (SZSOutputIsA(SZSO2,SZSO1)) {
                printf("%s isa %s\n",SZSOutputToString(SZSO2),
SZSOutputToString(SZSO1));
            } else {
                printf("%s nota %s\n",SZSOutputToString(SZSO2),
SZSOutputToString(SZSO1));
            }
        }
    }
    return(EXIT_SUCCESS);

}
	int ListCopy( CBaseEntity *pList[], int listMax )
	{
		int count = MIN(listMax, ListCount() );
		memcpy( pList, m_targetList.Base(), sizeof(CBaseEntity *) * count );
		return count;
	}
示例#10
0
void
Clone(ClientRec *client, Bool useSavedState)
{
    const char	*cwd;
    char	*program;
    char	**args;
    char	**env;
    char	**pp;
    char	*p;
    char	*restart_service_prop;
    char	*restart_protocol;
    char	*restart_machine;
    Bool	run_local;
    List	*pl, *pj;

    if (verbose)
    {
	printf ("Cloning id '%s', useSavedState = %d...\n",
		client->clientId, useSavedState);
	printf ("Host = %s\n", client->clientHostname);
    }

    cwd = ".";
    env = NULL;
    program = NULL;
    args = NULL;
    restart_service_prop = NULL;

    for (pl = ListFirst (client->props); pl; pl = ListNext (pl))
    {
	Prop *pprop = (Prop *) pl->thing;
	List *vl = ListFirst (pprop->values);
	PropValue *pval = (PropValue *) vl->thing;

	if (strcmp (pprop->name, SmProgram) == 0)
	    program = (char *) pval->value;
	else if (strcmp (pprop->name, SmCurrentDirectory) == 0)
	    cwd = (char *) pval->value;
	else if (strcmp (pprop->name, "_XC_RestartService") == 0)
	    restart_service_prop = (char *) pval->value;
	else if (
	    (!useSavedState && strcmp (pprop->name, SmCloneCommand) == 0) ||
	    (useSavedState && strcmp (pprop->name, SmRestartCommand) == 0))
	{
	    args = (char **) XtMalloc (
		(ListCount (pprop->values) + 1) * sizeof (char *));

	    pp = args;

	    for (pj = ListFirst (pprop->values); pj; pj = ListNext (pj))
	    {
		pval = (PropValue *) pj->thing;
		*pp++ = (char *) pval->value;
	    }
	    *pp = NULL;
	}
	else if (strcmp (pprop->name, SmEnvironment) == 0)
	{
	    env = (char **) XtMalloc (
		(ListCount (pprop->values) + 3 + 1) * sizeof (char *));
	    pp = env;

	    for (pj = ListFirst (pprop->values); pj; pj = ListNext (pj))
	    {
		pval = (PropValue *) pj->thing;
		p = (char *) pval->value;

		if ((display_env && strbw (p, "DISPLAY="))
	         || (session_env && strbw (p, "SESSION_MANAGER="))
		 || (audio_env && strbw (p, "AUDIOSERVER=")))
		    continue;

		*pp++ = p;
	    }

	    if (display_env)
		*pp++ = display_env;
	    if (session_env)
		*pp++ = session_env;
	    if (audio_env)
		*pp++ = audio_env;

	    *pp = NULL;
	}
    }

    if (program && args)
    {
	if (verbose)
	{
	    printf("\t%s\n", program);
	    printf("\t");
	    for (pp = args; *pp; pp++)
		printf ("%s ", *pp);
	    printf("\n");
	}

	GetRestartInfo (restart_service_prop, client->clientHostname,
    	    &run_local, &restart_protocol, &restart_machine);

	if (run_local)
	{
	    /*
	     * The client is being cloned on the local machine.
	     */

	    char msg[256];

	    switch(fork()) {
	    case -1:
		snprintf (msg, sizeof(msg),
			  "%s: Can't fork() %s", Argv[0], program);
		add_log_text (msg);
		perror (msg);
		break;
	    case 0:		/* kid */
		chdir(cwd);
		if(env) environ = env;
		execvp(program, args);
		snprintf (msg, sizeof(msg),
			  "%s: Can't execvp() %s", Argv[0], program);
		perror (msg);
		/*
		 * TODO : We would like to send this log information to the
		 * log window in the parent.  This would require opening
		 * a pipe between the parent and child.  The child would
		 * set close-on-exec.  If the exec succeeds, the pipe will
		 * be closed.  If it fails, the child can write a message
		 * to the parent.
		 */
		_exit(255);
	    default:	/* parent */
		break;
	    }
	}
	else if (!remote_allowed)
	{
	    fprintf(stderr,
		   "Can't remote clone client ID '%s': only local supported\n",
			client->clientId);
	}
	else
	{
	    /*
	     * The client is being cloned on a remote machine.
	     */

	    remote_start (restart_protocol, restart_machine,
		program, args, cwd, env,
		non_local_display_env, non_local_session_env);
	}

	if (restart_protocol)
	    XtFree (restart_protocol);

	if (restart_machine)
	    XtFree (restart_machine);

    }
    else
    {
#ifdef XKB
	XkbStdBell(XtDisplay(topLevel),XtWindow(topLevel),0,XkbBI_Failure);
#else
	XBell (XtDisplay (topLevel), 0);
#endif

	fprintf(stderr, "Can't restart ID '%s':  no program or no args\n",
		client->clientId);
    }

    if (args)
	XtFree ((char *)args);
    if (env)
	XtFree ((char *)env);
}
示例#11
0
Status
Restart(int flag)
{
    List 	*cl, *pl, *vl;
    PendingClient *c;
    Prop 	*prop;
    const char	*cwd;
    char	*program;
    char	**args;
    char	**env;
    char	**pp;
    int		cnt;
    char	*p;
    char	*restart_service_prop;
    char	*restart_protocol;
    char	*restart_machine;
    Bool	run_local;
    Bool	is_manager;
    Bool	ran_manager = 0;

    for(cl = ListFirst(PendingList); cl; cl = ListNext(cl)) {
	c = (PendingClient *)cl->thing;

	if (verbose) {
	    printf("Restarting id '%s'...\n", c->clientId);
	    printf("Host = %s\n", c->clientHostname);
	}
	cwd = ".";
	env = NULL;
	program=NULL;
	args=NULL;
	restart_service_prop=NULL;

	is_manager = 0;

	for(pl = ListFirst(c->props); pl; pl = ListNext(pl)) {
	    prop = (Prop *)pl->thing;
	    if(!strcmp(prop->name, SmProgram)) {
		vl = ListFirst(prop->values);
		if(vl) program = ((PropValue *)vl->thing)->value;
		if (CheckIsManager (program))
		    is_manager = 1;
	    } else if(!strcmp(prop->name, SmCurrentDirectory)) {
		vl = ListFirst(prop->values);
		if(vl) cwd = ((PropValue *)vl->thing)->value;
	    } else if(!strcmp(prop->name, "_XC_RestartService")) {
		vl = ListFirst(prop->values);
		if(vl) restart_service_prop =
		    ((PropValue *)vl->thing)->value;
	    } else if(!strcmp(prop->name, SmRestartCommand)) {
		cnt = ListCount(prop->values);
		args = (char **)XtMalloc((cnt+1) * sizeof(char *));
		pp = args;
		for(vl = ListFirst(prop->values); vl; vl = ListNext(vl)) {
		    *pp++ = ((PropValue *)vl->thing)->value;
		}
		*pp = NULL;
	    } else if(!strcmp(prop->name, SmEnvironment)) {
		cnt = ListCount(prop->values);
		env = (char **)XtMalloc((cnt+3+1) * sizeof(char *));
		pp = env;
		for(vl = ListFirst(prop->values); vl; vl = ListNext(vl)) {
		    p = ((PropValue *)vl->thing)->value;
		    if((display_env && strbw(p, "DISPLAY="))
		    || (session_env && strbw(p, "SESSION_MANAGER="))
		    || (audio_env && strbw(p, "AUDIOSERVER="))
		        ) continue;
		    *pp++ = p;
		}
		if(display_env) *pp++ = display_env;
		if(session_env) *pp++ = session_env;
		if(audio_env) *pp++ = audio_env;
		*pp = NULL;
	    }
	}

	if(program && args) {
	    char logtext[256];

	    if ((flag == RESTART_MANAGERS && !is_manager) ||
	        (flag == RESTART_REST_OF_CLIENTS && is_manager))
	    {
		if(args) XtFree((char *)args);
		if(env) XtFree((char *)env);
		continue;
	    }

	    if (flag == RESTART_MANAGERS && is_manager)
		ran_manager = 1;

	    if (verbose) {
		printf("\t%s\n", program);
		printf("\t");
		for(pp = args; *pp; pp++) printf("%s ", *pp);
		printf("\n");
	    }

	    GetRestartInfo (restart_service_prop, c->clientHostname,
    		&run_local, &restart_protocol, &restart_machine);

	    if (run_local)
	    {
		/*
		 * The client is being restarted on the local machine.
		 */

		snprintf (logtext, sizeof(logtext), "Restarting locally : ");
		for (pp = args; *pp; pp++)
		{
		    strcat (logtext, *pp);
		    strcat (logtext, " ");
		}

		strcat (logtext, "\n");
		add_log_text (logtext);

		switch(fork()) {
		case -1:
		    snprintf (logtext, sizeof(logtext),
			      "%s: Can't fork() %s", Argv[0], program);
		    add_log_text (logtext);
		    perror (logtext);
		    break;
		case 0:		/* kid */
		    chdir(cwd);
		    if(env) environ = env;
		    execvp(program, args);
		    snprintf (logtext, sizeof(logtext),
			      "%s: Can't execvp() %s", Argv[0], program);
		    perror (logtext);
		    /*
		     * TODO : We would like to send this log information to the
		     * log window in the parent.  This would require opening
		     * a pipe between the parent and child.  The child would
		     * set close-on-exec.  If the exec succeeds, the pipe will
		     * be closed.  If it fails, the child can write a message
		     * to the parent.
		     */
		    _exit(255);
		default:	/* parent */
		    break;
		}
	    }
	    else if (!remote_allowed)
	    {
		fprintf(stderr,
		   "Can't remote start client ID '%s': only local supported\n",
			c->clientId);
	    }
	    else
	    {
		/*
		 * The client is being restarted on a remote machine.
		 */

		snprintf (logtext, sizeof(logtext),
			  "Restarting remotely on %s : ", restart_machine);
		for (pp = args; *pp; pp++)
		{
		    strcat (logtext, *pp);
		    strcat (logtext, " ");
		}
		strcat (logtext, "\n");
		add_log_text (logtext);

		remote_start (restart_protocol, restart_machine,
		    program, args, cwd, env,
		    non_local_display_env, non_local_session_env);
	    }

	    if (restart_protocol)
		XtFree (restart_protocol);

	    if (restart_machine)
		XtFree (restart_machine);

	} else {
	    fprintf(stderr, "Can't restart ID '%s':  no program or no args\n",
		c->clientId);
	}
	if(args) XtFree((char *)args);
	if(env) XtFree((char *)env);
    }

    if (flag == RESTART_MANAGERS && !ran_manager)
	return (0);
    else
	return (1);
}
示例#12
0
文件: point.c 项目: 01org/opa-ff
/* If possible compress a point into a simpler format
 * This looks for lists which consist of a single entry or
 * lists which include all the components of a higher level type
 */
void PointFabricCompress(Point *point)
{
	switch (point->Type) {
	case POINT_TYPE_NONE:
		break;
	case POINT_TYPE_PORT:
		break;
	case POINT_TYPE_PORT_LIST:
		{
		PortData *portp;
		LIST_ITERATOR head = ListHead(&point->u.portList);
		ASSERT(head);

		ASSERT(ListCount(&point->u.portList) >= 1);

		portp = (PortData*)ListObj(head);
		if (ListCount(&point->u.portList) == 1) {
			/* degenerate case, simplify as a single port */
			PointFabricDestroy(point);
			PointInitSimple(point, POINT_TYPE_PORT, portp);
		} else if (ListCount(&point->u.portList) == cl_qmap_count(&portp->nodep->Ports)) {
			/* maybe we can consolidate to a single node */
			LIST_ITERATOR i;
			DLIST *pList = &point->u.portList;

			for (i=ListHead(pList); portp && i != NULL; i = ListNext(pList, i)) {
				if (portp->nodep != ((PortData*)ListObj(i))->nodep)
					portp = NULL;	/* not in same node, flag for below */
			}
			if (portp) {
				/* degenerate case, simplify as a single node */
				PointFabricDestroy(point);
				PointInitSimple(point, POINT_TYPE_NODE, portp->nodep);
			}
#if 0
		} else {
			// the likelihood of this is low for port oriented searches
			// and it would present just the system image guide in the summary
			// and may be less obvious to the user than a list of ports
			/* maybe we can consolidate to a single system */
			LIST_ITERATOR i;
			DLIST *pList = &point->u.portList;

			for (i=ListHead(pList); portp && i != NULL; i = ListNext(pList, i)) {
				if (portp->nodep->systemp != ((PortData*)ListObj(i))->nodep->systemp)
					portp = NULL;	/* not in same system, flag for below */
			}
			if (portp) {
				/* all ports are in same system. is it a complete list? */
				/* count ports in the system */
				uint32 count = 0;
				cl_map_item_t *p;

				for (p=cl_qmap_head(&portp->nodep->systemp->Nodes); p != cl_qmap_end(&portp->nodep->systemp->Nodes); p = cl_qmap_next(p)) {
					NodeData *nodep = PARENT_STRUCT(p, NodeData, SystemNodesEntry);
					count += cl_qmap_count(&nodep->Ports);
				}
				if (ListCount(&point->u.portList) != count)
					portp = NULL;	/* incomplete list, flag for below */
			}
			if (portp) {
				/* degenerate case, simplify as a single system */
				PointFabricDestroy(point);
				PointInitSimple(point, POINT_TYPE_SYSTEM, portp->nodep->systemp);
			}
#endif
		}
		break;
		}
	case POINT_TYPE_NODE:
		break;
	case POINT_TYPE_NODE_LIST:
		{
		NodeData *nodep;
		LIST_ITERATOR head = ListHead(&point->u.nodeList);
		ASSERT(head);

		ASSERT(ListCount(&point->u.nodeList) >= 1);
		nodep = (NodeData*)ListObj(head);
		if (ListCount(&point->u.nodeList) == 1) {
			/* degenerate case, simplify as a single node */
			PointFabricDestroy(point);
			PointInitSimple(point, POINT_TYPE_NODE, nodep);
		} else if (ListCount(&point->u.nodeList) == cl_qmap_count(&nodep->systemp->Nodes)) {
			/* maybe we can consolidate to a single system */
			LIST_ITERATOR i;
			DLIST *pList = &point->u.nodeList;

			for (i=ListHead(pList); nodep && i != NULL; i = ListNext(pList, i)) {
				if (nodep->systemp != ((NodeData*)ListObj(i))->systemp)
					nodep = NULL;	/* not in same system, flag for below */
			}
			if (nodep) {
				/* degenerate case, simplify as a single system */
				PointFabricDestroy(point);
				PointInitSimple(point, POINT_TYPE_SYSTEM, nodep->systemp);
			}
		}
		break;
		}
#if !defined(VXWORKS) || defined(BUILD_DMC)
	case POINT_TYPE_IOC:
		break;
	case POINT_TYPE_IOC_LIST:
		{
		IocData *iocp;
		LIST_ITERATOR head = ListHead(&point->u.iocList);
		ASSERT(head);

		ASSERT(ListCount(&point->u.iocList) >= 1);
		iocp = (IocData*)ListObj(head);
		if (ListCount(&point->u.iocList) == 1) {
			/* degenerate case, simplify as a single IOC */
			PointFabricDestroy(point);
			PointInitSimple(point, POINT_TYPE_IOC, iocp);
		} else if (ListCount(&point->u.iocList) == QListCount(&iocp->ioup->Iocs)) {
			/* maybe we can consolidate to a single node */
			LIST_ITERATOR i;
			DLIST *pList = &point->u.iocList;

			for (i=ListHead(pList); iocp && i != NULL; i = ListNext(pList, i)) {
				if (iocp->ioup != ((IocData*)ListObj(i))->ioup)
					iocp = NULL;	/* not in same iou, flag for below */
			}
			if (iocp) {
				/* degenerate case, simplify as a single node */
				PointFabricDestroy(point);
				PointInitSimple(point, POINT_TYPE_NODE, iocp->ioup->nodep);
			}
#if 0
		} else {
			// the likelihood of this is low for ioc oriented searches
			// and it would present just the system image guide in the summary
			// and may be less obvious to the user than a list of iocs
			/* maybe we can consolidate to a single system */
			LIST_ITERATOR i;
			DLIST *pList = &point->u.iocList;

			for (i=ListHead(pList); iocp && i != NULL; i = ListNext(pList, i)) {
				if (iocp->ioup->nodep->systemp != ((IocData*)ListObj(i))->ioup->nodep->systemp)
					iocp = NULL;	/* not in same system, flag for below */
			}
			if (iocp) {
				/* all IOCs are in same system. is it a complete list? */
				/* count IOCs in the system */
				uint32 count = 0;
				cl_map_item_t *p;

				for (p=cl_qmap_head(&iocp->ioup->nodep->systemp->Nodes); p != cl_qmap_end(&iocp->ioup->nodep->systemp->Nodes); p = cl_qmap_next(p)) {
					NodeData *nodep = PARENT_STRUCT(p, NodeData, SystemNodesEntry);
					if (nodep->ioup)
						count += QListCount(&nodep->ioup->Iocs);
				}
				if (ListCount(&point->u.iocList) != count)
					iocp = NULL;	/* incomplete list, flag for below */
			}
			if (iocp) {
				/* degenerate case, simplify as a single system */
				PointFabricDestroy(point);
				PointInitSimple(point, POINT_TYPE_SYSTEM, iocp->ioup->nodep->systemp);
			}
#endif
		}
		break;
		}
#endif
	case POINT_TYPE_SYSTEM:
		break;
	}
}