bool pred_fprintf (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { struct format_val *dest = &pred_ptr->args.printf_vec; struct segment *segment; for (segment = dest->segment; segment; segment = segment->next) { if ( (KIND_FORMAT == segment->segkind) && segment->format_char[1]) /* Component of date. */ { struct timespec ts; int valid = 0; switch (segment->format_char[0]) { case 'A': ts = get_stat_atime (stat_buf); valid = 1; break; case 'B': ts = get_stat_birthtime (stat_buf); if ('@' == segment->format_char[1]) valid = 1; else valid = (ts.tv_nsec >= 0); break; case 'C': ts = get_stat_ctime (stat_buf); valid = 1; break; case 'T': ts = get_stat_mtime (stat_buf); valid = 1; break; default: assert (0); abort (); } /* We trust the output of format_date not to contain * nasty characters, though the value of the date * is itself untrusted data. */ if (valid) { /* trusted */ checked_fprintf (dest, segment->text, format_date (ts, segment->format_char[1])); } else { /* The specified timestamp is not available, output * nothing for the timestamp, but use the rest (so that * for example find foo -printf '[%Bs] %p\n' can print * "[] foo"). */ /* trusted */ checked_fprintf (dest, segment->text, ""); } } else { /* Print a segment which is not a date. */ do_fprintf (dest, segment, pathname, stat_buf); } } return true; }
int main (int argc, char** argv) /*****/ /* main program, corresponds to procedures */ /* Main and Proc_0 in the Ada version */ { One_Fifty Int_1_Loc; REG One_Fifty Int_2_Loc; One_Fifty Int_3_Loc; REG char Ch_Index; Enumeration Enum_Loc; Str_30 Str_1_Loc; Str_30 Str_2_Loc; REG int Run_Index; REG int Number_Of_Runs; /* Arguments */ #if HOST_DEBUG if (argc > 2) { do_fprintf (stdout, "Usage: %s [number of loops]\n", argv[0]); exit (1); } if (argc == 2) { Number_Of_Runs = atoi (argv[1]); } else #endif { Number_Of_Runs = NUMBER_OF_RUNS; } if (Number_Of_Runs <= 0) { Number_Of_Runs = NUMBER_OF_RUNS; } /* Initializations */ Next_Ptr_Glob = (Rec_Pointer) alloca (sizeof (Rec_Type)); Ptr_Glob = (Rec_Pointer) alloca (sizeof (Rec_Type)); Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; Ptr_Glob->Discr = Ident_1; Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; Ptr_Glob->variant.var_1.Int_Comp = 40; strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING"); strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); Arr_2_Glob [8][7] = 10; /* Was missing in published program. Without this statement, */ /* Arr_2_Glob [8][7] would have an undefined value. */ /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ /* overflow may occur for this array element. */ #if HOST_DEBUG do_fprintf (stdout, "\n"); do_fprintf (stdout, "Dhrystone Benchmark, Version %s\n", Version); if (Reg) { do_fprintf (stdout, "Program compiled with 'register' attribute\n"); } else { do_fprintf (stdout, "Program compiled without 'register' attribute\n"); } do_fprintf (stdout, "Using %s, HZ=%d\n", CLOCK_TYPE, HZ); do_fprintf (stdout, "\n"); #endif Done = false; while (!Done) { #if HOST_DEBUG do_fprintf (stdout, "Trying %d runs through Dhrystone:\n", Number_Of_Runs); #endif /***************/ /* Start timer */ /***************/ Start_Timer(); setStats(1); for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { Proc_5(); Proc_4(); /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ Int_1_Loc = 2; Int_2_Loc = 3; strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); Enum_Loc = Ident_2; Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc); /* Bool_Glob == 1 */ while (Int_1_Loc < Int_2_Loc) /* loop body executed once */ { Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; /* Int_3_Loc == 7 */ Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc); /* Int_3_Loc == 7 */ Int_1_Loc += 1; } /* while */ /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); /* Int_Glob == 5 */ Proc_1 (Ptr_Glob); for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) /* loop body executed twice */ { if (Enum_Loc == Func_1 (Ch_Index, 'C')) /* then, not executed */ { Proc_6 (Ident_1, &Enum_Loc); strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); Int_2_Loc = Run_Index; Int_Glob = Run_Index; } } /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ Int_2_Loc = Int_2_Loc * Int_1_Loc; Int_1_Loc = Int_2_Loc / Int_3_Loc; Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ Proc_2 (&Int_1_Loc); /* Int_1_Loc == 5 */ } /* loop "for Run_Index" */ /**************/ /* Stop timer */ /**************/ setStats(0); Stop_Timer(); User_Time = End_Time - Begin_Time; if (User_Time < Too_Small_Time) { do_fprintf (stdout, "Measured time too small to obtain meaningful results\n"); Number_Of_Runs = Number_Of_Runs * 10; do_fprintf (stdout, "\n"); } else Done = true; } do_fprintf (stderr, "Final values of the variables used in the benchmark:\n"); do_fprintf (stderr, "\n"); do_fprintf (stderr, "Int_Glob: %d\n", Int_Glob); do_fprintf (stderr, " should be: %d\n", 5); do_fprintf (stderr, "Bool_Glob: %d\n", Bool_Glob); do_fprintf (stderr, " should be: %d\n", 1); do_fprintf (stderr, "Ch_1_Glob: %c\n", Ch_1_Glob); do_fprintf (stderr, " should be: %c\n", 'A'); do_fprintf (stderr, "Ch_2_Glob: %c\n", Ch_2_Glob); do_fprintf (stderr, " should be: %c\n", 'B'); do_fprintf (stderr, "Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]); do_fprintf (stderr, " should be: %d\n", 7); do_fprintf (stderr, "Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); do_fprintf (stderr, " should be: Number_Of_Runs + 10\n"); do_fprintf (stderr, "Ptr_Glob->\n"); do_fprintf (stderr, " Ptr_Comp: %d\n", (long) Ptr_Glob->Ptr_Comp); do_fprintf (stderr, " should be: (implementation-dependent)\n"); do_fprintf (stderr, " Discr: %d\n", Ptr_Glob->Discr); do_fprintf (stderr, " should be: %d\n", 0); do_fprintf (stderr, " Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp); do_fprintf (stderr, " should be: %d\n", 2); do_fprintf (stderr, " Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp); do_fprintf (stderr, " should be: %d\n", 17); do_fprintf (stderr, " Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp); do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, SOME STRING\n"); do_fprintf (stderr, "Next_Ptr_Glob->\n"); do_fprintf (stderr, " Ptr_Comp: %d\n", (long) Next_Ptr_Glob->Ptr_Comp); do_fprintf (stderr, " should be: (implementation-dependent), same as above\n"); do_fprintf (stderr, " Discr: %d\n", Next_Ptr_Glob->Discr); do_fprintf (stderr, " should be: %d\n", 0); do_fprintf (stderr, " Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp); do_fprintf (stderr, " should be: %d\n", 1); do_fprintf (stderr, " Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp); do_fprintf (stderr, " should be: %d\n", 18); do_fprintf (stderr, " Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp); do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, SOME STRING\n"); do_fprintf (stderr, "Int_1_Loc: %d\n", Int_1_Loc); do_fprintf (stderr, " should be: %d\n", 5); do_fprintf (stderr, "Int_2_Loc: %d\n", Int_2_Loc); do_fprintf (stderr, " should be: %d\n", 13); do_fprintf (stderr, "Int_3_Loc: %d\n", Int_3_Loc); do_fprintf (stderr, " should be: %d\n", 7); do_fprintf (stderr, "Enum_Loc: %d\n", Enum_Loc); do_fprintf (stderr, " should be: %d\n", 1); do_fprintf (stderr, "Str_1_Loc: %s\n", Str_1_Loc); do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); do_fprintf (stderr, "Str_2_Loc: %s\n", Str_2_Loc); do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); do_fprintf (stderr, "\n"); #if HOST_DEBUG Microseconds = (float) User_Time * Mic_secs_Per_Second / ((float) HZ * ((float) Number_Of_Runs)); Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs) / (float) User_Time; do_fprintf (stdout, "Microseconds for one run through Dhrystone: "); do_fprintf (stdout, "%10.1f \n", Microseconds); do_fprintf (stdout, "Dhrystones per Second: "); do_fprintf (stdout, "%10.0f \n", Dhrystones_Per_Second); do_fprintf (stdout, "\n"); #endif return 0; }