#include <stdio.h>
#include <string.h>
#include "tools.h"

void ParseSysLogConfig(void)
{
// awk '/file\(/ {print $2,$4$5}' /etc/syslog-ng/syslog-ng.conf

}

char* IndentMenuItem(const char* szString)
{
    char* szIndented = NULL;
    asprintf(&szIndented, "  %s", szString);
    return szIndented;
}

bool InEditMode(const char* ItemText, const char* ItemName, const char* ItemValue)
{
    bool bEditMode = true;
/*    // ugly solution to detect, if in edit mode
    char* value = strdup(ItemText);
    strreplace(value, ItemName, "");
    strreplace(value, ":\t", "");
    // for bigpatch
    strreplace(value, "\t", "");
    if (strlen(value) == strlen(ItemValue))
        bEditMode = false;
    free(value);*/
    return bEditMode;
}

char* UnindentMenuItem(const char* ItemText)
{
    return strchr(ItemText, '/');
}

void FormatThousands(char *pstrText, long long llSize)
{
   char strTmp[32];
   int i1,i2,m;

   sprintf(strTmp, "%lld", llSize);
   m=strlen(strTmp)%3;

   for(i1=0,i2=0;i1<m;i1++,i2++) pstrText[i1]=strTmp[i2];

   while(strTmp[i2]) {
      if(i1)
         pstrText[i1++]='.';
      for(m=0;m<3;m++) pstrText[i1++]=strTmp[i2++];
   }
   pstrText[i1]='\0';
}

bool ParseDirectory(char *Full, char *dir, char *file)
{
   if(!Full) {
      strcpy(dir, "/");
      strcpy(file, "");
   }
   else {
      const char *tmp=strrchr(Full, '/');
      if(tmp) {
         int n=(int)(tmp-Full);
         int nn=strlen(tmp)-1;
         strn0cpy(dir, Full, max(n, MaxFileName));
         strn0cpy(file, tmp+1, max(nn, MaxFileName)); 
      }
      else {
         strcpy(dir, "/"); //assume root, although it is most likely wrong
         strn0cpy(file, Full, MaxFileName);
      }
   }
   return true;
}
