Exemple #1
0
int main()
{
	Node *tmp;
	Stack *myStack;
	myStack = mkstack(0);
	tmp = create();
	tmp -> value = fgetc(stdin);
	fgetc(stdin);

	while(tmp->value != '\n')
	{
		myStack = push(myStack, tmp);
		tmp = create();
		tmp->value = fgetc(stdin);
		fgetc(stdin);
	}

	fprintf(stdout, "linked list has %d nodes\n", myStack->data->qty);
	fprintf(stdout, "String is: ");
	do {
		tmp = pop(&myStack);
		if(tmp != NULL)
		{
			fprintf(stdout, "%c", tmp->value);
		}
		rmnode(*tmp);
	}
	while(tmp != NULL);

	fprintf(stdout, "\n");
	return(0);
}
Exemple #2
0
int main()
{
	Node *tmp = mknode(17);
	
	fprintf(stdout, "Before calling rmnode(tmp) ...   \n");
	fprintf(stdout, "---------------------------------------------\n");
	fprintf(stdout, "tmp has an address of:         %p\n", &tmp);
	fprintf(stdout, "tmp points to:                 %p\n",  tmp);

	tmp = rmnode(tmp);

	fprintf(stdout, "\nAfter calling rmnode(tmp) ...    \n");
	fprintf(stdout, "---------------------------------------------\n");
	fprintf(stdout, "tmp has an address of:         %p\n", &tmp);
	fprintf(stdout, "tmp points to:                 %p\n",  tmp);

	if (tmp == NULL)
	{
		fprintf(stdout, "tmp successfully deleted.\n");
	}
	else
	{
		fprintf(stderr, "error deleting tmp.\n");
		exit(1);
	}

	return(0);
}
Exemple #3
0
int main()
{
	Node *tmp    = NULL;
	int   testno = 0;

	fprintf(stdout, "UNIT TEST: node library rmnode() function\n");
	fprintf(stdout, "=========================================\n");

	fprintf(stdout, "Test %d: Removing NULL node ...\n", testno++);
	tmp          = rmnode(tmp);
	if (tmp == NULL)
		fprintf(stdout, " you have: NULL (success)\n");
	else
		fprintf(stdout, " you have: something\n");

	fprintf(stdout, "should be: NULL (success)\n\n"); 
	fflush(stdout);

	tmp          = mknode(37);
	if (tmp == NULL)
	{
		fprintf(stderr, "ERROR: node is NULL\n");
		exit(1);
	}

	fprintf(stdout, "Test %d: Removing node ...\n", testno++);
	tmp          = rmnode(tmp);
	if (tmp == NULL)
		fprintf(stdout, " you have: NULL (success)\n");
	else
		fprintf(stdout, " you have: something\n");

	fprintf(stdout, "should be: NULL (success)\n\n"); 
	fflush(stdout);

	return(0);
}
Exemple #4
0
int main()
{
	List *list1               = NULL;
	Node *tmp, *tmp2;

	int   i                   = 0;
	int   j                   = 0;
	int   k                   = 0;
	int   data[]              = { 2, 4, 8, 16, 32, 48, 64 };
	int   testno              = 0;

	tmp                       = NULL;
	tmp2                      = NULL;
	
	fprintf(stdout, "UNIT TEST: list library swapnode() function\n");
	fprintf(stdout, "===========================================\n");

	fprintf(stdout, "Test %d: Running swapnode() on NULL list ...\n", testno++);
	list1                     = swapnode(list1, tmp, tmp2);
	if (list1                == NULL)
		fprintf(stdout, " you have: NULL list\n");
	else
		fprintf(stdout, " you have: non-NULL list (problem)\n");
	fprintf(stdout, "should be: NULL list\n\n");
	fflush (stdout);

	list1                     = mklist();

	fprintf(stdout, "Test %d: Running swapnode() on EMPTY list ...\n", testno++);
	list1                     = swapnode(list1, tmp, tmp2);
	if (list1                == NULL)
		fprintf(stdout, " you have: NULL list (problem)\n");
	else if ((list1 -> first == NULL) &&
		     (list1 -> last  == NULL))
	{
		fprintf(stdout, " you have: EMPTY list\n");
	}
	else
		fprintf(stdout, " you have: non-NULL list (problem)\n");
	fprintf(stdout, "should be: EMPTY list\n\n");
	fflush (stdout);

	for (i = 0; i < 7; i++)
	{
		list1                 = append(list1, list1 -> last, mknode(data[i]));
	}

	fprintf(stdout, "Completed list, before swapping starts::\n");
	fprintf(stdout, "           ");
	displayf(list1, 0);
	fprintf(stdout, "\n");

	tmp                       = list1 -> first;
	tmp2                      = list1 -> last;
	i                         = getpos(list1, tmp);
	j                         = getpos(list1, tmp2);
	while ((tmp              != NULL) &&
		   (tmp2             != NULL))
	{
		fprintf(stdout, "Test %d: Running swapnode(), swapping positions %d and %d ...\n", testno++, i, j);
		list1                 = swapnode(list1, tmp, tmp2);
		fprintf(stdout, " you have: ");
		displayf(list1, 0);
		fprintf(stdout, "should be: ");

		// Master copy swaperoo
		k                     = data[i];
		data[i]               = data[j];
		data[j]               = k;

		// Display master swapped copy
		for (k = 0; k < 7; k++)
			fprintf(stdout, "%d -> ", data[k]);
		fprintf(stdout, "NULL\n\n");
		fflush (stdout);

		tmp                   = setpos(list1, ++i);
		tmp2                  = setpos(list1, --j);
	}

	// Cleaning up...
	//
	list1 = rmlist(list1);
	tmp   = rmnode(tmp);
	tmp2  = rmnode(tmp2);

	return(0);
}
Exemple #5
0
static int MainShadow(int ac, char **av, bool *pbTableSort )
{
    
    
    
    int nError = ERROR_NONE;
    bool bDoAllPasses = false;
    int nMaxPasses = 10;
    
    char buf[MAXLINE];
    int i;
    MNEMONIC *mne;
    
    int oldredo = -1;
    unsigned long oldwhy = 0;
    int oldeval = 0;
    
    addhashtable(Ops);
    pass = 1;

    if (ac < 2)
    {

fail:
    puts(dasm_id);
    puts("Copyright (c) 1988-2008 by various authors (see file AUTHORS).");
    puts("License GPLv2+: GNU GPL version 2 or later (see file COPYING).");
    puts("DASM is free software: you are free to change and redistribute it.");
    puts("There is ABSOLUTELY NO WARRANTY, to the extent permitted by law.");
    puts("");
    puts("Usage: dasm sourcefile [options]");
    puts("");
    puts("-f#      output format 1-3 (default 1)");
    puts("-oname   output file name (else a.out)");
    puts("-lname   list file name (else none generated)");
    puts("-Lname   list file, containing all passes");
    puts("-sname   symbol dump file name (else none generated)");
    puts("-v#      verboseness 0-4 (default 0)");
    puts("-d       debug mode (for developers)");
    puts("-Dsymbol              define symbol, set to 0");
    puts("-Dsymbol=expression   define symbol, set to expression");
    puts("-Msymbol=expression   define symbol using EQM (same as -D)");
    puts("-Idir    search directory for INCLUDE and INCBIN");
    puts("-p#      maximum number of passes");
    puts("-P#      maximum number of passes, with fewer checks");
    puts("-T#      symbol table sorting (default 0 = alphabetical, 1 = address/value)");
    puts("-E#      error format (default 0 = MS, 1 = Dillon, 2 = GNU)");
    puts("");
    puts("Report bugs to [email protected] please!");

    return ERROR_COMMAND_LINE;
    }
    
    for (i = 2; i < ac; ++i)
    {
        if ( ( av[i][0] == '-' ) || ( av[i][0] == '/' ) )
        {
            char *str = av[i]+2;
            switch(av[i][1])
            {
            /* TODO: need to improve option parsing and errors for it */
            case 'E':
                F_errorformat = atoi(str);
                if (F_errorformat < ERRORFORMAT_DEFAULT
                   || F_errorformat >= ERRORFORMAT_MAX )
                {
                    panic("Invalid error format for -E, must be 0, 1, 2");
                }
                break;

            case 'T':
                F_sortmode = atoi(str);
                if (F_sortmode < SORTMODE_DEFAULT
                   || F_sortmode >= SORTMODE_MAX )
                {
                    panic("Invalid sorting mode for -T option, must be 0 or 1");
                }
                /* TODO: refactor into regular configuration [phf] */
                *pbTableSort = (F_sortmode != SORTMODE_DEFAULT);
                break;
                
            case 'd':
                Xdebug = atoi(str) != 0;
                printf( "Debug trace %s\n", Xdebug ? "ON" : "OFF" );
                break;
                
            case 'M':
            case 'D':
                while (*str && *str != '=')
                    ++str;
                if (*str == '=')
                {
                    *str = 0;
                    ++str;
                }
                else
                {
                    str = "0";
                }
                Av[0] = av[i]+2;
                
                if (av[i][1] == 'M')
                    v_eqm(str, NULL);
                else
                    v_set(str, NULL);
                break;
                
            case 'f':   /*  F_format    */
                F_format = atoi(str);
                if (F_format < FORMAT_DEFAULT || F_format >= FORMAT_MAX )
                    panic("Illegal format specification");
                break;
                
            case 'o':   /*  F_outfile   */
                F_outfile = str;
nofile:
                if (*str == 0)
                    panic("-o Switch requires file name.");
                break;

            case 'L':
                F_ListAllPasses = 1;
                /* fall through to 'l' */

            case 'l':   /*  F_listfile  */
                F_listfile = str;
                goto nofile;
                
            case 'P':   /*  F_Passes   */
                bDoAllPasses = true;
                
                /* fall through to 'p' */
            case 'p':   /*  F_passes   */
                nMaxPasses = atoi(str);
                break;
                
            case 's':   /*  F_symfile   */
                F_symfile = str;
                goto nofile;
            case 'v':   /*  F_verbose   */
                F_verbose = atoi(str);
                break;
                
            case 'I':
                v_incdir(str, NULL);
                break;
                
            default:
                goto fail;
            }
            continue;
        }
        goto fail;
    }
    
    /*    INITIAL SEGMENT */
    
    {
        SEGMENT *seg = (SEGMENT *)permalloc(sizeof(SEGMENT));
        seg->name = strcpy(permalloc(sizeof(ISEGNAME)), ISEGNAME);
        seg->flags= seg->rflags = seg->initflags = seg->initrflags = SF_UNKNOWN;
        Csegment = Seglist = seg;
    }
    /*    TOP LEVEL IF    */
    {
        IFSTACK *ifs = (IFSTACK *)zmalloc(sizeof(IFSTACK));
        ifs->file = NULL;
        ifs->flags = IFF_BASE;
        ifs->acctrue = 1;
        ifs->xtrue  = 1;
        Ifstack = ifs;
    }
    
    
nextpass:
    
    
    if ( F_verbose )
    {
        puts("");
        printf("START OF PASS: %d\n", pass);
    }
    
    Localindex = Lastlocalindex = 0;
    
    Localdollarindex = Lastlocaldollarindex = 0;
    
    /*_fmode = 0x8000;*/
    FI_temp = fopen(F_outfile, "wb");
    /*_fmode = 0;*/
    Fisclear = 1;
    CheckSum = 0;
    if (FI_temp == NULL) {
        printf("Warning: Unable to [re]open '%s'\n", F_outfile);
        return ERROR_FILE_ERROR;
    }
    if (F_listfile) {

        FI_listfile = fopen(F_listfile,
            F_ListAllPasses && (pass > 1)? "a" : "w");

        if (FI_listfile == NULL) {
            printf("Warning: Unable to [re]open '%s'\n", F_listfile);
            return ERROR_FILE_ERROR;
        }
    }
    pushinclude(av[1]);
    
    while ( pIncfile )
    {
        for (;;) {
            const char *comment;
            if ( pIncfile->flags & INF_MACRO) {
                if ( pIncfile->strlist == NULL) {
                    Av[0] = "";
                    v_mexit(NULL, NULL);
                    continue;
                }
                strcpy(buf, pIncfile->strlist->buf);
                pIncfile->strlist = pIncfile->strlist->next;
            }
            else
            {
                if (fgets(buf, MAXLINE, pIncfile->fi) == NULL)
                    break;
            }
            
            if (Xdebug)
                printf("%08lx %s\n", (unsigned long) pIncfile, buf);
            
            comment = cleanup(buf, false);
            ++pIncfile->lineno;
            mne = parse(buf);
            
            if (Av[1][0])
            {
                if (mne)
                {
                    if ((mne->flags & MF_IF) || (Ifstack->xtrue && Ifstack->acctrue))
                        (*mne->vect)(Av[2], mne);
                }
                else
                {
                    if (Ifstack->xtrue && Ifstack->acctrue)
                        asmerr( ERROR_UNKNOWN_MNEMONIC, false, Av[1] );
                }
                
            }
            else
            {
                if (Ifstack->xtrue && Ifstack->acctrue)
                    programlabel();
            }
            
            if (F_listfile && ListMode)
                outlistfile(comment);
        }
        
        while (Reploop && Reploop->file == pIncfile)
            rmnode((void **)&Reploop, sizeof(REPLOOP));
        
        while (Ifstack->file == pIncfile)
            rmnode((void **)&Ifstack, sizeof(IFSTACK));
        
        fclose( pIncfile->fi );
        free( pIncfile->name );
        --Inclevel;
        rmnode((void **)&pIncfile, sizeof(INCFILE));
        
        if ( pIncfile )
        {
        /*
        if (F_verbose > 1)
        printf("back to: %s\n", Incfile->name);
            */
            if (F_listfile)
                fprintf(FI_listfile, "------- FILE %s\n", pIncfile->name);
        }
    }
    
    
    
    if ( F_verbose >= 1 )
        ShowSegments();
    
    if ( F_verbose >= 3 )
    {
        if ( !Redo || ( F_verbose == 4 ) )
            ShowSymbols( stdout, *pbTableSort );
        
        ShowUnresolvedSymbols();
    }
    
    closegenerate();
    fclose(FI_temp);
    if (FI_listfile)
        fclose(FI_listfile);
    
    if (Redo)
    {
        if ( !bDoAllPasses )
            if (Redo == oldredo && Redo_why == oldwhy && Redo_eval == oldeval)
            {
                ShowUnresolvedSymbols();
                return ERROR_NOT_RESOLVABLE;
            }
            
            oldredo = Redo;
            oldwhy = Redo_why;
            oldeval = Redo_eval;
            Redo = 0;
            Redo_why = 0;
            Redo_eval = 0;

            Redo_if <<= 1;
            ++pass;
            
            if ( bStopAtEnd )
            {
                printf("Unrecoverable error(s) in pass, aborting assembly!\n");
            }
            else if ( pass > nMaxPasses )
            {
                char sBuffer[64];
                sprintf( sBuffer, "%d", pass );
                return asmerr( ERROR_TOO_MANY_PASSES, false, sBuffer );
                
            }
            else
            {
                clearrefs();
                clearsegs();
                goto nextpass;
            }
    }
    
    return nError;
}