IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33646


Ignore:
Timestamp:
Apr 1, 2012, 2:15:36 PM (14 years ago)
Author:
eugene
Message:

move myAssert, myAbort, OHANA_ASSERT into libohana; add features to parse time and ints in space and csv lines (used by opihi/read functions); add abspath function; move rconnect into libohana

Location:
trunk/Ohana/src/libohana
Files:
5 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/Makefile

    r31663 r33646  
    3838$(SRC)/Fread.$(ARCH).o           \
    3939$(SRC)/IOBufferOps.$(ARCH).o     \
     40$(SRC)/memstr.$(ARCH).o  \
     41$(SRC)/rconnect.$(ARCH).o        \
    4042$(SRC)/CommOps.$(ARCH).o         \
    4143$(SRC)/isolate_elements.$(ARCH).o        \
  • trunk/Ohana/src/libohana/include/ohana.h

    r32632 r33646  
    215215*/
    216216# define OHANA_WHITESPACE(c)(((c) == 0x09) || ((c) == 0x0a) || ((c) == 0x0b) || ((c) == 0x0b) || ((c) == 0x0c) || ((c) == 0x0d) || ((c) == 0x20))
     217# define OHANA_ASSERT(LOGIC,...) { if (!(LOGIC)) { fprintf (stderr, __VA_ARGS__); abort(); } }
     218# define myAssert(LOGIC,...) { if (!(LOGIC)) { fprintf (stderr, __VA_ARGS__); abort(); } }
     219# define myAbort(MSG) { fprintf (stderr, "%s\n", MSG); abort(); }
    217220
    218221// sorting is now defined as a macro call
     
    236239char   *strncreate             PROTO((char *string, int n));
    237240int     scan_line              PROTO((FILE *f, char *line));
     241int     scan_line_maxlen       PROTO((FILE *f, char *line, int maxlen));
    238242int     dparse                 PROTO((double *X, int NX, char *line));
    239243int     dparse_csv             PROTO((double *X, int NX, char *line));
     244int     iparse                 PROTO((int *X, int NX, char *line));
     245int     iparse_csv             PROTO((int *X, int NX, char *line));
     246int     tparse                 PROTO((time_t *X, int NX, char *line));
     247int     tparse_csv             PROTO((time_t *X, int NX, char *line));
    240248int     fparse                 PROTO((float *X, int NX, char *line));
    241249int     get_argument           PROTO((int argc, char **argv, char *arg));
     
    256264int     check_dir_access       PROTO((char *path, int verbose));
    257265int     check_file_exec        PROTO((char *filename));
     266char   *abspath                PROTO((char *oldpath, int maxlength));
    258267
    259268/* in glockfile.c */
     
    323332off_t   Fwrite                 PROTO((void *ptr, off_t size, off_t nitems, FILE *f, char *type));
    324333
     334char   *memstr                 PROTO((char *m1, char *m2, int n));
     335int     write_fmt              PROTO((int fd, char *format, ...));
     336
    325337char   **isolate_elements      PROTO((int argc, char **argv, int *nstack));
    326338
     
    332344// gprint gets a stub implementation in libohana. opihi implements the real one.
    333345int    gprint (gpDest dest, char *format, ...);
     346
     347// rconnect is used to run remote programs with a pipe for communication
     348typedef enum {
     349  RCONNECT_ERR_NONE    = 0,
     350  RCONNECT_ERR_EXEC    = 1,
     351  RCONNECT_ERR_PIPE    = 2,
     352  RCONNECT_ERR_CONNECT = 3,
     353} RconnectErrors;
     354
     355void rconnect_set_timeout (int timeout);
     356int rconnect (char *command, char *hostname, char *shell, int *stdio, int *errorInfo, int doHandshake);
    334357
    335358/*
  • trunk/Ohana/src/libohana/include/ohana_allocate.h

    r31663 r33646  
    1212OhanaMemstats ohana_memstats (int mode);
    1313
     14/* EAM 2012.01.18 : comparative tests on my desktop 'pikake' (Intel Core 2 Quad) show a
     15 * modest speed loss when using the Ohana memory managment stuff.  the tests runs a ~1.2M
     16 * allocations followed by the same number of frees.  with the Ohana memory code, these
     17 * ran at ~0.69 sec per block; without the time was ~0.56 sec per block
     18 */
     19
    1420/* default is to use basic system memory functions */
     21
    1522# ifdef OHANA_MEMORY
    1623
  • trunk/Ohana/src/libohana/src/findexec.c

    r27435 r33646  
    404404  return TRUE;
    405405}
     406
     407// ohana-based equivalent to 'realpath'.  realpath does not guarantee an absolute path (eg on Solaris),
     408// just a 'cannonical path'.  I don't care about resolving out links, just ensuring an absolute path
     409// also, realpath is a bit ambiguous on the maxlength argument
     410char *abspath (char *oldpath, int maxlength) {
     411
     412  if (!oldpath) return NULL;
     413
     414  if (oldpath[0] == '/') {
     415    char *newpath = strcreate (oldpath);
     416    return newpath;
     417  }
     418
     419  char *cwd  = getcwd(NULL, maxlength);
     420  if (cwd == NULL) {
     421    // XXX need an error reporting function...
     422    fprintf (stderr, "error getting cwd (longer than %d chars?)\n", maxlength);
     423    return NULL;
     424  }
     425
     426  char *newpath = NULL;
     427
     428  int Nbytes = strlen(cwd) + strlen(oldpath) + 2;
     429  ALLOCATE (newpath, char, Nbytes);
     430  snprintf (newpath, Nbytes, "%s/%s", cwd, oldpath);
     431  return newpath;
     432}
  • trunk/Ohana/src/libohana/src/string.c

    r31663 r33646  
    143143}
    144144
     145int scan_line_maxlen (FILE *f, char *line, int maxlen) {
     146
     147  int i, status;
     148  char c;
     149 
     150  status = EOF + 1;
     151 
     152  for (i = 0, c = 0; (c != '\n') && (status != EOF) && (i < maxlen); i++) {
     153    status = fscanf (f, "%c", &c);
     154    line[i] = c;
     155  }
     156  line[i - 1] = 0;  /* this could make things crash! */
     157
     158  if (i > 1) {
     159    status = EOF + 1;
     160  }
     161
     162  return (status);
     163}
     164
    145165char *_parse_nextword (char *string) {
    146166
     
    203223  if (word[0] == '-') return (-1);
    204224  return (1);
     225}
     226
     227int iparse (int *X, int NX, char *line) {
     228
     229  int i;
     230  char *word;
     231  char *ptr;
     232
     233  word = line;
     234  for (i = 0; i < NX - 1; i++)
     235    word = _parse_nextword (word);
     236
     237  *X = strtol (word, &ptr, 0);
     238  if (ptr == word) return (FALSE);
     239  if (word[0] == '-') return (-1);
     240  return (1);
     241}
     242
     243int iparse_csv (int *X, int NX, char *line) {
     244
     245  int i;
     246  char *word;
     247  char *ptr;
     248
     249  word = line;
     250  for (i = 0; i < NX - 1; i++)
     251    word = _parse_nextword_csv (word);
     252 
     253  if (word[0] == '"') word[0] = ' ';
     254  if (word[0] == ',') {
     255      *X = 0;
     256      return 1;
     257  }
     258
     259  *X = strtol (word, &ptr, 0);
     260  if (ptr == word) return (FALSE);
     261  if (word[0] == '-') return (-1);
     262  return (1);
     263}
     264
     265int tparse (time_t *X, int NX, char *line) {
     266
     267  int i, status;
     268  char *word;
     269
     270  word = line;
     271  for (i = 0; i < NX - 1; i++)
     272    word = _parse_nextword (word);
     273
     274  status = ohana_str_to_time (word, X);
     275  if (!status) return (FALSE);
     276  return (TRUE);
     277}
     278
     279int tparse_csv (time_t *X, int NX, char *line) {
     280
     281  int i, status;
     282  char *word;
     283
     284  word = line;
     285  for (i = 0; i < NX - 1; i++)
     286    word = _parse_nextword_csv (word);
     287 
     288  if (word[0] == '"') word[0] = ' ';
     289  if (word[0] == ',') {
     290      *X = 0;
     291      return 1;
     292  }
     293
     294  status = ohana_str_to_time (word, X);
     295  if (!status) return (FALSE);
     296  return (TRUE);
    205297}
    206298
Note: See TracChangeset for help on using the changeset viewer.