Esempio n. 1
0
int main()
{
unsigned long long int num,n,i,count,temp;
SCAN("%llu",&num);
while(num--)
{
	SCAN("%llu",&n);
	temp=S(n);
	count=temp*temp;
	count==n?(prime(temp)?PRINT("YES\n"):PRINT("NO\n")):PRINT("NO\n");
}
return 0;
}
Esempio n. 2
0
RIGHT_TYPE askForAdminRight(void){
  /*!  
   * \todo Perhaps also other rights for ui applications
   * 
   * \brief When an ui command has no right for the required application, admin password will be asked.
   */
  PRINT("You has no right for this command! Password for admin: ");
  char input[10] = {0};
    unsigned char hashvalue[HASH_SIZE];
    for(int j = 0; j < 3; j++){
      int input_size = SCAN("%s", input);
      /*!
       *  The hash value of the admin password is stored, so that, it is difficult for attacker to missuse the admin password
       *  \todo configure the hash value
       */
      //sha_construction.func((const unsigned char *)input, input_size, hashvalue);
      //if(0==memcmp(ADMIN_PASSWORD_HASH, hashvalue, sha_construction.size)){
      // TODO change admin password hash value
      if(0==memcmp(input, ADMIN_PASSWORD_HASH, 1)){
        return ADMIN_RIGHT;
      }else{
  PRINT("Password error! Try again %d/3: ",j+1);
        
      }
  }
  return NO_RIGHT;
}
Esempio n. 3
0
/* >> TOK_STRING | TOK_INTEGER | TOK_BOOLEAN | TOK_KEYWORD | '{' */
static int parse_operand (section_t **section,scan_t *sc,char **keyword)
{
   int result;

   SCAN();
   if (!result)
	 {
		parse_error (sc,"operand",0);
		return (ERR);
	 }

   if (result == '{') return (parse_array_or_section (section,sc,keyword));

   if (result == TOK_STRING || result == TOK_INTEGER || result == TOK_BOOLEAN || result == TOK_KEYWORD)
	 {
		stmt_t *nw;

		if ((nw = stmt_init (keyword,result)) == NULL)
		  return (ERR);

		if (stmt_add (nw,sc) < 0)
		  {
			 stmt_destroy (&nw);
			 return (ERR);
		  }

		stmt_save (*section,&nw);

		return (OK);
	 }

   parse_error (sc,"TOK_STRING, TOK_INTEGER, TOK_BOOLEAN, TOK_ENUM, or '{'",result);
   return (ERR);
}
Esempio n. 4
0
static int parse_section (section_t **section,scan_t *sc,char **lookahead)
{
   int result = OK;
   if (lookahead != NULL)
	 {
		result = parse_assignment (section,sc,lookahead,SECTION_START);
		while (result == OK)
		  {
			 SCAN();
			 if (result == '}') return (OK);
			 if (result != TOK_KEYWORD)
			   {
				  parse_error (sc,"'}', or TOK_KEYWORD",result);
				  return (ERR);
			   }
			 result = parse_assignment (section,sc,&sc->token.keyword,SECTION_END);
			 if (result == FIN)
			   {
				  parse_error (sc,"'}'",result);
				  return (ERR);
			   }
		  }
	 }
   else while (result == OK) result = parse_assignment (section,sc,NULL,0);
   return (result);
}
Esempio n. 5
0
static int
t2 (void)
{
  int result = 0;
  int n;
  long N;
  int retval;
#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
  VAR = -1; \
  retval = sscanf (INPUT, FORMAT, &VAR); \
  printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
	  INPUT, FORMAT, retval, (long int) VAR); \
  result |= retval != EXP_RES || VAR != EXP_VAL

  SCAN ("12345", "%ld", N, 1, 12345);
  SCAN ("12345", "%llllld", N, 0, -1);
  SCAN ("12345", "%LLLLLd", N, 0, -1);
  SCAN ("test ", "%*s%n",  n, 0, 4);
  SCAN ("test ", "%2*s%n",  n, 0, -1);
  SCAN ("12 ",   "%l2d",  n, 0, -1);
  SCAN ("12 ",   "%2ld",  N, 1, 12);

  n = -1;
  N = -1;
  retval = sscanf ("1 1", "%d %Z", &n, &N);
  printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
	  retval, n, N); \
  result |= retval != 1 || n != 1 || N != -1;

  return result;
}
Esempio n. 6
0
void main(void)
{
   PASSWORD();           	//Identication ROUTING
   Dsta();               	//Splesh Screen
   SCAN();               	//Animation ROUTING for LOADING
   clrscr();             	//Clear the screen
   Window(1,1,80,25,LIGHTGRAY); //CREATE LIGHT GRAY screen
   status_bar();         	//CREAT Status Bar
   Window(1,1,80,23,1);  	//CREAT Foure Ground Window
   MAINMENU(1);          	//CALLING Mainmenu_ROUTING
}
Esempio n. 7
0
int main()
{
	int a,b,i,count=0,arr[25000],var,temp,x;
	int sum=0;
	SCAN("%d",&a);
	SCAN("%d",&b);
	temp=a;
	while(temp)
	{
		arr[count++]=temp%10;
		temp/=10;
	}
    temp=0;
	for(i=1;i<b;i++)
	{
		var=0;
		while(var<count)
		{
			x=arr[var]*a+temp;
			arr[var]=x%10;
			temp=x/10;
			var++;
		}
		while(temp)
		{
			arr[count++]=temp%10;
			temp=temp/10;
		}
	}
	for(i=count-1;i>=0;i--)
	{
		PRINT("%d",arr[i]);
		sum+=arr[i];
	}
	PRINT("\n%d",sum);
 
return 0;
}
Esempio n. 8
0
File: test.c Progetto: aklt/commas
int main(int argc, char **argv) {
    int opt;
    char buffer[1024];
    char inputFilename[256] = "-\0";
    FILE *argInput = stdin;
    size_t argChunkSize = 1;
    size_t haveRead;

    STRUCT_T *c1 = NEW(1, print_field, print_record_end, print_error);

    while ((opt = getopt(argc, argv, "s:i:h")) != -1) {

        switch (opt) {
        case 's':
            argChunkSize = atoi(optarg);
            break;
        case 'i':
            if (strlen(optarg) > 1 || strncmp(optarg, "-", 1) != 0) {
                strncpy(inputFilename, optarg, strlen(optarg));
                argInput = fopen(inputFilename, "r");
                if (!argInput) {
                    printf("Could not open file: %s\n", inputFilename);
                    exit(1);
                }
            }
            break;
        case 'h':
            printf("Usage: test1 -s <N>        Chunk size\n"
                   "             -i <filename> Input file\n"
                   "             -h            Show help\n");
            exit(0);
            break;
        default:
            printf("Unknown arg %s\n", optarg);
        }
    }

    while ((haveRead = fread(buffer, 1, argChunkSize, argInput)) > 0) {
        buffer[haveRead] = '\0';
        /*fprintf(stderr, "Read %d %s\n", haveRead, buffer);*/
        SCAN(c1, buffer, haveRead);
    }
    FREE(c1);
    return 0;
}
Esempio n. 9
0
static int
t2 (void)
{
  int result = 0;
  int n;
  long N;
  int retval;
#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
  VAR = -1; \
  retval = sscanf (INPUT, FORMAT, &VAR); \
  printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
	  INPUT, FORMAT, retval, (long int) VAR); \
  result |= retval != EXP_RES || VAR != EXP_VAL

  /* This function is testing corner cases of the scanf format string,
     so they do not all conform to -Wformat's expectations.  */
  DIAG_PUSH_NEEDS_COMMENT;
  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat-extra-args");

  SCAN ("12345", "%ld", N, 1, 12345);
  SCAN ("12345", "%llllld", N, 0, -1);
  SCAN ("12345", "%LLLLLd", N, 0, -1);
  SCAN ("test ", "%*s%n",  n, 0, 4);
  SCAN ("test ", "%2*s%n",  n, 0, -1);
  SCAN ("12 ",   "%l2d",  n, 0, -1);
  SCAN ("12 ",   "%2ld",  N, 1, 12);

  n = -1;
  N = -1;
  retval = sscanf ("1 1", "%d %Z", &n, &N);
  printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
	  retval, n, N); \
  result |= retval != 1 || n != 1 || N != -1;

  DIAG_POP_NEEDS_COMMENT;

  return result;
}
Esempio n. 10
0
int main()
{

#ifdef DEBUG
	fp = fopen("test.txt","r");
#endif

	int figure = 0;
	
	point* buffer;
	int num_of_points;
	
	int i , j;

	double area;
	
	buffer = (point*)malloc(sizeof(point) * 1003 );

	SCAN("%d",&num_of_points);
	
	while( num_of_points )
	{
		
		figure++;

		if( figure != 1 )
			printf("\n");

		for( i = 0 ; i < num_of_points ; i++ )
		{
			SCAN("%lf %lf" , &buffer[i].x , &buffer[i].y );
		}

		if( num_of_points < 3 )
		{
			printf("Figure %d: Impossible\n" , figure );
			goto next;
		}
		

		buffer[i].x = buffer[0].x;
		buffer[i].y = buffer[0].y;

		for( i = 0 ; i < num_of_points ; i++ )
		{
			for( j = i + 2; j < num_of_points ; j++ )
			{
				if( i == 0 && j == num_of_points - 1 )
					continue;
				if( is_crossed( buffer , i , j ) )
				{
					printf("Figure %d: Impossible\n" , figure );
					goto next;
				}
			}
		}

		area = calculate_area( buffer , num_of_points ) ;
		if( area  <  0.001 )
			printf("Figure %d: Impossible\n" , figure );
		else
			printf("Figure %d: %.2lf\n" , figure , area );

		
next:
		SCAN( "%d" , &num_of_points );
	}

	return 0;
}
/* Gateway of LEMIRE_ND_MINENGINE */
void mexFunction(int nlhs, mxArray *plhs[],
        int nrhs, const mxArray *prhs[]) {
    
    mxClassID ClassID;
    
    /* pointer to the index array */
    double *idx, *minidx;
    /* Data pointers, which one are used depends on the class of A */
    double *adouble, *valdouble;
    float *asingle, *valsingle;
    int64 *aint64, *valint64;
    int32 *aint32, *valint32;
    int16 *aint16, *valint16;
    int08 *aint08, *valint08;
    uint64 *auint64, *valuint64;
    uint32 *auint32, *valuint32;
    uint16 *auint16, *valuint16;
    uint08 *auint08, *valuint08;

    mwSize i, pleft, n, window;
    mwSize imax, margin, linidx;
    int left, lstart, size;
    mwSize *Wedge; /* wedge */
    int nWedge; /* wedge number of elements (0 is empty wedge) */
    int Wedgefirst, Wedgelast; /* Indices of two ends of the wedge */
    int shape;
    
    mwSize p, q, j, k;
    mwIndex stepA, stepMinMax;
    const mwSize* dimA;
    mwSize dimOut[3];
    
    void *adata, *valdata;
    double *idxdata, *minidxdata;
    
    /* Check number of arguments */
    if (nrhs!=4)
        mexErrMsgTxt("LEMIRE_ND_MINENGINE: four arguments are required.");
    
     /* Get the shape */
    shape = (int)mxGetScalar(SHAPE);
    
    /* Get class of input matrix A */
    ClassID = mxGetClassID(A);
    
    if (mxGetClassID(IDX) != mxDOUBLE_CLASS)
        mexErrMsgTxt("LEMIRE_ND_MINENGINE: idx must be double.");
    
    /* Do not support on sparse */
    if (mxIsSparse(A))
        mexErrMsgTxt("LEMIRE_ND_MINENGINE: First input A must be full.");       
    
    /* Get the number of elements of A */
    /* Get the size, MUST BE two or three, no check */
    dimA = mxGetDimensions(A);
    p = dimA[0];
    n = dimA[1];
    if (mxGetNumberOfDimensions(A)<3)
        q = 1; /* third dimension is singleton */
    else
        q = dimA[2];
   
    /* Window input must be double */
    if (mxGetClassID(WINDOW)!=mxDOUBLE_CLASS)
        mexErrMsgTxt("LEMIRE_ND_MINENGINE: Second input WINDOW must be double.");
    
    /* Get the window size, cast it in mwSize */
    window = (mwSize)(*mxGetPr(WINDOW));
    margin = window-1;
    
    if (window<1) /* Check if it's valid */
        mexErrMsgTxt("LEMIRE_ND_MINENGINE: windows must be 1 or greater.");   
    if (window>n || window>MAXINT)
        mexErrMsgTxt("LEMIRE_ND_MINENGINE: windows larger than data length.");
    
    /* Allocate wedges buffers for L and U, each is size (window+1) */
    size = (int)(window+1);
    Wedge = mxMalloc(size*sizeof(mwSize));
    if (Wedge==NULL) mexErrMsgTxt("LEMIRE_ND_MINENGINE: out of memory.");
    
    /* This parameters configure for three cases:
     * - full scan (minimum 1-element intersecting with window), or
     * - same scan (output has the same size as input)
     * - valid scan (full overlapping with window) */ 
    if (shape==FULL_SHAPE) {
        dimOut[1] = n+margin;
        lstart = -(int)(margin);
    } else if (shape==SAME_SHAPE) {
        dimOut[1] = n;
        lstart = -(int)(margin/2);
    } else { /* if (shape==VALID_SHAPE) */
        dimOut[1] = n-margin;
        lstart = 0;
    }
    
    /* The last index to be scanned */
    imax = (dimOut[1] + margin) + lstart;
    
    /* Create output arrays */
    dimOut[0] = p;
    dimOut[2] = q;

    MINVAL = mxCreateNumericArray(3, dimOut, ClassID, mxREAL);
    MINIDX = mxCreateNumericArray(3, dimOut, mxDOUBLE_CLASS, mxREAL); 
    /* Check if allocation is succeeded */
    if ((MINVAL==NULL) || (MINIDX==NULL))
         mexErrMsgTxt("LEMIRE_ND_MINENGINE: out of memory.");    
      
    /* Jump step of the third dimension */
    stepA = p*n; /* for A */
    stepMinMax = p*dimOut[1]; /* step for output */
    
    /* Get data pointers */
    adata = mxGetData(A);
    idxdata = mxGetPr(IDX); 
    valdata = mxGetData(MINVAL);
    minidxdata = mxGetPr(MINIDX);
        
    /* Call the engine depending on ClassID */
    switch (ClassID) {
        case mxDOUBLE_CLASS:
            SCAN(adouble, valdouble, double);
            break;
        case mxSINGLE_CLASS:
            SCAN(asingle, valsingle, float);
            break;
        case mxINT64_CLASS:
            SCAN(aint64, valint64, int64);
            break;
        case mxUINT64_CLASS:
            SCAN(auint64, valuint64, uint64);
            break;
        case mxINT32_CLASS:
            SCAN(aint32, valint32, int32);
            break;
        case mxUINT32_CLASS:
            SCAN(auint32, valuint32, uint32);
            break;
        case mxCHAR_CLASS:
            SCAN(auint16, valuint16, uint16);
            break;
        case mxINT16_CLASS:
            SCAN(aint16, valint16, int16);
            break;
        case mxUINT16_CLASS:
            SCAN(auint16, valuint16, uint16);
            break;
        case mxLOGICAL_CLASS:
            SCAN(auint08, valuint08, uint08);
            break;
        case mxINT8_CLASS:
            SCAN(aint08, valint08, int08);
            break;
        case mxUINT8_CLASS:
            SCAN(auint08, valuint08, uint08);
            break;
        default:
            mexErrMsgTxt("LEMIRE_ND_MINENGINE: Class not supported.");
    } /* switch */
    
    /* Free the buffer */
    mxFree(Wedge);
    
    return;
    
} /* Gateway LEMIRE_ND_MINENGINE */
Esempio n. 12
0
void loop(void)
{
    char s[2048];
    char file[256];
    int num;

    for (;;)
    {
        if (!fgets(s, 2048, stdin))
        {
            Sleep( 100 );
            continue;
        }
        if (SCAN("uci"))
        {
            printf("id name Irina %s\n", VERSION);
            printf("id author Lucas Monge\n");
            printf("option name Hash type spin min 2 max 1024 default 32");
            printf("option name Personality type combo default Irina var Irina var Steven var Monkey var Donkey var Bull var Wolf var Lion var Rat var Snake var Material var Random var Capture var Advance\n");
            printf("option name Min Time type spin default 0 min 0 max 99\n");
            printf("option name Max Time type spin default 0 min 0 max 99\n");
            printf("uciok\n");
        }
        else if (SCAN("isready"))
        {
            printf("readyok\n");
        }
        else if (SCAN("stop"))
        {
            continue;
        }
        else if (SCAN("quit"))
        {
            break;
        }
        else if (SCAN("fen"))
        {
            board_fen(s);
            printf("%s\n", s);
        }
        else if (SCAN("test"))
        {
            test();
        }
        else if (SCAN("perft file "))
        {
            strcpy(file, s+11);
            strip(file);
            perft_file( file );
        }
        else if (SCAN("perft"))
        {
            num = scan_int(s,"perft");
            perft( num );
        }
        else if (SCAN("ucinewgame"))
        {
            continue;
        }
        else if (SCAN("position"))
        {
            set_position(s);
        }
        else if (SCAN("go"))
        {
            go(s);
        }
        else if (SCAN("setoption name"))
        {
            set_option(s);

        }
    }
}
Esempio n. 13
0
/* >> TOK_KEYWORD '=' operand */
static int parse_assignment (section_t **section,scan_t *sc,char **lookahead,int why)
{
   int result;
   char *keyword;
   stmt_t *stmt = (*section)->stmt;

   /*
	* wtf is lookahead and why don't you parse TOK_KEYWORD '=' when it's not
	* NULL, I hear you say (;
	*
	* The reason for this hack is because if we parse a section (i.e. not the main
	* section), we've already looked at the keyword and the '=' sign (it's the only
	* way to distinguish between an array of enumerations and a section, so we need
	* to pass this information along and make this one exception.
	*
	* There is another instance where we need to peek at the next token and that is
	* to look for the '}' at the end of nested sections. We use why to distinguish
	* between the two cases.
	*
	* See parse_array_or_section() for more details.
	*/

   if (lookahead == NULL)
	 {
		SCAN();
		if (!result) return (FIN);
		if (result != TOK_KEYWORD)
		  {
			 parse_error (sc,"TOK_KEYWORD",result);
			 return (ERR);
		  }
		keyword = sc->token.keyword;
	 }
   else keyword = *lookahead;

   if (stmt != NULL)
	 do
	   {
		  if (!strcmp (stmt->name,keyword))
			{
			   log_printf (LOG_ERROR,"Parse error on line %d: Duplicate keyword: %s\n",sc->line,keyword);
			   mem_free (keyword);
			   return (ERR);
			}
		  stmt = stmt->next;
	   }
     while (stmt != (*section)->stmt);

   if (lookahead == NULL || why != SECTION_START)
	 {
		/* we can't use SCAN() here since we need to free keyword */
		if ((result = scan (sc)) < 0)
		  {
			 mem_free (keyword);
			 return (ERR);
		  }

		if (result != '=')
		  {
			 parse_error (sc,"'='",result);
			 mem_free (keyword);
			 return (ERR);
		  }
	 }

   result = parse_operand (section,sc,&keyword);

   if (result != OK) return (ERR);

   return (result);
}
Esempio n. 14
0
/*
 * value = TOK_STRING | TOK_INTEGER | TOK_BOOLEAN | TOK_KEYWORD
 * >> value (',' value)* '}'
 */
