void video_put(const char * str, byte newColor, const int row, const int col) { int i, j; int position = 2*(row*COLUMNS + col); for (i = 0; str[i]; i++) { if (str[i] == '\n' || str[i] == '\r') { NEWLINE(position, newColor); continue; } if (str[i] == '\t') { for (j = 0; j < 4; ++j) { video[position++] = ' '; video[position++] = newColor; } continue; } video[position++] = str[i]; video[position++] = newColor; } }
void video_printc(const char c) { int j; if (status.pos >= 2*LINES*COLUMNS) video_scrolling(1); if (c == '\n' || c == '\r') { NEWLINE(status.pos, status.color); if (status.pos >= 2*LINES*COLUMNS) video_scrolling(1); return; } if (c == '\t') { for (j = 0; j < 4; ++j) { video[status.pos++] = ' '; video[status.pos++] = status.color; } return; } video[status.pos++] = c; video[status.pos++] = status.color; video_update_cursor(); }
void video_newline() { NEWLINE(status.pos, status.color); if (status.pos >= 2*LINES*COLUMNS) video_scrolling(1); video_update_cursor(); }
void add_circ(int p1, int p2, int p3, std::string fileName) { std::ostringstream sstream; sstream << "Circle(" << NEWLINE() << ") = {" << p1 << ", " << p2 << ", " << p3 << "};"; add_infile(sstream.str(), fileName); }
void video_print(const char * str) { int i = 0, j; for (i = 0; str[i]; i++) { if (str[i] == '\n' || str[i] == '\r') { NEWLINE(status.pos, status.color); if (status.pos >= 2*LINES*COLUMNS) video_scrolling(1); continue; } if (str[i] == '\t') { for (j = 0; j < 4; ++j) { video[status.pos++] = ' '; video[status.pos++] = status.color; } continue; } video[status.pos++] = str[i]; video[status.pos++] = status.color; } video_update_cursor(); if (status.pos >= 2*LINES*COLUMNS) video_scrolling(1); }
void add_ell(int p1, int p2, int p3, int p4, std::string fileName) { std::ostringstream sstream; sstream << "Ellipse(" << NEWLINE() << ") = {" << p1 << ", " << p2 << ", " << p3 << ", " << p4 << "};"; add_infile(sstream.str(), fileName); }
main(int argc,char *argv[]) { if (argc != 2) { fprintf(stderr,"usage: %s name-for-package\n", argv[0]); exit(1); } NEWLINE(); PUTS("package "); PUTS(argv[1]); PUTS(" : Cc_Info =\n"); PUTS("\tstruct\n"); PUTS("\t\t");COMMENT("all sizes in bytes"); NEWLINE(); PUTVAL("intSzB", sizeof(int)); PUTVAL("shortSzB", sizeof(short)); PUTVAL("longSzB", sizeof(long)); NEWLINE(); PUTVAL("charSzB", sizeof(char)); NEWLINE(); PUTVAL("floatSzB", sizeof(float)); PUTVAL("doubleSzB", sizeof(double)); NEWLINE(); PUTVAL("ptrSzB", sizeof(int *)); NEWLINE(); PUTVAL("unionAlign", sizeof(int *)); PUTVAL("structAlign", sizeof(int *)); NEWLINE(); PUTS("\tend "); PUTS("/* package "); PUTS(argv[1]); PUTS(" */\n"); exit(0); }
/** * Callback function for readJpegFileContent. * * @param buf A pointer to a buffer. * @param siz A size of the buffer. */ void callback_func(int done, int total, uint8_t *buf, size_t siz) { fwrite(buf, siz, 1, work.fp); static int n = 0; int tmp = done * 100 / total; if (n != tmp) { n = tmp; DEBMSG("Writing...: %3d%%", n); NEWLINE(); } }
void add_multline(std::string type, std::vector<int> &p, std::string fileName) { std::ostringstream sstream; sstream << type << "(" << NEWLINE() << ") = {"; for(unsigned int i = 0; i < p.size(); i++) { if(i) sstream << ", "; sstream << p[i]; } sstream << "};"; add_infile(sstream.str(), fileName); }
/** * Entry point. */ int main(void) { DEBMSG("Camera module"); NEWLINE(); DEBMSG("Resetting..."); NEWLINE(); wait(1); if (cam1.reset() == 0) { DEBMSG("Reset OK."); NEWLINE(); } else { DEBMSG("Reset fail."); NEWLINE(); error("Reset fail."); } wait(1); int cnt = 0; while (1) { char fname[64]; snprintf(fname, sizeof(fname) - 1, FILENAME, cnt); int r = capture(&cam1, fname); if (r == 0) { DEBMSG("[%04d]:OK.", cnt); NEWLINE(); } else { DEBMSG("[%04d]:NG. (code=%d)", cnt, r); NEWLINE(); error("Failure."); } cnt++; } }
/** * Capture. * * @param cam A pointer to a camera object. * @param filename The file name. * * @return Return 0 if it succeed. */ int capture(Camera_LS_Y201 *cam, char *filename) { /* * Take a picture. */ if (cam->takePicture() != 0) { return -1; } DEBMSG("Captured."); NEWLINE(); /* * Open file. */ work.fp = fopen(filename, "wb"); if (work.fp == NULL) { return -2; } /* * Read the content. */ DEBMSG("%s", filename); NEWLINE(); if (cam->readJpegFileContent(callback_func) != 0) { fclose(work.fp); return -3; } fclose(work.fp); /* * Stop taking pictures. */ cam->stopTakingPictures(); return 0; }
void add_compound(std::string type, List_T *list, std::string fileName) { std::ostringstream sstream; if(SplitFileName(fileName)[2] != ".geo") sstream << "CreateTopology;\n"; if (type == "Surface"){ sstream << "Compound " << type << "(" << NEWSURFACE()+1000 << ") = {" << list2string(list) << "};"; } else if (type == "Line"){ sstream << "Compound " << type << "(" << NEWLINE()+1000 << ") = {" << list2string(list) << "};"; } else{ sstream << "Compound " << type << "(" << NEWREG() << ") = {" << list2string(list) << "};"; } add_infile(sstream.str(), fileName); }
void video_putc(char c, const byte newColor, const int row, const int col) { int j; int position = 2*(row*COLUMNS + col); if (c == '\n' || c == '\r') { NEWLINE(position, newColor); return; } if (c == '\t') { for (j = 0; j < 4; ++j) { video[position++] = ' '; video[position++] = newColor; } return; } video[position++] = c; video[position++] = newColor; }
/* lex a source buffer for a program */ L_TOKEN* LexSourceBuffer(const char* source_buffer, char** stripped, GRAMMAR_TABLE table) { const char* buffer; char* format; int* lineNumbers; int line; int size; int i, j; int a, b; L_TOKEN* start = NULL; L_TOKEN* end = NULL; buffer = source_buffer; size = strlen(buffer); // count lines lineNumbers = (int*)malloc((size+1)*sizeof(int)); line = 0; for (i = 0; i <= size; i++) { lineNumbers[i] = line; if (buffer[i] == '\n') line++; } // strip clean format = (char*)malloc(size+1); j = 0; for (i = 0; i < size; i++) { if (buffer[i] == '/' && buffer[i+1] == '/') { // inline comments while (i < size && buffer[i] != '\n') i++; i--; } else if (buffer[i] == '/' && buffer[i+1] == '*') { // multiline comments i++; i++; while (i < size - 1 && (buffer[i] != '*' || buffer[i+1] != '/')) { i++; } i++; } #ifdef IGNORE_MACROS else if (buffer[i] == '#') { while (i < size && buffer[i] != '\n') i++; i--; } #endif #ifdef SEMICOLON_COMMENTS else if (buffer[i] == ';') { while (i < size && buffer[i] != '\n') i++; i--; } #endif else if (isSpace(buffer[i])) { // whitespace format[j] = ' '; lineNumbers[j] = lineNumbers[i]; while (i < size && isSpace(buffer[i])) { if (buffer[i] == '\n') { format[j] = '\n'; lineNumbers[j] = lineNumbers[i]; } i++; } i--; j++; } else if (buffer[i] == '"' || buffer[i] == '\'') { char quote = buffer[i]; // string format[j++] = buffer[i++]; while (i < size - 1 && buffer[i] != quote) { if (buffer[i] == '\\') { lineNumbers[j] = lineNumbers[i]; format[j++] = buffer[i++]; } lineNumbers[j] = lineNumbers[i]; format[j++] = buffer[i++]; } lineNumbers[j] = lineNumbers[i]; format[j++] = buffer[i]; } else { // character lineNumbers[j] = lineNumbers[i]; format[j] = buffer[i]; j++; } } format[j] = 0; size = j; // lex // printf("Lexing...\n\n"); for (i = 0; i < size; i++) { line = lineNumbers[i]; if (isAlpha(format[i])) { a = i; // alpha while (i < size && (isAlpha(format[i]) || isNumeric(format[i]) || format[i] == '_')) { i++; } b = i; LexAddBlock(&start, &end, IDENTIFIER(format, a, b, line, table)); i--; } else if (isNumeric(format[i])) { // numeric a = i; while (i < size && isNumeric(format[i])) { i++; } if (format[i] == '.') { i++; while (i < size && isNumeric(format[i])) { i++; } b = i; LexAddBlock(&start, &end, FLOAT(format, a, b, line)); i--; } else { b = i; LexAddBlock(&start, &end, INTEGER(format, a, b, line)); i--; } } else if (format[i] == '"' || format[i] == '\'') { char delimiter = format[i]; // string a = i++; while (i < size && format[i] != delimiter) { i++; } b = i++; LexAddBlock(&start, &end, STRING(format, a, b+1, line)); i--; } else if (isGlyph(format[i])) { a = i; b = 0; // symbol while (i < size && isGlyph(format[i])) { i++; if (FindToken(&format[a], i - a, table)) b = i; } b = b ? b : i; LexAddBlock(&start, &end, TOKEN(format, a, b, line, table)); i = b - 1; } else if (format[i] == '\n') { #ifdef LEX_NEWLINES // end line LexAddBlock(&start, &end, NEWLINE(line)); #endif } else if (format[i] == ' ') { // whitespace } else { // ? PrintLexing(start); printf("Syntax error on line %i: ", line+1); printf("Illegal token %i.\n", format[i]); FreeLexing(start, format); *stripped = 0; return NULL; } } #ifdef LEX_NEWLINES // add newline to the end LexAddBlock(&start, &end, NEWLINE(line)); #endif // add $ to the end LexAddBlock(&start, &end, EOFSYMBOL(line)); free(lineNumbers); *stripped = format; return start; }
void drawOSD() { float x; float y; float tab; drawFrameSet2D(); glEnable(GL_BLEND); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBindTexture(GL_TEXTURE_2D, 0); #ifdef WITHOUT_AGAR // Top middle y = 10; glColor4f(1,1,1,1); drawFontWordCA(video.screenW / 2, y, "Hit SPACE to start a new simulation"); drawFontWordCA(video.screenW / 2, y += fontHeight, "Hold down a mouse button and move it around to change your orientation."); drawFontWordCA(video.screenW / 2, y += fontHeight, "Use the scroll wheel, or the A and Z keys to zoom in and out."); glColor4f(1,1,1,.5f); drawFontWordCA(video.screenW / 2, y += fontHeight, "press F1 for keyboard commands help."); #endif // Right DUHC(); drawFontWordRA((float)video.screenW - 10, (float)video.screenH - 10 - fontHeight * 1.0f, "press F1 for help"); drawFontWordRA((float)video.screenW - 10, (float)video.screenH - 10 - fontHeight * 3.0f, GRAVIT_VERSION); drawFontWordRA((float)video.screenW - 10, (float)video.screenH - 10 - fontHeight * 2.0f, GRAVIT_COPYRIGHT); // Left y = 10; x = 10; tab = getWordWidth("M") * 17; if (view.textMode == TM_STANDARD) { if (state.fileName) { DUH("simulation name", state.fileName); } else { DUH("simulation name", "-"); } DUH("particles", va("%i", state.particleCount)); DUH("avg video fps", va("%3.2f", fpsCurrentAverageFPS)); DUH("avg video frame time", va("%.0fms", fpsCurrentAverageFT)); DUH("last record frame time", va("%ims", view.deltaRecordFrame)); DUH("actual frames", va("%i", state.totalFrames)); DUH("recording skip", va("%i", state.historyNFrame)); if (view.frameSkip && state.mode & SM_PLAY) { DUH("display frame", va("%i (%i)", state.currentFrame, view.frameSkip)); } else { DUH("display frame", va("%i", state.currentFrame)); } DUH("recorded frames", va("%i", state.frame)); DUH("max frames", va("%i", state.historyFrames)); DUH("particle vertices", va("%i", view.vertices)); #if NBODY_METHOD == METHOD_OT DUH("tree nodes allocated", va("%i", view.recordNodes)); #endif DUH("memory allocated", va("%.1fmb", (float)state.memoryAllocated / 1024 / 1024)); if (state.mode & SM_RECORD) { glColor4f(1,0,0,.8f); y += fontHeight; y = drawFontWord(x, y, "RECORDING"); DUHC(); DUH("time left", va("~%0.1f minutes", (float)view.deltaRecordFrame * (state.historyFrames - state.frame) / 1000 / 60)); switch (view.recordStatus) { case 0: default: if (state.mode & SM_RECORD) { DUH("status", "rendering ..."); } else { DUH("status", "dormant"); } break; case 1: DUH("status", va("generating tree %.1f%%", (float)view.recordParticlesDone/state.particleCount*100)); break; case 2: DUH("status", va("applying forces %.1f%%", (float)view.recordParticlesDone/state.particleCount*100)); break; case 3: DUH("status", "freeing tree"); break; } } else if (state.mode & SM_PLAY) { glColor4f(0,1,0,.8f); y += fontHeight; y = drawFontWord(x, y, "PLAY"); } else if (state.currentlySpawning) { glColor4f(1,1,0,.8f); y += fontHeight; y = drawFontWord(x, y, "SPAWNING"); DUHC(); DUH("status", va("%.1f%%", (float)view.recordParticlesDone/state.particleCount*100)); } if (view.screenshotLoop) { glColor4f(1,0,0,.8f); y += fontHeight * 2; y = drawFontWord(x, y, "AUTO SCREENSHOT"); } // show renderer FPS average (if we have meaningful values) if ((view.timed_frames > 1) && (view.totalRenderTime > SDL_TIMESLICE )) { if (state.mode & SM_RECORD) { glColor4f(0,1,1,.5f); /*torquise*/ } else { DUHC(); y += fontHeight; } // XXX: This might be too many stats. I'll implement this in the ajax windowing screens. DUH("avg renderer fps", va("%5.2f", (float) view.timed_frames/ (float) view.totalRenderTime * 1000.0f )) /* DUH("avg renderer frame time", va("%4.1f ms", (float) view.totalRenderTime / (float) view.timed_frames )); */ DUHC(); } /* big = state.particleCount*state.particleCount-state.particleCount; DUH("total calcs", va("%-5i %3.2f%% (max: %i)", otGetNCalcs(), (float)otGetNCalcs()/big*100, state.particleCount*state.particleCount-state.particleCount)); DUH("space calcs", va("%-5i %3.2f%%", otGetSCalcs(), (float)100 * otGetSCalcs() / otGetNCalcs())); DUH("particle calcs", va("%-5i %3.2f%%", otGetPCalcs(), (float)100 * otGetPCalcs() / otGetNCalcs())); */ } if (view.textMode >= TM_HELP1) { WHITEHEADING(va("HELP!", view.textMode - TM_HELP1 + 1)); NEWLINE(); DUHC(); DUH("F1", "General Shortcut Keys"); DUH("F2", "Visual Effects Keys"); DUH("` (above TAB) or 1", "Use the Console"); DUH("ESC", "Exit Console/Help/Gravit"); } if (view.textMode == TM_HELP1) { WHITEHEADINGNL("GENERAL SHORTCUT KEYS"); WHITEHEADINGNL("Recording/Playback"); DUHC(); DUH("SPACE", "spawn particles"); DUH("F5", "replay"); DUH("F6", "record"); DUH("F7", "pause"); DUH("Q W", "decrease / increase playback speed"); DUH("CTRL + S", "quick save"); WHITEHEADINGNL("View Controls"); DUHC(); DUH("mouse X Y + button", "rotate (with mouse button)"); DUH("A Z", "zoom"); WHITEHEADINGNL("Stereoscopy"); DUHC(); DUH("S", "toggle stereo mode"); DUH("D F", "decrease / increase stereoseparation"); WHITEHEADINGNL("Other"); DUHC(); DUH("T", "display current oct tree"); DUH("O", "toggles drawing text"); DUH("P", "toggles drawing Sky background"); DUH("F9", "take one screenshot"); DUH("F10", "take a screenshot every frame (CAREFUL!)"); } if (view.textMode == TM_HELP2) { WHITEHEADINGNL("VISUAL EFFECTS KEYS"); WHITEHEADINGNL("Colours"); DUHC(); DUH("/", "colour mode (mass/vel/acc)"); DUH("L", "blending mode"); WHITEHEADINGNL("Particles"); DUHC(); DUH("\\", "particle render mode (circle/texture)"); DUH("= -", "min particle size"); DUH("[ ]", "max particle size"); WHITEHEADINGNL("Particle Tail"); DUHC(); DUH("X", "tail fade"); DUH("C V", "tail opacity"); DUH("B N", "tail length less/more"); DUH("M", "tail length infinite/none"); DUH(", (comma) . (period)", "tail resolution"); DUH("; (semicolon) ' (quote)", "tail width"); } }
void Tarefa_GPRS(void) { /* task setup */ /* Tarefa do Logger para comunicacao com modem na UART2 a 9600 bps */ #define SEND_STRING0 "AT+CIPSENDI=0,\"GET node/set.json?nodeid=10&data=" #define SEND_STRING1 "}&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1\\r\\nHost: emon-gpsnetcms.rhcloud.com\\r\\n\\r\\n\\r\\n\"" #define SEND_STRING2 "AT+CIPSENDI=0,\"GET /input/post.json?json={pow:" //#define SEND_STRING3 ("}&" API_KEY " HTTP/1.1\r\nHost: " ESP_TCP_SERVER_NAME "\r\n\r\n\r\n") #define SEND_STRING3 "}&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1\\r\\nHost: emon-gpsnetcms.rhcloud.com\\r\\n\\r\\n\\r\\n\"" const char resp_200_OK[] = "HTTP/1.1 200 OK"; #define REPLY_LENGTH (sizeof(resp_200_OK) + 2) char valor[] = "01"; INT8U cnt = 1; volatile char c; static char resp_serv[REPLY_LENGTH]; static INT8U resp_cnt = 0; INT16U tentativas = 0; /* init ESP_UART */ uart_init(ESP_UART,ESP_BAUD,ESP_UART_BUFSIZE,ESP_UART_PINS,ESP_MUTEX,ESP_MUTEX_PRIO); /* init modem */ modem_send("AT\r\n"); modem_wait_reply(); modem_send("AT+CWMODE=3\r\n"); modem_wait_reply(); modem_send(("AT+CWJAP=\"" ESP_AP "\",\"" ESP_PWD "\"\r\n")); modem_wait_reply(); modem_send("AT+CIPCREATE=\"TCP\",10201,2048\r\n"); modem_wait_reply(); modem_send("AT+CIPCONNECT=0,\"54.160.189.224\",80\r\n"); modem_wait_reply(); /* task main loop */ for (;;) { DelayTask(5000); /* delay de 5s */ /* Comando de envio GET /input/post.json?json={campo:valor}&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1 Host:emon-gpsnetcms.rhcloud.com GET /node/set.json?nodeid=10&data=20,20,20,20&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1 Host:emon-gpsnetcms.rhcloud.com */ tentativas++; modem_send(SEND_STRING2); sprintf(valor,"%d", cnt); modem_send(valor); modem_send(SEND_STRING3); NEWLINE(); //modem_wait_reply(); INT8U keep_data = 0; DelayTask(1000); /* delay de 1s */ resp_cnt = 0; while((c=modem_receive()) != (CHAR8)-1) { putchar_usb(c); if (keep_data < 2){ if (c=='+') { keep_data++; } }else{ resp_server_ok[resp_cnt++]=c; if(resp_cnt == 9) { if(c=='1'){ resp_cnt = 0; break; } } } } while((c=modem_receive()) != (CHAR8)-1) { putchar_usb(c); } modem_send("AT+CIPRD=0\r\n"); DelayTask(10); /* delay de 10ms */ /* resposta: HTTP/1.1 200 OK .Date: Wed, 03 Dec 2014 18:43:17 GMT .Server: Apache/2.2.15 (Red Hat) .Content-Length: 2 .Content-Type: application/json .Vary: Accept-Encoding .Accept-Ranges: none . .ok */ while((c=modem_receive()) != (CHAR8)-1) { putchar_usb(c); } cnt++; /* TODO: timeout */ #if 0 while(1){ c=modem_receive(); if ((c != '\r') && (c != '\n') && ((resp_cnt < sizeof(resp_serv)-2))){ resp_serv[resp_cnt++]=c; }else{ resp_serv[resp_cnt++]='\0'; if(strcmp (resp_serv,resp_200_OK) == 0){ cnt = (++cnt)%100; } resp_cnt = 0; break; } } #endif } }
/********************************************************************* * * Function : edit_read_line * * Description : Read a single non-empty line from a file and return * it. Trims comments, leading and trailing whitespace * and respects escaping of newline and comment char. * Provides the line in 2 alternative forms: raw and * preprocessed. * - raw is the raw data read from the file. If the * line is not modified, then this should be written * to the new file. * - prefix is any comments and blank lines that were * read from the file. If the line is modified, then * this should be written out to the file followed * by the modified data. (If this string is non-empty * then it will have a newline at the end). * - data is the actual data that will be parsed * further by appropriate routines. * On EOF, the 3 strings will all be set to NULL and * 0 will be returned. * * Parameters : * 1 : fp = File to read from * 2 : raw_out = destination for newly malloc'd pointer to * raw line data. May be NULL if you don't want it. * 3 : prefix_out = destination for newly malloc'd pointer to * comments. May be NULL if you don't want it. * 4 : data_out = destination for newly malloc'd pointer to * line data with comments and leading/trailing spaces * removed, and line continuation performed. May be * NULL if you don't want it. * 5 : newline = Standard for newlines in the file. * On input, set to value to use or NEWLINE_UNKNOWN. * On output, may be changed from NEWLINE_UNKNOWN to * actual convention in file. May be NULL if you * don't want it. * 6 : line_number = Line number in file. In "lines" as * reported by a text editor, not lines containing data. * * Returns : JB_ERR_OK on success * JB_ERR_MEMORY on out-of-memory * JB_ERR_FILE on EOF. * *********************************************************************/ jb_err edit_read_line(FILE *fp, char **raw_out, char **prefix_out, char **data_out, int *newline, unsigned long *line_number) { char *p; /* Temporary pointer */ char *linebuf; /* Line read from file */ char *linestart; /* Start of linebuf, usually first non-whitespace char */ int contflag = 0; /* Nonzero for line continuation - i.e. line ends '\' */ int is_empty = 1; /* Flag if not got any data yet */ char *raw = NULL; /* String to be stored in raw_out */ char *prefix = NULL; /* String to be stored in prefix_out */ char *data = NULL; /* String to be stored in data_out */ int scrapnewline; /* Used for (*newline) if newline==NULL */ jb_err rval = JB_ERR_OK; assert(fp); assert(raw_out || data_out); assert(newline == NULL || *newline == NEWLINE_UNKNOWN || *newline == NEWLINE_UNIX || *newline == NEWLINE_DOS || *newline == NEWLINE_MAC); if (newline == NULL) { scrapnewline = NEWLINE_UNKNOWN; newline = &scrapnewline; } /* Set output parameters to NULL */ if (raw_out) { *raw_out = NULL; } if (prefix_out) { *prefix_out = NULL; } if (data_out) { *data_out = NULL; } /* Set string variables to new, empty strings. */ if (raw_out) { raw = strdup(""); if (NULL == raw) { return JB_ERR_MEMORY; } } if (prefix_out) { prefix = strdup(""); if (NULL == prefix) { freez(raw); return JB_ERR_MEMORY; } } if (data_out) { data = strdup(""); if (NULL == data) { freez(raw); freez(prefix); return JB_ERR_MEMORY; } } /* Main loop. Loop while we need more data & it's not EOF. */ while ( (contflag || is_empty) && (JB_ERR_OK == (rval = simple_read_line(fp, &linebuf, newline)))) { if (line_number) { (*line_number)++; } if (raw) { string_append(&raw,linebuf); if (string_append(&raw,NEWLINE(*newline))) { freez(prefix); freez(data); free(linebuf); return JB_ERR_MEMORY; } } /* Line continuation? Trim escape and set flag. */ p = linebuf + strlen(linebuf) - 1; contflag = ((*linebuf != '\0') && (*p == '\\')); if (contflag) { *p = '\0'; } /* Trim leading spaces if we're at the start of the line */ linestart = linebuf; assert(NULL != data); if (*data == '\0') { /* Trim leading spaces */ while (*linestart && isspace((int)(unsigned char)*linestart)) { linestart++; } } /* Handle comment characters. */ p = linestart; while ((p = strchr(p, '#')) != NULL) { /* Found a comment char.. */ if ((p != linebuf) && (*(p-1) == '\\')) { /* ..and it's escaped, left-shift the line over the escape. */ char *q = p - 1; while ((*q = *(q + 1)) != '\0') { q++; } /* Now scan from just after the "#". */ } else { /* Real comment. Save it... */ if (p == linestart) { /* Special case: Line only contains a comment, so all the * previous whitespace is considered part of the comment. * Undo the whitespace skipping, if any. */ linestart = linebuf; p = linestart; } if (prefix) { string_append(&prefix,p); if (string_append(&prefix, NEWLINE(*newline))) { freez(raw); freez(data); free(linebuf); return JB_ERR_MEMORY; } } /* ... and chop off the rest of the line */ *p = '\0'; } } /* END while (there's a # character) */ /* Write to the buffer */ if (*linestart) { is_empty = 0; if (data) { if (string_append(&data, linestart)) { freez(raw); freez(prefix); free(linebuf); return JB_ERR_MEMORY; } } } free(linebuf); } /* END while(we need more data) */ /* Handle simple_read_line() errors - ignore EOF */ if ((rval != JB_ERR_OK) && (rval != JB_ERR_FILE)) { freez(raw); freez(prefix); freez(data); return rval; } if (raw ? (*raw == '\0') : is_empty) { /* EOF and no data there. (Definition of "data" depends on whether * the caller cares about "raw" or just "data"). */ freez(raw); freez(prefix); freez(data); return JB_ERR_FILE; } else { /* Got at least some data */ /* Remove trailing whitespace */ chomp(data); if (raw_out) { *raw_out = raw; } else { freez(raw); } if (prefix_out) { *prefix_out = prefix; } else { freez(prefix); } if (data_out) { *data_out = data; } else { freez(data); } return JB_ERR_OK; } }
/*----------------------------------------------------------------------------- FUNCTION: OutputABufferToWindow(HWND, char *, DWORD) PURPOSE: Updates TTY Buffer with characters just received. PARAMETERS: hTTY - handle to the TTY child window lpBuf - address of data buffer dwBufLen - size of data buffer HISTORY: Date Author Comment 5/ 8/91 BryanW Wrote it 10/27/95 AllenD Modified for MTTTY Sample -----------------------------------------------------------------------------*/ void OutputABufferToWindow(HWND hTTY, char * lpBuf, DWORD dwBufLen) { RECT rect; /* update screen buffer with new buffer need to do a character by character check for special characters */ int i; for ( i = 0 ; i < (int) dwBufLen; i++) { switch (lpBuf[ i ]) { case ASCII_BEL: // BELL CHAR MessageBeep( 0 ) ; break ; case ASCII_BS: // Backspace CHAR if (COLUMN( TTYInfo ) > 0) COLUMN( TTYInfo ) -- ; break ; case ASCII_CR: // Carriage Return COLUMN( TTYInfo ) = 0 ; if (!NEWLINE( TTYInfo )) break; // // FALL THROUGH // case ASCII_LF: // Line Feed if (ROW( TTYInfo )++ == MAXROWS - 1) { MoveMemory( (LPSTR) (SCREEN( TTYInfo )), (LPSTR) (SCREEN( TTYInfo ) + MAXCOLS), (MAXROWS - 1) * MAXCOLS ) ; FillMemory((LPSTR) (SCREEN( TTYInfo ) + (MAXROWS - 1) * MAXCOLS), MAXCOLS, ' ' ) ; InvalidateRect( hTTY, NULL, FALSE ) ; ROW( TTYInfo )-- ; } break ; default: // standard character SCREENCHAR(TTYInfo, COLUMN(TTYInfo), ROW(TTYInfo)) = lpBuf[ i ]; rect.left = (COLUMN( TTYInfo ) * XCHAR( TTYInfo )) - XOFFSET( TTYInfo ) ; rect.right = rect.left + XCHAR( TTYInfo ) ; rect.top = (ROW( TTYInfo ) * YCHAR( TTYInfo )) - YOFFSET( TTYInfo ) ; rect.bottom = rect.top + YCHAR( TTYInfo ) ; InvalidateRect( hTTY, &rect, FALSE ) ; // // Line wrap // if (COLUMN( TTYInfo ) < MAXCOLS-1 ) COLUMN( TTYInfo )++ ; else if (AUTOWRAP( TTYInfo )) OutputABufferToWindow(hTTY, "\r\n", 2 ) ; break; } } MoveTTYCursor(hTTY); return; }
int main(void) { char c; // bufor na znak char s[UART_MAX_GETSTR+1]; // bufor na ³añcuch znaków s16 liczba=0x5555; // liczba do testowania UART_init(); // inicjalizacja portu szeregowego PRINT("Test biblioteki UART .....\n\r"); while(1) { CLEAR(); PRINT("Testowanie funkcji UART_putstr_P() i UART_putstr_E()"); NEWLINE(); UART_putstr_P(text_P); NEWLINE(); UART_putstr_E(text_E); NEWLINE(); NEWLINE(); PRINT("Testowanie funkcji UART_putint()"); NEWLINE(); PRINT("Dwójkowo: "); UART_putint(liczba,2); NEWLINE(); PRINT("Ósemkowo: "); UART_putint(liczba,8); NEWLINE(); PRINT("Dziesiêtnie: "); UART_putint(liczba,10); NEWLINE(); PRINT("Szesnaskowo: "); UART_putint(liczba,16); NEWLINE(); /* NEWLINE(); PRINT("Testowanie funkcji UART_getchar() i UART_putchar()"); NEWLINE(); PRINT("Wyœlij cokolwiek z terminala, znak \"t\" koñczy..."); NEWLINE(); do { c=UART_getchar(); // pobierz znak z wejscia UART_putchar(c); // zrób echo } while (c != 't'); // a¿ nie napotkasz znaku "t" NEWLINE(); */ PRINT("Testowanie funkcji UART_getstr() i UART_putstr()"); NEWLINE(); PRINT("Wyœlij cokolwiek z terminala i naciœnij ENTER"); NEWLINE(); PRINT("...napis \"koniec\" koñczy..."); NEWLINE(); do { UART_getstr(s); // pobierz tekst z wejscia UART_putstr(s); // zrób echo NEWLINE(); } while (strncmp_P(s,PSTR("koniec"),6)!=0); // a¿ nie napotkasz "koniec" } }