Nuvola apps important.png Attention, suite à une analyse de sécurité, les liens vers quelques serveurs d'exploration sont désactivés.

-

Wicri:Source MediaWikiTableElemChimie.c

De Wicri Terre
/*   -*- coding: utf-8 -*-  */
/***********************************************************************
*
*               Module   : MediaWiki
*               Fichier  : MediaWikiTableElemChimie.c
*               Auteur   : Jacques Ducloy
*               Date     : Décembre 2016
*
************************************************************************
*
* Copyleft 2016 LorExplor 
* 
************************************************************************/
#include <stdio.h>     /* for printf */
#include <stdlib.h>    /* for exit */
#include <getopt.h>
#include "StrDict.h"
#include "Buffer.h"
#include "SxmlNode.h"

StrDict *wikiLinkDict;
StrDict *serverLinkDict;
StrDict *numberDocDict;
StrDict *elemCodeToSerieDict;
StrDict *elemSerieToStyleDict;
Buffer *bufPath;

int getopt();
extern char *optarg; 

char *wikiCode;
char *areaCode;
char *indexCode;

int highValue;

char *getColor(char *code, char *type)
{
  char *serie;
  SxmlNode *nodeListColor;
  char *nodeListColorStr;
  SxmlNode *colorNode;
  serie=StrDictSearch(elemCodeToSerieDict, code);
  if (!serie) return NULL;
  nodeListColorStr=StrDictSearch(elemSerieToStyleDict, serie);
  if (!nodeListColorStr) return NULL;
  nodeListColor=SxmlFromString(nodeListColorStr);
  colorNode=SxmlGetFirstChildByTagName(nodeListColor, type);
  if (!colorNode)return NULL;
  return SxmlLeafText(colorNode);
}

void printComposant (char *code, char *rang)
{
  char *link;
  char * number;
  char *linkServer;
  char *color;
  char *colorRef;
  int numInt;
  int relativeNumber;

  printf("|style=\"text-align:center;");
  link=StrDictSearch(wikiLinkDict, code);
  number=StrDictSearch(numberDocDict, code);
  if (!(link&&number))
    {
      color=getColor(code, "light");
      if (color) printf("border:2px dotted #%s;", color);
      else printf("border:2px dotted;");
      printf("\"|%s", code);
      printf("&lt;sup&gt;&amp;nbsp;%s&lt;/sup&gt;\n", rang);
      return;
    }

  numInt=atoi(number);
  relativeNumber=(numInt*100)/highValue;

  if(relativeNumber<10)
    {
      color=getColor(code, "light");
      if (color) printf("border:2px solid #%s;", color);
      else printf("border:2px;");
    }
    else if(relativeNumber<20)
    {
      color=getColor(code, "light");
      if (color) printf("border:4px solid #%s;", color);
      else printf("border:2px;");
    }
    else if(relativeNumber<30)
    {
      color=getColor(code, "light");
      if (color) printf("border:6px solid #%s;", color);
      else printf("border:2px;");
    }
    else if(relativeNumber<40)
    {
      color=getColor(code, "light");
      if (color) printf("border:2px solid #%s;background-color:#%s;", color, color);
      else printf("border:2px;");
    }
    else if(relativeNumber<50)
      {
      color=getColor(code, "light");
      colorRef=getColor(code, "ref");
      if (color&&colorRef) printf("border:2px solid #%s;background-color:#%s;", colorRef, color);
      else printf("border:2px;");
    }
    else 
      {
      color=getColor(code, "ref");
      colorRef=getColor(code, "strong");
      if (color&&colorRef) printf("border:2px solid #%s;background-color:#%s;", colorRef, color);
      else printf("border:2px;");
    }

  printf("\"|");

  linkServer=StrDictSearch(serverLinkDict, code);

  if(relativeNumber>50) printf("'''");
  printf("[[%s|%s]]", link, code);
  if(relativeNumber>50) printf("'''");

  printf("&lt;sup&gt;&amp;nbsp;%s&lt;/sup&gt;", rang);
  if (number) printf ("&lt;br/&gt;({{Explor lien |wiki=%s |area=%s |flux=    Main   |étape=   Exploration   |type=    indexItem   |index=    Mesh.i   |clé=%s   |texte=%s}})", wikiCode, areaCode, linkServer, number);
  else printf ("&lt;br/&gt;&amp;nbsp;");
  printf("\n");
}