static int parse_array_or_section (section_t **section,scan_t *sc,char **keyword)
{
   int result,saved = 0;
   stmt_t *nw = NULL;

   SCAN();

   if (result == TOK_KEYWORD)
	 {
		char *tmp = sc->token.keyword;

		if ((result = scan (sc)) < 0)
		  {
			 mem_free (tmp);
			 return (ERR);
		  }

		saved = result;

		if (result == '=')
		  {
			 if ((*section)->child == NULL)
			   {
				  if (((*section)->child = (section_t **) mem_alloc (sizeof (section_t *))) == NULL)
					{
out_of_memory:
					   log_printf (LOG_ERROR,"Out of memory\n");
					   mem_free (tmp);
					   return (ERR);
					}

				  if (((*section)->child[0] = (section_t *) mem_alloc (sizeof (section_t))) == NULL)
					{
					   mem_free ((*section)->child);
					   (*section)->child = NULL;
					   goto out_of_memory;
					}
			   }
			 else
			   {
				  section_t **ptr;

				  if ((ptr = (section_t **) mem_realloc ((*section)->child,((*section)->n + 1) * sizeof (section_t *))) == NULL)
					goto out_of_memory;

				  (*section)->child = ptr;

				  if (((*section)->child[(*section)->n] = (section_t *) mem_alloc (sizeof (section_t))) == NULL)
					goto out_of_memory;
			   }

			 (*section)->child[(*section)->n]->n = 0;
			 (*section)->child[(*section)->n]->name = *keyword;
			 (*section)->child[(*section)->n]->stmt = NULL;
			 (*section)->child[(*section)->n]->child = NULL;

			 ((*section)->n)++;

			 return (parse_section (&(*section)->child[(*section)->n - 1],sc,&tmp));
		  }

		result = TOK_KEYWORD;
		sc->token.keyword = tmp;
	 }

   if (result != TOK_STRING && result != TOK_INTEGER && result != TOK_BOOLEAN && result != TOK_KEYWORD)
	 {
		mem_free (*keyword);
missing_value:
		parse_error (sc,"TOK_STRING, TOK_INTEGER, TOK_BOOLEAN, or TOK_ENUM",result);
		goto error;
	 }

   if ((nw = stmt_init (keyword,result)) == NULL)
	 {
unable_to_add:
		if (result == TOK_STRING)
		  mem_free (sc->token.string);
		else if (result == TOK_KEYWORD)
		  mem_free (sc->token.keyword);
		goto error;
	 }

   if (stmt_add (nw,sc) < 0)
	 goto unable_to_add;

   if (result == TOK_KEYWORD)
	 result = saved;
   else if ((result = scan (sc)) < 0)
	 goto error;

   while (result == ',')
	 {
		if ((result = scan (sc)) < 0) goto error;

		if (result != TOK_STRING && result != TOK_INTEGER && result != TOK_BOOLEAN && result != TOK_KEYWORD)
		  goto missing_value;

		if (result != nw->type && (result != TOK_KEYWORD || nw->type != TOK_ENUM))
		  {
			 type_mismatch (sc,nw->type,result);
			 goto error;
		  }

		if (stmt_add (nw,sc) < 0)
		  goto unable_to_add;

		if ((result = scan (sc)) < 0) goto error;
	 }

   if (result != '}')
	 {
		parse_error (sc,"'}'",result);
		goto error;
	 }

   stmt_save (*section,&nw);

   return (OK);

error:
   if (nw != NULL) stmt_destroy (&nw);
   return (ERR);
}
Esempio n. 15
0
int
main()	{
	int	status = 0;		/* exit status to be returned */

    OPENTEST();
	
	/* <stdint.h> features: */

	fprintf(outfile,"CHAR_BIT=%u\n", (unsigned)CHAR_BIT );
	fprintf(outfile,"sizeof(char)=%u\n", (unsigned)sizeof(char));	/* s.b. 1 */
	fprintf(outfile,"sizeof(short)=%u\n", (unsigned)sizeof(short));
	fprintf(outfile,"sizeof(int)=%u\n", (unsigned)sizeof(int));
	fprintf(outfile,"sizeof(long)=%u\n", (unsigned)sizeof(long));
#ifdef	__Q8_QT
	fprintf(outfile,"sizeof(long long)=%u\n", (unsigned)sizeof(__Q8_QT));
#else
	fprintf(outfile,"*** long long isn't defined ***\n");
#endif
	fprintf(outfile,"sizeof(intmax_t)=%u\n", (unsigned)sizeof(intmax_t));
	fprintf(outfile,"sizeof(ptrdiff_t)=%u\n", (unsigned)sizeof(ptrdiff_t));
	fprintf(outfile,"sizeof(size_t)=%u\n", (unsigned)sizeof(size_t));
	fprintf(outfile,"sizeof(sig_atomic_t)=%u\n", (unsigned)sizeof(sig_atomic_t));
	fprintf(outfile,"sizeof(wchar_t)=%u\n", (unsigned)sizeof(wchar_t));
#if	defined(WINT_MAX) || __STDC_VERSION__ >= 199901
	fprintf(outfile,"sizeof(wint_t)=%u\n", (unsigned)sizeof(wint_t));
#else
	fprintf(outfile,"*** wint_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INT8_MAX
	fprintf(outfile,"sizeof(int8_t)=%u\n", (unsigned)sizeof(int8_t));
	fprintf(outfile,"sizeof(uint8_t)=%u\n", (unsigned)sizeof(uint8_t));
#endif
#ifdef	INT9_MAX
	fprintf(outfile,"sizeof(int9_t)=%u\n", (unsigned)sizeof(int9_t));
	fprintf(outfile,"sizeof(uint9_t)=%u\n", (unsigned)sizeof(uint9_t));
#endif
#ifdef	INT12_MAX
	fprintf(outfile,"sizeof(int12_t)=%u\n", (unsigned)sizeof(int12_t));
	fprintf(outfile,"sizeof(uint12_t)=%u\n", (unsigned)sizeof(uint12_t));
#endif
#ifdef	INT16_MAX
	fprintf(outfile,"sizeof(int16_t)=%u\n", (unsigned)sizeof(int16_t));
	fprintf(outfile,"sizeof(uint16_t)=%u\n", (unsigned)sizeof(uint16_t));
#endif
#ifdef	INT18_MAX
	fprintf(outfile,"sizeof(int18_t)=%u\n", (unsigned)sizeof(int18_t));
	fprintf(outfile,"sizeof(uint18_t)=%u\n", (unsigned)sizeof(uint18_t));
#endif
#ifdef	INT24_MAX
	fprintf(outfile,"sizeof(int24_t)=%u\n", (unsigned)sizeof(int24_t));
	fprintf(outfile,"sizeof(uint24_t)=%u\n", (unsigned)sizeof(uint24_t));
#endif
#ifdef	INT32_MAX
	fprintf(outfile,"sizeof(int32_t)=%u\n", (unsigned)sizeof(int32_t));
	fprintf(outfile,"sizeof(uint32_t)=%u\n", (unsigned)sizeof(uint32_t));
#endif
#ifdef	INT36_MAX
	fprintf(outfile,"sizeof(int36_t)=%u\n", (unsigned)sizeof(int36_t));
	fprintf(outfile,"sizeof(uint36_t)=%u\n", (unsigned)sizeof(uint36_t));
#endif
#ifdef	INT40_MAX
	fprintf(outfile,"sizeof(int40_t)=%u\n", (unsigned)sizeof(int40_t));
	fprintf(outfile,"sizeof(uint40_t)=%u\n", (unsigned)sizeof(uint40_t));
#endif
#ifdef	INT48_MAX
	fprintf(outfile,"sizeof(int48_t)=%u\n", (unsigned)sizeof(int48_t));
	fprintf(outfile,"sizeof(uint48_t)=%u\n", (unsigned)sizeof(uint48_t));
#endif
#ifdef	INT60_MAX
	fprintf(outfile,"sizeof(int60_t)=%u\n", (unsigned)sizeof(int60_t));
	fprintf(outfile,"sizeof(uint60_t)=%u\n", (unsigned)sizeof(uint60_t));
#endif
#ifdef	INT64_MAX
	fprintf(outfile,"sizeof(int64_t)=%u\n", (unsigned)sizeof(int64_t));
	fprintf(outfile,"sizeof(uint64_t)=%u\n", (unsigned)sizeof(uint64_t));
#endif
#ifdef	INT72_MAX
	fprintf(outfile,"sizeof(int72_t)=%u\n", (unsigned)sizeof(int72_t));
	fprintf(outfile,"sizeof(uint72_t)=%u\n", (unsigned)sizeof(uint72_t));
#endif
#ifdef	INT128_MAX
	fprintf(outfile,"sizeof(int128_t)=%u\n", (unsigned)sizeof(int128_t));
	fprintf(outfile,"sizeof(uint128_t)=%u\n", (unsigned)sizeof(uint128_t));
#endif
	fprintf(outfile,"sizeof(int_least8_t)=%u\n", (unsigned)sizeof(int_least8_t));
	fprintf(outfile,"sizeof(uint_least8_t)=%u\n", (unsigned)sizeof(uint_least8_t));
	fprintf(outfile,"sizeof(int_least16_t)=%u\n", (unsigned)sizeof(int_least16_t));
	fprintf(outfile,"sizeof(uint_least16_t)=%u\n", (unsigned)sizeof(uint_least16_t));
	fprintf(outfile,"sizeof(int_least32_t)=%u\n", (unsigned)sizeof(int_least32_t));
	fprintf(outfile,"sizeof(uint_least32_t)=%u\n", (unsigned)sizeof(uint_least32_t));
#ifdef	INT_LEAST64_MAX
	fprintf(outfile,"sizeof(int_least64_t)=%u\n", (unsigned)sizeof(int_least64_t));
	fprintf(outfile,"sizeof(uint_least64_t)=%u\n", (unsigned)sizeof(uint_least64_t));
#else
	fprintf(outfile,"*** uint_least64_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INT_LEAST128_MAX
	fprintf(outfile,"sizeof(int_least128_t)=%u\n", (unsigned)sizeof(int_least128_t));
	fprintf(outfile,"sizeof(uint_least128_t)=%u\n",
		(unsigned)sizeof(uint_least128_t));
#endif
	fprintf(outfile,"sizeof(int_fast8_t)=%u\n", (unsigned)sizeof(int_fast8_t));
	fprintf(outfile,"sizeof(uint_fast8_t)=%u\n", (unsigned)sizeof(uint_fast8_t));
	fprintf(outfile,"sizeof(int_fast16_t)=%u\n", (unsigned)sizeof(int_fast16_t));
	fprintf(outfile,"sizeof(uint_fast16_t)=%u\n", (unsigned)sizeof(uint_fast16_t));
	fprintf(outfile,"sizeof(int_fast32_t)=%u\n", (unsigned)sizeof(int_fast32_t));
	fprintf(outfile,"sizeof(uint_fast32_t)=%u\n", (unsigned)sizeof(uint_fast32_t));
#ifdef	INT_FAST64_MAX
	fprintf(outfile,"sizeof(int_fast64_t)=%u\n", (unsigned)sizeof(int_fast64_t));
	fprintf(outfile,"sizeof(uint_fast64_t)=%u\n", (unsigned)sizeof(uint_fast64_t));
#else
	fprintf(outfile,"*** int_fast64_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INT_FAST128_MAX
	fprintf(outfile,"sizeof(int_fast128_t)=%u\n", (unsigned)sizeof(int_fast128_t));
	fprintf(outfile,"sizeof(uint_fast128_t)=%u\n", (unsigned)sizeof(uint_fast128_t));
#endif
#if	defined(INTPTR_MAX)
	fprintf(outfile,"sizeof(intptr_t)=%u\n", (unsigned)sizeof(intptr_t));
#if	defined(UINTPTR_MAX)
	fprintf(outfile,"sizeof(uintptr_t)=%u\n", (unsigned)sizeof(uintptr_t));
#else
	fprintf(outfile,"*** intptr_t is defined but uintptr_t isn't ***\n");
	status = EXIT_FAILURE;
#endif
#elif	defined(UINTPTR_MAX)
	fprintf(outfile,"sizeof(uintptr_t)=%u\n", (unsigned)sizeof(uintptr_t));
	fprintf(outfile,"*** uintptr_t is defined but intptr_t isn't ***\n");
	status = EXIT_FAILURE;
#else
	fprintf(outfile,"*** neither intptr_t nor uintptr_t is defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INTMAX_MAX
	fprintf(outfile,"sizeof(intmax_t)=%u\n", (unsigned)sizeof(intmax_t));
	fprintf(outfile,"sizeof(uintmax_t)=%u\n", (unsigned)sizeof(uintmax_t));
#else
	fprintf(outfile,"*** intmax_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif

#ifdef	INT8_MAX
	fprintf(outfile,"INT8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT8_MIN);
	fprintf(outfile,"INT8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT8_MAX);
	fprintf(outfile,"UINT8_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT8_MAX);
#endif
#ifdef	INT9_MAX
	fprintf(outfile,"INT9_MIN=%"PRIdMAX"\n", (__Q8_MT)INT9_MIN);
	fprintf(outfile,"INT9_MAX=%"PRIdMAX"\n", (__Q8_MT)INT9_MAX);
	fprintf(outfile,"UINT9_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT9_MAX);
#endif
#ifdef	INT12_MAX
	fprintf(outfile,"INT12_MIN=%"PRIdMAX"\n", (__Q8_MT)INT12_MIN);
	fprintf(outfile,"INT12_MAX=%"PRIdMAX"\n", (__Q8_MT)INT12_MAX);
	fprintf(outfile,"UINT12_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT12_MAX);
#endif
#ifdef	INT16_MAX
	fprintf(outfile,"INT16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT16_MIN);
	fprintf(outfile,"INT16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT16_MAX);
	fprintf(outfile,"UINT16_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT16_MAX);
#endif
#ifdef	INT18_MAX
	fprintf(outfile,"INT18_MIN=%"PRIdMAX"\n", (__Q8_MT)INT18_MIN);
	fprintf(outfile,"INT18_MAX=%"PRIdMAX"\n", (__Q8_MT)INT18_MAX);
	fprintf(outfile,"UINT18_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT18_MAX);
#endif
#ifdef	INT24_MAX
	fprintf(outfile,"INT24_MIN=%"PRIdMAX"\n", (__Q8_MT)INT24_MIN);
	fprintf(outfile,"INT24_MAX=%"PRIdMAX"\n", (__Q8_MT)INT24_MAX);
	fprintf(outfile,"UINT24_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT24_MAX);
#endif
#ifdef	INT32_MAX
	fprintf(outfile,"INT32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT32_MIN);
	fprintf(outfile,"INT32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT32_MAX);
	fprintf(outfile,"UINT32_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT32_MAX);
#endif
#ifdef	INT36_MAX
	fprintf(outfile,"INT36_MIN=%"PRIdMAX"\n", (__Q8_MT)INT36_MIN);
	fprintf(outfile,"INT36_MAX=%"PRIdMAX"\n", (__Q8_MT)INT36_MAX);
	fprintf(outfile,"UINT36_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT36_MAX);
#endif
#ifdef	INT40_MAX
	fprintf(outfile,"INT40_MIN=%"PRIdMAX"\n", (__Q8_MT)INT40_MIN);
	fprintf(outfile,"INT40_MAX=%"PRIdMAX"\n", (__Q8_MT)INT40_MAX);
	fprintf(outfile,"UINT40_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT40_MAX);
#endif
#ifdef	INT48_MAX
	fprintf(outfile,"INT48_MIN=%"PRIdMAX"\n", (__Q8_MT)INT48_MIN);
	fprintf(outfile,"INT48_MAX=%"PRIdMAX"\n", (__Q8_MT)INT48_MAX);
	fprintf(outfile,"UINT48_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT48_MAX);
#endif
#ifdef	INT60_MAX
	fprintf(outfile,"INT60_MIN=%"PRIdMAX"\n", (__Q8_MT)INT60_MIN);
	fprintf(outfile,"INT60_MAX=%"PRIdMAX"\n", (__Q8_MT)INT60_MAX);
	fprintf(outfile,"UINT60_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT60_MAX);
#endif
#ifdef	INT64_MAX
	fprintf(outfile,"INT64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT64_MIN);
	fprintf(outfile,"INT64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT64_MAX);
	fprintf(outfile,"UINT64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT64_MAX);
#endif
#ifdef	INT72_MAX
	fprintf(outfile,"INT72_MIN=%"PRIdMAX"\n", (__Q8_MT)INT72_MIN);
	fprintf(outfile,"INT72_MAX=%"PRIdMAX"\n", (__Q8_MT)INT72_MAX);
	fprintf(outfile,"UINT72_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT72_MAX);
#endif
#ifdef	INT128_MAX
	fprintf(outfile,"INT128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT128_MIN);
	fprintf(outfile,"INT128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT128_MAX);
	fprintf(outfile,"UINT128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT128_MAX);
#endif
	fprintf(outfile,"INT_LEAST8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST8_MIN);
	fprintf(outfile,"INT_LEAST8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST8_MAX);
	fprintf(outfile,"UINT_LEAST8_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_LEAST8_MAX);
	fprintf(outfile,"INT_LEAST16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST16_MIN);
	fprintf(outfile,"INT_LEAST16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST16_MAX);
	fprintf(outfile,"UINT_LEAST16_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_LEAST16_MAX);
	fprintf(outfile,"INT_LEAST32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST32_MIN);
	fprintf(outfile,"INT_LEAST32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST32_MAX);
	fprintf(outfile,"UINT_LEAST32_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_LEAST32_MAX);
#ifdef	INT_LEAST64_MAX
	fprintf(outfile,"INT_LEAST64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST64_MIN);
	fprintf(outfile,"INT_LEAST64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST64_MAX);
	fprintf(outfile,"UINT_LEAST64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_LEAST64_MAX);
#endif
#ifdef	INT_LEAST128_MAX
	fprintf(outfile,"INT_LEAST128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST128_MIN);
	fprintf(outfile,"INT_LEAST128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST128_MAX);
	fprintf(outfile,"UINT_LEAST128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_LEAST128_MAX);
#endif
	fprintf(outfile,"INT_FAST8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST8_MIN);
	fprintf(outfile,"INT_FAST8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST8_MAX);
	fprintf(outfile,"UINT_FAST8_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_FAST8_MAX);
	fprintf(outfile,"INT_FAST16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST16_MIN);
	fprintf(outfile,"INT_FAST16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST16_MAX);
	fprintf(outfile,"UINT_FAST16_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_FAST16_MAX);
	fprintf(outfile,"INT_FAST32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST32_MIN);
	fprintf(outfile,"INT_FAST32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST32_MAX);
	fprintf(outfile,"UINT_FAST32_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_FAST32_MAX);
#ifdef	INT_FAST64_MAX
	fprintf(outfile,"INT_FAST64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST64_MIN);
	fprintf(outfile,"INT_FAST64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST64_MAX);
	fprintf(outfile,"UINT_FAST64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_FAST64_MAX);
#endif
#ifdef	INT_FAST128_MAX
	fprintf(outfile,"INT_FAST128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST128_MIN);
	fprintf(outfile,"INT_FAST128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST128_MAX);
	fprintf(outfile,"UINT_FAST128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_FAST128_MAX);
#endif
#ifdef	INTPTR_MAX
	fprintf(outfile,"INTPTR_MIN=%"PRIdMAX"\n", (__Q8_MT)INTPTR_MIN);
	fprintf(outfile,"INTPTR_MAX=%"PRIdMAX"\n", (__Q8_MT)INTPTR_MAX);
#endif
#ifdef	UINTPTR_MAX
	fprintf(outfile,"UINTPTR_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINTPTR_MAX);
#endif
#ifdef	INTMAX_MAX
	fprintf(outfile,"INTMAX_MIN=%"PRIdMAX"\n", (__Q8_MT)INTMAX_MIN);
	fprintf(outfile,"INTMAX_MAX=%"PRIdMAX"\n", (__Q8_MT)INTMAX_MAX);
	fprintf(outfile,"UINTMAX_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINTMAX_MAX);
#endif
#ifdef	PTRDIFF_MAX
	fprintf(outfile,"PTRDIFF_MIN=%"PRIdMAX"\n", (__Q8_MT)PTRDIFF_MIN);
	fprintf(outfile,"PTRDIFF_MAX=%"PRIdMAX"\n", (__Q8_MT)PTRDIFF_MAX);
#endif
#ifdef	SIG_ATOMIC_MAX
#if	SIG_ATOMIC_MIN < 0
	fprintf(outfile,"SIG_ATOMIC_MIN=%"PRIdMAX"\n", (__Q8_MT)SIG_ATOMIC_MIN);
	fprintf(outfile,"SIG_ATOMIC_MAX=%"PRIdMAX"\n", (__Q8_MT)SIG_ATOMIC_MAX);
#else
	fprintf(outfile,"SIG_ATOMIC_MIN=%"PRIuMAX"\n", (U__Q8_MT)SIG_ATOMIC_MIN);
	fprintf(outfile,"SIG_ATOMIC_MAX=%"PRIuMAX"\n", (U__Q8_MT)SIG_ATOMIC_MAX);
#endif
#endif
#ifdef	SIZE_MAX
	fprintf(outfile,"SIZE_MAX=%"PRIuMAX"\n", (U__Q8_MT)SIZE_MAX);
#endif

#ifdef	WCHAR_MAX
#if	WCHAR_MIN < 0
	fprintf(outfile,"WCHAR_MIN=%"PRIdMAX"\n", (__Q8_MT)WCHAR_MIN);
	fprintf(outfile,"WCHAR_MAX=%"PRIdMAX"\n", (__Q8_MT)WCHAR_MAX);
#else
	fprintf(outfile,"WCHAR_MIN=%"PRIuMAX"\n", (U__Q8_MT)WCHAR_MIN);
	fprintf(outfile,"WCHAR_MAX=%"PRIuMAX"\n", (U__Q8_MT)WCHAR_MAX);
#endif
#endif
#ifdef	WINT_MAX
#if	WINT_MIN < 0
	fprintf(outfile,"WINT_MIN=%"PRIdMAX"\n", (__Q8_MT)WINT_MIN);
	fprintf(outfile,"WINT_MAX=%"PRIdMAX"\n", (__Q8_MT)WINT_MAX);
#else
	fprintf(outfile,"WINT_MIN=%"PRIuMAX"\n", (U__Q8_MT)WINT_MIN);
	fprintf(outfile,"WINT_MAX=%"PRIuMAX"\n", (U__Q8_MT)WINT_MAX);
#endif
#endif

	/*
		7.18.4	Macros for integer constants
	*/

	/* INTn_C for n=8 and 16 were at one point unimplementable
	   on most platforms, so they're treated as "optional": */
#ifdef	INT8_C
	if ( INT8_C(-123) != -123 )
		fprintf(outfile,"*** INT8_C(-123) produced %"PRIdMAX" ***\n",
		       (__Q8_MT)INT8_C(-123)
		      );
	if ( UINT8_C(123) != 123 )
		fprintf(outfile,"*** UINT8_C(123) produced %"PRIuMAX" ***\n",
		       (U__Q8_MT)UINT8_C(123)
		      );
#endif
#ifdef	INT16_C
	if ( INT16_C(-12345) != -12345 )
		fprintf(outfile,"*** INT16_C(-12345) produced %"PRIdMAX" ***\n",
		       (__Q8_MT)INT16_C(-12345)
		      );
	if ( UINT16_C(12345) != 12345 )
		fprintf(outfile,"*** UINT16_C(12345) produced %"PRIuMAX" ***\n",
		       (U__Q8_MT)UINT16_C(12345)
		      );
#endif
	if ( INT32_C(-123456789) != -123456789 )
		fprintf(outfile,"*** INT32_C(-123456789) produced %"PRIdMAX" ***\n",
		       (__Q8_MT)INT32_C(-123456789)
		      );
	if ( UINT32_C(123456789) != 123456789 )
		fprintf(outfile,"*** UINT32_C(123456789) produced %"PRIuMAX" ***\n",
		       (U__Q8_MT)UINT32_C(123456789)
		      );
#ifdef	INT_LEAST64_MAX
	if ( INT64_C(-1234567890123456789) != -1234567890123456789 )
		fprintf(outfile,"*** INT64_C(-1234567890123456789) produced %"PRIdMAX
		       " ***\n",
		       (__Q8_MT)INT64_C(-1234567890123456789)
		      );
	if ( UINT64_C(1234567890123456789) != 1234567890123456789 )
		fprintf(outfile,"*** UINT64_C(1234567890123456789) produced %"PRIuMAX
		       " ***\n",
		       (U__Q8_MT)UINT64_C(1234567890123456789)
		      );
#endif
#ifdef	INTMAX_MAX
	if ( INTMAX_C(-1234567890123456789) != -1234567890123456789 )
		fprintf(outfile,"*** INTMAX_C(-1234567890123456789) produced %"PRIdMAX
		       " ***\n",
		       (__Q8_MT)INTMAX_C(-1234567890123456789)
		      );
	if ( UINTMAX_C(1234567890123456789) != 1234567890123456789 )
		fprintf(outfile,"*** UINTMAX_C(1234567890123456789) produced %"PRIuMAX
		       " ***\n",
		       (U__Q8_MT)UINTMAX_C(1234567890123456789)
		      );
#endif

	/* <inttypes.h> features: */

#if	__STDC_VERSION__ >= 199901
	fprintf(outfile,"sizeof(imaxdiv_t)=%u\n", (unsigned)sizeof(imaxdiv_t));
#endif

	/*
		7.8.1	Macros for format specifiers
	*/

	{
	/* scanf these strings */
	static const char	in_dn[] = "Z119bZ";
	static const char	in_dmo[] = "Z-0119bZ";
	static const char	in_dspx[] = "Z \t\n +0X119bZ";
	static const char	in_dsmx[] = "Z \t\n -0x119bZ";
	static const char	in_dsn[] = "Z \t\n 119bZ";
	static const char	in_dp[] = "Z+119bZ";
	static const char	in_dpx[] = "Z+0X119bz";

	/* sprintf into this */
	static char		buffer[1024];

#if 1

#define	SCAN(buf,fs,var,exp)	if ( sscanf(buf, "Z%" fs, &var) != 1 ) \
					{ \
					fprintf(outfile,"***%s=",fs, STR_SUB(fs) \
					       " failed ***\n" \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else if ( var != (exp) ) \
					{ \
					fprintf(outfile,"***%s=",fs,  STR_SUB(fs) \
					       " should be: " STR_SUB(exp) \
					       ", was: %" fs " ***\n", var \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else	/* for trailing semicolon */

#define	PRINT(fs,var,exp)	if ( sprintf(buffer, "%" fs, var ) <= 0 ) \
					{ \
					fprintf(outfile,"***%s=",fs, STR_SUB(fs) \
					       " failed ***\n" \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else if ( strcmp(buffer, STR_SUB(exp)) != 0 ) \
					{ \
					fprintf(outfile,"***%s=",fs,  STR_SUB(fs) \
					       " should be: " STR_SUB(exp) \
					       ", was: %s ***\n", buffer \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else	/* for trailing semicolon */

#else
								 
#define	SCAN(buf,fs,var,exp)
#define	PRINT(fs,var,exp)

#endif
								 
#ifdef	SCNo32

	SCAN(in_dn, SCNo32, int32, 9);

#endif
#ifdef	PRIo32
	PRINT(PRIo32, int32, 11);
#endif
	SCAN(in_dmo, SCNiLEAST16, intl16, -9);
	SCAN(in_dspx, SCNdLEAST16, intl16, 0);
	SCAN(in_dsmx, SCNiLEAST16, intl16, -4507);
	PRINT(PRIdLEAST16, intl16, -4507);
	PRINT(PRIiLEAST16, intl16, -4507);
	SCAN(in_dsn, SCNxLEAST16, uintl16, 4507);
	PRINT(PRIoLEAST16, uintl16, 10633);
	PRINT(PRIuLEAST16, uintl16, 4507);
	PRINT(PRIxLEAST16, uintl16, 119b);
	PRINT(PRIXLEAST16, uintl16, 119B);
	SCAN(in_dp, SCNxFAST16, uintf16, 4507);
	PRINT(PRIxFAST16, uintf16, 119b);
#ifdef	SCNdMAX
	SCAN(in_dp, SCNdMAX, intmax, 119);
#endif
#ifdef	PRIiMAX
	PRINT(PRIiMAX, intmax, 119);
#endif
#ifdef	SCNoMAX
	SCAN(in_dpx, SCNoMAX, uintmax, 0);
#endif
#ifdef	PRIxMAX
	PRINT(PRIxMAX, uintmax, 0);
#endif
	/* Obviously there should be a much larger battery of such tests. */
	}

#if	defined(INTMAX_MAX)		/* <inttypes.h> has C99 features */
	/*
		7.8.2	Functions for greatest-width integer types
	*/

	{
	static struct
		{
		intmax_t	input;
		intmax_t	expect;
		}	abs_data[] =
		{
#ifdef	INT8_MAX
	  { INT8_MAX,		INT8_MAX,   },
	  { -INT8_MAX,		INT8_MAX,   },
	 { 	UINT8_MAX,		UINT8_MAX,  },
#endif

#if 0
  
#ifdef	INT16_MAX
	 { 	INT16_MAX,		INT16_MAX,  },
	 { 	-INT16_MAX,		INT16_MAX,  },
	 { 	UINT16_MAX,		UINT16_MAX, },
#endif
#ifdef	INT32_MAX
	 { 	INT32_MAX,		INT32_MAX,  },
	 { 	-INT32_MAX,		INT32_MAX,  },
#ifdef	INT_LEAST64_MAX			/* else might support only 32 bits */
	 { 	UINT32_MAX,		UINT32_MAX, },
#endif
#endif
#ifdef	INT64_MAX
	 { 	INT64_MAX,		INT64_MAX,  },
	 { 	-INT64_MAX,		INT64_MAX,  },
#endif
	 { 	INT_LEAST8_MAX,		INT_LEAST8_MAX,      },
	 { 	-INT_LEAST8_MAX,	INT_LEAST8_MAX,      },
	 { 	UINT_LEAST8_MAX,	UINT_LEAST8_MAX,     },
	 { 	INT_LEAST16_MAX,	INT_LEAST16_MAX,     },
	 { 	-INT_LEAST16_MAX,	INT_LEAST16_MAX,     },
	 { 	UINT_LEAST16_MAX,	UINT_LEAST16_MAX,    },
	 { 	INT_LEAST32_MAX,	INT_LEAST32_MAX,     },
	 { 	-INT_LEAST32_MAX,	INT_LEAST32_MAX,     },
#ifdef	INT_LEAST64_MAX
	 { 	UINT_LEAST32_MAX,	UINT_LEAST32_MAX,    },
	 { 	INT_LEAST64_MAX,	INT_LEAST64_MAX,     },
	 { 	-INT_LEAST64_MAX,	INT_LEAST64_MAX,     },
#endif
	 { 	INT_FAST8_MAX,		INT_FAST8_MAX,       },
	 { 	-INT_FAST8_MAX,	INT_FAST8_MAX,           },
	 { 	UINT_FAST8_MAX,	UINT_FAST8_MAX,          },
	 { 	INT_FAST16_MAX,	INT_FAST16_MAX,          },
	 { 	-INT_FAST16_MAX,	INT_FAST16_MAX,      },
	 { 	UINT_FAST16_MAX,	UINT_FAST16_MAX,     },
	 { 	INT_FAST32_MAX,	INT_FAST32_MAX,          },
	 { 	-INT_FAST32_MAX,	INT_FAST32_MAX,      },
#ifdef	INT_FAST64_MAX
	 { 	UINT_FAST32_MAX,	UINT_FAST32_MAX,     },
	 { 	INT_FAST64_MAX,	INT_FAST64_MAX,          },
	 { 	-INT_FAST64_MAX,	INT_FAST64_MAX,      },
#endif
#ifdef	INTPTR_MAX
	 { 	INTPTR_MAX,		INTPTR_MAX,              },
	 { 	-INTPTR_MAX,		INTPTR_MAX,          },
#endif
#ifdef	UINTPTR_MAX
	 { 	UINTPTR_MAX,		UINTPTR_MAX,         },
#endif
	 { 	INTMAX_MAX,		INTMAX_MAX,              },
#ifdef	PTRDIFF_MAX
	 { 	PTRDIFF_MAX,		PTRDIFF_MAX,         },
#endif
#ifdef	SIG_ATOMIC_MAX
	 { 	SIG_ATOMIC_MAX,		SIG_ATOMIC_MAX,      },
#if	SIG_ATOMIC_MIN < 0
	 { 	-SIG_ATOMIC_MAX,	SIG_ATOMIC_MAX,      },
#endif
#endif
#ifdef	SIZE_MAX
	 { 	SIZE_MAX,		SIZE_MAX,                },
#endif
#ifdef	WCHAR_MAX
	 { 	WCHAR_MAX,		WCHAR_MAX,               },
#if	WCHAR_MIN < 0
	 { 	-WCHAR_MAX,		WCHAR_MAX,               },
#endif
#endif
#ifdef	WINT_MAX
	 { 	WINT_MAX,		WINT_MAX,                },
#if	WINT_MIN < 0
	 {  -WINT_MAX,		WINT_MAX,                },
#endif
#endif
	 { 	127,				127,                 },
	 { 	-127,				127,                 },
	 { 	128,				128,                 },
	 { 	-127-1,				128,                 },
	 { 	255,				255,                 },
	 { 	-256+1,				255,                 },
	 { 	256,				256,                 },
	 { 	-256,				256,                 },
	 { 	32767,				32767,               },
	 { 	-32767,				32767,               },
	 { 	32768,				32768,               },
	 { 	-32767-1,			32768,               },
	 { 	65535,				65535,               },
	 { 	-65536+1,			65535,               },
	 { 	65536,				65536,               },
	 { 	-65536,				65536,               },
	 { 	2147483647,			2147483647,          },
	 { 	-2147483647,			2147483647,      },
	 { 	2147483648,			2147483648,          },
	 { 	-2147483647-1,			2147483648,      },
#ifdef	INT_LEAST64_MAX			/* else might support only 32 bits */
	 { 	4294967295,			4294967295,          },
	 { 	-4294967296+1,			4294967295,      },
	 { 	4294967296,			4294967296,          },
	 { 	-4294967296,			4294967296,      },
	 { 	9223372036854775807,		9223372036854775807,    },
	 { 	-9223372036854775807,		9223372036854775807,    },
	 { 	1234567890123456789,		1234567890123456789,    },
	 { 	-1234567890123456789,		1234567890123456789,    },
#endif
	 { 	1,				1,                                  },
	 { 	-1,				1,                                  },
	 { 	2,				2,                                  },
	 { 	-2,				2,                                  },
	 { 	10,				10,                                 },
	 { 	-10,				10,                             },
	 { 	16,				16,                                 },
	 { 	-16,				16,                             },
#endif
		/* Other test cases can be added here. */
	 { 	0,		0	/* terminates the list */              },
		},	*adp = abs_data;

	do	{
		if ( (intmax = imaxabs(adp->input)) != adp->expect )
			{
			fprintf(outfile,"*** imaxabs(%"PRIdMAX") failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n",
			       adp->input, adp->expect, intmax
			      );
			status = EXIT_FAILURE;
			}
//		} while ( adp++->input != 0 );
		} while ( (adp++)->input != 0 );
	}

	{
	imaxdiv_t	result;
	static struct
		{
		intmax_t	numer;
		intmax_t	denom;
		intmax_t	exp_quot;
		intmax_t	exp_rem;
		}	div_data[] =
		{
	{	0, 1,				0, 0,   },
#if 0
	{	0, -1,				0, 0,   },
	{	0, 2,				0, 0,   },
	{	0, -2,				0, 0,   },
	{	0, 5,				0, 0,   },
	{	0, -5,				0, 0,   },
	{	1, 1,				1, 0,   },
	{	1, -1,				-1, 0,  },
	{	1, 2,				0, 1,   },
	{	1, -2,				0, 1,   },
	{	1, 5,				0, 1,   },
	{	1, -5,				0, 1,   },
	{	-1, 1,				-1, 0,  },
	{	-1, -1,				1, 0,   },
	{	-1, 2,				0, -1,  },
	{	-1, -2,				0, -1,  },
	{	-1, 5,				0, -1,  },
	{	-1, -5,				0, -1,  },
	{	2, 1,				2, 0,   },
	{	2, -1,				-2, 0,  },
	{	2, 2,				1, 0,   },
	{	2, -2,				-1, 0,  },
	{	2, 5,				0, 2,   },
	{	2, -5,				0, 2,   },
	{	-2, 1,				-2, 0,  },
	{	-2, -1,				2, 0,   },
	{	-2, 2,				-1, 0,  },
	{	-2, -2,				1, 0,   },
	{	-2, 5,				0, -2,  },
	{	-2, -5,				0, -2,  },
	{	17, 5,				3, 2,   },
	{	-17, -5,			3, -2,  },
	{	17, -5,				-3, 2,  },
	{	-17, 5,				-3, -2, },
	{	2147483647, 1,			2147483647, 0,         },
	{	-2147483647, 1,			-2147483647, 0,        },
	{	2147483648, 1,			2147483648, 0,         },
	{	-2147483647-1, 1,		-2147483647-1, 0,      },
	{	2147483647, 2,			1073741823, 1,         },
	{	-2147483647, 2,			-1073741823, -1,       },
	{	2147483648, 2,			1073741824, 0,         },
	{	-2147483647-1, 2,		-1073741824, 0,        },
#ifdef	INT_LEAST64_MAX			/* else might support only 32 bits */
	{	4294967295, 1,			4294967295, 0,         },
	{	-4294967296+1, 1,		-4294967296+1, 0,      },
	{	4294967296, 1,			4294967296, 0,         },
	{	-4294967296, 1,			-4294967296, 0,        },
	{	4294967295, -1,			-4294967296+1, 0,      },
	{	-4294967296+1, -1,		4294967295, 0,         },
	{	4294967296, -1,			-4294967296, 0,        },
	{	-4294967296, -1,		4294967296, 0,         },
	{	4294967295, 2,			2147483647, 1,         },
	{	-4294967296+1, 2,		-2147483647, -1,       },
	{	4294967296, 2,			2147483648, 0,         },
	{	-4294967296, 2,			-2147483647-1, 0,      },
	{	4294967295, 2147483647,		2, 1,              },
	{	-4294967296+1, 2147483647,	-2, -1,            },
	{	4294967296, 2147483647,		2, 2,              },
	{	-4294967296, 2147483647,	-2, -2,            },
	{	4294967295, -2147483647,	-2, 1,             },
	{	-4294967296+1, -2147483647,	2, -1,             },
	{	4294967296, -2147483647,	-2, 2,             },
	{	-4294967296, -2147483647,	2, -2,             },
	{	4294967295, 2147483648,		1, 2147483647,     },
	{	-4294967296+1, 2147483648,	-1, -2147483647,   },
	{	4294967296, 2147483648,		2, 0,              },
	{	-4294967296, 2147483648,	-2, 0,             },
	{	4294967295, -2147483647-1,	-1, 2147483647,    },
	{	-4294967296+1, -2147483647-1,	1, -2147483647,},
	{	4294967296, -2147483647-1,	-2, 0,             },
	{	-4294967296, -2147483647-1,	2, 0,              },
	{	9223372036854775807, 1,		9223372036854775807, 0,         },
	{	-9223372036854775807, 1,	-9223372036854775807, 0,        },
	{	9223372036854775807, 2,		4611686018427387903, 1,         },
	{	-9223372036854775807, 2,	-4611686018427387903, -1,       },
#endif
#endif
		/* There should be a much larger battery of such tests. */
	{	0, 0,		0, 0 },	/* 0 denom terminates the list */
		},	*ddp;

#if 0
	for ( ddp = div_data; ddp->denom != 0; ++ddp )
		if ( (result = imaxdiv(ddp->numer, ddp->denom)).quot
		     != ddp->exp_quot || result.rem != ddp->exp_rem
		   )	{
//			fprintf(outfile,"*** imaxdiv(%"PRIdMAX",%"PRIdMAX
//			       ") failed; should be: (%"PRIdMAX",%"PRIdMAX
//			       "), was: (%"PRIdMAX",%"PRIdMAX") ***\n",
//			       ddp->numer, ddp->denom, ddp->exp_quot,
//			       ddp->exp_rem, result.quot, result.rem
//			      );
			fprintf(outfile,"err:imaxdiv(%"PRIdMAX",%"PRIdMAX
			       ") = (%"PRIdMAX",%"PRIdMAX
			       "), is: (%"PRIdMAX",%"PRIdMAX")\n",
			       ddp->numer, ddp->denom, ddp->exp_quot,
			       ddp->exp_rem, result.quot, result.rem
			      );
			status = EXIT_FAILURE;
			}
#endif
	}
	
	{
	char		*endptr;
	wchar_t		*wendptr;
	static char	saved[64];	/* holds copy of input string */
	static wchar_t	wnptr[64];	/* holds wide copy of test string */
	static int	warned;		/* "warned for null endptr" flag */
	register int	i;
	static struct
		{
		char *		nptr;
		int		base;
		intmax_t	exp_val;
		int		exp_len;
		}	str_data[] =
		{
	{	"", 0,				0, 0,      },
	{	"", 2,				0, 0,      },
	{	"", 8,				0, 0,      },
	{	"", 9,				0, 0,      },
	{	"", 10,				0, 0,      },
	{	"", 16,				0, 0,      },
	{	"", 36,				0, 0,      },
	{	"0", 0,				0, 1,      },
	{	"0", 2,				0, 1,      },
	{	"0", 8,				0, 1,      },
	{	"0", 9,				0, 1,      },
	{	"0", 10,			0, 1,      },
	{	"0", 16,			0, 1,      },
	{	"0", 36,			0, 1,      },
	{	"+0", 0,			0, 2,      },
	{	"+0", 2,			0, 2,      },
	{	"+0", 8,			0, 2,      },
	{	"+0", 9,			0, 2,      },
	{	"+0", 10,			0, 2,      },
	{	"+0", 16,			0, 2,      },
	{	"+0", 36,			0, 2,      },
	{	"-0", 0,			0, 2,      },
	{	"-0", 2,			0, 2,      },
	{	"-0", 8,			0, 2,      },
	{	"-0", 9,			0, 2,      },
	{	"-0", 10,			0, 2,      },
	{	"-0", 16,			0, 2,      },
	{	"-0", 36,			0, 2,      },
	{	"Inf", 0,			0, 0,      },
	{	"Inf", 2,			0, 0,      },
	{	"Inf", 8,			0, 0,      },
	{	"Inf", 9,			0, 0,      },
	{	"Inf", 10,			0, 0,      },
	{	"Inf", 16,			0, 0,      },
	{	"Inf", 36,			24171, 3,  },
	{	"+Inf", 0,			0, 0,      },
	{	"+Inf", 2,			0, 0,      },
	{	"+Inf", 8,			0, 0,      },
	{	"+Inf", 9,			0, 0,      },
	{	"+Inf", 10,			0, 0,      },
	{	"+Inf", 16,			0, 0,      },
	{	"+Inf", 36,			24171, 4,  },
	{	"-Inf", 0,			0, 0,      },
	{	"-Inf", 2,			0, 0,      },
	{	"-Inf", 8,			0, 0,      },
	{	"-Inf", 9,			0, 0,      },
	{	"-Inf", 10,			0, 0,      },
	{	"-Inf", 16,			0, 0,      },
	{	"-Inf", 36,			-24171, 4, },
	{	"inf", 0,			0, 0,      },
	{	"inf", 2,			0, 0,      },
	{	"inf", 8,			0, 0,      },
	{	"inf", 9,			0, 0,      },
	{	"inf", 10,			0, 0,      },
	{	"inf", 16,			0, 0,      },
	{	"inf", 36,			24171, 3,  },
	{	"+inf", 0,			0, 0,      },
	{	"+inf", 2,			0, 0,      },
	{	"+inf", 8,			0, 0,      },
	{	"+inf", 9,			0, 0,      },
	{	"+inf", 10,			0, 0,      },
	{	"+inf", 16,			0, 0,      },
	{	"+inf", 36,			24171, 4,  },
	{	"-inf", 0,			0, 0,      },
	{	"-inf", 2,			0, 0,      },
	{	"-inf", 8,			0, 0,      },
	{	"-inf", 9,			0, 0,      },
	{	"-inf", 10,			0, 0,      },
	{	"-inf", 16,			0, 0,      },
	{	"-inf", 36,			-24171, 4, },
	{	"119b8Z", 0,			119, 3,         },
	{	"119bZ", 0,			119, 3,             },
	{	"-0119bZ", 0,			-9, 4,          },
	{	" \t\n 0X119bZ", 0,		4507, 10,       },
	{	" \t\n +0X119bZ", 0,		4507, 11,   },
	{	" \t\n -0x119bZ", 0,		-4507, 11,  },
	{	" \t\n 119bZ", 0,		119, 7,         },
	{	"+119bZ", 0,			119, 4,         },
	{	"+0X119bz", 0,			4507, 7,        },
	{	"119b8Z", 2,			3, 2,           },
	{	"119bZ", 2,			3, 2,               },
	{	"-0119bZ", 2,			-3, 4,          },
	{	" \t\n 0X119bZ", 2,		0, 5,           },
	{	" \t\n +0X119bZ", 2,		0, 6,       },
	{	" \t\n -0x119bZ", 2,		0, 6,       },
	{	" \t\n 119bZ", 2,		3, 6,           },
	{	"+119bZ", 2,			3, 3,           },
	{	"+0X119bz", 2,			0, 2,           },
	{	"119b8Z", 8,			9, 2,           },
	{	"119bZ", 8,			9, 2,               },
	{	"-0119bZ", 8,			-9, 4,          },
	{	" \t\n 0X119bZ", 8,		0, 5,           },
	{	" \t\n +0X119bZ", 8,		0, 6,       },
	{	" \t\n -0x119bZ", 8,		0, 6,       },
	{	" \t\n 119bZ", 8,		9, 6,           },
	{	"+119bZ", 8,			9, 3,           },
	{	"+0X119bz", 8,			0, 2,           },
	{	"119b8Z", 9,			10, 2,          },
	{	"119bZ", 9,			10, 2,              },
	{	"-0119bZ", 9,			-10, 4,         },
	{	" \t\n 0X119bZ", 9,		0, 5,           },
	{	" \t\n +0X119bZ", 9,		0, 6,       },
	{	" \t\n -0x119bZ", 9,		0, 6,       },
	{	" \t\n 119bZ", 9,		10, 6,          },
	{	"+119bZ", 9,			10, 3,          },
	{	"+0X119bz", 9,			0, 2,           },
	{	"119b8Z", 10,			119, 3,         },
	{	"119bZ", 10,			119, 3,         },
	{	"-0119bZ", 10,			-119, 5,        },
	{	" \t\n 0X119bZ", 10,		0, 5,       },
	{	" \t\n +0X119bZ", 10,		0, 6,       },
	{	" \t\n -0x119bZ", 10,		0, 6,       },
	{	" \t\n 119bZ", 10,		119, 7,         },
	{	"+119bZ", 10,			119, 4,         },
	{	"+0X119bz", 10,			0, 2,           },
	{	"119b8Z", 16,			72120, 5,       },
	{	"119bZ", 16,			4507, 4,        },
	{	"-0119bZ", 16,			-4507, 6,       },
	{	" \t\n 0X119bZ", 16,		4507, 10,   },
	{	" \t\n +0X119bZ", 16,		4507, 11,   },
	{	" \t\n -0x119bZ", 16,		-4507, 11,  },
	{	" \t\n 119bZ", 16,		4507,8,         },
	{	"+119bZ", 16,			4507, 5,        },
	{	"+0X119bz", 16,			4507, 7,        },
	{	"119b8Z", 36,			62580275, 6,    },
	{	"119bZ", 36,			1738367, 5,     },
	{	"-0119bZ", 36,			-1738367, 7,                 },
	{	" \t\n 0X119bZ", 36,		1997122175, 11,          },
	{	" \t\n +0X119bZ", 36,		1997122175, 12,          },
	{	" \t\n -0x119bZ", 36,		-1997122175, 12,         },
	{	" \t\n 119bZ", 36,		1738367, 9,                  },
	{	"+119bZ", 36,			1738367, 6,                  },
	{	"+0X119bz", 36,			1997122175, 8,               },
	 	/* There should be a much larger battery of such tests. */
	{	"127", 0,			127, 3,                          },
	{	"-127", 0,			-127, 4,                         },
	{	"128", 0,			128, 3,                          },
	{	"-128", 0,			-127-1, 4,                       },
	{	"255", 0,			255, 3,                          },
	{	"-255", 0,			-255, 4,                         },
	{	"256", 0,			256, 3,                          },
	{	"-256", 0,			-255-1, 4,                       },
	{	"32767", 0,			32767, 5,                        },
	{	"-32767", 0,			-32767, 6,                   },
	{	"32768", 0,			32768, 5,                        },
	{	"-32768", 0,			-32767-1, 6,                 },
	{	"65535", 0,			65535, 5,                        },
	{	"-65535", 0,			-65536+1, 6,                 },
	{	"65536", 0,			65536, 5,                        },
	{	"-65536", 0,			-65536, 6,                   },
	{	"2147483647", 0,		2147483647, 10,              },
	{	"-2147483647", 0,		-2147483647, 11,             },
	{	"2147483648", 0,		2147483648, 10,              },
	{	"-2147483648", 0,		-2147483647-1, 11,           },
	{	"4294967295", 0,		4294967295, 10,              },
	{	"-4294967295", 0,		-4294967296+1, 11,           },
	{	"4294967296", 0,		4294967296, 10,              },
	{	"-4294967296", 0,		-4294967296, 11,                        },
	{	"9223372036854775807", 0,	9223372036854775807, 19,            },
	{	"-9223372036854775807", 0,	-9223372036854775807, 20,           },
	{	"1234567890123456789", 0,	1234567890123456789, 19,            },
	{	"-1234567890123456789", 0,	-1234567890123456789, 20,           },
	{	"1", 0,				1, 1,                                       },
	{	"-1", 0,			-1, 2,                                      },
	{	"2", 0,				2, 1,                                       },
	{	"-2", 0,			-2, 2,                                      },
	{	"10", 0,			10, 2,                                      },
	{	"-10", 0,			-10, 3,                                     },
	{	"16", 0,			16, 2,                                      },
	{	"-16", 0,			-16, 3,                                     },
		/* Other test cases can be added here. */
	{	NULL, 0,	0, 0 },	/* terminates the list */
		},	*sdp;

	for ( sdp = str_data; sdp->nptr != NULL ; ++sdp )
		{
		/*
			7.8.2.3	The strtoimax and strtoumax functions
		*/

		strcpy(saved, sdp->nptr);

		errno = 0;		/* shouldn't be changed */

		if ( (intmax = strtoimax(sdp->nptr, &endptr, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			fprintf(outfile,"*** strtoimax(%s,,%d) failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
			       sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}
		else if ( endptr != sdp->nptr + sdp->exp_len )
			{
			int	save = errno;

			fprintf(outfile,"*** strtoimax(%s,,%d) returned wrong endptr"
			       " ***\n", sdp->nptr, sdp->base
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			fprintf(outfile,"*** strtoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		if ( strcmp(sdp->nptr, saved) != 0 )
			{
			fprintf(outfile,"*** strtoimax modified its input ***\n");
			status = EXIT_FAILURE;
			strcpy(saved, sdp->nptr);
			}

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = strtoumax(sdp->nptr, &endptr, sdp->base
						 )
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				fprintf(outfile,"*** strtoumax(%s,,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}
			else if ( endptr != sdp->nptr + sdp->exp_len )
				{
				int	save = errno;

				fprintf(outfile,"*** strtoumax(%s,,%d) returned wrong "
				       "endptr ***\n", sdp->nptr, sdp->base
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			if ( errno != 0 )
				{
				fprintf(outfile,"*** strtoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			if ( strcmp(sdp->nptr, saved) != 0 )
				{
				fprintf(outfile,"*** strtoumax"
				       " modified its input ***\n"
				      );
				status = EXIT_FAILURE;
				strcpy(saved, sdp->nptr);
				}
			}

		/* tests for null endptr */

#define	WARN()	if (!warned) warned = 1, fprintf(outfile,"*** Using null endptr: ***\n")

		warned = 0;
		errno = 0;		/* shouldn't be changed */

		if ( (intmax = strtoimax(sdp->nptr, (char **)NULL, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			WARN();
			fprintf(outfile,"*** strtoimax(%s,NULL,%d) failed; "
			       "should be: %"PRIdMAX", was: %"PRIdMAX" ***\n",
			       sdp->nptr, sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			WARN();
			fprintf(outfile,"*** strtoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		if ( strcmp(sdp->nptr, saved) != 0 )
			{
			WARN();
			fprintf(outfile,"*** strtoimax modified its input ***\n");
			status = EXIT_FAILURE;
			strcpy(saved, sdp->nptr);
			}

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = strtoumax(sdp->nptr, (char **)NULL,
						  sdp->base
						 )
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				WARN();
				fprintf(outfile,"*** strtoumax(%s,NULL,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			 if ( errno != 0 )
				{
				WARN();
				fprintf(outfile,"*** strtoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			 if ( strcmp(sdp->nptr, saved) != 0 )
				{
				WARN();
				fprintf(outfile,"*** strtoumax"
				       " modified its input ***\n"
				      );
				status = EXIT_FAILURE;
				strcpy(saved, sdp->nptr);
				}
			}

		/*
			7.8.2.4	The wcstoimax and wcstoumax functions
		*/

		for ( i = 0; i < 64; ++i )
			if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
				break;

		errno = 0;		/* shouldn't be changed */

		if ( (intmax = wcstoimax(wnptr, &wendptr, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			fprintf(outfile,"*** wcstoimax(%s,,%d) failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
			       sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}
		else if ( wendptr != wnptr + sdp->exp_len )
			{
			int	save = errno;

			fprintf(outfile,"*** wcstoimax(%s,,%d) returned wrong endptr"
			       " ***\n", sdp->nptr, sdp->base
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			fprintf(outfile,"*** wcstoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		for ( i = 0; i < 64; ++i )
			if ( wnptr[i] != sdp->nptr[i] )
				{
				fprintf(outfile,"*** wcstoimax modified its input ***\n"
				      );
				status = EXIT_FAILURE;

				for ( ; i < 64; ++i )
					if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
						break;

				break;
				}
			else if ( wnptr[i] == '\0' )
				break;

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = wcstoumax(wnptr, &wendptr, sdp->base)
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				fprintf(outfile,"*** wcstoumax(%s,,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}
			else if ( wendptr != wnptr + sdp->exp_len )
				{
				int	save = errno;

				fprintf(outfile,"*** wcstoumax(%s,,%d) returned wrong "
				       "endptr ***\n", sdp->nptr, sdp->base
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			if ( errno != 0 )
				{
				fprintf(outfile,"*** wcstoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			for ( i = 0; i < 64; ++i )
				if ( wnptr[i] != sdp->nptr[i] )
					{
					fprintf(outfile,"*** wcstoumax"
					       " modified its input ***\n"
					      );
					status = EXIT_FAILURE;

					for ( ; i < 64; ++i )
						if ( (wnptr[i] = sdp->nptr[i])
						  == '\0'
						   )
							break;

					break;
					}
				else if ( wnptr[i] == '\0' )
					break;
			}

		/* tests for null endptr */

		warned = 0;
		errno = 0;		/* shouldn't be changed */

		if ( (intmax = wcstoimax(wnptr, (wchar_t **)NULL, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			WARN();
			fprintf(outfile,"*** wcstoimax(%s,NULL,%d) failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
			       sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			WARN();
			fprintf(outfile,"*** wcstoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		for ( i = 0; i < 64; ++i )
			if ( wnptr[i] != sdp->nptr[i] )
				{
				WARN();
				fprintf(outfile,"*** wcstoimax modified its input ***\n"
				      );
				status = EXIT_FAILURE;

				for ( ; i < 64; ++i )
					if ( (wnptr[i] = sdp->nptr[i])
					  == '\0'
					   )
						break;

				break;
				}
			else if ( wnptr[i] == '\0' )
				break;

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = wcstoumax(wnptr, (wchar_t **)NULL,
						  sdp->base
						 )
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				WARN();
				fprintf(outfile,"*** wcstoumax(%s,NULL,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			 if ( errno != 0 )
				{
				WARN();
				fprintf(outfile,"*** wcstoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			for ( i = 0; i < 64; ++i )
				if ( wnptr[i] != sdp->nptr[i] )
					{
					WARN();
					fprintf(outfile,"*** wcstoumax"
					       " modified its input ***\n"
					      );
					status = EXIT_FAILURE;

					for ( ; i < 64; ++i )
						if ( (wnptr[i] = sdp->nptr[i])
						  == '\0'
						   )
							break;

					break;
					}
				else if ( wnptr[i] == '\0' )
					break;
			}
		}

	/*
		7.8.2.3	The strtoimax and strtoumax functions (continued)
	*/

	if ( (intmax = strtoimax("1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoimax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = strtoimax("+1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoimax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = strtoimax("-1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != INTMAX_MIN || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoimax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = strtoumax("1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoumax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = strtoumax("+1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoumax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = strtoumax("-1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoumax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}

	/*
		7.8.2.4	The wcstoimax and wcstoumax functions (continued)
	*/

#ifdef NO_INTERNAL_WCHAR
		fprintf(outfile,"NO_INTERNAL_WCHAR\n");
#else

	if ( (intmax = wcstoimax(L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoimax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = wcstoimax(L"+1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoimax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = wcstoimax(L"-1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != INTMAX_MIN || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoimax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = wcstoumax(L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoumax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = wcstoumax(L"+1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoumax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = wcstoumax(L"-1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoumax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}
#endif // NO_INTERNAL_WCHAR
	}
#endif	/* defined(INTMAX_MAX) */

	if ( status != 0 )
		fprintf(outfile, "sitest failed.\n");

    CLOSETEST();
	
	return status;
}
Esempio n. 16
0
int main()
{

	int num;
	
	int i , j , k;
	int p;
	int len;

	int lines;

	int pos[3];
	char enigma[3][27];

	char code[1024];

	int c1 , c2 , c3;

#ifdef DEBUG
	fp = fopen("test.txt","r");
#endif

	num = 0;
	SCAN("%d" , &len );
	while( len )
	{
		if( num )
			printf("\n");
	
		printf("Enigma %d:\n" , ++num );

		for( i = 0 ; i < 3 ; i++ )
			SCAN("%s",enigma[i] );
		for( i = 0 ; i < 3 ; i++ )
		{
			for( j = 0 ; j < len ; j++ )
			{
				enigma[i][j] = ( enigma[i][j] - 'A' - j + len) % len ;
				PRINT("%d " , enigma[i][j]);
			}

			PRINT("\n");
		}
		SCAN("%d" , &lines );
		while( lines-- )
		{
			SCAN("%s" , code );
			p = 0;
			pos[0] = pos[1] = pos[2] = 0;
			
			while( 1 )
			{
				for( j = 0 ; j < len ; j++ )
				{
					for( k = 0 ; k < len ; k++ )
					{
						if( code[p] == '\0' )
							goto done;

						for( i = 0 ; i < len ; i++ )
						{
							c1 = i + enigma[0][(i+pos[0])%len];
							if( c1 >= len )
								c1 -= len;

							c2 = c1 + enigma[1][(c1+pos[1])%len];
							if( c2 >= len )
								c2 -= len;

							c3 = c2 + enigma[2][(c2+pos[2])%len];
							if( c3 >= len )
								c3 -= len;

							if( c3 + 'A' == code[p] )
							{
								code[p] = i + 'a';
								break;
							}
						}

						p++;
						if( pos[0] == 0 )
							pos[0] = len - 1;
						else
							pos[0]--;
					}
					if( pos[1] == 0 )
						pos[1] = len - 1;
					else
						pos[1]--;
				}
				if( pos[2] == 0 )
					pos[2] = len - 1;
				else
					pos[2]--;
			}
done:
			printf("%s\n" , code );
		
		
		}

		
		SCAN("%d" , &len );
	}
	
	return 0;
}
Esempio n. 17
0
int main()
{
#ifdef DEBUG
	fp = fopen("test.txt","r");
#endif
	
	int n , m , k;
	
	int i , j;

	int t1 , t2;
	list *tmp_list;

	int l;

	tree_node* levels[11];
	tree_node* tmp_node;
	tree_node* node_prev_level;
	tree_node* tmp_parent;

	char tmp_char;
	char c1 , c2;

	int tmp_type;

	int ac1 , ac2;

	int valid;

	int cases;

	cases = 0;

	while( 1 )
	{
		
		SCAN("%d %d %d" , &n , &m , &k );
		if( n == 0 )
			break;

		cases++;
		if( cases != 1 )
			printf("\n");
		printf("NTA%d:\n" , cases );

		for( i = 0 ; i < n ; i++ )
			for( j = 0 ; j < k ; j++ )
			{
				SCAN("%d %d" , &t1 , &t2 );
				signal_table[i][j].l = t1;
				signal_table[i][j].r = t2;
				tmp_list = &signal_table[i][j];

				while( GETCHAR() != '\n' )
				{
					SCAN("%d %d" , &t1 , &t2 );
					tmp_list->next = (list*)malloc( sizeof(list) );
					tmp_list = tmp_list->next;
					tmp_list->l = t1;
					tmp_list->r = t2;
				}

				tmp_list->next = NULL;
			}

		/*for( i = 0 ; i < n ;i++ )
			for( j = 0 ; j < k; j++ )
			{
				tmp_list = &signal_table[i][j];

				while( tmp_list )
				{
					printf("%d %d " , tmp_list->l , tmp_list->r );
					tmp_list = tmp_list->next;
				}

				printf("\n");
			}
		*/


		while( 1 )
		{
			SCAN("%d\n" , &l );
			if( l == -1 )
				break;
			
			format_cache();
			valid = 0;

			/*PRINT("REACH 1:l=%d\n" , l);*/

			levels[0] = get_node();
			tmp_node = levels[0];
			tmp_char = GETCHAR();
			GETCHAR();
			tmp_node->type = tmp_char - 'a';
			tmp_node->next = get_node();


			for( i = 1 ; i <= l ; i++ )
			{
				node_prev_level = levels[i-1];

				levels[i] = get_node();

				tmp_node = levels[i];
				do
				{
					/*while( node_prev_level->type == '*'-'a' )
						node_prev_level = node_prev_level->next;*/

					SCAN("%c %c" , &c1 , &c2 );
					/*PRINT("REACH 2: c1=%c c2=%c\n" , c1 , c2 );*/

					tmp_node->next = get_node();
					tmp_node->parent = node_prev_level;
					tmp_node->type = c1 - 'a';
					if( c1 == '*' )
						tmp_node->accept = 0xffff<<(n-m) & 0xffff>>(16-n);
					tmp_node = tmp_node->next;

					tmp_node->next = get_node();
					tmp_node->parent = node_prev_level;
					tmp_node->type = c2 - 'a';
					if( c2 == '*' )
						tmp_node->accept = 0xffff<<(n-m) & 0xffff>>(16-n);
					tmp_node = tmp_node->next;

					node_prev_level = node_prev_level->next;
					if( node_prev_level == NULL )
					{
						malloc(1000000);
						return 0;
					}

					tmp_char = GETCHAR();	
				}while(tmp_char == ' ');

			}

			/*
			for( i = 1 ; i <= l ; i++ )
			{
				tmp_node = levels[i];
				while( tmp_node->next )
				{
					printf("%c(%c) " , tmp_node->type+'a' , tmp_node->parent->type+'a' );
					tmp_node = tmp_node->next;
				}
				printf("\n");
			}
			*/

			tmp_node = levels[l];

			while( tmp_node->next )
			{
				tmp_type = tmp_node->type;
				if( tmp_type != '*' - 'a' )
				{
					tmp_node->accept = 0;
					for( i = 0 ; i < n ; i++ )
					{
						tmp_list = &signal_table[i][tmp_type];

						while( tmp_list )
						{
							if( tmp_list->l >= n-m && tmp_list->r >= n-m )
							{
								tmp_node->accept |= 1<<i;
								break;
							}

							tmp_list = tmp_list->next;
						}
					}

					if( tmp_node-> accept == 0 )
					{
						valid = 0;
						goto print;
					}
				}

				tmp_node = tmp_node->next;
			}

			for( j = l ; j > 0 ; j-- )
			{
				tmp_node = levels[j];

				while( tmp_node-> next )
				{

					tmp_parent = tmp_node->parent;
					tmp_type = tmp_parent->type;
					
					ac1 = tmp_node->accept;
					tmp_node = tmp_node->next;
					ac2 = tmp_node->accept;
					tmp_node = tmp_node->next;

					if( tmp_type == '*' - 'a' )
						continue;
					
					tmp_parent->accept = 0;
					PRINT("REACH 3: node=%c ac1=0x%x ac2=0x%x\n" , tmp_type+'a' , ac1 , ac2 );

					for( i = 0 ; i < n ; i++ )
					{
						tmp_list = &signal_table[i][tmp_type];

						while( tmp_list )
						{
							PRINT("REACH 3.5: l=%d r=%d\n" , tmp_list->l , tmp_list->r );
							if( ( ( ac1 & (1<<tmp_list->l) ) ) && 
							     (  ac2 & (1<<tmp_list->r) ) )
							{
								tmp_parent->accept |= 1<<i;
								PRINT("REACH 4: node=%c signal=%d\n" , tmp_type+'a' , i );
								break;
							}

							tmp_list = tmp_list->next;
						}

					}

					if( tmp_parent->accept == 0 )
					{
						valid = 0;
						goto print;
					}
				}
				PRINT("REACH 5: j=%d\n" , j);
			}


			if( levels[0]->accept & 1 )
				valid = 1;
			else
				valid = 0;

print:
			if( valid )
				printf("Valid\n");
			else
				printf("Invalid\n");
		}
			

		
	}

	return 0;
Esempio n. 18
0
static void
whois(const char *query, const char *hostname, int flags)
{
	FILE *fp;
	struct addrinfo *hostres, *res;
	char *buf, *host, *nhost, *p;
	int s = -1, f;
	nfds_t i, j;
	size_t len, count;
	struct pollfd *fds;
	int timeout = 180;

	hostres = gethostinfo(hostname, 1);
	for (res = hostres, count = 0; res; res = res->ai_next)
		count++;
	fds = calloc(count, sizeof(*fds));
	if (fds == NULL)
		err(EX_OSERR, "calloc()");

	/*
	 * Traverse the result list elements and make non-block
	 * connection attempts.
	 */
	count = i = 0;
	for (res = hostres; res != NULL; res = res->ai_next) {
		s = socket(res->ai_family, res->ai_socktype | SOCK_NONBLOCK,
		    res->ai_protocol);
		if (s < 0)
			continue;
		if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
			if (errno == EINPROGRESS) {
				/* Add the socket to poll list */
				fds[i].fd = s;
				fds[i].events = POLLERR | POLLHUP |
						POLLIN | POLLOUT;
				count++;
				i++;
			} else {
				close(s);
				s = -1;

				/*
				 * Poll only if we have something to poll,
				 * otherwise just go ahead and try next
				 * address
				 */
				if (count == 0)
					continue;
			}
		} else
			goto done;

		/*
		 * If we are at the last address, poll until a connection is
		 * established or we failed all connection attempts.
		 */
		if (res->ai_next == NULL)
			timeout = INFTIM;

		/*
		 * Poll the watched descriptors for successful connections:
		 * if we still have more untried resolved addresses, poll only
		 * once; otherwise, poll until all descriptors have errors,
		 * which will be considered as ETIMEDOUT later.
		 */
		do {
			int n;

			n = poll(fds, i, timeout);
			if (n == 0) {
				/*
				 * No event reported in time.  Try with a
				 * smaller timeout (but cap at 2-3ms)
				 * after a new host have been added.
				 */
				if (timeout >= 3)
					timeout <<= 1;

				break;
			} else if (n < 0) {
				/*
				 * errno here can only be EINTR which we would
				 * want to clean up and bail out.
				 */
				s = -1;
				goto done;
			}

			/*
			 * Check for the event(s) we have seen.
			 */
			for (j = 0; j < i; j++) {
				if (fds[j].fd == -1 || fds[j].events == 0 ||
				    fds[j].revents == 0)
					continue;
				if (fds[j].revents & ~(POLLIN | POLLOUT)) {
					close(s);
					fds[j].fd = -1;
					fds[j].events = 0;
					count--;
					continue;
				} else if (fds[j].revents & (POLLIN | POLLOUT)) {
					/* Connect succeeded. */
					s = fds[j].fd;

					goto done;
				}

			}
		} while (timeout == INFTIM && count != 0);
	}

	/* All attempts were failed */
	s = -1;
	if (count == 0)
		errno = ETIMEDOUT;
done:
	if (s == -1)
		err(EX_OSERR, "connect()");

	/* Close all watched fds except the succeeded one */
	for (j = 0; j < i; j++)
		if (fds[j].fd != s && fds[j].fd != -1)
			close(fds[j].fd);
	free(fds);

	/* Restore default blocking behavior.  */
	if ((f = fcntl(s, F_GETFL)) == -1)
		err(EX_OSERR, "fcntl()");
	f &= ~O_NONBLOCK;
	if (fcntl(s, F_SETFL, f) == -1)
		err(EX_OSERR, "fcntl()");

	fp = fdopen(s, "r+");
	if (fp == NULL)
		err(EX_OSERR, "fdopen()");

	if (!(flags & WHOIS_SPAM_ME) &&
	    (strcasecmp(hostname, DENICHOST) == 0 ||
	     strcasecmp(hostname, "de" QNICHOST_TAIL) == 0)) {
		const char *q;
		int idn = 0;
		for (q = query; *q != '\0'; q++)
			if (!isascii(*q))
				idn = 1;
		fprintf(fp, "-T dn%s %s\r\n", idn ? "" : ",ace", query);
	} else if (!(flags & WHOIS_SPAM_ME) &&
		   (strcasecmp(hostname, DKNICHOST) == 0 ||
		    strcasecmp(hostname, "dk" QNICHOST_TAIL) == 0))
		fprintf(fp, "--show-handles %s\r\n", query);
	else if ((flags & WHOIS_SPAM_ME) ||
		 strchr(query, ' ') != NULL)
		fprintf(fp, "%s\r\n", query);
	else if (strcasecmp(hostname, ANICHOST) == 0) {
		if (strncasecmp(query, "AS", 2) == 0 &&
		    strspn(query+2, "0123456789") == strlen(query+2))
			fprintf(fp, "+ a %s\r\n", query+2);
		else
			fprintf(fp, "+ %s\r\n", query);
	} else if (strcasecmp(hostres->ai_canonname, VNICHOST) == 0)
		fprintf(fp, "domain %s\r\n", query);
	else
		fprintf(fp, "%s\r\n", query);
	fflush(fp);

	nhost = NULL;
	while ((buf = fgetln(fp, &len)) != NULL) {
		/* Nominet */
		if (!(flags & WHOIS_SPAM_ME) &&
		    len == 5 && strncmp(buf, "-- \r\n", 5) == 0)
			break;

		printf("%.*s", (int)len, buf);

		if ((flags & WHOIS_RECURSE) && nhost == NULL) {
			for (i = 0; whois_referral[i].prefix != NULL; i++) {
				p = buf;
				SCAN(p, buf+len, *p == ' ');
				if (strncasecmp(p, whois_referral[i].prefix,
					           whois_referral[i].len) != 0)
					continue;
				p += whois_referral[i].len;
				SCAN(p, buf+len, *p == ' ');
				host = p;
				SCAN(p, buf+len, ishost(*p));
				/* avoid loops */
				if (strncmp(hostname, host, p - host) != 0)
					s_asprintf(&nhost, "%.*s",
						   (int)(p - host), host);
				break;
			}
			for (i = 0; actually_arin[i] != NULL; i++) {
				if (strncmp(buf, actually_arin[i], len) == 0) {
					s_asprintf(&nhost, "%s", ANICHOST);
					break;
				}
			}
		}
		/* Verisign etc. */
		if (!(flags & WHOIS_SPAM_ME) &&
		    len >= sizeof(CHOPSPAM)-1 &&
		    (strncasecmp(buf, CHOPSPAM, sizeof(CHOPSPAM)-1) == 0 ||
		     strncasecmp(buf, CHOPSPAM+4, sizeof(CHOPSPAM)-5) == 0)) {
			printf("\n");
			break;
		}
	}
	fclose(fp);
	freeaddrinfo(hostres);
	if (nhost != NULL) {
		whois(query, nhost, flags);
		free(nhost);
	}
}