Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include "NephTable.h"
- char pNameBuffer[255];
- char pPrefixBuffer[255];
- int nColumn;
- int nItemCodeColumn;
- int nRecords;
- bool bSpecial;
- void __fastcall ReplaceSpace(char* szText)
- {
- if(szText == NULL)
- return;
- char* pText = &szText[0];
- while(*pText != 0x00)
- {
- if(*pText == 0x20 || *pText == 0x2D)
- *pText = '_';
- if(*pText == 0x27)
- {
- char* pNewText = pText;
- char* pTemp = pText;
- while(*pNewText != 0x00 || *pTemp != 0x00)
- {
- pNewText++;
- *pTemp = *pNewText;
- pTemp++;
- }
- }
- pText++;
- }
- }
- DWORD __fastcall MakeItemCode(char* sz)
- {
- if(strlen(sz) == 3)
- strcat(sz," ");
- return *(DWORD*)(sz);
- }
- int main()
- {
- SetConsoleTitle("DEnumer v 0.5 by Necrolis");
- NephTableInit();
- printf("Please Input The Enum Table Data In the Format:\n");
- printf("[FILE NAME] [ENUM PREFIX] [COLUMN NUMBER TO ENUM] [NUMBER OF RECORDS TO ENUM]\n");
- printf("=RECORD SWITCH= -1: Auto Line Count -2: ItemCode Translator\n");
- scanf("%s %s %d %d",pNameBuffer,pPrefixBuffer,&nColumn,&nRecords);
- if(nColumn <= 0)
- {
- printf("WARNING: Column Number Must Be Greater Than 0, Default Selected\n");
- nColumn = 1;
- }
- if(nRecords == -2)
- {
- printf("Please Enter The Item Code Column:\n");
- scanf("%d",&nItemCodeColumn);
- bSpecial = true;
- }
- printf("Creating File D2%sEnum.h\n",pPrefixBuffer);
- Table* pTable = LoadTable(pNameBuffer,'\t','\n');
- if(pTable == NULL)
- {
- printf("WARNING: Couldn't Find or Load: %s\n EXITING\n",pNameBuffer);
- system("PAUSE");
- return EXIT_FAILURE;
- }
- printf("File Loaded\n");
- if(nRecords == -1 || nRecords == -2)
- nRecords = pTable->nLines;
- int nUnusedCount = nRecords - pTable->nLines;
- sprintf(pNameBuffer,"D2%sEnum.h",pPrefixBuffer);
- FILE* pOutput = fopen(pNameBuffer,"w+");
- if(pOutput == NULL)
- {
- printf("WARNING: Couldn't Create: %s\nEXITING\n",pNameBuffer);
- system("PAUSE");
- return EXIT_FAILURE;
- }
- printf("Header File Created\n");
- strupr(pPrefixBuffer);
- fprintf(pOutput,"#ifndef __D2%s__\n#define __D2%s__\n\nenum D2%s\n{\n",pPrefixBuffer,pPrefixBuffer,pPrefixBuffer);
- printf("Header File Inited\n");
- if(bSpecial)
- {
- for(int i = 1; i < nRecords; i++)
- {
- if(i >= pTable->nLines)
- break;
- char* pCell = pTable->ptLines[i]->ptCell[nColumn - 1];
- char* pCodeCell = pTable->ptLines[i]->ptCell[nItemCodeColumn - 1];
- if(pCell == NULL || pCodeCell == NULL)
- break;
- ReplaceSpace(pCell);
- if(i + 1 == nRecords && nUnusedCount < 1)
- fprintf(pOutput,"\t%s_%s = 0x%02X\t\t\t// %s\n",pPrefixBuffer,strupr(pCell),MakeItemCode(pCodeCell),pCodeCell);
- else
- fprintf(pOutput,"\t%s_%s = 0x%02X,\t\t\t// %s\n",pPrefixBuffer,strupr(pCell),MakeItemCode(pCodeCell),pCodeCell);
- }
- }
- else
- {
- for(int i = 1; i < nRecords; i++)
- {
- if(i >= pTable->nLines)
- break;
- char* pCell = pTable->ptLines[i]->ptCell[nColumn - 1];
- if(pCell == NULL)
- break;
- ReplaceSpace(pCell);
- if(i + 1 == nRecords && nUnusedCount < 1)
- fprintf(pOutput,"\t%s_%s = 0x%02X\t\t\t// %d\n",pPrefixBuffer,strupr(pCell),i - 1,i - 1);
- else
- fprintf(pOutput,"\t%s_%s = 0x%02X,\t\t\t// %d\n",pPrefixBuffer,strupr(pCell),i - 1,i - 1);
- }
- printf("Processing\n");
- for(int x = pTable->nLines; x < pTable->nLines + nUnusedCount; x++)
- {
- if(x + 1 == pTable->nLines + nUnusedCount)
- fprintf(pOutput,"\t%s_UNUSED_%d = 0x%02X\t\t\t// %d\n",pPrefixBuffer,x,x,x);
- else
- fprintf(pOutput,"\t%s_UNUSED_%d = 0x%02X,\t\t\t// %d\n",pPrefixBuffer,x,x,x);
- }
- }
- fprintf(pOutput,"};\n\n#endif");
- printf("Processing...\n");
- fclose(pOutput);
- FreeTable(pTable);
- NephTableEnd();
- printf("Finished\n");
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement