showmsg.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "showmsg.h"
  5. char tmp_output[1024] = {"\0"};
  6. int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
  7. /*
  8. _ShowMessage MUST be used instead of printf as of 10/24/2004.
  9. Return: 0 = Successful, 1 = Failed.
  10. */
  11. // int ret = 0;
  12. char prefix[40];
  13. char *output;
  14. if (strlen(string) <= 0) {
  15. ShowError("Empty string passed to ShowMessage().\n");
  16. return 1;
  17. }
  18. switch (flag) {
  19. case MSG_STATUS: //Bright Green (To inform about good things)
  20. strcpy(prefix,"\033[1;32m[Status]\033[0;0m:");
  21. break;
  22. /* //Do we really need this now? [MC Cameri]
  23. case MSG_SQL: //Bright Violet (For dumping out anything related with SQL)
  24. strcpy(prefix,"\033[1;35m[SQL]\033[0;0m:");
  25. break;
  26. */
  27. case MSG_INFORMATION: //Bright White (Variable information)
  28. strcpy(prefix,"\033[1;29m[Info]\033[0;0m:");
  29. break;
  30. case MSG_NOTICE: //Bright White (Less than a warning)
  31. strcpy(prefix,"\033[1;29m[Notice]\033[0;0m:");
  32. break;
  33. case MSG_WARNING: //Bright Yellow
  34. strcpy(prefix,"\033[1;33m[Warning]\033[0;0m:");
  35. break;
  36. case MSG_ERROR: //Bright Red (Regular errors)
  37. strcpy(prefix,"\033[1;31m[Error]\033[0;0m:");
  38. break;
  39. case MSG_FATALERROR: //Bright Red (Fatal errors, abort(); if possible)
  40. strcpy(prefix,"\033[1;31m[Fatal Error]\033[0;0m:");
  41. break;
  42. default:
  43. ShowError("In function _ShowMessage() -> Invalid flag passed.\n");
  44. return 1;
  45. }
  46. output = (char*)malloc(sizeof(char)*(strlen(prefix)+strlen(string)+2)); // +2: space and a \0
  47. if (output == NULL) {
  48. return 1;
  49. // abort(); // Kill server? Deadly
  50. }
  51. strcpy(output,prefix);
  52. strcpy(output," ");
  53. strcat(output,string);
  54. printf(output);
  55. fflush(stdout);
  56. /*
  57. if ((core_config.debug_output_level > -1) && (flag >= core_config.debug_output_level)) {
  58. FILE *fp;
  59. fp=fopen(OUTPUT_MESSAGES_LOG,"a");
  60. if (fp == NULL) {
  61. printf("\033[1;31m[Error]\033[0;0m: Could not open \033[1;29m%s\033[0;0m, file not found.\n",OUTPUT_MESSAGES_LOG);
  62. fflush(stdout);
  63. return;
  64. }
  65. StripColor(output);
  66. strcpy(output,"\r");
  67. fwrite(output,strlen(output),1,fp);
  68. fclose(fp);
  69. }
  70. */
  71. return 0;
  72. }