-
- xbt_ex_free(e);
- }
-#else
- append1("%s","%.*s","(no backtrace on this arch)");
-#endif
- break;
-
- case 'd': /* date; LOG4J compliant */
- append1("%f","%.*f", gras_os_time());
- break;
- case 'r': /* application age; LOG4J compliant */
- append1("%f","%.*f", gras_os_time()-begin_of_time);
- break;
-
- case 'm': /* user-provided message; LOG4J compliant */
- vasprintf(&tmp2, fmt, ev->ap_copy);
- append1("%s","%.*s",tmp2);
- free(tmp2);
- break;
-
- default:
- fprintf(stderr,ERRMSG, *q,(char*)l->data);
- abort();
- }
- q++;
- } else {
- char tmp2[2];
- tmp2[0] = *(q++);
- tmp2[1] = '\0';
- xbt_strbuff_append(buff,tmp2);
- }
- }
- app->do_append(app,buff->data);
- xbt_strbuff_free(buff);
-}
-
-#define check_overflow \
- if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
- xbt_log_layout_format_dynamic(l,ev,msg_fmt,app); \
- return;\
- }
-static void xbt_log_layout_format_doit(xbt_log_layout_t l,
- xbt_log_event_t ev,
- const char *msg_fmt,
- xbt_log_appender_t app) {
- char *p,*q;
- int precision=-1;
-
- if (begin_of_time<0)
- begin_of_time=gras_os_time();
-
- p = ev->buffer;
- q = l->data;
-
- while (*q != '\0') {
- if (*q == '%') {
- q++;
- handle_modifier:
- switch (*q) {
- case '\0':
- fprintf(stderr,"Layout format (%s) ending with %%\n",(char*)l->data);
- abort();
- case '%':
- *p++ = '%';
- break;
- case 'n': /* platform-dependant line separator (LOG4J compliant) */
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer),"\n");
- check_overflow;
- break;
- case 'e': /* plain space (SimGrid extension) */
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer)," ");
- check_overflow;
- break;
-
- case '.': /* precision specifyier */
- q++;
- q += sscanf(q,"%d",&precision);
- goto handle_modifier;
-
- case 'c': /* category name; LOG4J compliant
- should accept a precision postfix to show the hierarchy */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer),"%s",ev->cat->name);
- check_overflow;
- } else {
- p += sprintf(p,"%.*s",(int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision),ev->cat->name);
- check_overflow;
- precision = -1;
- }
- break;
- case 'p': /* priority name; LOG4J compliant */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s", xbt_log_priority_names[ev->priority] );
- check_overflow;
- } else {
- p += sprintf(p, "%.*s", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), xbt_log_priority_names[ev->priority] );
- check_overflow;
- precision = -1;
- }
- break;
-
- case 'h': /* host name; SimGrid extension */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s", gras_os_myname());
- check_overflow;
- } else {
- p += sprintf(p, "%.*s", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), gras_os_myname());
- check_overflow;
- precision = -1;
- }
- break;
- case 't': /* thread name; LOG4J compliant */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s", xbt_thread_self_name());
- check_overflow;
- } else {
- p += sprintf(p, "%.*s", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), xbt_thread_self_name());
- check_overflow;
- precision = -1;
- }
- break;
- case 'P': /* process name; SimGrid extension */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s", xbt_procname());
- check_overflow;
- } else {
- p += sprintf(p, "%.*s", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision),xbt_procname());
- check_overflow;
- precision = -1;
- }
- break;
- case 'i': /* process PID name; SimGrid extension */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%d", (*xbt_getpid)());
- check_overflow;
- } else {
- p += sprintf(p, "%.*d", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), (*xbt_getpid)());
- check_overflow;
- precision = -1;
- }
- break;
-
- case 'F': /* file name; LOG4J compliant */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer),"%s",ev->fileName);
- check_overflow;
- } else {
- p += sprintf(p,"%.*s",(int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), ev->fileName);
- check_overflow;
- precision = -1;
- }
- break;
- case 'l': /* location; LOG4J compliant */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s:%d", ev->fileName, ev->lineNum);
- check_overflow;
- } else {
- p += snprintf(p, (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), "%s:%d", ev->fileName, ev->lineNum);
- check_overflow;
- precision = -1;
- }
- break;
- case 'L': /* line number; LOG4J compliant */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%d", ev->lineNum);
- check_overflow;
- } else {
- p += sprintf(p, "%.*d", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), ev->lineNum);
- check_overflow;
- precision = -1;
- }
- break;
- case 'M': /* method (ie, function) name; LOG4J compliant */
- if (precision == -1) {
- p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s", ev->functionName);
- check_overflow;
- } else {
- p += sprintf(p, "%.*s", (int)MIN(XBT_LOG_BUFF_SIZE-(p-ev->buffer),precision), ev->functionName);
- check_overflow;
- precision = -1;