Advertisement
NovaYoshi

non-interleaved table maker

Jun 30th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char ColNames[32][50];
  6. char ColInclude[32][512];
  7. char RowNames[256][70];
  8. char ColData[256][32][64];
  9. char EnumName[70] = "";
  10. int NumCols = 0;
  11. int NumRows = 0;
  12. int CurCol = 0;
  13.  
  14. int main(int argc, char *argv[]) {
  15.   if(argc < 3) {
  16.     puts("syntax: tblmake in.txt out.s");
  17.     return 0;
  18.   }
  19.  
  20.   char Buffer[700];
  21.  
  22.   int i,j,k;
  23.   FILE *InputFile = fopen(argv[1],"rb");
  24.   if(InputFile == NULL) {
  25.     puts("input file not found");
  26.     return 0;
  27.   }
  28.  
  29.   for(i=0;i<32;i++)
  30.     *ColInclude[i] = 0;
  31.  
  32.   for(k=0;!k;i=0) {
  33.     i=0;
  34.     while(1) {
  35.       j = fgetc(InputFile);
  36.       if(j == '\r') continue;
  37.       Buffer[i++]=j;
  38.       if(j == '\n' || j==EOF) {
  39.         Buffer[i-1] = 0;
  40.         if(j==EOF) k=1;
  41.           break;
  42.       }
  43.     }
  44.     // process line
  45.     if(!*Buffer)
  46.       continue;
  47.     if(Buffer[0] == 'E') {
  48.       strcpy(EnumName, Buffer+2);
  49.     } else if(Buffer[0] == 'L') {
  50.       strcpy(ColNames[NumCols], Buffer+2);
  51.       NumCols++;
  52.     } else if(Buffer[0] == 'R') {
  53.       strcpy(RowNames[NumRows], Buffer+2);
  54.       CurCol = 0;
  55.       NumRows++;
  56.     } else if(Buffer[0] == 'C') {
  57.       strcpy(ColData[NumRows-1][CurCol], Buffer+2);
  58.       CurCol++;
  59.     } else if(Buffer[0] == 'I') {
  60.       strcat(ColInclude[NumCols], Buffer+2);
  61.       strcat(ColInclude[NumCols], "\n");
  62.     }
  63.   }
  64.   fclose(InputFile);
  65.  
  66.   // make output file
  67.   FILE *OutputFile = fopen(argv[2],"wb");
  68.   if(OutputFile == NULL) {
  69.     puts("output file not created");
  70.     return 0;
  71.   }
  72.  
  73.   if(EnumName[0]) {
  74.     fprintf(OutputFile, ".enum %s\r\n", EnumName);
  75.     for(j=0; j<NumRows; j++) {
  76.       fprintf(OutputFile, "  %s\r\n", RowNames[j]);
  77.     }
  78.     fprintf(OutputFile, ".endenum\r\n\r\n");
  79.   }
  80.  
  81.   for(i=0; i<NumCols; i++) {
  82.     fprintf(OutputFile, "%s", ColInclude[i]);
  83.     fprintf(OutputFile, ".proc %s\r\n", ColNames[i]);
  84.     for(j=0; j<NumRows; j++) {
  85.       fprintf(OutputFile, "  %s ;%s\r\n", ColData[j][i], RowNames[j]);
  86.     }
  87.     fprintf(OutputFile, ".endproc\r\n\r\n");
  88.   }
  89.   fclose(OutputFile);
  90.  
  91.   printf("Rows: %i\n", NumRows);
  92.  
  93.   return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement