📄 mal_io.c
字号:
for(c= format;*c; c++){ if( *c=='\\'){ c++; #line 431 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" switch(*c){ case 'n': stream_printf(fd,"\n");break; case 't': stream_printf(fd,"\t");break; case 'r': stream_printf(fd,"\r");break; case '\\': stream_printf(fd,"\\");break; default : stream_printf(fd,"\\");stream_printf(fd,"%c",*c); }#line 480 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" } else if( *c== '%'){ char newformat[1024]; int i=0; if(*(c+1)=='%'){ stream_printf(fd,"%c",*c); c++; continue; } while(*c != 'f' && *c && i<1024) newformat[i++]= *c++; newformat[i++]='f'; newformat[i]=0; if(*c!= 'f') throw(MAL, "io.print", "Format limitation"); else stream_printf(fd,newformat,*s); } else stream_printf(fd,"%c",*c); }#line 517 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" return MAL_SUCCEED;}#line 525 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"#line 530 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"strIOprint_formatted_nil(stream *fd, str format, char last){ str c; for (c = format; *c; c++) { if (*c == '\\') { c++; #line 431 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" switch(*c){ case 'n': stream_printf(fd,"\n");break; case 't': stream_printf(fd,"\t");break; case 'r': stream_printf(fd,"\r");break; case '\\': stream_printf(fd,"\\");break; default : stream_printf(fd,"\\");stream_printf(fd,"%c",*c); }#line 538 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" } else if (*c == '%') { char newformat[1024]; int i = 0; if (*(c + 1) == '%') { stream_printf(fd, "%c", *c); c++; continue; } while (!isalpha((int) *c) && *c && *c != last && i < 1024) newformat[i++] = *c++; newformat[i++] = 's'; newformat[i] = 0; stream_printf(fd, newformat, "nil"); } else stream_printf(fd, "%c", *c); } return MAL_SUCCEED;}strIOprint_formatted_lng(int *ret, str *format, lng *val){ str c; stream *fd= MCgetClient()->fdout; (void) ret; for (c = *format; *c; c++) { if (*c == '\\') { c++; #line 431 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" switch(*c){ case 'n': stream_printf(fd,"\n");break; case 't': stream_printf(fd,"\t");break; case 'r': stream_printf(fd,"\r");break; case '\\': stream_printf(fd,"\\");break; default : stream_printf(fd,"\\");stream_printf(fd,"%c",*c); }#line 568 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" } else if (*c == '%') { char newformat[1024]; int i = 0; if (*(c + 1) == '%') { stream_printf(fd, "%c", *c); c++; continue; } while (!isalpha((int) *c) && *c && i < 1024) if( *c =='d' ) { break; } else if( *c=='l' && c[1]=='d') { c++; break; } else newformat[i++] = *c++; if( *val == lng_nil){ newformat[i++] = 's'; newformat[i] = 0; stream_printf(fd, newformat, "nil"); } else { char *f= LLFMT; strcpy(newformat+i,f+1); stream_printf(fd, newformat, *val); } } else stream_printf(fd, "%c", *c); } return MAL_SUCCEED;}strIOprint_formatted_str(int *ret, ptr fmt, str *s){ stream *fd = MCgetClient()->fdout; char *format; str c; (void) ret; /* TODO: check format properly !!! including sizes */ format = *(str *) fmt; if (format == NULL) throw(MAL, "io.print", "Format missing"); if (formatMarker(format) != 1) throw(MAL, "io.print", "Too many %%"); if (strNil(*s)) return IOprint_formatted_nil(fd, *(str *) fmt, 's'); #line 477 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" for(c= format;*c; c++){ if( *c=='\\'){ c++; #line 431 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" switch(*c){ case 'n': stream_printf(fd,"\n");break; case 't': stream_printf(fd,"\t");break; case 'r': stream_printf(fd,"\r");break; case '\\': stream_printf(fd,"\\");break; default : stream_printf(fd,"\\");stream_printf(fd,"%c",*c); }#line 480 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" } else if( *c== '%'){ char newformat[1024]; int i=0; if(*(c+1)=='%'){ stream_printf(fd,"%c",*c); c++; continue; } while(*c != 's' && *c && i<1024) newformat[i++]= *c++; newformat[i++]='s'; newformat[i]=0; if(*c!= 's') throw(MAL, "io.print", "Format limitation"); else stream_printf(fd,newformat,*s); } else stream_printf(fd,"%c",*c); }#line 620 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" return MAL_SUCCEED;}strIOprint_oid(int *ret, ptr fmt, oid *s){ stream *fd = MCgetClient()->fdout; char *format; str msg, c; int len = 50; format = *(str *) fmt; if (format == NULL) throw(MAL, "io.print", "Format missing"); if (formatMarker(format) != 1) throw(MAL, "io.print", "Too many %%"); if (*s == oid_nil) msg = GDKstrdup("nil"); else { msg = (str) GDKmalloc(len); OIDtoStr(&msg, &len, s); } #line 477 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" for(c= format;*c; c++){ if( *c=='\\'){ c++; #line 431 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" switch(*c){ case 'n': stream_printf(fd,"\n");break; case 't': stream_printf(fd,"\t");break; case 'r': stream_printf(fd,"\r");break; case '\\': stream_printf(fd,"\\");break; default : stream_printf(fd,"\\");stream_printf(fd,"%c",*c); }#line 480 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" } else if( *c== '%'){ char newformat[1024]; int i=0; if(*(c+1)=='%'){ stream_printf(fd,"%c",*c); c++; continue; } while(*c != 's' && *c && i<1024) newformat[i++]= *c++; newformat[i++]='s'; newformat[i]=0; if(*c!= 's') throw(MAL, "io.print", "Format limitation"); else stream_printf(fd,newformat,msg); } else stream_printf(fd,"%c",*c); }#line 645 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" GDKfree(msg); if (*ret == EOF) throw(MAL, "io.print", "End-of-file encountered"); return MAL_SUCCEED;}strIOprint_formatted_bit(int *ret, ptr fmt, bit *s){ stream *fd = MCgetClient()->fdout; char *format; str msg; str c; /* TODO: check format properly !!! including sizes */ format = *(str *) fmt; if (format == NULL) throw(MAL, "io.print", "Format missing"); if (formatMarker(format) != 1) throw(MAL, "io.print", "Too many %%"); if (*s == bit_nil) return IOprint_formatted_nil(fd, *(str *) fmt, 's'); if (*s) msg = "true"; else msg = "false"; #line 477 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" for(c= format;*c; c++){ if( *c=='\\'){ c++; #line 431 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" switch(*c){ case 'n': stream_printf(fd,"\n");break; case 't': stream_printf(fd,"\t");break; case 'r': stream_printf(fd,"\r");break; case '\\': stream_printf(fd,"\\");break; default : stream_printf(fd,"\\");stream_printf(fd,"%c",*c); }#line 480 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" } else if( *c== '%'){ char newformat[1024]; int i=0; if(*(c+1)=='%'){ stream_printf(fd,"%c",*c); c++; continue; } while(*c != 's' && *c && i<1024) newformat[i++]= *c++; newformat[i++]='s'; newformat[i]=0; if(*c!= 's') throw(MAL, "io.print", "Format limitation"); else stream_printf(fd,newformat,msg); } else stream_printf(fd,"%c",*c); }#line 673 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" if (*ret == EOF) throw(MAL, "io.print", "End-of-file encountered"); return MAL_SUCCEED;}#line 694 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"strIOexport(int *ret, int *bid, str *fnme){ BAT *b; stream *s = open_wastream(*fnme); if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "io.export", "Cannot access descriptor"); } if (s == NULL || stream_errnr(s)) { *ret = FALSE; throw(MAL, "io.export", "Could not open file"); } BATprintf(s, b); stream_close(s); stream_destroy(s); *ret = TRUE; BBPunfix(b->batCacheid); return MAL_SUCCEED;}#line 719 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"#define COMMA ','strIOimport(int *ret, int *bid, str *fnme){ BAT *b; int (*hconvert) (str, int *, ptr *), (*tconvert) (str, int *, ptr *); size_t bufsize = 2048; /* NIELS:tmp change used to be 1024 */ char *base, *cur, *end; char *buf = (char *) GDKmalloc(bufsize); ptr h = 0, t = 0; int lh = 0, lt = 0; FILE *fp = fopen(*fnme, "r"); if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "io.import", "Cannot access descriptor"); } hconvert = BATatoms[BAThtype(b)].atomFromStr; tconvert = BATatoms[BATttype(b)].atomFromStr;#line 740 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" if (fp == NULL) { BBPunfix(b->batCacheid); throw(MAL, "io.import", "Could not open file"); } else { int fn; struct stat st; if ((fn = fileno(fp)) <= 0) { BBPunfix(b->batCacheid); throw(MAL, "io.import", "Fileno fails"); } if (fstat(fn, &st) != 0) { BBPunfix(b->batCacheid); throw(MAL, "io.imports", "Fstat fails"); } (void) fclose(fp); if (st.st_size <= 0) { BBPunfix(b->batCacheid); throw(MAL, "io.imports", "File is empty or fstat broken"); } base = cur = (char *) MT_mmap(*fnme, MMAP_SEQUENTIAL, 0, st.st_size); end = cur + st.st_size; if (cur == (char *) -1) { BBPunfix(b->batCacheid); throw(MAL, "io.mport", "MT_mmap failed"); } }#line 772 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" while (cur < end) { str dst = buf, src = cur, p = strchr(cur, '\n'); size_t l = p - cur; if (!p) { p = end; } else while (src[l - 1] == '\\') { #line 792 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" if (buf+bufsize < dst+l) { int len = dst - buf; size_t inc = (size_t) ((dst+l) - buf); buf = (char*) GDKrealloc((void*) buf, bufsize = MAX(inc,bufsize)*2); dst = buf + len; } memcpy(dst, src, l-1);#line 780 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" dst += l - 1; src += l + 1; if ((p = strchr(src, '\n')) == 0) { p = end; break; } l = p - src; } #line 792 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" if (buf+bufsize < dst+l) { int len = dst - buf; size_t inc = (size_t) ((dst+l) - buf); buf = (char*) GDKrealloc((void*) buf, bufsize = MAX(inc,bufsize)*2); dst = buf + len; } memcpy(dst, src, l-1);#line 789 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"#line 800 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" dst[l] = 0; cur = p + 1;#line 805 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" for (p = buf; *p && GDKisspace(*p); p++) ; if (*p == '#') continue;#line 821 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" #line 811 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" for (;*p && *p != '['; p++); if (*p) for (p++; *p && GDKisspace(*p); p++); if (*p == 0) { char msg[BUFSIZ]; BBPunfix(*ret=b->batCacheid); snprintf(msg,BUFSIZ,"error in input %s",buf); throw(MAL, "io.import", msg); } p += hconvert(p, &lh, (ptr *) &h);#line 821 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" #line 811 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" for (;*p && *p != COMMA; p++); if (*p) for (p++; *p && GDKisspace(*p); p++); if (*p == 0) { char msg[BUFSIZ]; BBPunfix(*ret=b->batCacheid); snprintf(msg,BUFSIZ,"error in input %s",buf); throw(MAL, "io.import", msg); } p += tconvert(p, <, (ptr *) &t);#line 822 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" BUNins(b, h, t, FALSE);#line 828 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"#ifndef WIN32#define MAXBUF 40*MT_pagesize() if ((unsigned) (cur - base) > MAXBUF) { MT_munmap(base, MAXBUF); base += MAXBUF; }#endif }#line 839 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx" if (h) GDKfree(h); if (t) GDKfree(t); GDKfree(buf); MT_munmap(base, end - base); BBPkeepref(*ret= b->batCacheid); return MAL_SUCCEED;}#line 850 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/mal_io.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -