Changeset 15878 for trunk/Ohana/src/opihi/lib.shell/isolate_elements.c
- Timestamp:
- Dec 16, 2007, 2:27:00 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/isolate_elements.c
r10073 r15878 8 8 9 9 /* local private static variables */ 10 int N char, Nout, NOUT;11 char ** out;10 int NCHAR, Nchar, Nout, NOUT; 11 char **myOutput; 12 12 13 13 char **isolate_elements (int Nin, char **in, int *nout) { … … 17 17 NOUT = Nin; 18 18 Nchar = Nout = 0; 19 ALLOCATE (out, char *, NOUT); 20 ALLOCATE (out[Nout], char, NCHARS); 19 NCHAR = 256; 20 ALLOCATE (myOutput, char *, NOUT); 21 ALLOCATE (myOutput[Nout], char, NCHAR); 21 22 22 23 for (i = 0; i < Nin; i++) { … … 35 36 /* check previous entry on line */ 36 37 if (Nchar) { 37 OpStat = IsAnOp ( out[Nout]);38 if ( out[Nout][0] == ')') OpStat = FALSE;38 OpStat = IsAnOp (myOutput[Nout]); 39 if (myOutput[Nout][0] == ')') OpStat = FALSE; 39 40 } else { 40 OpStat = IsAnOp ( out[Nout-1]);41 if ( out[Nout-1][0] == ')') OpStat = FALSE;41 OpStat = IsAnOp (myOutput[Nout-1]); 42 if (myOutput[Nout-1][0] == ')') OpStat = FALSE; 42 43 } 43 44 /* if - follows an operator, must be negator */ … … 67 68 /* check previous entry on line */ 68 69 if (Nchar) { 69 OpStat = IsAnOp ( out[Nout]);70 if ( out[Nout][0] == ')') OpStat = FALSE;70 OpStat = IsAnOp (myOutput[Nout]); 71 if (myOutput[Nout][0] == ')') OpStat = FALSE; 71 72 } else { 72 OpStat = IsAnOp ( out[Nout-1]);73 if ( out[Nout-1][0] == ')') OpStat = FALSE;73 OpStat = IsAnOp (myOutput[Nout-1]); 74 if (myOutput[Nout-1][0] == ')') OpStat = FALSE; 74 75 } 75 76 /* if + follows an operator, must be posator */ … … 91 92 if (posate) continue; 92 93 EndOfString (); 93 /* copy operator to out[Nout] */94 /* copy operator to myOutput[Nout] */ 94 95 InsertValue (in[i][j]); 95 96 if (negate) InsertValue ('-'); … … 131 132 132 133 /* one extra entry is allocated, free here */ 133 free ( out[Nout]);134 free (myOutput[Nout]); 134 135 *nout = Nout; 135 return ( out);136 return (myOutput); 136 137 137 138 } 138 139 139 140 void InsertValue (char c) { 140 out[Nout][Nchar] = c;141 myOutput[Nout][Nchar] = c; 141 142 Nchar ++; 142 out[Nout][Nchar] = 0; 143 if (Nchar >= NCHAR - 2) { 144 NCHAR += 256; 145 REALLOCATE (myOutput[Nout], char, NCHAR); 146 } 147 myOutput[Nout][Nchar] = 0; 143 148 } 144 149 145 150 void EndOfString () { 146 151 if (Nchar > 0) { 147 out[Nout][Nchar] = 0;152 myOutput[Nout][Nchar] = 0; 148 153 Nout ++; 149 154 Nchar = 0; … … 151 156 if (Nout >= NOUT - 1) { 152 157 NOUT += 10; 153 REALLOCATE ( out, char *, NOUT);158 REALLOCATE (myOutput, char *, NOUT); 154 159 } 155 ALLOCATE (out[Nout], char, NCHARS); 160 NCHAR = 256; 161 ALLOCATE (myOutput[Nout], char, NCHAR); 156 162 } 157 163 }
Note:
See TracChangeset
for help on using the changeset viewer.
