IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 8, 2008, 11:27:46 AM (18 years ago)
Author:
eugene
Message:

added thread safety code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/isolate_elements.c

    r15878 r16891  
    22
    33/* local private functions */
    4 void InsertValue (char c);
    5 void EndOfString (void);
     4char **InsertValue (char **myOutput, int *Nout, int *Nchar, int *NCHAR, char c);
     5char **EndOfString (char **myOutput, int *Nout, int *Nchar, int *NOUT, int *NCHAR);
    66int IsAnOp (char *c);
    77int IsTwoOp (char *c);
    88
    9 /* local private static variables */
    10 int NCHAR, Nchar, Nout, NOUT;
    11 char **myOutput;
    12 
    139char **isolate_elements (int Nin, char **in, int *nout) {
    1410 
     11  /* local private static variables */
     12  int NCHAR, Nchar, Nout, NOUT;
     13  char **myOutput;
     14
    1515  int i, j, minus, negate, plus, posate, OpStat, SciNotation;
    1616
     
    9191      if (negate || minus || posate || plus || (IsAnOp (&in[i][j]) && !SciNotation)) {
    9292        if (posate) continue;
    93         EndOfString ();
     93        myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR);
    9494        /* 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        }
    9799
    98100        if (IsTwoOp (&in[i][j])) {
    99           InsertValue (in[i][j+1]);
     101          myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j+1]);
    100102          j++;
    101103        }
    102         EndOfString ();
     104        myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR);
    103105        continue;
    104106      }
    105107      /* quoted string */
    106108      if (in[i][j] == '"') {
    107         InsertValue (in[i][j]);
     109        myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]);
    108110        j++;
    109111        while ((j < strlen(in[i])) && (in[i][j] != '"')) {
    110           InsertValue (in[i][j]);
     112          myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]);
    111113          j++;
    112114        }
     
    117119        }
    118120        */
    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);
    121123        continue;
    122124      }
    123125      /* not an operator, not a quoted string */
    124126      if (!OHANA_WHITESPACE (in[i][j])) {
    125         InsertValue (in[i][j]);
     127        myOutput = InsertValue (myOutput, &Nout, &Nchar, &NCHAR, in[i][j]);
    126128      } else {
    127         EndOfString ();
     129        myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR);
    128130      }
    129131    }
    130     EndOfString ();
     132        myOutput = EndOfString (myOutput, &Nout, &Nchar, &NOUT, &NCHAR);
    131133  }
    132134
     
    138140}
    139141
    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);
     142char **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);
    146148  }
    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
     153char **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;
    155158   
    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));
    159162    }
    160     NCHAR = 256;
    161     ALLOCATE (myOutput[Nout], char, NCHAR);
     163    (*NCHAR) = 256;
     164    ALLOCATE (myOutput[*Nout], char, (*NCHAR));
    162165  }
     166  return (myOutput);
    163167}
    164168
Note: See TracChangeset for help on using the changeset viewer.