IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10647


Ignore:
Timestamp:
Dec 11, 2006, 10:15:41 PM (19 years ago)
Author:
eugene
Message:

moved global List into ListOps.c

Location:
trunk/Ohana/src/opihi
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.basic/list.c

    r7917 r10647  
    9898  /* read in loop */
    9999  depth = 0;
    100   ThisList = Nlists;
     100  ThisList = current_list_depth();
    101101  for (i = 0, done = FALSE; !done; ) {
    102102
  • trunk/Ohana/src/opihi/cmd.basic/run_for.c

    r7917 r10647  
    2727  /* read in loop */
    2828  depth = 0;
    29   ThisList = Nlists;
     29  ThisList = current_list_depth();
    3030  for (i = 0, done = FALSE; !done; ) {
    3131
     
    104104
    105105/*
    106   If we are entering at the keyboard (Nlists == 0), use readline.
     106  If we are entering at the keyboard (ThisList == 0), use readline.
    107107  Otherwise, read from the current list, remove list lines.
    108108  execute when we hit the final "END" (the true END -- we count macro defines!!)
  • trunk/Ohana/src/opihi/cmd.basic/run_if.c

    r8178 r10647  
    2626  nloop = 0;
    2727  depth = 0;
    28   ThisList = Nlists;
     28  ThisList = current_list_depth();
    2929
    3030  /* determine value of conditional expression */
     
    108108
    109109/*
    110      If we are entering at the keyboard (Nlists == 0), use readline.
     110     If we are entering at the keyboard (ThisList == 0), use readline.
    111111     Otherwise, read from the current list, remove list lines.
    112112     End when we hit the final "END" (the true END -- we count macro defines!!)
  • trunk/Ohana/src/opihi/cmd.basic/run_while.c

    r9844 r10647  
    2525  /* read in loop */
    2626  depth = 0;
    27   ThisList = Nlists;
     27  ThisList = current_list_depth();
    2828  for (i = 0, done = FALSE; !done; ) {
    2929
  • trunk/Ohana/src/opihi/cmd.basic/test/for.sh

    r10311 r10647  
    88 memtest1
    99 memtest2
     10 memtest2a
    1011 memtest3
    1112end
     
    162163end
    163164
     165# check memleaks with many loop lines
     166macro memtest2a
     167
     168 local i N
     169
     170 list word -x "ps -p $PID -o rss"
     171 $startmem = $word:1
     172
     173 output /dev/null
     174 for i 0 10000
     175  echo "test line in loop"
     176  echo "test line in loop"
     177 end   
     178 output stdout
     179 
     180 list word -x "ps -p $PID -o rss"
     181 $endmem = $word:1
     182
     183 $PASS = 1
     184
     185 if ($endmem - $startmem > 10)
     186   $PASS = 0
     187   echo "growth: {$endmem-$startmem}"
     188   echo "kB/loop: {($endmem-$startmem)/10000}"
     189 end
     190end
     191
     192# check memleaks with many loop lines
     193macro memtest2b
     194
     195 local i N
     196
     197 list word -x "ps -p $PID -o rss"
     198 $startmem = $word:1
     199
     200 output /dev/null
     201 for i 0 1000
     202  exec echo "test line in loop" > /dev/null
     203  exec echo "test line in loop" > /dev/null
     204 end   
     205 output stdout
     206 
     207 list word -x "ps -p $PID -o rss"
     208 $endmem = $word:1
     209
     210 $PASS = 1
     211
     212 if ($endmem - $startmem > 10)
     213   $PASS = 0
     214   echo "growth: {$endmem-$startmem}"
     215   echo "kB/loop: {($endmem-$startmem)/1000}"
     216 end
     217end
     218
    164219# check memleaks on break
    165220macro memtest3
  • trunk/Ohana/src/opihi/include/shell.h

    r9039 r10647  
    3737  int    n;
    3838  int    Nlines;
     39  int    Nalloc;
    3940} List;
    4041
     
    5051
    5152/*** globals used to track the shell language concepts  ***/
    52 List         *lists;                    /* variable to store the list of all lists */
    53 int          Nlists;                    /* number of currently available lists */
    54 
    5553int          interrupt;                 /* true if C-C has been pressed */
    5654int          auto_break;                /* if true, zero exit status forces macros to escape */
     
    8280int           is_macro_create           PROTO((char *line));
    8381void          InitLists                 PROTO(());
     82int current_list_depth ();
     83int increase_list_depth ();
     84int decrease_list_depth ();
     85char *get_next_listentry (int ThisList);
    8486
    8587void          InitCommands              PROTO(());
     
    101103
    102104int           exec_loop                 PROTO((Macro *loop));
    103 char         *get_next_listentry        PROTO((int ThisList));
    104 char         *remove_listentry          PROTO((int current));
     105/* char         *get_next_listentry     PROTO((int ThisList)); */
     106/* char         *remove_listentry       PROTO((int current)); */
     107
    105108int           ConfigInit                PROTO((int *argc, char **argv));
    106109char         *VarConfig                 PROTO((char *keyword, char *mode, void *ptr));
  • trunk/Ohana/src/opihi/lib.shell/ListOps.c

    r4763 r10647  
    11# include "opihi.h"
    22# include "macro.h"
     3
     4/*** local static variables used to track the command lists  ***/
     5static List *lists;                     /* variable to store the list of all lists */
     6static int  Nlists;                     /* number of currently available lists */
    37
    48void InitLists () {
     
    812}
    913
     14int current_list_depth () {
     15  return Nlists;
     16}
     17
     18int increase_list_depth () {
     19  Nlists ++;
     20  REALLOCATE (lists, List, MAX (Nlists + 1, 0) + 1);
     21  ALLOCATE (lists[Nlists].line, char *, 16);
     22  lists[Nlists].Nalloc = 16;
     23  lists[Nlists].Nlines = 0;
     24  lists[Nlists].n = 0;
     25  return Nlists;
     26}
     27
     28int decrease_list_depth () {
     29 
     30  int i;
     31
     32  for (i = 0; i < lists[Nlists].Nlines; i++) {
     33    free (lists[Nlists].line[i]);
     34  }
     35  free (lists[Nlists].line);
     36  Nlists --;
     37  REALLOCATE (lists, List, MAX (Nlists + 1, 0) + 1);
     38  return Nlists;
     39}
     40
    1041/* return a new string consisting of the next line in the current list */
    1142char *get_next_listentry (int ThisList) {
    1243
     44  int Nline;
    1345  char *output;
    1446
    15   lists[ThisList].n++;
    16 
    17   if (lists[ThisList].n >= lists[Nlists].Nlines)
    18     return ((char *) NULL);
    19 
    20   output = lists[Nlists].line[lists[ThisList].n];
     47  Nline = lists[ThisList].n;
     48
     49  if (Nline >= lists[ThisList].Nlines) return (NULL);
     50
     51  output = strcreate (lists[ThisList].line[Nline]);
     52  lists[ThisList].n ++;
    2153 
    2254  return (output);
    23 
    24 }
    25 
     55}
     56
     57# if (0)
    2658char *remove_listentry (int current) {
    2759
     
    4173  return (output);
    4274
     75}
     76# endif
     77
     78int add_listentry (int ThisList, char *line) {
     79
     80  int Nlines;
     81  char *output;
     82
     83  Nlines = lists[ThisList].Nlines;
     84  lists[ThisList].line[Nlines] = strcreate (line);
     85  lists[ThisList].Nlines ++;
     86
     87  if (lists[ThisList].Nlines == lists[ThisList].Nalloc) {
     88    lists[ThisList].Nalloc += 16;
     89    REALLOCATE (lists[ThisList].line, char *, lists[ThisList].Nalloc);
     90  }
     91   
     92  return (lists[ThisList].Nlines);
    4393}
    4494
  • trunk/Ohana/src/opihi/lib.shell/exec_loop.c

    r9469 r10647  
    88 
    99  /* increase the shell level (Nlists) by one */
    10   Nlists ++;
    11   ThisList = Nlists;
    12   REALLOCATE (lists, List, MAX (ThisList, 0) + 1);
    13  
     10  ThisList = increase_list_depth();
     11  if (ThisList == 0) abort();
     12
    1413  /* copy the macro to the current list */
    15   lists[ThisList].Nlines = loop[0].Nlines;
    16   ALLOCATE (lists[ThisList].line, char *, MAX (lists[ThisList].Nlines, 1));
    17   for (j = 0; j < lists[ThisList].Nlines; j++) {
    18     lists[ThisList].line[j] = strcreate (loop[0].line[j]);
     14  for (j = 0; j < loop[0].Nlines; j++) {
     15    add_listentry (ThisList, loop[0].line[j]);
    1916  }
    2017
     
    2623  loop_continue = loop_break = FALSE;
    2724  status = TRUE;
    28   Nlines = lists[ThisList].Nlines;
    29   for (n = 0; (n < Nlines) && !interrupt; n++) {
    30     lists[ThisList].n = n;
    31     line = lists[ThisList].line[n];
    3225
     26  while (!interrupt) {
     27    line = get_next_listentry (ThisList);
     28    if (line == NULL) break;
    3329    status = multicommand (line);
    34 
    35     if (line != NULL) free (line);
    36     n = lists[ThisList].n;
    37     Nlines = lists[ThisList].Nlines;
     30    free (line);
    3831    if (auto_break && !status) loop_break = TRUE;
    3932    if (loop_break || loop_continue) break;
     
    4235
    4336  /* free remaining lines on the list, free the list, decrement the shell level */
    44   for (n ++; n < Nlines; n ++) {
    45       free (lists[ThisList].line[n]);
    46   }
    47   free (lists[ThisList].line);
    48   Nlists --;
    49   REALLOCATE (lists, List, MAX (Nlists, 0) + 1);
     37  /*** can we free a list which is not the bottom lists? */
     38  decrease_list_depth();
    5039
    5140  if (loop_break) return (FALSE);
  • trunk/Ohana/src/opihi/lib.shell/macro_create.c

    r7917 r10647  
    6060
    6161  /* read in macro
    62      If we are entering at the keyboard (Nlists == 0), use readline.
     62     If we are entering at the keyboard (ThisList == 0), use readline.
    6363     Otherwise, read from the current list
    6464     End when we hit the final "END" (the true END -- we count macro defines!!) */
    6565     
    6666  depth = 0;
    67   ThisList = Nlists;
     67  ThisList = current_list_depth();
    6868  for (i = 0, done = FALSE; !done; ) {
    6969
  • trunk/Ohana/src/opihi/mana/opihi.c

    r9040 r10647  
    2020
    2121  auto_break = TRUE;
    22 
    23   Nlists = 0;
    24   ALLOCATE (lists, List, 1);
    2522
    2623  /* init functions required by libraries */
  • trunk/Ohana/src/opihi/pantasks/LocalJob.c

    r8548 r10647  
    2929      case 0:   /* pipe is closed, change child state? **/
    3030      default:  /* data in pipe */
     31        // fprintf (stderr, "read %d bytes (Nblock: %d, Nbuffer: %d)\n", Nread, job[0].stdout.Nblock, job[0].stdout.Nbuffer);
    3132        break;
    3233    }
  • trunk/Ohana/src/opihi/pantasks/scheduler.c

    r9037 r10647  
    1111 
    1212  auto_break = TRUE;
    13 
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    1613
    1714  /* init functions required by libraries */
  • trunk/Ohana/src/opihi/pantasks/task.c

    r9037 r10647  
    4545  /* allowed tokens: command, host, stderr, periods, trange, nmax, task.exit, task.exec, end */
    4646
    47   ThisList = Nlists;
     47  ThisList = current_list_depth();
    4848  while (1) {
    4949
  • trunk/Ohana/src/opihi/pantasks/task_macros.c

    r7917 r10647  
    105105  depth = 0;
    106106  done = FALSE;
    107   ThisList = Nlists;
     107  ThisList = current_list_depth();
    108108  while (!done) {
    109109
  • trunk/Ohana/src/opihi/pantasks/test/local.sh

    r9471 r10647  
    4141 list word -x "ps -p $PID -o rss"
    4242 $endmem = $word:1
    43  echo growth: {$endmem - $startmem}
     43 # echo growth: {$endmem - $startmem}
    4444end
    4545
  • trunk/Ohana/src/opihi/pcontrol/pcontrol.c

    r9473 r10647  
    6565
    6666void gotsignal (int signum) {
    67   gprint (GP_ERR, "got signal : %d\n", signum);
     67  // this message is lost if we are connected to a pantasks
     68  fprintf (stderr, "got signal : %d\n", signum);
    6869  return;
    6970}
Note: See TracChangeset for help on using the changeset viewer.