daily pastebin goal
24%
SHARE
TWEET

DEnumer

a guest May 15th, 2018 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include "NephTable.h"
  4.  
  5. char pNameBuffer[255];
  6. char pPrefixBuffer[255];
  7. int nColumn;
  8. int nItemCodeColumn;
  9. int nRecords;
  10. bool bSpecial;
  11.  
  12. void __fastcall ReplaceSpace(char* szText)
  13. {
  14.     if(szText == NULL)
  15.         return;
  16.     char* pText = &szText[0];
  17.     while(*pText != 0x00)
  18.     {
  19.         if(*pText == 0x20 || *pText == 0x2D)
  20.            *pText = '_';
  21.  
  22.         if(*pText == 0x27)
  23.         {
  24.            char* pNewText = pText;
  25.            char* pTemp = pText;
  26.            while(*pNewText != 0x00 || *pTemp != 0x00)
  27.            {
  28.                pNewText++;
  29.                *pTemp = *pNewText;
  30.                pTemp++;
  31.            }
  32.         }
  33.         pText++;
  34.     }
  35. }
  36.  
  37. DWORD __fastcall MakeItemCode(char* sz)
  38. {
  39.     if(strlen(sz) == 3)
  40.         strcat(sz," ");
  41.     return *(DWORD*)(sz);
  42. }
  43.  
  44. int main()
  45. {
  46.     SetConsoleTitle("DEnumer v 0.5 by Necrolis");
  47.     NephTableInit();
  48.     printf("Please Input The Enum Table Data In the Format:\n");
  49.     printf("[FILE NAME] [ENUM PREFIX] [COLUMN NUMBER TO ENUM] [NUMBER OF RECORDS TO ENUM]\n");
  50.     printf("=RECORD SWITCH= -1: Auto Line Count -2: ItemCode Translator\n");
  51.     scanf("%s %s %d %d",pNameBuffer,pPrefixBuffer,&nColumn,&nRecords);
  52.     if(nColumn <= 0)
  53.     {
  54.        printf("WARNING: Column Number Must Be Greater Than 0, Default Selected\n");
  55.        nColumn = 1;
  56.     }
  57.     if(nRecords == -2)
  58.     {
  59.         printf("Please Enter The Item Code Column:\n");
  60.         scanf("%d",&nItemCodeColumn);
  61.         bSpecial = true;
  62.     }
  63.     printf("Creating File D2%sEnum.h\n",pPrefixBuffer);
  64.     Table* pTable = LoadTable(pNameBuffer,'\t','\n');
  65.     if(pTable == NULL)
  66.     {
  67.        printf("WARNING: Couldn't Find or Load: %s\n EXITING\n",pNameBuffer);
  68.        system("PAUSE");
  69.        return EXIT_FAILURE;
  70.     }
  71.     printf("File Loaded\n");
  72.     if(nRecords == -1 || nRecords == -2)
  73.        nRecords = pTable->nLines;
  74.     int nUnusedCount = nRecords - pTable->nLines;
  75.     sprintf(pNameBuffer,"D2%sEnum.h",pPrefixBuffer);
  76.     FILE* pOutput = fopen(pNameBuffer,"w+");
  77.     if(pOutput == NULL)
  78.     {
  79.        printf("WARNING: Couldn't Create: %s\nEXITING\n",pNameBuffer);
  80.        system("PAUSE");
  81.        return EXIT_FAILURE;
  82.     }
  83.     printf("Header File Created\n");
  84.     strupr(pPrefixBuffer);
  85.     fprintf(pOutput,"#ifndef __D2%s__\n#define __D2%s__\n\nenum D2%s\n{\n",pPrefixBuffer,pPrefixBuffer,pPrefixBuffer);
  86.     printf("Header File Inited\n");
  87.     if(bSpecial)
  88.     {
  89.         for(int i = 1; i < nRecords; i++)
  90.         {
  91.             if(i >= pTable->nLines)
  92.                break;
  93.             char* pCell = pTable->ptLines[i]->ptCell[nColumn - 1];
  94.             char* pCodeCell = pTable->ptLines[i]->ptCell[nItemCodeColumn - 1];
  95.             if(pCell == NULL || pCodeCell == NULL)
  96.                break;
  97.             ReplaceSpace(pCell);
  98.             if(i + 1 == nRecords && nUnusedCount < 1)
  99.                 fprintf(pOutput,"\t%s_%s = 0x%02X\t\t\t// %s\n",pPrefixBuffer,strupr(pCell),MakeItemCode(pCodeCell),pCodeCell);
  100.             else
  101.                 fprintf(pOutput,"\t%s_%s = 0x%02X,\t\t\t// %s\n",pPrefixBuffer,strupr(pCell),MakeItemCode(pCodeCell),pCodeCell);
  102.         }
  103.     }
  104.     else
  105.     {
  106.         for(int i = 1; i < nRecords; i++)
  107.         {
  108.             if(i >= pTable->nLines)
  109.                break;
  110.             char* pCell = pTable->ptLines[i]->ptCell[nColumn - 1];
  111.             if(pCell == NULL)
  112.                break;
  113.             ReplaceSpace(pCell);
  114.             if(i + 1 == nRecords && nUnusedCount < 1)
  115.                 fprintf(pOutput,"\t%s_%s = 0x%02X\t\t\t// %d\n",pPrefixBuffer,strupr(pCell),i - 1,i - 1);
  116.             else
  117.                 fprintf(pOutput,"\t%s_%s = 0x%02X,\t\t\t// %d\n",pPrefixBuffer,strupr(pCell),i - 1,i - 1);
  118.         }
  119.         printf("Processing\n");
  120.         for(int x = pTable->nLines; x < pTable->nLines + nUnusedCount; x++)
  121.         {
  122.             if(x + 1 == pTable->nLines + nUnusedCount)
  123.                 fprintf(pOutput,"\t%s_UNUSED_%d = 0x%02X\t\t\t// %d\n",pPrefixBuffer,x,x,x);
  124.             else
  125.                 fprintf(pOutput,"\t%s_UNUSED_%d = 0x%02X,\t\t\t// %d\n",pPrefixBuffer,x,x,x);
  126.         }
  127.     }
  128.     fprintf(pOutput,"};\n\n#endif");
  129.     printf("Processing...\n");
  130.     fclose(pOutput);
  131.     FreeTable(pTable);
  132.     NephTableEnd();
  133.     printf("Finished\n");
  134.     system("PAUSE");
  135.     return EXIT_SUCCESS;
  136. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top