console.c

Description du code

Fonctions d'affichage Compilateur LSD010

Code source ou contenu du fichier

  1. /*
  2.  * console.c : output (terminal and files) helper file
  3.  * Part of the compiler project for LSD10 language
  4.  * Gaudry Stéphane
  5.  * More information on http://www.gaudry.be/langages-lex-yacc-intro.html
  6.  */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #if(VERBOSE_LEVEL<=DEB_E)
  11. #include <errno.h>
  12. #endif
  13. #if(VERBOSE_LEVEL<=DEB_I)
  14. #include <time.h>
  15. #endif
  16.  
  17. //includes for the var args
  18. #include <stdarg.h>
  19. //end of var args includes
  20. #include "common.h"
  21. #include "graphVizHelper.h"
  22. #include "symbolsTableDataRepresentation.h"
  23.  
  24.  
  25. extern int lexLinesCount;
  26. extern char* yytext;
  27. extern int *yylineno;
  28. extern FILE *yyin;
  29. extern AstNode *rootNode;
  30. extern DebugInfo *debugInfo;
  31.  
  32. void printHTMLTree(FILE *htmlFile, AstNode *node, int depth);
  33. void printHTMLNode(FILE *htmlFile, AstNode *node, int depth);
  34. void printXMLTree(FILE *htmlFile, AstNode *node, int depth);
  35. void printXMLNode(FILE *htmlFile, AstNode *node, int depth);
  36. /**************************************************************/
  37. /**
  38.  * Generates Yacc error with custom message
  39.  * todo: 2 function; this is used only to call the yyerror function and producing a exit(EXIT_SUCCESS),
  40.  * and another to print KO with an exit(EXIT_FAILURE) on compiler inexpected bug (like allocation error)
  41.  * Exposed method
  42.  */
  43. void onError(char* errorMsg, char* compilerFile, int compilerLine, AstNode *node)
  44. {
  45. if(node!=NULL)
  46. {
  47. lexLinesCount=node->debug->line;
  48. //lexCharsCountBeforeToken=node->debug->line; todo : yylloc.first_line??
  49. debugInfo=node->debug;
  50. }
  51. yytext=NULL;
  52. #if(VERBOSE_LEVEL<=DEB_EXEC)
  53. printMsg(DEB_W, errorMsg, compilerFile, compilerLine);
  54. #endif
  55. yyerror(errorMsg);
  56. }
  57. void onNotForwardDeclarationError(AstNode *current, AstNode *found)
  58. {
  59. char errorStr[1024];//todo: minimize length
  60. char *str = errorStr;
  61. if(current!=found)
  62. {
  63. str,
  64. "Backward declaration failure for %s %s line %d char %d, possible forward declaration on %s %s line %d col %d",
  65. typeToString(current->type),
  66. current->info->name,
  67. current->debug->line,
  68. current->debug->linePsn,
  69.  
  70. typeToString(found->type),
  71. found->info->name,
  72. found->debug->line,
  73. found->debug->linePsn
  74. );
  75. }
  76. else
  77. {
  78. str,
  79. "Backward declaration failure for %s %s line %d col %d",
  80. typeToString(current->type),
  81. current->info->name,
  82. current->debug->line,
  83. current->debug->linePsn
  84. );
  85. }
  86. onError(str, __FILE__, __LINE__, current);
  87. }
  88. void onNotIntegerNotBooleanTypeError(AstNode *node, char *file, int line)
  89. {
  90. char errorStr[1024];//todo: minimize length
  91. char *str = errorStr;
  92. str,
  93. "Type check failure : %s or %s expected, but %s found for '%s' line %d col %d (compiler %s, line %d)",
  94. typeToString(AST_INTEGER_VAR_TYPE),
  95. typeToString(AST_BOOLEAN_VAR_TYPE),
  96. typeToString(node->info->computedType),
  97. node->info->name,
  98. node->debug->line,
  99. node->debug->linePsn,
  100. file,
  101. line
  102. );
  103. lexLinesCount=node->debug->line;
  104. yytext=NULL;
  105. yyerror(str);
  106. //failure for the parsed code, but success for the compiler (it must stop here)
  107. exit(EXIT_SUCCESS);
  108. }
  109. /**
  110.  * Generates Yacc error if a type is not recognized
  111.  * Exposed method
  112.  */
  113. void onUnrecognizedTypeError(int type, char* file, int line)
  114. {
  115. char errorStr[1024];//todo: minimize length
  116. sprintf(errorStr, "Unrecognized type=%s (%d) on %s line %d", typeToString(type), type, file, line);
  117. onError(errorStr, file, line, NULL);
  118. }
  119. /**
  120.  * Print custom message on stdout, depending on the Debug level
  121.  * Exposed method
  122.  */
  123. void printMsg(int msgType, char *msg, char *file, int line)
  124. {
  125. /*if(VERBOSE_LEVEL>msgType)return;*/
  126. switch(msgType)
  127. {
  128. case DEB_W :
  129. printf(";\n;\tWarning : '%s' On %s, Line %d\n;\t-------------------------------------------------------------\n", msg, file, line);
  130. break;
  131. case DEB_E :
  132. printf(";\n;\tError : '%s' On %s, Line %d\n;\t-------------------------------------------------------------\n", msg, file, line);
  133. break;
  134. case DEB_EXEC :
  135. printf("\n; %s\n",msg);
  136. break;
  137. default :
  138. printf("\n;\tMessage : '%s' On %s, Line %d\n", msg, file, line);
  139. break;
  140. }
  141. return;
  142. }
  143. /******************************************************************************/
  144.  
  145. void printDebugTree(char *htmlFileName, char *xmlFileName)
  146. {
  147.  
  148. FILE * htmlFile;
  149. time_t genTime = time(NULL);
  150. if(htmlFileName==NULL)htmlFileName=AST_HTML_FILE;
  151. if(xmlFileName==NULL)xmlFileName=AST_XML_FILE;
  152. htmlFile = fopen(htmlFileName, "w");
  153. if(htmlFile!=NULL)
  154. {
  155. printf("\n;\tPrinting AST into %s file ... (%s, col %d)", htmlFileName, __FILE__, __LINE__);
  156. fprintf(htmlFile, "<html><head><title>AST</title></head><body>\n");
  157. fprintf(htmlFile, "<h1>LSD010 AST</h1>\n");
  158. fprintf(htmlFile, "<p>Document généré le %s par le compilateur LSD0<sup>10</sup></p>", asctime(localtime(&genTime)));
  159. printHTMLTree(htmlFile, rootNode, 0);
  160. fprintf(htmlFile, "</body></html>\n");
  161. fclose(htmlFile);
  162.  
  163. #if(VERBOSE_LEVEL<=DEB_EXEC)
  164. printMsg(DEB_EXEC,"\t...OK HTML printed", __FILE__, __LINE__);
  165. #endif
  166. }
  167. else
  168. {
  169. #if(VERBOSE_LEVEL<=DEB_EXEC)
  170. printMsg(DEB_EXEC,"Printing AST into HTML file ... Can't open file", __FILE__, __LINE__);
  171. printMsg(DEB_E, (char *)strerror(errno), __FILE__, __LINE__);
  172. #endif
  173. }
  174. htmlFile = fopen(xmlFileName==NULL?AST_XML_FILE:xmlFileName, "w");
  175. if(htmlFile!=NULL)
  176. {
  177. printf("\n;\tPrinting AST into %s file ... (%s, col %d)", xmlFileName, __FILE__, __LINE__);
  178. fprintf(htmlFile, "<lsd010>\n");
  179. fprintf(htmlFile, "<![CDATA[\nDocument généré le %s par le compilateur LSD010\n]]>\n", asctime(localtime(&genTime)));
  180. printXMLTree(htmlFile, rootNode, 0);
  181. fprintf(htmlFile, "</lsd010>\n");
  182. fclose(htmlFile);
  183.  
  184. #if(VERBOSE_LEVEL<=DEB_EXEC)
  185. printMsg(DEB_EXEC,"\t...OK XML printed", __FILE__, __LINE__);
  186. #endif
  187. }
  188. else
  189. {
  190. #if(VERBOSE_LEVEL<=DEB_EXEC)
  191. printMsg(DEB_EXEC,"Printing AST into XML file ... Can't open file", __FILE__, __LINE__);
  192. printMsg(DEB_E, (char *)strerror(errno), __FILE__, __LINE__);
  193. #endif
  194. }
  195. }
  196. /**
  197.  * Generates an HTML file and an XML file with AST nodes.
  198.  * These files are generated on the current directory.
  199.  * An error message is displayed if a problem occurs on opening files
  200.  * Exposed method
  201.  */
  202. void printTree()
  203. {
  204. printDebugTree(NULL, NULL);
  205. }
  206.  
  207. //alternate row
  208. int altRowSTI=0;
  209. void printScopeStack(ScopeStack *scopeStack, FILE * htmlFile, int topItem)
  210. {
  211. if(scopeStack!=NULL)
  212. {
  213. int altRow=0;
  214. altRowSTI=0;
  215. if(topItem!=0)
  216. {
  217. htmlFile,
  218. //"<table width=\"100%%\">",
  219. "<table width=\"100%%\" border=\"1\" cellpadding=\"2\" cellspacing=\"1\" class=\"table\">"
  220. );
  221. htmlFile,
  222. "<thead><tr><td colspan=\"5\">Pile du symbole : %s</td></tr>",
  223. scopeStack->declarationNode->info->name
  224. );
  225. fprintf(htmlFile, "<tr><th>Profondeur</th><th>Portée</th><th>Type</th><th>Ligne</th><th>Col</th></tr>");
  226. fprintf(htmlFile, "</thead><tbody>");
  227. }
  228. htmlFile,
  229. (++altRow%2==0)? "<tr class=\"td\">": "<tr class=\"td2\">"
  230. );
  231. htmlFile,
  232. "<td>%d</td><td>%d</td><td>%s</td><td>%d</td><td>%d</td></tr>",
  233. scopeStack->declarationNode->info->scopeDepth,
  234. scopeStack->declarationNode->info->scopeId,
  235. typeToString(scopeStack->declarationNode->info->type),
  236. scopeStack->declarationNode->debug->line,
  237. scopeStack->declarationNode->debug->linePsn
  238. );
  239. printScopeStack(scopeStack->parentPtr, htmlFile, 0);
  240. if(topItem!=0)
  241. {
  242. fprintf(htmlFile, "</tbody></table>");
  243. }
  244. }
  245. }
  246. int printSymbolsTableHeader()
  247. {
  248. FILE * htmlFile;
  249. time_t genTime = time(NULL);
  250. char *htmlFileName=SYMBOLSTABLE_HTML_FILE;
  251. htmlFile = fopen(htmlFileName, "w");
  252. if(htmlFile==NULL)
  253. {
  254. return EXIT_FAILURE;
  255. }
  256. fprintf(htmlFile, "<html><head><title>Table des symboles</title></head><body>\n");
  257. fprintf(htmlFile, "<h1>Etats de la table des symboles LSD010</h1>\n");
  258. fprintf(htmlFile, "<p>Document généré le %s par le compilateur LSD0<sup>10</sup></p>", asctime(localtime(&genTime)));
  259.  
  260. fclose(htmlFile);
  261. return EXIT_SUCCESS;
  262. }
  263. int printSymbolsTableFooter()
  264. {
  265. //printSymbolsTableItem();
  266. FILE * htmlFile;
  267. //time_t genTime = time(NULL);
  268. char *htmlFileName=SYMBOLSTABLE_HTML_FILE;
  269. htmlFile = fopen(htmlFileName, "a+");
  270. if(htmlFile==NULL)
  271. {
  272. return EXIT_FAILURE;
  273. }
  274. fprintf(htmlFile, "\n</body></html>\n");
  275.  
  276. fclose(htmlFile);
  277. return EXIT_SUCCESS;
  278. }
  279. // first null index
  280. int startNull = INITIAL_INT;
  281. // @todo: define a astnodedebug as parameter to show where
  282. // this scope enter/exit was found
  283.  
  284. int printSymbolsTableItem(char *title)
  285. {
  286. if(declarations!=NULL)
  287. {
  288. FILE * htmlFile;
  289. //time_t genTime = time(NULL);
  290. char *htmlFileName=SYMBOLSTABLE_HTML_FILE;
  291. htmlFile = fopen(htmlFileName, "a+");
  292. if(htmlFile!=NULL)
  293. {
  294. fprintf(htmlFile, "<?php \n?><h2>%s (portée actuelle : %d)</h2>", title, scopeHelperGetCurrentScope());
  295. //fprintf(htmlFile, "<table width=\"100%%\" border=\"1\"><thead>");
  296. fprintf(htmlFile, "<?php \n?><table width=\"100%%\" border=\"1\" cellpadding=\"2\" cellspacing=\"1\" class=\"table\"><thead>");
  297. fprintf(htmlFile, "<tr><td>Index</td><td>Liste cha&icirc;née de <pre>SymTableEntry</pre></td></tr>");
  298. fprintf(htmlFile, "</thead><tbody>");
  299. int i;
  300. for(i=0;i<TABLES_SIZE;i++)
  301. {
  302. if(declarations[i]==NULL)
  303. {
  304. if(startNull==INITIAL_INT)
  305. {
  306. startNull=i;
  307. }
  308. }
  309. else
  310. {
  311. if(startNull!=-INITIAL_INT)
  312. {
  313. fprintf(htmlFile, ++altRowSTI%2==0?"<tr class=\"td\">":"<tr class=\"td2\">");
  314. if(startNull<-i-1)
  315. {
  316. fprintf(htmlFile, "<td>%d...%d</td><td>NULL</td></tr>", startNull, i-1);
  317. }
  318. else
  319. {
  320. fprintf(htmlFile, "<td>%d</td><td>NULL</td></tr>", i-1);
  321. }
  322. startNull = INITIAL_INT;
  323. }
  324. fprintf(htmlFile, ++altRowSTI%2==0?"<tr class=\"td\">":"<tr class=\"td2\">");
  325. fprintf(htmlFile, "<td>%d</td><td>",i);
  326. SymTableEntry *entry = declarations[i];
  327. while(entry!=NULL)
  328. {
  329. printScopeStack(entry->scopeStack, htmlFile, 1);
  330. entry = entry->next;
  331. }
  332. fprintf(htmlFile, "</td></tr>");
  333. }
  334. }
  335. if(startNull!=INITIAL_INT)
  336. {
  337. fprintf(htmlFile, ++altRowSTI%2==0?"<tr class=\"td\">":"<tr class=\"td2\">");
  338. if(startNull<i-1)
  339. {
  340. fprintf(htmlFile, "<td>%d...%d</td><td>NULL</td></tr>", startNull, i-1);
  341. }
  342. else
  343. {
  344. fprintf(htmlFile, "<td>%d</td><td>NULL</td></tr>", i-1);
  345. }
  346. startNull = INITIAL_INT;
  347. }
  348. fprintf(htmlFile, "</tbody></table>");
  349. fclose(htmlFile);
  350. return EXIT_SUCCESS;
  351. }
  352. }
  353. else
  354. {
  355. printMsg(DEB_EXEC,"-------------------------Symbols table is null", __FILE__, __LINE__);
  356. }
  357. return EXIT_FAILURE;
  358. }
  359. char *variableUsageToString(VariableUsage usage)
  360. {
  361. switch(usage)
  362. {
  363. case VAR_USAGE_NEVER:
  364. return "n'est jamais utilisée";
  365. break;
  366. case VAR_USAGE_SOMETIMES:
  367. return "est parfois utilisée";
  368. break;
  369. case VAR_USAGE_ALWAYS:
  370. return "est toujours utilisée";
  371. break;
  372. default:
  373. return "[Erreur (valeur hors norme)]";
  374. }
  375. }
  376. void printScopeUsage(ScopeStack *scopeStack)
  377. {
  378. if(scopeStack!=NULL)
  379. {
  380. "; %s(...) : la %s '%s' %s\n",
  381. scopeStack->functionNode==NULL?"Program":scopeStack->functionNode->info->name,
  382. scopeStack->declarationNode->type==NODE_TYPE_FUNCTION?"fonction":"variable",
  383. scopeStack->declarationNode->info->name,
  384. variableUsageToString(scopeStack->usage)
  385. );
  386. printScopeUsage(scopeStack->parentPtr);
  387. }
  388. }
  389. int printSymbolsUsage()
  390. {
  391. printf("\n;\n;Symbols usage\n");
  392. if(declarations!=NULL)
  393. {
  394. int i;
  395. for(i=0;i<TABLES_SIZE;i++)
  396. {
  397. if(declarations[i]!=NULL)
  398. {
  399. SymTableEntry *entry = declarations[i];
  400. while(entry!=NULL)
  401. {
  402. printScopeUsage(entry->scopeStack);
  403. entry = entry->next;
  404. }
  405. }
  406. }
  407. return EXIT_SUCCESS;
  408. }
  409. else
  410. {
  411. printMsg(DEB_EXEC,"Can't print it: Symbols table is null", __FILE__, __LINE__);
  412. }
  413. return EXIT_FAILURE;
  414. }
  415. void printScopeDebug(ScopeStack *scopeStack, int tableId, int stackId)
  416. {
  417. if(scopeStack!=NULL)
  418. {
  419. "\n; Table[%3d][%2d]= %7s %10s line %3d, col %3d; scope %d; %s function, ",
  420. tableId,
  421. stackId,
  422. typeToString(scopeStack->declarationNode->info->type),
  423. scopeStack->declarationNode->info->name,
  424. scopeStack->declarationNode->debug->line,
  425. scopeStack->declarationNode->debug->linePsn,
  426. scopeStack->declarationNode->info->scopeId,
  427. scopeStack->functionNode==NULL?"No ":scopeStack->functionNode->info->name
  428. );
  429. printScopeDebug(scopeStack->parentPtr, tableId, ++stackId);
  430. }
  431. }
  432. int printSymbolsTableDebug(char*file, int line)
  433. {
  434. printMsg(DEB_EXEC,"-------------------------Symbols table state", file, line);
  435. if(declarations!=NULL)
  436. {
  437. int i;
  438. for(i=0;i<TABLES_SIZE;i++)
  439. {
  440. if(declarations[i]!=NULL)
  441. {
  442. SymTableEntry *entry = declarations[i];
  443. while(entry!=NULL)
  444. {
  445. printScopeDebug(entry->scopeStack, i, 0);
  446. entry = entry->next;
  447. }
  448. }
  449. }
  450. return EXIT_SUCCESS;
  451. }
  452. else
  453. {
  454. printMsg(DEB_EXEC,"-------------------------Symbols table is null", __FILE__, __LINE__);
  455. }
  456. return EXIT_FAILURE;
  457. }
  458. /******************************************************************************/
  459. /**
  460.  * Prints an AST node into the html file
  461.  * Internal business
  462.  */
  463. void printHTMLNode(FILE *file, AstNode *node, int depth)
  464. {
  465. if(node!=NULL)
  466. {
  467. fprintf(file, "<li><b>Noeud :</b> %s (%d)\n", typeToString(node->type), node->type);
  468. if(node->info!=NULL)
  469. {
  470. file,
  471. "<br /><b>Type :</b> %s <br /><b>Nom :</b> %s<br /><b>Valeur :</b> %d\n",
  472. typeToString(node->info->type),
  473. node->info->name,
  474. node->info->value
  475. );
  476. }else fprintf(file, "<li>Info null (%d)\n",depth);
  477. fprintf(file, "</li>\n");/*char *name, int type, int value
  478. while(node->rightBrother!=NULL)
  479. {
  480. printNode(file, node->rightBrother, depth);
  481. }*/
  482. }else fprintf(file, "<li>Noeud null (%d)</li>\n",depth);
  483. }
  484. /**
  485.  * Prints the AST into the html file
  486.  * Internal business
  487.  */
  488. void printHTMLTree(FILE *file, AstNode *node, int depth)
  489. {
  490. if(node!=NULL)
  491. {
  492. fprintf(file, "<ul>\n");
  493. printHTMLNode(file, node, depth);
  494. printHTMLTree(file, node->left, depth+1);
  495. printHTMLTree(file, node->right, depth+1);
  496. fprintf(file, "</ul>\n");
  497. }else fprintf(file, "<ul><li>Noeud null (%d)</li></ul>\n",depth);
  498.  
  499. }/**
  500.  * Prints an AST node into the xml file
  501.  * Internal business
  502.  */
  503. void printXMLNode(FILE *file, AstNode *node, int depth)
  504. {
  505. if(node!=NULL)
  506. {
  507. fprintf(file, "%s<depth>%d</depth>", typeToString(node->type), depth);
  508. fprintf(file, "<memaddress>%p</memaddress>", node);
  509. if(node->parent!=NULL)
  510. {
  511. fprintf(file, "<parent><type>%s</type><pmemaddress>%p</pmemaddress></parent>", typeToString(node->parent->type), node->parent);
  512. }else
  513. {
  514. fprintf(file, "<parent>NULL</parent>");
  515. }
  516. if(node->info!=NULL)
  517. {
  518. file,
  519. "<info><rightmemaddress>%p</rightmemaddress><leftmemaddress>%p</leftmemaddress><infotype>%s</infotype><infoname>%s</infoname><infoval>%d</infoval></info>\n",
  520. node->right,
  521. node->left,
  522. typeToString(node->info->type),
  523. node->info->name,
  524. node->info->value,
  525. depth
  526. );
  527. }
  528. }
  529. else fprintf(file, "null");
  530. }/**
  531.  * Prints the AST into the xml file
  532.  * Internal business
  533.  */
  534. void printXMLTree(FILE *file, AstNode *node, int depth)
  535. {
  536. fprintf(file, "<node%d>\n", depth);
  537. printXMLNode(file, node, depth);
  538. if(node!=NULL)
  539. {
  540. printXMLTree(file, node->left, depth+1);
  541. printXMLTree(file, node->right, depth+1);
  542. }
  543. fprintf(file, "</node%d>\n", depth);
  544.  
  545. }
  546. /******************************************************************************/
  547. /**
  548.  * Returns a human readable string from a given type constant value
  549.  * Expected : one of the DEB_xxx constants
  550.  * Exposed method
  551.  */
  552. char* debugLevelToString(int type)
  553. {
  554. char *str = NULL;
  555. switch(type)
  556. {
  557. case DEB_L:
  558. str = "Lex tokens";
  559. break;
  560. case DEB_Y:
  561. str = "Yacc parsing";
  562. break;
  563. case DEB_O:
  564. str = "Misc files";
  565. break;
  566. case DEB_I:
  567. str = "Information messages";
  568. break;
  569. case DEB_P:
  570. str = "P-code generation";
  571. break;
  572. case DEB_W:
  573. str = "Warning messages";
  574. break;
  575. case DEB_EXEC:
  576. str = "Minimum excution messages";
  577. break;
  578. case DEB_E:
  579. str = "Error messages";
  580. break;
  581. case DEB_NONE:
  582. str = "Silent (no other output than p-code, and OK or KO)";
  583. break;
  584. default:
  585. str = "undefined";
  586. #if(VERBOSE_LEVEL<=DEB_W)
  587. char str[1024];//todo: minimize length
  588. sprintf(str, "Undefined constant value '%d'", type);
  589. printMsg(DEB_W, str, __FILE__, __LINE__);
  590. #endif
  591. break;
  592. }
  593. return str;
  594. }
  595. /******************************************************************************/
  596. /**
  597.  * Generates p-code output on stdout,
  598.  * and (if GENERATE_PCODE_FILE is set to 1) write it into a file
  599.  * source http://www.pps.jussieu.fr/~rifflet/enseignements/LC4/vararg.html
  600.  * Only one digit format allowed (examples %s, %d, %f, %l)
  601.  */
  602. void printPCode(FILE* pcodeFile, char *format, ...)
  603. {
  604. if(PCODE_GENERATION_BYPASS)
  605. {
  606. return;
  607. }
  608. va_list p_list;
  609. int i;
  610. long l;
  611. double f;
  612. char *s;
  613. int validFormat;
  614. validFormat=0;
  615.  
  616. va_start(p_list, format);
  617.  
  618. #if(VERBOSE_LEVEL==DEB_NONE)
  619. if(*format!=';')
  620. {
  621. #endif
  622.  
  623. while (*format != 0) {
  624. switch(*format){
  625. case '%' :
  626. validFormat=1;
  627. break;
  628. case 'd': /* type int */
  629. if(validFormat==1)
  630. {
  631. i = va_arg(p_list, int);
  632. if(pcodeFile!=NULL){
  633. fprintf(pcodeFile, "%d", i);
  634. }
  635. printf("%d", i);
  636. }
  637. break;
  638. case 'l': /* type long */
  639. if(validFormat==1)
  640. {
  641. l = va_arg(p_list, long);
  642. if(pcodeFile!=NULL){
  643. fprintf(pcodeFile, "%ld", l);
  644. }
  645. printf("%ld", l);
  646. }
  647. break;
  648. case 'f' : /* type double */
  649. if(validFormat==1)
  650. {
  651. f = va_arg(p_list, double);
  652. if(pcodeFile!=NULL){
  653. fprintf(pcodeFile, "%lf", f);
  654. }
  655. printf("%lf", f);
  656. }
  657. break;
  658. case 's' : /* type char[] */
  659. if(validFormat==1)
  660. {
  661. s = va_arg(p_list, char *);
  662. if(pcodeFile!=NULL){
  663. fprintf(pcodeFile, "%s", s);
  664. }
  665. printf("%s", s);
  666. }
  667. break;
  668. // case 'c' : /* type char * */
  669. // if(validFormat==1)
  670. // {
  671. // s = va_arg(p_list, char *);
  672. // if(pcodeFile!=NULL){
  673. // fprintf(pcodeFile, "%s", s);
  674. // }
  675. // printf("%s", s);
  676. // }
  677. // break;
  678. default : /* type char[] */
  679. validFormat=0;
  680. break;
  681. }
  682. if(validFormat==0)
  683. {
  684. printf("%c",format[0]);
  685. if(pcodeFile!=NULL){
  686. fprintf(pcodeFile, "%c",format[0]);
  687. }
  688. }
  689. format++;
  690. }
  691. #if(VERBOSE_LEVEL==DEB_NONE)
  692. }
  693. #endif
  694. va_end(p_list);
  695. }

