int main( int argc, char *argv[] ) { int numbers; numbers = 0; char buffer[25]; if(argc == 1) { printlines(0); //For the record: This doesn't work with my #defined NONUMB... qq } if(argc == 2 && strncmp("-n", argv[1], 2) == 0) { printlines(1); } else { if( argc > 1 ) { int argctr; argctr = 1; if( strncmp(argv[1], "-n", 2) == 0 ) { numbers = 1; argctr++; } while (argctr < argc) { printfiles(numbers, argv[argctr]); argctr++; } } } return 0; }
void printrule(struct onode *o, FILE *out) { struct lnode *p = o->o_old; while (p->l_prev) p = p->l_prev; printlines(p, 0, out); fputs("=\n", out); printlines(o->o_new, 0, out); }
void printlines(struct tlist *node) { /* Print matching lines for a word via inorder traversal */ if(node) { printlines(node->left); printf("%d ", node->key); printlines(node->right); } }
printerror() { register PROCESS *p; char *filename; int c; p = process; if (p->signo != ESIGNAL && p->signo != SIGINT) { error("signal %d at px pc %d, lc %d", p->signo, p->pc, pc); } curline = srcline(pc); curfunc = whatblock(pc); skimsource(srcfilename(pc)); if (p->signo == ESIGNAL) { printf("\nerror at "); printwhere(curline, cursource); if (errnum != 0) { printf(": %s", pxerrmsg[errnum]); } } else { printf("\n\ninterrupt at "); printwhere(curline, cursource); } putchar('\n'); printlines(curline, curline); erecover(); }
int main(int argc, char* argv[]) { int i, fd; for(i = 1; i < argc; ++i) { fd = openfile(argv[i]); if(fd < 0) continue; printlines(fd, argv[i], argc); if(close(fd)) perror("Close"); } if(argc < 2) { fd = openfile("-"); printlines(fd, "-", argc); } return 0; }
void printtree(struct tref *node) { /* Print word tree via inorder traversal */ if(node) { printtree(node->left); printf("%s: ", node->key); printlines(node->lines); printf("\n"); printtree(node->right); } }
int main(int argc, char* argv[]){ FILE* input_file = NULL; //File pointer int lines = 0; // Initializes lines variable type int to 0 int numlines = atoi(argv[2]); //Converts command line arguement to type integer lines = get_number_of_lines (input_file, argv); //Calls the get_number_of_lines function to get the number of lines in a file printlines(input_file, argv, lines, numlines); // Calls the printlines function to print the N number of lines return 0; }
void doaddsub(char *n1, int l1, char *n2, int l2, char op) { int width = MAX(l1, l2) + 1; char **lines = alloclines(width, 4); int w1; int w2; memcpy(lines[0] + width - l1, n1, l1); memcpy(lines[1] + width - l2, n2, l2); lines[1][width - l2 - 1] = op; w1 = add(n1, l1, n2, l2, lines[3] + width, op); w2 = MAX(l1, l2 + 1); memset(lines[2] + width - MAX(l2 + 1, w1), '-', MAX(l2 + 1, w1)); printlines(lines, 4, width - MAX(w1, w2)); }
void domul(char *n1, int l1, char *n2, int l2) { int width = l1 + l2; char **lines = alloclines(width, 3 + l2 + 3); int firstlength = 0; int maxlength = 0; int i; int lastlength = 1; int w1; int w2; memcpy(lines[0] + width - l1, n1, l1); memcpy(lines[1] + width - l2, n2, l2); lines[1][width - l2 - 1] = '*'; for (i = 0; i < l2; i++) { int length; length = add(n1, l1, 0, 0, lines[3 + i] + width - i, n2[l2 - i - 1]); length += i; if (firstlength == 0) firstlength = length; if (maxlength < length) maxlength = length; } w1 = MAX(l2 + 1, firstlength); memset(lines[2] + width - w1, '-', w1); lines[3 + l2 + 1][width - 1] = '0'; for (i = 0; i < l2; i++) { lastlength = add(lines[3 + l2 + 1] + width - lastlength, lastlength, lines[3 + i] + width - maxlength, maxlength, lines[3 + l2 + 2] + width, '+'); memcpy(lines[3 + l2 + 1], lines[3 + l2 + 2], width); } w2 = MAX(maxlength, lastlength); memset(lines[3 + l2] + width - w2, '-', w2); printlines(lines, 3 + l2 + (l2 > 1) * 2, width - MAX(l1, MAX(w1, w2))); }
int main(int argc, char *argv[]) { int nlines = 0; int numeric = 0; if (argc > 1 && strcmp(argv[1], "-n") == 0) { numeric = 1; } if ((nlines = getlines(lineptr, MAXLINES)) >= 0) { qsort1((void **) lineptr, 0, nlines-1, (int (*)(void *, void *)) (numeric ? numcmp : strcmp) ); printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); printlines(lineptr, nlines); printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); } else { printf("error in reading lines \n"); } return 0; }
printnews() { if (ss_variables) { prvarnews(); } if (trcond()) { if (ss_lines && curline > 0) { skimsource(srcfilename(pc)); printf("trace: "); printlines(curline, curline); } if (ss_instructions) { printf("inst trace: "); printinst(pc, pc); } } bpact(); if (stopcond()) { isstopped = TRUE; curline = srcline(pc); printstatus(); } }
int main(int argc, char* argv[]) { // printf("%s %s\n", argv[1], argv[2]); int n; char *flagidentifier = "-"; int argnum = 1; if(argv[1]==NULL) return 1; char nline[20]; if(strncmp(argv[1], flagidentifier, 1)==0){ strcpy(nline, argv[1]+1); n = atoi(nline); argnum = 2; } else { n = 10; } FILE *fp; if((fp = fopen(argv[argnum], "r"))==NULL) { perror("mytail"); return 1; } cbuffer *a, *b; printlines(fp, n); }
int main(int argc, char *argv[]) { char *linesarray[MAXLINES]; int nlines; int n; if (argc == 1) n=4; else if (argc == 2) if (*argv[1]=='-') n=atoi((argv[1]+1)); else { printf("Not a valid argument. Argument is of type int positive and starts with '-'\n"); return 0; } if ( (nlines=readlines(linesarray)) > 0) printlines(linesarray, n, nlines); else printf("YOU MADE A SERIOUS MISTAKE\n"); return 0; }
// Convert to Printlines void Layer::MakePrintlines(Vector3d &lastPos, //GCodeState &state, vector<PLine3> &lines3, double offsetZ, Settings &settings) const { const double linewidth = settings.GetExtrudedMaterialWidth(thickness); const double cornerradius = linewidth*settings.get_double("Slicing","CornerRadius"); const bool clipnearest = settings.get_boolean("Slicing","MoveNearest"); const uint supportExtruder = settings.GetSupportExtruder(); const double minshelltime = settings.get_double("Slicing","MinShelltime"); const double maxshellspeed = settings.get_double("Extruder","MaxShellSpeed"); const bool ZliftAlways = settings.get_boolean("Extruder","ZliftAlways"); Vector2d startPoint(lastPos.x(),lastPos.y()); const double extr_per_mm = settings.GetExtrusionPerMM(thickness); //vector<PLine3> lines3; Printlines printlines(this, &settings, offsetZ); vector<PLine2> lines; vector<Poly> polys; // intermediate collection // polys to keep line movements inside //const vector<Poly> * clippolys = &polygons; const vector<Poly> * clippolys = GetOuterShell(); // 1. Skins, all but last, because they are the lowest lines, below layer Z if (skins > 1) { for(uint s = 0; s < skins; s++) { // z offset from bottom to top: double skin_z = Z - thickness + (s+1)*thickness/skins; if ( skin_z < 0 ){ cerr << "Skin Z<0! " << s << " -- " << Z << " -- "<<skin_z <<" -- " << thickness << endl; continue; } // skin infill polys: if (skinFullInfills[s]) polys.insert(polys.end(), skinFullInfills[s]->infillpolys.begin(), skinFullInfills[s]->infillpolys.end()); // add skin infill to lines printlines.addPolys(INFILL, polys, false); polys.clear(); // make polygons at skin_z: for(size_t p = 0; p < skinPolygons.size(); p++) { polys.push_back(Poly(skinPolygons[p], skin_z)); } // add skin to lines printlines.addPolys(SKIN, polys, (s==0), // displace at first skin maxshellspeed * 60, minshelltime); if (s < skins-1) { // not on the last layer, this handle with all other lines // have to get all these separately because z changes printlines.makeLines(startPoint, lines); if (!ZliftAlways) printlines.clipMovements(*clippolys, lines, clipnearest, linewidth); printlines.optimize(linewidth, minshelltime, cornerradius, lines); printlines.getLines(lines, lines3, extr_per_mm); printlines.clear(); lines.clear(); } polys.clear(); } } // last skin layer now still in lines lines.clear(); // 2. Skirt printlines.addPolys(SKIRT, skirtPolygons, false, maxshellspeed * 60, minshelltime); // 3. Support if (supportInfill) { uint extruderbefore = settings.selectedExtruder; settings.SelectExtruder(supportExtruder); printlines.addPolys(SUPPORT, supportInfill->infillpolys, false); settings.SelectExtruder(extruderbefore); } // 4. all other polygons: // Shells for(int p=shellPolygons.size()-1; p>=0; p--) { // inner to outer printlines.addPolys(SHELL, shellPolygons[p], (p==(int)(shellPolygons.size())-1), maxshellspeed * 60, minshelltime); } // Infill if (normalInfill) printlines.addPolys(INFILL, normalInfill->infillpolys, false); if (thinInfill) printlines.addPolys(INFILL, thinInfill->infillpolys, false); if (fullInfill) printlines.addPolys(INFILL, fullInfill->infillpolys, false); if (skirtInfill) printlines.addPolys(INFILL, skirtInfill->infillpolys, false); if (decorInfill) printlines.addPolys(INFILL, decorInfill->infillpolys, false); for (uint b=0; b < bridgeInfills.size(); b++) if (bridgeInfills[b]) printlines.addPolys(INFILL, bridgeInfills[b]->infillpolys, false); double polyspeedfactor = printlines.makeLines(startPoint, lines); // FINISH Command lchange(LAYERCHANGE, LayerNo); lchange.where = Vector3d(0.,0.,Z); lchange.comment += info(); lines3.push_back(PLine3(lchange)); if (!ZliftAlways) printlines.clipMovements(*clippolys, lines, clipnearest, linewidth); printlines.optimize(linewidth, settings.get_double("Slicing","MinLayertime"), cornerradius, lines); if ((guint)LayerNo < (guint)settings.get_integer("Slicing","FirstLayersNum")) printlines.setSpeedFactor(settings.get_double("Slicing","FirstLayersSpeed"), lines); double slowdownfactor = printlines.getSlowdownFactor() * polyspeedfactor; if (settings.get_boolean("Slicing","FanControl")) { int fanspeed = settings.get_integer("Slicing","MinFanSpeed"); if (slowdownfactor < 1 && slowdownfactor > 0) { double fanfactor = 1-slowdownfactor; fanspeed += int(fanfactor * (settings.get_integer("Slicing","MaxFanSpeed")-settings.get_integer("Slicing","MinFanSpeed"))); fanspeed = CLAMP(fanspeed, settings.get_integer("Slicing","MinFanSpeed"), settings.get_integer("Slicing","MaxFanSpeed")); //cerr << slowdownfactor << " - " << fanfactor << " - " << fanspeed << " - " << endl; } Command fancommand(FANON, fanspeed); lines3.push_back(PLine3(fancommand)); } printlines.getLines(lines, lines3, extr_per_mm); if (lines3.size()>0) lastPos = lines3.back().to; }
/* * Do the substitute command. * The current line is set to the last substitution done. */ static void subcommand(char *cp, NUM num1, NUM num2) { int delim; char *oldstr; char *newstr; LEN oldlen; LEN newlen; LEN deltalen; LEN offset; LINE *lp; LINE *nlp; BOOL globalflag; BOOL printflag; BOOL didsub; BOOL needprint; if ((num1 < 1) || (num2 > lastnum) || (num1 > num2)) { fprintf(stderr, "Bad line range for substitute\n"); return; } globalflag = FALSE; printflag = FALSE; didsub = FALSE; needprint = FALSE; if (isblank(*cp) || (*cp == '\0')) { fprintf(stderr, "Bad delimiter for substitute\n"); return; } delim = *cp++; oldstr = cp; cp = strchr(cp, delim); if (cp == NULL) { fprintf(stderr, "Missing 2nd delimiter for substitute\n"); return; } *cp++ = '\0'; newstr = cp; cp = strchr(cp, delim); if (cp) *cp++ = '\0'; else cp = ""; while (*cp) switch (*cp++) { case 'g': globalflag = TRUE; break; case 'p': printflag = TRUE; break; default: fprintf(stderr, "Unknown option for substitute\n"); return; } if (*oldstr == '\0') { if (searchstring[0] == '\0') { fprintf(stderr, "No previous search string\n"); return; } oldstr = searchstring; } if (oldstr != searchstring) strcpy(searchstring, oldstr); lp = findline(num1); if (lp == NULL) return; oldlen = strlen(oldstr); newlen = strlen(newstr); deltalen = newlen - oldlen; offset = 0; while (num1 <= num2) { offset = findstring(lp, oldstr, oldlen, offset); if (offset < 0) { if (needprint) { printlines(num1, num1, FALSE); needprint = FALSE; } offset = 0; lp = lp->next; num1++; continue; } needprint = printflag; didsub = TRUE; dirty = TRUE; /* * If the replacement string is the same size or shorter * than the old string, then the substitution is easy. */ if (deltalen <= 0) { memcpy(&lp->data[offset], newstr, newlen); if (deltalen) { memcpy(&lp->data[offset + newlen], &lp->data[offset + oldlen], lp->len - offset - oldlen); lp->len += deltalen; } offset += newlen; if (globalflag) continue; if (needprint) { printlines(num1, num1, FALSE); needprint = FALSE; } lp = nlp->next; num1++; continue; } /* * The new string is larger, so allocate a new line * structure and use that. Link it in in place of * the old line structure. */ nlp = (LINE *) malloc(sizeof(LINE) + lp->len + deltalen); if (nlp == NULL) { fprintf(stderr, "Cannot get memory for line\n"); return; } nlp->len = lp->len + deltalen; memcpy(nlp->data, lp->data, offset); memcpy(&nlp->data[offset], newstr, newlen); memcpy(&nlp->data[offset + newlen], &lp->data[offset + oldlen], lp->len - offset - oldlen); nlp->next = lp->next; nlp->prev = lp->prev; nlp->prev->next = nlp; nlp->next->prev = nlp; if (curline == lp) curline = nlp; free(lp); lp = nlp; offset += newlen; if (globalflag) continue; if (needprint) { printlines(num1, num1, FALSE); needprint = FALSE; } lp = lp->next; num1++; } if (!didsub) fprintf(stderr, "No substitutions found for \"%s\"\n", oldstr); }
/* * Read commands until we are told to stop. */ static void docommands(void) { char *cp; int len; NUM num1; NUM num2; BOOL have1; BOOL have2; while (TRUE) { intflag = FALSE; printf(": "); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) return; len = strlen(buf); if (len == 0) return; cp = &buf[len - 1]; if (*cp != '\n') { fprintf(stderr, "Command line too long\n"); do { len = fgetc(stdin); } while ((len != EOF) && (len != '\n')); continue; } while ((cp > buf) && isblank(cp[-1])) cp--; *cp = '\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)) { fprintf(stderr, "Bad file command\n"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { if (filename) printf("\"%s\"\n", filename); else printf("No filename\n"); break; } cp = strdup(cp); if (cp == NULL) { fprintf(stderr, "No memory for filename\n"); break; } if (filename) free(filename); filename = cp; break; case 'i': addlines(num1); break; case 'k': while (isblank(*cp)) cp++; if ((*cp < 'a') || (*cp > 'a') || cp[1]) { fprintf(stderr, "Bad mark name\n"); 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) { fprintf(stderr, "Bad quit command\n"); 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)) { fprintf(stderr, "Bad read command\n"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { fprintf(stderr, "No filename\n"); 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)) { fprintf(stderr, "Bad write command\n"); break; } while (isblank(*cp)) cp++; if (!have1) { num1 = 1; num2 = lastnum; } if (*cp == '\0') cp = filename; if (cp == NULL) { fprintf(stderr, "No file name specified\n"); 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) { fprintf(stderr, "No arguments allowed\n"); 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: fprintf(stderr, "Unimplemented command\n"); break; } } }