Reading Gcode in LocalFiileSystem and encodeing int array. but this program has bug.probably

Fork of MakeSequencer by yuki sato

Revision:
4:1d7c50f17687
Parent:
3:09ee560a3007
diff -r 09ee560a3007 -r 1d7c50f17687 MakeSequencer.cpp
--- a/MakeSequencer.cpp	Thu Oct 11 11:23:53 2018 +0000
+++ b/MakeSequencer.cpp	Wed Oct 17 01:09:47 2018 +0000
@@ -13,7 +13,7 @@
 {
     FILE *fp = fopen( "/local/out.txt", "r");
     MakeSequencer code(fp);
-    code.getGcode(3,sizeof(array)/sizeof(int),array);        //getGcode(int row,int aSize, int* array)
+    code.getGcode(1,sizeof(array)/sizeof(int),array);        //getGcode(int row,int aSize, int* array)
                                                              //array will get Gcode of a "int row" line
     for(int i = 0;i < sizeof(array)/sizeof(int);i++)
         printf("%d,",array[i]);
@@ -30,6 +30,7 @@
 {
     _fp=fp;
     FileOpen();
+ 
 }
 
 bool MakeSequencer::FileOpen()
@@ -61,6 +62,16 @@
 
 bool MakeSequencer::ReadGcode()
 {
+    //char * _buf     = new char[BUF];
+    char _buf[BUF];
+    int  *_tempnum  = new int[ARRAY_EREMENT];
+    char **_element = new char*[ARRAY_EREMENT];
+    bool **_check   = new bool*[ARRAY_EREMENT];
+    for (int a = 0; a < ARRAY_EREMENT; a++) 
+    {
+        _element[a] = new char[CODE_LENGTH];
+        _check[a]   = new bool[CODE_LENGTH];
+    }
     _ele = 0;
     for(int i = 0;fgets(_buf,sizeof(_buf), _fp) != NULL;i++)
     {
@@ -70,10 +81,10 @@
             return false;
         else
         {
-            string _tempstr[ARRAY_EREMENT];
+            string *_tempstr = new string[ARRAY_EREMENT];
             _count = -1;
             
-            for(int n = 0;n < ARRAY_EREMENT;n++)
+            for(int n = 0;n < ARRAY_EREMENT;n++)//bool array Initialize
             {
                 for(int p = 0;p < CODE_LENGTH;p++)
                     _check[n][p] = true;
@@ -98,11 +109,12 @@
                             }
                         }
                     }
-                    _element[_count][i] = _char;
+                    else
+                        _element[_count][i] = _char;
                     if(i == 0)
                         _ele++;
                 }
-                else if(_char >= '0'&& _char <= '9')
+                else if(_char >= '0'&& _char <= '9' || _char <= '-')
                 {
                     _tempstr[_count] = _tempstr[_count] + _char;
                 }   
@@ -113,15 +125,34 @@
                 else
                     return false;
             }
-            
+            printf("#(%d) ",i);
             for(int n = 0;n < _ele;n++)
             {
                 _tempnum[n] = atoi(_tempstr[n].c_str());
                 _data[n][i] = (i != 0 && _check[n][i] && _element[n][i] != _element[n][0])
                             ? _data[n][i-1]
                             : _tempnum[n];
+                            
+                _element[n][i] = (i != 0 && _check[n][i] && _element[n][i] != _element[n][0])
+                            ? _element[n][0]
+                            : _element[n][i];
+                printf("%c:%d",_element[n][i],_data[n][i]);
             }
+            printf("\n\r");
+            //delete[] _tempstr;
         }
+        
     }
+    for (int a = 0; a < ARRAY_EREMENT; a++) 
+    {
+        delete[] _data[a];
+        delete[] _check[a];
+        delete[] _element[a];
+    }
+    //delete[] _buf;
+    //delete[] _data;
+    delete[] _element;
+    delete[] _check;
+    delete[] _tempnum;
     return true;
 }
\ No newline at end of file