summaryrefslogtreecommitdiffstats
path: root/5/11.c
diff options
context:
space:
mode:
Diffstat (limited to '5/11.c')
-rw-r--r--5/11.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/5/11.c b/5/11.c
index 883ed8a..ba30951 100644
--- a/5/11.c
+++ b/5/11.c
@@ -18,10 +18,10 @@
int gettablist(char *s, int *t);
-/* Replaces blanks with tabs */
-void entab(char *s, char *t, int *tablist, int tablistc);
/* Replaces tabs with blanks */
void detab(char *s, char *t, int *tablist, int tablistc);
+/* Replaces blanks with tabs */
+void entab(char *s, char *t, int *tablist, int tablistc);
int main(int argc, char *argv[]) {
int colv[MAXTABLIST], colc;
@@ -92,6 +92,38 @@ int gettablist(char *s, int *t) {
return j;
}
+void detab(char *s, char *t, int *tablist, int tablistc) {
+ int i, j, k, col;
+
+ if (tablistc < 2) {
+ col = tablistc == 0 ? TABSIZE : tablist[0];
+ for (i = 0, j = 0; j < MAXTEXT && (t[j] = s[i]) != 0; i++) {
+ if (s[i] == '\t') {
+ for (k = 0; k < col && j < MAXTEXT; k++, j++)
+ t[j] = ' ';
+ } else
+ j++;
+ }
+ } else {
+ col = 1;
+ for (i = 0, j = 0, k = 0; k < MAXTEXT && s[i] != 0 && j <= tablistc; i++) {
+ if (s[i] != '\t') {
+ t[k++] = s[i];
+ if (s[i] == '\n')
+ col = 1;
+ else
+ col++;
+ } else {
+ for (; col <= tablist[j] && k < MAXTEXT; col++)
+ t[k++] = ' ';
+ j++;
+ }
+ }
+
+ t[k] = 0;
+ }
+}
+
void entab(char *s, char *t, int *tablist, int tablistc) {
int i, j, k, l, m, n;
@@ -138,35 +170,4 @@ void entab(char *s, char *t, int *tablist, int tablistc) {
t[k] = 0;
}
-}
-
-void detab(char *s, char *t, int *tablist, int tablistc) {
- int i, j, k, col;
-
- if (tablistc < 2) {
- for (i = 0, j = 0; j < MAXTEXT && (t[j] = s[i]) != 0; i++) {
- if (s[i] == '\t') {
- for (k = 0; k < TABSIZE && j < MAXTEXT; k++, j++)
- t[j] = ' ';
- } else
- j++;
- }
- } else {
- col = 1;
- for (i = 0, j = 0, k = 0; k < MAXTEXT && s[i] != 0 && j <= tablistc; i++) {
- if (s[i] != '\t') {
- t[k++] = s[i];
- if (s[i] == '\n')
- col = 1;
- else
- col++;
- } else {
- for (; col <= tablist[j] && k < MAXTEXT; col++)
- t[k++] = ' ';
- j++;
- }
- }
-
- t[k] = 0;
- }
} \ No newline at end of file