int main(int argc, char **argv)
{
  int cOption;

  wikiLinkDict=NewStrDict();
  serverLinkDict=NewStrDict();
  numberDocDict=NewStrDict();
  bufPath=NewBuffer();
  BufferStrcpy(bufPath, getenv("DILIB"));
  BufferStrcat(bufPath, "/Data/Wicri/Terre/chimieSerieToStyle.dict");
  elemSerieToStyleDict=StrDictFromFile(BufferString(bufPath));
  BufferStrcpy(bufPath, getenv("DILIB"));
  BufferStrcat(bufPath, "/Data/Wicri/Terre/chimieElementCodeToSerie.dict");
  elemCodeToSerieDict=StrDictFromFile(BufferString(bufPath));

  wikiCode="Wicri/Terre";

  while((cOption=getopt(argc,argv,"a:"))!=EOF) 
    {
      {switch (cOption)
	  { 
	  case 'a':
	    areaCode=optarg;
	    break;
	  }
      }
    }

  highValue=0;

  while (SxmlInputGetRecord())
    {
      char *codeKey;
      char *linkWiki;
      char *linkServer;
      char * number;
      int numberValue;
      codeKey=SxmlInputRecordKey;
      linkWiki=SxmlGetFirstText(SxmlNextSibling(SxmlFirstChild(SxmlInputRecord)));
      if (linkWiki) StrDictAddNewDatum(wikiLinkDict, strdup(codeKey), strdup(linkWiki));
      linkServer=SxmlGetFirstText(SxmlNextSibling(SxmlNextSibling(SxmlFirstChild(SxmlInputRecord))));
      if (linkServer) StrDictAddNewDatum(serverLinkDict, strdup(codeKey), strdup(linkServer));
      number=SxmlGetFirstText(SxmlLastChild(SxmlInputRecord));
      if (number) 
	{
	  StrDictAddNewDatum(numberDocDict, strdup(codeKey), strdup(number));
	  numberValue=atoi(number);
	  if (highValue < numberValue) highValue=numberValue;
	}
    }
  printf("{|\n");
  printf("|-\n");
  printComposant ("H", "1");
  printf("|colspan=\"16\" style=\"border-style:none;\"|&amp;nbsp;\n");
  printComposant ("He", "2");
  printf("|-\n");
  printComposant ("Li", "3");
  printComposant ("Be", "4");
  printf("|colspan=\"10\"  style=\"border-style:none;\"|&amp;nbsp;\n");
  printComposant ("B", "5");
  printComposant ("C", "6");
  printComposant ("N", "7");
  printComposant ("O", "8");
  printComposant ("F", "9");
  printComposant ("Ne", "10");
  printf("|-\n");
  printComposant ("Na", "11");
  printComposant ("Mg", "12");
  printf("|colspan=\"10\"  style=\"border-style:none;\"|&amp;nbsp;\n");
  printComposant ("Al", "13");
  printComposant ("Si", "14");
  printComposant ("P", "15");
  printComposant ("S", "16");
  printComposant ("Cl", "17");
  printComposant ("Ar", "18");
  printf("|-\n");
  printComposant ("K", "19");
  printComposant ("Ca", "20");
  printComposant ("Sc", "21");
  printComposant ("Ti", "22");
  printComposant ("V", "23");
  printComposant ("Cr", "24");
  printComposant ("Mn", "25");
  printComposant ("Fe", "26");
  printComposant ("Co", "27");
  printComposant ("Ni", "28");
  printComposant ("Cu", "29");
  printComposant ("Zn", "30");
  printComposant ("Ga", "31");
  printComposant ("Ge", "32");
  printComposant ("As", "33");
  printComposant ("Se", "34");
  printComposant ("Br", "35");
  printComposant ("Kr", "36");
  printf("|-\n");
  printComposant ("Kr", "37");
  printComposant ("Rb", "38");
  printComposant ("Sr", "39");
  printComposant ("Zr", "40");
  printComposant ("Nb", "41");
  printComposant ("Mo", "42");
  printComposant ("Tc", "43");
  printComposant ("Ru", "44");
  printComposant ("Rh", "45");
  printComposant ("Pd", "46");
  printComposant ("Ag", "47");
  printComposant ("Cd", "48");
  printComposant ("In", "49");
  printComposant ("Sn", "50");
  printComposant ("Sb", "51");
  printComposant ("Te", "52");
  printComposant ("I", "53");
  printComposant ("Xe", "54");
  printf("|-\n");
  printComposant ("Cs", "55");
  printComposant ("Ba", "56");
  printf("| * \n");
  printComposant ("Hf", "72");
  printComposant ("Ta", "73");
  printComposant ("W", "74");
  printComposant ("Re", "75");
  printComposant ("Os", "76");
  printComposant ("Ir", "77");
  printComposant ("Pt", "78");
  printComposant ("Au", "79");
  printComposant ("Hg", "80");
  printComposant ("Ti", "81");
  printComposant ("Pb", "82");
  printComposant ("Bi", "83");
  printComposant ("Po", "84");
  printComposant ("At", "85");
  printComposant ("Rn", "86");
  printf("|-\n");
  printComposant ("Fr", "87");
  printComposant ("Ra", "88");
  printf("| ** \n");
  printComposant ("Rf", "104");
  printComposant ("Db", "105");
  printComposant ("Sg", "106");
  printComposant ("Bh", "107");
  printComposant ("Hs", "108");
  printComposant ("Mt", "109");
  printComposant ("Ds", "110");
  printComposant ("Rg", "111");
  printComposant ("Cn", "112");
  printf("|-\n");
  printf("|colspan=\"3\"  style=\"border-style:none;\"|&amp;nbsp;* Lanthanides\n");
  printComposant ("La", "57");
  printComposant ("Ce", "58");
  printComposant ("Pr", "59");
  printComposant ("Nd", "60");
  printComposant ("Pm", "61");
  printComposant ("Sm", "62");
  printComposant ("Eu", "63");
  printComposant ("Gd", "64");
  printComposant ("Tb", "65");
  printComposant ("Dy", "66");
  printComposant ("Ho", "67");
  printComposant ("Er", "68");
  printComposant ("Tm", "69");
  printComposant ("Yb", "70");
  printComposant ("Lu", "71");
  printf("|-\n");
  printf("|colspan=\"3\"  style=\"border-style:none;\"|&amp;nbsp;** Actinides\n");
  printComposant ("Ac", "89");
  printComposant ("Th", "90");
  printComposant ("Pa", "91");
  printComposant ("U",  "92");
  printComposant ("Np", "93");
  printComposant ("Pu", "94");
  printComposant ("Am", "95");
  printComposant ("Cm", "96");
  printComposant ("Bk", "97");
  printComposant ("Cf", "98");
  printComposant ("Es", "99");
  printComposant ("Fm", "100");
  printComposant ("Md", "101");
  printComposant ("No", "102");
  printComposant ("Lr", "103");
  printf("|-\n");
  printf("|}\n");
  exit(EXIT_SUCCESS);
}