#include #include #define bool char #define MAX 1000000 char buf[MAX + 2]; int main(int argc, char* argv[]) { if(argc >= 2){ fprintf(stderr,"這個程式不需要額外參數\n"); return 2; } bool toolong=0,newsec=1,seccom=1; int len; while(1){ fgets(buf, MAX + 1, stdin); if(feof(stdin)){ break; } toolong=0,seccom=0; len=strlen(buf); if(len == 0){ /* 應該不會發生,此段可刪 */ fprintf(stderr,"發生不明錯誤,立即中止!\n"); return 1; } if(len == 1){ /* 空白行 */ if(newsec){ /* 判斷連續一堆空白行 */ seccom=1; continue; } fprintf(stdout,");\n"); newsec=1; seccom=1; continue; } if(buf[len - 1] != '\n'){ /* 如果字數超過 MAX */ toolong=1; }else{ buf[len - 1]='\0'; } if(newsec){ fprintf(stdout,"document.write(\n" "\'%s",buf); newsec=0; }else{ fprintf(stdout,"+\'%s",buf); } if(toolong){ do{ fgets(buf, MAX + 1, stdin); len=strlen(buf); if(buf[len - 1] == '\n'){ buf[len - 1]='\0'; toolong=0; } fprintf(stdout,"%s",buf); }while(toolong); } fprintf(stdout,"\'\n"); } if(!seccom){ /* 我不知結尾有沒有空白行,所以多一個判斷 */ fprintf(stdout,");\n"); } return 0; }