Changeset 16891 for trunk/Ohana/src/opihi/lib.shell/isolate_elements.c
- Timestamp:
- Mar 8, 2008, 11:27:46 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/isolate_elements.c
r15878 r16891 2 2 3 3 /* local private functions */ 4 void InsertValue (char c);5 void EndOfString (void);4 char **InsertValue (char **myOutput, int *Nout, int *Nchar, int *NCHAR, char c); 5 char **EndOfString (char **myOutput, int *Nout, int *Nchar, int *NOUT, int *NCHAR); 6 6 int IsAnOp (char *c); 7 7 int IsTwoOp (char *c); 8 8 9 /* local private static variables */10 int NCHAR, Nchar, Nout, NOUT;11 char **myOutput;12 13 9 char **isolate_elements (int Nin, char **in, int *nout) { 14 10 11 /* local private static variables */ 12 int NCHAR, Nchar, Nout, NOUT; 13 char **myOutput; 14 15 15 int i, j, minus, negate, plus, posate, OpStat, SciNotation; 16 16 … … 91 91 if (negate || minus || posate || plus || (IsAnOp (&in[i][j]) && !SciNotation)) { 92 92 if (posate) continue; 93 EndOfString ();93 myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR); 94 94 /* copy operator to myOutput[Nout] */ 95 InsertValue (in[i][j]); 96 if (negate) InsertValue ('-'); 95 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]); 96 if (negate) { 97 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, '-'); 98 } 97 99 98 100 if (IsTwoOp (&in[i][j])) { 99 InsertValue (in[i][j+1]);101 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j+1]); 100 102 j++; 101 103 } 102 EndOfString ();104 myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR); 103 105 continue; 104 106 } 105 107 /* quoted string */ 106 108 if (in[i][j] == '"') { 107 InsertValue (in[i][j]);109 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]); 108 110 j++; 109 111 while ((j < strlen(in[i])) && (in[i][j] != '"')) { 110 InsertValue (in[i][j]);112 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]); 111 113 j++; 112 114 } … … 117 119 } 118 120 */ 119 InsertValue (in[i][j]);120 EndOfString ();121 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]); 122 myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR); 121 123 continue; 122 124 } 123 125 /* not an operator, not a quoted string */ 124 126 if (!OHANA_WHITESPACE (in[i][j])) { 125 InsertValue (in[i][j]);127 myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]); 126 128 } else { 127 EndOfString ();129 myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR); 128 130 } 129 131 } 130 EndOfString ();132 myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR); 131 133 } 132 134 … … 138 140 } 139 141 140 void InsertValue (char c) {141 myOutput[ Nout][Nchar] = c;142 Nchar++;143 if ( Nchar >= NCHAR- 2) {144 NCHAR+= 256;145 REALLOCATE (myOutput[ Nout], char,NCHAR);142 char **InsertValue (char **myOutput, int *Nout, int *Nchar, int *NCHAR, char c) { 143 myOutput[*Nout][*Nchar] = c; 144 (*Nchar) ++; 145 if ((*Nchar) >= (*NCHAR) - 2) { 146 (*NCHAR) += 256; 147 REALLOCATE (myOutput[*Nout], char, *NCHAR); 146 148 } 147 myOutput[Nout][Nchar] = 0; 148 } 149 150 void EndOfString () { 151 if (Nchar > 0) { 152 myOutput[Nout][Nchar] = 0; 153 Nout ++; 154 Nchar = 0; 149 myOutput[*Nout][*Nchar] = 0; 150 return (myOutput); 151 } 152 153 char **EndOfString (char **myOutput, int *Nout, int *Nchar, int *NOUT, int *NCHAR) { 154 if ((*Nchar) > 0) { 155 myOutput[*Nout][*Nchar] = 0; 156 (*Nout) ++; 157 (*Nchar) = 0; 155 158 156 if ( Nout >= NOUT- 1) {157 NOUT+= 10;158 REALLOCATE (myOutput, char *, NOUT);159 if ((*Nout) >= (*NOUT) - 1) { 160 (*NOUT) += 10; 161 REALLOCATE (myOutput, char *, (*NOUT)); 159 162 } 160 NCHAR= 256;161 ALLOCATE (myOutput[ Nout], char, NCHAR);163 (*NCHAR) = 256; 164 ALLOCATE (myOutput[*Nout], char, (*NCHAR)); 162 165 } 166 return (myOutput); 163 167 } 164 168
Note:
See TracChangeset
for help on using the changeset viewer.
