/* .Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y */ /* .YT 3 2 0 0 3 3 1 / / / */ /* .H!a!0:io#092/disk#092/mediaAccess#092/grammar#092/cpp#092/Main.c!0.!c */ /*************************************************************************** io disk mediaAccess grammar Main.c ++++++++++++++++++++++++++++++++++ purpose : "main()"-function for the grammar ("<...>/MediaInfo.y") of a "mediaAccess"-media- info-structure (/-text) begin : Thu Dec 28 20:20:30 CEST 2017 changes : copyright : (C) 2017 by Thomas Bruecker email : public@thomas-r-bruecker.ch version : -0.0.0 ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either Version 2 of the License, or * * (at your option) any later Version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * * MA 02110-1301 USA. * * * ***************************************************************************/ #include /* mtrace() */ #include /* offsetof() */ #include #include #include #include "container.h" #include "MediaInfo.h" #include "MediaInfo.tab.h" int main( int argc, char* argv[] ) { enum CommandTP Command; # define CommandArgIndex 1 int Found; int I; struct MediaInfoParameterTP* pMediaInfoParameter; # define PathArgsIndex CommandArgIndex + 1 char* pPath; char* pPathComponent; struct ParameterTP* pParameter; int Result; int yylexVal; struct list_head* p; // mtrace(); if(0) { do { yylexVal = yylex(); printf("main: yylex: \"%c\" = %d\n", yylexVal, yylexVal); } while(yylexVal); yylex_destroy(); return 0; } /* else */ if(2 > argc) { printf("main: argc = %d\n", argc); return EXIT_NOT_ENOUGH_PARAMETERS; } Result = yyparse(); // printf("main: Result = %d\n", Result); if(pInput) { /* printf("main: argc = %d\n", argc); printf("main: pInput.0 = %s\n", pInput->pParameterIdentifier); printf("main: pInput.1 = %s\n", pInput->pMediaInfo->pMethodIdentifier); */ Found = 1; pMediaInfoParameter = pInput; for(I = PathArgsIndex; I < argc; I++) { struct MediaInfoParameterTP* pI; Found = 0; pPathComponent = argv[I]; // printf("main: I = %d\n", I); // printf("main: pathArg = %s\n", pPathComponent); list_for_each_entry_reverse( pI, &pMediaInfoParameter->pMediaInfo->pParameterList->MediaInfoParameters, List ) { // printf("main pi: %s\n", pI->pParameterIdentifier); if( !strcmp(pPathComponent, pI->pParameterIdentifier) ) { /* found path-component. */ // printf("main: done: %s\n", pPathComponent); pMediaInfoParameter = pI; Found = 1; break; } } if(!Found) { pPath = PathName(argc, argv, PathArgsIndex); fprintf(stderr, "path not found: \"%s\".\n", pPath); free(pPath); break; } } if(Found) { Command = XLateCommand(argv); switch(Command) { case MediaHandlerUuid: printf("%s\n", pMediaInfoParameter->pMediaInfo->pMethodIdentifier); break; case MediaInfo: PrintMediaInfo(pMediaInfoParameter->pMediaInfo, "", ""); break; case PARAMETERS: PrintParameters(pMediaInfoParameter->pMediaInfo->pParameterList, ""); break; case LS: LsMediaInfoParameters(pMediaInfoParameter->pMediaInfo->pParameterList); break; default: { /* pParameter = list_entry( &(pInput->pMediaInfo->pParameterList->Parameters), struct ParameterTP, List ); */ // printf("main: pInput.2 = 0%08X\n", pParameter); // printf("main: pInput.3 = 0%08X\n", &pInput->pMediaInfo->pParameterList->Parameters.prev); list_for_each(p, &(pInput->pMediaInfo->pParameterList->MediaInfoParameters) ) { // printf("main: px = 0%08X\n", p); pMediaInfoParameter = list_entry(p, struct MediaInfoParameterTP, List); printf( "main: %s = %s\n", pMediaInfoParameter->pParameterIdentifier, pMediaInfoParameter->pMediaInfo->pMethodIdentifier ); } list_for_each(p, &(pInput->pMediaInfo->pParameterList->Parameters) ) { // printf("main: px = 0%08X\n", p); pParameter = list_entry(p, struct ParameterTP, List); printf( "main: %s = %s\n", pParameter->pParameterIdentifier, pParameter->pValue ); } } //while(1); } /* switch */ } else { /* found */ Result = EXIT_PATH_NOT_FOUND; } /* found */ FreeInput(pInput); yylex_destroy(); return Result; } else { fprintf(stderr, "empty input.\n"); yylex_destroy(); if(Result) return Result; /* else */ return EXIT_EMPTY_INPUT; } /* printf("CONSTANT = 258\n"); printf("STRING = 259\n"); printf("UUID = 260\n"); printf("ParameterChar = 261\n"); */ }