/* * Clear up the lists of groups. * * IN : * @group_lists: The lists of groups. */ void clear_group(cg_group_lists* group_lists) { cg_group* group = NULL; if (!group_lists || TAILQ_EMPTY(group_lists)) return; for (group = TAILQ_FIRST(group_lists); group; group = TAILQ_FIRST(group_lists)) remove_group(group_lists, group); group_lists->count = 0; group = NULL; }
void remove_from_group(group_list_t *group, thread_list_t *thread){ if (thread->next == thread) { remove_group(group); } else { thread->next->previos = thread->previos; thread->previos->next = thread->next; if (group->thread_list == thread) { group->thread_list = thread->next; } } memarea_free(thread); }
int mbserver::del_group(void* req, char** out, size_t* outlen, MB_PLACEHOLDER placeholder, std::string body, size_t bodylen){ auto gid = placeholder.getN("#gid"); auto app = ref_context(req); crow::json::wvalue jsn; int lastid; auto db = mbdatabase::MbDatabaseInterface::getInstance(app); if (db == NULL){ return(500); } if (!db->remove_group(gid, &lastid)){ return(401); } jsn["stat"] = MBRESULT_OK; jsn["lastid"] = lastid; MB_MALLOC_RESULT(out, outlen, crow::json::dump(jsn).c_str()); UNUSED_PARAMETER(body); UNUSED_PARAMETER(bodylen); return(200); }
static int split_chain(t_atoms *atoms, rvec *x, int sel_nr, t_blocka *block, char ***gn) { char buf[STRLEN]; int j, nchain; atom_id i, a, natoms, *start = NULL, *end = NULL, ca_start, ca_end; rvec vec; natoms = atoms->nr; nchain = 0; ca_start = 0; while (ca_start < natoms) { while ((ca_start < natoms) && strcmp(*atoms->atomname[ca_start], "CA")) { ca_start++; } if (ca_start < natoms) { srenew(start, nchain+1); srenew(end, nchain+1); start[nchain] = ca_start; while ((start[nchain] > 0) && (atoms->atom[start[nchain]-1].resind == atoms->atom[ca_start].resind)) { start[nchain]--; } i = ca_start; do { ca_end = i; do { i++; } while ((i < natoms) && strcmp(*atoms->atomname[i], "CA")); if (i < natoms) { rvec_sub(x[ca_end], x[i], vec); } } while ((i < natoms) && (norm(vec) < 0.45)); end[nchain] = ca_end; while ((end[nchain]+1 < natoms) && (atoms->atom[end[nchain]+1].resind == atoms->atom[ca_end].resind)) { end[nchain]++; } ca_start = end[nchain]+1; nchain++; } } if (nchain == 1) { printf("Found 1 chain, will not split\n"); } else { printf("Found %d chains\n", nchain); } for (j = 0; j < nchain; j++) { printf("%d:%6d atoms (%d to %d)\n", j+1, end[j]-start[j]+1, start[j]+1, end[j]+1); } if (nchain > 1) { srenew(block->a, block->nra+block->index[sel_nr+1]-block->index[sel_nr]); for (j = 0; j < nchain; j++) { block->nr++; srenew(block->index, block->nr+1); srenew(*gn, block->nr); sprintf(buf, "%s_chain%d", (*gn)[sel_nr], j+1); (*gn)[block->nr-1] = strdup(buf); for (i = block->index[sel_nr]; i < block->index[sel_nr+1]; i++) { a = block->a[i]; if ((a >= start[j]) && (a <= end[j])) { block->a[block->nra] = a; block->nra++; } } block->index[block->nr] = block->nra; if (block->index[block->nr-1] == block->index[block->nr]) { remove_group(block->nr-1, NOTSET, block, gn); } } } sfree(start); sfree(end); return nchain; }
static void edit_index(int natoms, t_atoms *atoms, rvec *x, t_blocka *block, char ***gn, gmx_bool bVerbose) { static char **atnames, *ostring; static gmx_bool bFirst = TRUE; char inp_string[STRLEN], *string; char gname[STRLEN], gname1[STRLEN], gname2[STRLEN]; int i, i0, i1, sel_nr, sel_nr2, newgroup; atom_id nr, nr1, nr2, *index, *index1, *index2; gmx_bool bAnd, bOr, bPrintOnce; if (bFirst) { bFirst = FALSE; snew(atnames, MAXNAMES); for (i = 0; i < MAXNAMES; i++) { snew(atnames[i], NAME_LEN+1); } } string = NULL; snew(index, natoms); snew(index1, natoms); snew(index2, natoms); newgroup = NOTSET; bPrintOnce = TRUE; do { gname1[0] = '\0'; if (bVerbose || bPrintOnce || newgroup != NOTSET) { printf("\n"); if (bVerbose || bPrintOnce || newgroup == NOTSET) { i0 = 0; i1 = block->nr; } else { i0 = newgroup; i1 = newgroup+1; } for (i = i0; i < i1; i++) { printf("%3d %-20s: %5d atoms\n", i, (*gn)[i], block->index[i+1]-block->index[i]); } newgroup = NOTSET; } if (bVerbose || bPrintOnce) { printf("\n"); printf(" nr : group ! 'name' nr name 'splitch' nr Enter: list groups\n"); printf(" 'a': atom & 'del' nr 'splitres' nr 'l': list residues\n"); printf(" 't': atom type | 'keep' nr 'splitat' nr 'h': help\n"); printf(" 'r': residue 'res' nr 'chain' char\n"); printf(" \"name\": group 'case': case %s 'q': save and quit\n", bCase ? "insensitive" : "sensitive "); printf(" 'ri': residue index\n"); bPrintOnce = FALSE; } printf("\n"); printf("> "); if (NULL == fgets(inp_string, STRLEN, stdin)) { gmx_fatal(FARGS, "Error reading user input"); } inp_string[strlen(inp_string)-1] = 0; printf("\n"); string = inp_string; while (string[0] == ' ') { string++; } ostring = string; nr = 0; if (string[0] == 'h') { printf(" nr : selects an index group by number or quoted string.\n"); printf(" The string is first matched against the whole group name,\n"); printf(" then against the beginning and finally against an\n"); printf(" arbitrary substring. A multiple match is an error.\n"); printf(" 'a' nr1 [nr2 ...] : selects atoms, atom numbering starts at 1.\n"); printf(" 'a' nr1 - nr2 : selects atoms in the range from nr1 to nr2.\n"); printf(" 'a' name1[*] [name2[*] ...] : selects atoms by name(s), '?' matches any char,\n"); printf(" wildcard '*' allowed at the end of a name.\n"); printf(" 't' type1[*] [type2[*] ...] : as 'a', but for type, run input file required.\n"); printf(" 'r' nr1[ic1] [nr2[ic2] ...] : selects residues by number and insertion code.\n"); printf(" 'r' nr1 - nr2 : selects residues in the range from nr1 to nr2.\n"); printf(" 'r' name1[*] [name2[*] ...] : as 'a', but for residue names.\n"); printf(" 'ri' nr1 - nr2 : selects residue indices, 1-indexed, (as opposed to numbers) in the range from nr1 to nr2.\n"); printf(" 'chain' ch1 [ch2 ...] : selects atoms by chain identifier(s),\n"); printf(" not available with a .gro file as input.\n"); printf(" ! : takes the complement of a group with respect to all\n"); printf(" the atoms in the input file.\n"); printf(" & | : AND and OR, can be placed between any of the options\n"); printf(" above, the input is processed from left to right.\n"); printf(" 'name' nr name : rename group nr to name.\n"); printf(" 'del' nr1 [- nr2] : deletes one group or groups in the range from nr1 to nr2.\n"); printf(" 'keep' nr : deletes all groups except nr.\n"); printf(" 'case' : make all name compares case (in)sensitive.\n"); printf(" 'splitch' nr : split group into chains using CA distances.\n"); printf(" 'splitres' nr : split group into residues.\n"); printf(" 'splitat' nr : split group into atoms.\n"); printf(" 'res' nr : interpret numbers in group as residue numbers\n"); printf(" Enter : list the currently defined groups and commands\n"); printf(" 'l' : list the residues.\n"); printf(" 'h' : show this help.\n"); printf(" 'q' : save and quit.\n"); printf("\n"); printf(" Examples:\n"); printf(" > 2 | 4 & r 3-5\n"); printf(" selects all atoms from group 2 and 4 that have residue numbers 3, 4 or 5\n"); printf(" > a C* & !a C CA\n"); printf(" selects all atoms starting with 'C' but not the atoms 'C' and 'CA'\n"); printf(" > \"protein\" & ! \"backb\"\n"); printf(" selects all atoms that are in group 'protein' and not in group 'backbone'\n"); if (bVerbose) { printf("\npress Enter "); getchar(); } } else if (strncmp(string, "del", 3) == 0) { string += 3; if (parse_int(&string, &sel_nr)) { while (string[0] == ' ') { string++; } if (string[0] == '-') { string++; parse_int(&string, &sel_nr2); } else { sel_nr2 = NOTSET; } while (string[0] == ' ') { string++; } if (string[0] == '\0') { remove_group(sel_nr, sel_nr2, block, gn); } else { printf("\nSyntax error: \"%s\"\n", string); } } } else if (strncmp(string, "keep", 4) == 0) { string += 4; if (parse_int(&string, &sel_nr)) { remove_group(sel_nr+1, block->nr-1, block, gn); remove_group(0, sel_nr-1, block, gn); } } else if (strncmp(string, "name", 4) == 0) { string += 4; if (parse_int(&string, &sel_nr)) { if ((sel_nr >= 0) && (sel_nr < block->nr)) { sscanf(string, "%s", gname); sfree((*gn)[sel_nr]); (*gn)[sel_nr] = strdup(gname); } } } else if (strncmp(string, "case", 4) == 0) { bCase = !bCase; printf("Switched to case %s\n", bCase ? "sensitive" : "insensitive"); } else if (string[0] == 'v') { bVerbose = !bVerbose; printf("Turned verbose %s\n", bVerbose ? "on" : "off"); } else if (string[0] == 'l') { if (check_have_atoms(atoms, ostring) ) { list_residues(atoms); } } else if (strncmp(string, "splitch", 7) == 0) { string += 7; if (check_have_atoms(atoms, ostring) && parse_int(&string, &sel_nr) && (sel_nr >= 0) && (sel_nr < block->nr)) { split_chain(atoms, x, sel_nr, block, gn); } } else if (strncmp(string, "splitres", 8) == 0) { string += 8; if (check_have_atoms(atoms, ostring) && parse_int(&string, &sel_nr) && (sel_nr >= 0) && (sel_nr < block->nr)) { split_group(atoms, sel_nr, block, gn, FALSE); } } else if (strncmp(string, "splitat", 7) == 0) { string += 7; if (check_have_atoms(atoms, ostring) && parse_int(&string, &sel_nr) && (sel_nr >= 0) && (sel_nr < block->nr)) { split_group(atoms, sel_nr, block, gn, TRUE); } } else if (string[0] == '\0') { bPrintOnce = TRUE; } else if (string[0] != 'q') { nr1 = -1; nr2 = -1; if (parse_entry(&string, natoms, atoms, block, gn, &nr, index, gname)) { do { while (string[0] == ' ') { string++; } bAnd = FALSE; bOr = FALSE; if (string[0] == '&') { bAnd = TRUE; } else if (string[0] == '|') { bOr = TRUE; } if (bAnd || bOr) { string++; nr1 = nr; for (i = 0; i < nr; i++) { index1[i] = index[i]; } strcpy(gname1, gname); if (parse_entry(&string, natoms, atoms, block, gn, &nr2, index2, gname2)) { if (bOr) { or_groups(nr1, index1, nr2, index2, &nr, index); sprintf(gname, "%s_%s", gname1, gname2); } else { and_groups(nr1, index1, nr2, index2, &nr, index); sprintf(gname, "%s_&_%s", gname1, gname2); } } } } while (bAnd || bOr); } while (string[0] == ' ') { string++; } if (string[0]) { printf("\nSyntax error: \"%s\"\n", string); } else if (nr > 0) { copy2block(nr, index, block); srenew(*gn, block->nr); newgroup = block->nr-1; (*gn)[newgroup] = strdup(gname); } else { printf("Group is empty\n"); } } } while (string[0] != 'q'); sfree(index); sfree(index1); sfree(index2); }
int Gui::findPage( LGraphicsView *view, QGraphicsScene *scene, int &pageNum, QString const &addLine, Where ¤t, bool isMirrored, Meta meta, bool printing) { bool stepGroup = false; bool partIgnore = false; bool coverPage = false; bool stepPage = false; bool bfxStore1 = false; bool bfxStore2 = false; QStringList bfxParts; int partsAdded = 0; int stepNumber = 1; Rc rc; skipHeader(current); if (pageNum == 1) { topOfPages.clear(); topOfPages.append(current); } QStringList csiParts; QStringList saveCsiParts; Where saveCurrent = current; Where stepGroupCurrent; int saveStepNumber = 1; saveStepPageNum = stepPageNum; Meta saveMeta = meta; QHash<QString, QStringList> bfx; QHash<QString, QStringList> saveBfx; int numLines = ldrawFile.size(current.modelName); Where topOfStep = current; ldrawFile.setRendered(current.modelName, isMirrored); for ( ; current.lineNumber < numLines; current.lineNumber++) { // scan through the rest of the model counting pages // if we've already hit the display page, then do as little as possible QString line = ldrawFile.readLine(current.modelName,current.lineNumber).trimmed(); if (line.startsWith("0 GHOST ")) { line = line.mid(8).trimmed(); } switch (line.toAscii()[0]) { case '1': if ( ! partIgnore) { csiParts << line; if (firstStepPageNum == -1) { firstStepPageNum = pageNum; } lastStepPageNum = pageNum; QStringList token; split(line,token); QString type = token[token.size()-1]; isMirrored = ldrawFile.mirrored(token); bool contains = ldrawFile.contains(type); bool rendered = ldrawFile.rendered(type,isMirrored); if (contains) { if ( ! rendered && ! bfxStore2) { // can't be a callout SubmodelStack tos(current.modelName,current.lineNumber,stepNumber); meta.submodelStack << tos; Where current2(type,0); findPage(view,scene,pageNum,line,current2,isMirrored,meta,printing); saveStepPageNum = stepPageNum; meta.submodelStack.pop_back(); } } if (bfxStore1) { bfxParts << token[1]+type; } } case '2': case '3': case '4': case '5': ++partsAdded; csiParts << line; break; case '0': rc = meta.parse(line,current); switch (rc) { case StepGroupBeginRc: stepGroup = true; stepGroupCurrent = topOfStep; break; case StepGroupEndRc: if (stepGroup) { stepGroup = false; if (pageNum < displayPageNum) { saveCsiParts = csiParts; saveStepNumber = stepNumber; saveMeta = meta; saveBfx = bfx; } else if (pageNum == displayPageNum) { csiParts.clear(); stepPageNum = saveStepPageNum; if (pageNum == 1) { page.meta = meta; } else { page.meta = saveMeta; } page.meta.pop(); QStringList pliParts; (void) drawPage(view, scene, &page, saveStepNumber, addLine, stepGroupCurrent, saveCsiParts, pliParts, isMirrored, saveBfx, printing, bfxStore2, bfxParts); saveCurrent.modelName.clear(); saveCsiParts.clear(); } ++pageNum; topOfPages.append(current); saveStepPageNum = ++stepPageNum; } break; case StepRc: case RotStepRc: if (partsAdded) { stepNumber += ! coverPage && ! stepPage; stepPageNum += ! coverPage && ! stepGroup; if (pageNum < displayPageNum) { if ( ! stepGroup) { saveCsiParts = csiParts; saveStepNumber = stepNumber; saveMeta = meta; saveBfx = bfx; saveStepPageNum = stepPageNum; } saveCurrent = current; } if ( ! stepGroup) { if (pageNum == displayPageNum) { csiParts.clear(); stepPageNum = saveStepPageNum; if (pageNum == 1) { page.meta = meta; } else { page.meta = saveMeta; } page.meta.pop(); QStringList pliParts; (void) drawPage(view, scene, &page, saveStepNumber, addLine, saveCurrent, saveCsiParts, pliParts, isMirrored, saveBfx, printing, bfxStore2, bfxParts); saveCurrent.modelName.clear(); saveCsiParts.clear(); } ++pageNum; topOfPages.append(current); } topOfStep = current; partsAdded = 0; meta.pop(); coverPage = false; stepPage = false; bfxStore2 = bfxStore1; bfxStore1 = false; if ( ! bfxStore2) { bfxParts.clear(); } } else if ( ! stepGroup) { saveCurrent = current; // so that draw page doesn't have to // deal with steps that are not steps } break; case CalloutBeginRc: ++current; { Meta tmpMeta; while (rc != CalloutEndRc && current.lineNumber < numLines) { line = ldrawFile.readLine(current.modelName,current.lineNumber++).trimmed(); rc = OkRc; if (line[0] == '0') { rc = tmpMeta.parse(line,current); } else if (line[0] >= '1' && line[0] <= '5') { if (line[0] == '1') { partsAdded++; csiParts << line; } } } } --current; break; case InsertCoverPageRc: coverPage = true; partsAdded = true; break; case InsertPageRc: stepPage = true; partsAdded = true; break; case PartBeginIgnRc: partIgnore = true; break; case PartEndRc: partIgnore = false; break; // Any of the metas that can change csiParts needs // to be processed here case ClearRc: csiParts.empty(); break; /* Buffer exchange */ case BufferStoreRc: if (pageNum < displayPageNum) { bfx[meta.bfx.value()] = csiParts; } bfxStore1 = true; bfxParts.clear(); break; case BufferLoadRc: if (pageNum < displayPageNum) { csiParts = bfx[meta.bfx.value()]; } partsAdded = true; break; case MLCadGroupRc: if (pageNum < displayPageNum) { csiParts << line; partsAdded++; } break; /* remove a group or all instances of a part type */ case GroupRemoveRc: case RemoveGroupRc: case RemovePartRc: case RemoveNameRc: if (pageNum < displayPageNum) { QStringList newCSIParts; if (rc == RemoveGroupRc) { remove_group(csiParts, meta.LPub.remove.group.value(),newCSIParts); } else if (rc == RemovePartRc) { remove_parttype(csiParts, meta.LPub.remove.parttype.value(),newCSIParts); } else { remove_partname(csiParts, meta.LPub.remove.partname.value(),newCSIParts); } csiParts = newCSIParts; newCSIParts.empty(); } break; case IncludeRc: include(meta); break; default: break; } // switch break; } } // for every line csiParts.clear(); if (partsAdded) { if (pageNum == displayPageNum) { page.meta = saveMeta; QStringList pliParts; (void) drawPage(view, scene, &page, saveStepNumber, addLine, saveCurrent, saveCsiParts, pliParts, isMirrored, bfx, printing, bfxStore2, bfxParts); } ++pageNum; topOfPages.append(current); ++stepPageNum; } return 0; }
static HRESULT fill_groups( struct d3dadapter9 *This ) { DISPLAY_DEVICEW dd; DEVMODEW dm; POINT pt; HDC hdc; HRESULT hr; int i, j, k; WCHAR wdisp[] = {'D','I','S','P','L','A','Y',0}; ZeroMemory(&dd, sizeof(dd)); ZeroMemory(&dm, sizeof(dm)); dd.cb = sizeof(dd); dm.dmSize = sizeof(dm); for (i = 0; EnumDisplayDevicesW(NULL, i, &dd, 0); ++i) { struct adapter_group *group = add_group(This); if (!group) { ERR("Out of memory.\n"); return E_OUTOFMEMORY; } hdc = CreateDCW(wdisp, dd.DeviceName, NULL, NULL); if (!hdc) { remove_group(This); WARN("Unable to create DC for display %d.\n", i); goto end_group; } hr = present_create_adapter9(This->gdi_display, hdc, &group->adapter); DeleteDC(hdc); if (FAILED(hr)) { remove_group(This); goto end_group; } CopyMemory(group->devname, dd.DeviceName, sizeof(group->devname)); for (j = 0; EnumDisplayDevicesW(group->devname, j, &dd, 0); ++j) { struct output *out = add_output(This); boolean orient = FALSE, monit = FALSE; if (!out) { ERR("Out of memory.\n"); return E_OUTOFMEMORY; } for (k = 0; EnumDisplaySettingsExW(dd.DeviceName, k, &dm, 0); ++k) { D3DDISPLAYMODEEX *mode = add_mode(This); if (!out) { ERR("Out of memory.\n"); return E_OUTOFMEMORY; } mode->Size = sizeof(D3DDISPLAYMODEEX); mode->Width = dm.dmPelsWidth; mode->Height = dm.dmPelsHeight; mode->RefreshRate = dm.dmDisplayFrequency; mode->ScanLineOrdering = (dm.dmDisplayFlags & DM_INTERLACED) ? D3DSCANLINEORDERING_INTERLACED : D3DSCANLINEORDERING_PROGRESSIVE; switch (dm.dmBitsPerPel) { case 32: mode->Format = D3DFMT_X8R8G8B8; break; case 24: mode->Format = D3DFMT_R8G8B8; break; case 16: mode->Format = D3DFMT_R5G6B5; break; case 8: remove_mode(This); goto end_mode; default: remove_mode(This); WARN("Unknown format (%u bpp) in display %d, monitor " "%d, mode %d.\n", dm.dmBitsPerPel, i, j, k); goto end_mode; } if (!orient) { switch (dm.dmDisplayOrientation) { case DMDO_DEFAULT: out->rotation = D3DDISPLAYROTATION_IDENTITY; break; case DMDO_90: out->rotation = D3DDISPLAYROTATION_90; break; case DMDO_180: out->rotation = D3DDISPLAYROTATION_180; break; case DMDO_270: out->rotation = D3DDISPLAYROTATION_270; break; default: remove_output(This); WARN("Unknown display rotation in display %d, " "monitor %d\n", i, j); goto end_output; } orient = TRUE; } if (!monit) { pt.x = dm.dmPosition.x; pt.y = dm.dmPosition.y; out->monitor = MonitorFromPoint(pt, 0); if (!out->monitor) { remove_output(This); WARN("Unable to get monitor handle for display %d, " "monitor %d.\n", i, j); goto end_output; } monit = TRUE; } end_mode: ZeroMemory(&dm, sizeof(dm)); dm.dmSize = sizeof(dm); } end_output: ZeroMemory(&dd, sizeof(dd)); dd.cb = sizeof(dd); } end_group: ZeroMemory(&dd, sizeof(dd)); dd.cb = sizeof(dd); } return D3D_OK; }
int Gui::drawPage( LGraphicsView *view, QGraphicsScene *scene, Steps *steps, int stepNum, QString const &addLine, Where ¤t, QStringList &csiParts, QStringList &pliParts, bool isMirrored, QHash<QString, QStringList> &bfx, bool printing, bool bfxStore2, QStringList &bfxParts, bool calledOut) { bool global = true; QString line; Callout *callout = NULL; Range *range = NULL; Step *step = NULL; bool pliIgnore = false; bool partIgnore = false; bool synthBegin = false; bool multiStep = false; bool partsAdded = false; bool coverPage = false; bool bfxStore1 = false; bool bfxLoad = false; int numLines = ldrawFile.size(current.modelName); bool firstStep = true; steps->isMirrored = isMirrored; QList<InsertMeta> inserts; Where topOfStep = current; Rc gprc = OkRc; Rc rc; statusBar()->showMessage("Processing " + current.modelName); page.coverPage = false; QStringList calloutParts; /* * do until end of page */ for ( ; current <= numLines; current++) { Meta &curMeta = callout ? callout->meta : steps->meta; QStringList tokens; // If we hit end of file we've got to note end of step if (current >= numLines) { line.clear(); gprc = EndOfFileRc; tokens << "0"; // not end of file, so get the next LDraw line } else { line = ldrawFile.readLine(current.modelName,current.lineNumber); split(line,tokens); } if (tokens.size() == 15 && tokens[0] == "1") { QString color = tokens[1]; QString type = tokens[tokens.size()-1]; csiParts << line; partsAdded = true; /* since we have a part usage, we have a valid step */ if (step == NULL) { if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } step = new Step(topOfStep, range, stepNum, curMeta, calledOut, multiStep); range->append(step); } /* addition of ldraw parts */ if (curMeta.LPub.pli.show.value() && ! pliIgnore && ! partIgnore && ! synthBegin) { QString colorType = color+type; if (! isSubmodel(type) || curMeta.LPub.pli.includeSubs.value()) { if (bfxStore2 && bfxLoad) { bool removed = false; for (int i = 0; i < bfxParts.size(); i++) { if (bfxParts[i] == colorType) { bfxParts.removeAt(i); removed = true; break; } } if ( ! removed) { pliParts << Pli::partLine(line,current,steps->meta); } } else { pliParts << Pli::partLine(line,current,steps->meta); } } if (bfxStore1) { bfxParts << colorType; } } /* if it is a sub-model, then process it */ if (ldrawFile.contains(type) && callout) { /* we are a callout, so gather all the steps within the callout */ /* start with new meta, but no rotation step */ if (callout->bottom.modelName != type) { Where current2(type,0); skipHeader(current2); callout->meta.rotStep.clear(); SubmodelStack tos(current.modelName,current.lineNumber,stepNum); callout->meta.submodelStack << tos; Meta saveMeta = callout->meta; callout->meta.LPub.pli.constrain.resetToDefault(); step->append(callout); calloutParts.clear(); QStringList csiParts2; QHash<QString, QStringList> calloutBfx; int rc; rc = drawPage( view, scene, callout, 1, line, current2, csiParts2, calloutParts, ldrawFile.mirrored(tokens), calloutBfx, printing, bfxStore2, bfxParts, true); callout->meta = saveMeta; if (callout->meta.LPub.pli.show.value() && ! callout->meta.LPub.callout.pli.perStep.value() && ! pliIgnore && ! partIgnore && ! synthBegin) { pliParts += calloutParts; } if (rc != 0) { steps->placement = steps->meta.LPub.assem.placement; return rc; } } else { callout->instances++; pliParts += calloutParts; } /* remind user what file we're working on */ statusBar()->showMessage("Processing " + current.modelName); } } else if (tokens.size() > 0 && (tokens[0] == "2" || tokens[0] == "3" || tokens[0] == "4" || tokens[0] == "5")) { csiParts << line; partsAdded = true; /* we've got a line, triangle or polygon, so add it to the list */ /* and make sure we know we have a step */ if (step == NULL) { if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } step = new Step(topOfStep, range, stepNum, steps->meta, calledOut, multiStep); range->append(step); } } else if (tokens.size() > 0 && tokens[0] == "0" || gprc == EndOfFileRc) { /* must be meta-command (or comment) */ if (global && tokens.contains("!LPUB") && tokens.contains("GLOBAL")) { topOfStep = current; } else { global = false; } QString part; if (gprc == EndOfFileRc) { rc = gprc; } else { rc = curMeta.parse(line,current,true); } /* handle specific meta-commands */ switch (rc) { /* toss it all out the window, per James' original plan */ case ClearRc: pliParts.clear(); csiParts.clear(); steps->freeSteps(); break; /* Buffer exchange */ case BufferStoreRc: bfx[curMeta.bfx.value()] = csiParts; bfxStore1 = true; bfxParts.clear(); break; case BufferLoadRc: csiParts = bfx[curMeta.bfx.value()]; bfxLoad = true; break; case MLCadGroupRc: csiParts << line; break; case IncludeRc: include(curMeta); break; /* substitute part/parts with this */ case PliBeginSub1Rc: if (pliIgnore) { parseError("Nested PLI BEGIN/ENDS not allowed\n",current); } if (steps->meta.LPub.pli.show.value() && ! pliIgnore && ! partIgnore && ! synthBegin) { SubData subData = curMeta.LPub.pli.begin.sub.value(); QString addPart = QString("1 0 0 0 0 0 0 0 0 0 0 0 0 0 %1") .arg(subData.part); pliParts << Pli::partLine(addPart,current,curMeta); } if (step == NULL) { if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } step = new Step(topOfStep, range, stepNum, curMeta, calledOut, multiStep); range->append(step); } pliIgnore = true; break; /* substitute part/parts with this */ case PliBeginSub2Rc: if (pliIgnore) { parseError("Nested BEGIN/ENDS not allowed\n",current); } if (steps->meta.LPub.pli.show.value() && ! pliIgnore && ! partIgnore && ! synthBegin) { SubData subData = curMeta.LPub.pli.begin.sub.value(); QString addPart = QString("1 %1 0 0 0 0 0 0 0 0 0 0 0 0 %2") .arg(subData.color) .arg(subData.part); pliParts << Pli::partLine(addPart,current,curMeta); } if (step == NULL) { if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } step = new Step(topOfStep, range, stepNum, curMeta, calledOut, multiStep); range->append(step); } pliIgnore = true; break; /* do not put subsequent parts into PLI */ case PliBeginIgnRc: if (pliIgnore) { parseError("Nested BEGIN/ENDS not allowed\n",current); } pliIgnore = true; break; case PliEndRc: if ( ! pliIgnore) { parseError("PLI END with no PLI BEGIN",current); } pliIgnore = false; break; /* discard subsequent parts, and don't create CSI's for them */ case PartBeginIgnRc: case MLCadSkipBeginRc: if (partIgnore) { parseError("Nested BEGIN/ENDS not allowed\n",current); } partIgnore = true; break; case PartEndRc: case MLCadSkipEndRc: if (partIgnore) { parseError("Ignore ending with no ignore begin",current); } partIgnore = false; break; case SynthBeginRc: if (synthBegin) { parseError("Nested BEGIN/ENDS not allowed\n",current); } synthBegin = true; break; case SynthEndRc: if ( ! synthBegin) { parseError("Ignore ending with no ignore begin",current); } synthBegin = false; break; /* remove a group or all instances of a part type */ case GroupRemoveRc: case RemoveGroupRc: case RemovePartRc: case RemoveNameRc: { QStringList newCSIParts; if (rc == RemoveGroupRc) { remove_group(csiParts,steps->meta.LPub.remove.group.value(),newCSIParts); } else if (rc == RemovePartRc) { remove_parttype(csiParts, steps->meta.LPub.remove.parttype.value(),newCSIParts); } else { remove_partname(csiParts, steps->meta.LPub.remove.partname.value(),newCSIParts); } csiParts = newCSIParts; if (step == NULL) { if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } step = new Step(topOfStep, range, stepNum, curMeta, calledOut, multiStep); range->append(step); } } break; case ReserveSpaceRc: /* since we have a part usage, we have a valid step */ if (calledOut || multiStep) { step = NULL; Reserve *reserve = new Reserve(current,steps->meta.LPub); if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } range->append(reserve); } break; case InsertCoverPageRc: coverPage = true; page.coverPage = true; case InsertPageRc: partsAdded = true; break; case InsertRc: inserts.append(curMeta.LPub.insert); // these are always placed before any parts in step break; case CalloutBeginRc: if (callout) { parseError("Nested CALLOUT not allowed within the same file",current); } else { callout = new Callout(curMeta,view); callout->setTopOfCallout(current); } break; case CalloutDividerRc: if (range) { range->sepMeta = curMeta.LPub.callout.sep; range = NULL; step = NULL; } break; case CalloutPointerRc: if (callout) { callout->appendPointer(current,curMeta.LPub.callout); } break; case CalloutEndRc: if ( ! callout) { parseError("CALLOUT END without a CALLOUT BEGIN",current); } else { callout->parentStep = step; callout->parentRelativeType = step->relativeType; callout->pli.clear(); callout->placement = curMeta.LPub.callout.placement; callout->setBottomOfCallout(current); callout = NULL; } break; case StepGroupBeginRc: if (calledOut) { parseError("MULTI_STEP not allowed inside callout models",current); } else { if (multiStep) { parseError("Nested MULTI_STEP not allowed",current); } multiStep = true; } steps->relativeType = StepGroupType; break; case StepGroupDividerRc: if (range) { range->sepMeta = steps->meta.LPub.multiStep.sep; range = NULL; step = NULL; } break; /* finished off a multiStep */ case StepGroupEndRc: if (multiStep) { // save the current meta as the meta for step group // PLI for non-pli-per-step if (partsAdded) { parseError("Expected STEP before MULTI_STEP END", current); } multiStep = false; if (pliParts.size() && steps->meta.LPub.multiStep.pli.perStep.value() == false) { steps->pli.bom = false; steps->pli.setParts(pliParts,steps->stepGroupMeta); steps->pli.sizePli(&steps->stepGroupMeta, StepGroupType, false); } pliParts.clear(); /* this is a page we're supposed to process */ steps->placement = steps->meta.LPub.multiStep.placement; showLine(steps->topOfSteps()); bool endOfSubmodel = stepNum == ldrawFile.numSteps(current.modelName); int instances = ldrawFile.instances(current.modelName,isMirrored); addGraphicsPageItems(steps, coverPage, endOfSubmodel,instances, view, scene,printing); return HitEndOfPage; } break; /* we're hit some kind of step, or implied step and end of file */ case EndOfFileRc: case RotStepRc: case StepRc: if ( ! partsAdded && bfxLoad) { // special case of no parts added, but BFX load if (step == NULL) { if (range == NULL) { range = newRange(steps,calledOut); steps->append(range); } step = new Step(topOfStep, range, stepNum, curMeta, calledOut, multiStep); range->append(step); } int rc = step->createCsi( isMirrored ? addLine : "1 color 0 0 0 1 0 0 0 1 0 0 0 1 foo.ldr", csiParts, &step->csiPixmap, steps->meta); partsAdded = true; // OK, so this is a lie, but it works } if (partsAdded) { if (firstStep) { steps->stepGroupMeta = curMeta; firstStep = false; } if (pliIgnore) { parseError("PLI BEGIN then STEP. Expected PLI END",current); pliIgnore = false; } if (partIgnore) { parseError("PART BEGIN then STEP. Expected PART END",current); partIgnore = false; } if (synthBegin) { parseError("SYNTH BEGIN then STEP. Expected SYNTH_END",current); synthBegin = false; } bool pliPerStep; if (multiStep && steps->meta.LPub.multiStep.pli.perStep.value()) { pliPerStep = true; } else if (calledOut && steps->meta.LPub.callout.pli.perStep.value()) { pliPerStep = true; } else if ( ! multiStep && ! calledOut) { pliPerStep = true; } else { pliPerStep = false; } if (step) { Page *page = dynamic_cast<Page *>(steps); if (page) { page->inserts = inserts; } if (pliPerStep) { PlacementType relativeType; if (multiStep) { relativeType = StepGroupType; } else if (calledOut) { relativeType = CalloutType; } else { relativeType = SingleStepType; } step->pli.setParts(pliParts,steps->meta); pliParts.clear(); step->pli.sizePli(&steps->meta,relativeType,pliPerStep); } int rc = step->createCsi( isMirrored ? addLine : "1 color 0 0 0 1 0 0 0 1 0 0 0 1 foo.ldr", csiParts, &step->csiPixmap, steps->meta); statusBar()->showMessage("Processing " + current.modelName); if (rc) { return rc; } } else { if (pliPerStep) { pliParts.clear(); } /* * Only pages or step can have inserts.... no callouts */ if ( ! multiStep && ! calledOut) { Page *page = dynamic_cast<Page *>(steps); if (page) { page->inserts = inserts; } } } if ( ! multiStep && ! calledOut) { /* * Simple step */ if (steps->list.size() == 0) { steps->relativeType = PageType; } steps->placement = steps->meta.LPub.assem.placement; showLine(topOfStep); int numSteps = ldrawFile.numSteps(current.modelName); bool endOfSubmodel = numSteps == 0 || stepNum == numSteps; int instances = ldrawFile.instances(current.modelName,isMirrored); addGraphicsPageItems(steps,coverPage,endOfSubmodel,instances,view,scene,printing); stepPageNum += ! coverPage; steps->setBottomOfSteps(current); return HitEndOfPage; } steps->meta.pop(); stepNum += partsAdded; topOfStep = current; partsAdded = false; coverPage = false; step = NULL; bfxStore2 = bfxStore1; bfxStore1 = false; bfxLoad = false; } inserts.clear(); steps->setBottomOfSteps(current); break; case RangeErrorRc: showLine(current); QMessageBox::critical(NULL, QMessageBox::tr("LPub"), QMessageBox::tr("Parameter(s) out of range: %1:%2\n%3") .arg(current.modelName) .arg(current.lineNumber) .arg(line)); return RangeErrorRc; break; default: break; } } else if (line != "") { showLine(current); QMessageBox::critical(NULL, QMessageBox::tr("LPub"), QMessageBox::tr("Invalid LDraw Line Type: %1:%2\n %3") .arg(current.modelName) .arg(current.lineNumber) .arg(line)); return InvalidLDrawLineRc; } } steps->meta.rotStep.clear(); return 0; }
void Gui::writeToTmp( const QString &fileName, const QStringList &contents) { QString fname = QDir::currentPath() + "/" + Paths::tmpDir + "/" + fileName; QFile file(fname); if ( ! file.open(QFile::WriteOnly|QFile::Text)) { QMessageBox::warning(NULL,QMessageBox::tr("LPub"), QMessageBox::tr("Failed to open %1 for writing: %2") .arg(fname) .arg(file.errorString())); } else { QStringList csiParts; QHash<QString, QStringList> bfx; for (int i = 0; i < contents.size(); i++) { QString line = contents[i]; QStringList tokens; split(line,tokens); if (tokens.size()) { if (tokens[0] != "0") { csiParts << line; } else { Meta meta; Rc rc; Where here(fileName,i); rc = meta.parse(line,here,false); switch (rc) { /* Buffer exchange */ case BufferStoreRc: bfx[meta.bfx.value()] = csiParts; break; case BufferLoadRc: csiParts = bfx[meta.bfx.value()]; break; /* remove a group or all instances of a part type */ case GroupRemoveRc: case RemoveGroupRc: case RemovePartRc: case RemoveNameRc: { QStringList newCSIParts; if (rc == RemoveGroupRc) { remove_group(csiParts,meta.LPub.remove.group.value(),newCSIParts); } else if (rc == RemovePartRc) { remove_parttype(csiParts, meta.LPub.remove.parttype.value(),newCSIParts); } else { remove_partname(csiParts, meta.LPub.remove.partname.value(),newCSIParts); } csiParts = newCSIParts; } break; default: break; } } } } QTextStream out(&file); for (int i = 0; i < csiParts.size(); i++) { out << csiParts[i] << endl; } file.close(); } }
int Gui::getBOMParts( Where current, QStringList &pliParts) { bool partIgnore = false; bool pliIgnore = false; bool synthBegin = false; bool bfxStore1 = false; bool bfxStore2 = false; bool bfxLoad = false; bool partsAdded = false; QStringList bfxParts; Meta meta; skipHeader(current); QHash<QString, QStringList> bfx; int numLines = ldrawFile.size(current.modelName); Rc rc; for ( ; current.lineNumber < numLines; current.lineNumber++) { // scan through the rest of the model counting pages // if we've already hit the display page, then do as little as possible QString line = ldrawFile.readLine(current.modelName,current.lineNumber).trimmed(); if (line.startsWith("0 GHOST ")) { line = line.mid(8).trimmed(); } switch (line.toAscii()[0]) { case '1': if ( ! partIgnore && ! pliIgnore && ! synthBegin) { QStringList token; split(line,token); QString type = token[token.size()-1]; /* * Automatically ignore parts added twice due to buffer exchange */ bool removed = false; QString colorPart = token[1] + type; if (bfxStore2 && bfxLoad) { int i; for (i = 0; i < bfxParts.size(); i++) { if (bfxParts[i] == colorPart) { bfxParts.removeAt(i); removed = true; break; } } } if ( ! removed) { if (ldrawFile.contains(type)) { Where current2(type,0); getBOMParts(current2,pliParts); } else { pliParts << Pli::partLine(line,current,meta); } } if (bfxStore1) { bfxParts << colorPart; } partsAdded = true; } break; case '0': rc = meta.parse(line,current); /* substitute part/parts with this */ switch (rc) { case PliBeginSub1Rc: if (! pliIgnore && ! partIgnore && ! synthBegin) { QString line = QString("1 0 0 0 0 0 0 0 0 0 0 0 0 0 %1") .arg(meta.LPub.pli.begin.sub.value().part); pliParts << Pli::partLine(line,current,meta); pliIgnore = true; } break; /* substitute part/parts with this */ case PliBeginSub2Rc: if (! pliIgnore && ! partIgnore && ! synthBegin) { QString line = QString("1 %1 0 0 0 0 0 0 0 0 0 0 0 0 %2") .arg(meta.LPub.pli.begin.sub.value().color) .arg(meta.LPub.pli.begin.sub.value().part); pliParts << Pli::partLine(line,current,meta); pliIgnore = true; } break; case PliBeginIgnRc: pliIgnore = true; break; case PliEndRc: pliIgnore = false; break; case PartBeginIgnRc: partIgnore = true; break; case PartEndRc: partIgnore = false; break; case SynthBeginRc: synthBegin = true; break; case SynthEndRc: synthBegin = false; break; /* Buffer exchange */ case BufferStoreRc: bfxStore1 = true; bfxParts.clear(); break; case BufferLoadRc: bfxLoad = true; break; // Any of the metas that can change pliParts needs // to be processed here case ClearRc: pliParts.empty(); break; case MLCadGroupRc: pliParts << Pli::partLine(line,current,meta); break; /* remove a group or all instances of a part type */ case GroupRemoveRc: case RemoveGroupRc: case RemovePartRc: case RemoveNameRc: { QStringList newCSIParts; if (rc == RemoveGroupRc) { remove_group(pliParts,meta.LPub.remove.group.value(),newCSIParts); } else if (rc == RemovePartRc) { remove_parttype(pliParts, meta.LPub.remove.parttype.value(),newCSIParts); } else { remove_partname(pliParts, meta.LPub.remove.partname.value(),newCSIParts); } pliParts = newCSIParts; } break; case StepRc: if (partsAdded) { bfxStore2 = bfxStore1; bfxStore1 = false; bfxLoad = false; if ( ! bfxStore2) { bfxParts.clear(); } } partsAdded = false; break; default: break; } // switch break; } } // for every line return 0; }
static bool UseIShellLink( bool uninstall ) /*****************************************/ { WORD dir_index, icon_number; int i, num_icons, num_groups; int num_installed, num_total_install; DWORD temp; char prog_name[_MAX_PATH], prog_desc[_MAX_PATH]; char icon_name[_MAX_PATH], working_dir[_MAX_PATH]; char group[_MAX_PATH], prog_arg[_MAX_PATH], tmp[_MAX_PATH]; BOOL rc; if( uninstall ) { num_groups = SimGetNumPMGroups(); for( i = 0; i < num_groups; i++ ) { SimGetPMGroupName( i, group ); if( *group != '\0' ) { // Delete the PM Group box remove_group( group ); } } return( TRUE ); } SimGetPMGroup( group ); if( group[0] == '\0' ) { return( TRUE ); } CoInitialize( NULL ); // Create the PM Group box. if( !create_group( group ) ) { CoUninitialize(); return( FALSE ); } // Add the individual PM files to the Group box. num_icons = SimGetNumPMProgs(); StatusLines( STAT_CREATEPROGRAMFOLDER, "" ); num_total_install = 0; for( i = 0; i < num_icons; i++ ) { if( SimCheckPMCondition( i ) ) { ++num_total_install; } } num_installed = 0; StatusAmount( 0, num_total_install ); for( i = 0; i < num_icons; i++ ) { if( !SimCheckPMCondition( i ) ) { continue; } SimGetPMDesc( i, prog_desc ); dir_index = SimGetPMProgName( i, prog_name ); if( strcmp( prog_name, "GROUP" ) == 0 ) { /* creating a new group */ strcpy( group, prog_desc ); if( !create_group( group ) ) { CoUninitialize(); return( FALSE ); } } else { // Adding item to group if( dir_index == SIM_INIT_ERROR ) { working_dir[ 0 ] = '\0'; ReplaceVars( tmp, prog_name ); strcpy( prog_name, tmp ); } else { SimDirNoSlash( dir_index, working_dir ); } // Get parameters SimGetPMParms( i, tmp ); ReplaceVars( prog_arg, tmp ); // Append the subdir where the icon file is and the icon file's name. temp = SimGetPMIconInfo( i, icon_name ); dir_index = LOWORD( temp ); icon_number = HIWORD( temp ); if( icon_number == SIM_INIT_ERROR ) icon_number = 0; if( dir_index != SIM_INIT_ERROR ) { SimGetDir( dir_index, tmp ); strcat( tmp, icon_name ); strcpy( icon_name, tmp ); } // Add the new file to the already created PM Group. rc = create_icon( group, prog_name, prog_desc, prog_arg, working_dir, icon_name, icon_number ); if( rc == FALSE ) { CoUninitialize(); return( FALSE ); } } ++num_installed; StatusAmount( num_installed, num_total_install ); if( StatusCancelled() ) break; } StatusAmount( num_total_install, num_total_install ); CoUninitialize(); return( TRUE ); }
void main_loop(pDataStruct workingData){ char *commandList[] = {"set", "get", "add", "delete","exit","help","ls","cat","cd"}; char *setList[] = {"date", "user", "group","help"}; char *getList[] = {"date", "user", "group", "workingDir","help", "userlist", "grouplist", "usersingroup"}; char *addList[] = {"user", "group", "file", "directory", "usertogroup","perm", "appendfile","help"}; char *deleteList[] = {"user", "group", "file", "directory", "usertogroup","perm", "filebytes","help"}; char arg[16][MAXCOMMAND]; char command[MAXCOMMAND]; int argnum, i, j, tempNum, cmd, size; char *c; char temp[MAXPATH]; char *tempBuf; unsigned char *rcvBuf; pNode tempNode = NULL; pUser tempUser = NULL; pGroup tempGroup = NULL; pFile tempFile = NULL; pPerms tempPerms = NULL; pFileChunk tempFileChunk = NULL; pGroupUserList tempGroupUserList = NULL; while(1){ argnum = i = j = tempNum = cmd = 0; c = 0; bzero(temp, sizeof(temp)); tempBuf = NULL; tempNode = NULL; tempUser = NULL; tempGroup = NULL; tempFile = NULL; tempPerms = NULL; tempFileChunk = NULL; tempGroupUserList = NULL; bzero(command, sizeof(command)); print_prompt(workingData); get_string(command, MAXCOMMAND-1, ""); for (j = 0;j<16;j++){ bzero(arg[j],MAXCOMMAND); } argnum = parse_arg(arg, command); tempNum = 0; cmd = 100; for (i=0;i<sizeof(commandList)/4;i++){ if (strcmp(commandList[i],arg[0]) == 0 ){ cmd = i; } } switch(cmd) { case 0x0 : //set cmd = 100; for (i=0;i<sizeof(setList)/4;i++){ if (strcmp(setList[i],arg[1]) == 0){ cmd = i; } } switch(cmd) { case 0 : //set date workingData->date = get_time(); break;//end set date case 1 : //set user if ( strcmp(arg[2],"") == 0){ puts("missing user name or number"); break; } tempUser = find_user(arg[2],workingData); if ( tempUser != NULL ){ workingData->currentUser = tempUser; } else { printf("unknown user: @s\n",arg[2]); } break;//end set user case 2 : //set group if ( strcmp(arg[2], "") == 0){ puts("missing group name or number"); break; } tempGroup = find_group(arg[2], workingData); if ( tempGroup != NULL){ workingData->currentGroup = tempGroup; } else { printf("unknown group: @s\n",arg[2]); } break; case 3 : //set help print_help(setList,(sizeof(setList)/4)); break;//end set help default : printf("Invalid command: @s\n",arg[1]); } break;//end set case 1 ://get cmd = 100; for (i=0;i<sizeof(getList)/4;i++){ if (strcmp(getList[i],arg[1]) == 0){ cmd = i; } } switch(cmd) { case 0 : //get date strofdate( workingData->date); break;//end get date case 1 : //get user printf("@s\n",workingData->currentUser->name); break;//end get user case 2 : //get group printf("@s\n",workingData->currentGroup->name); break;//end get group case 3 : //get workingDir bzero(temp,MAXPATH); str_of_path( temp, workingData, workingData->workingDir); printf("@s/\n",temp); break;//end get workingDir case 4 : //get help print_help(getList,(sizeof(getList)/4)); break;//end get help case 5 : //get userlist print_user_list(workingData); break;//end get userlist case 6 : //get grouplist print_group_list(workingData); break;//end get grouplist case 7 : //get usersingroup if ( strcmp(arg[2], "") == 0){ puts("missing group name or number"); break; } tempGroup = find_group(arg[2], workingData); if ( tempGroup != NULL ){ print_users_in_group(tempGroup); break; } printf("unknown group: @s\n",arg[2]); break;//end get useringroup default : printf("Invalid command: @s\n",arg[1]); } break;//end get case 2 ://add cmd = 100; for (i=0;i<sizeof(addList)/4;i++){ if ( strcmp(addList[i],arg[1]) == 0 ){ cmd = i; } } switch(cmd) { case 0 : //add user if ( strcmp(arg[2],"") == 0 ){ bzero(temp,MAXPATH); get_string(temp, 128, "UserName"); strcpy(arg[2],temp); } tempUser = find_user( arg[2], workingData); if ( tempUser == NULL ){ add_user( arg[2], workingData ); } else { puts("Username already in use"); } break;//end add user case 1 : //add group if ( strcmp(arg[2],"") == 0 ){ bzero(temp,MAXPATH); get_string(temp, 128, "GroupName"); strcpy(arg[2], temp); } tempGroup = find_group( arg[2], workingData); if ( tempGroup == NULL ){ add_group( arg[2], workingData ); } else { puts("Groupname already in use"); } break;//end add group case 2 : //add file //add file name size tempNum = atoi(arg[3]); if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } if ( tempNum > MAXUPLOAD ){ puts("Too big"); break; } if ( find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode) != NULL ){ puts("There is another file or directory with that name"); break; } if ( tempNum > 0){ rcvBuf = mallocOrDie(tempNum,"Failed to allocate tempBuf"); puts("-----Begin File-----");//five - if ( tempNum != receive_bytes(rcvBuf,tempNum) ){ die("Failed to reveive file"); break; } } else {rcvBuf = NULL;} tempNode = add_file( workingData->workingDir, workingData->date, tempNum, arg[2], (char *)rcvBuf, workingData->currentUser ); break;//end add file case 3 : //add directory if (strcmp(arg[2],"") == 0){ puts("Directory name required"); break; } if ( find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode) != NULL ){ puts("There is another file or directory with that name"); break; } tempNode = add_directory( workingData->date, arg[2], workingData->workingDir, workingData->currentUser ); break;//end add directory case 4 : //add useringroup if (strcmp(arg[2],"") == 0){ puts("username or number required"); break; } tempUser = find_user( arg[2], workingData); if ( tempUser != NULL ){//user exists tempGroupUserList = is_user_in_group( tempUser, workingData->currentGroup ); if ( tempGroupUserList == NULL ){//user is not already in group add_user_to_group( tempUser, workingData->currentGroup ); } else {printf("@s is already in @s\n",arg[2], workingData->currentGroup->name);} } else { puts("User does not exist, add user first"); } break;//end add useringroup case 5 : //add perm if ( ( strcmp(arg[2],"") == 0 )||( strcmp(arg[2]," ") == 0 ) ){//arg[2] name of file or dir puts("name of file or directory required"); break; } if (!( (strcmp(arg[3],"user") == 0) ^ (strcmp(arg[3],"group") == 0) )) {//arg[3] user, group puts("'user' or 'group'"); break; } if (strcmp(arg[4],"") == 0){ puts("user name, group name, or number required");//arg[4] name or number of user or group break; } tempNode = find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode );//validate file or dir if (tempNode == NULL){ puts("Invalid file or directory"); break; } if (tempNode->type == LINK){ tempNode = tempNode->directoryHeadNode; break; } if (strcmp(arg[3],"user") == 0){ tempUser = find_user(arg[4],workingData); tempGroup = NULL; if (tempUser == NULL){ printf("user @s not found\n",arg[4]); break; } } else { tempGroup = find_group(arg[4],workingData); tempUser = NULL; if (tempGroup == NULL){ printf("group @s not found\n",arg[4]); break; } } validate_current_perms(tempNode, workingData); tempPerms = add_perm(tempUser, tempGroup, tempNode ); break;//end add perm case 6 : //add appendfile tempNum = atoi(arg[3]); if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } if ( tempNum > MAXUPLOAD ){ puts("Too big"); break; } tempFile = find_file_by_name(arg[2],workingData->workingDir); if ( tempFile == NULL ){ puts("No file in working directory by that name"); break; } if ( tempNum > 0){ tempBuf = mallocOrDie(tempNum,"Failed to allocate tempBuf"); puts("-----Begin File-----");//five - if ( tempNum != receive_bytes((unsigned char *)tempBuf,tempNum) ){ die("Failed to reveive file"); break; } } else { tempBuf = NULL; puts("Can not add 0 bytes to file"); break; } tempFileChunk = add_file_chunk( tempBuf, tempFile, tempNum ); break;//end add appendfile case 7 : //add help print_help(addList, (sizeof(addList)/4)); break;//end add help default : printf("Invalid command: @s\n",arg[1]); } break;//end add case 3 ://delete cmd = 100; for (i=0;i<sizeof(deleteList)/4;i++){ if ( strcmp(deleteList[i],arg[1]) == 0 ){ cmd = i; } } switch(cmd) { case 0 : //delete user bzero(temp,MAXPATH); if ( strcmp(arg[2],"") == 0 ){ get_string(temp, 128, "User Name or number"); strcpy(arg[2],temp); } tempUser = find_user( arg[2], workingData); if ( tempUser != NULL ){ remove_user(tempUser , workingData ); } else { puts("No such user found"); } break;//end delete user case 1 : //delete group bzero(temp,MAXPATH); if ( strcmp(arg[2],"") == 0 ){ get_string(temp, 128, "Group Name or number"); strcpy(arg[2],temp); } tempGroup = find_group( arg[2], workingData); if ( tempGroup != NULL ){ remove_group(tempGroup , workingData ); } else { puts("no such group found"); } break;//end delete group case 2 : //delete file if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } tempNode = find_file_node_by_name(arg[2],workingData->workingDir); if (tempNode == NULL){ puts("No such file"); break; } delete_node(tempNode, workingData); break;//end delete file case 3 : //delete directory if (strcmp(arg[2],"") == 0){ puts("Directory name required"); break; } tempNode = find_directory_by_name(arg[2],workingData->workingDir); if (tempNode == NULL){ puts("No such directory"); break; } delete_node(tempNode, workingData); break;//end delete directory case 4 : //delete usertogroup if (strcmp(arg[2],"") == 0){ puts("User name required"); break; } if (strcmp(arg[3],"") == 0){ puts("group name required"); break; } tempUser = find_user(arg[2],workingData); if (tempUser == NULL){ puts("No such user"); break; } tempGroup = find_group(arg[3],workingData); if (tempGroup == NULL){ puts("No such group"); break; } tempGroupUserList = is_user_in_group(tempUser, tempGroup); if (tempGroupUserList == NULL){ puts("User is not in group"); break; } remove_user_from_group(tempUser, tempGroup); break;//end delete usertogroup case 5 : //delete perm if (strcmp(arg[3],"") == 0){ puts("User or group name required"); break; } if (strcmp(arg[2],"") == 0){ puts("file name required"); break; } tempNode = find_node_by_name(arg[2],workingData->workingDir->directoryHeadNode); if (tempNode == NULL){ puts("No such file"); break; } tempPerms = find_perm_by_name(arg[3],tempNode,workingData); if (tempPerms != NULL){ delete_perms(tempNode, tempPerms); } else { puts("No such user permission on file"); } break;//end delete perm case 6 : //delete filebytes [file] [numbytes] if (strcmp(arg[2],"") == 0){ puts("Filename required"); break; } size = strict_atoi(arg[3]); if (size == 0){ puts("zero bytes deleted"); break; } //validate file tempNode = find_file_node_by_name(arg[2],workingData->workingDir); tempFile = tempNode->file; if (tempNode == NULL){ puts("No such file"); printf("@s\n",arg[2]); break; } tempNum = get_file_size(tempFile); if (size > tempNum){ puts("Too many bytes"); } //tempNum is new file size tempNum = tempNum - size; delete_file_bytes(tempFile, tempNum); break;//end delete file case 7 : //delete help print_help(deleteList, (sizeof(deleteList)/4)); break;//end delete help default: print_help(deleteList, (sizeof(deleteList)/4)); //break;//end delete help } break;//end delete case 4 ://cgc_exit puts("exiting"); goto cgc_exit; break; case 5 ://help print_help(commandList, (sizeof(commandList)/4)); break; case 6 ://ls print_working_dir(workingData); break; case 7 ://cat if (strcmp(arg[1],"") == 0){ puts("Filename required"); break; } tempFile = find_file_by_name(arg[1], workingData->workingDir); if ( tempFile != NULL ){ tempFileChunk = tempFile->head; puts("-----Begin File-----");//five - while ( tempFileChunk != NULL ){ if (tempFileChunk->chunkSize != cgc_write(tempFileChunk,tempFileChunk->chunkSize)){ puts("file write failed"); } /* c = tempFileChunk->chunk; for ( i = 0; i < tempFileChunk->chunkSize; i++ ){//putc each byte of every chunk putc( *c); c++; } */ tempFileChunk = tempFileChunk->next; } puts("-----END File-----");//five - } break; case 8 ://cd if (strcmp(arg[1],"") == 0){ puts("directory required"); break; } if (strcmp(arg[1],"..") == 0){ if (workingData->workingDir->parent != NULL){ workingData->workingDir = workingData->workingDir->parent; } break; } tempNode = find_directory_by_name(arg[1],workingData->workingDir); if ( tempNode != NULL ){ workingData->workingDir = tempNode; break; } puts("No such directory in working directory"); break;//end cd default : printf("Invalid command @s\n",arg[0]); print_help(commandList, (sizeof(commandList)/4)); } } cgc_exit: return; }