Wicri:Dilib source, module Wicri, commande WicriExpandApiFromList : Différence entre versions
De Wicri Outils
imported>Jacques Ducloy (→Code source) |
imported>Jacques Ducloy |
||
Ligne 12 : | Ligne 12 : | ||
#include <getopt.h> | #include <getopt.h> | ||
#include "SxmlNode.h" | #include "SxmlNode.h" | ||
+ | |||
+ | extern char *optarg; | ||
+ | extern int optind; | ||
+ | int getopt(); | ||
+ | |||
+ | char *apiAction; | ||
int proceedWiki(SxmlNode *wiki) | int proceedWiki(SxmlNode *wiki) | ||
Ligne 33 : | Ligne 39 : | ||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||
{ | { | ||
+ | int cOption; | ||
SxmlNode *docInput; | SxmlNode *docInput; | ||
+ | |||
+ | while((cOption=getopt(argc,argv,"a:"))!=EOF) | ||
+ | {switch (cOption) | ||
+ | { | ||
+ | case 'a': | ||
+ | apiAction=optarg; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
while ((docInput=SxmlInputNextDocumentElement())) | while ((docInput=SxmlInputNextDocumentElement())) | ||
{ | { |
Version du 22 juin 2020 à 15:18
Code source
/* -*- coding: utf-8 -*- */
/*
WicriExpandApiFromList.c
*/
#include <stdio.h> /* for printf */
#include <stdlib.h> /* for exit */
#include <getopt.h>
#include "SxmlNode.h"
extern char *optarg;
extern int optind;
int getopt();
char *apiAction;
int proceedWiki(SxmlNode *wiki)
{
char *name;
char *url;
static Buffer *bufUrl=NULL;
if (!bufUrl) bufUrl=NewBuffer();
BufferStrcpy (bufUrl, "https://lorexplor.istex.fr/Wicri/");
BufferStrcat (bufUrl, SxmlLeafText(SxmlGetFirstChildByTagName(wiki, "url")));
BufferStrCat (bufUrl, "/api.php?action=query&format=xml&");
name=SxmlLeafText(SxmlGetFirstChildByTagName(wiki, "name"));
printf ("%s\t%s\n", name, BufferString(bufUrl));
return 0;
}
int main(int argc, char **argv)
{
int cOption;
SxmlNode *docInput;
while((cOption=getopt(argc,argv,"a:"))!=EOF)
{switch (cOption)
{
case 'a':
apiAction=optarg;
break;
}
}
}
while ((docInput=SxmlInputNextDocumentElement()))
{
if(SxmlNodeHasName(docInput,"wiki"))
{
proceedWiki(docInput);
}
}
}
Mise en œuvre
La suite de commande ci-dessous range dans un répertoire testDilib le fichier WicriExpandApiFromList.c
WicriGetPage -l wicri-outils.fr -p "Wicri:Dilib source, module Wicri, commande WicriExpandApiFromList" \
| MediaWikiExtractSources -w | HfdStoreFile
- Simple test
Pour tester la commande en local, faire :
gcc testDilib/WicriExpandApiFromList.c $DILIB_CC -o testDilib/WicriExpandApiFromList
cat myPmc_resultFile.xml \
|NlmPmc2Sxml \
| Utf8FromHexEntity \
| SxmlUnIndent \
| importNlm/NlmPmc2Wicri