void tDxfExport2::writeEntities(tModel *m) { dw->sectionEntities(); writeLines(m); writePolylines(m); dw->sectionEnd(); }
void mainz() { //int ints[10]; //int *ip = &ints[2]; //printf("%d\n",ip - ints); //printf("%d\n",my_strcmp("changer","xx")); //char s[20] = "hello worldx"; //char t[20] = "world"; //my_strcat(s,t); //printf("%s\n",s); //printf("%d\n",my_strend(s,t)); // 自定义声明 typedef int (*PF)(char []); char strings[][12] = {"xxxx","yyy"}; int len , nlines =0; char *lines[100]; char line[100]; char *p; // 函数指针 //int (*getP)(char []) = getLine; PF getP = getLine; while((len = getP(line))>0) { p = (char *)malloc(len * sizeof(char)); strcpy(p,line); lines[nlines++] = p; } qsort(lines,0,nlines-1); writeLines(lines,nlines); }
fivePointSix() { char *plines[] = { "123", "456", "789" }; // define a pointer array. int i = 3; writeLines(plines, i); /* The code below is wrong, for plines here is array, not pointer, it can not ++ itself. * writeLines(char *plines[], int i) is ok, plines here is pointer, it can ++ itself. while (i-- > 0) printf("%s\n", *(plines++)); */ }
//------------------------------------------------------------------------------ // writeLines (vector <Line>, string) : Creates an output file stream from // the filename specified at arg2, then calls writeLines (vector <Line>, // ostream) to output the XGremlin writelines data to this file. // void writeLines (vector <Line> Lines, string Filename) throw (int) { ofstream ListFile (Filename.c_str(), ios::out); if (! ListFile.is_open()) { cout << "Error: Cannot open " << Filename << " for output. List writing ABORTED." << endl; throw int (LC_FILE_OPEN_ERROR); } try { writeLines (Lines, ListFile); } catch (const char *Err) { cout << "Error writing " << Err << " to " << Filename << ". List writing ABORTED." << endl; throw int (LC_FILE_WRITE_ERROR); } }
int main(int argc, const char *argv[]) { ofstream out; out.open("castel.tex"); double px[DEGREE+1]= {20, 100, 900, 1100}; double py[DEGREE+1]= {20, 500, 500, 200}; double u= 2.0/3.0; int step= 500; writeHeader(out, px, py); writeBezier(out, step, px, py); writeLines(out, u, px, py); writeBP(out, u, px, py); writeFooter(out); if (out.is_open()) { out.close(); } return 0; }
void BufferedTextOutput::popBundle() { AutoMutex _l(mLock); BufferState* b = getBuffer(); b->bundle--; LOG_FATAL_IF(b->bundle < 0, "TextOutput::popBundle() called more times than pushBundle()"); if (b->bundle < 0) b->bundle = 0; if (b->bundle == 0) { // Last bundle, write out data if it is complete. If it is not // complete, don't write until the last line is done... this may // or may not be the write thing to do, but it's the easiest. if (b->bufferPos > 0 && b->atFront) { struct iovec vec; vec.iov_base = b->buffer; vec.iov_len = b->bufferPos; writeLines(vec, 1); b->restart(); } } }
/* * Read commands until we are told to stop. */ static void doCommands(void) { const char *cp; char *endbuf, buf[USERSIZE]; int len, num1, num2; smallint have1, have2; while (TRUE) { /* Returns: * -1 on read errors or EOF, or on bare Ctrl-D. * 0 on ctrl-C, * >0 length of input string, including terminating '\n' */ len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1); if (len <= 0) return; endbuf = &buf[len - 1]; while ((endbuf > buf) && isblank(endbuf[-1])) endbuf--; *endbuf = '\0'; cp = skip_blank(buf); have1 = FALSE; have2 = FALSE; if ((curNum == 0) && (lastNum > 0)) { curNum = 1; curLine = lines.next; } if (!getNum(&cp, &have1, &num1)) continue; cp = skip_blank(cp); if (*cp == ',') { cp++; if (!getNum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastNum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curNum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addLines(num1 + 1); break; case 'c': deleteLines(num1, num2); addLines(num1); break; case 'd': deleteLines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { bb_error_msg("bad file command"); break; } cp = skip_blank(cp); if (*cp == '\0') { if (fileName) printf("\"%s\"\n", fileName); else puts("No file name"); break; } free(fileName); fileName = xstrdup(cp); break; case 'i': addLines(num1); break; case 'k': cp = skip_blank(cp); if ((*cp < 'a') || (*cp > 'z') || cp[1]) { bb_error_msg("bad mark name"); break; } marks[*cp - 'a'] = num2; break; case 'l': printLines(num1, num2, TRUE); break; case 'p': printLines(num1, num2, FALSE); break; case 'q': cp = skip_blank(cp); if (have1 || *cp) { bb_error_msg("bad quit command"); break; } if (!dirty) return; len = read_line_input(NULL, "Really quit? ", buf, 16, /*timeout*/ -1); /* read error/EOF - no way to continue */ if (len < 0) return; cp = skip_blank(buf); if ((*cp | 0x20) == 'y') /* Y or y */ return; break; case 'r': if (*cp && !isblank(*cp)) { bb_error_msg("bad read command"); break; } cp = skip_blank(cp); if (*cp == '\0') { bb_error_msg("no file name"); break; } if (!have1) num1 = lastNum; if (readLines(cp, num1 + 1)) break; if (fileName == NULL) fileName = xstrdup(cp); break; case 's': subCommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { bb_error_msg("bad write command"); break; } cp = skip_blank(cp); if (!have1) { num1 = 1; num2 = lastNum; } if (*cp == '\0') cp = fileName; if (cp == NULL) { bb_error_msg("no file name specified"); break; } writeLines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printLines(curNum - 21, curNum, FALSE); break; case '.': printLines(curNum - 11, curNum + 10, FALSE); break; default: printLines(curNum, curNum + 21, FALSE); break; } break; case '.': if (have1) { bb_error_msg("no arguments allowed"); break; } printLines(curNum, curNum, FALSE); break; case '-': if (setCurNum(curNum - 1)) printLines(curNum, curNum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printLines(num2, num2, FALSE); break; } if (setCurNum(curNum + 1)) printLines(curNum, curNum, FALSE); break; default: bb_error_msg("unimplemented command"); break; } } }
status_t BufferedTextOutput::print(const char* txt, size_t len) { //printf("BufferedTextOutput: printing %d\n", len); AutoMutex _l(mLock); BufferState* b = getBuffer(); const char* const end = txt+len; status_t err; while (txt < end) { // Find the next line. const char* first = txt; while (txt < end && *txt != '\n') txt++; // Include this and all following empty lines. while (txt < end && *txt == '\n') txt++; // Special cases for first data on a line. if (b->atFront) { if (b->indent > 0) { // If this is the start of a line, add the indent. const char* prefix = stringForIndent(b->indent); err = b->append(prefix, strlen(prefix)); if (err != NO_ERROR) return err; } else if (*(txt-1) == '\n' && !b->bundle) { // Fast path: if we are not indenting or bundling, and // have been given one or more complete lines, just write // them out without going through the buffer. // Slurp up all of the lines. const char* lastLine = txt+1; while (txt < end) { if (*txt++ == '\n') lastLine = txt; } struct iovec vec; vec.iov_base = (void*)first; vec.iov_len = lastLine-first; //printf("Writing %d bytes of data!\n", vec.iov_len); writeLines(vec, 1); txt = lastLine; continue; } } // Append the new text to the buffer. err = b->append(first, txt-first); if (err != NO_ERROR) return err; b->atFront = *(txt-1) == '\n'; // If we have finished a line and are not bundling, write // it out. //printf("Buffer is now %d bytes\n", b->bufferPos); if (b->atFront && !b->bundle) { struct iovec vec; vec.iov_base = b->buffer; vec.iov_len = b->bufferPos; //printf("Writing %d bytes of data!\n", vec.iov_len); writeLines(vec, 1); b->restart(); } } return NO_ERROR; }
/* * Read commands until we are told to stop. */ static void doCommands(void) { const char *cp; char *endbuf, *newname, buf[USERSIZE]; int len, num1, num2, have1, have2; while (TRUE) { printf(": "); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) return; len = strlen(buf); if (len == 0) return; endbuf = &buf[len - 1]; if (*endbuf != '\n') { bb_error_msg("command line too long"); do { len = fgetc(stdin); } while ((len != EOF) && (len != '\n')); continue; } while ((endbuf > buf) && isblank(endbuf[-1])) endbuf--; *endbuf = '\0'; cp = buf; while (isblank(*cp)) cp++; have1 = FALSE; have2 = FALSE; if ((curNum == 0) && (lastNum > 0)) { curNum = 1; curLine = lines.next; } if (!getNum(&cp, &have1, &num1)) continue; while (isblank(*cp)) cp++; if (*cp == ',') { cp++; if (!getNum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastNum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curNum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addLines(num1 + 1); break; case 'c': deleteLines(num1, num2); addLines(num1); break; case 'd': deleteLines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { bb_error_msg("bad file command"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { if (fileName) printf("\"%s\"\n", fileName); else printf("No file name\n"); break; } newname = strdup(cp); if (newname == NULL) { bb_error_msg("no memory for file name"); break; } if (fileName) free(fileName); fileName = newname; break; case 'i': addLines(num1); break; case 'k': while (isblank(*cp)) cp++; if ((*cp < 'a') || (*cp > 'a') || cp[1]) { bb_error_msg("bad mark name"); break; } marks[*cp - 'a'] = num2; break; case 'l': printLines(num1, num2, TRUE); break; case 'p': printLines(num1, num2, FALSE); break; case 'q': while (isblank(*cp)) cp++; if (have1 || *cp) { bb_error_msg("bad quit command"); break; } if (!dirty) return; printf("Really quit? "); fflush(stdout); buf[0] = '\0'; fgets(buf, sizeof(buf), stdin); cp = buf; while (isblank(*cp)) cp++; if ((*cp == 'y') || (*cp == 'Y')) return; break; case 'r': if (*cp && !isblank(*cp)) { bb_error_msg("bad read command"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { bb_error_msg("no file name"); break; } if (!have1) num1 = lastNum; if (readLines(cp, num1 + 1)) break; if (fileName == NULL) fileName = strdup(cp); break; case 's': subCommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { bb_error_msg("bad write command"); break; } while (isblank(*cp)) cp++; if (!have1) { num1 = 1; num2 = lastNum; } if (*cp == '\0') cp = fileName; if (cp == NULL) { bb_error_msg("no file name specified"); break; } writeLines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printLines(curNum-21, curNum, FALSE); break; case '.': printLines(curNum-11, curNum+10, FALSE); break; default: printLines(curNum, curNum+21, FALSE); break; } break; case '.': if (have1) { bb_error_msg("no arguments allowed"); break; } printLines(curNum, curNum, FALSE); break; case '-': if (setCurNum(curNum - 1)) printLines(curNum, curNum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printLines(num2, num2, FALSE); break; } if (setCurNum(curNum + 1)) printLines(curNum, curNum, FALSE); break; default: bb_error_msg("unimplemented command"); break; } } }