IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 11, 2013, 3:08:39 PM (13 years ago)
Author:
eugene
Message:

add -excel option to lists

Location:
branches/eam_branches/ipp-20130711/Ohana/src/opihi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130711/Ohana/src/opihi/cmd.basic/list.c

    r33662 r35802  
    22# define D_NLINES 100
    33static char prompt[] = ">> ";
     4
     5static int set_list_varname (char *line, char *base, int N, int excelStyle);
    46
    57int list (int argc, char **argv) {
     
    2123  }
    2224
     25  int EXCEL_STYLE = FALSE;
     26  if ((N = get_argument (argc, argv, "-excel-style"))) {
     27    remove_argument (N, &argc, argv);
     28    EXCEL_STYLE = TRUE;
     29  }
     30  if ((N = get_argument (argc, argv, "-excel"))) {
     31    remove_argument (N, &argc, argv);
     32    EXCEL_STYLE = TRUE;
     33  }
     34
    2335  if ((N = get_argument (argc, argv, "-vectors"))) {
    2436    remove_argument (N, &argc, argv);
     
    4961   
    5062    for (i = 0; i < argc - 3; i++) {
    51       sprintf (line, "%s:%d", argv[1], i);
     63      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    5264      set_str_variable (line, argv[i+3]);
    5365    }
     
    8395        if (!word) break;
    8496       
    85         sprintf (line, "%s:%d", argv[1], nWords);
     97        // sprintf (line, "%s:%d", argv[1], nWords);
     98        set_list_varname (line, argv[1], nWords, EXCEL_STYLE);
     99
    86100        set_str_variable (line, word);
    87101        FREE (word);
     
    120134      sprintf (line, "%s:%d", argv[3], i);
    121135      value = get_variable (line);
    122       sprintf (line, "%s:%d", argv[1], i);
     136      // sprintf (line, "%s:%d", argv[1], i);
     137      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    123138      set_str_variable (line, value);
    124139    }
     
    136151    N = get_int_variable (line, &found);
    137152    for (i = 0; i < argc - 3; i++) {
    138       sprintf (line, "%s:%d", argv[1], N + i);
     153      // sprintf (line, "%s:%d", argv[1], N + i);
     154      set_list_varname (line, argv[1], N + i, EXCEL_STYLE);
    139155      set_str_variable (line, argv[i+3]);
    140156    }
     
    159175    N = get_int_variable (line, &found);
    160176    for (i = 0; i < N; i++) {
    161       sprintf (line, "%s:%d", argv[1], i);
     177      // sprintf (line, "%s:%d", argv[1], i);
     178      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    162179      value = get_variable (line);
    163180      if (value == NULL) continue;
     
    165182        free (value);
    166183        for (j = i + 1; j < N; j++) {
    167           sprintf (line2, "%s:%d", argv[1], j);
     184          // sprintf (line2, "%s:%d", argv[1], j);
     185          set_list_varname (line2, argv[1], j, EXCEL_STYLE);
    168186          next_value = get_variable (line2);
    169187          set_str_variable (line, next_value);
     
    235253      if (B != (char *) NULL) { *B = 0; }
    236254      if (*A != 0) {
    237         sprintf (line, "%s:%d", argv[1], i);
     255        // sprintf (line, "%s:%d", argv[1], i);
     256        set_list_varname (line, argv[1], i, EXCEL_STYLE);
    238257        set_str_variable (line, A);
    239258        A = B + 1;
     
    283302
    284303    if (*input) {
    285       sprintf (line, "%s:%d", argv[1], i);
     304      // sprintf (line, "%s:%d", argv[1], i);
     305      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    286306      set_str_variable (line, input);
    287307      free (input);
    288308      i++;
    289    }
     309    }
    290310  }
    291311  return (TRUE);
    292312}
     313
     314static int set_list_varname (char *line, char *base, int N, int excelStyle) {
     315
     316  int i;
     317   
     318  // A-Z correspond to 0 - 25
     319
     320  if (excelStyle) {
     321    float f = log(26.0);
     322    float g = (N == 0) ? 0.0 : log(1.0*N);
     323    int Ndigit = (int) (g / f) + 1;
     324    if (Ndigit > 10) {
     325      sprintf (line, "%s:ZZZZZZZZZZ", base);
     326      return FALSE;
     327    }
     328    char name[12];
     329    memset (name, 0, 12);
     330    for (i = 0; i < Ndigit; i++) {
     331      float Npow = Ndigit - i - 1;
     332      float g = pow(26.0, Npow);
     333      int V = (int) (N / g);
     334      name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1;
     335      N -= V * g;
     336    }
     337    sprintf (line, "%s:%s", base, name);
     338  } else {
     339    sprintf (line, "%s:%d", base, N);
     340  }
     341  return TRUE;
     342}
  • branches/eam_branches/ipp-20130711/Ohana/src/opihi/lib.shell/ListOps.c

    r33963 r35802  
    189189int is_list_data (char *line) {
    190190
    191   char *comm, *temp;
    192 
    193   temp = thisword (nextword (nextword (line)));
    194   comm = thisword (line);
    195 
     191  char *comm = NULL;
     192  char *temp = NULL;
     193  char *ptr  = NULL;
     194
     195  comm = thisword (line);
    196196  if (comm == NULL) goto escape;
    197 
    198197  if (strcmp (comm, "list")) goto escape;
     198
     199  ptr = nextword (line);
     200  if (!strncmp("-excel", ptr, strlen("-excel"))) ptr = nextword (ptr);
     201  if (!strncmp("-excel-style", ptr, strlen("-excel-style"))) ptr = nextword (ptr);
     202  ptr = nextword (ptr);
     203  if (!strncmp("-excel", ptr, strlen("-excel"))) ptr = nextword (ptr);
     204  if (!strncmp("-excel-style", ptr, strlen("-excel-style"))) ptr = nextword (ptr);
     205  temp = thisword (ptr);
    199206
    200207  /* if (cond) (command) does not define a complete block */
Note: See TracChangeset for help on using the changeset viewer.