int main() { char line[MAXLINE]; getln(line, MAXLINE); decomment(line); printf("%s", line); return 0; }
void Skeleton::readHierarchy(char* buff, FILE* file) { char *p; char t1[200]; while ((p = fgets(buff, buffSize, file)) != NULL) { trim(&p); decomment(p); if (strlen(p) > 0) { if (strcmp(p, "end") == 0) { //end of hierarchy return; } else { //Read the root node sscanf(p, "%s ", t1); bone* rootBone = NULL; for (int i = 0; i < numBones; i++) { if (strcmp(root[i].name, t1) == 0) { rootBone = root + i; break; } } //Read the connections p += strlen(t1); bone* other = NULL; while (*p != '\0') { sscanf(p, "%s ", t1); for (int i = 0; i < numBones; i++) { if (strcmp(root[i].name, t1) == 0) { other = root + i; break; } } if (other == NULL) { printf("Unknown bone %s found in hierarchy. Failure", t1); exit(EXIT_FAILURE); } rootBone->children[rootBone->numChildren] = other; rootBone->numChildren++; p += strlen(t1) + 1; } } } } }
void main () { int i,c,l; char text[10000]; printf("Enter text, what has to be formatted.\n"); while( (l=gett(text) )>0 ){ printf("---------------Non formatted text seems so:--------------------|\n%s\n---------------------------------------------------------------|\n",text); // form(l,text); decomment(l,text); printf("---------------Same text after formatting seems so:------------|\n%s\n---------------------------------------------------------------|\n",text); } printf("normal end of program\n"); }
int Getchar(void) { int c; if (Unptr == Unbuf) { if (Piperead >= Pipewrite) decomment(); c = *Piperead++; } else { c = *--Unptr; } if (c == '\n') Line++; return c; }
void assemble(char *outname) { char *aline; int dataoffset, stringsoffset, linkisoffset; int datalen, stringslen, linkislen, oldlineno; struct export *e, *eo; numfuncs = 0; numlinkis = 0; temptype = -2; if(src == NULL) return; if(verbose) fprintf(stderr, "\n%s: Assembling file `%s'\n", progname, src->filename); errors = 0; makearea(&oheaders); makearea(&ostrings); makearea(&odata); makearea(&olinkis); PARENTO = addonestrtoarea(outname); /* build header */ addinttoarea(&oheaders, 0x6a624f51); /* "QObj" */ addinttoarea(&oheaders, -1); /* creator string */ addinttoarea(&oheaders, -1); /* num funcs */ addinttoarea(&oheaders, 60); /* address func headers */ addinttoarea(&oheaders, -1); /* procos */ addinttoarea(&oheaders, 0); /* reserved */ addinttoarea(&oheaders, 2); /* obj format version */ addinttoarea(&oheaders, 0); /* address code/data */ addinttoarea(&oheaders, 0); /* length code/data */ addinttoarea(&oheaders, 0); /* address strings */ addinttoarea(&oheaders, 0); /* length strings */ addinttoarea(&oheaders, 0); /* address linkis */ addinttoarea(&oheaders, 0); /* length linkis */ addinttoarea(&oheaders, 0); /* address debug info */ addinttoarea(&oheaders, 0); /* length debug info */ strcpy(creator, "qas RISC OS ARM Assembler vsn "VERS" © Stu Smith ["__DATE__"]"); strcpy(procos, "ARM/RISCOS"); funcheadsoff = oheaders.used; /* assemble line-by-line */ parseinit(); clearvalues(&llabels); clearvalues(&rns); clearvalues(&fns); clearvalues(&cns); clearvalues(&sets); while(src) { aline = getline(); decomment(aline); stripw(aline); if(*aline) { assmline(aline); } } endprevfunc(); placeint(&oheaders, addonestrtoarea(creator), 4); placeint(&oheaders, addonestrtoarea(procos), 16); placeint(&oheaders, numfuncs, 8); /* concat headers-data-strings */ alignarea(&oheaders); alignarea(&odata); alignarea(&ostrings); dataoffset = addtoarea(&oheaders, odata.mem, odata.used); datalen = odata.used; droparea(&odata); alignarea(&oheaders); linkisoffset = addtoarea(&oheaders, olinkis.mem, olinkis.used); linkislen = olinkis.used; droparea(&olinkis); alignarea(&oheaders); stringsoffset = addtoarea(&oheaders, ostrings.mem, ostrings.used); stringslen = ostrings.used; droparea(&ostrings); alignarea(&oheaders); if(numfuncs == 0) error("No symbols defined"); placeint(&oheaders, dataoffset, 28); placeint(&oheaders, datalen, 32); placeint(&oheaders, stringsoffset, 36); placeint(&oheaders, stringslen, 40); placeint(&oheaders, linkisoffset, 44); placeint(&oheaders, linkislen, 48); placeint(&oheaders, 0, 52); placeint(&oheaders, 0, 56); e = exportlist; while(e) { oldlineno = lineno; lineno = e->line; error("Can't export symbol `%s': not defined", e->symname); lineno = oldlineno; freemem(e->symname); eo = e->next; freemem(e); e = eo; } exportlist = NULL; /* save object file */ #ifndef DEBUG if(errors == 0) #endif saveblock(outname, oheaders.mem, oheaders.used); droparea(&oheaders); }
void Skeleton::readBone(char* buff, FILE* file) { char *p; char t1[50]; while ((p = fgets(buff, buffSize, file)) != NULL) { trim(&p); decomment(p); if (strlen(p) > 0) { if (strcmp(p, "end") == 0) { //end of this bone return; } else { sscanf(p, "%s ", t1); if (strcmp(t1, "name") == 0) { //Read the name and actually remember it char* name = (char*) malloc(sizeof(char) * 10); sscanf(p, "name %s", name); root[numBones].name = name; } else if (strcmp(t1, "direction") == 0) { //Also actually important float x, y, z; sscanf(p, "direction %f %f %f", &x, &y, &z); root[numBones].dirx = x; root[numBones].diry = y; root[numBones].dirz = z; } else if (strcmp(t1, "length") == 0) { //Also actually important float len; sscanf(p, "length %f", &len); root[numBones].length = len; } else if (strcmp(t1, "dof") == 0) { //Read the degrees of freedom! char d1[5]; char d2[5]; char d3[5]; int num = sscanf(p, "dof %s %s %s", d1, d2, d3); switch (num) { DOF dof; case 3: dof = dofFromString(d3); root[numBones].dof = root[numBones].dof | dof; //fallthrough!! /* no break */ case 2: dof = dofFromString(d2); root[numBones].dof = root[numBones].dof | dof; //fallthrough!! /* no break */ case 1: dof = dofFromString(d1); root[numBones].dof = root[numBones].dof | dof; break; } } else if (strcmp(t1, "axis") == 0) { //Read the rotation axis float x, y, z; int num = sscanf(p, "axis %f %f %f XYZ", &x, &y, &z); if (num != 3) { printf("axis format doesn't match expected\n"); printf("Expected: axis %%f %%f %%f XYZ\n"); printf("Got: %s", p); exit(EXIT_FAILURE); } root[numBones].rotx = x; root[numBones].roty = y; root[numBones].rotz = z; } //There are more things but they are not needed for the core } } } }
void Skeleton::readHeading(char* buff, FILE* file) { char* temp = buff; decomment(buff); trim(&temp); char head[50]; char rest[200]; int num = sscanf(temp, ":%s %s", head, rest); if (num == 0) { printf("Could not get heading name from %s, all is lost\n", temp); exit(EXIT_FAILURE); } if (strcmp(head, "version") == 0) { //version string - must be 1.10 char* version = rest; if (num != 2) { char *p = { '\0' }; while (strlen(p) == 0) { char* p = fgets(buff, buffSize, file); decomment(p); trim(&p); version = p; } } if (strcmp(version, "1.10") != 0) { printf("Invalid version: %s, must be 1.10\n", version); exit(EXIT_FAILURE); } //Finished reading version so read the next thing? } else if (strcmp(head, "name") == 0) { //This allows the skeleton to be called something //other than the file name //We don't actually care what the name is, so can //ignore this whole section } else if (strcmp(head, "documentation") == 0) { //Documentation section has no meaningful information //only of use if you want to copy the file. So we skip it } else if (strcmp(head, "units") == 0) { //Has factors for the units //To be able to model the real person, //these must be parsed correctly //Only really need to check if deg or rad, but even //that is probably not needed for the core or extension } else if (strcmp(head, "root") == 0) { //Read in information about root //Or be lazy and just assume it is going to be the normal CMU thing! } else if (strcmp(head, "bonedata") == 0) { //Description of each bone //This does need to actually be read :( char *p; while ((p = fgets(buff, buffSize, file)) != NULL) { decomment(p); trim(&p); if (strlen(p) > 0) { if (p[0] == ':') { return readHeading(buff, file); } else if (strcmp(p, "begin") != 0) { printf("Expected begin for bone data %d, found \"%s\"", numBones, p); exit(EXIT_FAILURE); } else { readBone(buff, file); numBones++; } } } } else if (strcmp(head, "hierarchy") == 0) { //Description of how the bones fit together char *p; while ((p = fgets(buff, buffSize, file)) != NULL) { trim(&p); decomment(p); if (strlen(p) > 0) { if (p[0] == ':') { return readHeading(buff, file); } else if (strcmp(p, "begin") != 0) { printf("Expected begin in hierarchy, found %s", p); exit(EXIT_FAILURE); } else { readHierarchy(buff, file); } } } } else { printf("Unknown heading %s\n", head); } }
/** * @brief Read and parse a skin. * * @param sname name of the skin * * @return 0 (ok), -1 (skin file not found or not readable) or -2 (parsing error) */ int skinRead(char *sname) { char *skinfname; FILE *skinfile; unsigned char line[256]; unsigned char item[32]; unsigned char param[256]; unsigned int i; skinfname = setname(skinDirInHome, sname); if ((skinfile = fopen(skinfname, "rt")) == NULL) { skinfname = setname(skinMPlayerDir, sname); if ((skinfile = fopen(skinfname, "rt")) == NULL) { mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotFound, skinfname); return -1; } } mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", skinfname); appFreeStruct(); skin = NULL; currWinName[0] = 0; linenumber = 0; while (fgetstr(line, sizeof(line), skinfile)) { linenumber++; strswap(line, '\t', ' '); trim(line); decomment(line); if (!*line) continue; cutItem(line, item, '=', 0); cutItem(line, param, '=', 1); strlower(item); for (i = 0; i < FF_ARRAY_ELEMS(skinItem); i++) { if (!strcmp(item, skinItem[i].name)) { if (skinItem[i].func(param) != 0) return -2; else break; } } if (i == FF_ARRAY_ELEMS(skinItem)) { skin_error(MSGTR_SKIN_UNKNOWN_ITEM, item); return -2; } } if (linenumber == 0) { mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotReadable, skinfname); return -1; } return 0; }