static void fetch_id(const char *dev, const char *name, struct bridge_id *id) { FILE *f = fpopen(dev, name); fscanf(f, "%2hhx%2hhx.%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", &id->prio[0], &id->prio[1], &id->addr[0], &id->addr[1], &id->addr[2], &id->addr[3], &id->addr[4], &id->addr[5]); fclose(f); }
/* Fetch an integer attribute out of sysfs. */ static int fetch_int(const char *dev, const char *name) { FILE *f = fpopen(dev, name); int value = -1; if (!f) return 0; fscanf(f, "%i", &value); fclose(f); return value; }
/* Fetch an integer attribute out of sysfs. */ static int fetch_int(const char *dev, const char *name) { FILE *f = fpopen(dev, name); int value = -1; if (!f) fprintf(stderr, "%s: %s\n", dev, strerror(errno)); else { fscanf(f, "%i", &value); fclose(f); } return value; }
static void fetch_id(const char *dev, const char *name, struct bridge_id *id) { FILE *f = fpopen(dev, name); if (!f) fprintf(stderr, "%s: %s\n", dev, strerror(errno)); else { fscanf(f, "%2hhx%2hhx.%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", &id->prio[0], &id->prio[1], &id->addr[0], &id->addr[1], &id->addr[2], &id->addr[3], &id->addr[4], &id->addr[5]); fclose(f); } }
int main( int argc, char **argv ) { int i; FILE *skeleton, *temp, *tokout, *actout; int ch; char tempfname[10]; char *fileprefix = "y"; size_t size; param_requested = 0; for( i = 1; i < argc; ++i ) { ch = argv[i][0]; switch( param_requested ) { case 'b': if( ch != '-' ) { if( ch != '\0' ) fileprefix = argv[i]; ++i; } break; case 'p': if( ch != '-' ) { if( ch != '\0' ) symprefix = argv[i]; ++i; } break; default: break; } param_requested = 0; if( argv[i][0] != '-' ) break; setoptions( &argv[i][1] ); } if( i != argc - 1 && i != argc - 2 ) { puts( "usage: yacc [-dlv] [-d[bcdfhpstuw]] [-b <file_prefix>] [-p <sym_prefix>]" ); puts( " <grammar> [<driver>]" ); puts( "options:" ); puts( " -b <file_prefix> file prefix used in place of default 'y' prefix" ); puts( " -d output header file" ); puts( " -db output bigger (less optimal) tables" ); puts( " -dc output compact tables (slower to execute)" ); puts( " -dd use dense tokens (no '+' style tokens allowed)" ); puts( " -de dump all symbols to header file as enum items, no macros" ); puts( " -df output fast tables (larger size)" ); puts( " -dh use 'default shift' optimization" ); puts( " -dp dump all productions" ); puts( " -ds dump full state tables" ); puts( " -dt translate 'keyword' to Y_KEYWORD, '++' to Y_PLUS_PLUS, etc." ); puts( " -du eliminate useless unit production reduction" ); puts( " -dw disable default action type checking" ); puts( " -l output #line directives" ); puts( " -p <sym_prefix> symbol prefix used in place of default 'yy' prefix" ); puts( " -v write description and report into file" ); exit( 1 ); } skeleton = NULL; if( i == argc - 2 ) { skeleton = openr( argv[argc - 1] ); if( skeleton == NULL ) { msg( "could not open driver source code '%s'\n", argv[argc - 1] ); } } loadpath = argv[0]; *getname( loadpath ) = '\0'; srcname = argv[i]; if( !strrchr( srcname, '.' ) ) { srcname = alloca( strlen( argv[i] )+3 ); srcname = strcat( strcpy( srcname, argv[i] ), ".y" ); } yaccin = openr( srcname ); size = strlen( fileprefix); codefilename = MALLOC( size + 6, char ); strcat( strcpy( codefilename, fileprefix), "tab.c" ); headerfilename = MALLOC( size + 6, char ); strcat( strcpy( headerfilename, fileprefix), "tab.h" ); descfilename = MALLOC( size + 5, char ); strcat( strcpy( descfilename, fileprefix), ".out" ); actout = openw( codefilename ); defs( actout ); tokout = openw( headerfilename ); dump_header( tokout ); temp = NULL; for( i = 0; i < 1000 && temp == NULL; ++i ) { sprintf( tempfname, "ytab.%3d", i ); temp = fopen( tempfname, "w+" ); } if( temp == NULL ) { msg( "Cannot create temporary file\n" ); } rules( temp ); buildpro(); CalcMinSentence(); if( proflag || showflag ) { showpro(); } lr0(); lalr1(); SetupStateTable(); /* apply state filters */ FindUnused(); if( eliminateunitflag ) { EliminateUnitReductions(); } if( default_shiftflag ) { if( keyword_id_low == 0 ) { msg( "No %%keyword_id <low> <high> specified." ); } else { MarkDefaultShifts(); } } MarkNoUnitRuleOptimizationStates(); RemoveDeadStates(); MarkDefaultReductions(); if( showflag ) { showstates(); } if( warnings ) { if( warnings == 1 ) { printf( "%s: 1 warning\n", srcname ); } else { printf( "%s: %d warnings\n", srcname, warnings ); } exit( 1 ); } parsestats(); dumpstatistic( "parser states", nstate ); dumpstatistic( "# states (1 reduce only)", nstate_1_reduce ); dumpstatistic( "reduce/reduce conflicts", RR_conflicts ); dumpstatistic( "shift/reduce conflicts", SR_conflicts ); show_unused(); if( skeleton == NULL ) { skeleton = fpopen( loadpath, "yydriver.c" ); if( skeleton == NULL ) { warn( "Can't find yacc skeleton yydriver.c\n" ); } } /* copy first part of skeleton */ if( skeleton != NULL ) copy_part( skeleton, actout ); rewind( tokout ); /* copy tokens */ copy_rest( tokout, actout ); close_header( tokout ); genobj( actout ); /* copy middle part of skeleton */ if( skeleton != NULL ) copy_part( skeleton, actout ); rewind( temp ); copy_rest( temp, actout ); fclose( temp ); remove( tempfname ); /* copy last part of skeleton */ if( skeleton != NULL ) { copy_rest( skeleton, actout ); fclose( skeleton ); } tail( actout ); fclose( actout ); FREE( codefilename ); FREE( headerfilename ); FREE( descfilename ); return( 0 ); }