static void print_ifclose(int indent) { f_print(fout, ")) {\n"); tabify(fout, indent); f_print(fout, "\treturn (FALSE);\n"); tabify(fout, indent); f_print(fout, "}\n"); }
void pdeclaration(const char *name, declaration *dec, int tab, const char *separator) { char buf[8]; /* enough to hold "struct ", include NUL */ const char *prefix; const char *type; if (streq(dec->type, "void")) { return; } tabify(fout, tab); if (streq(dec->type, name) && !dec->prefix) { f_print(fout, "struct "); } if (streq(dec->type, "string")) { f_print(fout, "char *%s", dec->name); } else { prefix = ""; if (streq(dec->type, "bool")) { type = "bool_t"; } else if (streq(dec->type, "opaque")) { type = "char"; } else { if (dec->prefix) { s_print(buf, "%s ", dec->prefix); prefix = buf; } type = dec->type; } switch (dec->rel) { case REL_ALIAS: f_print(fout, "%s%s %s", prefix, type, dec->name); break; case REL_VECTOR: f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, dec->array_max); break; case REL_POINTER: f_print(fout, "%s%s *%s", prefix, type, dec->name); break; case REL_ARRAY: f_print(fout, "struct {\n"); tabify(fout, tab); f_print(fout, "\tu_int %s_len;\n", dec->name); tabify(fout, tab); f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); tabify(fout, tab); f_print(fout, "} %s", dec->name); break; } } f_print(fout, "%s", separator); }
static int output(TelnetState* ts) { lua_State* L = ts->L; size_t len; const char* buf = luaL_checklstring(L, -1, &len); char* b = 0; b = tabify(buf, &len); if (b) buf = b; if (ts->editmode == TELNET_EDIT_MODE) { // teel adds newlines automatically -> remove it if (len>0 && buf[len-1] == '\n') len--; if (len>0 && buf[len-1] == '\r') len--; teel_outputbeforeline(ts->teel, buf, len); } else WriteBytes(&ts->out, buf, len); MEM_FREE(b); return 0; }
//------------------------------------------------------------------------------------------------------------------ bool Serializer::push(const Json& _j, ostream& _oStream, size_t _tab, bool _skipFirstRowTab) { if(!_skipFirstRowTab) tabify(_oStream, _tab); switch (_j.mType) { case Json::DataType::null: _oStream << "null"; return true; case Json::DataType::boolean: return push(_j.mNumber.b, _oStream); case Json::DataType::integer: _oStream << _j.mNumber.i; return true; case Json::DataType::real: _oStream << _j.mNumber.f; return true; case Json::DataType::text: _oStream << '\"' << _j.mText << '\"'; return true; case Json::DataType::array: return push(_j.mArray, _oStream, _tab); case Json::DataType::object: return push(_j.mObject, _oStream, _tab); default: return false; // Error data type } }
static void print_ifclose(int indent, int brace) { f_print(fout, "))\n"); tabify(fout, indent); f_print(fout, "\treturn (FALSE);\n"); if (brace) f_print(fout, "\t}\n"); }
//------------------------------------------------------------------------------------------------------------------ bool Serializer::push(const Json::Dictionary& _obj, ostream& _oStream, size_t _tab) { _oStream << "{\n"; // Open braces // Push elements size_t i = 0; for(const auto& element : _obj) { tabify(_oStream, _tab+1); _oStream << "\"" << element.first << "\": "; // Key if(!push(*element.second, _oStream, _tab+1, true)) // Value return false; // Error processing element if(i < _obj.size()-1) // All elements but the last one _oStream << ','; _oStream << '\n'; ++i; } // Close braces tabify(_oStream, _tab); _oStream << '}'; return true; }
int main(int argc, char *argv[]) { int ch, failed; char *filename; setlocale(LC_CTYPE, ""); nstops = 1; tabstops[0] = 8; while ((ch = getopt(argc, argv, "at:")) != -1) { switch (ch) { case 'a': /* Un-expand all spaces, not just leading. */ all = 1; break; case 't': /* Specify tab list, implies -a. */ getstops(optarg); all = 1; break; default: usage(); /*NOTREACHED*/ } } argc -= optind; argv += optind; failed = 0; if (argc == 0) failed |= tabify("stdin"); else { while ((filename = *argv++) != NULL) { if (freopen(filename, "r", stdin) == NULL) { warn("%s", filename); failed = 1; } else failed |= tabify(filename); } } exit(failed != 0); }
//------------------------------------------------------------------------------------------------------------------ bool Serializer::push(const Json::Array& _array, ostream& _oStream, size_t _tab) { _oStream << "[\n"; // Open braces // Push elements for(size_t i = 0; i < _array.size(); ++i) { if(!push(*_array[i], _oStream, _tab+1)) return false; // Error processing element if(i != _array.size()-1) // All elements but the last one _oStream << ','; _oStream << '\n'; } // Close braces tabify(_oStream, _tab); _oStream << ']'; return true; }
QString ModelPrinter::getRowSring(UnityMenuModel* sourceModel, int row, int depth) const { QString str; QTextStream stream(&str); // Print out this row QHash<int, QByteArray> roleNames = sourceModel->roleNames(); QList<int> roles = roleNames.keys(); qSort(roles); Q_FOREACH(int role, roles) { const QByteArray& roleName = roleNames[role]; stream << tabify(depth) << getVariantString(roleName, sourceModel->get(row, roleName)); } return str; }
static void print_ifsizeof(int indent, const char *prefix, const char *type) { if (indent) { f_print(fout, ",\n"); tabify(fout, indent); } else { f_print(fout, ", "); } if (streq(type, "bool")) { f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool"); } else { f_print(fout, "sizeof ("); if (undefined(type) && prefix) f_print(fout, "%s ", prefix); f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type); } }
static void indentLine(QTextBlock block, int newIndent) { QString indentString; indentString.fill(QLatin1Char(' '), newIndent); indentString.append(QLatin1String("a")); tabify(indentString); indentString.remove(indentString.length() - 1, 1); newIndent = indentString.length(); QTextCursor cursor(block); cursor.movePosition(QTextCursor::StartOfBlock); QString blockText = block.text(); int i = 0; while (!blockText.isEmpty() && (blockText.at(i) == QLatin1Char(' ') || blockText.at(i) == QLatin1Char('\t'))) ++i; if (i > 0) { cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, i); cursor.removeSelectedText(); } if (block.length() == 1) cursor.insertText(QLatin1String(" ")); if (!indentString.isEmpty()) cursor.insertText(indentString); /* while ( p->length() > 0 && ( p->at( 0 )->c == ' ' || p->at( 0 )->c == '\t' ) ) { ++oldIndent; p->remove( 0, 1 ); } if ( p->string()->length() == 0 ) p->append( QString::fromLatin1(" ") ); if ( !indentString.isEmpty() ) p->insert( 0, indentString ); */ }
static void print_ifopen(int indent, char *name) { tabify(fout, indent); f_print(fout, "if (!xdr_%s(xdrs", name); }
int main(int argc, char **argv) { int c; char *ep, *tab; char *line; size_t len; unsigned long i; setprogname(argv[0]); while ((c = getopt(argc, argv, "at:")) != -1) { switch (c) { case 'a': if (nstops) usage(); all++; break; case 't': if (all) usage(); while ((tab = strsep(&optarg, ", \t")) != NULL) { if (*tab == '\0') continue; errno = 0; i = strtoul(tab, &ep, 0); if (*ep || (errno == ERANGE && i == ULONG_MAX)) errx(EXIT_FAILURE, "Invalid tabstop `%s'", tab); if (nstops >= maxstops) { maxstops += 20; tabstops = erealloc(tabstops, maxstops); } if (nstops && tabstops[nstops - 1] >= (size_t)i) errx(EXIT_FAILURE, "Bad tabstop spec `%s', must be " "greater than the previous `%zu'", tab, tabstops[nstops - 1]); tabstops[nstops++] = i; } break; case '?': default: usage(); } } argc -= optind; argv += optind; for (i = 0; i < nstops; i++) fprintf(stderr, "%lu %zu\n", i, tabstops[i]); do { if (argc > 0) { if (freopen(argv[0], "r", stdin) == NULL) err(EXIT_FAILURE, "Cannot open `%s'", argv[0]); argc--, argv++; } while ((line = fgetln(stdin, &len)) != NULL) tabify(line, len); } while (argc > 0); return EXIT_SUCCESS; }