Autres extraits de codes en c

  • DisquetteDispo Vérifier la disponibilité du lecteur de disquette
  • Suite de Fibonacci Exemple d'itération en C
  • Suite de Fibonacci Exemple de récursion en C
  • astDataRepresentation.h Représentation de données de l'arbre syntaxique abstrait Compilateur LSD010
  • ast.h Arbre syntaxique abstrait Compilateur LSD010
  • ast.c Arbre syntaxique abstrait Compilateur LSD010
  • symbolsTableDataRepresentation.h Représentation de données de la table des symboles Compilateur LSD010
  • symbolsTable.h Fonctions de gestion de la table des symboles Compilateur LSD010
  • symbolsTable.c Fonctions de gestion de la table des symboles Compilateur LSD010
  • hashCode.h Fonctions de hachage Compilateur LSD010
  • hashCode.c Fonctions de hachage Compilateur LSD010
  • scopeStack.h Fonctions de gestion d'une pile de portées Compilateur LSD010
  • scopeStack.c Fonctions de gestion d'une pile de portées Compilateur LSD010
  • scopeHelper.h Fonctions de gestion de la portée courante Compilateur LSD010
  • console.h Fonctions d'affichage Compilateur LSD010
  • console.c Fonctions d'affichage Compilateur LSD010
  • graphVizHelper.h Génération d'une image d'un arbre syntaxique abstrait.
    Classe d'intégration de l'outil GraphViz. Compilateur LSD010
  • graphVizHelper.c Génération d'une image d'un arbre syntaxique abstrait.
    Classe d'intégration de l'outil GraphViz. Compilateur LSD010
  • common.h Définition des constantes et variables communes Compilateur LSD010
  • pcode.c Génération de p-code Compilateur LSD010
  • pcode.h Génération de p-code Compilateur LSD010
  • Tous les extraits

Document créé le 05/10/2009, dernière modification le 28/10/2018
Source du document imprimé : https://www.gaudry.be/sniplet-rf-lsd010/project/source/console.c.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.