Saturday, September 1, 2012

ASUS VH238H, SUSE 10.1

I hooked up ASUS VH238H monitor to our old computer running SUSE 10.1, but I could not get it to display in 1920 by 1080. I ended up modifying xorg.conf again.

This time, I changed "screen" section. I basically removed all the unnecessary resolutions and left only 1920x1080 in order to force the video card to display in that resolution. This did the trick. I wonder if this would work for the other, even older machine, running redhat.

-unkokusei

Friday, August 31, 2012

openSUSE 10.1

We have a somewhat ancient SUSE linux machine at hour office.

Today, one of our undergrads. was trying different monitors to see which one he liked the best on this machine. He was simply pluging-unpluging one after another. Then, at the third monitor, the screen blacked out. After rebooting the computer manually by pressing the power button, the computer complained about the display not found and the GUI didn't come on.

It said "fatal server error no screen found"

It turned out that xserver setting got messed up somehow. What I ended up doing was to modify one line in "device" section in xorg.conf. I changed in the "driver" line "fglrx" to "ati" and it worked. After that, I went online and found the following website:

http://forums.opensuse.org/information-new-users/advanced-how-faq-read-only/438705-opensuse-graphic-card-practical-theory-guide-users.html

There, it says "fglrx - this is the proprietary free (as in free beer) ATI driver for the latest ATI hardware." and also says "ati - this is the free open source "ati" driver for very old ATI hardware." 

Our computer is pretty old, built back in 2005 (could be older). Perhaps, the driver "fglrx" was not compatible with the video card. 

Hope this will help someone out there, who isn't very knowledgeable about linux like me.

-unkokusei

Sunday, August 26, 2012

In section 5.2, they talk about getint function. I just can't understand the point of this function. Why would one want to use ungetch function. It seems strange...

-unkokusei

Exercise 5-7

My solution for Exercise 5-7
THE C PROGRAMMING LANGUAGE, 2nd ed.
Kernighan and Ritchie


#include <stdio.h>
#include <string.h>

#define MAXLINES 5000   /* max # of lines to be stored */
#define BUFFERSIZE 1000000 /* */

char *lineptr[MAXLINES];    /* pointers to text lines */

int readlines(char *[], int, char []);
void writelines(char *[], int);
void qsort(char *[], int, int);

/* sort input lines */
int main()
{
    int nlines;     /* number of input lines read */
    char buffer[BUFFERSIZE];    /* instead of allocbuf */

    printf("To finish input, hit Enter, then EOF (Ctrl+z for Windows or Ctrl+d for Linux), then hit Enter again.\n");
    if ((nlines = readlines(lineptr, MAXLINES, buffer)) >= 0) {
        qsort(lineptr, 0, nlines-1);
        writelines(lineptr, nlines);
        return 0;
    } else {
        printf("error: input too big to sort\n");
        return 1;
    }
}

#define MAXLEN 1000 /* max length of any input line */
int getline(char *, int);
int mystrcmp(char *, char *);
void swap2(char *v[], int i, int j);

/* readlines: read input lines */
int readlines(char *lineptr[], int maxlines, char buffer[])
{
int len, nlines;
char *p, line[MAXLEN];
char *bufferp = buffer;

nlines = 0;
while ((len = getline(line, MAXLEN)) > 0) {
        if (buffer + BUFFERSIZE - bufferp >= len && nlines < maxlines) {
            line[len-1] = '\0'; /* delete newline */
            strcpy(bufferp, line);  /* store line in buffer */
            lineptr[nlines++] = bufferp;
            bufferp += len;
        } else {
            return -1;
        }
}
return nlines;
}

/* writelines: write output lines */
void writelines(char *lineptr[], int nlines)
{
int i;
    printf("------- writelines -------\n");
for (i = 0; i < nlines; i++)
printf("%s\n", lineptr[i]);
}

/* getline: read a line into s including newline, return length,
   lim = max length of any input line */
int getline(char s[], int lim)
{
    int c, i;

    for (i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; ++i)
        s[i] = c;
    if (c == '\n') {
        s[i] = c;
        ++i;
    }
    s[i] = '\0';
    return i;
}

/* qsort: sort v[left]...v[right] into increasing order */
void qsort(char *v[], int left, int right)
{
    int i, last;

    if (left >= right)
        return;
    swap2(v, left, (left + right)/2);
    last = left;
    for (i = left+1; i <= right; i++)
        if (mystrcmp(v[i], v[left]) < 0)
            swap2(v, ++last, i);
    swap2(v, left, last);
    qsort(v, left, last-1);
    qsort(v, last+1, right);
}

/* swap2: interchange v[i] and v[j] */
void swap2(char *v[], int i, int j)
{
    char *temp;

    temp = v[i];
    v[i] = v[j];
    v[j] = temp;
}

/* strcmp: return < 0 if s < t, 0 if s == t, > 0 if s > t */
int mystrcmp(char *s, char *t)
{
    int i;

    for (i = 0; s[i] == t[i]; i++)
        if (s[i] == '\0')
            return 0;
        return s[i] - t[i];
}

-unkokusei

Exercise 4-12

My solution for Exercise 4-12
THE C PROGRAMMING LANGUAGE, 2nd ed.
Kernighan and Ritchie

char *myitoa2(int n, char *s)
{
    int sign;

    if ((sign = n) < 0) {
        n = -n;
        *s++ = '-';
    }
    if (n / 10) {
        s = myitoa2(n / 10, s);
    }
    *s++ =  n % 10 + '0';
    *s = '\0';
    return s;
}

-unkokusei