/* .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/MediaInfo.c!0.!c */ /*************************************************************************** io disk mediaAccess grammar MediaInfo.c +++++++++++++++++++++++++++++++++++++++ purpose : functions for the grammar ("<...>/MediaInfo.y") of a "mediaAccess"-media-info-structure (/-text) begin : Thu Dec 28 20:34:16 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 /* offsetof */ #include #include #include /* strcat, strdup() */ #include "container.h" #include "MediaInfo.h" struct ParameterListTP* AddParameterListMediaInfo( struct MediaInfoParameterTP* pMediaInfoParameter, struct ParameterListTP* pParameterList ) { list_add_tail(&pMediaInfoParameter->List, &pParameterList->MediaInfoParameters); return pParameterList; } struct ParameterListTP* AddParameterListParameter( struct ParameterTP* pParameter, struct ParameterListTP* pParameterList ) { list_add_tail(&pParameter->List, &pParameterList->Parameters); return pParameterList; } void FreeInput(struct MediaInfoParameterTP* pMediaInfoParameter) { FreeMediaInfo(pMediaInfoParameter->pMediaInfo); /* "pMediaInfoParameter->pParameterIdentifier" is a string-constant! */ free(pMediaInfoParameter); } void FreeMediaInfo(struct MediaInfoTP* pMediaInfo) { free(pMediaInfo->pMethodIdentifier); FreeParameterList(pMediaInfo->pParameterList); free(pMediaInfo); } void FreeMediaInfoParameter(struct MediaInfoParameterTP* pMediaInfoParameter) { FreeMediaInfo(pMediaInfoParameter->pMediaInfo); free(pMediaInfoParameter->pParameterIdentifier); list_del(&pMediaInfoParameter->List); free(pMediaInfoParameter); } void FreeParameter(struct ParameterTP* pParameter) { free(pParameter->pParameterIdentifier); free(pParameter->pValue); list_del(&pParameter->List); free(pParameter); } void FreeParameterList(struct ParameterListTP* pParameterList) { struct MediaInfoParameterTP* pMediaInfoParameter; struct MediaInfoParameterTP* pTmpM; struct ParameterTP* pParameter; struct ParameterTP* pTmpP; list_for_each_entry_safe( pMediaInfoParameter, pTmpM, &pParameterList->MediaInfoParameters, List ) { /* printf( "FreeParameterListMP: %s = %s\n", pMediaInfoParameter->pParameterIdentifier, pMediaInfoParameter->pMediaInfo->pMethodIdentifier ); */ FreeMediaInfoParameter(pMediaInfoParameter); } list_for_each_entry_safe( pParameter, pTmpP, &pParameterList->Parameters, List ) { /* printf( "FreeParameterListP: %s = %s\n", pParameter->pParameterIdentifier, pParameter->pValue ); */ FreeParameter(pParameter); } free(pParameterList); } void LsMediaInfoParameters(struct ParameterListTP* pParameterList) { struct MediaInfoParameterTP* pParameter; list_for_each_entry(pParameter, &pParameterList->MediaInfoParameters, List) { printf("%s\n", pParameter->pParameterIdentifier); } } struct ParameterListTP* NewEmptyParameterList() { struct ParameterListTP* pParameterList; pParameterList = malloc( sizeof(struct ParameterListTP) ); if(!pParameterList) exit(EXIT_NO_MEMORY); INIT_LIST_HEAD(&pParameterList->MediaInfoParameters); INIT_LIST_HEAD(&pParameterList->Parameters); return pParameterList; } struct MediaInfoTP* NewMediaInfo( char* pMethodIdentifier, struct ParameterListTP* pParameterList ) { struct MediaInfoTP* pMediaInfo; pMediaInfo = malloc( sizeof(struct MediaInfoTP) ); if(!pMediaInfo) exit(EXIT_NO_MEMORY); pMediaInfo->pMethodIdentifier = pMethodIdentifier; pMediaInfo->pParameterList = pParameterList; return pMediaInfo; } struct MediaInfoParameterTP* NewMediaInfoParameter( struct MediaInfoTP* pMediaInfo, char* pParameterIdentifier ) { struct MediaInfoParameterTP* pMediaInfoParameter; pMediaInfoParameter = malloc( sizeof(struct MediaInfoParameterTP) ); if(!pMediaInfoParameter) exit(EXIT_NO_MEMORY); pMediaInfoParameter->pMediaInfo = pMediaInfo; pMediaInfoParameter->pParameterIdentifier = pParameterIdentifier; return pMediaInfoParameter; } struct ParameterTP* NewParameter( char* pParameterIdentifier, char* pValue ) { struct ParameterTP* pParameter; pParameter = malloc( sizeof(struct ParameterTP) ); if(!pParameter) exit(EXIT_NO_MEMORY); pParameter->pParameterIdentifier = pParameterIdentifier; pParameter->pValue = pValue; return pParameter; } struct ParameterListTP* NewParameterListMediaInfo( struct MediaInfoParameterTP* pMediaInfoParameter ) { struct ParameterListTP* pParameterList; pParameterList = NewEmptyParameterList(); list_add_tail(&pMediaInfoParameter->List, &pParameterList->MediaInfoParameters); return pParameterList; } struct ParameterListTP* NewParameterListParameter( struct ParameterTP* pParameter ) { struct ParameterListTP* pParameterList; pParameterList = NewEmptyParameterList(); list_add_tail(&pParameter->List, &pParameterList->Parameters); return pParameterList; } char* PathName(int ArgC, char** ArgV, int PathArgsIndex) { char pBuffer[4096]; int I; char* pPathComponent; char* pPath = pBuffer; pPath[0] = 0; for(I = PathArgsIndex; I < ArgC; I++) { pPathComponent = ArgV[I]; pPath = strcat(pPath, "/"); pPath = strcat(pPath, pPathComponent); } return strdup(pPath); } void PrintMediaInfo( struct MediaInfoTP* pMediaInfo, char* pPrefix, char* pSuffix ) { printf("{%s}(\n", pMediaInfo->pMethodIdentifier); PrintParameters(pMediaInfo->pParameterList, " "); PrintMediaInfoParameters(pMediaInfo->pParameterList); printf(")%s\n", pSuffix); } void PrintMediaInfoParameters(struct ParameterListTP* pParameterList) { struct MediaInfoParameterTP* pParameter; list_for_each_entry(pParameter, &pParameterList->MediaInfoParameters, List) { printf("%s='", pParameter->pParameterIdentifier); PrintMediaInfo(pParameter->pMediaInfo, "", "'\n"); } } void PrintParameters(struct ParameterListTP* pParameterList, char* pPrefix) { struct ParameterTP* pParameter; list_for_each_entry(pParameter, &pParameterList->Parameters, List) { printf("%s%s=%s\n", pPrefix, pParameter->pParameterIdentifier, pParameter->pValue); } } enum CommandTP XLateCommand(char** ArgV) { # define CommandArgIndex 1 /* fprintf(stderr, "main: Command: %s\n", ArgV[CommandArgIndex] ); */ if( !strcmp( "LS", ArgV[CommandArgIndex] ) ) return LS; if( !strcmp( "MediaInfo", ArgV[CommandArgIndex] ) ) return MediaInfo; if( !strcmp( "MediaHandlerUuid", ArgV[CommandArgIndex] ) ) return MediaHandlerUuid; if( !strcmp( "PARAMETERS", ArgV[CommandArgIndex] ) ) return PARAMETERS; }