Changeset 25dd31a for message.c


Ignore:
Timestamp:
Oct 26, 2003, 2:43:40 PM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
70b53ec
Parents:
eec69e1
Message:
Added a timestamp to the default style.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • message.c

    reec69e1 r25dd31a  
    1515void owl_message_init(owl_message *m)
    1616{
    17   time_t t;
    18 
    1917  m->id=owl_global_get_nextmsgid(&g);
    2018  m->type=OWL_MESSAGE_TYPE_GENERIC;
     
    2826 
    2927  /* save the time */
    30   t=time(NULL);
    31   m->time=owl_strdup(ctime(&t));
    32   m->time[strlen(m->time)-1]='\0';
     28  m->time=time(NULL);
     29  m->timestr=owl_strdup(ctime(&(m->time)));
     30  m->timestr[strlen(m->timestr)-1]='\0';
     31
     32  /* initialize the fmtext */
    3333  owl_fmtext_init_null(&(m->fmtext));
    3434}
     
    305305char *owl_message_get_timestr(owl_message *m)
    306306{
    307   return(m->time);
     307  if (m->timestr) return(m->timestr);
     308  return("");
     309}
     310
     311/* caller must free the return */
     312char *owl_message_get_shorttimestr(owl_message *m)
     313{
     314  struct tm *tmstruct;
     315  char *out;
     316
     317  tmstruct=localtime(&(m->time));
     318  out=owl_sprintf("%2.2i:%2.2i", tmstruct->tm_hour, tmstruct->tm_min);
     319  if (out) return(out);
     320  return("??:??");
    308321}
    309322
     
    705718  memcpy(&(m->notice), n, sizeof(ZNotice_t));
    706719
    707   /* a little gross, we'll reaplace \r's with ' ' for now */
     720  /* a little gross, we'll replace \r's with ' ' for now */
    708721  owl_zephyr_hackaway_cr(&(m->notice));
    709722 
    710723  m->delete=0;
     724
     725  /* save the time, we need to nuke the string saved by message_init */
     726  if (m->timestr) {
     727    owl_free(m->timestr);
     728  }
     729  m->time=n->z_time.tv_sec;
     730  m->timestr=owl_strdup(ctime(&(m->time)));
     731  m->timestr[strlen(m->timestr)-1]='\0';
    711732
    712733  /* set other info */
     
    782803    strcpy(m->hostname, inet_ntoa(n->z_sender_addr));
    783804  }
    784 
    785   /* save the time */
    786   m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec));
    787   m->time[strlen(m->time)-1]='\0';
    788805}
    789806#else
     
    847864  }
    848865#endif
    849   if (m->time) owl_free(m->time);
     866  if (m->timestr) owl_free(m->timestr);
    850867  if (m->zwriteline) owl_free(m->zwriteline);
    851868
Note: See TracChangeset for help on using the changeset viewer.